@tsparticles/particles 4.0.5 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/ParticlesInstance.js +5 -5
- package/browser/particles.js +2 -2
- package/browser/particles.lazy.js +2 -2
- package/cjs/ParticlesInstance.js +5 -5
- package/cjs/particles.js +2 -2
- package/cjs/particles.lazy.js +2 -2
- package/esm/ParticlesInstance.js +5 -5
- package/esm/particles.js +2 -2
- package/esm/particles.lazy.js +2 -2
- package/package.json +6 -6
- package/report.html +1 -1
- package/tsparticles.particles.bundle.js +1090 -1000
- package/tsparticles.particles.bundle.min.js +1 -1
- package/tsparticles.particles.js +8 -8
- package/tsparticles.particles.min.js +1 -1
- package/types/ParticlesInstance.d.ts +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.
|
|
2
|
+
/* tsParticles v4.1.1 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
return Math.atan2(this.y, this.x);
|
|
52
52
|
}
|
|
53
53
|
set angle(angle) {
|
|
54
|
-
this
|
|
54
|
+
this.#updateFromAngle(angle, this.length);
|
|
55
55
|
}
|
|
56
56
|
get length() {
|
|
57
57
|
return Math.sqrt(this.getLengthSq());
|
|
58
58
|
}
|
|
59
59
|
set length(length) {
|
|
60
|
-
this
|
|
60
|
+
this.#updateFromAngle(this.angle, length);
|
|
61
61
|
}
|
|
62
62
|
static clone(source) {
|
|
63
63
|
return Vector3d.create(source.x, source.y, getZ(source));
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
this.y -= v.y;
|
|
121
121
|
this.z -= getZ(v);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
#updateFromAngle(angle, length) {
|
|
124
124
|
this.x = Math.cos(angle) * length;
|
|
125
125
|
this.y = Math.sin(angle) * length;
|
|
126
126
|
}
|
|
@@ -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.
|
|
1121
|
+
return "4.1.1";
|
|
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
|
|
|
@@ -3114,7 +3034,7 @@
|
|
|
3114
3034
|
}
|
|
3115
3035
|
|
|
3116
3036
|
async function loadBlendPlugin(engine) {
|
|
3117
|
-
engine.checkVersion("4.
|
|
3037
|
+
engine.checkVersion("4.1.1");
|
|
3118
3038
|
await engine.pluginManager.register(e => {
|
|
3119
3039
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
3120
3040
|
});
|
|
@@ -3151,7 +3071,7 @@
|
|
|
3151
3071
|
}
|
|
3152
3072
|
|
|
3153
3073
|
async function loadCircleShape(engine) {
|
|
3154
|
-
engine.checkVersion("4.
|
|
3074
|
+
engine.checkVersion("4.1.1");
|
|
3155
3075
|
await engine.pluginManager.register(e => {
|
|
3156
3076
|
e.pluginManager.addShape(["circle"], () => {
|
|
3157
3077
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -3172,15 +3092,15 @@
|
|
|
3172
3092
|
return input.startsWith("#");
|
|
3173
3093
|
}
|
|
3174
3094
|
handleColor(color) {
|
|
3175
|
-
return this
|
|
3095
|
+
return this.#parseString(color.value);
|
|
3176
3096
|
}
|
|
3177
3097
|
handleRangeColor(color) {
|
|
3178
|
-
return this
|
|
3098
|
+
return this.#parseString(color.value);
|
|
3179
3099
|
}
|
|
3180
3100
|
parseString(input) {
|
|
3181
|
-
return this
|
|
3101
|
+
return this.#parseString(input);
|
|
3182
3102
|
}
|
|
3183
|
-
|
|
3103
|
+
#parseString(hexColor) {
|
|
3184
3104
|
if (typeof hexColor !== "string" || !this.accepts(hexColor)) {
|
|
3185
3105
|
return;
|
|
3186
3106
|
}
|
|
@@ -3199,7 +3119,7 @@
|
|
|
3199
3119
|
}
|
|
3200
3120
|
|
|
3201
3121
|
async function loadHexColorPlugin(engine) {
|
|
3202
|
-
engine.checkVersion("4.
|
|
3122
|
+
engine.checkVersion("4.1.1");
|
|
3203
3123
|
await engine.pluginManager.register(e => {
|
|
3204
3124
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
3205
3125
|
});
|
|
@@ -3252,7 +3172,7 @@
|
|
|
3252
3172
|
}
|
|
3253
3173
|
|
|
3254
3174
|
async function loadHslColorPlugin(engine) {
|
|
3255
|
-
engine.checkVersion("4.
|
|
3175
|
+
engine.checkVersion("4.1.1");
|
|
3256
3176
|
await engine.pluginManager.register(e => {
|
|
3257
3177
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
3258
3178
|
});
|
|
@@ -3260,13 +3180,13 @@
|
|
|
3260
3180
|
|
|
3261
3181
|
class MovePlugin {
|
|
3262
3182
|
id = "move";
|
|
3263
|
-
|
|
3183
|
+
#pluginManager;
|
|
3264
3184
|
constructor(pluginManager) {
|
|
3265
|
-
this
|
|
3185
|
+
this.#pluginManager = pluginManager;
|
|
3266
3186
|
}
|
|
3267
3187
|
async getPlugin(container) {
|
|
3268
3188
|
const { MovePluginInstance } = await Promise.resolve().then(function () { return MovePluginInstance$1; });
|
|
3269
|
-
return new MovePluginInstance(this
|
|
3189
|
+
return new MovePluginInstance(this.#pluginManager, container);
|
|
3270
3190
|
}
|
|
3271
3191
|
loadOptions() {
|
|
3272
3192
|
}
|
|
@@ -3276,7 +3196,7 @@
|
|
|
3276
3196
|
}
|
|
3277
3197
|
|
|
3278
3198
|
async function loadMovePlugin(engine) {
|
|
3279
|
-
engine.checkVersion("4.
|
|
3199
|
+
engine.checkVersion("4.1.1");
|
|
3280
3200
|
await engine.pluginManager.register(e => {
|
|
3281
3201
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
3282
3202
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
@@ -3294,18 +3214,58 @@
|
|
|
3294
3214
|
});
|
|
3295
3215
|
}
|
|
3296
3216
|
|
|
3217
|
+
class OpacityAnimation extends RangedAnimationOptions {
|
|
3218
|
+
destroy;
|
|
3219
|
+
constructor() {
|
|
3220
|
+
super();
|
|
3221
|
+
this.destroy = exports.DestroyType.none;
|
|
3222
|
+
this.speed = 2;
|
|
3223
|
+
}
|
|
3224
|
+
load(data) {
|
|
3225
|
+
super.load(data);
|
|
3226
|
+
if (isNull(data)) {
|
|
3227
|
+
return;
|
|
3228
|
+
}
|
|
3229
|
+
if (data.destroy !== undefined) {
|
|
3230
|
+
this.destroy = data.destroy;
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
|
|
3235
|
+
class Opacity extends RangedAnimationValueWithRandom {
|
|
3236
|
+
animation;
|
|
3237
|
+
constructor() {
|
|
3238
|
+
super();
|
|
3239
|
+
this.animation = new OpacityAnimation();
|
|
3240
|
+
this.value = 1;
|
|
3241
|
+
}
|
|
3242
|
+
load(data) {
|
|
3243
|
+
if (isNull(data)) {
|
|
3244
|
+
return;
|
|
3245
|
+
}
|
|
3246
|
+
super.load(data);
|
|
3247
|
+
const animation = data.animation;
|
|
3248
|
+
if (animation !== undefined) {
|
|
3249
|
+
this.animation.load(animation);
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
}
|
|
3253
|
+
|
|
3297
3254
|
class OpacityUpdater {
|
|
3298
|
-
container;
|
|
3255
|
+
#container;
|
|
3299
3256
|
constructor(container) {
|
|
3300
|
-
this
|
|
3257
|
+
this.#container = container;
|
|
3301
3258
|
}
|
|
3302
3259
|
init(particle) {
|
|
3303
3260
|
const opacityOptions = particle.options.opacity, pxRatio = 1;
|
|
3261
|
+
if (!opacityOptions) {
|
|
3262
|
+
return;
|
|
3263
|
+
}
|
|
3304
3264
|
particle.opacity = initParticleNumericAnimationValue(opacityOptions, pxRatio);
|
|
3305
3265
|
const opacityAnimation = opacityOptions.animation;
|
|
3306
3266
|
if (opacityAnimation.enable) {
|
|
3307
3267
|
particle.opacity.velocity =
|
|
3308
|
-
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this
|
|
3268
|
+
(getRangeValue(opacityAnimation.speed) / percentDenominator) * this.#container.retina.reduceFactor;
|
|
3309
3269
|
if (!opacityAnimation.sync) {
|
|
3310
3270
|
particle.opacity.velocity *= getRandom();
|
|
3311
3271
|
}
|
|
@@ -3321,6 +3281,12 @@
|
|
|
3321
3281
|
((particle.opacity.maxLoops ?? none) > none &&
|
|
3322
3282
|
(particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
|
|
3323
3283
|
}
|
|
3284
|
+
loadOptions(options, ...sources) {
|
|
3285
|
+
options.opacity ??= new Opacity();
|
|
3286
|
+
for (const source of sources) {
|
|
3287
|
+
options.opacity.load(source?.opacity);
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3324
3290
|
reset(particle) {
|
|
3325
3291
|
if (!particle.opacity) {
|
|
3326
3292
|
return;
|
|
@@ -3329,7 +3295,7 @@
|
|
|
3329
3295
|
particle.opacity.loops = 0;
|
|
3330
3296
|
}
|
|
3331
3297
|
update(particle, delta) {
|
|
3332
|
-
if (!this.isEnabled(particle) || !particle.opacity) {
|
|
3298
|
+
if (!this.isEnabled(particle) || !particle.opacity || !particle.options.opacity) {
|
|
3333
3299
|
return;
|
|
3334
3300
|
}
|
|
3335
3301
|
updateAnimation(particle, particle.opacity, true, particle.options.opacity.animation.destroy, delta);
|
|
@@ -3337,7 +3303,7 @@
|
|
|
3337
3303
|
}
|
|
3338
3304
|
|
|
3339
3305
|
async function loadOpacityUpdater(engine) {
|
|
3340
|
-
engine.checkVersion("4.
|
|
3306
|
+
engine.checkVersion("4.1.1");
|
|
3341
3307
|
await engine.pluginManager.register(e => {
|
|
3342
3308
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
3343
3309
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -3359,10 +3325,9 @@
|
|
|
3359
3325
|
}
|
|
3360
3326
|
const velocity = data.particle.velocity.x;
|
|
3361
3327
|
let bounced = false;
|
|
3362
|
-
if (
|
|
3363
|
-
data.
|
|
3364
|
-
|
|
3365
|
-
(data.direction === exports.OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity$4)) {
|
|
3328
|
+
if (data.outOfCanvas &&
|
|
3329
|
+
((data.direction === exports.OutModeDirection.right && velocity > minVelocity$4) ||
|
|
3330
|
+
(data.direction === exports.OutModeDirection.left && velocity < minVelocity$4))) {
|
|
3366
3331
|
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
3367
3332
|
data.particle.velocity.x *= -newVelocity;
|
|
3368
3333
|
bounced = true;
|
|
@@ -3371,10 +3336,10 @@
|
|
|
3371
3336
|
return;
|
|
3372
3337
|
}
|
|
3373
3338
|
const minPos = data.offset.x + data.size;
|
|
3374
|
-
if (data.
|
|
3339
|
+
if (data.outOfCanvas && data.direction === exports.OutModeDirection.right) {
|
|
3375
3340
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
3376
3341
|
}
|
|
3377
|
-
else if (data.
|
|
3342
|
+
else if (data.outOfCanvas && data.direction === exports.OutModeDirection.left) {
|
|
3378
3343
|
data.particle.position.x = minPos;
|
|
3379
3344
|
}
|
|
3380
3345
|
if (data.outMode === exports.OutMode.split) {
|
|
@@ -3394,10 +3359,9 @@
|
|
|
3394
3359
|
}
|
|
3395
3360
|
const velocity = data.particle.velocity.y;
|
|
3396
3361
|
let bounced = false;
|
|
3397
|
-
if (
|
|
3398
|
-
data.
|
|
3399
|
-
|
|
3400
|
-
(data.direction === exports.OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity$4)) {
|
|
3362
|
+
if (data.outOfCanvas &&
|
|
3363
|
+
((data.direction === exports.OutModeDirection.bottom && velocity > minVelocity$4) ||
|
|
3364
|
+
(data.direction === exports.OutModeDirection.top && velocity < minVelocity$4))) {
|
|
3401
3365
|
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
3402
3366
|
data.particle.velocity.y *= -newVelocity;
|
|
3403
3367
|
bounced = true;
|
|
@@ -3406,10 +3370,10 @@
|
|
|
3406
3370
|
return;
|
|
3407
3371
|
}
|
|
3408
3372
|
const minPos = data.offset.y + data.size;
|
|
3409
|
-
if (data.
|
|
3373
|
+
if (data.outOfCanvas && data.direction === exports.OutModeDirection.bottom) {
|
|
3410
3374
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
3411
3375
|
}
|
|
3412
|
-
else if (data.
|
|
3376
|
+
else if (data.outOfCanvas && data.direction === exports.OutModeDirection.top) {
|
|
3413
3377
|
data.particle.position.y = minPos;
|
|
3414
3378
|
}
|
|
3415
3379
|
if (data.outMode === exports.OutMode.split) {
|
|
@@ -3418,24 +3382,24 @@
|
|
|
3418
3382
|
}
|
|
3419
3383
|
|
|
3420
3384
|
class BounceOutMode {
|
|
3421
|
-
container;
|
|
3422
3385
|
modes;
|
|
3423
|
-
|
|
3386
|
+
#container;
|
|
3387
|
+
#particleBouncePlugins;
|
|
3424
3388
|
constructor(container) {
|
|
3425
|
-
this
|
|
3389
|
+
this.#container = container;
|
|
3426
3390
|
this.modes = [
|
|
3427
3391
|
exports.OutMode.bounce,
|
|
3428
3392
|
exports.OutMode.split,
|
|
3429
3393
|
];
|
|
3430
|
-
this
|
|
3394
|
+
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce !== undefined);
|
|
3431
3395
|
}
|
|
3432
3396
|
update(particle, direction, delta, outMode) {
|
|
3433
3397
|
if (!this.modes.includes(outMode)) {
|
|
3434
3398
|
return;
|
|
3435
3399
|
}
|
|
3436
|
-
const container = this
|
|
3400
|
+
const container = this.#container;
|
|
3437
3401
|
let handled = false;
|
|
3438
|
-
for (const plugin of this
|
|
3402
|
+
for (const plugin of this.#particleBouncePlugins) {
|
|
3439
3403
|
handled = plugin.particleBounce?.(particle, delta, direction) ?? false;
|
|
3440
3404
|
if (handled) {
|
|
3441
3405
|
break;
|
|
@@ -3444,29 +3408,26 @@
|
|
|
3444
3408
|
if (handled) {
|
|
3445
3409
|
return;
|
|
3446
3410
|
}
|
|
3447
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
3448
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3449
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
3411
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
3412
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3413
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
3450
3414
|
}
|
|
3451
3415
|
}
|
|
3452
3416
|
|
|
3453
3417
|
const minVelocity$3 = 0;
|
|
3454
3418
|
class DestroyOutMode {
|
|
3455
|
-
container;
|
|
3456
3419
|
modes;
|
|
3457
|
-
constructor(
|
|
3458
|
-
this.container = container;
|
|
3420
|
+
constructor(_container) {
|
|
3459
3421
|
this.modes = [exports.OutMode.destroy];
|
|
3460
3422
|
}
|
|
3461
3423
|
update(particle, direction, _delta, outMode) {
|
|
3462
3424
|
if (!this.modes.includes(outMode)) {
|
|
3463
3425
|
return;
|
|
3464
3426
|
}
|
|
3465
|
-
const container = this.container;
|
|
3466
3427
|
switch (particle.outType) {
|
|
3467
3428
|
case exports.ParticleOutType.normal:
|
|
3468
3429
|
case exports.ParticleOutType.outside:
|
|
3469
|
-
if (
|
|
3430
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3470
3431
|
return;
|
|
3471
3432
|
}
|
|
3472
3433
|
break;
|
|
@@ -3487,10 +3448,10 @@
|
|
|
3487
3448
|
|
|
3488
3449
|
const minVelocity$2 = 0;
|
|
3489
3450
|
class NoneOutMode {
|
|
3490
|
-
container;
|
|
3491
3451
|
modes;
|
|
3452
|
+
#container;
|
|
3492
3453
|
constructor(container) {
|
|
3493
|
-
this
|
|
3454
|
+
this.#container = container;
|
|
3494
3455
|
this.modes = [exports.OutMode.none];
|
|
3495
3456
|
}
|
|
3496
3457
|
update(particle, direction, _delta, outMode) {
|
|
@@ -3503,7 +3464,7 @@
|
|
|
3503
3464
|
(direction === exports.OutModeDirection.top || direction === exports.OutModeDirection.bottom))) {
|
|
3504
3465
|
return;
|
|
3505
3466
|
}
|
|
3506
|
-
const gravityOptions = particle.options.move.gravity, container = this
|
|
3467
|
+
const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
3507
3468
|
if (!gravityOptions.enable) {
|
|
3508
3469
|
if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
|
|
3509
3470
|
(particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
|
|
@@ -3529,17 +3490,17 @@
|
|
|
3529
3490
|
|
|
3530
3491
|
const minVelocity$1 = 0, minDistance$2 = 0, updateVector = Vector.origin;
|
|
3531
3492
|
class OutOutMode {
|
|
3532
|
-
container;
|
|
3533
3493
|
modes;
|
|
3494
|
+
#container;
|
|
3534
3495
|
constructor(container) {
|
|
3535
|
-
this
|
|
3496
|
+
this.#container = container;
|
|
3536
3497
|
this.modes = [exports.OutMode.out];
|
|
3537
3498
|
}
|
|
3538
3499
|
update(particle, direction, _delta, outMode) {
|
|
3539
3500
|
if (!this.modes.includes(outMode)) {
|
|
3540
3501
|
return;
|
|
3541
3502
|
}
|
|
3542
|
-
const container = this
|
|
3503
|
+
const container = this.#container;
|
|
3543
3504
|
switch (particle.outType) {
|
|
3544
3505
|
case exports.ParticleOutType.inside: {
|
|
3545
3506
|
const { x: vx, y: vy } = particle.velocity;
|
|
@@ -3569,7 +3530,7 @@
|
|
|
3569
3530
|
break;
|
|
3570
3531
|
}
|
|
3571
3532
|
default: {
|
|
3572
|
-
if (
|
|
3533
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
3573
3534
|
return;
|
|
3574
3535
|
}
|
|
3575
3536
|
switch (particle.outType) {
|
|
@@ -3653,16 +3614,16 @@
|
|
|
3653
3614
|
};
|
|
3654
3615
|
class OutOfCanvasUpdater {
|
|
3655
3616
|
updaters;
|
|
3656
|
-
container;
|
|
3617
|
+
#container;
|
|
3657
3618
|
constructor(container) {
|
|
3658
|
-
this
|
|
3619
|
+
this.#container = container;
|
|
3659
3620
|
this.updaters = new Map();
|
|
3660
3621
|
}
|
|
3661
3622
|
init(particle) {
|
|
3662
|
-
this
|
|
3663
|
-
this
|
|
3664
|
-
this
|
|
3665
|
-
this
|
|
3623
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.bounce, container => new BounceOutMode(container));
|
|
3624
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.out, container => new OutOutMode(container));
|
|
3625
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.destroy, container => new DestroyOutMode(container));
|
|
3626
|
+
this.#addUpdaterIfMissing(particle, exports.OutMode.none, container => new NoneOutMode(container));
|
|
3666
3627
|
}
|
|
3667
3628
|
isEnabled(particle) {
|
|
3668
3629
|
return !particle.destroyed && !particle.spawning;
|
|
@@ -3670,18 +3631,18 @@
|
|
|
3670
3631
|
update(particle, delta) {
|
|
3671
3632
|
const outModes = particle.options.move.outModes;
|
|
3672
3633
|
particle.justWarped = false;
|
|
3673
|
-
this
|
|
3674
|
-
this
|
|
3675
|
-
this
|
|
3676
|
-
this
|
|
3634
|
+
this.#updateOutMode(particle, delta, outModes.bottom ?? outModes.default, exports.OutModeDirection.bottom);
|
|
3635
|
+
this.#updateOutMode(particle, delta, outModes.left ?? outModes.default, exports.OutModeDirection.left);
|
|
3636
|
+
this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, exports.OutModeDirection.right);
|
|
3637
|
+
this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, exports.OutModeDirection.top);
|
|
3677
3638
|
}
|
|
3678
|
-
|
|
3639
|
+
#addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
3679
3640
|
const outModes = particle.options.move.outModes;
|
|
3680
3641
|
if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
|
|
3681
|
-
this.updaters.set(outMode, getUpdater(this
|
|
3642
|
+
this.updaters.set(outMode, getUpdater(this.#container));
|
|
3682
3643
|
}
|
|
3683
3644
|
};
|
|
3684
|
-
|
|
3645
|
+
#updateOutMode = (particle, delta, outMode, direction) => {
|
|
3685
3646
|
for (const updater of this.updaters.values()) {
|
|
3686
3647
|
updater.update(particle, direction, delta, outMode);
|
|
3687
3648
|
}
|
|
@@ -3689,7 +3650,7 @@
|
|
|
3689
3650
|
}
|
|
3690
3651
|
|
|
3691
3652
|
async function loadOutModesUpdater(engine) {
|
|
3692
|
-
engine.checkVersion("4.
|
|
3653
|
+
engine.checkVersion("4.1.1");
|
|
3693
3654
|
await engine.pluginManager.register(e => {
|
|
3694
3655
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
3695
3656
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -3699,20 +3660,20 @@
|
|
|
3699
3660
|
|
|
3700
3661
|
const defaultOpacity = 1;
|
|
3701
3662
|
class PaintUpdater {
|
|
3702
|
-
|
|
3703
|
-
|
|
3663
|
+
#container;
|
|
3664
|
+
#pluginManager;
|
|
3704
3665
|
constructor(pluginManager, container) {
|
|
3705
|
-
this
|
|
3706
|
-
this
|
|
3666
|
+
this.#container = container;
|
|
3667
|
+
this.#pluginManager = pluginManager;
|
|
3707
3668
|
}
|
|
3708
3669
|
init(particle) {
|
|
3709
|
-
const container = this
|
|
3670
|
+
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;
|
|
3710
3671
|
if (fill) {
|
|
3711
3672
|
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3712
3673
|
particle.fillEnabled = fill.enable;
|
|
3713
3674
|
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3714
3675
|
particle.fillAnimation = fillColor.animation;
|
|
3715
|
-
const fillHslColor = rangeColorToHsl(this
|
|
3676
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3716
3677
|
if (fillHslColor) {
|
|
3717
3678
|
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3718
3679
|
}
|
|
@@ -3728,7 +3689,7 @@
|
|
|
3728
3689
|
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3729
3690
|
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3730
3691
|
particle.strokeAnimation = strokeColor.animation;
|
|
3731
|
-
const strokeHslColor = rangeColorToHsl(this
|
|
3692
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3732
3693
|
if (strokeHslColor) {
|
|
3733
3694
|
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3734
3695
|
}
|
|
@@ -3760,7 +3721,7 @@
|
|
|
3760
3721
|
}
|
|
3761
3722
|
|
|
3762
3723
|
async function loadPaintUpdater(engine) {
|
|
3763
|
-
engine.checkVersion("4.
|
|
3724
|
+
engine.checkVersion("4.1.1");
|
|
3764
3725
|
await engine.pluginManager.register(e => {
|
|
3765
3726
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
3766
3727
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3815,27 +3776,69 @@
|
|
|
3815
3776
|
}
|
|
3816
3777
|
|
|
3817
3778
|
async function loadRgbColorPlugin(engine) {
|
|
3818
|
-
engine.checkVersion("4.
|
|
3779
|
+
engine.checkVersion("4.1.1");
|
|
3819
3780
|
await engine.pluginManager.register(e => {
|
|
3820
3781
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3821
3782
|
});
|
|
3822
3783
|
}
|
|
3823
3784
|
|
|
3785
|
+
class SizeAnimation extends RangedAnimationOptions {
|
|
3786
|
+
destroy;
|
|
3787
|
+
constructor() {
|
|
3788
|
+
super();
|
|
3789
|
+
this.destroy = exports.DestroyType.none;
|
|
3790
|
+
this.speed = 5;
|
|
3791
|
+
}
|
|
3792
|
+
load(data) {
|
|
3793
|
+
super.load(data);
|
|
3794
|
+
if (isNull(data)) {
|
|
3795
|
+
return;
|
|
3796
|
+
}
|
|
3797
|
+
if (data.destroy !== undefined) {
|
|
3798
|
+
this.destroy = data.destroy;
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
}
|
|
3802
|
+
|
|
3803
|
+
class Size extends RangedAnimationValueWithRandom {
|
|
3804
|
+
animation;
|
|
3805
|
+
constructor() {
|
|
3806
|
+
super();
|
|
3807
|
+
this.animation = new SizeAnimation();
|
|
3808
|
+
this.value = 3;
|
|
3809
|
+
}
|
|
3810
|
+
load(data) {
|
|
3811
|
+
super.load(data);
|
|
3812
|
+
if (isNull(data)) {
|
|
3813
|
+
return;
|
|
3814
|
+
}
|
|
3815
|
+
const animation = data.animation;
|
|
3816
|
+
if (animation !== undefined) {
|
|
3817
|
+
this.animation.load(animation);
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
|
|
3824
3822
|
const minLoops = 0;
|
|
3825
3823
|
class SizeUpdater {
|
|
3826
|
-
|
|
3824
|
+
#container;
|
|
3827
3825
|
constructor(container) {
|
|
3828
|
-
this
|
|
3826
|
+
this.#container = container;
|
|
3829
3827
|
}
|
|
3830
3828
|
init(particle) {
|
|
3831
|
-
const container = this
|
|
3832
|
-
if (
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3829
|
+
const container = this.#container, sizeOptions = particle.options.size;
|
|
3830
|
+
if (!sizeOptions) {
|
|
3831
|
+
return;
|
|
3832
|
+
}
|
|
3833
|
+
const sizeAnimation = sizeOptions.animation;
|
|
3834
|
+
if (!sizeAnimation.enable) {
|
|
3835
|
+
return;
|
|
3838
3836
|
}
|
|
3837
|
+
particle.size.velocity = (particle.retina.sizeAnimationSpeed / percentDenominator) * container.retina.reduceFactor;
|
|
3838
|
+
if (sizeAnimation.sync) {
|
|
3839
|
+
return;
|
|
3840
|
+
}
|
|
3841
|
+
particle.size.velocity *= getRandom();
|
|
3839
3842
|
}
|
|
3840
3843
|
isEnabled(particle) {
|
|
3841
3844
|
return (!particle.destroyed &&
|
|
@@ -3845,12 +3848,26 @@
|
|
|
3845
3848
|
((particle.size.maxLoops ?? minLoops) > minLoops &&
|
|
3846
3849
|
(particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
|
|
3847
3850
|
}
|
|
3851
|
+
loadOptions(options, ...sources) {
|
|
3852
|
+
options.size ??= new Size();
|
|
3853
|
+
for (const source of sources) {
|
|
3854
|
+
options.size.load(source?.size);
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
preInit(particle) {
|
|
3858
|
+
const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
|
|
3859
|
+
if (!sizeOptions) {
|
|
3860
|
+
return;
|
|
3861
|
+
}
|
|
3862
|
+
particle.size = initParticleNumericAnimationValue(sizeOptions, pxRatio);
|
|
3863
|
+
particle.retina.sizeAnimationSpeed = getRangeValue(sizeOptions.animation.speed) * pxRatio;
|
|
3864
|
+
}
|
|
3848
3865
|
reset(particle) {
|
|
3849
3866
|
particle.size.time = 0;
|
|
3850
3867
|
particle.size.loops = 0;
|
|
3851
3868
|
}
|
|
3852
3869
|
update(particle, delta) {
|
|
3853
|
-
if (!this.isEnabled(particle)) {
|
|
3870
|
+
if (!this.isEnabled(particle) || !particle.options.size) {
|
|
3854
3871
|
return;
|
|
3855
3872
|
}
|
|
3856
3873
|
updateAnimation(particle, particle.size, true, particle.options.size.animation.destroy, delta);
|
|
@@ -3858,7 +3875,7 @@
|
|
|
3858
3875
|
}
|
|
3859
3876
|
|
|
3860
3877
|
async function loadSizeUpdater(engine) {
|
|
3861
|
-
engine.checkVersion("4.
|
|
3878
|
+
engine.checkVersion("4.1.1");
|
|
3862
3879
|
await engine.pluginManager.register(e => {
|
|
3863
3880
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3864
3881
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3867,7 +3884,7 @@
|
|
|
3867
3884
|
}
|
|
3868
3885
|
|
|
3869
3886
|
async function loadBasic(engine) {
|
|
3870
|
-
engine.checkVersion("4.
|
|
3887
|
+
engine.checkVersion("4.1.1");
|
|
3871
3888
|
await engine.pluginManager.register(async (e) => {
|
|
3872
3889
|
await Promise.all([
|
|
3873
3890
|
loadBlendPlugin(e),
|
|
@@ -3994,20 +4011,20 @@
|
|
|
3994
4011
|
})(InteractivityDetect || (InteractivityDetect = {}));
|
|
3995
4012
|
|
|
3996
4013
|
class Modes {
|
|
3997
|
-
|
|
3998
|
-
|
|
4014
|
+
#container;
|
|
4015
|
+
#pluginManager;
|
|
3999
4016
|
constructor(pluginManager, container) {
|
|
4000
|
-
this
|
|
4001
|
-
this
|
|
4017
|
+
this.#pluginManager = pluginManager;
|
|
4018
|
+
this.#container = container;
|
|
4002
4019
|
}
|
|
4003
4020
|
load(data) {
|
|
4004
4021
|
if (isNull(data)) {
|
|
4005
4022
|
return;
|
|
4006
4023
|
}
|
|
4007
|
-
if (!this
|
|
4024
|
+
if (!this.#container) {
|
|
4008
4025
|
return;
|
|
4009
4026
|
}
|
|
4010
|
-
const interactors = this.
|
|
4027
|
+
const interactors = this.#pluginManager.interactors?.get(this.#container);
|
|
4011
4028
|
if (!interactors) {
|
|
4012
4029
|
return;
|
|
4013
4030
|
}
|
|
@@ -4044,13 +4061,13 @@
|
|
|
4044
4061
|
|
|
4045
4062
|
class InteractivityPlugin {
|
|
4046
4063
|
id = "interactivity";
|
|
4047
|
-
|
|
4064
|
+
#pluginManager;
|
|
4048
4065
|
constructor(pluginManager) {
|
|
4049
|
-
this
|
|
4066
|
+
this.#pluginManager = pluginManager;
|
|
4050
4067
|
}
|
|
4051
4068
|
async getPlugin(container) {
|
|
4052
4069
|
const { InteractivityPluginInstance } = await Promise.resolve().then(function () { return InteractivityPluginInstance$1; });
|
|
4053
|
-
return new InteractivityPluginInstance(this
|
|
4070
|
+
return new InteractivityPluginInstance(this.#pluginManager, container);
|
|
4054
4071
|
}
|
|
4055
4072
|
loadOptions(container, options, source) {
|
|
4056
4073
|
if (!this.needsPlugin()) {
|
|
@@ -4058,10 +4075,10 @@
|
|
|
4058
4075
|
}
|
|
4059
4076
|
let interactivityOptions = options.interactivity;
|
|
4060
4077
|
if (!interactivityOptions?.load) {
|
|
4061
|
-
options.interactivity = interactivityOptions = new Interactivity(this
|
|
4078
|
+
options.interactivity = interactivityOptions = new Interactivity(this.#pluginManager, container);
|
|
4062
4079
|
}
|
|
4063
4080
|
interactivityOptions.load(source?.interactivity);
|
|
4064
|
-
const interactors = this.
|
|
4081
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
4065
4082
|
if (!interactors) {
|
|
4066
4083
|
return;
|
|
4067
4084
|
}
|
|
@@ -4075,7 +4092,7 @@
|
|
|
4075
4092
|
if (source?.interactivity) {
|
|
4076
4093
|
options.interactivity = deepExtend({}, source.interactivity);
|
|
4077
4094
|
}
|
|
4078
|
-
const interactors = this.
|
|
4095
|
+
const interactors = this.#pluginManager.interactors?.get(container);
|
|
4079
4096
|
if (!interactors) {
|
|
4080
4097
|
return;
|
|
4081
4098
|
}
|
|
@@ -4105,7 +4122,7 @@
|
|
|
4105
4122
|
const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
|
|
4106
4123
|
|
|
4107
4124
|
async function loadInteractivityPlugin(engine) {
|
|
4108
|
-
engine.checkVersion("4.
|
|
4125
|
+
engine.checkVersion("4.1.1");
|
|
4109
4126
|
await engine.pluginManager.register(e => {
|
|
4110
4127
|
const interactivityEngine = e, interactivityPluginManager = interactivityEngine.pluginManager;
|
|
4111
4128
|
interactivityPluginManager.addPlugin(new InteractivityPlugin(interactivityPluginManager));
|
|
@@ -4369,7 +4386,7 @@
|
|
|
4369
4386
|
}
|
|
4370
4387
|
|
|
4371
4388
|
async function loadParticlesCollisionsInteraction(engine) {
|
|
4372
|
-
engine.checkVersion("4.
|
|
4389
|
+
engine.checkVersion("4.1.1");
|
|
4373
4390
|
await engine.pluginManager.register((e) => {
|
|
4374
4391
|
ensureInteractivityPluginLoaded(e);
|
|
4375
4392
|
e.pluginManager.addPlugin(new OverlapPlugin());
|
|
@@ -4380,15 +4397,15 @@
|
|
|
4380
4397
|
}
|
|
4381
4398
|
|
|
4382
4399
|
class CircleWarp extends Circle {
|
|
4383
|
-
canvasSize;
|
|
4400
|
+
#canvasSize;
|
|
4384
4401
|
constructor(x, y, radius, canvasSize) {
|
|
4385
4402
|
super(x, y, radius);
|
|
4386
|
-
this
|
|
4403
|
+
this.#canvasSize = canvasSize;
|
|
4387
4404
|
}
|
|
4388
4405
|
contains(point) {
|
|
4389
4406
|
if (super.contains(point))
|
|
4390
4407
|
return true;
|
|
4391
|
-
const { width, height } = this
|
|
4408
|
+
const { width, height } = this.#canvasSize, { x, y } = point;
|
|
4392
4409
|
return (super.contains({ x: x - width, y }) ||
|
|
4393
4410
|
super.contains({ x: x + width, y }) ||
|
|
4394
4411
|
super.contains({ x, y: y - height }) ||
|
|
@@ -4401,7 +4418,7 @@
|
|
|
4401
4418
|
intersects(range) {
|
|
4402
4419
|
if (super.intersects(range))
|
|
4403
4420
|
return true;
|
|
4404
|
-
const { width, height } = this
|
|
4421
|
+
const { width, height } = this.#canvasSize, pos = range.position, shifts = [
|
|
4405
4422
|
{ x: -width, y: 0 },
|
|
4406
4423
|
{ x: width, y: 0 },
|
|
4407
4424
|
{ x: 0, y: -height },
|
|
@@ -4553,15 +4570,15 @@
|
|
|
4553
4570
|
return Math.hypot(warpDistances.x, warpDistances.y);
|
|
4554
4571
|
}
|
|
4555
4572
|
class Linker extends ParticlesInteractorBase {
|
|
4556
|
-
|
|
4557
|
-
|
|
4573
|
+
#maxDistance;
|
|
4574
|
+
#pluginManager;
|
|
4558
4575
|
constructor(pluginManager, container) {
|
|
4559
4576
|
super(container);
|
|
4560
|
-
this
|
|
4561
|
-
this
|
|
4577
|
+
this.#pluginManager = pluginManager;
|
|
4578
|
+
this.#maxDistance = 0;
|
|
4562
4579
|
}
|
|
4563
4580
|
get maxDistance() {
|
|
4564
|
-
return this
|
|
4581
|
+
return this.#maxDistance;
|
|
4565
4582
|
}
|
|
4566
4583
|
clear() {
|
|
4567
4584
|
}
|
|
@@ -4574,8 +4591,8 @@
|
|
|
4574
4591
|
return;
|
|
4575
4592
|
}
|
|
4576
4593
|
p1.links = [];
|
|
4577
|
-
if (p1.linksDistance && p1.linksDistance > this
|
|
4578
|
-
this
|
|
4594
|
+
if (p1.linksDistance && p1.linksDistance > this.#maxDistance) {
|
|
4595
|
+
this.#maxDistance = p1.linksDistance;
|
|
4579
4596
|
}
|
|
4580
4597
|
const pos1 = p1.getPosition(), container = this.container, canvasSize = container.canvas.size;
|
|
4581
4598
|
if (pos1.x < originPoint.x || pos1.y < originPoint.y || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
|
@@ -4603,11 +4620,11 @@
|
|
|
4603
4620
|
continue;
|
|
4604
4621
|
}
|
|
4605
4622
|
const opacityLine = (opacityOffset - distance / optDistance) * optOpacity;
|
|
4606
|
-
this
|
|
4623
|
+
this.#setColor(p1);
|
|
4607
4624
|
p1.links.push({
|
|
4608
4625
|
destination: p2,
|
|
4609
4626
|
opacity: opacityLine,
|
|
4610
|
-
color: this
|
|
4627
|
+
color: this.#getLinkColor(p1, p2),
|
|
4611
4628
|
isWarped: distWarp < distDirect,
|
|
4612
4629
|
});
|
|
4613
4630
|
}
|
|
@@ -4623,7 +4640,7 @@
|
|
|
4623
4640
|
}
|
|
4624
4641
|
reset() {
|
|
4625
4642
|
}
|
|
4626
|
-
|
|
4643
|
+
#getLinkColor(p1, p2) {
|
|
4627
4644
|
const container = this.container, linksOptions = p1.options.links;
|
|
4628
4645
|
if (!linksOptions) {
|
|
4629
4646
|
return;
|
|
@@ -4633,7 +4650,7 @@
|
|
|
4633
4650
|
: container.particles.linksColor;
|
|
4634
4651
|
return getLinkColor(p1, p2, linkColor);
|
|
4635
4652
|
}
|
|
4636
|
-
|
|
4653
|
+
#setColor(p1) {
|
|
4637
4654
|
if (!p1.options.links) {
|
|
4638
4655
|
return;
|
|
4639
4656
|
}
|
|
@@ -4644,7 +4661,7 @@
|
|
|
4644
4661
|
if (linkColor) {
|
|
4645
4662
|
return;
|
|
4646
4663
|
}
|
|
4647
|
-
linkColor = getLinkRandomColor(this
|
|
4664
|
+
linkColor = getLinkRandomColor(this.#pluginManager, linksOptions.color, linksOptions.blink, linksOptions.consent);
|
|
4648
4665
|
if (linksOptions.id === undefined) {
|
|
4649
4666
|
container.particles.linksColor = linkColor;
|
|
4650
4667
|
}
|
|
@@ -4656,13 +4673,13 @@
|
|
|
4656
4673
|
|
|
4657
4674
|
class LinksPlugin {
|
|
4658
4675
|
id = "links";
|
|
4659
|
-
|
|
4676
|
+
#pluginManager;
|
|
4660
4677
|
constructor(pluginManager) {
|
|
4661
|
-
this
|
|
4678
|
+
this.#pluginManager = pluginManager;
|
|
4662
4679
|
}
|
|
4663
4680
|
async getPlugin(container) {
|
|
4664
4681
|
const { LinkInstance } = await Promise.resolve().then(function () { return LinkInstance$1; });
|
|
4665
|
-
return new LinkInstance(this
|
|
4682
|
+
return new LinkInstance(this.#pluginManager, container);
|
|
4666
4683
|
}
|
|
4667
4684
|
loadOptions() {
|
|
4668
4685
|
}
|
|
@@ -4672,7 +4689,7 @@
|
|
|
4672
4689
|
}
|
|
4673
4690
|
|
|
4674
4691
|
async function loadParticlesLinksInteraction(engine) {
|
|
4675
|
-
engine.checkVersion("4.
|
|
4692
|
+
engine.checkVersion("4.1.1");
|
|
4676
4693
|
await engine.pluginManager.register((e) => {
|
|
4677
4694
|
const pluginManager = e.pluginManager;
|
|
4678
4695
|
ensureInteractivityPluginLoaded(e);
|
|
@@ -4685,7 +4702,7 @@
|
|
|
4685
4702
|
|
|
4686
4703
|
let initPromise = null;
|
|
4687
4704
|
async function doInitPlugins(engine) {
|
|
4688
|
-
engine.checkVersion("4.
|
|
4705
|
+
engine.checkVersion("4.1.1");
|
|
4689
4706
|
await engine.pluginManager.register(async (e) => {
|
|
4690
4707
|
const loadParticlesInteractivity = async (e) => {
|
|
4691
4708
|
await loadInteractivityPlugin(e);
|
|
@@ -4728,7 +4745,7 @@
|
|
|
4728
4745
|
particles.init = async () => {
|
|
4729
4746
|
await initPlugins(tsParticles);
|
|
4730
4747
|
};
|
|
4731
|
-
particles.version = "4.
|
|
4748
|
+
particles.version = "4.1.1";
|
|
4732
4749
|
globalThis.particles = particles;
|
|
4733
4750
|
|
|
4734
4751
|
const globalObject = globalThis;
|
|
@@ -4743,58 +4760,58 @@
|
|
|
4743
4760
|
}
|
|
4744
4761
|
}
|
|
4745
4762
|
class RenderManager {
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4763
|
+
#canvasClearPlugins;
|
|
4764
|
+
#canvasManager;
|
|
4765
|
+
#canvasPaintPlugins;
|
|
4766
|
+
#clearDrawPlugins;
|
|
4767
|
+
#colorPlugins;
|
|
4768
|
+
#container;
|
|
4769
|
+
#context;
|
|
4770
|
+
#contextSettings;
|
|
4771
|
+
#drawParticlePlugins;
|
|
4772
|
+
#drawParticlesCleanupPlugins;
|
|
4773
|
+
#drawParticlesSetupPlugins;
|
|
4774
|
+
#drawPlugins;
|
|
4775
|
+
#drawSettingsCleanupPlugins;
|
|
4776
|
+
#drawSettingsSetupPlugins;
|
|
4777
|
+
#pluginManager;
|
|
4778
|
+
#postDrawUpdaters;
|
|
4779
|
+
#preDrawUpdaters;
|
|
4780
|
+
#reusableColorStyles = {};
|
|
4781
|
+
#reusablePluginColors = [undefined, undefined];
|
|
4782
|
+
#reusableTransform = {};
|
|
4766
4783
|
constructor(pluginManager, container, canvasManager) {
|
|
4767
|
-
this
|
|
4768
|
-
this
|
|
4769
|
-
this
|
|
4770
|
-
this
|
|
4771
|
-
this
|
|
4772
|
-
this
|
|
4773
|
-
this
|
|
4774
|
-
this
|
|
4775
|
-
this
|
|
4776
|
-
this
|
|
4777
|
-
this
|
|
4778
|
-
this
|
|
4779
|
-
this
|
|
4780
|
-
this
|
|
4781
|
-
this
|
|
4782
|
-
this
|
|
4784
|
+
this.#pluginManager = pluginManager;
|
|
4785
|
+
this.#container = container;
|
|
4786
|
+
this.#canvasManager = canvasManager;
|
|
4787
|
+
this.#context = null;
|
|
4788
|
+
this.#preDrawUpdaters = [];
|
|
4789
|
+
this.#postDrawUpdaters = [];
|
|
4790
|
+
this.#colorPlugins = [];
|
|
4791
|
+
this.#canvasClearPlugins = [];
|
|
4792
|
+
this.#canvasPaintPlugins = [];
|
|
4793
|
+
this.#clearDrawPlugins = [];
|
|
4794
|
+
this.#drawParticlePlugins = [];
|
|
4795
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4796
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4797
|
+
this.#drawPlugins = [];
|
|
4798
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4799
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4783
4800
|
}
|
|
4784
4801
|
get settings() {
|
|
4785
|
-
return this
|
|
4802
|
+
return this.#contextSettings;
|
|
4786
4803
|
}
|
|
4787
4804
|
canvasClear() {
|
|
4788
|
-
if (!this.
|
|
4805
|
+
if (!this.#container.actualOptions.clear) {
|
|
4789
4806
|
return;
|
|
4790
4807
|
}
|
|
4791
4808
|
this.draw(ctx => {
|
|
4792
|
-
clear(ctx, this.
|
|
4809
|
+
clear(ctx, this.#canvasManager.size);
|
|
4793
4810
|
});
|
|
4794
4811
|
}
|
|
4795
4812
|
clear() {
|
|
4796
4813
|
let pluginHandled = false;
|
|
4797
|
-
for (const plugin of this
|
|
4814
|
+
for (const plugin of this.#canvasClearPlugins) {
|
|
4798
4815
|
pluginHandled = plugin.canvasClear?.() ?? false;
|
|
4799
4816
|
if (pluginHandled) {
|
|
4800
4817
|
break;
|
|
@@ -4807,21 +4824,21 @@
|
|
|
4807
4824
|
}
|
|
4808
4825
|
destroy() {
|
|
4809
4826
|
this.stop();
|
|
4810
|
-
this
|
|
4811
|
-
this
|
|
4812
|
-
this
|
|
4813
|
-
this
|
|
4814
|
-
this
|
|
4815
|
-
this
|
|
4816
|
-
this
|
|
4817
|
-
this
|
|
4818
|
-
this
|
|
4819
|
-
this
|
|
4820
|
-
this
|
|
4821
|
-
this
|
|
4827
|
+
this.#preDrawUpdaters = [];
|
|
4828
|
+
this.#postDrawUpdaters = [];
|
|
4829
|
+
this.#colorPlugins = [];
|
|
4830
|
+
this.#canvasClearPlugins = [];
|
|
4831
|
+
this.#canvasPaintPlugins = [];
|
|
4832
|
+
this.#clearDrawPlugins = [];
|
|
4833
|
+
this.#drawParticlePlugins = [];
|
|
4834
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4835
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4836
|
+
this.#drawPlugins = [];
|
|
4837
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4838
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4822
4839
|
}
|
|
4823
4840
|
draw(cb) {
|
|
4824
|
-
const ctx = this
|
|
4841
|
+
const ctx = this.#context;
|
|
4825
4842
|
if (!ctx) {
|
|
4826
4843
|
return;
|
|
4827
4844
|
}
|
|
@@ -4836,21 +4853,21 @@
|
|
|
4836
4853
|
return;
|
|
4837
4854
|
}
|
|
4838
4855
|
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
4839
|
-
let [fColor, sColor] = this
|
|
4856
|
+
let [fColor, sColor] = this.#getPluginParticleColors(particle);
|
|
4840
4857
|
fColor ??= pfColor;
|
|
4841
4858
|
sColor ??= psColor;
|
|
4842
4859
|
if (!fColor && !sColor) {
|
|
4843
4860
|
return;
|
|
4844
4861
|
}
|
|
4845
|
-
const container = this
|
|
4862
|
+
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;
|
|
4846
4863
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
4847
4864
|
colorStyles.fill = fill;
|
|
4848
4865
|
colorStyles.stroke = stroke;
|
|
4849
4866
|
this.draw((context) => {
|
|
4850
|
-
for (const plugin of this
|
|
4867
|
+
for (const plugin of this.#drawParticlesSetupPlugins) {
|
|
4851
4868
|
plugin.drawParticleSetup?.(context, particle, delta);
|
|
4852
4869
|
}
|
|
4853
|
-
this
|
|
4870
|
+
this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
|
|
4854
4871
|
drawParticle({
|
|
4855
4872
|
container,
|
|
4856
4873
|
context,
|
|
@@ -4861,35 +4878,35 @@
|
|
|
4861
4878
|
opacity: opacity,
|
|
4862
4879
|
transform,
|
|
4863
4880
|
});
|
|
4864
|
-
this
|
|
4865
|
-
for (const plugin of this
|
|
4881
|
+
this.#applyPostDrawUpdaters(particle);
|
|
4882
|
+
for (const plugin of this.#drawParticlesCleanupPlugins) {
|
|
4866
4883
|
plugin.drawParticleCleanup?.(context, particle, delta);
|
|
4867
4884
|
}
|
|
4868
4885
|
});
|
|
4869
4886
|
}
|
|
4870
4887
|
drawParticlePlugins(particle, delta) {
|
|
4871
4888
|
this.draw(ctx => {
|
|
4872
|
-
for (const plugin of this
|
|
4889
|
+
for (const plugin of this.#drawParticlePlugins) {
|
|
4873
4890
|
drawParticlePlugin(ctx, plugin, particle, delta);
|
|
4874
4891
|
}
|
|
4875
4892
|
});
|
|
4876
4893
|
}
|
|
4877
4894
|
drawParticles(delta) {
|
|
4878
|
-
const { particles } = this
|
|
4895
|
+
const { particles } = this.#container;
|
|
4879
4896
|
this.clear();
|
|
4880
4897
|
particles.update(delta);
|
|
4881
4898
|
this.draw(ctx => {
|
|
4882
|
-
for (const plugin of this
|
|
4899
|
+
for (const plugin of this.#drawSettingsSetupPlugins) {
|
|
4883
4900
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
4884
4901
|
}
|
|
4885
|
-
for (const plugin of this
|
|
4902
|
+
for (const plugin of this.#drawPlugins) {
|
|
4886
4903
|
plugin.draw?.(ctx, delta);
|
|
4887
4904
|
}
|
|
4888
4905
|
particles.drawParticles(delta);
|
|
4889
|
-
for (const plugin of this
|
|
4906
|
+
for (const plugin of this.#clearDrawPlugins) {
|
|
4890
4907
|
plugin.clearDraw?.(ctx, delta);
|
|
4891
4908
|
}
|
|
4892
|
-
for (const plugin of this
|
|
4909
|
+
for (const plugin of this.#drawSettingsCleanupPlugins) {
|
|
4893
4910
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
4894
4911
|
}
|
|
4895
4912
|
});
|
|
@@ -4900,64 +4917,64 @@
|
|
|
4900
4917
|
this.paint();
|
|
4901
4918
|
}
|
|
4902
4919
|
initPlugins() {
|
|
4903
|
-
this
|
|
4904
|
-
this
|
|
4905
|
-
this
|
|
4906
|
-
this
|
|
4907
|
-
this
|
|
4908
|
-
this
|
|
4909
|
-
this
|
|
4910
|
-
this
|
|
4911
|
-
this
|
|
4912
|
-
this
|
|
4913
|
-
for (const plugin of this.
|
|
4920
|
+
this.#colorPlugins = [];
|
|
4921
|
+
this.#canvasClearPlugins = [];
|
|
4922
|
+
this.#canvasPaintPlugins = [];
|
|
4923
|
+
this.#clearDrawPlugins = [];
|
|
4924
|
+
this.#drawParticlePlugins = [];
|
|
4925
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4926
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4927
|
+
this.#drawPlugins = [];
|
|
4928
|
+
this.#drawSettingsSetupPlugins = [];
|
|
4929
|
+
this.#drawSettingsCleanupPlugins = [];
|
|
4930
|
+
for (const plugin of this.#container.plugins) {
|
|
4914
4931
|
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4915
|
-
this.
|
|
4932
|
+
this.#colorPlugins.push(plugin);
|
|
4916
4933
|
}
|
|
4917
4934
|
if (plugin.canvasClear) {
|
|
4918
|
-
this.
|
|
4935
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4919
4936
|
}
|
|
4920
4937
|
if (plugin.canvasPaint) {
|
|
4921
|
-
this.
|
|
4938
|
+
this.#canvasPaintPlugins.push(plugin);
|
|
4922
4939
|
}
|
|
4923
4940
|
if (plugin.drawParticle) {
|
|
4924
|
-
this.
|
|
4941
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4925
4942
|
}
|
|
4926
4943
|
if (plugin.drawParticleSetup) {
|
|
4927
|
-
this.
|
|
4944
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4928
4945
|
}
|
|
4929
4946
|
if (plugin.drawParticleCleanup) {
|
|
4930
|
-
this.
|
|
4947
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4931
4948
|
}
|
|
4932
4949
|
if (plugin.draw) {
|
|
4933
|
-
this.
|
|
4950
|
+
this.#drawPlugins.push(plugin);
|
|
4934
4951
|
}
|
|
4935
4952
|
if (plugin.drawSettingsSetup) {
|
|
4936
|
-
this.
|
|
4953
|
+
this.#drawSettingsSetupPlugins.push(plugin);
|
|
4937
4954
|
}
|
|
4938
4955
|
if (plugin.drawSettingsCleanup) {
|
|
4939
|
-
this.
|
|
4956
|
+
this.#drawSettingsCleanupPlugins.push(plugin);
|
|
4940
4957
|
}
|
|
4941
4958
|
if (plugin.clearDraw) {
|
|
4942
|
-
this.
|
|
4959
|
+
this.#clearDrawPlugins.push(plugin);
|
|
4943
4960
|
}
|
|
4944
4961
|
}
|
|
4945
4962
|
}
|
|
4946
4963
|
initUpdaters() {
|
|
4947
|
-
this
|
|
4948
|
-
this
|
|
4949
|
-
for (const updater of this.
|
|
4964
|
+
this.#preDrawUpdaters = [];
|
|
4965
|
+
this.#postDrawUpdaters = [];
|
|
4966
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
4950
4967
|
if (updater.afterDraw) {
|
|
4951
|
-
this.
|
|
4968
|
+
this.#postDrawUpdaters.push(updater);
|
|
4952
4969
|
}
|
|
4953
4970
|
if (updater.getColorStyles ?? updater.getTransformValues ?? updater.beforeDraw) {
|
|
4954
|
-
this.
|
|
4971
|
+
this.#preDrawUpdaters.push(updater);
|
|
4955
4972
|
}
|
|
4956
4973
|
}
|
|
4957
4974
|
}
|
|
4958
4975
|
paint() {
|
|
4959
4976
|
let handled = false;
|
|
4960
|
-
for (const plugin of this
|
|
4977
|
+
for (const plugin of this.#canvasPaintPlugins) {
|
|
4961
4978
|
handled = plugin.canvasPaint?.() ?? false;
|
|
4962
4979
|
if (handled) {
|
|
4963
4980
|
break;
|
|
@@ -4970,35 +4987,35 @@
|
|
|
4970
4987
|
}
|
|
4971
4988
|
paintBase(baseColor) {
|
|
4972
4989
|
this.draw(ctx => {
|
|
4973
|
-
paintBase(ctx, this.
|
|
4990
|
+
paintBase(ctx, this.#canvasManager.size, baseColor);
|
|
4974
4991
|
});
|
|
4975
4992
|
}
|
|
4976
4993
|
paintImage(image, opacity) {
|
|
4977
4994
|
this.draw(ctx => {
|
|
4978
|
-
paintImage(ctx, this.
|
|
4995
|
+
paintImage(ctx, this.#canvasManager.size, image, opacity);
|
|
4979
4996
|
});
|
|
4980
4997
|
}
|
|
4981
4998
|
setContext(context) {
|
|
4982
|
-
this
|
|
4983
|
-
if (this
|
|
4984
|
-
this.
|
|
4999
|
+
this.#context = context;
|
|
5000
|
+
if (this.#context) {
|
|
5001
|
+
this.#context.globalCompositeOperation = defaultCompositeValue;
|
|
4985
5002
|
}
|
|
4986
5003
|
}
|
|
4987
5004
|
setContextSettings(settings) {
|
|
4988
|
-
this
|
|
5005
|
+
this.#contextSettings = settings;
|
|
4989
5006
|
}
|
|
4990
5007
|
stop() {
|
|
4991
5008
|
this.draw(ctx => {
|
|
4992
|
-
clear(ctx, this.
|
|
5009
|
+
clear(ctx, this.#canvasManager.size);
|
|
4993
5010
|
});
|
|
4994
5011
|
}
|
|
4995
|
-
|
|
4996
|
-
for (const updater of this
|
|
5012
|
+
#applyPostDrawUpdaters = particle => {
|
|
5013
|
+
for (const updater of this.#postDrawUpdaters) {
|
|
4997
5014
|
updater.afterDraw?.(particle);
|
|
4998
5015
|
}
|
|
4999
5016
|
};
|
|
5000
|
-
|
|
5001
|
-
for (const updater of this
|
|
5017
|
+
#applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
|
|
5018
|
+
for (const updater of this.#preDrawUpdaters) {
|
|
5002
5019
|
if (updater.getColorStyles) {
|
|
5003
5020
|
const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
|
5004
5021
|
if (fill) {
|
|
@@ -5017,22 +5034,22 @@
|
|
|
5017
5034
|
updater.beforeDraw?.(particle);
|
|
5018
5035
|
}
|
|
5019
5036
|
};
|
|
5020
|
-
|
|
5037
|
+
#getPluginParticleColors = particle => {
|
|
5021
5038
|
let fColor, sColor;
|
|
5022
|
-
for (const plugin of this
|
|
5039
|
+
for (const plugin of this.#colorPlugins) {
|
|
5023
5040
|
if (!fColor && plugin.particleFillColor) {
|
|
5024
|
-
fColor = rangeColorToHsl(this
|
|
5041
|
+
fColor = rangeColorToHsl(this.#pluginManager, plugin.particleFillColor(particle));
|
|
5025
5042
|
}
|
|
5026
5043
|
if (!sColor && plugin.particleStrokeColor) {
|
|
5027
|
-
sColor = rangeColorToHsl(this
|
|
5044
|
+
sColor = rangeColorToHsl(this.#pluginManager, plugin.particleStrokeColor(particle));
|
|
5028
5045
|
}
|
|
5029
5046
|
if (fColor && sColor) {
|
|
5030
5047
|
break;
|
|
5031
5048
|
}
|
|
5032
5049
|
}
|
|
5033
|
-
this
|
|
5034
|
-
this
|
|
5035
|
-
return this
|
|
5050
|
+
this.#reusablePluginColors[fColorIndex] = fColor;
|
|
5051
|
+
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
5052
|
+
return this.#reusablePluginColors;
|
|
5036
5053
|
};
|
|
5037
5054
|
}
|
|
5038
5055
|
|
|
@@ -5090,53 +5107,53 @@
|
|
|
5090
5107
|
renderCanvas;
|
|
5091
5108
|
size;
|
|
5092
5109
|
zoom = defaultZoom;
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5110
|
+
#container;
|
|
5111
|
+
#generated;
|
|
5112
|
+
#mutationObserver;
|
|
5113
|
+
#originalStyle;
|
|
5114
|
+
#pluginManager;
|
|
5115
|
+
#pointerEvents;
|
|
5116
|
+
#resizePlugins;
|
|
5117
|
+
#standardSize;
|
|
5118
|
+
#zoomCenter;
|
|
5102
5119
|
constructor(pluginManager, container) {
|
|
5103
|
-
this
|
|
5104
|
-
this
|
|
5120
|
+
this.#pluginManager = pluginManager;
|
|
5121
|
+
this.#container = container;
|
|
5105
5122
|
this.render = new RenderManager(pluginManager, container, this);
|
|
5106
|
-
this
|
|
5123
|
+
this.#standardSize = {
|
|
5107
5124
|
height: 0,
|
|
5108
5125
|
width: 0,
|
|
5109
5126
|
};
|
|
5110
|
-
const pxRatio = container.retina.pixelRatio, stdSize = this
|
|
5127
|
+
const pxRatio = container.retina.pixelRatio, stdSize = this.#standardSize;
|
|
5111
5128
|
this.size = {
|
|
5112
5129
|
height: stdSize.height * pxRatio,
|
|
5113
5130
|
width: stdSize.width * pxRatio,
|
|
5114
5131
|
};
|
|
5115
|
-
this
|
|
5116
|
-
this
|
|
5117
|
-
this
|
|
5132
|
+
this.#generated = false;
|
|
5133
|
+
this.#resizePlugins = [];
|
|
5134
|
+
this.#pointerEvents = "none";
|
|
5118
5135
|
}
|
|
5119
|
-
get
|
|
5120
|
-
return this.
|
|
5136
|
+
get #fullScreen() {
|
|
5137
|
+
return this.#container.actualOptions.fullScreen.enable;
|
|
5121
5138
|
}
|
|
5122
5139
|
destroy() {
|
|
5123
5140
|
this.stop();
|
|
5124
|
-
if (this
|
|
5141
|
+
if (this.#generated) {
|
|
5125
5142
|
const element = this.domElement;
|
|
5126
5143
|
element?.remove();
|
|
5127
5144
|
this.domElement = undefined;
|
|
5128
5145
|
this.renderCanvas = undefined;
|
|
5129
5146
|
}
|
|
5130
5147
|
else {
|
|
5131
|
-
this
|
|
5148
|
+
this.#resetOriginalStyle();
|
|
5132
5149
|
}
|
|
5133
5150
|
this.render.destroy();
|
|
5134
|
-
this
|
|
5151
|
+
this.#resizePlugins = [];
|
|
5135
5152
|
}
|
|
5136
5153
|
getZoomCenter() {
|
|
5137
|
-
const pxRatio = this.
|
|
5138
|
-
if (this
|
|
5139
|
-
return this
|
|
5154
|
+
const pxRatio = this.#container.retina.pixelRatio, { width, height } = this.size;
|
|
5155
|
+
if (this.#zoomCenter) {
|
|
5156
|
+
return this.#zoomCenter;
|
|
5140
5157
|
}
|
|
5141
5158
|
return {
|
|
5142
5159
|
x: (width * half) / pxRatio,
|
|
@@ -5144,20 +5161,20 @@
|
|
|
5144
5161
|
};
|
|
5145
5162
|
}
|
|
5146
5163
|
init() {
|
|
5147
|
-
this
|
|
5164
|
+
this.#safeMutationObserver(obs => {
|
|
5148
5165
|
obs.disconnect();
|
|
5149
5166
|
});
|
|
5150
|
-
this
|
|
5167
|
+
this.#mutationObserver = safeMutationObserver(records => {
|
|
5151
5168
|
for (const record of records) {
|
|
5152
5169
|
if (record.type === "attributes" && record.attributeName === "style") {
|
|
5153
|
-
this
|
|
5170
|
+
this.#repairStyle();
|
|
5154
5171
|
}
|
|
5155
5172
|
}
|
|
5156
5173
|
});
|
|
5157
5174
|
this.resize();
|
|
5158
|
-
this
|
|
5175
|
+
this.#initStyle();
|
|
5159
5176
|
this.initBackground();
|
|
5160
|
-
this
|
|
5177
|
+
this.#safeMutationObserver(obs => {
|
|
5161
5178
|
const element = this.domElement;
|
|
5162
5179
|
if (!element || !(element instanceof Node)) {
|
|
5163
5180
|
return;
|
|
@@ -5168,13 +5185,13 @@
|
|
|
5168
5185
|
this.render.init();
|
|
5169
5186
|
}
|
|
5170
5187
|
initBackground() {
|
|
5171
|
-
const
|
|
5188
|
+
const container = this.#container, options = container.actualOptions, background = options.background, element = this.domElement;
|
|
5172
5189
|
if (!element) {
|
|
5173
5190
|
return;
|
|
5174
5191
|
}
|
|
5175
|
-
const elementStyle = element.style, color = rangeColorToRgb(this
|
|
5192
|
+
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
5176
5193
|
if (color) {
|
|
5177
|
-
elementStyle.backgroundColor = getStyleFromRgb(color,
|
|
5194
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
|
|
5178
5195
|
}
|
|
5179
5196
|
else {
|
|
5180
5197
|
elementStyle.backgroundColor = "";
|
|
@@ -5185,27 +5202,27 @@
|
|
|
5185
5202
|
elementStyle.backgroundSize = background.size || "";
|
|
5186
5203
|
}
|
|
5187
5204
|
initPlugins() {
|
|
5188
|
-
this
|
|
5189
|
-
for (const plugin of this.
|
|
5205
|
+
this.#resizePlugins = [];
|
|
5206
|
+
for (const plugin of this.#container.plugins) {
|
|
5190
5207
|
if (plugin.resize) {
|
|
5191
|
-
this.
|
|
5208
|
+
this.#resizePlugins.push(plugin);
|
|
5192
5209
|
}
|
|
5193
5210
|
}
|
|
5194
5211
|
}
|
|
5195
5212
|
loadCanvas(canvas) {
|
|
5196
|
-
if (this
|
|
5213
|
+
if (this.#generated && this.domElement) {
|
|
5197
5214
|
this.domElement.remove();
|
|
5198
5215
|
}
|
|
5199
|
-
const container = this
|
|
5216
|
+
const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
|
|
5200
5217
|
this.domElement = domCanvas;
|
|
5201
|
-
this
|
|
5218
|
+
this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
|
|
5202
5219
|
this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
|
|
5203
5220
|
const domElement = this.domElement;
|
|
5204
5221
|
if (domElement) {
|
|
5205
5222
|
domElement.ariaHidden = "true";
|
|
5206
|
-
this
|
|
5223
|
+
this.#originalStyle = cloneStyle(domElement.style);
|
|
5207
5224
|
}
|
|
5208
|
-
const standardSize = this
|
|
5225
|
+
const standardSize = this.#standardSize, renderCanvas = this.renderCanvas;
|
|
5209
5226
|
if (domElement) {
|
|
5210
5227
|
standardSize.height = domElement.offsetHeight;
|
|
5211
5228
|
standardSize.width = domElement.offsetWidth;
|
|
@@ -5214,7 +5231,7 @@
|
|
|
5214
5231
|
standardSize.height = renderCanvas.height;
|
|
5215
5232
|
standardSize.width = renderCanvas.width;
|
|
5216
5233
|
}
|
|
5217
|
-
const pxRatio = this.
|
|
5234
|
+
const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
|
|
5218
5235
|
renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
|
|
5219
5236
|
renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
|
|
5220
5237
|
const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
|
|
@@ -5225,12 +5242,12 @@
|
|
|
5225
5242
|
willReadFrequently: false,
|
|
5226
5243
|
});
|
|
5227
5244
|
this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
|
|
5228
|
-
this
|
|
5245
|
+
this.#safeMutationObserver(obs => {
|
|
5229
5246
|
obs.disconnect();
|
|
5230
5247
|
});
|
|
5231
5248
|
container.retina.init();
|
|
5232
5249
|
this.initBackground();
|
|
5233
|
-
this
|
|
5250
|
+
this.#safeMutationObserver(obs => {
|
|
5234
5251
|
const element = this.domElement;
|
|
5235
5252
|
if (!element || !(element instanceof Node)) {
|
|
5236
5253
|
return;
|
|
@@ -5243,11 +5260,11 @@
|
|
|
5243
5260
|
if (!element) {
|
|
5244
5261
|
return false;
|
|
5245
5262
|
}
|
|
5246
|
-
const container = this
|
|
5263
|
+
const container = this.#container, renderCanvas = this.renderCanvas;
|
|
5247
5264
|
if (renderCanvas === undefined) {
|
|
5248
5265
|
return false;
|
|
5249
5266
|
}
|
|
5250
|
-
const currentSize = container.canvas
|
|
5267
|
+
const currentSize = container.canvas.#standardSize, newSize = {
|
|
5251
5268
|
width: element.offsetWidth,
|
|
5252
5269
|
height: element.offsetHeight,
|
|
5253
5270
|
}, pxRatio = container.retina.pixelRatio, retinaSize = {
|
|
@@ -5266,7 +5283,7 @@
|
|
|
5266
5283
|
const canvasSize = this.size;
|
|
5267
5284
|
renderCanvas.width = canvasSize.width = retinaSize.width;
|
|
5268
5285
|
renderCanvas.height = canvasSize.height = retinaSize.height;
|
|
5269
|
-
if (this.
|
|
5286
|
+
if (this.#container.started) {
|
|
5270
5287
|
container.particles.setResizeFactor({
|
|
5271
5288
|
width: currentSize.width / oldSize.width,
|
|
5272
5289
|
height: currentSize.height / oldSize.height,
|
|
@@ -5279,46 +5296,46 @@
|
|
|
5279
5296
|
if (!element) {
|
|
5280
5297
|
return;
|
|
5281
5298
|
}
|
|
5282
|
-
this
|
|
5283
|
-
this
|
|
5299
|
+
this.#pointerEvents = type;
|
|
5300
|
+
this.#repairStyle();
|
|
5284
5301
|
}
|
|
5285
5302
|
setZoom(zoomLevel, center) {
|
|
5286
5303
|
this.zoom = zoomLevel;
|
|
5287
|
-
this
|
|
5304
|
+
this.#zoomCenter = center;
|
|
5288
5305
|
}
|
|
5289
5306
|
stop() {
|
|
5290
|
-
this
|
|
5307
|
+
this.#safeMutationObserver(obs => {
|
|
5291
5308
|
obs.disconnect();
|
|
5292
5309
|
});
|
|
5293
|
-
this
|
|
5310
|
+
this.#mutationObserver = undefined;
|
|
5294
5311
|
this.render.stop();
|
|
5295
5312
|
}
|
|
5296
5313
|
async windowResize() {
|
|
5297
5314
|
if (!this.domElement || !this.resize()) {
|
|
5298
5315
|
return;
|
|
5299
5316
|
}
|
|
5300
|
-
const container = this
|
|
5317
|
+
const container = this.#container, needsRefresh = container.updateActualOptions();
|
|
5301
5318
|
container.particles.setDensity();
|
|
5302
|
-
this
|
|
5319
|
+
this.#applyResizePlugins();
|
|
5303
5320
|
if (needsRefresh) {
|
|
5304
5321
|
await container.refresh();
|
|
5305
5322
|
}
|
|
5306
5323
|
}
|
|
5307
|
-
|
|
5308
|
-
for (const plugin of this
|
|
5324
|
+
#applyResizePlugins = () => {
|
|
5325
|
+
for (const plugin of this.#resizePlugins) {
|
|
5309
5326
|
plugin.resize?.();
|
|
5310
5327
|
}
|
|
5311
5328
|
};
|
|
5312
|
-
|
|
5313
|
-
const element = this.domElement, options = this.
|
|
5329
|
+
#initStyle = () => {
|
|
5330
|
+
const element = this.domElement, options = this.#container.actualOptions;
|
|
5314
5331
|
if (!element) {
|
|
5315
5332
|
return;
|
|
5316
5333
|
}
|
|
5317
|
-
if (this
|
|
5318
|
-
this
|
|
5334
|
+
if (this.#fullScreen) {
|
|
5335
|
+
this.#setFullScreenStyle();
|
|
5319
5336
|
}
|
|
5320
5337
|
else {
|
|
5321
|
-
this
|
|
5338
|
+
this.#resetOriginalStyle();
|
|
5322
5339
|
}
|
|
5323
5340
|
for (const key in options.style) {
|
|
5324
5341
|
if (!key || !(key in options.style)) {
|
|
@@ -5331,72 +5348,72 @@
|
|
|
5331
5348
|
element.style.setProperty(key, value, "important");
|
|
5332
5349
|
}
|
|
5333
5350
|
};
|
|
5334
|
-
|
|
5351
|
+
#repairStyle = () => {
|
|
5335
5352
|
const element = this.domElement;
|
|
5336
5353
|
if (!element) {
|
|
5337
5354
|
return;
|
|
5338
5355
|
}
|
|
5339
|
-
this
|
|
5356
|
+
this.#safeMutationObserver(observer => {
|
|
5340
5357
|
observer.disconnect();
|
|
5341
5358
|
});
|
|
5342
|
-
this
|
|
5359
|
+
this.#initStyle();
|
|
5343
5360
|
this.initBackground();
|
|
5344
|
-
const pointerEvents = this
|
|
5361
|
+
const pointerEvents = this.#pointerEvents;
|
|
5345
5362
|
element.style.pointerEvents = pointerEvents;
|
|
5346
5363
|
element.style.setProperty("pointer-events", pointerEvents);
|
|
5347
|
-
this
|
|
5364
|
+
this.#safeMutationObserver(observer => {
|
|
5348
5365
|
if (!(element instanceof Node)) {
|
|
5349
5366
|
return;
|
|
5350
5367
|
}
|
|
5351
5368
|
observer.observe(element, { attributes: true });
|
|
5352
5369
|
});
|
|
5353
5370
|
};
|
|
5354
|
-
|
|
5355
|
-
const element = this.domElement, originalStyle = this
|
|
5371
|
+
#resetOriginalStyle = () => {
|
|
5372
|
+
const element = this.domElement, originalStyle = this.#originalStyle;
|
|
5356
5373
|
if (!element || !originalStyle) {
|
|
5357
5374
|
return;
|
|
5358
5375
|
}
|
|
5359
5376
|
setStyle(element, originalStyle, true);
|
|
5360
5377
|
};
|
|
5361
|
-
|
|
5362
|
-
if (!this
|
|
5378
|
+
#safeMutationObserver = callback => {
|
|
5379
|
+
if (!this.#mutationObserver) {
|
|
5363
5380
|
return;
|
|
5364
5381
|
}
|
|
5365
|
-
callback(this
|
|
5382
|
+
callback(this.#mutationObserver);
|
|
5366
5383
|
};
|
|
5367
|
-
|
|
5384
|
+
#setFullScreenStyle = () => {
|
|
5368
5385
|
const element = this.domElement;
|
|
5369
5386
|
if (!element) {
|
|
5370
5387
|
return;
|
|
5371
5388
|
}
|
|
5372
|
-
setStyle(element, getFullScreenStyle(this.
|
|
5389
|
+
setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
|
|
5373
5390
|
};
|
|
5374
5391
|
}
|
|
5375
5392
|
|
|
5376
5393
|
class EventListeners {
|
|
5377
|
-
container;
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5394
|
+
#container;
|
|
5395
|
+
#handlers;
|
|
5396
|
+
#resizeObserver;
|
|
5397
|
+
#resizeTimeout;
|
|
5381
5398
|
constructor(container) {
|
|
5382
|
-
this
|
|
5383
|
-
this
|
|
5399
|
+
this.#container = container;
|
|
5400
|
+
this.#handlers = {
|
|
5384
5401
|
visibilityChange: () => {
|
|
5385
|
-
this
|
|
5402
|
+
this.#handleVisibilityChange();
|
|
5386
5403
|
},
|
|
5387
5404
|
resize: () => {
|
|
5388
|
-
this
|
|
5405
|
+
this.#handleWindowResize();
|
|
5389
5406
|
},
|
|
5390
5407
|
};
|
|
5391
5408
|
}
|
|
5392
5409
|
addListeners() {
|
|
5393
|
-
this
|
|
5410
|
+
this.#manageListeners(true);
|
|
5394
5411
|
}
|
|
5395
5412
|
removeListeners() {
|
|
5396
|
-
this
|
|
5413
|
+
this.#manageListeners(false);
|
|
5397
5414
|
}
|
|
5398
|
-
|
|
5399
|
-
const container = this
|
|
5415
|
+
#handleVisibilityChange = () => {
|
|
5416
|
+
const container = this.#container, options = container.actualOptions;
|
|
5400
5417
|
if (!options.pauseOnBlur) {
|
|
5401
5418
|
return;
|
|
5402
5419
|
}
|
|
@@ -5414,24 +5431,24 @@
|
|
|
5414
5431
|
}
|
|
5415
5432
|
}
|
|
5416
5433
|
};
|
|
5417
|
-
|
|
5418
|
-
if (this
|
|
5419
|
-
clearTimeout(this
|
|
5420
|
-
|
|
5434
|
+
#handleWindowResize = () => {
|
|
5435
|
+
if (this.#resizeTimeout) {
|
|
5436
|
+
clearTimeout(this.#resizeTimeout);
|
|
5437
|
+
this.#resizeTimeout = undefined;
|
|
5421
5438
|
}
|
|
5422
5439
|
const handleResize = async () => {
|
|
5423
|
-
const canvas = this
|
|
5440
|
+
const canvas = this.#container.canvas;
|
|
5424
5441
|
await canvas.windowResize();
|
|
5425
5442
|
};
|
|
5426
|
-
this
|
|
5443
|
+
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
5427
5444
|
};
|
|
5428
|
-
|
|
5429
|
-
const handlers = this
|
|
5430
|
-
this
|
|
5445
|
+
#manageListeners = add => {
|
|
5446
|
+
const handlers = this.#handlers;
|
|
5447
|
+
this.#manageResize(add);
|
|
5431
5448
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
5432
5449
|
};
|
|
5433
|
-
|
|
5434
|
-
const handlers = this
|
|
5450
|
+
#manageResize = add => {
|
|
5451
|
+
const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
|
|
5435
5452
|
if (!options.resize.enable) {
|
|
5436
5453
|
return;
|
|
5437
5454
|
}
|
|
@@ -5440,22 +5457,22 @@
|
|
|
5440
5457
|
return;
|
|
5441
5458
|
}
|
|
5442
5459
|
const canvasEl = container.canvas.domElement;
|
|
5443
|
-
if (this
|
|
5460
|
+
if (this.#resizeObserver && !add) {
|
|
5444
5461
|
if (canvasEl) {
|
|
5445
|
-
this.
|
|
5462
|
+
this.#resizeObserver.unobserve(canvasEl);
|
|
5446
5463
|
}
|
|
5447
|
-
this.
|
|
5448
|
-
|
|
5464
|
+
this.#resizeObserver.disconnect();
|
|
5465
|
+
this.#resizeObserver = undefined;
|
|
5449
5466
|
}
|
|
5450
|
-
else if (!this
|
|
5451
|
-
this
|
|
5467
|
+
else if (!this.#resizeObserver && add && canvasEl) {
|
|
5468
|
+
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
5452
5469
|
const entry = entries.find(e => e.target === canvasEl);
|
|
5453
5470
|
if (!entry) {
|
|
5454
5471
|
return;
|
|
5455
5472
|
}
|
|
5456
|
-
this
|
|
5473
|
+
this.#handleWindowResize();
|
|
5457
5474
|
});
|
|
5458
|
-
this.
|
|
5475
|
+
this.#resizeObserver.observe(canvasEl);
|
|
5459
5476
|
}
|
|
5460
5477
|
};
|
|
5461
5478
|
}
|
|
@@ -5528,24 +5545,24 @@
|
|
|
5528
5545
|
unbreakable;
|
|
5529
5546
|
velocity;
|
|
5530
5547
|
zIndexFactor;
|
|
5531
|
-
|
|
5548
|
+
#cachedOpacityData = {
|
|
5532
5549
|
fillOpacity: defaultOpacity$2,
|
|
5533
5550
|
opacity: defaultOpacity$2,
|
|
5534
5551
|
strokeOpacity: defaultOpacity$2,
|
|
5535
5552
|
};
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5553
|
+
#cachedPosition = Vector3d.origin;
|
|
5554
|
+
#cachedRotateData = { sin: 0, cos: 0 };
|
|
5555
|
+
#cachedTransform = {
|
|
5539
5556
|
a: 1,
|
|
5540
5557
|
b: 0,
|
|
5541
5558
|
c: 0,
|
|
5542
5559
|
d: 1,
|
|
5543
5560
|
};
|
|
5544
|
-
|
|
5545
|
-
|
|
5561
|
+
#container;
|
|
5562
|
+
#pluginManager;
|
|
5546
5563
|
constructor(pluginManager, container) {
|
|
5547
|
-
this
|
|
5548
|
-
this
|
|
5564
|
+
this.#pluginManager = pluginManager;
|
|
5565
|
+
this.#container = container;
|
|
5549
5566
|
}
|
|
5550
5567
|
destroy(override) {
|
|
5551
5568
|
if (this.unbreakable || this.destroyed) {
|
|
@@ -5554,7 +5571,7 @@
|
|
|
5554
5571
|
this.destroyed = true;
|
|
5555
5572
|
this.bubble.inRange = false;
|
|
5556
5573
|
this.slow.inRange = false;
|
|
5557
|
-
const container = this
|
|
5574
|
+
const container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined;
|
|
5558
5575
|
shapeDrawer?.particleDestroy?.(this);
|
|
5559
5576
|
for (const plugin of container.particleDestroyedPlugins) {
|
|
5560
5577
|
plugin.particleDestroyed?.(this, override);
|
|
@@ -5562,12 +5579,12 @@
|
|
|
5562
5579
|
for (const updater of container.particleUpdaters) {
|
|
5563
5580
|
updater.particleDestroyed?.(this, override);
|
|
5564
5581
|
}
|
|
5565
|
-
this.
|
|
5582
|
+
this.#container.dispatchEvent(exports.EventType.particleDestroyed, {
|
|
5566
5583
|
particle: this,
|
|
5567
5584
|
});
|
|
5568
5585
|
}
|
|
5569
5586
|
draw(delta) {
|
|
5570
|
-
const container = this
|
|
5587
|
+
const container = this.#container, render = container.canvas.render;
|
|
5571
5588
|
render.drawParticlePlugins(this, delta);
|
|
5572
5589
|
render.drawParticle(this, delta);
|
|
5573
5590
|
}
|
|
@@ -5575,50 +5592,50 @@
|
|
|
5575
5592
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
5576
5593
|
}
|
|
5577
5594
|
getFillColor() {
|
|
5578
|
-
return this
|
|
5595
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
5579
5596
|
}
|
|
5580
5597
|
getMass() {
|
|
5581
5598
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
5582
5599
|
}
|
|
5583
5600
|
getOpacity() {
|
|
5584
5601
|
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;
|
|
5585
|
-
this.
|
|
5586
|
-
this.
|
|
5587
|
-
this.
|
|
5588
|
-
return this
|
|
5602
|
+
this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
5603
|
+
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5604
|
+
this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
5605
|
+
return this.#cachedOpacityData;
|
|
5589
5606
|
}
|
|
5590
5607
|
getPosition() {
|
|
5591
|
-
this.
|
|
5592
|
-
this.
|
|
5593
|
-
this.
|
|
5594
|
-
return this
|
|
5608
|
+
this.#cachedPosition.x = this.position.x + this.offset.x;
|
|
5609
|
+
this.#cachedPosition.y = this.position.y + this.offset.y;
|
|
5610
|
+
this.#cachedPosition.z = this.position.z;
|
|
5611
|
+
return this.#cachedPosition;
|
|
5595
5612
|
}
|
|
5596
5613
|
getRadius() {
|
|
5597
5614
|
return this.bubble.radius ?? this.size.value;
|
|
5598
5615
|
}
|
|
5599
5616
|
getRotateData() {
|
|
5600
5617
|
const angle = this.getAngle();
|
|
5601
|
-
this.
|
|
5602
|
-
this.
|
|
5603
|
-
return this
|
|
5618
|
+
this.#cachedRotateData.sin = Math.sin(angle);
|
|
5619
|
+
this.#cachedRotateData.cos = Math.cos(angle);
|
|
5620
|
+
return this.#cachedRotateData;
|
|
5604
5621
|
}
|
|
5605
5622
|
getStrokeColor() {
|
|
5606
|
-
return this
|
|
5623
|
+
return this.#getRollColor(this.bubble.color ?? getHslFromAnimation(this.strokeColor));
|
|
5607
5624
|
}
|
|
5608
5625
|
getTransformData(externalTransform) {
|
|
5609
5626
|
const rotateData = this.getRotateData(), rotating = this.isRotating;
|
|
5610
|
-
this.
|
|
5611
|
-
this.
|
|
5627
|
+
this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
|
|
5628
|
+
this.#cachedTransform.b = rotating
|
|
5612
5629
|
? rotateData.sin * (externalTransform.b ?? identity$1)
|
|
5613
5630
|
: (externalTransform.b ?? defaultTransform.b);
|
|
5614
|
-
this.
|
|
5631
|
+
this.#cachedTransform.c = rotating
|
|
5615
5632
|
? -rotateData.sin * (externalTransform.c ?? identity$1)
|
|
5616
5633
|
: (externalTransform.c ?? defaultTransform.c);
|
|
5617
|
-
this.
|
|
5618
|
-
return this
|
|
5634
|
+
this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
|
|
5635
|
+
return this.#cachedTransform;
|
|
5619
5636
|
}
|
|
5620
5637
|
init(id, position, overrideOptions, group) {
|
|
5621
|
-
const container = this
|
|
5638
|
+
const container = this.#container;
|
|
5622
5639
|
this.id = id;
|
|
5623
5640
|
this.group = group;
|
|
5624
5641
|
this.justWarped = false;
|
|
@@ -5638,21 +5655,27 @@
|
|
|
5638
5655
|
moveSpeed: 0,
|
|
5639
5656
|
sizeAnimationSpeed: 0,
|
|
5640
5657
|
};
|
|
5658
|
+
this.size = {
|
|
5659
|
+
value: 1,
|
|
5660
|
+
max: 1,
|
|
5661
|
+
min: 1,
|
|
5662
|
+
enable: false,
|
|
5663
|
+
};
|
|
5641
5664
|
this.outType = exports.ParticleOutType.normal;
|
|
5642
5665
|
this.ignoresResizeRatio = true;
|
|
5643
|
-
const
|
|
5666
|
+
const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
|
|
5644
5667
|
this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
|
|
5645
5668
|
this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
|
5646
5669
|
const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
|
|
5647
5670
|
if (overrideOptions) {
|
|
5648
|
-
if (overrideOptions.effect?.type) {
|
|
5671
|
+
if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
|
|
5649
5672
|
const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
|
|
5650
5673
|
if (effect) {
|
|
5651
5674
|
this.effect = effect;
|
|
5652
5675
|
effectOptions.load(overrideOptions.effect);
|
|
5653
5676
|
}
|
|
5654
5677
|
}
|
|
5655
|
-
if (overrideOptions.shape?.type) {
|
|
5678
|
+
if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
|
|
5656
5679
|
const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
|
5657
5680
|
if (shape) {
|
|
5658
5681
|
this.shape = shape;
|
|
@@ -5661,21 +5684,20 @@
|
|
|
5661
5684
|
}
|
|
5662
5685
|
}
|
|
5663
5686
|
if (this.effect === randomColorValue) {
|
|
5664
|
-
const availableEffects = [...this.
|
|
5687
|
+
const availableEffects = [...this.#container.effectDrawers.keys()];
|
|
5665
5688
|
this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
|
|
5666
5689
|
}
|
|
5667
5690
|
if (this.shape === randomColorValue) {
|
|
5668
|
-
const availableShapes = [...this.
|
|
5691
|
+
const availableShapes = [...this.#container.shapeDrawers.keys()];
|
|
5669
5692
|
this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
|
|
5670
5693
|
}
|
|
5671
5694
|
this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
|
|
5672
5695
|
this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
|
|
5673
5696
|
particlesOptions.load(overrideOptions);
|
|
5674
|
-
const effectData = this.effectData;
|
|
5697
|
+
const effectData = this.effectData, shapeData = this.shapeData;
|
|
5675
5698
|
if (effectData) {
|
|
5676
5699
|
particlesOptions.load(effectData.particles);
|
|
5677
5700
|
}
|
|
5678
|
-
const shapeData = this.shapeData;
|
|
5679
5701
|
if (shapeData) {
|
|
5680
5702
|
particlesOptions.load(shapeData.particles);
|
|
5681
5703
|
}
|
|
@@ -5683,7 +5705,9 @@
|
|
|
5683
5705
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
5684
5706
|
this.options = particlesOptions;
|
|
5685
5707
|
container.retina.initParticle(this);
|
|
5686
|
-
|
|
5708
|
+
for (const updater of container.particleUpdaters) {
|
|
5709
|
+
updater.preInit?.(this);
|
|
5710
|
+
}
|
|
5687
5711
|
this.bubble = {
|
|
5688
5712
|
inRange: false,
|
|
5689
5713
|
};
|
|
@@ -5691,8 +5715,8 @@
|
|
|
5691
5715
|
inRange: false,
|
|
5692
5716
|
factor: 1,
|
|
5693
5717
|
};
|
|
5694
|
-
this
|
|
5695
|
-
this.initialVelocity = this
|
|
5718
|
+
this.#initPosition(position);
|
|
5719
|
+
this.initialVelocity = this.#calculateVelocity();
|
|
5696
5720
|
this.velocity = this.initialVelocity.copy();
|
|
5697
5721
|
this.zIndexFactor = this.position.z / container.zLayers;
|
|
5698
5722
|
this.sides = 24;
|
|
@@ -5723,12 +5747,11 @@
|
|
|
5723
5747
|
plugin.particleCreated?.(this);
|
|
5724
5748
|
}
|
|
5725
5749
|
}
|
|
5726
|
-
isInsideCanvas() {
|
|
5727
|
-
|
|
5728
|
-
|
|
5729
|
-
|
|
5730
|
-
|
|
5731
|
-
position.x <= canvasSize.width + radius);
|
|
5750
|
+
isInsideCanvas(direction) {
|
|
5751
|
+
return this.#getInsideCanvasResult({ direction }).inside;
|
|
5752
|
+
}
|
|
5753
|
+
isInsideCanvasForOutMode(outMode, direction) {
|
|
5754
|
+
return this.#getInsideCanvasResult({ direction, outMode }).inside;
|
|
5732
5755
|
}
|
|
5733
5756
|
isShowingBack() {
|
|
5734
5757
|
if (!this.roll) {
|
|
@@ -5753,13 +5776,13 @@
|
|
|
5753
5776
|
return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
|
5754
5777
|
}
|
|
5755
5778
|
reset() {
|
|
5756
|
-
for (const updater of this.
|
|
5779
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
5757
5780
|
updater.reset?.(this);
|
|
5758
5781
|
}
|
|
5759
5782
|
}
|
|
5760
|
-
|
|
5783
|
+
#calcPosition = (position, zIndex) => {
|
|
5761
5784
|
let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
|
|
5762
|
-
const container = this
|
|
5785
|
+
const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
|
|
5763
5786
|
while (!signal.aborted) {
|
|
5764
5787
|
for (const plugin of plugins) {
|
|
5765
5788
|
const pluginPos = plugin.particlePosition?.(posVec, this);
|
|
@@ -5771,10 +5794,10 @@
|
|
|
5771
5794
|
size: canvasSize,
|
|
5772
5795
|
position: posVec,
|
|
5773
5796
|
}), pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex);
|
|
5774
|
-
this
|
|
5775
|
-
this
|
|
5776
|
-
this
|
|
5777
|
-
this
|
|
5797
|
+
this.#fixHorizontal(pos, radius, outModes.left ?? outModes.default);
|
|
5798
|
+
this.#fixHorizontal(pos, radius, outModes.right ?? outModes.default);
|
|
5799
|
+
this.#fixVertical(pos, radius, outModes.top ?? outModes.default);
|
|
5800
|
+
this.#fixVertical(pos, radius, outModes.bottom ?? outModes.default);
|
|
5778
5801
|
let isValidPosition = true;
|
|
5779
5802
|
for (const plugin of container.particles.checkParticlePositionPlugins) {
|
|
5780
5803
|
isValidPosition = plugin.checkParticlePosition?.(this, pos, tryCount) ?? true;
|
|
@@ -5790,8 +5813,8 @@
|
|
|
5790
5813
|
}
|
|
5791
5814
|
return posVec;
|
|
5792
5815
|
};
|
|
5793
|
-
|
|
5794
|
-
const baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy()
|
|
5816
|
+
#calculateVelocity = () => {
|
|
5817
|
+
const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
|
|
5795
5818
|
if (moveOptions.direction === exports.MoveDirection.inside || moveOptions.direction === exports.MoveDirection.outside) {
|
|
5796
5819
|
return res;
|
|
5797
5820
|
}
|
|
@@ -5807,27 +5830,86 @@
|
|
|
5807
5830
|
}
|
|
5808
5831
|
return res;
|
|
5809
5832
|
};
|
|
5810
|
-
|
|
5833
|
+
#fixHorizontal = (pos, radius, outMode) => {
|
|
5811
5834
|
fixOutMode({
|
|
5812
5835
|
outMode,
|
|
5813
5836
|
checkModes: [exports.OutMode.bounce],
|
|
5814
5837
|
coord: pos.x,
|
|
5815
|
-
maxCoord: this.
|
|
5838
|
+
maxCoord: this.#container.canvas.size.width,
|
|
5816
5839
|
setCb: (value) => (pos.x += value),
|
|
5817
5840
|
radius,
|
|
5818
5841
|
});
|
|
5819
5842
|
};
|
|
5820
|
-
|
|
5843
|
+
#fixVertical = (pos, radius, outMode) => {
|
|
5821
5844
|
fixOutMode({
|
|
5822
5845
|
outMode,
|
|
5823
5846
|
checkModes: [exports.OutMode.bounce],
|
|
5824
5847
|
coord: pos.y,
|
|
5825
|
-
maxCoord: this.
|
|
5848
|
+
maxCoord: this.#container.canvas.size.height,
|
|
5826
5849
|
setCb: (value) => (pos.y += value),
|
|
5827
5850
|
radius,
|
|
5828
5851
|
});
|
|
5829
5852
|
};
|
|
5830
|
-
|
|
5853
|
+
#getDefaultInsideCanvasResult = (direction, outMode) => {
|
|
5854
|
+
const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === exports.OutMode.bounce;
|
|
5855
|
+
if (direction === exports.OutModeDirection.bottom) {
|
|
5856
|
+
return {
|
|
5857
|
+
inside: isBounce ? position.y + radius < canvasSize.height : position.y - radius < canvasSize.height,
|
|
5858
|
+
reason: "default",
|
|
5859
|
+
};
|
|
5860
|
+
}
|
|
5861
|
+
if (direction === exports.OutModeDirection.left) {
|
|
5862
|
+
return {
|
|
5863
|
+
inside: isBounce ? position.x - radius > defaultAngle : position.x + radius > defaultAngle,
|
|
5864
|
+
reason: "default",
|
|
5865
|
+
};
|
|
5866
|
+
}
|
|
5867
|
+
if (direction === exports.OutModeDirection.right) {
|
|
5868
|
+
return {
|
|
5869
|
+
inside: isBounce ? position.x + radius < canvasSize.width : position.x - radius < canvasSize.width,
|
|
5870
|
+
reason: "default",
|
|
5871
|
+
};
|
|
5872
|
+
}
|
|
5873
|
+
if (direction === exports.OutModeDirection.top) {
|
|
5874
|
+
return {
|
|
5875
|
+
inside: isBounce ? position.y - radius > defaultAngle : position.y + radius > defaultAngle,
|
|
5876
|
+
reason: "default",
|
|
5877
|
+
};
|
|
5878
|
+
}
|
|
5879
|
+
return {
|
|
5880
|
+
inside: position.x >= -radius &&
|
|
5881
|
+
position.y >= -radius &&
|
|
5882
|
+
position.y <= canvasSize.height + radius &&
|
|
5883
|
+
position.x <= canvasSize.width + radius,
|
|
5884
|
+
reason: "default",
|
|
5885
|
+
};
|
|
5886
|
+
};
|
|
5887
|
+
#getInsideCanvasCallbackData = (direction, outMode) => {
|
|
5888
|
+
return {
|
|
5889
|
+
canvasSize: this.#container.canvas.size,
|
|
5890
|
+
direction,
|
|
5891
|
+
outMode,
|
|
5892
|
+
particle: this,
|
|
5893
|
+
radius: this.getRadius(),
|
|
5894
|
+
};
|
|
5895
|
+
};
|
|
5896
|
+
#getInsideCanvasResult = (data) => {
|
|
5897
|
+
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;
|
|
5898
|
+
if (!shapeCheck && !effectCheck) {
|
|
5899
|
+
return defaultResult;
|
|
5900
|
+
}
|
|
5901
|
+
const callbackData = this.#getInsideCanvasCallbackData(data.direction, data.outMode), shapeResult = shapeCheck ? this.#normalizeInsideCanvasResult(shapeCheck(callbackData), "shape") : undefined, effectResult = effectCheck ? this.#normalizeInsideCanvasResult(effectCheck(callbackData), "effect") : undefined;
|
|
5902
|
+
if (shapeResult && effectResult) {
|
|
5903
|
+
const margin = Math.max(shapeResult.margin ?? defaultAngle, effectResult.margin ?? defaultAngle);
|
|
5904
|
+
return {
|
|
5905
|
+
inside: shapeResult.inside && effectResult.inside,
|
|
5906
|
+
margin: margin > defaultAngle ? margin : undefined,
|
|
5907
|
+
reason: "combined",
|
|
5908
|
+
};
|
|
5909
|
+
}
|
|
5910
|
+
return shapeResult ?? effectResult ?? defaultResult;
|
|
5911
|
+
};
|
|
5912
|
+
#getRollColor = color => {
|
|
5831
5913
|
if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
|
|
5832
5914
|
return color;
|
|
5833
5915
|
}
|
|
@@ -5842,8 +5924,8 @@
|
|
|
5842
5924
|
}
|
|
5843
5925
|
return color;
|
|
5844
5926
|
};
|
|
5845
|
-
|
|
5846
|
-
const container = this
|
|
5927
|
+
#initPosition = position => {
|
|
5928
|
+
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5847
5929
|
if (!initialPosition) {
|
|
5848
5930
|
throw new Error("a valid position cannot be found for particle");
|
|
5849
5931
|
}
|
|
@@ -5866,45 +5948,58 @@
|
|
|
5866
5948
|
}
|
|
5867
5949
|
this.offset = Vector.origin;
|
|
5868
5950
|
};
|
|
5951
|
+
#normalizeInsideCanvasResult = (result, reason) => {
|
|
5952
|
+
if (typeof result === "boolean") {
|
|
5953
|
+
return {
|
|
5954
|
+
inside: result,
|
|
5955
|
+
reason,
|
|
5956
|
+
};
|
|
5957
|
+
}
|
|
5958
|
+
return {
|
|
5959
|
+
inside: result.inside,
|
|
5960
|
+
margin: result.margin,
|
|
5961
|
+
reason: result.reason ?? reason,
|
|
5962
|
+
};
|
|
5963
|
+
};
|
|
5869
5964
|
}
|
|
5870
5965
|
|
|
5871
5966
|
class SpatialHashGrid {
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5876
|
-
|
|
5877
|
-
|
|
5878
|
-
|
|
5967
|
+
#cellSize;
|
|
5968
|
+
#cells = new Map();
|
|
5969
|
+
#circlePool = [];
|
|
5970
|
+
#circlePoolIdx;
|
|
5971
|
+
#pendingCellSize;
|
|
5972
|
+
#rectanglePool = [];
|
|
5973
|
+
#rectanglePoolIdx;
|
|
5879
5974
|
constructor(cellSize) {
|
|
5880
|
-
this
|
|
5881
|
-
this
|
|
5882
|
-
this
|
|
5975
|
+
this.#cellSize = cellSize;
|
|
5976
|
+
this.#circlePoolIdx = 0;
|
|
5977
|
+
this.#rectanglePoolIdx = 0;
|
|
5883
5978
|
}
|
|
5884
5979
|
clear() {
|
|
5885
|
-
this.
|
|
5886
|
-
const pendingCellSize = this
|
|
5980
|
+
this.#cells.clear();
|
|
5981
|
+
const pendingCellSize = this.#pendingCellSize;
|
|
5887
5982
|
if (pendingCellSize) {
|
|
5888
|
-
this
|
|
5983
|
+
this.#cellSize = pendingCellSize;
|
|
5889
5984
|
}
|
|
5890
|
-
this
|
|
5985
|
+
this.#pendingCellSize = undefined;
|
|
5891
5986
|
}
|
|
5892
5987
|
insert(particle) {
|
|
5893
|
-
const { x, y } = particle.getPosition(), key = this
|
|
5894
|
-
if (!this.
|
|
5895
|
-
this.
|
|
5988
|
+
const { x, y } = particle.getPosition(), key = this.#cellKeyFromCoords(x, y);
|
|
5989
|
+
if (!this.#cells.has(key)) {
|
|
5990
|
+
this.#cells.set(key, []);
|
|
5896
5991
|
}
|
|
5897
|
-
this.
|
|
5992
|
+
this.#cells.get(key)?.push(particle);
|
|
5898
5993
|
}
|
|
5899
5994
|
query(range, check, out = []) {
|
|
5900
|
-
const bounds = this
|
|
5995
|
+
const bounds = this.#getRangeBounds(range);
|
|
5901
5996
|
if (!bounds) {
|
|
5902
5997
|
return out;
|
|
5903
5998
|
}
|
|
5904
|
-
const minCellX = Math.floor(bounds.minX / this
|
|
5999
|
+
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);
|
|
5905
6000
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5906
6001
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5907
|
-
const key = `${cx}_${cy}`, cellParticles = this.
|
|
6002
|
+
const key = `${cx}_${cy}`, cellParticles = this.#cells.get(key);
|
|
5908
6003
|
if (!cellParticles) {
|
|
5909
6004
|
continue;
|
|
5910
6005
|
}
|
|
@@ -5921,29 +6016,29 @@
|
|
|
5921
6016
|
return out;
|
|
5922
6017
|
}
|
|
5923
6018
|
queryCircle(position, radius, check, out = []) {
|
|
5924
|
-
const circle = this
|
|
5925
|
-
this
|
|
6019
|
+
const circle = this.#acquireCircle(position.x, position.y, radius), result = this.query(circle, check, out);
|
|
6020
|
+
this.#releaseShapes();
|
|
5926
6021
|
return result;
|
|
5927
6022
|
}
|
|
5928
6023
|
queryRectangle(position, size, check, out = []) {
|
|
5929
|
-
const rect = this
|
|
5930
|
-
this
|
|
6024
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height), result = this.query(rect, check, out);
|
|
6025
|
+
this.#releaseShapes();
|
|
5931
6026
|
return result;
|
|
5932
6027
|
}
|
|
5933
6028
|
setCellSize(cellSize) {
|
|
5934
|
-
this
|
|
6029
|
+
this.#pendingCellSize = cellSize;
|
|
5935
6030
|
}
|
|
5936
|
-
|
|
5937
|
-
return (this
|
|
6031
|
+
#acquireCircle(x, y, r) {
|
|
6032
|
+
return (this.#circlePool[this.#circlePoolIdx++] ??= new Circle(x, y, r)).reset(x, y, r);
|
|
5938
6033
|
}
|
|
5939
|
-
|
|
5940
|
-
return (this
|
|
6034
|
+
#acquireRectangle(x, y, w, h) {
|
|
6035
|
+
return (this.#rectanglePool[this.#rectanglePoolIdx++] ??= new Rectangle(x, y, w, h)).reset(x, y, w, h);
|
|
5941
6036
|
}
|
|
5942
|
-
|
|
5943
|
-
const cellX = Math.floor(x / this
|
|
6037
|
+
#cellKeyFromCoords(x, y) {
|
|
6038
|
+
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
5944
6039
|
return `${cellX}_${cellY}`;
|
|
5945
6040
|
}
|
|
5946
|
-
|
|
6041
|
+
#getRangeBounds(range) {
|
|
5947
6042
|
if (range instanceof Circle) {
|
|
5948
6043
|
const r = range.radius, { x, y } = range.position;
|
|
5949
6044
|
return {
|
|
@@ -5964,53 +6059,53 @@
|
|
|
5964
6059
|
}
|
|
5965
6060
|
return null;
|
|
5966
6061
|
}
|
|
5967
|
-
|
|
5968
|
-
this
|
|
5969
|
-
this
|
|
6062
|
+
#releaseShapes() {
|
|
6063
|
+
this.#circlePoolIdx = 0;
|
|
6064
|
+
this.#rectanglePoolIdx = 0;
|
|
5970
6065
|
}
|
|
5971
6066
|
}
|
|
5972
6067
|
|
|
5973
6068
|
class ParticlesManager {
|
|
5974
6069
|
checkParticlePositionPlugins;
|
|
5975
6070
|
grid;
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
5980
|
-
|
|
5981
|
-
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
6071
|
+
#array;
|
|
6072
|
+
#container;
|
|
6073
|
+
#groupLimits;
|
|
6074
|
+
#limit;
|
|
6075
|
+
#nextId;
|
|
6076
|
+
#particleBuckets;
|
|
6077
|
+
#particleResetPlugins;
|
|
6078
|
+
#particleUpdatePlugins;
|
|
6079
|
+
#pluginManager;
|
|
6080
|
+
#pool;
|
|
6081
|
+
#postParticleUpdatePlugins;
|
|
6082
|
+
#postUpdatePlugins;
|
|
6083
|
+
#resizeFactor;
|
|
6084
|
+
#updatePlugins;
|
|
6085
|
+
#zBuckets;
|
|
5991
6086
|
constructor(pluginManager, container) {
|
|
5992
|
-
this
|
|
5993
|
-
this
|
|
5994
|
-
this
|
|
5995
|
-
this
|
|
5996
|
-
this
|
|
5997
|
-
this
|
|
5998
|
-
this
|
|
5999
|
-
this
|
|
6000
|
-
this
|
|
6087
|
+
this.#pluginManager = pluginManager;
|
|
6088
|
+
this.#container = container;
|
|
6089
|
+
this.#nextId = 0;
|
|
6090
|
+
this.#array = [];
|
|
6091
|
+
this.#pool = [];
|
|
6092
|
+
this.#limit = 0;
|
|
6093
|
+
this.#groupLimits = new Map();
|
|
6094
|
+
this.#particleBuckets = new Map();
|
|
6095
|
+
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
6001
6096
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
6002
6097
|
this.checkParticlePositionPlugins = [];
|
|
6003
|
-
this
|
|
6004
|
-
this
|
|
6005
|
-
this
|
|
6006
|
-
this
|
|
6007
|
-
this
|
|
6098
|
+
this.#particleResetPlugins = [];
|
|
6099
|
+
this.#particleUpdatePlugins = [];
|
|
6100
|
+
this.#postUpdatePlugins = [];
|
|
6101
|
+
this.#postParticleUpdatePlugins = [];
|
|
6102
|
+
this.#updatePlugins = [];
|
|
6008
6103
|
}
|
|
6009
6104
|
get count() {
|
|
6010
|
-
return this.
|
|
6105
|
+
return this.#array.length;
|
|
6011
6106
|
}
|
|
6012
6107
|
addParticle(position, overrideOptions, group, initializer) {
|
|
6013
|
-
const limitMode = this.
|
|
6108
|
+
const limitMode = this.#container.actualOptions.particles.number.limit.mode, limit = group === undefined ? this.#limit : (this.#groupLimits.get(group) ?? this.#limit), currentCount = this.count;
|
|
6014
6109
|
if (limit > minLimit) {
|
|
6015
6110
|
switch (limitMode) {
|
|
6016
6111
|
case exports.LimitMode.delete: {
|
|
@@ -6028,20 +6123,20 @@
|
|
|
6028
6123
|
}
|
|
6029
6124
|
}
|
|
6030
6125
|
try {
|
|
6031
|
-
const particle = this.
|
|
6032
|
-
particle.init(this
|
|
6126
|
+
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
6127
|
+
particle.init(this.#nextId, position, overrideOptions, group);
|
|
6033
6128
|
let canAdd = true;
|
|
6034
6129
|
if (initializer) {
|
|
6035
6130
|
canAdd = initializer(particle);
|
|
6036
6131
|
}
|
|
6037
6132
|
if (!canAdd) {
|
|
6038
|
-
this.
|
|
6133
|
+
this.#pool.push(particle);
|
|
6039
6134
|
return;
|
|
6040
6135
|
}
|
|
6041
|
-
this.
|
|
6042
|
-
this
|
|
6043
|
-
this
|
|
6044
|
-
this.
|
|
6136
|
+
this.#array.push(particle);
|
|
6137
|
+
this.#insertParticleIntoBucket(particle);
|
|
6138
|
+
this.#nextId++;
|
|
6139
|
+
this.#container.dispatchEvent(exports.EventType.particleAdded, {
|
|
6045
6140
|
particle,
|
|
6046
6141
|
});
|
|
6047
6142
|
return particle;
|
|
@@ -6052,25 +6147,25 @@
|
|
|
6052
6147
|
return undefined;
|
|
6053
6148
|
}
|
|
6054
6149
|
clear() {
|
|
6055
|
-
this
|
|
6056
|
-
this.
|
|
6057
|
-
this
|
|
6150
|
+
this.#array = [];
|
|
6151
|
+
this.#particleBuckets.clear();
|
|
6152
|
+
this.#resetBuckets(this.#container.zLayers);
|
|
6058
6153
|
}
|
|
6059
6154
|
destroy() {
|
|
6060
|
-
this
|
|
6061
|
-
this.
|
|
6062
|
-
this.
|
|
6063
|
-
this
|
|
6155
|
+
this.#array = [];
|
|
6156
|
+
this.#pool.length = 0;
|
|
6157
|
+
this.#particleBuckets.clear();
|
|
6158
|
+
this.#zBuckets = [];
|
|
6064
6159
|
this.checkParticlePositionPlugins = [];
|
|
6065
|
-
this
|
|
6066
|
-
this
|
|
6067
|
-
this
|
|
6068
|
-
this
|
|
6069
|
-
this
|
|
6160
|
+
this.#particleResetPlugins = [];
|
|
6161
|
+
this.#particleUpdatePlugins = [];
|
|
6162
|
+
this.#postUpdatePlugins = [];
|
|
6163
|
+
this.#postParticleUpdatePlugins = [];
|
|
6164
|
+
this.#updatePlugins = [];
|
|
6070
6165
|
}
|
|
6071
6166
|
drawParticles(delta) {
|
|
6072
|
-
for (let i = this.
|
|
6073
|
-
const bucket = this
|
|
6167
|
+
for (let i = this.#zBuckets.length - one; i >= minIndex; i--) {
|
|
6168
|
+
const bucket = this.#zBuckets[i];
|
|
6074
6169
|
if (!bucket) {
|
|
6075
6170
|
continue;
|
|
6076
6171
|
}
|
|
@@ -6080,24 +6175,24 @@
|
|
|
6080
6175
|
}
|
|
6081
6176
|
}
|
|
6082
6177
|
filter(condition) {
|
|
6083
|
-
return this.
|
|
6178
|
+
return this.#array.filter(condition);
|
|
6084
6179
|
}
|
|
6085
6180
|
find(condition) {
|
|
6086
|
-
return this.
|
|
6181
|
+
return this.#array.find(condition);
|
|
6087
6182
|
}
|
|
6088
6183
|
get(index) {
|
|
6089
|
-
return this
|
|
6184
|
+
return this.#array[index];
|
|
6090
6185
|
}
|
|
6091
6186
|
async init() {
|
|
6092
|
-
const container = this
|
|
6187
|
+
const container = this.#container, options = container.actualOptions;
|
|
6093
6188
|
this.checkParticlePositionPlugins = [];
|
|
6094
|
-
this
|
|
6095
|
-
this
|
|
6096
|
-
this
|
|
6097
|
-
this
|
|
6098
|
-
this
|
|
6099
|
-
this.
|
|
6100
|
-
this
|
|
6189
|
+
this.#updatePlugins = [];
|
|
6190
|
+
this.#particleUpdatePlugins = [];
|
|
6191
|
+
this.#postUpdatePlugins = [];
|
|
6192
|
+
this.#particleResetPlugins = [];
|
|
6193
|
+
this.#postParticleUpdatePlugins = [];
|
|
6194
|
+
this.#particleBuckets.clear();
|
|
6195
|
+
this.#resetBuckets(container.zLayers);
|
|
6101
6196
|
this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
6102
6197
|
for (const plugin of container.plugins) {
|
|
6103
6198
|
if (plugin.redrawInit) {
|
|
@@ -6107,26 +6202,26 @@
|
|
|
6107
6202
|
this.checkParticlePositionPlugins.push(plugin);
|
|
6108
6203
|
}
|
|
6109
6204
|
if (plugin.update) {
|
|
6110
|
-
this.
|
|
6205
|
+
this.#updatePlugins.push(plugin);
|
|
6111
6206
|
}
|
|
6112
6207
|
if (plugin.particleUpdate) {
|
|
6113
|
-
this.
|
|
6208
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
6114
6209
|
}
|
|
6115
6210
|
if (plugin.postUpdate) {
|
|
6116
|
-
this.
|
|
6211
|
+
this.#postUpdatePlugins.push(plugin);
|
|
6117
6212
|
}
|
|
6118
6213
|
if (plugin.particleReset) {
|
|
6119
|
-
this.
|
|
6214
|
+
this.#particleResetPlugins.push(plugin);
|
|
6120
6215
|
}
|
|
6121
6216
|
if (plugin.postParticleUpdate) {
|
|
6122
|
-
this.
|
|
6217
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
6123
6218
|
}
|
|
6124
6219
|
}
|
|
6125
|
-
await this.
|
|
6126
|
-
for (const drawer of this.
|
|
6220
|
+
await this.#container.initDrawersAndUpdaters();
|
|
6221
|
+
for (const drawer of this.#container.effectDrawers.values()) {
|
|
6127
6222
|
await drawer.init?.(container);
|
|
6128
6223
|
}
|
|
6129
|
-
for (const drawer of this.
|
|
6224
|
+
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
6130
6225
|
await drawer.init?.(container);
|
|
6131
6226
|
}
|
|
6132
6227
|
let handled = false;
|
|
@@ -6160,10 +6255,10 @@
|
|
|
6160
6255
|
async redraw() {
|
|
6161
6256
|
this.clear();
|
|
6162
6257
|
await this.init();
|
|
6163
|
-
this.
|
|
6258
|
+
this.#container.canvas.render.drawParticles({ value: 0, factor: 0 });
|
|
6164
6259
|
}
|
|
6165
6260
|
remove(particle, group, override) {
|
|
6166
|
-
this.removeAt(this.
|
|
6261
|
+
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
6167
6262
|
}
|
|
6168
6263
|
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
6169
6264
|
if (index < minIndex || index > this.count) {
|
|
@@ -6171,7 +6266,7 @@
|
|
|
6171
6266
|
}
|
|
6172
6267
|
let deleted = 0;
|
|
6173
6268
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
6174
|
-
if (this
|
|
6269
|
+
if (this.#removeParticle(i, group, override)) {
|
|
6175
6270
|
i--;
|
|
6176
6271
|
deleted++;
|
|
6177
6272
|
}
|
|
@@ -6181,9 +6276,9 @@
|
|
|
6181
6276
|
this.removeAt(minIndex, quantity, group);
|
|
6182
6277
|
}
|
|
6183
6278
|
setDensity() {
|
|
6184
|
-
const options = this.
|
|
6279
|
+
const options = this.#container.actualOptions, groups = options.particles.groups;
|
|
6185
6280
|
let pluginsCount = 0;
|
|
6186
|
-
for (const plugin of this.
|
|
6281
|
+
for (const plugin of this.#container.plugins) {
|
|
6187
6282
|
if (plugin.particlesDensityCount) {
|
|
6188
6283
|
pluginsCount += plugin.particlesDensityCount();
|
|
6189
6284
|
}
|
|
@@ -6193,51 +6288,51 @@
|
|
|
6193
6288
|
if (!groupData) {
|
|
6194
6289
|
continue;
|
|
6195
6290
|
}
|
|
6196
|
-
const groupDataOptions = loadParticlesOptions(this
|
|
6197
|
-
this
|
|
6291
|
+
const groupDataOptions = loadParticlesOptions(this.#pluginManager, this.#container, groupData);
|
|
6292
|
+
this.#applyDensity(groupDataOptions, pluginsCount, group);
|
|
6198
6293
|
}
|
|
6199
|
-
this
|
|
6294
|
+
this.#applyDensity(options.particles, pluginsCount);
|
|
6200
6295
|
}
|
|
6201
6296
|
setResizeFactor(factor) {
|
|
6202
|
-
this
|
|
6297
|
+
this.#resizeFactor = factor;
|
|
6203
6298
|
}
|
|
6204
6299
|
update(delta) {
|
|
6205
6300
|
this.grid.clear();
|
|
6206
|
-
for (const plugin of this
|
|
6301
|
+
for (const plugin of this.#updatePlugins) {
|
|
6207
6302
|
plugin.update?.(delta);
|
|
6208
6303
|
}
|
|
6209
|
-
const particlesToDelete = this
|
|
6210
|
-
for (const plugin of this
|
|
6304
|
+
const particlesToDelete = this.#updateParticlesPhase1(delta);
|
|
6305
|
+
for (const plugin of this.#postUpdatePlugins) {
|
|
6211
6306
|
plugin.postUpdate?.(delta);
|
|
6212
6307
|
}
|
|
6213
|
-
this
|
|
6308
|
+
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
6214
6309
|
if (particlesToDelete.size) {
|
|
6215
6310
|
for (const particle of particlesToDelete) {
|
|
6216
6311
|
this.remove(particle);
|
|
6217
6312
|
}
|
|
6218
6313
|
}
|
|
6219
|
-
|
|
6314
|
+
this.#resizeFactor = undefined;
|
|
6220
6315
|
}
|
|
6221
|
-
|
|
6222
|
-
this.
|
|
6316
|
+
#addToPool = (...particles) => {
|
|
6317
|
+
this.#pool.push(...particles);
|
|
6223
6318
|
};
|
|
6224
|
-
|
|
6319
|
+
#applyDensity = (options, pluginsCount, group, groupOptions) => {
|
|
6225
6320
|
const numberOptions = options.number;
|
|
6226
6321
|
if (!numberOptions.density.enable) {
|
|
6227
6322
|
if (group === undefined) {
|
|
6228
|
-
this
|
|
6323
|
+
this.#limit = numberOptions.limit.value;
|
|
6229
6324
|
}
|
|
6230
6325
|
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
6231
|
-
this.
|
|
6326
|
+
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
6232
6327
|
}
|
|
6233
6328
|
return;
|
|
6234
6329
|
}
|
|
6235
|
-
const densityFactor = this
|
|
6330
|
+
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);
|
|
6236
6331
|
if (group === undefined) {
|
|
6237
|
-
this
|
|
6332
|
+
this.#limit = numberOptions.limit.value * densityFactor;
|
|
6238
6333
|
}
|
|
6239
6334
|
else {
|
|
6240
|
-
this.
|
|
6335
|
+
this.#groupLimits.set(group, numberOptions.limit.value * densityFactor);
|
|
6241
6336
|
}
|
|
6242
6337
|
if (particlesCount < particlesNumber) {
|
|
6243
6338
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -6246,18 +6341,18 @@
|
|
|
6246
6341
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
6247
6342
|
}
|
|
6248
6343
|
};
|
|
6249
|
-
|
|
6344
|
+
#createBuckets = (zLayers) => {
|
|
6250
6345
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6251
6346
|
return Array.from({ length: bucketCount }, () => []);
|
|
6252
6347
|
};
|
|
6253
|
-
|
|
6254
|
-
const maxBucketIndex = this.
|
|
6348
|
+
#getBucketIndex = (zIndex) => {
|
|
6349
|
+
const maxBucketIndex = this.#zBuckets.length - one;
|
|
6255
6350
|
if (maxBucketIndex <= minIndex) {
|
|
6256
6351
|
return minIndex;
|
|
6257
6352
|
}
|
|
6258
6353
|
return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
|
|
6259
6354
|
};
|
|
6260
|
-
|
|
6355
|
+
#getParticleInsertIndex = (bucket, particleId) => {
|
|
6261
6356
|
let start = minIndex, end = bucket.length;
|
|
6262
6357
|
while (start < end) {
|
|
6263
6358
|
const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
|
|
@@ -6274,8 +6369,8 @@
|
|
|
6274
6369
|
}
|
|
6275
6370
|
return start;
|
|
6276
6371
|
};
|
|
6277
|
-
|
|
6278
|
-
const container = this
|
|
6372
|
+
#initDensityFactor = densityOptions => {
|
|
6373
|
+
const container = this.#container;
|
|
6279
6374
|
if (!densityOptions.enable) {
|
|
6280
6375
|
return defaultDensityFactor;
|
|
6281
6376
|
}
|
|
@@ -6285,82 +6380,82 @@
|
|
|
6285
6380
|
}
|
|
6286
6381
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
6287
6382
|
};
|
|
6288
|
-
|
|
6289
|
-
const bucketIndex = this
|
|
6383
|
+
#insertParticleIntoBucket = (particle) => {
|
|
6384
|
+
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6290
6385
|
if (!bucket) {
|
|
6291
6386
|
return;
|
|
6292
6387
|
}
|
|
6293
|
-
bucket.splice(this
|
|
6294
|
-
this.
|
|
6388
|
+
bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
|
|
6389
|
+
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
6295
6390
|
};
|
|
6296
|
-
|
|
6297
|
-
const particle = this
|
|
6391
|
+
#removeParticle = (index, group, override) => {
|
|
6392
|
+
const particle = this.#array[index];
|
|
6298
6393
|
if (!particle) {
|
|
6299
6394
|
return false;
|
|
6300
6395
|
}
|
|
6301
6396
|
if (particle.group !== group) {
|
|
6302
6397
|
return false;
|
|
6303
6398
|
}
|
|
6304
|
-
this.
|
|
6305
|
-
this
|
|
6399
|
+
this.#array.splice(index, deleteCount);
|
|
6400
|
+
this.#removeParticleFromBucket(particle);
|
|
6306
6401
|
particle.destroy(override);
|
|
6307
|
-
this.
|
|
6402
|
+
this.#container.dispatchEvent(exports.EventType.particleRemoved, {
|
|
6308
6403
|
particle,
|
|
6309
6404
|
});
|
|
6310
|
-
this
|
|
6405
|
+
this.#addToPool(particle);
|
|
6311
6406
|
return true;
|
|
6312
6407
|
};
|
|
6313
|
-
|
|
6314
|
-
const bucketIndex = this.
|
|
6408
|
+
#removeParticleFromBucket = (particle) => {
|
|
6409
|
+
const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
6315
6410
|
if (!bucket) {
|
|
6316
|
-
this.
|
|
6411
|
+
this.#particleBuckets.delete(particle.id);
|
|
6317
6412
|
return;
|
|
6318
6413
|
}
|
|
6319
|
-
const particleIndex = this
|
|
6414
|
+
const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
|
|
6320
6415
|
if (bucket[particleIndex]?.id !== particle.id) {
|
|
6321
|
-
this.
|
|
6416
|
+
this.#particleBuckets.delete(particle.id);
|
|
6322
6417
|
return;
|
|
6323
6418
|
}
|
|
6324
6419
|
bucket.splice(particleIndex, deleteCount);
|
|
6325
|
-
this.
|
|
6420
|
+
this.#particleBuckets.delete(particle.id);
|
|
6326
6421
|
};
|
|
6327
|
-
|
|
6422
|
+
#resetBuckets = (zLayers) => {
|
|
6328
6423
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
6329
|
-
if (this.
|
|
6330
|
-
this
|
|
6424
|
+
if (this.#zBuckets.length !== bucketCount) {
|
|
6425
|
+
this.#zBuckets = this.#createBuckets(bucketCount);
|
|
6331
6426
|
return;
|
|
6332
6427
|
}
|
|
6333
|
-
for (const bucket of this
|
|
6428
|
+
for (const bucket of this.#zBuckets) {
|
|
6334
6429
|
bucket.length = minIndex;
|
|
6335
6430
|
}
|
|
6336
6431
|
};
|
|
6337
|
-
|
|
6338
|
-
const newBucketIndex = this
|
|
6432
|
+
#updateParticleBucket = (particle) => {
|
|
6433
|
+
const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
|
|
6339
6434
|
if (currentBucketIndex === undefined) {
|
|
6340
|
-
this
|
|
6435
|
+
this.#insertParticleIntoBucket(particle);
|
|
6341
6436
|
return;
|
|
6342
6437
|
}
|
|
6343
6438
|
if (currentBucketIndex === newBucketIndex) {
|
|
6344
6439
|
return;
|
|
6345
6440
|
}
|
|
6346
|
-
const currentBucket = this
|
|
6441
|
+
const currentBucket = this.#zBuckets[currentBucketIndex];
|
|
6347
6442
|
if (currentBucket) {
|
|
6348
|
-
const particleIndex = this
|
|
6443
|
+
const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
|
|
6349
6444
|
if (currentBucket[particleIndex]?.id === particle.id) {
|
|
6350
6445
|
currentBucket.splice(particleIndex, deleteCount);
|
|
6351
6446
|
}
|
|
6352
6447
|
}
|
|
6353
|
-
const newBucket = this
|
|
6448
|
+
const newBucket = this.#zBuckets[newBucketIndex];
|
|
6354
6449
|
if (!newBucket) {
|
|
6355
|
-
this.
|
|
6450
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6356
6451
|
return;
|
|
6357
6452
|
}
|
|
6358
|
-
newBucket.splice(this
|
|
6359
|
-
this.
|
|
6453
|
+
newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
|
|
6454
|
+
this.#particleBuckets.set(particle.id, newBucketIndex);
|
|
6360
6455
|
};
|
|
6361
|
-
|
|
6362
|
-
const particlesToDelete = new Set(), resizeFactor = this
|
|
6363
|
-
for (const particle of this
|
|
6456
|
+
#updateParticlesPhase1 = (delta) => {
|
|
6457
|
+
const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
|
|
6458
|
+
for (const particle of this.#array) {
|
|
6364
6459
|
if (resizeFactor && !particle.ignoresResizeRatio) {
|
|
6365
6460
|
particle.position.x *= resizeFactor.width;
|
|
6366
6461
|
particle.position.y *= resizeFactor.height;
|
|
@@ -6368,10 +6463,10 @@
|
|
|
6368
6463
|
particle.initialPosition.y *= resizeFactor.height;
|
|
6369
6464
|
}
|
|
6370
6465
|
particle.ignoresResizeRatio = false;
|
|
6371
|
-
for (const plugin of this
|
|
6466
|
+
for (const plugin of this.#particleResetPlugins) {
|
|
6372
6467
|
plugin.particleReset?.(particle);
|
|
6373
6468
|
}
|
|
6374
|
-
for (const plugin of this
|
|
6469
|
+
for (const plugin of this.#particleUpdatePlugins) {
|
|
6375
6470
|
if (particle.destroyed) {
|
|
6376
6471
|
break;
|
|
6377
6472
|
}
|
|
@@ -6385,36 +6480,36 @@
|
|
|
6385
6480
|
}
|
|
6386
6481
|
return particlesToDelete;
|
|
6387
6482
|
};
|
|
6388
|
-
|
|
6389
|
-
for (const particle of this
|
|
6483
|
+
#updateParticlesPhase2 = (delta, particlesToDelete) => {
|
|
6484
|
+
for (const particle of this.#array) {
|
|
6390
6485
|
if (particle.destroyed) {
|
|
6391
6486
|
particlesToDelete.add(particle);
|
|
6392
6487
|
continue;
|
|
6393
6488
|
}
|
|
6394
|
-
for (const updater of this.
|
|
6489
|
+
for (const updater of this.#container.particleUpdaters) {
|
|
6395
6490
|
updater.update(particle, delta);
|
|
6396
6491
|
}
|
|
6397
6492
|
if (!particle.spawning) {
|
|
6398
|
-
for (const plugin of this
|
|
6493
|
+
for (const plugin of this.#postParticleUpdatePlugins) {
|
|
6399
6494
|
plugin.postParticleUpdate?.(particle, delta);
|
|
6400
6495
|
}
|
|
6401
6496
|
}
|
|
6402
|
-
this
|
|
6497
|
+
this.#updateParticleBucket(particle);
|
|
6403
6498
|
}
|
|
6404
6499
|
};
|
|
6405
6500
|
}
|
|
6406
6501
|
|
|
6407
6502
|
class Retina {
|
|
6408
|
-
container;
|
|
6409
6503
|
pixelRatio;
|
|
6410
6504
|
reduceFactor;
|
|
6505
|
+
#container;
|
|
6411
6506
|
constructor(container) {
|
|
6412
|
-
this
|
|
6507
|
+
this.#container = container;
|
|
6413
6508
|
this.pixelRatio = defaultRatio;
|
|
6414
6509
|
this.reduceFactor = defaultReduceFactor;
|
|
6415
6510
|
}
|
|
6416
6511
|
init() {
|
|
6417
|
-
const container = this
|
|
6512
|
+
const container = this.#container, options = container.actualOptions;
|
|
6418
6513
|
this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
|
|
6419
6514
|
this.reduceFactor = defaultReduceFactor;
|
|
6420
6515
|
const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
|
|
@@ -6428,7 +6523,6 @@
|
|
|
6428
6523
|
props.maxSpeed = getRangeValue(moveOptions.gravity.maxSpeed) * ratio;
|
|
6429
6524
|
props.moveDrift = getRangeValue(moveOptions.drift) * ratio;
|
|
6430
6525
|
props.moveSpeed = getRangeValue(moveOptions.speed) * ratio;
|
|
6431
|
-
props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
|
6432
6526
|
const maxDistance = props.maxDistance;
|
|
6433
6527
|
maxDistance.horizontal = moveDistance.horizontal === undefined ? undefined : moveDistance.horizontal * ratio;
|
|
6434
6528
|
maxDistance.vertical = moveDistance.vertical === undefined ? undefined : moveDistance.vertical * ratio;
|
|
@@ -6466,73 +6560,73 @@
|
|
|
6466
6560
|
shapeDrawers;
|
|
6467
6561
|
started;
|
|
6468
6562
|
zLayers;
|
|
6469
|
-
|
|
6470
|
-
|
|
6471
|
-
|
|
6472
|
-
|
|
6473
|
-
|
|
6474
|
-
|
|
6475
|
-
|
|
6476
|
-
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
|
|
6480
|
-
|
|
6481
|
-
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6485
|
-
|
|
6563
|
+
#delay;
|
|
6564
|
+
#delayTimeout;
|
|
6565
|
+
#delta = { value: 0, factor: 0 };
|
|
6566
|
+
#dispatchCallback;
|
|
6567
|
+
#drawAnimationFrame;
|
|
6568
|
+
#duration;
|
|
6569
|
+
#eventListeners;
|
|
6570
|
+
#firstStart;
|
|
6571
|
+
#initialSourceOptions;
|
|
6572
|
+
#lastFrameTime;
|
|
6573
|
+
#lifeTime;
|
|
6574
|
+
#onDestroy;
|
|
6575
|
+
#options;
|
|
6576
|
+
#paused;
|
|
6577
|
+
#pluginManager;
|
|
6578
|
+
#smooth;
|
|
6579
|
+
#sourceOptions;
|
|
6486
6580
|
constructor(params) {
|
|
6487
6581
|
const { dispatchCallback, pluginManager, id, onDestroy, sourceOptions } = params;
|
|
6488
|
-
this
|
|
6489
|
-
this
|
|
6490
|
-
this
|
|
6582
|
+
this.#pluginManager = pluginManager;
|
|
6583
|
+
this.#dispatchCallback = dispatchCallback;
|
|
6584
|
+
this.#onDestroy = onDestroy;
|
|
6491
6585
|
this.id = Symbol(id);
|
|
6492
6586
|
this.fpsLimit = 120;
|
|
6493
6587
|
this.hdr = false;
|
|
6494
|
-
this
|
|
6495
|
-
this
|
|
6496
|
-
this
|
|
6497
|
-
this
|
|
6498
|
-
this
|
|
6588
|
+
this.#smooth = false;
|
|
6589
|
+
this.#delay = 0;
|
|
6590
|
+
this.#duration = 0;
|
|
6591
|
+
this.#lifeTime = 0;
|
|
6592
|
+
this.#firstStart = true;
|
|
6499
6593
|
this.started = false;
|
|
6500
6594
|
this.destroyed = false;
|
|
6501
|
-
this
|
|
6502
|
-
this
|
|
6595
|
+
this.#paused = true;
|
|
6596
|
+
this.#lastFrameTime = 0;
|
|
6503
6597
|
this.zLayers = 100;
|
|
6504
6598
|
this.pageHidden = false;
|
|
6505
|
-
this
|
|
6506
|
-
this
|
|
6599
|
+
this.#sourceOptions = sourceOptions;
|
|
6600
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6507
6601
|
this.effectDrawers = new Map();
|
|
6508
6602
|
this.shapeDrawers = new Map();
|
|
6509
6603
|
this.particleUpdaters = [];
|
|
6510
6604
|
this.retina = new Retina(this);
|
|
6511
|
-
this.canvas = new CanvasManager(this
|
|
6512
|
-
this.particles = new ParticlesManager(this
|
|
6605
|
+
this.canvas = new CanvasManager(this.#pluginManager, this);
|
|
6606
|
+
this.particles = new ParticlesManager(this.#pluginManager, this);
|
|
6513
6607
|
this.plugins = [];
|
|
6514
6608
|
this.particleDestroyedPlugins = [];
|
|
6515
6609
|
this.particleCreatedPlugins = [];
|
|
6516
6610
|
this.particlePositionPlugins = [];
|
|
6517
|
-
this
|
|
6518
|
-
this.actualOptions = loadContainerOptions(this
|
|
6519
|
-
this
|
|
6611
|
+
this.#options = loadContainerOptions(this.#pluginManager, this);
|
|
6612
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this);
|
|
6613
|
+
this.#eventListeners = new EventListeners(this);
|
|
6520
6614
|
this.dispatchEvent(exports.EventType.containerBuilt);
|
|
6521
6615
|
}
|
|
6522
6616
|
get animationStatus() {
|
|
6523
|
-
return !this
|
|
6617
|
+
return !this.#paused && !this.pageHidden && guardCheck(this);
|
|
6524
6618
|
}
|
|
6525
6619
|
get options() {
|
|
6526
|
-
return this
|
|
6620
|
+
return this.#options;
|
|
6527
6621
|
}
|
|
6528
6622
|
get sourceOptions() {
|
|
6529
|
-
return this
|
|
6623
|
+
return this.#sourceOptions;
|
|
6530
6624
|
}
|
|
6531
6625
|
addLifeTime(value) {
|
|
6532
|
-
this
|
|
6626
|
+
this.#lifeTime += value;
|
|
6533
6627
|
}
|
|
6534
6628
|
alive() {
|
|
6535
|
-
return !this
|
|
6629
|
+
return !this.#duration || this.#lifeTime <= this.#duration;
|
|
6536
6630
|
}
|
|
6537
6631
|
destroy(remove = true) {
|
|
6538
6632
|
if (!guardCheck(this)) {
|
|
@@ -6554,13 +6648,13 @@
|
|
|
6554
6648
|
this.shapeDrawers = new Map();
|
|
6555
6649
|
this.particleUpdaters = [];
|
|
6556
6650
|
this.plugins.length = 0;
|
|
6557
|
-
this.
|
|
6651
|
+
this.#pluginManager.clearPlugins(this);
|
|
6558
6652
|
this.destroyed = true;
|
|
6559
|
-
this
|
|
6653
|
+
this.#onDestroy(remove);
|
|
6560
6654
|
this.dispatchEvent(exports.EventType.containerDestroyed);
|
|
6561
6655
|
}
|
|
6562
6656
|
dispatchEvent(type, data) {
|
|
6563
|
-
this
|
|
6657
|
+
this.#dispatchCallback(type, {
|
|
6564
6658
|
container: this,
|
|
6565
6659
|
data,
|
|
6566
6660
|
});
|
|
@@ -6570,12 +6664,12 @@
|
|
|
6570
6664
|
return;
|
|
6571
6665
|
}
|
|
6572
6666
|
let refreshTime = force;
|
|
6573
|
-
this
|
|
6667
|
+
this.#drawAnimationFrame = animate((timestamp) => {
|
|
6574
6668
|
if (refreshTime) {
|
|
6575
|
-
this
|
|
6669
|
+
this.#lastFrameTime = undefined;
|
|
6576
6670
|
refreshTime = false;
|
|
6577
6671
|
}
|
|
6578
|
-
this
|
|
6672
|
+
this.#nextFrame(timestamp);
|
|
6579
6673
|
});
|
|
6580
6674
|
}
|
|
6581
6675
|
async export(type, options = {}) {
|
|
@@ -6597,7 +6691,7 @@
|
|
|
6597
6691
|
return;
|
|
6598
6692
|
}
|
|
6599
6693
|
const allContainerPlugins = new Map();
|
|
6600
|
-
for (const plugin of this.
|
|
6694
|
+
for (const plugin of this.#pluginManager.plugins) {
|
|
6601
6695
|
const containerPlugin = await plugin.getPlugin(this);
|
|
6602
6696
|
if (containerPlugin.preInit) {
|
|
6603
6697
|
await containerPlugin.preInit();
|
|
@@ -6605,8 +6699,8 @@
|
|
|
6605
6699
|
allContainerPlugins.set(plugin, containerPlugin);
|
|
6606
6700
|
}
|
|
6607
6701
|
await this.initDrawersAndUpdaters();
|
|
6608
|
-
this
|
|
6609
|
-
this.actualOptions = loadContainerOptions(this
|
|
6702
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6703
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6610
6704
|
this.plugins.length = 0;
|
|
6611
6705
|
this.particleDestroyedPlugins.length = 0;
|
|
6612
6706
|
this.particleCreatedPlugins.length = 0;
|
|
@@ -6633,11 +6727,11 @@
|
|
|
6633
6727
|
const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
|
|
6634
6728
|
this.hdr = hdr;
|
|
6635
6729
|
this.zLayers = zLayers;
|
|
6636
|
-
this
|
|
6637
|
-
this
|
|
6638
|
-
this
|
|
6730
|
+
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
6731
|
+
this.#delay = getRangeValue(delay) * millisecondsToSeconds;
|
|
6732
|
+
this.#lifeTime = 0;
|
|
6639
6733
|
this.fpsLimit = fpsLimit > minFpsLimit ? fpsLimit : defaultFpsLimit;
|
|
6640
|
-
this
|
|
6734
|
+
this.#smooth = smooth;
|
|
6641
6735
|
for (const plugin of this.plugins) {
|
|
6642
6736
|
await plugin.init?.();
|
|
6643
6737
|
}
|
|
@@ -6650,7 +6744,7 @@
|
|
|
6650
6744
|
this.dispatchEvent(exports.EventType.particlesSetup);
|
|
6651
6745
|
}
|
|
6652
6746
|
async initDrawersAndUpdaters() {
|
|
6653
|
-
const pluginManager = this
|
|
6747
|
+
const pluginManager = this.#pluginManager;
|
|
6654
6748
|
this.effectDrawers = await pluginManager.getEffectDrawers(this, true);
|
|
6655
6749
|
this.shapeDrawers = await pluginManager.getShapeDrawers(this, true);
|
|
6656
6750
|
this.particleUpdaters = await pluginManager.getUpdaters(this, true);
|
|
@@ -6659,18 +6753,18 @@
|
|
|
6659
6753
|
if (!guardCheck(this)) {
|
|
6660
6754
|
return;
|
|
6661
6755
|
}
|
|
6662
|
-
if (this
|
|
6663
|
-
cancelAnimation(this
|
|
6664
|
-
|
|
6756
|
+
if (this.#drawAnimationFrame !== undefined) {
|
|
6757
|
+
cancelAnimation(this.#drawAnimationFrame);
|
|
6758
|
+
this.#drawAnimationFrame = undefined;
|
|
6665
6759
|
}
|
|
6666
|
-
if (this
|
|
6760
|
+
if (this.#paused) {
|
|
6667
6761
|
return;
|
|
6668
6762
|
}
|
|
6669
6763
|
for (const plugin of this.plugins) {
|
|
6670
6764
|
plugin.pause?.();
|
|
6671
6765
|
}
|
|
6672
6766
|
if (!this.pageHidden) {
|
|
6673
|
-
this
|
|
6767
|
+
this.#paused = true;
|
|
6674
6768
|
}
|
|
6675
6769
|
this.dispatchEvent(exports.EventType.containerPaused);
|
|
6676
6770
|
}
|
|
@@ -6678,13 +6772,13 @@
|
|
|
6678
6772
|
if (!guardCheck(this)) {
|
|
6679
6773
|
return;
|
|
6680
6774
|
}
|
|
6681
|
-
const needsUpdate = this
|
|
6682
|
-
if (this
|
|
6683
|
-
this
|
|
6775
|
+
const needsUpdate = this.#paused || force;
|
|
6776
|
+
if (this.#firstStart && !this.actualOptions.autoPlay) {
|
|
6777
|
+
this.#firstStart = false;
|
|
6684
6778
|
return;
|
|
6685
6779
|
}
|
|
6686
|
-
if (this
|
|
6687
|
-
this
|
|
6780
|
+
if (this.#paused) {
|
|
6781
|
+
this.#paused = false;
|
|
6688
6782
|
}
|
|
6689
6783
|
if (needsUpdate) {
|
|
6690
6784
|
for (const plugin of this.plugins) {
|
|
@@ -6707,10 +6801,10 @@
|
|
|
6707
6801
|
if (!guardCheck(this)) {
|
|
6708
6802
|
return;
|
|
6709
6803
|
}
|
|
6710
|
-
this
|
|
6711
|
-
this
|
|
6712
|
-
this
|
|
6713
|
-
this.actualOptions = loadContainerOptions(this
|
|
6804
|
+
this.#initialSourceOptions = sourceOptions;
|
|
6805
|
+
this.#sourceOptions = sourceOptions;
|
|
6806
|
+
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6807
|
+
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6714
6808
|
return this.refresh();
|
|
6715
6809
|
}
|
|
6716
6810
|
async start() {
|
|
@@ -6721,7 +6815,7 @@
|
|
|
6721
6815
|
this.started = true;
|
|
6722
6816
|
await new Promise(resolve => {
|
|
6723
6817
|
const start = async () => {
|
|
6724
|
-
this.
|
|
6818
|
+
this.#eventListeners.addListeners();
|
|
6725
6819
|
for (const plugin of this.plugins) {
|
|
6726
6820
|
await plugin.start?.();
|
|
6727
6821
|
}
|
|
@@ -6729,20 +6823,20 @@
|
|
|
6729
6823
|
this.play();
|
|
6730
6824
|
resolve();
|
|
6731
6825
|
};
|
|
6732
|
-
this
|
|
6826
|
+
this.#delayTimeout = setTimeout(() => void start(), this.#delay);
|
|
6733
6827
|
});
|
|
6734
6828
|
}
|
|
6735
6829
|
stop() {
|
|
6736
6830
|
if (!guardCheck(this) || !this.started) {
|
|
6737
6831
|
return;
|
|
6738
6832
|
}
|
|
6739
|
-
if (this
|
|
6740
|
-
clearTimeout(this
|
|
6741
|
-
|
|
6833
|
+
if (this.#delayTimeout) {
|
|
6834
|
+
clearTimeout(this.#delayTimeout);
|
|
6835
|
+
this.#delayTimeout = undefined;
|
|
6742
6836
|
}
|
|
6743
|
-
this
|
|
6837
|
+
this.#firstStart = true;
|
|
6744
6838
|
this.started = false;
|
|
6745
|
-
this.
|
|
6839
|
+
this.#eventListeners.removeListeners();
|
|
6746
6840
|
this.pause();
|
|
6747
6841
|
this.particles.clear();
|
|
6748
6842
|
this.canvas.stop();
|
|
@@ -6752,7 +6846,7 @@
|
|
|
6752
6846
|
this.particleCreatedPlugins.length = 0;
|
|
6753
6847
|
this.particleDestroyedPlugins.length = 0;
|
|
6754
6848
|
this.particlePositionPlugins.length = 0;
|
|
6755
|
-
this
|
|
6849
|
+
this.#sourceOptions = this.#options;
|
|
6756
6850
|
this.dispatchEvent(exports.EventType.containerStopped);
|
|
6757
6851
|
}
|
|
6758
6852
|
updateActualOptions() {
|
|
@@ -6764,23 +6858,23 @@
|
|
|
6764
6858
|
}
|
|
6765
6859
|
return refresh;
|
|
6766
6860
|
}
|
|
6767
|
-
|
|
6861
|
+
#nextFrame = (timestamp) => {
|
|
6768
6862
|
try {
|
|
6769
|
-
if (!this
|
|
6770
|
-
this
|
|
6771
|
-
timestamp < this
|
|
6863
|
+
if (!this.#smooth &&
|
|
6864
|
+
this.#lastFrameTime !== undefined &&
|
|
6865
|
+
timestamp < this.#lastFrameTime + millisecondsToSeconds / this.fpsLimit) {
|
|
6772
6866
|
this.draw(false);
|
|
6773
6867
|
return;
|
|
6774
6868
|
}
|
|
6775
|
-
this
|
|
6776
|
-
updateDelta(this
|
|
6777
|
-
this.addLifeTime(this.
|
|
6778
|
-
this
|
|
6779
|
-
if (this.
|
|
6869
|
+
this.#lastFrameTime ??= timestamp;
|
|
6870
|
+
updateDelta(this.#delta, timestamp - this.#lastFrameTime, this.fpsLimit, this.#smooth);
|
|
6871
|
+
this.addLifeTime(this.#delta.value);
|
|
6872
|
+
this.#lastFrameTime = timestamp;
|
|
6873
|
+
if (this.#delta.value > millisecondsToSeconds) {
|
|
6780
6874
|
this.draw(false);
|
|
6781
6875
|
return;
|
|
6782
6876
|
}
|
|
6783
|
-
this.canvas.render.drawParticles(this
|
|
6877
|
+
this.canvas.render.drawParticles(this.#delta);
|
|
6784
6878
|
if (!this.alive()) {
|
|
6785
6879
|
this.destroy();
|
|
6786
6880
|
return;
|
|
@@ -6801,18 +6895,18 @@
|
|
|
6801
6895
|
});
|
|
6802
6896
|
|
|
6803
6897
|
class ParticlesInstance {
|
|
6804
|
-
|
|
6898
|
+
#container;
|
|
6805
6899
|
constructor(container) {
|
|
6806
|
-
this
|
|
6900
|
+
this.#container = container;
|
|
6807
6901
|
}
|
|
6808
6902
|
pause() {
|
|
6809
|
-
this.
|
|
6903
|
+
this.#container.pause();
|
|
6810
6904
|
}
|
|
6811
6905
|
play() {
|
|
6812
|
-
this.
|
|
6906
|
+
this.#container.play();
|
|
6813
6907
|
}
|
|
6814
6908
|
stop() {
|
|
6815
|
-
this.
|
|
6909
|
+
this.#container.stop();
|
|
6816
6910
|
}
|
|
6817
6911
|
}
|
|
6818
6912
|
|
|
@@ -6822,10 +6916,10 @@
|
|
|
6822
6916
|
});
|
|
6823
6917
|
|
|
6824
6918
|
class BlendPluginInstance {
|
|
6825
|
-
|
|
6826
|
-
|
|
6919
|
+
#container;
|
|
6920
|
+
#defaultCompositeValue;
|
|
6827
6921
|
constructor(container) {
|
|
6828
|
-
this
|
|
6922
|
+
this.#container = container;
|
|
6829
6923
|
}
|
|
6830
6924
|
drawParticleCleanup(context, particle) {
|
|
6831
6925
|
if (!particle.options.blend?.enable) {
|
|
@@ -6842,14 +6936,14 @@
|
|
|
6842
6936
|
context.globalCompositeOperation = particle.options.blend.mode;
|
|
6843
6937
|
}
|
|
6844
6938
|
drawSettingsCleanup(context) {
|
|
6845
|
-
if (!this
|
|
6939
|
+
if (!this.#defaultCompositeValue) {
|
|
6846
6940
|
return;
|
|
6847
6941
|
}
|
|
6848
|
-
context.globalCompositeOperation = this
|
|
6942
|
+
context.globalCompositeOperation = this.#defaultCompositeValue;
|
|
6849
6943
|
}
|
|
6850
6944
|
drawSettingsSetup(context) {
|
|
6851
|
-
const previousComposite = context.globalCompositeOperation, blend = this.
|
|
6852
|
-
this
|
|
6945
|
+
const previousComposite = context.globalCompositeOperation, blend = this.#container.actualOptions.blend;
|
|
6946
|
+
this.#defaultCompositeValue = previousComposite;
|
|
6853
6947
|
context.globalCompositeOperation = blend?.enable ? blend.mode : previousComposite;
|
|
6854
6948
|
}
|
|
6855
6949
|
}
|
|
@@ -6992,11 +7086,11 @@
|
|
|
6992
7086
|
class MovePluginInstance {
|
|
6993
7087
|
availablePathGenerators;
|
|
6994
7088
|
pathGenerators;
|
|
6995
|
-
|
|
6996
|
-
|
|
7089
|
+
#container;
|
|
7090
|
+
#pluginManager;
|
|
6997
7091
|
constructor(pluginManager, container) {
|
|
6998
|
-
this
|
|
6999
|
-
this
|
|
7092
|
+
this.#pluginManager = pluginManager;
|
|
7093
|
+
this.#container = container;
|
|
7000
7094
|
this.availablePathGenerators = new Map();
|
|
7001
7095
|
this.pathGenerators = new Map();
|
|
7002
7096
|
}
|
|
@@ -7027,7 +7121,7 @@
|
|
|
7027
7121
|
acceleration: getRangeValue(gravityOptions.acceleration),
|
|
7028
7122
|
inverse: gravityOptions.inverse,
|
|
7029
7123
|
};
|
|
7030
|
-
initSpin(this
|
|
7124
|
+
initSpin(this.#container, particle);
|
|
7031
7125
|
}
|
|
7032
7126
|
particleDestroyed(particle) {
|
|
7033
7127
|
const pathGenerator = particle.pathGenerator;
|
|
@@ -7038,7 +7132,7 @@
|
|
|
7038
7132
|
if (!moveOptions.enable) {
|
|
7039
7133
|
return;
|
|
7040
7134
|
}
|
|
7041
|
-
const container = this
|
|
7135
|
+
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;
|
|
7042
7136
|
if (moveOptions.spin.enable) {
|
|
7043
7137
|
spin(container, particle, moveSpeed, reduceFactor);
|
|
7044
7138
|
}
|
|
@@ -7048,18 +7142,18 @@
|
|
|
7048
7142
|
applyDistance(particle);
|
|
7049
7143
|
}
|
|
7050
7144
|
preInit() {
|
|
7051
|
-
return this
|
|
7145
|
+
return this.#init();
|
|
7052
7146
|
}
|
|
7053
7147
|
redrawInit() {
|
|
7054
|
-
return this
|
|
7148
|
+
return this.#init();
|
|
7055
7149
|
}
|
|
7056
7150
|
update() {
|
|
7057
7151
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
7058
7152
|
pathGenerator.update();
|
|
7059
7153
|
}
|
|
7060
7154
|
}
|
|
7061
|
-
async
|
|
7062
|
-
const availablePathGenerators = await this.
|
|
7155
|
+
async #init() {
|
|
7156
|
+
const availablePathGenerators = await this.#pluginManager.getPathGenerators?.(this.#container, true);
|
|
7063
7157
|
if (!availablePathGenerators) {
|
|
7064
7158
|
return;
|
|
7065
7159
|
}
|
|
@@ -7078,65 +7172,65 @@
|
|
|
7078
7172
|
|
|
7079
7173
|
const touchDelay = 500;
|
|
7080
7174
|
class InteractivityEventListeners {
|
|
7081
|
-
|
|
7082
|
-
|
|
7083
|
-
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
|
|
7175
|
+
#canPush = true;
|
|
7176
|
+
#clickPositionPlugins;
|
|
7177
|
+
#container;
|
|
7178
|
+
#handlers;
|
|
7179
|
+
#interactionManager;
|
|
7180
|
+
#touches;
|
|
7087
7181
|
constructor(container, interactionManager) {
|
|
7088
|
-
this
|
|
7089
|
-
this
|
|
7090
|
-
this
|
|
7091
|
-
this
|
|
7092
|
-
this
|
|
7182
|
+
this.#container = container;
|
|
7183
|
+
this.#clickPositionPlugins = [];
|
|
7184
|
+
this.#interactionManager = interactionManager;
|
|
7185
|
+
this.#touches = new Map();
|
|
7186
|
+
this.#handlers = {
|
|
7093
7187
|
mouseDown: () => {
|
|
7094
|
-
this
|
|
7188
|
+
this.#mouseDown();
|
|
7095
7189
|
},
|
|
7096
7190
|
mouseLeave: () => {
|
|
7097
|
-
this
|
|
7191
|
+
this.#mouseTouchFinish();
|
|
7098
7192
|
},
|
|
7099
7193
|
mouseMove: (e) => {
|
|
7100
|
-
this
|
|
7194
|
+
this.#mouseTouchMove(e);
|
|
7101
7195
|
},
|
|
7102
7196
|
mouseUp: (e) => {
|
|
7103
|
-
this
|
|
7197
|
+
this.#mouseTouchClick(e);
|
|
7104
7198
|
},
|
|
7105
7199
|
touchStart: (e) => {
|
|
7106
|
-
this
|
|
7200
|
+
this.#touchStart(e);
|
|
7107
7201
|
},
|
|
7108
7202
|
touchMove: (e) => {
|
|
7109
|
-
this
|
|
7203
|
+
this.#mouseTouchMove(e);
|
|
7110
7204
|
},
|
|
7111
7205
|
touchEnd: (e) => {
|
|
7112
|
-
this
|
|
7206
|
+
this.#touchEnd(e);
|
|
7113
7207
|
},
|
|
7114
7208
|
touchCancel: (e) => {
|
|
7115
|
-
this
|
|
7209
|
+
this.#touchEnd(e);
|
|
7116
7210
|
},
|
|
7117
7211
|
touchEndClick: (e) => {
|
|
7118
|
-
this
|
|
7212
|
+
this.#touchEndClick(e);
|
|
7119
7213
|
},
|
|
7120
7214
|
visibilityChange: () => {
|
|
7121
|
-
this
|
|
7215
|
+
this.#handleVisibilityChange();
|
|
7122
7216
|
},
|
|
7123
7217
|
};
|
|
7124
7218
|
}
|
|
7125
7219
|
addListeners() {
|
|
7126
|
-
this
|
|
7220
|
+
this.#manageListeners(true);
|
|
7127
7221
|
}
|
|
7128
7222
|
init() {
|
|
7129
|
-
this.
|
|
7130
|
-
for (const plugin of this.
|
|
7131
|
-
this.
|
|
7223
|
+
this.#clickPositionPlugins.length = 0;
|
|
7224
|
+
for (const plugin of this.#container.plugins.filter(p => !!p.clickPositionValid)) {
|
|
7225
|
+
this.#clickPositionPlugins.push(plugin);
|
|
7132
7226
|
}
|
|
7133
7227
|
}
|
|
7134
7228
|
removeListeners() {
|
|
7135
|
-
this
|
|
7229
|
+
this.#manageListeners(false);
|
|
7136
7230
|
}
|
|
7137
|
-
|
|
7138
|
-
const container = this
|
|
7139
|
-
if (this
|
|
7231
|
+
#doMouseTouchClick = e => {
|
|
7232
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions;
|
|
7233
|
+
if (this.#canPush) {
|
|
7140
7234
|
const mouseInteractivity = interactionManager.interactivityData.mouse, mousePos = mouseInteractivity.position;
|
|
7141
7235
|
if (!mousePos) {
|
|
7142
7236
|
return;
|
|
@@ -7153,15 +7247,15 @@
|
|
|
7153
7247
|
}
|
|
7154
7248
|
if (e.type === "touchend") {
|
|
7155
7249
|
setTimeout(() => {
|
|
7156
|
-
this
|
|
7250
|
+
this.#mouseTouchFinish();
|
|
7157
7251
|
}, touchDelay);
|
|
7158
7252
|
}
|
|
7159
7253
|
};
|
|
7160
|
-
|
|
7161
|
-
this
|
|
7254
|
+
#handleVisibilityChange = () => {
|
|
7255
|
+
this.#mouseTouchFinish();
|
|
7162
7256
|
};
|
|
7163
|
-
|
|
7164
|
-
const handlers = this
|
|
7257
|
+
#manageInteractivityListeners = add => {
|
|
7258
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivityEl = interactionManager.interactivityData.element;
|
|
7165
7259
|
if (!interactivityEl) {
|
|
7166
7260
|
return;
|
|
7167
7261
|
}
|
|
@@ -7192,8 +7286,8 @@
|
|
|
7192
7286
|
manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);
|
|
7193
7287
|
manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
|
|
7194
7288
|
};
|
|
7195
|
-
|
|
7196
|
-
const handlers = this
|
|
7289
|
+
#manageListeners = add => {
|
|
7290
|
+
const handlers = this.#handlers, container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, detectType = options.interactivity?.detectsOn, canvasEl = container.canvas.domElement;
|
|
7197
7291
|
if (detectType === InteractivityDetect.window) {
|
|
7198
7292
|
interactionManager.interactivityData.element = safeDocument();
|
|
7199
7293
|
}
|
|
@@ -7203,35 +7297,35 @@
|
|
|
7203
7297
|
else {
|
|
7204
7298
|
interactionManager.interactivityData.element = canvasEl;
|
|
7205
7299
|
}
|
|
7206
|
-
this
|
|
7300
|
+
this.#manageInteractivityListeners(add);
|
|
7207
7301
|
manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
|
7208
7302
|
};
|
|
7209
|
-
|
|
7210
|
-
const { interactivityData } = this
|
|
7303
|
+
#mouseDown = () => {
|
|
7304
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
7211
7305
|
mouse.clicking = true;
|
|
7212
7306
|
mouse.downPosition = mouse.position;
|
|
7213
7307
|
};
|
|
7214
|
-
|
|
7215
|
-
const container = this
|
|
7308
|
+
#mouseTouchClick = e => {
|
|
7309
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
|
|
7216
7310
|
mouse.inside = true;
|
|
7217
7311
|
let handled = false;
|
|
7218
7312
|
const mousePosition = mouse.position;
|
|
7219
7313
|
if (!mousePosition || !options.interactivity?.events.onClick.enable) {
|
|
7220
7314
|
return;
|
|
7221
7315
|
}
|
|
7222
|
-
for (const plugin of this
|
|
7316
|
+
for (const plugin of this.#clickPositionPlugins) {
|
|
7223
7317
|
handled = plugin.clickPositionValid?.(mousePosition) ?? false;
|
|
7224
7318
|
if (handled) {
|
|
7225
7319
|
break;
|
|
7226
7320
|
}
|
|
7227
7321
|
}
|
|
7228
7322
|
if (!handled) {
|
|
7229
|
-
this
|
|
7323
|
+
this.#doMouseTouchClick(e);
|
|
7230
7324
|
}
|
|
7231
7325
|
mouse.clicking = false;
|
|
7232
7326
|
};
|
|
7233
|
-
|
|
7234
|
-
const { interactivityData } = this
|
|
7327
|
+
#mouseTouchFinish = () => {
|
|
7328
|
+
const { interactivityData } = this.#interactionManager, { mouse } = interactivityData;
|
|
7235
7329
|
delete mouse.position;
|
|
7236
7330
|
delete mouse.clickPosition;
|
|
7237
7331
|
delete mouse.downPosition;
|
|
@@ -7239,15 +7333,15 @@
|
|
|
7239
7333
|
mouse.inside = false;
|
|
7240
7334
|
mouse.clicking = false;
|
|
7241
7335
|
};
|
|
7242
|
-
|
|
7243
|
-
const container = this
|
|
7336
|
+
#mouseTouchMove = e => {
|
|
7337
|
+
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, interactivity = interactionManager.interactivityData, canvasEl = container.canvas.domElement;
|
|
7244
7338
|
if (!interactivity.element) {
|
|
7245
7339
|
return;
|
|
7246
7340
|
}
|
|
7247
7341
|
interactivity.mouse.inside = true;
|
|
7248
7342
|
let pos;
|
|
7249
7343
|
if (e.type.startsWith("pointer")) {
|
|
7250
|
-
this
|
|
7344
|
+
this.#canPush = true;
|
|
7251
7345
|
const mouseEvent = e;
|
|
7252
7346
|
if (interactivity.element === safeDocument()) {
|
|
7253
7347
|
if (canvasEl) {
|
|
@@ -7282,7 +7376,7 @@
|
|
|
7282
7376
|
}
|
|
7283
7377
|
}
|
|
7284
7378
|
else {
|
|
7285
|
-
this
|
|
7379
|
+
this.#canPush = e.type !== "touchmove";
|
|
7286
7380
|
if (canvasEl) {
|
|
7287
7381
|
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect();
|
|
7288
7382
|
if (!lastTouch) {
|
|
@@ -7302,60 +7396,60 @@
|
|
|
7302
7396
|
interactivity.mouse.position = pos;
|
|
7303
7397
|
interactivity.status = mouseMoveEvent;
|
|
7304
7398
|
};
|
|
7305
|
-
|
|
7399
|
+
#touchEnd = e => {
|
|
7306
7400
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
7307
7401
|
for (const touch of touches) {
|
|
7308
|
-
this.
|
|
7402
|
+
this.#touches.delete(touch.identifier);
|
|
7309
7403
|
}
|
|
7310
|
-
this
|
|
7404
|
+
this.#mouseTouchFinish();
|
|
7311
7405
|
};
|
|
7312
|
-
|
|
7406
|
+
#touchEndClick = e => {
|
|
7313
7407
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
7314
7408
|
for (const touch of touches) {
|
|
7315
|
-
this.
|
|
7409
|
+
this.#touches.delete(touch.identifier);
|
|
7316
7410
|
}
|
|
7317
|
-
this
|
|
7411
|
+
this.#mouseTouchClick(e);
|
|
7318
7412
|
};
|
|
7319
|
-
|
|
7413
|
+
#touchStart = e => {
|
|
7320
7414
|
const evt = e, touches = Array.from(evt.changedTouches);
|
|
7321
7415
|
for (const touch of touches) {
|
|
7322
|
-
this.
|
|
7416
|
+
this.#touches.set(touch.identifier, performance.now());
|
|
7323
7417
|
}
|
|
7324
|
-
this
|
|
7418
|
+
this.#mouseTouchMove(e);
|
|
7325
7419
|
};
|
|
7326
7420
|
}
|
|
7327
7421
|
|
|
7328
7422
|
const clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0;
|
|
7329
7423
|
class InteractionManager {
|
|
7330
|
-
container;
|
|
7331
7424
|
interactivityData;
|
|
7332
|
-
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7336
|
-
|
|
7337
|
-
|
|
7338
|
-
|
|
7425
|
+
#clickHandlers;
|
|
7426
|
+
#container;
|
|
7427
|
+
#eventListeners;
|
|
7428
|
+
#externalInteractors;
|
|
7429
|
+
#interactors;
|
|
7430
|
+
#intersectionObserver;
|
|
7431
|
+
#particleInteractors;
|
|
7432
|
+
#pluginManager;
|
|
7339
7433
|
constructor(pluginManager, container) {
|
|
7340
|
-
this
|
|
7341
|
-
this
|
|
7342
|
-
this
|
|
7343
|
-
this
|
|
7344
|
-
this
|
|
7345
|
-
this
|
|
7346
|
-
this
|
|
7434
|
+
this.#container = container;
|
|
7435
|
+
this.#pluginManager = pluginManager;
|
|
7436
|
+
this.#interactors = [];
|
|
7437
|
+
this.#externalInteractors = [];
|
|
7438
|
+
this.#particleInteractors = [];
|
|
7439
|
+
this.#clickHandlers = new Map();
|
|
7440
|
+
this.#eventListeners = new InteractivityEventListeners(container, this);
|
|
7347
7441
|
this.interactivityData = {
|
|
7348
7442
|
mouse: {
|
|
7349
7443
|
clicking: false,
|
|
7350
7444
|
inside: false,
|
|
7351
7445
|
},
|
|
7352
7446
|
};
|
|
7353
|
-
this
|
|
7354
|
-
this
|
|
7447
|
+
this.#intersectionObserver = safeIntersectionObserver(entries => {
|
|
7448
|
+
this.#intersectionManager(entries);
|
|
7355
7449
|
});
|
|
7356
7450
|
}
|
|
7357
7451
|
addClickHandler(callback) {
|
|
7358
|
-
const
|
|
7452
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
7359
7453
|
if (container.destroyed) {
|
|
7360
7454
|
return;
|
|
7361
7455
|
}
|
|
@@ -7417,119 +7511,119 @@
|
|
|
7417
7511
|
touchMoved = false;
|
|
7418
7512
|
};
|
|
7419
7513
|
let touched = false, touchMoved = false;
|
|
7420
|
-
this.
|
|
7421
|
-
this.
|
|
7422
|
-
this.
|
|
7423
|
-
this.
|
|
7424
|
-
this.
|
|
7425
|
-
for (const [key, handler] of this
|
|
7514
|
+
this.#clickHandlers.set(clickEvent, clickHandler);
|
|
7515
|
+
this.#clickHandlers.set(touchStartEvent, touchStartHandler);
|
|
7516
|
+
this.#clickHandlers.set(touchMoveEvent, touchMoveHandler);
|
|
7517
|
+
this.#clickHandlers.set(touchEndEvent, touchEndHandler);
|
|
7518
|
+
this.#clickHandlers.set(touchCancelEvent, touchCancelHandler);
|
|
7519
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
7426
7520
|
el.addEventListener(key, handler);
|
|
7427
7521
|
}
|
|
7428
7522
|
}
|
|
7429
7523
|
addListeners() {
|
|
7430
|
-
this.
|
|
7524
|
+
this.#eventListeners.addListeners();
|
|
7431
7525
|
}
|
|
7432
7526
|
clearClickHandlers() {
|
|
7433
|
-
const
|
|
7527
|
+
const container = this.#container, interactivityData = this.interactivityData;
|
|
7434
7528
|
if (container.destroyed) {
|
|
7435
7529
|
return;
|
|
7436
7530
|
}
|
|
7437
|
-
for (const [key, handler] of this
|
|
7531
|
+
for (const [key, handler] of this.#clickHandlers) {
|
|
7438
7532
|
interactivityData.element?.removeEventListener(key, handler);
|
|
7439
7533
|
}
|
|
7440
|
-
this.
|
|
7534
|
+
this.#clickHandlers.clear();
|
|
7441
7535
|
}
|
|
7442
7536
|
externalInteract(delta) {
|
|
7443
|
-
for (const interactor of this
|
|
7444
|
-
const
|
|
7537
|
+
for (const interactor of this.#externalInteractors) {
|
|
7538
|
+
const interactivityData = this.interactivityData;
|
|
7445
7539
|
if (interactor.isEnabled(interactivityData)) {
|
|
7446
7540
|
interactor.interact(interactivityData, delta);
|
|
7447
7541
|
}
|
|
7448
7542
|
}
|
|
7449
7543
|
}
|
|
7450
7544
|
handleClickMode(mode) {
|
|
7451
|
-
if (this
|
|
7545
|
+
if (this.#container.destroyed) {
|
|
7452
7546
|
return;
|
|
7453
7547
|
}
|
|
7454
|
-
const
|
|
7455
|
-
for (const interactor of this
|
|
7548
|
+
const interactivityData = this.interactivityData;
|
|
7549
|
+
for (const interactor of this.#externalInteractors) {
|
|
7456
7550
|
interactor.handleClickMode?.(mode, interactivityData);
|
|
7457
7551
|
}
|
|
7458
7552
|
}
|
|
7459
7553
|
init() {
|
|
7460
|
-
this.
|
|
7461
|
-
for (const interactor of this
|
|
7554
|
+
this.#eventListeners.init();
|
|
7555
|
+
for (const interactor of this.#interactors) {
|
|
7462
7556
|
switch (interactor.type) {
|
|
7463
7557
|
case InteractorType.external:
|
|
7464
|
-
this.
|
|
7558
|
+
this.#externalInteractors.push(interactor);
|
|
7465
7559
|
break;
|
|
7466
7560
|
case InteractorType.particles:
|
|
7467
|
-
this.
|
|
7561
|
+
this.#particleInteractors.push(interactor);
|
|
7468
7562
|
break;
|
|
7469
7563
|
}
|
|
7470
7564
|
interactor.init();
|
|
7471
7565
|
}
|
|
7472
7566
|
}
|
|
7473
7567
|
async initInteractors() {
|
|
7474
|
-
const interactors = await this.
|
|
7568
|
+
const interactors = await this.#pluginManager.getInteractors?.(this.#container, true);
|
|
7475
7569
|
if (!interactors) {
|
|
7476
7570
|
return;
|
|
7477
7571
|
}
|
|
7478
|
-
this
|
|
7479
|
-
this
|
|
7480
|
-
this
|
|
7572
|
+
this.#interactors = interactors;
|
|
7573
|
+
this.#externalInteractors = [];
|
|
7574
|
+
this.#particleInteractors = [];
|
|
7481
7575
|
}
|
|
7482
7576
|
particlesInteract(particle, delta) {
|
|
7483
|
-
const
|
|
7484
|
-
for (const interactor of this
|
|
7577
|
+
const interactivityData = this.interactivityData;
|
|
7578
|
+
for (const interactor of this.#externalInteractors) {
|
|
7485
7579
|
interactor.clear(particle, delta);
|
|
7486
7580
|
}
|
|
7487
|
-
for (const interactor of this
|
|
7581
|
+
for (const interactor of this.#particleInteractors) {
|
|
7488
7582
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7489
7583
|
interactor.interact(particle, interactivityData, delta);
|
|
7490
7584
|
}
|
|
7491
7585
|
}
|
|
7492
7586
|
}
|
|
7493
7587
|
removeListeners() {
|
|
7494
|
-
this.
|
|
7588
|
+
this.#eventListeners.removeListeners();
|
|
7495
7589
|
}
|
|
7496
7590
|
reset(particle) {
|
|
7497
|
-
const
|
|
7498
|
-
for (const interactor of this
|
|
7591
|
+
const interactivityData = this.interactivityData;
|
|
7592
|
+
for (const interactor of this.#externalInteractors) {
|
|
7499
7593
|
if (interactor.isEnabled(interactivityData)) {
|
|
7500
7594
|
interactor.reset(interactivityData, particle);
|
|
7501
7595
|
}
|
|
7502
7596
|
}
|
|
7503
|
-
for (const interactor of this
|
|
7597
|
+
for (const interactor of this.#particleInteractors) {
|
|
7504
7598
|
if (interactor.isEnabled(particle, interactivityData)) {
|
|
7505
7599
|
interactor.reset(interactivityData, particle);
|
|
7506
7600
|
}
|
|
7507
7601
|
}
|
|
7508
7602
|
}
|
|
7509
7603
|
startObserving() {
|
|
7510
|
-
const
|
|
7511
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7512
|
-
this.
|
|
7604
|
+
const interactivityData = this.interactivityData;
|
|
7605
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7606
|
+
this.#intersectionObserver.observe(interactivityData.element);
|
|
7513
7607
|
}
|
|
7514
7608
|
}
|
|
7515
7609
|
stopObserving() {
|
|
7516
|
-
const
|
|
7517
|
-
if (interactivityData.element instanceof HTMLElement && this
|
|
7518
|
-
this.
|
|
7610
|
+
const interactivityData = this.interactivityData;
|
|
7611
|
+
if (interactivityData.element instanceof HTMLElement && this.#intersectionObserver) {
|
|
7612
|
+
this.#intersectionObserver.unobserve(interactivityData.element);
|
|
7519
7613
|
}
|
|
7520
7614
|
}
|
|
7521
7615
|
updateMaxDistance() {
|
|
7522
7616
|
let maxTotalDistance = 0;
|
|
7523
|
-
for (const interactor of this
|
|
7617
|
+
for (const interactor of this.#interactors) {
|
|
7524
7618
|
if (interactor.maxDistance > maxTotalDistance) {
|
|
7525
7619
|
maxTotalDistance = interactor.maxDistance;
|
|
7526
7620
|
}
|
|
7527
7621
|
}
|
|
7528
|
-
const container = this
|
|
7622
|
+
const container = this.#container;
|
|
7529
7623
|
container.particles.grid.setCellSize(maxTotalDistance * container.retina.pixelRatio);
|
|
7530
7624
|
}
|
|
7531
|
-
|
|
7532
|
-
const
|
|
7625
|
+
#intersectionManager = entries => {
|
|
7626
|
+
const container = this.#container;
|
|
7533
7627
|
if (container.destroyed || !container.actualOptions.pauseOnOutsideViewport) {
|
|
7534
7628
|
return;
|
|
7535
7629
|
}
|
|
@@ -7549,13 +7643,13 @@
|
|
|
7549
7643
|
|
|
7550
7644
|
class InteractivityPluginInstance {
|
|
7551
7645
|
interactionManager;
|
|
7552
|
-
|
|
7553
|
-
|
|
7646
|
+
#container;
|
|
7647
|
+
#pluginManager;
|
|
7554
7648
|
constructor(pluginManager, container) {
|
|
7555
|
-
this
|
|
7556
|
-
this
|
|
7649
|
+
this.#container = container;
|
|
7650
|
+
this.#pluginManager = pluginManager;
|
|
7557
7651
|
this.interactionManager = new InteractionManager(pluginManager, container);
|
|
7558
|
-
this.
|
|
7652
|
+
this.#container.addClickHandler = (callback) => {
|
|
7559
7653
|
this.interactionManager.addClickHandler(callback);
|
|
7560
7654
|
};
|
|
7561
7655
|
}
|
|
@@ -7567,11 +7661,11 @@
|
|
|
7567
7661
|
}
|
|
7568
7662
|
destroy() {
|
|
7569
7663
|
this.clearClickHandlers();
|
|
7570
|
-
this.
|
|
7664
|
+
this.#pluginManager.interactors?.delete(this.#container);
|
|
7571
7665
|
}
|
|
7572
7666
|
particleCreated(particle) {
|
|
7573
|
-
const interactivityParticle = particle, interactivity = new Interactivity(this
|
|
7574
|
-
interactivity.load(this.
|
|
7667
|
+
const interactivityParticle = particle, interactivity = new Interactivity(this.#pluginManager, this.#container);
|
|
7668
|
+
interactivity.load(this.#container.actualOptions.interactivity);
|
|
7575
7669
|
interactivity.load(interactivityParticle.options.interactivity);
|
|
7576
7670
|
interactivityParticle.interactivity = interactivity;
|
|
7577
7671
|
}
|
|
@@ -7611,14 +7705,14 @@
|
|
|
7611
7705
|
|
|
7612
7706
|
const minRetries = 0;
|
|
7613
7707
|
class OverlapPluginInstance {
|
|
7614
|
-
|
|
7708
|
+
#container;
|
|
7615
7709
|
constructor(container) {
|
|
7616
|
-
this
|
|
7710
|
+
this.#container = container;
|
|
7617
7711
|
}
|
|
7618
7712
|
checkParticlePosition(particle, position, tryCount) {
|
|
7619
|
-
return !this
|
|
7713
|
+
return !this.#hasOverlaps(particle, position, tryCount);
|
|
7620
7714
|
}
|
|
7621
|
-
|
|
7715
|
+
#hasOverlaps = (particle, pos, tryCount) => {
|
|
7622
7716
|
const collisionsOptions = particle.options.collisions;
|
|
7623
7717
|
if (!collisionsOptions?.enable) {
|
|
7624
7718
|
return false;
|
|
@@ -7631,7 +7725,7 @@
|
|
|
7631
7725
|
if (retries >= minRetries && tryCount > retries) {
|
|
7632
7726
|
throw new Error(`Particle is overlapping and can't be placed`);
|
|
7633
7727
|
}
|
|
7634
|
-
return !!this.
|
|
7728
|
+
return !!this.#container.particles.find(p => getDistance(pos, p.position) < particle.getRadius() + p.getRadius());
|
|
7635
7729
|
};
|
|
7636
7730
|
}
|
|
7637
7731
|
|
|
@@ -7655,14 +7749,14 @@
|
|
|
7655
7749
|
|
|
7656
7750
|
const minOpacity = 0, minWidth = 0, minDistance = 0, maxFrequency = 1, defaultFrequency = 0;
|
|
7657
7751
|
class LinkInstance {
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7752
|
+
#colorCache = new Map();
|
|
7753
|
+
#container;
|
|
7754
|
+
#freqs;
|
|
7755
|
+
#pluginManager;
|
|
7662
7756
|
constructor(pluginManager, container) {
|
|
7663
|
-
this
|
|
7664
|
-
this
|
|
7665
|
-
this
|
|
7757
|
+
this.#pluginManager = pluginManager;
|
|
7758
|
+
this.#container = container;
|
|
7759
|
+
this.#freqs = { links: new Map(), triangles: new Map() };
|
|
7666
7760
|
}
|
|
7667
7761
|
drawParticle(context, particle) {
|
|
7668
7762
|
const { links, options } = particle;
|
|
@@ -7679,13 +7773,13 @@
|
|
|
7679
7773
|
};
|
|
7680
7774
|
for (const link of links) {
|
|
7681
7775
|
if (linkOpts.frequency < maxFrequency &&
|
|
7682
|
-
this
|
|
7776
|
+
this.#getLinkFrequency(particle, link.destination) > linkOpts.frequency) {
|
|
7683
7777
|
continue;
|
|
7684
7778
|
}
|
|
7685
7779
|
const pos2 = link.destination.getPosition();
|
|
7686
7780
|
if (trianglesEnabled && !link.isWarped && p1Destinations) {
|
|
7687
7781
|
flushLines();
|
|
7688
|
-
this
|
|
7782
|
+
this.#drawTriangles(options, particle, link, p1Destinations, pos1, pos2, context);
|
|
7689
7783
|
}
|
|
7690
7784
|
if (link.opacity <= minOpacity || width <= minWidth) {
|
|
7691
7785
|
continue;
|
|
@@ -7695,7 +7789,7 @@
|
|
|
7695
7789
|
}
|
|
7696
7790
|
let opacity = link.opacity, colorLine = link.color;
|
|
7697
7791
|
const twinkleRgb = twinkle?.enable && getRandom() < twinkle.frequency
|
|
7698
|
-
? rangeColorToRgb(this
|
|
7792
|
+
? rangeColorToRgb(this.#pluginManager, twinkle.color)
|
|
7699
7793
|
: undefined;
|
|
7700
7794
|
if (twinkle && twinkleRgb) {
|
|
7701
7795
|
colorLine = twinkleRgb;
|
|
@@ -7703,14 +7797,14 @@
|
|
|
7703
7797
|
}
|
|
7704
7798
|
if (!colorLine) {
|
|
7705
7799
|
const linkColor = linkOpts.id !== undefined
|
|
7706
|
-
? this.
|
|
7707
|
-
: this.
|
|
7800
|
+
? this.#container.particles.linksColors.get(linkOpts.id)
|
|
7801
|
+
: this.#container.particles.linksColor;
|
|
7708
7802
|
colorLine = getLinkColor(particle, link.destination, linkColor);
|
|
7709
7803
|
}
|
|
7710
7804
|
if (!colorLine) {
|
|
7711
7805
|
continue;
|
|
7712
7806
|
}
|
|
7713
|
-
const colorStyle = this
|
|
7807
|
+
const colorStyle = this.#getCachedStyle(colorLine);
|
|
7714
7808
|
if (colorStyle !== currentColorStyle || width !== currentWidth || opacity !== currentAlpha) {
|
|
7715
7809
|
flushLines();
|
|
7716
7810
|
context.strokeStyle = colorStyle;
|
|
@@ -7723,7 +7817,7 @@
|
|
|
7723
7817
|
pathOpen = true;
|
|
7724
7818
|
}
|
|
7725
7819
|
if (link.isWarped) {
|
|
7726
|
-
const canvasSize = this.
|
|
7820
|
+
const canvasSize = this.#container.canvas.size, dx = pos2.x - pos1.x, dy = pos2.y - pos1.y;
|
|
7727
7821
|
let sx = originPoint.x, sy = originPoint.y;
|
|
7728
7822
|
if (Math.abs(dx) > canvasSize.width * half) {
|
|
7729
7823
|
sx = dx > minDistance ? -canvasSize.width : canvasSize.width;
|
|
@@ -7745,9 +7839,9 @@
|
|
|
7745
7839
|
context.globalAlpha = originalAlpha;
|
|
7746
7840
|
}
|
|
7747
7841
|
init() {
|
|
7748
|
-
this.
|
|
7749
|
-
this.
|
|
7750
|
-
this.
|
|
7842
|
+
this.#freqs.links.clear();
|
|
7843
|
+
this.#freqs.triangles.clear();
|
|
7844
|
+
this.#colorCache.clear();
|
|
7751
7845
|
return Promise.resolve();
|
|
7752
7846
|
}
|
|
7753
7847
|
particleCreated(particle) {
|
|
@@ -7757,14 +7851,14 @@
|
|
|
7757
7851
|
}
|
|
7758
7852
|
particle.linksDistance = particle.options.links.distance;
|
|
7759
7853
|
particle.linksWidth = particle.options.links.width;
|
|
7760
|
-
const ratio = this.
|
|
7854
|
+
const ratio = this.#container.retina.pixelRatio;
|
|
7761
7855
|
particle.retina.linksDistance = particle.linksDistance * ratio;
|
|
7762
7856
|
particle.retina.linksWidth = particle.linksWidth * ratio;
|
|
7763
7857
|
}
|
|
7764
7858
|
particleDestroyed(particle) {
|
|
7765
7859
|
particle.links = [];
|
|
7766
7860
|
}
|
|
7767
|
-
|
|
7861
|
+
#drawTriangles(options, p1, link, p1Destinations, pos1, pos2, context) {
|
|
7768
7862
|
const p2 = link.destination, triangleOptions = options.links?.triangles;
|
|
7769
7863
|
if (!triangleOptions?.enable || !p2.options.links?.triangles.enable) {
|
|
7770
7864
|
return;
|
|
@@ -7775,21 +7869,21 @@
|
|
|
7775
7869
|
}
|
|
7776
7870
|
for (const vertex of p2Links) {
|
|
7777
7871
|
if (vertex.isWarped ||
|
|
7778
|
-
this
|
|
7872
|
+
this.#getLinkFrequency(p2, vertex.destination) > p2.options.links.frequency ||
|
|
7779
7873
|
!p1Destinations.has(vertex.destination.id)) {
|
|
7780
7874
|
continue;
|
|
7781
7875
|
}
|
|
7782
7876
|
const p3 = vertex.destination;
|
|
7783
|
-
if (this
|
|
7877
|
+
if (this.#getTriangleFrequency(p1, p2, p3) > (options.links?.triangles.frequency ?? defaultFrequency)) {
|
|
7784
7878
|
continue;
|
|
7785
7879
|
}
|
|
7786
|
-
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this
|
|
7880
|
+
const opacityTriangle = triangleOptions.opacity ?? (link.opacity + vertex.opacity) * half, colorTriangle = rangeColorToRgb(this.#pluginManager, triangleOptions.color) ?? link.color;
|
|
7787
7881
|
if (!colorTriangle || opacityTriangle <= minOpacity) {
|
|
7788
7882
|
continue;
|
|
7789
7883
|
}
|
|
7790
7884
|
const pos3 = p3.getPosition();
|
|
7791
7885
|
context.save();
|
|
7792
|
-
context.fillStyle = this
|
|
7886
|
+
context.fillStyle = this.#getCachedStyle(colorTriangle);
|
|
7793
7887
|
context.globalAlpha = opacityTriangle;
|
|
7794
7888
|
context.beginPath();
|
|
7795
7889
|
context.moveTo(pos1.x, pos1.y);
|
|
@@ -7800,20 +7894,20 @@
|
|
|
7800
7894
|
context.restore();
|
|
7801
7895
|
}
|
|
7802
7896
|
}
|
|
7803
|
-
|
|
7897
|
+
#getCachedStyle(rgb) {
|
|
7804
7898
|
const key = `${rgb.r},${rgb.g},${rgb.b}`;
|
|
7805
|
-
let style = this.
|
|
7899
|
+
let style = this.#colorCache.get(key);
|
|
7806
7900
|
if (!style) {
|
|
7807
|
-
style = getStyleFromRgb(rgb, this.
|
|
7808
|
-
this.
|
|
7901
|
+
style = getStyleFromRgb(rgb, this.#container.hdr);
|
|
7902
|
+
this.#colorCache.set(key, style);
|
|
7809
7903
|
}
|
|
7810
7904
|
return style;
|
|
7811
7905
|
}
|
|
7812
|
-
|
|
7813
|
-
return setLinkFrequency([p1, p2], this.
|
|
7906
|
+
#getLinkFrequency(p1, p2) {
|
|
7907
|
+
return setLinkFrequency([p1, p2], this.#freqs.links);
|
|
7814
7908
|
}
|
|
7815
|
-
|
|
7816
|
-
return setLinkFrequency([p1, p2, p3], this.
|
|
7909
|
+
#getTriangleFrequency(p1, p2, p3) {
|
|
7910
|
+
return setLinkFrequency([p1, p2, p3], this.#freqs.triangles);
|
|
7817
7911
|
}
|
|
7818
7912
|
}
|
|
7819
7913
|
|
|
@@ -7837,8 +7931,6 @@
|
|
|
7837
7931
|
exports.MoveCenter = MoveCenter;
|
|
7838
7932
|
exports.MoveGravity = MoveGravity;
|
|
7839
7933
|
exports.MovePath = MovePath;
|
|
7840
|
-
exports.Opacity = Opacity;
|
|
7841
|
-
exports.OpacityAnimation = OpacityAnimation;
|
|
7842
7934
|
exports.Options = Options;
|
|
7843
7935
|
exports.OptionsColor = OptionsColor;
|
|
7844
7936
|
exports.OutModes = OutModes;
|
|
@@ -7854,8 +7946,6 @@
|
|
|
7854
7946
|
exports.Rectangle = Rectangle;
|
|
7855
7947
|
exports.ResizeEvent = ResizeEvent;
|
|
7856
7948
|
exports.Shape = Shape;
|
|
7857
|
-
exports.Size = Size;
|
|
7858
|
-
exports.SizeAnimation = SizeAnimation;
|
|
7859
7949
|
exports.Spin = Spin;
|
|
7860
7950
|
exports.Stroke = Stroke;
|
|
7861
7951
|
exports.ValueWithRandom = ValueWithRandom;
|