@tsparticles/preset-snow 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,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.0 */
|
|
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, defaultDensityFactor = 1, deleteCount = 1, defaultAngle = 0, identity = 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$1 = {
|
|
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$1.engineVersionMismatch]: "The tsParticles version is different from the loaded plugins version. Engine version: {0}. Plugin version: {1}",
|
|
323
|
+
[ErrorCodes$1.particlePositionNotFound]: "a valid position cannot be found for particle",
|
|
324
|
+
[ErrorCodes$1.pluginRegisterAfterLoad]: "Register plugins can only be done before calling tsParticles.load()",
|
|
325
|
+
[ErrorCodes$1.offscreenCanvasUnsupported]: "OffscreenCanvas is required but not supported by this browser",
|
|
326
|
+
[ErrorCodes$1.offscreenCanvasTransferFailed]: "OffscreenCanvas transfer failed",
|
|
327
|
+
[ErrorCodes$1.hdrEnableInvalid]: 'Invalid HDR "enable" value: expected a boolean, got "{0}"',
|
|
328
|
+
[ErrorCodes$1.hdrModeInvalid]: 'Invalid HDR "mode" value: expected one of {0}, got "{1}"',
|
|
329
|
+
[ErrorCodes$1.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 {
|
|
@@ -573,7 +715,6 @@
|
|
|
573
715
|
class PluginManager {
|
|
574
716
|
colorManagers = new Map();
|
|
575
717
|
easingFunctions = new Map();
|
|
576
|
-
effectDrawers = new Map();
|
|
577
718
|
initializers = {
|
|
578
719
|
effects: new Map(),
|
|
579
720
|
shapes: new Map(),
|
|
@@ -582,8 +723,6 @@
|
|
|
582
723
|
palettes = new Map();
|
|
583
724
|
plugins = [];
|
|
584
725
|
presets = new Map();
|
|
585
|
-
shapeDrawers = new Map();
|
|
586
|
-
updaters = new Map();
|
|
587
726
|
#allLoadersSet = new Set();
|
|
588
727
|
#configs = new Map();
|
|
589
728
|
#engine;
|
|
@@ -601,57 +740,79 @@
|
|
|
601
740
|
}
|
|
602
741
|
return res;
|
|
603
742
|
}
|
|
743
|
+
get initialized() {
|
|
744
|
+
return this.#initialized;
|
|
745
|
+
}
|
|
604
746
|
addColorManager(name, manager) {
|
|
747
|
+
if (this.#initialized) {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
605
750
|
this.colorManagers.set(name, manager);
|
|
606
751
|
}
|
|
607
752
|
addConfig(config) {
|
|
753
|
+
if (this.#initialized) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
608
756
|
const key = config.key ?? config.name ?? "default";
|
|
609
757
|
this.#configs.set(key, config);
|
|
610
758
|
this.#engine.dispatchEvent(EventType.configAdded, { data: { name: key, config } });
|
|
611
759
|
}
|
|
612
760
|
addEasing(name, easing) {
|
|
761
|
+
if (this.#initialized) {
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
613
764
|
if (this.easingFunctions.get(name)) {
|
|
614
765
|
return;
|
|
615
766
|
}
|
|
616
767
|
this.easingFunctions.set(name, easing);
|
|
617
768
|
}
|
|
618
769
|
addEffect(effect, drawer) {
|
|
770
|
+
if (this.#initialized) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
619
773
|
this.initializers.effects.set(effect, drawer);
|
|
620
774
|
}
|
|
621
775
|
addPalette(name, palette) {
|
|
776
|
+
if (this.#initialized) {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
622
779
|
this.palettes.set(name, palette);
|
|
623
780
|
}
|
|
624
781
|
addParticleUpdater(name, updaterInitializer) {
|
|
782
|
+
if (this.#initialized) {
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
625
785
|
this.initializers.updaters.set(name, updaterInitializer);
|
|
626
786
|
}
|
|
627
787
|
addPlugin(plugin) {
|
|
788
|
+
if (this.#initialized) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
628
791
|
if (this.getPlugin(plugin.id)) {
|
|
629
792
|
return;
|
|
630
793
|
}
|
|
631
794
|
this.plugins.push(plugin);
|
|
632
795
|
}
|
|
633
796
|
addPreset(preset, options, override = false) {
|
|
797
|
+
if (this.#initialized) {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
634
800
|
if (!(override || !this.getPreset(preset))) {
|
|
635
801
|
return;
|
|
636
802
|
}
|
|
637
803
|
this.presets.set(preset, options);
|
|
638
804
|
}
|
|
639
805
|
addShape(shapes, drawer) {
|
|
806
|
+
if (this.#initialized) {
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
640
809
|
for (const shape of shapes) {
|
|
641
810
|
this.initializers.shapes.set(shape, drawer);
|
|
642
811
|
}
|
|
643
812
|
}
|
|
644
|
-
clearPlugins(container) {
|
|
645
|
-
this.effectDrawers.delete(container);
|
|
646
|
-
this.shapeDrawers.delete(container);
|
|
647
|
-
this.updaters.delete(container);
|
|
648
|
-
}
|
|
649
813
|
getEasing(name) {
|
|
650
814
|
return this.easingFunctions.get(name) ?? ((value) => value);
|
|
651
815
|
}
|
|
652
|
-
getEffectDrawers(container, force = false) {
|
|
653
|
-
return getItemMapFromInitializer(container, this.effectDrawers, this.initializers.effects, force);
|
|
654
|
-
}
|
|
655
816
|
getPalette(name) {
|
|
656
817
|
return this.palettes.get(name);
|
|
657
818
|
}
|
|
@@ -661,12 +822,6 @@
|
|
|
661
822
|
getPreset(preset) {
|
|
662
823
|
return this.presets.get(preset);
|
|
663
824
|
}
|
|
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
825
|
async init() {
|
|
671
826
|
if (this.#initialized || this.#isRunningLoaders) {
|
|
672
827
|
return;
|
|
@@ -685,16 +840,9 @@
|
|
|
685
840
|
this.#initialized = true;
|
|
686
841
|
}
|
|
687
842
|
}
|
|
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
843
|
async register(...loaders) {
|
|
696
844
|
if (this.#initialized) {
|
|
697
|
-
throw new Error(
|
|
845
|
+
throw new Error(getErrorMessage(ErrorCodes$1.pluginRegisterAfterLoad));
|
|
698
846
|
}
|
|
699
847
|
for (const loader of loaders) {
|
|
700
848
|
if (this.#isRunningLoaders) {
|
|
@@ -706,88 +854,15 @@
|
|
|
706
854
|
}
|
|
707
855
|
}
|
|
708
856
|
async #runLoader(loader, executed, allLoaders) {
|
|
709
|
-
if (executed.has(loader))
|
|
857
|
+
if (executed.has(loader)) {
|
|
710
858
|
return;
|
|
859
|
+
}
|
|
711
860
|
executed.add(loader);
|
|
712
861
|
allLoaders.add(loader);
|
|
713
862
|
await loader(this.#engine);
|
|
714
863
|
}
|
|
715
864
|
}
|
|
716
865
|
|
|
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
866
|
class Engine {
|
|
792
867
|
pluginManager = new PluginManager(this);
|
|
793
868
|
#domArray = [];
|
|
@@ -797,7 +872,7 @@
|
|
|
797
872
|
return this.#domArray;
|
|
798
873
|
}
|
|
799
874
|
get version() {
|
|
800
|
-
return "4.
|
|
875
|
+
return "4.5.0";
|
|
801
876
|
}
|
|
802
877
|
addEventListener(type, listener) {
|
|
803
878
|
this.#eventDispatcher.addEventListener(type, listener);
|
|
@@ -806,7 +881,7 @@
|
|
|
806
881
|
if (this.version === pluginVersion) {
|
|
807
882
|
return;
|
|
808
883
|
}
|
|
809
|
-
throw new Error(
|
|
884
|
+
throw new Error(getErrorMessage(ErrorCodes$1.engineVersionMismatch, this.version, pluginVersion));
|
|
810
885
|
}
|
|
811
886
|
dispatchEvent(type, args) {
|
|
812
887
|
this.#eventDispatcher.dispatchEvent(type, args);
|
|
@@ -1055,20 +1130,6 @@
|
|
|
1055
1130
|
DrawLayer[DrawLayer["Foreground"] = 7] = "Foreground";
|
|
1056
1131
|
})(DrawLayer || (DrawLayer = {}));
|
|
1057
1132
|
|
|
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
1133
|
function loadProperty(obj, key, value) {
|
|
1073
1134
|
if (value !== undefined) {
|
|
1074
1135
|
obj[key] = value;
|
|
@@ -1100,6 +1161,20 @@
|
|
|
1100
1161
|
}
|
|
1101
1162
|
}
|
|
1102
1163
|
|
|
1164
|
+
class OptionLoader {
|
|
1165
|
+
load(data) {
|
|
1166
|
+
if (isNull(data)) {
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
this.doLoad(data);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function loadOptions(options, ...sourceOptionsArr) {
|
|
1173
|
+
for (const sourceOptions of sourceOptionsArr) {
|
|
1174
|
+
options.load(sourceOptions);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1103
1178
|
class AnimationOptions extends OptionLoader {
|
|
1104
1179
|
count = 0;
|
|
1105
1180
|
decay = 0;
|
|
@@ -1250,15 +1325,14 @@
|
|
|
1250
1325
|
peakNits = defaultPeakNits;
|
|
1251
1326
|
doLoad(data) {
|
|
1252
1327
|
if (data.enable !== undefined && !isBoolean(data.enable)) {
|
|
1253
|
-
throw new Error(
|
|
1328
|
+
throw new Error(getErrorMessage(ErrorCodes$1.hdrEnableInvalid, String(data.enable)));
|
|
1254
1329
|
}
|
|
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)}"`);
|
|
1330
|
+
if (data.mode !== undefined && !isEnumValue(HdrMode, data.mode)) {
|
|
1331
|
+
throw new Error(getErrorMessage(ErrorCodes$1.hdrModeInvalid, Object.values(HdrMode).join(", "), toStringValue(data.mode)));
|
|
1258
1332
|
}
|
|
1259
1333
|
if (data.peakNits !== undefined &&
|
|
1260
1334
|
(!isNumber(data.peakNits) || !Number.isFinite(data.peakNits) || data.peakNits <= minPeakNits)) {
|
|
1261
|
-
throw new Error(
|
|
1335
|
+
throw new Error(getErrorMessage(ErrorCodes$1.hdrPeakNitsInvalid, String(data.peakNits)));
|
|
1262
1336
|
}
|
|
1263
1337
|
loadProperty(this, "enable", data.enable);
|
|
1264
1338
|
loadProperty(this, "mode", data.mode);
|
|
@@ -1636,12 +1710,10 @@
|
|
|
1636
1710
|
plugin.loadParticlesOptions(this.#container, this, data);
|
|
1637
1711
|
}
|
|
1638
1712
|
}
|
|
1639
|
-
const updaters = this.#
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
updater.loadOptions(this, data);
|
|
1644
|
-
}
|
|
1713
|
+
const updaters = this.#container.particleUpdaters;
|
|
1714
|
+
for (const updater of updaters) {
|
|
1715
|
+
if (updater.loadOptions) {
|
|
1716
|
+
updater.loadOptions(this, data);
|
|
1645
1717
|
}
|
|
1646
1718
|
}
|
|
1647
1719
|
}
|
|
@@ -1974,9 +2046,9 @@
|
|
|
1974
2046
|
const grayscaleValue = Math.round(lNormalized * rgbMax);
|
|
1975
2047
|
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
|
|
1976
2048
|
}
|
|
1977
|
-
const
|
|
2049
|
+
const temp2 = lNormalized < half
|
|
1978
2050
|
? lNormalized * (sNormalizedOffset + sNormalized)
|
|
1979
|
-
: lNormalized + sNormalized - lNormalized * sNormalized,
|
|
2051
|
+
: 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
2052
|
return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
|
|
1981
2053
|
}
|
|
1982
2054
|
function hslToRgbFloat(hsl) {
|
|
@@ -1985,9 +2057,9 @@
|
|
|
1985
2057
|
const grayscaleValue = lNormalized * rgbMax;
|
|
1986
2058
|
return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
|
|
1987
2059
|
}
|
|
1988
|
-
const
|
|
2060
|
+
const temp2 = lNormalized < half
|
|
1989
2061
|
? lNormalized * (sNormalizedOffset + sNormalized)
|
|
1990
|
-
: lNormalized + sNormalized - lNormalized * sNormalized,
|
|
2062
|
+
: 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
2063
|
return { r: red, g: green, b: blue };
|
|
1992
2064
|
}
|
|
1993
2065
|
function hslaToRgba(hsla) {
|
|
@@ -2201,7 +2273,7 @@
|
|
|
2201
2273
|
}
|
|
2202
2274
|
|
|
2203
2275
|
async function loadBlendPlugin(engine) {
|
|
2204
|
-
engine.checkVersion("4.
|
|
2276
|
+
engine.checkVersion("4.5.0");
|
|
2205
2277
|
await engine.pluginManager.register(e => {
|
|
2206
2278
|
e.pluginManager.addPlugin(new BlendPlugin());
|
|
2207
2279
|
});
|
|
@@ -2238,7 +2310,7 @@
|
|
|
2238
2310
|
}
|
|
2239
2311
|
|
|
2240
2312
|
async function loadCircleShape(engine) {
|
|
2241
|
-
engine.checkVersion("4.
|
|
2313
|
+
engine.checkVersion("4.5.0");
|
|
2242
2314
|
await engine.pluginManager.register(e => {
|
|
2243
2315
|
e.pluginManager.addShape(["circle"], () => {
|
|
2244
2316
|
return Promise.resolve(new CircleDrawer());
|
|
@@ -2253,7 +2325,7 @@
|
|
|
2253
2325
|
RgbIndexes[RgbIndexes["b"] = 3] = "b";
|
|
2254
2326
|
RgbIndexes[RgbIndexes["a"] = 4] = "a";
|
|
2255
2327
|
})(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,
|
|
2328
|
+
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
2329
|
class HexColorManager {
|
|
2258
2330
|
accepts(input) {
|
|
2259
2331
|
return input.startsWith("#");
|
|
@@ -2286,7 +2358,7 @@
|
|
|
2286
2358
|
}
|
|
2287
2359
|
|
|
2288
2360
|
async function loadHexColorPlugin(engine) {
|
|
2289
|
-
engine.checkVersion("4.
|
|
2361
|
+
engine.checkVersion("4.5.0");
|
|
2290
2362
|
await engine.pluginManager.register(e => {
|
|
2291
2363
|
e.pluginManager.addColorManager("hex", new HexColorManager());
|
|
2292
2364
|
});
|
|
@@ -2326,7 +2398,7 @@
|
|
|
2326
2398
|
if (!this.accepts(input)) {
|
|
2327
2399
|
return;
|
|
2328
2400
|
}
|
|
2329
|
-
const result = hslRegex.exec(input), minLength = 4,
|
|
2401
|
+
const result = hslRegex.exec(input), minLength = 4, radix = 10;
|
|
2330
2402
|
return result
|
|
2331
2403
|
? hslaToRgba({
|
|
2332
2404
|
a: result.length > minLength ? parseAlpha(result[HslIndexes.a]) : defaultAlpha,
|
|
@@ -2339,12 +2411,20 @@
|
|
|
2339
2411
|
}
|
|
2340
2412
|
|
|
2341
2413
|
async function loadHslColorPlugin(engine) {
|
|
2342
|
-
engine.checkVersion("4.
|
|
2414
|
+
engine.checkVersion("4.5.0");
|
|
2343
2415
|
await engine.pluginManager.register(e => {
|
|
2344
2416
|
e.pluginManager.addColorManager("hsl", new HslColorManager());
|
|
2345
2417
|
});
|
|
2346
2418
|
}
|
|
2347
2419
|
|
|
2420
|
+
const ErrorCodes = {
|
|
2421
|
+
baseMoverNotLoaded: "TSP-3203",
|
|
2422
|
+
};
|
|
2423
|
+
|
|
2424
|
+
const ErrorMessages = {
|
|
2425
|
+
[ErrorCodes.baseMoverNotLoaded]: "tsParticles Base Mover is not loaded",
|
|
2426
|
+
};
|
|
2427
|
+
|
|
2348
2428
|
class MovePlugin {
|
|
2349
2429
|
id = "move";
|
|
2350
2430
|
#pluginManager;
|
|
@@ -2363,20 +2443,20 @@
|
|
|
2363
2443
|
}
|
|
2364
2444
|
|
|
2365
2445
|
async function loadMovePlugin(engine) {
|
|
2366
|
-
engine.checkVersion("4.
|
|
2446
|
+
engine.checkVersion("4.5.0");
|
|
2447
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
2448
|
+
addErrorMessages(ErrorMessages);
|
|
2449
|
+
}
|
|
2367
2450
|
await engine.pluginManager.register(e => {
|
|
2368
2451
|
const moveEngine = e, movePluginManager = moveEngine.pluginManager;
|
|
2369
2452
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
2370
|
-
movePluginManager.pathGenerators ??= new Map();
|
|
2371
2453
|
movePluginManager.addPathGenerator = (name, generator) => {
|
|
2454
|
+
if (movePluginManager.initialized) {
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2372
2457
|
movePluginManager.initializers.pathGenerators ??= new Map();
|
|
2373
2458
|
movePluginManager.initializers.pathGenerators.set(name, generator);
|
|
2374
2459
|
};
|
|
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
2460
|
e.pluginManager.addPlugin(new MovePlugin(e.pluginManager));
|
|
2381
2461
|
});
|
|
2382
2462
|
}
|
|
@@ -2573,7 +2653,7 @@
|
|
|
2573
2653
|
}
|
|
2574
2654
|
|
|
2575
2655
|
async function loadOpacityUpdater(engine) {
|
|
2576
|
-
engine.checkVersion("4.
|
|
2656
|
+
engine.checkVersion("4.5.0");
|
|
2577
2657
|
await engine.pluginManager.register(e => {
|
|
2578
2658
|
e.pluginManager.addParticleUpdater("opacity", container => {
|
|
2579
2659
|
return Promise.resolve(new OpacityUpdater(container));
|
|
@@ -2582,70 +2662,60 @@
|
|
|
2582
2662
|
}
|
|
2583
2663
|
|
|
2584
2664
|
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)) {
|
|
2665
|
+
const bounceAxisConfigs = {
|
|
2666
|
+
[OutModeDirection.left]: {
|
|
2667
|
+
axis: "x",
|
|
2668
|
+
canvas: "width",
|
|
2669
|
+
bounce: "horizontal",
|
|
2670
|
+
negativeEdge: "right",
|
|
2671
|
+
positiveEdge: "left",
|
|
2672
|
+
negative: true,
|
|
2673
|
+
},
|
|
2674
|
+
[OutModeDirection.right]: {
|
|
2675
|
+
axis: "x",
|
|
2676
|
+
canvas: "width",
|
|
2677
|
+
bounce: "horizontal",
|
|
2678
|
+
negativeEdge: "right",
|
|
2679
|
+
positiveEdge: "left",
|
|
2680
|
+
negative: false,
|
|
2681
|
+
},
|
|
2682
|
+
[OutModeDirection.top]: {
|
|
2683
|
+
axis: "y",
|
|
2684
|
+
canvas: "height",
|
|
2685
|
+
bounce: "vertical",
|
|
2686
|
+
negativeEdge: "bottom",
|
|
2687
|
+
positiveEdge: "top",
|
|
2688
|
+
negative: true,
|
|
2689
|
+
},
|
|
2690
|
+
[OutModeDirection.bottom]: {
|
|
2691
|
+
axis: "y",
|
|
2692
|
+
canvas: "height",
|
|
2693
|
+
bounce: "vertical",
|
|
2694
|
+
negativeEdge: "bottom",
|
|
2695
|
+
positiveEdge: "top",
|
|
2696
|
+
negative: false,
|
|
2697
|
+
},
|
|
2698
|
+
};
|
|
2699
|
+
function bounce(data) {
|
|
2700
|
+
if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) || !(data.direction in bounceAxisConfigs)) {
|
|
2622
2701
|
return;
|
|
2623
2702
|
}
|
|
2624
|
-
|
|
2625
|
-
|
|
2703
|
+
const config = bounceAxisConfigs[data.direction], bounds = data.bounds, canvasDim = data.canvasSize[config.canvas], position = data.particle.position, velocity = data.particle.velocity[config.axis];
|
|
2704
|
+
if (config.negative && bounds[config.negativeEdge] < boundsMin) {
|
|
2705
|
+
position[config.axis] = data.size + data.offset[config.axis];
|
|
2626
2706
|
}
|
|
2627
|
-
else if (
|
|
2628
|
-
|
|
2707
|
+
else if (!config.negative && bounds[config.positiveEdge] > canvasDim) {
|
|
2708
|
+
position[config.axis] = canvasDim - data.size - data.offset[config.axis];
|
|
2629
2709
|
}
|
|
2630
|
-
const velocity = data.particle.velocity.y;
|
|
2631
|
-
let bounced = false;
|
|
2632
2710
|
if (data.outOfCanvas &&
|
|
2633
|
-
((
|
|
2634
|
-
|
|
2635
|
-
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
2636
|
-
data.particle.velocity.y *= -newVelocity;
|
|
2637
|
-
bounced = true;
|
|
2711
|
+
((config.negative && velocity < minVelocity) || (!config.negative && velocity > minVelocity))) {
|
|
2712
|
+
data.particle.velocity[config.axis] *= -getRangeValue(data.particle.options.bounce[config.bounce].value);
|
|
2638
2713
|
}
|
|
2639
|
-
|
|
2714
|
+
else {
|
|
2640
2715
|
return;
|
|
2641
2716
|
}
|
|
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
|
-
}
|
|
2717
|
+
const minPos = data.offset[config.axis] + data.size;
|
|
2718
|
+
position[config.axis] = config.negative ? minPos : canvasDim - minPos;
|
|
2649
2719
|
if (data.outMode === OutMode.split) {
|
|
2650
2720
|
data.particle.destroy();
|
|
2651
2721
|
}
|
|
@@ -2661,26 +2731,19 @@
|
|
|
2661
2731
|
OutMode.bounce,
|
|
2662
2732
|
OutMode.split,
|
|
2663
2733
|
];
|
|
2664
|
-
this.#particleBouncePlugins = container.plugins.filter(p => p.particleBounce
|
|
2734
|
+
this.#particleBouncePlugins = container.plugins.filter(p => !!p.particleBounce);
|
|
2665
2735
|
}
|
|
2666
2736
|
update(particle, direction, delta, outMode) {
|
|
2667
2737
|
if (!this.modes.includes(outMode)) {
|
|
2668
2738
|
return;
|
|
2669
2739
|
}
|
|
2670
|
-
const container = this.#container;
|
|
2671
|
-
let handled = false;
|
|
2672
2740
|
for (const plugin of this.#particleBouncePlugins) {
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
break;
|
|
2741
|
+
if (plugin.particleBounce?.(particle, delta, direction)) {
|
|
2742
|
+
return;
|
|
2676
2743
|
}
|
|
2677
2744
|
}
|
|
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 });
|
|
2745
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = this.#container.canvas.size, outOfCanvas = !particle.isInsideCanvasForOutMode(outMode, direction);
|
|
2746
|
+
bounce({ particle, outMode, direction, bounds, canvasSize, offset, outOfCanvas, size });
|
|
2684
2747
|
}
|
|
2685
2748
|
}
|
|
2686
2749
|
|
|
@@ -2769,107 +2832,108 @@
|
|
|
2769
2832
|
return;
|
|
2770
2833
|
}
|
|
2771
2834
|
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;
|
|
2835
|
+
if (particle.outType === ParticleOutType.inside) {
|
|
2836
|
+
this.#applyOutModeInside(particle, container);
|
|
2837
|
+
}
|
|
2838
|
+
else {
|
|
2839
|
+
if (particle.isInsideCanvasForOutMode(outMode, direction)) {
|
|
2840
|
+
return;
|
|
2799
2841
|
}
|
|
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;
|
|
2842
|
+
if (particle.outType === ParticleOutType.outside) {
|
|
2843
|
+
this.#applyParticleModeOutside(particle);
|
|
2871
2844
|
}
|
|
2845
|
+
else {
|
|
2846
|
+
this.#applyOutModeNormal(particle, container, direction);
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2850
|
+
#applyOutModeInside(particle, container) {
|
|
2851
|
+
const { x: vx, y: vy } = particle.velocity;
|
|
2852
|
+
updateVector.setTo(originPoint);
|
|
2853
|
+
updateVector.length = particle.moveCenter.radius;
|
|
2854
|
+
updateVector.angle = particle.velocity.angle + Math.PI;
|
|
2855
|
+
updateVector.addTo(particle.moveCenter);
|
|
2856
|
+
const { dx, dy } = getDistances(particle.position, updateVector);
|
|
2857
|
+
if ((vx <= minVelocity && dx >= minDistance) ||
|
|
2858
|
+
(vy <= minVelocity && dy >= minDistance) ||
|
|
2859
|
+
(vx >= minVelocity && dx <= minDistance) ||
|
|
2860
|
+
(vy >= minVelocity && dy <= minDistance)) {
|
|
2861
|
+
return;
|
|
2872
2862
|
}
|
|
2863
|
+
particle.position.x = Math.floor(randomInRangeValue({
|
|
2864
|
+
min: 0,
|
|
2865
|
+
max: container.canvas.size.width,
|
|
2866
|
+
}));
|
|
2867
|
+
particle.position.y = Math.floor(randomInRangeValue({
|
|
2868
|
+
min: 0,
|
|
2869
|
+
max: container.canvas.size.height,
|
|
2870
|
+
}));
|
|
2871
|
+
const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
|
|
2872
|
+
particle.direction = Math.atan2(-newDy, -newDx);
|
|
2873
|
+
particle.velocity.angle = particle.direction;
|
|
2874
|
+
particle.justWarped = true;
|
|
2875
|
+
}
|
|
2876
|
+
#applyOutModeNormal(particle, container, direction) {
|
|
2877
|
+
const warp = particle.options.move.warp, canvasSize = container.canvas.size, sizeValue = particle.getRadius(), newPos = {
|
|
2878
|
+
bottom: canvasSize.height + sizeValue + particle.offset.y,
|
|
2879
|
+
left: -sizeValue - particle.offset.x,
|
|
2880
|
+
right: canvasSize.width + sizeValue + particle.offset.x,
|
|
2881
|
+
top: -sizeValue - particle.offset.y,
|
|
2882
|
+
}, nextBounds = calculateBounds(particle.position, sizeValue);
|
|
2883
|
+
if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width + particle.offset.x) {
|
|
2884
|
+
particle.position.x = newPos.left;
|
|
2885
|
+
particle.initialPosition.x = particle.position.x;
|
|
2886
|
+
if (!warp) {
|
|
2887
|
+
particle.position.y = getRandom() * canvasSize.height;
|
|
2888
|
+
particle.initialPosition.y = particle.position.y;
|
|
2889
|
+
}
|
|
2890
|
+
particle.justWarped = true;
|
|
2891
|
+
}
|
|
2892
|
+
else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
|
|
2893
|
+
particle.position.x = newPos.right;
|
|
2894
|
+
particle.initialPosition.x = particle.position.x;
|
|
2895
|
+
if (!warp) {
|
|
2896
|
+
particle.position.y = getRandom() * canvasSize.height;
|
|
2897
|
+
particle.initialPosition.y = particle.position.y;
|
|
2898
|
+
}
|
|
2899
|
+
particle.justWarped = true;
|
|
2900
|
+
}
|
|
2901
|
+
if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height + particle.offset.y) {
|
|
2902
|
+
if (!warp) {
|
|
2903
|
+
particle.position.x = getRandom() * canvasSize.width;
|
|
2904
|
+
particle.initialPosition.x = particle.position.x;
|
|
2905
|
+
}
|
|
2906
|
+
particle.position.y = newPos.top;
|
|
2907
|
+
particle.initialPosition.y = particle.position.y;
|
|
2908
|
+
particle.justWarped = true;
|
|
2909
|
+
}
|
|
2910
|
+
else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
|
|
2911
|
+
if (!warp) {
|
|
2912
|
+
particle.position.x = getRandom() * canvasSize.width;
|
|
2913
|
+
particle.initialPosition.x = particle.position.x;
|
|
2914
|
+
}
|
|
2915
|
+
particle.position.y = newPos.bottom;
|
|
2916
|
+
particle.initialPosition.y = particle.position.y;
|
|
2917
|
+
particle.justWarped = true;
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
#applyParticleModeOutside(particle) {
|
|
2921
|
+
particle.position.x =
|
|
2922
|
+
Math.floor(randomInRangeValue({
|
|
2923
|
+
min: -particle.moveCenter.radius,
|
|
2924
|
+
max: particle.moveCenter.radius,
|
|
2925
|
+
})) + particle.moveCenter.x;
|
|
2926
|
+
particle.position.y =
|
|
2927
|
+
Math.floor(randomInRangeValue({
|
|
2928
|
+
min: -particle.moveCenter.radius,
|
|
2929
|
+
max: particle.moveCenter.radius,
|
|
2930
|
+
})) + particle.moveCenter.y;
|
|
2931
|
+
const { dx, dy } = getDistances(particle.position, particle.moveCenter);
|
|
2932
|
+
if (particle.moveCenter.radius) {
|
|
2933
|
+
particle.direction = Math.atan2(dy, dx);
|
|
2934
|
+
particle.velocity.angle = particle.direction;
|
|
2935
|
+
}
|
|
2936
|
+
particle.justWarped = true;
|
|
2873
2937
|
}
|
|
2874
2938
|
}
|
|
2875
2939
|
|
|
@@ -2918,56 +2982,26 @@
|
|
|
2918
2982
|
}
|
|
2919
2983
|
|
|
2920
2984
|
async function loadOutModesUpdater(engine) {
|
|
2921
|
-
engine.checkVersion("4.
|
|
2985
|
+
engine.checkVersion("4.5.0");
|
|
2922
2986
|
await engine.pluginManager.register(e => {
|
|
2923
2987
|
e.pluginManager.addParticleUpdater("outModes", container => {
|
|
2924
2988
|
return Promise.resolve(new OutOfCanvasUpdater(container));
|
|
2925
2989
|
});
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2928
|
-
|
|
2929
|
-
const defaultOpacity = 1;
|
|
2930
|
-
class PaintUpdater {
|
|
2931
|
-
#container;
|
|
2932
|
-
#pluginManager;
|
|
2933
|
-
constructor(pluginManager, container) {
|
|
2934
|
-
this.#container = container;
|
|
2935
|
-
this.#pluginManager = pluginManager;
|
|
2936
|
-
}
|
|
2937
|
-
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
|
-
}
|
|
2990
|
+
});
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
const defaultOpacity = 1;
|
|
2994
|
+
class PaintUpdater {
|
|
2995
|
+
#container;
|
|
2996
|
+
#pluginManager;
|
|
2997
|
+
constructor(pluginManager, container) {
|
|
2998
|
+
this.#container = container;
|
|
2999
|
+
this.#pluginManager = pluginManager;
|
|
3000
|
+
}
|
|
3001
|
+
init(particle) {
|
|
3002
|
+
const container = this.#container, options = particle.options, paint = itemFromSingleOrMultiple(options.paint, particle.id, options.reduceDuplicates);
|
|
3003
|
+
this.#initFill(paint, particle, container);
|
|
3004
|
+
this.#initStroke(paint, particle, container);
|
|
2971
3005
|
}
|
|
2972
3006
|
isEnabled(particle) {
|
|
2973
3007
|
const { fillAnimation, fillColor, strokeAnimation, strokeColor } = particle, fillEnabled = !!fillAnimation &&
|
|
@@ -2986,10 +3020,48 @@
|
|
|
2986
3020
|
updateColor(particle.fillColor, delta, this.#container.hdr);
|
|
2987
3021
|
updateColor(particle.strokeColor, delta, this.#container.hdr);
|
|
2988
3022
|
}
|
|
3023
|
+
#initFill(paint, particle, container) {
|
|
3024
|
+
const fill = paint?.fill, color = paint?.color, paintColor = color ?? undefined;
|
|
3025
|
+
if (!fill) {
|
|
3026
|
+
particle.fillEnabled = false;
|
|
3027
|
+
particle.fillAnimation = undefined;
|
|
3028
|
+
particle.fillColor = undefined;
|
|
3029
|
+
particle.fillOpacity = defaultOpacity;
|
|
3030
|
+
return;
|
|
3031
|
+
}
|
|
3032
|
+
const fillColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), fill.color);
|
|
3033
|
+
particle.fillEnabled = fill.enable;
|
|
3034
|
+
particle.fillOpacity = getRangeValue(fill.opacity);
|
|
3035
|
+
particle.fillAnimation = fillColor.animation;
|
|
3036
|
+
const fillHslColor = rangeColorToHsl(this.#pluginManager, fillColor);
|
|
3037
|
+
if (!fillHslColor) {
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
particle.fillColor = getHslAnimationFromHsl(fillHslColor, particle.fillAnimation, container.retina.reduceFactor);
|
|
3041
|
+
}
|
|
3042
|
+
#initStroke(paint, particle, container) {
|
|
3043
|
+
const stroke = paint?.stroke, color = paint?.color, paintColor = color ?? undefined;
|
|
3044
|
+
if (!stroke) {
|
|
3045
|
+
particle.strokeAnimation = undefined;
|
|
3046
|
+
particle.strokeColor = undefined;
|
|
3047
|
+
particle.strokeOpacity = defaultOpacity;
|
|
3048
|
+
particle.strokeWidth = 0;
|
|
3049
|
+
return;
|
|
3050
|
+
}
|
|
3051
|
+
const strokeColor = AnimatableColor.create(paintColor === undefined ? undefined : AnimatableColor.create(undefined, paintColor), stroke.color);
|
|
3052
|
+
particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
|
3053
|
+
particle.strokeOpacity = getRangeValue(stroke.opacity ?? defaultOpacity);
|
|
3054
|
+
particle.strokeAnimation = strokeColor.animation;
|
|
3055
|
+
const strokeHslColor = rangeColorToHsl(this.#pluginManager, strokeColor) ?? particle.getFillColor();
|
|
3056
|
+
if (!strokeHslColor) {
|
|
3057
|
+
return;
|
|
3058
|
+
}
|
|
3059
|
+
particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
|
3060
|
+
}
|
|
2989
3061
|
}
|
|
2990
3062
|
|
|
2991
3063
|
async function loadPaintUpdater(engine) {
|
|
2992
|
-
engine.checkVersion("4.
|
|
3064
|
+
engine.checkVersion("4.5.0");
|
|
2993
3065
|
await engine.pluginManager.register(e => {
|
|
2994
3066
|
e.pluginManager.addParticleUpdater("paint", container => {
|
|
2995
3067
|
return Promise.resolve(new PaintUpdater(e.pluginManager, container));
|
|
@@ -3031,7 +3103,7 @@
|
|
|
3031
3103
|
if (!this.accepts(input)) {
|
|
3032
3104
|
return;
|
|
3033
3105
|
}
|
|
3034
|
-
const result = rgbRegex.exec(input), radix = 10, minLength = 4
|
|
3106
|
+
const result = rgbRegex.exec(input), radix = 10, minLength = 4;
|
|
3035
3107
|
return result
|
|
3036
3108
|
? {
|
|
3037
3109
|
a: result.length > minLength ? parseAlpha(result[RgbIndexes.a]) : defaultAlpha,
|
|
@@ -3044,7 +3116,7 @@
|
|
|
3044
3116
|
}
|
|
3045
3117
|
|
|
3046
3118
|
async function loadRgbColorPlugin(engine) {
|
|
3047
|
-
engine.checkVersion("4.
|
|
3119
|
+
engine.checkVersion("4.5.0");
|
|
3048
3120
|
await engine.pluginManager.register(e => {
|
|
3049
3121
|
e.pluginManager.addColorManager("rgb", new RgbColorManager());
|
|
3050
3122
|
});
|
|
@@ -3129,7 +3201,7 @@
|
|
|
3129
3201
|
}
|
|
3130
3202
|
|
|
3131
3203
|
async function loadSizeUpdater(engine) {
|
|
3132
|
-
engine.checkVersion("4.
|
|
3204
|
+
engine.checkVersion("4.5.0");
|
|
3133
3205
|
await engine.pluginManager.register(e => {
|
|
3134
3206
|
e.pluginManager.addParticleUpdater("size", container => {
|
|
3135
3207
|
return Promise.resolve(new SizeUpdater(container));
|
|
@@ -3138,7 +3210,7 @@
|
|
|
3138
3210
|
}
|
|
3139
3211
|
|
|
3140
3212
|
async function loadBasic(engine) {
|
|
3141
|
-
engine.checkVersion("4.
|
|
3213
|
+
engine.checkVersion("4.5.0");
|
|
3142
3214
|
await engine.pluginManager.register(async (e) => {
|
|
3143
3215
|
await Promise.all([
|
|
3144
3216
|
loadBlendPlugin(e),
|
|
@@ -3274,7 +3346,7 @@
|
|
|
3274
3346
|
}
|
|
3275
3347
|
|
|
3276
3348
|
async function loadWobbleUpdater(engine) {
|
|
3277
|
-
engine.checkVersion("4.
|
|
3349
|
+
engine.checkVersion("4.5.0");
|
|
3278
3350
|
await engine.pluginManager.register(e => {
|
|
3279
3351
|
e.pluginManager.addParticleUpdater("wobble", container => {
|
|
3280
3352
|
return Promise.resolve(new WobbleUpdater(container));
|
|
@@ -3386,21 +3458,28 @@
|
|
|
3386
3458
|
});
|
|
3387
3459
|
}
|
|
3388
3460
|
clear() {
|
|
3461
|
+
const visited = new Set();
|
|
3389
3462
|
for (const plugin of this.#canvasClearPlugins) {
|
|
3463
|
+
visited.add(plugin);
|
|
3390
3464
|
if (plugin.canvasClear?.() ?? false) {
|
|
3391
|
-
return;
|
|
3465
|
+
return plugin;
|
|
3392
3466
|
}
|
|
3393
3467
|
}
|
|
3394
3468
|
for (const layer of Object.values(DrawLayer)) {
|
|
3395
3469
|
if (typeof layer === "number") {
|
|
3396
3470
|
for (const plugin of this.#getLayerPlugins(layer)) {
|
|
3471
|
+
if (visited.has(plugin)) {
|
|
3472
|
+
continue;
|
|
3473
|
+
}
|
|
3474
|
+
visited.add(plugin);
|
|
3397
3475
|
if (plugin.canvasClear?.() ?? false) {
|
|
3398
|
-
return;
|
|
3476
|
+
return plugin;
|
|
3399
3477
|
}
|
|
3400
3478
|
}
|
|
3401
3479
|
}
|
|
3402
3480
|
}
|
|
3403
3481
|
this.canvasClear();
|
|
3482
|
+
return undefined;
|
|
3404
3483
|
}
|
|
3405
3484
|
destroy() {
|
|
3406
3485
|
this.stop();
|
|
@@ -3478,8 +3557,7 @@
|
|
|
3478
3557
|
});
|
|
3479
3558
|
}
|
|
3480
3559
|
drawParticles(delta) {
|
|
3481
|
-
const { particles, actualOptions } = this.#container;
|
|
3482
|
-
this.clear();
|
|
3560
|
+
const { particles, actualOptions } = this.#container, clearedPlugin = this.clear();
|
|
3483
3561
|
particles.update(delta);
|
|
3484
3562
|
this.draw(ctx => {
|
|
3485
3563
|
const width = this.#canvasManager.size.width, height = this.#canvasManager.size.height;
|
|
@@ -3501,7 +3579,9 @@
|
|
|
3501
3579
|
}
|
|
3502
3580
|
}
|
|
3503
3581
|
for (const plugin of this.#getLayerPlugins(DrawLayer.BackgroundMask)) {
|
|
3504
|
-
plugin
|
|
3582
|
+
if (plugin !== clearedPlugin) {
|
|
3583
|
+
plugin.canvasPaint?.();
|
|
3584
|
+
}
|
|
3505
3585
|
}
|
|
3506
3586
|
for (const plugin of this.#getLayerPlugins(DrawLayer.CanvasSetup)) {
|
|
3507
3587
|
plugin.drawSettingsSetup?.(ctx, delta);
|
|
@@ -3533,35 +3613,7 @@
|
|
|
3533
3613
|
this.#layers[layer] = [];
|
|
3534
3614
|
}
|
|
3535
3615
|
}
|
|
3536
|
-
|
|
3537
|
-
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
3538
|
-
this.#colorPlugins.push(plugin);
|
|
3539
|
-
}
|
|
3540
|
-
if (plugin.drawParticle) {
|
|
3541
|
-
this.#drawParticlePlugins.push(plugin);
|
|
3542
|
-
}
|
|
3543
|
-
if (plugin.drawParticleSetup) {
|
|
3544
|
-
this.#drawParticlesSetupPlugins.push(plugin);
|
|
3545
|
-
}
|
|
3546
|
-
if (plugin.drawParticleCleanup) {
|
|
3547
|
-
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
3548
|
-
}
|
|
3549
|
-
if (plugin.canvasClear) {
|
|
3550
|
-
this.#canvasClearPlugins.push(plugin);
|
|
3551
|
-
}
|
|
3552
|
-
if (plugin.canvasPaint) {
|
|
3553
|
-
this.#getLayerPlugins(DrawLayer.BackgroundMask).push(plugin);
|
|
3554
|
-
}
|
|
3555
|
-
if (plugin.drawSettingsSetup) {
|
|
3556
|
-
this.#getLayerPlugins(DrawLayer.CanvasSetup).push(plugin);
|
|
3557
|
-
}
|
|
3558
|
-
if (plugin.draw) {
|
|
3559
|
-
this.#getLayerPlugins(DrawLayer.PluginContent).push(plugin);
|
|
3560
|
-
}
|
|
3561
|
-
if (plugin.clearDraw ?? plugin.drawSettingsCleanup) {
|
|
3562
|
-
this.#getLayerPlugins(DrawLayer.CanvasCleanup).push(plugin);
|
|
3563
|
-
}
|
|
3564
|
-
}
|
|
3616
|
+
this.#initPluginsArray();
|
|
3565
3617
|
}
|
|
3566
3618
|
initUpdaters() {
|
|
3567
3619
|
this.#preDrawUpdaters = [];
|
|
@@ -3770,6 +3822,45 @@
|
|
|
3770
3822
|
this.#reusablePluginColors[sColorIndex] = sColor;
|
|
3771
3823
|
return this.#reusablePluginColors;
|
|
3772
3824
|
}
|
|
3825
|
+
#initLayerPlugin(plugin) {
|
|
3826
|
+
const layerMap = [
|
|
3827
|
+
[DrawLayer.BackgroundMask, !!plugin.canvasPaint],
|
|
3828
|
+
[DrawLayer.CanvasSetup, !!plugin.drawSettingsSetup],
|
|
3829
|
+
[DrawLayer.PluginContent, !!plugin.draw],
|
|
3830
|
+
[DrawLayer.CanvasCleanup, !!(plugin.clearDraw ?? plugin.drawSettingsCleanup)],
|
|
3831
|
+
];
|
|
3832
|
+
for (const [layer, active] of layerMap) {
|
|
3833
|
+
if (active) {
|
|
3834
|
+
this.#layers[layer].push(plugin);
|
|
3835
|
+
}
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
#initPluginsArray() {
|
|
3839
|
+
for (const plugin of this.#container.plugins) {
|
|
3840
|
+
if (plugin.particleFillColor ?? plugin.particleStrokeColor) {
|
|
3841
|
+
this.#colorPlugins.push(plugin);
|
|
3842
|
+
}
|
|
3843
|
+
if (plugin.drawParticle) {
|
|
3844
|
+
this.#drawParticlePlugins.push(plugin);
|
|
3845
|
+
}
|
|
3846
|
+
if (plugin.drawParticleSetup) {
|
|
3847
|
+
this.#drawParticlesSetupPlugins.push(plugin);
|
|
3848
|
+
}
|
|
3849
|
+
if (plugin.drawParticleCleanup) {
|
|
3850
|
+
this.#drawParticlesCleanupPlugins.push(plugin);
|
|
3851
|
+
}
|
|
3852
|
+
if (plugin.canvasClear) {
|
|
3853
|
+
this.#canvasClearPlugins.push(plugin);
|
|
3854
|
+
}
|
|
3855
|
+
this.#initLayerPlugin(plugin);
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
#isSupportedElement(element) {
|
|
3859
|
+
return ((typeof HTMLCanvasElement !== "undefined" && element instanceof HTMLCanvasElement) ||
|
|
3860
|
+
(typeof OffscreenCanvas !== "undefined" && element instanceof OffscreenCanvas) ||
|
|
3861
|
+
(typeof HTMLVideoElement !== "undefined" && element instanceof HTMLVideoElement) ||
|
|
3862
|
+
(typeof HTMLImageElement !== "undefined" && element instanceof HTMLImageElement));
|
|
3863
|
+
}
|
|
3773
3864
|
#resolveBackgroundElement() {
|
|
3774
3865
|
const background = this.#container.actualOptions.background;
|
|
3775
3866
|
this.#backgroundElement = null;
|
|
@@ -3779,9 +3870,7 @@
|
|
|
3779
3870
|
if (typeof background.element === "string") {
|
|
3780
3871
|
if (typeof document !== "undefined") {
|
|
3781
3872
|
const node = document.querySelector(background.element);
|
|
3782
|
-
if (
|
|
3783
|
-
(typeof HTMLVideoElement !== "undefined" && node instanceof HTMLVideoElement) ||
|
|
3784
|
-
(typeof HTMLImageElement !== "undefined" && node instanceof HTMLImageElement)) {
|
|
3873
|
+
if (node && this.#isSupportedElement(node)) {
|
|
3785
3874
|
this.#backgroundElement = node;
|
|
3786
3875
|
}
|
|
3787
3876
|
else if (node) {
|
|
@@ -3792,10 +3881,7 @@
|
|
|
3792
3881
|
}
|
|
3793
3882
|
}
|
|
3794
3883
|
}
|
|
3795
|
-
else if ((
|
|
3796
|
-
(typeof OffscreenCanvas !== "undefined" && background.element instanceof OffscreenCanvas) ||
|
|
3797
|
-
(typeof HTMLVideoElement !== "undefined" && background.element instanceof HTMLVideoElement) ||
|
|
3798
|
-
(typeof HTMLImageElement !== "undefined" && background.element instanceof HTMLImageElement)) {
|
|
3884
|
+
else if (this.#isSupportedElement(background.element)) {
|
|
3799
3885
|
this.#backgroundElement = background.element;
|
|
3800
3886
|
}
|
|
3801
3887
|
}
|
|
@@ -3813,7 +3899,7 @@
|
|
|
3813
3899
|
return transferredCanvas;
|
|
3814
3900
|
}
|
|
3815
3901
|
if (typeof canvas.transferControlToOffscreen !== "function") {
|
|
3816
|
-
throw new TypeError(
|
|
3902
|
+
throw new TypeError(getErrorMessage(ErrorCodes$1.offscreenCanvasUnsupported));
|
|
3817
3903
|
}
|
|
3818
3904
|
try {
|
|
3819
3905
|
const offscreenCanvas = canvas.transferControlToOffscreen();
|
|
@@ -3821,10 +3907,16 @@
|
|
|
3821
3907
|
return offscreenCanvas;
|
|
3822
3908
|
}
|
|
3823
3909
|
catch {
|
|
3824
|
-
throw new TypeError(
|
|
3910
|
+
throw new TypeError(getErrorMessage(ErrorCodes$1.offscreenCanvasTransferFailed));
|
|
3825
3911
|
}
|
|
3826
3912
|
}, isHtmlCanvasElement = (canvas) => {
|
|
3827
3913
|
return typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement;
|
|
3914
|
+
}, getEffectiveColorSpace = (context) => {
|
|
3915
|
+
if (!context) {
|
|
3916
|
+
return undefined;
|
|
3917
|
+
}
|
|
3918
|
+
const colorInfo = context;
|
|
3919
|
+
return colorInfo.getContextAttributes?.().colorSpace ?? undefined;
|
|
3828
3920
|
};
|
|
3829
3921
|
function setStyle(canvas, style, important = false) {
|
|
3830
3922
|
if (!style) {
|
|
@@ -3949,7 +4041,7 @@
|
|
|
3949
4041
|
const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
|
|
3950
4042
|
if (color) {
|
|
3951
4043
|
const hdrOptions = container.actualOptions.hdr;
|
|
3952
|
-
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, hdrOptions.mode);
|
|
4044
|
+
elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard));
|
|
3953
4045
|
}
|
|
3954
4046
|
else {
|
|
3955
4047
|
elementStyle.backgroundColor = "";
|
|
@@ -4069,11 +4161,11 @@
|
|
|
4069
4161
|
const container = this.#container, canSupportHdr = container.actualOptions.hdr.enable &&
|
|
4070
4162
|
safeMatchMedia("(color-gamut: p3)")?.matches &&
|
|
4071
4163
|
safeMatchMedia("(dynamic-range: high)")?.matches;
|
|
4072
|
-
container.
|
|
4073
|
-
container.hdrMode = container.actualOptions.hdr.mode;
|
|
4164
|
+
container.hdrMode = toEnumValue(HdrMode, container.actualOptions.hdr.mode, HdrMode.standard);
|
|
4074
4165
|
container.peakNits = container.actualOptions.hdr.peakNits;
|
|
4075
4166
|
const renderCanvas = this.renderCanvas;
|
|
4076
4167
|
if (!renderCanvas) {
|
|
4168
|
+
container.hdr = canSupportHdr ?? false;
|
|
4077
4169
|
return;
|
|
4078
4170
|
}
|
|
4079
4171
|
this.render.setContextSettings({
|
|
@@ -4092,7 +4184,6 @@
|
|
|
4092
4184
|
context = null;
|
|
4093
4185
|
}
|
|
4094
4186
|
if (canSupportHdr && !context) {
|
|
4095
|
-
container.hdr = false;
|
|
4096
4187
|
const sdrSettings = {
|
|
4097
4188
|
alpha: true,
|
|
4098
4189
|
desynchronized: true,
|
|
@@ -4108,11 +4199,16 @@
|
|
|
4108
4199
|
}
|
|
4109
4200
|
}
|
|
4110
4201
|
this.render.setContext(context);
|
|
4202
|
+
if (context) {
|
|
4203
|
+
const effectiveColorSpace = getEffectiveColorSpace(context);
|
|
4204
|
+
if (effectiveColorSpace !== undefined) {
|
|
4205
|
+
container.hdr = effectiveColorSpace === "display-p3";
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4111
4208
|
}
|
|
4112
4209
|
#initHdrListeners() {
|
|
4113
4210
|
this.#removeHdrListeners();
|
|
4114
4211
|
const p3Query = safeMatchMedia("(color-gamut: p3)"), hdrQuery = safeMatchMedia("(dynamic-range: high)"), handleChange = () => {
|
|
4115
|
-
this.#recreateRenderCanvas();
|
|
4116
4212
|
this.#initContext();
|
|
4117
4213
|
this.initBackground();
|
|
4118
4214
|
}, listeners = [];
|
|
@@ -4148,16 +4244,6 @@
|
|
|
4148
4244
|
element.style.setProperty(key, value, "important");
|
|
4149
4245
|
}
|
|
4150
4246
|
}
|
|
4151
|
-
#recreateRenderCanvas() {
|
|
4152
|
-
const renderCanvas = this.renderCanvas;
|
|
4153
|
-
if (!renderCanvas) {
|
|
4154
|
-
return;
|
|
4155
|
-
}
|
|
4156
|
-
if (this.domElement) {
|
|
4157
|
-
return;
|
|
4158
|
-
}
|
|
4159
|
-
this.renderCanvas = new OffscreenCanvas(renderCanvas.width, renderCanvas.height);
|
|
4160
|
-
}
|
|
4161
4247
|
#removeHdrListeners() {
|
|
4162
4248
|
if (!this.#hdrMediaListeners) {
|
|
4163
4249
|
return;
|
|
@@ -4256,8 +4342,7 @@
|
|
|
4256
4342
|
this.#resizeTimeout = undefined;
|
|
4257
4343
|
}
|
|
4258
4344
|
const handleResize = async () => {
|
|
4259
|
-
|
|
4260
|
-
await canvas.windowResize();
|
|
4345
|
+
await this.#container.canvas.windowResize();
|
|
4261
4346
|
};
|
|
4262
4347
|
this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
|
|
4263
4348
|
}
|
|
@@ -4285,8 +4370,8 @@
|
|
|
4285
4370
|
}
|
|
4286
4371
|
else if (!this.#resizeObserver && add && canvasEl) {
|
|
4287
4372
|
this.#resizeObserver = new ResizeObserver((entries) => {
|
|
4288
|
-
const
|
|
4289
|
-
if (!
|
|
4373
|
+
const res = entries.some(e => e.target === canvasEl);
|
|
4374
|
+
if (!res) {
|
|
4290
4375
|
return;
|
|
4291
4376
|
}
|
|
4292
4377
|
this.#handleWindowResize();
|
|
@@ -4550,10 +4635,10 @@
|
|
|
4550
4635
|
return this.#modifiers.find(m => m.id === id);
|
|
4551
4636
|
}
|
|
4552
4637
|
getOpacity() {
|
|
4553
|
-
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
|
|
4554
|
-
this.#cachedOpacityData.fillOpacity = fillOpacity;
|
|
4638
|
+
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;
|
|
4639
|
+
this.#cachedOpacityData.fillOpacity = this.fillOpacity ?? defaultOpacity$1;
|
|
4555
4640
|
this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
4556
|
-
this.#cachedOpacityData.strokeOpacity = strokeOpacity;
|
|
4641
|
+
this.#cachedOpacityData.strokeOpacity = this.strokeOpacity ?? defaultOpacity$1;
|
|
4557
4642
|
return this.#cachedOpacityData;
|
|
4558
4643
|
}
|
|
4559
4644
|
getPosition() {
|
|
@@ -4800,7 +4885,7 @@
|
|
|
4800
4885
|
#initPosition(position) {
|
|
4801
4886
|
const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
|
|
4802
4887
|
if (!initialPosition) {
|
|
4803
|
-
throw new Error(
|
|
4888
|
+
throw new Error(getErrorMessage(ErrorCodes$1.particlePositionNotFound));
|
|
4804
4889
|
}
|
|
4805
4890
|
this.position = initialPosition;
|
|
4806
4891
|
this.initialPosition = this.position.copy();
|
|
@@ -4849,6 +4934,12 @@
|
|
|
4849
4934
|
this.#circlePoolIdx = 0;
|
|
4850
4935
|
this.#rectanglePoolIdx = 0;
|
|
4851
4936
|
}
|
|
4937
|
+
get cellSize() {
|
|
4938
|
+
return this.#cellSize;
|
|
4939
|
+
}
|
|
4940
|
+
set cellSize(value) {
|
|
4941
|
+
this.#pendingCellSize = value;
|
|
4942
|
+
}
|
|
4852
4943
|
clear() {
|
|
4853
4944
|
this.#cells.clear();
|
|
4854
4945
|
const pendingCellSize = this.#pendingCellSize;
|
|
@@ -4872,18 +4963,7 @@
|
|
|
4872
4963
|
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);
|
|
4873
4964
|
for (let cx = minCellX; cx <= maxCellX; cx++) {
|
|
4874
4965
|
for (let cy = minCellY; cy <= maxCellY; cy++) {
|
|
4875
|
-
|
|
4876
|
-
if (!cellParticles) {
|
|
4877
|
-
continue;
|
|
4878
|
-
}
|
|
4879
|
-
for (const p of cellParticles) {
|
|
4880
|
-
if (check && !check(p)) {
|
|
4881
|
-
continue;
|
|
4882
|
-
}
|
|
4883
|
-
if (range.contains(p.getPosition())) {
|
|
4884
|
-
out.push(p);
|
|
4885
|
-
}
|
|
4886
|
-
}
|
|
4966
|
+
this.#queryCell(cx, cy, range, check, out);
|
|
4887
4967
|
}
|
|
4888
4968
|
}
|
|
4889
4969
|
return out;
|
|
@@ -4898,14 +4978,23 @@
|
|
|
4898
4978
|
this.#releaseShapes();
|
|
4899
4979
|
return result;
|
|
4900
4980
|
}
|
|
4901
|
-
setCellSize(cellSize) {
|
|
4902
|
-
this.#pendingCellSize = cellSize;
|
|
4903
|
-
}
|
|
4904
4981
|
#acquireCircle(x, y, r) {
|
|
4905
|
-
|
|
4982
|
+
const idx = this.#circlePoolIdx++;
|
|
4983
|
+
let circle = this.#circlePool[idx];
|
|
4984
|
+
if (!circle) {
|
|
4985
|
+
circle = new Circle(x, y, r);
|
|
4986
|
+
this.#circlePool[idx] = circle;
|
|
4987
|
+
}
|
|
4988
|
+
return circle.reset(x, y, r);
|
|
4906
4989
|
}
|
|
4907
4990
|
#acquireRectangle(x, y, w, h) {
|
|
4908
|
-
|
|
4991
|
+
const idx = this.#rectanglePoolIdx++;
|
|
4992
|
+
let rectangle = this.#rectanglePool[idx];
|
|
4993
|
+
if (!rectangle) {
|
|
4994
|
+
rectangle = new Rectangle(x, y, w, h);
|
|
4995
|
+
this.#rectanglePool[idx] = rectangle;
|
|
4996
|
+
}
|
|
4997
|
+
return rectangle.reset(x, y, w, h);
|
|
4909
4998
|
}
|
|
4910
4999
|
#cellKeyFromCoords(x, y) {
|
|
4911
5000
|
const cellX = Math.floor(x / this.#cellSize), cellY = Math.floor(y / this.#cellSize);
|
|
@@ -4932,6 +5021,20 @@
|
|
|
4932
5021
|
}
|
|
4933
5022
|
return null;
|
|
4934
5023
|
}
|
|
5024
|
+
#queryCell(cx, cy, range, check, out) {
|
|
5025
|
+
const cellParticles = this.#cells.get(`${cx}_${cy}`);
|
|
5026
|
+
if (!cellParticles) {
|
|
5027
|
+
return;
|
|
5028
|
+
}
|
|
5029
|
+
for (const p of cellParticles) {
|
|
5030
|
+
if (check && !check(p)) {
|
|
5031
|
+
continue;
|
|
5032
|
+
}
|
|
5033
|
+
if (range.contains(p.getPosition())) {
|
|
5034
|
+
out.push(p);
|
|
5035
|
+
}
|
|
5036
|
+
}
|
|
5037
|
+
}
|
|
4935
5038
|
#releaseShapes() {
|
|
4936
5039
|
this.#circlePoolIdx = 0;
|
|
4937
5040
|
this.#rectanglePoolIdx = 0;
|
|
@@ -4940,9 +5043,9 @@
|
|
|
4940
5043
|
|
|
4941
5044
|
class ParticlesManager {
|
|
4942
5045
|
checkParticlePositionPlugins;
|
|
4943
|
-
grid;
|
|
4944
5046
|
#array;
|
|
4945
5047
|
#container;
|
|
5048
|
+
#grid;
|
|
4946
5049
|
#groupLimits;
|
|
4947
5050
|
#limit;
|
|
4948
5051
|
#nextId;
|
|
@@ -4966,7 +5069,7 @@
|
|
|
4966
5069
|
this.#groupLimits = new Map();
|
|
4967
5070
|
this.#particleBuckets = new Map();
|
|
4968
5071
|
this.#zBuckets = this.#createBuckets(this.#container.zLayers);
|
|
4969
|
-
this
|
|
5072
|
+
this.#grid = new SpatialHashGrid(spatialHashGridCellSize);
|
|
4970
5073
|
this.checkParticlePositionPlugins = [];
|
|
4971
5074
|
this.#particleResetPlugins = [];
|
|
4972
5075
|
this.#particleUpdatePlugins = [];
|
|
@@ -4977,23 +5080,12 @@
|
|
|
4977
5080
|
get count() {
|
|
4978
5081
|
return this.#array.length;
|
|
4979
5082
|
}
|
|
5083
|
+
get grid() {
|
|
5084
|
+
return this.#grid;
|
|
5085
|
+
}
|
|
4980
5086
|
addParticle(position, overrideOptions, group, initializer) {
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
switch (limitMode) {
|
|
4984
|
-
case LimitMode.delete: {
|
|
4985
|
-
const countToRemove = currentCount + countOffset - limit;
|
|
4986
|
-
if (countToRemove > minCount) {
|
|
4987
|
-
this.removeQuantity(countToRemove);
|
|
4988
|
-
}
|
|
4989
|
-
break;
|
|
4990
|
-
}
|
|
4991
|
-
case LimitMode.wait:
|
|
4992
|
-
if (currentCount >= limit) {
|
|
4993
|
-
return;
|
|
4994
|
-
}
|
|
4995
|
-
break;
|
|
4996
|
-
}
|
|
5087
|
+
if (this.#checkAndApplyLimits(group, this.count)) {
|
|
5088
|
+
return;
|
|
4997
5089
|
}
|
|
4998
5090
|
try {
|
|
4999
5091
|
const particle = this.#pool.pop() ?? new Particle(this.#pluginManager, this.#container);
|
|
@@ -5057,7 +5149,7 @@
|
|
|
5057
5149
|
return this.#array[index];
|
|
5058
5150
|
}
|
|
5059
5151
|
async init() {
|
|
5060
|
-
const container = this.#container
|
|
5152
|
+
const container = this.#container;
|
|
5061
5153
|
this.checkParticlePositionPlugins = [];
|
|
5062
5154
|
this.#updatePlugins = [];
|
|
5063
5155
|
this.#particleUpdatePlugins = [];
|
|
@@ -5066,59 +5158,16 @@
|
|
|
5066
5158
|
this.#postParticleUpdatePlugins = [];
|
|
5067
5159
|
this.#particleBuckets.clear();
|
|
5068
5160
|
this.#resetBuckets(container.zLayers);
|
|
5069
|
-
this
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
if (
|
|
5075
|
-
this
|
|
5076
|
-
}
|
|
5077
|
-
if (plugin.update) {
|
|
5078
|
-
this.#updatePlugins.push(plugin);
|
|
5079
|
-
}
|
|
5080
|
-
if (plugin.particleUpdate) {
|
|
5081
|
-
this.#particleUpdatePlugins.push(plugin);
|
|
5082
|
-
}
|
|
5083
|
-
if (plugin.postUpdate) {
|
|
5084
|
-
this.#postUpdatePlugins.push(plugin);
|
|
5085
|
-
}
|
|
5086
|
-
if (plugin.particleReset) {
|
|
5087
|
-
this.#particleResetPlugins.push(plugin);
|
|
5088
|
-
}
|
|
5089
|
-
if (plugin.postParticleUpdate) {
|
|
5090
|
-
this.#postParticleUpdatePlugins.push(plugin);
|
|
5091
|
-
}
|
|
5092
|
-
}
|
|
5093
|
-
await this.#container.initDrawersAndUpdaters();
|
|
5094
|
-
for (const drawer of this.#container.effectDrawers.values()) {
|
|
5095
|
-
await drawer.init?.(container);
|
|
5096
|
-
}
|
|
5097
|
-
for (const drawer of this.#container.shapeDrawers.values()) {
|
|
5098
|
-
await drawer.init?.(container);
|
|
5099
|
-
}
|
|
5100
|
-
let handled = false;
|
|
5101
|
-
for (const plugin of container.plugins) {
|
|
5102
|
-
handled = plugin.particlesInitialization?.() ?? handled;
|
|
5103
|
-
if (handled) {
|
|
5104
|
-
break;
|
|
5105
|
-
}
|
|
5106
|
-
}
|
|
5107
|
-
if (!handled) {
|
|
5108
|
-
const particlesOptions = options.particles, groups = particlesOptions.groups;
|
|
5109
|
-
for (const group in groups) {
|
|
5110
|
-
const groupOptions = groups[group];
|
|
5111
|
-
if (!groupOptions) {
|
|
5112
|
-
continue;
|
|
5113
|
-
}
|
|
5114
|
-
for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
|
|
5115
|
-
this.addParticle(undefined, groupOptions, group);
|
|
5116
|
-
}
|
|
5117
|
-
}
|
|
5118
|
-
for (let i = this.count; i < particlesOptions.number.value; i++) {
|
|
5119
|
-
this.addParticle();
|
|
5161
|
+
this.#grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
|
|
5162
|
+
this.#applyLimits(container.actualOptions.particles);
|
|
5163
|
+
const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
|
|
5164
|
+
for (const group in groups) {
|
|
5165
|
+
const groupData = groups[group];
|
|
5166
|
+
if (groupData) {
|
|
5167
|
+
this.#applyLimits(loadParticlesOptions(this.#pluginManager, this.#container, groupData), group, groupData);
|
|
5120
5168
|
}
|
|
5121
5169
|
}
|
|
5170
|
+
await this.#initPlugins();
|
|
5122
5171
|
}
|
|
5123
5172
|
push(nb, position, overrideOptions, group) {
|
|
5124
5173
|
for (let i = 0; i < nb; i++) {
|
|
@@ -5133,13 +5182,13 @@
|
|
|
5133
5182
|
remove(particle, group, override) {
|
|
5134
5183
|
this.removeAt(this.#array.indexOf(particle), undefined, group, override);
|
|
5135
5184
|
}
|
|
5136
|
-
removeAt(index, quantity = defaultRemoveQuantity, group, override) {
|
|
5185
|
+
removeAt(index, quantity = defaultRemoveQuantity, group, override, matchGroup = true) {
|
|
5137
5186
|
if (index < minIndex || index > this.count) {
|
|
5138
5187
|
return;
|
|
5139
5188
|
}
|
|
5140
5189
|
let deleted = 0;
|
|
5141
5190
|
for (let i = index; deleted < quantity && i < this.count; i++) {
|
|
5142
|
-
if (this.#removeParticle(i, group, override)) {
|
|
5191
|
+
if (this.#removeParticle(i, group, override, matchGroup)) {
|
|
5143
5192
|
i--;
|
|
5144
5193
|
deleted++;
|
|
5145
5194
|
}
|
|
@@ -5170,7 +5219,7 @@
|
|
|
5170
5219
|
this.#resizeFactor = factor;
|
|
5171
5220
|
}
|
|
5172
5221
|
update(delta) {
|
|
5173
|
-
this
|
|
5222
|
+
this.#grid.clear();
|
|
5174
5223
|
for (const plugin of this.#updatePlugins) {
|
|
5175
5224
|
plugin.update?.(delta);
|
|
5176
5225
|
}
|
|
@@ -5181,7 +5230,7 @@
|
|
|
5181
5230
|
this.#updateParticlesPhase2(delta, particlesToDelete);
|
|
5182
5231
|
if (particlesToDelete.size) {
|
|
5183
5232
|
for (const particle of particlesToDelete) {
|
|
5184
|
-
this.remove(particle);
|
|
5233
|
+
this.remove(particle, particle.group);
|
|
5185
5234
|
}
|
|
5186
5235
|
}
|
|
5187
5236
|
this.#resizeFactor = undefined;
|
|
@@ -5192,12 +5241,7 @@
|
|
|
5192
5241
|
#applyDensity(options, pluginsCount, group, groupOptions) {
|
|
5193
5242
|
const numberOptions = options.number;
|
|
5194
5243
|
if (!numberOptions.density.enable) {
|
|
5195
|
-
|
|
5196
|
-
this.#limit = numberOptions.limit.value;
|
|
5197
|
-
}
|
|
5198
|
-
else if (groupOptions?.number.limit.value ?? numberOptions.limit.value) {
|
|
5199
|
-
this.#groupLimits.set(group, groupOptions?.number.limit.value ?? numberOptions.limit.value);
|
|
5200
|
-
}
|
|
5244
|
+
this.#applyLimits(options, group, groupOptions);
|
|
5201
5245
|
return;
|
|
5202
5246
|
}
|
|
5203
5247
|
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);
|
|
@@ -5205,7 +5249,10 @@
|
|
|
5205
5249
|
this.#limit = numberOptions.limit.value * densityFactor;
|
|
5206
5250
|
}
|
|
5207
5251
|
else {
|
|
5208
|
-
this.#groupLimits.set(group,
|
|
5252
|
+
this.#groupLimits.set(group, {
|
|
5253
|
+
limit: numberOptions.limit.value * densityFactor,
|
|
5254
|
+
mode: toEnumValue(LimitMode, numberOptions.limit.mode, LimitMode.delete),
|
|
5255
|
+
});
|
|
5209
5256
|
}
|
|
5210
5257
|
if (particlesCount < particlesNumber) {
|
|
5211
5258
|
this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
|
@@ -5214,6 +5261,55 @@
|
|
|
5214
5261
|
this.removeQuantity(particlesCount - particlesNumber, group);
|
|
5215
5262
|
}
|
|
5216
5263
|
}
|
|
5264
|
+
#applyLimits(options, group, groupOptions) {
|
|
5265
|
+
if (group === undefined) {
|
|
5266
|
+
this.#limit = options.number.limit.value;
|
|
5267
|
+
const groups = this.#container.actualOptions.particles.groups;
|
|
5268
|
+
for (const existingGroup of this.#groupLimits.keys()) {
|
|
5269
|
+
if (!(existingGroup in groups)) {
|
|
5270
|
+
this.#groupLimits.delete(existingGroup);
|
|
5271
|
+
}
|
|
5272
|
+
}
|
|
5273
|
+
}
|
|
5274
|
+
else {
|
|
5275
|
+
const limitValue = groupOptions?.number?.limit?.value ?? options.number.limit.value;
|
|
5276
|
+
if (limitValue > minLimit) {
|
|
5277
|
+
this.#groupLimits.set(group, {
|
|
5278
|
+
limit: limitValue,
|
|
5279
|
+
mode: toEnumValue(LimitMode, groupOptions?.number?.limit?.mode ?? options.number.limit.mode, LimitMode.delete),
|
|
5280
|
+
});
|
|
5281
|
+
}
|
|
5282
|
+
else {
|
|
5283
|
+
this.#groupLimits.delete(group);
|
|
5284
|
+
}
|
|
5285
|
+
}
|
|
5286
|
+
}
|
|
5287
|
+
#checkAndApplyLimits(group, currentCount) {
|
|
5288
|
+
const globalLimit = this.#limit, globalMode = this.#container.actualOptions.particles.number.limit.mode;
|
|
5289
|
+
if (globalLimit > minLimit && globalMode === LimitMode.wait && currentCount >= globalLimit) {
|
|
5290
|
+
return true;
|
|
5291
|
+
}
|
|
5292
|
+
const groupLimitEntry = group === undefined ? undefined : this.#groupLimits.get(group);
|
|
5293
|
+
if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.wait) {
|
|
5294
|
+
const groupCount = this.filter(t => t.group === group).length;
|
|
5295
|
+
if (groupCount >= groupLimitEntry.limit) {
|
|
5296
|
+
return true;
|
|
5297
|
+
}
|
|
5298
|
+
}
|
|
5299
|
+
if (groupLimitEntry && groupLimitEntry.limit > minLimit && groupLimitEntry.mode === LimitMode.delete) {
|
|
5300
|
+
const groupCountToRemove = this.filter(t => t.group === group).length + countOffset - groupLimitEntry.limit;
|
|
5301
|
+
if (groupCountToRemove > minCount) {
|
|
5302
|
+
this.removeQuantity(groupCountToRemove, group);
|
|
5303
|
+
}
|
|
5304
|
+
}
|
|
5305
|
+
if (globalLimit > minLimit && globalMode === LimitMode.delete) {
|
|
5306
|
+
const globalCountToRemove = this.count + countOffset - globalLimit;
|
|
5307
|
+
if (globalCountToRemove > minCount) {
|
|
5308
|
+
this.#removeAny(globalCountToRemove);
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
return false;
|
|
5312
|
+
}
|
|
5217
5313
|
#createBuckets(zLayers) {
|
|
5218
5314
|
const bucketCount = Math.max(Math.floor(zLayers), one);
|
|
5219
5315
|
return Array.from({ length: bucketCount }, () => []);
|
|
@@ -5236,6 +5332,70 @@
|
|
|
5236
5332
|
}
|
|
5237
5333
|
return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
|
|
5238
5334
|
}
|
|
5335
|
+
async #initDrawersAndUpdaters() {
|
|
5336
|
+
const container = this.#container;
|
|
5337
|
+
await container.initDrawersAndUpdaters();
|
|
5338
|
+
for (const drawer of container.effectDrawers.values()) {
|
|
5339
|
+
await drawer.init?.(container);
|
|
5340
|
+
}
|
|
5341
|
+
for (const drawer of container.shapeDrawers.values()) {
|
|
5342
|
+
await drawer.init?.(container);
|
|
5343
|
+
}
|
|
5344
|
+
}
|
|
5345
|
+
async #initPlugins() {
|
|
5346
|
+
await this.#initPluginsArrays();
|
|
5347
|
+
await this.#initDrawersAndUpdaters();
|
|
5348
|
+
let handled = false;
|
|
5349
|
+
const container = this.#container;
|
|
5350
|
+
for (const plugin of container.plugins) {
|
|
5351
|
+
handled = plugin.particlesInitialization?.() ?? handled;
|
|
5352
|
+
if (handled) {
|
|
5353
|
+
break;
|
|
5354
|
+
}
|
|
5355
|
+
}
|
|
5356
|
+
if (handled) {
|
|
5357
|
+
return;
|
|
5358
|
+
}
|
|
5359
|
+
const particlesOptions = container.actualOptions.particles, groups = particlesOptions.groups;
|
|
5360
|
+
for (const group in groups) {
|
|
5361
|
+
const groupOptions = groups[group];
|
|
5362
|
+
if (!groupOptions) {
|
|
5363
|
+
continue;
|
|
5364
|
+
}
|
|
5365
|
+
for (let i = this.count, j = 0; j < groupOptions.number.value && i < particlesOptions.number.value; i++, j++) {
|
|
5366
|
+
this.addParticle(undefined, groupOptions, group);
|
|
5367
|
+
}
|
|
5368
|
+
}
|
|
5369
|
+
for (let i = this.count; i < particlesOptions.number.value; i++) {
|
|
5370
|
+
this.addParticle();
|
|
5371
|
+
}
|
|
5372
|
+
}
|
|
5373
|
+
async #initPluginsArrays() {
|
|
5374
|
+
const container = this.#container;
|
|
5375
|
+
for (const plugin of container.plugins) {
|
|
5376
|
+
if (plugin.redrawInit) {
|
|
5377
|
+
await plugin.redrawInit();
|
|
5378
|
+
}
|
|
5379
|
+
if (plugin.checkParticlePosition) {
|
|
5380
|
+
this.checkParticlePositionPlugins.push(plugin);
|
|
5381
|
+
}
|
|
5382
|
+
if (plugin.update) {
|
|
5383
|
+
this.#updatePlugins.push(plugin);
|
|
5384
|
+
}
|
|
5385
|
+
if (plugin.particleUpdate) {
|
|
5386
|
+
this.#particleUpdatePlugins.push(plugin);
|
|
5387
|
+
}
|
|
5388
|
+
if (plugin.postUpdate) {
|
|
5389
|
+
this.#postUpdatePlugins.push(plugin);
|
|
5390
|
+
}
|
|
5391
|
+
if (plugin.particleReset) {
|
|
5392
|
+
this.#particleResetPlugins.push(plugin);
|
|
5393
|
+
}
|
|
5394
|
+
if (plugin.postParticleUpdate) {
|
|
5395
|
+
this.#postParticleUpdatePlugins.push(plugin);
|
|
5396
|
+
}
|
|
5397
|
+
}
|
|
5398
|
+
}
|
|
5239
5399
|
#insertParticleIntoBucket(particle) {
|
|
5240
5400
|
const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
|
|
5241
5401
|
if (!bucket) {
|
|
@@ -5244,12 +5404,15 @@
|
|
|
5244
5404
|
bucket.push(particle);
|
|
5245
5405
|
this.#particleBuckets.set(particle.id, bucketIndex);
|
|
5246
5406
|
}
|
|
5247
|
-
#
|
|
5407
|
+
#removeAny(quantity) {
|
|
5408
|
+
this.removeAt(minIndex, quantity, undefined, undefined, false);
|
|
5409
|
+
}
|
|
5410
|
+
#removeParticle(index, group, override, matchGroup = true) {
|
|
5248
5411
|
const particle = this.#array[index];
|
|
5249
5412
|
if (!particle) {
|
|
5250
5413
|
return false;
|
|
5251
5414
|
}
|
|
5252
|
-
if (particle.group !== group) {
|
|
5415
|
+
if (matchGroup && particle.group !== group) {
|
|
5253
5416
|
return false;
|
|
5254
5417
|
}
|
|
5255
5418
|
this.#array.splice(index, deleteCount);
|
|
@@ -5336,7 +5499,7 @@
|
|
|
5336
5499
|
particlesToDelete.add(particle);
|
|
5337
5500
|
continue;
|
|
5338
5501
|
}
|
|
5339
|
-
this
|
|
5502
|
+
this.#grid.insert(particle);
|
|
5340
5503
|
}
|
|
5341
5504
|
return particlesToDelete;
|
|
5342
5505
|
}
|
|
@@ -5512,7 +5675,6 @@
|
|
|
5512
5675
|
this.shapeDrawers = new Map();
|
|
5513
5676
|
this.particleUpdaters = [];
|
|
5514
5677
|
this.plugins.length = 0;
|
|
5515
|
-
this.#pluginManager.clearPlugins(this);
|
|
5516
5678
|
this.destroyed = true;
|
|
5517
5679
|
this.#onDestroy(remove);
|
|
5518
5680
|
this.dispatchEvent(EventType.containerDestroyed);
|
|
@@ -5565,31 +5727,14 @@
|
|
|
5565
5727
|
await this.initDrawersAndUpdaters();
|
|
5566
5728
|
this.#options = loadContainerOptions(this.#pluginManager, this, this.#initialSourceOptions, this.sourceOptions);
|
|
5567
5729
|
this.actualOptions = loadContainerOptions(this.#pluginManager, this, this.#options);
|
|
5568
|
-
this
|
|
5569
|
-
this.particleDestroyedPlugins.length = 0;
|
|
5570
|
-
this.particleCreatedPlugins.length = 0;
|
|
5571
|
-
this.particlePositionPlugins.length = 0;
|
|
5572
|
-
for (const [plugin, containerPlugin] of allContainerPlugins) {
|
|
5573
|
-
if (plugin.needsPlugin(this.actualOptions)) {
|
|
5574
|
-
this.plugins.push(containerPlugin);
|
|
5575
|
-
if (containerPlugin.particleCreated) {
|
|
5576
|
-
this.particleCreatedPlugins.push(containerPlugin);
|
|
5577
|
-
}
|
|
5578
|
-
if (containerPlugin.particleDestroyed) {
|
|
5579
|
-
this.particleDestroyedPlugins.push(containerPlugin);
|
|
5580
|
-
}
|
|
5581
|
-
if (containerPlugin.particlePosition) {
|
|
5582
|
-
this.particlePositionPlugins.push(containerPlugin);
|
|
5583
|
-
}
|
|
5584
|
-
}
|
|
5585
|
-
}
|
|
5730
|
+
this.#initPlugins(allContainerPlugins);
|
|
5586
5731
|
this.retina.init();
|
|
5587
5732
|
this.canvas.init();
|
|
5588
5733
|
this.updateActualOptions();
|
|
5589
5734
|
this.canvas.initBackground();
|
|
5590
5735
|
this.canvas.resize();
|
|
5591
5736
|
const { delay, duration, fpsLimit, smooth, zLayers } = this.actualOptions, hdrOptions = this.actualOptions.hdr;
|
|
5592
|
-
this.hdrMode = hdrOptions.mode;
|
|
5737
|
+
this.hdrMode = toEnumValue(HdrMode, hdrOptions.mode, HdrMode.standard);
|
|
5593
5738
|
this.peakNits = hdrOptions.peakNits;
|
|
5594
5739
|
this.zLayers = zLayers;
|
|
5595
5740
|
this.#duration = getRangeValue(duration) * millisecondsToSeconds;
|
|
@@ -5610,9 +5755,9 @@
|
|
|
5610
5755
|
}
|
|
5611
5756
|
async initDrawersAndUpdaters() {
|
|
5612
5757
|
const pluginManager = this.#pluginManager;
|
|
5613
|
-
this.effectDrawers = await
|
|
5614
|
-
this.shapeDrawers = await
|
|
5615
|
-
this.particleUpdaters = await
|
|
5758
|
+
this.effectDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.effects);
|
|
5759
|
+
this.shapeDrawers = await getItemMapFromInitializer(this, pluginManager.initializers.shapes);
|
|
5760
|
+
this.particleUpdaters = await getItemsFromInitializer(this, pluginManager.initializers.updaters);
|
|
5616
5761
|
}
|
|
5617
5762
|
pause() {
|
|
5618
5763
|
if (!guardCheck(this)) {
|
|
@@ -5723,6 +5868,27 @@
|
|
|
5723
5868
|
}
|
|
5724
5869
|
return refresh;
|
|
5725
5870
|
}
|
|
5871
|
+
#initPlugins(allContainerPlugins) {
|
|
5872
|
+
this.plugins.length = 0;
|
|
5873
|
+
this.particleDestroyedPlugins.length = 0;
|
|
5874
|
+
this.particleCreatedPlugins.length = 0;
|
|
5875
|
+
this.particlePositionPlugins.length = 0;
|
|
5876
|
+
for (const [plugin, containerPlugin] of allContainerPlugins) {
|
|
5877
|
+
if (!plugin.needsPlugin(this.actualOptions)) {
|
|
5878
|
+
continue;
|
|
5879
|
+
}
|
|
5880
|
+
this.plugins.push(containerPlugin);
|
|
5881
|
+
if (containerPlugin.particleCreated) {
|
|
5882
|
+
this.particleCreatedPlugins.push(containerPlugin);
|
|
5883
|
+
}
|
|
5884
|
+
if (containerPlugin.particleDestroyed) {
|
|
5885
|
+
this.particleDestroyedPlugins.push(containerPlugin);
|
|
5886
|
+
}
|
|
5887
|
+
if (containerPlugin.particlePosition) {
|
|
5888
|
+
this.particlePositionPlugins.push(containerPlugin);
|
|
5889
|
+
}
|
|
5890
|
+
}
|
|
5891
|
+
}
|
|
5726
5892
|
#nextFrame(timestamp) {
|
|
5727
5893
|
try {
|
|
5728
5894
|
if (!this.#smooth &&
|
|
@@ -5999,11 +6165,11 @@
|
|
|
5999
6165
|
}
|
|
6000
6166
|
}
|
|
6001
6167
|
async #init() {
|
|
6002
|
-
const
|
|
6003
|
-
if (!
|
|
6168
|
+
const pluginManager = this.#pluginManager;
|
|
6169
|
+
if (!pluginManager.initializers.pathGenerators) {
|
|
6004
6170
|
return;
|
|
6005
6171
|
}
|
|
6006
|
-
this.availablePathGenerators =
|
|
6172
|
+
this.availablePathGenerators = await getItemMapFromInitializer(this.#container, pluginManager.initializers.pathGenerators);
|
|
6007
6173
|
this.pathGenerators = new Map();
|
|
6008
6174
|
for (const pathGenerator of this.pathGenerators.values()) {
|
|
6009
6175
|
pathGenerator.init();
|
|
@@ -6019,6 +6185,7 @@
|
|
|
6019
6185
|
exports.loadSnowPreset = loadSnowPreset;
|
|
6020
6186
|
exports.tsParticles = tsParticles;
|
|
6021
6187
|
|
|
6022
|
-
}));
|
|
6188
|
+
})(g.__tsParticlesInternals.presets.snow = g.__tsParticlesInternals.presets.snow || {});
|
|
6189
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : self);
|
|
6190
|
+
|
|
6023
6191
|
Object.assign(globalThis.window || globalThis, { loadSnowPreset: (globalThis.__tsParticlesInternals.presets.snow || {}).loadSnowPreset });
|
|
6024
|
-
delete (globalThis.window || globalThis).tsparticlesInternalExports;
|