@tsparticles/preset-hyperspace 4.0.5 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* Preset v4.
|
|
2
|
+
/* Preset v4.1.1 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -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.
|
|
1015
|
+
return "4.1.1";
|
|
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.
|
|
2808
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2845
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2893
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2946
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
2970
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3077
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3424
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3495
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3550
|
+
engine.checkVersion("4.1.1");
|
|
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
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3600
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3601
|
+
if (!sizeOptions) {
|
|
3602
|
+
return;
|
|
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;
|
|
3609
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.
|
|
3649
|
+
engine.checkVersion("4.1.1");
|
|
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.
|
|
3658
|
+
engine.checkVersion("4.1.1");
|
|
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)) {
|
|
@@ -3940,7 +3957,7 @@
|
|
|
3940
3957
|
})(EmitterClickMode || (EmitterClickMode = {}));
|
|
3941
3958
|
|
|
3942
3959
|
async function loadEmittersPluginSimple(engine) {
|
|
3943
|
-
engine.checkVersion("4.
|
|
3960
|
+
engine.checkVersion("4.1.1");
|
|
3944
3961
|
await engine.pluginManager.register(async (e) => {
|
|
3945
3962
|
const instancesManager = await getEmittersInstancesManager(e);
|
|
3946
3963
|
await addEmittersShapesManager(e);
|
|
@@ -4028,7 +4045,7 @@
|
|
|
4028
4045
|
}
|
|
4029
4046
|
|
|
4030
4047
|
async function loadEmittersShapeSquare(engine) {
|
|
4031
|
-
engine.checkVersion("4.
|
|
4048
|
+
engine.checkVersion("4.1.1");
|
|
4032
4049
|
await engine.pluginManager.register((e) => {
|
|
4033
4050
|
ensureEmittersPluginLoaded(e);
|
|
4034
4051
|
e.pluginManager.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator());
|
|
@@ -4145,12 +4162,12 @@
|
|
|
4145
4162
|
|
|
4146
4163
|
const noTime = 0, identity$1 = 1, infiniteValue = -1;
|
|
4147
4164
|
class LifeUpdater {
|
|
4148
|
-
container;
|
|
4165
|
+
#container;
|
|
4149
4166
|
constructor(container) {
|
|
4150
|
-
this
|
|
4167
|
+
this.#container = container;
|
|
4151
4168
|
}
|
|
4152
4169
|
init(particle) {
|
|
4153
|
-
const container = this
|
|
4170
|
+
const container = this.#container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
4154
4171
|
if (!lifeOptions) {
|
|
4155
4172
|
return;
|
|
4156
4173
|
}
|
|
@@ -4189,12 +4206,12 @@
|
|
|
4189
4206
|
if (!this.isEnabled(particle) || !particle.life) {
|
|
4190
4207
|
return;
|
|
4191
4208
|
}
|
|
4192
|
-
updateLife(particle, delta, this
|
|
4209
|
+
updateLife(particle, delta, this.#container.canvas.size);
|
|
4193
4210
|
}
|
|
4194
4211
|
}
|
|
4195
4212
|
|
|
4196
4213
|
async function loadLifeUpdater(engine) {
|
|
4197
|
-
engine.checkVersion("4.
|
|
4214
|
+
engine.checkVersion("4.1.1");
|
|
4198
4215
|
await engine.pluginManager.register(e => {
|
|
4199
4216
|
e.pluginManager.addParticleUpdater("life", container => {
|
|
4200
4217
|
return Promise.resolve(new LifeUpdater(container));
|
|
@@ -4245,13 +4262,13 @@
|
|
|
4245
4262
|
|
|
4246
4263
|
class TrailPlugin {
|
|
4247
4264
|
id = "trail";
|
|
4248
|
-
|
|
4265
|
+
#pluginManager;
|
|
4249
4266
|
constructor(pluginManager) {
|
|
4250
|
-
this
|
|
4267
|
+
this.#pluginManager = pluginManager;
|
|
4251
4268
|
}
|
|
4252
4269
|
async getPlugin(container) {
|
|
4253
4270
|
const { TrailPluginInstance } = await Promise.resolve().then(function () { return TrailPluginInstance$1; });
|
|
4254
|
-
return new TrailPluginInstance(this
|
|
4271
|
+
return new TrailPluginInstance(this.#pluginManager, container);
|
|
4255
4272
|
}
|
|
4256
4273
|
loadOptions(_container, options, source) {
|
|
4257
4274
|
if (!this.needsPlugin()) {
|
|
@@ -4269,7 +4286,7 @@
|
|
|
4269
4286
|
}
|
|
4270
4287
|
|
|
4271
4288
|
async function loadTrailPlugin(engine) {
|
|
4272
|
-
engine.checkVersion("4.
|
|
4289
|
+
engine.checkVersion("4.1.1");
|
|
4273
4290
|
await engine.pluginManager.register(e => {
|
|
4274
4291
|
e.pluginManager.addPlugin(new TrailPlugin(e.pluginManager));
|
|
4275
4292
|
});
|
|
@@ -4366,58 +4383,58 @@
|
|
|
4366
4383
|
}
|
|
4367
4384
|
}
|
|
4368
4385
|
class RenderManager {
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4386
|
+
#canvasClearPlugins;
|
|
4387
|
+
#canvasManager;
|
|
4388
|
+
#canvasPaintPlugins;
|
|
4389
|
+
#clearDrawPlugins;
|
|
4390
|
+
#colorPlugins;
|
|
4391
|
+
#container;
|
|
4392
|
+
#context;
|
|
4393
|
+
#contextSettings;
|
|
4394
|
+
#drawParticlePlugins;
|
|
4395
|
+
#drawParticlesCleanupPlugins;
|
|
4396
|
+
#drawParticlesSetupPlugins;
|
|
4397
|
+
#drawPlugins;
|
|
4398
|
+
#drawSettingsCleanupPlugins;
|
|
4399
|
+
#drawSettingsSetupPlugins;
|
|
4400
|
+
#pluginManager;
|
|
4401
|
+
#postDrawUpdaters;
|
|
4402
|
+
#preDrawUpdaters;
|
|
4403
|
+
#reusableColorStyles = {};
|
|
4404
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4405
|
+
#reusableTransform = {};
|
|
4389
4406
|
constructor(pluginManager, container, canvasManager) {
|
|
4390
|
-
this
|
|
4391
|
-
this
|
|
4392
|
-
this
|
|
4393
|
-
this
|
|
4394
|
-
this
|
|
4395
|
-
this
|
|
4396
|
-
this
|
|
4397
|
-
this
|
|
4398
|
-
this
|
|
4399
|
-
this
|
|
4400
|
-
this
|
|
4401
|
-
this
|
|
4402
|
-
this
|
|
4403
|
-
this
|
|
4404
|
-
this
|
|
4405
|
-
this
|
|
4407
|
+
this.#pluginManager = pluginManager;
|
|
4408
|
+
this.#container = container;
|
|
4409
|
+
this.#canvasManager = canvasManager;
|
|
4410
|
+
this.#context = null;
|
|
4411
|
+
this.#preDrawUpdaters = [];
|
|
4412
|
+
this.#postDrawUpdaters = [];
|
|
4413
|
+
this.#colorPlugins = [];
|
|
4414
|
+
this.#canvasClearPlugins = [];
|
|
4415
|
+
this.#canvasPaintPlugins = [];
|
|
4416
|
+
this.#clearDrawPlugins = [];
|
|
4417
|
+
this.#drawParticlePlugins = [];
|
|
4418
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4419
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4420
|
+
this.#drawPlugins = [];
|
|
4421
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4422
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4406
4423
|
}
|
|
4407
4424
|
get settings() {
|
|
4408
|
-
return this
|
|
4425
|
+
return this.#contextSettings;
|
|
4409
4426
|
}
|
|
4410
4427
|
canvasClear() {
|
|
4411
|
-
if (!this.
|
|
4428
|
+
if (!this.#container.actualOptions.clear) {
|
|
4412
4429
|
return;
|
|
4413
4430
|
}
|
|
4414
4431
|
this.draw(ctx => {
|
|
4415
|
-
clear(ctx, this.
|
|
4432
|
+
clear(ctx, this.#canvasManager.size);
|
|
4416
4433
|
});
|
|
4417
4434
|
}
|
|
4418
4435
|
clear() {
|
|
4419
4436
|
let pluginHandled = false;
|
|
4420
|
-
for (const plugin of this
|
|
4437
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4421
4438
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4422
4439
|
if (pluginHandled) {
|
|
4423
4440
|
break;
|
|
@@ -4430,21 +4447,21 @@
|
|
|
4430
4447
|
}
|
|
4431
4448
|
destroy() {
|
|
4432
4449
|
this.stop();
|
|
4433
|
-
this
|
|
4434
|
-
this
|
|
4435
|
-
this
|
|
4436
|
-
this
|
|
4437
|
-
this
|
|
4438
|
-
this
|
|
4439
|
-
this
|
|
4440
|
-
this
|
|
4441
|
-
this
|
|
4442
|
-
this
|
|
4443
|
-
this
|
|
4444
|
-
this
|
|
4450
|
+
this.#preDrawUpdaters = [];
|
|
4451
|
+
this.#postDrawUpdaters = [];
|
|
4452
|
+
this.#colorPlugins = [];
|
|
4453
|
+
this.#canvasClearPlugins = [];
|
|
4454
|
+
this.#canvasPaintPlugins = [];
|
|
4455
|
+
this.#clearDrawPlugins = [];
|
|
4456
|
+
this.#drawParticlePlugins = [];
|
|
4457
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4458
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4459
|
+
this.#drawPlugins = [];
|
|
4460
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4461
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4445
4462
|
}
|
|
4446
4463
|
draw(cb) {
|
|
4447
|
-
const ctx = this
|
|
4464
|
+
const ctx = this.#context;
|
|
4448
4465
|
if (!ctx) {
|
|
4449
4466
|
return;
|
|
4450
4467
|
}
|
|
@@ -4459,21 +4476,21 @@
|
|
|
4459
4476
|
return;
|
|
4460
4477
|
}
|
|
4461
4478
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4462
|
-
let [fColor, sColor] = this
|
|
4479
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4463
4480
|
fColor ??= pfColor;
|
|
4464
4481
|
sColor ??= psColor;
|
|
4465
4482
|
if (!fColor && !sColor) {
|
|
4466
4483
|
return;
|
|
4467
4484
|
}
|
|
4468
|
-
const container = this
|
|
4485
|
+
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;
|
|
4469
4486
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4470
4487
|
colorStyles.fill = fill;
|
|
4471
4488
|
colorStyles.stroke = stroke;
|
|
4472
4489
|
this.draw((context) => {
|
|
4473
|
-
for (const plugin of this
|
|
4490
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4474
4491
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4475
4492
|
}
|
|
4476
|
-
this
|
|
4493
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4477
4494
|
drawParticle({
|
|
4478
4495
|
container,
|
|
4479
4496
|
context,
|
|
@@ -4484,35 +4501,35 @@
|
|
|
4484
4501
|
opacity: opacity,
|
|
4485
4502
|
transform,
|
|
4486
4503
|
});
|
|
4487
|
-
this
|
|
4488
|
-
for (const plugin of this
|
|
4504
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4505
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4489
4506
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4490
4507
|
}
|
|
4491
4508
|
});
|
|
4492
4509
|
}
|
|
4493
4510
|
drawParticlePlugins(particle, delta) {
|
|
4494
4511
|
this.draw(ctx => {
|
|
4495
|
-
for (const plugin of this
|
|
4512
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4496
4513
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4497
4514
|
}
|
|
4498
4515
|
});
|
|
4499
4516
|
}
|
|
4500
4517
|
drawParticles(delta) {
|
|
4501
|
-
const { particles } = this
|
|
4518
|
+
const { particles } = this.#container;
|
|
4502
4519
|
this.clear();
|
|
4503
4520
|
particles.update(delta);
|
|
4504
4521
|
this.draw(ctx => {
|
|
4505
|
-
for (const plugin of this
|
|
4522
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4506
4523
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4507
4524
|
}
|
|
4508
|
-
for (const plugin of this
|
|
4525
|
+
for (const plugin of this.#drawPlugins) {
|
|
4509
4526
|
plugin.draw?.(ctx, delta);
|
|
4510
4527
|
}
|
|
4511
4528
|
particles.drawParticles(delta);
|
|
4512
|
-
for (const plugin of this
|
|
4529
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4513
4530
|
plugin.clearDraw?.(ctx, delta);
|
|
4514
4531
|
}
|
|
4515
|
-
for (const plugin of this
|
|
4532
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4516
4533
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4517
4534
|
}
|
|
4518
4535
|
});
|
|
@@ -4523,64 +4540,64 @@
|
|
|
4523
4540
|
this.paint();
|
|
4524
4541
|
}
|
|
4525
4542
|
initPlugins() {
|
|
4526
|
-
this
|
|
4527
|
-
this
|
|
4528
|
-
this
|
|
4529
|
-
this
|
|
4530
|
-
this
|
|
4531
|
-
this
|
|
4532
|
-
this
|
|
4533
|
-
this
|
|
4534
|
-
this
|
|
4535
|
-
this
|
|
4536
|
-
for (const plugin of this.
|
|
4543
|
+
this.#colorPlugins = [];
|
|
4544
|
+
this.#canvasClearPlugins = [];
|
|
4545
|
+
this.#canvasPaintPlugins = [];
|
|
4546
|
+
this.#clearDrawPlugins = [];
|
|
4547
|
+
this.#drawParticlePlugins = [];
|
|
4548
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4549
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4550
|
+
this.#drawPlugins = [];
|
|
4551
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4552
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4553
|
+
for (const plugin of this.#container.plugins) {
|
|
4537
4554
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4538
|
-
this.
|
|
4555
|
+
this.#colorPlugins.push(plugin);
|
|
4539
4556
|
}
|
|
4540
4557
|
if (plugin.canvasClear) {
|
|
4541
|
-
this.
|
|
4558
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4542
4559
|
}
|
|
4543
4560
|
if (plugin.canvasPaint) {
|
|
4544
|
-
this.
|
|
4561
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4545
4562
|
}
|
|
4546
4563
|
if (plugin.drawParticle) {
|
|
4547
|
-
this.
|
|
4564
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4548
4565
|
}
|
|
4549
4566
|
if (plugin.drawParticleSetup) {
|
|
4550
|
-
this.
|
|
4567
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4551
4568
|
}
|
|
4552
4569
|
if (plugin.drawParticleCleanup) {
|
|
4553
|
-
this.
|
|
4570
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4554
4571
|
}
|
|
4555
4572
|
if (plugin.draw) {
|
|
4556
|
-
this.
|
|
4573
|
+
this.#drawPlugins.push(plugin);
|
|
4557
4574
|
}
|
|
4558
4575
|
if (plugin.drawSettingsSetup) {
|
|
4559
|
-
this.
|
|
4576
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4560
4577
|
}
|
|
4561
4578
|
if (plugin.drawSettingsCleanup) {
|
|
4562
|
-
this.
|
|
4579
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4563
4580
|
}
|
|
4564
4581
|
if (plugin.clearDraw) {
|
|
4565
|
-
this.
|
|
4582
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4566
4583
|
}
|
|
4567
4584
|
}
|
|
4568
4585
|
}
|
|
4569
4586
|
initUpdaters() {
|
|
4570
|
-
this
|
|
4571
|
-
this
|
|
4572
|
-
for (const updater of this.
|
|
4587
|
+
this.#preDrawUpdaters = [];
|
|
4588
|
+
this.#postDrawUpdaters = [];
|
|
4589
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4573
4590
|
if (updater.afterDraw) {
|
|
4574
|
-
this.
|
|
4591
|
+
this.#postDrawUpdaters.push(updater);
|
|
4575
4592
|
}
|
|
4576
4593
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4577
|
-
this.
|
|
4594
|
+
this.#preDrawUpdaters.push(updater);
|
|
4578
4595
|
}
|
|
4579
4596
|
}
|
|
4580
4597
|
}
|
|
4581
4598
|
paint() {
|
|
4582
4599
|
let handled = false;
|
|
4583
|
-
for (const plugin of this
|
|
4600
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4584
4601
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4585
4602
|
if (handled) {
|
|
4586
4603
|
break;
|
|
@@ -4593,35 +4610,35 @@
|
|
|
4593
4610
|
}
|
|
4594
4611
|
paintBase(baseColor) {
|
|
4595
4612
|
this.draw(ctx => {
|
|
4596
|
-
paintBase(ctx, this.
|
|
4613
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4597
4614
|
});
|
|
4598
4615
|
}
|
|
4599
4616
|
paintImage(image, opacity) {
|
|
4600
4617
|
this.draw(ctx => {
|
|
4601
|
-
paintImage(ctx, this.
|
|
4618
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4602
4619
|
});
|
|
4603
4620
|
}
|
|
4604
4621
|
setContext(context) {
|
|
4605
|
-
this
|
|
4606
|
-
if (this
|
|
4607
|
-
this.
|
|
4622
|
+
this.#context = context;
|
|
4623
|
+
if (this.#context) {
|
|
4624
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4608
4625
|
}
|
|
4609
4626
|
}
|
|
4610
4627
|
setContextSettings(settings) {
|
|
4611
|
-
this
|
|
4628
|
+
this.#contextSettings = settings;
|
|
4612
4629
|
}
|
|
4613
4630
|
stop() {
|
|
4614
4631
|
this.draw(ctx => {
|
|
4615
|
-
clear(ctx, this.
|
|
4632
|
+
clear(ctx, this.#canvasManager.size);
|
|
4616
4633
|
});
|
|
4617
4634
|
}
|
|
4618
|
-
|
|
4619
|
-
for (const updater of this
|
|
4635
|
+
#applyPostDrawUpdaters = particle => {
|
|
4636
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4620
4637
|
updater.afterDraw?.(particle);
|
|
4621
4638
|
}
|
|
4622
4639
|
};
|
|
4623
|
-
|
|
4624
|
-
for (const updater of this
|
|
4640
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
4641
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
4625
4642
|
if (updater.getColorStyles) {
|
|
4626
4643
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
4627
4644
|
if (fill) {
|
|
@@ -4640,22 +4657,22 @@
|
|
|
4640
4657
|
updater.beforeDraw?.(particle);
|
|
4641
4658
|
}
|
|
4642
4659
|
};
|
|
4643
|
-
|
|
4660
|
+
#getPluginParticleColors = particle => {
|
|
4644
4661
|
let fColor, sColor;
|
|
4645
|
-
for (const plugin of this
|
|
4662
|
+
for (const plugin of this.#colorPlugins) {
|
|
4646
4663
|
if (!fColor && plugin.particleFillColor) {
|
|
4647
|
-
fColor = rangeColorToHsl(this
|
|
4664
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
4648
4665
|
}
|
|
4649
4666
|
if (!sColor && plugin.particleStrokeColor) {
|
|
4650
|
-
sColor = rangeColorToHsl(this
|
|
4667
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
4651
4668
|
}
|
|
4652
4669
|
if (fColor && sColor) {
|
|
4653
4670
|
break;
|
|
4654
4671
|
}
|
|
4655
4672
|
}
|
|
4656
|
-
this
|
|
4657
|
-
this
|
|
4658
|
-
return this
|
|
4673
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
4674
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4675
|
+
return this.#reusablePluginColors;
|
|
4659
4676
|
};
|
|
4660
4677
|
}
|
|
4661
4678
|
|
|
@@ -4713,53 +4730,53 @@
|
|
|
4713
4730
|
renderCanvas;
|
|
4714
4731
|
size;
|
|
4715
4732
|
zoom = defaultZoom;
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4733
|
+
#container;
|
|
4734
|
+
#generated;
|
|
4735
|
+
#mutationObserver;
|
|
4736
|
+
#originalStyle;
|
|
4737
|
+
#pluginManager;
|
|
4738
|
+
#pointerEvents;
|
|
4739
|
+
#resizePlugins;
|
|
4740
|
+
#standardSize;
|
|
4741
|
+
#zoomCenter;
|
|
4725
4742
|
constructor(pluginManager, container) {
|
|
4726
|
-
this
|
|
4727
|
-
this
|
|
4743
|
+
this.#pluginManager = pluginManager;
|
|
4744
|
+
this.#container = container;
|
|
4728
4745
|
this.render = new RenderManager(pluginManager, container, this);
|
|
4729
|
-
this
|
|
4746
|
+
this.#standardSize = {
|
|
4730
4747
|
height: 0,
|
|
4731
4748
|
width: 0,
|
|
4732
4749
|
};
|
|
4733
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
4750
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
4734
4751
|
this.size = {
|
|
4735
4752
|
height: stdSize.height * pxRatio,
|
|
4736
4753
|
width: stdSize.width * pxRatio,
|
|
4737
4754
|
};
|
|
4738
|
-
this
|
|
4739
|
-
this
|
|
4740
|
-
this
|
|
4755
|
+
this.#generated = false;
|
|
4756
|
+
this.#resizePlugins = [];
|
|
4757
|
+
this.#pointerEvents = "none";
|
|
4741
4758
|
}
|
|
4742
|
-
get
|
|
4743
|
-
return this.
|
|
4759
|
+
get #fullScreen() {
|
|
4760
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
4744
4761
|
}
|
|
4745
4762
|
destroy() {
|
|
4746
4763
|
this.stop();
|
|
4747
|
-
if (this
|
|
4764
|
+
if (this.#generated) {
|
|
4748
4765
|
const element = this.domElement;
|
|
4749
4766
|
element?.remove();
|
|
4750
4767
|
this.domElement = undefined;
|
|
4751
4768
|
this.renderCanvas = undefined;
|
|
4752
4769
|
}
|
|
4753
4770
|
else {
|
|
4754
|
-
this
|
|
4771
|
+
this.#resetOriginalStyle();
|
|
4755
4772
|
}
|
|
4756
4773
|
this.render.destroy();
|
|
4757
|
-
this
|
|
4774
|
+
this.#resizePlugins = [];
|
|
4758
4775
|
}
|
|
4759
4776
|
getZoomCenter() {
|
|
4760
|
-
const pxRatio = this.
|
|
4761
|
-
if (this
|
|
4762
|
-
return this
|
|
4777
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
4778
|
+
if (this.#zoomCenter) {
|
|
4779
|
+
return this.#zoomCenter;
|
|
4763
4780
|
}
|
|
4764
4781
|
return {
|
|
4765
4782
|
x: (width * half) / pxRatio,
|
|
@@ -4767,20 +4784,20 @@
|
|
|
4767
4784
|
};
|
|
4768
4785
|
}
|
|
4769
4786
|
init() {
|
|
4770
|
-
this
|
|
4787
|
+
this.#safeMutationObserver(obs => {
|
|
4771
4788
|
obs.disconnect();
|
|
4772
4789
|
});
|
|
4773
|
-
this
|
|
4790
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
4774
4791
|
for (const record of records) {
|
|
4775
4792
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
4776
|
-
this
|
|
4793
|
+
this.#repairStyle();
|
|
4777
4794
|
}
|
|
4778
4795
|
}
|
|
4779
4796
|
});
|
|
4780
4797
|
this.resize();
|
|
4781
|
-
this
|
|
4798
|
+
this.#initStyle();
|
|
4782
4799
|
this.initBackground();
|
|
4783
|
-
this
|
|
4800
|
+
this.#safeMutationObserver(obs => {
|
|
4784
4801
|
const element = this.domElement;
|
|
4785
4802
|
if (!element || !(element instanceof Node)) {
|
|
4786
4803
|
return;
|
|
@@ -4791,13 +4808,13 @@
|
|
|
4791
4808
|
this.render.init();
|
|
4792
4809
|
}
|
|
4793
4810
|
initBackground() {
|
|
4794
|
-
const
|
|
4811
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
4795
4812
|
if (!element) {
|
|
4796
4813
|
return;
|
|
4797
4814
|
}
|
|
4798
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
4815
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4799
4816
|
if (color) {
|
|
4800
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
4817
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
4801
4818
|
}
|
|
4802
4819
|
else {
|
|
4803
4820
|
elementStyle.backgroundColor = "";
|
|
@@ -4808,27 +4825,27 @@
|
|
|
4808
4825
|
elementStyle.backgroundSize = background.size || "";
|
|
4809
4826
|
}
|
|
4810
4827
|
initPlugins() {
|
|
4811
|
-
this
|
|
4812
|
-
for (const plugin of this.
|
|
4828
|
+
this.#resizePlugins = [];
|
|
4829
|
+
for (const plugin of this.#container.plugins) {
|
|
4813
4830
|
if (plugin.resize) {
|
|
4814
|
-
this.
|
|
4831
|
+
this.#resizePlugins.push(plugin);
|
|
4815
4832
|
}
|
|
4816
4833
|
}
|
|
4817
4834
|
}
|
|
4818
4835
|
loadCanvas(canvas) {
|
|
4819
|
-
if (this
|
|
4836
|
+
if (this.#generated && this.domElement) {
|
|
4820
4837
|
this.domElement.remove();
|
|
4821
4838
|
}
|
|
4822
|
-
const container = this
|
|
4839
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
4823
4840
|
this.domElement = domCanvas;
|
|
4824
|
-
this
|
|
4841
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
4825
4842
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
4826
4843
|
const domElement = this.domElement;
|
|
4827
4844
|
if (domElement) {
|
|
4828
4845
|
domElement.ariaHidden = "true";
|
|
4829
|
-
this
|
|
4846
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
4830
4847
|
}
|
|
4831
|
-
const standardSize = this
|
|
4848
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
4832
4849
|
if (domElement) {
|
|
4833
4850
|
standardSize.height = domElement.offsetHeight;
|
|
4834
4851
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -4837,7 +4854,7 @@
|
|
|
4837
4854
|
standardSize.height = renderCanvas.height;
|
|
4838
4855
|
standardSize.width = renderCanvas.width;
|
|
4839
4856
|
}
|
|
4840
|
-
const pxRatio = this.
|
|
4857
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
4841
4858
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
4842
4859
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
4843
4860
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -4848,12 +4865,12 @@
|
|
|
4848
4865
|
willReadFrequently: false,
|
|
4849
4866
|
});
|
|
4850
4867
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
4851
|
-
this
|
|
4868
|
+
this.#safeMutationObserver(obs => {
|
|
4852
4869
|
obs.disconnect();
|
|
4853
4870
|
});
|
|
4854
4871
|
container.retina.init();
|
|
4855
4872
|
this.initBackground();
|
|
4856
|
-
this
|
|
4873
|
+
this.#safeMutationObserver(obs => {
|
|
4857
4874
|
const element = this.domElement;
|
|
4858
4875
|
if (!element || !(element instanceof Node)) {
|
|
4859
4876
|
return;
|
|
@@ -4866,11 +4883,11 @@
|
|
|
4866
4883
|
if (!element) {
|
|
4867
4884
|
return false;
|
|
4868
4885
|
}
|
|
4869
|
-
const container = this
|
|
4886
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
4870
4887
|
if (renderCanvas === undefined) {
|
|
4871
4888
|
return false;
|
|
4872
4889
|
}
|
|
4873
|
-
const currentSize = container.canvas
|
|
4890
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
4874
4891
|
width: element.offsetWidth,
|
|
4875
4892
|
height: element.offsetHeight,
|
|
4876
4893
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -4889,7 +4906,7 @@
|
|
|
4889
4906
|
const canvasSize = this.size;
|
|
4890
4907
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
4891
4908
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
4892
|
-
if (this.
|
|
4909
|
+
if (this.#container.started) {
|
|
4893
4910
|
container.particles.setResizeFactor({
|
|
4894
4911
|
width: currentSize.width / oldSize.width,
|
|
4895
4912
|
height: currentSize.height / oldSize.height,
|
|
@@ -4902,46 +4919,46 @@
|
|
|
4902
4919
|
if (!element) {
|
|
4903
4920
|
return;
|
|
4904
4921
|
}
|
|
4905
|
-
this
|
|
4906
|
-
this
|
|
4922
|
+
this.#pointerEvents = type;
|
|
4923
|
+
this.#repairStyle();
|
|
4907
4924
|
}
|
|
4908
4925
|
setZoom(zoomLevel, center) {
|
|
4909
4926
|
this.zoom = zoomLevel;
|
|
4910
|
-
this
|
|
4927
|
+
this.#zoomCenter = center;
|
|
4911
4928
|
}
|
|
4912
4929
|
stop() {
|
|
4913
|
-
this
|
|
4930
|
+
this.#safeMutationObserver(obs => {
|
|
4914
4931
|
obs.disconnect();
|
|
4915
4932
|
});
|
|
4916
|
-
this
|
|
4933
|
+
this.#mutationObserver = undefined;
|
|
4917
4934
|
this.render.stop();
|
|
4918
4935
|
}
|
|
4919
4936
|
async windowResize() {
|
|
4920
4937
|
if (!this.domElement || !this.resize()) {
|
|
4921
4938
|
return;
|
|
4922
4939
|
}
|
|
4923
|
-
const container = this
|
|
4940
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
4924
4941
|
container.particles.setDensity();
|
|
4925
|
-
this
|
|
4942
|
+
this.#applyResizePlugins();
|
|
4926
4943
|
if (needsRefresh) {
|
|
4927
4944
|
await container.refresh();
|
|
4928
4945
|
}
|
|
4929
4946
|
}
|
|
4930
|
-
|
|
4931
|
-
for (const plugin of this
|
|
4947
|
+
#applyResizePlugins = () => {
|
|
4948
|
+
for (const plugin of this.#resizePlugins) {
|
|
4932
4949
|
plugin.resize?.();
|
|
4933
4950
|
}
|
|
4934
4951
|
};
|
|
4935
|
-
|
|
4936
|
-
const element = this.domElement, options = this.
|
|
4952
|
+
#initStyle = () => {
|
|
4953
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
4937
4954
|
if (!element) {
|
|
4938
4955
|
return;
|
|
4939
4956
|
}
|
|
4940
|
-
if (this
|
|
4941
|
-
this
|
|
4957
|
+
if (this.#fullScreen) {
|
|
4958
|
+
this.#setFullScreenStyle();
|
|
4942
4959
|
}
|
|
4943
4960
|
else {
|
|
4944
|
-
this
|
|
4961
|
+
this.#resetOriginalStyle();
|
|
4945
4962
|
}
|
|
4946
4963
|
for (const key in options.style) {
|
|
4947
4964
|
if (!key || !(key in options.style)) {
|
|
@@ -4954,72 +4971,72 @@
|
|
|
4954
4971
|
element.style.setProperty(key, value, "important");
|
|
4955
4972
|
}
|
|
4956
4973
|
};
|
|
4957
|
-
|
|
4974
|
+
#repairStyle = () => {
|
|
4958
4975
|
const element = this.domElement;
|
|
4959
4976
|
if (!element) {
|
|
4960
4977
|
return;
|
|
4961
4978
|
}
|
|
4962
|
-
this
|
|
4979
|
+
this.#safeMutationObserver(observer => {
|
|
4963
4980
|
observer.disconnect();
|
|
4964
4981
|
});
|
|
4965
|
-
this
|
|
4982
|
+
this.#initStyle();
|
|
4966
4983
|
this.initBackground();
|
|
4967
|
-
const pointerEvents = this
|
|
4984
|
+
const pointerEvents = this.#pointerEvents;
|
|
4968
4985
|
element.style.pointerEvents = pointerEvents;
|
|
4969
4986
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
4970
|
-
this
|
|
4987
|
+
this.#safeMutationObserver(observer => {
|
|
4971
4988
|
if (!(element instanceof Node)) {
|
|
4972
4989
|
return;
|
|
4973
4990
|
}
|
|
4974
4991
|
observer.observe(element, { attributes: true });
|
|
4975
4992
|
});
|
|
4976
4993
|
};
|
|
4977
|
-
|
|
4978
|
-
const element = this.domElement, originalStyle = this
|
|
4994
|
+
#resetOriginalStyle = () => {
|
|
4995
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
4979
4996
|
if (!element || !originalStyle) {
|
|
4980
4997
|
return;
|
|
4981
4998
|
}
|
|
4982
4999
|
setStyle(element, originalStyle, true);
|
|
4983
5000
|
};
|
|
4984
|
-
|
|
4985
|
-
if (!this
|
|
5001
|
+
#safeMutationObserver = callback => {
|
|
5002
|
+
if (!this.#mutationObserver) {
|
|
4986
5003
|
return;
|
|
4987
5004
|
}
|
|
4988
|
-
callback(this
|
|
5005
|
+
callback(this.#mutationObserver);
|
|
4989
5006
|
};
|
|
4990
|
-
|
|
5007
|
+
#setFullScreenStyle = () => {
|
|
4991
5008
|
const element = this.domElement;
|
|
4992
5009
|
if (!element) {
|
|
4993
5010
|
return;
|
|
4994
5011
|
}
|
|
4995
|
-
setStyle(element, getFullScreenStyle(this.
|
|
5012
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
4996
5013
|
};
|
|
4997
5014
|
}
|
|
4998
5015
|
|
|
4999
5016
|
class EventListeners {
|
|
5000
|
-
container;
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
|
|
5017
|
+
#container;
|
|
5018
|
+
#handlers;
|
|
5019
|
+
#resizeObserver;
|
|
5020
|
+
#resizeTimeout;
|
|
5004
5021
|
constructor(container) {
|
|
5005
|
-
this
|
|
5006
|
-
this
|
|
5022
|
+
this.#container = container;
|
|
5023
|
+
this.#handlers = {
|
|
5007
5024
|
visibilityChange: () => {
|
|
5008
|
-
this
|
|
5025
|
+
this.#handleVisibilityChange();
|
|
5009
5026
|
},
|
|
5010
5027
|
resize: () => {
|
|
5011
|
-
this
|
|
5028
|
+
this.#handleWindowResize();
|
|
5012
5029
|
},
|
|
5013
5030
|
};
|
|
5014
5031
|
}
|
|
5015
5032
|
addListeners() {
|
|
5016
|
-
this
|
|
5033
|
+
this.#manageListeners(true);
|
|
5017
5034
|
}
|
|
5018
5035
|
removeListeners() {
|
|
5019
|
-
this
|
|
5036
|
+
this.#manageListeners(false);
|
|
5020
5037
|
}
|
|
5021
|
-
|
|
5022
|
-
const container = this
|
|
5038
|
+
#handleVisibilityChange = () => {
|
|
5039
|
+
const container = this.#container, options = container.actualOptions;
|
|
5023
5040
|
if (!options.pauseOnBlur) {
|
|
5024
5041
|
return;
|
|
5025
5042
|
}
|
|
@@ -5037,24 +5054,24 @@
|
|
|
5037
5054
|
}
|
|
5038
5055
|
}
|
|
5039
5056
|
};
|
|
5040
|
-
|
|
5041
|
-
if (this
|
|
5042
|
-
clearTimeout(this
|
|
5043
|
-
|
|
5057
|
+
#handleWindowResize = () => {
|
|
5058
|
+
if (this.#resizeTimeout) {
|
|
5059
|
+
clearTimeout(this.#resizeTimeout);
|
|
5060
|
+
this.#resizeTimeout = undefined;
|
|
5044
5061
|
}
|
|
5045
5062
|
const handleResize = async () => {
|
|
5046
|
-
const canvas = this
|
|
5063
|
+
const canvas = this.#container.canvas;
|
|
5047
5064
|
await canvas.windowResize();
|
|
5048
5065
|
};
|
|
5049
|
-
this
|
|
5066
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5050
5067
|
};
|
|
5051
|
-
|
|
5052
|
-
const handlers = this
|
|
5053
|
-
this
|
|
5068
|
+
#manageListeners = add => {
|
|
5069
|
+
const handlers = this.#handlers;
|
|
5070
|
+
this.#manageResize(add);
|
|
5054
5071
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5055
5072
|
};
|
|
5056
|
-
|
|
5057
|
-
const handlers = this
|
|
5073
|
+
#manageResize = add => {
|
|
5074
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5058
5075
|
if (!options.resize.enable) {
|
|
5059
5076
|
return;
|
|
5060
5077
|
}
|
|
@@ -5063,22 +5080,22 @@
|
|
|
5063
5080
|
return;
|
|
5064
5081
|
}
|
|
5065
5082
|
const canvasEl = container.canvas.domElement;
|
|
5066
|
-
if (this
|
|
5083
|
+
if (this.#resizeObserver && !add) {
|
|
5067
5084
|
if (canvasEl) {
|
|
5068
|
-
this.
|
|
5085
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5069
5086
|
}
|
|
5070
|
-
this.
|
|
5071
|
-
|
|
5087
|
+
this.#resizeObserver.disconnect();
|
|
5088
|
+
this.#resizeObserver = undefined;
|
|
5072
5089
|
}
|
|
5073
|
-
else if (!this
|
|
5074
|
-
this
|
|
5090
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5091
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5075
5092
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5076
5093
|
if (!entry) {
|
|
5077
5094
|
return;
|
|
5078
5095
|
}
|
|
5079
|
-
this
|
|
5096
|
+
this.#handleWindowResize();
|
|
5080
5097
|
});
|
|
5081
|
-
this.
|
|
5098
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5082
5099
|
}
|
|
5083
5100
|
};
|
|
5084
5101
|
}
|
|
@@ -5151,24 +5168,24 @@
|
|
|
5151
5168
|
unbreakable;
|
|
5152
5169
|
velocity;
|
|
5153
5170
|
zIndexFactor;
|
|
5154
|
-
|
|
5171
|
+
#cachedOpacityData = {
|
|
5155
5172
|
fillOpacity: defaultOpacity$1,
|
|
5156
5173
|
opacity: defaultOpacity$1,
|
|
5157
5174
|
strokeOpacity: defaultOpacity$1,
|
|
5158
5175
|
};
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5176
|
+
#cachedPosition = Vector3d.origin;
|
|
5177
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5178
|
+
#cachedTransform = {
|
|
5162
5179
|
a: 1,
|
|
5163
5180
|
b: 0,
|
|
5164
5181
|
c: 0,
|
|
5165
5182
|
d: 1,
|
|
5166
5183
|
};
|
|
5167
|
-
|
|
5168
|
-
|
|
5184
|
+
#container;
|
|
5185
|
+
#pluginManager;
|
|
5169
5186
|
constructor(pluginManager, container) {
|
|
5170
|
-
this
|
|
5171
|
-
this
|
|
5187
|
+
this.#pluginManager = pluginManager;
|
|
5188
|
+
this.#container = container;
|
|
5172
5189
|
}
|
|
5173
5190
|
destroy(override) {
|
|
5174
5191
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5177,7 +5194,7 @@
|
|
|
5177
5194
|
this.destroyed = true;
|
|
5178
5195
|
this.bubble.inRange = false;
|
|
5179
5196
|
this.slow.inRange = false;
|
|
5180
|
-
const container = this
|
|
5197
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5181
5198
|
shapeDrawer?.particleDestroy?.(this);
|
|
5182
5199
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5183
5200
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5185,12 +5202,12 @@
|
|
|
5185
5202
|
for (const updater of container.particleUpdaters) {
|
|
5186
5203
|
updater.particleDestroyed?.(this, override);
|
|
5187
5204
|
}
|
|
5188
|
-
this.
|
|
5205
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5189
5206
|
particle: this,
|
|
5190
5207
|
});
|
|
5191
5208
|
}
|
|
5192
5209
|
draw(delta) {
|
|
5193
|
-
const container = this
|
|
5210
|
+
const container = this.#container, render = container.canvas.render;
|
|
5194
5211
|
render.drawParticlePlugins(this, delta);
|
|
5195
5212
|
render.drawParticle(this, delta);
|
|
5196
5213
|
}
|
|
@@ -5198,50 +5215,50 @@
|
|
|
5198
5215
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5199
5216
|
}
|
|
5200
5217
|
getFillColor() {
|
|
5201
|
-
return this
|
|
5218
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5202
5219
|
}
|
|
5203
5220
|
getMass() {
|
|
5204
5221
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5205
5222
|
}
|
|
5206
5223
|
getOpacity() {
|
|
5207
5224
|
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;
|
|
5208
|
-
this.
|
|
5209
|
-
this.
|
|
5210
|
-
this.
|
|
5211
|
-
return this
|
|
5225
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5226
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5227
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5228
|
+
return this.#cachedOpacityData;
|
|
5212
5229
|
}
|
|
5213
5230
|
getPosition() {
|
|
5214
|
-
this.
|
|
5215
|
-
this.
|
|
5216
|
-
this.
|
|
5217
|
-
return this
|
|
5231
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5232
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5233
|
+
this.#cachedPosition.z = this.position.z;
|
|
5234
|
+
return this.#cachedPosition;
|
|
5218
5235
|
}
|
|
5219
5236
|
getRadius() {
|
|
5220
5237
|
return this.bubble.radius ?? this.size.value;
|
|
5221
5238
|
}
|
|
5222
5239
|
getRotateData() {
|
|
5223
5240
|
const angle = this.getAngle();
|
|
5224
|
-
this.
|
|
5225
|
-
this.
|
|
5226
|
-
return this
|
|
5241
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5242
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5243
|
+
return this.#cachedRotateData;
|
|
5227
5244
|
}
|
|
5228
5245
|
getStrokeColor() {
|
|
5229
|
-
return this
|
|
5246
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5230
5247
|
}
|
|
5231
5248
|
getTransformData(externalTransform) {
|
|
5232
5249
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5233
|
-
this.
|
|
5234
|
-
this.
|
|
5250
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5251
|
+
this.#cachedTransform.b = rotating
|
|
5235
5252
|
? rotateData.sin * (externalTransform.b ?? identity$2)
|
|
5236
5253
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5237
|
-
this.
|
|
5254
|
+
this.#cachedTransform.c = rotating
|
|
5238
5255
|
? -rotateData.sin * (externalTransform.c ?? identity$2)
|
|
5239
5256
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5240
|
-
this.
|
|
5241
|
-
return this
|
|
5257
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5258
|
+
return this.#cachedTransform;
|
|
5242
5259
|
}
|
|
5243
5260
|
init(id, position, overrideOptions, group) {
|
|
5244
|
-
const container = this
|
|
5261
|
+
const container = this.#container;
|
|
5245
5262
|
this.id = id;
|
|
5246
5263
|
this.group = group;
|
|
5247
5264
|
this.justWarped = false;
|
|
@@ -5261,21 +5278,27 @@
|
|
|
5261
5278
|
moveSpeed: 0,
|
|
5262
5279
|
sizeAnimationSpeed: 0,
|
|
5263
5280
|
};
|
|
5281
|
+
this.size = {
|
|
5282
|
+
value: 1,
|
|
5283
|
+
max: 1,
|
|
5284
|
+
min: 1,
|
|
5285
|
+
enable: false,
|
|
5286
|
+
};
|
|
5264
5287
|
this.outType = ParticleOutType.normal;
|
|
5265
5288
|
this.ignoresResizeRatio = true;
|
|
5266
|
-
const
|
|
5289
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5267
5290
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5268
5291
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5269
5292
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5270
5293
|
if (overrideOptions) {
|
|
5271
|
-
if (overrideOptions.effect?.type) {
|
|
5294
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5272
5295
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5273
5296
|
if (effect) {
|
|
5274
5297
|
this.effect = effect;
|
|
5275
5298
|
effectOptions.load(overrideOptions.effect);
|
|
5276
5299
|
}
|
|
5277
5300
|
}
|
|
5278
|
-
if (overrideOptions.shape?.type) {
|
|
5301
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5279
5302
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5280
5303
|
if (shape) {
|
|
5281
5304
|
this.shape = shape;
|
|
@@ -5284,21 +5307,20 @@
|
|
|
5284
5307
|
}
|
|
5285
5308
|
}
|
|
5286
5309
|
if (this.effect === randomColorValue) {
|
|
5287
|
-
const availableEffects = [...this.
|
|
5310
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5288
5311
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5289
5312
|
}
|
|
5290
5313
|
if (this.shape === randomColorValue) {
|
|
5291
|
-
const availableShapes = [...this.
|
|
5314
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5292
5315
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5293
5316
|
}
|
|
5294
5317
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5295
5318
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5296
5319
|
particlesOptions.load(overrideOptions);
|
|
5297
|
-
const effectData = this.effectData;
|
|
5320
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5298
5321
|
if (effectData) {
|
|
5299
5322
|
particlesOptions.load(effectData.particles);
|
|
5300
5323
|
}
|
|
5301
|
-
const shapeData = this.shapeData;
|
|
5302
5324
|
if (shapeData) {
|
|
5303
5325
|
particlesOptions.load(shapeData.particles);
|
|
5304
5326
|
}
|
|
@@ -5306,7 +5328,9 @@
|
|
|
5306
5328
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5307
5329
|
this.options = particlesOptions;
|
|
5308
5330
|
container.retina.initParticle(this);
|
|
5309
|
-
|
|
5331
|
+
for (const updater of container.particleUpdaters) {
|
|
5332
|
+
updater.preInit?.(this);
|
|
5333
|
+
}
|
|
5310
5334
|
this.bubble = {
|
|
5311
5335
|
inRange: false,
|
|
5312
5336
|
};
|
|
@@ -5314,8 +5338,8 @@
|
|
|
5314
5338
|
inRange: false,
|
|
5315
5339
|
factor: 1,
|
|
5316
5340
|
};
|
|
5317
|
-
this
|
|
5318
|
-
this.initialVelocity = this
|
|
5341
|
+
this.#initPosition(position);
|
|
5342
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5319
5343
|
this.velocity = this.initialVelocity.copy();
|
|
5320
5344
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5321
5345
|
this.sides = 24;
|
|
@@ -5346,12 +5370,11 @@
|
|
|
5346
5370
|
plugin.particleCreated?.(this);
|
|
5347
5371
|
}
|
|
5348
5372
|
}
|
|
5349
|
-
isInsideCanvas() {
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
position.x <= canvasSize.width + radius);
|
|
5373
|
+
isInsideCanvas(direction) {
|
|
5374
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5375
|
+
}
|
|
5376
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5377
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5355
5378
|
}
|
|
5356
5379
|
isShowingBack() {
|
|
5357
5380
|
if (!this.roll) {
|
|
@@ -5376,13 +5399,13 @@
|
|
|
5376
5399
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5377
5400
|
}
|
|
5378
5401
|
reset() {
|
|
5379
|
-
for (const updater of this.
|
|
5402
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5380
5403
|
updater.reset?.(this);
|
|
5381
5404
|
}
|
|
5382
5405
|
}
|
|
5383
|
-
|
|
5406
|
+
#calcPosition = (position, zIndex) => {
|
|
5384
5407
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5385
|
-
const container = this
|
|
5408
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5386
5409
|
while (!signal.aborted) {
|
|
5387
5410
|
for (const plugin of plugins) {
|
|
5388
5411
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5394,10 +5417,10 @@
|
|
|
5394
5417
|
size: canvasSize,
|
|
5395
5418
|
position: posVec,
|
|
5396
5419
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5397
|
-
this
|
|
5398
|
-
this
|
|
5399
|
-
this
|
|
5400
|
-
this
|
|
5420
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5421
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5422
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5423
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5401
5424
|
let isValidPosition = true;
|
|
5402
5425
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5403
5426
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5413,8 +5436,8 @@
|
|
|
5413
5436
|
}
|
|
5414
5437
|
return posVec;
|
|
5415
5438
|
};
|
|
5416
|
-
|
|
5417
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5439
|
+
#calculateVelocity = () => {
|
|
5440
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5418
5441
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5419
5442
|
return res;
|
|
5420
5443
|
}
|
|
@@ -5430,27 +5453,86 @@
|
|
|
5430
5453
|
}
|
|
5431
5454
|
return res;
|
|
5432
5455
|
};
|
|
5433
|
-
|
|
5456
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5434
5457
|
fixOutMode({
|
|
5435
5458
|
outMode,
|
|
5436
5459
|
checkModes: [OutMode.bounce],
|
|
5437
5460
|
coord: pos.x,
|
|
5438
|
-
maxCoord: this.
|
|
5461
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5439
5462
|
setCb: (value) => (pos.x += value),
|
|
5440
5463
|
radius,
|
|
5441
5464
|
});
|
|
5442
5465
|
};
|
|
5443
|
-
|
|
5466
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5444
5467
|
fixOutMode({
|
|
5445
5468
|
outMode,
|
|
5446
5469
|
checkModes: [OutMode.bounce],
|
|
5447
5470
|
coord: pos.y,
|
|
5448
|
-
maxCoord: this.
|
|
5471
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5449
5472
|
setCb: (value) => (pos.y += value),
|
|
5450
5473
|
radius,
|
|
5451
5474
|
});
|
|
5452
5475
|
};
|
|
5453
|
-
|
|
5476
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5477
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
5478
|
+
if (direction === OutModeDirection.bottom) {
|
|
5479
|
+
return {
|
|
5480
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5481
|
+
reason: "default",
|
|
5482
|
+
};
|
|
5483
|
+
}
|
|
5484
|
+
if (direction === OutModeDirection.left) {
|
|
5485
|
+
return {
|
|
5486
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5487
|
+
reason: "default",
|
|
5488
|
+
};
|
|
5489
|
+
}
|
|
5490
|
+
if (direction === OutModeDirection.right) {
|
|
5491
|
+
return {
|
|
5492
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5493
|
+
reason: "default",
|
|
5494
|
+
};
|
|
5495
|
+
}
|
|
5496
|
+
if (direction === OutModeDirection.top) {
|
|
5497
|
+
return {
|
|
5498
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5499
|
+
reason: "default",
|
|
5500
|
+
};
|
|
5501
|
+
}
|
|
5502
|
+
return {
|
|
5503
|
+
inside: position.x >= -radius &&
|
|
5504
|
+
position.y >= -radius &&
|
|
5505
|
+
position.y <= canvasSize.height + radius &&
|
|
5506
|
+
position.x <= canvasSize.width + radius,
|
|
5507
|
+
reason: "default",
|
|
5508
|
+
};
|
|
5509
|
+
};
|
|
5510
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5511
|
+
return {
|
|
5512
|
+
canvasSize: this.#container.canvas.size,
|
|
5513
|
+
direction,
|
|
5514
|
+
outMode,
|
|
5515
|
+
particle: this,
|
|
5516
|
+
radius: this.getRadius(),
|
|
5517
|
+
};
|
|
5518
|
+
};
|
|
5519
|
+
#getInsideCanvasResult = (data) => {
|
|
5520
|
+
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;
|
|
5521
|
+
if (!shapeCheck && !effectCheck) {
|
|
5522
|
+
return defaultResult;
|
|
5523
|
+
}
|
|
5524
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5525
|
+
if (shapeResult && effectResult) {
|
|
5526
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5527
|
+
return {
|
|
5528
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5529
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5530
|
+
reason: "combined",
|
|
5531
|
+
};
|
|
5532
|
+
}
|
|
5533
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5534
|
+
};
|
|
5535
|
+
#getRollColor = color => {
|
|
5454
5536
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5455
5537
|
return color;
|
|
5456
5538
|
}
|
|
@@ -5465,8 +5547,8 @@
|
|
|
5465
5547
|
}
|
|
5466
5548
|
return color;
|
|
5467
5549
|
};
|
|
5468
|
-
|
|
5469
|
-
const container = this
|
|
5550
|
+
#initPosition = position => {
|
|
5551
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5470
5552
|
if (!initialPosition) {
|
|
5471
5553
|
throw new Error("a valid position cannot be found for particle");
|
|
5472
5554
|
}
|
|
@@ -5489,45 +5571,58 @@
|
|
|
5489
5571
|
}
|
|
5490
5572
|
this.offset = Vector.origin;
|
|
5491
5573
|
};
|
|
5574
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5575
|
+
if (typeof result === "boolean") {
|
|
5576
|
+
return {
|
|
5577
|
+
inside: result,
|
|
5578
|
+
reason,
|
|
5579
|
+
};
|
|
5580
|
+
}
|
|
5581
|
+
return {
|
|
5582
|
+
inside: result.inside,
|
|
5583
|
+
margin: result.margin,
|
|
5584
|
+
reason: result.reason ?? reason,
|
|
5585
|
+
};
|
|
5586
|
+
};
|
|
5492
5587
|
}
|
|
5493
5588
|
|
|
5494
5589
|
class SpatialHashGrid {
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5590
|
+
#cellSize;
|
|
5591
|
+
#cells = new Map();
|
|
5592
|
+
#circlePool = [];
|
|
5593
|
+
#circlePoolIdx;
|
|
5594
|
+
#pendingCellSize;
|
|
5595
|
+
#rectanglePool = [];
|
|
5596
|
+
#rectanglePoolIdx;
|
|
5502
5597
|
constructor(cellSize) {
|
|
5503
|
-
this
|
|
5504
|
-
this
|
|
5505
|
-
this
|
|
5598
|
+
this.#cellSize = cellSize;
|
|
5599
|
+
this.#circlePoolIdx = 0;
|
|
5600
|
+
this.#rectanglePoolIdx = 0;
|
|
5506
5601
|
}
|
|
5507
5602
|
clear() {
|
|
5508
|
-
this.
|
|
5509
|
-
const pendingCellSize = this
|
|
5603
|
+
this.#cells.clear();
|
|
5604
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5510
5605
|
if (pendingCellSize) {
|
|
5511
|
-
this
|
|
5606
|
+
this.#cellSize = pendingCellSize;
|
|
5512
5607
|
}
|
|
5513
|
-
this
|
|
5608
|
+
this.#pendingCellSize = undefined;
|
|
5514
5609
|
}
|
|
5515
5610
|
insert(particle) {
|
|
5516
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5517
|
-
if (!this.
|
|
5518
|
-
this.
|
|
5611
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5612
|
+
if (!this.#cells.has(key)) {
|
|
5613
|
+
this.#cells.set(key, []);
|
|
5519
5614
|
}
|
|
5520
|
-
this.
|
|
5615
|
+
this.#cells.get(key)?.push(particle);
|
|
5521
5616
|
}
|
|
5522
5617
|
query(range, check, out = []) {
|
|
5523
|
-
const bounds = this
|
|
5618
|
+
const bounds = this.#getRangeBounds(range);
|
|
5524
5619
|
if (!bounds) {
|
|
5525
5620
|
return out;
|
|
5526
5621
|
}
|
|
5527
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5622
|
+
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);
|
|
5528
5623
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5529
5624
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5530
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
5625
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5531
5626
|
if (!cellParticles) {
|
|
5532
5627
|
continue;
|
|
5533
5628
|
}
|
|
@@ -5544,29 +5639,29 @@
|
|
|
5544
5639
|
return out;
|
|
5545
5640
|
}
|
|
5546
5641
|
queryCircle(position, radius, check, out = []) {
|
|
5547
|
-
const circle = this
|
|
5548
|
-
this
|
|
5642
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
5643
|
+
this.#releaseShapes();
|
|
5549
5644
|
return result;
|
|
5550
5645
|
}
|
|
5551
5646
|
queryRectangle(position, size, check, out = []) {
|
|
5552
|
-
const rect = this
|
|
5553
|
-
this
|
|
5647
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
5648
|
+
this.#releaseShapes();
|
|
5554
5649
|
return result;
|
|
5555
5650
|
}
|
|
5556
5651
|
setCellSize(cellSize) {
|
|
5557
|
-
this
|
|
5652
|
+
this.#pendingCellSize = cellSize;
|
|
5558
5653
|
}
|
|
5559
|
-
|
|
5560
|
-
return (this
|
|
5654
|
+
#acquireCircle(x, y, r) {
|
|
5655
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5561
5656
|
}
|
|
5562
|
-
|
|
5563
|
-
return (this
|
|
5657
|
+
#acquireRectangle(x, y, w, h) {
|
|
5658
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5564
5659
|
}
|
|
5565
|
-
|
|
5566
|
-
const cellX = Math.floor(x / this
|
|
5660
|
+
#cellKeyFromCoords(x, y) {
|
|
5661
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5567
5662
|
return `${cellX}_${cellY}`;
|
|
5568
5663
|
}
|
|
5569
|
-
|
|
5664
|
+
#getRangeBounds(range) {
|
|
5570
5665
|
if (range instanceof Circle) {
|
|
5571
5666
|
const r = range.radius, { x, y } = range.position;
|
|
5572
5667
|
return {
|
|
@@ -5587,53 +5682,53 @@
|
|
|
5587
5682
|
}
|
|
5588
5683
|
return null;
|
|
5589
5684
|
}
|
|
5590
|
-
|
|
5591
|
-
this
|
|
5592
|
-
this
|
|
5685
|
+
#releaseShapes() {
|
|
5686
|
+
this.#circlePoolIdx = 0;
|
|
5687
|
+
this.#rectanglePoolIdx = 0;
|
|
5593
5688
|
}
|
|
5594
5689
|
}
|
|
5595
5690
|
|
|
5596
5691
|
class ParticlesManager {
|
|
5597
5692
|
checkParticlePositionPlugins;
|
|
5598
5693
|
grid;
|
|
5599
|
-
|
|
5600
|
-
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
|
|
5605
|
-
|
|
5606
|
-
|
|
5607
|
-
|
|
5608
|
-
|
|
5609
|
-
|
|
5610
|
-
|
|
5611
|
-
|
|
5612
|
-
|
|
5613
|
-
|
|
5694
|
+
#array;
|
|
5695
|
+
#container;
|
|
5696
|
+
#groupLimits;
|
|
5697
|
+
#limit;
|
|
5698
|
+
#nextId;
|
|
5699
|
+
#particleBuckets;
|
|
5700
|
+
#particleResetPlugins;
|
|
5701
|
+
#particleUpdatePlugins;
|
|
5702
|
+
#pluginManager;
|
|
5703
|
+
#pool;
|
|
5704
|
+
#postParticleUpdatePlugins;
|
|
5705
|
+
#postUpdatePlugins;
|
|
5706
|
+
#resizeFactor;
|
|
5707
|
+
#updatePlugins;
|
|
5708
|
+
#zBuckets;
|
|
5614
5709
|
constructor(pluginManager, container) {
|
|
5615
|
-
this
|
|
5616
|
-
this
|
|
5617
|
-
this
|
|
5618
|
-
this
|
|
5619
|
-
this
|
|
5620
|
-
this
|
|
5621
|
-
this
|
|
5622
|
-
this
|
|
5623
|
-
this
|
|
5710
|
+
this.#pluginManager = pluginManager;
|
|
5711
|
+
this.#container = container;
|
|
5712
|
+
this.#nextId = 0;
|
|
5713
|
+
this.#array = [];
|
|
5714
|
+
this.#pool = [];
|
|
5715
|
+
this.#limit = 0;
|
|
5716
|
+
this.#groupLimits = new Map();
|
|
5717
|
+
this.#particleBuckets = new Map();
|
|
5718
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5624
5719
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5625
5720
|
this.checkParticlePositionPlugins = [];
|
|
5626
|
-
this
|
|
5627
|
-
this
|
|
5628
|
-
this
|
|
5629
|
-
this
|
|
5630
|
-
this
|
|
5721
|
+
this.#particleResetPlugins = [];
|
|
5722
|
+
this.#particleUpdatePlugins = [];
|
|
5723
|
+
this.#postUpdatePlugins = [];
|
|
5724
|
+
this.#postParticleUpdatePlugins = [];
|
|
5725
|
+
this.#updatePlugins = [];
|
|
5631
5726
|
}
|
|
5632
5727
|
get count() {
|
|
5633
|
-
return this.
|
|
5728
|
+
return this.#array.length;
|
|
5634
5729
|
}
|
|
5635
5730
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5636
|
-
const limitMode = this.
|
|
5731
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
5637
5732
|
if (limit > minLimit) {
|
|
5638
5733
|
switch (limitMode) {
|
|
5639
5734
|
case LimitMode.delete: {
|
|
@@ -5651,20 +5746,20 @@
|
|
|
5651
5746
|
}
|
|
5652
5747
|
}
|
|
5653
5748
|
try {
|
|
5654
|
-
const particle = this.
|
|
5655
|
-
particle.init(this
|
|
5749
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
5750
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
5656
5751
|
let canAdd = true;
|
|
5657
5752
|
if (initializer) {
|
|
5658
5753
|
canAdd = initializer(particle);
|
|
5659
5754
|
}
|
|
5660
5755
|
if (!canAdd) {
|
|
5661
|
-
this.
|
|
5756
|
+
this.#pool.push(particle);
|
|
5662
5757
|
return;
|
|
5663
5758
|
}
|
|
5664
|
-
this.
|
|
5665
|
-
this
|
|
5666
|
-
this
|
|
5667
|
-
this.
|
|
5759
|
+
this.#array.push(particle);
|
|
5760
|
+
this.#insertParticleIntoBucket(particle);
|
|
5761
|
+
this.#nextId++;
|
|
5762
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
5668
5763
|
particle,
|
|
5669
5764
|
});
|
|
5670
5765
|
return particle;
|
|
@@ -5675,25 +5770,25 @@
|
|
|
5675
5770
|
return undefined;
|
|
5676
5771
|
}
|
|
5677
5772
|
clear() {
|
|
5678
|
-
this
|
|
5679
|
-
this.
|
|
5680
|
-
this
|
|
5773
|
+
this.#array = [];
|
|
5774
|
+
this.#particleBuckets.clear();
|
|
5775
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
5681
5776
|
}
|
|
5682
5777
|
destroy() {
|
|
5683
|
-
this
|
|
5684
|
-
this.
|
|
5685
|
-
this.
|
|
5686
|
-
this
|
|
5778
|
+
this.#array = [];
|
|
5779
|
+
this.#pool.length = 0;
|
|
5780
|
+
this.#particleBuckets.clear();
|
|
5781
|
+
this.#zBuckets = [];
|
|
5687
5782
|
this.checkParticlePositionPlugins = [];
|
|
5688
|
-
this
|
|
5689
|
-
this
|
|
5690
|
-
this
|
|
5691
|
-
this
|
|
5692
|
-
this
|
|
5783
|
+
this.#particleResetPlugins = [];
|
|
5784
|
+
this.#particleUpdatePlugins = [];
|
|
5785
|
+
this.#postUpdatePlugins = [];
|
|
5786
|
+
this.#postParticleUpdatePlugins = [];
|
|
5787
|
+
this.#updatePlugins = [];
|
|
5693
5788
|
}
|
|
5694
5789
|
drawParticles(delta) {
|
|
5695
|
-
for (let i = this.
|
|
5696
|
-
const bucket = this
|
|
5790
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
5791
|
+
const bucket = this.#zBuckets[i];
|
|
5697
5792
|
if (!bucket) {
|
|
5698
5793
|
continue;
|
|
5699
5794
|
}
|
|
@@ -5703,24 +5798,24 @@
|
|
|
5703
5798
|
}
|
|
5704
5799
|
}
|
|
5705
5800
|
filter(condition) {
|
|
5706
|
-
return this.
|
|
5801
|
+
return this.#array.filter(condition);
|
|
5707
5802
|
}
|
|
5708
5803
|
find(condition) {
|
|
5709
|
-
return this.
|
|
5804
|
+
return this.#array.find(condition);
|
|
5710
5805
|
}
|
|
5711
5806
|
get(index) {
|
|
5712
|
-
return this
|
|
5807
|
+
return this.#array[index];
|
|
5713
5808
|
}
|
|
5714
5809
|
async init() {
|
|
5715
|
-
const container = this
|
|
5810
|
+
const container = this.#container, options = container.actualOptions;
|
|
5716
5811
|
this.checkParticlePositionPlugins = [];
|
|
5717
|
-
this
|
|
5718
|
-
this
|
|
5719
|
-
this
|
|
5720
|
-
this
|
|
5721
|
-
this
|
|
5722
|
-
this.
|
|
5723
|
-
this
|
|
5812
|
+
this.#updatePlugins = [];
|
|
5813
|
+
this.#particleUpdatePlugins = [];
|
|
5814
|
+
this.#postUpdatePlugins = [];
|
|
5815
|
+
this.#particleResetPlugins = [];
|
|
5816
|
+
this.#postParticleUpdatePlugins = [];
|
|
5817
|
+
this.#particleBuckets.clear();
|
|
5818
|
+
this.#resetBuckets(container.zLayers);
|
|
5724
5819
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5725
5820
|
for (const plugin of container.plugins) {
|
|
5726
5821
|
if (plugin.redrawInit) {
|
|
@@ -5730,26 +5825,26 @@
|
|
|
5730
5825
|
this.checkParticlePositionPlugins.push(plugin);
|
|
5731
5826
|
}
|
|
5732
5827
|
if (plugin.update) {
|
|
5733
|
-
this.
|
|
5828
|
+
this.#updatePlugins.push(plugin);
|
|
5734
5829
|
}
|
|
5735
5830
|
if (plugin.particleUpdate) {
|
|
5736
|
-
this.
|
|
5831
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5737
5832
|
}
|
|
5738
5833
|
if (plugin.postUpdate) {
|
|
5739
|
-
this.
|
|
5834
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5740
5835
|
}
|
|
5741
5836
|
if (plugin.particleReset) {
|
|
5742
|
-
this.
|
|
5837
|
+
this.#particleResetPlugins.push(plugin);
|
|
5743
5838
|
}
|
|
5744
5839
|
if (plugin.postParticleUpdate) {
|
|
5745
|
-
this.
|
|
5840
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5746
5841
|
}
|
|
5747
5842
|
}
|
|
5748
|
-
await this.
|
|
5749
|
-
for (const drawer of this.
|
|
5843
|
+
await this.#container.initDrawersAndUpdaters();
|
|
5844
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5750
5845
|
await drawer.init?.(container);
|
|
5751
5846
|
}
|
|
5752
|
-
for (const drawer of this.
|
|
5847
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5753
5848
|
await drawer.init?.(container);
|
|
5754
5849
|
}
|
|
5755
5850
|
let handled = false;
|
|
@@ -5783,10 +5878,10 @@
|
|
|
5783
5878
|
async redraw() {
|
|
5784
5879
|
this.clear();
|
|
5785
5880
|
await this.init();
|
|
5786
|
-
this.
|
|
5881
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
5787
5882
|
}
|
|
5788
5883
|
remove(particle, group, override) {
|
|
5789
|
-
this.removeAt(this.
|
|
5884
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5790
5885
|
}
|
|
5791
5886
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5792
5887
|
if (index < minIndex || index > this.count) {
|
|
@@ -5794,7 +5889,7 @@
|
|
|
5794
5889
|
}
|
|
5795
5890
|
let deleted = 0;
|
|
5796
5891
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5797
|
-
if (this
|
|
5892
|
+
if (this.#removeParticle(i, group, override)) {
|
|
5798
5893
|
i--;
|
|
5799
5894
|
deleted++;
|
|
5800
5895
|
}
|
|
@@ -5804,9 +5899,9 @@
|
|
|
5804
5899
|
this.removeAt(minIndex, quantity, group);
|
|
5805
5900
|
}
|
|
5806
5901
|
setDensity() {
|
|
5807
|
-
const options = this.
|
|
5902
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
5808
5903
|
let pluginsCount = 0;
|
|
5809
|
-
for (const plugin of this.
|
|
5904
|
+
for (const plugin of this.#container.plugins) {
|
|
5810
5905
|
if (plugin.particlesDensityCount) {
|
|
5811
5906
|
pluginsCount += plugin.particlesDensityCount();
|
|
5812
5907
|
}
|
|
@@ -5816,51 +5911,51 @@
|
|
|
5816
5911
|
if (!groupData) {
|
|
5817
5912
|
continue;
|
|
5818
5913
|
}
|
|
5819
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
5820
|
-
this
|
|
5914
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
5915
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
5821
5916
|
}
|
|
5822
|
-
this
|
|
5917
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
5823
5918
|
}
|
|
5824
5919
|
setResizeFactor(factor) {
|
|
5825
|
-
this
|
|
5920
|
+
this.#resizeFactor = factor;
|
|
5826
5921
|
}
|
|
5827
5922
|
update(delta) {
|
|
5828
5923
|
this.grid.clear();
|
|
5829
|
-
for (const plugin of this
|
|
5924
|
+
for (const plugin of this.#updatePlugins) {
|
|
5830
5925
|
plugin.update?.(delta);
|
|
5831
5926
|
}
|
|
5832
|
-
const particlesToDelete = this
|
|
5833
|
-
for (const plugin of this
|
|
5927
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
5928
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
5834
5929
|
plugin.postUpdate?.(delta);
|
|
5835
5930
|
}
|
|
5836
|
-
this
|
|
5931
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5837
5932
|
if (particlesToDelete.size) {
|
|
5838
5933
|
for (const particle of particlesToDelete) {
|
|
5839
5934
|
this.remove(particle);
|
|
5840
5935
|
}
|
|
5841
5936
|
}
|
|
5842
|
-
|
|
5937
|
+
this.#resizeFactor = undefined;
|
|
5843
5938
|
}
|
|
5844
|
-
|
|
5845
|
-
this.
|
|
5939
|
+
#addToPool = (...particles) => {
|
|
5940
|
+
this.#pool.push(...particles);
|
|
5846
5941
|
};
|
|
5847
|
-
|
|
5942
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
5848
5943
|
const numberOptions = options.number;
|
|
5849
5944
|
if (!numberOptions.density.enable) {
|
|
5850
5945
|
if (group === undefined) {
|
|
5851
|
-
this
|
|
5946
|
+
this.#limit = numberOptions.limit.value;
|
|
5852
5947
|
}
|
|
5853
5948
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5854
|
-
this.
|
|
5949
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5855
5950
|
}
|
|
5856
5951
|
return;
|
|
5857
5952
|
}
|
|
5858
|
-
const densityFactor = this
|
|
5953
|
+
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);
|
|
5859
5954
|
if (group === undefined) {
|
|
5860
|
-
this
|
|
5955
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5861
5956
|
}
|
|
5862
5957
|
else {
|
|
5863
|
-
this.
|
|
5958
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
5864
5959
|
}
|
|
5865
5960
|
if (particlesCount < particlesNumber) {
|
|
5866
5961
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5869,18 +5964,18 @@
|
|
|
5869
5964
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5870
5965
|
}
|
|
5871
5966
|
};
|
|
5872
|
-
|
|
5967
|
+
#createBuckets = (zLayers) => {
|
|
5873
5968
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5874
5969
|
return Array.from({ length: bucketCount }, () => []);
|
|
5875
5970
|
};
|
|
5876
|
-
|
|
5877
|
-
const maxBucketIndex = this.
|
|
5971
|
+
#getBucketIndex = (zIndex) => {
|
|
5972
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
5878
5973
|
if (maxBucketIndex <= minIndex) {
|
|
5879
5974
|
return minIndex;
|
|
5880
5975
|
}
|
|
5881
5976
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
5882
5977
|
};
|
|
5883
|
-
|
|
5978
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
5884
5979
|
let start = minIndex, end = bucket.length;
|
|
5885
5980
|
while (start < end) {
|
|
5886
5981
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -5897,8 +5992,8 @@
|
|
|
5897
5992
|
}
|
|
5898
5993
|
return start;
|
|
5899
5994
|
};
|
|
5900
|
-
|
|
5901
|
-
const container = this
|
|
5995
|
+
#initDensityFactor = densityOptions => {
|
|
5996
|
+
const container = this.#container;
|
|
5902
5997
|
if (!densityOptions.enable) {
|
|
5903
5998
|
return defaultDensityFactor;
|
|
5904
5999
|
}
|
|
@@ -5908,82 +6003,82 @@
|
|
|
5908
6003
|
}
|
|
5909
6004
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5910
6005
|
};
|
|
5911
|
-
|
|
5912
|
-
const bucketIndex = this
|
|
6006
|
+
#insertParticleIntoBucket = (particle) => {
|
|
6007
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5913
6008
|
if (!bucket) {
|
|
5914
6009
|
return;
|
|
5915
6010
|
}
|
|
5916
|
-
bucket.splice(this
|
|
5917
|
-
this.
|
|
6011
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
6012
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5918
6013
|
};
|
|
5919
|
-
|
|
5920
|
-
const particle = this
|
|
6014
|
+
#removeParticle = (index, group, override) => {
|
|
6015
|
+
const particle = this.#array[index];
|
|
5921
6016
|
if (!particle) {
|
|
5922
6017
|
return false;
|
|
5923
6018
|
}
|
|
5924
6019
|
if (particle.group !== group) {
|
|
5925
6020
|
return false;
|
|
5926
6021
|
}
|
|
5927
|
-
this.
|
|
5928
|
-
this
|
|
6022
|
+
this.#array.splice(index, deleteCount);
|
|
6023
|
+
this.#removeParticleFromBucket(particle);
|
|
5929
6024
|
particle.destroy(override);
|
|
5930
|
-
this.
|
|
6025
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
5931
6026
|
particle,
|
|
5932
6027
|
});
|
|
5933
|
-
this
|
|
6028
|
+
this.#addToPool(particle);
|
|
5934
6029
|
return true;
|
|
5935
6030
|
};
|
|
5936
|
-
|
|
5937
|
-
const bucketIndex = this.
|
|
6031
|
+
#removeParticleFromBucket = (particle) => {
|
|
6032
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5938
6033
|
if (!bucket) {
|
|
5939
|
-
this.
|
|
6034
|
+
this.#particleBuckets.delete(particle.id);
|
|
5940
6035
|
return;
|
|
5941
6036
|
}
|
|
5942
|
-
const particleIndex = this
|
|
6037
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
5943
6038
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
5944
|
-
this.
|
|
6039
|
+
this.#particleBuckets.delete(particle.id);
|
|
5945
6040
|
return;
|
|
5946
6041
|
}
|
|
5947
6042
|
bucket.splice(particleIndex, deleteCount);
|
|
5948
|
-
this.
|
|
6043
|
+
this.#particleBuckets.delete(particle.id);
|
|
5949
6044
|
};
|
|
5950
|
-
|
|
6045
|
+
#resetBuckets = (zLayers) => {
|
|
5951
6046
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5952
|
-
if (this.
|
|
5953
|
-
this
|
|
6047
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6048
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
5954
6049
|
return;
|
|
5955
6050
|
}
|
|
5956
|
-
for (const bucket of this
|
|
6051
|
+
for (const bucket of this.#zBuckets) {
|
|
5957
6052
|
bucket.length = minIndex;
|
|
5958
6053
|
}
|
|
5959
6054
|
};
|
|
5960
|
-
|
|
5961
|
-
const newBucketIndex = this
|
|
6055
|
+
#updateParticleBucket = (particle) => {
|
|
6056
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
5962
6057
|
if (currentBucketIndex === undefined) {
|
|
5963
|
-
this
|
|
6058
|
+
this.#insertParticleIntoBucket(particle);
|
|
5964
6059
|
return;
|
|
5965
6060
|
}
|
|
5966
6061
|
if (currentBucketIndex === newBucketIndex) {
|
|
5967
6062
|
return;
|
|
5968
6063
|
}
|
|
5969
|
-
const currentBucket = this
|
|
6064
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
5970
6065
|
if (currentBucket) {
|
|
5971
|
-
const particleIndex = this
|
|
6066
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
5972
6067
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
5973
6068
|
currentBucket.splice(particleIndex, deleteCount);
|
|
5974
6069
|
}
|
|
5975
6070
|
}
|
|
5976
|
-
const newBucket = this
|
|
6071
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
5977
6072
|
if (!newBucket) {
|
|
5978
|
-
this.
|
|
6073
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5979
6074
|
return;
|
|
5980
6075
|
}
|
|
5981
|
-
newBucket.splice(this
|
|
5982
|
-
this.
|
|
6076
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6077
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
5983
6078
|
};
|
|
5984
|
-
|
|
5985
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
5986
|
-
for (const particle of this
|
|
6079
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6080
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6081
|
+
for (const particle of this.#array) {
|
|
5987
6082
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
5988
6083
|
particle.position.x *= resizeFactor.width;
|
|
5989
6084
|
particle.position.y *= resizeFactor.height;
|
|
@@ -5991,10 +6086,10 @@
|
|
|
5991
6086
|
particle.initialPosition.y *= resizeFactor.height;
|
|
5992
6087
|
}
|
|
5993
6088
|
particle.ignoresResizeRatio = false;
|
|
5994
|
-
for (const plugin of this
|
|
6089
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
5995
6090
|
plugin.particleReset?.(particle);
|
|
5996
6091
|
}
|
|
5997
|
-
for (const plugin of this
|
|
6092
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
5998
6093
|
if (particle.destroyed) {
|
|
5999
6094
|
break;
|
|
6000
6095
|
}
|
|
@@ -6008,36 +6103,36 @@
|
|
|
6008
6103
|
}
|
|
6009
6104
|
return particlesToDelete;
|
|
6010
6105
|
};
|
|
6011
|
-
|
|
6012
|
-
for (const particle of this
|
|
6106
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6107
|
+
for (const particle of this.#array) {
|
|
6013
6108
|
if (particle.destroyed) {
|
|
6014
6109
|
particlesToDelete.add(particle);
|
|
6015
6110
|
continue;
|
|
6016
6111
|
}
|
|
6017
|
-
for (const updater of this.
|
|
6112
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6018
6113
|
updater.update(particle, delta);
|
|
6019
6114
|
}
|
|
6020
6115
|
if (!particle.spawning) {
|
|
6021
|
-
for (const plugin of this
|
|
6116
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
6022
6117
|
plugin.postParticleUpdate?.(particle, delta);
|
|
6023
6118
|
}
|
|
6024
6119
|
}
|
|
6025
|
-
this
|
|
6120
|
+
this.#updateParticleBucket(particle);
|
|
6026
6121
|
}
|
|
6027
6122
|
};
|
|
6028
6123
|
}
|
|
6029
6124
|
|
|
6030
6125
|
class Retina {
|
|
6031
|
-
container;
|
|
6032
6126
|
pixelRatio;
|
|
6033
6127
|
reduceFactor;
|
|
6128
|
+
#container;
|
|
6034
6129
|
constructor(container) {
|
|
6035
|
-
this
|
|
6130
|
+
this.#container = container;
|
|
6036
6131
|
this.pixelRatio = defaultRatio;
|
|
6037
6132
|
this.reduceFactor = defaultReduceFactor;
|
|
6038
6133
|
}
|
|
6039
6134
|
init() {
|
|
6040
|
-
const container = this
|
|
6135
|
+
const container = this.#container, options = container.actualOptions;
|
|
6041
6136
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6042
6137
|
this.reduceFactor = defaultReduceFactor;
|
|
6043
6138
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6051,7 +6146,6 @@
|
|
|
6051
6146
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6052
6147
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6053
6148
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6054
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6055
6149
|
const maxDistance = props.maxDistance;
|
|
6056
6150
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6057
6151
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6089,73 +6183,73 @@
|
|
|
6089
6183
|
shapeDrawers;
|
|
6090
6184
|
started;
|
|
6091
6185
|
zLayers;
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
|
|
6098
|
-
|
|
6099
|
-
|
|
6100
|
-
|
|
6101
|
-
|
|
6102
|
-
|
|
6103
|
-
|
|
6104
|
-
|
|
6105
|
-
|
|
6106
|
-
|
|
6107
|
-
|
|
6108
|
-
|
|
6186
|
+
#delay;
|
|
6187
|
+
#delayTimeout;
|
|
6188
|
+
#delta = { value: 0, factor: 0 };
|
|
6189
|
+
#dispatchCallback;
|
|
6190
|
+
#drawAnimationFrame;
|
|
6191
|
+
#duration;
|
|
6192
|
+
#eventListeners;
|
|
6193
|
+
#firstStart;
|
|
6194
|
+
#initialSourceOptions;
|
|
6195
|
+
#lastFrameTime;
|
|
6196
|
+
#lifeTime;
|
|
6197
|
+
#onDestroy;
|
|
6198
|
+
#options;
|
|
6199
|
+
#paused;
|
|
6200
|
+
#pluginManager;
|
|
6201
|
+
#smooth;
|
|
6202
|
+
#sourceOptions;
|
|
6109
6203
|
constructor(params) {
|
|
6110
6204
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6111
|
-
this
|
|
6112
|
-
this
|
|
6113
|
-
this
|
|
6205
|
+
this.#pluginManager = pluginManager;
|
|
6206
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6207
|
+
this.#onDestroy = onDestroy;
|
|
6114
6208
|
this.id = Symbol(id);
|
|
6115
6209
|
this.fpsLimit = 120;
|
|
6116
6210
|
this.hdr = false;
|
|
6117
|
-
this
|
|
6118
|
-
this
|
|
6119
|
-
this
|
|
6120
|
-
this
|
|
6121
|
-
this
|
|
6211
|
+
this.#smooth = false;
|
|
6212
|
+
this.#delay = 0;
|
|
6213
|
+
this.#duration = 0;
|
|
6214
|
+
this.#lifeTime = 0;
|
|
6215
|
+
this.#firstStart = true;
|
|
6122
6216
|
this.started = false;
|
|
6123
6217
|
this.destroyed = false;
|
|
6124
|
-
this
|
|
6125
|
-
this
|
|
6218
|
+
this.#paused = true;
|
|
6219
|
+
this.#lastFrameTime = 0;
|
|
6126
6220
|
this.zLayers = 100;
|
|
6127
6221
|
this.pageHidden = false;
|
|
6128
|
-
this
|
|
6129
|
-
this
|
|
6222
|
+
this.#sourceOptions = sourceOptions;
|
|
6223
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6130
6224
|
this.effectDrawers = new Map();
|
|
6131
6225
|
this.shapeDrawers = new Map();
|
|
6132
6226
|
this.particleUpdaters = [];
|
|
6133
6227
|
this.retina = new Retina(this);
|
|
6134
|
-
this.canvas = new CanvasManager(this
|
|
6135
|
-
this.particles = new ParticlesManager(this
|
|
6228
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6229
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6136
6230
|
this.plugins = [];
|
|
6137
6231
|
this.particleDestroyedPlugins = [];
|
|
6138
6232
|
this.particleCreatedPlugins = [];
|
|
6139
6233
|
this.particlePositionPlugins = [];
|
|
6140
|
-
this
|
|
6141
|
-
this.actualOptions = loadContainerOptions(this
|
|
6142
|
-
this
|
|
6234
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6235
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6236
|
+
this.#eventListeners = new EventListeners(this);
|
|
6143
6237
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6144
6238
|
}
|
|
6145
6239
|
get animationStatus() {
|
|
6146
|
-
return !this
|
|
6240
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6147
6241
|
}
|
|
6148
6242
|
get options() {
|
|
6149
|
-
return this
|
|
6243
|
+
return this.#options;
|
|
6150
6244
|
}
|
|
6151
6245
|
get sourceOptions() {
|
|
6152
|
-
return this
|
|
6246
|
+
return this.#sourceOptions;
|
|
6153
6247
|
}
|
|
6154
6248
|
addLifeTime(value) {
|
|
6155
|
-
this
|
|
6249
|
+
this.#lifeTime += value;
|
|
6156
6250
|
}
|
|
6157
6251
|
alive() {
|
|
6158
|
-
return !this
|
|
6252
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6159
6253
|
}
|
|
6160
6254
|
destroy(remove = true) {
|
|
6161
6255
|
if (!guardCheck(this)) {
|
|
@@ -6177,13 +6271,13 @@
|
|
|
6177
6271
|
this.shapeDrawers = new Map();
|
|
6178
6272
|
this.particleUpdaters = [];
|
|
6179
6273
|
this.plugins.length = 0;
|
|
6180
|
-
this.
|
|
6274
|
+
this.#pluginManager.clearPlugins(this);
|
|
6181
6275
|
this.destroyed = true;
|
|
6182
|
-
this
|
|
6276
|
+
this.#onDestroy(remove);
|
|
6183
6277
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6184
6278
|
}
|
|
6185
6279
|
dispatchEvent(type, data) {
|
|
6186
|
-
this
|
|
6280
|
+
this.#dispatchCallback(type, {
|
|
6187
6281
|
container: this,
|
|
6188
6282
|
data,
|
|
6189
6283
|
});
|
|
@@ -6193,12 +6287,12 @@
|
|
|
6193
6287
|
return;
|
|
6194
6288
|
}
|
|
6195
6289
|
let refreshTime = force;
|
|
6196
|
-
this
|
|
6290
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6197
6291
|
if (refreshTime) {
|
|
6198
|
-
this
|
|
6292
|
+
this.#lastFrameTime = undefined;
|
|
6199
6293
|
refreshTime = false;
|
|
6200
6294
|
}
|
|
6201
|
-
this
|
|
6295
|
+
this.#nextFrame(timestamp);
|
|
6202
6296
|
});
|
|
6203
6297
|
}
|
|
6204
6298
|
async export(type, options = {}) {
|
|
@@ -6220,7 +6314,7 @@
|
|
|
6220
6314
|
return;
|
|
6221
6315
|
}
|
|
6222
6316
|
const allContainerPlugins = new Map();
|
|
6223
|
-
for (const plugin of this.
|
|
6317
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6224
6318
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6225
6319
|
if (containerPlugin.preInit) {
|
|
6226
6320
|
await containerPlugin.preInit();
|
|
@@ -6228,8 +6322,8 @@
|
|
|
6228
6322
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6229
6323
|
}
|
|
6230
6324
|
await this.initDrawersAndUpdaters();
|
|
6231
|
-
this
|
|
6232
|
-
this.actualOptions = loadContainerOptions(this
|
|
6325
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6326
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6233
6327
|
this.plugins.length = 0;
|
|
6234
6328
|
this.particleDestroyedPlugins.length = 0;
|
|
6235
6329
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6256,11 +6350,11 @@
|
|
|
6256
6350
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6257
6351
|
this.hdr = hdr;
|
|
6258
6352
|
this.zLayers = zLayers;
|
|
6259
|
-
this
|
|
6260
|
-
this
|
|
6261
|
-
this
|
|
6353
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6354
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6355
|
+
this.#lifeTime = 0;
|
|
6262
6356
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6263
|
-
this
|
|
6357
|
+
this.#smooth = smooth;
|
|
6264
6358
|
for (const plugin of this.plugins) {
|
|
6265
6359
|
await plugin.init?.();
|
|
6266
6360
|
}
|
|
@@ -6273,7 +6367,7 @@
|
|
|
6273
6367
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6274
6368
|
}
|
|
6275
6369
|
async initDrawersAndUpdaters() {
|
|
6276
|
-
const pluginManager = this
|
|
6370
|
+
const pluginManager = this.#pluginManager;
|
|
6277
6371
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6278
6372
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6279
6373
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6282,18 +6376,18 @@
|
|
|
6282
6376
|
if (!guardCheck(this)) {
|
|
6283
6377
|
return;
|
|
6284
6378
|
}
|
|
6285
|
-
if (this
|
|
6286
|
-
cancelAnimation(this
|
|
6287
|
-
|
|
6379
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6380
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6381
|
+
this.#drawAnimationFrame = undefined;
|
|
6288
6382
|
}
|
|
6289
|
-
if (this
|
|
6383
|
+
if (this.#paused) {
|
|
6290
6384
|
return;
|
|
6291
6385
|
}
|
|
6292
6386
|
for (const plugin of this.plugins) {
|
|
6293
6387
|
plugin.pause?.();
|
|
6294
6388
|
}
|
|
6295
6389
|
if (!this.pageHidden) {
|
|
6296
|
-
this
|
|
6390
|
+
this.#paused = true;
|
|
6297
6391
|
}
|
|
6298
6392
|
this.dispatchEvent(EventType.containerPaused);
|
|
6299
6393
|
}
|
|
@@ -6301,13 +6395,13 @@
|
|
|
6301
6395
|
if (!guardCheck(this)) {
|
|
6302
6396
|
return;
|
|
6303
6397
|
}
|
|
6304
|
-
const needsUpdate = this
|
|
6305
|
-
if (this
|
|
6306
|
-
this
|
|
6398
|
+
const needsUpdate = this.#paused || force;
|
|
6399
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6400
|
+
this.#firstStart = false;
|
|
6307
6401
|
return;
|
|
6308
6402
|
}
|
|
6309
|
-
if (this
|
|
6310
|
-
this
|
|
6403
|
+
if (this.#paused) {
|
|
6404
|
+
this.#paused = false;
|
|
6311
6405
|
}
|
|
6312
6406
|
if (needsUpdate) {
|
|
6313
6407
|
for (const plugin of this.plugins) {
|
|
@@ -6330,10 +6424,10 @@
|
|
|
6330
6424
|
if (!guardCheck(this)) {
|
|
6331
6425
|
return;
|
|
6332
6426
|
}
|
|
6333
|
-
this
|
|
6334
|
-
this
|
|
6335
|
-
this
|
|
6336
|
-
this.actualOptions = loadContainerOptions(this
|
|
6427
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6428
|
+
this.#sourceOptions = sourceOptions;
|
|
6429
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6430
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6337
6431
|
return this.refresh();
|
|
6338
6432
|
}
|
|
6339
6433
|
async start() {
|
|
@@ -6344,7 +6438,7 @@
|
|
|
6344
6438
|
this.started = true;
|
|
6345
6439
|
await new Promise(resolve => {
|
|
6346
6440
|
const start = async () => {
|
|
6347
|
-
this.
|
|
6441
|
+
this.#eventListeners.addListeners();
|
|
6348
6442
|
for (const plugin of this.plugins) {
|
|
6349
6443
|
await plugin.start?.();
|
|
6350
6444
|
}
|
|
@@ -6352,20 +6446,20 @@
|
|
|
6352
6446
|
this.play();
|
|
6353
6447
|
resolve();
|
|
6354
6448
|
};
|
|
6355
|
-
this
|
|
6449
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6356
6450
|
});
|
|
6357
6451
|
}
|
|
6358
6452
|
stop() {
|
|
6359
6453
|
if (!guardCheck(this) || !this.started) {
|
|
6360
6454
|
return;
|
|
6361
6455
|
}
|
|
6362
|
-
if (this
|
|
6363
|
-
clearTimeout(this
|
|
6364
|
-
|
|
6456
|
+
if (this.#delayTimeout) {
|
|
6457
|
+
clearTimeout(this.#delayTimeout);
|
|
6458
|
+
this.#delayTimeout = undefined;
|
|
6365
6459
|
}
|
|
6366
|
-
this
|
|
6460
|
+
this.#firstStart = true;
|
|
6367
6461
|
this.started = false;
|
|
6368
|
-
this.
|
|
6462
|
+
this.#eventListeners.removeListeners();
|
|
6369
6463
|
this.pause();
|
|
6370
6464
|
this.particles.clear();
|
|
6371
6465
|
this.canvas.stop();
|
|
@@ -6375,7 +6469,7 @@
|
|
|
6375
6469
|
this.particleCreatedPlugins.length = 0;
|
|
6376
6470
|
this.particleDestroyedPlugins.length = 0;
|
|
6377
6471
|
this.particlePositionPlugins.length = 0;
|
|
6378
|
-
this
|
|
6472
|
+
this.#sourceOptions = this.#options;
|
|
6379
6473
|
this.dispatchEvent(EventType.containerStopped);
|
|
6380
6474
|
}
|
|
6381
6475
|
updateActualOptions() {
|
|
@@ -6387,23 +6481,23 @@
|
|
|
6387
6481
|
}
|
|
6388
6482
|
return refresh;
|
|
6389
6483
|
}
|
|
6390
|
-
|
|
6484
|
+
#nextFrame = (timestamp) => {
|
|
6391
6485
|
try {
|
|
6392
|
-
if (!this
|
|
6393
|
-
this
|
|
6394
|
-
timestamp < this
|
|
6486
|
+
if (!this.#smooth &&
|
|
6487
|
+
this.#lastFrameTime !== undefined &&
|
|
6488
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6395
6489
|
this.draw(false);
|
|
6396
6490
|
return;
|
|
6397
6491
|
}
|
|
6398
|
-
this
|
|
6399
|
-
updateDelta(this
|
|
6400
|
-
this.addLifeTime(this.
|
|
6401
|
-
this
|
|
6402
|
-
if (this.
|
|
6492
|
+
this.#lastFrameTime ??= timestamp;
|
|
6493
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6494
|
+
this.addLifeTime(this.#delta.value);
|
|
6495
|
+
this.#lastFrameTime = timestamp;
|
|
6496
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6403
6497
|
this.draw(false);
|
|
6404
6498
|
return;
|
|
6405
6499
|
}
|
|
6406
|
-
this.canvas.render.drawParticles(this
|
|
6500
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6407
6501
|
if (!this.alive()) {
|
|
6408
6502
|
this.destroy();
|
|
6409
6503
|
return;
|
|
@@ -6424,10 +6518,10 @@
|
|
|
6424
6518
|
});
|
|
6425
6519
|
|
|
6426
6520
|
class BlendPluginInstance {
|
|
6427
|
-
|
|
6428
|
-
|
|
6521
|
+
#container;
|
|
6522
|
+
#defaultCompositeValue;
|
|
6429
6523
|
constructor(container) {
|
|
6430
|
-
this
|
|
6524
|
+
this.#container = container;
|
|
6431
6525
|
}
|
|
6432
6526
|
drawParticleCleanup(context, particle) {
|
|
6433
6527
|
if (!particle.options.blend?.enable) {
|
|
@@ -6444,14 +6538,14 @@
|
|
|
6444
6538
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6445
6539
|
}
|
|
6446
6540
|
drawSettingsCleanup(context) {
|
|
6447
|
-
if (!this
|
|
6541
|
+
if (!this.#defaultCompositeValue) {
|
|
6448
6542
|
return;
|
|
6449
6543
|
}
|
|
6450
|
-
context.globalCompositeOperation = this
|
|
6544
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6451
6545
|
}
|
|
6452
6546
|
drawSettingsSetup(context) {
|
|
6453
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6454
|
-
this
|
|
6547
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6548
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6455
6549
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6456
6550
|
}
|
|
6457
6551
|
}
|
|
@@ -6594,11 +6688,11 @@
|
|
|
6594
6688
|
class MovePluginInstance {
|
|
6595
6689
|
availablePathGenerators;
|
|
6596
6690
|
pathGenerators;
|
|
6597
|
-
|
|
6598
|
-
|
|
6691
|
+
#container;
|
|
6692
|
+
#pluginManager;
|
|
6599
6693
|
constructor(pluginManager, container) {
|
|
6600
|
-
this
|
|
6601
|
-
this
|
|
6694
|
+
this.#pluginManager = pluginManager;
|
|
6695
|
+
this.#container = container;
|
|
6602
6696
|
this.availablePathGenerators = new Map();
|
|
6603
6697
|
this.pathGenerators = new Map();
|
|
6604
6698
|
}
|
|
@@ -6629,7 +6723,7 @@
|
|
|
6629
6723
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
6630
6724
|
inverse: gravityOptions.inverse,
|
|
6631
6725
|
};
|
|
6632
|
-
initSpin(this
|
|
6726
|
+
initSpin(this.#container, particle);
|
|
6633
6727
|
}
|
|
6634
6728
|
particleDestroyed(particle) {
|
|
6635
6729
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -6640,7 +6734,7 @@
|
|
|
6640
6734
|
if (!moveOptions.enable) {
|
|
6641
6735
|
return;
|
|
6642
6736
|
}
|
|
6643
|
-
const container = this
|
|
6737
|
+
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;
|
|
6644
6738
|
if (moveOptions.spin.enable) {
|
|
6645
6739
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
6646
6740
|
}
|
|
@@ -6650,18 +6744,18 @@
|
|
|
6650
6744
|
applyDistance(particle);
|
|
6651
6745
|
}
|
|
6652
6746
|
preInit() {
|
|
6653
|
-
return this
|
|
6747
|
+
return this.#init();
|
|
6654
6748
|
}
|
|
6655
6749
|
redrawInit() {
|
|
6656
|
-
return this
|
|
6750
|
+
return this.#init();
|
|
6657
6751
|
}
|
|
6658
6752
|
update() {
|
|
6659
6753
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6660
6754
|
pathGenerator.update();
|
|
6661
6755
|
}
|
|
6662
6756
|
}
|
|
6663
|
-
async
|
|
6664
|
-
const availablePathGenerators = await this.
|
|
6757
|
+
async #init() {
|
|
6758
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
6665
6759
|
if (!availablePathGenerators) {
|
|
6666
6760
|
return;
|
|
6667
6761
|
}
|
|
@@ -6679,44 +6773,44 @@
|
|
|
6679
6773
|
});
|
|
6680
6774
|
|
|
6681
6775
|
class EmittersPluginInstance {
|
|
6682
|
-
container;
|
|
6683
|
-
|
|
6776
|
+
#container;
|
|
6777
|
+
#instancesManager;
|
|
6684
6778
|
constructor(instancesManager, container) {
|
|
6685
|
-
this
|
|
6686
|
-
this
|
|
6687
|
-
this.
|
|
6779
|
+
this.#instancesManager = instancesManager;
|
|
6780
|
+
this.#container = container;
|
|
6781
|
+
this.#instancesManager.initContainer(container);
|
|
6688
6782
|
}
|
|
6689
6783
|
async init() {
|
|
6690
|
-
const emittersOptions = this
|
|
6784
|
+
const emittersOptions = this.#container.actualOptions.emitters;
|
|
6691
6785
|
if (isArray(emittersOptions)) {
|
|
6692
6786
|
for (const emitterOptions of emittersOptions) {
|
|
6693
|
-
await this.
|
|
6787
|
+
await this.#instancesManager.addEmitter(this.#container, emitterOptions);
|
|
6694
6788
|
}
|
|
6695
6789
|
}
|
|
6696
6790
|
else {
|
|
6697
|
-
await this.
|
|
6791
|
+
await this.#instancesManager.addEmitter(this.#container, emittersOptions);
|
|
6698
6792
|
}
|
|
6699
6793
|
}
|
|
6700
6794
|
pause() {
|
|
6701
|
-
for (const emitter of this.
|
|
6795
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6702
6796
|
emitter.pause();
|
|
6703
6797
|
}
|
|
6704
6798
|
}
|
|
6705
6799
|
play() {
|
|
6706
|
-
for (const emitter of this.
|
|
6800
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6707
6801
|
emitter.play();
|
|
6708
6802
|
}
|
|
6709
6803
|
}
|
|
6710
6804
|
resize() {
|
|
6711
|
-
for (const emitter of this.
|
|
6805
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
6712
6806
|
emitter.resize();
|
|
6713
6807
|
}
|
|
6714
6808
|
}
|
|
6715
6809
|
stop() {
|
|
6716
|
-
this.
|
|
6810
|
+
this.#instancesManager.clear(this.#container);
|
|
6717
6811
|
}
|
|
6718
6812
|
update(delta) {
|
|
6719
|
-
this.
|
|
6813
|
+
this.#instancesManager.getArray(this.#container).forEach(emitter => {
|
|
6720
6814
|
emitter.update(delta);
|
|
6721
6815
|
});
|
|
6722
6816
|
}
|
|
@@ -6749,16 +6843,16 @@
|
|
|
6749
6843
|
|
|
6750
6844
|
const defaultIndex = 0;
|
|
6751
6845
|
class EmittersInstancesManager {
|
|
6752
|
-
|
|
6753
|
-
|
|
6846
|
+
#containerArrays;
|
|
6847
|
+
#pluginManager;
|
|
6754
6848
|
constructor(pluginManager) {
|
|
6755
|
-
this
|
|
6756
|
-
this
|
|
6849
|
+
this.#containerArrays = new Map();
|
|
6850
|
+
this.#pluginManager = pluginManager;
|
|
6757
6851
|
}
|
|
6758
6852
|
async addEmitter(container, options, position) {
|
|
6759
6853
|
const emitterOptions = new Emitter();
|
|
6760
6854
|
emitterOptions.load(options);
|
|
6761
|
-
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this
|
|
6855
|
+
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this.#pluginManager, container, (emitter) => {
|
|
6762
6856
|
this.removeEmitter(container, emitter);
|
|
6763
6857
|
}, emitterOptions, position);
|
|
6764
6858
|
await emitter.init();
|
|
@@ -6767,22 +6861,22 @@
|
|
|
6767
6861
|
}
|
|
6768
6862
|
clear(container) {
|
|
6769
6863
|
this.initContainer(container);
|
|
6770
|
-
this.
|
|
6864
|
+
this.#containerArrays.set(container, []);
|
|
6771
6865
|
}
|
|
6772
6866
|
getArray(container) {
|
|
6773
6867
|
this.initContainer(container);
|
|
6774
|
-
let array = this.
|
|
6868
|
+
let array = this.#containerArrays.get(container);
|
|
6775
6869
|
if (!array) {
|
|
6776
6870
|
array = [];
|
|
6777
|
-
this.
|
|
6871
|
+
this.#containerArrays.set(container, array);
|
|
6778
6872
|
}
|
|
6779
6873
|
return array;
|
|
6780
6874
|
}
|
|
6781
6875
|
initContainer(container) {
|
|
6782
|
-
if (this.
|
|
6876
|
+
if (this.#containerArrays.has(container)) {
|
|
6783
6877
|
return;
|
|
6784
6878
|
}
|
|
6785
|
-
this.
|
|
6879
|
+
this.#containerArrays.set(container, []);
|
|
6786
6880
|
container.getEmitter = (idxOrName) => {
|
|
6787
6881
|
const array = this.getArray(container);
|
|
6788
6882
|
return idxOrName === undefined || isNumber(idxOrName)
|
|
@@ -6824,15 +6918,15 @@
|
|
|
6824
6918
|
|
|
6825
6919
|
const minimumLength = 0;
|
|
6826
6920
|
class TrailPluginInstance {
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6921
|
+
#container;
|
|
6922
|
+
#pluginManager;
|
|
6923
|
+
#trailFill;
|
|
6830
6924
|
constructor(pluginManager, container) {
|
|
6831
|
-
this
|
|
6832
|
-
this
|
|
6925
|
+
this.#container = container;
|
|
6926
|
+
this.#pluginManager = pluginManager;
|
|
6833
6927
|
}
|
|
6834
6928
|
canvasClear() {
|
|
6835
|
-
const container = this
|
|
6929
|
+
const container = this.#container, trail = container.actualOptions.trail, trailFill = this.#trailFill;
|
|
6836
6930
|
if (!trail?.enable || !trailFill || trail.length <= minimumLength) {
|
|
6837
6931
|
return false;
|
|
6838
6932
|
}
|
|
@@ -6850,24 +6944,24 @@
|
|
|
6850
6944
|
}
|
|
6851
6945
|
async init() {
|
|
6852
6946
|
try {
|
|
6853
|
-
await this
|
|
6947
|
+
await this.#initTrail();
|
|
6854
6948
|
}
|
|
6855
6949
|
catch (e) {
|
|
6856
6950
|
getLogger().error(e);
|
|
6857
6951
|
}
|
|
6858
6952
|
}
|
|
6859
|
-
|
|
6860
|
-
const options = this.
|
|
6953
|
+
#initTrail = async () => {
|
|
6954
|
+
const options = this.#container.actualOptions, trail = options.trail;
|
|
6861
6955
|
if (!trail?.enable) {
|
|
6862
6956
|
return;
|
|
6863
6957
|
}
|
|
6864
6958
|
const trailFill = trail.fill, opacity = inverseFactorNumerator / trail.length;
|
|
6865
6959
|
if (trailFill.color) {
|
|
6866
|
-
const fillColor = rangeColorToRgb(this
|
|
6960
|
+
const fillColor = rangeColorToRgb(this.#pluginManager, trailFill.color);
|
|
6867
6961
|
if (!fillColor) {
|
|
6868
6962
|
return;
|
|
6869
6963
|
}
|
|
6870
|
-
this
|
|
6964
|
+
this.#trailFill = {
|
|
6871
6965
|
color: {
|
|
6872
6966
|
...fillColor,
|
|
6873
6967
|
},
|
|
@@ -6881,7 +6975,7 @@
|
|
|
6881
6975
|
}
|
|
6882
6976
|
const img = safeDocument().createElement("img");
|
|
6883
6977
|
img.addEventListener("load", () => {
|
|
6884
|
-
this
|
|
6978
|
+
this.#trailFill = {
|
|
6885
6979
|
image: img,
|
|
6886
6980
|
opacity,
|
|
6887
6981
|
};
|
|
@@ -6931,34 +7025,34 @@
|
|
|
6931
7025
|
spawnStrokeColor;
|
|
6932
7026
|
spawnStrokeOpacity;
|
|
6933
7027
|
spawnStrokeWidth;
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
6940
|
-
|
|
6941
|
-
|
|
6942
|
-
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
|
|
6950
|
-
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
|
|
7028
|
+
#container;
|
|
7029
|
+
#currentDuration;
|
|
7030
|
+
#currentEmitDelay;
|
|
7031
|
+
#currentSpawnDelay;
|
|
7032
|
+
#duration;
|
|
7033
|
+
#emitDelay;
|
|
7034
|
+
#firstSpawn;
|
|
7035
|
+
#immortal;
|
|
7036
|
+
#initialPosition;
|
|
7037
|
+
#lifeCount;
|
|
7038
|
+
#mutationObserver;
|
|
7039
|
+
#particlesOptions;
|
|
7040
|
+
#paused;
|
|
7041
|
+
#pluginManager;
|
|
7042
|
+
#removeCallback;
|
|
7043
|
+
#resizeObserver;
|
|
7044
|
+
#shape;
|
|
7045
|
+
#size;
|
|
7046
|
+
#spawnDelay;
|
|
7047
|
+
#startParticlesAdded;
|
|
6954
7048
|
constructor(pluginManager, container, removeCallback, options, position) {
|
|
6955
|
-
this
|
|
6956
|
-
this
|
|
6957
|
-
this
|
|
6958
|
-
this
|
|
6959
|
-
this
|
|
6960
|
-
this
|
|
6961
|
-
this
|
|
7049
|
+
this.#pluginManager = pluginManager;
|
|
7050
|
+
this.#container = container;
|
|
7051
|
+
this.#removeCallback = removeCallback;
|
|
7052
|
+
this.#currentDuration = 0;
|
|
7053
|
+
this.#currentEmitDelay = 0;
|
|
7054
|
+
this.#currentSpawnDelay = 0;
|
|
7055
|
+
this.#initialPosition = position;
|
|
6962
7056
|
if (options instanceof Emitter) {
|
|
6963
7057
|
this.options = options;
|
|
6964
7058
|
}
|
|
@@ -6966,159 +7060,159 @@
|
|
|
6966
7060
|
this.options = new Emitter();
|
|
6967
7061
|
this.options.load(options);
|
|
6968
7062
|
}
|
|
6969
|
-
this
|
|
7063
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
6970
7064
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
6971
7065
|
container.retina.reduceFactor
|
|
6972
7066
|
: Infinity;
|
|
6973
|
-
this.position = this
|
|
7067
|
+
this.position = this.#initialPosition ?? this.#calcPosition();
|
|
6974
7068
|
this.name = this.options.name;
|
|
6975
7069
|
this.fill = this.options.fill;
|
|
6976
|
-
this
|
|
6977
|
-
this
|
|
7070
|
+
this.#firstSpawn = !this.options.life.wait;
|
|
7071
|
+
this.#startParticlesAdded = false;
|
|
6978
7072
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
6979
7073
|
particlesOptions.move ??= {};
|
|
6980
7074
|
particlesOptions.move.direction ??= this.options.direction;
|
|
6981
7075
|
if (this.options.spawn.fill?.color) {
|
|
6982
|
-
this.spawnFillColor = rangeColorToHsl(this
|
|
7076
|
+
this.spawnFillColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.fill.color);
|
|
6983
7077
|
}
|
|
6984
7078
|
if (this.options.spawn.stroke?.color) {
|
|
6985
|
-
this.spawnStrokeColor = rangeColorToHsl(this
|
|
6986
|
-
}
|
|
6987
|
-
this
|
|
6988
|
-
this
|
|
6989
|
-
this
|
|
6990
|
-
this.size = getSize(this
|
|
6991
|
-
this
|
|
6992
|
-
this
|
|
7079
|
+
this.spawnStrokeColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.stroke.color);
|
|
7080
|
+
}
|
|
7081
|
+
this.#paused = !this.options.autoPlay;
|
|
7082
|
+
this.#particlesOptions = particlesOptions;
|
|
7083
|
+
this.#size = this.#calcSize();
|
|
7084
|
+
this.size = getSize(this.#size, this.#container.canvas.size);
|
|
7085
|
+
this.#lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
7086
|
+
this.#immortal = this.#lifeCount <= minLifeCount;
|
|
6993
7087
|
if (this.options.domId) {
|
|
6994
7088
|
const element = safeDocument().getElementById(this.options.domId);
|
|
6995
7089
|
if (element) {
|
|
6996
|
-
this
|
|
7090
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
6997
7091
|
this.resize();
|
|
6998
7092
|
});
|
|
6999
|
-
this
|
|
7093
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
7000
7094
|
this.resize();
|
|
7001
7095
|
});
|
|
7002
|
-
this.
|
|
7096
|
+
this.#mutationObserver.observe(element, {
|
|
7003
7097
|
attributes: true,
|
|
7004
7098
|
attributeFilter: ["style", "width", "height"],
|
|
7005
7099
|
});
|
|
7006
|
-
this.
|
|
7100
|
+
this.#resizeObserver.observe(element);
|
|
7007
7101
|
}
|
|
7008
7102
|
}
|
|
7009
|
-
const shapeOptions = this.options.shape, shapeGenerator = this.
|
|
7103
|
+
const shapeOptions = this.options.shape, shapeGenerator = this.#pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
7010
7104
|
if (shapeGenerator) {
|
|
7011
|
-
this
|
|
7105
|
+
this.#shape = shapeGenerator.generate(this.#container, this.position, this.size, this.fill, shapeOptions.options);
|
|
7012
7106
|
}
|
|
7013
|
-
this.
|
|
7107
|
+
this.#container.dispatchEvent("emitterCreated", {
|
|
7014
7108
|
emitter: this,
|
|
7015
7109
|
});
|
|
7016
7110
|
this.play();
|
|
7017
7111
|
}
|
|
7018
7112
|
externalPause() {
|
|
7019
|
-
this
|
|
7113
|
+
this.#paused = true;
|
|
7020
7114
|
this.pause();
|
|
7021
7115
|
}
|
|
7022
7116
|
externalPlay() {
|
|
7023
|
-
this
|
|
7117
|
+
this.#paused = false;
|
|
7024
7118
|
this.play();
|
|
7025
7119
|
}
|
|
7026
7120
|
async init() {
|
|
7027
|
-
await this
|
|
7121
|
+
await this.#shape?.init();
|
|
7028
7122
|
}
|
|
7029
7123
|
pause() {
|
|
7030
|
-
if (this
|
|
7124
|
+
if (this.#paused) {
|
|
7031
7125
|
return;
|
|
7032
7126
|
}
|
|
7033
|
-
|
|
7127
|
+
this.#emitDelay = undefined;
|
|
7034
7128
|
}
|
|
7035
7129
|
play() {
|
|
7036
|
-
if (this
|
|
7130
|
+
if (this.#paused) {
|
|
7037
7131
|
return;
|
|
7038
7132
|
}
|
|
7039
|
-
if (!((this
|
|
7040
|
-
(this
|
|
7133
|
+
if (!((this.#lifeCount > minLifeCount || this.#immortal || !this.options.life.count) &&
|
|
7134
|
+
(this.#firstSpawn || this.#currentSpawnDelay >= (this.#spawnDelay ?? defaultSpawnDelay)))) {
|
|
7041
7135
|
return;
|
|
7042
7136
|
}
|
|
7043
|
-
const container = this
|
|
7044
|
-
if (this
|
|
7137
|
+
const container = this.#container;
|
|
7138
|
+
if (this.#emitDelay === undefined) {
|
|
7045
7139
|
const delay = getRangeValue(this.options.rate.delay);
|
|
7046
|
-
this
|
|
7140
|
+
this.#emitDelay = container.retina.reduceFactor
|
|
7047
7141
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
7048
7142
|
: Infinity;
|
|
7049
7143
|
}
|
|
7050
|
-
if (this
|
|
7051
|
-
this
|
|
7144
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
7145
|
+
this.#prepareToDie();
|
|
7052
7146
|
}
|
|
7053
7147
|
}
|
|
7054
7148
|
resize() {
|
|
7055
|
-
const initialPosition = this
|
|
7149
|
+
const initialPosition = this.#initialPosition, container = this.#container;
|
|
7056
7150
|
this.position =
|
|
7057
7151
|
initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
|
|
7058
7152
|
? initialPosition
|
|
7059
|
-
: this
|
|
7060
|
-
this
|
|
7061
|
-
this.size = getSize(this
|
|
7062
|
-
this
|
|
7153
|
+
: this.#calcPosition();
|
|
7154
|
+
this.#size = this.#calcSize();
|
|
7155
|
+
this.size = getSize(this.#size, container.canvas.size);
|
|
7156
|
+
this.#shape?.resize(this.position, this.size);
|
|
7063
7157
|
}
|
|
7064
7158
|
update(delta) {
|
|
7065
|
-
if (this
|
|
7159
|
+
if (this.#paused) {
|
|
7066
7160
|
return;
|
|
7067
7161
|
}
|
|
7068
|
-
const container = this
|
|
7069
|
-
if (this
|
|
7070
|
-
this
|
|
7071
|
-
this
|
|
7072
|
-
this
|
|
7162
|
+
const container = this.#container;
|
|
7163
|
+
if (this.#firstSpawn) {
|
|
7164
|
+
this.#firstSpawn = false;
|
|
7165
|
+
this.#currentSpawnDelay = this.#spawnDelay ?? defaultSpawnDelay;
|
|
7166
|
+
this.#currentEmitDelay = this.#emitDelay ?? defaultEmitDelay;
|
|
7073
7167
|
}
|
|
7074
|
-
if (!this
|
|
7075
|
-
this
|
|
7076
|
-
this
|
|
7168
|
+
if (!this.#startParticlesAdded) {
|
|
7169
|
+
this.#startParticlesAdded = true;
|
|
7170
|
+
this.#emitParticles(this.options.startCount);
|
|
7077
7171
|
}
|
|
7078
|
-
if (this
|
|
7079
|
-
this
|
|
7080
|
-
if (this
|
|
7172
|
+
if (this.#duration !== undefined) {
|
|
7173
|
+
this.#currentDuration += delta.value;
|
|
7174
|
+
if (this.#currentDuration >= this.#duration) {
|
|
7081
7175
|
this.pause();
|
|
7082
|
-
if (this
|
|
7083
|
-
|
|
7176
|
+
if (this.#spawnDelay !== undefined) {
|
|
7177
|
+
this.#spawnDelay = undefined;
|
|
7084
7178
|
}
|
|
7085
|
-
if (!this
|
|
7086
|
-
this
|
|
7179
|
+
if (!this.#immortal) {
|
|
7180
|
+
this.#lifeCount--;
|
|
7087
7181
|
}
|
|
7088
|
-
if (this
|
|
7089
|
-
this.position = this
|
|
7090
|
-
this
|
|
7091
|
-
this
|
|
7182
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
7183
|
+
this.position = this.#calcPosition();
|
|
7184
|
+
this.#shape?.resize(this.position, this.size);
|
|
7185
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
7092
7186
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
7093
7187
|
container.retina.reduceFactor
|
|
7094
7188
|
: Infinity;
|
|
7095
7189
|
}
|
|
7096
7190
|
else {
|
|
7097
|
-
this
|
|
7191
|
+
this.#destroy();
|
|
7098
7192
|
}
|
|
7099
|
-
this
|
|
7100
|
-
|
|
7193
|
+
this.#currentDuration -= this.#duration;
|
|
7194
|
+
this.#duration = undefined;
|
|
7101
7195
|
}
|
|
7102
7196
|
}
|
|
7103
|
-
if (this
|
|
7104
|
-
this
|
|
7105
|
-
if (this
|
|
7106
|
-
this.
|
|
7197
|
+
if (this.#spawnDelay !== undefined) {
|
|
7198
|
+
this.#currentSpawnDelay += delta.value;
|
|
7199
|
+
if (this.#currentSpawnDelay >= this.#spawnDelay) {
|
|
7200
|
+
this.#container.dispatchEvent("emitterPlay");
|
|
7107
7201
|
this.play();
|
|
7108
|
-
this
|
|
7109
|
-
|
|
7202
|
+
this.#currentSpawnDelay -= this.#spawnDelay;
|
|
7203
|
+
this.#spawnDelay = undefined;
|
|
7110
7204
|
}
|
|
7111
7205
|
}
|
|
7112
|
-
if (this
|
|
7113
|
-
this
|
|
7114
|
-
if (this
|
|
7115
|
-
this
|
|
7116
|
-
this
|
|
7206
|
+
if (this.#emitDelay !== undefined) {
|
|
7207
|
+
this.#currentEmitDelay += delta.value;
|
|
7208
|
+
if (this.#currentEmitDelay >= this.#emitDelay) {
|
|
7209
|
+
this.#emit();
|
|
7210
|
+
this.#currentEmitDelay -= this.#emitDelay;
|
|
7117
7211
|
}
|
|
7118
7212
|
}
|
|
7119
7213
|
}
|
|
7120
|
-
|
|
7121
|
-
const container = this
|
|
7214
|
+
#calcPosition() {
|
|
7215
|
+
const container = this.#container;
|
|
7122
7216
|
if (this.options.domId) {
|
|
7123
7217
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7124
7218
|
if (element) {
|
|
@@ -7134,8 +7228,8 @@
|
|
|
7134
7228
|
position: this.options.position,
|
|
7135
7229
|
});
|
|
7136
7230
|
}
|
|
7137
|
-
|
|
7138
|
-
const container = this
|
|
7231
|
+
#calcSize() {
|
|
7232
|
+
const container = this.#container;
|
|
7139
7233
|
if (this.options.domId) {
|
|
7140
7234
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7141
7235
|
if (element) {
|
|
@@ -7158,32 +7252,32 @@
|
|
|
7158
7252
|
return size;
|
|
7159
7253
|
})());
|
|
7160
7254
|
}
|
|
7161
|
-
|
|
7162
|
-
this
|
|
7163
|
-
this
|
|
7164
|
-
this
|
|
7165
|
-
this
|
|
7166
|
-
this
|
|
7167
|
-
this.
|
|
7255
|
+
#destroy = () => {
|
|
7256
|
+
this.#mutationObserver?.disconnect();
|
|
7257
|
+
this.#mutationObserver = undefined;
|
|
7258
|
+
this.#resizeObserver?.disconnect();
|
|
7259
|
+
this.#resizeObserver = undefined;
|
|
7260
|
+
this.#removeCallback(this);
|
|
7261
|
+
this.#container.dispatchEvent("emitterDestroyed", {
|
|
7168
7262
|
emitter: this,
|
|
7169
7263
|
});
|
|
7170
7264
|
};
|
|
7171
|
-
|
|
7172
|
-
if (this
|
|
7265
|
+
#emit() {
|
|
7266
|
+
if (this.#paused) {
|
|
7173
7267
|
return;
|
|
7174
7268
|
}
|
|
7175
7269
|
const quantity = getRangeValue(this.options.rate.quantity);
|
|
7176
|
-
this
|
|
7270
|
+
this.#emitParticles(quantity);
|
|
7177
7271
|
}
|
|
7178
|
-
|
|
7179
|
-
const singleParticlesOptions = (itemFromSingleOrMultiple(this
|
|
7272
|
+
#emitParticles(quantity) {
|
|
7273
|
+
const singleParticlesOptions = (itemFromSingleOrMultiple(this.#particlesOptions) ??
|
|
7180
7274
|
{}), 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
|
|
7181
7275
|
? defaultOpacity$1
|
|
7182
7276
|
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
7183
7277
|
? defaultOpacity$1
|
|
7184
7278
|
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
7185
7279
|
? defaultStrokeWidth
|
|
7186
|
-
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.
|
|
7280
|
+
: 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;
|
|
7187
7281
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
7188
7282
|
const particlesOptions = needsCopy
|
|
7189
7283
|
? deepExtend({}, singleParticlesOptions)
|
|
@@ -7194,23 +7288,23 @@
|
|
|
7194
7288
|
this.spawnStrokeWidth = strokeWidth;
|
|
7195
7289
|
if (this.spawnFillColor) {
|
|
7196
7290
|
if (fillHslAnimation && maxValues) {
|
|
7197
|
-
this.spawnFillColor.h = this
|
|
7198
|
-
this.spawnFillColor.s = this
|
|
7199
|
-
this.spawnFillColor.l = this
|
|
7291
|
+
this.spawnFillColor.h = this.#setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
7292
|
+
this.spawnFillColor.s = this.#setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
7293
|
+
this.spawnFillColor.l = this.#setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
7200
7294
|
}
|
|
7201
7295
|
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
7202
7296
|
}
|
|
7203
7297
|
if (this.spawnStrokeColor) {
|
|
7204
7298
|
if (strokeHslAnimation && maxValues) {
|
|
7205
|
-
this.spawnStrokeColor.h = this
|
|
7206
|
-
this.spawnStrokeColor.s = this
|
|
7207
|
-
this.spawnStrokeColor.l = this
|
|
7299
|
+
this.spawnStrokeColor.h = this.#setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
7300
|
+
this.spawnStrokeColor.s = this.#setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
7301
|
+
this.spawnStrokeColor.l = this.#setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
7208
7302
|
}
|
|
7209
7303
|
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
7210
7304
|
}
|
|
7211
7305
|
let position = this.position;
|
|
7212
|
-
if (this
|
|
7213
|
-
const shapePosData = this.
|
|
7306
|
+
if (this.#shape) {
|
|
7307
|
+
const shapePosData = this.#shape.randomPosition();
|
|
7214
7308
|
if (shapePosData) {
|
|
7215
7309
|
position = shapePosData.position;
|
|
7216
7310
|
const replaceData = shapeOptions.replace;
|
|
@@ -7223,21 +7317,21 @@
|
|
|
7223
7317
|
}
|
|
7224
7318
|
}
|
|
7225
7319
|
if (position) {
|
|
7226
|
-
this.
|
|
7320
|
+
this.#container.particles.addParticle(position, particlesOptions);
|
|
7227
7321
|
}
|
|
7228
7322
|
}
|
|
7229
7323
|
}
|
|
7230
|
-
|
|
7231
|
-
if (this
|
|
7324
|
+
#prepareToDie = () => {
|
|
7325
|
+
if (this.#paused) {
|
|
7232
7326
|
return;
|
|
7233
7327
|
}
|
|
7234
7328
|
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
7235
|
-
if ((this
|
|
7236
|
-
this
|
|
7329
|
+
if ((this.#lifeCount > minLifeCount || this.#immortal) && duration !== undefined && duration > minDuration) {
|
|
7330
|
+
this.#duration = duration * millisecondsToSeconds;
|
|
7237
7331
|
}
|
|
7238
7332
|
};
|
|
7239
|
-
|
|
7240
|
-
const container = this
|
|
7333
|
+
#setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
7334
|
+
const container = this.#container;
|
|
7241
7335
|
if (!animation.enable) {
|
|
7242
7336
|
return initValue;
|
|
7243
7337
|
}
|