@tsparticles/preset-firefly 4.4.0 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,21 +1,35 @@
|
|
|
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);
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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);})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
+
(function (g) {
|
|
3
|
+
/* Preset v4.5.1 */
|
|
4
|
+
g.__tsParticlesInternals = g.__tsParticlesInternals || {};
|
|
5
|
+
g.__tsParticlesInternals.presets = g.__tsParticlesInternals.presets || {};
|
|
6
|
+
(function (exports) {
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const errorPrefix = "tsParticles - Error", codedErrorPattern = /^\[tsParticles Error (TSP-\d+)\]\s*/, fullMatchIndex = 0, codeIndex = 1;
|
|
10
|
+
const wrap = (fn) => (...args) => {
|
|
11
|
+
fn(...args);
|
|
12
|
+
}, _logger = {
|
|
13
|
+
debug: wrap(console.debug),
|
|
14
|
+
error: (message, ...optionalParams) => {
|
|
15
|
+
if (typeof message === "string") {
|
|
16
|
+
const match = codedErrorPattern.exec(message);
|
|
17
|
+
if (match?.[codeIndex]) {
|
|
18
|
+
console.error(`tsParticles - ${match[codeIndex]} - ${message.slice(match[fullMatchIndex].length)}`, ...optionalParams);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
console.error(`${errorPrefix} - ${message}`, ...optionalParams);
|
|
23
|
+
},
|
|
24
|
+
info: wrap(console.info),
|
|
25
|
+
log: wrap(console.log),
|
|
26
|
+
trace: wrap(console.trace),
|
|
27
|
+
verbose: wrap(console.log),
|
|
28
|
+
warning: wrap(console.warn),
|
|
29
|
+
};
|
|
30
|
+
function getLogger() {
|
|
31
|
+
return _logger;
|
|
32
|
+
}
|
|
19
33
|
|
|
20
34
|
var MoveDirection;
|
|
21
35
|
(function (MoveDirection) {
|
|
@@ -32,6 +46,17 @@
|
|
|
32
46
|
MoveDirection["inside"] = "inside";
|
|
33
47
|
})(MoveDirection || (MoveDirection = {}));
|
|
34
48
|
|
|
49
|
+
const generatedAttribute = "generated", fullPercent = "100%", defaultCompositeValue = "source-over", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
|
|
50
|
+
x: 0,
|
|
51
|
+
y: 0,
|
|
52
|
+
z: 0,
|
|
53
|
+
}, defaultTransform = {
|
|
54
|
+
a: 1,
|
|
55
|
+
b: 0,
|
|
56
|
+
c: 0,
|
|
57
|
+
d: 1,
|
|
58
|
+
}, randomColorValue = "random", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, spatialHashGridCellSize = 100, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, inverseFactorNumerator = 1, rgbMax = 255, hMax = 360, sMax = 100, lMax = 100, hMin = 0, sMin = 0, hPhase = 60, empty = 0, quarter = 0.25, threeQuarter = half + quarter, minVelocity = 0, minDistance = 0, minRadius = 0, defaultTransformValue = 1, minimumSize = 0, zIndexFactorOffset = 1, defaultOpacity$1 = 1, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minZ = 0, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, defaultAngle = 0, identity$1 = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, maxNits = 400, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0, defaultZoom = 1;
|
|
59
|
+
|
|
35
60
|
function getZ(source) {
|
|
36
61
|
return "z" in source ? source.z : originPoint.z;
|
|
37
62
|
}
|
|
@@ -147,6 +172,12 @@
|
|
|
147
172
|
function isNumber(arg) {
|
|
148
173
|
return typeof arg === "number";
|
|
149
174
|
}
|
|
175
|
+
function isEnumValue(enumObject, arg) {
|
|
176
|
+
return Object.values(enumObject).some(enumValue => enumValue === arg);
|
|
177
|
+
}
|
|
178
|
+
function toEnumValue(enumObject, arg, defaultValue) {
|
|
179
|
+
return isEnumValue(enumObject, arg) ? arg : defaultValue;
|
|
180
|
+
}
|
|
150
181
|
function isObject(arg) {
|
|
151
182
|
return typeof arg === "object" && arg !== null;
|
|
152
183
|
}
|
|
@@ -270,11 +301,61 @@
|
|
|
270
301
|
};
|
|
271
302
|
}
|
|
272
303
|
function parseAlpha(input) {
|
|
273
|
-
const defaultAlpha = 1;
|
|
274
304
|
if (!input) {
|
|
275
305
|
return defaultAlpha;
|
|
276
306
|
}
|
|
277
|
-
return input.endsWith("%") ? parseFloat(input) / percentDenominator : parseFloat(input);
|
|
307
|
+
return input.endsWith("%") ? Number.parseFloat(input) / percentDenominator : Number.parseFloat(input);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const ErrorCodes$2 = {
|
|
311
|
+
engineVersionMismatch: "TSP-1001",
|
|
312
|
+
particlePositionNotFound: "TSP-1002",
|
|
313
|
+
pluginRegisterAfterLoad: "TSP-1003",
|
|
314
|
+
offscreenCanvasUnsupported: "TSP-1101",
|
|
315
|
+
offscreenCanvasTransferFailed: "TSP-1102",
|
|
316
|
+
hdrEnableInvalid: "TSP-1201",
|
|
317
|
+
hdrModeInvalid: "TSP-1202",
|
|
318
|
+
hdrPeakNitsInvalid: "TSP-1203",
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const messages = {
|
|
322
|
+
[ErrorCodes$2.engineVersionMismatch]: "The tsParticles version is different from the loaded plugins version. Engine version: {0}. Plugin version: {1}",
|
|
323
|
+
[ErrorCodes$2.particlePositionNotFound]: "a valid position cannot be found for particle",
|
|
324
|
+
[ErrorCodes$2.pluginRegisterAfterLoad]: "Register plugins can only be done before calling tsParticles.load()",
|
|
325
|
+
[ErrorCodes$2.offscreenCanvasUnsupported]: "OffscreenCanvas is required but not supported by this browser",
|
|
326
|
+
[ErrorCodes$2.offscreenCanvasTransferFailed]: "OffscreenCanvas transfer failed",
|
|
327
|
+
[ErrorCodes$2.hdrEnableInvalid]: 'Invalid HDR "enable" value: expected a boolean, got "{0}"',
|
|
328
|
+
[ErrorCodes$2.hdrModeInvalid]: 'Invalid HDR "mode" value: expected one of {0}, got "{1}"',
|
|
329
|
+
[ErrorCodes$2.hdrPeakNitsInvalid]: 'Invalid HDR "peakNits" value: expected a positive number, got "{0}"',
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
let registeredMessages;
|
|
333
|
+
const ensureRegisteredMessages = () => {
|
|
334
|
+
registeredMessages ??= new Map(Object.entries(messages));
|
|
335
|
+
return registeredMessages;
|
|
336
|
+
}, toStringValue$1 = (value) => String(value), format = (template, args) => {
|
|
337
|
+
return template.replace(/\{(\d+)\}/g, (match, index) => {
|
|
338
|
+
const arg = args[Number(index)];
|
|
339
|
+
return arg === undefined ? match : toStringValue$1(arg);
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
function addErrorMessages(extraMessages) {
|
|
343
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
const catalog = ensureRegisteredMessages();
|
|
347
|
+
for (const [code, message] of Object.entries(extraMessages)) {
|
|
348
|
+
if (message !== undefined) {
|
|
349
|
+
catalog.set(code, message);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
function getErrorMessage(code, ...args) {
|
|
354
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
|
|
355
|
+
return `[tsParticles Error ${code}] https://particles.js.org/errors/#${code}`;
|
|
356
|
+
}
|
|
357
|
+
const template = ensureRegisteredMessages().get(code) ?? `Unknown error code ${code}`;
|
|
358
|
+
return format(template, args);
|
|
278
359
|
}
|
|
279
360
|
|
|
280
361
|
var OutModeDirection;
|
|
@@ -291,7 +372,6 @@
|
|
|
291
372
|
PixelMode["percent"] = "percent";
|
|
292
373
|
})(PixelMode || (PixelMode = {}));
|
|
293
374
|
|
|
294
|
-
const minRadius = 0;
|
|
295
375
|
function isForbiddenKey(key) {
|
|
296
376
|
return key === "__proto__" || key === "constructor" || key === "prototype";
|
|
297
377
|
}
|
|
@@ -487,22 +567,84 @@
|
|
|
487
567
|
element.removeEventListener(event, handler, removeOptions);
|
|
488
568
|
}
|
|
489
569
|
}
|
|
490
|
-
async function getItemsFromInitializer(container,
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
570
|
+
async function getItemsFromInitializer(container, initializers) {
|
|
571
|
+
return await Promise.all([...initializers.values()].map(t => t(container)));
|
|
572
|
+
}
|
|
573
|
+
async function getItemMapFromInitializer(container, initializers) {
|
|
574
|
+
const entries = await Promise.all([...initializers.entries()].map(([key, initializer]) => initializer(container).then(item => [key, item])));
|
|
575
|
+
return new Map(entries);
|
|
576
|
+
}
|
|
577
|
+
async function getDataFromUrl(data) {
|
|
578
|
+
const url = itemFromSingleOrMultiple(data.url, data.index);
|
|
579
|
+
if (!url) {
|
|
580
|
+
return data.fallback;
|
|
495
581
|
}
|
|
496
|
-
|
|
582
|
+
try {
|
|
583
|
+
const response = await fetch(url);
|
|
584
|
+
if (response.ok) {
|
|
585
|
+
const current = (await response.json());
|
|
586
|
+
if (isSourceOptionsValue(current)) {
|
|
587
|
+
return current;
|
|
588
|
+
}
|
|
589
|
+
getLogger().error("invalid configuration data while retrieving config file");
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
getLogger().error(`${response.status.toString()} while retrieving config file`);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
catch (error) {
|
|
596
|
+
getLogger().error(`error while retrieving config file: ${error}`);
|
|
597
|
+
}
|
|
598
|
+
return data.fallback;
|
|
497
599
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const entries = await Promise.all([...initializers.entries()].map(([key, initializer]) => initializer(container).then(item => [key, item])));
|
|
502
|
-
res = new Map(entries);
|
|
503
|
-
map.set(container, res);
|
|
600
|
+
function isSourceOptionsValue(value) {
|
|
601
|
+
if (isArray(value)) {
|
|
602
|
+
return value.every((entry) => isObject(entry) && !isArray(entry));
|
|
504
603
|
}
|
|
505
|
-
return
|
|
604
|
+
return isObject(value) && !isArray(value);
|
|
605
|
+
}
|
|
606
|
+
function getCanvasFromContainer(domContainer) {
|
|
607
|
+
let canvasEl;
|
|
608
|
+
const documentSafe = safeDocument(), isCanvas = domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag;
|
|
609
|
+
if (isCanvas) {
|
|
610
|
+
canvasEl = domContainer;
|
|
611
|
+
canvasEl.dataset[generatedAttribute] ??= generatedFalse;
|
|
612
|
+
if (canvasEl.dataset[generatedAttribute] === generatedTrue) {
|
|
613
|
+
canvasEl.style.width ||= fullPercent;
|
|
614
|
+
canvasEl.style.height ||= fullPercent;
|
|
615
|
+
canvasEl.style.pointerEvents = "none";
|
|
616
|
+
canvasEl.style.setProperty("pointer-events", "none");
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases.item(canvasFirstIndex);
|
|
621
|
+
if (foundCanvas) {
|
|
622
|
+
canvasEl = foundCanvas;
|
|
623
|
+
canvasEl.dataset[generatedAttribute] = generatedFalse;
|
|
624
|
+
}
|
|
625
|
+
else {
|
|
626
|
+
canvasEl = documentSafe.createElement(canvasTag);
|
|
627
|
+
canvasEl.dataset[generatedAttribute] = generatedTrue;
|
|
628
|
+
domContainer.appendChild(canvasEl);
|
|
629
|
+
}
|
|
630
|
+
canvasEl.style.width ||= fullPercent;
|
|
631
|
+
canvasEl.style.height ||= fullPercent;
|
|
632
|
+
canvasEl.style.pointerEvents = "none";
|
|
633
|
+
canvasEl.style.setProperty("pointer-events", "none");
|
|
634
|
+
}
|
|
635
|
+
return canvasEl;
|
|
636
|
+
}
|
|
637
|
+
function getDomContainer(id, source) {
|
|
638
|
+
const documentSafe = safeDocument();
|
|
639
|
+
let domContainer = source ?? documentSafe.getElementById(id);
|
|
640
|
+
if (domContainer) {
|
|
641
|
+
return domContainer;
|
|
642
|
+
}
|
|
643
|
+
domContainer = documentSafe.createElement("canvas");
|
|
644
|
+
domContainer.id = id;
|
|
645
|
+
domContainer.dataset[generatedAttribute] = generatedTrue;
|
|
646
|
+
documentSafe.body.append(domContainer);
|
|
647
|
+
return domContainer;
|
|
506
648
|
}
|
|
507
649
|
|
|
508
650
|
class EventDispatcher {
|
|
@@ -512,12 +654,8 @@
|
|
|
512
654
|
}
|
|
513
655
|
addEventListener(type, listener) {
|
|
514
656
|
this.removeEventListener(type, listener);
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
arr = [];
|
|
518
|
-
this.#listeners.set(type, arr);
|
|
519
|
-
}
|
|
520
|
-
arr.push(listener);
|
|
657
|
+
const arr = this.#listeners.get(type);
|
|
658
|
+
this.#listeners.set(type, arr ? [...arr, listener] : [listener]);
|
|
521
659
|
}
|
|
522
660
|
dispatchEvent(type, args) {
|
|
523
661
|
const listeners = this.#listeners.get(type);
|
|
@@ -549,7 +687,7 @@
|
|
|
549
687
|
this.#listeners.delete(type);
|
|
550
688
|
}
|
|
551
689
|
else {
|
|
552
|
-
arr.
|
|
690
|
+
this.#listeners.set(type, [...arr.slice(minIndex, idx), ...arr.slice(idx + deleteCount)]);
|
|
553
691
|
}
|
|
554
692
|
}
|
|
555
693
|
}
|
|
@@ -573,7 +711,6 @@
|
|
|
573
711
|
class PluginManager {
|
|
574
712
|
colorManagers = new Map();
|
|
575
713
|
easingFunctions = new Map();
|
|
576
|
-
effectDrawers = new Map();
|
|
577
714
|
initializers = {
|
|
578
715
|
effects: new Map(),
|
|
579
716
|
shapes: new Map(),
|
|
@@ -582,8 +719,6 @@
|
|
|
582
719
|
palettes = new Map();
|
|
583
720
|
plugins = [];
|
|
584
721
|
presets = new Map();
|
|
585
|
-
shapeDrawers = new Map();
|
|
586
|
-
updaters = new Map();
|
|
587
722
|
#allLoadersSet = new Set();
|
|
588
723
|
#configs = new Map();
|
|
589
724
|
#engine;
|
|
@@ -601,57 +736,79 @@
|
|
|
601
736
|
}
|
|
602
737
|
return res;
|
|
603
738
|
}
|
|
739
|
+
get initialized() {
|
|
740
|
+
return this.#initialized;
|
|
741
|
+
}
|
|
604
742
|
addColorManager(name, manager) {
|
|
743
|
+
if (this.#initialized) {
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
605
746
|
this.colorManagers.set(name, manager);
|
|
606
747
|
}
|
|
607
748
|
addConfig(config) {
|
|
749
|
+
if (this.#initialized) {
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
608
752
|
const key = config.key ?? config.name ?? "default";
|
|
609
753
|
this.#configs.set(key, config);
|
|
610
754
|
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
611
755
|
}
|
|
612
756
|
addEasing(name, easing) {
|
|
757
|
+
if (this.#initialized) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
613
760
|
if (this.easingFunctions.get(name)) {
|
|
614
761
|
return;
|
|
615
762
|
}
|
|
616
763
|
this.easingFunctions.set(name, easing);
|
|
617
764
|
}
|
|
618
765
|
addEffect(effect, drawer) {
|
|
766
|
+
if (this.#initialized) {
|
|
767
|
+
return;
|
|
768
|
+
}
|
|
619
769
|
this.initializers.effects.set(effect, drawer);
|
|
620
770
|
}
|
|
621
771
|
addPalette(name, palette) {
|
|
772
|
+
if (this.#initialized) {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
622
775
|
this.palettes.set(name, palette);
|
|
623
776
|
}
|
|
624
777
|
addParticleUpdater(name, updaterInitializer) {
|
|
778
|
+
if (this.#initialized) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
625
781
|
this.initializers.updaters.set(name, updaterInitializer);
|
|
626
782
|
}
|
|
627
783
|
addPlugin(plugin) {
|
|
784
|
+
if (this.#initialized) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
628
787
|
if (this.getPlugin(plugin.id)) {
|
|
629
788
|
return;
|
|
630
789
|
}
|
|
631
790
|
this.plugins.push(plugin);
|
|
632
791
|
}
|
|
633
792
|
addPreset(preset, options, override = false) {
|
|
793
|
+
if (this.#initialized) {
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
634
796
|
if (!(override || !this.getPreset(preset))) {
|
|
635
797
|
return;
|
|
636
798
|
}
|
|
637
799
|
this.presets.set(preset, options);
|
|
638
800
|
}
|
|
639
801
|
addShape(shapes, drawer) {
|
|
802
|
+
if (this.#initialized) {
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
640
805
|
for (const shape of shapes) {
|
|
641
806
|
this.initializers.shapes.set(shape, drawer);
|
|
642
807
|
}
|
|
643
808
|
}
|
|
644
|
-
clearPlugins(container) {
|
|
645
|
-
this.effectDrawers.delete(container);
|
|
646
|
-
this.shapeDrawers.delete(container);
|
|
647
|
-
this.updaters.delete(container);
|
|
648
|
-
}
|
|
649
809
|
getEasing(name) {
|
|
650
810
|
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
651
811
|
}
|
|
652
|
-
getEffectDrawers(container, force = false) {
|
|
653
|
-
return getItemMapFromInitializer(container, this.effectDrawers, this.initializers.effects, force);
|
|
654
|
-
}
|
|
655
812
|
getPalette(name) {
|
|
656
813
|
return this.palettes.get(name);
|
|
657
814
|
}
|
|
@@ -661,12 +818,6 @@
|
|
|
661
818
|
getPreset(preset) {
|
|
662
819
|
return this.presets.get(preset);
|
|
663
820
|
}
|
|
664
|
-
async getShapeDrawers(container, force = false) {
|
|
665
|
-
return getItemMapFromInitializer(container, this.shapeDrawers, this.initializers.shapes, force);
|
|
666
|
-
}
|
|
667
|
-
async getUpdaters(container, force = false) {
|
|
668
|
-
return getItemsFromInitializer(container, this.updaters, this.initializers.updaters, force);
|
|
669
|
-
}
|
|
670
821
|
async init() {
|
|
671
822
|
if (this.#initialized || this.#isRunningLoaders) {
|
|
672
823
|
return;
|
|
@@ -685,16 +836,9 @@
|
|
|
685
836
|
this.#initialized = true;
|
|
686
837
|
}
|
|
687
838
|
}
|
|
688
|
-
loadParticlesOptions(container, options, ...sourceOptions) {
|
|
689
|
-
const updaters = this.updaters.get(container);
|
|
690
|
-
if (!updaters) {
|
|
691
|
-
return;
|
|
692
|
-
}
|
|
693
|
-
updaters.forEach(updater => updater.loadOptions?.(options, ...sourceOptions));
|
|
694
|
-
}
|
|
695
839
|
async register(...loaders) {
|
|
696
840
|
if (this.#initialized) {
|
|
697
|
-
throw new Error(
|
|
841
|
+
throw new Error(getErrorMessage(ErrorCodes$2.pluginRegisterAfterLoad));
|
|
698
842
|
}
|
|
699
843
|
for (const loader of loaders) {
|
|
700
844
|
if (this.#isRunningLoaders) {
|
|
@@ -706,88 +850,15 @@
|
|
|
706
850
|
}
|
|
707
851
|
}
|
|
708
852
|
async #runLoader(loader, executed, allLoaders) {
|
|
709
|
-
if (executed.has(loader))
|
|
853
|
+
if (executed.has(loader)) {
|
|
710
854
|
return;
|
|
855
|
+
}
|
|
711
856
|
executed.add(loader);
|
|
712
857
|
allLoaders.add(loader);
|
|
713
858
|
await loader(this.#engine);
|
|
714
859
|
}
|
|
715
860
|
}
|
|
716
861
|
|
|
717
|
-
const errorPrefix = "tsParticles - Error";
|
|
718
|
-
const wrap = (fn) => (...args) => {
|
|
719
|
-
fn(...args);
|
|
720
|
-
}, _logger = {
|
|
721
|
-
debug: wrap(console.debug),
|
|
722
|
-
error: (message, ...optionalParams) => {
|
|
723
|
-
console.error(`${errorPrefix} - ${message}`, ...optionalParams);
|
|
724
|
-
},
|
|
725
|
-
info: wrap(console.info),
|
|
726
|
-
log: wrap(console.log),
|
|
727
|
-
trace: wrap(console.trace),
|
|
728
|
-
verbose: wrap(console.log),
|
|
729
|
-
warning: wrap(console.warn),
|
|
730
|
-
};
|
|
731
|
-
function getLogger() {
|
|
732
|
-
return _logger;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
const fullPercent = "100%";
|
|
736
|
-
async function getDataFromUrl(data) {
|
|
737
|
-
const url = itemFromSingleOrMultiple(data.url, data.index);
|
|
738
|
-
if (!url) {
|
|
739
|
-
return data.fallback;
|
|
740
|
-
}
|
|
741
|
-
const response = await fetch(url);
|
|
742
|
-
if (response.ok) {
|
|
743
|
-
return (await response.json());
|
|
744
|
-
}
|
|
745
|
-
getLogger().error(`${response.status.toString()} while retrieving config file`);
|
|
746
|
-
return data.fallback;
|
|
747
|
-
}
|
|
748
|
-
const getCanvasFromContainer = (domContainer) => {
|
|
749
|
-
const documentSafe = safeDocument();
|
|
750
|
-
let canvasEl;
|
|
751
|
-
const isCanvas = domContainer instanceof HTMLCanvasElement || domContainer.tagName.toLowerCase() === canvasTag;
|
|
752
|
-
if (isCanvas) {
|
|
753
|
-
canvasEl = domContainer;
|
|
754
|
-
canvasEl.dataset[generatedAttribute] ??= generatedFalse;
|
|
755
|
-
if (canvasEl.dataset[generatedAttribute] === generatedTrue) {
|
|
756
|
-
canvasEl.style.width ||= fullPercent;
|
|
757
|
-
canvasEl.style.height ||= fullPercent;
|
|
758
|
-
canvasEl.style.pointerEvents = "none";
|
|
759
|
-
canvasEl.style.setProperty("pointer-events", "none");
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
else {
|
|
763
|
-
const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases.item(canvasFirstIndex);
|
|
764
|
-
if (foundCanvas) {
|
|
765
|
-
canvasEl = foundCanvas;
|
|
766
|
-
canvasEl.dataset[generatedAttribute] = generatedFalse;
|
|
767
|
-
}
|
|
768
|
-
else {
|
|
769
|
-
canvasEl = documentSafe.createElement(canvasTag);
|
|
770
|
-
canvasEl.dataset[generatedAttribute] = generatedTrue;
|
|
771
|
-
domContainer.appendChild(canvasEl);
|
|
772
|
-
}
|
|
773
|
-
canvasEl.style.width ||= fullPercent;
|
|
774
|
-
canvasEl.style.height ||= fullPercent;
|
|
775
|
-
canvasEl.style.pointerEvents = "none";
|
|
776
|
-
canvasEl.style.setProperty("pointer-events", "none");
|
|
777
|
-
}
|
|
778
|
-
return canvasEl;
|
|
779
|
-
}, getDomContainer = (id, source) => {
|
|
780
|
-
const documentSafe = safeDocument();
|
|
781
|
-
let domContainer = source ?? documentSafe.getElementById(id);
|
|
782
|
-
if (domContainer) {
|
|
783
|
-
return domContainer;
|
|
784
|
-
}
|
|
785
|
-
domContainer = documentSafe.createElement("canvas");
|
|
786
|
-
domContainer.id = id;
|
|
787
|
-
domContainer.dataset[generatedAttribute] = generatedTrue;
|
|
788
|
-
documentSafe.body.append(domContainer);
|
|
789
|
-
return domContainer;
|
|
790
|
-
};
|
|
791
862
|
class Engine {
|
|
792
863
|
pluginManager = new PluginManager(this);
|
|
793
864
|
#domArray = [];
|
|
@@ -797,7 +868,7 @@
|
|
|
797
868
|
return this.#domArray;
|
|
798
869
|
}
|
|
799
870
|
get version() {
|
|
800
|
-
return "4.
|
|
871
|
+
return "4.5.1";
|
|
801
872
|
}
|
|
802
873
|
addEventListener(type, listener) {
|
|
803
874
|
this.#eventDispatcher.addEventListener(type, listener);
|
|
@@ -806,7 +877,7 @@
|
|
|
806
877
|
if (this.version === pluginVersion) {
|
|
807
878
|
return;
|
|
808
879
|
}
|
|
809
|
-
throw new Error(
|
|
880
|
+
throw new Error(getErrorMessage(ErrorCodes$2.engineVersionMismatch, this.version, pluginVersion));
|
|
810
881
|
}
|
|
811
882
|
dispatchEvent(type, args) {
|
|
812
883
|
this.#eventDispatcher.dispatchEvent(type, args);
|
|
@@ -1055,20 +1126,6 @@
|
|
|
1055
1126
|
DrawLayer[DrawLayer["Foreground"] = 7] = "Foreground";
|
|
1056
1127
|
})(DrawLayer || (DrawLayer = {}));
|
|
1057
1128
|
|
|
1058
|
-
class OptionLoader {
|
|
1059
|
-
load(data) {
|
|
1060
|
-
if (isNull(data)) {
|
|
1061
|
-
return;
|
|
1062
|
-
}
|
|
1063
|
-
this.doLoad(data);
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
function loadOptions(options, ...sourceOptionsArr) {
|
|
1067
|
-
for (const sourceOptions of sourceOptionsArr) {
|
|
1068
|
-
options.load(sourceOptions);
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
1129
|
function loadProperty(obj, key, value) {
|
|
1073
1130
|
if (value !== undefined) {
|
|
1074
1131
|
obj[key] = value;
|
|
@@ -1100,6 +1157,20 @@
|
|
|
1100
1157
|
}
|
|
1101
1158
|
}
|
|
1102
1159
|
|
|
1160
|
+
class OptionLoader {
|
|
1161
|
+
load(data) {
|
|
1162
|
+
if (isNull(data)) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
this.doLoad(data);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
function loadOptions(options, ...sourceOptionsArr) {
|
|
1169
|
+
for (const sourceOptions of sourceOptionsArr) {
|
|
1170
|
+
options.load(sourceOptions);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1103
1174
|
class AnimationOptions extends OptionLoader {
|
|
1104
1175
|
count = 0;
|
|
1105
1176
|
decay = 0;
|
|
@@ -1250,15 +1321,14 @@
|
|
|
1250
1321
|
peakNits = defaultPeakNits;
|
|
1251
1322
|
doLoad(data) {
|
|
1252
1323
|
if (data.enable !== undefined && !isBoolean(data.enable)) {
|
|
1253
|
-
throw new Error(
|
|
1324
|
+
throw new Error(getErrorMessage(ErrorCodes$2.hdrEnableInvalid, String(data.enable)));
|
|
1254
1325
|
}
|
|
1255
|
-
if (data.mode !== undefined &&
|
|
1256
|
-
(
|
|
1257
|
-
throw new Error(`Invalid HDR "mode" value: expected one of ${Object.values(HdrMode).join(", ")}, got "${toStringValue(data.mode)}"`);
|
|
1326
|
+
if (data.mode !== undefined && !isEnumValue(HdrMode, data.mode)) {
|
|
1327
|
+
throw new Error(getErrorMessage(ErrorCodes$2.hdrModeInvalid, Object.values(HdrMode).join(", "), toStringValue(data.mode)));
|
|
1258
1328
|
}
|
|
1259
1329
|
if (data.peakNits !== undefined &&
|
|
1260
1330
|
(!isNumber(data.peakNits) || !Number.isFinite(data.peakNits) || data.peakNits <= minPeakNits)) {
|
|
1261
|
-
throw new Error(
|
|
1331
|
+
throw new Error(getErrorMessage(ErrorCodes$2.hdrPeakNitsInvalid, String(data.peakNits)));
|
|
1262
1332
|
}
|
|
1263
1333
|
loadProperty(this, "enable", data.enable);
|
|
1264
1334
|
loadProperty(this, "mode", data.mode);
|
|
@@ -1636,12 +1706,10 @@
|
|
|
1636
1706
|
plugin.loadParticlesOptions(this.#container, this, data);
|
|
1637
1707
|
}
|
|
1638
1708
|
}
|
|
1639
|
-
const updaters = this.#
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
updater.loadOptions(this, data);
|
|
1644
|
-
}
|
|
1709
|
+
const updaters = this.#container.particleUpdaters;
|
|
1710
|
+
for (const updater of updaters) {
|
|
1711
|
+
if (updater.loadOptions) {
|
|
1712
|
+
updater.loadOptions(this, data);
|
|
1645
1713
|
}
|
|
1646
1714
|
}
|
|
1647
1715
|
}
|
|
@@ -1974,9 +2042,9 @@
|
|
|
1974
2042
|
const grayscaleValue = Math.round(lNormalized * rgbMax);
|
|
1975
2043
|
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
|
|
1976
2044
|
}
|
|
1977
|
-
const
|
|
2045
|
+
const temp2 = lNormalized < half
|
|
1978
2046
|
? lNormalized * (sNormalizedOffset + sNormalized)
|
|
1979
|
-
: lNormalized + sNormalized - lNormalized * sNormalized,
|
|
2047
|
+
: lNormalized + sNormalized - lNormalized * sNormalized, temp1 = double * lNormalized - temp2, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized)), blue = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized - phaseThird));
|
|
1980
2048
|
return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
|
|
1981
2049
|
}
|
|
1982
2050
|
function hslToRgbFloat(hsl) {
|
|
@@ -1985,9 +2053,9 @@
|
|
|
1985
2053
|
const grayscaleValue = lNormalized * rgbMax;
|
|
1986
2054
|
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
|
|
1987
2055
|
}
|
|
1988
|
-
const
|
|
2056
|
+
const temp2 = lNormalized < half
|
|
1989
2057
|
? lNormalized * (sNormalizedOffset + sNormalized)
|
|
1990
|
-
: lNormalized + sNormalized - lNormalized * sNormalized,
|
|
2058
|
+
: lNormalized + sNormalized - lNormalized * sNormalized, temp1 = double * lNormalized - temp2, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized)), blue = Math.min(rgbMax, rgbMax * hslChannel(temp1, temp2, hNormalized - phaseThird));
|
|
1991
2059
|
return { r: red, g: green, b: blue };
|
|
1992
2060
|
}
|
|
1993
2061
|
function hslaToRgba(hsla) {
|
|
@@ -2201,7 +2269,7 @@
|
|
|
2201
2269
|
}
|
|
2202
2270
|
|
|
2203
2271
|
async function loadBlendPlugin(engine) {
|
|
2204
|
-
engine.checkVersion("4.
|
|
2272
|
+
engine.checkVersion("4.5.1");
|
|
2205
2273
|
await engine.pluginManager.register(e => {
|
|
2206
2274
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2207
2275
|
});
|
|
@@ -2238,7 +2306,7 @@
|
|
|
2238
2306
|
}
|
|
2239
2307
|
|
|
2240
2308
|
async function loadCircleShape(engine) {
|
|
2241
|
-
engine.checkVersion("4.
|
|
2309
|
+
engine.checkVersion("4.5.1");
|
|
2242
2310
|
await engine.pluginManager.register(e => {
|
|
2243
2311
|
e.pluginManager.addShape(["circle"], () => {
|
|
2244
2312
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2253,7 +2321,7 @@
|
|
|
2253
2321
|
RgbIndexes[RgbIndexes["b"] = 3] = "b";
|
|
2254
2322
|
RgbIndexes[RgbIndexes["a"] = 4] = "a";
|
|
2255
2323
|
})(RgbIndexes$1 || (RgbIndexes$1 = {}));
|
|
2256
|
-
const shorthandHexRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, hexRadix = 16,
|
|
2324
|
+
const shorthandHexRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i, hexRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i, hexRadix = 16, alphaFactor = 0xff;
|
|
2257
2325
|
class HexColorManager {
|
|
2258
2326
|
accepts(input) {
|
|
2259
2327
|
return input.startsWith("#");
|
|
@@ -2286,7 +2354,7 @@
|
|
|
2286
2354
|
}
|
|
2287
2355
|
|
|
2288
2356
|
async function loadHexColorPlugin(engine) {
|
|
2289
|
-
engine.checkVersion("4.
|
|
2357
|
+
engine.checkVersion("4.5.1");
|
|
2290
2358
|
await engine.pluginManager.register(e => {
|
|
2291
2359
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
2292
2360
|
});
|
|
@@ -2326,7 +2394,7 @@
|
|
|
2326
2394
|
if (!this.accepts(input)) {
|
|
2327
2395
|
return;
|
|
2328
2396
|
}
|
|
2329
|
-
const result = hslRegex.exec(input), minLength = 4,
|
|
2397
|
+
const result = hslRegex.exec(input), minLength = 4, radix = 10;
|
|
2330
2398
|
return result
|
|
2331
2399
|
? hslaToRgba({
|
|
2332
2400
|
a: result.length > minLength ? parseAlpha(result[HslIndexes.a]) : defaultAlpha,
|
|
@@ -2339,12 +2407,20 @@
|
|
|
2339
2407
|
}
|
|
2340
2408
|
|
|
2341
2409
|
async function loadHslColorPlugin(engine) {
|
|
2342
|
-
engine.checkVersion("4.
|
|
2410
|
+
engine.checkVersion("4.5.1");
|
|
2343
2411
|
await engine.pluginManager.register(e => {
|
|
2344
2412
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
2345
2413
|
});
|
|
2346
2414
|
}
|
|
2347
2415
|
|
|
2416
|
+
const ErrorCodes$1 = {
|
|
2417
|
+
baseMoverNotLoaded: "TSP-3203",
|
|
2418
|
+
};
|
|
2419
|
+
|
|
2420
|
+
const ErrorMessages$1 = {
|
|
2421
|
+
[ErrorCodes$1.baseMoverNotLoaded]: "tsParticles Base Mover is not loaded",
|
|
2422
|
+
};
|
|
2423
|
+
|
|
2348
2424
|
class MovePlugin {
|
|
2349
2425
|
id = "move";
|
|
2350
2426
|
#pluginManager;
|
|
@@ -2363,20 +2439,20 @@
|
|
|
2363
2439
|
}
|
|
2364
2440
|
|
|
2365
2441
|
async function loadMovePlugin(engine) {
|
|
2366
|
-
engine.checkVersion("4.
|
|
2442
|
+
engine.checkVersion("4.5.1");
|
|
2443
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
2444
|
+
addErrorMessages(ErrorMessages$1);
|
|
2445
|
+
}
|
|
2367
2446
|
await engine.pluginManager.register(e => {
|
|
2368
2447
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
2369
2448
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
2370
|
-
movePluginManager.pathGenerators ??= new Map();
|
|
2371
2449
|
movePluginManager.addPathGenerator = (name, generator) => {
|
|
2450
|
+
if (movePluginManager.initialized) {
|
|
2451
|
+
return;
|
|
2452
|
+
}
|
|
2372
2453
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
2373
2454
|
movePluginManager.initializers.pathGenerators.set(name, generator);
|
|
2374
2455
|
};
|
|
2375
|
-
movePluginManager.getPathGenerators = async (container, force = false) => {
|
|
2376
|
-
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
2377
|
-
movePluginManager.pathGenerators ??= new Map();
|
|
2378
|
-
return getItemMapFromInitializer(container, movePluginManager.pathGenerators, movePluginManager.initializers.pathGenerators, force);
|
|
2379
|
-
};
|
|
2380
2456
|
e.pluginManager.addPlugin(new MovePlugin(e.pluginManager));
|
|
2381
2457
|
});
|
|
2382
2458
|
}
|
|
@@ -2573,7 +2649,7 @@
|
|
|
2573
2649
|
}
|
|
2574
2650
|
|
|
2575
2651
|
async function loadOpacityUpdater(engine) {
|
|
2576
|
-
engine.checkVersion("4.
|
|
2652
|
+
engine.checkVersion("4.5.1");
|
|
2577
2653
|
await engine.pluginManager.register(e => {
|
|
2578
2654
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
2579
2655
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -2582,70 +2658,60 @@
|
|
|
2582
2658
|
}
|
|
2583
2659
|
|
|
2584
2660
|
const boundsMin = 0;
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
}
|
|
2618
|
-
}
|
|
2619
|
-
function
|
|
2620
|
-
if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
|
|
2621
|
-
(data.direction !== OutModeDirection.bottom && data.direction !== OutModeDirection.top)) {
|
|
2661
|
+
const bounceAxisConfigs = {
|
|
2662
|
+
[OutModeDirection.left]: {
|
|
2663
|
+
axis: "x",
|
|
2664
|
+
canvas: "width",
|
|
2665
|
+
bounce: "horizontal",
|
|
2666
|
+
negativeEdge: "right",
|
|
2667
|
+
positiveEdge: "left",
|
|
2668
|
+
negative: true,
|
|
2669
|
+
},
|
|
2670
|
+
[OutModeDirection.right]: {
|
|
2671
|
+
axis: "x",
|
|
2672
|
+
canvas: "width",
|
|
2673
|
+
bounce: "horizontal",
|
|
2674
|
+
negativeEdge: "right",
|
|
2675
|
+
positiveEdge: "left",
|
|
2676
|
+
negative: false,
|
|
2677
|
+
},
|
|
2678
|
+
[OutModeDirection.top]: {
|
|
2679
|
+
axis: "y",
|
|
2680
|
+
canvas: "height",
|
|
2681
|
+
bounce: "vertical",
|
|
2682
|
+
negativeEdge: "bottom",
|
|
2683
|
+
positiveEdge: "top",
|
|
2684
|
+
negative: true,
|
|
2685
|
+
},
|
|
2686
|
+
[OutModeDirection.bottom]: {
|
|
2687
|
+
axis: "y",
|
|
2688
|
+
canvas: "height",
|
|
2689
|
+
bounce: "vertical",
|
|
2690
|
+
negativeEdge: "bottom",
|
|
2691
|
+
positiveEdge: "top",
|
|
2692
|
+
negative: false,
|
|
2693
|
+
},
|
|
2694
|
+
};
|
|
2695
|
+
function bounce(data) {
|
|
2696
|
+
if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) || !(data.direction in bounceAxisConfigs)) {
|
|
2622
2697
|
return;
|
|
2623
2698
|
}
|
|
2624
|
-
|
|
2625
|
-
|
|
2699
|
+
const config = bounceAxisConfigs[data.direction], bounds = data.bounds, canvasDim = data.canvasSize[config.canvas], position = data.particle.position, velocity = data.particle.velocity[config.axis];
|
|
2700
|
+
if (config.negative && bounds[config.negativeEdge] < boundsMin) {
|
|
2701
|
+
position[config.axis] = data.size + data.offset[config.axis];
|
|
2626
2702
|
}
|
|
2627
|
-
else if (
|
|
2628
|
-
|
|
2703
|
+
else if (!config.negative && bounds[config.positiveEdge] > canvasDim) {
|
|
2704
|
+
position[config.axis] = canvasDim - data.size - data.offset[config.axis];
|
|
2629
2705
|
}
|
|
2630
|
-
const velocity = data.particle.velocity.y;
|
|
2631
|
-
let bounced = false;
|
|
2632
2706
|
if (data.outOfCanvas &&
|
|
2633
|
-
((
|
|
2634
|
-
|
|
2635
|
-
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
2636
|
-
data.particle.velocity.y *= -newVelocity;
|
|
2637
|
-
bounced = true;
|
|
2707
|
+
((config.negative && velocity < minVelocity) || (!config.negative && velocity > minVelocity))) {
|
|
2708
|
+
data.particle.velocity[config.axis] *= -getRangeValue(data.particle.options.bounce[config.bounce].value);
|
|
2638
2709
|
}
|
|
2639
|
-
|
|
2710
|
+
else {
|
|
2640
2711
|
return;
|
|
2641
2712
|
}
|
|
2642
|
-
const minPos = data.offset.
|
|
2643
|
-
|
|
2644
|
-
data.particle.position.y = data.canvasSize.height - minPos;
|
|
2645
|
-
}
|
|
2646
|
-
else if (data.outOfCanvas && data.direction === OutModeDirection.top) {
|
|
2647
|
-
data.particle.position.y = minPos;
|
|
2648
|
-
}
|
|
2713
|
+
const minPos = data.offset[config.axis] + data.size;
|
|
2714
|
+
position[config.axis] = config.negative ? minPos : canvasDim - minPos;
|
|
2649
2715
|
if (data.outMode === OutMode.split) {
|
|
2650
2716
|
data.particle.destroy();
|
|
2651
2717
|
}
|
|
@@ -2661,26 +2727,19 @@
|
|
|
2661
2727
|
OutMode.bounce,
|
|
2662
2728
|
OutMode.split,
|
|
2663
2729
|
];
|
|
2664
|
-
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce
|
|
2730
|
+
this.#particleBouncePlugins = container.plugins.filter(p => !!p.particleBounce);
|
|
2665
2731
|
}
|
|
2666
2732
|
update(particle, direction, delta, outMode) {
|
|
2667
2733
|
if (!this.modes.includes(outMode)) {
|
|
2668
2734
|
return;
|
|
2669
2735
|
}
|
|
2670
|
-
const container = this.#container;
|
|
2671
|
-
let handled = false;
|
|
2672
2736
|
for (const plugin of this.#particleBouncePlugins) {
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
break;
|
|
2737
|
+
if (plugin.particleBounce?.(particle, delta, direction)) {
|
|
2738
|
+
return;
|
|
2676
2739
|
}
|
|
2677
2740
|
}
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
}
|
|
2681
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
2682
|
-
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
2683
|
-
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
2741
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = this.#container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
2742
|
+
bounce({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
2684
2743
|
}
|
|
2685
2744
|
}
|
|
2686
2745
|
|
|
@@ -2769,107 +2828,108 @@
|
|
|
2769
2828
|
return;
|
|
2770
2829
|
}
|
|
2771
2830
|
const container = this.#container;
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
updateVector.addTo(particle.moveCenter);
|
|
2779
|
-
const { dx, dy } = getDistances(particle.position, updateVector);
|
|
2780
|
-
if ((vx <= minVelocity && dx >= minDistance) ||
|
|
2781
|
-
(vy <= minVelocity && dy >= minDistance) ||
|
|
2782
|
-
(vx >= minVelocity && dx <= minDistance) ||
|
|
2783
|
-
(vy >= minVelocity && dy <= minDistance)) {
|
|
2784
|
-
return;
|
|
2785
|
-
}
|
|
2786
|
-
particle.position.x = Math.floor(randomInRangeValue({
|
|
2787
|
-
min: 0,
|
|
2788
|
-
max: container.canvas.size.width,
|
|
2789
|
-
}));
|
|
2790
|
-
particle.position.y = Math.floor(randomInRangeValue({
|
|
2791
|
-
min: 0,
|
|
2792
|
-
max: container.canvas.size.height,
|
|
2793
|
-
}));
|
|
2794
|
-
const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
|
|
2795
|
-
particle.direction = Math.atan2(-newDy, -newDx);
|
|
2796
|
-
particle.velocity.angle = particle.direction;
|
|
2797
|
-
particle.justWarped = true;
|
|
2798
|
-
break;
|
|
2831
|
+
if (particle.outType === ParticleOutType.inside) {
|
|
2832
|
+
this.#applyOutModeInside(particle, container);
|
|
2833
|
+
}
|
|
2834
|
+
else {
|
|
2835
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
2836
|
+
return;
|
|
2799
2837
|
}
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
return;
|
|
2803
|
-
}
|
|
2804
|
-
switch (particle.outType) {
|
|
2805
|
-
case ParticleOutType.outside: {
|
|
2806
|
-
particle.position.x =
|
|
2807
|
-
Math.floor(randomInRangeValue({
|
|
2808
|
-
min: -particle.moveCenter.radius,
|
|
2809
|
-
max: particle.moveCenter.radius,
|
|
2810
|
-
})) + particle.moveCenter.x;
|
|
2811
|
-
particle.position.y =
|
|
2812
|
-
Math.floor(randomInRangeValue({
|
|
2813
|
-
min: -particle.moveCenter.radius,
|
|
2814
|
-
max: particle.moveCenter.radius,
|
|
2815
|
-
})) + particle.moveCenter.y;
|
|
2816
|
-
const { dx, dy } = getDistances(particle.position, particle.moveCenter);
|
|
2817
|
-
if (particle.moveCenter.radius) {
|
|
2818
|
-
particle.direction = Math.atan2(dy, dx);
|
|
2819
|
-
particle.velocity.angle = particle.direction;
|
|
2820
|
-
}
|
|
2821
|
-
particle.justWarped = true;
|
|
2822
|
-
break;
|
|
2823
|
-
}
|
|
2824
|
-
case ParticleOutType.normal: {
|
|
2825
|
-
const warp = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
|
|
2826
|
-
bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
|
|
2827
|
-
left: -particle.getRadius() - particle.offset.x,
|
|
2828
|
-
right: canvasSize.width + particle.getRadius() + particle.offset.x,
|
|
2829
|
-
top: -particle.getRadius() - particle.offset.y,
|
|
2830
|
-
}, sizeValue = particle.getRadius(), nextBounds = calculateBounds(particle.position, sizeValue);
|
|
2831
|
-
if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width + particle.offset.x) {
|
|
2832
|
-
particle.position.x = newPos.left;
|
|
2833
|
-
particle.initialPosition.x = particle.position.x;
|
|
2834
|
-
if (!warp) {
|
|
2835
|
-
particle.position.y = getRandom() * canvasSize.height;
|
|
2836
|
-
particle.initialPosition.y = particle.position.y;
|
|
2837
|
-
}
|
|
2838
|
-
particle.justWarped = true;
|
|
2839
|
-
}
|
|
2840
|
-
else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
|
|
2841
|
-
particle.position.x = newPos.right;
|
|
2842
|
-
particle.initialPosition.x = particle.position.x;
|
|
2843
|
-
if (!warp) {
|
|
2844
|
-
particle.position.y = getRandom() * canvasSize.height;
|
|
2845
|
-
particle.initialPosition.y = particle.position.y;
|
|
2846
|
-
}
|
|
2847
|
-
particle.justWarped = true;
|
|
2848
|
-
}
|
|
2849
|
-
if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height + particle.offset.y) {
|
|
2850
|
-
if (!warp) {
|
|
2851
|
-
particle.position.x = getRandom() * canvasSize.width;
|
|
2852
|
-
particle.initialPosition.x = particle.position.x;
|
|
2853
|
-
}
|
|
2854
|
-
particle.position.y = newPos.top;
|
|
2855
|
-
particle.initialPosition.y = particle.position.y;
|
|
2856
|
-
particle.justWarped = true;
|
|
2857
|
-
}
|
|
2858
|
-
else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
|
|
2859
|
-
if (!warp) {
|
|
2860
|
-
particle.position.x = getRandom() * canvasSize.width;
|
|
2861
|
-
particle.initialPosition.x = particle.position.x;
|
|
2862
|
-
}
|
|
2863
|
-
particle.position.y = newPos.bottom;
|
|
2864
|
-
particle.initialPosition.y = particle.position.y;
|
|
2865
|
-
particle.justWarped = true;
|
|
2866
|
-
}
|
|
2867
|
-
break;
|
|
2868
|
-
}
|
|
2869
|
-
}
|
|
2870
|
-
break;
|
|
2838
|
+
if (particle.outType === ParticleOutType.outside) {
|
|
2839
|
+
this.#applyParticleModeOutside(particle);
|
|
2871
2840
|
}
|
|
2872
|
-
|
|
2841
|
+
else {
|
|
2842
|
+
this.#applyOutModeNormal(particle, container, direction);
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
#applyOutModeInside(particle, container) {
|
|
2847
|
+
const { x: vx, y: vy } = particle.velocity;
|
|
2848
|
+
updateVector.setTo(originPoint);
|
|
2849
|
+
updateVector.length = particle.moveCenter.radius;
|
|
2850
|
+
updateVector.angle = particle.velocity.angle + Math.PI;
|
|
2851
|
+
updateVector.addTo(particle.moveCenter);
|
|
2852
|
+
const { dx, dy } = getDistances(particle.position, updateVector);
|
|
2853
|
+
if ((vx <= minVelocity && dx >= minDistance) ||
|
|
2854
|
+
(vy <= minVelocity && dy >= minDistance) ||
|
|
2855
|
+
(vx >= minVelocity && dx <= minDistance) ||
|
|
2856
|
+
(vy >= minVelocity && dy <= minDistance)) {
|
|
2857
|
+
return;
|
|
2858
|
+
}
|
|
2859
|
+
particle.position.x = Math.floor(randomInRangeValue({
|
|
2860
|
+
min: 0,
|
|
2861
|
+
max: container.canvas.size.width,
|
|
2862
|
+
}));
|
|
2863
|
+
particle.position.y = Math.floor(randomInRangeValue({
|
|
2864
|
+
min: 0,
|
|
2865
|
+
max: container.canvas.size.height,
|
|
2866
|
+
}));
|
|
2867
|
+
const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
|
|
2868
|
+
particle.direction = Math.atan2(-newDy, -newDx);
|
|
2869
|
+
particle.velocity.angle = particle.direction;
|
|
2870
|
+
particle.justWarped = true;
|
|
2871
|
+
}
|
|
2872
|
+
#applyOutModeNormal(particle, container, direction) {
|
|
2873
|
+
const warp = particle.options.move.warp, canvasSize = container.canvas.size, sizeValue = particle.getRadius(), newPos = {
|
|
2874
|
+
bottom: canvasSize.height + sizeValue + particle.offset.y,
|
|
2875
|
+
left: -sizeValue - particle.offset.x,
|
|
2876
|
+
right: canvasSize.width + sizeValue + particle.offset.x,
|
|
2877
|
+
top: -sizeValue - particle.offset.y,
|
|
2878
|
+
}, nextBounds = calculateBounds(particle.position, sizeValue);
|
|
2879
|
+
if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width + particle.offset.x) {
|
|
2880
|
+
particle.position.x = newPos.left;
|
|
2881
|
+
particle.initialPosition.x = particle.position.x;
|
|
2882
|
+
if (!warp) {
|
|
2883
|
+
particle.position.y = getRandom() * canvasSize.height;
|
|
2884
|
+
particle.initialPosition.y = particle.position.y;
|
|
2885
|
+
}
|
|
2886
|
+
particle.justWarped = true;
|
|
2887
|
+
}
|
|
2888
|
+
else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
|
|
2889
|
+
particle.position.x = newPos.right;
|
|
2890
|
+
particle.initialPosition.x = particle.position.x;
|
|
2891
|
+
if (!warp) {
|
|
2892
|
+
particle.position.y = getRandom() * canvasSize.height;
|
|
2893
|
+
particle.initialPosition.y = particle.position.y;
|
|
2894
|
+
}
|
|
2895
|
+
particle.justWarped = true;
|
|
2896
|
+
}
|
|
2897
|
+
if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height + particle.offset.y) {
|
|
2898
|
+
if (!warp) {
|
|
2899
|
+
particle.position.x = getRandom() * canvasSize.width;
|
|
2900
|
+
particle.initialPosition.x = particle.position.x;
|
|
2901
|
+
}
|
|
2902
|
+
particle.position.y = newPos.top;
|
|
2903
|
+
particle.initialPosition.y = particle.position.y;
|
|
2904
|
+
particle.justWarped = true;
|
|
2905
|
+
}
|
|
2906
|
+
else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
|
|
2907
|
+
if (!warp) {
|
|
2908
|
+
particle.position.x = getRandom() * canvasSize.width;
|
|
2909
|
+
particle.initialPosition.x = particle.position.x;
|
|
2910
|
+
}
|
|
2911
|
+
particle.position.y = newPos.bottom;
|
|
2912
|
+
particle.initialPosition.y = particle.position.y;
|
|
2913
|
+
particle.justWarped = true;
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
#applyParticleModeOutside(particle) {
|
|
2917
|
+
particle.position.x =
|
|
2918
|
+
Math.floor(randomInRangeValue({
|
|
2919
|
+
min: -particle.moveCenter.radius,
|
|
2920
|
+
max: particle.moveCenter.radius,
|
|
2921
|
+
})) + particle.moveCenter.x;
|
|
2922
|
+
particle.position.y =
|
|
2923
|
+
Math.floor(randomInRangeValue({
|
|
2924
|
+
min: -particle.moveCenter.radius,
|
|
2925
|
+
max: particle.moveCenter.radius,
|
|
2926
|
+
})) + particle.moveCenter.y;
|
|
2927
|
+
const { dx, dy } = getDistances(particle.position, particle.moveCenter);
|
|
2928
|
+
if (particle.moveCenter.radius) {
|
|
2929
|
+
particle.direction = Math.atan2(dy, dx);
|
|
2930
|
+
particle.velocity.angle = particle.direction;
|
|
2931
|
+
}
|
|
2932
|
+
particle.justWarped = true;
|
|
2873
2933
|
}
|
|
2874
2934
|
}
|
|
2875
2935
|
|
|
@@ -2918,7 +2978,7 @@
|
|
|
2918
2978
|
}
|
|
2919
2979
|
|
|
2920
2980
|
async function loadOutModesUpdater(engine) {
|
|
2921
|
-
engine.checkVersion("4.
|
|
2981
|
+
engine.checkVersion("4.5.1");
|
|
2922
2982
|
await engine.pluginManager.register(e => {
|
|
2923
2983
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
2924
2984
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
@@ -2935,39 +2995,9 @@
|
|
|
2935
2995
|
this.#pluginManager = pluginManager;
|
|
2936
2996
|
}
|
|
2937
2997
|
init(particle) {
|
|
2938
|
-
const container = this.#container, options = particle.options, paint = itemFromSingleOrMultiple(options.paint, particle.id, options.reduceDuplicates)
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
particle.fillEnabled = fill.enable;
|
|
2942
|
-
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
2943
|
-
particle.fillAnimation = fillColor.animation;
|
|
2944
|
-
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
2945
|
-
if (fillHslColor) {
|
|
2946
|
-
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
2947
|
-
}
|
|
2948
|
-
}
|
|
2949
|
-
else {
|
|
2950
|
-
particle.fillEnabled = false;
|
|
2951
|
-
particle.fillAnimation = undefined;
|
|
2952
|
-
particle.fillColor = undefined;
|
|
2953
|
-
particle.fillOpacity = defaultOpacity;
|
|
2954
|
-
}
|
|
2955
|
-
if (stroke) {
|
|
2956
|
-
const strokeColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), stroke.color);
|
|
2957
|
-
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
2958
|
-
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
2959
|
-
particle.strokeAnimation = strokeColor.animation;
|
|
2960
|
-
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
2961
|
-
if (strokeHslColor) {
|
|
2962
|
-
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
2963
|
-
}
|
|
2964
|
-
}
|
|
2965
|
-
else {
|
|
2966
|
-
particle.strokeAnimation = undefined;
|
|
2967
|
-
particle.strokeColor = undefined;
|
|
2968
|
-
particle.strokeOpacity = defaultOpacity;
|
|
2969
|
-
particle.strokeWidth = 0;
|
|
2970
|
-
}
|
|
2998
|
+
const container = this.#container, options = particle.options, paint = itemFromSingleOrMultiple(options.paint, particle.id, options.reduceDuplicates);
|
|
2999
|
+
this.#initFill(paint, particle, container);
|
|
3000
|
+
this.#initStroke(paint, particle, container);
|
|
2971
3001
|
}
|
|
2972
3002
|
isEnabled(particle) {
|
|
2973
3003
|
const { fillAnimation, fillColor, strokeAnimation, strokeColor } = particle, fillEnabled = !!fillAnimation &&
|
|
@@ -2986,10 +3016,48 @@
|
|
|
2986
3016
|
updateColor(particle.fillColor, delta, this.#container.hdr);
|
|
2987
3017
|
updateColor(particle.strokeColor, delta, this.#container.hdr);
|
|
2988
3018
|
}
|
|
3019
|
+
#initFill(paint, particle, container) {
|
|
3020
|
+
const fill = paint?.fill, color = paint?.color, paintColor = color ?? undefined;
|
|
3021
|
+
if (!fill) {
|
|
3022
|
+
particle.fillEnabled = false;
|
|
3023
|
+
particle.fillAnimation = undefined;
|
|
3024
|
+
particle.fillColor = undefined;
|
|
3025
|
+
particle.fillOpacity = defaultOpacity;
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
3028
|
+
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3029
|
+
particle.fillEnabled = fill.enable;
|
|
3030
|
+
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3031
|
+
particle.fillAnimation = fillColor.animation;
|
|
3032
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3033
|
+
if (!fillHslColor) {
|
|
3034
|
+
return;
|
|
3035
|
+
}
|
|
3036
|
+
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3037
|
+
}
|
|
3038
|
+
#initStroke(paint, particle, container) {
|
|
3039
|
+
const stroke = paint?.stroke, color = paint?.color, paintColor = color ?? undefined;
|
|
3040
|
+
if (!stroke) {
|
|
3041
|
+
particle.strokeAnimation = undefined;
|
|
3042
|
+
particle.strokeColor = undefined;
|
|
3043
|
+
particle.strokeOpacity = defaultOpacity;
|
|
3044
|
+
particle.strokeWidth = 0;
|
|
3045
|
+
return;
|
|
3046
|
+
}
|
|
3047
|
+
const strokeColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), stroke.color);
|
|
3048
|
+
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3049
|
+
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3050
|
+
particle.strokeAnimation = strokeColor.animation;
|
|
3051
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3052
|
+
if (!strokeHslColor) {
|
|
3053
|
+
return;
|
|
3054
|
+
}
|
|
3055
|
+
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3056
|
+
}
|
|
2989
3057
|
}
|
|
2990
3058
|
|
|
2991
3059
|
async function loadPaintUpdater(engine) {
|
|
2992
|
-
engine.checkVersion("4.
|
|
3060
|
+
engine.checkVersion("4.5.1");
|
|
2993
3061
|
await engine.pluginManager.register(e => {
|
|
2994
3062
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
2995
3063
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3031,7 +3099,7 @@
|
|
|
3031
3099
|
if (!this.accepts(input)) {
|
|
3032
3100
|
return;
|
|
3033
3101
|
}
|
|
3034
|
-
const result = rgbRegex.exec(input), radix = 10, minLength = 4
|
|
3102
|
+
const result = rgbRegex.exec(input), radix = 10, minLength = 4;
|
|
3035
3103
|
return result
|
|
3036
3104
|
? {
|
|
3037
3105
|
a: result.length > minLength ? parseAlpha(result[RgbIndexes.a]) : defaultAlpha,
|
|
@@ -3044,7 +3112,7 @@
|
|
|
3044
3112
|
}
|
|
3045
3113
|
|
|
3046
3114
|
async function loadRgbColorPlugin(engine) {
|
|
3047
|
-
engine.checkVersion("4.
|
|
3115
|
+
engine.checkVersion("4.5.1");
|
|
3048
3116
|
await engine.pluginManager.register(e => {
|
|
3049
3117
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3050
3118
|
});
|
|
@@ -3129,7 +3197,7 @@
|
|
|
3129
3197
|
}
|
|
3130
3198
|
|
|
3131
3199
|
async function loadSizeUpdater(engine) {
|
|
3132
|
-
engine.checkVersion("4.
|
|
3200
|
+
engine.checkVersion("4.5.1");
|
|
3133
3201
|
await engine.pluginManager.register(e => {
|
|
3134
3202
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3135
3203
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3138,7 +3206,7 @@
|
|
|
3138
3206
|
}
|
|
3139
3207
|
|
|
3140
3208
|
async function loadBasic(engine) {
|
|
3141
|
-
engine.checkVersion("4.
|
|
3209
|
+
engine.checkVersion("4.5.1");
|
|
3142
3210
|
await engine.pluginManager.register(async (e) => {
|
|
3143
3211
|
await Promise.all([
|
|
3144
3212
|
loadBlendPlugin(e),
|
|
@@ -3155,6 +3223,16 @@
|
|
|
3155
3223
|
});
|
|
3156
3224
|
}
|
|
3157
3225
|
|
|
3226
|
+
const ErrorCodes = {
|
|
3227
|
+
interactivityPluginNotLoaded: "TSP-3201",
|
|
3228
|
+
interactivityClickHandlerNotSet: "TSP-3202",
|
|
3229
|
+
};
|
|
3230
|
+
|
|
3231
|
+
const ErrorMessages = {
|
|
3232
|
+
[ErrorCodes.interactivityPluginNotLoaded]: "tsParticles Interactivity Plugin is not loaded",
|
|
3233
|
+
[ErrorCodes.interactivityClickHandlerNotSet]: "Click handlers can only be set after calling tsParticles.load()",
|
|
3234
|
+
};
|
|
3235
|
+
|
|
3158
3236
|
class ClickEvent {
|
|
3159
3237
|
enable = false;
|
|
3160
3238
|
mode = [];
|
|
@@ -3231,9 +3309,7 @@
|
|
|
3231
3309
|
|
|
3232
3310
|
class Modes {
|
|
3233
3311
|
#container;
|
|
3234
|
-
|
|
3235
|
-
constructor(pluginManager, container) {
|
|
3236
|
-
this.#pluginManager = pluginManager;
|
|
3312
|
+
constructor(container) {
|
|
3237
3313
|
this.#container = container;
|
|
3238
3314
|
}
|
|
3239
3315
|
load(data) {
|
|
@@ -3243,10 +3319,7 @@
|
|
|
3243
3319
|
if (!this.#container) {
|
|
3244
3320
|
return;
|
|
3245
3321
|
}
|
|
3246
|
-
const interactors = this.#
|
|
3247
|
-
if (!interactors) {
|
|
3248
|
-
return;
|
|
3249
|
-
}
|
|
3322
|
+
const interactors = this.#container.interactionManager?.interactors ?? [];
|
|
3250
3323
|
for (const interactor of interactors) {
|
|
3251
3324
|
if (!interactor.loadModeOptions) {
|
|
3252
3325
|
continue;
|
|
@@ -3260,8 +3333,8 @@
|
|
|
3260
3333
|
detectsOn = InteractivityDetect.window;
|
|
3261
3334
|
events = new Events();
|
|
3262
3335
|
modes;
|
|
3263
|
-
constructor(
|
|
3264
|
-
this.modes = new Modes(
|
|
3336
|
+
constructor(container) {
|
|
3337
|
+
this.modes = new Modes(container);
|
|
3265
3338
|
}
|
|
3266
3339
|
load(data) {
|
|
3267
3340
|
if (isNull(data)) {
|
|
@@ -3292,10 +3365,10 @@
|
|
|
3292
3365
|
}
|
|
3293
3366
|
let interactivityOptions = options.interactivity;
|
|
3294
3367
|
if (!interactivityOptions?.load) {
|
|
3295
|
-
options.interactivity = interactivityOptions = new Interactivity(
|
|
3368
|
+
options.interactivity = interactivityOptions = new Interactivity(container);
|
|
3296
3369
|
}
|
|
3297
3370
|
interactivityOptions.load(source?.interactivity);
|
|
3298
|
-
const interactors =
|
|
3371
|
+
const interactors = container.interactionManager?.interactors;
|
|
3299
3372
|
if (!interactors) {
|
|
3300
3373
|
return;
|
|
3301
3374
|
}
|
|
@@ -3309,7 +3382,7 @@
|
|
|
3309
3382
|
if (source?.interactivity) {
|
|
3310
3383
|
options.interactivity = deepExtend({}, source.interactivity);
|
|
3311
3384
|
}
|
|
3312
|
-
const interactors =
|
|
3385
|
+
const interactors = container.interactionManager?.interactors;
|
|
3313
3386
|
if (!interactors) {
|
|
3314
3387
|
return;
|
|
3315
3388
|
}
|
|
@@ -3339,25 +3412,25 @@
|
|
|
3339
3412
|
const clickEvent = "click", mouseDownEvent = "pointerdown", mouseUpEvent = "pointerup", mouseLeaveEvent = "pointerleave", mouseMoveEvent = "pointermove", touchStartEvent = "touchstart", touchEndEvent = "touchend", touchMoveEvent = "touchmove", touchCancelEvent = "touchcancel";
|
|
3340
3413
|
|
|
3341
3414
|
async function loadInteractivityPlugin(engine) {
|
|
3342
|
-
engine.checkVersion("4.
|
|
3415
|
+
engine.checkVersion("4.5.1");
|
|
3416
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
3417
|
+
addErrorMessages(ErrorMessages);
|
|
3418
|
+
}
|
|
3343
3419
|
await engine.pluginManager.register(e => {
|
|
3344
3420
|
const interactivityEngine = e, interactivityPluginManager = interactivityEngine.pluginManager;
|
|
3345
3421
|
interactivityPluginManager.addPlugin(new InteractivityPlugin(interactivityPluginManager));
|
|
3346
3422
|
interactivityPluginManager.initializers.interactors ??= new Map();
|
|
3347
|
-
interactivityPluginManager.interactors ??= new Map();
|
|
3348
3423
|
interactivityPluginManager.addInteractor = (name, interactorInitializer) => {
|
|
3424
|
+
if (interactivityPluginManager.initialized) {
|
|
3425
|
+
return;
|
|
3426
|
+
}
|
|
3349
3427
|
interactivityPluginManager.initializers.interactors ??= new Map();
|
|
3350
3428
|
interactivityPluginManager.initializers.interactors.set(name, interactorInitializer);
|
|
3351
3429
|
};
|
|
3352
|
-
interactivityPluginManager.getInteractors = async (container, force = false) => {
|
|
3353
|
-
interactivityPluginManager.interactors ??= new Map();
|
|
3354
|
-
interactivityPluginManager.initializers.interactors ??= new Map();
|
|
3355
|
-
return getItemsFromInitializer(container, interactivityPluginManager.interactors, interactivityPluginManager.initializers.interactors, force);
|
|
3356
|
-
};
|
|
3357
3430
|
interactivityPluginManager.setOnClickHandler = (callback) => {
|
|
3358
3431
|
const { items } = interactivityEngine;
|
|
3359
3432
|
if (!items.length) {
|
|
3360
|
-
throw new Error(
|
|
3433
|
+
throw new Error(getErrorMessage(ErrorCodes.interactivityClickHandlerNotSet));
|
|
3361
3434
|
}
|
|
3362
3435
|
items.forEach(item => {
|
|
3363
3436
|
const interactivityContainer = item;
|
|
@@ -3368,7 +3441,7 @@
|
|
|
3368
3441
|
}
|
|
3369
3442
|
function ensureInteractivityPluginLoaded(e) {
|
|
3370
3443
|
if (!e.pluginManager.addInteractor) {
|
|
3371
|
-
throw new Error(
|
|
3444
|
+
throw new Error(getErrorMessage(ErrorCodes.interactivityPluginNotLoaded));
|
|
3372
3445
|
}
|
|
3373
3446
|
}
|
|
3374
3447
|
|
|
@@ -3536,7 +3609,7 @@
|
|
|
3536
3609
|
}
|
|
3537
3610
|
|
|
3538
3611
|
async function loadExternalTrailInteraction(engine) {
|
|
3539
|
-
engine.checkVersion("4.
|
|
3612
|
+
engine.checkVersion("4.5.1");
|
|
3540
3613
|
await engine.pluginManager.register((e) => {
|
|
3541
3614
|
ensureInteractivityPluginLoaded(e);
|
|
3542
3615
|
e.pluginManager.addInteractor?.("externalTrail", container => {
|
|
@@ -3620,7 +3693,7 @@
|
|
|
3620
3693
|
particle.destroy();
|
|
3621
3694
|
return;
|
|
3622
3695
|
}
|
|
3623
|
-
const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.
|
|
3696
|
+
const widthRange = setRangeValue(minCanvasSize, canvasSize.width), heightRange = setRangeValue(minCanvasSize, canvasSize.height);
|
|
3624
3697
|
particle.position.x = randomInRangeValue(widthRange);
|
|
3625
3698
|
particle.position.y = randomInRangeValue(heightRange);
|
|
3626
3699
|
particle.spawning = true;
|
|
@@ -3682,7 +3755,7 @@
|
|
|
3682
3755
|
}
|
|
3683
3756
|
|
|
3684
3757
|
async function loadLifeUpdater(engine) {
|
|
3685
|
-
engine.checkVersion("4.
|
|
3758
|
+
engine.checkVersion("4.5.1");
|
|
3686
3759
|
await engine.pluginManager.register(e => {
|
|
3687
3760
|
e.pluginManager.addParticleUpdater("life", container => {
|
|
3688
3761
|
return Promise.resolve(new LifeUpdater(container));
|
|
@@ -3836,21 +3909,28 @@
|
|
|
3836
3909
|
});
|
|
3837
3910
|
}
|
|
3838
3911
|
clear() {
|
|
3912
|
+
const visited = new Set();
|
|
3839
3913
|
for (const plugin of this.#canvasClearPlugins) {
|
|
3914
|
+
visited.add(plugin);
|
|
3840
3915
|
if (plugin.canvasClear?.() ?? false) {
|
|
3841
|
-
return;
|
|
3916
|
+
return plugin;
|
|
3842
3917
|
}
|
|
3843
3918
|
}
|
|
3844
3919
|
for (const layer of Object.values(DrawLayer)) {
|
|
3845
3920
|
if (typeof layer === "number") {
|
|
3846
3921
|
for (const plugin of this.#getLayerPlugins(layer)) {
|
|
3922
|
+
if (visited.has(plugin)) {
|
|
3923
|
+
continue;
|
|
3924
|
+
}
|
|
3925
|
+
visited.add(plugin);
|
|
3847
3926
|
if (plugin.canvasClear?.() ?? false) {
|
|
3848
|
-
return;
|
|
3927
|
+
return plugin;
|
|
3849
3928
|
}
|
|
3850
3929
|
}
|
|
3851
3930
|
}
|
|
3852
3931
|
}
|
|
3853
3932
|
this.canvasClear();
|
|
3933
|
+
return undefined;
|
|
3854
3934
|
}
|
|
3855
3935
|
destroy() {
|
|
3856
3936
|
this.stop();
|
|
@@ -3928,8 +4008,7 @@
|
|
|
3928
4008
|
});
|
|
3929
4009
|
}
|
|
3930
4010
|
drawParticles(delta) {
|
|
3931
|
-
const { particles, actualOptions } = this.#container;
|
|
3932
|
-
this.clear();
|
|
4011
|
+
const { particles, actualOptions } = this.#container, clearedPlugin = this.clear();
|
|
3933
4012
|
particles.update(delta);
|
|
3934
4013
|
this.draw(ctx => {
|
|
3935
4014
|
const width = this.#canvasManager.size.width, height = this.#canvasManager.size.height;
|
|
@@ -3951,7 +4030,9 @@
|
|
|
3951
4030
|
}
|
|
3952
4031
|
}
|
|
3953
4032
|
for (const plugin of this.#getLayerPlugins(DrawLayer.BackgroundMask)) {
|
|
3954
|
-
plugin
|
|
4033
|
+
if (plugin !== clearedPlugin) {
|
|
4034
|
+
plugin.canvasPaint?.();
|
|
4035
|
+
}
|
|
3955
4036
|
}
|
|
3956
4037
|
for (const plugin of this.#getLayerPlugins(DrawLayer.CanvasSetup)) {
|
|
3957
4038
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
@@ -3965,53 +4046,25 @@
|
|
|
3965
4046
|
plugin.drawSettingsCleanup?.(ctx, delta);
|
|
3966
4047
|
}
|
|
3967
4048
|
});
|
|
3968
|
-
}
|
|
3969
|
-
init() {
|
|
3970
|
-
this.initUpdaters();
|
|
3971
|
-
this.initPlugins();
|
|
3972
|
-
this.#resolveBackgroundElement();
|
|
3973
|
-
this.paint();
|
|
3974
|
-
}
|
|
3975
|
-
initPlugins() {
|
|
3976
|
-
this.#canvasClearPlugins = [];
|
|
3977
|
-
this.#colorPlugins = [];
|
|
3978
|
-
this.#drawParticlePlugins = [];
|
|
3979
|
-
this.#drawParticlesSetupPlugins = [];
|
|
3980
|
-
this.#drawParticlesCleanupPlugins = [];
|
|
3981
|
-
for (const layer of Object.values(DrawLayer)) {
|
|
3982
|
-
if (typeof layer === "number") {
|
|
3983
|
-
this.#layers[layer] = [];
|
|
3984
|
-
}
|
|
3985
|
-
}
|
|
3986
|
-
for (const plugin of this.#container.plugins) {
|
|
3987
|
-
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
3988
|
-
this.#colorPlugins.push(plugin);
|
|
3989
|
-
}
|
|
3990
|
-
if (plugin.drawParticle) {
|
|
3991
|
-
this.#drawParticlePlugins.push(plugin);
|
|
3992
|
-
}
|
|
3993
|
-
if (plugin.drawParticleSetup) {
|
|
3994
|
-
this.#drawParticlesSetupPlugins.push(plugin);
|
|
3995
|
-
}
|
|
3996
|
-
if (plugin.drawParticleCleanup) {
|
|
3997
|
-
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
3998
|
-
}
|
|
3999
|
-
if (plugin.canvasClear) {
|
|
4000
|
-
this.#canvasClearPlugins.push(plugin);
|
|
4001
|
-
}
|
|
4002
|
-
if (plugin.canvasPaint) {
|
|
4003
|
-
this.#getLayerPlugins(DrawLayer.BackgroundMask).push(plugin);
|
|
4004
|
-
}
|
|
4005
|
-
if (plugin.drawSettingsSetup) {
|
|
4006
|
-
this.#getLayerPlugins(DrawLayer.CanvasSetup).push(plugin);
|
|
4007
|
-
}
|
|
4008
|
-
if (plugin.draw) {
|
|
4009
|
-
this.#getLayerPlugins(DrawLayer.PluginContent).push(plugin);
|
|
4010
|
-
}
|
|
4011
|
-
if (plugin.clearDraw ?? plugin.drawSettingsCleanup) {
|
|
4012
|
-
this.#getLayerPlugins(DrawLayer.CanvasCleanup).push(plugin);
|
|
4049
|
+
}
|
|
4050
|
+
init() {
|
|
4051
|
+
this.initUpdaters();
|
|
4052
|
+
this.initPlugins();
|
|
4053
|
+
this.#resolveBackgroundElement();
|
|
4054
|
+
this.paint();
|
|
4055
|
+
}
|
|
4056
|
+
initPlugins() {
|
|
4057
|
+
this.#canvasClearPlugins = [];
|
|
4058
|
+
this.#colorPlugins = [];
|
|
4059
|
+
this.#drawParticlePlugins = [];
|
|
4060
|
+
this.#drawParticlesSetupPlugins = [];
|
|
4061
|
+
this.#drawParticlesCleanupPlugins = [];
|
|
4062
|
+
for (const layer of Object.values(DrawLayer)) {
|
|
4063
|
+
if (typeof layer === "number") {
|
|
4064
|
+
this.#layers[layer] = [];
|
|
4013
4065
|
}
|
|
4014
4066
|
}
|
|
4067
|
+
this.#initPluginsArray();
|
|
4015
4068
|
}
|
|
4016
4069
|
initUpdaters() {
|
|
4017
4070
|
this.#preDrawUpdaters = [];
|
|
@@ -4220,6 +4273,45 @@
|
|
|
4220
4273
|
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
4221
4274
|
return this.#reusablePluginColors;
|
|
4222
4275
|
}
|
|
4276
|
+
#initLayerPlugin(plugin) {
|
|
4277
|
+
const layerMap = [
|
|
4278
|
+
[DrawLayer.BackgroundMask, !!plugin.canvasPaint],
|
|
4279
|
+
[DrawLayer.CanvasSetup, !!plugin.drawSettingsSetup],
|
|
4280
|
+
[DrawLayer.PluginContent, !!plugin.draw],
|
|
4281
|
+
[DrawLayer.CanvasCleanup, !!(plugin.clearDraw ?? plugin.drawSettingsCleanup)],
|
|
4282
|
+
];
|
|
4283
|
+
for (const [layer, active] of layerMap) {
|
|
4284
|
+
if (active) {
|
|
4285
|
+
this.#layers[layer].push(plugin);
|
|
4286
|
+
}
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
#initPluginsArray() {
|
|
4290
|
+
for (const plugin of this.#container.plugins) {
|
|
4291
|
+
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
4292
|
+
this.#colorPlugins.push(plugin);
|
|
4293
|
+
}
|
|
4294
|
+
if (plugin.drawParticle) {
|
|
4295
|
+
this.#drawParticlePlugins.push(plugin);
|
|
4296
|
+
}
|
|
4297
|
+
if (plugin.drawParticleSetup) {
|
|
4298
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
4299
|
+
}
|
|
4300
|
+
if (plugin.drawParticleCleanup) {
|
|
4301
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
4302
|
+
}
|
|
4303
|
+
if (plugin.canvasClear) {
|
|
4304
|
+
this.#canvasClearPlugins.push(plugin);
|
|
4305
|
+
}
|
|
4306
|
+
this.#initLayerPlugin(plugin);
|
|
4307
|
+
}
|
|
4308
|
+
}
|
|
4309
|
+
#isSupportedElement(element) {
|
|
4310
|
+
return ((typeof HTMLCanvasElement !== "undefined" && element instanceof HTMLCanvasElement) ||
|
|
4311
|
+
(typeof OffscreenCanvas !== "undefined" && element instanceof OffscreenCanvas) ||
|
|
4312
|
+
(typeof HTMLVideoElement !== "undefined" && element instanceof HTMLVideoElement) ||
|
|
4313
|
+
(typeof HTMLImageElement !== "undefined" && element instanceof HTMLImageElement));
|
|
4314
|
+
}
|
|
4223
4315
|
#resolveBackgroundElement() {
|
|
4224
4316
|
const background = this.#container.actualOptions.background;
|
|
4225
4317
|
this.#backgroundElement = null;
|
|
@@ -4229,9 +4321,7 @@
|
|
|
4229
4321
|
if (typeof background.element === "string") {
|
|
4230
4322
|
if (typeof document !== "undefined") {
|
|
4231
4323
|
const node = document.querySelector(background.element);
|
|
4232
|
-
if (
|
|
4233
|
-
(typeof HTMLVideoElement !== "undefined" && node instanceof HTMLVideoElement) ||
|
|
4234
|
-
(typeof HTMLImageElement !== "undefined" && node instanceof HTMLImageElement)) {
|
|
4324
|
+
if (node && this.#isSupportedElement(node)) {
|
|
4235
4325
|
this.#backgroundElement = node;
|
|
4236
4326
|
}
|
|
4237
4327
|
else if (node) {
|
|
@@ -4242,10 +4332,7 @@
|
|
|
4242
4332
|
}
|
|
4243
4333
|
}
|
|
4244
4334
|
}
|
|
4245
|
-
else if ((
|
|
4246
|
-
(typeof OffscreenCanvas !== "undefined" && background.element instanceof OffscreenCanvas) ||
|
|
4247
|
-
(typeof HTMLVideoElement !== "undefined" && background.element instanceof HTMLVideoElement) ||
|
|
4248
|
-
(typeof HTMLImageElement !== "undefined" && background.element instanceof HTMLImageElement)) {
|
|
4335
|
+
else if (this.#isSupportedElement(background.element)) {
|
|
4249
4336
|
this.#backgroundElement = background.element;
|
|
4250
4337
|
}
|
|
4251
4338
|
}
|
|
@@ -4263,7 +4350,7 @@
|
|
|
4263
4350
|
return transferredCanvas;
|
|
4264
4351
|
}
|
|
4265
4352
|
if (typeof canvas.transferControlToOffscreen !== "function") {
|
|
4266
|
-
throw new TypeError(
|
|
4353
|
+
throw new TypeError(getErrorMessage(ErrorCodes$2.offscreenCanvasUnsupported));
|
|
4267
4354
|
}
|
|
4268
4355
|
try {
|
|
4269
4356
|
const offscreenCanvas = canvas.transferControlToOffscreen();
|
|
@@ -4271,10 +4358,16 @@
|
|
|
4271
4358
|
return offscreenCanvas;
|
|
4272
4359
|
}
|
|
4273
4360
|
catch {
|
|
4274
|
-
throw new TypeError(
|
|
4361
|
+
throw new TypeError(getErrorMessage(ErrorCodes$2.offscreenCanvasTransferFailed));
|
|
4275
4362
|
}
|
|
4276
4363
|
}, isHtmlCanvasElement = (canvas) => {
|
|
4277
4364
|
return typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement;
|
|
4365
|
+
}, getEffectiveColorSpace = (context) => {
|
|
4366
|
+
if (!context) {
|
|
4367
|
+
return undefined;
|
|
4368
|
+
}
|
|
4369
|
+
const colorInfo = context;
|
|
4370
|
+
return colorInfo.getContextAttributes?.().colorSpace ?? undefined;
|
|
4278
4371
|
};
|
|
4279
4372
|
function setStyle(canvas, style, important = false) {
|
|
4280
4373
|
if (!style) {
|
|
@@ -4399,7 +4492,7 @@
|
|
|
4399
4492
|
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
4400
4493
|
if (color) {
|
|
4401
4494
|
const hdrOptions = container.actualOptions.hdr;
|
|
4402
|
-
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, hdrOptions.mode);
|
|
4495
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard));
|
|
4403
4496
|
}
|
|
4404
4497
|
else {
|
|
4405
4498
|
elementStyle.backgroundColor = "";
|
|
@@ -4519,11 +4612,11 @@
|
|
|
4519
4612
|
const container = this.#container, canSupportHdr = container.actualOptions.hdr.enable &&
|
|
4520
4613
|
safeMatchMedia("(color-gamut: p3)")?.matches &&
|
|
4521
4614
|
safeMatchMedia("(dynamic-range: high)")?.matches;
|
|
4522
|
-
container.
|
|
4523
|
-
container.hdrMode = container.actualOptions.hdr.mode;
|
|
4615
|
+
container.hdrMode = toEnumValue(HdrMode, container.actualOptions.hdr.mode, HdrMode.standard);
|
|
4524
4616
|
container.peakNits = container.actualOptions.hdr.peakNits;
|
|
4525
4617
|
const renderCanvas = this.renderCanvas;
|
|
4526
4618
|
if (!renderCanvas) {
|
|
4619
|
+
container.hdr = canSupportHdr ?? false;
|
|
4527
4620
|
return;
|
|
4528
4621
|
}
|
|
4529
4622
|
this.render.setContextSettings({
|
|
@@ -4542,7 +4635,6 @@
|
|
|
4542
4635
|
context = null;
|
|
4543
4636
|
}
|
|
4544
4637
|
if (canSupportHdr && !context) {
|
|
4545
|
-
container.hdr = false;
|
|
4546
4638
|
const sdrSettings = {
|
|
4547
4639
|
alpha: true,
|
|
4548
4640
|
desynchronized: true,
|
|
@@ -4558,11 +4650,16 @@
|
|
|
4558
4650
|
}
|
|
4559
4651
|
}
|
|
4560
4652
|
this.render.setContext(context);
|
|
4653
|
+
if (context) {
|
|
4654
|
+
const effectiveColorSpace = getEffectiveColorSpace(context);
|
|
4655
|
+
if (effectiveColorSpace !== undefined) {
|
|
4656
|
+
container.hdr = effectiveColorSpace === "display-p3";
|
|
4657
|
+
}
|
|
4658
|
+
}
|
|
4561
4659
|
}
|
|
4562
4660
|
#initHdrListeners() {
|
|
4563
4661
|
this.#removeHdrListeners();
|
|
4564
4662
|
const p3Query = safeMatchMedia("(color-gamut: p3)"), hdrQuery = safeMatchMedia("(dynamic-range: high)"), handleChange = () => {
|
|
4565
|
-
this.#recreateRenderCanvas();
|
|
4566
4663
|
this.#initContext();
|
|
4567
4664
|
this.initBackground();
|
|
4568
4665
|
}, listeners = [];
|
|
@@ -4598,16 +4695,6 @@
|
|
|
4598
4695
|
element.style.setProperty(key, value, "important");
|
|
4599
4696
|
}
|
|
4600
4697
|
}
|
|
4601
|
-
#recreateRenderCanvas() {
|
|
4602
|
-
const renderCanvas = this.renderCanvas;
|
|
4603
|
-
if (!renderCanvas) {
|
|
4604
|
-
return;
|
|
4605
|
-
}
|
|
4606
|
-
if (this.domElement) {
|
|
4607
|
-
return;
|
|
4608
|
-
}
|
|
4609
|
-
this.renderCanvas = new OffscreenCanvas(renderCanvas.width, renderCanvas.height);
|
|
4610
|
-
}
|
|
4611
4698
|
#removeHdrListeners() {
|
|
4612
4699
|
if (!this.#hdrMediaListeners) {
|
|
4613
4700
|
return;
|
|
@@ -4679,6 +4766,10 @@
|
|
|
4679
4766
|
this.#manageListeners(true);
|
|
4680
4767
|
}
|
|
4681
4768
|
removeListeners() {
|
|
4769
|
+
if (this.#resizeTimeout !== undefined) {
|
|
4770
|
+
clearTimeout(this.#resizeTimeout);
|
|
4771
|
+
this.#resizeTimeout = undefined;
|
|
4772
|
+
}
|
|
4682
4773
|
this.#manageListeners(false);
|
|
4683
4774
|
}
|
|
4684
4775
|
#handleVisibilityChange() {
|
|
@@ -4706,8 +4797,7 @@
|
|
|
4706
4797
|
this.#resizeTimeout = undefined;
|
|
4707
4798
|
}
|
|
4708
4799
|
const handleResize = async () => {
|
|
4709
|
-
|
|
4710
|
-
await canvas.windowResize();
|
|
4800
|
+
await this.#container.canvas.windowResize();
|
|
4711
4801
|
};
|
|
4712
4802
|
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
4713
4803
|
}
|
|
@@ -4735,8 +4825,8 @@
|
|
|
4735
4825
|
}
|
|
4736
4826
|
else if (!this.#resizeObserver && add && canvasEl) {
|
|
4737
4827
|
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
4738
|
-
const
|
|
4739
|
-
if (!
|
|
4828
|
+
const res = entries.some(e => e.target === canvasEl);
|
|
4829
|
+
if (!res) {
|
|
4740
4830
|
return;
|
|
4741
4831
|
}
|
|
4742
4832
|
this.#handleWindowResize();
|
|
@@ -5000,10 +5090,10 @@
|
|
|
5000
5090
|
return this.#modifiers.find(m => m.id === id);
|
|
5001
5091
|
}
|
|
5002
5092
|
getOpacity() {
|
|
5003
|
-
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, baseOpacity = getRangeValue(this.opacity?.value ?? defaultOpacity$1), modifierOpacity = this.#applyModifiers(undefined, m => m.opacity), opacity = modifierOpacity ?? baseOpacity
|
|
5004
|
-
this.#cachedOpacityData.fillOpacity = fillOpacity;
|
|
5093
|
+
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, baseOpacity = getRangeValue(this.opacity?.value ?? defaultOpacity$1), modifierOpacity = this.#applyModifiers(undefined, m => m.opacity), opacity = modifierOpacity ?? baseOpacity;
|
|
5094
|
+
this.#cachedOpacityData.fillOpacity = this.fillOpacity ?? defaultOpacity$1;
|
|
5005
5095
|
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
5006
|
-
this.#cachedOpacityData.strokeOpacity = strokeOpacity;
|
|
5096
|
+
this.#cachedOpacityData.strokeOpacity = this.strokeOpacity ?? defaultOpacity$1;
|
|
5007
5097
|
return this.#cachedOpacityData;
|
|
5008
5098
|
}
|
|
5009
5099
|
getPosition() {
|
|
@@ -5250,7 +5340,7 @@
|
|
|
5250
5340
|
#initPosition(position) {
|
|
5251
5341
|
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
5252
5342
|
if (!initialPosition) {
|
|
5253
|
-
throw new Error(
|
|
5343
|
+
throw new Error(getErrorMessage(ErrorCodes$2.particlePositionNotFound));
|
|
5254
5344
|
}
|
|
5255
5345
|
this.position = initialPosition;
|
|
5256
5346
|
this.initialPosition = this.position.copy();
|
|
@@ -5299,6 +5389,12 @@
|
|
|
5299
5389
|
this.#circlePoolIdx = 0;
|
|
5300
5390
|
this.#rectanglePoolIdx = 0;
|
|
5301
5391
|
}
|
|
5392
|
+
get cellSize() {
|
|
5393
|
+
return this.#cellSize;
|
|
5394
|
+
}
|
|
5395
|
+
set cellSize(value) {
|
|
5396
|
+
this.#pendingCellSize = value;
|
|
5397
|
+
}
|
|
5302
5398
|
clear() {
|
|
5303
5399
|
this.#cells.clear();
|
|
5304
5400
|
const pendingCellSize = this.#pendingCellSize;
|
|
@@ -5322,40 +5418,46 @@
|
|
|
5322
5418
|
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);
|
|
5323
5419
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
5324
5420
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
5325
|
-
|
|
5326
|
-
if (!cellParticles) {
|
|
5327
|
-
continue;
|
|
5328
|
-
}
|
|
5329
|
-
for (const p of cellParticles) {
|
|
5330
|
-
if (check && !check(p)) {
|
|
5331
|
-
continue;
|
|
5332
|
-
}
|
|
5333
|
-
if (range.contains(p.getPosition())) {
|
|
5334
|
-
out.push(p);
|
|
5335
|
-
}
|
|
5336
|
-
}
|
|
5421
|
+
this.#queryCell(cx, cy, range, check, out);
|
|
5337
5422
|
}
|
|
5338
5423
|
}
|
|
5339
5424
|
return out;
|
|
5340
5425
|
}
|
|
5341
5426
|
queryCircle(position, radius, check, out = []) {
|
|
5342
|
-
const circle = this.#acquireCircle(position.x, position.y, radius)
|
|
5343
|
-
|
|
5344
|
-
|
|
5427
|
+
const circle = this.#acquireCircle(position.x, position.y, radius);
|
|
5428
|
+
try {
|
|
5429
|
+
return this.query(circle, check, out);
|
|
5430
|
+
}
|
|
5431
|
+
finally {
|
|
5432
|
+
this.#circlePoolIdx--;
|
|
5433
|
+
}
|
|
5345
5434
|
}
|
|
5346
5435
|
queryRectangle(position, size, check, out = []) {
|
|
5347
|
-
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height)
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5436
|
+
const rect = this.#acquireRectangle(position.x, position.y, size.width, size.height);
|
|
5437
|
+
try {
|
|
5438
|
+
return this.query(rect, check, out);
|
|
5439
|
+
}
|
|
5440
|
+
finally {
|
|
5441
|
+
this.#rectanglePoolIdx--;
|
|
5442
|
+
}
|
|
5353
5443
|
}
|
|
5354
5444
|
#acquireCircle(x, y, r) {
|
|
5355
|
-
|
|
5445
|
+
const idx = this.#circlePoolIdx++;
|
|
5446
|
+
let circle = this.#circlePool[idx];
|
|
5447
|
+
if (!circle) {
|
|
5448
|
+
circle = new Circle(x, y, r);
|
|
5449
|
+
this.#circlePool[idx] = circle;
|
|
5450
|
+
}
|
|
5451
|
+
return circle.reset(x, y, r);
|
|
5356
5452
|
}
|
|
5357
5453
|
#acquireRectangle(x, y, w, h) {
|
|
5358
|
-
|
|
5454
|
+
const idx = this.#rectanglePoolIdx++;
|
|
5455
|
+
let rectangle = this.#rectanglePool[idx];
|
|
5456
|
+
if (!rectangle) {
|
|
5457
|
+
rectangle = new Rectangle(x, y, w, h);
|
|
5458
|
+
this.#rectanglePool[idx] = rectangle;
|
|
5459
|
+
}
|
|
5460
|
+
return rectangle.reset(x, y, w, h);
|
|
5359
5461
|
}
|
|
5360
5462
|
#cellKeyFromCoords(x, y) {
|
|
5361
5463
|
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
@@ -5382,17 +5484,27 @@
|
|
|
5382
5484
|
}
|
|
5383
5485
|
return null;
|
|
5384
5486
|
}
|
|
5385
|
-
#
|
|
5386
|
-
|
|
5387
|
-
|
|
5487
|
+
#queryCell(cx, cy, range, check, out) {
|
|
5488
|
+
const cellParticles = this.#cells.get(`${cx}_${cy}`);
|
|
5489
|
+
if (!cellParticles) {
|
|
5490
|
+
return;
|
|
5491
|
+
}
|
|
5492
|
+
for (const p of cellParticles) {
|
|
5493
|
+
if (check && !check(p)) {
|
|
5494
|
+
continue;
|
|
5495
|
+
}
|
|
5496
|
+
if (range.contains(p.getPosition())) {
|
|
5497
|
+
out.push(p);
|
|
5498
|
+
}
|
|
5499
|
+
}
|
|
5388
5500
|
}
|
|
5389
5501
|
}
|
|
5390
5502
|
|
|
5391
5503
|
class ParticlesManager {
|
|
5392
5504
|
checkParticlePositionPlugins;
|
|
5393
|
-
grid;
|
|
5394
5505
|
#array;
|
|
5395
5506
|
#container;
|
|
5507
|
+
#grid;
|
|
5396
5508
|
#groupLimits;
|
|
5397
5509
|
#limit;
|
|
5398
5510
|
#nextId;
|
|
@@ -5416,7 +5528,7 @@
|
|
|
5416
5528
|
this.#groupLimits = new Map();
|
|
5417
5529
|
this.#particleBuckets = new Map();
|
|
5418
5530
|
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
5419
|
-
this
|
|
5531
|
+
this.#grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
5420
5532
|
this.checkParticlePositionPlugins = [];
|
|
5421
5533
|
this.#particleResetPlugins = [];
|
|
5422
5534
|
this.#particleUpdatePlugins = [];
|
|
@@ -5427,23 +5539,12 @@
|
|
|
5427
5539
|
get count() {
|
|
5428
5540
|
return this.#array.length;
|
|
5429
5541
|
}
|
|
5542
|
+
get grid() {
|
|
5543
|
+
return this.#grid;
|
|
5544
|
+
}
|
|
5430
5545
|
addParticle(position, overrideOptions, group, initializer) {
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
switch (limitMode) {
|
|
5434
|
-
case LimitMode.delete: {
|
|
5435
|
-
const countToRemove = currentCount + countOffset - limit;
|
|
5436
|
-
if (countToRemove > minCount) {
|
|
5437
|
-
this.removeQuantity(countToRemove);
|
|
5438
|
-
}
|
|
5439
|
-
break;
|
|
5440
|
-
}
|
|
5441
|
-
case LimitMode.wait:
|
|
5442
|
-
if (currentCount >= limit) {
|
|
5443
|
-
return;
|
|
5444
|
-
}
|
|
5445
|
-
break;
|
|
5446
|
-
}
|
|
5546
|
+
if (this.#checkAndApplyLimits(group, this.count)) {
|
|
5547
|
+
return;
|
|
5447
5548
|
}
|
|
5448
5549
|
try {
|
|
5449
5550
|
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
@@ -5507,7 +5608,7 @@
|
|
|
5507
5608
|
return this.#array[index];
|
|
5508
5609
|
}
|
|
5509
5610
|
async init() {
|
|
5510
|
-
const container = this.#container
|
|
5611
|
+
const container = this.#container;
|
|
5511
5612
|
this.checkParticlePositionPlugins = [];
|
|
5512
5613
|
this.#updatePlugins = [];
|
|
5513
5614
|
this.#particleUpdatePlugins = [];
|
|
@@ -5516,59 +5617,16 @@
|
|
|
5516
5617
|
this.#postParticleUpdatePlugins = [];
|
|
5517
5618
|
this.#particleBuckets.clear();
|
|
5518
5619
|
this.#resetBuckets(container.zLayers);
|
|
5519
|
-
this
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
if (
|
|
5525
|
-
this
|
|
5526
|
-
}
|
|
5527
|
-
if (plugin.update) {
|
|
5528
|
-
this.#updatePlugins.push(plugin);
|
|
5529
|
-
}
|
|
5530
|
-
if (plugin.particleUpdate) {
|
|
5531
|
-
this.#particleUpdatePlugins.push(plugin);
|
|
5532
|
-
}
|
|
5533
|
-
if (plugin.postUpdate) {
|
|
5534
|
-
this.#postUpdatePlugins.push(plugin);
|
|
5535
|
-
}
|
|
5536
|
-
if (plugin.particleReset) {
|
|
5537
|
-
this.#particleResetPlugins.push(plugin);
|
|
5538
|
-
}
|
|
5539
|
-
if (plugin.postParticleUpdate) {
|
|
5540
|
-
this.#postParticleUpdatePlugins.push(plugin);
|
|
5541
|
-
}
|
|
5542
|
-
}
|
|
5543
|
-
await this.#container.initDrawersAndUpdaters();
|
|
5544
|
-
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5545
|
-
await drawer.init?.(container);
|
|
5546
|
-
}
|
|
5547
|
-
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5548
|
-
await drawer.init?.(container);
|
|
5549
|
-
}
|
|
5550
|
-
let handled = false;
|
|
5551
|
-
for (const plugin of container.plugins) {
|
|
5552
|
-
handled = plugin.particlesInitialization?.() ?? handled;
|
|
5553
|
-
if (handled) {
|
|
5554
|
-
break;
|
|
5555
|
-
}
|
|
5556
|
-
}
|
|
5557
|
-
if (!handled) {
|
|
5558
|
-
const particlesOptions = options.particles, groups = particlesOptions.groups;
|
|
5559
|
-
for (const group in groups) {
|
|
5560
|
-
const groupOptions = groups[group];
|
|
5561
|
-
if (!groupOptions) {
|
|
5562
|
-
continue;
|
|
5563
|
-
}
|
|
5564
|
-
for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
|
|
5565
|
-
this.addParticle(undefined, groupOptions, group);
|
|
5566
|
-
}
|
|
5567
|
-
}
|
|
5568
|
-
for (let i = this.count; i < particlesOptions.number.value; i++) {
|
|
5569
|
-
this.addParticle();
|
|
5620
|
+
this.#grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5621
|
+
this.#applyLimits(container.actualOptions.particles);
|
|
5622
|
+
const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
|
|
5623
|
+
for (const group in groups) {
|
|
5624
|
+
const groupData = groups[group];
|
|
5625
|
+
if (groupData) {
|
|
5626
|
+
this.#applyLimits(loadParticlesOptions(this.#pluginManager, this.#container, groupData), group, groupData);
|
|
5570
5627
|
}
|
|
5571
5628
|
}
|
|
5629
|
+
await this.#initPlugins();
|
|
5572
5630
|
}
|
|
5573
5631
|
push(nb, position, overrideOptions, group) {
|
|
5574
5632
|
for (let i = 0; i < nb; i++) {
|
|
@@ -5583,13 +5641,13 @@
|
|
|
5583
5641
|
remove(particle, group, override) {
|
|
5584
5642
|
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5585
5643
|
}
|
|
5586
|
-
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5644
|
+
removeAt(index, quantity = defaultRemoveQuantity, group, override, matchGroup = true) {
|
|
5587
5645
|
if (index < minIndex || index > this.count) {
|
|
5588
5646
|
return;
|
|
5589
5647
|
}
|
|
5590
5648
|
let deleted = 0;
|
|
5591
5649
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5592
|
-
if (this.#removeParticle(i, group, override)) {
|
|
5650
|
+
if (this.#removeParticle(i, group, override, matchGroup)) {
|
|
5593
5651
|
i--;
|
|
5594
5652
|
deleted++;
|
|
5595
5653
|
}
|
|
@@ -5620,7 +5678,7 @@
|
|
|
5620
5678
|
this.#resizeFactor = factor;
|
|
5621
5679
|
}
|
|
5622
5680
|
update(delta) {
|
|
5623
|
-
this
|
|
5681
|
+
this.#grid.clear();
|
|
5624
5682
|
for (const plugin of this.#updatePlugins) {
|
|
5625
5683
|
plugin.update?.(delta);
|
|
5626
5684
|
}
|
|
@@ -5631,7 +5689,7 @@
|
|
|
5631
5689
|
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5632
5690
|
if (particlesToDelete.size) {
|
|
5633
5691
|
for (const particle of particlesToDelete) {
|
|
5634
|
-
this.remove(particle);
|
|
5692
|
+
this.remove(particle, particle.group);
|
|
5635
5693
|
}
|
|
5636
5694
|
}
|
|
5637
5695
|
this.#resizeFactor = undefined;
|
|
@@ -5642,12 +5700,7 @@
|
|
|
5642
5700
|
#applyDensity(options, pluginsCount, group, groupOptions) {
|
|
5643
5701
|
const numberOptions = options.number;
|
|
5644
5702
|
if (!numberOptions.density.enable) {
|
|
5645
|
-
|
|
5646
|
-
this.#limit = numberOptions.limit.value;
|
|
5647
|
-
}
|
|
5648
|
-
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5649
|
-
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5650
|
-
}
|
|
5703
|
+
this.#applyLimits(options, group, groupOptions);
|
|
5651
5704
|
return;
|
|
5652
5705
|
}
|
|
5653
5706
|
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);
|
|
@@ -5655,7 +5708,10 @@
|
|
|
5655
5708
|
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5656
5709
|
}
|
|
5657
5710
|
else {
|
|
5658
|
-
this.#groupLimits.set(group,
|
|
5711
|
+
this.#groupLimits.set(group, {
|
|
5712
|
+
limit: numberOptions.limit.value * densityFactor,
|
|
5713
|
+
mode: toEnumValue(LimitMode, numberOptions.limit.mode, LimitMode.delete),
|
|
5714
|
+
});
|
|
5659
5715
|
}
|
|
5660
5716
|
if (particlesCount < particlesNumber) {
|
|
5661
5717
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5664,6 +5720,55 @@
|
|
|
5664
5720
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5665
5721
|
}
|
|
5666
5722
|
}
|
|
5723
|
+
#applyLimits(options, group, groupOptions) {
|
|
5724
|
+
if (group === undefined) {
|
|
5725
|
+
this.#limit = options.number.limit.value;
|
|
5726
|
+
const groups = this.#container.actualOptions.particles.groups;
|
|
5727
|
+
for (const existingGroup of this.#groupLimits.keys()) {
|
|
5728
|
+
if (!(existingGroup in groups)) {
|
|
5729
|
+
this.#groupLimits.delete(existingGroup);
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5732
|
+
}
|
|
5733
|
+
else {
|
|
5734
|
+
const limitValue = groupOptions?.number?.limit?.value ?? options.number.limit.value;
|
|
5735
|
+
if (limitValue > minLimit) {
|
|
5736
|
+
this.#groupLimits.set(group, {
|
|
5737
|
+
limit: limitValue,
|
|
5738
|
+
mode: toEnumValue(LimitMode, groupOptions?.number?.limit?.mode ?? options.number.limit.mode, LimitMode.delete),
|
|
5739
|
+
});
|
|
5740
|
+
}
|
|
5741
|
+
else {
|
|
5742
|
+
this.#groupLimits.delete(group);
|
|
5743
|
+
}
|
|
5744
|
+
}
|
|
5745
|
+
}
|
|
5746
|
+
#checkAndApplyLimits(group, currentCount) {
|
|
5747
|
+
const globalLimit = this.#limit, globalMode = this.#container.actualOptions.particles.number.limit.mode;
|
|
5748
|
+
if (globalLimit > minLimit && globalMode === LimitMode.wait && currentCount >= globalLimit) {
|
|
5749
|
+
return true;
|
|
5750
|
+
}
|
|
5751
|
+
const groupLimitEntry = group === undefined ? undefined : this.#groupLimits.get(group);
|
|
5752
|
+
if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.wait) {
|
|
5753
|
+
const groupCount = this.filter(t => t.group === group).length;
|
|
5754
|
+
if (groupCount >= groupLimitEntry.limit) {
|
|
5755
|
+
return true;
|
|
5756
|
+
}
|
|
5757
|
+
}
|
|
5758
|
+
if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.delete) {
|
|
5759
|
+
const groupCountToRemove = this.filter(t => t.group === group).length + countOffset - groupLimitEntry.limit;
|
|
5760
|
+
if (groupCountToRemove > minCount) {
|
|
5761
|
+
this.removeQuantity(groupCountToRemove, group);
|
|
5762
|
+
}
|
|
5763
|
+
}
|
|
5764
|
+
if (globalLimit > minLimit && globalMode === LimitMode.delete) {
|
|
5765
|
+
const globalCountToRemove = this.count + countOffset - globalLimit;
|
|
5766
|
+
if (globalCountToRemove > minCount) {
|
|
5767
|
+
this.#removeAny(globalCountToRemove);
|
|
5768
|
+
}
|
|
5769
|
+
}
|
|
5770
|
+
return false;
|
|
5771
|
+
}
|
|
5667
5772
|
#createBuckets(zLayers) {
|
|
5668
5773
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5669
5774
|
return Array.from({ length: bucketCount }, () => []);
|
|
@@ -5686,6 +5791,70 @@
|
|
|
5686
5791
|
}
|
|
5687
5792
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5688
5793
|
}
|
|
5794
|
+
async #initDrawersAndUpdaters() {
|
|
5795
|
+
const container = this.#container;
|
|
5796
|
+
await container.initDrawersAndUpdaters();
|
|
5797
|
+
for (const drawer of container.effectDrawers.values()) {
|
|
5798
|
+
await drawer.init?.(container);
|
|
5799
|
+
}
|
|
5800
|
+
for (const drawer of container.shapeDrawers.values()) {
|
|
5801
|
+
await drawer.init?.(container);
|
|
5802
|
+
}
|
|
5803
|
+
}
|
|
5804
|
+
async #initPlugins() {
|
|
5805
|
+
await this.#initPluginsArrays();
|
|
5806
|
+
await this.#initDrawersAndUpdaters();
|
|
5807
|
+
let handled = false;
|
|
5808
|
+
const container = this.#container;
|
|
5809
|
+
for (const plugin of container.plugins) {
|
|
5810
|
+
handled = plugin.particlesInitialization?.() ?? handled;
|
|
5811
|
+
if (handled) {
|
|
5812
|
+
break;
|
|
5813
|
+
}
|
|
5814
|
+
}
|
|
5815
|
+
if (handled) {
|
|
5816
|
+
return;
|
|
5817
|
+
}
|
|
5818
|
+
const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
|
|
5819
|
+
for (const group in groups) {
|
|
5820
|
+
const groupOptions = groups[group];
|
|
5821
|
+
if (!groupOptions) {
|
|
5822
|
+
continue;
|
|
5823
|
+
}
|
|
5824
|
+
for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
|
|
5825
|
+
this.addParticle(undefined, groupOptions, group);
|
|
5826
|
+
}
|
|
5827
|
+
}
|
|
5828
|
+
for (let i = this.count; i < particlesOptions.number.value; i++) {
|
|
5829
|
+
this.addParticle();
|
|
5830
|
+
}
|
|
5831
|
+
}
|
|
5832
|
+
async #initPluginsArrays() {
|
|
5833
|
+
const container = this.#container;
|
|
5834
|
+
for (const plugin of container.plugins) {
|
|
5835
|
+
if (plugin.redrawInit) {
|
|
5836
|
+
await plugin.redrawInit();
|
|
5837
|
+
}
|
|
5838
|
+
if (plugin.checkParticlePosition) {
|
|
5839
|
+
this.checkParticlePositionPlugins.push(plugin);
|
|
5840
|
+
}
|
|
5841
|
+
if (plugin.update) {
|
|
5842
|
+
this.#updatePlugins.push(plugin);
|
|
5843
|
+
}
|
|
5844
|
+
if (plugin.particleUpdate) {
|
|
5845
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5846
|
+
}
|
|
5847
|
+
if (plugin.postUpdate) {
|
|
5848
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5849
|
+
}
|
|
5850
|
+
if (plugin.particleReset) {
|
|
5851
|
+
this.#particleResetPlugins.push(plugin);
|
|
5852
|
+
}
|
|
5853
|
+
if (plugin.postParticleUpdate) {
|
|
5854
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5855
|
+
}
|
|
5856
|
+
}
|
|
5857
|
+
}
|
|
5689
5858
|
#insertParticleIntoBucket(particle) {
|
|
5690
5859
|
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5691
5860
|
if (!bucket) {
|
|
@@ -5694,12 +5863,15 @@
|
|
|
5694
5863
|
bucket.push(particle);
|
|
5695
5864
|
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5696
5865
|
}
|
|
5697
|
-
#
|
|
5866
|
+
#removeAny(quantity) {
|
|
5867
|
+
this.removeAt(minIndex, quantity, undefined, undefined, false);
|
|
5868
|
+
}
|
|
5869
|
+
#removeParticle(index, group, override, matchGroup = true) {
|
|
5698
5870
|
const particle = this.#array[index];
|
|
5699
5871
|
if (!particle) {
|
|
5700
5872
|
return false;
|
|
5701
5873
|
}
|
|
5702
|
-
if (particle.group !== group) {
|
|
5874
|
+
if (matchGroup && particle.group !== group) {
|
|
5703
5875
|
return false;
|
|
5704
5876
|
}
|
|
5705
5877
|
this.#array.splice(index, deleteCount);
|
|
@@ -5786,7 +5958,7 @@
|
|
|
5786
5958
|
particlesToDelete.add(particle);
|
|
5787
5959
|
continue;
|
|
5788
5960
|
}
|
|
5789
|
-
this
|
|
5961
|
+
this.#grid.insert(particle);
|
|
5790
5962
|
}
|
|
5791
5963
|
return particlesToDelete;
|
|
5792
5964
|
}
|
|
@@ -5873,6 +6045,7 @@
|
|
|
5873
6045
|
started;
|
|
5874
6046
|
zLayers;
|
|
5875
6047
|
#delay;
|
|
6048
|
+
#delayResolve;
|
|
5876
6049
|
#delayTimeout;
|
|
5877
6050
|
#delta = { value: 0, factor: 0 };
|
|
5878
6051
|
#dispatchCallback;
|
|
@@ -5962,7 +6135,6 @@
|
|
|
5962
6135
|
this.shapeDrawers = new Map();
|
|
5963
6136
|
this.particleUpdaters = [];
|
|
5964
6137
|
this.plugins.length = 0;
|
|
5965
|
-
this.#pluginManager.clearPlugins(this);
|
|
5966
6138
|
this.destroyed = true;
|
|
5967
6139
|
this.#onDestroy(remove);
|
|
5968
6140
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
@@ -6015,31 +6187,14 @@
|
|
|
6015
6187
|
await this.initDrawersAndUpdaters();
|
|
6016
6188
|
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
6017
6189
|
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
6018
|
-
this
|
|
6019
|
-
this.particleDestroyedPlugins.length = 0;
|
|
6020
|
-
this.particleCreatedPlugins.length = 0;
|
|
6021
|
-
this.particlePositionPlugins.length = 0;
|
|
6022
|
-
for (const [plugin, containerPlugin] of allContainerPlugins) {
|
|
6023
|
-
if (plugin.needsPlugin(this.actualOptions)) {
|
|
6024
|
-
this.plugins.push(containerPlugin);
|
|
6025
|
-
if (containerPlugin.particleCreated) {
|
|
6026
|
-
this.particleCreatedPlugins.push(containerPlugin);
|
|
6027
|
-
}
|
|
6028
|
-
if (containerPlugin.particleDestroyed) {
|
|
6029
|
-
this.particleDestroyedPlugins.push(containerPlugin);
|
|
6030
|
-
}
|
|
6031
|
-
if (containerPlugin.particlePosition) {
|
|
6032
|
-
this.particlePositionPlugins.push(containerPlugin);
|
|
6033
|
-
}
|
|
6034
|
-
}
|
|
6035
|
-
}
|
|
6190
|
+
this.#initPlugins(allContainerPlugins);
|
|
6036
6191
|
this.retina.init();
|
|
6037
6192
|
this.canvas.init();
|
|
6038
6193
|
this.updateActualOptions();
|
|
6039
6194
|
this.canvas.initBackground();
|
|
6040
6195
|
this.canvas.resize();
|
|
6041
6196
|
const { delay, duration, fpsLimit, smooth, zLayers } = this.actualOptions, hdrOptions = this.actualOptions.hdr;
|
|
6042
|
-
this.hdrMode = hdrOptions.mode;
|
|
6197
|
+
this.hdrMode = toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard);
|
|
6043
6198
|
this.peakNits = hdrOptions.peakNits;
|
|
6044
6199
|
this.zLayers = zLayers;
|
|
6045
6200
|
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
@@ -6060,9 +6215,9 @@
|
|
|
6060
6215
|
}
|
|
6061
6216
|
async initDrawersAndUpdaters() {
|
|
6062
6217
|
const pluginManager = this.#pluginManager;
|
|
6063
|
-
this.effectDrawers = await
|
|
6064
|
-
this.shapeDrawers = await
|
|
6065
|
-
this.particleUpdaters = await
|
|
6218
|
+
this.effectDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.effects);
|
|
6219
|
+
this.shapeDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.shapes);
|
|
6220
|
+
this.particleUpdaters = await getItemsFromInitializer(this, pluginManager.initializers.updaters);
|
|
6066
6221
|
}
|
|
6067
6222
|
pause() {
|
|
6068
6223
|
if (!guardCheck(this)) {
|
|
@@ -6129,7 +6284,10 @@
|
|
|
6129
6284
|
await this.init();
|
|
6130
6285
|
this.started = true;
|
|
6131
6286
|
await new Promise(resolve => {
|
|
6287
|
+
this.#delayResolve = resolve;
|
|
6132
6288
|
const start = async () => {
|
|
6289
|
+
this.#delayTimeout = undefined;
|
|
6290
|
+
this.#delayResolve = undefined;
|
|
6133
6291
|
this.#eventListeners.addListeners();
|
|
6134
6292
|
for (const plugin of this.plugins) {
|
|
6135
6293
|
await plugin.start?.();
|
|
@@ -6145,9 +6303,11 @@
|
|
|
6145
6303
|
if (!guardCheck(this) || !this.started) {
|
|
6146
6304
|
return;
|
|
6147
6305
|
}
|
|
6148
|
-
if (this.#delayTimeout) {
|
|
6306
|
+
if (this.#delayTimeout !== undefined) {
|
|
6149
6307
|
clearTimeout(this.#delayTimeout);
|
|
6150
6308
|
this.#delayTimeout = undefined;
|
|
6309
|
+
this.#delayResolve?.();
|
|
6310
|
+
this.#delayResolve = undefined;
|
|
6151
6311
|
}
|
|
6152
6312
|
this.#firstStart = true;
|
|
6153
6313
|
this.started = false;
|
|
@@ -6173,6 +6333,27 @@
|
|
|
6173
6333
|
}
|
|
6174
6334
|
return refresh;
|
|
6175
6335
|
}
|
|
6336
|
+
#initPlugins(allContainerPlugins) {
|
|
6337
|
+
this.plugins.length = 0;
|
|
6338
|
+
this.particleDestroyedPlugins.length = 0;
|
|
6339
|
+
this.particleCreatedPlugins.length = 0;
|
|
6340
|
+
this.particlePositionPlugins.length = 0;
|
|
6341
|
+
for (const [plugin, containerPlugin] of allContainerPlugins) {
|
|
6342
|
+
if (!plugin.needsPlugin(this.actualOptions)) {
|
|
6343
|
+
continue;
|
|
6344
|
+
}
|
|
6345
|
+
this.plugins.push(containerPlugin);
|
|
6346
|
+
if (containerPlugin.particleCreated) {
|
|
6347
|
+
this.particleCreatedPlugins.push(containerPlugin);
|
|
6348
|
+
}
|
|
6349
|
+
if (containerPlugin.particleDestroyed) {
|
|
6350
|
+
this.particleDestroyedPlugins.push(containerPlugin);
|
|
6351
|
+
}
|
|
6352
|
+
if (containerPlugin.particlePosition) {
|
|
6353
|
+
this.particlePositionPlugins.push(containerPlugin);
|
|
6354
|
+
}
|
|
6355
|
+
}
|
|
6356
|
+
}
|
|
6176
6357
|
#nextFrame(timestamp) {
|
|
6177
6358
|
try {
|
|
6178
6359
|
if (!this.#smooth &&
|
|
@@ -6449,11 +6630,11 @@
|
|
|
6449
6630
|
}
|
|
6450
6631
|
}
|
|
6451
6632
|
async #init() {
|
|
6452
|
-
const
|
|
6453
|
-
if (!
|
|
6633
|
+
const pluginManager = this.#pluginManager;
|
|
6634
|
+
if (!pluginManager.initializers.pathGenerators) {
|
|
6454
6635
|
return;
|
|
6455
6636
|
}
|
|
6456
|
-
this.availablePathGenerators =
|
|
6637
|
+
this.availablePathGenerators = await getItemMapFromInitializer(this.#container, pluginManager.initializers.pathGenerators);
|
|
6457
6638
|
this.pathGenerators = new Map();
|
|
6458
6639
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6459
6640
|
pathGenerator.init();
|
|
@@ -6557,28 +6738,14 @@
|
|
|
6557
6738
|
}
|
|
6558
6739
|
const html = interactivityEl, canvas = container.canvas;
|
|
6559
6740
|
canvas.setPointerEvents(html === canvas.domElement ? "initial" : "none");
|
|
6560
|
-
if (add && !(options.interactivity?.events.onHover.enable || options.interactivity?.events.onClick.enable)) {
|
|
6561
|
-
return;
|
|
6562
|
-
}
|
|
6563
6741
|
manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
|
|
6564
6742
|
manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
|
|
6565
6743
|
manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
}
|
|
6572
|
-
else {
|
|
6573
|
-
manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
|
|
6574
|
-
}
|
|
6575
|
-
}
|
|
6576
|
-
else {
|
|
6577
|
-
manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
|
|
6578
|
-
manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
|
|
6579
|
-
manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
|
|
6580
|
-
manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
|
|
6581
|
-
}
|
|
6744
|
+
const onClickEnabled = !!options.interactivity?.events.onClick.enable;
|
|
6745
|
+
manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add && onClickEnabled);
|
|
6746
|
+
manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add && !onClickEnabled);
|
|
6747
|
+
manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
|
|
6748
|
+
manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
|
|
6582
6749
|
manageListener(interactivityEl, mouseLeaveEvent, handlers.mouseLeave, add);
|
|
6583
6750
|
manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
|
|
6584
6751
|
}
|
|
@@ -6604,19 +6771,18 @@
|
|
|
6604
6771
|
#mouseTouchClick(e) {
|
|
6605
6772
|
const container = this.#container, interactionManager = this.#interactionManager, options = container.actualOptions, { mouse } = interactionManager.interactivityData;
|
|
6606
6773
|
mouse.inside = true;
|
|
6607
|
-
let handled = false;
|
|
6608
6774
|
const mousePosition = mouse.position;
|
|
6609
|
-
if (
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6775
|
+
if (mousePosition && options.interactivity?.events.onClick.enable) {
|
|
6776
|
+
let handled = false;
|
|
6777
|
+
for (const plugin of this.#clickPositionPlugins) {
|
|
6778
|
+
handled = plugin.clickPositionValid?.(mousePosition) ?? false;
|
|
6779
|
+
if (handled) {
|
|
6780
|
+
break;
|
|
6781
|
+
}
|
|
6782
|
+
}
|
|
6783
|
+
if (!handled) {
|
|
6784
|
+
this.#doMouseTouchClick(e);
|
|
6616
6785
|
}
|
|
6617
|
-
}
|
|
6618
|
-
if (!handled) {
|
|
6619
|
-
this.#doMouseTouchClick(e);
|
|
6620
6786
|
}
|
|
6621
6787
|
mouse.clicking = false;
|
|
6622
6788
|
}
|
|
@@ -6712,6 +6878,9 @@
|
|
|
6712
6878
|
this.#touches.set(touch.identifier, performance.now());
|
|
6713
6879
|
}
|
|
6714
6880
|
this.#mouseTouchMove(e);
|
|
6881
|
+
const { mouse } = this.#interactionManager.interactivityData;
|
|
6882
|
+
mouse.clicking = true;
|
|
6883
|
+
mouse.downPosition = mouse.position;
|
|
6715
6884
|
}
|
|
6716
6885
|
}
|
|
6717
6886
|
|
|
@@ -6724,18 +6893,18 @@
|
|
|
6724
6893
|
}
|
|
6725
6894
|
class InteractionManager {
|
|
6726
6895
|
interactivityData;
|
|
6896
|
+
interactors;
|
|
6727
6897
|
#clickHandlers;
|
|
6728
6898
|
#container;
|
|
6729
6899
|
#eventListeners;
|
|
6730
6900
|
#externalInteractors;
|
|
6731
|
-
#interactors;
|
|
6732
6901
|
#intersectionObserver;
|
|
6733
6902
|
#particleInteractors;
|
|
6734
6903
|
#pluginManager;
|
|
6735
6904
|
constructor(pluginManager, container) {
|
|
6736
6905
|
this.#container = container;
|
|
6737
6906
|
this.#pluginManager = pluginManager;
|
|
6738
|
-
this
|
|
6907
|
+
this.interactors = [];
|
|
6739
6908
|
this.#externalInteractors = [];
|
|
6740
6909
|
this.#particleInteractors = [];
|
|
6741
6910
|
this.#clickHandlers = new Map();
|
|
@@ -6854,7 +7023,7 @@
|
|
|
6854
7023
|
}
|
|
6855
7024
|
init() {
|
|
6856
7025
|
this.#eventListeners.init();
|
|
6857
|
-
for (const interactor of this
|
|
7026
|
+
for (const interactor of this.interactors) {
|
|
6858
7027
|
switch (interactor.type) {
|
|
6859
7028
|
case InteractorType.external:
|
|
6860
7029
|
this.#externalInteractors.push(interactor);
|
|
@@ -6867,11 +7036,11 @@
|
|
|
6867
7036
|
}
|
|
6868
7037
|
}
|
|
6869
7038
|
async initInteractors() {
|
|
6870
|
-
const
|
|
6871
|
-
if (!interactors) {
|
|
7039
|
+
const pluginManager = this.#pluginManager;
|
|
7040
|
+
if (!pluginManager.initializers.interactors) {
|
|
6872
7041
|
return;
|
|
6873
7042
|
}
|
|
6874
|
-
this
|
|
7043
|
+
this.interactors = await getItemsFromInitializer(this.#container, pluginManager.initializers.interactors);
|
|
6875
7044
|
this.#externalInteractors = [];
|
|
6876
7045
|
this.#particleInteractors = [];
|
|
6877
7046
|
}
|
|
@@ -6916,13 +7085,13 @@
|
|
|
6916
7085
|
}
|
|
6917
7086
|
updateMaxDistance() {
|
|
6918
7087
|
let maxTotalDistance = 0;
|
|
6919
|
-
for (const interactor of this
|
|
7088
|
+
for (const interactor of this.interactors) {
|
|
6920
7089
|
if (interactor.maxDistance > maxTotalDistance) {
|
|
6921
7090
|
maxTotalDistance = interactor.maxDistance;
|
|
6922
7091
|
}
|
|
6923
7092
|
}
|
|
6924
7093
|
const container = this.#container;
|
|
6925
|
-
container.particles.grid.
|
|
7094
|
+
container.particles.grid.cellSize = maxTotalDistance * container.retina.pixelRatio;
|
|
6926
7095
|
}
|
|
6927
7096
|
#intersectionManager(entries) {
|
|
6928
7097
|
const container = this.#container;
|
|
@@ -6944,59 +7113,59 @@
|
|
|
6944
7113
|
}
|
|
6945
7114
|
|
|
6946
7115
|
class InteractivityPluginInstance {
|
|
6947
|
-
interactionManager;
|
|
6948
7116
|
#container;
|
|
6949
|
-
#pluginManager;
|
|
6950
7117
|
constructor(pluginManager, container) {
|
|
6951
|
-
|
|
6952
|
-
|
|
6953
|
-
this.interactionManager = new InteractionManager(pluginManager, container);
|
|
6954
|
-
this.#container.addClickHandler = (callback) => {
|
|
6955
|
-
this.interactionManager.addClickHandler(callback);
|
|
7118
|
+
container.addClickHandler = (callback) => {
|
|
7119
|
+
container.interactionManager?.addClickHandler(callback);
|
|
6956
7120
|
};
|
|
7121
|
+
container.interactionManager = new InteractionManager(pluginManager, container);
|
|
7122
|
+
this.#container = container;
|
|
6957
7123
|
}
|
|
6958
7124
|
addClickHandler(callback) {
|
|
6959
|
-
this.interactionManager
|
|
7125
|
+
this.#container.interactionManager?.addClickHandler(callback);
|
|
6960
7126
|
}
|
|
6961
7127
|
clearClickHandlers() {
|
|
6962
|
-
this.interactionManager
|
|
7128
|
+
this.#container.interactionManager?.clearClickHandlers();
|
|
6963
7129
|
}
|
|
6964
7130
|
destroy() {
|
|
6965
7131
|
this.clearClickHandlers();
|
|
6966
|
-
this.#pluginManager.interactors?.delete(this.#container);
|
|
6967
7132
|
}
|
|
6968
7133
|
particleCreated(particle) {
|
|
6969
|
-
const interactivityParticle = particle, interactivity = new Interactivity(
|
|
6970
|
-
interactivity.load(
|
|
7134
|
+
const interactivityParticle = particle, container = this.#container, interactivity = new Interactivity(container);
|
|
7135
|
+
interactivity.load(container.actualOptions.interactivity);
|
|
6971
7136
|
interactivity.load(interactivityParticle.options.interactivity);
|
|
6972
7137
|
interactivityParticle.interactivity = interactivity;
|
|
6973
7138
|
}
|
|
6974
7139
|
particleReset(particle) {
|
|
6975
|
-
this.interactionManager
|
|
7140
|
+
this.#container.interactionManager?.reset(particle);
|
|
6976
7141
|
}
|
|
6977
7142
|
postParticleUpdate(particle, delta) {
|
|
6978
|
-
this.interactionManager
|
|
7143
|
+
this.#container.interactionManager?.particlesInteract(particle, delta);
|
|
6979
7144
|
}
|
|
6980
7145
|
postUpdate(delta) {
|
|
6981
|
-
this
|
|
6982
|
-
|
|
7146
|
+
const container = this.#container;
|
|
7147
|
+
container.interactionManager?.externalInteract(delta);
|
|
7148
|
+
container.interactionManager?.updateMaxDistance();
|
|
6983
7149
|
}
|
|
6984
7150
|
async preInit() {
|
|
6985
|
-
|
|
6986
|
-
|
|
7151
|
+
const container = this.#container;
|
|
7152
|
+
await container.interactionManager?.initInteractors();
|
|
7153
|
+
container.interactionManager?.init();
|
|
6987
7154
|
}
|
|
6988
7155
|
async redrawInit() {
|
|
6989
|
-
|
|
6990
|
-
|
|
7156
|
+
const container = this.#container;
|
|
7157
|
+
await container.interactionManager?.initInteractors();
|
|
7158
|
+
container.interactionManager?.init();
|
|
6991
7159
|
}
|
|
6992
7160
|
start() {
|
|
6993
|
-
this
|
|
6994
|
-
|
|
7161
|
+
const container = this.#container;
|
|
7162
|
+
container.interactionManager?.addListeners();
|
|
7163
|
+
container.interactionManager?.startObserving();
|
|
6995
7164
|
return Promise.resolve();
|
|
6996
7165
|
}
|
|
6997
7166
|
stop() {
|
|
6998
|
-
this.interactionManager
|
|
6999
|
-
this.interactionManager
|
|
7167
|
+
this.#container.interactionManager?.removeListeners();
|
|
7168
|
+
this.#container.interactionManager?.stopObserving();
|
|
7000
7169
|
}
|
|
7001
7170
|
}
|
|
7002
7171
|
|
|
@@ -7008,6 +7177,7 @@
|
|
|
7008
7177
|
exports.loadFireflyPreset = loadFireflyPreset;
|
|
7009
7178
|
exports.tsParticles = tsParticles;
|
|
7010
7179
|
|
|
7011
|
-
}));
|
|
7180
|
+
})(g.__tsParticlesInternals.presets.firefly = g.__tsParticlesInternals.presets.firefly || {});
|
|
7181
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : self);
|
|
7182
|
+
|
|
7012
7183
|
Object.assign(globalThis.window || globalThis, { loadFireflyPreset: (globalThis.__tsParticlesInternals.presets.firefly || {}).loadFireflyPreset });
|
|
7013
|
-
delete (globalThis.window || globalThis).tsparticlesInternalExports;
|