@tsparticles/preset-ambient 4.1.2 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  (function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
2
- /* Preset v4.1.2 */
2
+ /* Preset v4.2.0 */
3
3
  (function (global, factory) {
4
4
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
5
5
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
@@ -15,7 +15,7 @@
15
15
  b: 0,
16
16
  c: 0,
17
17
  d: 1,
18
- }, randomColorValue = "random", double = 2, doublePI = Math.PI * double, defaultFps = 60, 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, 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 = 1, minStrokeWidth = 0, lFactor = 1, lMin = 0, triple = 3, sextuple = 6, sNormalizedOffset = 1, phaseNumerator = 1, defaultRgbMin = 0, defaultVelocity = 0, defaultLoops = 0, defaultTime = 0, defaultZoom = 1;
18
+ }, randomColorValue = "random", double = 2, doublePI = Math.PI * double, defaultFps = 60, 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, 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;
19
19
 
20
20
  var MoveDirection;
21
21
  (function (MoveDirection) {
@@ -82,11 +82,6 @@
82
82
  div(n) {
83
83
  return Vector3d.create(this.x / n, this.y / n, this.z / n);
84
84
  }
85
- divTo(n) {
86
- this.x /= n;
87
- this.y /= n;
88
- this.z /= n;
89
- }
90
85
  getLengthSq() {
91
86
  return this.x ** squareExp + this.y ** squareExp;
92
87
  }
@@ -282,27 +277,6 @@
282
277
  return input.endsWith("%") ? parseFloat(input) / percentDenominator : parseFloat(input);
283
278
  }
284
279
 
285
- var AnimationMode;
286
- (function (AnimationMode) {
287
- AnimationMode["auto"] = "auto";
288
- AnimationMode["increase"] = "increase";
289
- AnimationMode["decrease"] = "decrease";
290
- AnimationMode["random"] = "random";
291
- })(AnimationMode || (AnimationMode = {}));
292
-
293
- var AnimationStatus;
294
- (function (AnimationStatus) {
295
- AnimationStatus["increasing"] = "increasing";
296
- AnimationStatus["decreasing"] = "decreasing";
297
- })(AnimationStatus || (AnimationStatus = {}));
298
-
299
- var DestroyType;
300
- (function (DestroyType) {
301
- DestroyType["none"] = "none";
302
- DestroyType["max"] = "max";
303
- DestroyType["min"] = "min";
304
- })(DestroyType || (DestroyType = {}));
305
-
306
280
  var OutModeDirection;
307
281
  (function (OutModeDirection) {
308
282
  OutModeDirection["bottom"] = "bottom";
@@ -317,67 +291,7 @@
317
291
  PixelMode["percent"] = "percent";
318
292
  })(PixelMode || (PixelMode = {}));
319
293
 
320
- var StartValueType;
321
- (function (StartValueType) {
322
- StartValueType["max"] = "max";
323
- StartValueType["min"] = "min";
324
- StartValueType["random"] = "random";
325
- })(StartValueType || (StartValueType = {}));
326
-
327
294
  const minRadius = 0;
328
- function memoize(fn, options) {
329
- const cache = new Map(), stableStringify = (obj, seen = new WeakSet()) => {
330
- if (obj === null) {
331
- return "null";
332
- }
333
- const t = typeof obj;
334
- if (t === "undefined") {
335
- return "undefined";
336
- }
337
- if (t === "number" || t === "boolean" || t === "string") {
338
- return JSON.stringify(obj);
339
- }
340
- if (t === "function") {
341
- try {
342
- const fn = obj;
343
- return fn.toString();
344
- }
345
- catch {
346
- return '"[Function]"';
347
- }
348
- }
349
- if (t === "symbol") {
350
- try {
351
- return obj.toString();
352
- }
353
- catch {
354
- return '"[Symbol]"';
355
- }
356
- }
357
- if (Array.isArray(obj)) {
358
- return `[${obj.map(i => stableStringify(i, seen)).join(",")}]`;
359
- }
360
- if (seen.has(obj)) {
361
- return '"[Circular]"';
362
- }
363
- seen.add(obj);
364
- const keys = Object.keys(obj).sort();
365
- return `{${keys.map(k => `${JSON.stringify(k)}:${stableStringify(obj[k], seen)}`).join(",")}}`;
366
- }, defaultKeyer = (args) => stableStringify(args), makeKey = (args) => (defaultKeyer(args));
367
- return (...args) => {
368
- const key = makeKey(args), now = Date.now(), entry = cache.get(key);
369
- if (entry !== undefined) {
370
- {
371
- cache.delete(key);
372
- cache.set(key, { value: entry.value, ts: entry.ts });
373
- return entry.value;
374
- }
375
- }
376
- const result = fn(...args);
377
- cache.set(key, { value: result, ts: now });
378
- return result;
379
- };
380
- }
381
295
  function hasMatchMedia() {
382
296
  return typeof matchMedia !== "undefined";
383
297
  }
@@ -399,11 +313,8 @@
399
313
  function isInArray(value, array) {
400
314
  return value === array || (isArray(array) && array.includes(value));
401
315
  }
402
- function arrayRandomIndex(array) {
403
- return Math.floor(getRandom() * array.length);
404
- }
405
316
  function itemFromArray(array, index, useIndex = true) {
406
- return array[index !== undefined && useIndex ? index % array.length : arrayRandomIndex(array)];
317
+ return array[index !== undefined && useIndex ? index % array.length : Math.floor(getRandom() * array.length)];
407
318
  }
408
319
  function isPointInside(point, size, offset, radius, direction) {
409
320
  return areBoundsInside(calculateBounds(point, radius ?? minRadius), size, offset, direction);
@@ -487,56 +398,6 @@
487
398
  function itemFromSingleOrMultiple(obj, index, useIndex) {
488
399
  return isArray(obj) ? itemFromArray(obj, index, useIndex) : obj;
489
400
  }
490
- function initParticleNumericAnimationValue(options, pxRatio) {
491
- const valueRange = options.value, animationOptions = options.animation, res = {
492
- delayTime: getRangeValue(animationOptions.delay) * millisecondsToSeconds,
493
- enable: animationOptions.enable,
494
- value: getRangeValue(options.value) * pxRatio,
495
- max: getRangeMax(valueRange) * pxRatio,
496
- min: getRangeMin(valueRange) * pxRatio,
497
- loops: 0,
498
- maxLoops: getRangeValue(animationOptions.count),
499
- time: 0,
500
- }, decayOffset = 1;
501
- if (animationOptions.enable) {
502
- res.decay = decayOffset - getRangeValue(animationOptions.decay);
503
- switch (animationOptions.mode) {
504
- case AnimationMode.increase:
505
- res.status = AnimationStatus.increasing;
506
- break;
507
- case AnimationMode.decrease:
508
- res.status = AnimationStatus.decreasing;
509
- break;
510
- case AnimationMode.random:
511
- res.status = getRandom() >= half ? AnimationStatus.increasing : AnimationStatus.decreasing;
512
- break;
513
- }
514
- const autoStatus = animationOptions.mode === AnimationMode.auto;
515
- switch (animationOptions.startValue) {
516
- case StartValueType.min:
517
- res.value = res.min;
518
- if (autoStatus) {
519
- res.status = AnimationStatus.increasing;
520
- }
521
- break;
522
- case StartValueType.max:
523
- res.value = res.max;
524
- if (autoStatus) {
525
- res.status = AnimationStatus.decreasing;
526
- }
527
- break;
528
- case StartValueType.random:
529
- default:
530
- res.value = randomInRangeValue(res);
531
- if (autoStatus) {
532
- res.status = getRandom() >= half ? AnimationStatus.increasing : AnimationStatus.decreasing;
533
- }
534
- break;
535
- }
536
- }
537
- res.initialValue = res.value;
538
- return res;
539
- }
540
401
  function getPositionOrSize(positionOrSize, canvasSize) {
541
402
  const isPercent = positionOrSize.mode === PixelMode.percent;
542
403
  if (!isPercent) {
@@ -560,71 +421,6 @@
560
421
  function getPosition(position, canvasSize) {
561
422
  return getPositionOrSize(position, canvasSize);
562
423
  }
563
- function checkDestroy(particle, destroyType, value, minValue, maxValue) {
564
- switch (destroyType) {
565
- case DestroyType.max:
566
- if (value >= maxValue) {
567
- particle.destroy();
568
- }
569
- break;
570
- case DestroyType.min:
571
- if (value <= minValue) {
572
- particle.destroy();
573
- }
574
- break;
575
- }
576
- }
577
- function updateAnimation(particle, data, changeDirection, destroyType, delta) {
578
- const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minDecay = 1;
579
- if (particle.destroyed ||
580
- !data.enable ||
581
- ((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
582
- return;
583
- }
584
- const velocity = (data.velocity ?? minVelocity) * delta.factor, minValue = data.min, maxValue = data.max, decay = data.decay ?? minDecay;
585
- data.time ??= 0;
586
- if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
587
- data.time += delta.value;
588
- }
589
- if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
590
- return;
591
- }
592
- switch (data.status) {
593
- case AnimationStatus.increasing:
594
- data.value += velocity;
595
- break;
596
- case AnimationStatus.decreasing:
597
- data.value -= velocity;
598
- break;
599
- }
600
- if (data.velocity && decay !== identity) {
601
- data.velocity *= decay;
602
- }
603
- switch (data.status) {
604
- case AnimationStatus.increasing:
605
- if (data.value >= maxValue) {
606
- {
607
- data.status = AnimationStatus.decreasing;
608
- }
609
- data.loops ??= minLoops;
610
- data.loops++;
611
- }
612
- break;
613
- case AnimationStatus.decreasing:
614
- if (data.value <= minValue) {
615
- {
616
- data.status = AnimationStatus.increasing;
617
- }
618
- data.loops ??= minLoops;
619
- data.loops++;
620
- }
621
- break;
622
- }
623
- checkDestroy(particle, destroyType, data.value, minValue, maxValue);
624
- if (!particle.destroyed) {
625
- data.value = clamp(data.value, minValue, maxValue);
626
- }
627
- }
628
424
  function cloneStyle(style) {
629
425
  const clonedStyle = safeDocument().createElement("div").style;
630
426
  for (const key in style) {
@@ -646,30 +442,34 @@
646
442
  }
647
443
  return clonedStyle;
648
444
  }
649
- function computeFullScreenStyle(zIndex) {
650
- const fullScreenStyle = safeDocument().createElement("div").style, radix = 10, style = {
651
- width: "100%",
652
- height: "100%",
653
- margin: "0",
654
- padding: "0",
655
- borderWidth: "0",
656
- position: "fixed",
657
- zIndex: zIndex.toString(radix),
658
- "z-index": zIndex.toString(radix),
659
- top: "0",
660
- left: "0",
661
- "pointer-events": "none",
662
- };
663
- for (const key in style) {
664
- const value = style[key];
665
- if (value === undefined) {
666
- continue;
445
+ let _cachedZIndex, _cachedStyle;
446
+ function getFullScreenStyle(zIndex) {
447
+ if (_cachedZIndex !== zIndex || !_cachedStyle) {
448
+ _cachedZIndex = zIndex;
449
+ const fullScreenStyle = safeDocument().createElement("div").style, radix = 10, style = {
450
+ width: "100%",
451
+ height: "100%",
452
+ margin: "0",
453
+ padding: "0",
454
+ borderWidth: "0",
455
+ position: "fixed",
456
+ zIndex: zIndex.toString(radix),
457
+ "z-index": zIndex.toString(radix),
458
+ top: "0",
459
+ left: "0",
460
+ "pointer-events": "none",
461
+ };
462
+ for (const key in style) {
463
+ const value = style[key];
464
+ if (value === undefined) {
465
+ continue;
466
+ }
467
+ fullScreenStyle.setProperty(key, value);
667
468
  }
668
- fullScreenStyle.setProperty(key, value);
469
+ _cachedStyle = fullScreenStyle;
669
470
  }
670
- return fullScreenStyle;
471
+ return _cachedStyle;
671
472
  }
672
- const getFullScreenStyle = memoize(computeFullScreenStyle);
673
473
  function manageListener(element, event, handler, add, options) {
674
474
  if (add) {
675
475
  let addOptions = { passive: true };
@@ -996,7 +796,7 @@
996
796
  return this.#domArray;
997
797
  }
998
798
  get version() {
999
- return "4.1.2";
799
+ return "4.2.0";
1000
800
  }
1001
801
  addEventListener(type, listener) {
1002
802
  this.#eventDispatcher.addEventListener(type, listener);
@@ -1166,6 +966,14 @@
1166
966
  RotateDirection["random"] = "random";
1167
967
  })(RotateDirection || (RotateDirection = {}));
1168
968
 
969
+ var AnimationMode;
970
+ (function (AnimationMode) {
971
+ AnimationMode["auto"] = "auto";
972
+ AnimationMode["increase"] = "increase";
973
+ AnimationMode["decrease"] = "decrease";
974
+ AnimationMode["random"] = "random";
975
+ })(AnimationMode || (AnimationMode = {}));
976
+
1169
977
  var LimitMode;
1170
978
  (function (LimitMode) {
1171
979
  LimitMode["delete"] = "delete";
@@ -1187,6 +995,13 @@
1187
995
  AlterType["enlighten"] = "enlighten";
1188
996
  })(AlterType || (AlterType = {}));
1189
997
 
998
+ var DestroyType;
999
+ (function (DestroyType) {
1000
+ DestroyType["none"] = "none";
1001
+ DestroyType["max"] = "max";
1002
+ DestroyType["min"] = "min";
1003
+ })(DestroyType || (DestroyType = {}));
1004
+
1190
1005
  var GradientType;
1191
1006
  (function (GradientType) {
1192
1007
  GradientType["linear"] = "linear";
@@ -1201,160 +1016,121 @@
1201
1016
  ParticleOutType["outside"] = "outside";
1202
1017
  })(ParticleOutType || (ParticleOutType = {}));
1203
1018
 
1204
- var EasingType;
1205
- (function (EasingType) {
1206
- EasingType["easeInBack"] = "ease-in-back";
1207
- EasingType["easeInBounce"] = "ease-in-bounce";
1208
- EasingType["easeInCirc"] = "ease-in-circ";
1209
- EasingType["easeInCubic"] = "ease-in-cubic";
1210
- EasingType["easeInElastic"] = "ease-in-elastic";
1211
- EasingType["easeInExpo"] = "ease-in-expo";
1212
- EasingType["easeInGaussian"] = "ease-in-gaussian";
1213
- EasingType["easeInLinear"] = "ease-in-linear";
1214
- EasingType["easeInQuad"] = "ease-in-quad";
1215
- EasingType["easeInQuart"] = "ease-in-quart";
1216
- EasingType["easeInQuint"] = "ease-in-quint";
1217
- EasingType["easeInSigmoid"] = "ease-in-sigmoid";
1218
- EasingType["easeInSine"] = "ease-in-sine";
1219
- EasingType["easeInSmoothstep"] = "ease-in-smoothstep";
1220
- EasingType["easeOutBack"] = "ease-out-back";
1221
- EasingType["easeOutBounce"] = "ease-out-bounce";
1222
- EasingType["easeOutCirc"] = "ease-out-circ";
1223
- EasingType["easeOutCubic"] = "ease-out-cubic";
1224
- EasingType["easeOutElastic"] = "ease-out-elastic";
1225
- EasingType["easeOutExpo"] = "ease-out-expo";
1226
- EasingType["easeOutGaussian"] = "ease-out-gaussian";
1227
- EasingType["easeOutLinear"] = "ease-out-linear";
1228
- EasingType["easeOutQuad"] = "ease-out-quad";
1229
- EasingType["easeOutQuart"] = "ease-out-quart";
1230
- EasingType["easeOutQuint"] = "ease-out-quint";
1231
- EasingType["easeOutSigmoid"] = "ease-out-sigmoid";
1232
- EasingType["easeOutSine"] = "ease-out-sine";
1233
- EasingType["easeOutSmoothstep"] = "ease-out-smoothstep";
1234
- EasingType["easeInOutBack"] = "ease-in-out-back";
1235
- EasingType["easeInOutBounce"] = "ease-in-out-bounce";
1236
- EasingType["easeInOutCirc"] = "ease-in-out-circ";
1237
- EasingType["easeInOutCubic"] = "ease-in-out-cubic";
1238
- EasingType["easeInOutElastic"] = "ease-in-out-elastic";
1239
- EasingType["easeInOutExpo"] = "ease-in-out-expo";
1240
- EasingType["easeInOutGaussian"] = "ease-in-out-gaussian";
1241
- EasingType["easeInOutLinear"] = "ease-in-out-linear";
1242
- EasingType["easeInOutQuad"] = "ease-in-out-quad";
1243
- EasingType["easeInOutQuart"] = "ease-in-out-quart";
1244
- EasingType["easeInOutQuint"] = "ease-in-out-quint";
1245
- EasingType["easeInOutSigmoid"] = "ease-in-out-sigmoid";
1246
- EasingType["easeInOutSine"] = "ease-in-out-sine";
1247
- EasingType["easeInOutSmoothstep"] = "ease-in-out-smoothstep";
1248
- })(EasingType || (EasingType = {}));
1019
+ var StartValueType;
1020
+ (function (StartValueType) {
1021
+ StartValueType["max"] = "max";
1022
+ StartValueType["min"] = "min";
1023
+ StartValueType["random"] = "random";
1024
+ })(StartValueType || (StartValueType = {}));
1249
1025
 
1250
- class AnimationOptions {
1251
- count;
1252
- decay;
1253
- delay;
1254
- enable;
1255
- speed;
1256
- sync;
1257
- constructor() {
1258
- this.count = 0;
1259
- this.enable = false;
1260
- this.speed = 1;
1261
- this.decay = 0;
1262
- this.delay = 0;
1263
- this.sync = false;
1264
- }
1026
+ var AnimationStatus;
1027
+ (function (AnimationStatus) {
1028
+ AnimationStatus["increasing"] = "increasing";
1029
+ AnimationStatus["decreasing"] = "decreasing";
1030
+ })(AnimationStatus || (AnimationStatus = {}));
1031
+
1032
+ class OptionLoader {
1265
1033
  load(data) {
1266
1034
  if (isNull(data)) {
1267
1035
  return;
1268
1036
  }
1269
- if (data.count !== undefined) {
1270
- this.count = setRangeValue(data.count);
1271
- }
1272
- if (data.enable !== undefined) {
1273
- this.enable = data.enable;
1274
- }
1275
- if (data.speed !== undefined) {
1276
- this.speed = setRangeValue(data.speed);
1277
- }
1278
- if (data.decay !== undefined) {
1279
- this.decay = setRangeValue(data.decay);
1280
- }
1281
- if (data.delay !== undefined) {
1282
- this.delay = setRangeValue(data.delay);
1283
- }
1284
- if (data.sync !== undefined) {
1285
- this.sync = data.sync;
1286
- }
1037
+ this.doLoad(data);
1287
1038
  }
1288
1039
  }
1289
- class RangedAnimationOptions extends AnimationOptions {
1290
- mode;
1291
- startValue;
1292
- constructor() {
1293
- super();
1294
- this.mode = AnimationMode.auto;
1295
- this.startValue = StartValueType.random;
1040
+ function loadOptions(options, ...sourceOptionsArr) {
1041
+ for (const sourceOptions of sourceOptionsArr) {
1042
+ options.load(sourceOptions);
1296
1043
  }
1297
- load(data) {
1298
- super.load(data);
1299
- if (isNull(data)) {
1300
- return;
1301
- }
1302
- if (data.mode !== undefined) {
1303
- this.mode = data.mode;
1304
- }
1305
- if (data.startValue !== undefined) {
1306
- this.startValue = data.startValue;
1307
- }
1044
+ }
1045
+
1046
+ function loadProperty(obj, key, value) {
1047
+ if (value !== undefined) {
1048
+ obj[key] = value;
1049
+ }
1050
+ }
1051
+ function loadRangeProperty(obj, key, value) {
1052
+ if (value !== undefined) {
1053
+ obj[key] = setRangeValue(value);
1054
+ }
1055
+ }
1056
+ function loadNestedProperty(obj, key, value) {
1057
+ if (value !== undefined) {
1058
+ obj[key].load(value);
1059
+ }
1060
+ }
1061
+ function loadLazyProperty(obj, key, value, factory) {
1062
+ if (value !== undefined) {
1063
+ const objRecord = obj;
1064
+ objRecord[key] ??= factory();
1065
+ objRecord[key].load(value);
1066
+ }
1067
+ }
1068
+ function loadOptionProperty(obj, key, optionClass, ...sources) {
1069
+ const objRecord = obj;
1070
+ objRecord[key] ??= new optionClass();
1071
+ const target = objRecord[key];
1072
+ for (const source of sources) {
1073
+ target.load(source?.[key]);
1074
+ }
1075
+ }
1076
+
1077
+ class AnimationOptions extends OptionLoader {
1078
+ count = 0;
1079
+ decay = 0;
1080
+ delay = 0;
1081
+ enable = false;
1082
+ speed = 1;
1083
+ sync = false;
1084
+ doLoad(data) {
1085
+ loadRangeProperty(this, "count", data.count);
1086
+ loadProperty(this, "enable", data.enable);
1087
+ loadRangeProperty(this, "speed", data.speed);
1088
+ loadRangeProperty(this, "decay", data.decay);
1089
+ loadRangeProperty(this, "delay", data.delay);
1090
+ loadProperty(this, "sync", data.sync);
1091
+ }
1092
+ }
1093
+ class RangedAnimationOptions extends AnimationOptions {
1094
+ mode = AnimationMode.auto;
1095
+ startValue = StartValueType.random;
1096
+ doLoad(data) {
1097
+ super.doLoad(data);
1098
+ loadProperty(this, "mode", data.mode);
1099
+ loadProperty(this, "startValue", data.startValue);
1308
1100
  }
1309
1101
  }
1310
1102
 
1311
1103
  class ColorAnimation extends AnimationOptions {
1312
1104
  max;
1313
1105
  min;
1314
- offset;
1106
+ offset = 0;
1107
+ sync = true;
1315
1108
  constructor(min, max) {
1316
1109
  super();
1317
1110
  this.min = min;
1318
1111
  this.max = max;
1319
- this.offset = 0;
1320
- this.sync = true;
1321
1112
  }
1322
- load(data) {
1323
- super.load(data);
1324
- if (isNull(data)) {
1325
- return;
1326
- }
1327
- if (data.max !== undefined) {
1328
- this.max = data.max;
1329
- }
1330
- if (data.min !== undefined) {
1331
- this.min = data.min;
1332
- }
1333
- if (data.offset !== undefined) {
1334
- this.offset = setRangeValue(data.offset);
1335
- }
1113
+ doLoad(data) {
1114
+ super.doLoad(data);
1115
+ loadProperty(this, "max", data.max);
1116
+ loadProperty(this, "min", data.min);
1117
+ loadRangeProperty(this, "offset", data.offset);
1336
1118
  }
1337
1119
  }
1338
1120
 
1339
- class HslAnimation {
1121
+ class HslAnimation extends OptionLoader {
1340
1122
  h = new ColorAnimation(hMin, hMax);
1341
1123
  l = new ColorAnimation(lMin, lMax);
1342
1124
  s = new ColorAnimation(sMin, sMax);
1343
- load(data) {
1344
- if (isNull(data)) {
1345
- return;
1346
- }
1125
+ doLoad(data) {
1347
1126
  this.h.load(data.h);
1348
1127
  this.s.load(data.s);
1349
1128
  this.l.load(data.l);
1350
1129
  }
1351
1130
  }
1352
1131
 
1353
- class OptionsColor {
1354
- value;
1355
- constructor() {
1356
- this.value = "";
1357
- }
1132
+ class OptionsColor extends OptionLoader {
1133
+ value = "";
1358
1134
  static create(source, data) {
1359
1135
  const color = new OptionsColor();
1360
1136
  color.load(source);
@@ -1368,10 +1144,7 @@
1368
1144
  }
1369
1145
  return color;
1370
1146
  }
1371
- load(data) {
1372
- if (isNull(data)) {
1373
- return;
1374
- }
1147
+ doLoad(data) {
1375
1148
  if (!isNull(data.value)) {
1376
1149
  this.value = data.value;
1377
1150
  }
@@ -1379,11 +1152,7 @@
1379
1152
  }
1380
1153
 
1381
1154
  class AnimatableColor extends OptionsColor {
1382
- animation;
1383
- constructor() {
1384
- super();
1385
- this.animation = new HslAnimation();
1386
- }
1155
+ animation = new HslAnimation();
1387
1156
  static create(source, data) {
1388
1157
  const color = new AnimatableColor();
1389
1158
  color.load(source);
@@ -1397,11 +1166,8 @@
1397
1166
  }
1398
1167
  return color;
1399
1168
  }
1400
- load(data) {
1401
- super.load(data);
1402
- if (isNull(data)) {
1403
- return;
1404
- }
1169
+ doLoad(data) {
1170
+ super.doLoad(data);
1405
1171
  const colorAnimation = data.animation;
1406
1172
  if (colorAnimation !== undefined) {
1407
1173
  if (colorAnimation.enable === undefined) {
@@ -1414,100 +1180,53 @@
1414
1180
  }
1415
1181
  }
1416
1182
 
1417
- class Background {
1183
+ class Background extends OptionLoader {
1418
1184
  color;
1419
- image;
1420
- opacity;
1421
- position;
1422
- repeat;
1423
- size;
1185
+ image = "";
1186
+ opacity = 1;
1187
+ position = "";
1188
+ repeat = "";
1189
+ size = "";
1424
1190
  constructor() {
1191
+ super();
1425
1192
  this.color = new OptionsColor();
1426
1193
  this.color.value = "";
1427
- this.image = "";
1428
- this.position = "";
1429
- this.repeat = "";
1430
- this.size = "";
1431
- this.opacity = 1;
1432
1194
  }
1433
- load(data) {
1434
- if (isNull(data)) {
1435
- return;
1436
- }
1195
+ doLoad(data) {
1437
1196
  if (data.color !== undefined) {
1438
1197
  this.color = OptionsColor.create(this.color, data.color);
1439
1198
  }
1440
- if (data.image !== undefined) {
1441
- this.image = data.image;
1442
- }
1443
- if (data.position !== undefined) {
1444
- this.position = data.position;
1445
- }
1446
- if (data.repeat !== undefined) {
1447
- this.repeat = data.repeat;
1448
- }
1449
- if (data.size !== undefined) {
1450
- this.size = data.size;
1451
- }
1452
- if (data.opacity !== undefined) {
1453
- this.opacity = data.opacity;
1454
- }
1199
+ loadProperty(this, "image", data.image);
1200
+ loadProperty(this, "position", data.position);
1201
+ loadProperty(this, "repeat", data.repeat);
1202
+ loadProperty(this, "size", data.size);
1203
+ loadProperty(this, "opacity", data.opacity);
1455
1204
  }
1456
1205
  }
1457
1206
 
1458
- class FullScreen {
1459
- enable;
1460
- zIndex;
1461
- constructor() {
1462
- this.enable = true;
1463
- this.zIndex = 0;
1464
- }
1465
- load(data) {
1466
- if (isNull(data)) {
1467
- return;
1468
- }
1469
- if (data.enable !== undefined) {
1470
- this.enable = data.enable;
1471
- }
1472
- if (data.zIndex !== undefined) {
1473
- this.zIndex = data.zIndex;
1474
- }
1207
+ class FullScreen extends OptionLoader {
1208
+ enable = true;
1209
+ zIndex = 0;
1210
+ doLoad(data) {
1211
+ loadProperty(this, "enable", data.enable);
1212
+ loadProperty(this, "zIndex", data.zIndex);
1475
1213
  }
1476
1214
  }
1477
1215
 
1478
- class ResizeEvent {
1479
- delay;
1480
- enable;
1481
- constructor() {
1482
- this.delay = 0.5;
1483
- this.enable = true;
1484
- }
1485
- load(data) {
1486
- if (isNull(data)) {
1487
- return;
1488
- }
1489
- if (data.delay !== undefined) {
1490
- this.delay = data.delay;
1491
- }
1492
- if (data.enable !== undefined) {
1493
- this.enable = data.enable;
1494
- }
1216
+ class ResizeEvent extends OptionLoader {
1217
+ delay = 0.5;
1218
+ enable = true;
1219
+ doLoad(data) {
1220
+ loadProperty(this, "delay", data.delay);
1221
+ loadProperty(this, "enable", data.enable);
1495
1222
  }
1496
1223
  }
1497
1224
 
1498
- class Effect {
1499
- close;
1500
- options;
1501
- type;
1502
- constructor() {
1503
- this.close = true;
1504
- this.options = {};
1505
- this.type = [];
1506
- }
1507
- load(data) {
1508
- if (isNull(data)) {
1509
- return;
1510
- }
1225
+ class Effect extends OptionLoader {
1226
+ close = true;
1227
+ options = {};
1228
+ type = [];
1229
+ doLoad(data) {
1511
1230
  const options = data.options;
1512
1231
  if (options !== undefined) {
1513
1232
  for (const effect in options) {
@@ -1517,128 +1236,62 @@
1517
1236
  }
1518
1237
  }
1519
1238
  }
1520
- if (data.close !== undefined) {
1521
- this.close = data.close;
1522
- }
1523
- if (data.type !== undefined) {
1524
- this.type = data.type;
1525
- }
1239
+ loadProperty(this, "close", data.close);
1240
+ loadProperty(this, "type", data.type);
1526
1241
  }
1527
1242
  }
1528
1243
 
1529
- class Fill {
1244
+ class Fill extends OptionLoader {
1530
1245
  color;
1531
- enable;
1532
- opacity;
1533
- constructor() {
1534
- this.enable = true;
1535
- this.opacity = 1;
1536
- }
1537
- load(data) {
1538
- if (isNull(data)) {
1539
- return;
1540
- }
1246
+ enable = true;
1247
+ opacity = 1;
1248
+ doLoad(data) {
1541
1249
  if (data.color !== undefined) {
1542
1250
  this.color = AnimatableColor.create(this.color, data.color);
1543
1251
  }
1544
- if (data.enable !== undefined) {
1545
- this.enable = data.enable;
1546
- }
1547
- if (data.opacity !== undefined) {
1548
- this.opacity = setRangeValue(data.opacity);
1549
- }
1252
+ loadProperty(this, "enable", data.enable);
1253
+ loadRangeProperty(this, "opacity", data.opacity);
1550
1254
  }
1551
1255
  }
1552
1256
 
1553
- class MoveAngle {
1554
- offset;
1555
- value;
1556
- constructor() {
1557
- this.offset = 0;
1558
- this.value = 90;
1559
- }
1560
- load(data) {
1561
- if (isNull(data)) {
1562
- return;
1563
- }
1564
- if (data.offset !== undefined) {
1565
- this.offset = setRangeValue(data.offset);
1566
- }
1567
- if (data.value !== undefined) {
1568
- this.value = setRangeValue(data.value);
1569
- }
1257
+ class MoveAngle extends OptionLoader {
1258
+ offset = 0;
1259
+ value = 90;
1260
+ doLoad(data) {
1261
+ loadRangeProperty(this, "offset", data.offset);
1262
+ loadRangeProperty(this, "value", data.value);
1570
1263
  }
1571
1264
  }
1572
1265
 
1573
- class MoveCenter {
1574
- mode;
1575
- radius;
1576
- x;
1577
- y;
1578
- constructor() {
1579
- this.x = 50;
1580
- this.y = 50;
1581
- this.mode = PixelMode.percent;
1582
- this.radius = 0;
1583
- }
1584
- load(data) {
1585
- if (isNull(data)) {
1586
- return;
1587
- }
1588
- if (data.x !== undefined) {
1589
- this.x = data.x;
1590
- }
1591
- if (data.y !== undefined) {
1592
- this.y = data.y;
1593
- }
1594
- if (data.mode !== undefined) {
1595
- this.mode = data.mode;
1596
- }
1597
- if (data.radius !== undefined) {
1598
- this.radius = data.radius;
1599
- }
1266
+ class MoveCenter extends OptionLoader {
1267
+ mode = PixelMode.percent;
1268
+ radius = 0;
1269
+ x = 50;
1270
+ y = 50;
1271
+ doLoad(data) {
1272
+ loadProperty(this, "x", data.x);
1273
+ loadProperty(this, "y", data.y);
1274
+ loadProperty(this, "mode", data.mode);
1275
+ loadProperty(this, "radius", data.radius);
1600
1276
  }
1601
1277
  }
1602
1278
 
1603
- class MoveGravity {
1604
- acceleration;
1605
- enable;
1606
- inverse;
1607
- maxSpeed;
1608
- constructor() {
1609
- this.acceleration = 9.81;
1610
- this.enable = false;
1611
- this.inverse = false;
1612
- this.maxSpeed = 50;
1613
- }
1614
- load(data) {
1615
- if (isNull(data)) {
1616
- return;
1617
- }
1618
- if (data.acceleration !== undefined) {
1619
- this.acceleration = setRangeValue(data.acceleration);
1620
- }
1621
- if (data.enable !== undefined) {
1622
- this.enable = data.enable;
1623
- }
1624
- if (data.inverse !== undefined) {
1625
- this.inverse = data.inverse;
1626
- }
1627
- if (data.maxSpeed !== undefined) {
1628
- this.maxSpeed = setRangeValue(data.maxSpeed);
1629
- }
1279
+ class MoveGravity extends OptionLoader {
1280
+ acceleration = 9.81;
1281
+ enable = false;
1282
+ inverse = false;
1283
+ maxSpeed = 50;
1284
+ doLoad(data) {
1285
+ loadRangeProperty(this, "acceleration", data.acceleration);
1286
+ loadProperty(this, "enable", data.enable);
1287
+ loadProperty(this, "inverse", data.inverse);
1288
+ loadRangeProperty(this, "maxSpeed", data.maxSpeed);
1630
1289
  }
1631
1290
  }
1632
1291
 
1633
- class ValueWithRandom {
1634
- value;
1635
- constructor() {
1636
- this.value = 0;
1637
- }
1638
- load(data) {
1639
- if (isNull(data)) {
1640
- return;
1641
- }
1292
+ class ValueWithRandom extends OptionLoader {
1293
+ value = 0;
1294
+ doLoad(data) {
1642
1295
  if (!isNull(data.value)) {
1643
1296
  this.value = setRangeValue(data.value);
1644
1297
  }
@@ -1646,51 +1299,25 @@
1646
1299
  }
1647
1300
  class AnimationValueWithRandom extends ValueWithRandom {
1648
1301
  animation = new AnimationOptions();
1649
- load(data) {
1650
- super.load(data);
1651
- if (isNull(data)) {
1652
- return;
1653
- }
1654
- const animation = data.animation;
1655
- if (animation !== undefined) {
1656
- this.animation.load(animation);
1657
- }
1302
+ doLoad(data) {
1303
+ super.doLoad(data);
1304
+ loadNestedProperty(this, "animation", data.animation);
1658
1305
  }
1659
1306
  }
1660
1307
  class RangedAnimationValueWithRandom extends AnimationValueWithRandom {
1661
- animation;
1662
- constructor() {
1663
- super();
1664
- this.animation = new RangedAnimationOptions();
1665
- }
1666
- load(data) {
1667
- super.load(data);
1668
- }
1308
+ animation = new RangedAnimationOptions();
1669
1309
  }
1670
1310
 
1671
- class MovePath {
1672
- clamp;
1673
- delay;
1674
- enable;
1311
+ class MovePath extends OptionLoader {
1312
+ clamp = true;
1313
+ delay = new ValueWithRandom();
1314
+ enable = false;
1675
1315
  generator;
1676
- options;
1677
- constructor() {
1678
- this.clamp = true;
1679
- this.delay = new ValueWithRandom();
1680
- this.enable = false;
1681
- this.options = {};
1682
- }
1683
- load(data) {
1684
- if (isNull(data)) {
1685
- return;
1686
- }
1687
- if (data.clamp !== undefined) {
1688
- this.clamp = data.clamp;
1689
- }
1316
+ options = {};
1317
+ doLoad(data) {
1318
+ loadProperty(this, "clamp", data.clamp);
1690
1319
  this.delay.load(data.delay);
1691
- if (data.enable !== undefined) {
1692
- this.enable = data.enable;
1693
- }
1320
+ loadProperty(this, "enable", data.enable);
1694
1321
  this.generator = data.generator;
1695
1322
  if (data.options) {
1696
1323
  this.options = deepExtend(this.options, data.options);
@@ -1698,19 +1325,13 @@
1698
1325
  }
1699
1326
  }
1700
1327
 
1701
- class OutModes {
1328
+ class OutModes extends OptionLoader {
1702
1329
  bottom;
1703
- default;
1330
+ default = OutMode.out;
1704
1331
  left;
1705
1332
  right;
1706
1333
  top;
1707
- constructor() {
1708
- this.default = OutMode.out;
1709
- }
1710
- load(data) {
1711
- if (isNull(data)) {
1712
- return;
1713
- }
1334
+ doLoad(data) {
1714
1335
  if (data.default !== undefined) {
1715
1336
  this.default = data.default;
1716
1337
  }
@@ -1721,79 +1342,42 @@
1721
1342
  }
1722
1343
  }
1723
1344
 
1724
- class Spin {
1725
- acceleration;
1726
- enable;
1345
+ class Spin extends OptionLoader {
1346
+ acceleration = 0;
1347
+ enable = false;
1727
1348
  position;
1728
- constructor() {
1729
- this.acceleration = 0;
1730
- this.enable = false;
1731
- }
1732
- load(data) {
1733
- if (isNull(data)) {
1734
- return;
1735
- }
1736
- if (data.acceleration !== undefined) {
1737
- this.acceleration = setRangeValue(data.acceleration);
1738
- }
1739
- if (data.enable !== undefined) {
1740
- this.enable = data.enable;
1741
- }
1349
+ doLoad(data) {
1350
+ loadRangeProperty(this, "acceleration", data.acceleration);
1351
+ loadProperty(this, "enable", data.enable);
1742
1352
  if (data.position) {
1743
1353
  this.position = deepExtend({}, data.position);
1744
1354
  }
1745
1355
  }
1746
1356
  }
1747
1357
 
1748
- class Move {
1749
- angle;
1750
- center;
1751
- decay;
1752
- direction;
1753
- distance;
1754
- drift;
1755
- enable;
1756
- gravity;
1757
- outModes;
1758
- path;
1759
- random;
1760
- size;
1761
- speed;
1762
- spin;
1763
- straight;
1764
- vibrate;
1765
- warp;
1766
- constructor() {
1767
- this.angle = new MoveAngle();
1768
- this.center = new MoveCenter();
1769
- this.decay = 0;
1770
- this.distance = {};
1771
- this.direction = MoveDirection.none;
1772
- this.drift = 0;
1773
- this.enable = false;
1774
- this.gravity = new MoveGravity();
1775
- this.path = new MovePath();
1776
- this.outModes = new OutModes();
1777
- this.random = false;
1778
- this.size = false;
1779
- this.speed = 2;
1780
- this.spin = new Spin();
1781
- this.straight = false;
1782
- this.vibrate = false;
1783
- this.warp = false;
1784
- }
1785
- load(data) {
1786
- if (isNull(data)) {
1787
- return;
1788
- }
1358
+ class Move extends OptionLoader {
1359
+ angle = new MoveAngle();
1360
+ center = new MoveCenter();
1361
+ decay = 0;
1362
+ direction = MoveDirection.none;
1363
+ distance = {};
1364
+ drift = 0;
1365
+ enable = false;
1366
+ gravity = new MoveGravity();
1367
+ outModes = new OutModes();
1368
+ path = new MovePath();
1369
+ random = false;
1370
+ size = false;
1371
+ speed = 2;
1372
+ spin = new Spin();
1373
+ straight = false;
1374
+ vibrate = false;
1375
+ warp = false;
1376
+ doLoad(data) {
1789
1377
  this.angle.load(isNumber(data.angle) ? { value: data.angle } : data.angle);
1790
1378
  this.center.load(data.center);
1791
- if (data.decay !== undefined) {
1792
- this.decay = setRangeValue(data.decay);
1793
- }
1794
- if (data.direction !== undefined) {
1795
- this.direction = data.direction;
1796
- }
1379
+ loadRangeProperty(this, "decay", data.decay);
1380
+ loadProperty(this, "direction", data.direction);
1797
1381
  if (data.distance !== undefined) {
1798
1382
  this.distance = isNumber(data.distance)
1799
1383
  ? {
@@ -1802,12 +1386,8 @@
1802
1386
  }
1803
1387
  : { ...data.distance };
1804
1388
  }
1805
- if (data.drift !== undefined) {
1806
- this.drift = setRangeValue(data.drift);
1807
- }
1808
- if (data.enable !== undefined) {
1809
- this.enable = data.enable;
1810
- }
1389
+ loadRangeProperty(this, "drift", data.drift);
1390
+ loadProperty(this, "enable", data.enable);
1811
1391
  this.gravity.load(data.gravity);
1812
1392
  const outModes = data.outModes;
1813
1393
  if (outModes !== undefined) {
@@ -1821,177 +1401,91 @@
1821
1401
  }
1822
1402
  }
1823
1403
  this.path.load(data.path);
1824
- if (data.random !== undefined) {
1825
- this.random = data.random;
1826
- }
1827
- if (data.size !== undefined) {
1828
- this.size = data.size;
1829
- }
1830
- if (data.speed !== undefined) {
1831
- this.speed = setRangeValue(data.speed);
1832
- }
1404
+ loadProperty(this, "random", data.random);
1405
+ loadProperty(this, "size", data.size);
1406
+ loadRangeProperty(this, "speed", data.speed);
1833
1407
  this.spin.load(data.spin);
1834
- if (data.straight !== undefined) {
1835
- this.straight = data.straight;
1836
- }
1837
- if (data.vibrate !== undefined) {
1838
- this.vibrate = data.vibrate;
1839
- }
1840
- if (data.warp !== undefined) {
1841
- this.warp = data.warp;
1842
- }
1408
+ loadProperty(this, "straight", data.straight);
1409
+ loadProperty(this, "vibrate", data.vibrate);
1410
+ loadProperty(this, "warp", data.warp);
1843
1411
  }
1844
1412
  }
1845
1413
 
1846
- class Stroke {
1414
+ class Stroke extends OptionLoader {
1847
1415
  color;
1848
1416
  opacity;
1849
- width;
1850
- constructor() {
1851
- this.width = 0;
1852
- }
1853
- load(data) {
1854
- if (isNull(data)) {
1855
- return;
1856
- }
1417
+ width = 0;
1418
+ doLoad(data) {
1857
1419
  if (data.color !== undefined) {
1858
1420
  this.color = AnimatableColor.create(this.color, data.color);
1859
1421
  }
1860
- if (data.width !== undefined) {
1861
- this.width = setRangeValue(data.width);
1862
- }
1863
- if (data.opacity !== undefined) {
1864
- this.opacity = setRangeValue(data.opacity);
1865
- }
1422
+ loadRangeProperty(this, "width", data.width);
1423
+ loadRangeProperty(this, "opacity", data.opacity);
1866
1424
  }
1867
1425
  }
1868
1426
 
1869
- class Paint {
1427
+ class Paint extends OptionLoader {
1870
1428
  color;
1871
1429
  fill;
1872
1430
  stroke;
1873
- load(data) {
1874
- if (isNull(data)) {
1875
- return;
1876
- }
1431
+ doLoad(data) {
1877
1432
  if (data.color !== undefined) {
1878
1433
  this.color = AnimatableColor.create(this.color, data.color);
1879
1434
  }
1880
- if (data.fill !== undefined) {
1881
- this.fill ??= new Fill();
1882
- this.fill.load(data.fill);
1883
- }
1884
- if (data.stroke !== undefined) {
1885
- this.stroke ??= new Stroke();
1886
- this.stroke.load(data.stroke);
1887
- }
1435
+ loadLazyProperty(this, "fill", data.fill, () => new Fill());
1436
+ loadLazyProperty(this, "stroke", data.stroke, () => new Stroke());
1888
1437
  }
1889
1438
  }
1890
1439
 
1891
1440
  class ParticlesBounceFactor extends ValueWithRandom {
1892
- constructor() {
1893
- super();
1894
- this.value = 1;
1895
- }
1441
+ value = 1;
1896
1442
  }
1897
1443
 
1898
- class ParticlesBounce {
1899
- horizontal;
1900
- vertical;
1901
- constructor() {
1902
- this.horizontal = new ParticlesBounceFactor();
1903
- this.vertical = new ParticlesBounceFactor();
1904
- }
1905
- load(data) {
1906
- if (isNull(data)) {
1907
- return;
1908
- }
1444
+ class ParticlesBounce extends OptionLoader {
1445
+ horizontal = new ParticlesBounceFactor();
1446
+ vertical = new ParticlesBounceFactor();
1447
+ doLoad(data) {
1909
1448
  this.horizontal.load(data.horizontal);
1910
1449
  this.vertical.load(data.vertical);
1911
1450
  }
1912
1451
  }
1913
1452
 
1914
- class ParticlesDensity {
1915
- enable;
1916
- height;
1917
- width;
1918
- constructor() {
1919
- this.enable = false;
1920
- this.width = 1920;
1921
- this.height = 1080;
1922
- }
1923
- load(data) {
1924
- if (isNull(data)) {
1925
- return;
1926
- }
1927
- if (data.enable !== undefined) {
1928
- this.enable = data.enable;
1929
- }
1930
- const width = data.width;
1931
- if (width !== undefined) {
1932
- this.width = width;
1933
- }
1934
- const height = data.height;
1935
- if (height !== undefined) {
1936
- this.height = height;
1937
- }
1453
+ class ParticlesDensity extends OptionLoader {
1454
+ enable = false;
1455
+ height = 1080;
1456
+ width = 1920;
1457
+ doLoad(data) {
1458
+ loadProperty(this, "enable", data.enable);
1459
+ loadProperty(this, "width", data.width);
1460
+ loadProperty(this, "height", data.height);
1938
1461
  }
1939
1462
  }
1940
1463
 
1941
- class ParticlesNumberLimit {
1942
- mode;
1943
- value;
1944
- constructor() {
1945
- this.mode = LimitMode.delete;
1946
- this.value = 0;
1947
- }
1948
- load(data) {
1949
- if (isNull(data)) {
1950
- return;
1951
- }
1952
- if (data.mode !== undefined) {
1953
- this.mode = data.mode;
1954
- }
1955
- if (data.value !== undefined) {
1956
- this.value = data.value;
1957
- }
1464
+ class ParticlesNumberLimit extends OptionLoader {
1465
+ mode = LimitMode.delete;
1466
+ value = 0;
1467
+ doLoad(data) {
1468
+ loadProperty(this, "mode", data.mode);
1469
+ loadProperty(this, "value", data.value);
1958
1470
  }
1959
1471
  }
1960
1472
 
1961
- class ParticlesNumber {
1962
- density;
1963
- limit;
1964
- value;
1965
- constructor() {
1966
- this.density = new ParticlesDensity();
1967
- this.limit = new ParticlesNumberLimit();
1968
- this.value = 0;
1969
- }
1970
- load(data) {
1971
- if (isNull(data)) {
1972
- return;
1973
- }
1473
+ class ParticlesNumber extends OptionLoader {
1474
+ density = new ParticlesDensity();
1475
+ limit = new ParticlesNumberLimit();
1476
+ value = 0;
1477
+ doLoad(data) {
1974
1478
  this.density.load(data.density);
1975
1479
  this.limit.load(data.limit);
1976
- if (data.value !== undefined) {
1977
- this.value = data.value;
1978
- }
1480
+ loadProperty(this, "value", data.value);
1979
1481
  }
1980
1482
  }
1981
1483
 
1982
- class Shape {
1983
- close;
1984
- options;
1985
- type;
1986
- constructor() {
1987
- this.close = true;
1988
- this.options = {};
1989
- this.type = "circle";
1990
- }
1991
- load(data) {
1992
- if (isNull(data)) {
1993
- return;
1994
- }
1484
+ class Shape extends OptionLoader {
1485
+ close = true;
1486
+ options = {};
1487
+ type = "circle";
1488
+ doLoad(data) {
1995
1489
  const options = data.options;
1996
1490
  if (options !== undefined) {
1997
1491
  for (const shape in options) {
@@ -2001,76 +1495,47 @@
2001
1495
  }
2002
1496
  }
2003
1497
  }
2004
- if (data.close !== undefined) {
2005
- this.close = data.close;
2006
- }
2007
- if (data.type !== undefined) {
2008
- this.type = data.type;
2009
- }
1498
+ loadProperty(this, "close", data.close);
1499
+ loadProperty(this, "type", data.type);
2010
1500
  }
2011
1501
  }
2012
1502
 
2013
1503
  class ZIndex extends ValueWithRandom {
2014
- opacityRate;
2015
- sizeRate;
2016
- velocityRate;
2017
- constructor() {
2018
- super();
2019
- this.opacityRate = 1;
2020
- this.sizeRate = 1;
2021
- this.velocityRate = 1;
2022
- }
2023
- load(data) {
2024
- super.load(data);
2025
- if (isNull(data)) {
2026
- return;
2027
- }
2028
- if (data.opacityRate !== undefined) {
2029
- this.opacityRate = data.opacityRate;
2030
- }
2031
- if (data.sizeRate !== undefined) {
2032
- this.sizeRate = data.sizeRate;
2033
- }
2034
- if (data.velocityRate !== undefined) {
2035
- this.velocityRate = data.velocityRate;
2036
- }
1504
+ opacityRate = 1;
1505
+ sizeRate = 1;
1506
+ velocityRate = 1;
1507
+ doLoad(data) {
1508
+ super.doLoad(data);
1509
+ loadProperty(this, "opacityRate", data.opacityRate);
1510
+ loadProperty(this, "sizeRate", data.sizeRate);
1511
+ loadProperty(this, "velocityRate", data.velocityRate);
2037
1512
  }
2038
1513
  }
2039
1514
 
2040
- class ParticlesOptions {
2041
- bounce;
2042
- effect;
2043
- groups;
2044
- move;
2045
- number;
1515
+ class ParticlesOptions extends OptionLoader {
1516
+ bounce = new ParticlesBounce();
1517
+ effect = new Effect();
1518
+ groups = {};
1519
+ move = new Move();
1520
+ number = new ParticlesNumber();
2046
1521
  paint;
2047
1522
  palette;
2048
- reduceDuplicates;
2049
- shape;
2050
- zIndex;
1523
+ reduceDuplicates = false;
1524
+ shape = new Shape();
1525
+ zIndex = new ZIndex();
2051
1526
  #container;
2052
1527
  #pluginManager;
2053
1528
  constructor(pluginManager, container) {
1529
+ super();
2054
1530
  this.#pluginManager = pluginManager;
2055
1531
  this.#container = container;
2056
- this.bounce = new ParticlesBounce();
2057
- this.effect = new Effect();
2058
- this.groups = {};
2059
- this.move = new Move();
2060
- this.number = new ParticlesNumber();
2061
1532
  this.paint = new Paint();
2062
1533
  this.paint.color = new AnimatableColor();
2063
1534
  this.paint.color.value = "#fff";
2064
1535
  this.paint.fill = new Fill();
2065
1536
  this.paint.fill.enable = true;
2066
- this.reduceDuplicates = false;
2067
- this.shape = new Shape();
2068
- this.zIndex = new ZIndex();
2069
1537
  }
2070
- load(data) {
2071
- if (isNull(data)) {
2072
- return;
2073
- }
1538
+ doLoad(data) {
2074
1539
  if (data.palette) {
2075
1540
  this.palette = data.palette;
2076
1541
  this.#importPalette(this.palette);
@@ -2128,7 +1593,7 @@
2128
1593
  }
2129
1594
  }
2130
1595
  }
2131
- #importPalette = (palette) => {
1596
+ #importPalette(palette) {
2132
1597
  const paletteData = this.#pluginManager.getPalette(palette);
2133
1598
  if (!paletteData) {
2134
1599
  return;
@@ -2172,69 +1637,49 @@
2172
1637
  mode: paletteData.blendMode,
2173
1638
  },
2174
1639
  });
2175
- };
2176
- }
2177
-
2178
- function loadOptions(options, ...sourceOptionsArr) {
2179
- for (const sourceOptions of sourceOptionsArr) {
2180
- options.load(sourceOptions);
2181
1640
  }
2182
1641
  }
1642
+
2183
1643
  function loadParticlesOptions(pluginManager, container, ...sourceOptionsArr) {
2184
1644
  const options = new ParticlesOptions(pluginManager, container);
2185
1645
  loadOptions(options, ...sourceOptionsArr);
2186
1646
  return options;
2187
1647
  }
2188
1648
 
2189
- class Options {
2190
- autoPlay;
1649
+ class Options extends OptionLoader {
1650
+ autoPlay = true;
2191
1651
  background;
2192
- clear;
2193
- defaultThemes;
2194
- delay;
2195
- detectRetina;
2196
- duration;
2197
- fpsLimit;
1652
+ clear = true;
1653
+ defaultThemes = {};
1654
+ delay = 0;
1655
+ detectRetina = true;
1656
+ duration = 0;
1657
+ fpsLimit = 120;
2198
1658
  fullScreen;
2199
- hdr;
1659
+ hdr = true;
2200
1660
  key;
2201
1661
  name;
2202
1662
  palette;
2203
1663
  particles;
2204
- pauseOnBlur;
2205
- pauseOnOutsideViewport;
1664
+ pauseOnBlur = true;
1665
+ pauseOnOutsideViewport = true;
2206
1666
  preset;
2207
1667
  resize;
2208
- smooth;
2209
- style;
2210
- zLayers;
1668
+ smooth = false;
1669
+ style = {};
1670
+ zLayers = 100;
2211
1671
  #container;
2212
1672
  #pluginManager;
2213
1673
  constructor(pluginManager, container) {
1674
+ super();
2214
1675
  this.#pluginManager = pluginManager;
2215
1676
  this.#container = container;
2216
- this.autoPlay = true;
2217
1677
  this.background = new Background();
2218
- this.clear = true;
2219
- this.defaultThemes = {};
2220
- this.delay = 0;
2221
1678
  this.fullScreen = new FullScreen();
2222
- this.detectRetina = true;
2223
- this.duration = 0;
2224
- this.fpsLimit = 120;
2225
- this.hdr = true;
2226
1679
  this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
2227
- this.pauseOnBlur = true;
2228
- this.pauseOnOutsideViewport = true;
2229
1680
  this.resize = new ResizeEvent();
2230
- this.smooth = false;
2231
- this.style = {};
2232
- this.zLayers = 100;
2233
1681
  }
2234
- load(data) {
2235
- if (isNull(data)) {
2236
- return;
2237
- }
1682
+ doLoad(data) {
2238
1683
  if (data.preset !== undefined) {
2239
1684
  this.preset = data.preset;
2240
1685
  executeOnSingleOrMultiple(this.preset, preset => {
@@ -2245,44 +1690,18 @@
2245
1690
  this.palette = data.palette;
2246
1691
  this.#importPalette(this.palette);
2247
1692
  }
2248
- if (data.autoPlay !== undefined) {
2249
- this.autoPlay = data.autoPlay;
2250
- }
2251
- if (data.clear !== undefined) {
2252
- this.clear = data.clear;
2253
- }
2254
- if (data.key !== undefined) {
2255
- this.key = data.key;
2256
- }
2257
- if (data.name !== undefined) {
2258
- this.name = data.name;
2259
- }
2260
- if (data.delay !== undefined) {
2261
- this.delay = setRangeValue(data.delay);
2262
- }
2263
- const detectRetina = data.detectRetina;
2264
- if (detectRetina !== undefined) {
2265
- this.detectRetina = detectRetina;
2266
- }
2267
- if (data.duration !== undefined) {
2268
- this.duration = setRangeValue(data.duration);
2269
- }
2270
- const fpsLimit = data.fpsLimit;
2271
- if (fpsLimit !== undefined) {
2272
- this.fpsLimit = fpsLimit;
2273
- }
2274
- if (data.hdr !== undefined) {
2275
- this.hdr = data.hdr;
2276
- }
2277
- if (data.pauseOnBlur !== undefined) {
2278
- this.pauseOnBlur = data.pauseOnBlur;
2279
- }
2280
- if (data.pauseOnOutsideViewport !== undefined) {
2281
- this.pauseOnOutsideViewport = data.pauseOnOutsideViewport;
2282
- }
2283
- if (data.zLayers !== undefined) {
2284
- this.zLayers = data.zLayers;
2285
- }
1693
+ loadProperty(this, "autoPlay", data.autoPlay);
1694
+ loadProperty(this, "clear", data.clear);
1695
+ loadProperty(this, "key", data.key);
1696
+ loadProperty(this, "name", data.name);
1697
+ loadRangeProperty(this, "delay", data.delay);
1698
+ loadProperty(this, "detectRetina", data.detectRetina);
1699
+ loadRangeProperty(this, "duration", data.duration);
1700
+ loadProperty(this, "fpsLimit", data.fpsLimit);
1701
+ loadProperty(this, "hdr", data.hdr);
1702
+ loadProperty(this, "pauseOnBlur", data.pauseOnBlur);
1703
+ loadProperty(this, "pauseOnOutsideViewport", data.pauseOnOutsideViewport);
1704
+ loadProperty(this, "zLayers", data.zLayers);
2286
1705
  this.background.load(data.background);
2287
1706
  const fullScreen = data.fullScreen;
2288
1707
  if (isBoolean(fullScreen)) {
@@ -2294,14 +1713,12 @@
2294
1713
  this.particles.load(data.particles);
2295
1714
  this.resize.load(data.resize);
2296
1715
  this.style = deepExtend(this.style, data.style);
2297
- if (data.smooth !== undefined) {
2298
- this.smooth = data.smooth;
2299
- }
1716
+ loadProperty(this, "smooth", data.smooth);
2300
1717
  this.#pluginManager.plugins.forEach(plugin => {
2301
1718
  plugin.loadOptions(this.#container, this, data);
2302
1719
  });
2303
1720
  }
2304
- #importPalette = palette => {
1721
+ #importPalette(palette) {
2305
1722
  const paletteData = this.#pluginManager.getPalette(palette);
2306
1723
  if (!paletteData) {
2307
1724
  return;
@@ -2318,143 +1735,19 @@
2318
1735
  palette,
2319
1736
  },
2320
1737
  });
2321
- };
2322
- #importPreset = preset => {
2323
- this.load(this.#pluginManager.getPreset(preset));
2324
- };
2325
- }
2326
-
2327
- function paintBase(context, dimension, baseColor) {
2328
- context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
2329
- context.fillRect(originPoint.x, originPoint.y, dimension.width, dimension.height);
2330
- }
2331
- function paintImage(context, dimension, image, opacity) {
2332
- if (!image) {
2333
- return;
2334
- }
2335
- const prevAlpha = context.globalAlpha;
2336
- context.globalAlpha = opacity;
2337
- context.drawImage(image, originPoint.x, originPoint.y, dimension.width, dimension.height);
2338
- context.globalAlpha = prevAlpha;
2339
- }
2340
- function clear(context, dimension) {
2341
- context.clearRect(originPoint.x, originPoint.y, dimension.width, dimension.height);
2342
- }
2343
- function drawParticle(data) {
2344
- const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = defaultZoom, drawPosition = {
2345
- x: pos.x,
2346
- y: pos.y,
2347
- };
2348
- context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
2349
- if (colorStyles.fill) {
2350
- context.fillStyle = colorStyles.fill;
2351
- }
2352
- const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
2353
- context.lineWidth = strokeWidth;
2354
- if (colorStyles.stroke) {
2355
- context.strokeStyle = colorStyles.stroke;
2356
- }
2357
- const drawData = {
2358
- context,
2359
- particle,
2360
- radius,
2361
- drawRadius: radius * drawScale,
2362
- opacity,
2363
- delta,
2364
- pixelRatio: container.retina.pixelRatio,
2365
- fill: fillEnabled,
2366
- stroke: strokeWidth > minStrokeWidth,
2367
- transformData,
2368
- position: { ...pos },
2369
- drawPosition,
2370
- drawScale,
2371
- };
2372
- for (const plugin of container.plugins) {
2373
- plugin.drawParticleTransform?.(drawData);
2374
- }
2375
- const effect = particle.effect ? effectDrawers.get(particle.effect) : undefined, shape = particle.shape ? shapeDrawers.get(particle.shape) : undefined;
2376
- drawBeforeEffect(effect, drawData);
2377
- drawShapeBeforeDraw(shape, drawData);
2378
- drawShape(shape, drawData);
2379
- drawShapeAfterDraw(shape, drawData);
2380
- drawAfterEffect(effect, drawData);
2381
- context.resetTransform();
2382
- }
2383
- function drawAfterEffect(drawer, data) {
2384
- if (!drawer?.drawAfter) {
2385
- return;
2386
- }
2387
- const { particle } = data;
2388
- if (!particle.effect) {
2389
- return;
2390
- }
2391
- drawer.drawAfter(data);
2392
- }
2393
- function drawBeforeEffect(drawer, data) {
2394
- if (!drawer?.drawBefore) {
2395
- return;
2396
- }
2397
- const { particle } = data;
2398
- if (!particle.effect) {
2399
- return;
2400
- }
2401
- drawer.drawBefore(data);
2402
- }
2403
- function drawShape(drawer, data) {
2404
- if (!drawer) {
2405
- return;
2406
- }
2407
- const { context, fill, particle, stroke } = data;
2408
- if (!particle.shape) {
2409
- return;
2410
- }
2411
- context.beginPath();
2412
- drawer.draw(data);
2413
- if (particle.shapeClose) {
2414
- context.closePath();
2415
- }
2416
- if (fill) {
2417
- context.fill();
2418
- }
2419
- if (stroke) {
2420
- context.stroke();
2421
1738
  }
2422
- }
2423
- function drawShapeAfterDraw(drawer, data) {
2424
- if (!drawer?.afterDraw) {
2425
- return;
2426
- }
2427
- const { particle } = data;
2428
- if (!particle.shape) {
2429
- return;
2430
- }
2431
- drawer.afterDraw(data);
2432
- }
2433
- function drawShapeBeforeDraw(drawer, data) {
2434
- if (!drawer?.beforeDraw) {
2435
- return;
2436
- }
2437
- const { particle } = data;
2438
- if (!particle.shape) {
2439
- return;
2440
- }
2441
- drawer.beforeDraw(data);
2442
- }
2443
- function drawParticlePlugin(context, plugin, particle, delta) {
2444
- if (!plugin.drawParticle) {
2445
- return;
1739
+ #importPreset(preset) {
1740
+ this.load(this.#pluginManager.getPreset(preset));
2446
1741
  }
2447
- plugin.drawParticle(context, particle, delta);
2448
1742
  }
2449
1743
 
2450
- const styleCache = new Map(), maxCacheSize = 1000, firstIndex = 0, rgbFixedPrecision = 2, hslFixedPrecision = 2;
1744
+ const styleCache = new Map(), maxStyleCacheSize = 2000, rgbFixedPrecision = 2, hslFixedPrecision = 2, sdrReferenceWhiteNits = 203;
2451
1745
  function getCachedStyle(key, generator) {
2452
1746
  let cached = styleCache.get(key);
2453
1747
  if (!cached) {
2454
1748
  cached = generator();
2455
- if (styleCache.size >= maxCacheSize) {
2456
- const keysToDelete = [...styleCache.keys()].slice(firstIndex, maxCacheSize * half);
2457
- keysToDelete.forEach(k => styleCache.delete(k));
1749
+ if (styleCache.size > maxStyleCacheSize) {
1750
+ styleCache.clear();
2458
1751
  }
2459
1752
  styleCache.set(key, cached);
2460
1753
  }
@@ -2557,34 +1850,35 @@
2557
1850
  function stringToRgb(pluginManager, input) {
2558
1851
  return stringToRgba(pluginManager, input);
2559
1852
  }
1853
+ function hslChannel(temp1, temp2, temp3) {
1854
+ const temp3Min = 0, temp3Max = 1;
1855
+ if (temp3 < temp3Min) {
1856
+ temp3++;
1857
+ }
1858
+ if (temp3 > temp3Max) {
1859
+ temp3--;
1860
+ }
1861
+ if (temp3 * sextuple < temp3Max) {
1862
+ return temp1 + (temp2 - temp1) * sextuple * temp3;
1863
+ }
1864
+ if (temp3 * double < temp3Max) {
1865
+ return temp2;
1866
+ }
1867
+ if (temp3 * triple < temp3Max * double) {
1868
+ const temp3Offset = double / triple;
1869
+ return temp1 + (temp2 - temp1) * (temp3Offset - temp3) * sextuple;
1870
+ }
1871
+ return temp1;
1872
+ }
2560
1873
  function hslToRgb(hsl) {
2561
1874
  const h = ((hsl.h % hMax) + hMax) % hMax, s = Math.max(sMin, Math.min(sMax, hsl.s)), l = Math.max(lMin, Math.min(lMax, hsl.l)), hNormalized = h / hMax, sNormalized = s / sMax, lNormalized = l / lMax;
2562
1875
  if (s === sMin) {
2563
1876
  const grayscaleValue = Math.round(lNormalized * rgbMax);
2564
1877
  return { r: grayscaleValue, g: grayscaleValue, b: grayscaleValue };
2565
1878
  }
2566
- const channel = (temp1, temp2, temp3) => {
2567
- const temp3Min = 0, temp3Max = 1;
2568
- if (temp3 < temp3Min) {
2569
- temp3++;
2570
- }
2571
- if (temp3 > temp3Max) {
2572
- temp3--;
2573
- }
2574
- if (temp3 * sextuple < temp3Max) {
2575
- return temp1 + (temp2 - temp1) * sextuple * temp3;
2576
- }
2577
- if (temp3 * double < temp3Max) {
2578
- return temp2;
2579
- }
2580
- if (temp3 * triple < temp3Max * double) {
2581
- const temp3Offset = double / triple;
2582
- return temp1 + (temp2 - temp1) * (temp3Offset - temp3) * sextuple;
2583
- }
2584
- return temp1;
2585
- }, temp1 = lNormalized < half
1879
+ const temp1 = lNormalized < half
2586
1880
  ? lNormalized * (sNormalizedOffset + sNormalized)
2587
- : lNormalized + sNormalized - lNormalized * sNormalized, temp2 = double * lNormalized - temp1, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * channel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * channel(temp2, temp1, hNormalized)), blue = Math.min(rgbMax, rgbMax * channel(temp2, temp1, hNormalized - phaseThird));
1881
+ : lNormalized + sNormalized - lNormalized * sNormalized, temp2 = double * lNormalized - temp1, phaseThird = phaseNumerator / triple, red = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized + phaseThird)), green = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized)), blue = Math.min(rgbMax, rgbMax * hslChannel(temp2, temp1, hNormalized - phaseThird));
2588
1882
  return { r: Math.round(red), g: Math.round(green), b: Math.round(blue) };
2589
1883
  }
2590
1884
  function hslaToRgba(hsla) {
@@ -2597,7 +1891,7 @@
2597
1891
  };
2598
1892
  }
2599
1893
  function getRandomRgbColor(min) {
2600
- const fixedMin = defaultRgbMin, fixedMax = rgbMax + identity$1, getRgbInRangeValue = () => Math.floor(getRandomInRange(fixedMin, fixedMax));
1894
+ const fixedMin = defaultRgbMin, fixedMax = rgbMax + identity, getRgbInRangeValue = () => Math.floor(getRandomInRange(fixedMin, fixedMax));
2601
1895
  return {
2602
1896
  b: getRgbInRangeValue(),
2603
1897
  g: getRgbInRangeValue(),
@@ -2608,21 +1902,18 @@
2608
1902
  const op = opacity ?? defaultOpacity$1, key = `rgb-${color.r.toFixed(rgbFixedPrecision)}-${color.g.toFixed(rgbFixedPrecision)}-${color.b.toFixed(rgbFixedPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
2609
1903
  return getCachedStyle(key, () => (hdr ? getHdrStyleFromRgb(color, opacity) : getSdrStyleFromRgb(color, opacity)));
2610
1904
  }
2611
- function getHdrStyleFromRgb(color, opacity) {
2612
- return `color(display-p3 ${(color.r / rgbMax).toString()} ${(color.g / rgbMax).toString()} ${(color.b / rgbMax).toString()} / ${(opacity ?? defaultOpacity$1).toString()})`;
1905
+ function getHdrStyleFromRgb(color, opacity, peakNits = maxNits) {
1906
+ const headroom = peakNits / sdrReferenceWhiteNits;
1907
+ return `color(display-p3 ${((color.r / rgbMax) * headroom).toString()} ${((color.g / rgbMax) * headroom).toString()} ${((color.b / rgbMax) * headroom).toString()} / ${(opacity ?? defaultOpacity$1).toString()})`;
2613
1908
  }
2614
1909
  function getSdrStyleFromRgb(color, opacity) {
2615
1910
  return `rgba(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()}, ${(opacity ?? defaultOpacity$1).toString()})`;
2616
1911
  }
2617
1912
  function getStyleFromHsl(color, hdr, opacity) {
2618
1913
  const op = opacity ?? defaultOpacity$1, key = `hsl-${color.h.toFixed(hslFixedPrecision)}-${color.s.toFixed(hslFixedPrecision)}-${color.l.toFixed(hslFixedPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
2619
- return getCachedStyle(key, () => (hdr ? getHdrStyleFromHsl(color, opacity) : getSdrStyleFromHsl(color, opacity)));
2620
- }
2621
- function getHdrStyleFromHsl(color, opacity) {
2622
- return getHdrStyleFromRgb(hslToRgb(color), opacity);
2623
- }
2624
- function getSdrStyleFromHsl(color, opacity) {
2625
- return `hsla(${color.h.toString()}, ${color.s.toString()}%, ${color.l.toString()}%, ${(opacity ?? defaultOpacity$1).toString()})`;
1914
+ return getCachedStyle(key, () => hdr
1915
+ ? getStyleFromRgb(hslToRgb(color), true, opacity)
1916
+ : `hsla(${color.h.toString()}, ${color.s.toString()}%, ${color.l.toString()}%, ${op.toString()})`);
2626
1917
  }
2627
1918
  function getHslFromAnimation(animation) {
2628
1919
  return animation === undefined
@@ -2744,22 +2035,14 @@
2744
2035
  const tsParticles = initEngine();
2745
2036
 
2746
2037
  class Blend {
2747
- enable;
2748
- mode;
2749
- constructor() {
2750
- this.mode = "destination-out";
2751
- this.enable = false;
2752
- }
2038
+ enable = false;
2039
+ mode = "destination-out";
2753
2040
  load(data) {
2754
2041
  if (isNull(data)) {
2755
2042
  return;
2756
2043
  }
2757
- if (data.mode !== undefined) {
2758
- this.mode = data.mode;
2759
- }
2760
- if (data.enable !== undefined) {
2761
- this.enable = data.enable;
2762
- }
2044
+ loadProperty(this, "mode", data.mode);
2045
+ loadProperty(this, "enable", data.enable);
2763
2046
  }
2764
2047
  }
2765
2048
 
@@ -2789,7 +2072,7 @@
2789
2072
  }
2790
2073
 
2791
2074
  async function loadBlendPlugin(engine) {
2792
- engine.checkVersion("4.1.2");
2075
+ engine.checkVersion("4.2.0");
2793
2076
  await engine.pluginManager.register(e => {
2794
2077
  e.pluginManager.addPlugin(new BlendPlugin());
2795
2078
  });
@@ -2826,7 +2109,7 @@
2826
2109
  }
2827
2110
 
2828
2111
  async function loadCircleShape(engine) {
2829
- engine.checkVersion("4.1.2");
2112
+ engine.checkVersion("4.2.0");
2830
2113
  await engine.pluginManager.register(e => {
2831
2114
  e.pluginManager.addShape(["circle"], () => {
2832
2115
  return Promise.resolve(new CircleDrawer());
@@ -2874,7 +2157,7 @@
2874
2157
  }
2875
2158
 
2876
2159
  async function loadHexColorPlugin(engine) {
2877
- engine.checkVersion("4.1.2");
2160
+ engine.checkVersion("4.2.0");
2878
2161
  await engine.pluginManager.register(e => {
2879
2162
  e.pluginManager.addColorManager("hex", new HexColorManager());
2880
2163
  });
@@ -2927,7 +2210,7 @@
2927
2210
  }
2928
2211
 
2929
2212
  async function loadHslColorPlugin(engine) {
2930
- engine.checkVersion("4.1.2");
2213
+ engine.checkVersion("4.2.0");
2931
2214
  await engine.pluginManager.register(e => {
2932
2215
  e.pluginManager.addColorManager("hsl", new HslColorManager());
2933
2216
  });
@@ -2945,55 +2228,161 @@
2945
2228
  }
2946
2229
  loadOptions() {
2947
2230
  }
2948
- needsPlugin() {
2949
- return true;
2231
+ needsPlugin() {
2232
+ return true;
2233
+ }
2234
+ }
2235
+
2236
+ async function loadMovePlugin(engine) {
2237
+ engine.checkVersion("4.2.0");
2238
+ await engine.pluginManager.register(e => {
2239
+ const moveEngine = e, movePluginManager = moveEngine.pluginManager;
2240
+ movePluginManager.initializers.pathGenerators ??= new Map();
2241
+ movePluginManager.pathGenerators ??= new Map();
2242
+ movePluginManager.addPathGenerator = (name, generator) => {
2243
+ movePluginManager.initializers.pathGenerators ??= new Map();
2244
+ movePluginManager.initializers.pathGenerators.set(name, generator);
2245
+ };
2246
+ movePluginManager.getPathGenerators = async (container, force = false) => {
2247
+ movePluginManager.initializers.pathGenerators ??= new Map();
2248
+ movePluginManager.pathGenerators ??= new Map();
2249
+ return getItemMapFromInitializer(container, movePluginManager.pathGenerators, movePluginManager.initializers.pathGenerators, force);
2250
+ };
2251
+ e.pluginManager.addPlugin(new MovePlugin(e.pluginManager));
2252
+ });
2253
+ }
2254
+
2255
+ function checkDestroy(particle, destroyType, value, minValue, maxValue) {
2256
+ switch (destroyType) {
2257
+ case DestroyType.max:
2258
+ if (value >= maxValue) {
2259
+ particle.destroy();
2260
+ }
2261
+ break;
2262
+ case DestroyType.min:
2263
+ if (value <= minValue) {
2264
+ particle.destroy();
2265
+ }
2266
+ break;
2267
+ }
2268
+ }
2269
+ function initParticleNumericAnimationValue(options, pxRatio) {
2270
+ const valueRange = options.value, animationOptions = options.animation, res = {
2271
+ delayTime: getRangeValue(animationOptions.delay) * millisecondsToSeconds,
2272
+ enable: animationOptions.enable,
2273
+ value: getRangeValue(options.value) * pxRatio,
2274
+ max: getRangeMax(valueRange) * pxRatio,
2275
+ min: getRangeMin(valueRange) * pxRatio,
2276
+ loops: 0,
2277
+ maxLoops: getRangeValue(animationOptions.count),
2278
+ time: 0,
2279
+ }, decayOffset = 1;
2280
+ if (animationOptions.enable) {
2281
+ res.decay = decayOffset - getRangeValue(animationOptions.decay);
2282
+ switch (animationOptions.mode) {
2283
+ case AnimationMode.increase:
2284
+ res.status = AnimationStatus.increasing;
2285
+ break;
2286
+ case AnimationMode.decrease:
2287
+ res.status = AnimationStatus.decreasing;
2288
+ break;
2289
+ case AnimationMode.random:
2290
+ res.status = getRandom() >= half ? AnimationStatus.increasing : AnimationStatus.decreasing;
2291
+ break;
2292
+ }
2293
+ const autoStatus = animationOptions.mode === AnimationMode.auto;
2294
+ switch (animationOptions.startValue) {
2295
+ case StartValueType.min:
2296
+ res.value = res.min;
2297
+ if (autoStatus) {
2298
+ res.status = AnimationStatus.increasing;
2299
+ }
2300
+ break;
2301
+ case StartValueType.max:
2302
+ res.value = res.max;
2303
+ if (autoStatus) {
2304
+ res.status = AnimationStatus.decreasing;
2305
+ }
2306
+ break;
2307
+ case StartValueType.random:
2308
+ default:
2309
+ res.value = randomInRangeValue(res);
2310
+ if (autoStatus) {
2311
+ res.status = getRandom() >= half ? AnimationStatus.increasing : AnimationStatus.decreasing;
2312
+ }
2313
+ break;
2314
+ }
2315
+ }
2316
+ res.initialValue = res.value;
2317
+ return res;
2318
+ }
2319
+ function updateAnimation(particle, data, changeDirection, destroyType, delta) {
2320
+ const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minDecay = 1;
2321
+ if (particle.destroyed ||
2322
+ !data.enable ||
2323
+ ((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
2324
+ return;
2325
+ }
2326
+ const velocity = (data.velocity ?? minVelocity) * delta.factor, minValue = data.min, maxValue = data.max, decay = data.decay ?? minDecay;
2327
+ data.time ??= 0;
2328
+ const delayTime = data.delayTime ?? minDelay;
2329
+ if (delayTime > minDelay && data.time < delayTime) {
2330
+ data.time += delta.value;
2331
+ if (data.time < delayTime) {
2332
+ return;
2333
+ }
2334
+ }
2335
+ switch (data.status) {
2336
+ case AnimationStatus.increasing:
2337
+ data.value += velocity;
2338
+ break;
2339
+ case AnimationStatus.decreasing:
2340
+ data.value -= velocity;
2341
+ break;
2342
+ }
2343
+ if (data.velocity && decay !== identity) {
2344
+ data.velocity *= decay;
2345
+ }
2346
+ switch (data.status) {
2347
+ case AnimationStatus.increasing:
2348
+ if (data.value >= maxValue) {
2349
+ {
2350
+ data.status = AnimationStatus.decreasing;
2351
+ }
2352
+ data.loops ??= minLoops;
2353
+ data.loops++;
2354
+ }
2355
+ break;
2356
+ case AnimationStatus.decreasing:
2357
+ if (data.value <= minValue) {
2358
+ {
2359
+ data.status = AnimationStatus.increasing;
2360
+ }
2361
+ data.loops ??= minLoops;
2362
+ data.loops++;
2363
+ }
2364
+ break;
2365
+ }
2366
+ checkDestroy(particle, destroyType, data.value, minValue, maxValue);
2367
+ if (!particle.destroyed) {
2368
+ data.value = clamp(data.value, minValue, maxValue);
2950
2369
  }
2951
2370
  }
2952
2371
 
2953
- async function loadMovePlugin(engine) {
2954
- engine.checkVersion("4.1.2");
2955
- await engine.pluginManager.register(e => {
2956
- const moveEngine = e, movePluginManager = moveEngine.pluginManager;
2957
- movePluginManager.initializers.pathGenerators ??= new Map();
2958
- movePluginManager.pathGenerators ??= new Map();
2959
- movePluginManager.addPathGenerator = (name, generator) => {
2960
- movePluginManager.initializers.pathGenerators ??= new Map();
2961
- movePluginManager.initializers.pathGenerators.set(name, generator);
2962
- };
2963
- movePluginManager.getPathGenerators = async (container, force = false) => {
2964
- movePluginManager.initializers.pathGenerators ??= new Map();
2965
- movePluginManager.pathGenerators ??= new Map();
2966
- return getItemMapFromInitializer(container, movePluginManager.pathGenerators, movePluginManager.initializers.pathGenerators, force);
2967
- };
2968
- e.pluginManager.addPlugin(new MovePlugin(e.pluginManager));
2969
- });
2970
- }
2971
-
2972
2372
  class OpacityAnimation extends RangedAnimationOptions {
2973
- destroy;
2974
- constructor() {
2975
- super();
2976
- this.destroy = DestroyType.none;
2977
- this.speed = 2;
2978
- }
2373
+ destroy = DestroyType.none;
2979
2374
  load(data) {
2980
2375
  super.load(data);
2981
2376
  if (isNull(data)) {
2982
2377
  return;
2983
2378
  }
2984
- if (data.destroy !== undefined) {
2985
- this.destroy = data.destroy;
2986
- }
2379
+ loadProperty(this, "destroy", data.destroy);
2987
2380
  }
2988
2381
  }
2989
2382
 
2990
2383
  class Opacity extends RangedAnimationValueWithRandom {
2991
- animation;
2992
- constructor() {
2993
- super();
2994
- this.animation = new OpacityAnimation();
2995
- this.value = 1;
2996
- }
2384
+ animation = new OpacityAnimation();
2385
+ value = 1;
2997
2386
  load(data) {
2998
2387
  if (isNull(data)) {
2999
2388
  return;
@@ -3037,10 +2426,7 @@
3037
2426
  (particle.opacity.loops ?? none) < (particle.opacity.maxLoops ?? none))));
3038
2427
  }
3039
2428
  loadOptions(options, ...sources) {
3040
- options.opacity ??= new Opacity();
3041
- for (const source of sources) {
3042
- options.opacity.load(source?.opacity);
3043
- }
2429
+ loadOptionProperty(options, "opacity", Opacity, ...sources);
3044
2430
  }
3045
2431
  reset(particle) {
3046
2432
  if (!particle.opacity) {
@@ -3058,7 +2444,7 @@
3058
2444
  }
3059
2445
 
3060
2446
  async function loadOpacityUpdater(engine) {
3061
- engine.checkVersion("4.1.2");
2447
+ engine.checkVersion("4.2.0");
3062
2448
  await engine.pluginManager.register(e => {
3063
2449
  e.pluginManager.addParticleUpdater("opacity", container => {
3064
2450
  return Promise.resolve(new OpacityUpdater(container));
@@ -3066,7 +2452,7 @@
3066
2452
  });
3067
2453
  }
3068
2454
 
3069
- const minVelocity$4 = 0, boundsMin = 0;
2455
+ const boundsMin = 0;
3070
2456
  function bounceHorizontal(data) {
3071
2457
  if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
3072
2458
  (data.direction !== OutModeDirection.left && data.direction !== OutModeDirection.right)) {
@@ -3081,8 +2467,8 @@
3081
2467
  const velocity = data.particle.velocity.x;
3082
2468
  let bounced = false;
3083
2469
  if (data.outOfCanvas &&
3084
- ((data.direction === OutModeDirection.right && velocity > minVelocity$4) ||
3085
- (data.direction === OutModeDirection.left && velocity < minVelocity$4))) {
2470
+ ((data.direction === OutModeDirection.right && velocity > minVelocity) ||
2471
+ (data.direction === OutModeDirection.left && velocity < minVelocity))) {
3086
2472
  const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
3087
2473
  data.particle.velocity.x *= -newVelocity;
3088
2474
  bounced = true;
@@ -3115,8 +2501,8 @@
3115
2501
  const velocity = data.particle.velocity.y;
3116
2502
  let bounced = false;
3117
2503
  if (data.outOfCanvas &&
3118
- ((data.direction === OutModeDirection.bottom && velocity > minVelocity$4) ||
3119
- (data.direction === OutModeDirection.top && velocity < minVelocity$4))) {
2504
+ ((data.direction === OutModeDirection.bottom && velocity > minVelocity) ||
2505
+ (data.direction === OutModeDirection.top && velocity < minVelocity))) {
3120
2506
  const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
3121
2507
  data.particle.velocity.y *= -newVelocity;
3122
2508
  bounced = true;
@@ -3169,7 +2555,6 @@
3169
2555
  }
3170
2556
  }
3171
2557
 
3172
- const minVelocity$3 = 0;
3173
2558
  class DestroyOutMode {
3174
2559
  modes;
3175
2560
  constructor(_container) {
@@ -3188,10 +2573,10 @@
3188
2573
  break;
3189
2574
  case ParticleOutType.inside: {
3190
2575
  const { dx, dy } = getDistances(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
3191
- if ((vx < minVelocity$3 && dx > particle.moveCenter.radius) ||
3192
- (vy < minVelocity$3 && dy > particle.moveCenter.radius) ||
3193
- (vx >= minVelocity$3 && dx < -particle.moveCenter.radius) ||
3194
- (vy >= minVelocity$3 && dy < -particle.moveCenter.radius)) {
2576
+ if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
2577
+ (vy < minVelocity && dy > particle.moveCenter.radius) ||
2578
+ (vx >= minVelocity && dx < -particle.moveCenter.radius) ||
2579
+ (vy >= minVelocity && dy < -particle.moveCenter.radius)) {
3195
2580
  return;
3196
2581
  }
3197
2582
  break;
@@ -3201,7 +2586,6 @@
3201
2586
  }
3202
2587
  }
3203
2588
 
3204
- const minVelocity$2 = 0;
3205
2589
  class NoneOutMode {
3206
2590
  modes;
3207
2591
  #container;
@@ -3221,10 +2605,10 @@
3221
2605
  }
3222
2606
  const gravityOptions = particle.options.move.gravity, container = this.#container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
3223
2607
  if (!gravityOptions.enable) {
3224
- if ((particle.velocity.y > minVelocity$2 && particle.position.y <= canvasSize.height + pRadius) ||
3225
- (particle.velocity.y < minVelocity$2 && particle.position.y >= -pRadius) ||
3226
- (particle.velocity.x > minVelocity$2 && particle.position.x <= canvasSize.width + pRadius) ||
3227
- (particle.velocity.x < minVelocity$2 && particle.position.x >= -pRadius)) {
2608
+ if ((particle.velocity.y > minVelocity && particle.position.y <= canvasSize.height + pRadius) ||
2609
+ (particle.velocity.y < minVelocity && particle.position.y >= -pRadius) ||
2610
+ (particle.velocity.x > minVelocity && particle.position.x <= canvasSize.width + pRadius) ||
2611
+ (particle.velocity.x < minVelocity && particle.position.x >= -pRadius)) {
3228
2612
  return;
3229
2613
  }
3230
2614
  if (!isPointInside(particle.position, container.canvas.size, originPoint, pRadius, direction)) {
@@ -3243,7 +2627,7 @@
3243
2627
  }
3244
2628
  }
3245
2629
 
3246
- const minVelocity$1 = 0, minDistance = 0, updateVector = Vector.origin;
2630
+ const updateVector = Vector.origin;
3247
2631
  class OutOutMode {
3248
2632
  modes;
3249
2633
  #container;
@@ -3264,10 +2648,10 @@
3264
2648
  updateVector.angle = particle.velocity.angle + Math.PI;
3265
2649
  updateVector.addTo(particle.moveCenter);
3266
2650
  const { dx, dy } = getDistances(particle.position, updateVector);
3267
- if ((vx <= minVelocity$1 && dx >= minDistance) ||
3268
- (vy <= minVelocity$1 && dy >= minDistance) ||
3269
- (vx >= minVelocity$1 && dx <= minDistance) ||
3270
- (vy >= minVelocity$1 && dy <= minDistance)) {
2651
+ if ((vx <= minVelocity && dx >= minDistance) ||
2652
+ (vy <= minVelocity && dy >= minDistance) ||
2653
+ (vx >= minVelocity && dx <= minDistance) ||
2654
+ (vy >= minVelocity && dy <= minDistance)) {
3271
2655
  return;
3272
2656
  }
3273
2657
  particle.position.x = Math.floor(randomInRangeValue({
@@ -3391,21 +2775,21 @@
3391
2775
  this.#updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
3392
2776
  this.#updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
3393
2777
  }
3394
- #addUpdaterIfMissing = (particle, outMode, getUpdater) => {
2778
+ #addUpdaterIfMissing(particle, outMode, getUpdater) {
3395
2779
  const outModes = particle.options.move.outModes;
3396
2780
  if (!this.updaters.has(outMode) && checkOutMode(outModes, outMode)) {
3397
2781
  this.updaters.set(outMode, getUpdater(this.#container));
3398
2782
  }
3399
- };
3400
- #updateOutMode = (particle, delta, outMode, direction) => {
2783
+ }
2784
+ #updateOutMode(particle, delta, outMode, direction) {
3401
2785
  for (const updater of this.updaters.values()) {
3402
2786
  updater.update(particle, direction, delta, outMode);
3403
2787
  }
3404
- };
2788
+ }
3405
2789
  }
3406
2790
 
3407
2791
  async function loadOutModesUpdater(engine) {
3408
- engine.checkVersion("4.1.2");
2792
+ engine.checkVersion("4.2.0");
3409
2793
  await engine.pluginManager.register(e => {
3410
2794
  e.pluginManager.addParticleUpdater("outModes", container => {
3411
2795
  return Promise.resolve(new OutOfCanvasUpdater(container));
@@ -3476,7 +2860,7 @@
3476
2860
  }
3477
2861
 
3478
2862
  async function loadPaintUpdater(engine) {
3479
- engine.checkVersion("4.1.2");
2863
+ engine.checkVersion("4.2.0");
3480
2864
  await engine.pluginManager.register(e => {
3481
2865
  e.pluginManager.addParticleUpdater("paint", container => {
3482
2866
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -3531,37 +2915,26 @@
3531
2915
  }
3532
2916
 
3533
2917
  async function loadRgbColorPlugin(engine) {
3534
- engine.checkVersion("4.1.2");
2918
+ engine.checkVersion("4.2.0");
3535
2919
  await engine.pluginManager.register(e => {
3536
2920
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
3537
2921
  });
3538
2922
  }
3539
2923
 
3540
2924
  class SizeAnimation extends RangedAnimationOptions {
3541
- destroy;
3542
- constructor() {
3543
- super();
3544
- this.destroy = DestroyType.none;
3545
- this.speed = 5;
3546
- }
2925
+ destroy = DestroyType.none;
3547
2926
  load(data) {
3548
2927
  super.load(data);
3549
2928
  if (isNull(data)) {
3550
2929
  return;
3551
2930
  }
3552
- if (data.destroy !== undefined) {
3553
- this.destroy = data.destroy;
3554
- }
2931
+ loadProperty(this, "destroy", data.destroy);
3555
2932
  }
3556
2933
  }
3557
2934
 
3558
2935
  class Size extends RangedAnimationValueWithRandom {
3559
- animation;
3560
- constructor() {
3561
- super();
3562
- this.animation = new SizeAnimation();
3563
- this.value = 3;
3564
- }
2936
+ animation = new SizeAnimation();
2937
+ value = 3;
3565
2938
  load(data) {
3566
2939
  super.load(data);
3567
2940
  if (isNull(data)) {
@@ -3604,10 +2977,7 @@
3604
2977
  (particle.size.loops ?? minLoops) < (particle.size.maxLoops ?? minLoops))));
3605
2978
  }
3606
2979
  loadOptions(options, ...sources) {
3607
- options.size ??= new Size();
3608
- for (const source of sources) {
3609
- options.size.load(source?.size);
3610
- }
2980
+ loadOptionProperty(options, "size", Size, ...sources);
3611
2981
  }
3612
2982
  preInit(particle) {
3613
2983
  const pxRatio = this.#container.retina.pixelRatio, options = particle.options, sizeOptions = options.size;
@@ -3630,7 +3000,7 @@
3630
3000
  }
3631
3001
 
3632
3002
  async function loadSizeUpdater(engine) {
3633
- engine.checkVersion("4.1.2");
3003
+ engine.checkVersion("4.2.0");
3634
3004
  await engine.pluginManager.register(e => {
3635
3005
  e.pluginManager.addParticleUpdater("size", container => {
3636
3006
  return Promise.resolve(new SizeUpdater(container));
@@ -3639,7 +3009,7 @@
3639
3009
  }
3640
3010
 
3641
3011
  async function loadBasic(engine) {
3642
- engine.checkVersion("4.1.2");
3012
+ engine.checkVersion("4.2.0");
3643
3013
  await engine.pluginManager.register(async (e) => {
3644
3014
  await Promise.all([
3645
3015
  loadBlendPlugin(e),
@@ -3824,7 +3194,7 @@
3824
3194
  return;
3825
3195
  }
3826
3196
  this.draw(ctx => {
3827
- clear(ctx, this.#canvasManager.size);
3197
+ ctx.clearRect(originPoint.x, originPoint.y, this.#canvasManager.size.width, this.#canvasManager.size.height);
3828
3198
  });
3829
3199
  }
3830
3200
  clear() {
@@ -3886,7 +3256,7 @@
3886
3256
  plugin.drawParticleSetup?.(context, particle, delta);
3887
3257
  }
3888
3258
  this.#applyPreDrawUpdaters(context, particle, radius, opacity, colorStyles, transform);
3889
- drawParticle({
3259
+ this.#drawParticle({
3890
3260
  container,
3891
3261
  context,
3892
3262
  particle,
@@ -3905,7 +3275,7 @@
3905
3275
  drawParticlePlugins(particle, delta) {
3906
3276
  this.draw(ctx => {
3907
3277
  for (const plugin of this.#drawParticlePlugins) {
3908
- drawParticlePlugin(ctx, plugin, particle, delta);
3278
+ this.#drawParticlePlugin(ctx, plugin, particle, delta);
3909
3279
  }
3910
3280
  });
3911
3281
  }
@@ -4005,12 +3375,19 @@
4005
3375
  }
4006
3376
  paintBase(baseColor) {
4007
3377
  this.draw(ctx => {
4008
- paintBase(ctx, this.#canvasManager.size, baseColor);
3378
+ ctx.fillStyle = baseColor ?? "rgba(0,0,0,0)";
3379
+ ctx.fillRect(originPoint.x, originPoint.y, this.#canvasManager.size.width, this.#canvasManager.size.height);
4009
3380
  });
4010
3381
  }
4011
3382
  paintImage(image, opacity) {
4012
3383
  this.draw(ctx => {
4013
- paintImage(ctx, this.#canvasManager.size, image, opacity);
3384
+ if (!image) {
3385
+ return;
3386
+ }
3387
+ const prevAlpha = ctx.globalAlpha;
3388
+ ctx.globalAlpha = opacity;
3389
+ ctx.drawImage(image, originPoint.x, originPoint.y, this.#canvasManager.size.width, this.#canvasManager.size.height);
3390
+ ctx.globalAlpha = prevAlpha;
4014
3391
  });
4015
3392
  }
4016
3393
  setContext(context) {
@@ -4024,15 +3401,15 @@
4024
3401
  }
4025
3402
  stop() {
4026
3403
  this.draw(ctx => {
4027
- clear(ctx, this.#canvasManager.size);
3404
+ ctx.clearRect(originPoint.x, originPoint.y, this.#canvasManager.size.width, this.#canvasManager.size.height);
4028
3405
  });
4029
3406
  }
4030
- #applyPostDrawUpdaters = particle => {
3407
+ #applyPostDrawUpdaters(particle) {
4031
3408
  for (const updater of this.#postDrawUpdaters) {
4032
3409
  updater.afterDraw?.(particle);
4033
3410
  }
4034
- };
4035
- #applyPreDrawUpdaters = (ctx, particle, radius, zOpacity, colorStyles, transform) => {
3411
+ }
3412
+ #applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform) {
4036
3413
  for (const updater of this.#preDrawUpdaters) {
4037
3414
  if (updater.getColorStyles) {
4038
3415
  const { fill, stroke } = updater.getColorStyles(particle, ctx, radius, zOpacity);
@@ -4051,8 +3428,114 @@
4051
3428
  }
4052
3429
  updater.beforeDraw?.(particle);
4053
3430
  }
4054
- };
4055
- #getPluginParticleColors = particle => {
3431
+ }
3432
+ #drawAfterEffect(drawer, data) {
3433
+ if (!drawer?.drawAfter) {
3434
+ return;
3435
+ }
3436
+ const { particle } = data;
3437
+ if (!particle.effect) {
3438
+ return;
3439
+ }
3440
+ drawer.drawAfter(data);
3441
+ }
3442
+ #drawBeforeEffect(drawer, data) {
3443
+ if (!drawer?.drawBefore) {
3444
+ return;
3445
+ }
3446
+ const { particle } = data;
3447
+ if (!particle.effect) {
3448
+ return;
3449
+ }
3450
+ drawer.drawBefore(data);
3451
+ }
3452
+ #drawParticle(data) {
3453
+ const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = defaultZoom, drawPosition = {
3454
+ x: pos.x,
3455
+ y: pos.y,
3456
+ };
3457
+ context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
3458
+ if (colorStyles.fill) {
3459
+ context.fillStyle = colorStyles.fill;
3460
+ }
3461
+ const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
3462
+ context.lineWidth = strokeWidth;
3463
+ if (colorStyles.stroke) {
3464
+ context.strokeStyle = colorStyles.stroke;
3465
+ }
3466
+ const drawData = {
3467
+ context,
3468
+ particle,
3469
+ radius,
3470
+ drawRadius: radius * drawScale,
3471
+ opacity,
3472
+ delta,
3473
+ pixelRatio: container.retina.pixelRatio,
3474
+ fill: fillEnabled,
3475
+ stroke: strokeWidth > minStrokeWidth,
3476
+ transformData,
3477
+ position: { ...pos },
3478
+ drawPosition,
3479
+ drawScale,
3480
+ };
3481
+ for (const plugin of container.plugins) {
3482
+ plugin.drawParticleTransform?.(drawData);
3483
+ }
3484
+ const effect = particle.effect ? effectDrawers.get(particle.effect) : undefined, shape = particle.shape ? shapeDrawers.get(particle.shape) : undefined;
3485
+ this.#drawBeforeEffect(effect, drawData);
3486
+ this.#drawShapeBeforeDraw(shape, drawData);
3487
+ this.#drawShape(shape, drawData);
3488
+ this.#drawShapeAfterDraw(shape, drawData);
3489
+ this.#drawAfterEffect(effect, drawData);
3490
+ context.resetTransform();
3491
+ }
3492
+ #drawParticlePlugin(context, plugin, particle, delta) {
3493
+ if (!plugin.drawParticle) {
3494
+ return;
3495
+ }
3496
+ plugin.drawParticle(context, particle, delta);
3497
+ }
3498
+ #drawShape(drawer, data) {
3499
+ if (!drawer) {
3500
+ return;
3501
+ }
3502
+ const { context, fill, particle, stroke } = data;
3503
+ if (!particle.shape) {
3504
+ return;
3505
+ }
3506
+ context.beginPath();
3507
+ drawer.draw(data);
3508
+ if (particle.shapeClose) {
3509
+ context.closePath();
3510
+ }
3511
+ if (fill) {
3512
+ context.fill();
3513
+ }
3514
+ if (stroke) {
3515
+ context.stroke();
3516
+ }
3517
+ }
3518
+ #drawShapeAfterDraw(drawer, data) {
3519
+ if (!drawer?.afterDraw) {
3520
+ return;
3521
+ }
3522
+ const { particle } = data;
3523
+ if (!particle.shape) {
3524
+ return;
3525
+ }
3526
+ drawer.afterDraw(data);
3527
+ }
3528
+ #drawShapeBeforeDraw(drawer, data) {
3529
+ if (!drawer?.beforeDraw) {
3530
+ return;
3531
+ }
3532
+ const { particle } = data;
3533
+ if (!particle.shape) {
3534
+ return;
3535
+ }
3536
+ drawer.beforeDraw(data);
3537
+ }
3538
+ #getPluginParticleColors(particle) {
4056
3539
  let fColor, sColor;
4057
3540
  for (const plugin of this.#colorPlugins) {
4058
3541
  if (!fColor && plugin.particleFillColor) {
@@ -4068,7 +3551,7 @@
4068
3551
  this.#reusablePluginColors[fColorIndex] = fColor;
4069
3552
  this.#reusablePluginColors[sColorIndex] = sColor;
4070
3553
  return this.#reusablePluginColors;
4071
- };
3554
+ }
4072
3555
  }
4073
3556
 
4074
3557
  const transferredCanvases = new WeakMap(), getTransferredCanvas = (canvas) => {
@@ -4200,6 +3683,7 @@
4200
3683
  obs.observe(element, { attributes: true });
4201
3684
  });
4202
3685
  this.initPlugins();
3686
+ this.#initContext();
4203
3687
  this.render.init();
4204
3688
  }
4205
3689
  initBackground() {
@@ -4209,7 +3693,7 @@
4209
3693
  }
4210
3694
  const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
4211
3695
  if (color) {
4212
- elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity);
3696
+ elementStyle.backgroundColor = getStyleFromRgb(color, container.actualOptions.hdr, background.opacity);
4213
3697
  }
4214
3698
  else {
4215
3699
  elementStyle.backgroundColor = "";
@@ -4231,7 +3715,7 @@
4231
3715
  if (this.#generated && this.domElement) {
4232
3716
  this.domElement.remove();
4233
3717
  }
4234
- const container = this.#container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
3718
+ const domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
4235
3719
  this.domElement = domCanvas;
4236
3720
  this.#generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
4237
3721
  this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
@@ -4252,26 +3736,6 @@
4252
3736
  const pxRatio = this.#container.retina.pixelRatio, retinaSize = this.size;
4253
3737
  renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
4254
3738
  renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
4255
- const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
4256
- this.render.setContextSettings({
4257
- alpha: true,
4258
- colorSpace: canSupportHdrQuery?.matches && container.hdr ? "display-p3" : "srgb",
4259
- desynchronized: true,
4260
- willReadFrequently: false,
4261
- });
4262
- this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
4263
- this.#safeMutationObserver(obs => {
4264
- obs.disconnect();
4265
- });
4266
- container.retina.init();
4267
- this.initBackground();
4268
- this.#safeMutationObserver(obs => {
4269
- const element = this.domElement;
4270
- if (!element || !(element instanceof Node)) {
4271
- return;
4272
- }
4273
- obs.observe(element, { attributes: true });
4274
- });
4275
3739
  }
4276
3740
  resize() {
4277
3741
  const element = this.domElement;
@@ -4339,12 +3803,30 @@
4339
3803
  await container.refresh();
4340
3804
  }
4341
3805
  }
4342
- #applyResizePlugins = () => {
3806
+ #applyResizePlugins() {
4343
3807
  for (const plugin of this.#resizePlugins) {
4344
3808
  plugin.resize?.();
4345
3809
  }
4346
- };
4347
- #initStyle = () => {
3810
+ }
3811
+ #initContext() {
3812
+ const container = this.#container, canSupportHdr = container.actualOptions.hdr &&
3813
+ safeMatchMedia("(color-gamut: p3)")?.matches &&
3814
+ safeMatchMedia("(dynamic-range: high)")?.matches;
3815
+ this.render.setContextSettings({
3816
+ alpha: true,
3817
+ desynchronized: true,
3818
+ willReadFrequently: false,
3819
+ ...(canSupportHdr
3820
+ ? { colorSpace: "display-p3", colorType: "float16" }
3821
+ : { colorSpace: "srgb" }),
3822
+ });
3823
+ const renderCanvas = this.renderCanvas;
3824
+ if (!renderCanvas) {
3825
+ return;
3826
+ }
3827
+ this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
3828
+ }
3829
+ #initStyle() {
4348
3830
  const element = this.domElement, options = this.#container.actualOptions;
4349
3831
  if (!element) {
4350
3832
  return;
@@ -4365,8 +3847,8 @@
4365
3847
  }
4366
3848
  element.style.setProperty(key, value, "important");
4367
3849
  }
4368
- };
4369
- #repairStyle = () => {
3850
+ }
3851
+ #repairStyle() {
4370
3852
  const element = this.domElement;
4371
3853
  if (!element) {
4372
3854
  return;
@@ -4385,27 +3867,27 @@
4385
3867
  }
4386
3868
  observer.observe(element, { attributes: true });
4387
3869
  });
4388
- };
4389
- #resetOriginalStyle = () => {
3870
+ }
3871
+ #resetOriginalStyle() {
4390
3872
  const element = this.domElement, originalStyle = this.#originalStyle;
4391
3873
  if (!element || !originalStyle) {
4392
3874
  return;
4393
3875
  }
4394
3876
  setStyle(element, originalStyle, true);
4395
- };
4396
- #safeMutationObserver = callback => {
3877
+ }
3878
+ #safeMutationObserver(callback) {
4397
3879
  if (!this.#mutationObserver) {
4398
3880
  return;
4399
3881
  }
4400
3882
  callback(this.#mutationObserver);
4401
- };
4402
- #setFullScreenStyle = () => {
3883
+ }
3884
+ #setFullScreenStyle() {
4403
3885
  const element = this.domElement;
4404
3886
  if (!element) {
4405
3887
  return;
4406
3888
  }
4407
3889
  setStyle(element, getFullScreenStyle(this.#container.actualOptions.fullScreen.zIndex), true);
4408
- };
3890
+ }
4409
3891
  }
4410
3892
 
4411
3893
  class EventListeners {
@@ -4430,7 +3912,7 @@
4430
3912
  removeListeners() {
4431
3913
  this.#manageListeners(false);
4432
3914
  }
4433
- #handleVisibilityChange = () => {
3915
+ #handleVisibilityChange() {
4434
3916
  const container = this.#container, options = container.actualOptions;
4435
3917
  if (!options.pauseOnBlur) {
4436
3918
  return;
@@ -4448,8 +3930,8 @@
4448
3930
  container.draw(true);
4449
3931
  }
4450
3932
  }
4451
- };
4452
- #handleWindowResize = () => {
3933
+ }
3934
+ #handleWindowResize() {
4453
3935
  if (this.#resizeTimeout) {
4454
3936
  clearTimeout(this.#resizeTimeout);
4455
3937
  this.#resizeTimeout = undefined;
@@ -4459,13 +3941,13 @@
4459
3941
  await canvas.windowResize();
4460
3942
  };
4461
3943
  this.#resizeTimeout = setTimeout(() => void handleResize(), this.#container.actualOptions.resize.delay * millisecondsToSeconds);
4462
- };
4463
- #manageListeners = add => {
3944
+ }
3945
+ #manageListeners(add) {
4464
3946
  const handlers = this.#handlers;
4465
3947
  this.#manageResize(add);
4466
3948
  manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
4467
- };
4468
- #manageResize = add => {
3949
+ }
3950
+ #manageResize(add) {
4469
3951
  const handlers = this.#handlers, container = this.#container, options = container.actualOptions;
4470
3952
  if (!options.resize.enable) {
4471
3953
  return;
@@ -4492,7 +3974,7 @@
4492
3974
  });
4493
3975
  this.#resizeObserver.observe(canvasEl);
4494
3976
  }
4495
- };
3977
+ }
4496
3978
  }
4497
3979
 
4498
3980
  function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
@@ -4519,6 +4001,131 @@
4519
4001
  data.setCb(data.radius);
4520
4002
  }
4521
4003
  }
4004
+ function normalizeAngle(angle, modulus) {
4005
+ const normalized = angle % modulus;
4006
+ return normalized < defaultAngle ? normalized + modulus : normalized;
4007
+ }
4008
+ function initParticleState(particle, id, group) {
4009
+ particle.id = id;
4010
+ particle.group = group;
4011
+ particle.justWarped = false;
4012
+ particle.effectClose = true;
4013
+ particle.shapeClose = true;
4014
+ particle.pathRotation = false;
4015
+ particle.lastPathTime = 0;
4016
+ particle.destroyed = false;
4017
+ particle.unbreakable = false;
4018
+ particle.isRotating = false;
4019
+ particle.rotation = 0;
4020
+ particle.misplaced = false;
4021
+ particle.retina = {
4022
+ maxDistance: {},
4023
+ maxSpeed: 0,
4024
+ moveDrift: 0,
4025
+ moveSpeed: 0,
4026
+ sizeAnimationSpeed: 0,
4027
+ };
4028
+ particle.size = {
4029
+ value: 1,
4030
+ max: 1,
4031
+ min: 1,
4032
+ enable: false,
4033
+ };
4034
+ particle.outType = ParticleOutType.normal;
4035
+ particle.ignoresResizeRatio = true;
4036
+ }
4037
+ function resolveParticleOptions(particle, container, pluginManager, overrideOptions) {
4038
+ const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates;
4039
+ particle.effect = itemFromSingleOrMultiple(particlesOptions.effect.type, particle.id, reduceDuplicates);
4040
+ particle.shape = itemFromSingleOrMultiple(particlesOptions.shape.type, particle.id, reduceDuplicates);
4041
+ const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
4042
+ if (overrideOptions) {
4043
+ if (overrideOptions.effect) {
4044
+ const overrideEffectType = overrideOptions.effect.type;
4045
+ if (overrideEffectType && overrideEffectType !== particle.effect) {
4046
+ const effect = itemFromSingleOrMultiple(overrideEffectType, particle.id, reduceDuplicates);
4047
+ if (effect) {
4048
+ particle.effect = effect;
4049
+ }
4050
+ }
4051
+ effectOptions.load(overrideOptions.effect);
4052
+ }
4053
+ if (overrideOptions.shape) {
4054
+ const overrideShapeType = overrideOptions.shape.type;
4055
+ if (overrideShapeType && overrideShapeType !== particle.shape) {
4056
+ const shape = itemFromSingleOrMultiple(overrideShapeType, particle.id, reduceDuplicates);
4057
+ if (shape) {
4058
+ particle.shape = shape;
4059
+ }
4060
+ }
4061
+ shapeOptions.load(overrideOptions.shape);
4062
+ }
4063
+ }
4064
+ if (particle.effect === randomColorValue) {
4065
+ const availableEffects = [...container.effectDrawers.keys()];
4066
+ particle.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
4067
+ }
4068
+ if (particle.shape === randomColorValue) {
4069
+ const availableShapes = [...container.shapeDrawers.keys()];
4070
+ particle.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
4071
+ }
4072
+ particle.effectData = particle.effect
4073
+ ? loadEffectData(particle.effect, effectOptions, particle.id, reduceDuplicates)
4074
+ : undefined;
4075
+ particle.shapeData = particle.shape
4076
+ ? loadShapeData(particle.shape, shapeOptions, particle.id, reduceDuplicates)
4077
+ : undefined;
4078
+ particlesOptions.load(overrideOptions);
4079
+ const effectData = particle.effectData, shapeData = particle.shapeData;
4080
+ if (effectData) {
4081
+ particlesOptions.load(effectData.particles);
4082
+ }
4083
+ if (shapeData) {
4084
+ particlesOptions.load(shapeData.particles);
4085
+ }
4086
+ particle.effectClose = effectData?.close ?? particlesOptions.effect.close;
4087
+ particle.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
4088
+ return particlesOptions;
4089
+ }
4090
+ function initParticleDrawers(particle, container) {
4091
+ let effectDrawer, shapeDrawer;
4092
+ if (particle.effect) {
4093
+ effectDrawer = container.effectDrawers.get(particle.effect);
4094
+ }
4095
+ if (effectDrawer?.loadEffect) {
4096
+ effectDrawer.loadEffect(particle);
4097
+ }
4098
+ if (particle.shape) {
4099
+ shapeDrawer = container.shapeDrawers.get(particle.shape);
4100
+ }
4101
+ if (shapeDrawer?.loadShape) {
4102
+ shapeDrawer.loadShape(particle);
4103
+ }
4104
+ const sideCountFunc = shapeDrawer?.getSidesCount;
4105
+ if (sideCountFunc) {
4106
+ particle.sides = sideCountFunc(particle);
4107
+ }
4108
+ }
4109
+ function runUpdaterPreInit(updaters, particle) {
4110
+ for (const updater of updaters) {
4111
+ updater.preInit?.(particle);
4112
+ }
4113
+ }
4114
+ function runUpdaterInit(updaters, particle) {
4115
+ for (const updater of updaters) {
4116
+ updater.init(particle);
4117
+ }
4118
+ }
4119
+ function runDrawerInit(container, particle) {
4120
+ const shapeDrawer = particle.shape ? container.shapeDrawers.get(particle.shape) : undefined, effectDrawer = particle.effect ? container.effectDrawers.get(particle.effect) : undefined;
4121
+ effectDrawer?.particleInit?.(container, particle);
4122
+ shapeDrawer?.particleInit?.(container, particle);
4123
+ }
4124
+ function runParticleCreatedPlugins(container, particle) {
4125
+ for (const plugin of container.particleCreatedPlugins) {
4126
+ plugin.particleCreated?.(particle);
4127
+ }
4128
+ }
4522
4129
  class Particle {
4523
4130
  backColor;
4524
4131
  bubble;
@@ -4644,88 +4251,20 @@
4644
4251
  const rotateData = this.getRotateData(), rotating = this.isRotating;
4645
4252
  this.#cachedTransform.a = rotateData.cos * (externalTransform.a ?? defaultTransform.a);
4646
4253
  this.#cachedTransform.b = rotating
4647
- ? rotateData.sin * (externalTransform.b ?? identity$1)
4254
+ ? rotateData.sin * (externalTransform.b ?? identity)
4648
4255
  : (externalTransform.b ?? defaultTransform.b);
4649
4256
  this.#cachedTransform.c = rotating
4650
- ? -rotateData.sin * (externalTransform.c ?? identity$1)
4257
+ ? -rotateData.sin * (externalTransform.c ?? identity)
4651
4258
  : (externalTransform.c ?? defaultTransform.c);
4652
4259
  this.#cachedTransform.d = rotateData.cos * (externalTransform.d ?? defaultTransform.d);
4653
4260
  return this.#cachedTransform;
4654
4261
  }
4655
4262
  init(id, position, overrideOptions, group) {
4656
4263
  const container = this.#container;
4657
- this.id = id;
4658
- this.group = group;
4659
- this.justWarped = false;
4660
- this.effectClose = true;
4661
- this.shapeClose = true;
4662
- this.pathRotation = false;
4663
- this.lastPathTime = 0;
4664
- this.destroyed = false;
4665
- this.unbreakable = false;
4666
- this.isRotating = false;
4667
- this.rotation = 0;
4668
- this.misplaced = false;
4669
- this.retina = {
4670
- maxDistance: {},
4671
- maxSpeed: 0,
4672
- moveDrift: 0,
4673
- moveSpeed: 0,
4674
- sizeAnimationSpeed: 0,
4675
- };
4676
- this.size = {
4677
- value: 1,
4678
- max: 1,
4679
- min: 1,
4680
- enable: false,
4681
- };
4682
- this.outType = ParticleOutType.normal;
4683
- this.ignoresResizeRatio = true;
4684
- const mainOptions = container.actualOptions, particlesOptions = loadParticlesOptions(this.#pluginManager, container, mainOptions.particles), reduceDuplicates = particlesOptions.reduceDuplicates, effectType = particlesOptions.effect.type, shapeType = particlesOptions.shape.type;
4685
- this.effect = itemFromSingleOrMultiple(effectType, this.id, reduceDuplicates);
4686
- this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
4687
- const effectOptions = particlesOptions.effect, shapeOptions = particlesOptions.shape;
4688
- if (overrideOptions) {
4689
- if (overrideOptions.effect?.type && overrideOptions.effect.type !== this.effect) {
4690
- const overrideEffectType = overrideOptions.effect.type, effect = itemFromSingleOrMultiple(overrideEffectType, this.id, reduceDuplicates);
4691
- if (effect) {
4692
- this.effect = effect;
4693
- effectOptions.load(overrideOptions.effect);
4694
- }
4695
- }
4696
- if (overrideOptions.shape?.type && overrideOptions.shape.type !== this.shape) {
4697
- const overrideShapeType = overrideOptions.shape.type, shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
4698
- if (shape) {
4699
- this.shape = shape;
4700
- shapeOptions.load(overrideOptions.shape);
4701
- }
4702
- }
4703
- }
4704
- if (this.effect === randomColorValue) {
4705
- const availableEffects = [...this.#container.effectDrawers.keys()];
4706
- this.effect = availableEffects[Math.floor(getRandom() * availableEffects.length)];
4707
- }
4708
- if (this.shape === randomColorValue) {
4709
- const availableShapes = [...this.#container.shapeDrawers.keys()];
4710
- this.shape = availableShapes[Math.floor(getRandom() * availableShapes.length)];
4711
- }
4712
- this.effectData = this.effect ? loadEffectData(this.effect, effectOptions, this.id, reduceDuplicates) : undefined;
4713
- this.shapeData = this.shape ? loadShapeData(this.shape, shapeOptions, this.id, reduceDuplicates) : undefined;
4714
- particlesOptions.load(overrideOptions);
4715
- const effectData = this.effectData, shapeData = this.shapeData;
4716
- if (effectData) {
4717
- particlesOptions.load(effectData.particles);
4718
- }
4719
- if (shapeData) {
4720
- particlesOptions.load(shapeData.particles);
4721
- }
4722
- this.effectClose = effectData?.close ?? particlesOptions.effect.close;
4723
- this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
4724
- this.options = particlesOptions;
4264
+ initParticleState(this, id, group);
4265
+ this.options = resolveParticleOptions(this, container, this.#pluginManager, overrideOptions);
4725
4266
  container.retina.initParticle(this);
4726
- for (const updater of container.particleUpdaters) {
4727
- updater.preInit?.(this);
4728
- }
4267
+ runUpdaterPreInit(container.particleUpdaters, this);
4729
4268
  this.bubble = {
4730
4269
  inRange: false,
4731
4270
  };
@@ -4738,32 +4277,11 @@
4738
4277
  this.velocity = this.initialVelocity.copy();
4739
4278
  this.zIndexFactor = this.position.z / container.zLayers;
4740
4279
  this.sides = 24;
4741
- let effectDrawer, shapeDrawer;
4742
- if (this.effect) {
4743
- effectDrawer = container.effectDrawers.get(this.effect);
4744
- }
4745
- if (effectDrawer?.loadEffect) {
4746
- effectDrawer.loadEffect(this);
4747
- }
4748
- if (this.shape) {
4749
- shapeDrawer = container.shapeDrawers.get(this.shape);
4750
- }
4751
- if (shapeDrawer?.loadShape) {
4752
- shapeDrawer.loadShape(this);
4753
- }
4754
- const sideCountFunc = shapeDrawer?.getSidesCount;
4755
- if (sideCountFunc) {
4756
- this.sides = sideCountFunc(this);
4757
- }
4280
+ initParticleDrawers(this, container);
4758
4281
  this.spawning = false;
4759
- for (const updater of container.particleUpdaters) {
4760
- updater.init(this);
4761
- }
4762
- effectDrawer?.particleInit?.(container, this);
4763
- shapeDrawer?.particleInit?.(container, this);
4764
- for (const plugin of container.particleCreatedPlugins) {
4765
- plugin.particleCreated?.(this);
4766
- }
4282
+ runUpdaterInit(container.particleUpdaters, this);
4283
+ runDrawerInit(container, this);
4284
+ runParticleCreatedPlugins(container, this);
4767
4285
  }
4768
4286
  isInsideCanvas(direction) {
4769
4287
  return this.#getInsideCanvasResult({ direction }).inside;
@@ -4777,15 +4295,15 @@
4777
4295
  }
4778
4296
  const angle = this.roll.angle;
4779
4297
  if (this.roll.horizontal && this.roll.vertical) {
4780
- const normalizedAngle = angle % doublePI, adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + doublePI : normalizedAngle;
4298
+ const adjustedAngle = normalizeAngle(angle, doublePI);
4781
4299
  return adjustedAngle >= Math.PI * half && adjustedAngle < Math.PI * triple * half;
4782
4300
  }
4783
4301
  if (this.roll.horizontal) {
4784
- const normalizedAngle = (angle + Math.PI * half) % (Math.PI * double), adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
4302
+ const adjustedAngle = normalizeAngle(angle + Math.PI * half, doublePI);
4785
4303
  return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
4786
4304
  }
4787
4305
  if (this.roll.vertical) {
4788
- const normalizedAngle = angle % (Math.PI * double), adjustedAngle = normalizedAngle < defaultAngle ? normalizedAngle + Math.PI * double : normalizedAngle;
4306
+ const adjustedAngle = normalizeAngle(angle, doublePI);
4789
4307
  return adjustedAngle >= Math.PI && adjustedAngle < Math.PI * double;
4790
4308
  }
4791
4309
  return false;
@@ -4798,10 +4316,10 @@
4798
4316
  updater.reset?.(this);
4799
4317
  }
4800
4318
  }
4801
- #calcPosition = (position, zIndex) => {
4319
+ #calcPosition(position, zIndex) {
4802
4320
  let tryCount = defaultRetryCount, posVec = position ? Vector3d.create(position.x, position.y, zIndex) : undefined;
4803
- const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size, abortController = new AbortController(), { signal } = abortController;
4804
- while (!signal.aborted) {
4321
+ const container = this.#container, plugins = container.particlePositionPlugins, outModes = this.options.move.outModes, radius = this.getRadius(), canvasSize = container.canvas.size;
4322
+ for (;;) {
4805
4323
  for (const plugin of plugins) {
4806
4324
  const pluginPos = plugin.particlePosition?.(posVec, this);
4807
4325
  if (pluginPos) {
@@ -4829,9 +4347,8 @@
4829
4347
  tryCount += tryCountIncrement;
4830
4348
  posVec = undefined;
4831
4349
  }
4832
- return posVec;
4833
- };
4834
- #calculateVelocity = () => {
4350
+ }
4351
+ #calculateVelocity() {
4835
4352
  const moveOptions = this.options.move, baseVelocity = getParticleBaseVelocity(this.direction), res = baseVelocity.copy();
4836
4353
  if (moveOptions.direction === MoveDirection.inside || moveOptions.direction === MoveDirection.outside) {
4837
4354
  return res;
@@ -4847,8 +4364,8 @@
4847
4364
  res.length *= getRandom();
4848
4365
  }
4849
4366
  return res;
4850
- };
4851
- #fixHorizontal = (pos, radius, outMode) => {
4367
+ }
4368
+ #fixHorizontal(pos, radius, outMode) {
4852
4369
  fixOutMode({
4853
4370
  outMode,
4854
4371
  checkModes: [OutMode.bounce],
@@ -4857,8 +4374,8 @@
4857
4374
  setCb: (value) => (pos.x += value),
4858
4375
  radius,
4859
4376
  });
4860
- };
4861
- #fixVertical = (pos, radius, outMode) => {
4377
+ }
4378
+ #fixVertical(pos, radius, outMode) {
4862
4379
  fixOutMode({
4863
4380
  outMode,
4864
4381
  checkModes: [OutMode.bounce],
@@ -4867,8 +4384,8 @@
4867
4384
  setCb: (value) => (pos.y += value),
4868
4385
  radius,
4869
4386
  });
4870
- };
4871
- #getDefaultInsideCanvasResult = (direction, outMode) => {
4387
+ }
4388
+ #getDefaultInsideCanvasResult(direction, outMode) {
4872
4389
  const radius = this.getRadius(), canvasSize = this.#container.canvas.size, position = this.position, isBounce = outMode === OutMode.bounce;
4873
4390
  if (direction === OutModeDirection.bottom) {
4874
4391
  return {
@@ -4901,8 +4418,8 @@
4901
4418
  position.x <= canvasSize.width + radius,
4902
4419
  reason: "default",
4903
4420
  };
4904
- };
4905
- #getInsideCanvasCallbackData = (direction, outMode) => {
4421
+ }
4422
+ #getInsideCanvasCallbackData(direction, outMode) {
4906
4423
  return {
4907
4424
  canvasSize: this.#container.canvas.size,
4908
4425
  direction,
@@ -4910,8 +4427,8 @@
4910
4427
  particle: this,
4911
4428
  radius: this.getRadius(),
4912
4429
  };
4913
- };
4914
- #getInsideCanvasResult = (data) => {
4430
+ }
4431
+ #getInsideCanvasResult(data) {
4915
4432
  const defaultResult = this.#getDefaultInsideCanvasResult(data.direction, data.outMode), container = this.#container, shapeDrawer = this.shape ? container.shapeDrawers.get(this.shape) : undefined, effectDrawer = this.effect ? container.effectDrawers.get(this.effect) : undefined, shapeCheck = shapeDrawer?.isInsideCanvas, effectCheck = effectDrawer?.isInsideCanvas;
4916
4433
  if (!shapeCheck && !effectCheck) {
4917
4434
  return defaultResult;
@@ -4926,8 +4443,8 @@
4926
4443
  };
4927
4444
  }
4928
4445
  return shapeResult ?? effectResult ?? defaultResult;
4929
- };
4930
- #getRollColor = color => {
4446
+ }
4447
+ #getRollColor(color) {
4931
4448
  if (!color || !this.roll || (!this.backColor && !this.roll.alter)) {
4932
4449
  return color;
4933
4450
  }
@@ -4941,8 +4458,8 @@
4941
4458
  return alterHsl(color, this.roll.alter.type, this.roll.alter.value);
4942
4459
  }
4943
4460
  return color;
4944
- };
4945
- #initPosition = position => {
4461
+ }
4462
+ #initPosition(position) {
4946
4463
  const container = this.#container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this.#calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
4947
4464
  if (!initialPosition) {
4948
4465
  throw new Error("a valid position cannot be found for particle");
@@ -4965,8 +4482,8 @@
4965
4482
  break;
4966
4483
  }
4967
4484
  this.offset = Vector.origin;
4968
- };
4969
- #normalizeInsideCanvasResult = (result, reason) => {
4485
+ }
4486
+ #normalizeInsideCanvasResult(result, reason) {
4970
4487
  if (typeof result === "boolean") {
4971
4488
  return {
4972
4489
  inside: result,
@@ -4978,7 +4495,7 @@
4978
4495
  margin: result.margin,
4979
4496
  reason: result.reason ?? reason,
4980
4497
  };
4981
- };
4498
+ }
4982
4499
  }
4983
4500
 
4984
4501
  class SpatialHashGrid {
@@ -5331,10 +4848,10 @@
5331
4848
  }
5332
4849
  this.#resizeFactor = undefined;
5333
4850
  }
5334
- #addToPool = (...particles) => {
4851
+ #addToPool(...particles) {
5335
4852
  this.#pool.push(...particles);
5336
- };
5337
- #applyDensity = (options, pluginsCount, group, groupOptions) => {
4853
+ }
4854
+ #applyDensity(options, pluginsCount, group, groupOptions) {
5338
4855
  const numberOptions = options.number;
5339
4856
  if (!numberOptions.density.enable) {
5340
4857
  if (group === undefined) {
@@ -5358,36 +4875,19 @@
5358
4875
  else if (particlesCount > particlesNumber) {
5359
4876
  this.removeQuantity(particlesCount - particlesNumber, group);
5360
4877
  }
5361
- };
5362
- #createBuckets = (zLayers) => {
4878
+ }
4879
+ #createBuckets(zLayers) {
5363
4880
  const bucketCount = Math.max(Math.floor(zLayers), one);
5364
4881
  return Array.from({ length: bucketCount }, () => []);
5365
- };
5366
- #getBucketIndex = (zIndex) => {
4882
+ }
4883
+ #getBucketIndex(zIndex) {
5367
4884
  const maxBucketIndex = this.#zBuckets.length - one;
5368
4885
  if (maxBucketIndex <= minIndex) {
5369
4886
  return minIndex;
5370
4887
  }
5371
4888
  return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
5372
- };
5373
- #getParticleInsertIndex = (bucket, particleId) => {
5374
- let start = minIndex, end = bucket.length;
5375
- while (start < end) {
5376
- const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
5377
- if (!middleParticle) {
5378
- end = middle;
5379
- continue;
5380
- }
5381
- if (middleParticle.id < particleId) {
5382
- start = middle + one;
5383
- }
5384
- else {
5385
- end = middle;
5386
- }
5387
- }
5388
- return start;
5389
- };
5390
- #initDensityFactor = densityOptions => {
4889
+ }
4890
+ #initDensityFactor(densityOptions) {
5391
4891
  const container = this.#container;
5392
4892
  if (!densityOptions.enable) {
5393
4893
  return defaultDensityFactor;
@@ -5397,16 +4897,16 @@
5397
4897
  return defaultDensityFactor;
5398
4898
  }
5399
4899
  return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
5400
- };
5401
- #insertParticleIntoBucket = (particle) => {
4900
+ }
4901
+ #insertParticleIntoBucket(particle) {
5402
4902
  const bucketIndex = this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
5403
4903
  if (!bucket) {
5404
4904
  return;
5405
4905
  }
5406
- bucket.splice(this.#getParticleInsertIndex(bucket, particle.id), empty, particle);
4906
+ bucket.push(particle);
5407
4907
  this.#particleBuckets.set(particle.id, bucketIndex);
5408
- };
5409
- #removeParticle = (index, group, override) => {
4908
+ }
4909
+ #removeParticle(index, group, override) {
5410
4910
  const particle = this.#array[index];
5411
4911
  if (!particle) {
5412
4912
  return false;
@@ -5422,22 +4922,20 @@
5422
4922
  });
5423
4923
  this.#addToPool(particle);
5424
4924
  return true;
5425
- };
5426
- #removeParticleFromBucket = (particle) => {
4925
+ }
4926
+ #removeParticleFromBucket(particle) {
5427
4927
  const bucketIndex = this.#particleBuckets.get(particle.id) ?? this.#getBucketIndex(particle.position.z), bucket = this.#zBuckets[bucketIndex];
5428
4928
  if (!bucket) {
5429
4929
  this.#particleBuckets.delete(particle.id);
5430
4930
  return;
5431
4931
  }
5432
- const particleIndex = this.#getParticleInsertIndex(bucket, particle.id);
5433
- if (bucket[particleIndex]?.id !== particle.id) {
5434
- this.#particleBuckets.delete(particle.id);
5435
- return;
4932
+ const idx = bucket.findIndex(p => p.id === particle.id);
4933
+ if (idx >= minIndex) {
4934
+ bucket.splice(idx, deleteCount);
5436
4935
  }
5437
- bucket.splice(particleIndex, deleteCount);
5438
4936
  this.#particleBuckets.delete(particle.id);
5439
- };
5440
- #resetBuckets = (zLayers) => {
4937
+ }
4938
+ #resetBuckets(zLayers) {
5441
4939
  const bucketCount = Math.max(Math.floor(zLayers), one);
5442
4940
  if (this.#zBuckets.length !== bucketCount) {
5443
4941
  this.#zBuckets = this.#createBuckets(bucketCount);
@@ -5446,8 +4944,8 @@
5446
4944
  for (const bucket of this.#zBuckets) {
5447
4945
  bucket.length = minIndex;
5448
4946
  }
5449
- };
5450
- #updateParticleBucket = (particle) => {
4947
+ }
4948
+ #updateParticleBucket(particle) {
5451
4949
  const newBucketIndex = this.#getBucketIndex(particle.position.z), currentBucketIndex = this.#particleBuckets.get(particle.id);
5452
4950
  if (currentBucketIndex === undefined) {
5453
4951
  this.#insertParticleIntoBucket(particle);
@@ -5458,9 +4956,9 @@
5458
4956
  }
5459
4957
  const currentBucket = this.#zBuckets[currentBucketIndex];
5460
4958
  if (currentBucket) {
5461
- const particleIndex = this.#getParticleInsertIndex(currentBucket, particle.id);
5462
- if (currentBucket[particleIndex]?.id === particle.id) {
5463
- currentBucket.splice(particleIndex, deleteCount);
4959
+ const idx = currentBucket.findIndex(p => p.id === particle.id);
4960
+ if (idx >= minIndex) {
4961
+ currentBucket.splice(idx, deleteCount);
5464
4962
  }
5465
4963
  }
5466
4964
  const newBucket = this.#zBuckets[newBucketIndex];
@@ -5468,10 +4966,16 @@
5468
4966
  this.#particleBuckets.set(particle.id, newBucketIndex);
5469
4967
  return;
5470
4968
  }
5471
- newBucket.splice(this.#getParticleInsertIndex(newBucket, particle.id), empty, particle);
4969
+ newBucket.push(particle);
4970
+ if (newBucket.length >= double) {
4971
+ const prev = newBucket[newBucket.length - double];
4972
+ if (prev && particle.id < prev.id) {
4973
+ newBucket.sort((a, b) => a.id - b.id);
4974
+ }
4975
+ }
5472
4976
  this.#particleBuckets.set(particle.id, newBucketIndex);
5473
- };
5474
- #updateParticlesPhase1 = (delta) => {
4977
+ }
4978
+ #updateParticlesPhase1(delta) {
5475
4979
  const particlesToDelete = new Set(), resizeFactor = this.#resizeFactor;
5476
4980
  for (const particle of this.#array) {
5477
4981
  if (resizeFactor && !particle.ignoresResizeRatio) {
@@ -5497,8 +5001,8 @@
5497
5001
  this.grid.insert(particle);
5498
5002
  }
5499
5003
  return particlesToDelete;
5500
- };
5501
- #updateParticlesPhase2 = (delta, particlesToDelete) => {
5004
+ }
5005
+ #updateParticlesPhase2(delta, particlesToDelete) {
5502
5006
  for (const particle of this.#array) {
5503
5007
  if (particle.destroyed) {
5504
5008
  particlesToDelete.add(particle);
@@ -5514,7 +5018,7 @@
5514
5018
  }
5515
5019
  this.#updateParticleBucket(particle);
5516
5020
  }
5517
- };
5021
+ }
5518
5022
  }
5519
5023
 
5520
5024
  class Retina {
@@ -5876,7 +5380,7 @@
5876
5380
  }
5877
5381
  return refresh;
5878
5382
  }
5879
- #nextFrame = (timestamp) => {
5383
+ #nextFrame(timestamp) {
5880
5384
  try {
5881
5385
  if (!this.#smooth &&
5882
5386
  this.#lastFrameTime !== undefined &&
@@ -5904,7 +5408,7 @@
5904
5408
  catch (e) {
5905
5409
  getLogger().error("error in animation loop", e);
5906
5410
  }
5907
- };
5411
+ }
5908
5412
  }
5909
5413
 
5910
5414
  var Container$1 = /*#__PURE__*/Object.freeze({
@@ -5950,7 +5454,7 @@
5950
5454
  BlendPluginInstance: BlendPluginInstance
5951
5455
  });
5952
5456
 
5953
- const minVelocity = 0, identity = 1, moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01, defaultPathDelay = 0, noDecay = 1;
5457
+ const moveSpeedFactor = 60, minSpinRadius = 0, spinFactor = 0.01, defaultPathDelay = 0, noDecay = 1;
5954
5458
  function applyDistance(particle) {
5955
5459
  const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical;
5956
5460
  if (!hDistance && !vDistance) {