@tsparticles/preset-fireworks 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
|
}
|
|
@@ -730,38 +730,38 @@
|
|
|
730
730
|
}
|
|
731
731
|
|
|
732
732
|
class EventDispatcher {
|
|
733
|
-
|
|
733
|
+
#listeners;
|
|
734
734
|
constructor() {
|
|
735
|
-
this
|
|
735
|
+
this.#listeners = new Map();
|
|
736
736
|
}
|
|
737
737
|
addEventListener(type, listener) {
|
|
738
738
|
this.removeEventListener(type, listener);
|
|
739
|
-
let arr = this.
|
|
739
|
+
let arr = this.#listeners.get(type);
|
|
740
740
|
if (!arr) {
|
|
741
741
|
arr = [];
|
|
742
|
-
this.
|
|
742
|
+
this.#listeners.set(type, arr);
|
|
743
743
|
}
|
|
744
744
|
arr.push(listener);
|
|
745
745
|
}
|
|
746
746
|
dispatchEvent(type, args) {
|
|
747
|
-
const listeners = this.
|
|
747
|
+
const listeners = this.#listeners.get(type);
|
|
748
748
|
listeners?.forEach(handler => {
|
|
749
749
|
handler(args);
|
|
750
750
|
});
|
|
751
751
|
}
|
|
752
752
|
hasEventListener(type) {
|
|
753
|
-
return !!this.
|
|
753
|
+
return !!this.#listeners.get(type);
|
|
754
754
|
}
|
|
755
755
|
removeAllEventListeners(type) {
|
|
756
756
|
if (!type) {
|
|
757
|
-
this
|
|
757
|
+
this.#listeners = new Map();
|
|
758
758
|
}
|
|
759
759
|
else {
|
|
760
|
-
this.
|
|
760
|
+
this.#listeners.delete(type);
|
|
761
761
|
}
|
|
762
762
|
}
|
|
763
763
|
removeEventListener(type, listener) {
|
|
764
|
-
const arr = this.
|
|
764
|
+
const arr = this.#listeners.get(type);
|
|
765
765
|
if (!arr) {
|
|
766
766
|
return;
|
|
767
767
|
}
|
|
@@ -770,7 +770,7 @@
|
|
|
770
770
|
return;
|
|
771
771
|
}
|
|
772
772
|
if (length === deleteCount) {
|
|
773
|
-
this.
|
|
773
|
+
this.#listeners.delete(type);
|
|
774
774
|
}
|
|
775
775
|
else {
|
|
776
776
|
arr.splice(idx, deleteCount);
|
|
@@ -808,19 +808,19 @@
|
|
|
808
808
|
presets = new Map();
|
|
809
809
|
shapeDrawers = new Map();
|
|
810
810
|
updaters = new Map();
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
811
|
+
#allLoadersSet = new Set();
|
|
812
|
+
#configs = new Map();
|
|
813
|
+
#engine;
|
|
814
|
+
#executedSet = new Set();
|
|
815
|
+
#initialized = false;
|
|
816
|
+
#isRunningLoaders = false;
|
|
817
|
+
#loadPromises = new Set();
|
|
818
818
|
constructor(engine) {
|
|
819
|
-
this
|
|
819
|
+
this.#engine = engine;
|
|
820
820
|
}
|
|
821
821
|
get configs() {
|
|
822
822
|
const res = {};
|
|
823
|
-
for (const [name, config] of this
|
|
823
|
+
for (const [name, config] of this.#configs) {
|
|
824
824
|
res[name] = config;
|
|
825
825
|
}
|
|
826
826
|
return res;
|
|
@@ -830,8 +830,8 @@
|
|
|
830
830
|
}
|
|
831
831
|
addConfig(config) {
|
|
832
832
|
const key = config.key ?? config.name ?? "default";
|
|
833
|
-
this.
|
|
834
|
-
this.
|
|
833
|
+
this.#configs.set(key, config);
|
|
834
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
835
835
|
}
|
|
836
836
|
addEasing(name, easing) {
|
|
837
837
|
if (this.easingFunctions.get(name)) {
|
|
@@ -892,21 +892,21 @@
|
|
|
892
892
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
893
893
|
}
|
|
894
894
|
async init() {
|
|
895
|
-
if (this
|
|
895
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
896
896
|
return;
|
|
897
897
|
}
|
|
898
|
-
this
|
|
899
|
-
this
|
|
900
|
-
this
|
|
898
|
+
this.#isRunningLoaders = true;
|
|
899
|
+
this.#executedSet = new Set();
|
|
900
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
901
901
|
try {
|
|
902
|
-
for (const loader of this
|
|
903
|
-
await this
|
|
902
|
+
for (const loader of this.#allLoadersSet) {
|
|
903
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
904
904
|
}
|
|
905
905
|
}
|
|
906
906
|
finally {
|
|
907
|
-
this.
|
|
908
|
-
this
|
|
909
|
-
this
|
|
907
|
+
this.#loadPromises.clear();
|
|
908
|
+
this.#isRunningLoaders = false;
|
|
909
|
+
this.#initialized = true;
|
|
910
910
|
}
|
|
911
911
|
}
|
|
912
912
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -917,24 +917,24 @@
|
|
|
917
917
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
918
918
|
}
|
|
919
919
|
async register(...loaders) {
|
|
920
|
-
if (this
|
|
920
|
+
if (this.#initialized) {
|
|
921
921
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
922
922
|
}
|
|
923
923
|
for (const loader of loaders) {
|
|
924
|
-
if (this
|
|
925
|
-
await this
|
|
924
|
+
if (this.#isRunningLoaders) {
|
|
925
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
926
926
|
}
|
|
927
927
|
else {
|
|
928
|
-
this.
|
|
928
|
+
this.#loadPromises.add(loader);
|
|
929
929
|
}
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
|
-
async
|
|
932
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
933
933
|
if (executed.has(loader))
|
|
934
934
|
return;
|
|
935
935
|
executed.add(loader);
|
|
936
936
|
allLoaders.add(loader);
|
|
937
|
-
await loader(this
|
|
937
|
+
await loader(this.#engine);
|
|
938
938
|
}
|
|
939
939
|
}
|
|
940
940
|
|
|
@@ -1014,17 +1014,17 @@
|
|
|
1014
1014
|
};
|
|
1015
1015
|
class Engine {
|
|
1016
1016
|
pluginManager = new PluginManager(this);
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1017
|
+
#domArray = [];
|
|
1018
|
+
#eventDispatcher = new EventDispatcher();
|
|
1019
|
+
#initialized = false;
|
|
1020
1020
|
get items() {
|
|
1021
|
-
return this
|
|
1021
|
+
return this.#domArray;
|
|
1022
1022
|
}
|
|
1023
1023
|
get version() {
|
|
1024
|
-
return "4.
|
|
1024
|
+
return "4.1.1";
|
|
1025
1025
|
}
|
|
1026
1026
|
addEventListener(type, listener) {
|
|
1027
|
-
this.
|
|
1027
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1028
1028
|
}
|
|
1029
1029
|
checkVersion(pluginVersion) {
|
|
1030
1030
|
if (this.version === pluginVersion) {
|
|
@@ -1033,17 +1033,17 @@
|
|
|
1033
1033
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1034
1034
|
}
|
|
1035
1035
|
dispatchEvent(type, args) {
|
|
1036
|
-
this.
|
|
1036
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1037
1037
|
}
|
|
1038
1038
|
async init() {
|
|
1039
|
-
if (this
|
|
1039
|
+
if (this.#initialized) {
|
|
1040
1040
|
return;
|
|
1041
1041
|
}
|
|
1042
1042
|
await this.pluginManager.init();
|
|
1043
|
-
this
|
|
1043
|
+
this.#initialized = true;
|
|
1044
1044
|
}
|
|
1045
1045
|
item(index) {
|
|
1046
|
-
const
|
|
1046
|
+
const items = this.items, item = items[index];
|
|
1047
1047
|
if (item?.destroyed) {
|
|
1048
1048
|
items.splice(index, removeDeleteCount);
|
|
1049
1049
|
return;
|
|
@@ -1097,7 +1097,7 @@
|
|
|
1097
1097
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1098
1098
|
}
|
|
1099
1099
|
removeEventListener(type, listener) {
|
|
1100
|
-
this.
|
|
1100
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1101
1101
|
}
|
|
1102
1102
|
}
|
|
1103
1103
|
|
|
@@ -1868,43 +1868,6 @@
|
|
|
1868
1868
|
}
|
|
1869
1869
|
}
|
|
1870
1870
|
|
|
1871
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1872
|
-
destroy;
|
|
1873
|
-
constructor() {
|
|
1874
|
-
super();
|
|
1875
|
-
this.destroy = DestroyType.none;
|
|
1876
|
-
this.speed = 2;
|
|
1877
|
-
}
|
|
1878
|
-
load(data) {
|
|
1879
|
-
super.load(data);
|
|
1880
|
-
if (isNull(data)) {
|
|
1881
|
-
return;
|
|
1882
|
-
}
|
|
1883
|
-
if (data.destroy !== undefined) {
|
|
1884
|
-
this.destroy = data.destroy;
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1890
|
-
animation;
|
|
1891
|
-
constructor() {
|
|
1892
|
-
super();
|
|
1893
|
-
this.animation = new OpacityAnimation();
|
|
1894
|
-
this.value = 1;
|
|
1895
|
-
}
|
|
1896
|
-
load(data) {
|
|
1897
|
-
if (isNull(data)) {
|
|
1898
|
-
return;
|
|
1899
|
-
}
|
|
1900
|
-
super.load(data);
|
|
1901
|
-
const animation = data.animation;
|
|
1902
|
-
if (animation !== undefined) {
|
|
1903
|
-
this.animation.load(animation);
|
|
1904
|
-
}
|
|
1905
|
-
}
|
|
1906
|
-
}
|
|
1907
|
-
|
|
1908
1871
|
class Stroke {
|
|
1909
1872
|
color;
|
|
1910
1873
|
opacity;
|
|
@@ -2072,43 +2035,6 @@
|
|
|
2072
2035
|
}
|
|
2073
2036
|
}
|
|
2074
2037
|
|
|
2075
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2076
|
-
destroy;
|
|
2077
|
-
constructor() {
|
|
2078
|
-
super();
|
|
2079
|
-
this.destroy = DestroyType.none;
|
|
2080
|
-
this.speed = 5;
|
|
2081
|
-
}
|
|
2082
|
-
load(data) {
|
|
2083
|
-
super.load(data);
|
|
2084
|
-
if (isNull(data)) {
|
|
2085
|
-
return;
|
|
2086
|
-
}
|
|
2087
|
-
if (data.destroy !== undefined) {
|
|
2088
|
-
this.destroy = data.destroy;
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
|
|
2093
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2094
|
-
animation;
|
|
2095
|
-
constructor() {
|
|
2096
|
-
super();
|
|
2097
|
-
this.animation = new SizeAnimation();
|
|
2098
|
-
this.value = 3;
|
|
2099
|
-
}
|
|
2100
|
-
load(data) {
|
|
2101
|
-
super.load(data);
|
|
2102
|
-
if (isNull(data)) {
|
|
2103
|
-
return;
|
|
2104
|
-
}
|
|
2105
|
-
const animation = data.animation;
|
|
2106
|
-
if (animation !== undefined) {
|
|
2107
|
-
this.animation.load(animation);
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
|
|
2112
2038
|
class ZIndex extends ValueWithRandom {
|
|
2113
2039
|
opacityRate;
|
|
2114
2040
|
sizeRate;
|
|
@@ -2142,24 +2068,21 @@
|
|
|
2142
2068
|
groups;
|
|
2143
2069
|
move;
|
|
2144
2070
|
number;
|
|
2145
|
-
opacity;
|
|
2146
2071
|
paint;
|
|
2147
2072
|
palette;
|
|
2148
2073
|
reduceDuplicates;
|
|
2149
2074
|
shape;
|
|
2150
|
-
size;
|
|
2151
2075
|
zIndex;
|
|
2152
|
-
|
|
2153
|
-
|
|
2076
|
+
#container;
|
|
2077
|
+
#pluginManager;
|
|
2154
2078
|
constructor(pluginManager, container) {
|
|
2155
|
-
this
|
|
2156
|
-
this
|
|
2079
|
+
this.#pluginManager = pluginManager;
|
|
2080
|
+
this.#container = container;
|
|
2157
2081
|
this.bounce = new ParticlesBounce();
|
|
2158
2082
|
this.effect = new Effect();
|
|
2159
2083
|
this.groups = {};
|
|
2160
2084
|
this.move = new Move();
|
|
2161
2085
|
this.number = new ParticlesNumber();
|
|
2162
|
-
this.opacity = new Opacity();
|
|
2163
2086
|
this.paint = new Paint();
|
|
2164
2087
|
this.paint.color = new AnimatableColor();
|
|
2165
2088
|
this.paint.color.value = "#fff";
|
|
@@ -2167,7 +2090,6 @@
|
|
|
2167
2090
|
this.paint.fill.enable = true;
|
|
2168
2091
|
this.reduceDuplicates = false;
|
|
2169
2092
|
this.shape = new Shape();
|
|
2170
|
-
this.size = new Size();
|
|
2171
2093
|
this.zIndex = new ZIndex();
|
|
2172
2094
|
}
|
|
2173
2095
|
load(data) {
|
|
@@ -2176,7 +2098,7 @@
|
|
|
2176
2098
|
}
|
|
2177
2099
|
if (data.palette) {
|
|
2178
2100
|
this.palette = data.palette;
|
|
2179
|
-
this
|
|
2101
|
+
this.#importPalette(this.palette);
|
|
2180
2102
|
}
|
|
2181
2103
|
if (data.groups !== undefined) {
|
|
2182
2104
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2196,7 +2118,6 @@
|
|
|
2196
2118
|
this.effect.load(data.effect);
|
|
2197
2119
|
this.move.load(data.move);
|
|
2198
2120
|
this.number.load(data.number);
|
|
2199
|
-
this.opacity.load(data.opacity);
|
|
2200
2121
|
const paintToLoad = data.paint;
|
|
2201
2122
|
if (paintToLoad) {
|
|
2202
2123
|
if (isArray(paintToLoad)) {
|
|
@@ -2215,15 +2136,14 @@
|
|
|
2215
2136
|
}
|
|
2216
2137
|
}
|
|
2217
2138
|
this.shape.load(data.shape);
|
|
2218
|
-
this.size.load(data.size);
|
|
2219
2139
|
this.zIndex.load(data.zIndex);
|
|
2220
|
-
if (this
|
|
2221
|
-
for (const plugin of this.
|
|
2140
|
+
if (this.#container) {
|
|
2141
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2222
2142
|
if (plugin.loadParticlesOptions) {
|
|
2223
|
-
plugin.loadParticlesOptions(this
|
|
2143
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2224
2144
|
}
|
|
2225
2145
|
}
|
|
2226
|
-
const updaters = this.
|
|
2146
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2227
2147
|
if (updaters) {
|
|
2228
2148
|
for (const updater of updaters) {
|
|
2229
2149
|
if (updater.loadOptions) {
|
|
@@ -2233,8 +2153,8 @@
|
|
|
2233
2153
|
}
|
|
2234
2154
|
}
|
|
2235
2155
|
}
|
|
2236
|
-
|
|
2237
|
-
const paletteData = this.
|
|
2156
|
+
#importPalette = (palette) => {
|
|
2157
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2238
2158
|
if (!paletteData) {
|
|
2239
2159
|
return;
|
|
2240
2160
|
}
|
|
@@ -2313,11 +2233,11 @@
|
|
|
2313
2233
|
smooth;
|
|
2314
2234
|
style;
|
|
2315
2235
|
zLayers;
|
|
2316
|
-
|
|
2317
|
-
|
|
2236
|
+
#container;
|
|
2237
|
+
#pluginManager;
|
|
2318
2238
|
constructor(pluginManager, container) {
|
|
2319
|
-
this
|
|
2320
|
-
this
|
|
2239
|
+
this.#pluginManager = pluginManager;
|
|
2240
|
+
this.#container = container;
|
|
2321
2241
|
this.autoPlay = true;
|
|
2322
2242
|
this.background = new Background();
|
|
2323
2243
|
this.clear = true;
|
|
@@ -2328,7 +2248,7 @@
|
|
|
2328
2248
|
this.duration = 0;
|
|
2329
2249
|
this.fpsLimit = 120;
|
|
2330
2250
|
this.hdr = true;
|
|
2331
|
-
this.particles = loadParticlesOptions(this
|
|
2251
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2332
2252
|
this.pauseOnBlur = true;
|
|
2333
2253
|
this.pauseOnOutsideViewport = true;
|
|
2334
2254
|
this.resize = new ResizeEvent();
|
|
@@ -2343,12 +2263,12 @@
|
|
|
2343
2263
|
if (data.preset !== undefined) {
|
|
2344
2264
|
this.preset = data.preset;
|
|
2345
2265
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2346
|
-
this
|
|
2266
|
+
this.#importPreset(preset);
|
|
2347
2267
|
});
|
|
2348
2268
|
}
|
|
2349
2269
|
if (data.palette !== undefined) {
|
|
2350
2270
|
this.palette = data.palette;
|
|
2351
|
-
this
|
|
2271
|
+
this.#importPalette(this.palette);
|
|
2352
2272
|
}
|
|
2353
2273
|
if (data.autoPlay !== undefined) {
|
|
2354
2274
|
this.autoPlay = data.autoPlay;
|
|
@@ -2402,12 +2322,12 @@
|
|
|
2402
2322
|
if (data.smooth !== undefined) {
|
|
2403
2323
|
this.smooth = data.smooth;
|
|
2404
2324
|
}
|
|
2405
|
-
this.
|
|
2406
|
-
plugin.loadOptions(this
|
|
2325
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2326
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2407
2327
|
});
|
|
2408
2328
|
}
|
|
2409
|
-
|
|
2410
|
-
const paletteData = this.
|
|
2329
|
+
#importPalette = palette => {
|
|
2330
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2411
2331
|
if (!paletteData) {
|
|
2412
2332
|
return;
|
|
2413
2333
|
}
|
|
@@ -2424,8 +2344,8 @@
|
|
|
2424
2344
|
},
|
|
2425
2345
|
});
|
|
2426
2346
|
};
|
|
2427
|
-
|
|
2428
|
-
this.load(this.
|
|
2347
|
+
#importPreset = preset => {
|
|
2348
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2429
2349
|
};
|
|
2430
2350
|
}
|
|
2431
2351
|
|
|
@@ -3150,7 +3070,7 @@
|
|
|
3150
3070
|
}
|
|
3151
3071
|
|
|
3152
3072
|
async function loadBlendPlugin(engine) {
|
|
3153
|
-
engine.checkVersion("4.
|
|
3073
|
+
engine.checkVersion("4.1.1");
|
|
3154
3074
|
await engine.pluginManager.register(e => {
|
|
3155
3075
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
3156
3076
|
});
|
|
@@ -3187,7 +3107,7 @@
|
|
|
3187
3107
|
}
|
|
3188
3108
|
|
|
3189
3109
|
async function loadCircleShape(engine) {
|
|
3190
|
-
engine.checkVersion("4.
|
|
3110
|
+
engine.checkVersion("4.1.1");
|
|
3191
3111
|
await engine.pluginManager.register(e => {
|
|
3192
3112
|
e.pluginManager.addShape(["circle"], () => {
|
|
3193
3113
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -3208,15 +3128,15 @@
|
|
|
3208
3128
|
return input.startsWith("#");
|
|
3209
3129
|
}
|
|
3210
3130
|
handleColor(color) {
|
|
3211
|
-
return this
|
|
3131
|
+
return this.#parseString(color.value);
|
|
3212
3132
|
}
|
|
3213
3133
|
handleRangeColor(color) {
|
|
3214
|
-
return this
|
|
3134
|
+
return this.#parseString(color.value);
|
|
3215
3135
|
}
|
|
3216
3136
|
parseString(input) {
|
|
3217
|
-
return this
|
|
3137
|
+
return this.#parseString(input);
|
|
3218
3138
|
}
|
|
3219
|
-
|
|
3139
|
+
#parseString(hexColor) {
|
|
3220
3140
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
3221
3141
|
return;
|
|
3222
3142
|
}
|
|
@@ -3235,7 +3155,7 @@
|
|
|
3235
3155
|
}
|
|
3236
3156
|
|
|
3237
3157
|
async function loadHexColorPlugin(engine) {
|
|
3238
|
-
engine.checkVersion("4.
|
|
3158
|
+
engine.checkVersion("4.1.1");
|
|
3239
3159
|
await engine.pluginManager.register(e => {
|
|
3240
3160
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
3241
3161
|
});
|
|
@@ -3288,7 +3208,7 @@
|
|
|
3288
3208
|
}
|
|
3289
3209
|
|
|
3290
3210
|
async function loadHslColorPlugin(engine) {
|
|
3291
|
-
engine.checkVersion("4.
|
|
3211
|
+
engine.checkVersion("4.1.1");
|
|
3292
3212
|
await engine.pluginManager.register(e => {
|
|
3293
3213
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3294
3214
|
});
|
|
@@ -3296,13 +3216,13 @@
|
|
|
3296
3216
|
|
|
3297
3217
|
class MovePlugin {
|
|
3298
3218
|
id = "move";
|
|
3299
|
-
|
|
3219
|
+
#pluginManager;
|
|
3300
3220
|
constructor(pluginManager) {
|
|
3301
|
-
this
|
|
3221
|
+
this.#pluginManager = pluginManager;
|
|
3302
3222
|
}
|
|
3303
3223
|
async getPlugin(container) {
|
|
3304
3224
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3305
|
-
return new MovePluginInstance(this
|
|
3225
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3306
3226
|
}
|
|
3307
3227
|
loadOptions() {
|
|
3308
3228
|
}
|
|
@@ -3312,7 +3232,7 @@
|
|
|
3312
3232
|
}
|
|
3313
3233
|
|
|
3314
3234
|
async function loadMovePlugin(engine) {
|
|
3315
|
-
engine.checkVersion("4.
|
|
3235
|
+
engine.checkVersion("4.1.1");
|
|
3316
3236
|
await engine.pluginManager.register(e => {
|
|
3317
3237
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3318
3238
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3330,18 +3250,58 @@
|
|
|
3330
3250
|
});
|
|
3331
3251
|
}
|
|
3332
3252
|
|
|
3253
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
3254
|
+
destroy;
|
|
3255
|
+
constructor() {
|
|
3256
|
+
super();
|
|
3257
|
+
this.destroy = DestroyType.none;
|
|
3258
|
+
this.speed = 2;
|
|
3259
|
+
}
|
|
3260
|
+
load(data) {
|
|
3261
|
+
super.load(data);
|
|
3262
|
+
if (isNull(data)) {
|
|
3263
|
+
return;
|
|
3264
|
+
}
|
|
3265
|
+
if (data.destroy !== undefined) {
|
|
3266
|
+
this.destroy = data.destroy;
|
|
3267
|
+
}
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
|
|
3271
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
3272
|
+
animation;
|
|
3273
|
+
constructor() {
|
|
3274
|
+
super();
|
|
3275
|
+
this.animation = new OpacityAnimation();
|
|
3276
|
+
this.value = 1;
|
|
3277
|
+
}
|
|
3278
|
+
load(data) {
|
|
3279
|
+
if (isNull(data)) {
|
|
3280
|
+
return;
|
|
3281
|
+
}
|
|
3282
|
+
super.load(data);
|
|
3283
|
+
const animation = data.animation;
|
|
3284
|
+
if (animation !== undefined) {
|
|
3285
|
+
this.animation.load(animation);
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3333
3290
|
class OpacityUpdater {
|
|
3334
|
-
container;
|
|
3291
|
+
#container;
|
|
3335
3292
|
constructor(container) {
|
|
3336
|
-
this
|
|
3293
|
+
this.#container = container;
|
|
3337
3294
|
}
|
|
3338
3295
|
init(particle) {
|
|
3339
3296
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3297
|
+
if (!opacityOptions) {
|
|
3298
|
+
return;
|
|
3299
|
+
}
|
|
3340
3300
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3341
3301
|
const opacityAnimation = opacityOptions.animation;
|
|
3342
3302
|
if (opacityAnimation.enable) {
|
|
3343
3303
|
particle.opacity.velocity =
|
|
3344
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3304
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3345
3305
|
if (!opacityAnimation.sync) {
|
|
3346
3306
|
particle.opacity.velocity *= getRandom();
|
|
3347
3307
|
}
|
|
@@ -3357,6 +3317,12 @@
|
|
|
3357
3317
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3358
3318
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3359
3319
|
}
|
|
3320
|
+
loadOptions(options, ...sources) {
|
|
3321
|
+
options.opacity ??= new Opacity();
|
|
3322
|
+
for (const source of sources) {
|
|
3323
|
+
options.opacity.load(source?.opacity);
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3360
3326
|
reset(particle) {
|
|
3361
3327
|
if (!particle.opacity) {
|
|
3362
3328
|
return;
|
|
@@ -3365,7 +3331,7 @@
|
|
|
3365
3331
|
particle.opacity.loops = 0;
|
|
3366
3332
|
}
|
|
3367
3333
|
update(particle, delta) {
|
|
3368
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3334
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3369
3335
|
return;
|
|
3370
3336
|
}
|
|
3371
3337
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3373,7 +3339,7 @@
|
|
|
3373
3339
|
}
|
|
3374
3340
|
|
|
3375
3341
|
async function loadOpacityUpdater(engine) {
|
|
3376
|
-
engine.checkVersion("4.
|
|
3342
|
+
engine.checkVersion("4.1.1");
|
|
3377
3343
|
await engine.pluginManager.register(e => {
|
|
3378
3344
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3379
3345
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3395,10 +3361,9 @@
|
|
|
3395
3361
|
}
|
|
3396
3362
|
const velocity = data.particle.velocity.x;
|
|
3397
3363
|
let bounced = false;
|
|
3398
|
-
if (
|
|
3399
|
-
data.
|
|
3400
|
-
|
|
3401
|
-
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3364
|
+
if (data.outOfCanvas &&
|
|
3365
|
+
((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3366
|
+
(data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3402
3367
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3403
3368
|
data.particle.velocity.x *= -newVelocity;
|
|
3404
3369
|
bounced = true;
|
|
@@ -3407,10 +3372,10 @@
|
|
|
3407
3372
|
return;
|
|
3408
3373
|
}
|
|
3409
3374
|
const minPos = data.offset.x + data.size;
|
|
3410
|
-
if (data.
|
|
3375
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.right) {
|
|
3411
3376
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3412
3377
|
}
|
|
3413
|
-
else if (data.
|
|
3378
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
|
|
3414
3379
|
data.particle.position.x = minPos;
|
|
3415
3380
|
}
|
|
3416
3381
|
if (data.outMode === OutMode.split) {
|
|
@@ -3430,10 +3395,9 @@
|
|
|
3430
3395
|
}
|
|
3431
3396
|
const velocity = data.particle.velocity.y;
|
|
3432
3397
|
let bounced = false;
|
|
3433
|
-
if (
|
|
3434
|
-
data.
|
|
3435
|
-
|
|
3436
|
-
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3398
|
+
if (data.outOfCanvas &&
|
|
3399
|
+
((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3400
|
+
(data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3437
3401
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3438
3402
|
data.particle.velocity.y *= -newVelocity;
|
|
3439
3403
|
bounced = true;
|
|
@@ -3442,10 +3406,10 @@
|
|
|
3442
3406
|
return;
|
|
3443
3407
|
}
|
|
3444
3408
|
const minPos = data.offset.y + data.size;
|
|
3445
|
-
if (data.
|
|
3409
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
|
|
3446
3410
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3447
3411
|
}
|
|
3448
|
-
else if (data.
|
|
3412
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
3449
3413
|
data.particle.position.y = minPos;
|
|
3450
3414
|
}
|
|
3451
3415
|
if (data.outMode === OutMode.split) {
|
|
@@ -3454,24 +3418,24 @@
|
|
|
3454
3418
|
}
|
|
3455
3419
|
|
|
3456
3420
|
class BounceOutMode {
|
|
3457
|
-
container;
|
|
3458
3421
|
modes;
|
|
3459
|
-
|
|
3422
|
+
#container;
|
|
3423
|
+
#particleBouncePlugins;
|
|
3460
3424
|
constructor(container) {
|
|
3461
|
-
this
|
|
3425
|
+
this.#container = container;
|
|
3462
3426
|
this.modes = [
|
|
3463
3427
|
OutMode.bounce,
|
|
3464
3428
|
OutMode.split,
|
|
3465
3429
|
];
|
|
3466
|
-
this
|
|
3430
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3467
3431
|
}
|
|
3468
3432
|
update(particle, direction, delta, outMode) {
|
|
3469
3433
|
if (!this.modes.includes(outMode)) {
|
|
3470
3434
|
return;
|
|
3471
3435
|
}
|
|
3472
|
-
const container = this
|
|
3436
|
+
const container = this.#container;
|
|
3473
3437
|
let handled = false;
|
|
3474
|
-
for (const plugin of this
|
|
3438
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3475
3439
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3476
3440
|
if (handled) {
|
|
3477
3441
|
break;
|
|
@@ -3480,29 +3444,26 @@
|
|
|
3480
3444
|
if (handled) {
|
|
3481
3445
|
return;
|
|
3482
3446
|
}
|
|
3483
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3484
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3485
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3447
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3448
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3449
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3486
3450
|
}
|
|
3487
3451
|
}
|
|
3488
3452
|
|
|
3489
3453
|
const minVelocity$3 = 0;
|
|
3490
3454
|
class DestroyOutMode {
|
|
3491
|
-
container;
|
|
3492
3455
|
modes;
|
|
3493
|
-
constructor(
|
|
3494
|
-
this.container = container;
|
|
3456
|
+
constructor(_container) {
|
|
3495
3457
|
this.modes = [OutMode.destroy];
|
|
3496
3458
|
}
|
|
3497
3459
|
update(particle, direction, _delta, outMode) {
|
|
3498
3460
|
if (!this.modes.includes(outMode)) {
|
|
3499
3461
|
return;
|
|
3500
3462
|
}
|
|
3501
|
-
const container = this.container;
|
|
3502
3463
|
switch (particle.outType) {
|
|
3503
3464
|
case ParticleOutType.normal:
|
|
3504
3465
|
case ParticleOutType.outside:
|
|
3505
|
-
if (
|
|
3466
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3506
3467
|
return;
|
|
3507
3468
|
}
|
|
3508
3469
|
break;
|
|
@@ -3523,10 +3484,10 @@
|
|
|
3523
3484
|
|
|
3524
3485
|
const minVelocity$2 = 0;
|
|
3525
3486
|
class NoneOutMode {
|
|
3526
|
-
container;
|
|
3527
3487
|
modes;
|
|
3488
|
+
#container;
|
|
3528
3489
|
constructor(container) {
|
|
3529
|
-
this
|
|
3490
|
+
this.#container = container;
|
|
3530
3491
|
this.modes = [OutMode.none];
|
|
3531
3492
|
}
|
|
3532
3493
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3539,7 +3500,7 @@
|
|
|
3539
3500
|
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
3540
3501
|
return;
|
|
3541
3502
|
}
|
|
3542
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3503
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3543
3504
|
if (!gravityOptions.enable) {
|
|
3544
3505
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3545
3506
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3565,17 +3526,17 @@
|
|
|
3565
3526
|
|
|
3566
3527
|
const minVelocity$1 = 0, minDistance = 0, updateVector = Vector.origin;
|
|
3567
3528
|
class OutOutMode {
|
|
3568
|
-
container;
|
|
3569
3529
|
modes;
|
|
3530
|
+
#container;
|
|
3570
3531
|
constructor(container) {
|
|
3571
|
-
this
|
|
3532
|
+
this.#container = container;
|
|
3572
3533
|
this.modes = [OutMode.out];
|
|
3573
3534
|
}
|
|
3574
3535
|
update(particle, direction, _delta, outMode) {
|
|
3575
3536
|
if (!this.modes.includes(outMode)) {
|
|
3576
3537
|
return;
|
|
3577
3538
|
}
|
|
3578
|
-
const container = this
|
|
3539
|
+
const container = this.#container;
|
|
3579
3540
|
switch (particle.outType) {
|
|
3580
3541
|
case ParticleOutType.inside: {
|
|
3581
3542
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3605,7 +3566,7 @@
|
|
|
3605
3566
|
break;
|
|
3606
3567
|
}
|
|
3607
3568
|
default: {
|
|
3608
|
-
if (
|
|
3569
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3609
3570
|
return;
|
|
3610
3571
|
}
|
|
3611
3572
|
switch (particle.outType) {
|
|
@@ -3689,16 +3650,16 @@
|
|
|
3689
3650
|
};
|
|
3690
3651
|
class OutOfCanvasUpdater {
|
|
3691
3652
|
updaters;
|
|
3692
|
-
container;
|
|
3653
|
+
#container;
|
|
3693
3654
|
constructor(container) {
|
|
3694
|
-
this
|
|
3655
|
+
this.#container = container;
|
|
3695
3656
|
this.updaters = new Map();
|
|
3696
3657
|
}
|
|
3697
3658
|
init(particle) {
|
|
3698
|
-
this
|
|
3699
|
-
this
|
|
3700
|
-
this
|
|
3701
|
-
this
|
|
3659
|
+
this.#addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
3660
|
+
this.#addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
3661
|
+
this.#addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
3662
|
+
this.#addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
3702
3663
|
}
|
|
3703
3664
|
isEnabled(particle) {
|
|
3704
3665
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3706,18 +3667,18 @@
|
|
|
3706
3667
|
update(particle, delta) {
|
|
3707
3668
|
const outModes = particle.options.move.outModes;
|
|
3708
3669
|
particle.justWarped = false;
|
|
3709
|
-
this
|
|
3710
|
-
this
|
|
3711
|
-
this
|
|
3712
|
-
this
|
|
3670
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
3671
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
3672
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
3673
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
3713
3674
|
}
|
|
3714
|
-
|
|
3675
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3715
3676
|
const outModes = particle.options.move.outModes;
|
|
3716
3677
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3717
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3678
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3718
3679
|
}
|
|
3719
3680
|
};
|
|
3720
|
-
|
|
3681
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3721
3682
|
for (const updater of this.updaters.values()) {
|
|
3722
3683
|
updater.update(particle, direction, delta, outMode);
|
|
3723
3684
|
}
|
|
@@ -3725,7 +3686,7 @@
|
|
|
3725
3686
|
}
|
|
3726
3687
|
|
|
3727
3688
|
async function loadOutModesUpdater(engine) {
|
|
3728
|
-
engine.checkVersion("4.
|
|
3689
|
+
engine.checkVersion("4.1.1");
|
|
3729
3690
|
await engine.pluginManager.register(e => {
|
|
3730
3691
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3731
3692
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3735,20 +3696,20 @@
|
|
|
3735
3696
|
|
|
3736
3697
|
const defaultOpacity = 1;
|
|
3737
3698
|
class PaintUpdater {
|
|
3738
|
-
|
|
3739
|
-
|
|
3699
|
+
#container;
|
|
3700
|
+
#pluginManager;
|
|
3740
3701
|
constructor(pluginManager, container) {
|
|
3741
|
-
this
|
|
3742
|
-
this
|
|
3702
|
+
this.#container = container;
|
|
3703
|
+
this.#pluginManager = pluginManager;
|
|
3743
3704
|
}
|
|
3744
3705
|
init(particle) {
|
|
3745
|
-
const container = this
|
|
3706
|
+
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;
|
|
3746
3707
|
if (fill) {
|
|
3747
3708
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3748
3709
|
particle.fillEnabled = fill.enable;
|
|
3749
3710
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3750
3711
|
particle.fillAnimation = fillColor.animation;
|
|
3751
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3712
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3752
3713
|
if (fillHslColor) {
|
|
3753
3714
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3754
3715
|
}
|
|
@@ -3764,7 +3725,7 @@
|
|
|
3764
3725
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3765
3726
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3766
3727
|
particle.strokeAnimation = strokeColor.animation;
|
|
3767
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3728
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3768
3729
|
if (strokeHslColor) {
|
|
3769
3730
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3770
3731
|
}
|
|
@@ -3796,7 +3757,7 @@
|
|
|
3796
3757
|
}
|
|
3797
3758
|
|
|
3798
3759
|
async function loadPaintUpdater(engine) {
|
|
3799
|
-
engine.checkVersion("4.
|
|
3760
|
+
engine.checkVersion("4.1.1");
|
|
3800
3761
|
await engine.pluginManager.register(e => {
|
|
3801
3762
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3802
3763
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3851,27 +3812,69 @@
|
|
|
3851
3812
|
}
|
|
3852
3813
|
|
|
3853
3814
|
async function loadRgbColorPlugin(engine) {
|
|
3854
|
-
engine.checkVersion("4.
|
|
3815
|
+
engine.checkVersion("4.1.1");
|
|
3855
3816
|
await engine.pluginManager.register(e => {
|
|
3856
3817
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3857
3818
|
});
|
|
3858
3819
|
}
|
|
3859
3820
|
|
|
3821
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3822
|
+
destroy;
|
|
3823
|
+
constructor() {
|
|
3824
|
+
super();
|
|
3825
|
+
this.destroy = DestroyType.none;
|
|
3826
|
+
this.speed = 5;
|
|
3827
|
+
}
|
|
3828
|
+
load(data) {
|
|
3829
|
+
super.load(data);
|
|
3830
|
+
if (isNull(data)) {
|
|
3831
|
+
return;
|
|
3832
|
+
}
|
|
3833
|
+
if (data.destroy !== undefined) {
|
|
3834
|
+
this.destroy = data.destroy;
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
|
|
3839
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3840
|
+
animation;
|
|
3841
|
+
constructor() {
|
|
3842
|
+
super();
|
|
3843
|
+
this.animation = new SizeAnimation();
|
|
3844
|
+
this.value = 3;
|
|
3845
|
+
}
|
|
3846
|
+
load(data) {
|
|
3847
|
+
super.load(data);
|
|
3848
|
+
if (isNull(data)) {
|
|
3849
|
+
return;
|
|
3850
|
+
}
|
|
3851
|
+
const animation = data.animation;
|
|
3852
|
+
if (animation !== undefined) {
|
|
3853
|
+
this.animation.load(animation);
|
|
3854
|
+
}
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
|
|
3860
3858
|
const minLoops = 0;
|
|
3861
3859
|
class SizeUpdater {
|
|
3862
|
-
|
|
3860
|
+
#container;
|
|
3863
3861
|
constructor(container) {
|
|
3864
|
-
this
|
|
3862
|
+
this.#container = container;
|
|
3865
3863
|
}
|
|
3866
3864
|
init(particle) {
|
|
3867
|
-
const container = this
|
|
3868
|
-
if (
|
|
3869
|
-
|
|
3870
|
-
(particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3871
|
-
if (!sizeAnimation.sync) {
|
|
3872
|
-
particle.size.velocity *= getRandom();
|
|
3873
|
-
}
|
|
3865
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3866
|
+
if (!sizeOptions) {
|
|
3867
|
+
return;
|
|
3874
3868
|
}
|
|
3869
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3870
|
+
if (!sizeAnimation.enable) {
|
|
3871
|
+
return;
|
|
3872
|
+
}
|
|
3873
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3874
|
+
if (sizeAnimation.sync) {
|
|
3875
|
+
return;
|
|
3876
|
+
}
|
|
3877
|
+
particle.size.velocity *= getRandom();
|
|
3875
3878
|
}
|
|
3876
3879
|
isEnabled(particle) {
|
|
3877
3880
|
return (!particle.destroyed &&
|
|
@@ -3881,12 +3884,26 @@
|
|
|
3881
3884
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3882
3885
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3883
3886
|
}
|
|
3887
|
+
loadOptions(options, ...sources) {
|
|
3888
|
+
options.size ??= new Size();
|
|
3889
|
+
for (const source of sources) {
|
|
3890
|
+
options.size.load(source?.size);
|
|
3891
|
+
}
|
|
3892
|
+
}
|
|
3893
|
+
preInit(particle) {
|
|
3894
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3895
|
+
if (!sizeOptions) {
|
|
3896
|
+
return;
|
|
3897
|
+
}
|
|
3898
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3899
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3900
|
+
}
|
|
3884
3901
|
reset(particle) {
|
|
3885
3902
|
particle.size.time = 0;
|
|
3886
3903
|
particle.size.loops = 0;
|
|
3887
3904
|
}
|
|
3888
3905
|
update(particle, delta) {
|
|
3889
|
-
if (!this.isEnabled(particle)) {
|
|
3906
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3890
3907
|
return;
|
|
3891
3908
|
}
|
|
3892
3909
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3894,7 +3911,7 @@
|
|
|
3894
3911
|
}
|
|
3895
3912
|
|
|
3896
3913
|
async function loadSizeUpdater(engine) {
|
|
3897
|
-
engine.checkVersion("4.
|
|
3914
|
+
engine.checkVersion("4.1.1");
|
|
3898
3915
|
await engine.pluginManager.register(e => {
|
|
3899
3916
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3900
3917
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3903,7 +3920,7 @@
|
|
|
3903
3920
|
}
|
|
3904
3921
|
|
|
3905
3922
|
async function loadBasic(engine) {
|
|
3906
|
-
engine.checkVersion("4.
|
|
3923
|
+
engine.checkVersion("4.1.1");
|
|
3907
3924
|
await engine.pluginManager.register(async (e) => {
|
|
3908
3925
|
await Promise.all([
|
|
3909
3926
|
loadBlendPlugin(e),
|
|
@@ -4120,13 +4137,15 @@
|
|
|
4120
4137
|
mode: PixelMode.precise,
|
|
4121
4138
|
},
|
|
4122
4139
|
});
|
|
4123
|
-
const factor = identity$2 / getRangeValue(splitOptions.factor.value);
|
|
4124
|
-
if (
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4140
|
+
const factor = identity$2 / getRangeValue(splitOptions.factor.value), sizeOptions = splitParticleOptions["size"];
|
|
4141
|
+
if (sizeOptions) {
|
|
4142
|
+
if (isNumber(sizeOptions.value)) {
|
|
4143
|
+
sizeOptions.value *= factor;
|
|
4144
|
+
}
|
|
4145
|
+
else {
|
|
4146
|
+
sizeOptions.value.min *= factor;
|
|
4147
|
+
sizeOptions.value.max *= factor;
|
|
4148
|
+
}
|
|
4130
4149
|
}
|
|
4131
4150
|
splitParticleOptions.load(splitParticlesOptions);
|
|
4132
4151
|
const splitParticlePaintOptions = itemFromSingleOrMultiple(splitParticleOptions.paint), splitParticleFillOptions = splitParticlePaintOptions?.fill, splitParticleStrokeOptions = splitParticlePaintOptions?.stroke, fillColor = resolveSplitColor(splitOptions.fillColorOffset, splitFillColor, splitParticleFillOptions?.color, parentFillColor), strokeColor = resolveSplitColor(splitOptions.strokeColorOffset, splitStrokeColor, splitParticleStrokeOptions?.color, parentStrokeColor);
|
|
@@ -4171,14 +4190,14 @@
|
|
|
4171
4190
|
|
|
4172
4191
|
const defaultDeltaFactor$1 = 1, fpsFactor = 60, minExplodeSpeed = 0.01, maxExplodeProgress = 1;
|
|
4173
4192
|
class DestroyUpdater {
|
|
4174
|
-
|
|
4175
|
-
|
|
4193
|
+
#container;
|
|
4194
|
+
#pluginManager;
|
|
4176
4195
|
constructor(pluginManager, container) {
|
|
4177
|
-
this
|
|
4178
|
-
this
|
|
4196
|
+
this.#container = container;
|
|
4197
|
+
this.#pluginManager = pluginManager;
|
|
4179
4198
|
}
|
|
4180
4199
|
init(particle) {
|
|
4181
|
-
const container = this
|
|
4200
|
+
const container = this.#container, particlesOptions = particle.options, destroyOptions = particlesOptions.destroy;
|
|
4182
4201
|
if (!destroyOptions) {
|
|
4183
4202
|
return;
|
|
4184
4203
|
}
|
|
@@ -4217,7 +4236,7 @@
|
|
|
4217
4236
|
const destroyOptions = particle.options.destroy;
|
|
4218
4237
|
switch (destroyOptions?.mode) {
|
|
4219
4238
|
case DestroyMode.split:
|
|
4220
|
-
split(this
|
|
4239
|
+
split(this.#pluginManager, this.#container, particle);
|
|
4221
4240
|
break;
|
|
4222
4241
|
case DestroyMode.explode: {
|
|
4223
4242
|
if (particle.exploding) {
|
|
@@ -4273,7 +4292,7 @@
|
|
|
4273
4292
|
}
|
|
4274
4293
|
|
|
4275
4294
|
async function loadDestroyUpdater(engine) {
|
|
4276
|
-
engine.checkVersion("4.
|
|
4295
|
+
engine.checkVersion("4.1.1");
|
|
4277
4296
|
await engine.pluginManager.register(e => {
|
|
4278
4297
|
e.pluginManager.addParticleUpdater("destroy", container => {
|
|
4279
4298
|
return Promise.resolve(new DestroyUpdater(e.pluginManager, container));
|
|
@@ -4490,13 +4509,13 @@
|
|
|
4490
4509
|
|
|
4491
4510
|
class EmittersPlugin {
|
|
4492
4511
|
id = "emitters";
|
|
4493
|
-
|
|
4512
|
+
#instancesManager;
|
|
4494
4513
|
constructor(instancesManager) {
|
|
4495
|
-
this
|
|
4514
|
+
this.#instancesManager = instancesManager;
|
|
4496
4515
|
}
|
|
4497
4516
|
async getPlugin(container) {
|
|
4498
4517
|
const { EmittersPluginInstance } = await Promise.resolve().then(function () { return EmittersPluginInstance$1; });
|
|
4499
|
-
return new EmittersPluginInstance(this
|
|
4518
|
+
return new EmittersPluginInstance(this.#instancesManager, container);
|
|
4500
4519
|
}
|
|
4501
4520
|
loadOptions(_container, options, source) {
|
|
4502
4521
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -4566,7 +4585,7 @@
|
|
|
4566
4585
|
})(EmitterClickMode || (EmitterClickMode = {}));
|
|
4567
4586
|
|
|
4568
4587
|
async function loadEmittersPluginSimple(engine) {
|
|
4569
|
-
engine.checkVersion("4.
|
|
4588
|
+
engine.checkVersion("4.1.1");
|
|
4570
4589
|
await engine.pluginManager.register(async (e) => {
|
|
4571
4590
|
const instancesManager = await getEmittersInstancesManager(e);
|
|
4572
4591
|
await addEmittersShapesManager(e);
|
|
@@ -4654,7 +4673,7 @@
|
|
|
4654
4673
|
}
|
|
4655
4674
|
|
|
4656
4675
|
async function loadEmittersShapeSquare(engine) {
|
|
4657
|
-
engine.checkVersion("4.
|
|
4676
|
+
engine.checkVersion("4.1.1");
|
|
4658
4677
|
await engine.pluginManager.register((e) => {
|
|
4659
4678
|
ensureEmittersPluginLoaded(e);
|
|
4660
4679
|
e.pluginManager.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator());
|
|
@@ -4771,12 +4790,12 @@
|
|
|
4771
4790
|
|
|
4772
4791
|
const noTime = 0, identity$1 = 1, infiniteValue = -1;
|
|
4773
4792
|
class LifeUpdater {
|
|
4774
|
-
container;
|
|
4793
|
+
#container;
|
|
4775
4794
|
constructor(container) {
|
|
4776
|
-
this
|
|
4795
|
+
this.#container = container;
|
|
4777
4796
|
}
|
|
4778
4797
|
init(particle) {
|
|
4779
|
-
const container = this
|
|
4798
|
+
const container = this.#container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
4780
4799
|
if (!lifeOptions) {
|
|
4781
4800
|
return;
|
|
4782
4801
|
}
|
|
@@ -4815,12 +4834,12 @@
|
|
|
4815
4834
|
if (!this.isEnabled(particle) || !particle.life) {
|
|
4816
4835
|
return;
|
|
4817
4836
|
}
|
|
4818
|
-
updateLife(particle, delta, this
|
|
4837
|
+
updateLife(particle, delta, this.#container.canvas.size);
|
|
4819
4838
|
}
|
|
4820
4839
|
}
|
|
4821
4840
|
|
|
4822
4841
|
async function loadLifeUpdater(engine) {
|
|
4823
|
-
engine.checkVersion("4.
|
|
4842
|
+
engine.checkVersion("4.1.1");
|
|
4824
4843
|
await engine.pluginManager.register(e => {
|
|
4825
4844
|
e.pluginManager.addParticleUpdater("life", container => {
|
|
4826
4845
|
return Promise.resolve(new LifeUpdater(container));
|
|
@@ -4846,7 +4865,7 @@
|
|
|
4846
4865
|
}
|
|
4847
4866
|
|
|
4848
4867
|
async function loadLineShape(engine) {
|
|
4849
|
-
engine.checkVersion("4.
|
|
4868
|
+
engine.checkVersion("4.1.1");
|
|
4850
4869
|
await engine.pluginManager.register(e => {
|
|
4851
4870
|
e.pluginManager.addShape(["line"], () => Promise.resolve(new LineDrawer()));
|
|
4852
4871
|
});
|
|
@@ -4910,9 +4929,9 @@
|
|
|
4910
4929
|
|
|
4911
4930
|
const doublePIDeg = 360;
|
|
4912
4931
|
class RotateUpdater {
|
|
4913
|
-
container;
|
|
4932
|
+
#container;
|
|
4914
4933
|
constructor(container) {
|
|
4915
|
-
this
|
|
4934
|
+
this.#container = container;
|
|
4916
4935
|
}
|
|
4917
4936
|
init(particle) {
|
|
4918
4937
|
const rotateOptions = particle.options.rotate;
|
|
@@ -4944,7 +4963,7 @@
|
|
|
4944
4963
|
if (rotateAnimation.enable) {
|
|
4945
4964
|
particle.rotate.decay = identity$2 - getRangeValue(rotateAnimation.decay);
|
|
4946
4965
|
particle.rotate.velocity =
|
|
4947
|
-
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this
|
|
4966
|
+
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this.#container.retina.reduceFactor;
|
|
4948
4967
|
if (!rotateAnimation.sync) {
|
|
4949
4968
|
particle.rotate.velocity *= getRandom();
|
|
4950
4969
|
}
|
|
@@ -4978,7 +4997,7 @@
|
|
|
4978
4997
|
}
|
|
4979
4998
|
|
|
4980
4999
|
async function loadRotateUpdater(engine) {
|
|
4981
|
-
engine.checkVersion("4.
|
|
5000
|
+
engine.checkVersion("4.1.1");
|
|
4982
5001
|
await engine.pluginManager.register(e => {
|
|
4983
5002
|
e.pluginManager.addParticleUpdater("rotate", container => {
|
|
4984
5003
|
return Promise.resolve(new RotateUpdater(container));
|
|
@@ -5329,9 +5348,9 @@
|
|
|
5329
5348
|
};
|
|
5330
5349
|
class SoundsPlugin {
|
|
5331
5350
|
id = "sounds";
|
|
5332
|
-
|
|
5351
|
+
#engine;
|
|
5333
5352
|
constructor(engine) {
|
|
5334
|
-
this
|
|
5353
|
+
this.#engine = engine;
|
|
5335
5354
|
const listenerOptions = {
|
|
5336
5355
|
capture: true,
|
|
5337
5356
|
once: true,
|
|
@@ -5341,7 +5360,7 @@
|
|
|
5341
5360
|
}
|
|
5342
5361
|
async getPlugin(container) {
|
|
5343
5362
|
const { SoundsPluginInstance } = await Promise.resolve().then(function () { return SoundsPluginInstance$1; });
|
|
5344
|
-
return new SoundsPluginInstance(container, this
|
|
5363
|
+
return new SoundsPluginInstance(container, this.#engine);
|
|
5345
5364
|
}
|
|
5346
5365
|
loadOptions(_container, options, source) {
|
|
5347
5366
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -5359,13 +5378,13 @@
|
|
|
5359
5378
|
}
|
|
5360
5379
|
|
|
5361
5380
|
async function loadSoundsPlugin(engine) {
|
|
5362
|
-
engine.checkVersion("4.
|
|
5381
|
+
engine.checkVersion("4.1.1");
|
|
5363
5382
|
await engine.pluginManager.register(e => {
|
|
5364
5383
|
e.pluginManager.addPlugin(new SoundsPlugin(e));
|
|
5365
5384
|
});
|
|
5366
5385
|
}
|
|
5367
5386
|
|
|
5368
|
-
const minTrailLength = 3, trailLengthOffset = 1, minWidth = -1, firstIndex = 0, defaultLength = 10, loopTrailLengthOffset = 2, loopTrailLengthMinIndex = 0;
|
|
5387
|
+
const minTrailLength = 3, trailLengthOffset = 1, minWidth = -1, firstIndex = 0, defaultLength = 10, loopTrailLengthOffset = 2, loopTrailLengthMinIndex = 0, defaultWidth = 0, minBound = 0;
|
|
5369
5388
|
const defaultTransform = {
|
|
5370
5389
|
a: 1,
|
|
5371
5390
|
b: 0,
|
|
@@ -5373,12 +5392,12 @@
|
|
|
5373
5392
|
d: 1,
|
|
5374
5393
|
};
|
|
5375
5394
|
class TrailDrawer {
|
|
5376
|
-
|
|
5395
|
+
#container;
|
|
5377
5396
|
constructor(container) {
|
|
5378
|
-
this
|
|
5397
|
+
this.#container = container;
|
|
5379
5398
|
}
|
|
5380
5399
|
drawAfter(data) {
|
|
5381
|
-
const { context, drawPosition, drawRadius, drawScale, particle, transformData } = data, container = this
|
|
5400
|
+
const { context, drawPosition, drawRadius, drawScale, particle, transformData } = data, container = this.#container, diameter = drawRadius * double, pxRatio = container.retina.pixelRatio, trail = particle.trail;
|
|
5382
5401
|
if (!trail || !particle.trailLength) {
|
|
5383
5402
|
return;
|
|
5384
5403
|
}
|
|
@@ -5426,6 +5445,39 @@
|
|
|
5426
5445
|
}
|
|
5427
5446
|
context.restore();
|
|
5428
5447
|
}
|
|
5448
|
+
isInsideCanvas(data) {
|
|
5449
|
+
const { canvasSize, direction, outMode, particle, radius } = data, position = particle.position, trail = particle.trail;
|
|
5450
|
+
let minX = position.x - radius, maxX = position.x + radius, minY = position.y - radius, maxY = position.y + radius;
|
|
5451
|
+
if (trail?.length) {
|
|
5452
|
+
const widthPadding = Math.max(radius, particle.trailMaxWidth ?? defaultWidth, particle.trailMinWidth ?? defaultWidth);
|
|
5453
|
+
for (const step of trail) {
|
|
5454
|
+
minX = Math.min(minX, step.position.x - widthPadding);
|
|
5455
|
+
maxX = Math.max(maxX, step.position.x + widthPadding);
|
|
5456
|
+
minY = Math.min(minY, step.position.y - widthPadding);
|
|
5457
|
+
maxY = Math.max(maxY, step.position.y + widthPadding);
|
|
5458
|
+
}
|
|
5459
|
+
}
|
|
5460
|
+
const strictBounds = outMode === OutMode.destroy;
|
|
5461
|
+
if (direction === OutModeDirection.bottom) {
|
|
5462
|
+
return minY <= canvasSize.height;
|
|
5463
|
+
}
|
|
5464
|
+
if (direction === OutModeDirection.left) {
|
|
5465
|
+
return maxX >= minBound;
|
|
5466
|
+
}
|
|
5467
|
+
if (direction === OutModeDirection.right) {
|
|
5468
|
+
return minX <= canvasSize.width;
|
|
5469
|
+
}
|
|
5470
|
+
if (direction === OutModeDirection.top) {
|
|
5471
|
+
return maxY >= minBound;
|
|
5472
|
+
}
|
|
5473
|
+
if (!strictBounds) {
|
|
5474
|
+
return (position.x + radius >= minBound &&
|
|
5475
|
+
position.y + radius >= minBound &&
|
|
5476
|
+
position.x - radius <= canvasSize.width &&
|
|
5477
|
+
position.y - radius <= canvasSize.height);
|
|
5478
|
+
}
|
|
5479
|
+
return maxX >= minBound && maxY >= minBound && minX <= canvasSize.width && minY <= canvasSize.height;
|
|
5480
|
+
}
|
|
5429
5481
|
particleInit(container, particle) {
|
|
5430
5482
|
particle.trail = [];
|
|
5431
5483
|
const effectData = particle.effectData;
|
|
@@ -5442,7 +5494,7 @@
|
|
|
5442
5494
|
}
|
|
5443
5495
|
|
|
5444
5496
|
async function loadTrailEffect(engine) {
|
|
5445
|
-
engine.checkVersion("4.
|
|
5497
|
+
engine.checkVersion("4.1.1");
|
|
5446
5498
|
await engine.pluginManager.register(e => {
|
|
5447
5499
|
e.pluginManager.addEffect("trail", container => {
|
|
5448
5500
|
return Promise.resolve(new TrailDrawer(container));
|
|
@@ -5483,58 +5535,58 @@
|
|
|
5483
5535
|
}
|
|
5484
5536
|
}
|
|
5485
5537
|
class RenderManager {
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5538
|
+
#canvasClearPlugins;
|
|
5539
|
+
#canvasManager;
|
|
5540
|
+
#canvasPaintPlugins;
|
|
5541
|
+
#clearDrawPlugins;
|
|
5542
|
+
#colorPlugins;
|
|
5543
|
+
#container;
|
|
5544
|
+
#context;
|
|
5545
|
+
#contextSettings;
|
|
5546
|
+
#drawParticlePlugins;
|
|
5547
|
+
#drawParticlesCleanupPlugins;
|
|
5548
|
+
#drawParticlesSetupPlugins;
|
|
5549
|
+
#drawPlugins;
|
|
5550
|
+
#drawSettingsCleanupPlugins;
|
|
5551
|
+
#drawSettingsSetupPlugins;
|
|
5552
|
+
#pluginManager;
|
|
5553
|
+
#postDrawUpdaters;
|
|
5554
|
+
#preDrawUpdaters;
|
|
5555
|
+
#reusableColorStyles = {};
|
|
5556
|
+
#reusablePluginColors = [undefined, undefined];
|
|
5557
|
+
#reusableTransform = {};
|
|
5506
5558
|
constructor(pluginManager, container, canvasManager) {
|
|
5507
|
-
this
|
|
5508
|
-
this
|
|
5509
|
-
this
|
|
5510
|
-
this
|
|
5511
|
-
this
|
|
5512
|
-
this
|
|
5513
|
-
this
|
|
5514
|
-
this
|
|
5515
|
-
this
|
|
5516
|
-
this
|
|
5517
|
-
this
|
|
5518
|
-
this
|
|
5519
|
-
this
|
|
5520
|
-
this
|
|
5521
|
-
this
|
|
5522
|
-
this
|
|
5559
|
+
this.#pluginManager = pluginManager;
|
|
5560
|
+
this.#container = container;
|
|
5561
|
+
this.#canvasManager = canvasManager;
|
|
5562
|
+
this.#context = null;
|
|
5563
|
+
this.#preDrawUpdaters = [];
|
|
5564
|
+
this.#postDrawUpdaters = [];
|
|
5565
|
+
this.#colorPlugins = [];
|
|
5566
|
+
this.#canvasClearPlugins = [];
|
|
5567
|
+
this.#canvasPaintPlugins = [];
|
|
5568
|
+
this.#clearDrawPlugins = [];
|
|
5569
|
+
this.#drawParticlePlugins = [];
|
|
5570
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5571
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5572
|
+
this.#drawPlugins = [];
|
|
5573
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5574
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5523
5575
|
}
|
|
5524
5576
|
get settings() {
|
|
5525
|
-
return this
|
|
5577
|
+
return this.#contextSettings;
|
|
5526
5578
|
}
|
|
5527
5579
|
canvasClear() {
|
|
5528
|
-
if (!this.
|
|
5580
|
+
if (!this.#container.actualOptions.clear) {
|
|
5529
5581
|
return;
|
|
5530
5582
|
}
|
|
5531
5583
|
this.draw(ctx => {
|
|
5532
|
-
clear(ctx, this.
|
|
5584
|
+
clear(ctx, this.#canvasManager.size);
|
|
5533
5585
|
});
|
|
5534
5586
|
}
|
|
5535
5587
|
clear() {
|
|
5536
5588
|
let pluginHandled = false;
|
|
5537
|
-
for (const plugin of this
|
|
5589
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
5538
5590
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
5539
5591
|
if (pluginHandled) {
|
|
5540
5592
|
break;
|
|
@@ -5547,21 +5599,21 @@
|
|
|
5547
5599
|
}
|
|
5548
5600
|
destroy() {
|
|
5549
5601
|
this.stop();
|
|
5550
|
-
this
|
|
5551
|
-
this
|
|
5552
|
-
this
|
|
5553
|
-
this
|
|
5554
|
-
this
|
|
5555
|
-
this
|
|
5556
|
-
this
|
|
5557
|
-
this
|
|
5558
|
-
this
|
|
5559
|
-
this
|
|
5560
|
-
this
|
|
5561
|
-
this
|
|
5602
|
+
this.#preDrawUpdaters = [];
|
|
5603
|
+
this.#postDrawUpdaters = [];
|
|
5604
|
+
this.#colorPlugins = [];
|
|
5605
|
+
this.#canvasClearPlugins = [];
|
|
5606
|
+
this.#canvasPaintPlugins = [];
|
|
5607
|
+
this.#clearDrawPlugins = [];
|
|
5608
|
+
this.#drawParticlePlugins = [];
|
|
5609
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5610
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5611
|
+
this.#drawPlugins = [];
|
|
5612
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5613
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5562
5614
|
}
|
|
5563
5615
|
draw(cb) {
|
|
5564
|
-
const ctx = this
|
|
5616
|
+
const ctx = this.#context;
|
|
5565
5617
|
if (!ctx) {
|
|
5566
5618
|
return;
|
|
5567
5619
|
}
|
|
@@ -5576,21 +5628,21 @@
|
|
|
5576
5628
|
return;
|
|
5577
5629
|
}
|
|
5578
5630
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
5579
|
-
let [fColor, sColor] = this
|
|
5631
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
5580
5632
|
fColor ??= pfColor;
|
|
5581
5633
|
sColor ??= psColor;
|
|
5582
5634
|
if (!fColor && !sColor) {
|
|
5583
5635
|
return;
|
|
5584
5636
|
}
|
|
5585
|
-
const container = this
|
|
5637
|
+
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;
|
|
5586
5638
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
5587
5639
|
colorStyles.fill = fill;
|
|
5588
5640
|
colorStyles.stroke = stroke;
|
|
5589
5641
|
this.draw((context) => {
|
|
5590
|
-
for (const plugin of this
|
|
5642
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
5591
5643
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
5592
5644
|
}
|
|
5593
|
-
this
|
|
5645
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
5594
5646
|
drawParticle({
|
|
5595
5647
|
container,
|
|
5596
5648
|
context,
|
|
@@ -5601,35 +5653,35 @@
|
|
|
5601
5653
|
opacity: opacity,
|
|
5602
5654
|
transform,
|
|
5603
5655
|
});
|
|
5604
|
-
this
|
|
5605
|
-
for (const plugin of this
|
|
5656
|
+
this.#applyPostDrawUpdaters(particle);
|
|
5657
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
5606
5658
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
5607
5659
|
}
|
|
5608
5660
|
});
|
|
5609
5661
|
}
|
|
5610
5662
|
drawParticlePlugins(particle, delta) {
|
|
5611
5663
|
this.draw(ctx => {
|
|
5612
|
-
for (const plugin of this
|
|
5664
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
5613
5665
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
5614
5666
|
}
|
|
5615
5667
|
});
|
|
5616
5668
|
}
|
|
5617
5669
|
drawParticles(delta) {
|
|
5618
|
-
const { particles } = this
|
|
5670
|
+
const { particles } = this.#container;
|
|
5619
5671
|
this.clear();
|
|
5620
5672
|
particles.update(delta);
|
|
5621
5673
|
this.draw(ctx => {
|
|
5622
|
-
for (const plugin of this
|
|
5674
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
5623
5675
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
5624
5676
|
}
|
|
5625
|
-
for (const plugin of this
|
|
5677
|
+
for (const plugin of this.#drawPlugins) {
|
|
5626
5678
|
plugin.draw?.(ctx, delta);
|
|
5627
5679
|
}
|
|
5628
5680
|
particles.drawParticles(delta);
|
|
5629
|
-
for (const plugin of this
|
|
5681
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
5630
5682
|
plugin.clearDraw?.(ctx, delta);
|
|
5631
5683
|
}
|
|
5632
|
-
for (const plugin of this
|
|
5684
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
5633
5685
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
5634
5686
|
}
|
|
5635
5687
|
});
|
|
@@ -5640,64 +5692,64 @@
|
|
|
5640
5692
|
this.paint();
|
|
5641
5693
|
}
|
|
5642
5694
|
initPlugins() {
|
|
5643
|
-
this
|
|
5644
|
-
this
|
|
5645
|
-
this
|
|
5646
|
-
this
|
|
5647
|
-
this
|
|
5648
|
-
this
|
|
5649
|
-
this
|
|
5650
|
-
this
|
|
5651
|
-
this
|
|
5652
|
-
this
|
|
5653
|
-
for (const plugin of this.
|
|
5695
|
+
this.#colorPlugins = [];
|
|
5696
|
+
this.#canvasClearPlugins = [];
|
|
5697
|
+
this.#canvasPaintPlugins = [];
|
|
5698
|
+
this.#clearDrawPlugins = [];
|
|
5699
|
+
this.#drawParticlePlugins = [];
|
|
5700
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5701
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5702
|
+
this.#drawPlugins = [];
|
|
5703
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5704
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5705
|
+
for (const plugin of this.#container.plugins) {
|
|
5654
5706
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
5655
|
-
this.
|
|
5707
|
+
this.#colorPlugins.push(plugin);
|
|
5656
5708
|
}
|
|
5657
5709
|
if (plugin.canvasClear) {
|
|
5658
|
-
this.
|
|
5710
|
+
this.#canvasClearPlugins.push(plugin);
|
|
5659
5711
|
}
|
|
5660
5712
|
if (plugin.canvasPaint) {
|
|
5661
|
-
this.
|
|
5713
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
5662
5714
|
}
|
|
5663
5715
|
if (plugin.drawParticle) {
|
|
5664
|
-
this.
|
|
5716
|
+
this.#drawParticlePlugins.push(plugin);
|
|
5665
5717
|
}
|
|
5666
5718
|
if (plugin.drawParticleSetup) {
|
|
5667
|
-
this.
|
|
5719
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
5668
5720
|
}
|
|
5669
5721
|
if (plugin.drawParticleCleanup) {
|
|
5670
|
-
this.
|
|
5722
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
5671
5723
|
}
|
|
5672
5724
|
if (plugin.draw) {
|
|
5673
|
-
this.
|
|
5725
|
+
this.#drawPlugins.push(plugin);
|
|
5674
5726
|
}
|
|
5675
5727
|
if (plugin.drawSettingsSetup) {
|
|
5676
|
-
this.
|
|
5728
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
5677
5729
|
}
|
|
5678
5730
|
if (plugin.drawSettingsCleanup) {
|
|
5679
|
-
this.
|
|
5731
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
5680
5732
|
}
|
|
5681
5733
|
if (plugin.clearDraw) {
|
|
5682
|
-
this.
|
|
5734
|
+
this.#clearDrawPlugins.push(plugin);
|
|
5683
5735
|
}
|
|
5684
5736
|
}
|
|
5685
5737
|
}
|
|
5686
5738
|
initUpdaters() {
|
|
5687
|
-
this
|
|
5688
|
-
this
|
|
5689
|
-
for (const updater of this.
|
|
5739
|
+
this.#preDrawUpdaters = [];
|
|
5740
|
+
this.#postDrawUpdaters = [];
|
|
5741
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5690
5742
|
if (updater.afterDraw) {
|
|
5691
|
-
this.
|
|
5743
|
+
this.#postDrawUpdaters.push(updater);
|
|
5692
5744
|
}
|
|
5693
5745
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
5694
|
-
this.
|
|
5746
|
+
this.#preDrawUpdaters.push(updater);
|
|
5695
5747
|
}
|
|
5696
5748
|
}
|
|
5697
5749
|
}
|
|
5698
5750
|
paint() {
|
|
5699
5751
|
let handled = false;
|
|
5700
|
-
for (const plugin of this
|
|
5752
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
5701
5753
|
handled = plugin.canvasPaint?.() ?? false;
|
|
5702
5754
|
if (handled) {
|
|
5703
5755
|
break;
|
|
@@ -5710,35 +5762,35 @@
|
|
|
5710
5762
|
}
|
|
5711
5763
|
paintBase(baseColor) {
|
|
5712
5764
|
this.draw(ctx => {
|
|
5713
|
-
paintBase(ctx, this.
|
|
5765
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
5714
5766
|
});
|
|
5715
5767
|
}
|
|
5716
5768
|
paintImage(image, opacity) {
|
|
5717
5769
|
this.draw(ctx => {
|
|
5718
|
-
paintImage(ctx, this.
|
|
5770
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
5719
5771
|
});
|
|
5720
5772
|
}
|
|
5721
5773
|
setContext(context) {
|
|
5722
|
-
this
|
|
5723
|
-
if (this
|
|
5724
|
-
this.
|
|
5774
|
+
this.#context = context;
|
|
5775
|
+
if (this.#context) {
|
|
5776
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
5725
5777
|
}
|
|
5726
5778
|
}
|
|
5727
5779
|
setContextSettings(settings) {
|
|
5728
|
-
this
|
|
5780
|
+
this.#contextSettings = settings;
|
|
5729
5781
|
}
|
|
5730
5782
|
stop() {
|
|
5731
5783
|
this.draw(ctx => {
|
|
5732
|
-
clear(ctx, this.
|
|
5784
|
+
clear(ctx, this.#canvasManager.size);
|
|
5733
5785
|
});
|
|
5734
5786
|
}
|
|
5735
|
-
|
|
5736
|
-
for (const updater of this
|
|
5787
|
+
#applyPostDrawUpdaters = particle => {
|
|
5788
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
5737
5789
|
updater.afterDraw?.(particle);
|
|
5738
5790
|
}
|
|
5739
5791
|
};
|
|
5740
|
-
|
|
5741
|
-
for (const updater of this
|
|
5792
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
5793
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
5742
5794
|
if (updater.getColorStyles) {
|
|
5743
5795
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
5744
5796
|
if (fill) {
|
|
@@ -5757,22 +5809,22 @@
|
|
|
5757
5809
|
updater.beforeDraw?.(particle);
|
|
5758
5810
|
}
|
|
5759
5811
|
};
|
|
5760
|
-
|
|
5812
|
+
#getPluginParticleColors = particle => {
|
|
5761
5813
|
let fColor, sColor;
|
|
5762
|
-
for (const plugin of this
|
|
5814
|
+
for (const plugin of this.#colorPlugins) {
|
|
5763
5815
|
if (!fColor && plugin.particleFillColor) {
|
|
5764
|
-
fColor = rangeColorToHsl(this
|
|
5816
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
5765
5817
|
}
|
|
5766
5818
|
if (!sColor && plugin.particleStrokeColor) {
|
|
5767
|
-
sColor = rangeColorToHsl(this
|
|
5819
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
5768
5820
|
}
|
|
5769
5821
|
if (fColor && sColor) {
|
|
5770
5822
|
break;
|
|
5771
5823
|
}
|
|
5772
5824
|
}
|
|
5773
|
-
this
|
|
5774
|
-
this
|
|
5775
|
-
return this
|
|
5825
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
5826
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
5827
|
+
return this.#reusablePluginColors;
|
|
5776
5828
|
};
|
|
5777
5829
|
}
|
|
5778
5830
|
|
|
@@ -5830,53 +5882,53 @@
|
|
|
5830
5882
|
renderCanvas;
|
|
5831
5883
|
size;
|
|
5832
5884
|
zoom = defaultZoom;
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5885
|
+
#container;
|
|
5886
|
+
#generated;
|
|
5887
|
+
#mutationObserver;
|
|
5888
|
+
#originalStyle;
|
|
5889
|
+
#pluginManager;
|
|
5890
|
+
#pointerEvents;
|
|
5891
|
+
#resizePlugins;
|
|
5892
|
+
#standardSize;
|
|
5893
|
+
#zoomCenter;
|
|
5842
5894
|
constructor(pluginManager, container) {
|
|
5843
|
-
this
|
|
5844
|
-
this
|
|
5895
|
+
this.#pluginManager = pluginManager;
|
|
5896
|
+
this.#container = container;
|
|
5845
5897
|
this.render = new RenderManager(pluginManager, container, this);
|
|
5846
|
-
this
|
|
5898
|
+
this.#standardSize = {
|
|
5847
5899
|
height: 0,
|
|
5848
5900
|
width: 0,
|
|
5849
5901
|
};
|
|
5850
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
5902
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
5851
5903
|
this.size = {
|
|
5852
5904
|
height: stdSize.height * pxRatio,
|
|
5853
5905
|
width: stdSize.width * pxRatio,
|
|
5854
5906
|
};
|
|
5855
|
-
this
|
|
5856
|
-
this
|
|
5857
|
-
this
|
|
5907
|
+
this.#generated = false;
|
|
5908
|
+
this.#resizePlugins = [];
|
|
5909
|
+
this.#pointerEvents = "none";
|
|
5858
5910
|
}
|
|
5859
|
-
get
|
|
5860
|
-
return this.
|
|
5911
|
+
get #fullScreen() {
|
|
5912
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
5861
5913
|
}
|
|
5862
5914
|
destroy() {
|
|
5863
5915
|
this.stop();
|
|
5864
|
-
if (this
|
|
5916
|
+
if (this.#generated) {
|
|
5865
5917
|
const element = this.domElement;
|
|
5866
5918
|
element?.remove();
|
|
5867
5919
|
this.domElement = undefined;
|
|
5868
5920
|
this.renderCanvas = undefined;
|
|
5869
5921
|
}
|
|
5870
5922
|
else {
|
|
5871
|
-
this
|
|
5923
|
+
this.#resetOriginalStyle();
|
|
5872
5924
|
}
|
|
5873
5925
|
this.render.destroy();
|
|
5874
|
-
this
|
|
5926
|
+
this.#resizePlugins = [];
|
|
5875
5927
|
}
|
|
5876
5928
|
getZoomCenter() {
|
|
5877
|
-
const pxRatio = this.
|
|
5878
|
-
if (this
|
|
5879
|
-
return this
|
|
5929
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
5930
|
+
if (this.#zoomCenter) {
|
|
5931
|
+
return this.#zoomCenter;
|
|
5880
5932
|
}
|
|
5881
5933
|
return {
|
|
5882
5934
|
x: (width * half) / pxRatio,
|
|
@@ -5884,20 +5936,20 @@
|
|
|
5884
5936
|
};
|
|
5885
5937
|
}
|
|
5886
5938
|
init() {
|
|
5887
|
-
this
|
|
5939
|
+
this.#safeMutationObserver(obs => {
|
|
5888
5940
|
obs.disconnect();
|
|
5889
5941
|
});
|
|
5890
|
-
this
|
|
5942
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
5891
5943
|
for (const record of records) {
|
|
5892
5944
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
5893
|
-
this
|
|
5945
|
+
this.#repairStyle();
|
|
5894
5946
|
}
|
|
5895
5947
|
}
|
|
5896
5948
|
});
|
|
5897
5949
|
this.resize();
|
|
5898
|
-
this
|
|
5950
|
+
this.#initStyle();
|
|
5899
5951
|
this.initBackground();
|
|
5900
|
-
this
|
|
5952
|
+
this.#safeMutationObserver(obs => {
|
|
5901
5953
|
const element = this.domElement;
|
|
5902
5954
|
if (!element || !(element instanceof Node)) {
|
|
5903
5955
|
return;
|
|
@@ -5908,13 +5960,13 @@
|
|
|
5908
5960
|
this.render.init();
|
|
5909
5961
|
}
|
|
5910
5962
|
initBackground() {
|
|
5911
|
-
const
|
|
5963
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
5912
5964
|
if (!element) {
|
|
5913
5965
|
return;
|
|
5914
5966
|
}
|
|
5915
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
5967
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
5916
5968
|
if (color) {
|
|
5917
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
5969
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
5918
5970
|
}
|
|
5919
5971
|
else {
|
|
5920
5972
|
elementStyle.backgroundColor = "";
|
|
@@ -5925,27 +5977,27 @@
|
|
|
5925
5977
|
elementStyle.backgroundSize = background.size || "";
|
|
5926
5978
|
}
|
|
5927
5979
|
initPlugins() {
|
|
5928
|
-
this
|
|
5929
|
-
for (const plugin of this.
|
|
5980
|
+
this.#resizePlugins = [];
|
|
5981
|
+
for (const plugin of this.#container.plugins) {
|
|
5930
5982
|
if (plugin.resize) {
|
|
5931
|
-
this.
|
|
5983
|
+
this.#resizePlugins.push(plugin);
|
|
5932
5984
|
}
|
|
5933
5985
|
}
|
|
5934
5986
|
}
|
|
5935
5987
|
loadCanvas(canvas) {
|
|
5936
|
-
if (this
|
|
5988
|
+
if (this.#generated && this.domElement) {
|
|
5937
5989
|
this.domElement.remove();
|
|
5938
5990
|
}
|
|
5939
|
-
const container = this
|
|
5991
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
5940
5992
|
this.domElement = domCanvas;
|
|
5941
|
-
this
|
|
5993
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
5942
5994
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
5943
5995
|
const domElement = this.domElement;
|
|
5944
5996
|
if (domElement) {
|
|
5945
5997
|
domElement.ariaHidden = "true";
|
|
5946
|
-
this
|
|
5998
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
5947
5999
|
}
|
|
5948
|
-
const standardSize = this
|
|
6000
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
5949
6001
|
if (domElement) {
|
|
5950
6002
|
standardSize.height = domElement.offsetHeight;
|
|
5951
6003
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -5954,7 +6006,7 @@
|
|
|
5954
6006
|
standardSize.height = renderCanvas.height;
|
|
5955
6007
|
standardSize.width = renderCanvas.width;
|
|
5956
6008
|
}
|
|
5957
|
-
const pxRatio = this.
|
|
6009
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
5958
6010
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
5959
6011
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
5960
6012
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -5965,12 +6017,12 @@
|
|
|
5965
6017
|
willReadFrequently: false,
|
|
5966
6018
|
});
|
|
5967
6019
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
5968
|
-
this
|
|
6020
|
+
this.#safeMutationObserver(obs => {
|
|
5969
6021
|
obs.disconnect();
|
|
5970
6022
|
});
|
|
5971
6023
|
container.retina.init();
|
|
5972
6024
|
this.initBackground();
|
|
5973
|
-
this
|
|
6025
|
+
this.#safeMutationObserver(obs => {
|
|
5974
6026
|
const element = this.domElement;
|
|
5975
6027
|
if (!element || !(element instanceof Node)) {
|
|
5976
6028
|
return;
|
|
@@ -5983,11 +6035,11 @@
|
|
|
5983
6035
|
if (!element) {
|
|
5984
6036
|
return false;
|
|
5985
6037
|
}
|
|
5986
|
-
const container = this
|
|
6038
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
5987
6039
|
if (renderCanvas === undefined) {
|
|
5988
6040
|
return false;
|
|
5989
6041
|
}
|
|
5990
|
-
const currentSize = container.canvas
|
|
6042
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
5991
6043
|
width: element.offsetWidth,
|
|
5992
6044
|
height: element.offsetHeight,
|
|
5993
6045
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -6006,7 +6058,7 @@
|
|
|
6006
6058
|
const canvasSize = this.size;
|
|
6007
6059
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
6008
6060
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
6009
|
-
if (this.
|
|
6061
|
+
if (this.#container.started) {
|
|
6010
6062
|
container.particles.setResizeFactor({
|
|
6011
6063
|
width: currentSize.width / oldSize.width,
|
|
6012
6064
|
height: currentSize.height / oldSize.height,
|
|
@@ -6019,46 +6071,46 @@
|
|
|
6019
6071
|
if (!element) {
|
|
6020
6072
|
return;
|
|
6021
6073
|
}
|
|
6022
|
-
this
|
|
6023
|
-
this
|
|
6074
|
+
this.#pointerEvents = type;
|
|
6075
|
+
this.#repairStyle();
|
|
6024
6076
|
}
|
|
6025
6077
|
setZoom(zoomLevel, center) {
|
|
6026
6078
|
this.zoom = zoomLevel;
|
|
6027
|
-
this
|
|
6079
|
+
this.#zoomCenter = center;
|
|
6028
6080
|
}
|
|
6029
6081
|
stop() {
|
|
6030
|
-
this
|
|
6082
|
+
this.#safeMutationObserver(obs => {
|
|
6031
6083
|
obs.disconnect();
|
|
6032
6084
|
});
|
|
6033
|
-
this
|
|
6085
|
+
this.#mutationObserver = undefined;
|
|
6034
6086
|
this.render.stop();
|
|
6035
6087
|
}
|
|
6036
6088
|
async windowResize() {
|
|
6037
6089
|
if (!this.domElement || !this.resize()) {
|
|
6038
6090
|
return;
|
|
6039
6091
|
}
|
|
6040
|
-
const container = this
|
|
6092
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
6041
6093
|
container.particles.setDensity();
|
|
6042
|
-
this
|
|
6094
|
+
this.#applyResizePlugins();
|
|
6043
6095
|
if (needsRefresh) {
|
|
6044
6096
|
await container.refresh();
|
|
6045
6097
|
}
|
|
6046
6098
|
}
|
|
6047
|
-
|
|
6048
|
-
for (const plugin of this
|
|
6099
|
+
#applyResizePlugins = () => {
|
|
6100
|
+
for (const plugin of this.#resizePlugins) {
|
|
6049
6101
|
plugin.resize?.();
|
|
6050
6102
|
}
|
|
6051
6103
|
};
|
|
6052
|
-
|
|
6053
|
-
const element = this.domElement, options = this.
|
|
6104
|
+
#initStyle = () => {
|
|
6105
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
6054
6106
|
if (!element) {
|
|
6055
6107
|
return;
|
|
6056
6108
|
}
|
|
6057
|
-
if (this
|
|
6058
|
-
this
|
|
6109
|
+
if (this.#fullScreen) {
|
|
6110
|
+
this.#setFullScreenStyle();
|
|
6059
6111
|
}
|
|
6060
6112
|
else {
|
|
6061
|
-
this
|
|
6113
|
+
this.#resetOriginalStyle();
|
|
6062
6114
|
}
|
|
6063
6115
|
for (const key in options.style) {
|
|
6064
6116
|
if (!key || !(key in options.style)) {
|
|
@@ -6071,72 +6123,72 @@
|
|
|
6071
6123
|
element.style.setProperty(key, value, "important");
|
|
6072
6124
|
}
|
|
6073
6125
|
};
|
|
6074
|
-
|
|
6126
|
+
#repairStyle = () => {
|
|
6075
6127
|
const element = this.domElement;
|
|
6076
6128
|
if (!element) {
|
|
6077
6129
|
return;
|
|
6078
6130
|
}
|
|
6079
|
-
this
|
|
6131
|
+
this.#safeMutationObserver(observer => {
|
|
6080
6132
|
observer.disconnect();
|
|
6081
6133
|
});
|
|
6082
|
-
this
|
|
6134
|
+
this.#initStyle();
|
|
6083
6135
|
this.initBackground();
|
|
6084
|
-
const pointerEvents = this
|
|
6136
|
+
const pointerEvents = this.#pointerEvents;
|
|
6085
6137
|
element.style.pointerEvents = pointerEvents;
|
|
6086
6138
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
6087
|
-
this
|
|
6139
|
+
this.#safeMutationObserver(observer => {
|
|
6088
6140
|
if (!(element instanceof Node)) {
|
|
6089
6141
|
return;
|
|
6090
6142
|
}
|
|
6091
6143
|
observer.observe(element, { attributes: true });
|
|
6092
6144
|
});
|
|
6093
6145
|
};
|
|
6094
|
-
|
|
6095
|
-
const element = this.domElement, originalStyle = this
|
|
6146
|
+
#resetOriginalStyle = () => {
|
|
6147
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
6096
6148
|
if (!element || !originalStyle) {
|
|
6097
6149
|
return;
|
|
6098
6150
|
}
|
|
6099
6151
|
setStyle(element, originalStyle, true);
|
|
6100
6152
|
};
|
|
6101
|
-
|
|
6102
|
-
if (!this
|
|
6153
|
+
#safeMutationObserver = callback => {
|
|
6154
|
+
if (!this.#mutationObserver) {
|
|
6103
6155
|
return;
|
|
6104
6156
|
}
|
|
6105
|
-
callback(this
|
|
6157
|
+
callback(this.#mutationObserver);
|
|
6106
6158
|
};
|
|
6107
|
-
|
|
6159
|
+
#setFullScreenStyle = () => {
|
|
6108
6160
|
const element = this.domElement;
|
|
6109
6161
|
if (!element) {
|
|
6110
6162
|
return;
|
|
6111
6163
|
}
|
|
6112
|
-
setStyle(element, getFullScreenStyle(this.
|
|
6164
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
6113
6165
|
};
|
|
6114
6166
|
}
|
|
6115
6167
|
|
|
6116
6168
|
class EventListeners {
|
|
6117
|
-
container;
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
|
|
6169
|
+
#container;
|
|
6170
|
+
#handlers;
|
|
6171
|
+
#resizeObserver;
|
|
6172
|
+
#resizeTimeout;
|
|
6121
6173
|
constructor(container) {
|
|
6122
|
-
this
|
|
6123
|
-
this
|
|
6174
|
+
this.#container = container;
|
|
6175
|
+
this.#handlers = {
|
|
6124
6176
|
visibilityChange: () => {
|
|
6125
|
-
this
|
|
6177
|
+
this.#handleVisibilityChange();
|
|
6126
6178
|
},
|
|
6127
6179
|
resize: () => {
|
|
6128
|
-
this
|
|
6180
|
+
this.#handleWindowResize();
|
|
6129
6181
|
},
|
|
6130
6182
|
};
|
|
6131
6183
|
}
|
|
6132
6184
|
addListeners() {
|
|
6133
|
-
this
|
|
6185
|
+
this.#manageListeners(true);
|
|
6134
6186
|
}
|
|
6135
6187
|
removeListeners() {
|
|
6136
|
-
this
|
|
6188
|
+
this.#manageListeners(false);
|
|
6137
6189
|
}
|
|
6138
|
-
|
|
6139
|
-
const container = this
|
|
6190
|
+
#handleVisibilityChange = () => {
|
|
6191
|
+
const container = this.#container, options = container.actualOptions;
|
|
6140
6192
|
if (!options.pauseOnBlur) {
|
|
6141
6193
|
return;
|
|
6142
6194
|
}
|
|
@@ -6154,24 +6206,24 @@
|
|
|
6154
6206
|
}
|
|
6155
6207
|
}
|
|
6156
6208
|
};
|
|
6157
|
-
|
|
6158
|
-
if (this
|
|
6159
|
-
clearTimeout(this
|
|
6160
|
-
|
|
6209
|
+
#handleWindowResize = () => {
|
|
6210
|
+
if (this.#resizeTimeout) {
|
|
6211
|
+
clearTimeout(this.#resizeTimeout);
|
|
6212
|
+
this.#resizeTimeout = undefined;
|
|
6161
6213
|
}
|
|
6162
6214
|
const handleResize = async () => {
|
|
6163
|
-
const canvas = this
|
|
6215
|
+
const canvas = this.#container.canvas;
|
|
6164
6216
|
await canvas.windowResize();
|
|
6165
6217
|
};
|
|
6166
|
-
this
|
|
6218
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
6167
6219
|
};
|
|
6168
|
-
|
|
6169
|
-
const handlers = this
|
|
6170
|
-
this
|
|
6220
|
+
#manageListeners = add => {
|
|
6221
|
+
const handlers = this.#handlers;
|
|
6222
|
+
this.#manageResize(add);
|
|
6171
6223
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
6172
6224
|
};
|
|
6173
|
-
|
|
6174
|
-
const handlers = this
|
|
6225
|
+
#manageResize = add => {
|
|
6226
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
6175
6227
|
if (!options.resize.enable) {
|
|
6176
6228
|
return;
|
|
6177
6229
|
}
|
|
@@ -6180,22 +6232,22 @@
|
|
|
6180
6232
|
return;
|
|
6181
6233
|
}
|
|
6182
6234
|
const canvasEl = container.canvas.domElement;
|
|
6183
|
-
if (this
|
|
6235
|
+
if (this.#resizeObserver && !add) {
|
|
6184
6236
|
if (canvasEl) {
|
|
6185
|
-
this.
|
|
6237
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
6186
6238
|
}
|
|
6187
|
-
this.
|
|
6188
|
-
|
|
6239
|
+
this.#resizeObserver.disconnect();
|
|
6240
|
+
this.#resizeObserver = undefined;
|
|
6189
6241
|
}
|
|
6190
|
-
else if (!this
|
|
6191
|
-
this
|
|
6242
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
6243
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
6192
6244
|
const entry = entries.find(e => e.target === canvasEl);
|
|
6193
6245
|
if (!entry) {
|
|
6194
6246
|
return;
|
|
6195
6247
|
}
|
|
6196
|
-
this
|
|
6248
|
+
this.#handleWindowResize();
|
|
6197
6249
|
});
|
|
6198
|
-
this.
|
|
6250
|
+
this.#resizeObserver.observe(canvasEl);
|
|
6199
6251
|
}
|
|
6200
6252
|
};
|
|
6201
6253
|
}
|
|
@@ -6268,24 +6320,24 @@
|
|
|
6268
6320
|
unbreakable;
|
|
6269
6321
|
velocity;
|
|
6270
6322
|
zIndexFactor;
|
|
6271
|
-
|
|
6323
|
+
#cachedOpacityData = {
|
|
6272
6324
|
fillOpacity: defaultOpacity$1,
|
|
6273
6325
|
opacity: defaultOpacity$1,
|
|
6274
6326
|
strokeOpacity: defaultOpacity$1,
|
|
6275
6327
|
};
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6328
|
+
#cachedPosition = Vector3d.origin;
|
|
6329
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
6330
|
+
#cachedTransform = {
|
|
6279
6331
|
a: 1,
|
|
6280
6332
|
b: 0,
|
|
6281
6333
|
c: 0,
|
|
6282
6334
|
d: 1,
|
|
6283
6335
|
};
|
|
6284
|
-
|
|
6285
|
-
|
|
6336
|
+
#container;
|
|
6337
|
+
#pluginManager;
|
|
6286
6338
|
constructor(pluginManager, container) {
|
|
6287
|
-
this
|
|
6288
|
-
this
|
|
6339
|
+
this.#pluginManager = pluginManager;
|
|
6340
|
+
this.#container = container;
|
|
6289
6341
|
}
|
|
6290
6342
|
destroy(override) {
|
|
6291
6343
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -6294,7 +6346,7 @@
|
|
|
6294
6346
|
this.destroyed = true;
|
|
6295
6347
|
this.bubble.inRange = false;
|
|
6296
6348
|
this.slow.inRange = false;
|
|
6297
|
-
const container = this
|
|
6349
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
6298
6350
|
shapeDrawer?.particleDestroy?.(this);
|
|
6299
6351
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
6300
6352
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -6302,12 +6354,12 @@
|
|
|
6302
6354
|
for (const updater of container.particleUpdaters) {
|
|
6303
6355
|
updater.particleDestroyed?.(this, override);
|
|
6304
6356
|
}
|
|
6305
|
-
this.
|
|
6357
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
6306
6358
|
particle: this,
|
|
6307
6359
|
});
|
|
6308
6360
|
}
|
|
6309
6361
|
draw(delta) {
|
|
6310
|
-
const container = this
|
|
6362
|
+
const container = this.#container, render = container.canvas.render;
|
|
6311
6363
|
render.drawParticlePlugins(this, delta);
|
|
6312
6364
|
render.drawParticle(this, delta);
|
|
6313
6365
|
}
|
|
@@ -6315,50 +6367,50 @@
|
|
|
6315
6367
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
6316
6368
|
}
|
|
6317
6369
|
getFillColor() {
|
|
6318
|
-
return this
|
|
6370
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
6319
6371
|
}
|
|
6320
6372
|
getMass() {
|
|
6321
6373
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
6322
6374
|
}
|
|
6323
6375
|
getOpacity() {
|
|
6324
6376
|
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;
|
|
6325
|
-
this.
|
|
6326
|
-
this.
|
|
6327
|
-
this.
|
|
6328
|
-
return this
|
|
6377
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
6378
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
6379
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
6380
|
+
return this.#cachedOpacityData;
|
|
6329
6381
|
}
|
|
6330
6382
|
getPosition() {
|
|
6331
|
-
this.
|
|
6332
|
-
this.
|
|
6333
|
-
this.
|
|
6334
|
-
return this
|
|
6383
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
6384
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
6385
|
+
this.#cachedPosition.z = this.position.z;
|
|
6386
|
+
return this.#cachedPosition;
|
|
6335
6387
|
}
|
|
6336
6388
|
getRadius() {
|
|
6337
6389
|
return this.bubble.radius ?? this.size.value;
|
|
6338
6390
|
}
|
|
6339
6391
|
getRotateData() {
|
|
6340
6392
|
const angle = this.getAngle();
|
|
6341
|
-
this.
|
|
6342
|
-
this.
|
|
6343
|
-
return this
|
|
6393
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
6394
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
6395
|
+
return this.#cachedRotateData;
|
|
6344
6396
|
}
|
|
6345
6397
|
getStrokeColor() {
|
|
6346
|
-
return this
|
|
6398
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
6347
6399
|
}
|
|
6348
6400
|
getTransformData(externalTransform) {
|
|
6349
6401
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
6350
|
-
this.
|
|
6351
|
-
this.
|
|
6402
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform$1.a);
|
|
6403
|
+
this.#cachedTransform.b = rotating
|
|
6352
6404
|
? rotateData.sin * (externalTransform.b ?? identity$2)
|
|
6353
6405
|
: (externalTransform.b ?? defaultTransform$1.b);
|
|
6354
|
-
this.
|
|
6406
|
+
this.#cachedTransform.c = rotating
|
|
6355
6407
|
? -rotateData.sin * (externalTransform.c ?? identity$2)
|
|
6356
6408
|
: (externalTransform.c ?? defaultTransform$1.c);
|
|
6357
|
-
this.
|
|
6358
|
-
return this
|
|
6409
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform$1.d);
|
|
6410
|
+
return this.#cachedTransform;
|
|
6359
6411
|
}
|
|
6360
6412
|
init(id, position, overrideOptions, group) {
|
|
6361
|
-
const container = this
|
|
6413
|
+
const container = this.#container;
|
|
6362
6414
|
this.id = id;
|
|
6363
6415
|
this.group = group;
|
|
6364
6416
|
this.justWarped = false;
|
|
@@ -6378,21 +6430,27 @@
|
|
|
6378
6430
|
moveSpeed: 0,
|
|
6379
6431
|
sizeAnimationSpeed: 0,
|
|
6380
6432
|
};
|
|
6433
|
+
this.size = {
|
|
6434
|
+
value: 1,
|
|
6435
|
+
max: 1,
|
|
6436
|
+
min: 1,
|
|
6437
|
+
enable: false,
|
|
6438
|
+
};
|
|
6381
6439
|
this.outType = ParticleOutType.normal;
|
|
6382
6440
|
this.ignoresResizeRatio = true;
|
|
6383
|
-
const
|
|
6441
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
6384
6442
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
6385
6443
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
6386
6444
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
6387
6445
|
if (overrideOptions) {
|
|
6388
|
-
if (overrideOptions.effect?.type) {
|
|
6446
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
6389
6447
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
6390
6448
|
if (effect) {
|
|
6391
6449
|
this.effect = effect;
|
|
6392
6450
|
effectOptions.load(overrideOptions.effect);
|
|
6393
6451
|
}
|
|
6394
6452
|
}
|
|
6395
|
-
if (overrideOptions.shape?.type) {
|
|
6453
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
6396
6454
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
6397
6455
|
if (shape) {
|
|
6398
6456
|
this.shape = shape;
|
|
@@ -6401,21 +6459,20 @@
|
|
|
6401
6459
|
}
|
|
6402
6460
|
}
|
|
6403
6461
|
if (this.effect === randomColorValue) {
|
|
6404
|
-
const availableEffects = [...this.
|
|
6462
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
6405
6463
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
6406
6464
|
}
|
|
6407
6465
|
if (this.shape === randomColorValue) {
|
|
6408
|
-
const availableShapes = [...this.
|
|
6466
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
6409
6467
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
6410
6468
|
}
|
|
6411
6469
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
6412
6470
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
6413
6471
|
particlesOptions.load(overrideOptions);
|
|
6414
|
-
const effectData = this.effectData;
|
|
6472
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
6415
6473
|
if (effectData) {
|
|
6416
6474
|
particlesOptions.load(effectData.particles);
|
|
6417
6475
|
}
|
|
6418
|
-
const shapeData = this.shapeData;
|
|
6419
6476
|
if (shapeData) {
|
|
6420
6477
|
particlesOptions.load(shapeData.particles);
|
|
6421
6478
|
}
|
|
@@ -6423,7 +6480,9 @@
|
|
|
6423
6480
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
6424
6481
|
this.options = particlesOptions;
|
|
6425
6482
|
container.retina.initParticle(this);
|
|
6426
|
-
|
|
6483
|
+
for (const updater of container.particleUpdaters) {
|
|
6484
|
+
updater.preInit?.(this);
|
|
6485
|
+
}
|
|
6427
6486
|
this.bubble = {
|
|
6428
6487
|
inRange: false,
|
|
6429
6488
|
};
|
|
@@ -6431,8 +6490,8 @@
|
|
|
6431
6490
|
inRange: false,
|
|
6432
6491
|
factor: 1,
|
|
6433
6492
|
};
|
|
6434
|
-
this
|
|
6435
|
-
this.initialVelocity = this
|
|
6493
|
+
this.#initPosition(position);
|
|
6494
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
6436
6495
|
this.velocity = this.initialVelocity.copy();
|
|
6437
6496
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
6438
6497
|
this.sides = 24;
|
|
@@ -6463,12 +6522,11 @@
|
|
|
6463
6522
|
plugin.particleCreated?.(this);
|
|
6464
6523
|
}
|
|
6465
6524
|
}
|
|
6466
|
-
isInsideCanvas() {
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
position.x <= canvasSize.width + radius);
|
|
6525
|
+
isInsideCanvas(direction) {
|
|
6526
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
6527
|
+
}
|
|
6528
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
6529
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
6472
6530
|
}
|
|
6473
6531
|
isShowingBack() {
|
|
6474
6532
|
if (!this.roll) {
|
|
@@ -6493,13 +6551,13 @@
|
|
|
6493
6551
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
6494
6552
|
}
|
|
6495
6553
|
reset() {
|
|
6496
|
-
for (const updater of this.
|
|
6554
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6497
6555
|
updater.reset?.(this);
|
|
6498
6556
|
}
|
|
6499
6557
|
}
|
|
6500
|
-
|
|
6558
|
+
#calcPosition = (position, zIndex) => {
|
|
6501
6559
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
6502
|
-
const container = this
|
|
6560
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
6503
6561
|
while (!signal.aborted) {
|
|
6504
6562
|
for (const plugin of plugins) {
|
|
6505
6563
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -6511,10 +6569,10 @@
|
|
|
6511
6569
|
size: canvasSize,
|
|
6512
6570
|
position: posVec,
|
|
6513
6571
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
6514
|
-
this
|
|
6515
|
-
this
|
|
6516
|
-
this
|
|
6517
|
-
this
|
|
6572
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
6573
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
6574
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
6575
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
6518
6576
|
let isValidPosition = true;
|
|
6519
6577
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
6520
6578
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -6530,8 +6588,8 @@
|
|
|
6530
6588
|
}
|
|
6531
6589
|
return posVec;
|
|
6532
6590
|
};
|
|
6533
|
-
|
|
6534
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
6591
|
+
#calculateVelocity = () => {
|
|
6592
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
6535
6593
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
6536
6594
|
return res;
|
|
6537
6595
|
}
|
|
@@ -6547,27 +6605,86 @@
|
|
|
6547
6605
|
}
|
|
6548
6606
|
return res;
|
|
6549
6607
|
};
|
|
6550
|
-
|
|
6608
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
6551
6609
|
fixOutMode({
|
|
6552
6610
|
outMode,
|
|
6553
6611
|
checkModes: [OutMode.bounce],
|
|
6554
6612
|
coord: pos.x,
|
|
6555
|
-
maxCoord: this.
|
|
6613
|
+
maxCoord: this.#container.canvas.size.width,
|
|
6556
6614
|
setCb: (value) => (pos.x += value),
|
|
6557
6615
|
radius,
|
|
6558
6616
|
});
|
|
6559
6617
|
};
|
|
6560
|
-
|
|
6618
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
6561
6619
|
fixOutMode({
|
|
6562
6620
|
outMode,
|
|
6563
6621
|
checkModes: [OutMode.bounce],
|
|
6564
6622
|
coord: pos.y,
|
|
6565
|
-
maxCoord: this.
|
|
6623
|
+
maxCoord: this.#container.canvas.size.height,
|
|
6566
6624
|
setCb: (value) => (pos.y += value),
|
|
6567
6625
|
radius,
|
|
6568
6626
|
});
|
|
6569
6627
|
};
|
|
6570
|
-
|
|
6628
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
6629
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
6630
|
+
if (direction === OutModeDirection.bottom) {
|
|
6631
|
+
return {
|
|
6632
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
6633
|
+
reason: "default",
|
|
6634
|
+
};
|
|
6635
|
+
}
|
|
6636
|
+
if (direction === OutModeDirection.left) {
|
|
6637
|
+
return {
|
|
6638
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
6639
|
+
reason: "default",
|
|
6640
|
+
};
|
|
6641
|
+
}
|
|
6642
|
+
if (direction === OutModeDirection.right) {
|
|
6643
|
+
return {
|
|
6644
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
6645
|
+
reason: "default",
|
|
6646
|
+
};
|
|
6647
|
+
}
|
|
6648
|
+
if (direction === OutModeDirection.top) {
|
|
6649
|
+
return {
|
|
6650
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
6651
|
+
reason: "default",
|
|
6652
|
+
};
|
|
6653
|
+
}
|
|
6654
|
+
return {
|
|
6655
|
+
inside: position.x >= -radius &&
|
|
6656
|
+
position.y >= -radius &&
|
|
6657
|
+
position.y <= canvasSize.height + radius &&
|
|
6658
|
+
position.x <= canvasSize.width + radius,
|
|
6659
|
+
reason: "default",
|
|
6660
|
+
};
|
|
6661
|
+
};
|
|
6662
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
6663
|
+
return {
|
|
6664
|
+
canvasSize: this.#container.canvas.size,
|
|
6665
|
+
direction,
|
|
6666
|
+
outMode,
|
|
6667
|
+
particle: this,
|
|
6668
|
+
radius: this.getRadius(),
|
|
6669
|
+
};
|
|
6670
|
+
};
|
|
6671
|
+
#getInsideCanvasResult = (data) => {
|
|
6672
|
+
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;
|
|
6673
|
+
if (!shapeCheck && !effectCheck) {
|
|
6674
|
+
return defaultResult;
|
|
6675
|
+
}
|
|
6676
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
6677
|
+
if (shapeResult && effectResult) {
|
|
6678
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
6679
|
+
return {
|
|
6680
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
6681
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
6682
|
+
reason: "combined",
|
|
6683
|
+
};
|
|
6684
|
+
}
|
|
6685
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
6686
|
+
};
|
|
6687
|
+
#getRollColor = color => {
|
|
6571
6688
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
6572
6689
|
return color;
|
|
6573
6690
|
}
|
|
@@ -6582,8 +6699,8 @@
|
|
|
6582
6699
|
}
|
|
6583
6700
|
return color;
|
|
6584
6701
|
};
|
|
6585
|
-
|
|
6586
|
-
const container = this
|
|
6702
|
+
#initPosition = position => {
|
|
6703
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
6587
6704
|
if (!initialPosition) {
|
|
6588
6705
|
throw new Error("a valid position cannot be found for particle");
|
|
6589
6706
|
}
|
|
@@ -6606,45 +6723,58 @@
|
|
|
6606
6723
|
}
|
|
6607
6724
|
this.offset = Vector.origin;
|
|
6608
6725
|
};
|
|
6726
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
6727
|
+
if (typeof result === "boolean") {
|
|
6728
|
+
return {
|
|
6729
|
+
inside: result,
|
|
6730
|
+
reason,
|
|
6731
|
+
};
|
|
6732
|
+
}
|
|
6733
|
+
return {
|
|
6734
|
+
inside: result.inside,
|
|
6735
|
+
margin: result.margin,
|
|
6736
|
+
reason: result.reason ?? reason,
|
|
6737
|
+
};
|
|
6738
|
+
};
|
|
6609
6739
|
}
|
|
6610
6740
|
|
|
6611
6741
|
class SpatialHashGrid {
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6742
|
+
#cellSize;
|
|
6743
|
+
#cells = new Map();
|
|
6744
|
+
#circlePool = [];
|
|
6745
|
+
#circlePoolIdx;
|
|
6746
|
+
#pendingCellSize;
|
|
6747
|
+
#rectanglePool = [];
|
|
6748
|
+
#rectanglePoolIdx;
|
|
6619
6749
|
constructor(cellSize) {
|
|
6620
|
-
this
|
|
6621
|
-
this
|
|
6622
|
-
this
|
|
6750
|
+
this.#cellSize = cellSize;
|
|
6751
|
+
this.#circlePoolIdx = 0;
|
|
6752
|
+
this.#rectanglePoolIdx = 0;
|
|
6623
6753
|
}
|
|
6624
6754
|
clear() {
|
|
6625
|
-
this.
|
|
6626
|
-
const pendingCellSize = this
|
|
6755
|
+
this.#cells.clear();
|
|
6756
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
6627
6757
|
if (pendingCellSize) {
|
|
6628
|
-
this
|
|
6758
|
+
this.#cellSize = pendingCellSize;
|
|
6629
6759
|
}
|
|
6630
|
-
this
|
|
6760
|
+
this.#pendingCellSize = undefined;
|
|
6631
6761
|
}
|
|
6632
6762
|
insert(particle) {
|
|
6633
|
-
const { x, y } = particle.getPosition(), key = this
|
|
6634
|
-
if (!this.
|
|
6635
|
-
this.
|
|
6763
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
6764
|
+
if (!this.#cells.has(key)) {
|
|
6765
|
+
this.#cells.set(key, []);
|
|
6636
6766
|
}
|
|
6637
|
-
this.
|
|
6767
|
+
this.#cells.get(key)?.push(particle);
|
|
6638
6768
|
}
|
|
6639
6769
|
query(range, check, out = []) {
|
|
6640
|
-
const bounds = this
|
|
6770
|
+
const bounds = this.#getRangeBounds(range);
|
|
6641
6771
|
if (!bounds) {
|
|
6642
6772
|
return out;
|
|
6643
6773
|
}
|
|
6644
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
6774
|
+
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);
|
|
6645
6775
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
6646
6776
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
6647
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
6777
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
6648
6778
|
if (!cellParticles) {
|
|
6649
6779
|
continue;
|
|
6650
6780
|
}
|
|
@@ -6661,29 +6791,29 @@
|
|
|
6661
6791
|
return out;
|
|
6662
6792
|
}
|
|
6663
6793
|
queryCircle(position, radius, check, out = []) {
|
|
6664
|
-
const circle = this
|
|
6665
|
-
this
|
|
6794
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
6795
|
+
this.#releaseShapes();
|
|
6666
6796
|
return result;
|
|
6667
6797
|
}
|
|
6668
6798
|
queryRectangle(position, size, check, out = []) {
|
|
6669
|
-
const rect = this
|
|
6670
|
-
this
|
|
6799
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
6800
|
+
this.#releaseShapes();
|
|
6671
6801
|
return result;
|
|
6672
6802
|
}
|
|
6673
6803
|
setCellSize(cellSize) {
|
|
6674
|
-
this
|
|
6804
|
+
this.#pendingCellSize = cellSize;
|
|
6675
6805
|
}
|
|
6676
|
-
|
|
6677
|
-
return (this
|
|
6806
|
+
#acquireCircle(x, y, r) {
|
|
6807
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
6678
6808
|
}
|
|
6679
|
-
|
|
6680
|
-
return (this
|
|
6809
|
+
#acquireRectangle(x, y, w, h) {
|
|
6810
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
6681
6811
|
}
|
|
6682
|
-
|
|
6683
|
-
const cellX = Math.floor(x / this
|
|
6812
|
+
#cellKeyFromCoords(x, y) {
|
|
6813
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
6684
6814
|
return `${cellX}_${cellY}`;
|
|
6685
6815
|
}
|
|
6686
|
-
|
|
6816
|
+
#getRangeBounds(range) {
|
|
6687
6817
|
if (range instanceof Circle) {
|
|
6688
6818
|
const r = range.radius, { x, y } = range.position;
|
|
6689
6819
|
return {
|
|
@@ -6704,53 +6834,53 @@
|
|
|
6704
6834
|
}
|
|
6705
6835
|
return null;
|
|
6706
6836
|
}
|
|
6707
|
-
|
|
6708
|
-
this
|
|
6709
|
-
this
|
|
6837
|
+
#releaseShapes() {
|
|
6838
|
+
this.#circlePoolIdx = 0;
|
|
6839
|
+
this.#rectanglePoolIdx = 0;
|
|
6710
6840
|
}
|
|
6711
6841
|
}
|
|
6712
6842
|
|
|
6713
6843
|
class ParticlesManager {
|
|
6714
6844
|
checkParticlePositionPlugins;
|
|
6715
6845
|
grid;
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
|
|
6730
|
-
|
|
6846
|
+
#array;
|
|
6847
|
+
#container;
|
|
6848
|
+
#groupLimits;
|
|
6849
|
+
#limit;
|
|
6850
|
+
#nextId;
|
|
6851
|
+
#particleBuckets;
|
|
6852
|
+
#particleResetPlugins;
|
|
6853
|
+
#particleUpdatePlugins;
|
|
6854
|
+
#pluginManager;
|
|
6855
|
+
#pool;
|
|
6856
|
+
#postParticleUpdatePlugins;
|
|
6857
|
+
#postUpdatePlugins;
|
|
6858
|
+
#resizeFactor;
|
|
6859
|
+
#updatePlugins;
|
|
6860
|
+
#zBuckets;
|
|
6731
6861
|
constructor(pluginManager, container) {
|
|
6732
|
-
this
|
|
6733
|
-
this
|
|
6734
|
-
this
|
|
6735
|
-
this
|
|
6736
|
-
this
|
|
6737
|
-
this
|
|
6738
|
-
this
|
|
6739
|
-
this
|
|
6740
|
-
this
|
|
6862
|
+
this.#pluginManager = pluginManager;
|
|
6863
|
+
this.#container = container;
|
|
6864
|
+
this.#nextId = 0;
|
|
6865
|
+
this.#array = [];
|
|
6866
|
+
this.#pool = [];
|
|
6867
|
+
this.#limit = 0;
|
|
6868
|
+
this.#groupLimits = new Map();
|
|
6869
|
+
this.#particleBuckets = new Map();
|
|
6870
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
6741
6871
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
6742
6872
|
this.checkParticlePositionPlugins = [];
|
|
6743
|
-
this
|
|
6744
|
-
this
|
|
6745
|
-
this
|
|
6746
|
-
this
|
|
6747
|
-
this
|
|
6873
|
+
this.#particleResetPlugins = [];
|
|
6874
|
+
this.#particleUpdatePlugins = [];
|
|
6875
|
+
this.#postUpdatePlugins = [];
|
|
6876
|
+
this.#postParticleUpdatePlugins = [];
|
|
6877
|
+
this.#updatePlugins = [];
|
|
6748
6878
|
}
|
|
6749
6879
|
get count() {
|
|
6750
|
-
return this.
|
|
6880
|
+
return this.#array.length;
|
|
6751
6881
|
}
|
|
6752
6882
|
addParticle(position, overrideOptions, group, initializer) {
|
|
6753
|
-
const limitMode = this.
|
|
6883
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
6754
6884
|
if (limit > minLimit) {
|
|
6755
6885
|
switch (limitMode) {
|
|
6756
6886
|
case LimitMode.delete: {
|
|
@@ -6768,20 +6898,20 @@
|
|
|
6768
6898
|
}
|
|
6769
6899
|
}
|
|
6770
6900
|
try {
|
|
6771
|
-
const particle = this.
|
|
6772
|
-
particle.init(this
|
|
6901
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
6902
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
6773
6903
|
let canAdd = true;
|
|
6774
6904
|
if (initializer) {
|
|
6775
6905
|
canAdd = initializer(particle);
|
|
6776
6906
|
}
|
|
6777
6907
|
if (!canAdd) {
|
|
6778
|
-
this.
|
|
6908
|
+
this.#pool.push(particle);
|
|
6779
6909
|
return;
|
|
6780
6910
|
}
|
|
6781
|
-
this.
|
|
6782
|
-
this
|
|
6783
|
-
this
|
|
6784
|
-
this.
|
|
6911
|
+
this.#array.push(particle);
|
|
6912
|
+
this.#insertParticleIntoBucket(particle);
|
|
6913
|
+
this.#nextId++;
|
|
6914
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
6785
6915
|
particle,
|
|
6786
6916
|
});
|
|
6787
6917
|
return particle;
|
|
@@ -6792,25 +6922,25 @@
|
|
|
6792
6922
|
return undefined;
|
|
6793
6923
|
}
|
|
6794
6924
|
clear() {
|
|
6795
|
-
this
|
|
6796
|
-
this.
|
|
6797
|
-
this
|
|
6925
|
+
this.#array = [];
|
|
6926
|
+
this.#particleBuckets.clear();
|
|
6927
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
6798
6928
|
}
|
|
6799
6929
|
destroy() {
|
|
6800
|
-
this
|
|
6801
|
-
this.
|
|
6802
|
-
this.
|
|
6803
|
-
this
|
|
6930
|
+
this.#array = [];
|
|
6931
|
+
this.#pool.length = 0;
|
|
6932
|
+
this.#particleBuckets.clear();
|
|
6933
|
+
this.#zBuckets = [];
|
|
6804
6934
|
this.checkParticlePositionPlugins = [];
|
|
6805
|
-
this
|
|
6806
|
-
this
|
|
6807
|
-
this
|
|
6808
|
-
this
|
|
6809
|
-
this
|
|
6935
|
+
this.#particleResetPlugins = [];
|
|
6936
|
+
this.#particleUpdatePlugins = [];
|
|
6937
|
+
this.#postUpdatePlugins = [];
|
|
6938
|
+
this.#postParticleUpdatePlugins = [];
|
|
6939
|
+
this.#updatePlugins = [];
|
|
6810
6940
|
}
|
|
6811
6941
|
drawParticles(delta) {
|
|
6812
|
-
for (let i = this.
|
|
6813
|
-
const bucket = this
|
|
6942
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
6943
|
+
const bucket = this.#zBuckets[i];
|
|
6814
6944
|
if (!bucket) {
|
|
6815
6945
|
continue;
|
|
6816
6946
|
}
|
|
@@ -6820,24 +6950,24 @@
|
|
|
6820
6950
|
}
|
|
6821
6951
|
}
|
|
6822
6952
|
filter(condition) {
|
|
6823
|
-
return this.
|
|
6953
|
+
return this.#array.filter(condition);
|
|
6824
6954
|
}
|
|
6825
6955
|
find(condition) {
|
|
6826
|
-
return this.
|
|
6956
|
+
return this.#array.find(condition);
|
|
6827
6957
|
}
|
|
6828
6958
|
get(index) {
|
|
6829
|
-
return this
|
|
6959
|
+
return this.#array[index];
|
|
6830
6960
|
}
|
|
6831
6961
|
async init() {
|
|
6832
|
-
const container = this
|
|
6962
|
+
const container = this.#container, options = container.actualOptions;
|
|
6833
6963
|
this.checkParticlePositionPlugins = [];
|
|
6834
|
-
this
|
|
6835
|
-
this
|
|
6836
|
-
this
|
|
6837
|
-
this
|
|
6838
|
-
this
|
|
6839
|
-
this.
|
|
6840
|
-
this
|
|
6964
|
+
this.#updatePlugins = [];
|
|
6965
|
+
this.#particleUpdatePlugins = [];
|
|
6966
|
+
this.#postUpdatePlugins = [];
|
|
6967
|
+
this.#particleResetPlugins = [];
|
|
6968
|
+
this.#postParticleUpdatePlugins = [];
|
|
6969
|
+
this.#particleBuckets.clear();
|
|
6970
|
+
this.#resetBuckets(container.zLayers);
|
|
6841
6971
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
6842
6972
|
for (const plugin of container.plugins) {
|
|
6843
6973
|
if (plugin.redrawInit) {
|
|
@@ -6847,26 +6977,26 @@
|
|
|
6847
6977
|
this.checkParticlePositionPlugins.push(plugin);
|
|
6848
6978
|
}
|
|
6849
6979
|
if (plugin.update) {
|
|
6850
|
-
this.
|
|
6980
|
+
this.#updatePlugins.push(plugin);
|
|
6851
6981
|
}
|
|
6852
6982
|
if (plugin.particleUpdate) {
|
|
6853
|
-
this.
|
|
6983
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
6854
6984
|
}
|
|
6855
6985
|
if (plugin.postUpdate) {
|
|
6856
|
-
this.
|
|
6986
|
+
this.#postUpdatePlugins.push(plugin);
|
|
6857
6987
|
}
|
|
6858
6988
|
if (plugin.particleReset) {
|
|
6859
|
-
this.
|
|
6989
|
+
this.#particleResetPlugins.push(plugin);
|
|
6860
6990
|
}
|
|
6861
6991
|
if (plugin.postParticleUpdate) {
|
|
6862
|
-
this.
|
|
6992
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
6863
6993
|
}
|
|
6864
6994
|
}
|
|
6865
|
-
await this.
|
|
6866
|
-
for (const drawer of this.
|
|
6995
|
+
await this.#container.initDrawersAndUpdaters();
|
|
6996
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
6867
6997
|
await drawer.init?.(container);
|
|
6868
6998
|
}
|
|
6869
|
-
for (const drawer of this.
|
|
6999
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
6870
7000
|
await drawer.init?.(container);
|
|
6871
7001
|
}
|
|
6872
7002
|
let handled = false;
|
|
@@ -6900,10 +7030,10 @@
|
|
|
6900
7030
|
async redraw() {
|
|
6901
7031
|
this.clear();
|
|
6902
7032
|
await this.init();
|
|
6903
|
-
this.
|
|
7033
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
6904
7034
|
}
|
|
6905
7035
|
remove(particle, group, override) {
|
|
6906
|
-
this.removeAt(this.
|
|
7036
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
6907
7037
|
}
|
|
6908
7038
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
6909
7039
|
if (index < minIndex || index > this.count) {
|
|
@@ -6911,7 +7041,7 @@
|
|
|
6911
7041
|
}
|
|
6912
7042
|
let deleted = 0;
|
|
6913
7043
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
6914
|
-
if (this
|
|
7044
|
+
if (this.#removeParticle(i, group, override)) {
|
|
6915
7045
|
i--;
|
|
6916
7046
|
deleted++;
|
|
6917
7047
|
}
|
|
@@ -6921,9 +7051,9 @@
|
|
|
6921
7051
|
this.removeAt(minIndex, quantity, group);
|
|
6922
7052
|
}
|
|
6923
7053
|
setDensity() {
|
|
6924
|
-
const options = this.
|
|
7054
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
6925
7055
|
let pluginsCount = 0;
|
|
6926
|
-
for (const plugin of this.
|
|
7056
|
+
for (const plugin of this.#container.plugins) {
|
|
6927
7057
|
if (plugin.particlesDensityCount) {
|
|
6928
7058
|
pluginsCount += plugin.particlesDensityCount();
|
|
6929
7059
|
}
|
|
@@ -6933,51 +7063,51 @@
|
|
|
6933
7063
|
if (!groupData) {
|
|
6934
7064
|
continue;
|
|
6935
7065
|
}
|
|
6936
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
6937
|
-
this
|
|
7066
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
7067
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
6938
7068
|
}
|
|
6939
|
-
this
|
|
7069
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
6940
7070
|
}
|
|
6941
7071
|
setResizeFactor(factor) {
|
|
6942
|
-
this
|
|
7072
|
+
this.#resizeFactor = factor;
|
|
6943
7073
|
}
|
|
6944
7074
|
update(delta) {
|
|
6945
7075
|
this.grid.clear();
|
|
6946
|
-
for (const plugin of this
|
|
7076
|
+
for (const plugin of this.#updatePlugins) {
|
|
6947
7077
|
plugin.update?.(delta);
|
|
6948
7078
|
}
|
|
6949
|
-
const particlesToDelete = this
|
|
6950
|
-
for (const plugin of this
|
|
7079
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
7080
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
6951
7081
|
plugin.postUpdate?.(delta);
|
|
6952
7082
|
}
|
|
6953
|
-
this
|
|
7083
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
6954
7084
|
if (particlesToDelete.size) {
|
|
6955
7085
|
for (const particle of particlesToDelete) {
|
|
6956
7086
|
this.remove(particle);
|
|
6957
7087
|
}
|
|
6958
7088
|
}
|
|
6959
|
-
|
|
7089
|
+
this.#resizeFactor = undefined;
|
|
6960
7090
|
}
|
|
6961
|
-
|
|
6962
|
-
this.
|
|
7091
|
+
#addToPool = (...particles) => {
|
|
7092
|
+
this.#pool.push(...particles);
|
|
6963
7093
|
};
|
|
6964
|
-
|
|
7094
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
6965
7095
|
const numberOptions = options.number;
|
|
6966
7096
|
if (!numberOptions.density.enable) {
|
|
6967
7097
|
if (group === undefined) {
|
|
6968
|
-
this
|
|
7098
|
+
this.#limit = numberOptions.limit.value;
|
|
6969
7099
|
}
|
|
6970
7100
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
6971
|
-
this.
|
|
7101
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
6972
7102
|
}
|
|
6973
7103
|
return;
|
|
6974
7104
|
}
|
|
6975
|
-
const densityFactor = this
|
|
7105
|
+
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);
|
|
6976
7106
|
if (group === undefined) {
|
|
6977
|
-
this
|
|
7107
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
6978
7108
|
}
|
|
6979
7109
|
else {
|
|
6980
|
-
this.
|
|
7110
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
6981
7111
|
}
|
|
6982
7112
|
if (particlesCount < particlesNumber) {
|
|
6983
7113
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -6986,18 +7116,18 @@
|
|
|
6986
7116
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
6987
7117
|
}
|
|
6988
7118
|
};
|
|
6989
|
-
|
|
7119
|
+
#createBuckets = (zLayers) => {
|
|
6990
7120
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6991
7121
|
return Array.from({ length: bucketCount }, () => []);
|
|
6992
7122
|
};
|
|
6993
|
-
|
|
6994
|
-
const maxBucketIndex = this.
|
|
7123
|
+
#getBucketIndex = (zIndex) => {
|
|
7124
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
6995
7125
|
if (maxBucketIndex <= minIndex) {
|
|
6996
7126
|
return minIndex;
|
|
6997
7127
|
}
|
|
6998
7128
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
6999
7129
|
};
|
|
7000
|
-
|
|
7130
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
7001
7131
|
let start = minIndex, end = bucket.length;
|
|
7002
7132
|
while (start < end) {
|
|
7003
7133
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -7014,8 +7144,8 @@
|
|
|
7014
7144
|
}
|
|
7015
7145
|
return start;
|
|
7016
7146
|
};
|
|
7017
|
-
|
|
7018
|
-
const container = this
|
|
7147
|
+
#initDensityFactor = densityOptions => {
|
|
7148
|
+
const container = this.#container;
|
|
7019
7149
|
if (!densityOptions.enable) {
|
|
7020
7150
|
return defaultDensityFactor;
|
|
7021
7151
|
}
|
|
@@ -7025,82 +7155,82 @@
|
|
|
7025
7155
|
}
|
|
7026
7156
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
7027
7157
|
};
|
|
7028
|
-
|
|
7029
|
-
const bucketIndex = this
|
|
7158
|
+
#insertParticleIntoBucket = (particle) => {
|
|
7159
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
7030
7160
|
if (!bucket) {
|
|
7031
7161
|
return;
|
|
7032
7162
|
}
|
|
7033
|
-
bucket.splice(this
|
|
7034
|
-
this.
|
|
7163
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
7164
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
7035
7165
|
};
|
|
7036
|
-
|
|
7037
|
-
const particle = this
|
|
7166
|
+
#removeParticle = (index, group, override) => {
|
|
7167
|
+
const particle = this.#array[index];
|
|
7038
7168
|
if (!particle) {
|
|
7039
7169
|
return false;
|
|
7040
7170
|
}
|
|
7041
7171
|
if (particle.group !== group) {
|
|
7042
7172
|
return false;
|
|
7043
7173
|
}
|
|
7044
|
-
this.
|
|
7045
|
-
this
|
|
7174
|
+
this.#array.splice(index, deleteCount);
|
|
7175
|
+
this.#removeParticleFromBucket(particle);
|
|
7046
7176
|
particle.destroy(override);
|
|
7047
|
-
this.
|
|
7177
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
7048
7178
|
particle,
|
|
7049
7179
|
});
|
|
7050
|
-
this
|
|
7180
|
+
this.#addToPool(particle);
|
|
7051
7181
|
return true;
|
|
7052
7182
|
};
|
|
7053
|
-
|
|
7054
|
-
const bucketIndex = this.
|
|
7183
|
+
#removeParticleFromBucket = (particle) => {
|
|
7184
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
7055
7185
|
if (!bucket) {
|
|
7056
|
-
this.
|
|
7186
|
+
this.#particleBuckets.delete(particle.id);
|
|
7057
7187
|
return;
|
|
7058
7188
|
}
|
|
7059
|
-
const particleIndex = this
|
|
7189
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
7060
7190
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
7061
|
-
this.
|
|
7191
|
+
this.#particleBuckets.delete(particle.id);
|
|
7062
7192
|
return;
|
|
7063
7193
|
}
|
|
7064
7194
|
bucket.splice(particleIndex, deleteCount);
|
|
7065
|
-
this.
|
|
7195
|
+
this.#particleBuckets.delete(particle.id);
|
|
7066
7196
|
};
|
|
7067
|
-
|
|
7197
|
+
#resetBuckets = (zLayers) => {
|
|
7068
7198
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
7069
|
-
if (this.
|
|
7070
|
-
this
|
|
7199
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
7200
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
7071
7201
|
return;
|
|
7072
7202
|
}
|
|
7073
|
-
for (const bucket of this
|
|
7203
|
+
for (const bucket of this.#zBuckets) {
|
|
7074
7204
|
bucket.length = minIndex;
|
|
7075
7205
|
}
|
|
7076
7206
|
};
|
|
7077
|
-
|
|
7078
|
-
const newBucketIndex = this
|
|
7207
|
+
#updateParticleBucket = (particle) => {
|
|
7208
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
7079
7209
|
if (currentBucketIndex === undefined) {
|
|
7080
|
-
this
|
|
7210
|
+
this.#insertParticleIntoBucket(particle);
|
|
7081
7211
|
return;
|
|
7082
7212
|
}
|
|
7083
7213
|
if (currentBucketIndex === newBucketIndex) {
|
|
7084
7214
|
return;
|
|
7085
7215
|
}
|
|
7086
|
-
const currentBucket = this
|
|
7216
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
7087
7217
|
if (currentBucket) {
|
|
7088
|
-
const particleIndex = this
|
|
7218
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
7089
7219
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
7090
7220
|
currentBucket.splice(particleIndex, deleteCount);
|
|
7091
7221
|
}
|
|
7092
7222
|
}
|
|
7093
|
-
const newBucket = this
|
|
7223
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
7094
7224
|
if (!newBucket) {
|
|
7095
|
-
this.
|
|
7225
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
7096
7226
|
return;
|
|
7097
7227
|
}
|
|
7098
|
-
newBucket.splice(this
|
|
7099
|
-
this.
|
|
7228
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
7229
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
7100
7230
|
};
|
|
7101
|
-
|
|
7102
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
7103
|
-
for (const particle of this
|
|
7231
|
+
#updateParticlesPhase1 = (delta) => {
|
|
7232
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
7233
|
+
for (const particle of this.#array) {
|
|
7104
7234
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
7105
7235
|
particle.position.x *= resizeFactor.width;
|
|
7106
7236
|
particle.position.y *= resizeFactor.height;
|
|
@@ -7108,10 +7238,10 @@
|
|
|
7108
7238
|
particle.initialPosition.y *= resizeFactor.height;
|
|
7109
7239
|
}
|
|
7110
7240
|
particle.ignoresResizeRatio = false;
|
|
7111
|
-
for (const plugin of this
|
|
7241
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
7112
7242
|
plugin.particleReset?.(particle);
|
|
7113
7243
|
}
|
|
7114
|
-
for (const plugin of this
|
|
7244
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
7115
7245
|
if (particle.destroyed) {
|
|
7116
7246
|
break;
|
|
7117
7247
|
}
|
|
@@ -7125,36 +7255,36 @@
|
|
|
7125
7255
|
}
|
|
7126
7256
|
return particlesToDelete;
|
|
7127
7257
|
};
|
|
7128
|
-
|
|
7129
|
-
for (const particle of this
|
|
7258
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
7259
|
+
for (const particle of this.#array) {
|
|
7130
7260
|
if (particle.destroyed) {
|
|
7131
7261
|
particlesToDelete.add(particle);
|
|
7132
7262
|
continue;
|
|
7133
7263
|
}
|
|
7134
|
-
for (const updater of this.
|
|
7264
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
7135
7265
|
updater.update(particle, delta);
|
|
7136
7266
|
}
|
|
7137
7267
|
if (!particle.spawning) {
|
|
7138
|
-
for (const plugin of this
|
|
7268
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
7139
7269
|
plugin.postParticleUpdate?.(particle, delta);
|
|
7140
7270
|
}
|
|
7141
7271
|
}
|
|
7142
|
-
this
|
|
7272
|
+
this.#updateParticleBucket(particle);
|
|
7143
7273
|
}
|
|
7144
7274
|
};
|
|
7145
7275
|
}
|
|
7146
7276
|
|
|
7147
7277
|
class Retina {
|
|
7148
|
-
container;
|
|
7149
7278
|
pixelRatio;
|
|
7150
7279
|
reduceFactor;
|
|
7280
|
+
#container;
|
|
7151
7281
|
constructor(container) {
|
|
7152
|
-
this
|
|
7282
|
+
this.#container = container;
|
|
7153
7283
|
this.pixelRatio = defaultRatio;
|
|
7154
7284
|
this.reduceFactor = defaultReduceFactor;
|
|
7155
7285
|
}
|
|
7156
7286
|
init() {
|
|
7157
|
-
const container = this
|
|
7287
|
+
const container = this.#container, options = container.actualOptions;
|
|
7158
7288
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
7159
7289
|
this.reduceFactor = defaultReduceFactor;
|
|
7160
7290
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -7168,7 +7298,6 @@
|
|
|
7168
7298
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
7169
7299
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
7170
7300
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
7171
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
7172
7301
|
const maxDistance = props.maxDistance;
|
|
7173
7302
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
7174
7303
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -7206,73 +7335,73 @@
|
|
|
7206
7335
|
shapeDrawers;
|
|
7207
7336
|
started;
|
|
7208
7337
|
zLayers;
|
|
7209
|
-
|
|
7210
|
-
|
|
7211
|
-
|
|
7212
|
-
|
|
7213
|
-
|
|
7214
|
-
|
|
7215
|
-
|
|
7216
|
-
|
|
7217
|
-
|
|
7218
|
-
|
|
7219
|
-
|
|
7220
|
-
|
|
7221
|
-
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7338
|
+
#delay;
|
|
7339
|
+
#delayTimeout;
|
|
7340
|
+
#delta = { value: 0, factor: 0 };
|
|
7341
|
+
#dispatchCallback;
|
|
7342
|
+
#drawAnimationFrame;
|
|
7343
|
+
#duration;
|
|
7344
|
+
#eventListeners;
|
|
7345
|
+
#firstStart;
|
|
7346
|
+
#initialSourceOptions;
|
|
7347
|
+
#lastFrameTime;
|
|
7348
|
+
#lifeTime;
|
|
7349
|
+
#onDestroy;
|
|
7350
|
+
#options;
|
|
7351
|
+
#paused;
|
|
7352
|
+
#pluginManager;
|
|
7353
|
+
#smooth;
|
|
7354
|
+
#sourceOptions;
|
|
7226
7355
|
constructor(params) {
|
|
7227
7356
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
7228
|
-
this
|
|
7229
|
-
this
|
|
7230
|
-
this
|
|
7357
|
+
this.#pluginManager = pluginManager;
|
|
7358
|
+
this.#dispatchCallback = dispatchCallback;
|
|
7359
|
+
this.#onDestroy = onDestroy;
|
|
7231
7360
|
this.id = Symbol(id);
|
|
7232
7361
|
this.fpsLimit = 120;
|
|
7233
7362
|
this.hdr = false;
|
|
7234
|
-
this
|
|
7235
|
-
this
|
|
7236
|
-
this
|
|
7237
|
-
this
|
|
7238
|
-
this
|
|
7363
|
+
this.#smooth = false;
|
|
7364
|
+
this.#delay = 0;
|
|
7365
|
+
this.#duration = 0;
|
|
7366
|
+
this.#lifeTime = 0;
|
|
7367
|
+
this.#firstStart = true;
|
|
7239
7368
|
this.started = false;
|
|
7240
7369
|
this.destroyed = false;
|
|
7241
|
-
this
|
|
7242
|
-
this
|
|
7370
|
+
this.#paused = true;
|
|
7371
|
+
this.#lastFrameTime = 0;
|
|
7243
7372
|
this.zLayers = 100;
|
|
7244
7373
|
this.pageHidden = false;
|
|
7245
|
-
this
|
|
7246
|
-
this
|
|
7374
|
+
this.#sourceOptions = sourceOptions;
|
|
7375
|
+
this.#initialSourceOptions = sourceOptions;
|
|
7247
7376
|
this.effectDrawers = new Map();
|
|
7248
7377
|
this.shapeDrawers = new Map();
|
|
7249
7378
|
this.particleUpdaters = [];
|
|
7250
7379
|
this.retina = new Retina(this);
|
|
7251
|
-
this.canvas = new CanvasManager(this
|
|
7252
|
-
this.particles = new ParticlesManager(this
|
|
7380
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
7381
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
7253
7382
|
this.plugins = [];
|
|
7254
7383
|
this.particleDestroyedPlugins = [];
|
|
7255
7384
|
this.particleCreatedPlugins = [];
|
|
7256
7385
|
this.particlePositionPlugins = [];
|
|
7257
|
-
this
|
|
7258
|
-
this.actualOptions = loadContainerOptions(this
|
|
7259
|
-
this
|
|
7386
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
7387
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
7388
|
+
this.#eventListeners = new EventListeners(this);
|
|
7260
7389
|
this.dispatchEvent(EventType.containerBuilt);
|
|
7261
7390
|
}
|
|
7262
7391
|
get animationStatus() {
|
|
7263
|
-
return !this
|
|
7392
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
7264
7393
|
}
|
|
7265
7394
|
get options() {
|
|
7266
|
-
return this
|
|
7395
|
+
return this.#options;
|
|
7267
7396
|
}
|
|
7268
7397
|
get sourceOptions() {
|
|
7269
|
-
return this
|
|
7398
|
+
return this.#sourceOptions;
|
|
7270
7399
|
}
|
|
7271
7400
|
addLifeTime(value) {
|
|
7272
|
-
this
|
|
7401
|
+
this.#lifeTime += value;
|
|
7273
7402
|
}
|
|
7274
7403
|
alive() {
|
|
7275
|
-
return !this
|
|
7404
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
7276
7405
|
}
|
|
7277
7406
|
destroy(remove = true) {
|
|
7278
7407
|
if (!guardCheck(this)) {
|
|
@@ -7294,13 +7423,13 @@
|
|
|
7294
7423
|
this.shapeDrawers = new Map();
|
|
7295
7424
|
this.particleUpdaters = [];
|
|
7296
7425
|
this.plugins.length = 0;
|
|
7297
|
-
this.
|
|
7426
|
+
this.#pluginManager.clearPlugins(this);
|
|
7298
7427
|
this.destroyed = true;
|
|
7299
|
-
this
|
|
7428
|
+
this.#onDestroy(remove);
|
|
7300
7429
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
7301
7430
|
}
|
|
7302
7431
|
dispatchEvent(type, data) {
|
|
7303
|
-
this
|
|
7432
|
+
this.#dispatchCallback(type, {
|
|
7304
7433
|
container: this,
|
|
7305
7434
|
data,
|
|
7306
7435
|
});
|
|
@@ -7310,12 +7439,12 @@
|
|
|
7310
7439
|
return;
|
|
7311
7440
|
}
|
|
7312
7441
|
let refreshTime = force;
|
|
7313
|
-
this
|
|
7442
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
7314
7443
|
if (refreshTime) {
|
|
7315
|
-
this
|
|
7444
|
+
this.#lastFrameTime = undefined;
|
|
7316
7445
|
refreshTime = false;
|
|
7317
7446
|
}
|
|
7318
|
-
this
|
|
7447
|
+
this.#nextFrame(timestamp);
|
|
7319
7448
|
});
|
|
7320
7449
|
}
|
|
7321
7450
|
async export(type, options = {}) {
|
|
@@ -7337,7 +7466,7 @@
|
|
|
7337
7466
|
return;
|
|
7338
7467
|
}
|
|
7339
7468
|
const allContainerPlugins = new Map();
|
|
7340
|
-
for (const plugin of this.
|
|
7469
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
7341
7470
|
const containerPlugin = await plugin.getPlugin(this);
|
|
7342
7471
|
if (containerPlugin.preInit) {
|
|
7343
7472
|
await containerPlugin.preInit();
|
|
@@ -7345,8 +7474,8 @@
|
|
|
7345
7474
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
7346
7475
|
}
|
|
7347
7476
|
await this.initDrawersAndUpdaters();
|
|
7348
|
-
this
|
|
7349
|
-
this.actualOptions = loadContainerOptions(this
|
|
7477
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
7478
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
7350
7479
|
this.plugins.length = 0;
|
|
7351
7480
|
this.particleDestroyedPlugins.length = 0;
|
|
7352
7481
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -7373,11 +7502,11 @@
|
|
|
7373
7502
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
7374
7503
|
this.hdr = hdr;
|
|
7375
7504
|
this.zLayers = zLayers;
|
|
7376
|
-
this
|
|
7377
|
-
this
|
|
7378
|
-
this
|
|
7505
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
7506
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
7507
|
+
this.#lifeTime = 0;
|
|
7379
7508
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
7380
|
-
this
|
|
7509
|
+
this.#smooth = smooth;
|
|
7381
7510
|
for (const plugin of this.plugins) {
|
|
7382
7511
|
await plugin.init?.();
|
|
7383
7512
|
}
|
|
@@ -7390,7 +7519,7 @@
|
|
|
7390
7519
|
this.dispatchEvent(EventType.particlesSetup);
|
|
7391
7520
|
}
|
|
7392
7521
|
async initDrawersAndUpdaters() {
|
|
7393
|
-
const pluginManager = this
|
|
7522
|
+
const pluginManager = this.#pluginManager;
|
|
7394
7523
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
7395
7524
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
7396
7525
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -7399,18 +7528,18 @@
|
|
|
7399
7528
|
if (!guardCheck(this)) {
|
|
7400
7529
|
return;
|
|
7401
7530
|
}
|
|
7402
|
-
if (this
|
|
7403
|
-
cancelAnimation(this
|
|
7404
|
-
|
|
7531
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
7532
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
7533
|
+
this.#drawAnimationFrame = undefined;
|
|
7405
7534
|
}
|
|
7406
|
-
if (this
|
|
7535
|
+
if (this.#paused) {
|
|
7407
7536
|
return;
|
|
7408
7537
|
}
|
|
7409
7538
|
for (const plugin of this.plugins) {
|
|
7410
7539
|
plugin.pause?.();
|
|
7411
7540
|
}
|
|
7412
7541
|
if (!this.pageHidden) {
|
|
7413
|
-
this
|
|
7542
|
+
this.#paused = true;
|
|
7414
7543
|
}
|
|
7415
7544
|
this.dispatchEvent(EventType.containerPaused);
|
|
7416
7545
|
}
|
|
@@ -7418,13 +7547,13 @@
|
|
|
7418
7547
|
if (!guardCheck(this)) {
|
|
7419
7548
|
return;
|
|
7420
7549
|
}
|
|
7421
|
-
const needsUpdate = this
|
|
7422
|
-
if (this
|
|
7423
|
-
this
|
|
7550
|
+
const needsUpdate = this.#paused || force;
|
|
7551
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
7552
|
+
this.#firstStart = false;
|
|
7424
7553
|
return;
|
|
7425
7554
|
}
|
|
7426
|
-
if (this
|
|
7427
|
-
this
|
|
7555
|
+
if (this.#paused) {
|
|
7556
|
+
this.#paused = false;
|
|
7428
7557
|
}
|
|
7429
7558
|
if (needsUpdate) {
|
|
7430
7559
|
for (const plugin of this.plugins) {
|
|
@@ -7447,10 +7576,10 @@
|
|
|
7447
7576
|
if (!guardCheck(this)) {
|
|
7448
7577
|
return;
|
|
7449
7578
|
}
|
|
7450
|
-
this
|
|
7451
|
-
this
|
|
7452
|
-
this
|
|
7453
|
-
this.actualOptions = loadContainerOptions(this
|
|
7579
|
+
this.#initialSourceOptions = sourceOptions;
|
|
7580
|
+
this.#sourceOptions = sourceOptions;
|
|
7581
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
7582
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
7454
7583
|
return this.refresh();
|
|
7455
7584
|
}
|
|
7456
7585
|
async start() {
|
|
@@ -7461,7 +7590,7 @@
|
|
|
7461
7590
|
this.started = true;
|
|
7462
7591
|
await new Promise(resolve => {
|
|
7463
7592
|
const start = async () => {
|
|
7464
|
-
this.
|
|
7593
|
+
this.#eventListeners.addListeners();
|
|
7465
7594
|
for (const plugin of this.plugins) {
|
|
7466
7595
|
await plugin.start?.();
|
|
7467
7596
|
}
|
|
@@ -7469,20 +7598,20 @@
|
|
|
7469
7598
|
this.play();
|
|
7470
7599
|
resolve();
|
|
7471
7600
|
};
|
|
7472
|
-
this
|
|
7601
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
7473
7602
|
});
|
|
7474
7603
|
}
|
|
7475
7604
|
stop() {
|
|
7476
7605
|
if (!guardCheck(this) || !this.started) {
|
|
7477
7606
|
return;
|
|
7478
7607
|
}
|
|
7479
|
-
if (this
|
|
7480
|
-
clearTimeout(this
|
|
7481
|
-
|
|
7608
|
+
if (this.#delayTimeout) {
|
|
7609
|
+
clearTimeout(this.#delayTimeout);
|
|
7610
|
+
this.#delayTimeout = undefined;
|
|
7482
7611
|
}
|
|
7483
|
-
this
|
|
7612
|
+
this.#firstStart = true;
|
|
7484
7613
|
this.started = false;
|
|
7485
|
-
this.
|
|
7614
|
+
this.#eventListeners.removeListeners();
|
|
7486
7615
|
this.pause();
|
|
7487
7616
|
this.particles.clear();
|
|
7488
7617
|
this.canvas.stop();
|
|
@@ -7492,7 +7621,7 @@
|
|
|
7492
7621
|
this.particleCreatedPlugins.length = 0;
|
|
7493
7622
|
this.particleDestroyedPlugins.length = 0;
|
|
7494
7623
|
this.particlePositionPlugins.length = 0;
|
|
7495
|
-
this
|
|
7624
|
+
this.#sourceOptions = this.#options;
|
|
7496
7625
|
this.dispatchEvent(EventType.containerStopped);
|
|
7497
7626
|
}
|
|
7498
7627
|
updateActualOptions() {
|
|
@@ -7504,23 +7633,23 @@
|
|
|
7504
7633
|
}
|
|
7505
7634
|
return refresh;
|
|
7506
7635
|
}
|
|
7507
|
-
|
|
7636
|
+
#nextFrame = (timestamp) => {
|
|
7508
7637
|
try {
|
|
7509
|
-
if (!this
|
|
7510
|
-
this
|
|
7511
|
-
timestamp < this
|
|
7638
|
+
if (!this.#smooth &&
|
|
7639
|
+
this.#lastFrameTime !== undefined &&
|
|
7640
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
7512
7641
|
this.draw(false);
|
|
7513
7642
|
return;
|
|
7514
7643
|
}
|
|
7515
|
-
this
|
|
7516
|
-
updateDelta(this
|
|
7517
|
-
this.addLifeTime(this.
|
|
7518
|
-
this
|
|
7519
|
-
if (this.
|
|
7644
|
+
this.#lastFrameTime ??= timestamp;
|
|
7645
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
7646
|
+
this.addLifeTime(this.#delta.value);
|
|
7647
|
+
this.#lastFrameTime = timestamp;
|
|
7648
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
7520
7649
|
this.draw(false);
|
|
7521
7650
|
return;
|
|
7522
7651
|
}
|
|
7523
|
-
this.canvas.render.drawParticles(this
|
|
7652
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
7524
7653
|
if (!this.alive()) {
|
|
7525
7654
|
this.destroy();
|
|
7526
7655
|
return;
|
|
@@ -7541,10 +7670,10 @@
|
|
|
7541
7670
|
});
|
|
7542
7671
|
|
|
7543
7672
|
class BlendPluginInstance {
|
|
7544
|
-
|
|
7545
|
-
|
|
7673
|
+
#container;
|
|
7674
|
+
#defaultCompositeValue;
|
|
7546
7675
|
constructor(container) {
|
|
7547
|
-
this
|
|
7676
|
+
this.#container = container;
|
|
7548
7677
|
}
|
|
7549
7678
|
drawParticleCleanup(context, particle) {
|
|
7550
7679
|
if (!particle.options.blend?.enable) {
|
|
@@ -7561,14 +7690,14 @@
|
|
|
7561
7690
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
7562
7691
|
}
|
|
7563
7692
|
drawSettingsCleanup(context) {
|
|
7564
|
-
if (!this
|
|
7693
|
+
if (!this.#defaultCompositeValue) {
|
|
7565
7694
|
return;
|
|
7566
7695
|
}
|
|
7567
|
-
context.globalCompositeOperation = this
|
|
7696
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
7568
7697
|
}
|
|
7569
7698
|
drawSettingsSetup(context) {
|
|
7570
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
7571
|
-
this
|
|
7699
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
7700
|
+
this.#defaultCompositeValue = previousComposite;
|
|
7572
7701
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
7573
7702
|
}
|
|
7574
7703
|
}
|
|
@@ -7711,11 +7840,11 @@
|
|
|
7711
7840
|
class MovePluginInstance {
|
|
7712
7841
|
availablePathGenerators;
|
|
7713
7842
|
pathGenerators;
|
|
7714
|
-
|
|
7715
|
-
|
|
7843
|
+
#container;
|
|
7844
|
+
#pluginManager;
|
|
7716
7845
|
constructor(pluginManager, container) {
|
|
7717
|
-
this
|
|
7718
|
-
this
|
|
7846
|
+
this.#pluginManager = pluginManager;
|
|
7847
|
+
this.#container = container;
|
|
7719
7848
|
this.availablePathGenerators = new Map();
|
|
7720
7849
|
this.pathGenerators = new Map();
|
|
7721
7850
|
}
|
|
@@ -7746,7 +7875,7 @@
|
|
|
7746
7875
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
7747
7876
|
inverse: gravityOptions.inverse,
|
|
7748
7877
|
};
|
|
7749
|
-
initSpin(this
|
|
7878
|
+
initSpin(this.#container, particle);
|
|
7750
7879
|
}
|
|
7751
7880
|
particleDestroyed(particle) {
|
|
7752
7881
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -7757,7 +7886,7 @@
|
|
|
7757
7886
|
if (!moveOptions.enable) {
|
|
7758
7887
|
return;
|
|
7759
7888
|
}
|
|
7760
|
-
const container = this
|
|
7889
|
+
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;
|
|
7761
7890
|
if (moveOptions.spin.enable) {
|
|
7762
7891
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
7763
7892
|
}
|
|
@@ -7767,18 +7896,18 @@
|
|
|
7767
7896
|
applyDistance(particle);
|
|
7768
7897
|
}
|
|
7769
7898
|
preInit() {
|
|
7770
|
-
return this
|
|
7899
|
+
return this.#init();
|
|
7771
7900
|
}
|
|
7772
7901
|
redrawInit() {
|
|
7773
|
-
return this
|
|
7902
|
+
return this.#init();
|
|
7774
7903
|
}
|
|
7775
7904
|
update() {
|
|
7776
7905
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
7777
7906
|
pathGenerator.update();
|
|
7778
7907
|
}
|
|
7779
7908
|
}
|
|
7780
|
-
async
|
|
7781
|
-
const availablePathGenerators = await this.
|
|
7909
|
+
async #init() {
|
|
7910
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
7782
7911
|
if (!availablePathGenerators) {
|
|
7783
7912
|
return;
|
|
7784
7913
|
}
|
|
@@ -7796,44 +7925,44 @@
|
|
|
7796
7925
|
});
|
|
7797
7926
|
|
|
7798
7927
|
class EmittersPluginInstance {
|
|
7799
|
-
container;
|
|
7800
|
-
|
|
7928
|
+
#container;
|
|
7929
|
+
#instancesManager;
|
|
7801
7930
|
constructor(instancesManager, container) {
|
|
7802
|
-
this
|
|
7803
|
-
this
|
|
7804
|
-
this.
|
|
7931
|
+
this.#instancesManager = instancesManager;
|
|
7932
|
+
this.#container = container;
|
|
7933
|
+
this.#instancesManager.initContainer(container);
|
|
7805
7934
|
}
|
|
7806
7935
|
async init() {
|
|
7807
|
-
const emittersOptions = this
|
|
7936
|
+
const emittersOptions = this.#container.actualOptions.emitters;
|
|
7808
7937
|
if (isArray(emittersOptions)) {
|
|
7809
7938
|
for (const emitterOptions of emittersOptions) {
|
|
7810
|
-
await this.
|
|
7939
|
+
await this.#instancesManager.addEmitter(this.#container, emitterOptions);
|
|
7811
7940
|
}
|
|
7812
7941
|
}
|
|
7813
7942
|
else {
|
|
7814
|
-
await this.
|
|
7943
|
+
await this.#instancesManager.addEmitter(this.#container, emittersOptions);
|
|
7815
7944
|
}
|
|
7816
7945
|
}
|
|
7817
7946
|
pause() {
|
|
7818
|
-
for (const emitter of this.
|
|
7947
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
7819
7948
|
emitter.pause();
|
|
7820
7949
|
}
|
|
7821
7950
|
}
|
|
7822
7951
|
play() {
|
|
7823
|
-
for (const emitter of this.
|
|
7952
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
7824
7953
|
emitter.play();
|
|
7825
7954
|
}
|
|
7826
7955
|
}
|
|
7827
7956
|
resize() {
|
|
7828
|
-
for (const emitter of this.
|
|
7957
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
7829
7958
|
emitter.resize();
|
|
7830
7959
|
}
|
|
7831
7960
|
}
|
|
7832
7961
|
stop() {
|
|
7833
|
-
this.
|
|
7962
|
+
this.#instancesManager.clear(this.#container);
|
|
7834
7963
|
}
|
|
7835
7964
|
update(delta) {
|
|
7836
|
-
this.
|
|
7965
|
+
this.#instancesManager.getArray(this.#container).forEach(emitter => {
|
|
7837
7966
|
emitter.update(delta);
|
|
7838
7967
|
});
|
|
7839
7968
|
}
|
|
@@ -7866,16 +7995,16 @@
|
|
|
7866
7995
|
|
|
7867
7996
|
const defaultIndex = 0;
|
|
7868
7997
|
class EmittersInstancesManager {
|
|
7869
|
-
|
|
7870
|
-
|
|
7998
|
+
#containerArrays;
|
|
7999
|
+
#pluginManager;
|
|
7871
8000
|
constructor(pluginManager) {
|
|
7872
|
-
this
|
|
7873
|
-
this
|
|
8001
|
+
this.#containerArrays = new Map();
|
|
8002
|
+
this.#pluginManager = pluginManager;
|
|
7874
8003
|
}
|
|
7875
8004
|
async addEmitter(container, options, position) {
|
|
7876
8005
|
const emitterOptions = new Emitter();
|
|
7877
8006
|
emitterOptions.load(options);
|
|
7878
|
-
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this
|
|
8007
|
+
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this.#pluginManager, container, (emitter) => {
|
|
7879
8008
|
this.removeEmitter(container, emitter);
|
|
7880
8009
|
}, emitterOptions, position);
|
|
7881
8010
|
await emitter.init();
|
|
@@ -7884,22 +8013,22 @@
|
|
|
7884
8013
|
}
|
|
7885
8014
|
clear(container) {
|
|
7886
8015
|
this.initContainer(container);
|
|
7887
|
-
this.
|
|
8016
|
+
this.#containerArrays.set(container, []);
|
|
7888
8017
|
}
|
|
7889
8018
|
getArray(container) {
|
|
7890
8019
|
this.initContainer(container);
|
|
7891
|
-
let array = this.
|
|
8020
|
+
let array = this.#containerArrays.get(container);
|
|
7892
8021
|
if (!array) {
|
|
7893
8022
|
array = [];
|
|
7894
|
-
this.
|
|
8023
|
+
this.#containerArrays.set(container, array);
|
|
7895
8024
|
}
|
|
7896
8025
|
return array;
|
|
7897
8026
|
}
|
|
7898
8027
|
initContainer(container) {
|
|
7899
|
-
if (this.
|
|
8028
|
+
if (this.#containerArrays.has(container)) {
|
|
7900
8029
|
return;
|
|
7901
8030
|
}
|
|
7902
|
-
this.
|
|
8031
|
+
this.#containerArrays.set(container, []);
|
|
7903
8032
|
container.getEmitter = (idxOrName) => {
|
|
7904
8033
|
const array = this.getArray(container);
|
|
7905
8034
|
return idxOrName === undefined || isNumber(idxOrName)
|
|
@@ -7979,25 +8108,25 @@
|
|
|
7979
8108
|
icon.style.cssText += style;
|
|
7980
8109
|
}
|
|
7981
8110
|
class SoundsPluginInstance {
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
7986
|
-
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
8111
|
+
#audioMap;
|
|
8112
|
+
#audioSources;
|
|
8113
|
+
#container;
|
|
8114
|
+
#engine;
|
|
8115
|
+
#gain;
|
|
8116
|
+
#muteImg;
|
|
8117
|
+
#unmuteImg;
|
|
8118
|
+
#volume;
|
|
8119
|
+
#volumeDownImg;
|
|
8120
|
+
#volumeUpImg;
|
|
7992
8121
|
constructor(container, engine) {
|
|
7993
|
-
this
|
|
7994
|
-
this
|
|
7995
|
-
this
|
|
7996
|
-
this
|
|
7997
|
-
this
|
|
8122
|
+
this.#container = container;
|
|
8123
|
+
this.#engine = engine;
|
|
8124
|
+
this.#volume = 0;
|
|
8125
|
+
this.#audioSources = [];
|
|
8126
|
+
this.#audioMap = new Map();
|
|
7998
8127
|
}
|
|
7999
8128
|
async init() {
|
|
8000
|
-
const container = this
|
|
8129
|
+
const container = this.#container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
8001
8130
|
if (!soundsOptions?.enable) {
|
|
8002
8131
|
return;
|
|
8003
8132
|
}
|
|
@@ -8014,9 +8143,9 @@
|
|
|
8014
8143
|
addEventListener(mouseDownEvent, firstClickHandler, listenerOptions);
|
|
8015
8144
|
addEventListener(touchStartEvent, firstClickHandler, listenerOptions);
|
|
8016
8145
|
}
|
|
8017
|
-
this
|
|
8146
|
+
this.#volume = soundsOptions.volume.value;
|
|
8018
8147
|
const events = soundsOptions.events;
|
|
8019
|
-
this
|
|
8148
|
+
this.#audioMap = new Map();
|
|
8020
8149
|
for (const event of events) {
|
|
8021
8150
|
if (!event.audio) {
|
|
8022
8151
|
continue;
|
|
@@ -8026,8 +8155,8 @@
|
|
|
8026
8155
|
if (!response.ok) {
|
|
8027
8156
|
return;
|
|
8028
8157
|
}
|
|
8029
|
-
const arrayBuffer = await response.arrayBuffer(), audioContext = this
|
|
8030
|
-
this.
|
|
8158
|
+
const arrayBuffer = await response.arrayBuffer(), audioContext = this.#getAudioContext(), audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
|
8159
|
+
this.#audioMap.set(audio.source, audioBuffer);
|
|
8031
8160
|
});
|
|
8032
8161
|
if (promises instanceof Promise) {
|
|
8033
8162
|
await promises;
|
|
@@ -8038,12 +8167,12 @@
|
|
|
8038
8167
|
}
|
|
8039
8168
|
}
|
|
8040
8169
|
async mute() {
|
|
8041
|
-
if (!this.
|
|
8170
|
+
if (!this.#container.muted) {
|
|
8042
8171
|
await this.toggleMute();
|
|
8043
8172
|
}
|
|
8044
8173
|
}
|
|
8045
8174
|
async start() {
|
|
8046
|
-
const container = this
|
|
8175
|
+
const container = this.#container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
8047
8176
|
if (!soundsOptions?.enable || !container.canvas.domElement) {
|
|
8048
8177
|
return;
|
|
8049
8178
|
}
|
|
@@ -8054,7 +8183,7 @@
|
|
|
8054
8183
|
}, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
|
|
8055
8184
|
await this.toggleMute();
|
|
8056
8185
|
}, enableIcons = soundsOptions.icons.enable, display = enableIcons ? ImageDisplay.Block : ImageDisplay.None;
|
|
8057
|
-
this
|
|
8186
|
+
this.#muteImg = initImage({
|
|
8058
8187
|
container,
|
|
8059
8188
|
options,
|
|
8060
8189
|
pos,
|
|
@@ -8064,7 +8193,7 @@
|
|
|
8064
8193
|
rightOffsets: [volumeDown.width, volumeUp.width],
|
|
8065
8194
|
clickCb: toggleMute,
|
|
8066
8195
|
});
|
|
8067
|
-
this
|
|
8196
|
+
this.#unmuteImg = initImage({
|
|
8068
8197
|
container,
|
|
8069
8198
|
options,
|
|
8070
8199
|
pos,
|
|
@@ -8074,7 +8203,7 @@
|
|
|
8074
8203
|
rightOffsets: [volumeDown.width, volumeUp.width],
|
|
8075
8204
|
clickCb: toggleMute,
|
|
8076
8205
|
});
|
|
8077
|
-
this
|
|
8206
|
+
this.#volumeDownImg = initImage({
|
|
8078
8207
|
container,
|
|
8079
8208
|
options,
|
|
8080
8209
|
pos,
|
|
@@ -8086,7 +8215,7 @@
|
|
|
8086
8215
|
await this.volumeDown();
|
|
8087
8216
|
},
|
|
8088
8217
|
});
|
|
8089
|
-
this
|
|
8218
|
+
this.#volumeUpImg = initImage({
|
|
8090
8219
|
container,
|
|
8091
8220
|
options,
|
|
8092
8221
|
pos,
|
|
@@ -8103,62 +8232,62 @@
|
|
|
8103
8232
|
}
|
|
8104
8233
|
}
|
|
8105
8234
|
stop() {
|
|
8106
|
-
this.
|
|
8235
|
+
this.#container.muted = true;
|
|
8107
8236
|
void (async () => {
|
|
8108
|
-
await this
|
|
8109
|
-
removeImage(this
|
|
8110
|
-
removeImage(this
|
|
8111
|
-
removeImage(this
|
|
8112
|
-
removeImage(this
|
|
8237
|
+
await this.#mute();
|
|
8238
|
+
removeImage(this.#muteImg);
|
|
8239
|
+
removeImage(this.#unmuteImg);
|
|
8240
|
+
removeImage(this.#volumeDownImg);
|
|
8241
|
+
removeImage(this.#volumeUpImg);
|
|
8113
8242
|
})();
|
|
8114
8243
|
}
|
|
8115
8244
|
async toggleMute() {
|
|
8116
|
-
const container = this
|
|
8245
|
+
const container = this.#container;
|
|
8117
8246
|
container.muted = !container.muted;
|
|
8118
|
-
this
|
|
8119
|
-
await this
|
|
8247
|
+
this.#updateMuteIcons();
|
|
8248
|
+
await this.#updateMuteStatus();
|
|
8120
8249
|
}
|
|
8121
8250
|
async unmute() {
|
|
8122
|
-
if (this.
|
|
8251
|
+
if (this.#container.muted) {
|
|
8123
8252
|
await this.toggleMute();
|
|
8124
8253
|
}
|
|
8125
8254
|
}
|
|
8126
8255
|
async volumeDown() {
|
|
8127
|
-
const container = this
|
|
8256
|
+
const container = this.#container, soundsOptions = container.actualOptions.sounds;
|
|
8128
8257
|
if (!soundsOptions?.enable) {
|
|
8129
8258
|
return;
|
|
8130
8259
|
}
|
|
8131
8260
|
if (container.muted) {
|
|
8132
|
-
this
|
|
8261
|
+
this.#volume = 0;
|
|
8133
8262
|
}
|
|
8134
|
-
this
|
|
8135
|
-
await this
|
|
8263
|
+
this.#volume -= soundsOptions.volume.step;
|
|
8264
|
+
await this.#updateVolume();
|
|
8136
8265
|
}
|
|
8137
8266
|
async volumeUp() {
|
|
8138
|
-
const container = this
|
|
8267
|
+
const container = this.#container, soundsOptions = container.actualOptions.sounds;
|
|
8139
8268
|
if (!soundsOptions?.enable) {
|
|
8140
8269
|
return;
|
|
8141
8270
|
}
|
|
8142
|
-
this
|
|
8143
|
-
await this
|
|
8271
|
+
this.#volume += soundsOptions.volume.step;
|
|
8272
|
+
await this.#updateVolume();
|
|
8144
8273
|
}
|
|
8145
|
-
|
|
8274
|
+
#addBuffer = audioCtx => {
|
|
8146
8275
|
const buffer = audioCtx.createBufferSource();
|
|
8147
|
-
this.
|
|
8276
|
+
this.#audioSources.push(buffer);
|
|
8148
8277
|
return buffer;
|
|
8149
8278
|
};
|
|
8150
|
-
|
|
8279
|
+
#addOscillator = audioCtx => {
|
|
8151
8280
|
const oscillator = audioCtx.createOscillator();
|
|
8152
|
-
this.
|
|
8281
|
+
this.#audioSources.push(oscillator);
|
|
8153
8282
|
return oscillator;
|
|
8154
8283
|
};
|
|
8155
|
-
|
|
8156
|
-
const container = this
|
|
8284
|
+
#getAudioContext() {
|
|
8285
|
+
const container = this.#container;
|
|
8157
8286
|
container.audioContext ??= new AudioContext();
|
|
8158
8287
|
return container.audioContext;
|
|
8159
8288
|
}
|
|
8160
|
-
|
|
8161
|
-
const container = this
|
|
8289
|
+
#initEvents = () => {
|
|
8290
|
+
const container = this.#container, soundsOptions = container.actualOptions.sounds;
|
|
8162
8291
|
if (!soundsOptions?.enable || !container.canvas.domElement) {
|
|
8163
8292
|
return;
|
|
8164
8293
|
}
|
|
@@ -8169,12 +8298,12 @@
|
|
|
8169
8298
|
}
|
|
8170
8299
|
void (async () => {
|
|
8171
8300
|
const filterNotValid = event.filter && !event.filter(args);
|
|
8172
|
-
if (this
|
|
8301
|
+
if (this.#container !== args.container) {
|
|
8173
8302
|
return;
|
|
8174
8303
|
}
|
|
8175
|
-
if (!!this.
|
|
8304
|
+
if (!!this.#container.muted || this.#container.destroyed) {
|
|
8176
8305
|
executeOnSingleOrMultiple(event.event, item => {
|
|
8177
|
-
this.
|
|
8306
|
+
this.#engine.removeEventListener(item, cb);
|
|
8178
8307
|
});
|
|
8179
8308
|
return;
|
|
8180
8309
|
}
|
|
@@ -8187,7 +8316,7 @@
|
|
|
8187
8316
|
if (!audio) {
|
|
8188
8317
|
return;
|
|
8189
8318
|
}
|
|
8190
|
-
this
|
|
8319
|
+
this.#playBuffer(audio);
|
|
8191
8320
|
}
|
|
8192
8321
|
else if (event.melodies) {
|
|
8193
8322
|
const melody = itemFromArray(event.melodies);
|
|
@@ -8195,10 +8324,10 @@
|
|
|
8195
8324
|
return;
|
|
8196
8325
|
}
|
|
8197
8326
|
if (melody.melodies.length) {
|
|
8198
|
-
await Promise.allSettled(melody.melodies.map(m => this
|
|
8327
|
+
await Promise.allSettled(melody.melodies.map(m => this.#playNote(m.notes, defaultNoteIndex, melody.loop)));
|
|
8199
8328
|
}
|
|
8200
8329
|
else {
|
|
8201
|
-
await this
|
|
8330
|
+
await this.#playNote(melody.notes, defaultNoteIndex, melody.loop);
|
|
8202
8331
|
}
|
|
8203
8332
|
}
|
|
8204
8333
|
else if (event.notes) {
|
|
@@ -8206,63 +8335,63 @@
|
|
|
8206
8335
|
if (!note) {
|
|
8207
8336
|
return;
|
|
8208
8337
|
}
|
|
8209
|
-
await this
|
|
8338
|
+
await this.#playNote([note], defaultNoteIndex, false);
|
|
8210
8339
|
}
|
|
8211
8340
|
})();
|
|
8212
8341
|
};
|
|
8213
8342
|
executeOnSingleOrMultiple(event.event, item => {
|
|
8214
|
-
this.
|
|
8343
|
+
this.#engine.addEventListener(item, cb);
|
|
8215
8344
|
});
|
|
8216
8345
|
}
|
|
8217
8346
|
};
|
|
8218
|
-
|
|
8219
|
-
const container = this
|
|
8220
|
-
for (const source of this
|
|
8221
|
-
this
|
|
8347
|
+
#mute = async () => {
|
|
8348
|
+
const container = this.#container, audioContext = this.#getAudioContext();
|
|
8349
|
+
for (const source of this.#audioSources) {
|
|
8350
|
+
this.#removeAudioSource(source);
|
|
8222
8351
|
}
|
|
8223
|
-
if (this
|
|
8224
|
-
this.
|
|
8352
|
+
if (this.#gain) {
|
|
8353
|
+
this.#gain.disconnect();
|
|
8225
8354
|
}
|
|
8226
8355
|
await audioContext.close();
|
|
8227
8356
|
container.audioContext = undefined;
|
|
8228
|
-
this.
|
|
8357
|
+
this.#container.dispatchEvent(SoundsEventType.mute);
|
|
8229
8358
|
};
|
|
8230
|
-
|
|
8231
|
-
const audioBuffer = this.
|
|
8359
|
+
#playBuffer = audio => {
|
|
8360
|
+
const audioBuffer = this.#audioMap.get(audio.source);
|
|
8232
8361
|
if (!audioBuffer) {
|
|
8233
8362
|
return;
|
|
8234
8363
|
}
|
|
8235
|
-
const audioCtx = this.
|
|
8364
|
+
const audioCtx = this.#container.audioContext;
|
|
8236
8365
|
if (!audioCtx) {
|
|
8237
8366
|
return;
|
|
8238
8367
|
}
|
|
8239
|
-
const source = this
|
|
8368
|
+
const source = this.#addBuffer(audioCtx);
|
|
8240
8369
|
source.loop = audio.loop;
|
|
8241
8370
|
source.buffer = audioBuffer;
|
|
8242
|
-
source.connect(this
|
|
8371
|
+
source.connect(this.#gain ?? audioCtx.destination);
|
|
8243
8372
|
source.start();
|
|
8244
8373
|
};
|
|
8245
|
-
|
|
8246
|
-
if (!this
|
|
8374
|
+
#playFrequency = async (frequency, duration) => {
|
|
8375
|
+
if (!this.#gain || this.#container.muted) {
|
|
8247
8376
|
return;
|
|
8248
8377
|
}
|
|
8249
|
-
const audioContext = this
|
|
8250
|
-
oscillator.connect(this
|
|
8378
|
+
const audioContext = this.#getAudioContext(), oscillator = this.#addOscillator(audioContext);
|
|
8379
|
+
oscillator.connect(this.#gain);
|
|
8251
8380
|
oscillator.type = "sine";
|
|
8252
8381
|
oscillator.frequency.value = frequency;
|
|
8253
8382
|
oscillator.start();
|
|
8254
8383
|
return new Promise(resolve => {
|
|
8255
8384
|
setTimeout(() => {
|
|
8256
|
-
this
|
|
8385
|
+
this.#removeAudioSource(oscillator);
|
|
8257
8386
|
resolve();
|
|
8258
8387
|
}, duration);
|
|
8259
8388
|
});
|
|
8260
8389
|
};
|
|
8261
|
-
|
|
8262
|
-
if (this.
|
|
8390
|
+
#playMuteSound = () => {
|
|
8391
|
+
if (this.#container.muted) {
|
|
8263
8392
|
return;
|
|
8264
8393
|
}
|
|
8265
|
-
const audioContext = this
|
|
8394
|
+
const audioContext = this.#getAudioContext(), gain = audioContext.createGain();
|
|
8266
8395
|
gain.connect(audioContext.destination);
|
|
8267
8396
|
gain.gain.value = 0;
|
|
8268
8397
|
const oscillator = audioContext.createOscillator();
|
|
@@ -8276,8 +8405,8 @@
|
|
|
8276
8405
|
gain.disconnect();
|
|
8277
8406
|
});
|
|
8278
8407
|
};
|
|
8279
|
-
|
|
8280
|
-
if (this.
|
|
8408
|
+
#playNote = async (notes, noteIdx, loop) => {
|
|
8409
|
+
if (this.#container.muted) {
|
|
8281
8410
|
return;
|
|
8282
8411
|
}
|
|
8283
8412
|
const note = notes[noteIdx];
|
|
@@ -8285,7 +8414,7 @@
|
|
|
8285
8414
|
return;
|
|
8286
8415
|
}
|
|
8287
8416
|
const value = note.value, promises = executeOnSingleOrMultiple(value, async (_, idx) => {
|
|
8288
|
-
return this
|
|
8417
|
+
return this.#playNoteValue(notes, noteIdx, idx);
|
|
8289
8418
|
});
|
|
8290
8419
|
await (isArray(promises) ? Promise.allSettled(promises) : promises);
|
|
8291
8420
|
const indexOffset = 1;
|
|
@@ -8293,9 +8422,9 @@
|
|
|
8293
8422
|
if (loop && nextNoteIdx >= notes.length) {
|
|
8294
8423
|
nextNoteIdx = nextNoteIdx % notes.length;
|
|
8295
8424
|
}
|
|
8296
|
-
await this
|
|
8425
|
+
await this.#playNote(notes, nextNoteIdx, loop);
|
|
8297
8426
|
};
|
|
8298
|
-
|
|
8427
|
+
#playNoteValue = async (notes, noteIdx, valueIdx) => {
|
|
8299
8428
|
const note = notes[noteIdx];
|
|
8300
8429
|
if (!note) {
|
|
8301
8430
|
return;
|
|
@@ -8309,36 +8438,36 @@
|
|
|
8309
8438
|
if (!isNumber(freq)) {
|
|
8310
8439
|
return;
|
|
8311
8440
|
}
|
|
8312
|
-
await this
|
|
8441
|
+
await this.#playFrequency(freq, note.duration);
|
|
8313
8442
|
}
|
|
8314
8443
|
catch (e) {
|
|
8315
8444
|
getLogger().error(e);
|
|
8316
8445
|
}
|
|
8317
8446
|
};
|
|
8318
|
-
|
|
8447
|
+
#removeAudioSource = source => {
|
|
8319
8448
|
source.stop();
|
|
8320
8449
|
source.disconnect();
|
|
8321
8450
|
const deleteCount = 1;
|
|
8322
|
-
this.
|
|
8451
|
+
this.#audioSources.splice(this.#audioSources.indexOf(source), deleteCount);
|
|
8323
8452
|
};
|
|
8324
|
-
|
|
8325
|
-
const container = this
|
|
8453
|
+
#unmute = () => {
|
|
8454
|
+
const container = this.#container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
8326
8455
|
if (!soundsOptions) {
|
|
8327
8456
|
return;
|
|
8328
8457
|
}
|
|
8329
|
-
const audioContext = this
|
|
8458
|
+
const audioContext = this.#getAudioContext(), gain = audioContext.createGain();
|
|
8330
8459
|
gain.connect(audioContext.destination);
|
|
8331
8460
|
gain.gain.value = soundsOptions.volume.value / percentDenominator;
|
|
8332
|
-
this
|
|
8333
|
-
this
|
|
8334
|
-
this.
|
|
8461
|
+
this.#gain = gain;
|
|
8462
|
+
this.#initEvents();
|
|
8463
|
+
this.#container.dispatchEvent(SoundsEventType.unmute);
|
|
8335
8464
|
};
|
|
8336
|
-
|
|
8337
|
-
const container = this
|
|
8465
|
+
#updateMuteIcons = () => {
|
|
8466
|
+
const container = this.#container, soundsOptions = container.actualOptions.sounds;
|
|
8338
8467
|
if (!soundsOptions?.enable || !soundsOptions.icons.enable) {
|
|
8339
8468
|
return;
|
|
8340
8469
|
}
|
|
8341
|
-
const muteImg = this
|
|
8470
|
+
const muteImg = this.#muteImg, unmuteImg = this.#unmuteImg;
|
|
8342
8471
|
if (muteImg) {
|
|
8343
8472
|
muteImg.style.display = container.muted ? "block" : "none";
|
|
8344
8473
|
}
|
|
@@ -8346,40 +8475,40 @@
|
|
|
8346
8475
|
unmuteImg.style.display = container.muted ? "none" : "block";
|
|
8347
8476
|
}
|
|
8348
8477
|
};
|
|
8349
|
-
|
|
8350
|
-
const container = this
|
|
8478
|
+
#updateMuteStatus = async () => {
|
|
8479
|
+
const container = this.#container, audioContext = this.#getAudioContext();
|
|
8351
8480
|
if (container.muted) {
|
|
8352
8481
|
await audioContext.suspend();
|
|
8353
|
-
await this
|
|
8482
|
+
await this.#mute();
|
|
8354
8483
|
}
|
|
8355
8484
|
else {
|
|
8356
8485
|
await audioContext.resume();
|
|
8357
|
-
this
|
|
8358
|
-
this
|
|
8486
|
+
this.#unmute();
|
|
8487
|
+
this.#playMuteSound();
|
|
8359
8488
|
}
|
|
8360
8489
|
};
|
|
8361
|
-
|
|
8362
|
-
const container = this
|
|
8490
|
+
#updateVolume = async () => {
|
|
8491
|
+
const container = this.#container, soundsOptions = container.actualOptions.sounds;
|
|
8363
8492
|
if (!soundsOptions?.enable) {
|
|
8364
8493
|
return;
|
|
8365
8494
|
}
|
|
8366
|
-
clamp(this
|
|
8495
|
+
clamp(this.#volume, soundsOptions.volume.min, soundsOptions.volume.max);
|
|
8367
8496
|
let stateChanged = false;
|
|
8368
|
-
if (this
|
|
8369
|
-
this
|
|
8497
|
+
if (this.#volume <= minVolume && !container.muted) {
|
|
8498
|
+
this.#volume = 0;
|
|
8370
8499
|
container.muted = true;
|
|
8371
8500
|
stateChanged = true;
|
|
8372
8501
|
}
|
|
8373
|
-
else if (this
|
|
8502
|
+
else if (this.#volume > minVolume && container.muted) {
|
|
8374
8503
|
container.muted = false;
|
|
8375
8504
|
stateChanged = true;
|
|
8376
8505
|
}
|
|
8377
8506
|
if (stateChanged) {
|
|
8378
|
-
this
|
|
8379
|
-
await this
|
|
8507
|
+
this.#updateMuteIcons();
|
|
8508
|
+
await this.#updateMuteStatus();
|
|
8380
8509
|
}
|
|
8381
|
-
if (this
|
|
8382
|
-
this.
|
|
8510
|
+
if (this.#gain?.gain) {
|
|
8511
|
+
this.#gain.gain.value = this.#volume / percentDenominator;
|
|
8383
8512
|
}
|
|
8384
8513
|
};
|
|
8385
8514
|
}
|
|
@@ -8418,34 +8547,34 @@
|
|
|
8418
8547
|
spawnStrokeColor;
|
|
8419
8548
|
spawnStrokeOpacity;
|
|
8420
8549
|
spawnStrokeWidth;
|
|
8421
|
-
|
|
8422
|
-
|
|
8423
|
-
|
|
8424
|
-
|
|
8425
|
-
|
|
8426
|
-
|
|
8427
|
-
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8431
|
-
|
|
8432
|
-
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8550
|
+
#container;
|
|
8551
|
+
#currentDuration;
|
|
8552
|
+
#currentEmitDelay;
|
|
8553
|
+
#currentSpawnDelay;
|
|
8554
|
+
#duration;
|
|
8555
|
+
#emitDelay;
|
|
8556
|
+
#firstSpawn;
|
|
8557
|
+
#immortal;
|
|
8558
|
+
#initialPosition;
|
|
8559
|
+
#lifeCount;
|
|
8560
|
+
#mutationObserver;
|
|
8561
|
+
#particlesOptions;
|
|
8562
|
+
#paused;
|
|
8563
|
+
#pluginManager;
|
|
8564
|
+
#removeCallback;
|
|
8565
|
+
#resizeObserver;
|
|
8566
|
+
#shape;
|
|
8567
|
+
#size;
|
|
8568
|
+
#spawnDelay;
|
|
8569
|
+
#startParticlesAdded;
|
|
8441
8570
|
constructor(pluginManager, container, removeCallback, options, position) {
|
|
8442
|
-
this
|
|
8443
|
-
this
|
|
8444
|
-
this
|
|
8445
|
-
this
|
|
8446
|
-
this
|
|
8447
|
-
this
|
|
8448
|
-
this
|
|
8571
|
+
this.#pluginManager = pluginManager;
|
|
8572
|
+
this.#container = container;
|
|
8573
|
+
this.#removeCallback = removeCallback;
|
|
8574
|
+
this.#currentDuration = 0;
|
|
8575
|
+
this.#currentEmitDelay = 0;
|
|
8576
|
+
this.#currentSpawnDelay = 0;
|
|
8577
|
+
this.#initialPosition = position;
|
|
8449
8578
|
if (options instanceof Emitter) {
|
|
8450
8579
|
this.options = options;
|
|
8451
8580
|
}
|
|
@@ -8453,159 +8582,159 @@
|
|
|
8453
8582
|
this.options = new Emitter();
|
|
8454
8583
|
this.options.load(options);
|
|
8455
8584
|
}
|
|
8456
|
-
this
|
|
8585
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
8457
8586
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
8458
8587
|
container.retina.reduceFactor
|
|
8459
8588
|
: Infinity;
|
|
8460
|
-
this.position = this
|
|
8589
|
+
this.position = this.#initialPosition ?? this.#calcPosition();
|
|
8461
8590
|
this.name = this.options.name;
|
|
8462
8591
|
this.fill = this.options.fill;
|
|
8463
|
-
this
|
|
8464
|
-
this
|
|
8592
|
+
this.#firstSpawn = !this.options.life.wait;
|
|
8593
|
+
this.#startParticlesAdded = false;
|
|
8465
8594
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
8466
8595
|
particlesOptions.move ??= {};
|
|
8467
8596
|
particlesOptions.move.direction ??= this.options.direction;
|
|
8468
8597
|
if (this.options.spawn.fill?.color) {
|
|
8469
|
-
this.spawnFillColor = rangeColorToHsl(this
|
|
8598
|
+
this.spawnFillColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.fill.color);
|
|
8470
8599
|
}
|
|
8471
8600
|
if (this.options.spawn.stroke?.color) {
|
|
8472
|
-
this.spawnStrokeColor = rangeColorToHsl(this
|
|
8473
|
-
}
|
|
8474
|
-
this
|
|
8475
|
-
this
|
|
8476
|
-
this
|
|
8477
|
-
this.size = getSize(this
|
|
8478
|
-
this
|
|
8479
|
-
this
|
|
8601
|
+
this.spawnStrokeColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.stroke.color);
|
|
8602
|
+
}
|
|
8603
|
+
this.#paused = !this.options.autoPlay;
|
|
8604
|
+
this.#particlesOptions = particlesOptions;
|
|
8605
|
+
this.#size = this.#calcSize();
|
|
8606
|
+
this.size = getSize(this.#size, this.#container.canvas.size);
|
|
8607
|
+
this.#lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
8608
|
+
this.#immortal = this.#lifeCount <= minLifeCount;
|
|
8480
8609
|
if (this.options.domId) {
|
|
8481
8610
|
const element = safeDocument().getElementById(this.options.domId);
|
|
8482
8611
|
if (element) {
|
|
8483
|
-
this
|
|
8612
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
8484
8613
|
this.resize();
|
|
8485
8614
|
});
|
|
8486
|
-
this
|
|
8615
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
8487
8616
|
this.resize();
|
|
8488
8617
|
});
|
|
8489
|
-
this.
|
|
8618
|
+
this.#mutationObserver.observe(element, {
|
|
8490
8619
|
attributes: true,
|
|
8491
8620
|
attributeFilter: ["style", "width", "height"],
|
|
8492
8621
|
});
|
|
8493
|
-
this.
|
|
8622
|
+
this.#resizeObserver.observe(element);
|
|
8494
8623
|
}
|
|
8495
8624
|
}
|
|
8496
|
-
const shapeOptions = this.options.shape, shapeGenerator = this.
|
|
8625
|
+
const shapeOptions = this.options.shape, shapeGenerator = this.#pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
8497
8626
|
if (shapeGenerator) {
|
|
8498
|
-
this
|
|
8627
|
+
this.#shape = shapeGenerator.generate(this.#container, this.position, this.size, this.fill, shapeOptions.options);
|
|
8499
8628
|
}
|
|
8500
|
-
this.
|
|
8629
|
+
this.#container.dispatchEvent("emitterCreated", {
|
|
8501
8630
|
emitter: this,
|
|
8502
8631
|
});
|
|
8503
8632
|
this.play();
|
|
8504
8633
|
}
|
|
8505
8634
|
externalPause() {
|
|
8506
|
-
this
|
|
8635
|
+
this.#paused = true;
|
|
8507
8636
|
this.pause();
|
|
8508
8637
|
}
|
|
8509
8638
|
externalPlay() {
|
|
8510
|
-
this
|
|
8639
|
+
this.#paused = false;
|
|
8511
8640
|
this.play();
|
|
8512
8641
|
}
|
|
8513
8642
|
async init() {
|
|
8514
|
-
await this
|
|
8643
|
+
await this.#shape?.init();
|
|
8515
8644
|
}
|
|
8516
8645
|
pause() {
|
|
8517
|
-
if (this
|
|
8646
|
+
if (this.#paused) {
|
|
8518
8647
|
return;
|
|
8519
8648
|
}
|
|
8520
|
-
|
|
8649
|
+
this.#emitDelay = undefined;
|
|
8521
8650
|
}
|
|
8522
8651
|
play() {
|
|
8523
|
-
if (this
|
|
8652
|
+
if (this.#paused) {
|
|
8524
8653
|
return;
|
|
8525
8654
|
}
|
|
8526
|
-
if (!((this
|
|
8527
|
-
(this
|
|
8655
|
+
if (!((this.#lifeCount > minLifeCount || this.#immortal || !this.options.life.count) &&
|
|
8656
|
+
(this.#firstSpawn || this.#currentSpawnDelay >= (this.#spawnDelay ?? defaultSpawnDelay)))) {
|
|
8528
8657
|
return;
|
|
8529
8658
|
}
|
|
8530
|
-
const container = this
|
|
8531
|
-
if (this
|
|
8659
|
+
const container = this.#container;
|
|
8660
|
+
if (this.#emitDelay === undefined) {
|
|
8532
8661
|
const delay = getRangeValue(this.options.rate.delay);
|
|
8533
|
-
this
|
|
8662
|
+
this.#emitDelay = container.retina.reduceFactor
|
|
8534
8663
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
8535
8664
|
: Infinity;
|
|
8536
8665
|
}
|
|
8537
|
-
if (this
|
|
8538
|
-
this
|
|
8666
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
8667
|
+
this.#prepareToDie();
|
|
8539
8668
|
}
|
|
8540
8669
|
}
|
|
8541
8670
|
resize() {
|
|
8542
|
-
const initialPosition = this
|
|
8671
|
+
const initialPosition = this.#initialPosition, container = this.#container;
|
|
8543
8672
|
this.position =
|
|
8544
8673
|
initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
|
|
8545
8674
|
? initialPosition
|
|
8546
|
-
: this
|
|
8547
|
-
this
|
|
8548
|
-
this.size = getSize(this
|
|
8549
|
-
this
|
|
8675
|
+
: this.#calcPosition();
|
|
8676
|
+
this.#size = this.#calcSize();
|
|
8677
|
+
this.size = getSize(this.#size, container.canvas.size);
|
|
8678
|
+
this.#shape?.resize(this.position, this.size);
|
|
8550
8679
|
}
|
|
8551
8680
|
update(delta) {
|
|
8552
|
-
if (this
|
|
8681
|
+
if (this.#paused) {
|
|
8553
8682
|
return;
|
|
8554
8683
|
}
|
|
8555
|
-
const container = this
|
|
8556
|
-
if (this
|
|
8557
|
-
this
|
|
8558
|
-
this
|
|
8559
|
-
this
|
|
8684
|
+
const container = this.#container;
|
|
8685
|
+
if (this.#firstSpawn) {
|
|
8686
|
+
this.#firstSpawn = false;
|
|
8687
|
+
this.#currentSpawnDelay = this.#spawnDelay ?? defaultSpawnDelay;
|
|
8688
|
+
this.#currentEmitDelay = this.#emitDelay ?? defaultEmitDelay;
|
|
8560
8689
|
}
|
|
8561
|
-
if (!this
|
|
8562
|
-
this
|
|
8563
|
-
this
|
|
8690
|
+
if (!this.#startParticlesAdded) {
|
|
8691
|
+
this.#startParticlesAdded = true;
|
|
8692
|
+
this.#emitParticles(this.options.startCount);
|
|
8564
8693
|
}
|
|
8565
|
-
if (this
|
|
8566
|
-
this
|
|
8567
|
-
if (this
|
|
8694
|
+
if (this.#duration !== undefined) {
|
|
8695
|
+
this.#currentDuration += delta.value;
|
|
8696
|
+
if (this.#currentDuration >= this.#duration) {
|
|
8568
8697
|
this.pause();
|
|
8569
|
-
if (this
|
|
8570
|
-
|
|
8698
|
+
if (this.#spawnDelay !== undefined) {
|
|
8699
|
+
this.#spawnDelay = undefined;
|
|
8571
8700
|
}
|
|
8572
|
-
if (!this
|
|
8573
|
-
this
|
|
8701
|
+
if (!this.#immortal) {
|
|
8702
|
+
this.#lifeCount--;
|
|
8574
8703
|
}
|
|
8575
|
-
if (this
|
|
8576
|
-
this.position = this
|
|
8577
|
-
this
|
|
8578
|
-
this
|
|
8704
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
8705
|
+
this.position = this.#calcPosition();
|
|
8706
|
+
this.#shape?.resize(this.position, this.size);
|
|
8707
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
8579
8708
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
8580
8709
|
container.retina.reduceFactor
|
|
8581
8710
|
: Infinity;
|
|
8582
8711
|
}
|
|
8583
8712
|
else {
|
|
8584
|
-
this
|
|
8713
|
+
this.#destroy();
|
|
8585
8714
|
}
|
|
8586
|
-
this
|
|
8587
|
-
|
|
8715
|
+
this.#currentDuration -= this.#duration;
|
|
8716
|
+
this.#duration = undefined;
|
|
8588
8717
|
}
|
|
8589
8718
|
}
|
|
8590
|
-
if (this
|
|
8591
|
-
this
|
|
8592
|
-
if (this
|
|
8593
|
-
this.
|
|
8719
|
+
if (this.#spawnDelay !== undefined) {
|
|
8720
|
+
this.#currentSpawnDelay += delta.value;
|
|
8721
|
+
if (this.#currentSpawnDelay >= this.#spawnDelay) {
|
|
8722
|
+
this.#container.dispatchEvent("emitterPlay");
|
|
8594
8723
|
this.play();
|
|
8595
|
-
this
|
|
8596
|
-
|
|
8724
|
+
this.#currentSpawnDelay -= this.#spawnDelay;
|
|
8725
|
+
this.#spawnDelay = undefined;
|
|
8597
8726
|
}
|
|
8598
8727
|
}
|
|
8599
|
-
if (this
|
|
8600
|
-
this
|
|
8601
|
-
if (this
|
|
8602
|
-
this
|
|
8603
|
-
this
|
|
8728
|
+
if (this.#emitDelay !== undefined) {
|
|
8729
|
+
this.#currentEmitDelay += delta.value;
|
|
8730
|
+
if (this.#currentEmitDelay >= this.#emitDelay) {
|
|
8731
|
+
this.#emit();
|
|
8732
|
+
this.#currentEmitDelay -= this.#emitDelay;
|
|
8604
8733
|
}
|
|
8605
8734
|
}
|
|
8606
8735
|
}
|
|
8607
|
-
|
|
8608
|
-
const container = this
|
|
8736
|
+
#calcPosition() {
|
|
8737
|
+
const container = this.#container;
|
|
8609
8738
|
if (this.options.domId) {
|
|
8610
8739
|
const element = safeDocument().getElementById(this.options.domId);
|
|
8611
8740
|
if (element) {
|
|
@@ -8621,8 +8750,8 @@
|
|
|
8621
8750
|
position: this.options.position,
|
|
8622
8751
|
});
|
|
8623
8752
|
}
|
|
8624
|
-
|
|
8625
|
-
const container = this
|
|
8753
|
+
#calcSize() {
|
|
8754
|
+
const container = this.#container;
|
|
8626
8755
|
if (this.options.domId) {
|
|
8627
8756
|
const element = safeDocument().getElementById(this.options.domId);
|
|
8628
8757
|
if (element) {
|
|
@@ -8645,32 +8774,32 @@
|
|
|
8645
8774
|
return size;
|
|
8646
8775
|
})());
|
|
8647
8776
|
}
|
|
8648
|
-
|
|
8649
|
-
this
|
|
8650
|
-
this
|
|
8651
|
-
this
|
|
8652
|
-
this
|
|
8653
|
-
this
|
|
8654
|
-
this.
|
|
8777
|
+
#destroy = () => {
|
|
8778
|
+
this.#mutationObserver?.disconnect();
|
|
8779
|
+
this.#mutationObserver = undefined;
|
|
8780
|
+
this.#resizeObserver?.disconnect();
|
|
8781
|
+
this.#resizeObserver = undefined;
|
|
8782
|
+
this.#removeCallback(this);
|
|
8783
|
+
this.#container.dispatchEvent("emitterDestroyed", {
|
|
8655
8784
|
emitter: this,
|
|
8656
8785
|
});
|
|
8657
8786
|
};
|
|
8658
|
-
|
|
8659
|
-
if (this
|
|
8787
|
+
#emit() {
|
|
8788
|
+
if (this.#paused) {
|
|
8660
8789
|
return;
|
|
8661
8790
|
}
|
|
8662
8791
|
const quantity = getRangeValue(this.options.rate.quantity);
|
|
8663
|
-
this
|
|
8792
|
+
this.#emitParticles(quantity);
|
|
8664
8793
|
}
|
|
8665
|
-
|
|
8666
|
-
const singleParticlesOptions = (itemFromSingleOrMultiple(this
|
|
8794
|
+
#emitParticles(quantity) {
|
|
8795
|
+
const singleParticlesOptions = (itemFromSingleOrMultiple(this.#particlesOptions) ??
|
|
8667
8796
|
{}), 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
|
|
8668
8797
|
? defaultOpacity$1
|
|
8669
8798
|
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
8670
8799
|
? defaultOpacity$1
|
|
8671
8800
|
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
8672
8801
|
? defaultStrokeWidth
|
|
8673
|
-
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.
|
|
8802
|
+
: 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;
|
|
8674
8803
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
8675
8804
|
const particlesOptions = needsCopy
|
|
8676
8805
|
? deepExtend({}, singleParticlesOptions)
|
|
@@ -8681,23 +8810,23 @@
|
|
|
8681
8810
|
this.spawnStrokeWidth = strokeWidth;
|
|
8682
8811
|
if (this.spawnFillColor) {
|
|
8683
8812
|
if (fillHslAnimation && maxValues) {
|
|
8684
|
-
this.spawnFillColor.h = this
|
|
8685
|
-
this.spawnFillColor.s = this
|
|
8686
|
-
this.spawnFillColor.l = this
|
|
8813
|
+
this.spawnFillColor.h = this.#setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
8814
|
+
this.spawnFillColor.s = this.#setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
8815
|
+
this.spawnFillColor.l = this.#setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
8687
8816
|
}
|
|
8688
8817
|
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
8689
8818
|
}
|
|
8690
8819
|
if (this.spawnStrokeColor) {
|
|
8691
8820
|
if (strokeHslAnimation && maxValues) {
|
|
8692
|
-
this.spawnStrokeColor.h = this
|
|
8693
|
-
this.spawnStrokeColor.s = this
|
|
8694
|
-
this.spawnStrokeColor.l = this
|
|
8821
|
+
this.spawnStrokeColor.h = this.#setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
8822
|
+
this.spawnStrokeColor.s = this.#setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
8823
|
+
this.spawnStrokeColor.l = this.#setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
8695
8824
|
}
|
|
8696
8825
|
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
8697
8826
|
}
|
|
8698
8827
|
let position = this.position;
|
|
8699
|
-
if (this
|
|
8700
|
-
const shapePosData = this.
|
|
8828
|
+
if (this.#shape) {
|
|
8829
|
+
const shapePosData = this.#shape.randomPosition();
|
|
8701
8830
|
if (shapePosData) {
|
|
8702
8831
|
position = shapePosData.position;
|
|
8703
8832
|
const replaceData = shapeOptions.replace;
|
|
@@ -8710,21 +8839,21 @@
|
|
|
8710
8839
|
}
|
|
8711
8840
|
}
|
|
8712
8841
|
if (position) {
|
|
8713
|
-
this.
|
|
8842
|
+
this.#container.particles.addParticle(position, particlesOptions);
|
|
8714
8843
|
}
|
|
8715
8844
|
}
|
|
8716
8845
|
}
|
|
8717
|
-
|
|
8718
|
-
if (this
|
|
8846
|
+
#prepareToDie = () => {
|
|
8847
|
+
if (this.#paused) {
|
|
8719
8848
|
return;
|
|
8720
8849
|
}
|
|
8721
8850
|
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
8722
|
-
if ((this
|
|
8723
|
-
this
|
|
8851
|
+
if ((this.#lifeCount > minLifeCount || this.#immortal) && duration !== undefined && duration > minDuration) {
|
|
8852
|
+
this.#duration = duration * millisecondsToSeconds;
|
|
8724
8853
|
}
|
|
8725
8854
|
};
|
|
8726
|
-
|
|
8727
|
-
const container = this
|
|
8855
|
+
#setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
8856
|
+
const container = this.#container;
|
|
8728
8857
|
if (!animation.enable) {
|
|
8729
8858
|
return initValue;
|
|
8730
8859
|
}
|