@tsparticles/confetti 4.0.5 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/confetti.js +2 -2
- package/browser/confetti.lazy.js +2 -2
- package/cjs/confetti.js +2 -2
- package/cjs/confetti.lazy.js +2 -2
- package/esm/confetti.js +2 -2
- package/esm/confetti.lazy.js +2 -2
- package/package.json +17 -17
- package/report.html +1 -1
- package/tsparticles.confetti.bundle.js +1120 -1030
- package/tsparticles.confetti.bundle.min.js +1 -1
- package/tsparticles.confetti.js +3 -3
- package/tsparticles.confetti.min.js +1 -1
|
@@ -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
|
-
/* tsParticles v4.0
|
|
2
|
+
/* tsParticles 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
|
}
|
|
@@ -804,38 +804,38 @@
|
|
|
804
804
|
}
|
|
805
805
|
|
|
806
806
|
class EventDispatcher {
|
|
807
|
-
|
|
807
|
+
#listeners;
|
|
808
808
|
constructor() {
|
|
809
|
-
this
|
|
809
|
+
this.#listeners = new Map();
|
|
810
810
|
}
|
|
811
811
|
addEventListener(type, listener) {
|
|
812
812
|
this.removeEventListener(type, listener);
|
|
813
|
-
let arr = this.
|
|
813
|
+
let arr = this.#listeners.get(type);
|
|
814
814
|
if (!arr) {
|
|
815
815
|
arr = [];
|
|
816
|
-
this.
|
|
816
|
+
this.#listeners.set(type, arr);
|
|
817
817
|
}
|
|
818
818
|
arr.push(listener);
|
|
819
819
|
}
|
|
820
820
|
dispatchEvent(type, args) {
|
|
821
|
-
const listeners = this.
|
|
821
|
+
const listeners = this.#listeners.get(type);
|
|
822
822
|
listeners?.forEach(handler => {
|
|
823
823
|
handler(args);
|
|
824
824
|
});
|
|
825
825
|
}
|
|
826
826
|
hasEventListener(type) {
|
|
827
|
-
return !!this.
|
|
827
|
+
return !!this.#listeners.get(type);
|
|
828
828
|
}
|
|
829
829
|
removeAllEventListeners(type) {
|
|
830
830
|
if (!type) {
|
|
831
|
-
this
|
|
831
|
+
this.#listeners = new Map();
|
|
832
832
|
}
|
|
833
833
|
else {
|
|
834
|
-
this.
|
|
834
|
+
this.#listeners.delete(type);
|
|
835
835
|
}
|
|
836
836
|
}
|
|
837
837
|
removeEventListener(type, listener) {
|
|
838
|
-
const arr = this.
|
|
838
|
+
const arr = this.#listeners.get(type);
|
|
839
839
|
if (!arr) {
|
|
840
840
|
return;
|
|
841
841
|
}
|
|
@@ -844,7 +844,7 @@
|
|
|
844
844
|
return;
|
|
845
845
|
}
|
|
846
846
|
if (length === deleteCount) {
|
|
847
|
-
this.
|
|
847
|
+
this.#listeners.delete(type);
|
|
848
848
|
}
|
|
849
849
|
else {
|
|
850
850
|
arr.splice(idx, deleteCount);
|
|
@@ -882,19 +882,19 @@
|
|
|
882
882
|
presets = new Map();
|
|
883
883
|
shapeDrawers = new Map();
|
|
884
884
|
updaters = new Map();
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
885
|
+
#allLoadersSet = new Set();
|
|
886
|
+
#configs = new Map();
|
|
887
|
+
#engine;
|
|
888
|
+
#executedSet = new Set();
|
|
889
|
+
#initialized = false;
|
|
890
|
+
#isRunningLoaders = false;
|
|
891
|
+
#loadPromises = new Set();
|
|
892
892
|
constructor(engine) {
|
|
893
|
-
this
|
|
893
|
+
this.#engine = engine;
|
|
894
894
|
}
|
|
895
895
|
get configs() {
|
|
896
896
|
const res = {};
|
|
897
|
-
for (const [name, config] of this
|
|
897
|
+
for (const [name, config] of this.#configs) {
|
|
898
898
|
res[name] = config;
|
|
899
899
|
}
|
|
900
900
|
return res;
|
|
@@ -904,8 +904,8 @@
|
|
|
904
904
|
}
|
|
905
905
|
addConfig(config) {
|
|
906
906
|
const key = config.key ?? config.name ?? "default";
|
|
907
|
-
this.
|
|
908
|
-
this.
|
|
907
|
+
this.#configs.set(key, config);
|
|
908
|
+
this.#engine.dispatchEvent(exports.EventType.configAdded, { data: { name: key, config } });
|
|
909
909
|
}
|
|
910
910
|
addEasing(name, easing) {
|
|
911
911
|
if (this.easingFunctions.get(name)) {
|
|
@@ -966,21 +966,21 @@
|
|
|
966
966
|
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
967
967
|
}
|
|
968
968
|
async init() {
|
|
969
|
-
if (this
|
|
969
|
+
if (this.#initialized || this.#isRunningLoaders) {
|
|
970
970
|
return;
|
|
971
971
|
}
|
|
972
|
-
this
|
|
973
|
-
this
|
|
974
|
-
this
|
|
972
|
+
this.#isRunningLoaders = true;
|
|
973
|
+
this.#executedSet = new Set();
|
|
974
|
+
this.#allLoadersSet = new Set(this.#loadPromises);
|
|
975
975
|
try {
|
|
976
|
-
for (const loader of this
|
|
977
|
-
await this
|
|
976
|
+
for (const loader of this.#allLoadersSet) {
|
|
977
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
finally {
|
|
981
|
-
this.
|
|
982
|
-
this
|
|
983
|
-
this
|
|
981
|
+
this.#loadPromises.clear();
|
|
982
|
+
this.#isRunningLoaders = false;
|
|
983
|
+
this.#initialized = true;
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
986
|
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
@@ -991,24 +991,24 @@
|
|
|
991
991
|
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
992
992
|
}
|
|
993
993
|
async register(...loaders) {
|
|
994
|
-
if (this
|
|
994
|
+
if (this.#initialized) {
|
|
995
995
|
throw new Error("Register plugins can only be done before calling tsParticles.load()");
|
|
996
996
|
}
|
|
997
997
|
for (const loader of loaders) {
|
|
998
|
-
if (this
|
|
999
|
-
await this
|
|
998
|
+
if (this.#isRunningLoaders) {
|
|
999
|
+
await this.#runLoader(loader, this.#executedSet, this.#allLoadersSet);
|
|
1000
1000
|
}
|
|
1001
1001
|
else {
|
|
1002
|
-
this.
|
|
1002
|
+
this.#loadPromises.add(loader);
|
|
1003
1003
|
}
|
|
1004
1004
|
}
|
|
1005
1005
|
}
|
|
1006
|
-
async
|
|
1006
|
+
async #runLoader(loader, executed, allLoaders) {
|
|
1007
1007
|
if (executed.has(loader))
|
|
1008
1008
|
return;
|
|
1009
1009
|
executed.add(loader);
|
|
1010
1010
|
allLoaders.add(loader);
|
|
1011
|
-
await loader(this
|
|
1011
|
+
await loader(this.#engine);
|
|
1012
1012
|
}
|
|
1013
1013
|
}
|
|
1014
1014
|
|
|
@@ -1111,17 +1111,17 @@
|
|
|
1111
1111
|
};
|
|
1112
1112
|
class Engine {
|
|
1113
1113
|
pluginManager = new PluginManager(this);
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1114
|
+
#domArray = [];
|
|
1115
|
+
#eventDispatcher = new EventDispatcher();
|
|
1116
|
+
#initialized = false;
|
|
1117
1117
|
get items() {
|
|
1118
|
-
return this
|
|
1118
|
+
return this.#domArray;
|
|
1119
1119
|
}
|
|
1120
1120
|
get version() {
|
|
1121
|
-
return "4.0
|
|
1121
|
+
return "4.1.0";
|
|
1122
1122
|
}
|
|
1123
1123
|
addEventListener(type, listener) {
|
|
1124
|
-
this.
|
|
1124
|
+
this.#eventDispatcher.addEventListener(type, listener);
|
|
1125
1125
|
}
|
|
1126
1126
|
checkVersion(pluginVersion) {
|
|
1127
1127
|
if (this.version === pluginVersion) {
|
|
@@ -1130,17 +1130,17 @@
|
|
|
1130
1130
|
throw new Error(`The tsParticles version is different from the loaded plugins version. Engine version: ${this.version}. Plugin version: ${pluginVersion}`);
|
|
1131
1131
|
}
|
|
1132
1132
|
dispatchEvent(type, args) {
|
|
1133
|
-
this.
|
|
1133
|
+
this.#eventDispatcher.dispatchEvent(type, args);
|
|
1134
1134
|
}
|
|
1135
1135
|
async init() {
|
|
1136
|
-
if (this
|
|
1136
|
+
if (this.#initialized) {
|
|
1137
1137
|
return;
|
|
1138
1138
|
}
|
|
1139
1139
|
await this.pluginManager.init();
|
|
1140
|
-
this
|
|
1140
|
+
this.#initialized = true;
|
|
1141
1141
|
}
|
|
1142
1142
|
item(index) {
|
|
1143
|
-
const
|
|
1143
|
+
const items = this.items, item = items[index];
|
|
1144
1144
|
if (item?.destroyed) {
|
|
1145
1145
|
items.splice(index, removeDeleteCount);
|
|
1146
1146
|
return;
|
|
@@ -1194,7 +1194,7 @@
|
|
|
1194
1194
|
await Promise.all(this.items.map(t => t.refresh()));
|
|
1195
1195
|
}
|
|
1196
1196
|
removeEventListener(type, listener) {
|
|
1197
|
-
this.
|
|
1197
|
+
this.#eventDispatcher.removeEventListener(type, listener);
|
|
1198
1198
|
}
|
|
1199
1199
|
}
|
|
1200
1200
|
|
|
@@ -1965,43 +1965,6 @@
|
|
|
1965
1965
|
}
|
|
1966
1966
|
}
|
|
1967
1967
|
|
|
1968
|
-
class OpacityAnimation extends RangedAnimationOptions {
|
|
1969
|
-
destroy;
|
|
1970
|
-
constructor() {
|
|
1971
|
-
super();
|
|
1972
|
-
this.destroy = exports.DestroyType.none;
|
|
1973
|
-
this.speed = 2;
|
|
1974
|
-
}
|
|
1975
|
-
load(data) {
|
|
1976
|
-
super.load(data);
|
|
1977
|
-
if (isNull(data)) {
|
|
1978
|
-
return;
|
|
1979
|
-
}
|
|
1980
|
-
if (data.destroy !== undefined) {
|
|
1981
|
-
this.destroy = data.destroy;
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
}
|
|
1985
|
-
|
|
1986
|
-
class Opacity extends RangedAnimationValueWithRandom {
|
|
1987
|
-
animation;
|
|
1988
|
-
constructor() {
|
|
1989
|
-
super();
|
|
1990
|
-
this.animation = new OpacityAnimation();
|
|
1991
|
-
this.value = 1;
|
|
1992
|
-
}
|
|
1993
|
-
load(data) {
|
|
1994
|
-
if (isNull(data)) {
|
|
1995
|
-
return;
|
|
1996
|
-
}
|
|
1997
|
-
super.load(data);
|
|
1998
|
-
const animation = data.animation;
|
|
1999
|
-
if (animation !== undefined) {
|
|
2000
|
-
this.animation.load(animation);
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
|
|
2005
1968
|
class Stroke {
|
|
2006
1969
|
color;
|
|
2007
1970
|
opacity;
|
|
@@ -2169,43 +2132,6 @@
|
|
|
2169
2132
|
}
|
|
2170
2133
|
}
|
|
2171
2134
|
|
|
2172
|
-
class SizeAnimation extends RangedAnimationOptions {
|
|
2173
|
-
destroy;
|
|
2174
|
-
constructor() {
|
|
2175
|
-
super();
|
|
2176
|
-
this.destroy = exports.DestroyType.none;
|
|
2177
|
-
this.speed = 5;
|
|
2178
|
-
}
|
|
2179
|
-
load(data) {
|
|
2180
|
-
super.load(data);
|
|
2181
|
-
if (isNull(data)) {
|
|
2182
|
-
return;
|
|
2183
|
-
}
|
|
2184
|
-
if (data.destroy !== undefined) {
|
|
2185
|
-
this.destroy = data.destroy;
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
|
|
2190
|
-
class Size extends RangedAnimationValueWithRandom {
|
|
2191
|
-
animation;
|
|
2192
|
-
constructor() {
|
|
2193
|
-
super();
|
|
2194
|
-
this.animation = new SizeAnimation();
|
|
2195
|
-
this.value = 3;
|
|
2196
|
-
}
|
|
2197
|
-
load(data) {
|
|
2198
|
-
super.load(data);
|
|
2199
|
-
if (isNull(data)) {
|
|
2200
|
-
return;
|
|
2201
|
-
}
|
|
2202
|
-
const animation = data.animation;
|
|
2203
|
-
if (animation !== undefined) {
|
|
2204
|
-
this.animation.load(animation);
|
|
2205
|
-
}
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
|
|
2209
2135
|
class ZIndex extends ValueWithRandom {
|
|
2210
2136
|
opacityRate;
|
|
2211
2137
|
sizeRate;
|
|
@@ -2239,24 +2165,21 @@
|
|
|
2239
2165
|
groups;
|
|
2240
2166
|
move;
|
|
2241
2167
|
number;
|
|
2242
|
-
opacity;
|
|
2243
2168
|
paint;
|
|
2244
2169
|
palette;
|
|
2245
2170
|
reduceDuplicates;
|
|
2246
2171
|
shape;
|
|
2247
|
-
size;
|
|
2248
2172
|
zIndex;
|
|
2249
|
-
|
|
2250
|
-
|
|
2173
|
+
#container;
|
|
2174
|
+
#pluginManager;
|
|
2251
2175
|
constructor(pluginManager, container) {
|
|
2252
|
-
this
|
|
2253
|
-
this
|
|
2176
|
+
this.#pluginManager = pluginManager;
|
|
2177
|
+
this.#container = container;
|
|
2254
2178
|
this.bounce = new ParticlesBounce();
|
|
2255
2179
|
this.effect = new Effect();
|
|
2256
2180
|
this.groups = {};
|
|
2257
2181
|
this.move = new Move();
|
|
2258
2182
|
this.number = new ParticlesNumber();
|
|
2259
|
-
this.opacity = new Opacity();
|
|
2260
2183
|
this.paint = new Paint();
|
|
2261
2184
|
this.paint.color = new AnimatableColor();
|
|
2262
2185
|
this.paint.color.value = "#fff";
|
|
@@ -2264,7 +2187,6 @@
|
|
|
2264
2187
|
this.paint.fill.enable = true;
|
|
2265
2188
|
this.reduceDuplicates = false;
|
|
2266
2189
|
this.shape = new Shape();
|
|
2267
|
-
this.size = new Size();
|
|
2268
2190
|
this.zIndex = new ZIndex();
|
|
2269
2191
|
}
|
|
2270
2192
|
load(data) {
|
|
@@ -2273,7 +2195,7 @@
|
|
|
2273
2195
|
}
|
|
2274
2196
|
if (data.palette) {
|
|
2275
2197
|
this.palette = data.palette;
|
|
2276
|
-
this
|
|
2198
|
+
this.#importPalette(this.palette);
|
|
2277
2199
|
}
|
|
2278
2200
|
if (data.groups !== undefined) {
|
|
2279
2201
|
for (const group of Object.keys(data.groups)) {
|
|
@@ -2293,7 +2215,6 @@
|
|
|
2293
2215
|
this.effect.load(data.effect);
|
|
2294
2216
|
this.move.load(data.move);
|
|
2295
2217
|
this.number.load(data.number);
|
|
2296
|
-
this.opacity.load(data.opacity);
|
|
2297
2218
|
const paintToLoad = data.paint;
|
|
2298
2219
|
if (paintToLoad) {
|
|
2299
2220
|
if (isArray(paintToLoad)) {
|
|
@@ -2312,15 +2233,14 @@
|
|
|
2312
2233
|
}
|
|
2313
2234
|
}
|
|
2314
2235
|
this.shape.load(data.shape);
|
|
2315
|
-
this.size.load(data.size);
|
|
2316
2236
|
this.zIndex.load(data.zIndex);
|
|
2317
|
-
if (this
|
|
2318
|
-
for (const plugin of this.
|
|
2237
|
+
if (this.#container) {
|
|
2238
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
2319
2239
|
if (plugin.loadParticlesOptions) {
|
|
2320
|
-
plugin.loadParticlesOptions(this
|
|
2240
|
+
plugin.loadParticlesOptions(this.#container, this, data);
|
|
2321
2241
|
}
|
|
2322
2242
|
}
|
|
2323
|
-
const updaters = this.
|
|
2243
|
+
const updaters = this.#pluginManager.updaters.get(this.#container);
|
|
2324
2244
|
if (updaters) {
|
|
2325
2245
|
for (const updater of updaters) {
|
|
2326
2246
|
if (updater.loadOptions) {
|
|
@@ -2330,8 +2250,8 @@
|
|
|
2330
2250
|
}
|
|
2331
2251
|
}
|
|
2332
2252
|
}
|
|
2333
|
-
|
|
2334
|
-
const paletteData = this.
|
|
2253
|
+
#importPalette = (palette) => {
|
|
2254
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2335
2255
|
if (!paletteData) {
|
|
2336
2256
|
return;
|
|
2337
2257
|
}
|
|
@@ -2410,11 +2330,11 @@
|
|
|
2410
2330
|
smooth;
|
|
2411
2331
|
style;
|
|
2412
2332
|
zLayers;
|
|
2413
|
-
|
|
2414
|
-
|
|
2333
|
+
#container;
|
|
2334
|
+
#pluginManager;
|
|
2415
2335
|
constructor(pluginManager, container) {
|
|
2416
|
-
this
|
|
2417
|
-
this
|
|
2336
|
+
this.#pluginManager = pluginManager;
|
|
2337
|
+
this.#container = container;
|
|
2418
2338
|
this.autoPlay = true;
|
|
2419
2339
|
this.background = new Background();
|
|
2420
2340
|
this.clear = true;
|
|
@@ -2425,7 +2345,7 @@
|
|
|
2425
2345
|
this.duration = 0;
|
|
2426
2346
|
this.fpsLimit = 120;
|
|
2427
2347
|
this.hdr = true;
|
|
2428
|
-
this.particles = loadParticlesOptions(this
|
|
2348
|
+
this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
|
|
2429
2349
|
this.pauseOnBlur = true;
|
|
2430
2350
|
this.pauseOnOutsideViewport = true;
|
|
2431
2351
|
this.resize = new ResizeEvent();
|
|
@@ -2440,12 +2360,12 @@
|
|
|
2440
2360
|
if (data.preset !== undefined) {
|
|
2441
2361
|
this.preset = data.preset;
|
|
2442
2362
|
executeOnSingleOrMultiple(this.preset, preset => {
|
|
2443
|
-
this
|
|
2363
|
+
this.#importPreset(preset);
|
|
2444
2364
|
});
|
|
2445
2365
|
}
|
|
2446
2366
|
if (data.palette !== undefined) {
|
|
2447
2367
|
this.palette = data.palette;
|
|
2448
|
-
this
|
|
2368
|
+
this.#importPalette(this.palette);
|
|
2449
2369
|
}
|
|
2450
2370
|
if (data.autoPlay !== undefined) {
|
|
2451
2371
|
this.autoPlay = data.autoPlay;
|
|
@@ -2499,12 +2419,12 @@
|
|
|
2499
2419
|
if (data.smooth !== undefined) {
|
|
2500
2420
|
this.smooth = data.smooth;
|
|
2501
2421
|
}
|
|
2502
|
-
this.
|
|
2503
|
-
plugin.loadOptions(this
|
|
2422
|
+
this.#pluginManager.plugins.forEach(plugin => {
|
|
2423
|
+
plugin.loadOptions(this.#container, this, data);
|
|
2504
2424
|
});
|
|
2505
2425
|
}
|
|
2506
|
-
|
|
2507
|
-
const paletteData = this.
|
|
2426
|
+
#importPalette = palette => {
|
|
2427
|
+
const paletteData = this.#pluginManager.getPalette(palette);
|
|
2508
2428
|
if (!paletteData) {
|
|
2509
2429
|
return;
|
|
2510
2430
|
}
|
|
@@ -2521,8 +2441,8 @@
|
|
|
2521
2441
|
},
|
|
2522
2442
|
});
|
|
2523
2443
|
};
|
|
2524
|
-
|
|
2525
|
-
this.load(this.
|
|
2444
|
+
#importPreset = preset => {
|
|
2445
|
+
this.load(this.#pluginManager.getPreset(preset));
|
|
2526
2446
|
};
|
|
2527
2447
|
}
|
|
2528
2448
|
|
|
@@ -3055,7 +2975,7 @@
|
|
|
3055
2975
|
}
|
|
3056
2976
|
|
|
3057
2977
|
async function loadBlendPlugin(engine) {
|
|
3058
|
-
engine.checkVersion("4.0
|
|
2978
|
+
engine.checkVersion("4.1.0");
|
|
3059
2979
|
await engine.pluginManager.register(e => {
|
|
3060
2980
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
3061
2981
|
});
|
|
@@ -3092,7 +3012,7 @@
|
|
|
3092
3012
|
}
|
|
3093
3013
|
|
|
3094
3014
|
async function loadCircleShape(engine) {
|
|
3095
|
-
engine.checkVersion("4.0
|
|
3015
|
+
engine.checkVersion("4.1.0");
|
|
3096
3016
|
await engine.pluginManager.register(e => {
|
|
3097
3017
|
e.pluginManager.addShape(["circle"], () => {
|
|
3098
3018
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -3113,15 +3033,15 @@
|
|
|
3113
3033
|
return input.startsWith("#");
|
|
3114
3034
|
}
|
|
3115
3035
|
handleColor(color) {
|
|
3116
|
-
return this
|
|
3036
|
+
return this.#parseString(color.value);
|
|
3117
3037
|
}
|
|
3118
3038
|
handleRangeColor(color) {
|
|
3119
|
-
return this
|
|
3039
|
+
return this.#parseString(color.value);
|
|
3120
3040
|
}
|
|
3121
3041
|
parseString(input) {
|
|
3122
|
-
return this
|
|
3042
|
+
return this.#parseString(input);
|
|
3123
3043
|
}
|
|
3124
|
-
|
|
3044
|
+
#parseString(hexColor) {
|
|
3125
3045
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
3126
3046
|
return;
|
|
3127
3047
|
}
|
|
@@ -3140,7 +3060,7 @@
|
|
|
3140
3060
|
}
|
|
3141
3061
|
|
|
3142
3062
|
async function loadHexColorPlugin(engine) {
|
|
3143
|
-
engine.checkVersion("4.0
|
|
3063
|
+
engine.checkVersion("4.1.0");
|
|
3144
3064
|
await engine.pluginManager.register(e => {
|
|
3145
3065
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
3146
3066
|
});
|
|
@@ -3193,7 +3113,7 @@
|
|
|
3193
3113
|
}
|
|
3194
3114
|
|
|
3195
3115
|
async function loadHslColorPlugin(engine) {
|
|
3196
|
-
engine.checkVersion("4.0
|
|
3116
|
+
engine.checkVersion("4.1.0");
|
|
3197
3117
|
await engine.pluginManager.register(e => {
|
|
3198
3118
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3199
3119
|
});
|
|
@@ -3201,13 +3121,13 @@
|
|
|
3201
3121
|
|
|
3202
3122
|
class MovePlugin {
|
|
3203
3123
|
id = "move";
|
|
3204
|
-
|
|
3124
|
+
#pluginManager;
|
|
3205
3125
|
constructor(pluginManager) {
|
|
3206
|
-
this
|
|
3126
|
+
this.#pluginManager = pluginManager;
|
|
3207
3127
|
}
|
|
3208
3128
|
async getPlugin(container) {
|
|
3209
3129
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3210
|
-
return new MovePluginInstance(this
|
|
3130
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3211
3131
|
}
|
|
3212
3132
|
loadOptions() {
|
|
3213
3133
|
}
|
|
@@ -3217,7 +3137,7 @@
|
|
|
3217
3137
|
}
|
|
3218
3138
|
|
|
3219
3139
|
async function loadMovePlugin(engine) {
|
|
3220
|
-
engine.checkVersion("4.0
|
|
3140
|
+
engine.checkVersion("4.1.0");
|
|
3221
3141
|
await engine.pluginManager.register(e => {
|
|
3222
3142
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3223
3143
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3235,18 +3155,58 @@
|
|
|
3235
3155
|
});
|
|
3236
3156
|
}
|
|
3237
3157
|
|
|
3158
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
3159
|
+
destroy;
|
|
3160
|
+
constructor() {
|
|
3161
|
+
super();
|
|
3162
|
+
this.destroy = exports.DestroyType.none;
|
|
3163
|
+
this.speed = 2;
|
|
3164
|
+
}
|
|
3165
|
+
load(data) {
|
|
3166
|
+
super.load(data);
|
|
3167
|
+
if (isNull(data)) {
|
|
3168
|
+
return;
|
|
3169
|
+
}
|
|
3170
|
+
if (data.destroy !== undefined) {
|
|
3171
|
+
this.destroy = data.destroy;
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
3177
|
+
animation;
|
|
3178
|
+
constructor() {
|
|
3179
|
+
super();
|
|
3180
|
+
this.animation = new OpacityAnimation();
|
|
3181
|
+
this.value = 1;
|
|
3182
|
+
}
|
|
3183
|
+
load(data) {
|
|
3184
|
+
if (isNull(data)) {
|
|
3185
|
+
return;
|
|
3186
|
+
}
|
|
3187
|
+
super.load(data);
|
|
3188
|
+
const animation = data.animation;
|
|
3189
|
+
if (animation !== undefined) {
|
|
3190
|
+
this.animation.load(animation);
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3238
3195
|
class OpacityUpdater {
|
|
3239
|
-
container;
|
|
3196
|
+
#container;
|
|
3240
3197
|
constructor(container) {
|
|
3241
|
-
this
|
|
3198
|
+
this.#container = container;
|
|
3242
3199
|
}
|
|
3243
3200
|
init(particle) {
|
|
3244
3201
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3202
|
+
if (!opacityOptions) {
|
|
3203
|
+
return;
|
|
3204
|
+
}
|
|
3245
3205
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3246
3206
|
const opacityAnimation = opacityOptions.animation;
|
|
3247
3207
|
if (opacityAnimation.enable) {
|
|
3248
3208
|
particle.opacity.velocity =
|
|
3249
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3209
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3250
3210
|
if (!opacityAnimation.sync) {
|
|
3251
3211
|
particle.opacity.velocity *= getRandom();
|
|
3252
3212
|
}
|
|
@@ -3262,6 +3222,12 @@
|
|
|
3262
3222
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3263
3223
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3264
3224
|
}
|
|
3225
|
+
loadOptions(options, ...sources) {
|
|
3226
|
+
options.opacity ??= new Opacity();
|
|
3227
|
+
for (const source of sources) {
|
|
3228
|
+
options.opacity.load(source?.opacity);
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3265
3231
|
reset(particle) {
|
|
3266
3232
|
if (!particle.opacity) {
|
|
3267
3233
|
return;
|
|
@@ -3270,7 +3236,7 @@
|
|
|
3270
3236
|
particle.opacity.loops = 0;
|
|
3271
3237
|
}
|
|
3272
3238
|
update(particle, delta) {
|
|
3273
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3239
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3274
3240
|
return;
|
|
3275
3241
|
}
|
|
3276
3242
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3278,7 +3244,7 @@
|
|
|
3278
3244
|
}
|
|
3279
3245
|
|
|
3280
3246
|
async function loadOpacityUpdater(engine) {
|
|
3281
|
-
engine.checkVersion("4.0
|
|
3247
|
+
engine.checkVersion("4.1.0");
|
|
3282
3248
|
await engine.pluginManager.register(e => {
|
|
3283
3249
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3284
3250
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3300,10 +3266,9 @@
|
|
|
3300
3266
|
}
|
|
3301
3267
|
const velocity = data.particle.velocity.x;
|
|
3302
3268
|
let bounced = false;
|
|
3303
|
-
if (
|
|
3304
|
-
data.
|
|
3305
|
-
|
|
3306
|
-
(data.direction === exports.OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3269
|
+
if (data.outOfCanvas &&
|
|
3270
|
+
((data.direction === exports.OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3271
|
+
(data.direction === exports.OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3307
3272
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3308
3273
|
data.particle.velocity.x *= -newVelocity;
|
|
3309
3274
|
bounced = true;
|
|
@@ -3312,10 +3277,10 @@
|
|
|
3312
3277
|
return;
|
|
3313
3278
|
}
|
|
3314
3279
|
const minPos = data.offset.x + data.size;
|
|
3315
|
-
if (data.
|
|
3280
|
+
if (data.outOfCanvas && data.direction === exports.OutModeDirection.right) {
|
|
3316
3281
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3317
3282
|
}
|
|
3318
|
-
else if (data.
|
|
3283
|
+
else if (data.outOfCanvas && data.direction === exports.OutModeDirection.left) {
|
|
3319
3284
|
data.particle.position.x = minPos;
|
|
3320
3285
|
}
|
|
3321
3286
|
if (data.outMode === exports.OutMode.split) {
|
|
@@ -3335,10 +3300,9 @@
|
|
|
3335
3300
|
}
|
|
3336
3301
|
const velocity = data.particle.velocity.y;
|
|
3337
3302
|
let bounced = false;
|
|
3338
|
-
if (
|
|
3339
|
-
data.
|
|
3340
|
-
|
|
3341
|
-
(data.direction === exports.OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3303
|
+
if (data.outOfCanvas &&
|
|
3304
|
+
((data.direction === exports.OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3305
|
+
(data.direction === exports.OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3342
3306
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3343
3307
|
data.particle.velocity.y *= -newVelocity;
|
|
3344
3308
|
bounced = true;
|
|
@@ -3347,10 +3311,10 @@
|
|
|
3347
3311
|
return;
|
|
3348
3312
|
}
|
|
3349
3313
|
const minPos = data.offset.y + data.size;
|
|
3350
|
-
if (data.
|
|
3314
|
+
if (data.outOfCanvas && data.direction === exports.OutModeDirection.bottom) {
|
|
3351
3315
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3352
3316
|
}
|
|
3353
|
-
else if (data.
|
|
3317
|
+
else if (data.outOfCanvas && data.direction === exports.OutModeDirection.top) {
|
|
3354
3318
|
data.particle.position.y = minPos;
|
|
3355
3319
|
}
|
|
3356
3320
|
if (data.outMode === exports.OutMode.split) {
|
|
@@ -3359,24 +3323,24 @@
|
|
|
3359
3323
|
}
|
|
3360
3324
|
|
|
3361
3325
|
class BounceOutMode {
|
|
3362
|
-
container;
|
|
3363
3326
|
modes;
|
|
3364
|
-
|
|
3327
|
+
#container;
|
|
3328
|
+
#particleBouncePlugins;
|
|
3365
3329
|
constructor(container) {
|
|
3366
|
-
this
|
|
3330
|
+
this.#container = container;
|
|
3367
3331
|
this.modes = [
|
|
3368
3332
|
exports.OutMode.bounce,
|
|
3369
3333
|
exports.OutMode.split,
|
|
3370
3334
|
];
|
|
3371
|
-
this
|
|
3335
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3372
3336
|
}
|
|
3373
3337
|
update(particle, direction, delta, outMode) {
|
|
3374
3338
|
if (!this.modes.includes(outMode)) {
|
|
3375
3339
|
return;
|
|
3376
3340
|
}
|
|
3377
|
-
const container = this
|
|
3341
|
+
const container = this.#container;
|
|
3378
3342
|
let handled = false;
|
|
3379
|
-
for (const plugin of this
|
|
3343
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3380
3344
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3381
3345
|
if (handled) {
|
|
3382
3346
|
break;
|
|
@@ -3385,29 +3349,26 @@
|
|
|
3385
3349
|
if (handled) {
|
|
3386
3350
|
return;
|
|
3387
3351
|
}
|
|
3388
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3389
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3390
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3352
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3353
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3354
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3391
3355
|
}
|
|
3392
3356
|
}
|
|
3393
3357
|
|
|
3394
3358
|
const minVelocity$3 = 0;
|
|
3395
3359
|
class DestroyOutMode {
|
|
3396
|
-
container;
|
|
3397
3360
|
modes;
|
|
3398
|
-
constructor(
|
|
3399
|
-
this.container = container;
|
|
3361
|
+
constructor(_container) {
|
|
3400
3362
|
this.modes = [exports.OutMode.destroy];
|
|
3401
3363
|
}
|
|
3402
3364
|
update(particle, direction, _delta, outMode) {
|
|
3403
3365
|
if (!this.modes.includes(outMode)) {
|
|
3404
3366
|
return;
|
|
3405
3367
|
}
|
|
3406
|
-
const container = this.container;
|
|
3407
3368
|
switch (particle.outType) {
|
|
3408
3369
|
case exports.ParticleOutType.normal:
|
|
3409
3370
|
case exports.ParticleOutType.outside:
|
|
3410
|
-
if (
|
|
3371
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3411
3372
|
return;
|
|
3412
3373
|
}
|
|
3413
3374
|
break;
|
|
@@ -3428,10 +3389,10 @@
|
|
|
3428
3389
|
|
|
3429
3390
|
const minVelocity$2 = 0;
|
|
3430
3391
|
class NoneOutMode {
|
|
3431
|
-
container;
|
|
3432
3392
|
modes;
|
|
3393
|
+
#container;
|
|
3433
3394
|
constructor(container) {
|
|
3434
|
-
this
|
|
3395
|
+
this.#container = container;
|
|
3435
3396
|
this.modes = [exports.OutMode.none];
|
|
3436
3397
|
}
|
|
3437
3398
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3444,7 +3405,7 @@
|
|
|
3444
3405
|
(direction === exports.OutModeDirection.top || direction === exports.OutModeDirection.bottom))) {
|
|
3445
3406
|
return;
|
|
3446
3407
|
}
|
|
3447
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3408
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3448
3409
|
if (!gravityOptions.enable) {
|
|
3449
3410
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3450
3411
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3470,17 +3431,17 @@
|
|
|
3470
3431
|
|
|
3471
3432
|
const minVelocity$1 = 0, minDistance = 0, updateVector = Vector.origin;
|
|
3472
3433
|
class OutOutMode {
|
|
3473
|
-
container;
|
|
3474
3434
|
modes;
|
|
3435
|
+
#container;
|
|
3475
3436
|
constructor(container) {
|
|
3476
|
-
this
|
|
3437
|
+
this.#container = container;
|
|
3477
3438
|
this.modes = [exports.OutMode.out];
|
|
3478
3439
|
}
|
|
3479
3440
|
update(particle, direction, _delta, outMode) {
|
|
3480
3441
|
if (!this.modes.includes(outMode)) {
|
|
3481
3442
|
return;
|
|
3482
3443
|
}
|
|
3483
|
-
const container = this
|
|
3444
|
+
const container = this.#container;
|
|
3484
3445
|
switch (particle.outType) {
|
|
3485
3446
|
case exports.ParticleOutType.inside: {
|
|
3486
3447
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3510,7 +3471,7 @@
|
|
|
3510
3471
|
break;
|
|
3511
3472
|
}
|
|
3512
3473
|
default: {
|
|
3513
|
-
if (
|
|
3474
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3514
3475
|
return;
|
|
3515
3476
|
}
|
|
3516
3477
|
switch (particle.outType) {
|
|
@@ -3594,16 +3555,16 @@
|
|
|
3594
3555
|
};
|
|
3595
3556
|
class OutOfCanvasUpdater {
|
|
3596
3557
|
updaters;
|
|
3597
|
-
container;
|
|
3558
|
+
#container;
|
|
3598
3559
|
constructor(container) {
|
|
3599
|
-
this
|
|
3560
|
+
this.#container = container;
|
|
3600
3561
|
this.updaters = new Map();
|
|
3601
3562
|
}
|
|
3602
3563
|
init(particle) {
|
|
3603
|
-
this
|
|
3604
|
-
this
|
|
3605
|
-
this
|
|
3606
|
-
this
|
|
3564
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.bounce, container => new BounceOutMode(container));
|
|
3565
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.out, container => new OutOutMode(container));
|
|
3566
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.destroy, container => new DestroyOutMode(container));
|
|
3567
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.none, container => new NoneOutMode(container));
|
|
3607
3568
|
}
|
|
3608
3569
|
isEnabled(particle) {
|
|
3609
3570
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3611,18 +3572,18 @@
|
|
|
3611
3572
|
update(particle, delta) {
|
|
3612
3573
|
const outModes = particle.options.move.outModes;
|
|
3613
3574
|
particle.justWarped = false;
|
|
3614
|
-
this
|
|
3615
|
-
this
|
|
3616
|
-
this
|
|
3617
|
-
this
|
|
3575
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, exports.OutModeDirection.bottom);
|
|
3576
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, exports.OutModeDirection.left);
|
|
3577
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, exports.OutModeDirection.right);
|
|
3578
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, exports.OutModeDirection.top);
|
|
3618
3579
|
}
|
|
3619
|
-
|
|
3580
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3620
3581
|
const outModes = particle.options.move.outModes;
|
|
3621
3582
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3622
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3583
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3623
3584
|
}
|
|
3624
3585
|
};
|
|
3625
|
-
|
|
3586
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3626
3587
|
for (const updater of this.updaters.values()) {
|
|
3627
3588
|
updater.update(particle, direction, delta, outMode);
|
|
3628
3589
|
}
|
|
@@ -3630,7 +3591,7 @@
|
|
|
3630
3591
|
}
|
|
3631
3592
|
|
|
3632
3593
|
async function loadOutModesUpdater(engine) {
|
|
3633
|
-
engine.checkVersion("4.0
|
|
3594
|
+
engine.checkVersion("4.1.0");
|
|
3634
3595
|
await engine.pluginManager.register(e => {
|
|
3635
3596
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3636
3597
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3640,20 +3601,20 @@
|
|
|
3640
3601
|
|
|
3641
3602
|
const defaultOpacity$1 = 1;
|
|
3642
3603
|
class PaintUpdater {
|
|
3643
|
-
|
|
3644
|
-
|
|
3604
|
+
#container;
|
|
3605
|
+
#pluginManager;
|
|
3645
3606
|
constructor(pluginManager, container) {
|
|
3646
|
-
this
|
|
3647
|
-
this
|
|
3607
|
+
this.#container = container;
|
|
3608
|
+
this.#pluginManager = pluginManager;
|
|
3648
3609
|
}
|
|
3649
3610
|
init(particle) {
|
|
3650
|
-
const container = this
|
|
3611
|
+
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;
|
|
3651
3612
|
if (fill) {
|
|
3652
3613
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3653
3614
|
particle.fillEnabled = fill.enable;
|
|
3654
3615
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3655
3616
|
particle.fillAnimation = fillColor.animation;
|
|
3656
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3617
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3657
3618
|
if (fillHslColor) {
|
|
3658
3619
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3659
3620
|
}
|
|
@@ -3669,7 +3630,7 @@
|
|
|
3669
3630
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3670
3631
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity$1);
|
|
3671
3632
|
particle.strokeAnimation = strokeColor.animation;
|
|
3672
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3633
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3673
3634
|
if (strokeHslColor) {
|
|
3674
3635
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3675
3636
|
}
|
|
@@ -3701,7 +3662,7 @@
|
|
|
3701
3662
|
}
|
|
3702
3663
|
|
|
3703
3664
|
async function loadPaintUpdater(engine) {
|
|
3704
|
-
engine.checkVersion("4.0
|
|
3665
|
+
engine.checkVersion("4.1.0");
|
|
3705
3666
|
await engine.pluginManager.register(e => {
|
|
3706
3667
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3707
3668
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3756,27 +3717,69 @@
|
|
|
3756
3717
|
}
|
|
3757
3718
|
|
|
3758
3719
|
async function loadRgbColorPlugin(engine) {
|
|
3759
|
-
engine.checkVersion("4.0
|
|
3720
|
+
engine.checkVersion("4.1.0");
|
|
3760
3721
|
await engine.pluginManager.register(e => {
|
|
3761
3722
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3762
3723
|
});
|
|
3763
3724
|
}
|
|
3764
3725
|
|
|
3726
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3727
|
+
destroy;
|
|
3728
|
+
constructor() {
|
|
3729
|
+
super();
|
|
3730
|
+
this.destroy = exports.DestroyType.none;
|
|
3731
|
+
this.speed = 5;
|
|
3732
|
+
}
|
|
3733
|
+
load(data) {
|
|
3734
|
+
super.load(data);
|
|
3735
|
+
if (isNull(data)) {
|
|
3736
|
+
return;
|
|
3737
|
+
}
|
|
3738
|
+
if (data.destroy !== undefined) {
|
|
3739
|
+
this.destroy = data.destroy;
|
|
3740
|
+
}
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3745
|
+
animation;
|
|
3746
|
+
constructor() {
|
|
3747
|
+
super();
|
|
3748
|
+
this.animation = new SizeAnimation();
|
|
3749
|
+
this.value = 3;
|
|
3750
|
+
}
|
|
3751
|
+
load(data) {
|
|
3752
|
+
super.load(data);
|
|
3753
|
+
if (isNull(data)) {
|
|
3754
|
+
return;
|
|
3755
|
+
}
|
|
3756
|
+
const animation = data.animation;
|
|
3757
|
+
if (animation !== undefined) {
|
|
3758
|
+
this.animation.load(animation);
|
|
3759
|
+
}
|
|
3760
|
+
}
|
|
3761
|
+
}
|
|
3762
|
+
|
|
3765
3763
|
const minLoops = 0;
|
|
3766
3764
|
class SizeUpdater {
|
|
3767
|
-
|
|
3765
|
+
#container;
|
|
3768
3766
|
constructor(container) {
|
|
3769
|
-
this
|
|
3767
|
+
this.#container = container;
|
|
3770
3768
|
}
|
|
3771
3769
|
init(particle) {
|
|
3772
|
-
const container = this
|
|
3773
|
-
if (
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3770
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3771
|
+
if (!sizeOptions) {
|
|
3772
|
+
return;
|
|
3773
|
+
}
|
|
3774
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3775
|
+
if (!sizeAnimation.enable) {
|
|
3776
|
+
return;
|
|
3777
|
+
}
|
|
3778
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3779
|
+
if (sizeAnimation.sync) {
|
|
3780
|
+
return;
|
|
3779
3781
|
}
|
|
3782
|
+
particle.size.velocity *= getRandom();
|
|
3780
3783
|
}
|
|
3781
3784
|
isEnabled(particle) {
|
|
3782
3785
|
return (!particle.destroyed &&
|
|
@@ -3786,12 +3789,26 @@
|
|
|
3786
3789
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3787
3790
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3788
3791
|
}
|
|
3792
|
+
loadOptions(options, ...sources) {
|
|
3793
|
+
options.size ??= new Size();
|
|
3794
|
+
for (const source of sources) {
|
|
3795
|
+
options.size.load(source?.size);
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
preInit(particle) {
|
|
3799
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3800
|
+
if (!sizeOptions) {
|
|
3801
|
+
return;
|
|
3802
|
+
}
|
|
3803
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3804
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3805
|
+
}
|
|
3789
3806
|
reset(particle) {
|
|
3790
3807
|
particle.size.time = 0;
|
|
3791
3808
|
particle.size.loops = 0;
|
|
3792
3809
|
}
|
|
3793
3810
|
update(particle, delta) {
|
|
3794
|
-
if (!this.isEnabled(particle)) {
|
|
3811
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3795
3812
|
return;
|
|
3796
3813
|
}
|
|
3797
3814
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3799,7 +3816,7 @@
|
|
|
3799
3816
|
}
|
|
3800
3817
|
|
|
3801
3818
|
async function loadSizeUpdater(engine) {
|
|
3802
|
-
engine.checkVersion("4.0
|
|
3819
|
+
engine.checkVersion("4.1.0");
|
|
3803
3820
|
await engine.pluginManager.register(e => {
|
|
3804
3821
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3805
3822
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3808,7 +3825,7 @@
|
|
|
3808
3825
|
}
|
|
3809
3826
|
|
|
3810
3827
|
async function loadBasic(engine) {
|
|
3811
|
-
engine.checkVersion("4.0
|
|
3828
|
+
engine.checkVersion("4.1.0");
|
|
3812
3829
|
await engine.pluginManager.register(async (e) => {
|
|
3813
3830
|
await Promise.all([
|
|
3814
3831
|
loadBlendPlugin(e),
|
|
@@ -4108,7 +4125,7 @@
|
|
|
4108
4125
|
}
|
|
4109
4126
|
|
|
4110
4127
|
async function loadClubsSuitShape(engine) {
|
|
4111
|
-
engine.checkVersion("4.0
|
|
4128
|
+
engine.checkVersion("4.1.0");
|
|
4112
4129
|
await engine.pluginManager.register(e => {
|
|
4113
4130
|
e.pluginManager.addShape(["club", "clubs"], () => Promise.resolve(new ClubDrawer()));
|
|
4114
4131
|
});
|
|
@@ -4122,7 +4139,7 @@
|
|
|
4122
4139
|
}
|
|
4123
4140
|
|
|
4124
4141
|
async function loadDiamondsSuitShape(engine) {
|
|
4125
|
-
engine.checkVersion("4.0
|
|
4142
|
+
engine.checkVersion("4.1.0");
|
|
4126
4143
|
await engine.pluginManager.register(e => {
|
|
4127
4144
|
e.pluginManager.addShape(["diamond", "diamonds"], () => Promise.resolve(new DiamondDrawer()));
|
|
4128
4145
|
});
|
|
@@ -4136,7 +4153,7 @@
|
|
|
4136
4153
|
};
|
|
4137
4154
|
|
|
4138
4155
|
async function loadHeartsSuitShape(engine) {
|
|
4139
|
-
engine.checkVersion("4.0
|
|
4156
|
+
engine.checkVersion("4.1.0");
|
|
4140
4157
|
await engine.pluginManager.register(e => {
|
|
4141
4158
|
e.pluginManager.addShape(["heart", "hearts"], () => Promise.resolve(new HeartDrawer$1()));
|
|
4142
4159
|
});
|
|
@@ -4150,14 +4167,14 @@
|
|
|
4150
4167
|
}
|
|
4151
4168
|
|
|
4152
4169
|
async function loadSpadesSuitShape(engine) {
|
|
4153
|
-
engine.checkVersion("4.0
|
|
4170
|
+
engine.checkVersion("4.1.0");
|
|
4154
4171
|
await engine.pluginManager.register(e => {
|
|
4155
4172
|
e.pluginManager.addShape(["spade", "spades"], () => Promise.resolve(new SpadeDrawer()));
|
|
4156
4173
|
});
|
|
4157
4174
|
}
|
|
4158
4175
|
|
|
4159
4176
|
async function loadCardSuitsShape(engine) {
|
|
4160
|
-
engine.checkVersion("4.0
|
|
4177
|
+
engine.checkVersion("4.1.0");
|
|
4161
4178
|
await Promise.all([
|
|
4162
4179
|
loadClubsSuitShape(engine),
|
|
4163
4180
|
loadDiamondsSuitShape(engine),
|
|
@@ -4375,13 +4392,13 @@
|
|
|
4375
4392
|
|
|
4376
4393
|
class EmittersPlugin {
|
|
4377
4394
|
id = "emitters";
|
|
4378
|
-
|
|
4395
|
+
#instancesManager;
|
|
4379
4396
|
constructor(instancesManager) {
|
|
4380
|
-
this
|
|
4397
|
+
this.#instancesManager = instancesManager;
|
|
4381
4398
|
}
|
|
4382
4399
|
async getPlugin(container) {
|
|
4383
4400
|
const { EmittersPluginInstance } = await Promise.resolve().then(function () { return EmittersPluginInstance$1; });
|
|
4384
|
-
return new EmittersPluginInstance(this
|
|
4401
|
+
return new EmittersPluginInstance(this.#instancesManager, container);
|
|
4385
4402
|
}
|
|
4386
4403
|
loadOptions(_container, options, source) {
|
|
4387
4404
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -4434,7 +4451,7 @@
|
|
|
4434
4451
|
})(EmitterClickMode || (EmitterClickMode = {}));
|
|
4435
4452
|
|
|
4436
4453
|
async function loadEmittersPluginSimple(engine) {
|
|
4437
|
-
engine.checkVersion("4.0
|
|
4454
|
+
engine.checkVersion("4.1.0");
|
|
4438
4455
|
await engine.pluginManager.register(async (e) => {
|
|
4439
4456
|
const instancesManager = await getEmittersInstancesManager(e);
|
|
4440
4457
|
await addEmittersShapesManager(e);
|
|
@@ -4460,13 +4477,13 @@
|
|
|
4460
4477
|
|
|
4461
4478
|
const defaultFont = '"Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif', noPadding = 0, firstItem = 0;
|
|
4462
4479
|
class EmojiDrawer {
|
|
4463
|
-
|
|
4480
|
+
#emojiShapeDict = new Map();
|
|
4464
4481
|
destroy() {
|
|
4465
|
-
for (const [key, data] of this
|
|
4482
|
+
for (const [key, data] of this.#emojiShapeDict) {
|
|
4466
4483
|
if (data instanceof ImageBitmap) {
|
|
4467
4484
|
data.close();
|
|
4468
4485
|
}
|
|
4469
|
-
this.
|
|
4486
|
+
this.#emojiShapeDict.delete(key);
|
|
4470
4487
|
}
|
|
4471
4488
|
}
|
|
4472
4489
|
draw(data) {
|
|
@@ -4474,7 +4491,7 @@
|
|
|
4474
4491
|
if (!key) {
|
|
4475
4492
|
return;
|
|
4476
4493
|
}
|
|
4477
|
-
const image = this.
|
|
4494
|
+
const image = this.#emojiShapeDict.get(key);
|
|
4478
4495
|
if (!image) {
|
|
4479
4496
|
return;
|
|
4480
4497
|
}
|
|
@@ -4517,7 +4534,7 @@
|
|
|
4517
4534
|
...shapeData,
|
|
4518
4535
|
...emoji,
|
|
4519
4536
|
}, font = emojiOptions.font, value = emojiOptions.value, cacheKey = `${value}_${font}`;
|
|
4520
|
-
if (this.
|
|
4537
|
+
if (this.#emojiShapeDict.has(cacheKey)) {
|
|
4521
4538
|
particle.emojiDataKey = cacheKey;
|
|
4522
4539
|
return;
|
|
4523
4540
|
}
|
|
@@ -4530,13 +4547,13 @@
|
|
|
4530
4547
|
context.textAlign = "center";
|
|
4531
4548
|
context.fillText(value, fullSize, fullSize);
|
|
4532
4549
|
const image = cacheCanvas instanceof HTMLCanvasElement ? cacheCanvas : cacheCanvas.transferToImageBitmap();
|
|
4533
|
-
this.
|
|
4550
|
+
this.#emojiShapeDict.set(cacheKey, image);
|
|
4534
4551
|
particle.emojiDataKey = cacheKey;
|
|
4535
4552
|
}
|
|
4536
4553
|
}
|
|
4537
4554
|
|
|
4538
4555
|
async function loadEmojiShape(engine) {
|
|
4539
|
-
engine.checkVersion("4.0
|
|
4556
|
+
engine.checkVersion("4.1.0");
|
|
4540
4557
|
await engine.pluginManager.register(e => {
|
|
4541
4558
|
e.pluginManager.addShape(validTypes, () => Promise.resolve(new EmojiDrawer()));
|
|
4542
4559
|
});
|
|
@@ -4562,7 +4579,7 @@
|
|
|
4562
4579
|
}
|
|
4563
4580
|
|
|
4564
4581
|
async function loadHeartShape(engine) {
|
|
4565
|
-
engine.checkVersion("4.0
|
|
4582
|
+
engine.checkVersion("4.1.0");
|
|
4566
4583
|
await engine.pluginManager.register(e => {
|
|
4567
4584
|
e.pluginManager.addShape(["heart"], () => Promise.resolve(new HeartDrawer()));
|
|
4568
4585
|
});
|
|
@@ -5147,11 +5164,11 @@
|
|
|
5147
5164
|
|
|
5148
5165
|
const sides$2 = 12;
|
|
5149
5166
|
class ImageDrawer {
|
|
5150
|
-
|
|
5151
|
-
|
|
5167
|
+
#container;
|
|
5168
|
+
#engine;
|
|
5152
5169
|
constructor(engine, container) {
|
|
5153
|
-
this
|
|
5154
|
-
this
|
|
5170
|
+
this.#engine = engine;
|
|
5171
|
+
this.#container = container;
|
|
5155
5172
|
}
|
|
5156
5173
|
draw(data) {
|
|
5157
5174
|
const { context, radius, particle, opacity } = data, image = particle.image, element = image?.element;
|
|
@@ -5160,7 +5177,7 @@
|
|
|
5160
5177
|
}
|
|
5161
5178
|
context.globalAlpha = opacity;
|
|
5162
5179
|
if (image.gif && image.gifData) {
|
|
5163
|
-
drawGif(data, this.
|
|
5180
|
+
drawGif(data, this.#container.canvas.render.settings);
|
|
5164
5181
|
}
|
|
5165
5182
|
else if (element) {
|
|
5166
5183
|
const ratio = image.ratio, pos = {
|
|
@@ -5176,17 +5193,17 @@
|
|
|
5176
5193
|
}
|
|
5177
5194
|
async init(container) {
|
|
5178
5195
|
const options = container.actualOptions;
|
|
5179
|
-
if (!options.preload || !this.
|
|
5196
|
+
if (!options.preload || !this.#engine.loadImage) {
|
|
5180
5197
|
return;
|
|
5181
5198
|
}
|
|
5182
5199
|
const promises = [];
|
|
5183
5200
|
for (const imageData of options.preload) {
|
|
5184
|
-
promises.push(this.
|
|
5201
|
+
promises.push(this.#engine.loadImage(container, imageData));
|
|
5185
5202
|
}
|
|
5186
5203
|
await Promise.all(promises);
|
|
5187
5204
|
}
|
|
5188
5205
|
loadShape(particle) {
|
|
5189
|
-
const
|
|
5206
|
+
const container = this.#container;
|
|
5190
5207
|
if (!particle.shape || !shapeTypes.includes(particle.shape)) {
|
|
5191
5208
|
return;
|
|
5192
5209
|
}
|
|
@@ -5194,11 +5211,11 @@
|
|
|
5194
5211
|
if (!imageData) {
|
|
5195
5212
|
return;
|
|
5196
5213
|
}
|
|
5197
|
-
const images = this.
|
|
5214
|
+
const images = this.#engine.getImages?.(container), image = images?.find((t) => t.name === imageData.name || t.source === imageData.src);
|
|
5198
5215
|
if (image) {
|
|
5199
5216
|
return;
|
|
5200
5217
|
}
|
|
5201
|
-
void this
|
|
5218
|
+
void this.#loadImageShape(container, imageData).then(() => {
|
|
5202
5219
|
this.loadShape(particle);
|
|
5203
5220
|
});
|
|
5204
5221
|
}
|
|
@@ -5206,7 +5223,7 @@
|
|
|
5206
5223
|
if (particle.shape !== "image" && particle.shape !== "images") {
|
|
5207
5224
|
return;
|
|
5208
5225
|
}
|
|
5209
|
-
const images = this.
|
|
5226
|
+
const images = this.#engine.getImages?.(container), imageData = particle.shapeData;
|
|
5210
5227
|
if (!imageData) {
|
|
5211
5228
|
return;
|
|
5212
5229
|
}
|
|
@@ -5251,11 +5268,11 @@
|
|
|
5251
5268
|
particle.shapeClose = imageShape.close;
|
|
5252
5269
|
})();
|
|
5253
5270
|
}
|
|
5254
|
-
loadImageShape = async (container, imageShape) => {
|
|
5255
|
-
if (!this.
|
|
5271
|
+
#loadImageShape = async (container, imageShape) => {
|
|
5272
|
+
if (!this.#engine.loadImage) {
|
|
5256
5273
|
throw new Error(`Image shape not initialized`);
|
|
5257
5274
|
}
|
|
5258
|
-
await this.
|
|
5275
|
+
await this.#engine.loadImage(container, {
|
|
5259
5276
|
gif: imageShape.gif,
|
|
5260
5277
|
name: imageShape.name,
|
|
5261
5278
|
replaceColor: imageShape.replaceColor,
|
|
@@ -5302,13 +5319,13 @@
|
|
|
5302
5319
|
|
|
5303
5320
|
class ImagePreloaderPlugin {
|
|
5304
5321
|
id = "image-preloader";
|
|
5305
|
-
|
|
5322
|
+
#engine;
|
|
5306
5323
|
constructor(engine) {
|
|
5307
|
-
this
|
|
5324
|
+
this.#engine = engine;
|
|
5308
5325
|
}
|
|
5309
5326
|
async getPlugin(container) {
|
|
5310
5327
|
const { ImagePreloaderInstance } = await Promise.resolve().then(function () { return ImagePreloaderInstance$1; });
|
|
5311
|
-
return new ImagePreloaderInstance(this
|
|
5328
|
+
return new ImagePreloaderInstance(this.#engine, container);
|
|
5312
5329
|
}
|
|
5313
5330
|
loadOptions(_container, options, source) {
|
|
5314
5331
|
if (!source?.preload) {
|
|
@@ -5387,7 +5404,7 @@
|
|
|
5387
5404
|
};
|
|
5388
5405
|
}
|
|
5389
5406
|
async function loadImageShape(engine) {
|
|
5390
|
-
engine.checkVersion("4.0
|
|
5407
|
+
engine.checkVersion("4.1.0");
|
|
5391
5408
|
await engine.pluginManager.register(e => {
|
|
5392
5409
|
addLoadImageToEngine(e);
|
|
5393
5410
|
e.pluginManager.addPlugin(new ImagePreloaderPlugin(e));
|
|
@@ -5505,12 +5522,12 @@
|
|
|
5505
5522
|
|
|
5506
5523
|
const noTime = 0, identity$2 = 1, infiniteValue = -1;
|
|
5507
5524
|
class LifeUpdater {
|
|
5508
|
-
container;
|
|
5525
|
+
#container;
|
|
5509
5526
|
constructor(container) {
|
|
5510
|
-
this
|
|
5527
|
+
this.#container = container;
|
|
5511
5528
|
}
|
|
5512
5529
|
init(particle) {
|
|
5513
|
-
const container = this
|
|
5530
|
+
const container = this.#container, particlesOptions = particle.options, lifeOptions = particlesOptions.life;
|
|
5514
5531
|
if (!lifeOptions) {
|
|
5515
5532
|
return;
|
|
5516
5533
|
}
|
|
@@ -5549,12 +5566,12 @@
|
|
|
5549
5566
|
if (!this.isEnabled(particle) || !particle.life) {
|
|
5550
5567
|
return;
|
|
5551
5568
|
}
|
|
5552
|
-
updateLife(particle, delta, this
|
|
5569
|
+
updateLife(particle, delta, this.#container.canvas.size);
|
|
5553
5570
|
}
|
|
5554
5571
|
}
|
|
5555
5572
|
|
|
5556
5573
|
async function loadLifeUpdater(engine) {
|
|
5557
|
-
engine.checkVersion("4.0
|
|
5574
|
+
engine.checkVersion("4.1.0");
|
|
5558
5575
|
await engine.pluginManager.register(e => {
|
|
5559
5576
|
e.pluginManager.addParticleUpdater("life", container => {
|
|
5560
5577
|
return Promise.resolve(new LifeUpdater(container));
|
|
@@ -5622,7 +5639,7 @@
|
|
|
5622
5639
|
}
|
|
5623
5640
|
|
|
5624
5641
|
async function loadMotionPlugin(engine) {
|
|
5625
|
-
engine.checkVersion("4.0
|
|
5642
|
+
engine.checkVersion("4.1.0");
|
|
5626
5643
|
await engine.pluginManager.register(e => {
|
|
5627
5644
|
e.pluginManager.addPlugin(new MotionPlugin());
|
|
5628
5645
|
});
|
|
@@ -5707,19 +5724,19 @@
|
|
|
5707
5724
|
}
|
|
5708
5725
|
|
|
5709
5726
|
async function loadGenericPolygonShape(engine) {
|
|
5710
|
-
engine.checkVersion("4.0
|
|
5727
|
+
engine.checkVersion("4.1.0");
|
|
5711
5728
|
await engine.pluginManager.register(e => {
|
|
5712
5729
|
e.pluginManager.addShape(["polygon"], () => Promise.resolve(new PolygonDrawer()));
|
|
5713
5730
|
});
|
|
5714
5731
|
}
|
|
5715
5732
|
async function loadTriangleShape(engine) {
|
|
5716
|
-
engine.checkVersion("4.0
|
|
5733
|
+
engine.checkVersion("4.1.0");
|
|
5717
5734
|
await engine.pluginManager.register(e => {
|
|
5718
5735
|
e.pluginManager.addShape(["triangle"], () => Promise.resolve(new TriangleDrawer()));
|
|
5719
5736
|
});
|
|
5720
5737
|
}
|
|
5721
5738
|
async function loadPolygonShape(engine) {
|
|
5722
|
-
engine.checkVersion("4.0
|
|
5739
|
+
engine.checkVersion("4.1.0");
|
|
5723
5740
|
await Promise.all([
|
|
5724
5741
|
loadGenericPolygonShape(engine),
|
|
5725
5742
|
loadTriangleShape(engine),
|
|
@@ -5844,9 +5861,9 @@
|
|
|
5844
5861
|
}
|
|
5845
5862
|
|
|
5846
5863
|
class RollUpdater {
|
|
5847
|
-
|
|
5864
|
+
#pluginManager;
|
|
5848
5865
|
constructor(pluginManager) {
|
|
5849
|
-
this
|
|
5866
|
+
this.#pluginManager = pluginManager;
|
|
5850
5867
|
}
|
|
5851
5868
|
getTransformValues(particle) {
|
|
5852
5869
|
const roll = particle.roll?.enable && particle.roll, rollHorizontal = roll && roll.horizontal, rollVertical = roll && roll.vertical;
|
|
@@ -5856,7 +5873,7 @@
|
|
|
5856
5873
|
};
|
|
5857
5874
|
}
|
|
5858
5875
|
init(particle) {
|
|
5859
|
-
initParticle(this
|
|
5876
|
+
initParticle(this.#pluginManager, particle);
|
|
5860
5877
|
}
|
|
5861
5878
|
isEnabled(particle) {
|
|
5862
5879
|
const roll = particle.options.roll;
|
|
@@ -5877,7 +5894,7 @@
|
|
|
5877
5894
|
}
|
|
5878
5895
|
|
|
5879
5896
|
async function loadRollUpdater(engine) {
|
|
5880
|
-
engine.checkVersion("4.0
|
|
5897
|
+
engine.checkVersion("4.1.0");
|
|
5881
5898
|
await engine.pluginManager.register(e => {
|
|
5882
5899
|
e.pluginManager.addParticleUpdater("roll", () => {
|
|
5883
5900
|
return Promise.resolve(new RollUpdater(e.pluginManager));
|
|
@@ -5943,9 +5960,9 @@
|
|
|
5943
5960
|
|
|
5944
5961
|
const doublePIDeg = 360;
|
|
5945
5962
|
class RotateUpdater {
|
|
5946
|
-
container;
|
|
5963
|
+
#container;
|
|
5947
5964
|
constructor(container) {
|
|
5948
|
-
this
|
|
5965
|
+
this.#container = container;
|
|
5949
5966
|
}
|
|
5950
5967
|
init(particle) {
|
|
5951
5968
|
const rotateOptions = particle.options.rotate;
|
|
@@ -5977,7 +5994,7 @@
|
|
|
5977
5994
|
if (rotateAnimation.enable) {
|
|
5978
5995
|
particle.rotate.decay = identity$3 - getRangeValue(rotateAnimation.decay);
|
|
5979
5996
|
particle.rotate.velocity =
|
|
5980
|
-
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this
|
|
5997
|
+
(getRangeValue(rotateAnimation.speed) / doublePIDeg) * this.#container.retina.reduceFactor;
|
|
5981
5998
|
if (!rotateAnimation.sync) {
|
|
5982
5999
|
particle.rotate.velocity *= getRandom();
|
|
5983
6000
|
}
|
|
@@ -6011,7 +6028,7 @@
|
|
|
6011
6028
|
}
|
|
6012
6029
|
|
|
6013
6030
|
async function loadRotateUpdater(engine) {
|
|
6014
|
-
engine.checkVersion("4.0
|
|
6031
|
+
engine.checkVersion("4.1.0");
|
|
6015
6032
|
await engine.pluginManager.register(e => {
|
|
6016
6033
|
e.pluginManager.addParticleUpdater("rotate", container => {
|
|
6017
6034
|
return Promise.resolve(new RotateUpdater(container));
|
|
@@ -6035,7 +6052,7 @@
|
|
|
6035
6052
|
}
|
|
6036
6053
|
|
|
6037
6054
|
async function loadSquareShape(engine) {
|
|
6038
|
-
engine.checkVersion("4.0
|
|
6055
|
+
engine.checkVersion("4.1.0");
|
|
6039
6056
|
await engine.pluginManager.register(e => {
|
|
6040
6057
|
e.pluginManager.addShape(["edge", "square"], () => Promise.resolve(new SquareDrawer()));
|
|
6041
6058
|
});
|
|
@@ -6069,7 +6086,7 @@
|
|
|
6069
6086
|
}
|
|
6070
6087
|
|
|
6071
6088
|
async function loadStarShape(engine) {
|
|
6072
|
-
engine.checkVersion("4.0
|
|
6089
|
+
engine.checkVersion("4.1.0");
|
|
6073
6090
|
await engine.pluginManager.register(e => {
|
|
6074
6091
|
e.pluginManager.addShape(["star"], () => Promise.resolve(new StarDrawer()));
|
|
6075
6092
|
});
|
|
@@ -6140,9 +6157,9 @@
|
|
|
6140
6157
|
|
|
6141
6158
|
const maxAngle$1 = 360;
|
|
6142
6159
|
class TiltUpdater {
|
|
6143
|
-
container;
|
|
6160
|
+
#container;
|
|
6144
6161
|
constructor(container) {
|
|
6145
|
-
this
|
|
6162
|
+
this.#container = container;
|
|
6146
6163
|
}
|
|
6147
6164
|
getTransformValues(particle) {
|
|
6148
6165
|
const tilt = particle.tilt?.enable && particle.tilt;
|
|
@@ -6181,7 +6198,7 @@
|
|
|
6181
6198
|
const tiltAnimation = particle.options.tilt?.animation;
|
|
6182
6199
|
if (tiltAnimation?.enable) {
|
|
6183
6200
|
particle.tilt.decay = identity$3 - getRangeValue(tiltAnimation.decay);
|
|
6184
|
-
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this
|
|
6201
|
+
particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / maxAngle$1) * this.#container.retina.reduceFactor;
|
|
6185
6202
|
if (!tiltAnimation.sync) {
|
|
6186
6203
|
particle.tilt.velocity *= getRandom();
|
|
6187
6204
|
}
|
|
@@ -6206,7 +6223,7 @@
|
|
|
6206
6223
|
}
|
|
6207
6224
|
|
|
6208
6225
|
async function loadTiltUpdater(engine) {
|
|
6209
|
-
engine.checkVersion("4.0
|
|
6226
|
+
engine.checkVersion("4.1.0");
|
|
6210
6227
|
await engine.pluginManager.register(e => {
|
|
6211
6228
|
e.pluginManager.addParticleUpdater("tilt", container => {
|
|
6212
6229
|
return Promise.resolve(new TiltUpdater(container));
|
|
@@ -6287,9 +6304,9 @@
|
|
|
6287
6304
|
|
|
6288
6305
|
const maxAngle = 360, moveSpeedFactor$1 = 10, defaultDistance = 0;
|
|
6289
6306
|
class WobbleUpdater {
|
|
6290
|
-
|
|
6307
|
+
#container;
|
|
6291
6308
|
constructor(container) {
|
|
6292
|
-
this
|
|
6309
|
+
this.#container = container;
|
|
6293
6310
|
}
|
|
6294
6311
|
init(particle) {
|
|
6295
6312
|
const wobbleOpt = particle.options.wobble;
|
|
@@ -6308,7 +6325,7 @@
|
|
|
6308
6325
|
};
|
|
6309
6326
|
}
|
|
6310
6327
|
particle.retina.wobbleDistance =
|
|
6311
|
-
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.
|
|
6328
|
+
getRangeValue(wobbleOpt?.distance ?? defaultDistance) * this.#container.retina.pixelRatio;
|
|
6312
6329
|
}
|
|
6313
6330
|
isEnabled(particle) {
|
|
6314
6331
|
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable;
|
|
@@ -6323,12 +6340,12 @@
|
|
|
6323
6340
|
if (!this.isEnabled(particle)) {
|
|
6324
6341
|
return;
|
|
6325
6342
|
}
|
|
6326
|
-
updateWobble(this
|
|
6343
|
+
updateWobble(this.#container, particle, delta);
|
|
6327
6344
|
}
|
|
6328
6345
|
}
|
|
6329
6346
|
|
|
6330
6347
|
async function loadWobbleUpdater(engine) {
|
|
6331
|
-
engine.checkVersion("4.0
|
|
6348
|
+
engine.checkVersion("4.1.0");
|
|
6332
6349
|
await engine.pluginManager.register(e => {
|
|
6333
6350
|
e.pluginManager.addParticleUpdater("wobble", container => {
|
|
6334
6351
|
return Promise.resolve(new WobbleUpdater(container));
|
|
@@ -6755,7 +6772,7 @@
|
|
|
6755
6772
|
|
|
6756
6773
|
let initPromise = null;
|
|
6757
6774
|
async function doInitPlugins(engine) {
|
|
6758
|
-
engine.checkVersion("4.0
|
|
6775
|
+
engine.checkVersion("4.1.0");
|
|
6759
6776
|
await engine.pluginManager.register(async (e) => {
|
|
6760
6777
|
await Promise.all([
|
|
6761
6778
|
loadBasic(e),
|
|
@@ -6828,7 +6845,7 @@
|
|
|
6828
6845
|
confetti.init = async () => {
|
|
6829
6846
|
await initPlugins(tsParticles);
|
|
6830
6847
|
};
|
|
6831
|
-
confetti.version = "4.0
|
|
6848
|
+
confetti.version = "4.1.0";
|
|
6832
6849
|
globalThis.confetti = confetti;
|
|
6833
6850
|
|
|
6834
6851
|
const globalObject = globalThis;
|
|
@@ -6843,58 +6860,58 @@
|
|
|
6843
6860
|
}
|
|
6844
6861
|
}
|
|
6845
6862
|
class RenderManager {
|
|
6846
|
-
|
|
6847
|
-
|
|
6848
|
-
|
|
6849
|
-
|
|
6850
|
-
|
|
6851
|
-
|
|
6852
|
-
|
|
6853
|
-
|
|
6854
|
-
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6861
|
-
|
|
6862
|
-
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
|
|
6863
|
+
#canvasClearPlugins;
|
|
6864
|
+
#canvasManager;
|
|
6865
|
+
#canvasPaintPlugins;
|
|
6866
|
+
#clearDrawPlugins;
|
|
6867
|
+
#colorPlugins;
|
|
6868
|
+
#container;
|
|
6869
|
+
#context;
|
|
6870
|
+
#contextSettings;
|
|
6871
|
+
#drawParticlePlugins;
|
|
6872
|
+
#drawParticlesCleanupPlugins;
|
|
6873
|
+
#drawParticlesSetupPlugins;
|
|
6874
|
+
#drawPlugins;
|
|
6875
|
+
#drawSettingsCleanupPlugins;
|
|
6876
|
+
#drawSettingsSetupPlugins;
|
|
6877
|
+
#pluginManager;
|
|
6878
|
+
#postDrawUpdaters;
|
|
6879
|
+
#preDrawUpdaters;
|
|
6880
|
+
#reusableColorStyles = {};
|
|
6881
|
+
#reusablePluginColors = [undefined, undefined];
|
|
6882
|
+
#reusableTransform = {};
|
|
6866
6883
|
constructor(pluginManager, container, canvasManager) {
|
|
6867
|
-
this
|
|
6868
|
-
this
|
|
6869
|
-
this
|
|
6870
|
-
this
|
|
6871
|
-
this
|
|
6872
|
-
this
|
|
6873
|
-
this
|
|
6874
|
-
this
|
|
6875
|
-
this
|
|
6876
|
-
this
|
|
6877
|
-
this
|
|
6878
|
-
this
|
|
6879
|
-
this
|
|
6880
|
-
this
|
|
6881
|
-
this
|
|
6882
|
-
this
|
|
6884
|
+
this.#pluginManager = pluginManager;
|
|
6885
|
+
this.#container = container;
|
|
6886
|
+
this.#canvasManager = canvasManager;
|
|
6887
|
+
this.#context = null;
|
|
6888
|
+
this.#preDrawUpdaters = [];
|
|
6889
|
+
this.#postDrawUpdaters = [];
|
|
6890
|
+
this.#colorPlugins = [];
|
|
6891
|
+
this.#canvasClearPlugins = [];
|
|
6892
|
+
this.#canvasPaintPlugins = [];
|
|
6893
|
+
this.#clearDrawPlugins = [];
|
|
6894
|
+
this.#drawParticlePlugins = [];
|
|
6895
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
6896
|
+
this.#drawParticlesSetupPlugins = [];
|
|
6897
|
+
this.#drawPlugins = [];
|
|
6898
|
+
this.#drawSettingsSetupPlugins = [];
|
|
6899
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
6883
6900
|
}
|
|
6884
6901
|
get settings() {
|
|
6885
|
-
return this
|
|
6902
|
+
return this.#contextSettings;
|
|
6886
6903
|
}
|
|
6887
6904
|
canvasClear() {
|
|
6888
|
-
if (!this.
|
|
6905
|
+
if (!this.#container.actualOptions.clear) {
|
|
6889
6906
|
return;
|
|
6890
6907
|
}
|
|
6891
6908
|
this.draw(ctx => {
|
|
6892
|
-
clear(ctx, this.
|
|
6909
|
+
clear(ctx, this.#canvasManager.size);
|
|
6893
6910
|
});
|
|
6894
6911
|
}
|
|
6895
6912
|
clear() {
|
|
6896
6913
|
let pluginHandled = false;
|
|
6897
|
-
for (const plugin of this
|
|
6914
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
6898
6915
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
6899
6916
|
if (pluginHandled) {
|
|
6900
6917
|
break;
|
|
@@ -6907,21 +6924,21 @@
|
|
|
6907
6924
|
}
|
|
6908
6925
|
destroy() {
|
|
6909
6926
|
this.stop();
|
|
6910
|
-
this
|
|
6911
|
-
this
|
|
6912
|
-
this
|
|
6913
|
-
this
|
|
6914
|
-
this
|
|
6915
|
-
this
|
|
6916
|
-
this
|
|
6917
|
-
this
|
|
6918
|
-
this
|
|
6919
|
-
this
|
|
6920
|
-
this
|
|
6921
|
-
this
|
|
6927
|
+
this.#preDrawUpdaters = [];
|
|
6928
|
+
this.#postDrawUpdaters = [];
|
|
6929
|
+
this.#colorPlugins = [];
|
|
6930
|
+
this.#canvasClearPlugins = [];
|
|
6931
|
+
this.#canvasPaintPlugins = [];
|
|
6932
|
+
this.#clearDrawPlugins = [];
|
|
6933
|
+
this.#drawParticlePlugins = [];
|
|
6934
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
6935
|
+
this.#drawParticlesSetupPlugins = [];
|
|
6936
|
+
this.#drawPlugins = [];
|
|
6937
|
+
this.#drawSettingsSetupPlugins = [];
|
|
6938
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
6922
6939
|
}
|
|
6923
6940
|
draw(cb) {
|
|
6924
|
-
const ctx = this
|
|
6941
|
+
const ctx = this.#context;
|
|
6925
6942
|
if (!ctx) {
|
|
6926
6943
|
return;
|
|
6927
6944
|
}
|
|
@@ -6936,21 +6953,21 @@
|
|
|
6936
6953
|
return;
|
|
6937
6954
|
}
|
|
6938
6955
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
6939
|
-
let [fColor, sColor] = this
|
|
6956
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
6940
6957
|
fColor ??= pfColor;
|
|
6941
6958
|
sColor ??= psColor;
|
|
6942
6959
|
if (!fColor && !sColor) {
|
|
6943
6960
|
return;
|
|
6944
6961
|
}
|
|
6945
|
-
const container = this
|
|
6962
|
+
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;
|
|
6946
6963
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
6947
6964
|
colorStyles.fill = fill;
|
|
6948
6965
|
colorStyles.stroke = stroke;
|
|
6949
6966
|
this.draw((context) => {
|
|
6950
|
-
for (const plugin of this
|
|
6967
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
6951
6968
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
6952
6969
|
}
|
|
6953
|
-
this
|
|
6970
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
6954
6971
|
drawParticle({
|
|
6955
6972
|
container,
|
|
6956
6973
|
context,
|
|
@@ -6961,35 +6978,35 @@
|
|
|
6961
6978
|
opacity: opacity,
|
|
6962
6979
|
transform,
|
|
6963
6980
|
});
|
|
6964
|
-
this
|
|
6965
|
-
for (const plugin of this
|
|
6981
|
+
this.#applyPostDrawUpdaters(particle);
|
|
6982
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
6966
6983
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
6967
6984
|
}
|
|
6968
6985
|
});
|
|
6969
6986
|
}
|
|
6970
6987
|
drawParticlePlugins(particle, delta) {
|
|
6971
6988
|
this.draw(ctx => {
|
|
6972
|
-
for (const plugin of this
|
|
6989
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
6973
6990
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
6974
6991
|
}
|
|
6975
6992
|
});
|
|
6976
6993
|
}
|
|
6977
6994
|
drawParticles(delta) {
|
|
6978
|
-
const { particles } = this
|
|
6995
|
+
const { particles } = this.#container;
|
|
6979
6996
|
this.clear();
|
|
6980
6997
|
particles.update(delta);
|
|
6981
6998
|
this.draw(ctx => {
|
|
6982
|
-
for (const plugin of this
|
|
6999
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
6983
7000
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
6984
7001
|
}
|
|
6985
|
-
for (const plugin of this
|
|
7002
|
+
for (const plugin of this.#drawPlugins) {
|
|
6986
7003
|
plugin.draw?.(ctx, delta);
|
|
6987
7004
|
}
|
|
6988
7005
|
particles.drawParticles(delta);
|
|
6989
|
-
for (const plugin of this
|
|
7006
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
6990
7007
|
plugin.clearDraw?.(ctx, delta);
|
|
6991
7008
|
}
|
|
6992
|
-
for (const plugin of this
|
|
7009
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
6993
7010
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
6994
7011
|
}
|
|
6995
7012
|
});
|
|
@@ -7000,64 +7017,64 @@
|
|
|
7000
7017
|
this.paint();
|
|
7001
7018
|
}
|
|
7002
7019
|
initPlugins() {
|
|
7003
|
-
this
|
|
7004
|
-
this
|
|
7005
|
-
this
|
|
7006
|
-
this
|
|
7007
|
-
this
|
|
7008
|
-
this
|
|
7009
|
-
this
|
|
7010
|
-
this
|
|
7011
|
-
this
|
|
7012
|
-
this
|
|
7013
|
-
for (const plugin of this.
|
|
7020
|
+
this.#colorPlugins = [];
|
|
7021
|
+
this.#canvasClearPlugins = [];
|
|
7022
|
+
this.#canvasPaintPlugins = [];
|
|
7023
|
+
this.#clearDrawPlugins = [];
|
|
7024
|
+
this.#drawParticlePlugins = [];
|
|
7025
|
+
this.#drawParticlesSetupPlugins = [];
|
|
7026
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
7027
|
+
this.#drawPlugins = [];
|
|
7028
|
+
this.#drawSettingsSetupPlugins = [];
|
|
7029
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
7030
|
+
for (const plugin of this.#container.plugins) {
|
|
7014
7031
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
7015
|
-
this.
|
|
7032
|
+
this.#colorPlugins.push(plugin);
|
|
7016
7033
|
}
|
|
7017
7034
|
if (plugin.canvasClear) {
|
|
7018
|
-
this.
|
|
7035
|
+
this.#canvasClearPlugins.push(plugin);
|
|
7019
7036
|
}
|
|
7020
7037
|
if (plugin.canvasPaint) {
|
|
7021
|
-
this.
|
|
7038
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
7022
7039
|
}
|
|
7023
7040
|
if (plugin.drawParticle) {
|
|
7024
|
-
this.
|
|
7041
|
+
this.#drawParticlePlugins.push(plugin);
|
|
7025
7042
|
}
|
|
7026
7043
|
if (plugin.drawParticleSetup) {
|
|
7027
|
-
this.
|
|
7044
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
7028
7045
|
}
|
|
7029
7046
|
if (plugin.drawParticleCleanup) {
|
|
7030
|
-
this.
|
|
7047
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
7031
7048
|
}
|
|
7032
7049
|
if (plugin.draw) {
|
|
7033
|
-
this.
|
|
7050
|
+
this.#drawPlugins.push(plugin);
|
|
7034
7051
|
}
|
|
7035
7052
|
if (plugin.drawSettingsSetup) {
|
|
7036
|
-
this.
|
|
7053
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
7037
7054
|
}
|
|
7038
7055
|
if (plugin.drawSettingsCleanup) {
|
|
7039
|
-
this.
|
|
7056
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
7040
7057
|
}
|
|
7041
7058
|
if (plugin.clearDraw) {
|
|
7042
|
-
this.
|
|
7059
|
+
this.#clearDrawPlugins.push(plugin);
|
|
7043
7060
|
}
|
|
7044
7061
|
}
|
|
7045
7062
|
}
|
|
7046
7063
|
initUpdaters() {
|
|
7047
|
-
this
|
|
7048
|
-
this
|
|
7049
|
-
for (const updater of this.
|
|
7064
|
+
this.#preDrawUpdaters = [];
|
|
7065
|
+
this.#postDrawUpdaters = [];
|
|
7066
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
7050
7067
|
if (updater.afterDraw) {
|
|
7051
|
-
this.
|
|
7068
|
+
this.#postDrawUpdaters.push(updater);
|
|
7052
7069
|
}
|
|
7053
7070
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
7054
|
-
this.
|
|
7071
|
+
this.#preDrawUpdaters.push(updater);
|
|
7055
7072
|
}
|
|
7056
7073
|
}
|
|
7057
7074
|
}
|
|
7058
7075
|
paint() {
|
|
7059
7076
|
let handled = false;
|
|
7060
|
-
for (const plugin of this
|
|
7077
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
7061
7078
|
handled = plugin.canvasPaint?.() ?? false;
|
|
7062
7079
|
if (handled) {
|
|
7063
7080
|
break;
|
|
@@ -7070,35 +7087,35 @@
|
|
|
7070
7087
|
}
|
|
7071
7088
|
paintBase(baseColor) {
|
|
7072
7089
|
this.draw(ctx => {
|
|
7073
|
-
paintBase(ctx, this.
|
|
7090
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
7074
7091
|
});
|
|
7075
7092
|
}
|
|
7076
7093
|
paintImage(image, opacity) {
|
|
7077
7094
|
this.draw(ctx => {
|
|
7078
|
-
paintImage(ctx, this.
|
|
7095
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
7079
7096
|
});
|
|
7080
7097
|
}
|
|
7081
7098
|
setContext(context) {
|
|
7082
|
-
this
|
|
7083
|
-
if (this
|
|
7084
|
-
this.
|
|
7099
|
+
this.#context = context;
|
|
7100
|
+
if (this.#context) {
|
|
7101
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
7085
7102
|
}
|
|
7086
7103
|
}
|
|
7087
7104
|
setContextSettings(settings) {
|
|
7088
|
-
this
|
|
7105
|
+
this.#contextSettings = settings;
|
|
7089
7106
|
}
|
|
7090
7107
|
stop() {
|
|
7091
7108
|
this.draw(ctx => {
|
|
7092
|
-
clear(ctx, this.
|
|
7109
|
+
clear(ctx, this.#canvasManager.size);
|
|
7093
7110
|
});
|
|
7094
7111
|
}
|
|
7095
|
-
|
|
7096
|
-
for (const updater of this
|
|
7112
|
+
#applyPostDrawUpdaters = particle => {
|
|
7113
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
7097
7114
|
updater.afterDraw?.(particle);
|
|
7098
7115
|
}
|
|
7099
7116
|
};
|
|
7100
|
-
|
|
7101
|
-
for (const updater of this
|
|
7117
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
7118
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
7102
7119
|
if (updater.getColorStyles) {
|
|
7103
7120
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
7104
7121
|
if (fill) {
|
|
@@ -7117,22 +7134,22 @@
|
|
|
7117
7134
|
updater.beforeDraw?.(particle);
|
|
7118
7135
|
}
|
|
7119
7136
|
};
|
|
7120
|
-
|
|
7137
|
+
#getPluginParticleColors = particle => {
|
|
7121
7138
|
let fColor, sColor;
|
|
7122
|
-
for (const plugin of this
|
|
7139
|
+
for (const plugin of this.#colorPlugins) {
|
|
7123
7140
|
if (!fColor && plugin.particleFillColor) {
|
|
7124
|
-
fColor = rangeColorToHsl(this
|
|
7141
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
7125
7142
|
}
|
|
7126
7143
|
if (!sColor && plugin.particleStrokeColor) {
|
|
7127
|
-
sColor = rangeColorToHsl(this
|
|
7144
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
7128
7145
|
}
|
|
7129
7146
|
if (fColor && sColor) {
|
|
7130
7147
|
break;
|
|
7131
7148
|
}
|
|
7132
7149
|
}
|
|
7133
|
-
this
|
|
7134
|
-
this
|
|
7135
|
-
return this
|
|
7150
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
7151
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
7152
|
+
return this.#reusablePluginColors;
|
|
7136
7153
|
};
|
|
7137
7154
|
}
|
|
7138
7155
|
|
|
@@ -7190,53 +7207,53 @@
|
|
|
7190
7207
|
renderCanvas;
|
|
7191
7208
|
size;
|
|
7192
7209
|
zoom = defaultZoom;
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7199
|
-
|
|
7200
|
-
|
|
7201
|
-
|
|
7210
|
+
#container;
|
|
7211
|
+
#generated;
|
|
7212
|
+
#mutationObserver;
|
|
7213
|
+
#originalStyle;
|
|
7214
|
+
#pluginManager;
|
|
7215
|
+
#pointerEvents;
|
|
7216
|
+
#resizePlugins;
|
|
7217
|
+
#standardSize;
|
|
7218
|
+
#zoomCenter;
|
|
7202
7219
|
constructor(pluginManager, container) {
|
|
7203
|
-
this
|
|
7204
|
-
this
|
|
7220
|
+
this.#pluginManager = pluginManager;
|
|
7221
|
+
this.#container = container;
|
|
7205
7222
|
this.render = new RenderManager(pluginManager, container, this);
|
|
7206
|
-
this
|
|
7223
|
+
this.#standardSize = {
|
|
7207
7224
|
height: 0,
|
|
7208
7225
|
width: 0,
|
|
7209
7226
|
};
|
|
7210
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
7227
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
7211
7228
|
this.size = {
|
|
7212
7229
|
height: stdSize.height * pxRatio,
|
|
7213
7230
|
width: stdSize.width * pxRatio,
|
|
7214
7231
|
};
|
|
7215
|
-
this
|
|
7216
|
-
this
|
|
7217
|
-
this
|
|
7232
|
+
this.#generated = false;
|
|
7233
|
+
this.#resizePlugins = [];
|
|
7234
|
+
this.#pointerEvents = "none";
|
|
7218
7235
|
}
|
|
7219
|
-
get
|
|
7220
|
-
return this.
|
|
7236
|
+
get #fullScreen() {
|
|
7237
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
7221
7238
|
}
|
|
7222
7239
|
destroy() {
|
|
7223
7240
|
this.stop();
|
|
7224
|
-
if (this
|
|
7241
|
+
if (this.#generated) {
|
|
7225
7242
|
const element = this.domElement;
|
|
7226
7243
|
element?.remove();
|
|
7227
7244
|
this.domElement = undefined;
|
|
7228
7245
|
this.renderCanvas = undefined;
|
|
7229
7246
|
}
|
|
7230
7247
|
else {
|
|
7231
|
-
this
|
|
7248
|
+
this.#resetOriginalStyle();
|
|
7232
7249
|
}
|
|
7233
7250
|
this.render.destroy();
|
|
7234
|
-
this
|
|
7251
|
+
this.#resizePlugins = [];
|
|
7235
7252
|
}
|
|
7236
7253
|
getZoomCenter() {
|
|
7237
|
-
const pxRatio = this.
|
|
7238
|
-
if (this
|
|
7239
|
-
return this
|
|
7254
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
7255
|
+
if (this.#zoomCenter) {
|
|
7256
|
+
return this.#zoomCenter;
|
|
7240
7257
|
}
|
|
7241
7258
|
return {
|
|
7242
7259
|
x: (width * half) / pxRatio,
|
|
@@ -7244,20 +7261,20 @@
|
|
|
7244
7261
|
};
|
|
7245
7262
|
}
|
|
7246
7263
|
init() {
|
|
7247
|
-
this
|
|
7264
|
+
this.#safeMutationObserver(obs => {
|
|
7248
7265
|
obs.disconnect();
|
|
7249
7266
|
});
|
|
7250
|
-
this
|
|
7267
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
7251
7268
|
for (const record of records) {
|
|
7252
7269
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
7253
|
-
this
|
|
7270
|
+
this.#repairStyle();
|
|
7254
7271
|
}
|
|
7255
7272
|
}
|
|
7256
7273
|
});
|
|
7257
7274
|
this.resize();
|
|
7258
|
-
this
|
|
7275
|
+
this.#initStyle();
|
|
7259
7276
|
this.initBackground();
|
|
7260
|
-
this
|
|
7277
|
+
this.#safeMutationObserver(obs => {
|
|
7261
7278
|
const element = this.domElement;
|
|
7262
7279
|
if (!element || !(element instanceof Node)) {
|
|
7263
7280
|
return;
|
|
@@ -7268,13 +7285,13 @@
|
|
|
7268
7285
|
this.render.init();
|
|
7269
7286
|
}
|
|
7270
7287
|
initBackground() {
|
|
7271
|
-
const
|
|
7288
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
7272
7289
|
if (!element) {
|
|
7273
7290
|
return;
|
|
7274
7291
|
}
|
|
7275
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
7292
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
7276
7293
|
if (color) {
|
|
7277
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
7294
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
7278
7295
|
}
|
|
7279
7296
|
else {
|
|
7280
7297
|
elementStyle.backgroundColor = "";
|
|
@@ -7285,27 +7302,27 @@
|
|
|
7285
7302
|
elementStyle.backgroundSize = background.size || "";
|
|
7286
7303
|
}
|
|
7287
7304
|
initPlugins() {
|
|
7288
|
-
this
|
|
7289
|
-
for (const plugin of this.
|
|
7305
|
+
this.#resizePlugins = [];
|
|
7306
|
+
for (const plugin of this.#container.plugins) {
|
|
7290
7307
|
if (plugin.resize) {
|
|
7291
|
-
this.
|
|
7308
|
+
this.#resizePlugins.push(plugin);
|
|
7292
7309
|
}
|
|
7293
7310
|
}
|
|
7294
7311
|
}
|
|
7295
7312
|
loadCanvas(canvas) {
|
|
7296
|
-
if (this
|
|
7313
|
+
if (this.#generated && this.domElement) {
|
|
7297
7314
|
this.domElement.remove();
|
|
7298
7315
|
}
|
|
7299
|
-
const container = this
|
|
7316
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
7300
7317
|
this.domElement = domCanvas;
|
|
7301
|
-
this
|
|
7318
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
7302
7319
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
7303
7320
|
const domElement = this.domElement;
|
|
7304
7321
|
if (domElement) {
|
|
7305
7322
|
domElement.ariaHidden = "true";
|
|
7306
|
-
this
|
|
7323
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
7307
7324
|
}
|
|
7308
|
-
const standardSize = this
|
|
7325
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
7309
7326
|
if (domElement) {
|
|
7310
7327
|
standardSize.height = domElement.offsetHeight;
|
|
7311
7328
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -7314,7 +7331,7 @@
|
|
|
7314
7331
|
standardSize.height = renderCanvas.height;
|
|
7315
7332
|
standardSize.width = renderCanvas.width;
|
|
7316
7333
|
}
|
|
7317
|
-
const pxRatio = this.
|
|
7334
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
7318
7335
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
7319
7336
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
7320
7337
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -7325,12 +7342,12 @@
|
|
|
7325
7342
|
willReadFrequently: false,
|
|
7326
7343
|
});
|
|
7327
7344
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
7328
|
-
this
|
|
7345
|
+
this.#safeMutationObserver(obs => {
|
|
7329
7346
|
obs.disconnect();
|
|
7330
7347
|
});
|
|
7331
7348
|
container.retina.init();
|
|
7332
7349
|
this.initBackground();
|
|
7333
|
-
this
|
|
7350
|
+
this.#safeMutationObserver(obs => {
|
|
7334
7351
|
const element = this.domElement;
|
|
7335
7352
|
if (!element || !(element instanceof Node)) {
|
|
7336
7353
|
return;
|
|
@@ -7343,11 +7360,11 @@
|
|
|
7343
7360
|
if (!element) {
|
|
7344
7361
|
return false;
|
|
7345
7362
|
}
|
|
7346
|
-
const container = this
|
|
7363
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
7347
7364
|
if (renderCanvas === undefined) {
|
|
7348
7365
|
return false;
|
|
7349
7366
|
}
|
|
7350
|
-
const currentSize = container.canvas
|
|
7367
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
7351
7368
|
width: element.offsetWidth,
|
|
7352
7369
|
height: element.offsetHeight,
|
|
7353
7370
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -7366,7 +7383,7 @@
|
|
|
7366
7383
|
const canvasSize = this.size;
|
|
7367
7384
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
7368
7385
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
7369
|
-
if (this.
|
|
7386
|
+
if (this.#container.started) {
|
|
7370
7387
|
container.particles.setResizeFactor({
|
|
7371
7388
|
width: currentSize.width / oldSize.width,
|
|
7372
7389
|
height: currentSize.height / oldSize.height,
|
|
@@ -7379,46 +7396,46 @@
|
|
|
7379
7396
|
if (!element) {
|
|
7380
7397
|
return;
|
|
7381
7398
|
}
|
|
7382
|
-
this
|
|
7383
|
-
this
|
|
7399
|
+
this.#pointerEvents = type;
|
|
7400
|
+
this.#repairStyle();
|
|
7384
7401
|
}
|
|
7385
7402
|
setZoom(zoomLevel, center) {
|
|
7386
7403
|
this.zoom = zoomLevel;
|
|
7387
|
-
this
|
|
7404
|
+
this.#zoomCenter = center;
|
|
7388
7405
|
}
|
|
7389
7406
|
stop() {
|
|
7390
|
-
this
|
|
7407
|
+
this.#safeMutationObserver(obs => {
|
|
7391
7408
|
obs.disconnect();
|
|
7392
7409
|
});
|
|
7393
|
-
this
|
|
7410
|
+
this.#mutationObserver = undefined;
|
|
7394
7411
|
this.render.stop();
|
|
7395
7412
|
}
|
|
7396
7413
|
async windowResize() {
|
|
7397
7414
|
if (!this.domElement || !this.resize()) {
|
|
7398
7415
|
return;
|
|
7399
7416
|
}
|
|
7400
|
-
const container = this
|
|
7417
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
7401
7418
|
container.particles.setDensity();
|
|
7402
|
-
this
|
|
7419
|
+
this.#applyResizePlugins();
|
|
7403
7420
|
if (needsRefresh) {
|
|
7404
7421
|
await container.refresh();
|
|
7405
7422
|
}
|
|
7406
7423
|
}
|
|
7407
|
-
|
|
7408
|
-
for (const plugin of this
|
|
7424
|
+
#applyResizePlugins = () => {
|
|
7425
|
+
for (const plugin of this.#resizePlugins) {
|
|
7409
7426
|
plugin.resize?.();
|
|
7410
7427
|
}
|
|
7411
7428
|
};
|
|
7412
|
-
|
|
7413
|
-
const element = this.domElement, options = this.
|
|
7429
|
+
#initStyle = () => {
|
|
7430
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
7414
7431
|
if (!element) {
|
|
7415
7432
|
return;
|
|
7416
7433
|
}
|
|
7417
|
-
if (this
|
|
7418
|
-
this
|
|
7434
|
+
if (this.#fullScreen) {
|
|
7435
|
+
this.#setFullScreenStyle();
|
|
7419
7436
|
}
|
|
7420
7437
|
else {
|
|
7421
|
-
this
|
|
7438
|
+
this.#resetOriginalStyle();
|
|
7422
7439
|
}
|
|
7423
7440
|
for (const key in options.style) {
|
|
7424
7441
|
if (!key || !(key in options.style)) {
|
|
@@ -7431,72 +7448,72 @@
|
|
|
7431
7448
|
element.style.setProperty(key, value, "important");
|
|
7432
7449
|
}
|
|
7433
7450
|
};
|
|
7434
|
-
|
|
7451
|
+
#repairStyle = () => {
|
|
7435
7452
|
const element = this.domElement;
|
|
7436
7453
|
if (!element) {
|
|
7437
7454
|
return;
|
|
7438
7455
|
}
|
|
7439
|
-
this
|
|
7456
|
+
this.#safeMutationObserver(observer => {
|
|
7440
7457
|
observer.disconnect();
|
|
7441
7458
|
});
|
|
7442
|
-
this
|
|
7459
|
+
this.#initStyle();
|
|
7443
7460
|
this.initBackground();
|
|
7444
|
-
const pointerEvents = this
|
|
7461
|
+
const pointerEvents = this.#pointerEvents;
|
|
7445
7462
|
element.style.pointerEvents = pointerEvents;
|
|
7446
7463
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
7447
|
-
this
|
|
7464
|
+
this.#safeMutationObserver(observer => {
|
|
7448
7465
|
if (!(element instanceof Node)) {
|
|
7449
7466
|
return;
|
|
7450
7467
|
}
|
|
7451
7468
|
observer.observe(element, { attributes: true });
|
|
7452
7469
|
});
|
|
7453
7470
|
};
|
|
7454
|
-
|
|
7455
|
-
const element = this.domElement, originalStyle = this
|
|
7471
|
+
#resetOriginalStyle = () => {
|
|
7472
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
7456
7473
|
if (!element || !originalStyle) {
|
|
7457
7474
|
return;
|
|
7458
7475
|
}
|
|
7459
7476
|
setStyle(element, originalStyle, true);
|
|
7460
7477
|
};
|
|
7461
|
-
|
|
7462
|
-
if (!this
|
|
7478
|
+
#safeMutationObserver = callback => {
|
|
7479
|
+
if (!this.#mutationObserver) {
|
|
7463
7480
|
return;
|
|
7464
7481
|
}
|
|
7465
|
-
callback(this
|
|
7482
|
+
callback(this.#mutationObserver);
|
|
7466
7483
|
};
|
|
7467
|
-
|
|
7484
|
+
#setFullScreenStyle = () => {
|
|
7468
7485
|
const element = this.domElement;
|
|
7469
7486
|
if (!element) {
|
|
7470
7487
|
return;
|
|
7471
7488
|
}
|
|
7472
|
-
setStyle(element, getFullScreenStyle(this.
|
|
7489
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
7473
7490
|
};
|
|
7474
7491
|
}
|
|
7475
7492
|
|
|
7476
7493
|
class EventListeners {
|
|
7477
|
-
container;
|
|
7478
|
-
|
|
7479
|
-
|
|
7480
|
-
|
|
7494
|
+
#container;
|
|
7495
|
+
#handlers;
|
|
7496
|
+
#resizeObserver;
|
|
7497
|
+
#resizeTimeout;
|
|
7481
7498
|
constructor(container) {
|
|
7482
|
-
this
|
|
7483
|
-
this
|
|
7499
|
+
this.#container = container;
|
|
7500
|
+
this.#handlers = {
|
|
7484
7501
|
visibilityChange: () => {
|
|
7485
|
-
this
|
|
7502
|
+
this.#handleVisibilityChange();
|
|
7486
7503
|
},
|
|
7487
7504
|
resize: () => {
|
|
7488
|
-
this
|
|
7505
|
+
this.#handleWindowResize();
|
|
7489
7506
|
},
|
|
7490
7507
|
};
|
|
7491
7508
|
}
|
|
7492
7509
|
addListeners() {
|
|
7493
|
-
this
|
|
7510
|
+
this.#manageListeners(true);
|
|
7494
7511
|
}
|
|
7495
7512
|
removeListeners() {
|
|
7496
|
-
this
|
|
7513
|
+
this.#manageListeners(false);
|
|
7497
7514
|
}
|
|
7498
|
-
|
|
7499
|
-
const container = this
|
|
7515
|
+
#handleVisibilityChange = () => {
|
|
7516
|
+
const container = this.#container, options = container.actualOptions;
|
|
7500
7517
|
if (!options.pauseOnBlur) {
|
|
7501
7518
|
return;
|
|
7502
7519
|
}
|
|
@@ -7514,24 +7531,24 @@
|
|
|
7514
7531
|
}
|
|
7515
7532
|
}
|
|
7516
7533
|
};
|
|
7517
|
-
|
|
7518
|
-
if (this
|
|
7519
|
-
clearTimeout(this
|
|
7520
|
-
|
|
7534
|
+
#handleWindowResize = () => {
|
|
7535
|
+
if (this.#resizeTimeout) {
|
|
7536
|
+
clearTimeout(this.#resizeTimeout);
|
|
7537
|
+
this.#resizeTimeout = undefined;
|
|
7521
7538
|
}
|
|
7522
7539
|
const handleResize = async () => {
|
|
7523
|
-
const canvas = this
|
|
7540
|
+
const canvas = this.#container.canvas;
|
|
7524
7541
|
await canvas.windowResize();
|
|
7525
7542
|
};
|
|
7526
|
-
this
|
|
7543
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
7527
7544
|
};
|
|
7528
|
-
|
|
7529
|
-
const handlers = this
|
|
7530
|
-
this
|
|
7545
|
+
#manageListeners = add => {
|
|
7546
|
+
const handlers = this.#handlers;
|
|
7547
|
+
this.#manageResize(add);
|
|
7531
7548
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
7532
7549
|
};
|
|
7533
|
-
|
|
7534
|
-
const handlers = this
|
|
7550
|
+
#manageResize = add => {
|
|
7551
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
7535
7552
|
if (!options.resize.enable) {
|
|
7536
7553
|
return;
|
|
7537
7554
|
}
|
|
@@ -7540,22 +7557,22 @@
|
|
|
7540
7557
|
return;
|
|
7541
7558
|
}
|
|
7542
7559
|
const canvasEl = container.canvas.domElement;
|
|
7543
|
-
if (this
|
|
7560
|
+
if (this.#resizeObserver && !add) {
|
|
7544
7561
|
if (canvasEl) {
|
|
7545
|
-
this.
|
|
7562
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
7546
7563
|
}
|
|
7547
|
-
this.
|
|
7548
|
-
|
|
7564
|
+
this.#resizeObserver.disconnect();
|
|
7565
|
+
this.#resizeObserver = undefined;
|
|
7549
7566
|
}
|
|
7550
|
-
else if (!this
|
|
7551
|
-
this
|
|
7567
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
7568
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
7552
7569
|
const entry = entries.find(e => e.target === canvasEl);
|
|
7553
7570
|
if (!entry) {
|
|
7554
7571
|
return;
|
|
7555
7572
|
}
|
|
7556
|
-
this
|
|
7573
|
+
this.#handleWindowResize();
|
|
7557
7574
|
});
|
|
7558
|
-
this.
|
|
7575
|
+
this.#resizeObserver.observe(canvasEl);
|
|
7559
7576
|
}
|
|
7560
7577
|
};
|
|
7561
7578
|
}
|
|
@@ -7628,24 +7645,24 @@
|
|
|
7628
7645
|
unbreakable;
|
|
7629
7646
|
velocity;
|
|
7630
7647
|
zIndexFactor;
|
|
7631
|
-
|
|
7648
|
+
#cachedOpacityData = {
|
|
7632
7649
|
fillOpacity: defaultOpacity$2,
|
|
7633
7650
|
opacity: defaultOpacity$2,
|
|
7634
7651
|
strokeOpacity: defaultOpacity$2,
|
|
7635
7652
|
};
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7653
|
+
#cachedPosition = Vector3d.origin;
|
|
7654
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
7655
|
+
#cachedTransform = {
|
|
7639
7656
|
a: 1,
|
|
7640
7657
|
b: 0,
|
|
7641
7658
|
c: 0,
|
|
7642
7659
|
d: 1,
|
|
7643
7660
|
};
|
|
7644
|
-
|
|
7645
|
-
|
|
7661
|
+
#container;
|
|
7662
|
+
#pluginManager;
|
|
7646
7663
|
constructor(pluginManager, container) {
|
|
7647
|
-
this
|
|
7648
|
-
this
|
|
7664
|
+
this.#pluginManager = pluginManager;
|
|
7665
|
+
this.#container = container;
|
|
7649
7666
|
}
|
|
7650
7667
|
destroy(override) {
|
|
7651
7668
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -7654,7 +7671,7 @@
|
|
|
7654
7671
|
this.destroyed = true;
|
|
7655
7672
|
this.bubble.inRange = false;
|
|
7656
7673
|
this.slow.inRange = false;
|
|
7657
|
-
const container = this
|
|
7674
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
7658
7675
|
shapeDrawer?.particleDestroy?.(this);
|
|
7659
7676
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
7660
7677
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -7662,12 +7679,12 @@
|
|
|
7662
7679
|
for (const updater of container.particleUpdaters) {
|
|
7663
7680
|
updater.particleDestroyed?.(this, override);
|
|
7664
7681
|
}
|
|
7665
|
-
this.
|
|
7682
|
+
this.#container.dispatchEvent(exports.EventType.particleDestroyed, {
|
|
7666
7683
|
particle: this,
|
|
7667
7684
|
});
|
|
7668
7685
|
}
|
|
7669
7686
|
draw(delta) {
|
|
7670
|
-
const container = this
|
|
7687
|
+
const container = this.#container, render = container.canvas.render;
|
|
7671
7688
|
render.drawParticlePlugins(this, delta);
|
|
7672
7689
|
render.drawParticle(this, delta);
|
|
7673
7690
|
}
|
|
@@ -7675,50 +7692,50 @@
|
|
|
7675
7692
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
7676
7693
|
}
|
|
7677
7694
|
getFillColor() {
|
|
7678
|
-
return this
|
|
7695
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
7679
7696
|
}
|
|
7680
7697
|
getMass() {
|
|
7681
7698
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
7682
7699
|
}
|
|
7683
7700
|
getOpacity() {
|
|
7684
7701
|
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? getRangeValue(this.opacity?.value ?? defaultOpacity$2), fillOpacity = this.fillOpacity ?? defaultOpacity$2, strokeOpacity = this.strokeOpacity ?? defaultOpacity$2;
|
|
7685
|
-
this.
|
|
7686
|
-
this.
|
|
7687
|
-
this.
|
|
7688
|
-
return this
|
|
7702
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
7703
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
7704
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
7705
|
+
return this.#cachedOpacityData;
|
|
7689
7706
|
}
|
|
7690
7707
|
getPosition() {
|
|
7691
|
-
this.
|
|
7692
|
-
this.
|
|
7693
|
-
this.
|
|
7694
|
-
return this
|
|
7708
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
7709
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
7710
|
+
this.#cachedPosition.z = this.position.z;
|
|
7711
|
+
return this.#cachedPosition;
|
|
7695
7712
|
}
|
|
7696
7713
|
getRadius() {
|
|
7697
7714
|
return this.bubble.radius ?? this.size.value;
|
|
7698
7715
|
}
|
|
7699
7716
|
getRotateData() {
|
|
7700
7717
|
const angle = this.getAngle();
|
|
7701
|
-
this.
|
|
7702
|
-
this.
|
|
7703
|
-
return this
|
|
7718
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
7719
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
7720
|
+
return this.#cachedRotateData;
|
|
7704
7721
|
}
|
|
7705
7722
|
getStrokeColor() {
|
|
7706
|
-
return this
|
|
7723
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
7707
7724
|
}
|
|
7708
7725
|
getTransformData(externalTransform) {
|
|
7709
7726
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
7710
|
-
this.
|
|
7711
|
-
this.
|
|
7727
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
7728
|
+
this.#cachedTransform.b = rotating
|
|
7712
7729
|
? rotateData.sin * (externalTransform.b ?? identity$3)
|
|
7713
7730
|
: (externalTransform.b ?? defaultTransform.b);
|
|
7714
|
-
this.
|
|
7731
|
+
this.#cachedTransform.c = rotating
|
|
7715
7732
|
? -rotateData.sin * (externalTransform.c ?? identity$3)
|
|
7716
7733
|
: (externalTransform.c ?? defaultTransform.c);
|
|
7717
|
-
this.
|
|
7718
|
-
return this
|
|
7734
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
7735
|
+
return this.#cachedTransform;
|
|
7719
7736
|
}
|
|
7720
7737
|
init(id, position, overrideOptions, group) {
|
|
7721
|
-
const container = this
|
|
7738
|
+
const container = this.#container;
|
|
7722
7739
|
this.id = id;
|
|
7723
7740
|
this.group = group;
|
|
7724
7741
|
this.justWarped = false;
|
|
@@ -7738,21 +7755,27 @@
|
|
|
7738
7755
|
moveSpeed: 0,
|
|
7739
7756
|
sizeAnimationSpeed: 0,
|
|
7740
7757
|
};
|
|
7758
|
+
this.size = {
|
|
7759
|
+
value: 1,
|
|
7760
|
+
max: 1,
|
|
7761
|
+
min: 1,
|
|
7762
|
+
enable: false,
|
|
7763
|
+
};
|
|
7741
7764
|
this.outType = exports.ParticleOutType.normal;
|
|
7742
7765
|
this.ignoresResizeRatio = true;
|
|
7743
|
-
const
|
|
7766
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
7744
7767
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
7745
7768
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
7746
7769
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
7747
7770
|
if (overrideOptions) {
|
|
7748
|
-
if (overrideOptions.effect?.type) {
|
|
7771
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
7749
7772
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
7750
7773
|
if (effect) {
|
|
7751
7774
|
this.effect = effect;
|
|
7752
7775
|
effectOptions.load(overrideOptions.effect);
|
|
7753
7776
|
}
|
|
7754
7777
|
}
|
|
7755
|
-
if (overrideOptions.shape?.type) {
|
|
7778
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
7756
7779
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
7757
7780
|
if (shape) {
|
|
7758
7781
|
this.shape = shape;
|
|
@@ -7761,21 +7784,20 @@
|
|
|
7761
7784
|
}
|
|
7762
7785
|
}
|
|
7763
7786
|
if (this.effect === randomColorValue) {
|
|
7764
|
-
const availableEffects = [...this.
|
|
7787
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
7765
7788
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
7766
7789
|
}
|
|
7767
7790
|
if (this.shape === randomColorValue) {
|
|
7768
|
-
const availableShapes = [...this.
|
|
7791
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
7769
7792
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
7770
7793
|
}
|
|
7771
7794
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
7772
7795
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
7773
7796
|
particlesOptions.load(overrideOptions);
|
|
7774
|
-
const effectData = this.effectData;
|
|
7797
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
7775
7798
|
if (effectData) {
|
|
7776
7799
|
particlesOptions.load(effectData.particles);
|
|
7777
7800
|
}
|
|
7778
|
-
const shapeData = this.shapeData;
|
|
7779
7801
|
if (shapeData) {
|
|
7780
7802
|
particlesOptions.load(shapeData.particles);
|
|
7781
7803
|
}
|
|
@@ -7783,7 +7805,9 @@
|
|
|
7783
7805
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
7784
7806
|
this.options = particlesOptions;
|
|
7785
7807
|
container.retina.initParticle(this);
|
|
7786
|
-
|
|
7808
|
+
for (const updater of container.particleUpdaters) {
|
|
7809
|
+
updater.preInit?.(this);
|
|
7810
|
+
}
|
|
7787
7811
|
this.bubble = {
|
|
7788
7812
|
inRange: false,
|
|
7789
7813
|
};
|
|
@@ -7791,8 +7815,8 @@
|
|
|
7791
7815
|
inRange: false,
|
|
7792
7816
|
factor: 1,
|
|
7793
7817
|
};
|
|
7794
|
-
this
|
|
7795
|
-
this.initialVelocity = this
|
|
7818
|
+
this.#initPosition(position);
|
|
7819
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
7796
7820
|
this.velocity = this.initialVelocity.copy();
|
|
7797
7821
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
7798
7822
|
this.sides = 24;
|
|
@@ -7823,12 +7847,11 @@
|
|
|
7823
7847
|
plugin.particleCreated?.(this);
|
|
7824
7848
|
}
|
|
7825
7849
|
}
|
|
7826
|
-
isInsideCanvas() {
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
|
|
7830
|
-
|
|
7831
|
-
position.x <= canvasSize.width + radius);
|
|
7850
|
+
isInsideCanvas(direction) {
|
|
7851
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
7852
|
+
}
|
|
7853
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
7854
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
7832
7855
|
}
|
|
7833
7856
|
isShowingBack() {
|
|
7834
7857
|
if (!this.roll) {
|
|
@@ -7853,13 +7876,13 @@
|
|
|
7853
7876
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
7854
7877
|
}
|
|
7855
7878
|
reset() {
|
|
7856
|
-
for (const updater of this.
|
|
7879
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
7857
7880
|
updater.reset?.(this);
|
|
7858
7881
|
}
|
|
7859
7882
|
}
|
|
7860
|
-
|
|
7883
|
+
#calcPosition = (position, zIndex) => {
|
|
7861
7884
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
7862
|
-
const container = this
|
|
7885
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
7863
7886
|
while (!signal.aborted) {
|
|
7864
7887
|
for (const plugin of plugins) {
|
|
7865
7888
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -7871,10 +7894,10 @@
|
|
|
7871
7894
|
size: canvasSize,
|
|
7872
7895
|
position: posVec,
|
|
7873
7896
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
7874
|
-
this
|
|
7875
|
-
this
|
|
7876
|
-
this
|
|
7877
|
-
this
|
|
7897
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
7898
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
7899
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
7900
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
7878
7901
|
let isValidPosition = true;
|
|
7879
7902
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
7880
7903
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -7890,8 +7913,8 @@
|
|
|
7890
7913
|
}
|
|
7891
7914
|
return posVec;
|
|
7892
7915
|
};
|
|
7893
|
-
|
|
7894
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
7916
|
+
#calculateVelocity = () => {
|
|
7917
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
7895
7918
|
if (moveOptions.direction === exports.MoveDirection.inside || moveOptions.direction === exports.MoveDirection.outside) {
|
|
7896
7919
|
return res;
|
|
7897
7920
|
}
|
|
@@ -7907,27 +7930,86 @@
|
|
|
7907
7930
|
}
|
|
7908
7931
|
return res;
|
|
7909
7932
|
};
|
|
7910
|
-
|
|
7933
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
7911
7934
|
fixOutMode({
|
|
7912
7935
|
outMode,
|
|
7913
7936
|
checkModes: [exports.OutMode.bounce],
|
|
7914
7937
|
coord: pos.x,
|
|
7915
|
-
maxCoord: this.
|
|
7938
|
+
maxCoord: this.#container.canvas.size.width,
|
|
7916
7939
|
setCb: (value) => (pos.x += value),
|
|
7917
7940
|
radius,
|
|
7918
7941
|
});
|
|
7919
7942
|
};
|
|
7920
|
-
|
|
7943
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
7921
7944
|
fixOutMode({
|
|
7922
7945
|
outMode,
|
|
7923
7946
|
checkModes: [exports.OutMode.bounce],
|
|
7924
7947
|
coord: pos.y,
|
|
7925
|
-
maxCoord: this.
|
|
7948
|
+
maxCoord: this.#container.canvas.size.height,
|
|
7926
7949
|
setCb: (value) => (pos.y += value),
|
|
7927
7950
|
radius,
|
|
7928
7951
|
});
|
|
7929
7952
|
};
|
|
7930
|
-
|
|
7953
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
7954
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === exports.OutMode.bounce;
|
|
7955
|
+
if (direction === exports.OutModeDirection.bottom) {
|
|
7956
|
+
return {
|
|
7957
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
7958
|
+
reason: "default",
|
|
7959
|
+
};
|
|
7960
|
+
}
|
|
7961
|
+
if (direction === exports.OutModeDirection.left) {
|
|
7962
|
+
return {
|
|
7963
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
7964
|
+
reason: "default",
|
|
7965
|
+
};
|
|
7966
|
+
}
|
|
7967
|
+
if (direction === exports.OutModeDirection.right) {
|
|
7968
|
+
return {
|
|
7969
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
7970
|
+
reason: "default",
|
|
7971
|
+
};
|
|
7972
|
+
}
|
|
7973
|
+
if (direction === exports.OutModeDirection.top) {
|
|
7974
|
+
return {
|
|
7975
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
7976
|
+
reason: "default",
|
|
7977
|
+
};
|
|
7978
|
+
}
|
|
7979
|
+
return {
|
|
7980
|
+
inside: position.x >= -radius &&
|
|
7981
|
+
position.y >= -radius &&
|
|
7982
|
+
position.y <= canvasSize.height + radius &&
|
|
7983
|
+
position.x <= canvasSize.width + radius,
|
|
7984
|
+
reason: "default",
|
|
7985
|
+
};
|
|
7986
|
+
};
|
|
7987
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
7988
|
+
return {
|
|
7989
|
+
canvasSize: this.#container.canvas.size,
|
|
7990
|
+
direction,
|
|
7991
|
+
outMode,
|
|
7992
|
+
particle: this,
|
|
7993
|
+
radius: this.getRadius(),
|
|
7994
|
+
};
|
|
7995
|
+
};
|
|
7996
|
+
#getInsideCanvasResult = (data) => {
|
|
7997
|
+
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;
|
|
7998
|
+
if (!shapeCheck && !effectCheck) {
|
|
7999
|
+
return defaultResult;
|
|
8000
|
+
}
|
|
8001
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
8002
|
+
if (shapeResult && effectResult) {
|
|
8003
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
8004
|
+
return {
|
|
8005
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
8006
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
8007
|
+
reason: "combined",
|
|
8008
|
+
};
|
|
8009
|
+
}
|
|
8010
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
8011
|
+
};
|
|
8012
|
+
#getRollColor = color => {
|
|
7931
8013
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
7932
8014
|
return color;
|
|
7933
8015
|
}
|
|
@@ -7942,8 +8024,8 @@
|
|
|
7942
8024
|
}
|
|
7943
8025
|
return color;
|
|
7944
8026
|
};
|
|
7945
|
-
|
|
7946
|
-
const container = this
|
|
8027
|
+
#initPosition = position => {
|
|
8028
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
7947
8029
|
if (!initialPosition) {
|
|
7948
8030
|
throw new Error("a valid position cannot be found for particle");
|
|
7949
8031
|
}
|
|
@@ -7966,45 +8048,58 @@
|
|
|
7966
8048
|
}
|
|
7967
8049
|
this.offset = Vector.origin;
|
|
7968
8050
|
};
|
|
8051
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
8052
|
+
if (typeof result === "boolean") {
|
|
8053
|
+
return {
|
|
8054
|
+
inside: result,
|
|
8055
|
+
reason,
|
|
8056
|
+
};
|
|
8057
|
+
}
|
|
8058
|
+
return {
|
|
8059
|
+
inside: result.inside,
|
|
8060
|
+
margin: result.margin,
|
|
8061
|
+
reason: result.reason ?? reason,
|
|
8062
|
+
};
|
|
8063
|
+
};
|
|
7969
8064
|
}
|
|
7970
8065
|
|
|
7971
8066
|
class SpatialHashGrid {
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
-
|
|
8067
|
+
#cellSize;
|
|
8068
|
+
#cells = new Map();
|
|
8069
|
+
#circlePool = [];
|
|
8070
|
+
#circlePoolIdx;
|
|
8071
|
+
#pendingCellSize;
|
|
8072
|
+
#rectanglePool = [];
|
|
8073
|
+
#rectanglePoolIdx;
|
|
7979
8074
|
constructor(cellSize) {
|
|
7980
|
-
this
|
|
7981
|
-
this
|
|
7982
|
-
this
|
|
8075
|
+
this.#cellSize = cellSize;
|
|
8076
|
+
this.#circlePoolIdx = 0;
|
|
8077
|
+
this.#rectanglePoolIdx = 0;
|
|
7983
8078
|
}
|
|
7984
8079
|
clear() {
|
|
7985
|
-
this.
|
|
7986
|
-
const pendingCellSize = this
|
|
8080
|
+
this.#cells.clear();
|
|
8081
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
7987
8082
|
if (pendingCellSize) {
|
|
7988
|
-
this
|
|
8083
|
+
this.#cellSize = pendingCellSize;
|
|
7989
8084
|
}
|
|
7990
|
-
this
|
|
8085
|
+
this.#pendingCellSize = undefined;
|
|
7991
8086
|
}
|
|
7992
8087
|
insert(particle) {
|
|
7993
|
-
const { x, y } = particle.getPosition(), key = this
|
|
7994
|
-
if (!this.
|
|
7995
|
-
this.
|
|
8088
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
8089
|
+
if (!this.#cells.has(key)) {
|
|
8090
|
+
this.#cells.set(key, []);
|
|
7996
8091
|
}
|
|
7997
|
-
this.
|
|
8092
|
+
this.#cells.get(key)?.push(particle);
|
|
7998
8093
|
}
|
|
7999
8094
|
query(range, check, out = []) {
|
|
8000
|
-
const bounds = this
|
|
8095
|
+
const bounds = this.#getRangeBounds(range);
|
|
8001
8096
|
if (!bounds) {
|
|
8002
8097
|
return out;
|
|
8003
8098
|
}
|
|
8004
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
8099
|
+
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);
|
|
8005
8100
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
8006
8101
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
8007
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
8102
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
8008
8103
|
if (!cellParticles) {
|
|
8009
8104
|
continue;
|
|
8010
8105
|
}
|
|
@@ -8021,29 +8116,29 @@
|
|
|
8021
8116
|
return out;
|
|
8022
8117
|
}
|
|
8023
8118
|
queryCircle(position, radius, check, out = []) {
|
|
8024
|
-
const circle = this
|
|
8025
|
-
this
|
|
8119
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
8120
|
+
this.#releaseShapes();
|
|
8026
8121
|
return result;
|
|
8027
8122
|
}
|
|
8028
8123
|
queryRectangle(position, size, check, out = []) {
|
|
8029
|
-
const rect = this
|
|
8030
|
-
this
|
|
8124
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
8125
|
+
this.#releaseShapes();
|
|
8031
8126
|
return result;
|
|
8032
8127
|
}
|
|
8033
8128
|
setCellSize(cellSize) {
|
|
8034
|
-
this
|
|
8129
|
+
this.#pendingCellSize = cellSize;
|
|
8035
8130
|
}
|
|
8036
|
-
|
|
8037
|
-
return (this
|
|
8131
|
+
#acquireCircle(x, y, r) {
|
|
8132
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
8038
8133
|
}
|
|
8039
|
-
|
|
8040
|
-
return (this
|
|
8134
|
+
#acquireRectangle(x, y, w, h) {
|
|
8135
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
8041
8136
|
}
|
|
8042
|
-
|
|
8043
|
-
const cellX = Math.floor(x / this
|
|
8137
|
+
#cellKeyFromCoords(x, y) {
|
|
8138
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
8044
8139
|
return `${cellX}_${cellY}`;
|
|
8045
8140
|
}
|
|
8046
|
-
|
|
8141
|
+
#getRangeBounds(range) {
|
|
8047
8142
|
if (range instanceof Circle) {
|
|
8048
8143
|
const r = range.radius, { x, y } = range.position;
|
|
8049
8144
|
return {
|
|
@@ -8064,53 +8159,53 @@
|
|
|
8064
8159
|
}
|
|
8065
8160
|
return null;
|
|
8066
8161
|
}
|
|
8067
|
-
|
|
8068
|
-
this
|
|
8069
|
-
this
|
|
8162
|
+
#releaseShapes() {
|
|
8163
|
+
this.#circlePoolIdx = 0;
|
|
8164
|
+
this.#rectanglePoolIdx = 0;
|
|
8070
8165
|
}
|
|
8071
8166
|
}
|
|
8072
8167
|
|
|
8073
8168
|
class ParticlesManager {
|
|
8074
8169
|
checkParticlePositionPlugins;
|
|
8075
8170
|
grid;
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8171
|
+
#array;
|
|
8172
|
+
#container;
|
|
8173
|
+
#groupLimits;
|
|
8174
|
+
#limit;
|
|
8175
|
+
#nextId;
|
|
8176
|
+
#particleBuckets;
|
|
8177
|
+
#particleResetPlugins;
|
|
8178
|
+
#particleUpdatePlugins;
|
|
8179
|
+
#pluginManager;
|
|
8180
|
+
#pool;
|
|
8181
|
+
#postParticleUpdatePlugins;
|
|
8182
|
+
#postUpdatePlugins;
|
|
8183
|
+
#resizeFactor;
|
|
8184
|
+
#updatePlugins;
|
|
8185
|
+
#zBuckets;
|
|
8091
8186
|
constructor(pluginManager, container) {
|
|
8092
|
-
this
|
|
8093
|
-
this
|
|
8094
|
-
this
|
|
8095
|
-
this
|
|
8096
|
-
this
|
|
8097
|
-
this
|
|
8098
|
-
this
|
|
8099
|
-
this
|
|
8100
|
-
this
|
|
8187
|
+
this.#pluginManager = pluginManager;
|
|
8188
|
+
this.#container = container;
|
|
8189
|
+
this.#nextId = 0;
|
|
8190
|
+
this.#array = [];
|
|
8191
|
+
this.#pool = [];
|
|
8192
|
+
this.#limit = 0;
|
|
8193
|
+
this.#groupLimits = new Map();
|
|
8194
|
+
this.#particleBuckets = new Map();
|
|
8195
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
8101
8196
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
8102
8197
|
this.checkParticlePositionPlugins = [];
|
|
8103
|
-
this
|
|
8104
|
-
this
|
|
8105
|
-
this
|
|
8106
|
-
this
|
|
8107
|
-
this
|
|
8198
|
+
this.#particleResetPlugins = [];
|
|
8199
|
+
this.#particleUpdatePlugins = [];
|
|
8200
|
+
this.#postUpdatePlugins = [];
|
|
8201
|
+
this.#postParticleUpdatePlugins = [];
|
|
8202
|
+
this.#updatePlugins = [];
|
|
8108
8203
|
}
|
|
8109
8204
|
get count() {
|
|
8110
|
-
return this.
|
|
8205
|
+
return this.#array.length;
|
|
8111
8206
|
}
|
|
8112
8207
|
addParticle(position, overrideOptions, group, initializer) {
|
|
8113
|
-
const limitMode = this.
|
|
8208
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
8114
8209
|
if (limit > minLimit) {
|
|
8115
8210
|
switch (limitMode) {
|
|
8116
8211
|
case exports.LimitMode.delete: {
|
|
@@ -8128,20 +8223,20 @@
|
|
|
8128
8223
|
}
|
|
8129
8224
|
}
|
|
8130
8225
|
try {
|
|
8131
|
-
const particle = this.
|
|
8132
|
-
particle.init(this
|
|
8226
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
8227
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
8133
8228
|
let canAdd = true;
|
|
8134
8229
|
if (initializer) {
|
|
8135
8230
|
canAdd = initializer(particle);
|
|
8136
8231
|
}
|
|
8137
8232
|
if (!canAdd) {
|
|
8138
|
-
this.
|
|
8233
|
+
this.#pool.push(particle);
|
|
8139
8234
|
return;
|
|
8140
8235
|
}
|
|
8141
|
-
this.
|
|
8142
|
-
this
|
|
8143
|
-
this
|
|
8144
|
-
this.
|
|
8236
|
+
this.#array.push(particle);
|
|
8237
|
+
this.#insertParticleIntoBucket(particle);
|
|
8238
|
+
this.#nextId++;
|
|
8239
|
+
this.#container.dispatchEvent(exports.EventType.particleAdded, {
|
|
8145
8240
|
particle,
|
|
8146
8241
|
});
|
|
8147
8242
|
return particle;
|
|
@@ -8152,25 +8247,25 @@
|
|
|
8152
8247
|
return undefined;
|
|
8153
8248
|
}
|
|
8154
8249
|
clear() {
|
|
8155
|
-
this
|
|
8156
|
-
this.
|
|
8157
|
-
this
|
|
8250
|
+
this.#array = [];
|
|
8251
|
+
this.#particleBuckets.clear();
|
|
8252
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
8158
8253
|
}
|
|
8159
8254
|
destroy() {
|
|
8160
|
-
this
|
|
8161
|
-
this.
|
|
8162
|
-
this.
|
|
8163
|
-
this
|
|
8255
|
+
this.#array = [];
|
|
8256
|
+
this.#pool.length = 0;
|
|
8257
|
+
this.#particleBuckets.clear();
|
|
8258
|
+
this.#zBuckets = [];
|
|
8164
8259
|
this.checkParticlePositionPlugins = [];
|
|
8165
|
-
this
|
|
8166
|
-
this
|
|
8167
|
-
this
|
|
8168
|
-
this
|
|
8169
|
-
this
|
|
8260
|
+
this.#particleResetPlugins = [];
|
|
8261
|
+
this.#particleUpdatePlugins = [];
|
|
8262
|
+
this.#postUpdatePlugins = [];
|
|
8263
|
+
this.#postParticleUpdatePlugins = [];
|
|
8264
|
+
this.#updatePlugins = [];
|
|
8170
8265
|
}
|
|
8171
8266
|
drawParticles(delta) {
|
|
8172
|
-
for (let i = this.
|
|
8173
|
-
const bucket = this
|
|
8267
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
8268
|
+
const bucket = this.#zBuckets[i];
|
|
8174
8269
|
if (!bucket) {
|
|
8175
8270
|
continue;
|
|
8176
8271
|
}
|
|
@@ -8180,24 +8275,24 @@
|
|
|
8180
8275
|
}
|
|
8181
8276
|
}
|
|
8182
8277
|
filter(condition) {
|
|
8183
|
-
return this.
|
|
8278
|
+
return this.#array.filter(condition);
|
|
8184
8279
|
}
|
|
8185
8280
|
find(condition) {
|
|
8186
|
-
return this.
|
|
8281
|
+
return this.#array.find(condition);
|
|
8187
8282
|
}
|
|
8188
8283
|
get(index) {
|
|
8189
|
-
return this
|
|
8284
|
+
return this.#array[index];
|
|
8190
8285
|
}
|
|
8191
8286
|
async init() {
|
|
8192
|
-
const container = this
|
|
8287
|
+
const container = this.#container, options = container.actualOptions;
|
|
8193
8288
|
this.checkParticlePositionPlugins = [];
|
|
8194
|
-
this
|
|
8195
|
-
this
|
|
8196
|
-
this
|
|
8197
|
-
this
|
|
8198
|
-
this
|
|
8199
|
-
this.
|
|
8200
|
-
this
|
|
8289
|
+
this.#updatePlugins = [];
|
|
8290
|
+
this.#particleUpdatePlugins = [];
|
|
8291
|
+
this.#postUpdatePlugins = [];
|
|
8292
|
+
this.#particleResetPlugins = [];
|
|
8293
|
+
this.#postParticleUpdatePlugins = [];
|
|
8294
|
+
this.#particleBuckets.clear();
|
|
8295
|
+
this.#resetBuckets(container.zLayers);
|
|
8201
8296
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
8202
8297
|
for (const plugin of container.plugins) {
|
|
8203
8298
|
if (plugin.redrawInit) {
|
|
@@ -8207,26 +8302,26 @@
|
|
|
8207
8302
|
this.checkParticlePositionPlugins.push(plugin);
|
|
8208
8303
|
}
|
|
8209
8304
|
if (plugin.update) {
|
|
8210
|
-
this.
|
|
8305
|
+
this.#updatePlugins.push(plugin);
|
|
8211
8306
|
}
|
|
8212
8307
|
if (plugin.particleUpdate) {
|
|
8213
|
-
this.
|
|
8308
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
8214
8309
|
}
|
|
8215
8310
|
if (plugin.postUpdate) {
|
|
8216
|
-
this.
|
|
8311
|
+
this.#postUpdatePlugins.push(plugin);
|
|
8217
8312
|
}
|
|
8218
8313
|
if (plugin.particleReset) {
|
|
8219
|
-
this.
|
|
8314
|
+
this.#particleResetPlugins.push(plugin);
|
|
8220
8315
|
}
|
|
8221
8316
|
if (plugin.postParticleUpdate) {
|
|
8222
|
-
this.
|
|
8317
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
8223
8318
|
}
|
|
8224
8319
|
}
|
|
8225
|
-
await this.
|
|
8226
|
-
for (const drawer of this.
|
|
8320
|
+
await this.#container.initDrawersAndUpdaters();
|
|
8321
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
8227
8322
|
await drawer.init?.(container);
|
|
8228
8323
|
}
|
|
8229
|
-
for (const drawer of this.
|
|
8324
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
8230
8325
|
await drawer.init?.(container);
|
|
8231
8326
|
}
|
|
8232
8327
|
let handled = false;
|
|
@@ -8260,10 +8355,10 @@
|
|
|
8260
8355
|
async redraw() {
|
|
8261
8356
|
this.clear();
|
|
8262
8357
|
await this.init();
|
|
8263
|
-
this.
|
|
8358
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
8264
8359
|
}
|
|
8265
8360
|
remove(particle, group, override) {
|
|
8266
|
-
this.removeAt(this.
|
|
8361
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
8267
8362
|
}
|
|
8268
8363
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
8269
8364
|
if (index < minIndex || index > this.count) {
|
|
@@ -8271,7 +8366,7 @@
|
|
|
8271
8366
|
}
|
|
8272
8367
|
let deleted = 0;
|
|
8273
8368
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
8274
|
-
if (this
|
|
8369
|
+
if (this.#removeParticle(i, group, override)) {
|
|
8275
8370
|
i--;
|
|
8276
8371
|
deleted++;
|
|
8277
8372
|
}
|
|
@@ -8281,9 +8376,9 @@
|
|
|
8281
8376
|
this.removeAt(minIndex, quantity, group);
|
|
8282
8377
|
}
|
|
8283
8378
|
setDensity() {
|
|
8284
|
-
const options = this.
|
|
8379
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
8285
8380
|
let pluginsCount = 0;
|
|
8286
|
-
for (const plugin of this.
|
|
8381
|
+
for (const plugin of this.#container.plugins) {
|
|
8287
8382
|
if (plugin.particlesDensityCount) {
|
|
8288
8383
|
pluginsCount += plugin.particlesDensityCount();
|
|
8289
8384
|
}
|
|
@@ -8293,51 +8388,51 @@
|
|
|
8293
8388
|
if (!groupData) {
|
|
8294
8389
|
continue;
|
|
8295
8390
|
}
|
|
8296
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
8297
|
-
this
|
|
8391
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
8392
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
8298
8393
|
}
|
|
8299
|
-
this
|
|
8394
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
8300
8395
|
}
|
|
8301
8396
|
setResizeFactor(factor) {
|
|
8302
|
-
this
|
|
8397
|
+
this.#resizeFactor = factor;
|
|
8303
8398
|
}
|
|
8304
8399
|
update(delta) {
|
|
8305
8400
|
this.grid.clear();
|
|
8306
|
-
for (const plugin of this
|
|
8401
|
+
for (const plugin of this.#updatePlugins) {
|
|
8307
8402
|
plugin.update?.(delta);
|
|
8308
8403
|
}
|
|
8309
|
-
const particlesToDelete = this
|
|
8310
|
-
for (const plugin of this
|
|
8404
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
8405
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
8311
8406
|
plugin.postUpdate?.(delta);
|
|
8312
8407
|
}
|
|
8313
|
-
this
|
|
8408
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
8314
8409
|
if (particlesToDelete.size) {
|
|
8315
8410
|
for (const particle of particlesToDelete) {
|
|
8316
8411
|
this.remove(particle);
|
|
8317
8412
|
}
|
|
8318
8413
|
}
|
|
8319
|
-
|
|
8414
|
+
this.#resizeFactor = undefined;
|
|
8320
8415
|
}
|
|
8321
|
-
|
|
8322
|
-
this.
|
|
8416
|
+
#addToPool = (...particles) => {
|
|
8417
|
+
this.#pool.push(...particles);
|
|
8323
8418
|
};
|
|
8324
|
-
|
|
8419
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
8325
8420
|
const numberOptions = options.number;
|
|
8326
8421
|
if (!numberOptions.density.enable) {
|
|
8327
8422
|
if (group === undefined) {
|
|
8328
|
-
this
|
|
8423
|
+
this.#limit = numberOptions.limit.value;
|
|
8329
8424
|
}
|
|
8330
8425
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
8331
|
-
this.
|
|
8426
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
8332
8427
|
}
|
|
8333
8428
|
return;
|
|
8334
8429
|
}
|
|
8335
|
-
const densityFactor = this
|
|
8430
|
+
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);
|
|
8336
8431
|
if (group === undefined) {
|
|
8337
|
-
this
|
|
8432
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
8338
8433
|
}
|
|
8339
8434
|
else {
|
|
8340
|
-
this.
|
|
8435
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
8341
8436
|
}
|
|
8342
8437
|
if (particlesCount < particlesNumber) {
|
|
8343
8438
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -8346,18 +8441,18 @@
|
|
|
8346
8441
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
8347
8442
|
}
|
|
8348
8443
|
};
|
|
8349
|
-
|
|
8444
|
+
#createBuckets = (zLayers) => {
|
|
8350
8445
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
8351
8446
|
return Array.from({ length: bucketCount }, () => []);
|
|
8352
8447
|
};
|
|
8353
|
-
|
|
8354
|
-
const maxBucketIndex = this.
|
|
8448
|
+
#getBucketIndex = (zIndex) => {
|
|
8449
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
8355
8450
|
if (maxBucketIndex <= minIndex) {
|
|
8356
8451
|
return minIndex;
|
|
8357
8452
|
}
|
|
8358
8453
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
8359
8454
|
};
|
|
8360
|
-
|
|
8455
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
8361
8456
|
let start = minIndex, end = bucket.length;
|
|
8362
8457
|
while (start < end) {
|
|
8363
8458
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -8374,8 +8469,8 @@
|
|
|
8374
8469
|
}
|
|
8375
8470
|
return start;
|
|
8376
8471
|
};
|
|
8377
|
-
|
|
8378
|
-
const container = this
|
|
8472
|
+
#initDensityFactor = densityOptions => {
|
|
8473
|
+
const container = this.#container;
|
|
8379
8474
|
if (!densityOptions.enable) {
|
|
8380
8475
|
return defaultDensityFactor;
|
|
8381
8476
|
}
|
|
@@ -8385,82 +8480,82 @@
|
|
|
8385
8480
|
}
|
|
8386
8481
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
8387
8482
|
};
|
|
8388
|
-
|
|
8389
|
-
const bucketIndex = this
|
|
8483
|
+
#insertParticleIntoBucket = (particle) => {
|
|
8484
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
8390
8485
|
if (!bucket) {
|
|
8391
8486
|
return;
|
|
8392
8487
|
}
|
|
8393
|
-
bucket.splice(this
|
|
8394
|
-
this.
|
|
8488
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
8489
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
8395
8490
|
};
|
|
8396
|
-
|
|
8397
|
-
const particle = this
|
|
8491
|
+
#removeParticle = (index, group, override) => {
|
|
8492
|
+
const particle = this.#array[index];
|
|
8398
8493
|
if (!particle) {
|
|
8399
8494
|
return false;
|
|
8400
8495
|
}
|
|
8401
8496
|
if (particle.group !== group) {
|
|
8402
8497
|
return false;
|
|
8403
8498
|
}
|
|
8404
|
-
this.
|
|
8405
|
-
this
|
|
8499
|
+
this.#array.splice(index, deleteCount);
|
|
8500
|
+
this.#removeParticleFromBucket(particle);
|
|
8406
8501
|
particle.destroy(override);
|
|
8407
|
-
this.
|
|
8502
|
+
this.#container.dispatchEvent(exports.EventType.particleRemoved, {
|
|
8408
8503
|
particle,
|
|
8409
8504
|
});
|
|
8410
|
-
this
|
|
8505
|
+
this.#addToPool(particle);
|
|
8411
8506
|
return true;
|
|
8412
8507
|
};
|
|
8413
|
-
|
|
8414
|
-
const bucketIndex = this.
|
|
8508
|
+
#removeParticleFromBucket = (particle) => {
|
|
8509
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
8415
8510
|
if (!bucket) {
|
|
8416
|
-
this.
|
|
8511
|
+
this.#particleBuckets.delete(particle.id);
|
|
8417
8512
|
return;
|
|
8418
8513
|
}
|
|
8419
|
-
const particleIndex = this
|
|
8514
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
8420
8515
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
8421
|
-
this.
|
|
8516
|
+
this.#particleBuckets.delete(particle.id);
|
|
8422
8517
|
return;
|
|
8423
8518
|
}
|
|
8424
8519
|
bucket.splice(particleIndex, deleteCount);
|
|
8425
|
-
this.
|
|
8520
|
+
this.#particleBuckets.delete(particle.id);
|
|
8426
8521
|
};
|
|
8427
|
-
|
|
8522
|
+
#resetBuckets = (zLayers) => {
|
|
8428
8523
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
8429
|
-
if (this.
|
|
8430
|
-
this
|
|
8524
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
8525
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
8431
8526
|
return;
|
|
8432
8527
|
}
|
|
8433
|
-
for (const bucket of this
|
|
8528
|
+
for (const bucket of this.#zBuckets) {
|
|
8434
8529
|
bucket.length = minIndex;
|
|
8435
8530
|
}
|
|
8436
8531
|
};
|
|
8437
|
-
|
|
8438
|
-
const newBucketIndex = this
|
|
8532
|
+
#updateParticleBucket = (particle) => {
|
|
8533
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
8439
8534
|
if (currentBucketIndex === undefined) {
|
|
8440
|
-
this
|
|
8535
|
+
this.#insertParticleIntoBucket(particle);
|
|
8441
8536
|
return;
|
|
8442
8537
|
}
|
|
8443
8538
|
if (currentBucketIndex === newBucketIndex) {
|
|
8444
8539
|
return;
|
|
8445
8540
|
}
|
|
8446
|
-
const currentBucket = this
|
|
8541
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
8447
8542
|
if (currentBucket) {
|
|
8448
|
-
const particleIndex = this
|
|
8543
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
8449
8544
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
8450
8545
|
currentBucket.splice(particleIndex, deleteCount);
|
|
8451
8546
|
}
|
|
8452
8547
|
}
|
|
8453
|
-
const newBucket = this
|
|
8548
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
8454
8549
|
if (!newBucket) {
|
|
8455
|
-
this.
|
|
8550
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
8456
8551
|
return;
|
|
8457
8552
|
}
|
|
8458
|
-
newBucket.splice(this
|
|
8459
|
-
this.
|
|
8553
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
8554
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
8460
8555
|
};
|
|
8461
|
-
|
|
8462
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
8463
|
-
for (const particle of this
|
|
8556
|
+
#updateParticlesPhase1 = (delta) => {
|
|
8557
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
8558
|
+
for (const particle of this.#array) {
|
|
8464
8559
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
8465
8560
|
particle.position.x *= resizeFactor.width;
|
|
8466
8561
|
particle.position.y *= resizeFactor.height;
|
|
@@ -8468,10 +8563,10 @@
|
|
|
8468
8563
|
particle.initialPosition.y *= resizeFactor.height;
|
|
8469
8564
|
}
|
|
8470
8565
|
particle.ignoresResizeRatio = false;
|
|
8471
|
-
for (const plugin of this
|
|
8566
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
8472
8567
|
plugin.particleReset?.(particle);
|
|
8473
8568
|
}
|
|
8474
|
-
for (const plugin of this
|
|
8569
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
8475
8570
|
if (particle.destroyed) {
|
|
8476
8571
|
break;
|
|
8477
8572
|
}
|
|
@@ -8485,36 +8580,36 @@
|
|
|
8485
8580
|
}
|
|
8486
8581
|
return particlesToDelete;
|
|
8487
8582
|
};
|
|
8488
|
-
|
|
8489
|
-
for (const particle of this
|
|
8583
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
8584
|
+
for (const particle of this.#array) {
|
|
8490
8585
|
if (particle.destroyed) {
|
|
8491
8586
|
particlesToDelete.add(particle);
|
|
8492
8587
|
continue;
|
|
8493
8588
|
}
|
|
8494
|
-
for (const updater of this.
|
|
8589
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
8495
8590
|
updater.update(particle, delta);
|
|
8496
8591
|
}
|
|
8497
8592
|
if (!particle.spawning) {
|
|
8498
|
-
for (const plugin of this
|
|
8593
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
8499
8594
|
plugin.postParticleUpdate?.(particle, delta);
|
|
8500
8595
|
}
|
|
8501
8596
|
}
|
|
8502
|
-
this
|
|
8597
|
+
this.#updateParticleBucket(particle);
|
|
8503
8598
|
}
|
|
8504
8599
|
};
|
|
8505
8600
|
}
|
|
8506
8601
|
|
|
8507
8602
|
class Retina {
|
|
8508
|
-
container;
|
|
8509
8603
|
pixelRatio;
|
|
8510
8604
|
reduceFactor;
|
|
8605
|
+
#container;
|
|
8511
8606
|
constructor(container) {
|
|
8512
|
-
this
|
|
8607
|
+
this.#container = container;
|
|
8513
8608
|
this.pixelRatio = defaultRatio;
|
|
8514
8609
|
this.reduceFactor = defaultReduceFactor;
|
|
8515
8610
|
}
|
|
8516
8611
|
init() {
|
|
8517
|
-
const container = this
|
|
8612
|
+
const container = this.#container, options = container.actualOptions;
|
|
8518
8613
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
8519
8614
|
this.reduceFactor = defaultReduceFactor;
|
|
8520
8615
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -8528,7 +8623,6 @@
|
|
|
8528
8623
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
8529
8624
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
8530
8625
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
8531
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
8532
8626
|
const maxDistance = props.maxDistance;
|
|
8533
8627
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
8534
8628
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -8566,73 +8660,73 @@
|
|
|
8566
8660
|
shapeDrawers;
|
|
8567
8661
|
started;
|
|
8568
8662
|
zLayers;
|
|
8569
|
-
|
|
8570
|
-
|
|
8571
|
-
|
|
8572
|
-
|
|
8573
|
-
|
|
8574
|
-
|
|
8575
|
-
|
|
8576
|
-
|
|
8577
|
-
|
|
8578
|
-
|
|
8579
|
-
|
|
8580
|
-
|
|
8581
|
-
|
|
8582
|
-
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8663
|
+
#delay;
|
|
8664
|
+
#delayTimeout;
|
|
8665
|
+
#delta = { value: 0, factor: 0 };
|
|
8666
|
+
#dispatchCallback;
|
|
8667
|
+
#drawAnimationFrame;
|
|
8668
|
+
#duration;
|
|
8669
|
+
#eventListeners;
|
|
8670
|
+
#firstStart;
|
|
8671
|
+
#initialSourceOptions;
|
|
8672
|
+
#lastFrameTime;
|
|
8673
|
+
#lifeTime;
|
|
8674
|
+
#onDestroy;
|
|
8675
|
+
#options;
|
|
8676
|
+
#paused;
|
|
8677
|
+
#pluginManager;
|
|
8678
|
+
#smooth;
|
|
8679
|
+
#sourceOptions;
|
|
8586
8680
|
constructor(params) {
|
|
8587
8681
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
8588
|
-
this
|
|
8589
|
-
this
|
|
8590
|
-
this
|
|
8682
|
+
this.#pluginManager = pluginManager;
|
|
8683
|
+
this.#dispatchCallback = dispatchCallback;
|
|
8684
|
+
this.#onDestroy = onDestroy;
|
|
8591
8685
|
this.id = Symbol(id);
|
|
8592
8686
|
this.fpsLimit = 120;
|
|
8593
8687
|
this.hdr = false;
|
|
8594
|
-
this
|
|
8595
|
-
this
|
|
8596
|
-
this
|
|
8597
|
-
this
|
|
8598
|
-
this
|
|
8688
|
+
this.#smooth = false;
|
|
8689
|
+
this.#delay = 0;
|
|
8690
|
+
this.#duration = 0;
|
|
8691
|
+
this.#lifeTime = 0;
|
|
8692
|
+
this.#firstStart = true;
|
|
8599
8693
|
this.started = false;
|
|
8600
8694
|
this.destroyed = false;
|
|
8601
|
-
this
|
|
8602
|
-
this
|
|
8695
|
+
this.#paused = true;
|
|
8696
|
+
this.#lastFrameTime = 0;
|
|
8603
8697
|
this.zLayers = 100;
|
|
8604
8698
|
this.pageHidden = false;
|
|
8605
|
-
this
|
|
8606
|
-
this
|
|
8699
|
+
this.#sourceOptions = sourceOptions;
|
|
8700
|
+
this.#initialSourceOptions = sourceOptions;
|
|
8607
8701
|
this.effectDrawers = new Map();
|
|
8608
8702
|
this.shapeDrawers = new Map();
|
|
8609
8703
|
this.particleUpdaters = [];
|
|
8610
8704
|
this.retina = new Retina(this);
|
|
8611
|
-
this.canvas = new CanvasManager(this
|
|
8612
|
-
this.particles = new ParticlesManager(this
|
|
8705
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
8706
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
8613
8707
|
this.plugins = [];
|
|
8614
8708
|
this.particleDestroyedPlugins = [];
|
|
8615
8709
|
this.particleCreatedPlugins = [];
|
|
8616
8710
|
this.particlePositionPlugins = [];
|
|
8617
|
-
this
|
|
8618
|
-
this.actualOptions = loadContainerOptions(this
|
|
8619
|
-
this
|
|
8711
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
8712
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
8713
|
+
this.#eventListeners = new EventListeners(this);
|
|
8620
8714
|
this.dispatchEvent(exports.EventType.containerBuilt);
|
|
8621
8715
|
}
|
|
8622
8716
|
get animationStatus() {
|
|
8623
|
-
return !this
|
|
8717
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
8624
8718
|
}
|
|
8625
8719
|
get options() {
|
|
8626
|
-
return this
|
|
8720
|
+
return this.#options;
|
|
8627
8721
|
}
|
|
8628
8722
|
get sourceOptions() {
|
|
8629
|
-
return this
|
|
8723
|
+
return this.#sourceOptions;
|
|
8630
8724
|
}
|
|
8631
8725
|
addLifeTime(value) {
|
|
8632
|
-
this
|
|
8726
|
+
this.#lifeTime += value;
|
|
8633
8727
|
}
|
|
8634
8728
|
alive() {
|
|
8635
|
-
return !this
|
|
8729
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
8636
8730
|
}
|
|
8637
8731
|
destroy(remove = true) {
|
|
8638
8732
|
if (!guardCheck(this)) {
|
|
@@ -8654,13 +8748,13 @@
|
|
|
8654
8748
|
this.shapeDrawers = new Map();
|
|
8655
8749
|
this.particleUpdaters = [];
|
|
8656
8750
|
this.plugins.length = 0;
|
|
8657
|
-
this.
|
|
8751
|
+
this.#pluginManager.clearPlugins(this);
|
|
8658
8752
|
this.destroyed = true;
|
|
8659
|
-
this
|
|
8753
|
+
this.#onDestroy(remove);
|
|
8660
8754
|
this.dispatchEvent(exports.EventType.containerDestroyed);
|
|
8661
8755
|
}
|
|
8662
8756
|
dispatchEvent(type, data) {
|
|
8663
|
-
this
|
|
8757
|
+
this.#dispatchCallback(type, {
|
|
8664
8758
|
container: this,
|
|
8665
8759
|
data,
|
|
8666
8760
|
});
|
|
@@ -8670,12 +8764,12 @@
|
|
|
8670
8764
|
return;
|
|
8671
8765
|
}
|
|
8672
8766
|
let refreshTime = force;
|
|
8673
|
-
this
|
|
8767
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
8674
8768
|
if (refreshTime) {
|
|
8675
|
-
this
|
|
8769
|
+
this.#lastFrameTime = undefined;
|
|
8676
8770
|
refreshTime = false;
|
|
8677
8771
|
}
|
|
8678
|
-
this
|
|
8772
|
+
this.#nextFrame(timestamp);
|
|
8679
8773
|
});
|
|
8680
8774
|
}
|
|
8681
8775
|
async export(type, options = {}) {
|
|
@@ -8697,7 +8791,7 @@
|
|
|
8697
8791
|
return;
|
|
8698
8792
|
}
|
|
8699
8793
|
const allContainerPlugins = new Map();
|
|
8700
|
-
for (const plugin of this.
|
|
8794
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
8701
8795
|
const containerPlugin = await plugin.getPlugin(this);
|
|
8702
8796
|
if (containerPlugin.preInit) {
|
|
8703
8797
|
await containerPlugin.preInit();
|
|
@@ -8705,8 +8799,8 @@
|
|
|
8705
8799
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
8706
8800
|
}
|
|
8707
8801
|
await this.initDrawersAndUpdaters();
|
|
8708
|
-
this
|
|
8709
|
-
this.actualOptions = loadContainerOptions(this
|
|
8802
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
8803
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
8710
8804
|
this.plugins.length = 0;
|
|
8711
8805
|
this.particleDestroyedPlugins.length = 0;
|
|
8712
8806
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -8733,11 +8827,11 @@
|
|
|
8733
8827
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
8734
8828
|
this.hdr = hdr;
|
|
8735
8829
|
this.zLayers = zLayers;
|
|
8736
|
-
this
|
|
8737
|
-
this
|
|
8738
|
-
this
|
|
8830
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
8831
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
8832
|
+
this.#lifeTime = 0;
|
|
8739
8833
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
8740
|
-
this
|
|
8834
|
+
this.#smooth = smooth;
|
|
8741
8835
|
for (const plugin of this.plugins) {
|
|
8742
8836
|
await plugin.init?.();
|
|
8743
8837
|
}
|
|
@@ -8750,7 +8844,7 @@
|
|
|
8750
8844
|
this.dispatchEvent(exports.EventType.particlesSetup);
|
|
8751
8845
|
}
|
|
8752
8846
|
async initDrawersAndUpdaters() {
|
|
8753
|
-
const pluginManager = this
|
|
8847
|
+
const pluginManager = this.#pluginManager;
|
|
8754
8848
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
8755
8849
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
8756
8850
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -8759,18 +8853,18 @@
|
|
|
8759
8853
|
if (!guardCheck(this)) {
|
|
8760
8854
|
return;
|
|
8761
8855
|
}
|
|
8762
|
-
if (this
|
|
8763
|
-
cancelAnimation(this
|
|
8764
|
-
|
|
8856
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
8857
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
8858
|
+
this.#drawAnimationFrame = undefined;
|
|
8765
8859
|
}
|
|
8766
|
-
if (this
|
|
8860
|
+
if (this.#paused) {
|
|
8767
8861
|
return;
|
|
8768
8862
|
}
|
|
8769
8863
|
for (const plugin of this.plugins) {
|
|
8770
8864
|
plugin.pause?.();
|
|
8771
8865
|
}
|
|
8772
8866
|
if (!this.pageHidden) {
|
|
8773
|
-
this
|
|
8867
|
+
this.#paused = true;
|
|
8774
8868
|
}
|
|
8775
8869
|
this.dispatchEvent(exports.EventType.containerPaused);
|
|
8776
8870
|
}
|
|
@@ -8778,13 +8872,13 @@
|
|
|
8778
8872
|
if (!guardCheck(this)) {
|
|
8779
8873
|
return;
|
|
8780
8874
|
}
|
|
8781
|
-
const needsUpdate = this
|
|
8782
|
-
if (this
|
|
8783
|
-
this
|
|
8875
|
+
const needsUpdate = this.#paused || force;
|
|
8876
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
8877
|
+
this.#firstStart = false;
|
|
8784
8878
|
return;
|
|
8785
8879
|
}
|
|
8786
|
-
if (this
|
|
8787
|
-
this
|
|
8880
|
+
if (this.#paused) {
|
|
8881
|
+
this.#paused = false;
|
|
8788
8882
|
}
|
|
8789
8883
|
if (needsUpdate) {
|
|
8790
8884
|
for (const plugin of this.plugins) {
|
|
@@ -8807,10 +8901,10 @@
|
|
|
8807
8901
|
if (!guardCheck(this)) {
|
|
8808
8902
|
return;
|
|
8809
8903
|
}
|
|
8810
|
-
this
|
|
8811
|
-
this
|
|
8812
|
-
this
|
|
8813
|
-
this.actualOptions = loadContainerOptions(this
|
|
8904
|
+
this.#initialSourceOptions = sourceOptions;
|
|
8905
|
+
this.#sourceOptions = sourceOptions;
|
|
8906
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
8907
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
8814
8908
|
return this.refresh();
|
|
8815
8909
|
}
|
|
8816
8910
|
async start() {
|
|
@@ -8821,7 +8915,7 @@
|
|
|
8821
8915
|
this.started = true;
|
|
8822
8916
|
await new Promise(resolve => {
|
|
8823
8917
|
const start = async () => {
|
|
8824
|
-
this.
|
|
8918
|
+
this.#eventListeners.addListeners();
|
|
8825
8919
|
for (const plugin of this.plugins) {
|
|
8826
8920
|
await plugin.start?.();
|
|
8827
8921
|
}
|
|
@@ -8829,20 +8923,20 @@
|
|
|
8829
8923
|
this.play();
|
|
8830
8924
|
resolve();
|
|
8831
8925
|
};
|
|
8832
|
-
this
|
|
8926
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
8833
8927
|
});
|
|
8834
8928
|
}
|
|
8835
8929
|
stop() {
|
|
8836
8930
|
if (!guardCheck(this) || !this.started) {
|
|
8837
8931
|
return;
|
|
8838
8932
|
}
|
|
8839
|
-
if (this
|
|
8840
|
-
clearTimeout(this
|
|
8841
|
-
|
|
8933
|
+
if (this.#delayTimeout) {
|
|
8934
|
+
clearTimeout(this.#delayTimeout);
|
|
8935
|
+
this.#delayTimeout = undefined;
|
|
8842
8936
|
}
|
|
8843
|
-
this
|
|
8937
|
+
this.#firstStart = true;
|
|
8844
8938
|
this.started = false;
|
|
8845
|
-
this.
|
|
8939
|
+
this.#eventListeners.removeListeners();
|
|
8846
8940
|
this.pause();
|
|
8847
8941
|
this.particles.clear();
|
|
8848
8942
|
this.canvas.stop();
|
|
@@ -8852,7 +8946,7 @@
|
|
|
8852
8946
|
this.particleCreatedPlugins.length = 0;
|
|
8853
8947
|
this.particleDestroyedPlugins.length = 0;
|
|
8854
8948
|
this.particlePositionPlugins.length = 0;
|
|
8855
|
-
this
|
|
8949
|
+
this.#sourceOptions = this.#options;
|
|
8856
8950
|
this.dispatchEvent(exports.EventType.containerStopped);
|
|
8857
8951
|
}
|
|
8858
8952
|
updateActualOptions() {
|
|
@@ -8864,23 +8958,23 @@
|
|
|
8864
8958
|
}
|
|
8865
8959
|
return refresh;
|
|
8866
8960
|
}
|
|
8867
|
-
|
|
8961
|
+
#nextFrame = (timestamp) => {
|
|
8868
8962
|
try {
|
|
8869
|
-
if (!this
|
|
8870
|
-
this
|
|
8871
|
-
timestamp < this
|
|
8963
|
+
if (!this.#smooth &&
|
|
8964
|
+
this.#lastFrameTime !== undefined &&
|
|
8965
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
8872
8966
|
this.draw(false);
|
|
8873
8967
|
return;
|
|
8874
8968
|
}
|
|
8875
|
-
this
|
|
8876
|
-
updateDelta(this
|
|
8877
|
-
this.addLifeTime(this.
|
|
8878
|
-
this
|
|
8879
|
-
if (this.
|
|
8969
|
+
this.#lastFrameTime ??= timestamp;
|
|
8970
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
8971
|
+
this.addLifeTime(this.#delta.value);
|
|
8972
|
+
this.#lastFrameTime = timestamp;
|
|
8973
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
8880
8974
|
this.draw(false);
|
|
8881
8975
|
return;
|
|
8882
8976
|
}
|
|
8883
|
-
this.canvas.render.drawParticles(this
|
|
8977
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
8884
8978
|
if (!this.alive()) {
|
|
8885
8979
|
this.destroy();
|
|
8886
8980
|
return;
|
|
@@ -8901,10 +8995,10 @@
|
|
|
8901
8995
|
});
|
|
8902
8996
|
|
|
8903
8997
|
class BlendPluginInstance {
|
|
8904
|
-
|
|
8905
|
-
|
|
8998
|
+
#container;
|
|
8999
|
+
#defaultCompositeValue;
|
|
8906
9000
|
constructor(container) {
|
|
8907
|
-
this
|
|
9001
|
+
this.#container = container;
|
|
8908
9002
|
}
|
|
8909
9003
|
drawParticleCleanup(context, particle) {
|
|
8910
9004
|
if (!particle.options.blend?.enable) {
|
|
@@ -8921,14 +9015,14 @@
|
|
|
8921
9015
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
8922
9016
|
}
|
|
8923
9017
|
drawSettingsCleanup(context) {
|
|
8924
|
-
if (!this
|
|
9018
|
+
if (!this.#defaultCompositeValue) {
|
|
8925
9019
|
return;
|
|
8926
9020
|
}
|
|
8927
|
-
context.globalCompositeOperation = this
|
|
9021
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
8928
9022
|
}
|
|
8929
9023
|
drawSettingsSetup(context) {
|
|
8930
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
8931
|
-
this
|
|
9024
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
9025
|
+
this.#defaultCompositeValue = previousComposite;
|
|
8932
9026
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
8933
9027
|
}
|
|
8934
9028
|
}
|
|
@@ -9071,11 +9165,11 @@
|
|
|
9071
9165
|
class MovePluginInstance {
|
|
9072
9166
|
availablePathGenerators;
|
|
9073
9167
|
pathGenerators;
|
|
9074
|
-
|
|
9075
|
-
|
|
9168
|
+
#container;
|
|
9169
|
+
#pluginManager;
|
|
9076
9170
|
constructor(pluginManager, container) {
|
|
9077
|
-
this
|
|
9078
|
-
this
|
|
9171
|
+
this.#pluginManager = pluginManager;
|
|
9172
|
+
this.#container = container;
|
|
9079
9173
|
this.availablePathGenerators = new Map();
|
|
9080
9174
|
this.pathGenerators = new Map();
|
|
9081
9175
|
}
|
|
@@ -9106,7 +9200,7 @@
|
|
|
9106
9200
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
9107
9201
|
inverse: gravityOptions.inverse,
|
|
9108
9202
|
};
|
|
9109
|
-
initSpin(this
|
|
9203
|
+
initSpin(this.#container, particle);
|
|
9110
9204
|
}
|
|
9111
9205
|
particleDestroyed(particle) {
|
|
9112
9206
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -9117,7 +9211,7 @@
|
|
|
9117
9211
|
if (!moveOptions.enable) {
|
|
9118
9212
|
return;
|
|
9119
9213
|
}
|
|
9120
|
-
const container = this
|
|
9214
|
+
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;
|
|
9121
9215
|
if (moveOptions.spin.enable) {
|
|
9122
9216
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
9123
9217
|
}
|
|
@@ -9127,18 +9221,18 @@
|
|
|
9127
9221
|
applyDistance(particle);
|
|
9128
9222
|
}
|
|
9129
9223
|
preInit() {
|
|
9130
|
-
return this
|
|
9224
|
+
return this.#init();
|
|
9131
9225
|
}
|
|
9132
9226
|
redrawInit() {
|
|
9133
|
-
return this
|
|
9227
|
+
return this.#init();
|
|
9134
9228
|
}
|
|
9135
9229
|
update() {
|
|
9136
9230
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
9137
9231
|
pathGenerator.update();
|
|
9138
9232
|
}
|
|
9139
9233
|
}
|
|
9140
|
-
async
|
|
9141
|
-
const availablePathGenerators = await this.
|
|
9234
|
+
async #init() {
|
|
9235
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
9142
9236
|
if (!availablePathGenerators) {
|
|
9143
9237
|
return;
|
|
9144
9238
|
}
|
|
@@ -9156,44 +9250,44 @@
|
|
|
9156
9250
|
});
|
|
9157
9251
|
|
|
9158
9252
|
class EmittersPluginInstance {
|
|
9159
|
-
container;
|
|
9160
|
-
|
|
9253
|
+
#container;
|
|
9254
|
+
#instancesManager;
|
|
9161
9255
|
constructor(instancesManager, container) {
|
|
9162
|
-
this
|
|
9163
|
-
this
|
|
9164
|
-
this.
|
|
9256
|
+
this.#instancesManager = instancesManager;
|
|
9257
|
+
this.#container = container;
|
|
9258
|
+
this.#instancesManager.initContainer(container);
|
|
9165
9259
|
}
|
|
9166
9260
|
async init() {
|
|
9167
|
-
const emittersOptions = this
|
|
9261
|
+
const emittersOptions = this.#container.actualOptions.emitters;
|
|
9168
9262
|
if (isArray(emittersOptions)) {
|
|
9169
9263
|
for (const emitterOptions of emittersOptions) {
|
|
9170
|
-
await this.
|
|
9264
|
+
await this.#instancesManager.addEmitter(this.#container, emitterOptions);
|
|
9171
9265
|
}
|
|
9172
9266
|
}
|
|
9173
9267
|
else {
|
|
9174
|
-
await this.
|
|
9268
|
+
await this.#instancesManager.addEmitter(this.#container, emittersOptions);
|
|
9175
9269
|
}
|
|
9176
9270
|
}
|
|
9177
9271
|
pause() {
|
|
9178
|
-
for (const emitter of this.
|
|
9272
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
9179
9273
|
emitter.pause();
|
|
9180
9274
|
}
|
|
9181
9275
|
}
|
|
9182
9276
|
play() {
|
|
9183
|
-
for (const emitter of this.
|
|
9277
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
9184
9278
|
emitter.play();
|
|
9185
9279
|
}
|
|
9186
9280
|
}
|
|
9187
9281
|
resize() {
|
|
9188
|
-
for (const emitter of this.
|
|
9282
|
+
for (const emitter of this.#instancesManager.getArray(this.#container)) {
|
|
9189
9283
|
emitter.resize();
|
|
9190
9284
|
}
|
|
9191
9285
|
}
|
|
9192
9286
|
stop() {
|
|
9193
|
-
this.
|
|
9287
|
+
this.#instancesManager.clear(this.#container);
|
|
9194
9288
|
}
|
|
9195
9289
|
update(delta) {
|
|
9196
|
-
this.
|
|
9290
|
+
this.#instancesManager.getArray(this.#container).forEach(emitter => {
|
|
9197
9291
|
emitter.update(delta);
|
|
9198
9292
|
});
|
|
9199
9293
|
}
|
|
@@ -9226,16 +9320,16 @@
|
|
|
9226
9320
|
|
|
9227
9321
|
const defaultIndex = 0;
|
|
9228
9322
|
class EmittersInstancesManager {
|
|
9229
|
-
|
|
9230
|
-
|
|
9323
|
+
#containerArrays;
|
|
9324
|
+
#pluginManager;
|
|
9231
9325
|
constructor(pluginManager) {
|
|
9232
|
-
this
|
|
9233
|
-
this
|
|
9326
|
+
this.#containerArrays = new Map();
|
|
9327
|
+
this.#pluginManager = pluginManager;
|
|
9234
9328
|
}
|
|
9235
9329
|
async addEmitter(container, options, position) {
|
|
9236
9330
|
const emitterOptions = new Emitter();
|
|
9237
9331
|
emitterOptions.load(options);
|
|
9238
|
-
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this
|
|
9332
|
+
const { EmitterInstance } = await Promise.resolve().then(function () { return EmitterInstance$1; }), emitter = new EmitterInstance(this.#pluginManager, container, (emitter) => {
|
|
9239
9333
|
this.removeEmitter(container, emitter);
|
|
9240
9334
|
}, emitterOptions, position);
|
|
9241
9335
|
await emitter.init();
|
|
@@ -9244,22 +9338,22 @@
|
|
|
9244
9338
|
}
|
|
9245
9339
|
clear(container) {
|
|
9246
9340
|
this.initContainer(container);
|
|
9247
|
-
this.
|
|
9341
|
+
this.#containerArrays.set(container, []);
|
|
9248
9342
|
}
|
|
9249
9343
|
getArray(container) {
|
|
9250
9344
|
this.initContainer(container);
|
|
9251
|
-
let array = this.
|
|
9345
|
+
let array = this.#containerArrays.get(container);
|
|
9252
9346
|
if (!array) {
|
|
9253
9347
|
array = [];
|
|
9254
|
-
this.
|
|
9348
|
+
this.#containerArrays.set(container, array);
|
|
9255
9349
|
}
|
|
9256
9350
|
return array;
|
|
9257
9351
|
}
|
|
9258
9352
|
initContainer(container) {
|
|
9259
|
-
if (this.
|
|
9353
|
+
if (this.#containerArrays.has(container)) {
|
|
9260
9354
|
return;
|
|
9261
9355
|
}
|
|
9262
|
-
this.
|
|
9356
|
+
this.#containerArrays.set(container, []);
|
|
9263
9357
|
container.getEmitter = (idxOrName) => {
|
|
9264
9358
|
const array = this.getArray(container);
|
|
9265
9359
|
return idxOrName === undefined || isNumber(idxOrName)
|
|
@@ -9300,14 +9394,14 @@
|
|
|
9300
9394
|
});
|
|
9301
9395
|
|
|
9302
9396
|
class ImagePreloaderInstance {
|
|
9303
|
-
|
|
9304
|
-
|
|
9397
|
+
#container;
|
|
9398
|
+
#engine;
|
|
9305
9399
|
constructor(engine, container) {
|
|
9306
|
-
this
|
|
9307
|
-
this
|
|
9400
|
+
this.#engine = engine;
|
|
9401
|
+
this.#container = container;
|
|
9308
9402
|
}
|
|
9309
9403
|
destroy() {
|
|
9310
|
-
this.
|
|
9404
|
+
this.#engine.images?.delete(this.#container);
|
|
9311
9405
|
}
|
|
9312
9406
|
}
|
|
9313
9407
|
|
|
@@ -9318,12 +9412,12 @@
|
|
|
9318
9412
|
|
|
9319
9413
|
const defaultFactor = 1, defaultReduce = 1, disableReduce = 0, identity = 1;
|
|
9320
9414
|
class MotionPluginInstance {
|
|
9321
|
-
|
|
9415
|
+
#container;
|
|
9322
9416
|
constructor(container) {
|
|
9323
|
-
this
|
|
9417
|
+
this.#container = container;
|
|
9324
9418
|
}
|
|
9325
9419
|
async init() {
|
|
9326
|
-
const container = this
|
|
9420
|
+
const container = this.#container, options = container.actualOptions.motion;
|
|
9327
9421
|
if (!(options && (options.disable || options.reduce.value))) {
|
|
9328
9422
|
container.retina.reduceFactor = 1;
|
|
9329
9423
|
return;
|
|
@@ -9333,10 +9427,10 @@
|
|
|
9333
9427
|
container.retina.reduceFactor = defaultFactor;
|
|
9334
9428
|
return;
|
|
9335
9429
|
}
|
|
9336
|
-
this
|
|
9430
|
+
this.#handleMotionChange(mediaQuery);
|
|
9337
9431
|
const handleChange = () => {
|
|
9338
9432
|
void (async () => {
|
|
9339
|
-
this
|
|
9433
|
+
this.#handleMotionChange(mediaQuery);
|
|
9340
9434
|
try {
|
|
9341
9435
|
await container.refresh();
|
|
9342
9436
|
}
|
|
@@ -9347,8 +9441,8 @@
|
|
|
9347
9441
|
mediaQuery.addEventListener("change", handleChange);
|
|
9348
9442
|
await Promise.resolve();
|
|
9349
9443
|
}
|
|
9350
|
-
|
|
9351
|
-
const container = this
|
|
9444
|
+
#handleMotionChange = mediaQuery => {
|
|
9445
|
+
const container = this.#container, motion = container.actualOptions.motion;
|
|
9352
9446
|
if (!motion) {
|
|
9353
9447
|
return;
|
|
9354
9448
|
}
|
|
@@ -9400,34 +9494,34 @@
|
|
|
9400
9494
|
spawnStrokeColor;
|
|
9401
9495
|
spawnStrokeOpacity;
|
|
9402
9496
|
spawnStrokeWidth;
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9414
|
-
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
|
|
9418
|
-
|
|
9419
|
-
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9497
|
+
#container;
|
|
9498
|
+
#currentDuration;
|
|
9499
|
+
#currentEmitDelay;
|
|
9500
|
+
#currentSpawnDelay;
|
|
9501
|
+
#duration;
|
|
9502
|
+
#emitDelay;
|
|
9503
|
+
#firstSpawn;
|
|
9504
|
+
#immortal;
|
|
9505
|
+
#initialPosition;
|
|
9506
|
+
#lifeCount;
|
|
9507
|
+
#mutationObserver;
|
|
9508
|
+
#particlesOptions;
|
|
9509
|
+
#paused;
|
|
9510
|
+
#pluginManager;
|
|
9511
|
+
#removeCallback;
|
|
9512
|
+
#resizeObserver;
|
|
9513
|
+
#shape;
|
|
9514
|
+
#size;
|
|
9515
|
+
#spawnDelay;
|
|
9516
|
+
#startParticlesAdded;
|
|
9423
9517
|
constructor(pluginManager, container, removeCallback, options, position) {
|
|
9424
|
-
this
|
|
9425
|
-
this
|
|
9426
|
-
this
|
|
9427
|
-
this
|
|
9428
|
-
this
|
|
9429
|
-
this
|
|
9430
|
-
this
|
|
9518
|
+
this.#pluginManager = pluginManager;
|
|
9519
|
+
this.#container = container;
|
|
9520
|
+
this.#removeCallback = removeCallback;
|
|
9521
|
+
this.#currentDuration = 0;
|
|
9522
|
+
this.#currentEmitDelay = 0;
|
|
9523
|
+
this.#currentSpawnDelay = 0;
|
|
9524
|
+
this.#initialPosition = position;
|
|
9431
9525
|
if (options instanceof Emitter) {
|
|
9432
9526
|
this.options = options;
|
|
9433
9527
|
}
|
|
@@ -9435,159 +9529,159 @@
|
|
|
9435
9529
|
this.options = new Emitter();
|
|
9436
9530
|
this.options.load(options);
|
|
9437
9531
|
}
|
|
9438
|
-
this
|
|
9532
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
9439
9533
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
9440
9534
|
container.retina.reduceFactor
|
|
9441
9535
|
: Infinity;
|
|
9442
|
-
this.position = this
|
|
9536
|
+
this.position = this.#initialPosition ?? this.#calcPosition();
|
|
9443
9537
|
this.name = this.options.name;
|
|
9444
9538
|
this.fill = this.options.fill;
|
|
9445
|
-
this
|
|
9446
|
-
this
|
|
9539
|
+
this.#firstSpawn = !this.options.life.wait;
|
|
9540
|
+
this.#startParticlesAdded = false;
|
|
9447
9541
|
const particlesOptions = deepExtend({}, this.options.particles);
|
|
9448
9542
|
particlesOptions.move ??= {};
|
|
9449
9543
|
particlesOptions.move.direction ??= this.options.direction;
|
|
9450
9544
|
if (this.options.spawn.fill?.color) {
|
|
9451
|
-
this.spawnFillColor = rangeColorToHsl(this
|
|
9545
|
+
this.spawnFillColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.fill.color);
|
|
9452
9546
|
}
|
|
9453
9547
|
if (this.options.spawn.stroke?.color) {
|
|
9454
|
-
this.spawnStrokeColor = rangeColorToHsl(this
|
|
9455
|
-
}
|
|
9456
|
-
this
|
|
9457
|
-
this
|
|
9458
|
-
this
|
|
9459
|
-
this.size = getSize(this
|
|
9460
|
-
this
|
|
9461
|
-
this
|
|
9548
|
+
this.spawnStrokeColor = rangeColorToHsl(this.#pluginManager, this.options.spawn.stroke.color);
|
|
9549
|
+
}
|
|
9550
|
+
this.#paused = !this.options.autoPlay;
|
|
9551
|
+
this.#particlesOptions = particlesOptions;
|
|
9552
|
+
this.#size = this.#calcSize();
|
|
9553
|
+
this.size = getSize(this.#size, this.#container.canvas.size);
|
|
9554
|
+
this.#lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
9555
|
+
this.#immortal = this.#lifeCount <= minLifeCount;
|
|
9462
9556
|
if (this.options.domId) {
|
|
9463
9557
|
const element = safeDocument().getElementById(this.options.domId);
|
|
9464
9558
|
if (element) {
|
|
9465
|
-
this
|
|
9559
|
+
this.#mutationObserver = new MutationObserver(() => {
|
|
9466
9560
|
this.resize();
|
|
9467
9561
|
});
|
|
9468
|
-
this
|
|
9562
|
+
this.#resizeObserver = new ResizeObserver(() => {
|
|
9469
9563
|
this.resize();
|
|
9470
9564
|
});
|
|
9471
|
-
this.
|
|
9565
|
+
this.#mutationObserver.observe(element, {
|
|
9472
9566
|
attributes: true,
|
|
9473
9567
|
attributeFilter: ["style", "width", "height"],
|
|
9474
9568
|
});
|
|
9475
|
-
this.
|
|
9569
|
+
this.#resizeObserver.observe(element);
|
|
9476
9570
|
}
|
|
9477
9571
|
}
|
|
9478
|
-
const shapeOptions = this.options.shape, shapeGenerator = this.
|
|
9572
|
+
const shapeOptions = this.options.shape, shapeGenerator = this.#pluginManager.emitterShapeManager?.getShapeGenerator(shapeOptions.type);
|
|
9479
9573
|
if (shapeGenerator) {
|
|
9480
|
-
this
|
|
9574
|
+
this.#shape = shapeGenerator.generate(this.#container, this.position, this.size, this.fill, shapeOptions.options);
|
|
9481
9575
|
}
|
|
9482
|
-
this.
|
|
9576
|
+
this.#container.dispatchEvent("emitterCreated", {
|
|
9483
9577
|
emitter: this,
|
|
9484
9578
|
});
|
|
9485
9579
|
this.play();
|
|
9486
9580
|
}
|
|
9487
9581
|
externalPause() {
|
|
9488
|
-
this
|
|
9582
|
+
this.#paused = true;
|
|
9489
9583
|
this.pause();
|
|
9490
9584
|
}
|
|
9491
9585
|
externalPlay() {
|
|
9492
|
-
this
|
|
9586
|
+
this.#paused = false;
|
|
9493
9587
|
this.play();
|
|
9494
9588
|
}
|
|
9495
9589
|
async init() {
|
|
9496
|
-
await this
|
|
9590
|
+
await this.#shape?.init();
|
|
9497
9591
|
}
|
|
9498
9592
|
pause() {
|
|
9499
|
-
if (this
|
|
9593
|
+
if (this.#paused) {
|
|
9500
9594
|
return;
|
|
9501
9595
|
}
|
|
9502
|
-
|
|
9596
|
+
this.#emitDelay = undefined;
|
|
9503
9597
|
}
|
|
9504
9598
|
play() {
|
|
9505
|
-
if (this
|
|
9599
|
+
if (this.#paused) {
|
|
9506
9600
|
return;
|
|
9507
9601
|
}
|
|
9508
|
-
if (!((this
|
|
9509
|
-
(this
|
|
9602
|
+
if (!((this.#lifeCount > minLifeCount || this.#immortal || !this.options.life.count) &&
|
|
9603
|
+
(this.#firstSpawn || this.#currentSpawnDelay >= (this.#spawnDelay ?? defaultSpawnDelay)))) {
|
|
9510
9604
|
return;
|
|
9511
9605
|
}
|
|
9512
|
-
const container = this
|
|
9513
|
-
if (this
|
|
9606
|
+
const container = this.#container;
|
|
9607
|
+
if (this.#emitDelay === undefined) {
|
|
9514
9608
|
const delay = getRangeValue(this.options.rate.delay);
|
|
9515
|
-
this
|
|
9609
|
+
this.#emitDelay = container.retina.reduceFactor
|
|
9516
9610
|
? (delay * millisecondsToSeconds) / container.retina.reduceFactor
|
|
9517
9611
|
: Infinity;
|
|
9518
9612
|
}
|
|
9519
|
-
if (this
|
|
9520
|
-
this
|
|
9613
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
9614
|
+
this.#prepareToDie();
|
|
9521
9615
|
}
|
|
9522
9616
|
}
|
|
9523
9617
|
resize() {
|
|
9524
|
-
const initialPosition = this
|
|
9618
|
+
const initialPosition = this.#initialPosition, container = this.#container;
|
|
9525
9619
|
this.position =
|
|
9526
9620
|
initialPosition && isPointInside(initialPosition, container.canvas.size, Vector.origin)
|
|
9527
9621
|
? initialPosition
|
|
9528
|
-
: this
|
|
9529
|
-
this
|
|
9530
|
-
this.size = getSize(this
|
|
9531
|
-
this
|
|
9622
|
+
: this.#calcPosition();
|
|
9623
|
+
this.#size = this.#calcSize();
|
|
9624
|
+
this.size = getSize(this.#size, container.canvas.size);
|
|
9625
|
+
this.#shape?.resize(this.position, this.size);
|
|
9532
9626
|
}
|
|
9533
9627
|
update(delta) {
|
|
9534
|
-
if (this
|
|
9628
|
+
if (this.#paused) {
|
|
9535
9629
|
return;
|
|
9536
9630
|
}
|
|
9537
|
-
const container = this
|
|
9538
|
-
if (this
|
|
9539
|
-
this
|
|
9540
|
-
this
|
|
9541
|
-
this
|
|
9631
|
+
const container = this.#container;
|
|
9632
|
+
if (this.#firstSpawn) {
|
|
9633
|
+
this.#firstSpawn = false;
|
|
9634
|
+
this.#currentSpawnDelay = this.#spawnDelay ?? defaultSpawnDelay;
|
|
9635
|
+
this.#currentEmitDelay = this.#emitDelay ?? defaultEmitDelay;
|
|
9542
9636
|
}
|
|
9543
|
-
if (!this
|
|
9544
|
-
this
|
|
9545
|
-
this
|
|
9637
|
+
if (!this.#startParticlesAdded) {
|
|
9638
|
+
this.#startParticlesAdded = true;
|
|
9639
|
+
this.#emitParticles(this.options.startCount);
|
|
9546
9640
|
}
|
|
9547
|
-
if (this
|
|
9548
|
-
this
|
|
9549
|
-
if (this
|
|
9641
|
+
if (this.#duration !== undefined) {
|
|
9642
|
+
this.#currentDuration += delta.value;
|
|
9643
|
+
if (this.#currentDuration >= this.#duration) {
|
|
9550
9644
|
this.pause();
|
|
9551
|
-
if (this
|
|
9552
|
-
|
|
9645
|
+
if (this.#spawnDelay !== undefined) {
|
|
9646
|
+
this.#spawnDelay = undefined;
|
|
9553
9647
|
}
|
|
9554
|
-
if (!this
|
|
9555
|
-
this
|
|
9648
|
+
if (!this.#immortal) {
|
|
9649
|
+
this.#lifeCount--;
|
|
9556
9650
|
}
|
|
9557
|
-
if (this
|
|
9558
|
-
this.position = this
|
|
9559
|
-
this
|
|
9560
|
-
this
|
|
9651
|
+
if (this.#lifeCount > minLifeCount || this.#immortal) {
|
|
9652
|
+
this.position = this.#calcPosition();
|
|
9653
|
+
this.#shape?.resize(this.position, this.size);
|
|
9654
|
+
this.#spawnDelay = container.retina.reduceFactor
|
|
9561
9655
|
? (getRangeValue(this.options.life.delay ?? defaultLifeDelay) * millisecondsToSeconds) /
|
|
9562
9656
|
container.retina.reduceFactor
|
|
9563
9657
|
: Infinity;
|
|
9564
9658
|
}
|
|
9565
9659
|
else {
|
|
9566
|
-
this
|
|
9660
|
+
this.#destroy();
|
|
9567
9661
|
}
|
|
9568
|
-
this
|
|
9569
|
-
|
|
9662
|
+
this.#currentDuration -= this.#duration;
|
|
9663
|
+
this.#duration = undefined;
|
|
9570
9664
|
}
|
|
9571
9665
|
}
|
|
9572
|
-
if (this
|
|
9573
|
-
this
|
|
9574
|
-
if (this
|
|
9575
|
-
this.
|
|
9666
|
+
if (this.#spawnDelay !== undefined) {
|
|
9667
|
+
this.#currentSpawnDelay += delta.value;
|
|
9668
|
+
if (this.#currentSpawnDelay >= this.#spawnDelay) {
|
|
9669
|
+
this.#container.dispatchEvent("emitterPlay");
|
|
9576
9670
|
this.play();
|
|
9577
|
-
this
|
|
9578
|
-
|
|
9671
|
+
this.#currentSpawnDelay -= this.#spawnDelay;
|
|
9672
|
+
this.#spawnDelay = undefined;
|
|
9579
9673
|
}
|
|
9580
9674
|
}
|
|
9581
|
-
if (this
|
|
9582
|
-
this
|
|
9583
|
-
if (this
|
|
9584
|
-
this
|
|
9585
|
-
this
|
|
9675
|
+
if (this.#emitDelay !== undefined) {
|
|
9676
|
+
this.#currentEmitDelay += delta.value;
|
|
9677
|
+
if (this.#currentEmitDelay >= this.#emitDelay) {
|
|
9678
|
+
this.#emit();
|
|
9679
|
+
this.#currentEmitDelay -= this.#emitDelay;
|
|
9586
9680
|
}
|
|
9587
9681
|
}
|
|
9588
9682
|
}
|
|
9589
|
-
|
|
9590
|
-
const container = this
|
|
9683
|
+
#calcPosition() {
|
|
9684
|
+
const container = this.#container;
|
|
9591
9685
|
if (this.options.domId) {
|
|
9592
9686
|
const element = safeDocument().getElementById(this.options.domId);
|
|
9593
9687
|
if (element) {
|
|
@@ -9603,8 +9697,8 @@
|
|
|
9603
9697
|
position: this.options.position,
|
|
9604
9698
|
});
|
|
9605
9699
|
}
|
|
9606
|
-
|
|
9607
|
-
const container = this
|
|
9700
|
+
#calcSize() {
|
|
9701
|
+
const container = this.#container;
|
|
9608
9702
|
if (this.options.domId) {
|
|
9609
9703
|
const element = safeDocument().getElementById(this.options.domId);
|
|
9610
9704
|
if (element) {
|
|
@@ -9627,32 +9721,32 @@
|
|
|
9627
9721
|
return size;
|
|
9628
9722
|
})());
|
|
9629
9723
|
}
|
|
9630
|
-
|
|
9631
|
-
this
|
|
9632
|
-
this
|
|
9633
|
-
this
|
|
9634
|
-
this
|
|
9635
|
-
this
|
|
9636
|
-
this.
|
|
9724
|
+
#destroy = () => {
|
|
9725
|
+
this.#mutationObserver?.disconnect();
|
|
9726
|
+
this.#mutationObserver = undefined;
|
|
9727
|
+
this.#resizeObserver?.disconnect();
|
|
9728
|
+
this.#resizeObserver = undefined;
|
|
9729
|
+
this.#removeCallback(this);
|
|
9730
|
+
this.#container.dispatchEvent("emitterDestroyed", {
|
|
9637
9731
|
emitter: this,
|
|
9638
9732
|
});
|
|
9639
9733
|
};
|
|
9640
|
-
|
|
9641
|
-
if (this
|
|
9734
|
+
#emit() {
|
|
9735
|
+
if (this.#paused) {
|
|
9642
9736
|
return;
|
|
9643
9737
|
}
|
|
9644
9738
|
const quantity = getRangeValue(this.options.rate.quantity);
|
|
9645
|
-
this
|
|
9739
|
+
this.#emitParticles(quantity);
|
|
9646
9740
|
}
|
|
9647
|
-
|
|
9648
|
-
const singleParticlesOptions = (itemFromSingleOrMultiple(this
|
|
9741
|
+
#emitParticles(quantity) {
|
|
9742
|
+
const singleParticlesOptions = (itemFromSingleOrMultiple(this.#particlesOptions) ??
|
|
9649
9743
|
{}), 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
|
|
9650
9744
|
? defaultOpacity$2
|
|
9651
9745
|
: getRangeValue(this.options.spawn.fill.opacity), strokeHslAnimation = this.options.spawn.stroke?.color?.animation, strokeOpacity = this.options.spawn.stroke?.opacity === undefined
|
|
9652
9746
|
? defaultOpacity$2
|
|
9653
9747
|
: getRangeValue(this.options.spawn.stroke.opacity), strokeWidth = this.options.spawn.stroke?.width === undefined
|
|
9654
9748
|
? defaultStrokeWidth
|
|
9655
|
-
: getRangeValue(this.options.spawn.stroke.width), reduceFactor = this.
|
|
9749
|
+
: 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;
|
|
9656
9750
|
for (let i = 0; i < quantity * reduceFactor; i++) {
|
|
9657
9751
|
const particlesOptions = needsCopy
|
|
9658
9752
|
? deepExtend({}, singleParticlesOptions)
|
|
@@ -9663,23 +9757,23 @@
|
|
|
9663
9757
|
this.spawnStrokeWidth = strokeWidth;
|
|
9664
9758
|
if (this.spawnFillColor) {
|
|
9665
9759
|
if (fillHslAnimation && maxValues) {
|
|
9666
|
-
this.spawnFillColor.h = this
|
|
9667
|
-
this.spawnFillColor.s = this
|
|
9668
|
-
this.spawnFillColor.l = this
|
|
9760
|
+
this.spawnFillColor.h = this.#setColorAnimation(fillHslAnimation.h, this.spawnFillColor.h, maxValues.h, colorFactor);
|
|
9761
|
+
this.spawnFillColor.s = this.#setColorAnimation(fillHslAnimation.s, this.spawnFillColor.s, maxValues.s);
|
|
9762
|
+
this.spawnFillColor.l = this.#setColorAnimation(fillHslAnimation.l, this.spawnFillColor.l, maxValues.l);
|
|
9669
9763
|
}
|
|
9670
9764
|
setParticlesOptionsFillColor(particlesOptions, this.spawnFillColor, this.spawnFillOpacity, this.spawnFillEnabled);
|
|
9671
9765
|
}
|
|
9672
9766
|
if (this.spawnStrokeColor) {
|
|
9673
9767
|
if (strokeHslAnimation && maxValues) {
|
|
9674
|
-
this.spawnStrokeColor.h = this
|
|
9675
|
-
this.spawnStrokeColor.s = this
|
|
9676
|
-
this.spawnStrokeColor.l = this
|
|
9768
|
+
this.spawnStrokeColor.h = this.#setColorAnimation(strokeHslAnimation.h, this.spawnStrokeColor.h, maxValues.h, colorFactor);
|
|
9769
|
+
this.spawnStrokeColor.s = this.#setColorAnimation(strokeHslAnimation.s, this.spawnStrokeColor.s, maxValues.s);
|
|
9770
|
+
this.spawnStrokeColor.l = this.#setColorAnimation(strokeHslAnimation.l, this.spawnStrokeColor.l, maxValues.l);
|
|
9677
9771
|
}
|
|
9678
9772
|
setParticlesOptionsStrokeColor(particlesOptions, this.spawnStrokeColor, this.spawnStrokeOpacity, this.spawnStrokeWidth);
|
|
9679
9773
|
}
|
|
9680
9774
|
let position = this.position;
|
|
9681
|
-
if (this
|
|
9682
|
-
const shapePosData = this.
|
|
9775
|
+
if (this.#shape) {
|
|
9776
|
+
const shapePosData = this.#shape.randomPosition();
|
|
9683
9777
|
if (shapePosData) {
|
|
9684
9778
|
position = shapePosData.position;
|
|
9685
9779
|
const replaceData = shapeOptions.replace;
|
|
@@ -9692,21 +9786,21 @@
|
|
|
9692
9786
|
}
|
|
9693
9787
|
}
|
|
9694
9788
|
if (position) {
|
|
9695
|
-
this.
|
|
9789
|
+
this.#container.particles.addParticle(position, particlesOptions);
|
|
9696
9790
|
}
|
|
9697
9791
|
}
|
|
9698
9792
|
}
|
|
9699
|
-
|
|
9700
|
-
if (this
|
|
9793
|
+
#prepareToDie = () => {
|
|
9794
|
+
if (this.#paused) {
|
|
9701
9795
|
return;
|
|
9702
9796
|
}
|
|
9703
9797
|
const duration = this.options.life.duration !== undefined ? getRangeValue(this.options.life.duration) : undefined, minDuration = 0, minLifeCount = 0;
|
|
9704
|
-
if ((this
|
|
9705
|
-
this
|
|
9798
|
+
if ((this.#lifeCount > minLifeCount || this.#immortal) && duration !== undefined && duration > minDuration) {
|
|
9799
|
+
this.#duration = duration * millisecondsToSeconds;
|
|
9706
9800
|
}
|
|
9707
9801
|
};
|
|
9708
|
-
|
|
9709
|
-
const container = this
|
|
9802
|
+
#setColorAnimation = (animation, initValue, maxValue, factor = defaultColorAnimationFactor) => {
|
|
9803
|
+
const container = this.#container;
|
|
9710
9804
|
if (!animation.enable) {
|
|
9711
9805
|
return initValue;
|
|
9712
9806
|
}
|
|
@@ -9737,8 +9831,6 @@
|
|
|
9737
9831
|
exports.MoveCenter = MoveCenter;
|
|
9738
9832
|
exports.MoveGravity = MoveGravity;
|
|
9739
9833
|
exports.MovePath = MovePath;
|
|
9740
|
-
exports.Opacity = Opacity;
|
|
9741
|
-
exports.OpacityAnimation = OpacityAnimation;
|
|
9742
9834
|
exports.Options = Options;
|
|
9743
9835
|
exports.OptionsColor = OptionsColor;
|
|
9744
9836
|
exports.OutModes = OutModes;
|
|
@@ -9754,8 +9846,6 @@
|
|
|
9754
9846
|
exports.Rectangle = Rectangle;
|
|
9755
9847
|
exports.ResizeEvent = ResizeEvent;
|
|
9756
9848
|
exports.Shape = Shape;
|
|
9757
|
-
exports.Size = Size;
|
|
9758
|
-
exports.SizeAnimation = SizeAnimation;
|
|
9759
9849
|
exports.Spin = Spin;
|
|
9760
9850
|
exports.Stroke = Stroke;
|
|
9761
9851
|
exports.ValueWithRandom = ValueWithRandom;
|