@tsparticles/preset-confetti 4.0.4 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* Preset v4.0
|
|
2
|
+
/* Preset v4.1.0 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -727,38 +727,38 @@
|
|
|
727
727
|
}
|
|
728
728
|
|
|
729
729
|
class EventDispatcher {
|
|
730
|
-
|
|
730
|
+
#listeners;
|
|
731
731
|
constructor() {
|
|
732
|
-
this
|
|
732
|
+
this.#listeners = new Map();
|
|
733
733
|
}
|
|
734
734
|
addEventListener(type, listener) {
|
|
735
735
|
this.removeEventListener(type, listener);
|
|
736
|
-
let arr = this.
|
|
736
|
+
let arr = this.#listeners.get(type);
|
|
737
737
|
if (!arr) {
|
|
738
738
|
arr = [];
|
|
739
|
-
this.
|
|
739
|
+
this.#listeners.set(type, arr);
|
|
740
740
|
}
|
|
741
741
|
arr.push(listener);
|
|
742
742
|
}
|
|
743
743
|
dispatchEvent(type, args) {
|
|
744
|
-
const listeners = this.
|
|
744
|
+
const listeners = this.#listeners.get(type);
|
|
745
745
|
listeners?.forEach(handler => {
|
|
746
746
|
handler(args);
|
|
747
747
|
});
|
|
748
748
|
}
|
|
749
749
|
hasEventListener(type) {
|
|
750
|
-
return !!this.
|
|
750
|
+
return !!this.#listeners.get(type);
|
|
751
751
|
}
|
|
752
752
|
removeAllEventListeners(type) {
|
|
753
753
|
if (!type) {
|
|
754
|
-
this
|
|
754
|
+
this.#listeners = new Map();
|
|
755
755
|
}
|
|
756
756
|
else {
|
|
757
|
-
this.
|
|
757
|
+
this.#listeners.delete(type);
|
|
758
758
|
}
|
|
759
759
|
}
|
|
760
760
|
removeEventListener(type, listener) {
|
|
761
|
-
const arr = this.
|
|
761
|
+
const arr = this.#listeners.get(type);
|
|
762
762
|
if (!arr) {
|
|
763
763
|
return;
|
|
764
764
|
}
|
|
@@ -767,7 +767,7 @@
|
|
|
767
767
|
return;
|
|
768
768
|
}
|
|
769
769
|
if (length === deleteCount) {
|
|
770
|
-
this.
|
|
770
|
+
this.#listeners.delete(type);
|
|
771
771
|
}
|
|
772
772
|
else {
|
|
773
773
|
arr.splice(idx, deleteCount);
|
|
@@ -805,19 +805,19 @@
|
|
|
805
805
|
presets = new Map();
|
|
806
806
|
shapeDrawers = new Map();
|
|
807
807
|
updaters = new Map();
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
808
|
+
#allLoadersSet = new Set();
|
|
809
|
+
#configs = new Map();
|
|
810
|
+
#engine;
|
|
811
|
+
#executedSet = new Set();
|
|
812
|
+
#initialized = false;
|
|
813
|
+
#isRunningLoaders = false;
|
|
814
|
+
#loadPromises = new Set();
|
|
815
815
|
constructor(engine) {
|
|
816
|
-
this
|
|
816
|
+
this.#engine = engine;
|
|
817
817
|
}
|
|
818
818
|
get configs() {
|
|
819
819
|
const res = {};
|
|
820
|
-
for (const [name, config] of this
|
|
820
|
+
for (const [name, config] of this.#configs) {
|
|
821
821
|
res[name] = config;
|
|
822
822
|
}
|
|
823
823
|
return res;
|
|
@@ -827,8 +827,8 @@
|
|
|
827
827
|
}
|
|
828
828
|
addConfig(config) {
|
|
829
829
|
const key = config.key ?? config.name ?? "default";
|
|
830
|
-
this.
|
|
831
|
-
this.
|
|
830
|
+
this.#configs.set(key, config);
|
|
831
|
+
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
832
832
|
}
|
|
833
833
|
addEasing(name, easing) {
|
|
834
834
|
if (this.easingFunctions.get(name)) {
|
|
@@ -889,21 +889,21 @@
|
|
|
889
889
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
890
890
|
}
|
|
891
891
|
async init() {
|
|
892
|
-
if (this
|
|
892
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
893
893
|
return;
|
|
894
894
|
}
|
|
895
|
-
this
|
|
896
|
-
this
|
|
897
|
-
this
|
|
895
|
+
this.#isRunningLoaders = true;
|
|
896
|
+
this.#executedSet = new Set();
|
|
897
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
898
898
|
try {
|
|
899
|
-
for (const loader of this
|
|
900
|
-
await this
|
|
899
|
+
for (const loader of this.#allLoadersSet) {
|
|
900
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
901
901
|
}
|
|
902
902
|
}
|
|
903
903
|
finally {
|
|
904
|
-
this.
|
|
905
|
-
this
|
|
906
|
-
this
|
|
904
|
+
this.#loadPromises.clear();
|
|
905
|
+
this.#isRunningLoaders = false;
|
|
906
|
+
this.#initialized = true;
|
|
907
907
|
}
|
|
908
908
|
}
|
|
909
909
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -914,24 +914,24 @@
|
|
|
914
914
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
915
915
|
}
|
|
916
916
|
async register(...loaders) {
|
|
917
|
-
if (this
|
|
917
|
+
if (this.#initialized) {
|
|
918
918
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
919
919
|
}
|
|
920
920
|
for (const loader of loaders) {
|
|
921
|
-
if (this
|
|
922
|
-
await this
|
|
921
|
+
if (this.#isRunningLoaders) {
|
|
922
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
923
923
|
}
|
|
924
924
|
else {
|
|
925
|
-
this.
|
|
925
|
+
this.#loadPromises.add(loader);
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
928
|
}
|
|
929
|
-
async
|
|
929
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
930
930
|
if (executed.has(loader))
|
|
931
931
|
return;
|
|
932
932
|
executed.add(loader);
|
|
933
933
|
allLoaders.add(loader);
|
|
934
|
-
await loader(this
|
|
934
|
+
await loader(this.#engine);
|
|
935
935
|
}
|
|
936
936
|
}
|
|
937
937
|
|
|
@@ -1011,17 +1011,17 @@
|
|
|
1011
1011
|
};
|
|
1012
1012
|
class Engine {
|
|
1013
1013
|
pluginManager = new PluginManager(this);
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1014
|
+
#domArray = [];
|
|
1015
|
+
#eventDispatcher = new EventDispatcher();
|
|
1016
|
+
#initialized = false;
|
|
1017
1017
|
get items() {
|
|
1018
|
-
return this
|
|
1018
|
+
return this.#domArray;
|
|
1019
1019
|
}
|
|
1020
1020
|
get version() {
|
|
1021
|
-
return "4.0
|
|
1021
|
+
return "4.1.0";
|
|
1022
1022
|
}
|
|
1023
1023
|
addEventListener(type, listener) {
|
|
1024
|
-
this.
|
|
1024
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1025
1025
|
}
|
|
1026
1026
|
checkVersion(pluginVersion) {
|
|
1027
1027
|
if (this.version === pluginVersion) {
|
|
@@ -1030,17 +1030,17 @@
|
|
|
1030
1030
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1031
1031
|
}
|
|
1032
1032
|
dispatchEvent(type, args) {
|
|
1033
|
-
this.
|
|
1033
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1034
1034
|
}
|
|
1035
1035
|
async init() {
|
|
1036
|
-
if (this
|
|
1036
|
+
if (this.#initialized) {
|
|
1037
1037
|
return;
|
|
1038
1038
|
}
|
|
1039
1039
|
await this.pluginManager.init();
|
|
1040
|
-
this
|
|
1040
|
+
this.#initialized = true;
|
|
1041
1041
|
}
|
|
1042
1042
|
item(index) {
|
|
1043
|
-
const
|
|
1043
|
+
const items = this.items, item = items[index];
|
|
1044
1044
|
if (item?.destroyed) {
|
|
1045
1045
|
items.splice(index, removeDeleteCount);
|
|
1046
1046
|
return;
|
|
@@ -1094,7 +1094,7 @@
|
|
|
1094
1094
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1095
1095
|
}
|
|
1096
1096
|
removeEventListener(type, listener) {
|
|
1097
|
-
this.
|
|
1097
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1098
1098
|
}
|
|
1099
1099
|
}
|
|
1100
1100
|
|
|
@@ -1865,43 +1865,6 @@
|
|
|
1865
1865
|
}
|
|
1866
1866
|
}
|
|
1867
1867
|
|
|
1868
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1869
|
-
destroy;
|
|
1870
|
-
constructor() {
|
|
1871
|
-
super();
|
|
1872
|
-
this.destroy = DestroyType.none;
|
|
1873
|
-
this.speed = 2;
|
|
1874
|
-
}
|
|
1875
|
-
load(data) {
|
|
1876
|
-
super.load(data);
|
|
1877
|
-
if (isNull(data)) {
|
|
1878
|
-
return;
|
|
1879
|
-
}
|
|
1880
|
-
if (data.destroy !== undefined) {
|
|
1881
|
-
this.destroy = data.destroy;
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1887
|
-
animation;
|
|
1888
|
-
constructor() {
|
|
1889
|
-
super();
|
|
1890
|
-
this.animation = new OpacityAnimation();
|
|
1891
|
-
this.value = 1;
|
|
1892
|
-
}
|
|
1893
|
-
load(data) {
|
|
1894
|
-
if (isNull(data)) {
|
|
1895
|
-
return;
|
|
1896
|
-
}
|
|
1897
|
-
super.load(data);
|
|
1898
|
-
const animation = data.animation;
|
|
1899
|
-
if (animation !== undefined) {
|
|
1900
|
-
this.animation.load(animation);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
|
|
1905
1868
|
class Stroke {
|
|
1906
1869
|
color;
|
|
1907
1870
|
opacity;
|
|
@@ -2069,43 +2032,6 @@
|
|
|
2069
2032
|
}
|
|
2070
2033
|
}
|
|
2071
2034
|
|
|
2072
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2073
|
-
destroy;
|
|
2074
|
-
constructor() {
|
|
2075
|
-
super();
|
|
2076
|
-
this.destroy = DestroyType.none;
|
|
2077
|
-
this.speed = 5;
|
|
2078
|
-
}
|
|
2079
|
-
load(data) {
|
|
2080
|
-
super.load(data);
|
|
2081
|
-
if (isNull(data)) {
|
|
2082
|
-
return;
|
|
2083
|
-
}
|
|
2084
|
-
if (data.destroy !== undefined) {
|
|
2085
|
-
this.destroy = data.destroy;
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
}
|
|
2089
|
-
|
|
2090
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2091
|
-
animation;
|
|
2092
|
-
constructor() {
|
|
2093
|
-
super();
|
|
2094
|
-
this.animation = new SizeAnimation();
|
|
2095
|
-
this.value = 3;
|
|
2096
|
-
}
|
|
2097
|
-
load(data) {
|
|
2098
|
-
super.load(data);
|
|
2099
|
-
if (isNull(data)) {
|
|
2100
|
-
return;
|
|
2101
|
-
}
|
|
2102
|
-
const animation = data.animation;
|
|
2103
|
-
if (animation !== undefined) {
|
|
2104
|
-
this.animation.load(animation);
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
2035
|
class ZIndex extends ValueWithRandom {
|
|
2110
2036
|
opacityRate;
|
|
2111
2037
|
sizeRate;
|
|
@@ -2139,24 +2065,21 @@
|
|
|
2139
2065
|
groups;
|
|
2140
2066
|
move;
|
|
2141
2067
|
number;
|
|
2142
|
-
opacity;
|
|
2143
2068
|
paint;
|
|
2144
2069
|
palette;
|
|
2145
2070
|
reduceDuplicates;
|
|
2146
2071
|
shape;
|
|
2147
|
-
size;
|
|
2148
2072
|
zIndex;
|
|
2149
|
-
|
|
2150
|
-
|
|
2073
|
+
#container;
|
|
2074
|
+
#pluginManager;
|
|
2151
2075
|
constructor(pluginManager, container) {
|
|
2152
|
-
this
|
|
2153
|
-
this
|
|
2076
|
+
this.#pluginManager = pluginManager;
|
|
2077
|
+
this.#container = container;
|
|
2154
2078
|
this.bounce = new ParticlesBounce();
|
|
2155
2079
|
this.effect = new Effect();
|
|
2156
2080
|
this.groups = {};
|
|
2157
2081
|
this.move = new Move();
|
|
2158
2082
|
this.number = new ParticlesNumber();
|
|
2159
|
-
this.opacity = new Opacity();
|
|
2160
2083
|
this.paint = new Paint();
|
|
2161
2084
|
this.paint.color = new AnimatableColor();
|
|
2162
2085
|
this.paint.color.value = "#fff";
|
|
@@ -2164,7 +2087,6 @@
|
|
|
2164
2087
|
this.paint.fill.enable = true;
|
|
2165
2088
|
this.reduceDuplicates = false;
|
|
2166
2089
|
this.shape = new Shape();
|
|
2167
|
-
this.size = new Size();
|
|
2168
2090
|
this.zIndex = new ZIndex();
|
|
2169
2091
|
}
|
|
2170
2092
|
load(data) {
|
|
@@ -2173,7 +2095,7 @@
|
|
|
2173
2095
|
}
|
|
2174
2096
|
if (data.palette) {
|
|
2175
2097
|
this.palette = data.palette;
|
|
2176
|
-
this
|
|
2098
|
+
this.#importPalette(this.palette);
|
|
2177
2099
|
}
|
|
2178
2100
|
if (data.groups !== undefined) {
|
|
2179
2101
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2193,7 +2115,6 @@
|
|
|
2193
2115
|
this.effect.load(data.effect);
|
|
2194
2116
|
this.move.load(data.move);
|
|
2195
2117
|
this.number.load(data.number);
|
|
2196
|
-
this.opacity.load(data.opacity);
|
|
2197
2118
|
const paintToLoad = data.paint;
|
|
2198
2119
|
if (paintToLoad) {
|
|
2199
2120
|
if (isArray(paintToLoad)) {
|
|
@@ -2212,15 +2133,14 @@
|
|
|
2212
2133
|
}
|
|
2213
2134
|
}
|
|
2214
2135
|
this.shape.load(data.shape);
|
|
2215
|
-
this.size.load(data.size);
|
|
2216
2136
|
this.zIndex.load(data.zIndex);
|
|
2217
|
-
if (this
|
|
2218
|
-
for (const plugin of this.
|
|
2137
|
+
if (this.#container) {
|
|
2138
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2219
2139
|
if (plugin.loadParticlesOptions) {
|
|
2220
|
-
plugin.loadParticlesOptions(this
|
|
2140
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2221
2141
|
}
|
|
2222
2142
|
}
|
|
2223
|
-
const updaters = this.
|
|
2143
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2224
2144
|
if (updaters) {
|
|
2225
2145
|
for (const updater of updaters) {
|
|
2226
2146
|
if (updater.loadOptions) {
|
|
@@ -2230,8 +2150,8 @@
|
|
|
2230
2150
|
}
|
|
2231
2151
|
}
|
|
2232
2152
|
}
|
|
2233
|
-
|
|
2234
|
-
const paletteData = this.
|
|
2153
|
+
#importPalette = (palette) => {
|
|
2154
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2235
2155
|
if (!paletteData) {
|
|
2236
2156
|
return;
|
|
2237
2157
|
}
|
|
@@ -2310,11 +2230,11 @@
|
|
|
2310
2230
|
smooth;
|
|
2311
2231
|
style;
|
|
2312
2232
|
zLayers;
|
|
2313
|
-
|
|
2314
|
-
|
|
2233
|
+
#container;
|
|
2234
|
+
#pluginManager;
|
|
2315
2235
|
constructor(pluginManager, container) {
|
|
2316
|
-
this
|
|
2317
|
-
this
|
|
2236
|
+
this.#pluginManager = pluginManager;
|
|
2237
|
+
this.#container = container;
|
|
2318
2238
|
this.autoPlay = true;
|
|
2319
2239
|
this.background = new Background();
|
|
2320
2240
|
this.clear = true;
|
|
@@ -2325,7 +2245,7 @@
|
|
|
2325
2245
|
this.duration = 0;
|
|
2326
2246
|
this.fpsLimit = 120;
|
|
2327
2247
|
this.hdr = true;
|
|
2328
|
-
this.particles = loadParticlesOptions(this
|
|
2248
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2329
2249
|
this.pauseOnBlur = true;
|
|
2330
2250
|
this.pauseOnOutsideViewport = true;
|
|
2331
2251
|
this.resize = new ResizeEvent();
|
|
@@ -2340,12 +2260,12 @@
|
|
|
2340
2260
|
if (data.preset !== undefined) {
|
|
2341
2261
|
this.preset = data.preset;
|
|
2342
2262
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2343
|
-
this
|
|
2263
|
+
this.#importPreset(preset);
|
|
2344
2264
|
});
|
|
2345
2265
|
}
|
|
2346
2266
|
if (data.palette !== undefined) {
|
|
2347
2267
|
this.palette = data.palette;
|
|
2348
|
-
this
|
|
2268
|
+
this.#importPalette(this.palette);
|
|
2349
2269
|
}
|
|
2350
2270
|
if (data.autoPlay !== undefined) {
|
|
2351
2271
|
this.autoPlay = data.autoPlay;
|
|
@@ -2399,12 +2319,12 @@
|
|
|
2399
2319
|
if (data.smooth !== undefined) {
|
|
2400
2320
|
this.smooth = data.smooth;
|
|
2401
2321
|
}
|
|
2402
|
-
this.
|
|
2403
|
-
plugin.loadOptions(this
|
|
2322
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2323
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2404
2324
|
});
|
|
2405
2325
|
}
|
|
2406
|
-
|
|
2407
|
-
const paletteData = this.
|
|
2326
|
+
#importPalette = palette => {
|
|
2327
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2408
2328
|
if (!paletteData) {
|
|
2409
2329
|
return;
|
|
2410
2330
|
}
|
|
@@ -2421,8 +2341,8 @@
|
|
|
2421
2341
|
},
|
|
2422
2342
|
});
|
|
2423
2343
|
};
|
|
2424
|
-
|
|
2425
|
-
this.load(this.
|
|
2344
|
+
#importPreset = preset => {
|
|
2345
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2426
2346
|
};
|
|
2427
2347
|
}
|
|
2428
2348
|
|
|
@@ -2891,7 +2811,7 @@
|
|
|
2891
2811
|
}
|
|
2892
2812
|
|
|
2893
2813
|
async function loadBlendPlugin(engine) {
|
|
2894
|
-
engine.checkVersion("4.0
|
|
2814
|
+
engine.checkVersion("4.1.0");
|
|
2895
2815
|
await engine.pluginManager.register(e => {
|
|
2896
2816
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2897
2817
|
});
|
|
@@ -2928,7 +2848,7 @@
|
|
|
2928
2848
|
}
|
|
2929
2849
|
|
|
2930
2850
|
async function loadCircleShape(engine) {
|
|
2931
|
-
engine.checkVersion("4.0
|
|
2851
|
+
engine.checkVersion("4.1.0");
|
|
2932
2852
|
await engine.pluginManager.register(e => {
|
|
2933
2853
|
e.pluginManager.addShape(["circle"], () => {
|
|
2934
2854
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2949,15 +2869,15 @@
|
|
|
2949
2869
|
return input.startsWith("#");
|
|
2950
2870
|
}
|
|
2951
2871
|
handleColor(color) {
|
|
2952
|
-
return this
|
|
2872
|
+
return this.#parseString(color.value);
|
|
2953
2873
|
}
|
|
2954
2874
|
handleRangeColor(color) {
|
|
2955
|
-
return this
|
|
2875
|
+
return this.#parseString(color.value);
|
|
2956
2876
|
}
|
|
2957
2877
|
parseString(input) {
|
|
2958
|
-
return this
|
|
2878
|
+
return this.#parseString(input);
|
|
2959
2879
|
}
|
|
2960
|
-
|
|
2880
|
+
#parseString(hexColor) {
|
|
2961
2881
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
2962
2882
|
return;
|
|
2963
2883
|
}
|
|
@@ -2976,7 +2896,7 @@
|
|
|
2976
2896
|
}
|
|
2977
2897
|
|
|
2978
2898
|
async function loadHexColorPlugin(engine) {
|
|
2979
|
-
engine.checkVersion("4.0
|
|
2899
|
+
engine.checkVersion("4.1.0");
|
|
2980
2900
|
await engine.pluginManager.register(e => {
|
|
2981
2901
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
2982
2902
|
});
|
|
@@ -3029,7 +2949,7 @@
|
|
|
3029
2949
|
}
|
|
3030
2950
|
|
|
3031
2951
|
async function loadHslColorPlugin(engine) {
|
|
3032
|
-
engine.checkVersion("4.0
|
|
2952
|
+
engine.checkVersion("4.1.0");
|
|
3033
2953
|
await engine.pluginManager.register(e => {
|
|
3034
2954
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3035
2955
|
});
|
|
@@ -3037,13 +2957,13 @@
|
|
|
3037
2957
|
|
|
3038
2958
|
class MovePlugin {
|
|
3039
2959
|
id = "move";
|
|
3040
|
-
|
|
2960
|
+
#pluginManager;
|
|
3041
2961
|
constructor(pluginManager) {
|
|
3042
|
-
this
|
|
2962
|
+
this.#pluginManager = pluginManager;
|
|
3043
2963
|
}
|
|
3044
2964
|
async getPlugin(container) {
|
|
3045
2965
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3046
|
-
return new MovePluginInstance(this
|
|
2966
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3047
2967
|
}
|
|
3048
2968
|
loadOptions() {
|
|
3049
2969
|
}
|
|
@@ -3053,7 +2973,7 @@
|
|
|
3053
2973
|
}
|
|
3054
2974
|
|
|
3055
2975
|
async function loadMovePlugin(engine) {
|
|
3056
|
-
engine.checkVersion("4.0
|
|
2976
|
+
engine.checkVersion("4.1.0");
|
|
3057
2977
|
await engine.pluginManager.register(e => {
|
|
3058
2978
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3059
2979
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3071,18 +2991,58 @@
|
|
|
3071
2991
|
});
|
|
3072
2992
|
}
|
|
3073
2993
|
|
|
2994
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
2995
|
+
destroy;
|
|
2996
|
+
constructor() {
|
|
2997
|
+
super();
|
|
2998
|
+
this.destroy = DestroyType.none;
|
|
2999
|
+
this.speed = 2;
|
|
3000
|
+
}
|
|
3001
|
+
load(data) {
|
|
3002
|
+
super.load(data);
|
|
3003
|
+
if (isNull(data)) {
|
|
3004
|
+
return;
|
|
3005
|
+
}
|
|
3006
|
+
if (data.destroy !== undefined) {
|
|
3007
|
+
this.destroy = data.destroy;
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
3013
|
+
animation;
|
|
3014
|
+
constructor() {
|
|
3015
|
+
super();
|
|
3016
|
+
this.animation = new OpacityAnimation();
|
|
3017
|
+
this.value = 1;
|
|
3018
|
+
}
|
|
3019
|
+
load(data) {
|
|
3020
|
+
if (isNull(data)) {
|
|
3021
|
+
return;
|
|
3022
|
+
}
|
|
3023
|
+
super.load(data);
|
|
3024
|
+
const animation = data.animation;
|
|
3025
|
+
if (animation !== undefined) {
|
|
3026
|
+
this.animation.load(animation);
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3074
3031
|
class OpacityUpdater {
|
|
3075
|
-
container;
|
|
3032
|
+
#container;
|
|
3076
3033
|
constructor(container) {
|
|
3077
|
-
this
|
|
3034
|
+
this.#container = container;
|
|
3078
3035
|
}
|
|
3079
3036
|
init(particle) {
|
|
3080
3037
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3038
|
+
if (!opacityOptions) {
|
|
3039
|
+
return;
|
|
3040
|
+
}
|
|
3081
3041
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3082
3042
|
const opacityAnimation = opacityOptions.animation;
|
|
3083
3043
|
if (opacityAnimation.enable) {
|
|
3084
3044
|
particle.opacity.velocity =
|
|
3085
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3045
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3086
3046
|
if (!opacityAnimation.sync) {
|
|
3087
3047
|
particle.opacity.velocity *= getRandom();
|
|
3088
3048
|
}
|
|
@@ -3098,6 +3058,12 @@
|
|
|
3098
3058
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3099
3059
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3100
3060
|
}
|
|
3061
|
+
loadOptions(options, ...sources) {
|
|
3062
|
+
options.opacity ??= new Opacity();
|
|
3063
|
+
for (const source of sources) {
|
|
3064
|
+
options.opacity.load(source?.opacity);
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3101
3067
|
reset(particle) {
|
|
3102
3068
|
if (!particle.opacity) {
|
|
3103
3069
|
return;
|
|
@@ -3106,7 +3072,7 @@
|
|
|
3106
3072
|
particle.opacity.loops = 0;
|
|
3107
3073
|
}
|
|
3108
3074
|
update(particle, delta) {
|
|
3109
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3075
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3110
3076
|
return;
|
|
3111
3077
|
}
|
|
3112
3078
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3114,7 +3080,7 @@
|
|
|
3114
3080
|
}
|
|
3115
3081
|
|
|
3116
3082
|
async function loadOpacityUpdater(engine) {
|
|
3117
|
-
engine.checkVersion("4.0
|
|
3083
|
+
engine.checkVersion("4.1.0");
|
|
3118
3084
|
await engine.pluginManager.register(e => {
|
|
3119
3085
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3120
3086
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3136,10 +3102,9 @@
|
|
|
3136
3102
|
}
|
|
3137
3103
|
const velocity = data.particle.velocity.x;
|
|
3138
3104
|
let bounced = false;
|
|
3139
|
-
if (
|
|
3140
|
-
data.
|
|
3141
|
-
|
|
3142
|
-
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3105
|
+
if (data.outOfCanvas &&
|
|
3106
|
+
((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3107
|
+
(data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3143
3108
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3144
3109
|
data.particle.velocity.x *= -newVelocity;
|
|
3145
3110
|
bounced = true;
|
|
@@ -3148,10 +3113,10 @@
|
|
|
3148
3113
|
return;
|
|
3149
3114
|
}
|
|
3150
3115
|
const minPos = data.offset.x + data.size;
|
|
3151
|
-
if (data.
|
|
3116
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.right) {
|
|
3152
3117
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3153
3118
|
}
|
|
3154
|
-
else if (data.
|
|
3119
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.left) {
|
|
3155
3120
|
data.particle.position.x = minPos;
|
|
3156
3121
|
}
|
|
3157
3122
|
if (data.outMode === OutMode.split) {
|
|
@@ -3171,10 +3136,9 @@
|
|
|
3171
3136
|
}
|
|
3172
3137
|
const velocity = data.particle.velocity.y;
|
|
3173
3138
|
let bounced = false;
|
|
3174
|
-
if (
|
|
3175
|
-
data.
|
|
3176
|
-
|
|
3177
|
-
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3139
|
+
if (data.outOfCanvas &&
|
|
3140
|
+
((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3141
|
+
(data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3178
3142
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3179
3143
|
data.particle.velocity.y *= -newVelocity;
|
|
3180
3144
|
bounced = true;
|
|
@@ -3183,10 +3147,10 @@
|
|
|
3183
3147
|
return;
|
|
3184
3148
|
}
|
|
3185
3149
|
const minPos = data.offset.y + data.size;
|
|
3186
|
-
if (data.
|
|
3150
|
+
if (data.outOfCanvas && data.direction === OutModeDirection.bottom) {
|
|
3187
3151
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3188
3152
|
}
|
|
3189
|
-
else if (data.
|
|
3153
|
+
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
3190
3154
|
data.particle.position.y = minPos;
|
|
3191
3155
|
}
|
|
3192
3156
|
if (data.outMode === OutMode.split) {
|
|
@@ -3195,24 +3159,24 @@
|
|
|
3195
3159
|
}
|
|
3196
3160
|
|
|
3197
3161
|
class BounceOutMode {
|
|
3198
|
-
container;
|
|
3199
3162
|
modes;
|
|
3200
|
-
|
|
3163
|
+
#container;
|
|
3164
|
+
#particleBouncePlugins;
|
|
3201
3165
|
constructor(container) {
|
|
3202
|
-
this
|
|
3166
|
+
this.#container = container;
|
|
3203
3167
|
this.modes = [
|
|
3204
3168
|
OutMode.bounce,
|
|
3205
3169
|
OutMode.split,
|
|
3206
3170
|
];
|
|
3207
|
-
this
|
|
3171
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3208
3172
|
}
|
|
3209
3173
|
update(particle, direction, delta, outMode) {
|
|
3210
3174
|
if (!this.modes.includes(outMode)) {
|
|
3211
3175
|
return;
|
|
3212
3176
|
}
|
|
3213
|
-
const container = this
|
|
3177
|
+
const container = this.#container;
|
|
3214
3178
|
let handled = false;
|
|
3215
|
-
for (const plugin of this
|
|
3179
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3216
3180
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3217
3181
|
if (handled) {
|
|
3218
3182
|
break;
|
|
@@ -3221,29 +3185,26 @@
|
|
|
3221
3185
|
if (handled) {
|
|
3222
3186
|
return;
|
|
3223
3187
|
}
|
|
3224
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3225
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3226
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3188
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3189
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3190
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3227
3191
|
}
|
|
3228
3192
|
}
|
|
3229
3193
|
|
|
3230
3194
|
const minVelocity$3 = 0;
|
|
3231
3195
|
class DestroyOutMode {
|
|
3232
|
-
container;
|
|
3233
3196
|
modes;
|
|
3234
|
-
constructor(
|
|
3235
|
-
this.container = container;
|
|
3197
|
+
constructor(_container) {
|
|
3236
3198
|
this.modes = [OutMode.destroy];
|
|
3237
3199
|
}
|
|
3238
3200
|
update(particle, direction, _delta, outMode) {
|
|
3239
3201
|
if (!this.modes.includes(outMode)) {
|
|
3240
3202
|
return;
|
|
3241
3203
|
}
|
|
3242
|
-
const container = this.container;
|
|
3243
3204
|
switch (particle.outType) {
|
|
3244
3205
|
case ParticleOutType.normal:
|
|
3245
3206
|
case ParticleOutType.outside:
|
|
3246
|
-
if (
|
|
3207
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3247
3208
|
return;
|
|
3248
3209
|
}
|
|
3249
3210
|
break;
|
|
@@ -3264,10 +3225,10 @@
|
|
|
3264
3225
|
|
|
3265
3226
|
const minVelocity$2 = 0;
|
|
3266
3227
|
class NoneOutMode {
|
|
3267
|
-
container;
|
|
3268
3228
|
modes;
|
|
3229
|
+
#container;
|
|
3269
3230
|
constructor(container) {
|
|
3270
|
-
this
|
|
3231
|
+
this.#container = container;
|
|
3271
3232
|
this.modes = [OutMode.none];
|
|
3272
3233
|
}
|
|
3273
3234
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3280,7 +3241,7 @@
|
|
|
3280
3241
|
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
3281
3242
|
return;
|
|
3282
3243
|
}
|
|
3283
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3244
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3284
3245
|
if (!gravityOptions.enable) {
|
|
3285
3246
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3286
3247
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3306,17 +3267,17 @@
|
|
|
3306
3267
|
|
|
3307
3268
|
const minVelocity$1 = 0, minDistance = 0, updateVector = Vector.origin;
|
|
3308
3269
|
class OutOutMode {
|
|
3309
|
-
container;
|
|
3310
3270
|
modes;
|
|
3271
|
+
#container;
|
|
3311
3272
|
constructor(container) {
|
|
3312
|
-
this
|
|
3273
|
+
this.#container = container;
|
|
3313
3274
|
this.modes = [OutMode.out];
|
|
3314
3275
|
}
|
|
3315
3276
|
update(particle, direction, _delta, outMode) {
|
|
3316
3277
|
if (!this.modes.includes(outMode)) {
|
|
3317
3278
|
return;
|
|
3318
3279
|
}
|
|
3319
|
-
const container = this
|
|
3280
|
+
const container = this.#container;
|
|
3320
3281
|
switch (particle.outType) {
|
|
3321
3282
|
case ParticleOutType.inside: {
|
|
3322
3283
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3346,7 +3307,7 @@
|
|
|
3346
3307
|
break;
|
|
3347
3308
|
}
|
|
3348
3309
|
default: {
|
|
3349
|
-
if (
|
|
3310
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3350
3311
|
return;
|
|
3351
3312
|
}
|
|
3352
3313
|
switch (particle.outType) {
|
|
@@ -3430,16 +3391,16 @@
|
|
|
3430
3391
|
};
|
|
3431
3392
|
class OutOfCanvasUpdater {
|
|
3432
3393
|
updaters;
|
|
3433
|
-
container;
|
|
3394
|
+
#container;
|
|
3434
3395
|
constructor(container) {
|
|
3435
|
-
this
|
|
3396
|
+
this.#container = container;
|
|
3436
3397
|
this.updaters = new Map();
|
|
3437
3398
|
}
|
|
3438
3399
|
init(particle) {
|
|
3439
|
-
this
|
|
3440
|
-
this
|
|
3441
|
-
this
|
|
3442
|
-
this
|
|
3400
|
+
this.#addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
3401
|
+
this.#addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
3402
|
+
this.#addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
3403
|
+
this.#addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
3443
3404
|
}
|
|
3444
3405
|
isEnabled(particle) {
|
|
3445
3406
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3447,18 +3408,18 @@
|
|
|
3447
3408
|
update(particle, delta) {
|
|
3448
3409
|
const outModes = particle.options.move.outModes;
|
|
3449
3410
|
particle.justWarped = false;
|
|
3450
|
-
this
|
|
3451
|
-
this
|
|
3452
|
-
this
|
|
3453
|
-
this
|
|
3411
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
3412
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
3413
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
3414
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
3454
3415
|
}
|
|
3455
|
-
|
|
3416
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3456
3417
|
const outModes = particle.options.move.outModes;
|
|
3457
3418
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3458
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3419
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3459
3420
|
}
|
|
3460
3421
|
};
|
|
3461
|
-
|
|
3422
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3462
3423
|
for (const updater of this.updaters.values()) {
|
|
3463
3424
|
updater.update(particle, direction, delta, outMode);
|
|
3464
3425
|
}
|
|
@@ -3466,7 +3427,7 @@
|
|
|
3466
3427
|
}
|
|
3467
3428
|
|
|
3468
3429
|
async function loadOutModesUpdater(engine) {
|
|
3469
|
-
engine.checkVersion("4.0
|
|
3430
|
+
engine.checkVersion("4.1.0");
|
|
3470
3431
|
await engine.pluginManager.register(e => {
|
|
3471
3432
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3472
3433
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3476,20 +3437,20 @@
|
|
|
3476
3437
|
|
|
3477
3438
|
const defaultOpacity = 1;
|
|
3478
3439
|
class PaintUpdater {
|
|
3479
|
-
|
|
3480
|
-
|
|
3440
|
+
#container;
|
|
3441
|
+
#pluginManager;
|
|
3481
3442
|
constructor(pluginManager, container) {
|
|
3482
|
-
this
|
|
3483
|
-
this
|
|
3443
|
+
this.#container = container;
|
|
3444
|
+
this.#pluginManager = pluginManager;
|
|
3484
3445
|
}
|
|
3485
3446
|
init(particle) {
|
|
3486
|
-
const container = this
|
|
3447
|
+
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;
|
|
3487
3448
|
if (fill) {
|
|
3488
3449
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3489
3450
|
particle.fillEnabled = fill.enable;
|
|
3490
3451
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3491
3452
|
particle.fillAnimation = fillColor.animation;
|
|
3492
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3453
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3493
3454
|
if (fillHslColor) {
|
|
3494
3455
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3495
3456
|
}
|
|
@@ -3505,7 +3466,7 @@
|
|
|
3505
3466
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3506
3467
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3507
3468
|
particle.strokeAnimation = strokeColor.animation;
|
|
3508
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3469
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3509
3470
|
if (strokeHslColor) {
|
|
3510
3471
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3511
3472
|
}
|
|
@@ -3537,7 +3498,7 @@
|
|
|
3537
3498
|
}
|
|
3538
3499
|
|
|
3539
3500
|
async function loadPaintUpdater(engine) {
|
|
3540
|
-
engine.checkVersion("4.0
|
|
3501
|
+
engine.checkVersion("4.1.0");
|
|
3541
3502
|
await engine.pluginManager.register(e => {
|
|
3542
3503
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3543
3504
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3592,27 +3553,69 @@
|
|
|
3592
3553
|
}
|
|
3593
3554
|
|
|
3594
3555
|
async function loadRgbColorPlugin(engine) {
|
|
3595
|
-
engine.checkVersion("4.0
|
|
3556
|
+
engine.checkVersion("4.1.0");
|
|
3596
3557
|
await engine.pluginManager.register(e => {
|
|
3597
3558
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3598
3559
|
});
|
|
3599
3560
|
}
|
|
3600
3561
|
|
|
3562
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3563
|
+
destroy;
|
|
3564
|
+
constructor() {
|
|
3565
|
+
super();
|
|
3566
|
+
this.destroy = DestroyType.none;
|
|
3567
|
+
this.speed = 5;
|
|
3568
|
+
}
|
|
3569
|
+
load(data) {
|
|
3570
|
+
super.load(data);
|
|
3571
|
+
if (isNull(data)) {
|
|
3572
|
+
return;
|
|
3573
|
+
}
|
|
3574
|
+
if (data.destroy !== undefined) {
|
|
3575
|
+
this.destroy = data.destroy;
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
|
|
3580
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3581
|
+
animation;
|
|
3582
|
+
constructor() {
|
|
3583
|
+
super();
|
|
3584
|
+
this.animation = new SizeAnimation();
|
|
3585
|
+
this.value = 3;
|
|
3586
|
+
}
|
|
3587
|
+
load(data) {
|
|
3588
|
+
super.load(data);
|
|
3589
|
+
if (isNull(data)) {
|
|
3590
|
+
return;
|
|
3591
|
+
}
|
|
3592
|
+
const animation = data.animation;
|
|
3593
|
+
if (animation !== undefined) {
|
|
3594
|
+
this.animation.load(animation);
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
|
|
3601
3599
|
const minLoops = 0;
|
|
3602
3600
|
class SizeUpdater {
|
|
3603
|
-
|
|
3601
|
+
#container;
|
|
3604
3602
|
constructor(container) {
|
|
3605
|
-
this
|
|
3603
|
+
this.#container = container;
|
|
3606
3604
|
}
|
|
3607
3605
|
init(particle) {
|
|
3608
|
-
const container = this
|
|
3609
|
-
if (
|
|
3610
|
-
|
|
3611
|
-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3606
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3607
|
+
if (!sizeOptions) {
|
|
3608
|
+
return;
|
|
3609
|
+
}
|
|
3610
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3611
|
+
if (!sizeAnimation.enable) {
|
|
3612
|
+
return;
|
|
3613
|
+
}
|
|
3614
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3615
|
+
if (sizeAnimation.sync) {
|
|
3616
|
+
return;
|
|
3615
3617
|
}
|
|
3618
|
+
particle.size.velocity *= getRandom();
|
|
3616
3619
|
}
|
|
3617
3620
|
isEnabled(particle) {
|
|
3618
3621
|
return (!particle.destroyed &&
|
|
@@ -3622,12 +3625,26 @@
|
|
|
3622
3625
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3623
3626
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3624
3627
|
}
|
|
3628
|
+
loadOptions(options, ...sources) {
|
|
3629
|
+
options.size ??= new Size();
|
|
3630
|
+
for (const source of sources) {
|
|
3631
|
+
options.size.load(source?.size);
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
preInit(particle) {
|
|
3635
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3636
|
+
if (!sizeOptions) {
|
|
3637
|
+
return;
|
|
3638
|
+
}
|
|
3639
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3640
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3641
|
+
}
|
|
3625
3642
|
reset(particle) {
|
|
3626
3643
|
particle.size.time = 0;
|
|
3627
3644
|
particle.size.loops = 0;
|
|
3628
3645
|
}
|
|
3629
3646
|
update(particle, delta) {
|
|
3630
|
-
if (!this.isEnabled(particle)) {
|
|
3647
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3631
3648
|
return;
|
|
3632
3649
|
}
|
|
3633
3650
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3635,7 +3652,7 @@
|
|
|
3635
3652
|
}
|
|
3636
3653
|
|
|
3637
3654
|
async function loadSizeUpdater(engine) {
|
|
3638
|
-
engine.checkVersion("4.0
|
|
3655
|
+
engine.checkVersion("4.1.0");
|
|
3639
3656
|
await engine.pluginManager.register(e => {
|
|
3640
3657
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3641
3658
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3644,7 +3661,7 @@
|
|
|
3644
3661
|
}
|
|
3645
3662
|
|
|
3646
3663
|
async function loadBasic(engine) {
|
|
3647
|
-
engine.checkVersion("4.0
|
|
3664
|
+
engine.checkVersion("4.1.0");
|
|
3648
3665
|
await engine.pluginManager.register(async (e) => {
|
|
3649
3666
|
await Promise.all([
|
|
3650
3667
|
loadBlendPlugin(e),
|
|
@@ -3900,13 +3917,13 @@
|
|
|
3900
3917
|
|
|
3901
3918
|
class EmittersPlugin {
|
|
3902
3919
|
id = "emitters";
|
|
3903
|
-
|
|
3920
|
+
#instancesManager;
|
|
3904
3921
|
constructor(instancesManager) {
|
|
3905
|
-
this
|
|
3922
|
+
this.#instancesManager = instancesManager;
|
|
3906
3923
|
}
|
|
3907
3924
|
async getPlugin(container) {
|
|
3908
3925
|
const { EmittersPluginInstance } = await Promise.resolve().then(function () { return EmittersPluginInstance$1; });
|
|
3909
|
-
return new EmittersPluginInstance(this
|
|
3926
|
+
return new EmittersPluginInstance(this.#instancesManager, container);
|
|
3910
3927
|
}
|
|
3911
3928
|
loadOptions(_container, options, source) {
|
|
3912
3929
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -3959,7 +3976,7 @@
|
|
|
3959
3976
|
})(EmitterClickMode || (EmitterClickMode = {}));
|
|
3960
3977
|
|
|
3961
3978
|
async function loadEmittersPluginSimple(engine) {
|
|
3962
|
-
engine.checkVersion("4.0
|
|
3979
|
+
engine.checkVersion("4.1.0");
|
|
3963
3980
|
await engine.pluginManager.register(async (e) => {
|
|
3964
3981
|
const instancesManager = await getEmittersInstancesManager(e);
|
|
3965
3982
|
await addEmittersShapesManager(e);
|
|
@@ -4077,12 +4094,12 @@
|
|
|
4077
4094
|
|
|
4078
4095
|
const noTime = 0, identity$2 = 1, infiniteValue = -1;
|
|
4079
4096
|
class LifeUpdater {
|
|
4080
|
-
container;
|
|
4097
|
+
#container;
|
|
4081
4098
|
constructor(container) {
|
|
4082
|
-
this
|
|
4099
|
+
this.#container = container;
|
|
4083
4100
|
}
|
|
4084
4101
|
init(particle) {
|
|
4085
|
-
const container = this
|
|
4102
|
+
const container = this.#container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
4086
4103
|
if (!lifeOptions) {
|
|
4087
4104
|
return;
|
|
4088
4105
|
}
|
|
@@ -4121,12 +4138,12 @@
|
|
|
4121
4138
|
if (!this.isEnabled(particle) || !particle.life) {
|
|
4122
4139
|
return;
|
|
4123
4140
|
}
|
|
4124
|
-
updateLife(particle, delta, this
|
|
4141
|
+
updateLife(particle, delta, this.#container.canvas.size);
|
|
4125
4142
|
}
|
|
4126
4143
|
}
|
|
4127
4144
|
|
|
4128
4145
|
async function loadLifeUpdater(engine) {
|
|
4129
|
-
engine.checkVersion("4.0
|
|
4146
|
+
engine.checkVersion("4.1.0");
|
|
4130
4147
|
await engine.pluginManager.register(e => {
|
|
4131
4148
|
e.pluginManager.addParticleUpdater("life", container => {
|
|
4132
4149
|
return Promise.resolve(new LifeUpdater(container));
|
|
@@ -4194,7 +4211,7 @@
|
|
|
4194
4211
|
}
|
|
4195
4212
|
|
|
4196
4213
|
async function loadMotionPlugin(engine) {
|
|
4197
|
-
engine.checkVersion("4.0
|
|
4214
|
+
engine.checkVersion("4.1.0");
|
|
4198
4215
|
await engine.pluginManager.register(e => {
|
|
4199
4216
|
e.pluginManager.addPlugin(new MotionPlugin());
|
|
4200
4217
|
});
|
|
@@ -4318,9 +4335,9 @@
|
|
|
4318
4335
|
}
|
|
4319
4336
|
|
|
4320
4337
|
class RollUpdater {
|
|
4321
|
-
|
|
4338
|
+
#pluginManager;
|
|
4322
4339
|
constructor(pluginManager) {
|
|
4323
|
-
this
|
|
4340
|
+
this.#pluginManager = pluginManager;
|
|
4324
4341
|
}
|
|
4325
4342
|
getTransformValues(particle) {
|
|
4326
4343
|
const roll = particle.roll?.enable && particle.roll, rollHorizontal = roll && roll.horizontal, rollVertical = roll && roll.vertical;
|
|
@@ -4330,7 +4347,7 @@
|
|
|
4330
4347
|
};
|
|
4331
4348
|
}
|
|
4332
4349
|
init(particle) {
|
|
4333
|
-
initParticle(this
|
|
4350
|
+
initParticle(this.#pluginManager, particle);
|
|
4334
4351
|
}
|
|
4335
4352
|
isEnabled(particle) {
|
|
4336
4353
|
const roll = particle.options.roll;
|
|
@@ -4351,7 +4368,7 @@
|
|
|
4351
4368
|
}
|
|
4352
4369
|
|
|
4353
4370
|
async function loadRollUpdater(engine) {
|
|
4354
|
-
engine.checkVersion("4.0
|
|
4371
|
+
engine.checkVersion("4.1.0");
|
|
4355
4372
|
await engine.pluginManager.register(e => {
|
|
4356
4373
|
e.pluginManager.addParticleUpdater("roll", () => {
|
|
4357
4374
|
return Promise.resolve(new RollUpdater(e.pluginManager));
|
|
@@ -4417,9 +4434,9 @@
|
|
|
4417
4434
|
|
|
4418
4435
|
const doublePIDeg = 360;
|
|
4419
4436
|
class RotateUpdater {
|
|
4420
|
-
container;
|
|
4437
|
+
#container;
|
|
4421
4438
|
constructor(container) {
|
|
4422
|
-
this
|
|
4439
|
+
this.#container = container;
|
|
4423
4440
|
}
|
|
4424
4441
|
init(particle) {
|
|
4425
4442
|
const rotateOptions = particle.options.rotate;
|
|
@@ -4451,7 +4468,7 @@
|
|
|
4451
4468
|
if (rotateAnimation.enable) {
|
|
4452
4469
|
particle.rotate.decay = identity$3 - getRangeValue(rotateAnimation.decay);
|
|
4453
4470
|
particle.rotate.velocity =
|
|
4454
|
-
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this
|
|
4471
|
+
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this.#container.retina.reduceFactor;
|
|
4455
4472
|
if (!rotateAnimation.sync) {
|
|
4456
4473
|
particle.rotate.velocity *= getRandom();
|
|
4457
4474
|
}
|
|
@@ -4485,7 +4502,7 @@
|
|
|
4485
4502
|
}
|
|
4486
4503
|
|
|
4487
4504
|
async function loadRotateUpdater(engine) {
|
|
4488
|
-
engine.checkVersion("4.0
|
|
4505
|
+
engine.checkVersion("4.1.0");
|
|
4489
4506
|
await engine.pluginManager.register(e => {
|
|
4490
4507
|
e.pluginManager.addParticleUpdater("rotate", container => {
|
|
4491
4508
|
return Promise.resolve(new RotateUpdater(container));
|
|
@@ -4509,7 +4526,7 @@
|
|
|
4509
4526
|
}
|
|
4510
4527
|
|
|
4511
4528
|
async function loadSquareShape(engine) {
|
|
4512
|
-
engine.checkVersion("4.0
|
|
4529
|
+
engine.checkVersion("4.1.0");
|
|
4513
4530
|
await engine.pluginManager.register(e => {
|
|
4514
4531
|
e.pluginManager.addShape(["edge", "square"], () => Promise.resolve(new SquareDrawer()));
|
|
4515
4532
|
});
|
|
@@ -4580,9 +4597,9 @@
|
|
|
4580
4597
|
|
|
4581
4598
|
const maxAngle$1 = 360;
|
|
4582
4599
|
class TiltUpdater {
|
|
4583
|
-
container;
|
|
4600
|
+
#container;
|
|
4584
4601
|
constructor(container) {
|
|
4585
|
-
this
|
|
4602
|
+
this.#container = container;
|
|
4586
4603
|
}
|
|
4587
4604
|
getTransformValues(particle) {
|
|
4588
4605
|
const tilt = particle.tilt?.enable && particle.tilt;
|
|
@@ -4621,7 +4638,7 @@
|
|
|
4621
4638
|
const tiltAnimation = particle.options.tilt?.animation;
|
|
4622
4639
|
if (tiltAnimation?.enable) {
|
|
4623
4640
|
particle.tilt.decay = identity$3 - getRangeValue(tiltAnimation.decay);
|
|
4624
|
-
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this
|
|
4641
|
+
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this.#container.retina.reduceFactor;
|
|
4625
4642
|
if (!tiltAnimation.sync) {
|
|
4626
4643
|
particle.tilt.velocity *= getRandom();
|
|
4627
4644
|
}
|
|
@@ -4646,7 +4663,7 @@
|
|
|
4646
4663
|
}
|
|
4647
4664
|
|
|
4648
4665
|
async function loadTiltUpdater(engine) {
|
|
4649
|
-
engine.checkVersion("4.0
|
|
4666
|
+
engine.checkVersion("4.1.0");
|
|
4650
4667
|
await engine.pluginManager.register(e => {
|
|
4651
4668
|
e.pluginManager.addParticleUpdater("tilt", container => {
|
|
4652
4669
|
return Promise.resolve(new TiltUpdater(container));
|
|
@@ -4727,9 +4744,9 @@
|
|
|
4727
4744
|
|
|
4728
4745
|
const maxAngle = 360, moveSpeedFactor$1 = 10, defaultDistance = 0;
|
|
4729
4746
|
class WobbleUpdater {
|
|
4730
|
-
|
|
4747
|
+
#container;
|
|
4731
4748
|
constructor(container) {
|
|
4732
|
-
this
|
|
4749
|
+
this.#container = container;
|
|
4733
4750
|
}
|
|
4734
4751
|
init(particle) {
|
|
4735
4752
|
const wobbleOpt = particle.options.wobble;
|
|
@@ -4748,7 +4765,7 @@
|
|
|
4748
4765
|
};
|
|
4749
4766
|
}
|
|
4750
4767
|
particle.retina.wobbleDistance =
|
|
4751
|
-
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.
|
|
4768
|
+
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.#container.retina.pixelRatio;
|
|
4752
4769
|
}
|
|
4753
4770
|
isEnabled(particle) {
|
|
4754
4771
|
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
|
|
@@ -4763,12 +4780,12 @@
|
|
|
4763
4780
|
if (!this.isEnabled(particle)) {
|
|
4764
4781
|
return;
|
|
4765
4782
|
}
|
|
4766
|
-
updateWobble(this
|
|
4783
|
+
updateWobble(this.#container, particle, delta);
|
|
4767
4784
|
}
|
|
4768
4785
|
}
|
|
4769
4786
|
|
|
4770
4787
|
async function loadWobbleUpdater(engine) {
|
|
4771
|
-
engine.checkVersion("4.0
|
|
4788
|
+
engine.checkVersion("4.1.0");
|
|
4772
4789
|
await engine.pluginManager.register(e => {
|
|
4773
4790
|
e.pluginManager.addParticleUpdater("wobble", container => {
|
|
4774
4791
|
return Promise.resolve(new WobbleUpdater(container));
|
|
@@ -4937,58 +4954,58 @@
|
|
|
4937
4954
|
}
|
|
4938
4955
|
}
|
|
4939
4956
|
class RenderManager {
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4957
|
+
#canvasClearPlugins;
|
|
4958
|
+
#canvasManager;
|
|
4959
|
+
#canvasPaintPlugins;
|
|
4960
|
+
#clearDrawPlugins;
|
|
4961
|
+
#colorPlugins;
|
|
4962
|
+
#container;
|
|
4963
|
+
#context;
|
|
4964
|
+
#contextSettings;
|
|
4965
|
+
#drawParticlePlugins;
|
|
4966
|
+
#drawParticlesCleanupPlugins;
|
|
4967
|
+
#drawParticlesSetupPlugins;
|
|
4968
|
+
#drawPlugins;
|
|
4969
|
+
#drawSettingsCleanupPlugins;
|
|
4970
|
+
#drawSettingsSetupPlugins;
|
|
4971
|
+
#pluginManager;
|
|
4972
|
+
#postDrawUpdaters;
|
|
4973
|
+
#preDrawUpdaters;
|
|
4974
|
+
#reusableColorStyles = {};
|
|
4975
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4976
|
+
#reusableTransform = {};
|
|
4960
4977
|
constructor(pluginManager, container, canvasManager) {
|
|
4961
|
-
this
|
|
4962
|
-
this
|
|
4963
|
-
this
|
|
4964
|
-
this
|
|
4965
|
-
this
|
|
4966
|
-
this
|
|
4967
|
-
this
|
|
4968
|
-
this
|
|
4969
|
-
this
|
|
4970
|
-
this
|
|
4971
|
-
this
|
|
4972
|
-
this
|
|
4973
|
-
this
|
|
4974
|
-
this
|
|
4975
|
-
this
|
|
4976
|
-
this
|
|
4978
|
+
this.#pluginManager = pluginManager;
|
|
4979
|
+
this.#container = container;
|
|
4980
|
+
this.#canvasManager = canvasManager;
|
|
4981
|
+
this.#context = null;
|
|
4982
|
+
this.#preDrawUpdaters = [];
|
|
4983
|
+
this.#postDrawUpdaters = [];
|
|
4984
|
+
this.#colorPlugins = [];
|
|
4985
|
+
this.#canvasClearPlugins = [];
|
|
4986
|
+
this.#canvasPaintPlugins = [];
|
|
4987
|
+
this.#clearDrawPlugins = [];
|
|
4988
|
+
this.#drawParticlePlugins = [];
|
|
4989
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4990
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4991
|
+
this.#drawPlugins = [];
|
|
4992
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4993
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4977
4994
|
}
|
|
4978
4995
|
get settings() {
|
|
4979
|
-
return this
|
|
4996
|
+
return this.#contextSettings;
|
|
4980
4997
|
}
|
|
4981
4998
|
canvasClear() {
|
|
4982
|
-
if (!this.
|
|
4999
|
+
if (!this.#container.actualOptions.clear) {
|
|
4983
5000
|
return;
|
|
4984
5001
|
}
|
|
4985
5002
|
this.draw(ctx => {
|
|
4986
|
-
clear(ctx, this.
|
|
5003
|
+
clear(ctx, this.#canvasManager.size);
|
|
4987
5004
|
});
|
|
4988
5005
|
}
|
|
4989
5006
|
clear() {
|
|
4990
5007
|
let pluginHandled = false;
|
|
4991
|
-
for (const plugin of this
|
|
5008
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4992
5009
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4993
5010
|
if (pluginHandled) {
|
|
4994
5011
|
break;
|
|
@@ -5001,21 +5018,21 @@
|
|
|
5001
5018
|
}
|
|
5002
5019
|
destroy() {
|
|
5003
5020
|
this.stop();
|
|
5004
|
-
this
|
|
5005
|
-
this
|
|
5006
|
-
this
|
|
5007
|
-
this
|
|
5008
|
-
this
|
|
5009
|
-
this
|
|
5010
|
-
this
|
|
5011
|
-
this
|
|
5012
|
-
this
|
|
5013
|
-
this
|
|
5014
|
-
this
|
|
5015
|
-
this
|
|
5021
|
+
this.#preDrawUpdaters = [];
|
|
5022
|
+
this.#postDrawUpdaters = [];
|
|
5023
|
+
this.#colorPlugins = [];
|
|
5024
|
+
this.#canvasClearPlugins = [];
|
|
5025
|
+
this.#canvasPaintPlugins = [];
|
|
5026
|
+
this.#clearDrawPlugins = [];
|
|
5027
|
+
this.#drawParticlePlugins = [];
|
|
5028
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5029
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5030
|
+
this.#drawPlugins = [];
|
|
5031
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5032
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5016
5033
|
}
|
|
5017
5034
|
draw(cb) {
|
|
5018
|
-
const ctx = this
|
|
5035
|
+
const ctx = this.#context;
|
|
5019
5036
|
if (!ctx) {
|
|
5020
5037
|
return;
|
|
5021
5038
|
}
|
|
@@ -5030,21 +5047,21 @@
|
|
|
5030
5047
|
return;
|
|
5031
5048
|
}
|
|
5032
5049
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
5033
|
-
let [fColor, sColor] = this
|
|
5050
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
5034
5051
|
fColor ??= pfColor;
|
|
5035
5052
|
sColor ??= psColor;
|
|
5036
5053
|
if (!fColor && !sColor) {
|
|
5037
5054
|
return;
|
|
5038
5055
|
}
|
|
5039
|
-
const container = this
|
|
5056
|
+
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;
|
|
5040
5057
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
5041
5058
|
colorStyles.fill = fill;
|
|
5042
5059
|
colorStyles.stroke = stroke;
|
|
5043
5060
|
this.draw((context) => {
|
|
5044
|
-
for (const plugin of this
|
|
5061
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
5045
5062
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
5046
5063
|
}
|
|
5047
|
-
this
|
|
5064
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
5048
5065
|
drawParticle({
|
|
5049
5066
|
container,
|
|
5050
5067
|
context,
|
|
@@ -5055,35 +5072,35 @@
|
|
|
5055
5072
|
opacity: opacity,
|
|
5056
5073
|
transform,
|
|
5057
5074
|
});
|
|
5058
|
-
this
|
|
5059
|
-
for (const plugin of this
|
|
5075
|
+
this.#applyPostDrawUpdaters(particle);
|
|
5076
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
5060
5077
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
5061
5078
|
}
|
|
5062
5079
|
});
|
|
5063
5080
|
}
|
|
5064
5081
|
drawParticlePlugins(particle, delta) {
|
|
5065
5082
|
this.draw(ctx => {
|
|
5066
|
-
for (const plugin of this
|
|
5083
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
5067
5084
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
5068
5085
|
}
|
|
5069
5086
|
});
|
|
5070
5087
|
}
|
|
5071
5088
|
drawParticles(delta) {
|
|
5072
|
-
const { particles } = this
|
|
5089
|
+
const { particles } = this.#container;
|
|
5073
5090
|
this.clear();
|
|
5074
5091
|
particles.update(delta);
|
|
5075
5092
|
this.draw(ctx => {
|
|
5076
|
-
for (const plugin of this
|
|
5093
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
5077
5094
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
5078
5095
|
}
|
|
5079
|
-
for (const plugin of this
|
|
5096
|
+
for (const plugin of this.#drawPlugins) {
|
|
5080
5097
|
plugin.draw?.(ctx, delta);
|
|
5081
5098
|
}
|
|
5082
5099
|
particles.drawParticles(delta);
|
|
5083
|
-
for (const plugin of this
|
|
5100
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
5084
5101
|
plugin.clearDraw?.(ctx, delta);
|
|
5085
5102
|
}
|
|
5086
|
-
for (const plugin of this
|
|
5103
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
5087
5104
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
5088
5105
|
}
|
|
5089
5106
|
});
|
|
@@ -5094,64 +5111,64 @@
|
|
|
5094
5111
|
this.paint();
|
|
5095
5112
|
}
|
|
5096
5113
|
initPlugins() {
|
|
5097
|
-
this
|
|
5098
|
-
this
|
|
5099
|
-
this
|
|
5100
|
-
this
|
|
5101
|
-
this
|
|
5102
|
-
this
|
|
5103
|
-
this
|
|
5104
|
-
this
|
|
5105
|
-
this
|
|
5106
|
-
this
|
|
5107
|
-
for (const plugin of this.
|
|
5114
|
+
this.#colorPlugins = [];
|
|
5115
|
+
this.#canvasClearPlugins = [];
|
|
5116
|
+
this.#canvasPaintPlugins = [];
|
|
5117
|
+
this.#clearDrawPlugins = [];
|
|
5118
|
+
this.#drawParticlePlugins = [];
|
|
5119
|
+
this.#drawParticlesSetupPlugins = [];
|
|
5120
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
5121
|
+
this.#drawPlugins = [];
|
|
5122
|
+
this.#drawSettingsSetupPlugins = [];
|
|
5123
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
5124
|
+
for (const plugin of this.#container.plugins) {
|
|
5108
5125
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
5109
|
-
this.
|
|
5126
|
+
this.#colorPlugins.push(plugin);
|
|
5110
5127
|
}
|
|
5111
5128
|
if (plugin.canvasClear) {
|
|
5112
|
-
this.
|
|
5129
|
+
this.#canvasClearPlugins.push(plugin);
|
|
5113
5130
|
}
|
|
5114
5131
|
if (plugin.canvasPaint) {
|
|
5115
|
-
this.
|
|
5132
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
5116
5133
|
}
|
|
5117
5134
|
if (plugin.drawParticle) {
|
|
5118
|
-
this.
|
|
5135
|
+
this.#drawParticlePlugins.push(plugin);
|
|
5119
5136
|
}
|
|
5120
5137
|
if (plugin.drawParticleSetup) {
|
|
5121
|
-
this.
|
|
5138
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
5122
5139
|
}
|
|
5123
5140
|
if (plugin.drawParticleCleanup) {
|
|
5124
|
-
this.
|
|
5141
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
5125
5142
|
}
|
|
5126
5143
|
if (plugin.draw) {
|
|
5127
|
-
this.
|
|
5144
|
+
this.#drawPlugins.push(plugin);
|
|
5128
5145
|
}
|
|
5129
5146
|
if (plugin.drawSettingsSetup) {
|
|
5130
|
-
this.
|
|
5147
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
5131
5148
|
}
|
|
5132
5149
|
if (plugin.drawSettingsCleanup) {
|
|
5133
|
-
this.
|
|
5150
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
5134
5151
|
}
|
|
5135
5152
|
if (plugin.clearDraw) {
|
|
5136
|
-
this.
|
|
5153
|
+
this.#clearDrawPlugins.push(plugin);
|
|
5137
5154
|
}
|
|
5138
5155
|
}
|
|
5139
5156
|
}
|
|
5140
5157
|
initUpdaters() {
|
|
5141
|
-
this
|
|
5142
|
-
this
|
|
5143
|
-
for (const updater of this.
|
|
5158
|
+
this.#preDrawUpdaters = [];
|
|
5159
|
+
this.#postDrawUpdaters = [];
|
|
5160
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5144
5161
|
if (updater.afterDraw) {
|
|
5145
|
-
this.
|
|
5162
|
+
this.#postDrawUpdaters.push(updater);
|
|
5146
5163
|
}
|
|
5147
5164
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
5148
|
-
this.
|
|
5165
|
+
this.#preDrawUpdaters.push(updater);
|
|
5149
5166
|
}
|
|
5150
5167
|
}
|
|
5151
5168
|
}
|
|
5152
5169
|
paint() {
|
|
5153
5170
|
let handled = false;
|
|
5154
|
-
for (const plugin of this
|
|
5171
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
5155
5172
|
handled = plugin.canvasPaint?.() ?? false;
|
|
5156
5173
|
if (handled) {
|
|
5157
5174
|
break;
|
|
@@ -5164,35 +5181,35 @@
|
|
|
5164
5181
|
}
|
|
5165
5182
|
paintBase(baseColor) {
|
|
5166
5183
|
this.draw(ctx => {
|
|
5167
|
-
paintBase(ctx, this.
|
|
5184
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
5168
5185
|
});
|
|
5169
5186
|
}
|
|
5170
5187
|
paintImage(image, opacity) {
|
|
5171
5188
|
this.draw(ctx => {
|
|
5172
|
-
paintImage(ctx, this.
|
|
5189
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
5173
5190
|
});
|
|
5174
5191
|
}
|
|
5175
5192
|
setContext(context) {
|
|
5176
|
-
this
|
|
5177
|
-
if (this
|
|
5178
|
-
this.
|
|
5193
|
+
this.#context = context;
|
|
5194
|
+
if (this.#context) {
|
|
5195
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
5179
5196
|
}
|
|
5180
5197
|
}
|
|
5181
5198
|
setContextSettings(settings) {
|
|
5182
|
-
this
|
|
5199
|
+
this.#contextSettings = settings;
|
|
5183
5200
|
}
|
|
5184
5201
|
stop() {
|
|
5185
5202
|
this.draw(ctx => {
|
|
5186
|
-
clear(ctx, this.
|
|
5203
|
+
clear(ctx, this.#canvasManager.size);
|
|
5187
5204
|
});
|
|
5188
5205
|
}
|
|
5189
|
-
|
|
5190
|
-
for (const updater of this
|
|
5206
|
+
#applyPostDrawUpdaters = particle => {
|
|
5207
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
5191
5208
|
updater.afterDraw?.(particle);
|
|
5192
5209
|
}
|
|
5193
5210
|
};
|
|
5194
|
-
|
|
5195
|
-
for (const updater of this
|
|
5211
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
5212
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
5196
5213
|
if (updater.getColorStyles) {
|
|
5197
5214
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
5198
5215
|
if (fill) {
|
|
@@ -5211,22 +5228,22 @@
|
|
|
5211
5228
|
updater.beforeDraw?.(particle);
|
|
5212
5229
|
}
|
|
5213
5230
|
};
|
|
5214
|
-
|
|
5231
|
+
#getPluginParticleColors = particle => {
|
|
5215
5232
|
let fColor, sColor;
|
|
5216
|
-
for (const plugin of this
|
|
5233
|
+
for (const plugin of this.#colorPlugins) {
|
|
5217
5234
|
if (!fColor && plugin.particleFillColor) {
|
|
5218
|
-
fColor = rangeColorToHsl(this
|
|
5235
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
5219
5236
|
}
|
|
5220
5237
|
if (!sColor && plugin.particleStrokeColor) {
|
|
5221
|
-
sColor = rangeColorToHsl(this
|
|
5238
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
5222
5239
|
}
|
|
5223
5240
|
if (fColor && sColor) {
|
|
5224
5241
|
break;
|
|
5225
5242
|
}
|
|
5226
5243
|
}
|
|
5227
|
-
this
|
|
5228
|
-
this
|
|
5229
|
-
return this
|
|
5244
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
5245
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
5246
|
+
return this.#reusablePluginColors;
|
|
5230
5247
|
};
|
|
5231
5248
|
}
|
|
5232
5249
|
|
|
@@ -5284,53 +5301,53 @@
|
|
|
5284
5301
|
renderCanvas;
|
|
5285
5302
|
size;
|
|
5286
5303
|
zoom = defaultZoom;
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5304
|
+
#container;
|
|
5305
|
+
#generated;
|
|
5306
|
+
#mutationObserver;
|
|
5307
|
+
#originalStyle;
|
|
5308
|
+
#pluginManager;
|
|
5309
|
+
#pointerEvents;
|
|
5310
|
+
#resizePlugins;
|
|
5311
|
+
#standardSize;
|
|
5312
|
+
#zoomCenter;
|
|
5296
5313
|
constructor(pluginManager, container) {
|
|
5297
|
-
this
|
|
5298
|
-
this
|
|
5314
|
+
this.#pluginManager = pluginManager;
|
|
5315
|
+
this.#container = container;
|
|
5299
5316
|
this.render = new RenderManager(pluginManager, container, this);
|
|
5300
|
-
this
|
|
5317
|
+
this.#standardSize = {
|
|
5301
5318
|
height: 0,
|
|
5302
5319
|
width: 0,
|
|
5303
5320
|
};
|
|
5304
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
5321
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
5305
5322
|
this.size = {
|
|
5306
5323
|
height: stdSize.height * pxRatio,
|
|
5307
5324
|
width: stdSize.width * pxRatio,
|
|
5308
5325
|
};
|
|
5309
|
-
this
|
|
5310
|
-
this
|
|
5311
|
-
this
|
|
5326
|
+
this.#generated = false;
|
|
5327
|
+
this.#resizePlugins = [];
|
|
5328
|
+
this.#pointerEvents = "none";
|
|
5312
5329
|
}
|
|
5313
|
-
get
|
|
5314
|
-
return this.
|
|
5330
|
+
get #fullScreen() {
|
|
5331
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
5315
5332
|
}
|
|
5316
5333
|
destroy() {
|
|
5317
5334
|
this.stop();
|
|
5318
|
-
if (this
|
|
5335
|
+
if (this.#generated) {
|
|
5319
5336
|
const element = this.domElement;
|
|
5320
5337
|
element?.remove();
|
|
5321
5338
|
this.domElement = undefined;
|
|
5322
5339
|
this.renderCanvas = undefined;
|
|
5323
5340
|
}
|
|
5324
5341
|
else {
|
|
5325
|
-
this
|
|
5342
|
+
this.#resetOriginalStyle();
|
|
5326
5343
|
}
|
|
5327
5344
|
this.render.destroy();
|
|
5328
|
-
this
|
|
5345
|
+
this.#resizePlugins = [];
|
|
5329
5346
|
}
|
|
5330
5347
|
getZoomCenter() {
|
|
5331
|
-
const pxRatio = this.
|
|
5332
|
-
if (this
|
|
5333
|
-
return this
|
|
5348
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
5349
|
+
if (this.#zoomCenter) {
|
|
5350
|
+
return this.#zoomCenter;
|
|
5334
5351
|
}
|
|
5335
5352
|
return {
|
|
5336
5353
|
x: (width * half) / pxRatio,
|
|
@@ -5338,20 +5355,20 @@
|
|
|
5338
5355
|
};
|
|
5339
5356
|
}
|
|
5340
5357
|
init() {
|
|
5341
|
-
this
|
|
5358
|
+
this.#safeMutationObserver(obs => {
|
|
5342
5359
|
obs.disconnect();
|
|
5343
5360
|
});
|
|
5344
|
-
this
|
|
5361
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
5345
5362
|
for (const record of records) {
|
|
5346
5363
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
5347
|
-
this
|
|
5364
|
+
this.#repairStyle();
|
|
5348
5365
|
}
|
|
5349
5366
|
}
|
|
5350
5367
|
});
|
|
5351
5368
|
this.resize();
|
|
5352
|
-
this
|
|
5369
|
+
this.#initStyle();
|
|
5353
5370
|
this.initBackground();
|
|
5354
|
-
this
|
|
5371
|
+
this.#safeMutationObserver(obs => {
|
|
5355
5372
|
const element = this.domElement;
|
|
5356
5373
|
if (!element || !(element instanceof Node)) {
|
|
5357
5374
|
return;
|
|
@@ -5362,13 +5379,13 @@
|
|
|
5362
5379
|
this.render.init();
|
|
5363
5380
|
}
|
|
5364
5381
|
initBackground() {
|
|
5365
|
-
const
|
|
5382
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
5366
5383
|
if (!element) {
|
|
5367
5384
|
return;
|
|
5368
5385
|
}
|
|
5369
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
5386
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
5370
5387
|
if (color) {
|
|
5371
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
5388
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
5372
5389
|
}
|
|
5373
5390
|
else {
|
|
5374
5391
|
elementStyle.backgroundColor = "";
|
|
@@ -5379,27 +5396,27 @@
|
|
|
5379
5396
|
elementStyle.backgroundSize = background.size || "";
|
|
5380
5397
|
}
|
|
5381
5398
|
initPlugins() {
|
|
5382
|
-
this
|
|
5383
|
-
for (const plugin of this.
|
|
5399
|
+
this.#resizePlugins = [];
|
|
5400
|
+
for (const plugin of this.#container.plugins) {
|
|
5384
5401
|
if (plugin.resize) {
|
|
5385
|
-
this.
|
|
5402
|
+
this.#resizePlugins.push(plugin);
|
|
5386
5403
|
}
|
|
5387
5404
|
}
|
|
5388
5405
|
}
|
|
5389
5406
|
loadCanvas(canvas) {
|
|
5390
|
-
if (this
|
|
5407
|
+
if (this.#generated && this.domElement) {
|
|
5391
5408
|
this.domElement.remove();
|
|
5392
5409
|
}
|
|
5393
|
-
const container = this
|
|
5410
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
5394
5411
|
this.domElement = domCanvas;
|
|
5395
|
-
this
|
|
5412
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
5396
5413
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
5397
5414
|
const domElement = this.domElement;
|
|
5398
5415
|
if (domElement) {
|
|
5399
5416
|
domElement.ariaHidden = "true";
|
|
5400
|
-
this
|
|
5417
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
5401
5418
|
}
|
|
5402
|
-
const standardSize = this
|
|
5419
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
5403
5420
|
if (domElement) {
|
|
5404
5421
|
standardSize.height = domElement.offsetHeight;
|
|
5405
5422
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -5408,7 +5425,7 @@
|
|
|
5408
5425
|
standardSize.height = renderCanvas.height;
|
|
5409
5426
|
standardSize.width = renderCanvas.width;
|
|
5410
5427
|
}
|
|
5411
|
-
const pxRatio = this.
|
|
5428
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
5412
5429
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
5413
5430
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
5414
5431
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -5419,12 +5436,12 @@
|
|
|
5419
5436
|
willReadFrequently: false,
|
|
5420
5437
|
});
|
|
5421
5438
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
5422
|
-
this
|
|
5439
|
+
this.#safeMutationObserver(obs => {
|
|
5423
5440
|
obs.disconnect();
|
|
5424
5441
|
});
|
|
5425
5442
|
container.retina.init();
|
|
5426
5443
|
this.initBackground();
|
|
5427
|
-
this
|
|
5444
|
+
this.#safeMutationObserver(obs => {
|
|
5428
5445
|
const element = this.domElement;
|
|
5429
5446
|
if (!element || !(element instanceof Node)) {
|
|
5430
5447
|
return;
|
|
@@ -5437,11 +5454,11 @@
|
|
|
5437
5454
|
if (!element) {
|
|
5438
5455
|
return false;
|
|
5439
5456
|
}
|
|
5440
|
-
const container = this
|
|
5457
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
5441
5458
|
if (renderCanvas === undefined) {
|
|
5442
5459
|
return false;
|
|
5443
5460
|
}
|
|
5444
|
-
const currentSize = container.canvas
|
|
5461
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
5445
5462
|
width: element.offsetWidth,
|
|
5446
5463
|
height: element.offsetHeight,
|
|
5447
5464
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -5460,7 +5477,7 @@
|
|
|
5460
5477
|
const canvasSize = this.size;
|
|
5461
5478
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
5462
5479
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
5463
|
-
if (this.
|
|
5480
|
+
if (this.#container.started) {
|
|
5464
5481
|
container.particles.setResizeFactor({
|
|
5465
5482
|
width: currentSize.width / oldSize.width,
|
|
5466
5483
|
height: currentSize.height / oldSize.height,
|
|
@@ -5473,46 +5490,46 @@
|
|
|
5473
5490
|
if (!element) {
|
|
5474
5491
|
return;
|
|
5475
5492
|
}
|
|
5476
|
-
this
|
|
5477
|
-
this
|
|
5493
|
+
this.#pointerEvents = type;
|
|
5494
|
+
this.#repairStyle();
|
|
5478
5495
|
}
|
|
5479
5496
|
setZoom(zoomLevel, center) {
|
|
5480
5497
|
this.zoom = zoomLevel;
|
|
5481
|
-
this
|
|
5498
|
+
this.#zoomCenter = center;
|
|
5482
5499
|
}
|
|
5483
5500
|
stop() {
|
|
5484
|
-
this
|
|
5501
|
+
this.#safeMutationObserver(obs => {
|
|
5485
5502
|
obs.disconnect();
|
|
5486
5503
|
});
|
|
5487
|
-
this
|
|
5504
|
+
this.#mutationObserver = undefined;
|
|
5488
5505
|
this.render.stop();
|
|
5489
5506
|
}
|
|
5490
5507
|
async windowResize() {
|
|
5491
5508
|
if (!this.domElement || !this.resize()) {
|
|
5492
5509
|
return;
|
|
5493
5510
|
}
|
|
5494
|
-
const container = this
|
|
5511
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
5495
5512
|
container.particles.setDensity();
|
|
5496
|
-
this
|
|
5513
|
+
this.#applyResizePlugins();
|
|
5497
5514
|
if (needsRefresh) {
|
|
5498
5515
|
await container.refresh();
|
|
5499
5516
|
}
|
|
5500
5517
|
}
|
|
5501
|
-
|
|
5502
|
-
for (const plugin of this
|
|
5518
|
+
#applyResizePlugins = () => {
|
|
5519
|
+
for (const plugin of this.#resizePlugins) {
|
|
5503
5520
|
plugin.resize?.();
|
|
5504
5521
|
}
|
|
5505
5522
|
};
|
|
5506
|
-
|
|
5507
|
-
const element = this.domElement, options = this.
|
|
5523
|
+
#initStyle = () => {
|
|
5524
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
5508
5525
|
if (!element) {
|
|
5509
5526
|
return;
|
|
5510
5527
|
}
|
|
5511
|
-
if (this
|
|
5512
|
-
this
|
|
5528
|
+
if (this.#fullScreen) {
|
|
5529
|
+
this.#setFullScreenStyle();
|
|
5513
5530
|
}
|
|
5514
5531
|
else {
|
|
5515
|
-
this
|
|
5532
|
+
this.#resetOriginalStyle();
|
|
5516
5533
|
}
|
|
5517
5534
|
for (const key in options.style) {
|
|
5518
5535
|
if (!key || !(key in options.style)) {
|
|
@@ -5525,72 +5542,72 @@
|
|
|
5525
5542
|
element.style.setProperty(key, value, "important");
|
|
5526
5543
|
}
|
|
5527
5544
|
};
|
|
5528
|
-
|
|
5545
|
+
#repairStyle = () => {
|
|
5529
5546
|
const element = this.domElement;
|
|
5530
5547
|
if (!element) {
|
|
5531
5548
|
return;
|
|
5532
5549
|
}
|
|
5533
|
-
this
|
|
5550
|
+
this.#safeMutationObserver(observer => {
|
|
5534
5551
|
observer.disconnect();
|
|
5535
5552
|
});
|
|
5536
|
-
this
|
|
5553
|
+
this.#initStyle();
|
|
5537
5554
|
this.initBackground();
|
|
5538
|
-
const pointerEvents = this
|
|
5555
|
+
const pointerEvents = this.#pointerEvents;
|
|
5539
5556
|
element.style.pointerEvents = pointerEvents;
|
|
5540
5557
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
5541
|
-
this
|
|
5558
|
+
this.#safeMutationObserver(observer => {
|
|
5542
5559
|
if (!(element instanceof Node)) {
|
|
5543
5560
|
return;
|
|
5544
5561
|
}
|
|
5545
5562
|
observer.observe(element, { attributes: true });
|
|
5546
5563
|
});
|
|
5547
5564
|
};
|
|
5548
|
-
|
|
5549
|
-
const element = this.domElement, originalStyle = this
|
|
5565
|
+
#resetOriginalStyle = () => {
|
|
5566
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
5550
5567
|
if (!element || !originalStyle) {
|
|
5551
5568
|
return;
|
|
5552
5569
|
}
|
|
5553
5570
|
setStyle(element, originalStyle, true);
|
|
5554
5571
|
};
|
|
5555
|
-
|
|
5556
|
-
if (!this
|
|
5572
|
+
#safeMutationObserver = callback => {
|
|
5573
|
+
if (!this.#mutationObserver) {
|
|
5557
5574
|
return;
|
|
5558
5575
|
}
|
|
5559
|
-
callback(this
|
|
5576
|
+
callback(this.#mutationObserver);
|
|
5560
5577
|
};
|
|
5561
|
-
|
|
5578
|
+
#setFullScreenStyle = () => {
|
|
5562
5579
|
const element = this.domElement;
|
|
5563
5580
|
if (!element) {
|
|
5564
5581
|
return;
|
|
5565
5582
|
}
|
|
5566
|
-
setStyle(element, getFullScreenStyle(this.
|
|
5583
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
5567
5584
|
};
|
|
5568
5585
|
}
|
|
5569
5586
|
|
|
5570
5587
|
class EventListeners {
|
|
5571
|
-
container;
|
|
5572
|
-
|
|
5573
|
-
|
|
5574
|
-
|
|
5588
|
+
#container;
|
|
5589
|
+
#handlers;
|
|
5590
|
+
#resizeObserver;
|
|
5591
|
+
#resizeTimeout;
|
|
5575
5592
|
constructor(container) {
|
|
5576
|
-
this
|
|
5577
|
-
this
|
|
5593
|
+
this.#container = container;
|
|
5594
|
+
this.#handlers = {
|
|
5578
5595
|
visibilityChange: () => {
|
|
5579
|
-
this
|
|
5596
|
+
this.#handleVisibilityChange();
|
|
5580
5597
|
},
|
|
5581
5598
|
resize: () => {
|
|
5582
|
-
this
|
|
5599
|
+
this.#handleWindowResize();
|
|
5583
5600
|
},
|
|
5584
5601
|
};
|
|
5585
5602
|
}
|
|
5586
5603
|
addListeners() {
|
|
5587
|
-
this
|
|
5604
|
+
this.#manageListeners(true);
|
|
5588
5605
|
}
|
|
5589
5606
|
removeListeners() {
|
|
5590
|
-
this
|
|
5607
|
+
this.#manageListeners(false);
|
|
5591
5608
|
}
|
|
5592
|
-
|
|
5593
|
-
const container = this
|
|
5609
|
+
#handleVisibilityChange = () => {
|
|
5610
|
+
const container = this.#container, options = container.actualOptions;
|
|
5594
5611
|
if (!options.pauseOnBlur) {
|
|
5595
5612
|
return;
|
|
5596
5613
|
}
|
|
@@ -5608,24 +5625,24 @@
|
|
|
5608
5625
|
}
|
|
5609
5626
|
}
|
|
5610
5627
|
};
|
|
5611
|
-
|
|
5612
|
-
if (this
|
|
5613
|
-
clearTimeout(this
|
|
5614
|
-
|
|
5628
|
+
#handleWindowResize = () => {
|
|
5629
|
+
if (this.#resizeTimeout) {
|
|
5630
|
+
clearTimeout(this.#resizeTimeout);
|
|
5631
|
+
this.#resizeTimeout = undefined;
|
|
5615
5632
|
}
|
|
5616
5633
|
const handleResize = async () => {
|
|
5617
|
-
const canvas = this
|
|
5634
|
+
const canvas = this.#container.canvas;
|
|
5618
5635
|
await canvas.windowResize();
|
|
5619
5636
|
};
|
|
5620
|
-
this
|
|
5637
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5621
5638
|
};
|
|
5622
|
-
|
|
5623
|
-
const handlers = this
|
|
5624
|
-
this
|
|
5639
|
+
#manageListeners = add => {
|
|
5640
|
+
const handlers = this.#handlers;
|
|
5641
|
+
this.#manageResize(add);
|
|
5625
5642
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5626
5643
|
};
|
|
5627
|
-
|
|
5628
|
-
const handlers = this
|
|
5644
|
+
#manageResize = add => {
|
|
5645
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5629
5646
|
if (!options.resize.enable) {
|
|
5630
5647
|
return;
|
|
5631
5648
|
}
|
|
@@ -5634,22 +5651,22 @@
|
|
|
5634
5651
|
return;
|
|
5635
5652
|
}
|
|
5636
5653
|
const canvasEl = container.canvas.domElement;
|
|
5637
|
-
if (this
|
|
5654
|
+
if (this.#resizeObserver && !add) {
|
|
5638
5655
|
if (canvasEl) {
|
|
5639
|
-
this.
|
|
5656
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5640
5657
|
}
|
|
5641
|
-
this.
|
|
5642
|
-
|
|
5658
|
+
this.#resizeObserver.disconnect();
|
|
5659
|
+
this.#resizeObserver = undefined;
|
|
5643
5660
|
}
|
|
5644
|
-
else if (!this
|
|
5645
|
-
this
|
|
5661
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5662
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5646
5663
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5647
5664
|
if (!entry) {
|
|
5648
5665
|
return;
|
|
5649
5666
|
}
|
|
5650
|
-
this
|
|
5667
|
+
this.#handleWindowResize();
|
|
5651
5668
|
});
|
|
5652
|
-
this.
|
|
5669
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5653
5670
|
}
|
|
5654
5671
|
};
|
|
5655
5672
|
}
|
|
@@ -5722,24 +5739,24 @@
|
|
|
5722
5739
|
unbreakable;
|
|
5723
5740
|
velocity;
|
|
5724
5741
|
zIndexFactor;
|
|
5725
|
-
|
|
5742
|
+
#cachedOpacityData = {
|
|
5726
5743
|
fillOpacity: defaultOpacity$1,
|
|
5727
5744
|
opacity: defaultOpacity$1,
|
|
5728
5745
|
strokeOpacity: defaultOpacity$1,
|
|
5729
5746
|
};
|
|
5730
|
-
|
|
5731
|
-
|
|
5732
|
-
|
|
5747
|
+
#cachedPosition = Vector3d.origin;
|
|
5748
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5749
|
+
#cachedTransform = {
|
|
5733
5750
|
a: 1,
|
|
5734
5751
|
b: 0,
|
|
5735
5752
|
c: 0,
|
|
5736
5753
|
d: 1,
|
|
5737
5754
|
};
|
|
5738
|
-
|
|
5739
|
-
|
|
5755
|
+
#container;
|
|
5756
|
+
#pluginManager;
|
|
5740
5757
|
constructor(pluginManager, container) {
|
|
5741
|
-
this
|
|
5742
|
-
this
|
|
5758
|
+
this.#pluginManager = pluginManager;
|
|
5759
|
+
this.#container = container;
|
|
5743
5760
|
}
|
|
5744
5761
|
destroy(override) {
|
|
5745
5762
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5748,7 +5765,7 @@
|
|
|
5748
5765
|
this.destroyed = true;
|
|
5749
5766
|
this.bubble.inRange = false;
|
|
5750
5767
|
this.slow.inRange = false;
|
|
5751
|
-
const container = this
|
|
5768
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5752
5769
|
shapeDrawer?.particleDestroy?.(this);
|
|
5753
5770
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5754
5771
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5756,12 +5773,12 @@
|
|
|
5756
5773
|
for (const updater of container.particleUpdaters) {
|
|
5757
5774
|
updater.particleDestroyed?.(this, override);
|
|
5758
5775
|
}
|
|
5759
|
-
this.
|
|
5776
|
+
this.#container.dispatchEvent(EventType.particleDestroyed, {
|
|
5760
5777
|
particle: this,
|
|
5761
5778
|
});
|
|
5762
5779
|
}
|
|
5763
5780
|
draw(delta) {
|
|
5764
|
-
const container = this
|
|
5781
|
+
const container = this.#container, render = container.canvas.render;
|
|
5765
5782
|
render.drawParticlePlugins(this, delta);
|
|
5766
5783
|
render.drawParticle(this, delta);
|
|
5767
5784
|
}
|
|
@@ -5769,50 +5786,50 @@
|
|
|
5769
5786
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5770
5787
|
}
|
|
5771
5788
|
getFillColor() {
|
|
5772
|
-
return this
|
|
5789
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5773
5790
|
}
|
|
5774
5791
|
getMass() {
|
|
5775
5792
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5776
5793
|
}
|
|
5777
5794
|
getOpacity() {
|
|
5778
5795
|
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;
|
|
5779
|
-
this.
|
|
5780
|
-
this.
|
|
5781
|
-
this.
|
|
5782
|
-
return this
|
|
5796
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5797
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5798
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5799
|
+
return this.#cachedOpacityData;
|
|
5783
5800
|
}
|
|
5784
5801
|
getPosition() {
|
|
5785
|
-
this.
|
|
5786
|
-
this.
|
|
5787
|
-
this.
|
|
5788
|
-
return this
|
|
5802
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5803
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5804
|
+
this.#cachedPosition.z = this.position.z;
|
|
5805
|
+
return this.#cachedPosition;
|
|
5789
5806
|
}
|
|
5790
5807
|
getRadius() {
|
|
5791
5808
|
return this.bubble.radius ?? this.size.value;
|
|
5792
5809
|
}
|
|
5793
5810
|
getRotateData() {
|
|
5794
5811
|
const angle = this.getAngle();
|
|
5795
|
-
this.
|
|
5796
|
-
this.
|
|
5797
|
-
return this
|
|
5812
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5813
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5814
|
+
return this.#cachedRotateData;
|
|
5798
5815
|
}
|
|
5799
5816
|
getStrokeColor() {
|
|
5800
|
-
return this
|
|
5817
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5801
5818
|
}
|
|
5802
5819
|
getTransformData(externalTransform) {
|
|
5803
5820
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5804
|
-
this.
|
|
5805
|
-
this.
|
|
5821
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5822
|
+
this.#cachedTransform.b = rotating
|
|
5806
5823
|
? rotateData.sin * (externalTransform.b ?? identity$3)
|
|
5807
5824
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5808
|
-
this.
|
|
5825
|
+
this.#cachedTransform.c = rotating
|
|
5809
5826
|
? -rotateData.sin * (externalTransform.c ?? identity$3)
|
|
5810
5827
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5811
|
-
this.
|
|
5812
|
-
return this
|
|
5828
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5829
|
+
return this.#cachedTransform;
|
|
5813
5830
|
}
|
|
5814
5831
|
init(id, position, overrideOptions, group) {
|
|
5815
|
-
const container = this
|
|
5832
|
+
const container = this.#container;
|
|
5816
5833
|
this.id = id;
|
|
5817
5834
|
this.group = group;
|
|
5818
5835
|
this.justWarped = false;
|
|
@@ -5832,21 +5849,27 @@
|
|
|
5832
5849
|
moveSpeed: 0,
|
|
5833
5850
|
sizeAnimationSpeed: 0,
|
|
5834
5851
|
};
|
|
5852
|
+
this.size = {
|
|
5853
|
+
value: 1,
|
|
5854
|
+
max: 1,
|
|
5855
|
+
min: 1,
|
|
5856
|
+
enable: false,
|
|
5857
|
+
};
|
|
5835
5858
|
this.outType = ParticleOutType.normal;
|
|
5836
5859
|
this.ignoresResizeRatio = true;
|
|
5837
|
-
const
|
|
5860
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5838
5861
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5839
5862
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5840
5863
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5841
5864
|
if (overrideOptions) {
|
|
5842
|
-
if (overrideOptions.effect?.type) {
|
|
5865
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5843
5866
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5844
5867
|
if (effect) {
|
|
5845
5868
|
this.effect = effect;
|
|
5846
5869
|
effectOptions.load(overrideOptions.effect);
|
|
5847
5870
|
}
|
|
5848
5871
|
}
|
|
5849
|
-
if (overrideOptions.shape?.type) {
|
|
5872
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5850
5873
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5851
5874
|
if (shape) {
|
|
5852
5875
|
this.shape = shape;
|
|
@@ -5855,21 +5878,20 @@
|
|
|
5855
5878
|
}
|
|
5856
5879
|
}
|
|
5857
5880
|
if (this.effect === randomColorValue) {
|
|
5858
|
-
const availableEffects = [...this.
|
|
5881
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5859
5882
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5860
5883
|
}
|
|
5861
5884
|
if (this.shape === randomColorValue) {
|
|
5862
|
-
const availableShapes = [...this.
|
|
5885
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5863
5886
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5864
5887
|
}
|
|
5865
5888
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5866
5889
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5867
5890
|
particlesOptions.load(overrideOptions);
|
|
5868
|
-
const effectData = this.effectData;
|
|
5891
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5869
5892
|
if (effectData) {
|
|
5870
5893
|
particlesOptions.load(effectData.particles);
|
|
5871
5894
|
}
|
|
5872
|
-
const shapeData = this.shapeData;
|
|
5873
5895
|
if (shapeData) {
|
|
5874
5896
|
particlesOptions.load(shapeData.particles);
|
|
5875
5897
|
}
|
|
@@ -5877,7 +5899,9 @@
|
|
|
5877
5899
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5878
5900
|
this.options = particlesOptions;
|
|
5879
5901
|
container.retina.initParticle(this);
|
|
5880
|
-
|
|
5902
|
+
for (const updater of container.particleUpdaters) {
|
|
5903
|
+
updater.preInit?.(this);
|
|
5904
|
+
}
|
|
5881
5905
|
this.bubble = {
|
|
5882
5906
|
inRange: false,
|
|
5883
5907
|
};
|
|
@@ -5885,8 +5909,8 @@
|
|
|
5885
5909
|
inRange: false,
|
|
5886
5910
|
factor: 1,
|
|
5887
5911
|
};
|
|
5888
|
-
this
|
|
5889
|
-
this.initialVelocity = this
|
|
5912
|
+
this.#initPosition(position);
|
|
5913
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5890
5914
|
this.velocity = this.initialVelocity.copy();
|
|
5891
5915
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5892
5916
|
this.sides = 24;
|
|
@@ -5917,12 +5941,11 @@
|
|
|
5917
5941
|
plugin.particleCreated?.(this);
|
|
5918
5942
|
}
|
|
5919
5943
|
}
|
|
5920
|
-
isInsideCanvas() {
|
|
5921
|
-
|
|
5922
|
-
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
position.x <= canvasSize.width + radius);
|
|
5944
|
+
isInsideCanvas(direction) {
|
|
5945
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5946
|
+
}
|
|
5947
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5948
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5926
5949
|
}
|
|
5927
5950
|
isShowingBack() {
|
|
5928
5951
|
if (!this.roll) {
|
|
@@ -5947,13 +5970,13 @@
|
|
|
5947
5970
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5948
5971
|
}
|
|
5949
5972
|
reset() {
|
|
5950
|
-
for (const updater of this.
|
|
5973
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5951
5974
|
updater.reset?.(this);
|
|
5952
5975
|
}
|
|
5953
5976
|
}
|
|
5954
|
-
|
|
5977
|
+
#calcPosition = (position, zIndex) => {
|
|
5955
5978
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5956
|
-
const container = this
|
|
5979
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5957
5980
|
while (!signal.aborted) {
|
|
5958
5981
|
for (const plugin of plugins) {
|
|
5959
5982
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5965,10 +5988,10 @@
|
|
|
5965
5988
|
size: canvasSize,
|
|
5966
5989
|
position: posVec,
|
|
5967
5990
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5968
|
-
this
|
|
5969
|
-
this
|
|
5970
|
-
this
|
|
5971
|
-
this
|
|
5991
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5992
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5993
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5994
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5972
5995
|
let isValidPosition = true;
|
|
5973
5996
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5974
5997
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5984,8 +6007,8 @@
|
|
|
5984
6007
|
}
|
|
5985
6008
|
return posVec;
|
|
5986
6009
|
};
|
|
5987
|
-
|
|
5988
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
6010
|
+
#calculateVelocity = () => {
|
|
6011
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5989
6012
|
if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
|
|
5990
6013
|
return res;
|
|
5991
6014
|
}
|
|
@@ -6001,27 +6024,86 @@
|
|
|
6001
6024
|
}
|
|
6002
6025
|
return res;
|
|
6003
6026
|
};
|
|
6004
|
-
|
|
6027
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
6005
6028
|
fixOutMode({
|
|
6006
6029
|
outMode,
|
|
6007
6030
|
checkModes: [OutMode.bounce],
|
|
6008
6031
|
coord: pos.x,
|
|
6009
|
-
maxCoord: this.
|
|
6032
|
+
maxCoord: this.#container.canvas.size.width,
|
|
6010
6033
|
setCb: (value) => (pos.x += value),
|
|
6011
6034
|
radius,
|
|
6012
6035
|
});
|
|
6013
6036
|
};
|
|
6014
|
-
|
|
6037
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
6015
6038
|
fixOutMode({
|
|
6016
6039
|
outMode,
|
|
6017
6040
|
checkModes: [OutMode.bounce],
|
|
6018
6041
|
coord: pos.y,
|
|
6019
|
-
maxCoord: this.
|
|
6042
|
+
maxCoord: this.#container.canvas.size.height,
|
|
6020
6043
|
setCb: (value) => (pos.y += value),
|
|
6021
6044
|
radius,
|
|
6022
6045
|
});
|
|
6023
6046
|
};
|
|
6024
|
-
|
|
6047
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
6048
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
|
|
6049
|
+
if (direction === OutModeDirection.bottom) {
|
|
6050
|
+
return {
|
|
6051
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
6052
|
+
reason: "default",
|
|
6053
|
+
};
|
|
6054
|
+
}
|
|
6055
|
+
if (direction === OutModeDirection.left) {
|
|
6056
|
+
return {
|
|
6057
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
6058
|
+
reason: "default",
|
|
6059
|
+
};
|
|
6060
|
+
}
|
|
6061
|
+
if (direction === OutModeDirection.right) {
|
|
6062
|
+
return {
|
|
6063
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
6064
|
+
reason: "default",
|
|
6065
|
+
};
|
|
6066
|
+
}
|
|
6067
|
+
if (direction === OutModeDirection.top) {
|
|
6068
|
+
return {
|
|
6069
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
6070
|
+
reason: "default",
|
|
6071
|
+
};
|
|
6072
|
+
}
|
|
6073
|
+
return {
|
|
6074
|
+
inside: position.x >= -radius &&
|
|
6075
|
+
position.y >= -radius &&
|
|
6076
|
+
position.y <= canvasSize.height + radius &&
|
|
6077
|
+
position.x <= canvasSize.width + radius,
|
|
6078
|
+
reason: "default",
|
|
6079
|
+
};
|
|
6080
|
+
};
|
|
6081
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
6082
|
+
return {
|
|
6083
|
+
canvasSize: this.#container.canvas.size,
|
|
6084
|
+
direction,
|
|
6085
|
+
outMode,
|
|
6086
|
+
particle: this,
|
|
6087
|
+
radius: this.getRadius(),
|
|
6088
|
+
};
|
|
6089
|
+
};
|
|
6090
|
+
#getInsideCanvasResult = (data) => {
|
|
6091
|
+
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;
|
|
6092
|
+
if (!shapeCheck && !effectCheck) {
|
|
6093
|
+
return defaultResult;
|
|
6094
|
+
}
|
|
6095
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
6096
|
+
if (shapeResult && effectResult) {
|
|
6097
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
6098
|
+
return {
|
|
6099
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
6100
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
6101
|
+
reason: "combined",
|
|
6102
|
+
};
|
|
6103
|
+
}
|
|
6104
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
6105
|
+
};
|
|
6106
|
+
#getRollColor = color => {
|
|
6025
6107
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
6026
6108
|
return color;
|
|
6027
6109
|
}
|
|
@@ -6036,8 +6118,8 @@
|
|
|
6036
6118
|
}
|
|
6037
6119
|
return color;
|
|
6038
6120
|
};
|
|
6039
|
-
|
|
6040
|
-
const container = this
|
|
6121
|
+
#initPosition = position => {
|
|
6122
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
6041
6123
|
if (!initialPosition) {
|
|
6042
6124
|
throw new Error("a valid position cannot be found for particle");
|
|
6043
6125
|
}
|
|
@@ -6060,45 +6142,58 @@
|
|
|
6060
6142
|
}
|
|
6061
6143
|
this.offset = Vector.origin;
|
|
6062
6144
|
};
|
|
6145
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
6146
|
+
if (typeof result === "boolean") {
|
|
6147
|
+
return {
|
|
6148
|
+
inside: result,
|
|
6149
|
+
reason,
|
|
6150
|
+
};
|
|
6151
|
+
}
|
|
6152
|
+
return {
|
|
6153
|
+
inside: result.inside,
|
|
6154
|
+
margin: result.margin,
|
|
6155
|
+
reason: result.reason ?? reason,
|
|
6156
|
+
};
|
|
6157
|
+
};
|
|
6063
6158
|
}
|
|
6064
6159
|
|
|
6065
6160
|
class SpatialHashGrid {
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6161
|
+
#cellSize;
|
|
6162
|
+
#cells = new Map();
|
|
6163
|
+
#circlePool = [];
|
|
6164
|
+
#circlePoolIdx;
|
|
6165
|
+
#pendingCellSize;
|
|
6166
|
+
#rectanglePool = [];
|
|
6167
|
+
#rectanglePoolIdx;
|
|
6073
6168
|
constructor(cellSize) {
|
|
6074
|
-
this
|
|
6075
|
-
this
|
|
6076
|
-
this
|
|
6169
|
+
this.#cellSize = cellSize;
|
|
6170
|
+
this.#circlePoolIdx = 0;
|
|
6171
|
+
this.#rectanglePoolIdx = 0;
|
|
6077
6172
|
}
|
|
6078
6173
|
clear() {
|
|
6079
|
-
this.
|
|
6080
|
-
const pendingCellSize = this
|
|
6174
|
+
this.#cells.clear();
|
|
6175
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
6081
6176
|
if (pendingCellSize) {
|
|
6082
|
-
this
|
|
6177
|
+
this.#cellSize = pendingCellSize;
|
|
6083
6178
|
}
|
|
6084
|
-
this
|
|
6179
|
+
this.#pendingCellSize = undefined;
|
|
6085
6180
|
}
|
|
6086
6181
|
insert(particle) {
|
|
6087
|
-
const { x, y } = particle.getPosition(), key = this
|
|
6088
|
-
if (!this.
|
|
6089
|
-
this.
|
|
6182
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
6183
|
+
if (!this.#cells.has(key)) {
|
|
6184
|
+
this.#cells.set(key, []);
|
|
6090
6185
|
}
|
|
6091
|
-
this.
|
|
6186
|
+
this.#cells.get(key)?.push(particle);
|
|
6092
6187
|
}
|
|
6093
6188
|
query(range, check, out = []) {
|
|
6094
|
-
const bounds = this
|
|
6189
|
+
const bounds = this.#getRangeBounds(range);
|
|
6095
6190
|
if (!bounds) {
|
|
6096
6191
|
return out;
|
|
6097
6192
|
}
|
|
6098
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
6193
|
+
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);
|
|
6099
6194
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
6100
6195
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
6101
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
6196
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
6102
6197
|
if (!cellParticles) {
|
|
6103
6198
|
continue;
|
|
6104
6199
|
}
|
|
@@ -6115,29 +6210,29 @@
|
|
|
6115
6210
|
return out;
|
|
6116
6211
|
}
|
|
6117
6212
|
queryCircle(position, radius, check, out = []) {
|
|
6118
|
-
const circle = this
|
|
6119
|
-
this
|
|
6213
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
6214
|
+
this.#releaseShapes();
|
|
6120
6215
|
return result;
|
|
6121
6216
|
}
|
|
6122
6217
|
queryRectangle(position, size, check, out = []) {
|
|
6123
|
-
const rect = this
|
|
6124
|
-
this
|
|
6218
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
6219
|
+
this.#releaseShapes();
|
|
6125
6220
|
return result;
|
|
6126
6221
|
}
|
|
6127
6222
|
setCellSize(cellSize) {
|
|
6128
|
-
this
|
|
6223
|
+
this.#pendingCellSize = cellSize;
|
|
6129
6224
|
}
|
|
6130
|
-
|
|
6131
|
-
return (this
|
|
6225
|
+
#acquireCircle(x, y, r) {
|
|
6226
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
6132
6227
|
}
|
|
6133
|
-
|
|
6134
|
-
return (this
|
|
6228
|
+
#acquireRectangle(x, y, w, h) {
|
|
6229
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
6135
6230
|
}
|
|
6136
|
-
|
|
6137
|
-
const cellX = Math.floor(x / this
|
|
6231
|
+
#cellKeyFromCoords(x, y) {
|
|
6232
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
6138
6233
|
return `${cellX}_${cellY}`;
|
|
6139
6234
|
}
|
|
6140
|
-
|
|
6235
|
+
#getRangeBounds(range) {
|
|
6141
6236
|
if (range instanceof Circle) {
|
|
6142
6237
|
const r = range.radius, { x, y } = range.position;
|
|
6143
6238
|
return {
|
|
@@ -6158,53 +6253,53 @@
|
|
|
6158
6253
|
}
|
|
6159
6254
|
return null;
|
|
6160
6255
|
}
|
|
6161
|
-
|
|
6162
|
-
this
|
|
6163
|
-
this
|
|
6256
|
+
#releaseShapes() {
|
|
6257
|
+
this.#circlePoolIdx = 0;
|
|
6258
|
+
this.#rectanglePoolIdx = 0;
|
|
6164
6259
|
}
|
|
6165
6260
|
}
|
|
6166
6261
|
|
|
6167
6262
|
class ParticlesManager {
|
|
6168
6263
|
checkParticlePositionPlugins;
|
|
6169
6264
|
grid;
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6265
|
+
#array;
|
|
6266
|
+
#container;
|
|
6267
|
+
#groupLimits;
|
|
6268
|
+
#limit;
|
|
6269
|
+
#nextId;
|
|
6270
|
+
#particleBuckets;
|
|
6271
|
+
#particleResetPlugins;
|
|
6272
|
+
#particleUpdatePlugins;
|
|
6273
|
+
#pluginManager;
|
|
6274
|
+
#pool;
|
|
6275
|
+
#postParticleUpdatePlugins;
|
|
6276
|
+
#postUpdatePlugins;
|
|
6277
|
+
#resizeFactor;
|
|
6278
|
+
#updatePlugins;
|
|
6279
|
+
#zBuckets;
|
|
6185
6280
|
constructor(pluginManager, container) {
|
|
6186
|
-
this
|
|
6187
|
-
this
|
|
6188
|
-
this
|
|
6189
|
-
this
|
|
6190
|
-
this
|
|
6191
|
-
this
|
|
6192
|
-
this
|
|
6193
|
-
this
|
|
6194
|
-
this
|
|
6281
|
+
this.#pluginManager = pluginManager;
|
|
6282
|
+
this.#container = container;
|
|
6283
|
+
this.#nextId = 0;
|
|
6284
|
+
this.#array = [];
|
|
6285
|
+
this.#pool = [];
|
|
6286
|
+
this.#limit = 0;
|
|
6287
|
+
this.#groupLimits = new Map();
|
|
6288
|
+
this.#particleBuckets = new Map();
|
|
6289
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
6195
6290
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
6196
6291
|
this.checkParticlePositionPlugins = [];
|
|
6197
|
-
this
|
|
6198
|
-
this
|
|
6199
|
-
this
|
|
6200
|
-
this
|
|
6201
|
-
this
|
|
6292
|
+
this.#particleResetPlugins = [];
|
|
6293
|
+
this.#particleUpdatePlugins = [];
|
|
6294
|
+
this.#postUpdatePlugins = [];
|
|
6295
|
+
this.#postParticleUpdatePlugins = [];
|
|
6296
|
+
this.#updatePlugins = [];
|
|
6202
6297
|
}
|
|
6203
6298
|
get count() {
|
|
6204
|
-
return this.
|
|
6299
|
+
return this.#array.length;
|
|
6205
6300
|
}
|
|
6206
6301
|
addParticle(position, overrideOptions, group, initializer) {
|
|
6207
|
-
const limitMode = this.
|
|
6302
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
6208
6303
|
if (limit > minLimit) {
|
|
6209
6304
|
switch (limitMode) {
|
|
6210
6305
|
case LimitMode.delete: {
|
|
@@ -6222,20 +6317,20 @@
|
|
|
6222
6317
|
}
|
|
6223
6318
|
}
|
|
6224
6319
|
try {
|
|
6225
|
-
const particle = this.
|
|
6226
|
-
particle.init(this
|
|
6320
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
6321
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
6227
6322
|
let canAdd = true;
|
|
6228
6323
|
if (initializer) {
|
|
6229
6324
|
canAdd = initializer(particle);
|
|
6230
6325
|
}
|
|
6231
6326
|
if (!canAdd) {
|
|
6232
|
-
this.
|
|
6327
|
+
this.#pool.push(particle);
|
|
6233
6328
|
return;
|
|
6234
6329
|
}
|
|
6235
|
-
this.
|
|
6236
|
-
this
|
|
6237
|
-
this
|
|
6238
|
-
this.
|
|
6330
|
+
this.#array.push(particle);
|
|
6331
|
+
this.#insertParticleIntoBucket(particle);
|
|
6332
|
+
this.#nextId++;
|
|
6333
|
+
this.#container.dispatchEvent(EventType.particleAdded, {
|
|
6239
6334
|
particle,
|
|
6240
6335
|
});
|
|
6241
6336
|
return particle;
|
|
@@ -6246,25 +6341,25 @@
|
|
|
6246
6341
|
return undefined;
|
|
6247
6342
|
}
|
|
6248
6343
|
clear() {
|
|
6249
|
-
this
|
|
6250
|
-
this.
|
|
6251
|
-
this
|
|
6344
|
+
this.#array = [];
|
|
6345
|
+
this.#particleBuckets.clear();
|
|
6346
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
6252
6347
|
}
|
|
6253
6348
|
destroy() {
|
|
6254
|
-
this
|
|
6255
|
-
this.
|
|
6256
|
-
this.
|
|
6257
|
-
this
|
|
6349
|
+
this.#array = [];
|
|
6350
|
+
this.#pool.length = 0;
|
|
6351
|
+
this.#particleBuckets.clear();
|
|
6352
|
+
this.#zBuckets = [];
|
|
6258
6353
|
this.checkParticlePositionPlugins = [];
|
|
6259
|
-
this
|
|
6260
|
-
this
|
|
6261
|
-
this
|
|
6262
|
-
this
|
|
6263
|
-
this
|
|
6354
|
+
this.#particleResetPlugins = [];
|
|
6355
|
+
this.#particleUpdatePlugins = [];
|
|
6356
|
+
this.#postUpdatePlugins = [];
|
|
6357
|
+
this.#postParticleUpdatePlugins = [];
|
|
6358
|
+
this.#updatePlugins = [];
|
|
6264
6359
|
}
|
|
6265
6360
|
drawParticles(delta) {
|
|
6266
|
-
for (let i = this.
|
|
6267
|
-
const bucket = this
|
|
6361
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
6362
|
+
const bucket = this.#zBuckets[i];
|
|
6268
6363
|
if (!bucket) {
|
|
6269
6364
|
continue;
|
|
6270
6365
|
}
|
|
@@ -6274,24 +6369,24 @@
|
|
|
6274
6369
|
}
|
|
6275
6370
|
}
|
|
6276
6371
|
filter(condition) {
|
|
6277
|
-
return this.
|
|
6372
|
+
return this.#array.filter(condition);
|
|
6278
6373
|
}
|
|
6279
6374
|
find(condition) {
|
|
6280
|
-
return this.
|
|
6375
|
+
return this.#array.find(condition);
|
|
6281
6376
|
}
|
|
6282
6377
|
get(index) {
|
|
6283
|
-
return this
|
|
6378
|
+
return this.#array[index];
|
|
6284
6379
|
}
|
|
6285
6380
|
async init() {
|
|
6286
|
-
const container = this
|
|
6381
|
+
const container = this.#container, options = container.actualOptions;
|
|
6287
6382
|
this.checkParticlePositionPlugins = [];
|
|
6288
|
-
this
|
|
6289
|
-
this
|
|
6290
|
-
this
|
|
6291
|
-
this
|
|
6292
|
-
this
|
|
6293
|
-
this.
|
|
6294
|
-
this
|
|
6383
|
+
this.#updatePlugins = [];
|
|
6384
|
+
this.#particleUpdatePlugins = [];
|
|
6385
|
+
this.#postUpdatePlugins = [];
|
|
6386
|
+
this.#particleResetPlugins = [];
|
|
6387
|
+
this.#postParticleUpdatePlugins = [];
|
|
6388
|
+
this.#particleBuckets.clear();
|
|
6389
|
+
this.#resetBuckets(container.zLayers);
|
|
6295
6390
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
6296
6391
|
for (const plugin of container.plugins) {
|
|
6297
6392
|
if (plugin.redrawInit) {
|
|
@@ -6301,26 +6396,26 @@
|
|
|
6301
6396
|
this.checkParticlePositionPlugins.push(plugin);
|
|
6302
6397
|
}
|
|
6303
6398
|
if (plugin.update) {
|
|
6304
|
-
this.
|
|
6399
|
+
this.#updatePlugins.push(plugin);
|
|
6305
6400
|
}
|
|
6306
6401
|
if (plugin.particleUpdate) {
|
|
6307
|
-
this.
|
|
6402
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
6308
6403
|
}
|
|
6309
6404
|
if (plugin.postUpdate) {
|
|
6310
|
-
this.
|
|
6405
|
+
this.#postUpdatePlugins.push(plugin);
|
|
6311
6406
|
}
|
|
6312
6407
|
if (plugin.particleReset) {
|
|
6313
|
-
this.
|
|
6408
|
+
this.#particleResetPlugins.push(plugin);
|
|
6314
6409
|
}
|
|
6315
6410
|
if (plugin.postParticleUpdate) {
|
|
6316
|
-
this.
|
|
6411
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
6317
6412
|
}
|
|
6318
6413
|
}
|
|
6319
|
-
await this.
|
|
6320
|
-
for (const drawer of this.
|
|
6414
|
+
await this.#container.initDrawersAndUpdaters();
|
|
6415
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
6321
6416
|
await drawer.init?.(container);
|
|
6322
6417
|
}
|
|
6323
|
-
for (const drawer of this.
|
|
6418
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
6324
6419
|
await drawer.init?.(container);
|
|
6325
6420
|
}
|
|
6326
6421
|
let handled = false;
|
|
@@ -6354,10 +6449,10 @@
|
|
|
6354
6449
|
async redraw() {
|
|
6355
6450
|
this.clear();
|
|
6356
6451
|
await this.init();
|
|
6357
|
-
this.
|
|
6452
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
6358
6453
|
}
|
|
6359
6454
|
remove(particle, group, override) {
|
|
6360
|
-
this.removeAt(this.
|
|
6455
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
6361
6456
|
}
|
|
6362
6457
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
6363
6458
|
if (index < minIndex || index > this.count) {
|
|
@@ -6365,7 +6460,7 @@
|
|
|
6365
6460
|
}
|
|
6366
6461
|
let deleted = 0;
|
|
6367
6462
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
6368
|
-
if (this
|
|
6463
|
+
if (this.#removeParticle(i, group, override)) {
|
|
6369
6464
|
i--;
|
|
6370
6465
|
deleted++;
|
|
6371
6466
|
}
|
|
@@ -6375,9 +6470,9 @@
|
|
|
6375
6470
|
this.removeAt(minIndex, quantity, group);
|
|
6376
6471
|
}
|
|
6377
6472
|
setDensity() {
|
|
6378
|
-
const options = this.
|
|
6473
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
6379
6474
|
let pluginsCount = 0;
|
|
6380
|
-
for (const plugin of this.
|
|
6475
|
+
for (const plugin of this.#container.plugins) {
|
|
6381
6476
|
if (plugin.particlesDensityCount) {
|
|
6382
6477
|
pluginsCount += plugin.particlesDensityCount();
|
|
6383
6478
|
}
|
|
@@ -6387,51 +6482,51 @@
|
|
|
6387
6482
|
if (!groupData) {
|
|
6388
6483
|
continue;
|
|
6389
6484
|
}
|
|
6390
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
6391
|
-
this
|
|
6485
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
6486
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
6392
6487
|
}
|
|
6393
|
-
this
|
|
6488
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
6394
6489
|
}
|
|
6395
6490
|
setResizeFactor(factor) {
|
|
6396
|
-
this
|
|
6491
|
+
this.#resizeFactor = factor;
|
|
6397
6492
|
}
|
|
6398
6493
|
update(delta) {
|
|
6399
6494
|
this.grid.clear();
|
|
6400
|
-
for (const plugin of this
|
|
6495
|
+
for (const plugin of this.#updatePlugins) {
|
|
6401
6496
|
plugin.update?.(delta);
|
|
6402
6497
|
}
|
|
6403
|
-
const particlesToDelete = this
|
|
6404
|
-
for (const plugin of this
|
|
6498
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
6499
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
6405
6500
|
plugin.postUpdate?.(delta);
|
|
6406
6501
|
}
|
|
6407
|
-
this
|
|
6502
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
6408
6503
|
if (particlesToDelete.size) {
|
|
6409
6504
|
for (const particle of particlesToDelete) {
|
|
6410
6505
|
this.remove(particle);
|
|
6411
6506
|
}
|
|
6412
6507
|
}
|
|
6413
|
-
|
|
6508
|
+
this.#resizeFactor = undefined;
|
|
6414
6509
|
}
|
|
6415
|
-
|
|
6416
|
-
this.
|
|
6510
|
+
#addToPool = (...particles) => {
|
|
6511
|
+
this.#pool.push(...particles);
|
|
6417
6512
|
};
|
|
6418
|
-
|
|
6513
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
6419
6514
|
const numberOptions = options.number;
|
|
6420
6515
|
if (!numberOptions.density.enable) {
|
|
6421
6516
|
if (group === undefined) {
|
|
6422
|
-
this
|
|
6517
|
+
this.#limit = numberOptions.limit.value;
|
|
6423
6518
|
}
|
|
6424
6519
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
6425
|
-
this.
|
|
6520
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
6426
6521
|
}
|
|
6427
6522
|
return;
|
|
6428
6523
|
}
|
|
6429
|
-
const densityFactor = this
|
|
6524
|
+
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);
|
|
6430
6525
|
if (group === undefined) {
|
|
6431
|
-
this
|
|
6526
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
6432
6527
|
}
|
|
6433
6528
|
else {
|
|
6434
|
-
this.
|
|
6529
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
6435
6530
|
}
|
|
6436
6531
|
if (particlesCount < particlesNumber) {
|
|
6437
6532
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -6440,18 +6535,18 @@
|
|
|
6440
6535
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
6441
6536
|
}
|
|
6442
6537
|
};
|
|
6443
|
-
|
|
6538
|
+
#createBuckets = (zLayers) => {
|
|
6444
6539
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6445
6540
|
return Array.from({ length: bucketCount }, () => []);
|
|
6446
6541
|
};
|
|
6447
|
-
|
|
6448
|
-
const maxBucketIndex = this.
|
|
6542
|
+
#getBucketIndex = (zIndex) => {
|
|
6543
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
6449
6544
|
if (maxBucketIndex <= minIndex) {
|
|
6450
6545
|
return minIndex;
|
|
6451
6546
|
}
|
|
6452
6547
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
6453
6548
|
};
|
|
6454
|
-
|
|
6549
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
6455
6550
|
let start = minIndex, end = bucket.length;
|
|
6456
6551
|
while (start < end) {
|
|
6457
6552
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -6468,8 +6563,8 @@
|
|
|
6468
6563
|
}
|
|
6469
6564
|
return start;
|
|
6470
6565
|
};
|
|
6471
|
-
|
|
6472
|
-
const container = this
|
|
6566
|
+
#initDensityFactor = densityOptions => {
|
|
6567
|
+
const container = this.#container;
|
|
6473
6568
|
if (!densityOptions.enable) {
|
|
6474
6569
|
return defaultDensityFactor;
|
|
6475
6570
|
}
|
|
@@ -6479,82 +6574,82 @@
|
|
|
6479
6574
|
}
|
|
6480
6575
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
6481
6576
|
};
|
|
6482
|
-
|
|
6483
|
-
const bucketIndex = this
|
|
6577
|
+
#insertParticleIntoBucket = (particle) => {
|
|
6578
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6484
6579
|
if (!bucket) {
|
|
6485
6580
|
return;
|
|
6486
6581
|
}
|
|
6487
|
-
bucket.splice(this
|
|
6488
|
-
this.
|
|
6582
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
6583
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
6489
6584
|
};
|
|
6490
|
-
|
|
6491
|
-
const particle = this
|
|
6585
|
+
#removeParticle = (index, group, override) => {
|
|
6586
|
+
const particle = this.#array[index];
|
|
6492
6587
|
if (!particle) {
|
|
6493
6588
|
return false;
|
|
6494
6589
|
}
|
|
6495
6590
|
if (particle.group !== group) {
|
|
6496
6591
|
return false;
|
|
6497
6592
|
}
|
|
6498
|
-
this.
|
|
6499
|
-
this
|
|
6593
|
+
this.#array.splice(index, deleteCount);
|
|
6594
|
+
this.#removeParticleFromBucket(particle);
|
|
6500
6595
|
particle.destroy(override);
|
|
6501
|
-
this.
|
|
6596
|
+
this.#container.dispatchEvent(EventType.particleRemoved, {
|
|
6502
6597
|
particle,
|
|
6503
6598
|
});
|
|
6504
|
-
this
|
|
6599
|
+
this.#addToPool(particle);
|
|
6505
6600
|
return true;
|
|
6506
6601
|
};
|
|
6507
|
-
|
|
6508
|
-
const bucketIndex = this.
|
|
6602
|
+
#removeParticleFromBucket = (particle) => {
|
|
6603
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6509
6604
|
if (!bucket) {
|
|
6510
|
-
this.
|
|
6605
|
+
this.#particleBuckets.delete(particle.id);
|
|
6511
6606
|
return;
|
|
6512
6607
|
}
|
|
6513
|
-
const particleIndex = this
|
|
6608
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
6514
6609
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
6515
|
-
this.
|
|
6610
|
+
this.#particleBuckets.delete(particle.id);
|
|
6516
6611
|
return;
|
|
6517
6612
|
}
|
|
6518
6613
|
bucket.splice(particleIndex, deleteCount);
|
|
6519
|
-
this.
|
|
6614
|
+
this.#particleBuckets.delete(particle.id);
|
|
6520
6615
|
};
|
|
6521
|
-
|
|
6616
|
+
#resetBuckets = (zLayers) => {
|
|
6522
6617
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6523
|
-
if (this.
|
|
6524
|
-
this
|
|
6618
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6619
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
6525
6620
|
return;
|
|
6526
6621
|
}
|
|
6527
|
-
for (const bucket of this
|
|
6622
|
+
for (const bucket of this.#zBuckets) {
|
|
6528
6623
|
bucket.length = minIndex;
|
|
6529
6624
|
}
|
|
6530
6625
|
};
|
|
6531
|
-
|
|
6532
|
-
const newBucketIndex = this
|
|
6626
|
+
#updateParticleBucket = (particle) => {
|
|
6627
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
6533
6628
|
if (currentBucketIndex === undefined) {
|
|
6534
|
-
this
|
|
6629
|
+
this.#insertParticleIntoBucket(particle);
|
|
6535
6630
|
return;
|
|
6536
6631
|
}
|
|
6537
6632
|
if (currentBucketIndex === newBucketIndex) {
|
|
6538
6633
|
return;
|
|
6539
6634
|
}
|
|
6540
|
-
const currentBucket = this
|
|
6635
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
6541
6636
|
if (currentBucket) {
|
|
6542
|
-
const particleIndex = this
|
|
6637
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
6543
6638
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
6544
6639
|
currentBucket.splice(particleIndex, deleteCount);
|
|
6545
6640
|
}
|
|
6546
6641
|
}
|
|
6547
|
-
const newBucket = this
|
|
6642
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
6548
6643
|
if (!newBucket) {
|
|
6549
|
-
this.
|
|
6644
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6550
6645
|
return;
|
|
6551
6646
|
}
|
|
6552
|
-
newBucket.splice(this
|
|
6553
|
-
this.
|
|
6647
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6648
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6554
6649
|
};
|
|
6555
|
-
|
|
6556
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
6557
|
-
for (const particle of this
|
|
6650
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6651
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6652
|
+
for (const particle of this.#array) {
|
|
6558
6653
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
6559
6654
|
particle.position.x *= resizeFactor.width;
|
|
6560
6655
|
particle.position.y *= resizeFactor.height;
|
|
@@ -6562,10 +6657,10 @@
|
|
|
6562
6657
|
particle.initialPosition.y *= resizeFactor.height;
|
|
6563
6658
|
}
|
|
6564
6659
|
particle.ignoresResizeRatio = false;
|
|
6565
|
-
for (const plugin of this
|
|
6660
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
6566
6661
|
plugin.particleReset?.(particle);
|
|
6567
6662
|
}
|
|
6568
|
-
for (const plugin of this
|
|
6663
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
6569
6664
|
if (particle.destroyed) {
|
|
6570
6665
|
break;
|
|
6571
6666
|
}
|
|
@@ -6579,36 +6674,36 @@
|
|
|
6579
6674
|
}
|
|
6580
6675
|
return particlesToDelete;
|
|
6581
6676
|
};
|
|
6582
|
-
|
|
6583
|
-
for (const particle of this
|
|
6677
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6678
|
+
for (const particle of this.#array) {
|
|
6584
6679
|
if (particle.destroyed) {
|
|
6585
6680
|
particlesToDelete.add(particle);
|
|
6586
6681
|
continue;
|
|
6587
6682
|
}
|
|
6588
|
-
for (const updater of this.
|
|
6683
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6589
6684
|
updater.update(particle, delta);
|
|
6590
6685
|
}
|
|
6591
6686
|
if (!particle.spawning) {
|
|
6592
|
-
for (const plugin of this
|
|
6687
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
6593
6688
|
plugin.postParticleUpdate?.(particle, delta);
|
|
6594
6689
|
}
|
|
6595
6690
|
}
|
|
6596
|
-
this
|
|
6691
|
+
this.#updateParticleBucket(particle);
|
|
6597
6692
|
}
|
|
6598
6693
|
};
|
|
6599
6694
|
}
|
|
6600
6695
|
|
|
6601
6696
|
class Retina {
|
|
6602
|
-
container;
|
|
6603
6697
|
pixelRatio;
|
|
6604
6698
|
reduceFactor;
|
|
6699
|
+
#container;
|
|
6605
6700
|
constructor(container) {
|
|
6606
|
-
this
|
|
6701
|
+
this.#container = container;
|
|
6607
6702
|
this.pixelRatio = defaultRatio;
|
|
6608
6703
|
this.reduceFactor = defaultReduceFactor;
|
|
6609
6704
|
}
|
|
6610
6705
|
init() {
|
|
6611
|
-
const container = this
|
|
6706
|
+
const container = this.#container, options = container.actualOptions;
|
|
6612
6707
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6613
6708
|
this.reduceFactor = defaultReduceFactor;
|
|
6614
6709
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6622,7 +6717,6 @@
|
|
|
6622
6717
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6623
6718
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6624
6719
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6625
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6626
6720
|
const maxDistance = props.maxDistance;
|
|
6627
6721
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6628
6722
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6660,73 +6754,73 @@
|
|
|
6660
6754
|
shapeDrawers;
|
|
6661
6755
|
started;
|
|
6662
6756
|
zLayers;
|
|
6663
|
-
|
|
6664
|
-
|
|
6665
|
-
|
|
6666
|
-
|
|
6667
|
-
|
|
6668
|
-
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
|
|
6757
|
+
#delay;
|
|
6758
|
+
#delayTimeout;
|
|
6759
|
+
#delta = { value: 0, factor: 0 };
|
|
6760
|
+
#dispatchCallback;
|
|
6761
|
+
#drawAnimationFrame;
|
|
6762
|
+
#duration;
|
|
6763
|
+
#eventListeners;
|
|
6764
|
+
#firstStart;
|
|
6765
|
+
#initialSourceOptions;
|
|
6766
|
+
#lastFrameTime;
|
|
6767
|
+
#lifeTime;
|
|
6768
|
+
#onDestroy;
|
|
6769
|
+
#options;
|
|
6770
|
+
#paused;
|
|
6771
|
+
#pluginManager;
|
|
6772
|
+
#smooth;
|
|
6773
|
+
#sourceOptions;
|
|
6680
6774
|
constructor(params) {
|
|
6681
6775
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6682
|
-
this
|
|
6683
|
-
this
|
|
6684
|
-
this
|
|
6776
|
+
this.#pluginManager = pluginManager;
|
|
6777
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6778
|
+
this.#onDestroy = onDestroy;
|
|
6685
6779
|
this.id = Symbol(id);
|
|
6686
6780
|
this.fpsLimit = 120;
|
|
6687
6781
|
this.hdr = false;
|
|
6688
|
-
this
|
|
6689
|
-
this
|
|
6690
|
-
this
|
|
6691
|
-
this
|
|
6692
|
-
this
|
|
6782
|
+
this.#smooth = false;
|
|
6783
|
+
this.#delay = 0;
|
|
6784
|
+
this.#duration = 0;
|
|
6785
|
+
this.#lifeTime = 0;
|
|
6786
|
+
this.#firstStart = true;
|
|
6693
6787
|
this.started = false;
|
|
6694
6788
|
this.destroyed = false;
|
|
6695
|
-
this
|
|
6696
|
-
this
|
|
6789
|
+
this.#paused = true;
|
|
6790
|
+
this.#lastFrameTime = 0;
|
|
6697
6791
|
this.zLayers = 100;
|
|
6698
6792
|
this.pageHidden = false;
|
|
6699
|
-
this
|
|
6700
|
-
this
|
|
6793
|
+
this.#sourceOptions = sourceOptions;
|
|
6794
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6701
6795
|
this.effectDrawers = new Map();
|
|
6702
6796
|
this.shapeDrawers = new Map();
|
|
6703
6797
|
this.particleUpdaters = [];
|
|
6704
6798
|
this.retina = new Retina(this);
|
|
6705
|
-
this.canvas = new CanvasManager(this
|
|
6706
|
-
this.particles = new ParticlesManager(this
|
|
6799
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6800
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6707
6801
|
this.plugins = [];
|
|
6708
6802
|
this.particleDestroyedPlugins = [];
|
|
6709
6803
|
this.particleCreatedPlugins = [];
|
|
6710
6804
|
this.particlePositionPlugins = [];
|
|
6711
|
-
this
|
|
6712
|
-
this.actualOptions = loadContainerOptions(this
|
|
6713
|
-
this
|
|
6805
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6806
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6807
|
+
this.#eventListeners = new EventListeners(this);
|
|
6714
6808
|
this.dispatchEvent(EventType.containerBuilt);
|
|
6715
6809
|
}
|
|
6716
6810
|
get animationStatus() {
|
|
6717
|
-
return !this
|
|
6811
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6718
6812
|
}
|
|
6719
6813
|
get options() {
|
|
6720
|
-
return this
|
|
6814
|
+
return this.#options;
|
|
6721
6815
|
}
|
|
6722
6816
|
get sourceOptions() {
|
|
6723
|
-
return this
|
|
6817
|
+
return this.#sourceOptions;
|
|
6724
6818
|
}
|
|
6725
6819
|
addLifeTime(value) {
|
|
6726
|
-
this
|
|
6820
|
+
this.#lifeTime += value;
|
|
6727
6821
|
}
|
|
6728
6822
|
alive() {
|
|
6729
|
-
return !this
|
|
6823
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6730
6824
|
}
|
|
6731
6825
|
destroy(remove = true) {
|
|
6732
6826
|
if (!guardCheck(this)) {
|
|
@@ -6748,13 +6842,13 @@
|
|
|
6748
6842
|
this.shapeDrawers = new Map();
|
|
6749
6843
|
this.particleUpdaters = [];
|
|
6750
6844
|
this.plugins.length = 0;
|
|
6751
|
-
this.
|
|
6845
|
+
this.#pluginManager.clearPlugins(this);
|
|
6752
6846
|
this.destroyed = true;
|
|
6753
|
-
this
|
|
6847
|
+
this.#onDestroy(remove);
|
|
6754
6848
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
6755
6849
|
}
|
|
6756
6850
|
dispatchEvent(type, data) {
|
|
6757
|
-
this
|
|
6851
|
+
this.#dispatchCallback(type, {
|
|
6758
6852
|
container: this,
|
|
6759
6853
|
data,
|
|
6760
6854
|
});
|
|
@@ -6764,12 +6858,12 @@
|
|
|
6764
6858
|
return;
|
|
6765
6859
|
}
|
|
6766
6860
|
let refreshTime = force;
|
|
6767
|
-
this
|
|
6861
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6768
6862
|
if (refreshTime) {
|
|
6769
|
-
this
|
|
6863
|
+
this.#lastFrameTime = undefined;
|
|
6770
6864
|
refreshTime = false;
|
|
6771
6865
|
}
|
|
6772
|
-
this
|
|
6866
|
+
this.#nextFrame(timestamp);
|
|
6773
6867
|
});
|
|
6774
6868
|
}
|
|
6775
6869
|
async export(type, options = {}) {
|
|
@@ -6791,7 +6885,7 @@
|
|
|
6791
6885
|
return;
|
|
6792
6886
|
}
|
|
6793
6887
|
const allContainerPlugins = new Map();
|
|
6794
|
-
for (const plugin of this.
|
|
6888
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6795
6889
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6796
6890
|
if (containerPlugin.preInit) {
|
|
6797
6891
|
await containerPlugin.preInit();
|
|
@@ -6799,8 +6893,8 @@
|
|
|
6799
6893
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6800
6894
|
}
|
|
6801
6895
|
await this.initDrawersAndUpdaters();
|
|
6802
|
-
this
|
|
6803
|
-
this.actualOptions = loadContainerOptions(this
|
|
6896
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6897
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6804
6898
|
this.plugins.length = 0;
|
|
6805
6899
|
this.particleDestroyedPlugins.length = 0;
|
|
6806
6900
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6827,11 +6921,11 @@
|
|
|
6827
6921
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6828
6922
|
this.hdr = hdr;
|
|
6829
6923
|
this.zLayers = zLayers;
|
|
6830
|
-
this
|
|
6831
|
-
this
|
|
6832
|
-
this
|
|
6924
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6925
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6926
|
+
this.#lifeTime = 0;
|
|
6833
6927
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6834
|
-
this
|
|
6928
|
+
this.#smooth = smooth;
|
|
6835
6929
|
for (const plugin of this.plugins) {
|
|
6836
6930
|
await plugin.init?.();
|
|
6837
6931
|
}
|
|
@@ -6844,7 +6938,7 @@
|
|
|
6844
6938
|
this.dispatchEvent(EventType.particlesSetup);
|
|
6845
6939
|
}
|
|
6846
6940
|
async initDrawersAndUpdaters() {
|
|
6847
|
-
const pluginManager = this
|
|
6941
|
+
const pluginManager = this.#pluginManager;
|
|
6848
6942
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6849
6943
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6850
6944
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6853,18 +6947,18 @@
|
|
|
6853
6947
|
if (!guardCheck(this)) {
|
|
6854
6948
|
return;
|
|
6855
6949
|
}
|
|
6856
|
-
if (this
|
|
6857
|
-
cancelAnimation(this
|
|
6858
|
-
|
|
6950
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6951
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6952
|
+
this.#drawAnimationFrame = undefined;
|
|
6859
6953
|
}
|
|
6860
|
-
if (this
|
|
6954
|
+
if (this.#paused) {
|
|
6861
6955
|
return;
|
|
6862
6956
|
}
|
|
6863
6957
|
for (const plugin of this.plugins) {
|
|
6864
6958
|
plugin.pause?.();
|
|
6865
6959
|
}
|
|
6866
6960
|
if (!this.pageHidden) {
|
|
6867
|
-
this
|
|
6961
|
+
this.#paused = true;
|
|
6868
6962
|
}
|
|
6869
6963
|
this.dispatchEvent(EventType.containerPaused);
|
|
6870
6964
|
}
|
|
@@ -6872,13 +6966,13 @@
|
|
|
6872
6966
|
if (!guardCheck(this)) {
|
|
6873
6967
|
return;
|
|
6874
6968
|
}
|
|
6875
|
-
const needsUpdate = this
|
|
6876
|
-
if (this
|
|
6877
|
-
this
|
|
6969
|
+
const needsUpdate = this.#paused || force;
|
|
6970
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6971
|
+
this.#firstStart = false;
|
|
6878
6972
|
return;
|
|
6879
6973
|
}
|
|
6880
|
-
if (this
|
|
6881
|
-
this
|
|
6974
|
+
if (this.#paused) {
|
|
6975
|
+
this.#paused = false;
|
|
6882
6976
|
}
|
|
6883
6977
|
if (needsUpdate) {
|
|
6884
6978
|
for (const plugin of this.plugins) {
|
|
@@ -6901,10 +6995,10 @@
|
|
|
6901
6995
|
if (!guardCheck(this)) {
|
|
6902
6996
|
return;
|
|
6903
6997
|
}
|
|
6904
|
-
this
|
|
6905
|
-
this
|
|
6906
|
-
this
|
|
6907
|
-
this.actualOptions = loadContainerOptions(this
|
|
6998
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6999
|
+
this.#sourceOptions = sourceOptions;
|
|
7000
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
7001
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6908
7002
|
return this.refresh();
|
|
6909
7003
|
}
|
|
6910
7004
|
async start() {
|
|
@@ -6915,7 +7009,7 @@
|
|
|
6915
7009
|
this.started = true;
|
|
6916
7010
|
await new Promise(resolve => {
|
|
6917
7011
|
const start = async () => {
|
|
6918
|
-
this.
|
|
7012
|
+
this.#eventListeners.addListeners();
|
|
6919
7013
|
for (const plugin of this.plugins) {
|
|
6920
7014
|
await plugin.start?.();
|
|
6921
7015
|
}
|
|
@@ -6923,20 +7017,20 @@
|
|
|
6923
7017
|
this.play();
|
|
6924
7018
|
resolve();
|
|
6925
7019
|
};
|
|
6926
|
-
this
|
|
7020
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6927
7021
|
});
|
|
6928
7022
|
}
|
|
6929
7023
|
stop() {
|
|
6930
7024
|
if (!guardCheck(this) || !this.started) {
|
|
6931
7025
|
return;
|
|
6932
7026
|
}
|
|
6933
|
-
if (this
|
|
6934
|
-
clearTimeout(this
|
|
6935
|
-
|
|
7027
|
+
if (this.#delayTimeout) {
|
|
7028
|
+
clearTimeout(this.#delayTimeout);
|
|
7029
|
+
this.#delayTimeout = undefined;
|
|
6936
7030
|
}
|
|
6937
|
-
this
|
|
7031
|
+
this.#firstStart = true;
|
|
6938
7032
|
this.started = false;
|
|
6939
|
-
this.
|
|
7033
|
+
this.#eventListeners.removeListeners();
|
|
6940
7034
|
this.pause();
|
|
6941
7035
|
this.particles.clear();
|
|
6942
7036
|
this.canvas.stop();
|
|
@@ -6946,7 +7040,7 @@
|
|
|
6946
7040
|
this.particleCreatedPlugins.length = 0;
|
|
6947
7041
|
this.particleDestroyedPlugins.length = 0;
|
|
6948
7042
|
this.particlePositionPlugins.length = 0;
|
|
6949
|
-
this
|
|
7043
|
+
this.#sourceOptions = this.#options;
|
|
6950
7044
|
this.dispatchEvent(EventType.containerStopped);
|
|
6951
7045
|
}
|
|
6952
7046
|
updateActualOptions() {
|
|
@@ -6958,23 +7052,23 @@
|
|
|
6958
7052
|
}
|
|
6959
7053
|
return refresh;
|
|
6960
7054
|
}
|
|
6961
|
-
|
|
7055
|
+
#nextFrame = (timestamp) => {
|
|
6962
7056
|
try {
|
|
6963
|
-
if (!this
|
|
6964
|
-
this
|
|
6965
|
-
timestamp < this
|
|
7057
|
+
if (!this.#smooth &&
|
|
7058
|
+
this.#lastFrameTime !== undefined &&
|
|
7059
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6966
7060
|
this.draw(false);
|
|
6967
7061
|
return;
|
|
6968
7062
|
}
|
|
6969
|
-
this
|
|
6970
|
-
updateDelta(this
|
|
6971
|
-
this.addLifeTime(this.
|
|
6972
|
-
this
|
|
6973
|
-
if (this.
|
|
7063
|
+
this.#lastFrameTime ??= timestamp;
|
|
7064
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
7065
|
+
this.addLifeTime(this.#delta.value);
|
|
7066
|
+
this.#lastFrameTime = timestamp;
|
|
7067
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6974
7068
|
this.draw(false);
|
|
6975
7069
|
return;
|
|
6976
7070
|
}
|
|
6977
|
-
this.canvas.render.drawParticles(this
|
|
7071
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6978
7072
|
if (!this.alive()) {
|
|
6979
7073
|
this.destroy();
|
|
6980
7074
|
return;
|
|
@@ -6995,10 +7089,10 @@
|
|
|
6995
7089
|
});
|
|
6996
7090
|
|
|
6997
7091
|
class BlendPluginInstance {
|
|
6998
|
-
|
|
6999
|
-
|
|
7092
|
+
#container;
|
|
7093
|
+
#defaultCompositeValue;
|
|
7000
7094
|
constructor(container) {
|
|
7001
|
-
this
|
|
7095
|
+
this.#container = container;
|
|
7002
7096
|
}
|
|
7003
7097
|
drawParticleCleanup(context, particle) {
|
|
7004
7098
|
if (!particle.options.blend?.enable) {
|
|
@@ -7015,14 +7109,14 @@
|
|
|
7015
7109
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
7016
7110
|
}
|
|
7017
7111
|
drawSettingsCleanup(context) {
|
|
7018
|
-
if (!this
|
|
7112
|
+
if (!this.#defaultCompositeValue) {
|
|
7019
7113
|
return;
|
|
7020
7114
|
}
|
|
7021
|
-
context.globalCompositeOperation = this
|
|
7115
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
7022
7116
|
}
|
|
7023
7117
|
drawSettingsSetup(context) {
|
|
7024
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
7025
|
-
this
|
|
7118
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
7119
|
+
this.#defaultCompositeValue = previousComposite;
|
|
7026
7120
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
7027
7121
|
}
|
|
7028
7122
|
}
|
|
@@ -7165,11 +7259,11 @@
|
|
|
7165
7259
|
class MovePluginInstance {
|
|
7166
7260
|
availablePathGenerators;
|
|
7167
7261
|
pathGenerators;
|
|
7168
|
-
|
|
7169
|
-
|
|
7262
|
+
#container;
|
|
7263
|
+
#pluginManager;
|
|
7170
7264
|
constructor(pluginManager, container) {
|
|
7171
|
-
this
|
|
7172
|
-
this
|
|
7265
|
+
this.#pluginManager = pluginManager;
|
|
7266
|
+
this.#container = container;
|
|
7173
7267
|
this.availablePathGenerators = new Map();
|
|
7174
7268
|
this.pathGenerators = new Map();
|
|
7175
7269
|
}
|
|
@@ -7200,7 +7294,7 @@
|
|
|
7200
7294
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
7201
7295
|
inverse: gravityOptions.inverse,
|
|
7202
7296
|
};
|
|
7203
|
-
initSpin(this
|
|
7297
|
+
initSpin(this.#container, particle);
|
|
7204
7298
|
}
|
|
7205
7299
|
particleDestroyed(particle) {
|
|
7206
7300
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -7211,7 +7305,7 @@
|
|
|
7211
7305
|
if (!moveOptions.enable) {
|
|
7212
7306
|
return;
|
|
7213
7307
|
}
|
|
7214
|
-
const container = this
|
|
7308
|
+
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;
|
|
7215
7309
|
if (moveOptions.spin.enable) {
|
|
7216
7310
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
7217
7311
|
}
|
|
@@ -7221,18 +7315,18 @@
|
|
|
7221
7315
|
applyDistance(particle);
|
|
7222
7316
|
}
|
|
7223
7317
|
preInit() {
|
|
7224
|
-
return this
|
|
7318
|
+
return this.#init();
|
|
7225
7319
|
}
|
|
7226
7320
|
redrawInit() {
|
|
7227
|
-
return this
|
|
7321
|
+
return this.#init();
|
|
7228
7322
|
}
|
|
7229
7323
|
update() {
|
|
7230
7324
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
7231
7325
|
pathGenerator.update();
|
|
7232
7326
|
}
|
|
7233
7327
|
}
|
|
7234
|
-
async
|
|
7235
|
-
const availablePathGenerators = await this.
|
|
7328
|
+
async #init() {
|
|
7329
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
7236
7330
|
if (!availablePathGenerators) {
|
|
7237
7331
|
return;
|
|
7238
7332
|
}
|
|
@@ -7250,44 +7344,44 @@
|
|
|
7250
7344
|
});
|
|
7251
7345
|
|
|
7252
7346
|
class EmittersPluginInstance {
|
|
7253
|
-
container;
|
|
7254
|
-
|
|
7347
|
+
#container;
|
|
7348
|
+
#instancesManager;
|
|
7255
7349
|
constructor(instancesManager, container) {
|
|
7256
|
-
this
|
|
7257
|
-
this
|
|
7258
|
-
this.
|
|
7350
|
+
this.#instancesManager = instancesManager;
|
|
7351
|
+
this.#container = container;
|
|
7352
|
+
this.#instancesManager.initContainer(container);
|
|
7259
7353
|
}
|
|
7260
7354
|
async init() {
|
|
7261
|
-
const emittersOptions = this
|
|
7355
|
+
const emittersOptions = this.#container.actualOptions.emitters;
|
|
7262
7356
|
if (isArray(emittersOptions)) {
|
|
7263
7357
|
for (const emitterOptions of emittersOptions) {
|
|
7264
|
-
await this.
|
|
7358
|
+
await this.#instancesManager.addEmitter(this.#container, emitterOptions);
|
|
7265
7359
|
}
|
|
7266
7360
|
}
|
|
7267
7361
|
else {
|
|
7268
|
-
await this.
|
|
7362
|
+
await this.#instancesManager.addEmitter(this.#container, emittersOptions);
|
|
7269
7363
|
}
|
|
7270
7364
|
}
|
|
7271
7365
|
pause() {
|
|
7272
|
-
for (const emitter of this.
|
|
7366
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
7273
7367
|
emitter.pause();
|
|
7274
7368
|
}
|
|
7275
7369
|
}
|
|
7276
7370
|
play() {
|
|
7277
|
-
for (const emitter of this.
|
|
7371
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
7278
7372
|
emitter.play();
|
|
7279
7373
|
}
|
|
7280
7374
|
}
|
|
7281
7375
|
resize() {
|
|
7282
|
-
for (const emitter of this.
|
|
7376
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
7283
7377
|
emitter.resize();
|
|
7284
7378
|
}
|
|
7285
7379
|
}
|
|
7286
7380
|
stop() {
|
|
7287
|
-
this.
|
|
7381
|
+
this.#instancesManager.clear(this.#container);
|
|
7288
7382
|
}
|
|
7289
7383
|
update(delta) {
|
|
7290
|
-
this.
|
|
7384
|
+
this.#instancesManager.getArray(this.#container).forEach(emitter => {
|
|
7291
7385
|
emitter.update(delta);
|
|
7292
7386
|
});
|
|
7293
7387
|
}
|
|
@@ -7320,16 +7414,16 @@
|
|
|
7320
7414
|
|
|
7321
7415
|
const defaultIndex = 0;
|
|
7322
7416
|
class EmittersInstancesManager {
|
|
7323
|
-
|
|
7324
|
-
|
|
7417
|
+
#containerArrays;
|
|
7418
|
+
#pluginManager;
|
|
7325
7419
|
constructor(pluginManager) {
|
|
7326
|
-
this
|
|
7327
|
-
this
|
|
7420
|
+
this.#containerArrays = new Map();
|
|
7421
|
+
this.#pluginManager = pluginManager;
|
|
7328
7422
|
}
|
|
7329
7423
|
async addEmitter(container, options, position) {
|
|
7330
7424
|
const emitterOptions = new Emitter();
|
|
7331
7425
|
emitterOptions.load(options);
|
|
7332
|
-
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this
|
|
7426
|
+
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this.#pluginManager, container, (emitter) => {
|
|
7333
7427
|
this.removeEmitter(container, emitter);
|
|
7334
7428
|
}, emitterOptions, position);
|
|
7335
7429
|
await emitter.init();
|
|
@@ -7338,22 +7432,22 @@
|
|
|
7338
7432
|
}
|
|
7339
7433
|
clear(container) {
|
|
7340
7434
|
this.initContainer(container);
|
|
7341
|
-
this.
|
|
7435
|
+
this.#containerArrays.set(container, []);
|
|
7342
7436
|
}
|
|
7343
7437
|
getArray(container) {
|
|
7344
7438
|
this.initContainer(container);
|
|
7345
|
-
let array = this.
|
|
7439
|
+
let array = this.#containerArrays.get(container);
|
|
7346
7440
|
if (!array) {
|
|
7347
7441
|
array = [];
|
|
7348
|
-
this.
|
|
7442
|
+
this.#containerArrays.set(container, array);
|
|
7349
7443
|
}
|
|
7350
7444
|
return array;
|
|
7351
7445
|
}
|
|
7352
7446
|
initContainer(container) {
|
|
7353
|
-
if (this.
|
|
7447
|
+
if (this.#containerArrays.has(container)) {
|
|
7354
7448
|
return;
|
|
7355
7449
|
}
|
|
7356
|
-
this.
|
|
7450
|
+
this.#containerArrays.set(container, []);
|
|
7357
7451
|
container.getEmitter = (idxOrName) => {
|
|
7358
7452
|
const array = this.getArray(container);
|
|
7359
7453
|
return idxOrName === undefined || isNumber(idxOrName)
|
|
@@ -7395,12 +7489,12 @@
|
|
|
7395
7489
|
|
|
7396
7490
|
const defaultFactor = 1, defaultReduce = 1, disableReduce = 0, identity = 1;
|
|
7397
7491
|
class MotionPluginInstance {
|
|
7398
|
-
|
|
7492
|
+
#container;
|
|
7399
7493
|
constructor(container) {
|
|
7400
|
-
this
|
|
7494
|
+
this.#container = container;
|
|
7401
7495
|
}
|
|
7402
7496
|
async init() {
|
|
7403
|
-
const container = this
|
|
7497
|
+
const container = this.#container, options = container.actualOptions.motion;
|
|
7404
7498
|
if (!(options && (options.disable || options.reduce.value))) {
|
|
7405
7499
|
container.retina.reduceFactor = 1;
|
|
7406
7500
|
return;
|
|
@@ -7410,10 +7504,10 @@
|
|
|
7410
7504
|
container.retina.reduceFactor = defaultFactor;
|
|
7411
7505
|
return;
|
|
7412
7506
|
}
|
|
7413
|
-
this
|
|
7507
|
+
this.#handleMotionChange(mediaQuery);
|
|
7414
7508
|
const handleChange = () => {
|
|
7415
7509
|
void (async () => {
|
|
7416
|
-
this
|
|
7510
|
+
this.#handleMotionChange(mediaQuery);
|
|
7417
7511
|
try {
|
|
7418
7512
|
await container.refresh();
|
|
7419
7513
|
}
|
|
@@ -7424,8 +7518,8 @@
|
|
|
7424
7518
|
mediaQuery.addEventListener("change", handleChange);
|
|
7425
7519
|
await Promise.resolve();
|
|
7426
7520
|
}
|
|
7427
|
-
|
|
7428
|
-
const container = this
|
|
7521
|
+
#handleMotionChange = mediaQuery => {
|
|
7522
|
+
const container = this.#container, motion = container.actualOptions.motion;
|
|
7429
7523
|
if (!motion) {
|
|
7430
7524
|
return;
|
|
7431
7525
|
}
|
|
@@ -7477,34 +7571,34 @@
|
|
|
7477
7571
|
spawnStrokeColor;
|
|
7478
7572
|
spawnStrokeOpacity;
|
|
7479
7573
|
spawnStrokeWidth;
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7574
|
+
#container;
|
|
7575
|
+
#currentDuration;
|
|
7576
|
+
#currentEmitDelay;
|
|
7577
|
+
#currentSpawnDelay;
|
|
7578
|
+
#duration;
|
|
7579
|
+
#emitDelay;
|
|
7580
|
+
#firstSpawn;
|
|
7581
|
+
#immortal;
|
|
7582
|
+
#initialPosition;
|
|
7583
|
+
#lifeCount;
|
|
7584
|
+
#mutationObserver;
|
|
7585
|
+
#particlesOptions;
|
|
7586
|
+
#paused;
|
|
7587
|
+
#pluginManager;
|
|
7588
|
+
#removeCallback;
|
|
7589
|
+
#resizeObserver;
|
|
7590
|
+
#shape;
|
|
7591
|
+
#size;
|
|
7592
|
+
#spawnDelay;
|
|
7593
|
+
#startParticlesAdded;
|
|
7500
7594
|
constructor(pluginManager, container, removeCallback, options, position) {
|
|
7501
|
-
this
|
|
7502
|
-
this
|
|
7503
|
-
this
|
|
7504
|
-
this
|
|
7505
|
-
this
|
|
7506
|
-
this
|
|
7507
|
-
this
|
|
7595
|
+
this.#pluginManager = pluginManager;
|
|
7596
|
+
this.#container = container;
|
|
7597
|
+
this.#removeCallback = removeCallback;
|
|
7598
|
+
this.#currentDuration = 0;
|
|
7599
|
+
this.#currentEmitDelay = 0;
|
|
7600
|
+
this.#currentSpawnDelay = 0;
|
|
7601
|
+
this.#initialPosition = position;
|
|
7508
7602
|
if (options instanceof Emitter) {
|
|
7509
7603
|
this.options = options;
|
|
7510
7604
|
}
|
|
@@ -7512,159 +7606,159 @@
|
|
|
7512
7606
|
this.options = new Emitter();
|
|
7513
7607
|
this.options.load(options);
|
|
7514
7608
|
}
|
|
7515
|
-
this
|
|
7609
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
7516
7610
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
7517
7611
|
container.retina.reduceFactor
|
|
7518
7612
|
: Infinity;
|
|
7519
|
-
this.position = this
|
|
7613
|
+
this.position = this.#initialPosition ?? this.#calcPosition();
|
|
7520
7614
|
this.name = this.options.name;
|
|
7521
7615
|
this.fill = this.options.fill;
|
|
7522
|
-
this
|
|
7523
|
-
this
|
|
7616
|
+
this.#firstSpawn = !this.options.life.wait;
|
|
7617
|
+
this.#startParticlesAdded = false;
|
|
7524
7618
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
7525
7619
|
particlesOptions.move ??= {};
|
|
7526
7620
|
particlesOptions.move.direction ??= this.options.direction;
|
|
7527
7621
|
if (this.options.spawn.fill?.color) {
|
|
7528
|
-
this.spawnFillColor = rangeColorToHsl(this
|
|
7622
|
+
this.spawnFillColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.fill.color);
|
|
7529
7623
|
}
|
|
7530
7624
|
if (this.options.spawn.stroke?.color) {
|
|
7531
|
-
this.spawnStrokeColor = rangeColorToHsl(this
|
|
7532
|
-
}
|
|
7533
|
-
this
|
|
7534
|
-
this
|
|
7535
|
-
this
|
|
7536
|
-
this.size = getSize(this
|
|
7537
|
-
this
|
|
7538
|
-
this
|
|
7625
|
+
this.spawnStrokeColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.stroke.color);
|
|
7626
|
+
}
|
|
7627
|
+
this.#paused = !this.options.autoPlay;
|
|
7628
|
+
this.#particlesOptions = particlesOptions;
|
|
7629
|
+
this.#size = this.#calcSize();
|
|
7630
|
+
this.size = getSize(this.#size, this.#container.canvas.size);
|
|
7631
|
+
this.#lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
7632
|
+
this.#immortal = this.#lifeCount <= minLifeCount;
|
|
7539
7633
|
if (this.options.domId) {
|
|
7540
7634
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7541
7635
|
if (element) {
|
|
7542
|
-
this
|
|
7636
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
7543
7637
|
this.resize();
|
|
7544
7638
|
});
|
|
7545
|
-
this
|
|
7639
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
7546
7640
|
this.resize();
|
|
7547
7641
|
});
|
|
7548
|
-
this.
|
|
7642
|
+
this.#mutationObserver.observe(element, {
|
|
7549
7643
|
attributes: true,
|
|
7550
7644
|
attributeFilter: ["style", "width", "height"],
|
|
7551
7645
|
});
|
|
7552
|
-
this.
|
|
7646
|
+
this.#resizeObserver.observe(element);
|
|
7553
7647
|
}
|
|
7554
7648
|
}
|
|
7555
|
-
const shapeOptions = this.options.shape, shapeGenerator = this.
|
|
7649
|
+
const shapeOptions = this.options.shape, shapeGenerator = this.#pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
7556
7650
|
if (shapeGenerator) {
|
|
7557
|
-
this
|
|
7651
|
+
this.#shape = shapeGenerator.generate(this.#container, this.position, this.size, this.fill, shapeOptions.options);
|
|
7558
7652
|
}
|
|
7559
|
-
this.
|
|
7653
|
+
this.#container.dispatchEvent("emitterCreated", {
|
|
7560
7654
|
emitter: this,
|
|
7561
7655
|
});
|
|
7562
7656
|
this.play();
|
|
7563
7657
|
}
|
|
7564
7658
|
externalPause() {
|
|
7565
|
-
this
|
|
7659
|
+
this.#paused = true;
|
|
7566
7660
|
this.pause();
|
|
7567
7661
|
}
|
|
7568
7662
|
externalPlay() {
|
|
7569
|
-
this
|
|
7663
|
+
this.#paused = false;
|
|
7570
7664
|
this.play();
|
|
7571
7665
|
}
|
|
7572
7666
|
async init() {
|
|
7573
|
-
await this
|
|
7667
|
+
await this.#shape?.init();
|
|
7574
7668
|
}
|
|
7575
7669
|
pause() {
|
|
7576
|
-
if (this
|
|
7670
|
+
if (this.#paused) {
|
|
7577
7671
|
return;
|
|
7578
7672
|
}
|
|
7579
|
-
|
|
7673
|
+
this.#emitDelay = undefined;
|
|
7580
7674
|
}
|
|
7581
7675
|
play() {
|
|
7582
|
-
if (this
|
|
7676
|
+
if (this.#paused) {
|
|
7583
7677
|
return;
|
|
7584
7678
|
}
|
|
7585
|
-
if (!((this
|
|
7586
|
-
(this
|
|
7679
|
+
if (!((this.#lifeCount > minLifeCount || this.#immortal || !this.options.life.count) &&
|
|
7680
|
+
(this.#firstSpawn || this.#currentSpawnDelay >= (this.#spawnDelay ?? defaultSpawnDelay)))) {
|
|
7587
7681
|
return;
|
|
7588
7682
|
}
|
|
7589
|
-
const container = this
|
|
7590
|
-
if (this
|
|
7683
|
+
const container = this.#container;
|
|
7684
|
+
if (this.#emitDelay === undefined) {
|
|
7591
7685
|
const delay = getRangeValue(this.options.rate.delay);
|
|
7592
|
-
this
|
|
7686
|
+
this.#emitDelay = container.retina.reduceFactor
|
|
7593
7687
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
7594
7688
|
: Infinity;
|
|
7595
7689
|
}
|
|
7596
|
-
if (this
|
|
7597
|
-
this
|
|
7690
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
7691
|
+
this.#prepareToDie();
|
|
7598
7692
|
}
|
|
7599
7693
|
}
|
|
7600
7694
|
resize() {
|
|
7601
|
-
const initialPosition = this
|
|
7695
|
+
const initialPosition = this.#initialPosition, container = this.#container;
|
|
7602
7696
|
this.position =
|
|
7603
7697
|
initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
|
|
7604
7698
|
? initialPosition
|
|
7605
|
-
: this
|
|
7606
|
-
this
|
|
7607
|
-
this.size = getSize(this
|
|
7608
|
-
this
|
|
7699
|
+
: this.#calcPosition();
|
|
7700
|
+
this.#size = this.#calcSize();
|
|
7701
|
+
this.size = getSize(this.#size, container.canvas.size);
|
|
7702
|
+
this.#shape?.resize(this.position, this.size);
|
|
7609
7703
|
}
|
|
7610
7704
|
update(delta) {
|
|
7611
|
-
if (this
|
|
7705
|
+
if (this.#paused) {
|
|
7612
7706
|
return;
|
|
7613
7707
|
}
|
|
7614
|
-
const container = this
|
|
7615
|
-
if (this
|
|
7616
|
-
this
|
|
7617
|
-
this
|
|
7618
|
-
this
|
|
7708
|
+
const container = this.#container;
|
|
7709
|
+
if (this.#firstSpawn) {
|
|
7710
|
+
this.#firstSpawn = false;
|
|
7711
|
+
this.#currentSpawnDelay = this.#spawnDelay ?? defaultSpawnDelay;
|
|
7712
|
+
this.#currentEmitDelay = this.#emitDelay ?? defaultEmitDelay;
|
|
7619
7713
|
}
|
|
7620
|
-
if (!this
|
|
7621
|
-
this
|
|
7622
|
-
this
|
|
7714
|
+
if (!this.#startParticlesAdded) {
|
|
7715
|
+
this.#startParticlesAdded = true;
|
|
7716
|
+
this.#emitParticles(this.options.startCount);
|
|
7623
7717
|
}
|
|
7624
|
-
if (this
|
|
7625
|
-
this
|
|
7626
|
-
if (this
|
|
7718
|
+
if (this.#duration !== undefined) {
|
|
7719
|
+
this.#currentDuration += delta.value;
|
|
7720
|
+
if (this.#currentDuration >= this.#duration) {
|
|
7627
7721
|
this.pause();
|
|
7628
|
-
if (this
|
|
7629
|
-
|
|
7722
|
+
if (this.#spawnDelay !== undefined) {
|
|
7723
|
+
this.#spawnDelay = undefined;
|
|
7630
7724
|
}
|
|
7631
|
-
if (!this
|
|
7632
|
-
this
|
|
7725
|
+
if (!this.#immortal) {
|
|
7726
|
+
this.#lifeCount--;
|
|
7633
7727
|
}
|
|
7634
|
-
if (this
|
|
7635
|
-
this.position = this
|
|
7636
|
-
this
|
|
7637
|
-
this
|
|
7728
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
7729
|
+
this.position = this.#calcPosition();
|
|
7730
|
+
this.#shape?.resize(this.position, this.size);
|
|
7731
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
7638
7732
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
7639
7733
|
container.retina.reduceFactor
|
|
7640
7734
|
: Infinity;
|
|
7641
7735
|
}
|
|
7642
7736
|
else {
|
|
7643
|
-
this
|
|
7737
|
+
this.#destroy();
|
|
7644
7738
|
}
|
|
7645
|
-
this
|
|
7646
|
-
|
|
7739
|
+
this.#currentDuration -= this.#duration;
|
|
7740
|
+
this.#duration = undefined;
|
|
7647
7741
|
}
|
|
7648
7742
|
}
|
|
7649
|
-
if (this
|
|
7650
|
-
this
|
|
7651
|
-
if (this
|
|
7652
|
-
this.
|
|
7743
|
+
if (this.#spawnDelay !== undefined) {
|
|
7744
|
+
this.#currentSpawnDelay += delta.value;
|
|
7745
|
+
if (this.#currentSpawnDelay >= this.#spawnDelay) {
|
|
7746
|
+
this.#container.dispatchEvent("emitterPlay");
|
|
7653
7747
|
this.play();
|
|
7654
|
-
this
|
|
7655
|
-
|
|
7748
|
+
this.#currentSpawnDelay -= this.#spawnDelay;
|
|
7749
|
+
this.#spawnDelay = undefined;
|
|
7656
7750
|
}
|
|
7657
7751
|
}
|
|
7658
|
-
if (this
|
|
7659
|
-
this
|
|
7660
|
-
if (this
|
|
7661
|
-
this
|
|
7662
|
-
this
|
|
7752
|
+
if (this.#emitDelay !== undefined) {
|
|
7753
|
+
this.#currentEmitDelay += delta.value;
|
|
7754
|
+
if (this.#currentEmitDelay >= this.#emitDelay) {
|
|
7755
|
+
this.#emit();
|
|
7756
|
+
this.#currentEmitDelay -= this.#emitDelay;
|
|
7663
7757
|
}
|
|
7664
7758
|
}
|
|
7665
7759
|
}
|
|
7666
|
-
|
|
7667
|
-
const container = this
|
|
7760
|
+
#calcPosition() {
|
|
7761
|
+
const container = this.#container;
|
|
7668
7762
|
if (this.options.domId) {
|
|
7669
7763
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7670
7764
|
if (element) {
|
|
@@ -7680,8 +7774,8 @@
|
|
|
7680
7774
|
position: this.options.position,
|
|
7681
7775
|
});
|
|
7682
7776
|
}
|
|
7683
|
-
|
|
7684
|
-
const container = this
|
|
7777
|
+
#calcSize() {
|
|
7778
|
+
const container = this.#container;
|
|
7685
7779
|
if (this.options.domId) {
|
|
7686
7780
|
const element = safeDocument().getElementById(this.options.domId);
|
|
7687
7781
|
if (element) {
|
|
@@ -7704,32 +7798,32 @@
|
|
|
7704
7798
|
return size;
|
|
7705
7799
|
})());
|
|
7706
7800
|
}
|
|
7707
|
-
|
|
7708
|
-
this
|
|
7709
|
-
this
|
|
7710
|
-
this
|
|
7711
|
-
this
|
|
7712
|
-
this
|
|
7713
|
-
this.
|
|
7801
|
+
#destroy = () => {
|
|
7802
|
+
this.#mutationObserver?.disconnect();
|
|
7803
|
+
this.#mutationObserver = undefined;
|
|
7804
|
+
this.#resizeObserver?.disconnect();
|
|
7805
|
+
this.#resizeObserver = undefined;
|
|
7806
|
+
this.#removeCallback(this);
|
|
7807
|
+
this.#container.dispatchEvent("emitterDestroyed", {
|
|
7714
7808
|
emitter: this,
|
|
7715
7809
|
});
|
|
7716
7810
|
};
|
|
7717
|
-
|
|
7718
|
-
if (this
|
|
7811
|
+
#emit() {
|
|
7812
|
+
if (this.#paused) {
|
|
7719
7813
|
return;
|
|
7720
7814
|
}
|
|
7721
7815
|
const quantity = getRangeValue(this.options.rate.quantity);
|
|
7722
|
-
this
|
|
7816
|
+
this.#emitParticles(quantity);
|
|
7723
7817
|
}
|
|
7724
|
-
|
|
7725
|
-
const singleParticlesOptions = (itemFromSingleOrMultiple(this
|
|
7818
|
+
#emitParticles(quantity) {
|
|
7819
|
+
const singleParticlesOptions = (itemFromSingleOrMultiple(this.#particlesOptions) ??
|
|
7726
7820
|
{}), 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
|
|
7727
7821
|
? defaultOpacity$1
|
|
7728
7822
|
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
7729
7823
|
? defaultOpacity$1
|
|
7730
7824
|
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
7731
7825
|
? defaultStrokeWidth
|
|
7732
|
-
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.
|
|
7826
|
+
: 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;
|
|
7733
7827
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
7734
7828
|
const particlesOptions = needsCopy
|
|
7735
7829
|
? deepExtend({}, singleParticlesOptions)
|
|
@@ -7740,23 +7834,23 @@
|
|
|
7740
7834
|
this.spawnStrokeWidth = strokeWidth;
|
|
7741
7835
|
if (this.spawnFillColor) {
|
|
7742
7836
|
if (fillHslAnimation && maxValues) {
|
|
7743
|
-
this.spawnFillColor.h = this
|
|
7744
|
-
this.spawnFillColor.s = this
|
|
7745
|
-
this.spawnFillColor.l = this
|
|
7837
|
+
this.spawnFillColor.h = this.#setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
7838
|
+
this.spawnFillColor.s = this.#setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
7839
|
+
this.spawnFillColor.l = this.#setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
7746
7840
|
}
|
|
7747
7841
|
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
7748
7842
|
}
|
|
7749
7843
|
if (this.spawnStrokeColor) {
|
|
7750
7844
|
if (strokeHslAnimation && maxValues) {
|
|
7751
|
-
this.spawnStrokeColor.h = this
|
|
7752
|
-
this.spawnStrokeColor.s = this
|
|
7753
|
-
this.spawnStrokeColor.l = this
|
|
7845
|
+
this.spawnStrokeColor.h = this.#setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
7846
|
+
this.spawnStrokeColor.s = this.#setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
7847
|
+
this.spawnStrokeColor.l = this.#setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
7754
7848
|
}
|
|
7755
7849
|
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
7756
7850
|
}
|
|
7757
7851
|
let position = this.position;
|
|
7758
|
-
if (this
|
|
7759
|
-
const shapePosData = this.
|
|
7852
|
+
if (this.#shape) {
|
|
7853
|
+
const shapePosData = this.#shape.randomPosition();
|
|
7760
7854
|
if (shapePosData) {
|
|
7761
7855
|
position = shapePosData.position;
|
|
7762
7856
|
const replaceData = shapeOptions.replace;
|
|
@@ -7769,21 +7863,21 @@
|
|
|
7769
7863
|
}
|
|
7770
7864
|
}
|
|
7771
7865
|
if (position) {
|
|
7772
|
-
this.
|
|
7866
|
+
this.#container.particles.addParticle(position, particlesOptions);
|
|
7773
7867
|
}
|
|
7774
7868
|
}
|
|
7775
7869
|
}
|
|
7776
|
-
|
|
7777
|
-
if (this
|
|
7870
|
+
#prepareToDie = () => {
|
|
7871
|
+
if (this.#paused) {
|
|
7778
7872
|
return;
|
|
7779
7873
|
}
|
|
7780
7874
|
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
7781
|
-
if ((this
|
|
7782
|
-
this
|
|
7875
|
+
if ((this.#lifeCount > minLifeCount || this.#immortal) && duration !== undefined && duration > minDuration) {
|
|
7876
|
+
this.#duration = duration * millisecondsToSeconds;
|
|
7783
7877
|
}
|
|
7784
7878
|
};
|
|
7785
|
-
|
|
7786
|
-
const container = this
|
|
7879
|
+
#setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
7880
|
+
const container = this.#container;
|
|
7787
7881
|
if (!animation.enable) {
|
|
7788
7882
|
return initValue;
|
|
7789
7883
|
}
|