@tsparticles/preset-snow 4.3.2 → 4.4.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.3.2 */
2
+ /* Preset v4.4.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) :
@@ -797,7 +797,7 @@
797
797
  return this.#domArray;
798
798
  }
799
799
  get version() {
800
- return "4.3.2";
800
+ return "4.4.0";
801
801
  }
802
802
  addEventListener(type, listener) {
803
803
  this.#eventDispatcher.addEventListener(type, listener);
@@ -878,6 +878,10 @@
878
878
  }
879
879
 
880
880
  function initEngine() {
881
+ const existing = globalThis.tsParticles;
882
+ if (existing?.pluginManager) {
883
+ return existing;
884
+ }
881
885
  return new Engine();
882
886
  }
883
887
 
@@ -975,6 +979,15 @@
975
979
  AnimationMode["random"] = "random";
976
980
  })(AnimationMode || (AnimationMode = {}));
977
981
 
982
+ var HdrMode;
983
+ (function (HdrMode) {
984
+ HdrMode["standard"] = "standard";
985
+ HdrMode["natural"] = "natural";
986
+ HdrMode["vivid"] = "vivid";
987
+ HdrMode["cinematic"] = "cinematic";
988
+ HdrMode["dynamic"] = "dynamic";
989
+ })(HdrMode || (HdrMode = {}));
990
+
978
991
  var LimitMode;
979
992
  (function (LimitMode) {
980
993
  LimitMode["delete"] = "delete";
@@ -1230,6 +1243,29 @@
1230
1243
  }
1231
1244
  }
1232
1245
 
1246
+ const defaultPeakNits = 400, minPeakNits = 0, toStringValue = (value) => String(value);
1247
+ class HDROptions extends OptionLoader {
1248
+ enable = true;
1249
+ mode = HdrMode.standard;
1250
+ peakNits = defaultPeakNits;
1251
+ doLoad(data) {
1252
+ if (data.enable !== undefined && !isBoolean(data.enable)) {
1253
+ throw new Error(`Invalid HDR "enable" value: expected a boolean, got "${String(data.enable)}"`);
1254
+ }
1255
+ if (data.mode !== undefined &&
1256
+ (typeof data.mode !== "string" || !Object.values(HdrMode).includes(data.mode))) {
1257
+ throw new Error(`Invalid HDR "mode" value: expected one of ${Object.values(HdrMode).join(", ")}, got "${toStringValue(data.mode)}"`);
1258
+ }
1259
+ if (data.peakNits !== undefined &&
1260
+ (!isNumber(data.peakNits) || !Number.isFinite(data.peakNits) || data.peakNits <= minPeakNits)) {
1261
+ throw new Error(`Invalid HDR "peakNits" value: expected a positive number, got "${String(data.peakNits)}"`);
1262
+ }
1263
+ loadProperty(this, "enable", data.enable);
1264
+ loadProperty(this, "mode", data.mode);
1265
+ loadProperty(this, "peakNits", data.peakNits);
1266
+ }
1267
+ }
1268
+
1233
1269
  class ResizeEvent extends OptionLoader {
1234
1270
  delay = 0.5;
1235
1271
  enable = true;
@@ -1673,7 +1709,7 @@
1673
1709
  duration = 0;
1674
1710
  fpsLimit = 120;
1675
1711
  fullScreen;
1676
- hdr = true;
1712
+ hdr;
1677
1713
  key;
1678
1714
  name;
1679
1715
  palette;
@@ -1693,6 +1729,7 @@
1693
1729
  this.#container = container;
1694
1730
  this.background = new Background();
1695
1731
  this.fullScreen = new FullScreen();
1732
+ this.hdr = new HDROptions();
1696
1733
  this.particles = loadParticlesOptions(this.#pluginManager, this.#container);
1697
1734
  this.resize = new ResizeEvent();
1698
1735
  }
@@ -1715,7 +1752,15 @@
1715
1752
  loadProperty(this, "detectRetina", data.detectRetina);
1716
1753
  loadRangeProperty(this, "duration", data.duration);
1717
1754
  loadProperty(this, "fpsLimit", data.fpsLimit);
1718
- loadProperty(this, "hdr", data.hdr);
1755
+ const hdrData = data.hdr;
1756
+ if (isBoolean(hdrData)) {
1757
+ this.hdr.enable = hdrData;
1758
+ this.hdr.mode = HdrMode.standard;
1759
+ this.hdr.peakNits = 400;
1760
+ }
1761
+ else {
1762
+ this.hdr.load(hdrData);
1763
+ }
1719
1764
  loadProperty(this, "pauseOnBlur", data.pauseOnBlur);
1720
1765
  loadProperty(this, "pauseOnOutsideViewport", data.pauseOnOutsideViewport);
1721
1766
  loadProperty(this, "zLayers", data.zLayers);
@@ -1758,7 +1803,7 @@
1758
1803
  }
1759
1804
  }
1760
1805
 
1761
- const styleCache = new Map(), maxStyleCacheSize = 2000, rgbFixedPrecision = 2, hslFixedPrecision = 2, hdrRgbFixedPrecision = 4, hdrHslFixedPrecision = 4, sdrReferenceWhiteNits = 203, hdrAnimationScale = sdrReferenceWhiteNits / maxNits;
1806
+ const styleCache = new Map(), maxStyleCacheSize = 2000, rgbFixedPrecision = 2, hslFixedPrecision = 2, hdrRgbFixedPrecision = 4, hdrHslFixedPrecision = 4, sdrReferenceWhiteNits = 203, acesA = 2.51, acesB = 0.03, acesC = 2.43, acesD = 0.59, acesE = 0.14, saturationBoost = 1.15, lightnessBoost = 1.05, temperatureR = 1.05, temperatureB = 0.95, contrastFactor = 1.1, luminanceR = 0.2126, luminanceG = 0.7152, luminanceB = 0.0722, dynamicLuminanceFactor = 2, channelCount = 3;
1762
1807
  function getCachedStyle(key, generator) {
1763
1808
  let cached = styleCache.get(key);
1764
1809
  if (!cached) {
@@ -1770,6 +1815,42 @@
1770
1815
  }
1771
1816
  return cached;
1772
1817
  }
1818
+ function acesFilmic(x) {
1819
+ return clamp((x * (acesA * x + acesB)) / (x * (acesC * x + acesD) + acesE), none, one);
1820
+ }
1821
+ function applyHdrModeAdjustments(r, g, b, mode, maxChannel) {
1822
+ switch (mode) {
1823
+ case HdrMode.vivid: {
1824
+ const avg = (r + g + b) / channelCount;
1825
+ return {
1826
+ b: clamp(clamp(avg + (b - avg) * saturationBoost, none, maxChannel) * lightnessBoost, none, maxChannel),
1827
+ g: clamp(clamp(avg + (g - avg) * saturationBoost, none, maxChannel) * lightnessBoost, none, maxChannel),
1828
+ r: clamp(clamp(avg + (r - avg) * saturationBoost, none, maxChannel) * lightnessBoost, none, maxChannel),
1829
+ };
1830
+ }
1831
+ case HdrMode.cinematic: {
1832
+ const tempR = r * temperatureR, tempB = b * temperatureB, avg = (tempR + g + tempB) / channelCount;
1833
+ return {
1834
+ b: clamp(avg + (tempB - avg) * contrastFactor, none, maxChannel),
1835
+ g: clamp(avg + (g - avg) * contrastFactor, none, maxChannel),
1836
+ r: clamp(avg + (tempR - avg) * contrastFactor, none, maxChannel),
1837
+ };
1838
+ }
1839
+ case HdrMode.dynamic: {
1840
+ const luminance = luminanceR * r + luminanceG * g + luminanceB * b, vividWeight = Math.min(one, luminance * dynamicLuminanceFactor), naturalWeight = one - vividWeight, avg = (r + g + b) / channelCount, vividR = clamp(avg + (r - avg) * saturationBoost, none, maxChannel) * lightnessBoost, vividG = clamp(avg + (g - avg) * saturationBoost, none, maxChannel) * lightnessBoost, vividB = clamp(avg + (b - avg) * saturationBoost, none, maxChannel) * lightnessBoost;
1841
+ return {
1842
+ b: clamp(b * naturalWeight + vividB * vividWeight, none, maxChannel),
1843
+ g: clamp(g * naturalWeight + vividG * vividWeight, none, maxChannel),
1844
+ r: clamp(r * naturalWeight + vividR * vividWeight, none, maxChannel),
1845
+ };
1846
+ }
1847
+ case HdrMode.standard:
1848
+ return { b, g, r };
1849
+ case HdrMode.natural:
1850
+ default:
1851
+ return { b, g, r };
1852
+ }
1853
+ }
1773
1854
  function stringToRgba(pluginManager, input) {
1774
1855
  if (!input) {
1775
1856
  return;
@@ -1927,21 +2008,40 @@
1927
2008
  r: getRgbInRangeValue(),
1928
2009
  };
1929
2010
  }
1930
- function getStyleFromRgb(color, hdr, opacity) {
1931
- const rgbPrecision = hdr ? hdrRgbFixedPrecision : rgbFixedPrecision, op = opacity ?? defaultOpacity$1, key = `rgb-${color.r.toFixed(rgbPrecision)}-${color.g.toFixed(rgbPrecision)}-${color.b.toFixed(rgbPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
1932
- return getCachedStyle(key, () => (hdr ? getHdrStyleFromRgb(color, opacity) : getSdrStyleFromRgb(color, opacity)));
2011
+ function getStyleFromRgb(color, hdr, opacity, peakNits, mode) {
2012
+ const rgbPrecision = hdr ? hdrRgbFixedPrecision : rgbFixedPrecision, op = opacity ?? defaultOpacity$1, key = hdr
2013
+ ? `rgb-${color.r.toFixed(rgbPrecision)}-${color.g.toFixed(rgbPrecision)}-${color.b.toFixed(rgbPrecision)}-hdr-${op.toString()}-${(peakNits ?? maxNits).toString()}-${mode ?? HdrMode.standard}`
2014
+ : `rgb-${color.r.toFixed(rgbPrecision)}-${color.g.toFixed(rgbPrecision)}-${color.b.toFixed(rgbPrecision)}-sdr-${op.toString()}`;
2015
+ return getCachedStyle(key, () => hdr ? getHdrStyleFromRgb(color, opacity, peakNits, mode) : getSdrStyleFromRgb(color, opacity));
2016
+ }
2017
+ function getHdrStyleFromRgb(color, opacity, peakNits = maxNits, mode = HdrMode.standard) {
2018
+ const headroom = peakNits / sdrReferenceWhiteNits, middleGray = 0.18, mapped = hdrToneMapColor(color, headroom, middleGray, mode);
2019
+ return `color(display-p3 ${mapped.r.toString()} ${mapped.g.toString()} ${mapped.b.toString()} / ${(opacity ?? defaultOpacity$1).toString()})`;
1933
2020
  }
1934
- function getHdrStyleFromRgb(color, opacity, peakNits = maxNits) {
1935
- const headroom = peakNits / sdrReferenceWhiteNits;
1936
- return `color(display-p3 ${((color.r / rgbMax) * headroom).toString()} ${((color.g / rgbMax) * headroom).toString()} ${((color.b / rgbMax) * headroom).toString()} / ${(opacity ?? defaultOpacity$1).toString()})`;
2021
+ function hdrToneMapColor(color, headroom, middleGray, mode) {
2022
+ const rNorm = color.r / rgbMax, gNorm = color.g / rgbMax, bNorm = color.b / rgbMax;
2023
+ if (mode !== HdrMode.natural && mode !== HdrMode.vivid && mode !== HdrMode.cinematic && mode !== HdrMode.dynamic) {
2024
+ return { b: bNorm, g: gNorm, r: rNorm };
2025
+ }
2026
+ const maxChannel = Math.max(one, headroom), luminance = luminanceR * rNorm + luminanceG * gNorm + luminanceB * bNorm, mappedLuminance = hdrToneMap(luminance, headroom, middleGray), scale = luminance > none ? mappedLuminance / luminance : one;
2027
+ return applyHdrModeAdjustments(clamp(rNorm * scale, none, maxChannel), clamp(gNorm * scale, none, maxChannel), clamp(bNorm * scale, none, maxChannel), mode, maxChannel);
2028
+ }
2029
+ function hdrToneMap(normalized, headroom, middleGray) {
2030
+ if (normalized <= middleGray) {
2031
+ return acesFilmic(normalized);
2032
+ }
2033
+ const expanded = normalized + (normalized - middleGray) * (headroom - one);
2034
+ return acesFilmic(expanded);
1937
2035
  }
1938
2036
  function getSdrStyleFromRgb(color, opacity) {
1939
2037
  return `rgba(${color.r.toString()}, ${color.g.toString()}, ${color.b.toString()}, ${(opacity ?? defaultOpacity$1).toString()})`;
1940
2038
  }
1941
- function getStyleFromHsl(color, hdr, opacity) {
1942
- const hslPrecision = hdr ? hdrHslFixedPrecision : hslFixedPrecision, op = opacity ?? defaultOpacity$1, key = `hsl-${color.h.toFixed(hslPrecision)}-${color.s.toFixed(hslPrecision)}-${color.l.toFixed(hslPrecision)}-${hdr ? "hdr" : "sdr"}-${op.toString()}`;
2039
+ function getStyleFromHsl(color, hdr, opacity, peakNits, mode) {
2040
+ const hslPrecision = hdr ? hdrHslFixedPrecision : hslFixedPrecision, op = opacity ?? defaultOpacity$1, key = hdr
2041
+ ? `hsl-${color.h.toFixed(hslPrecision)}-${color.s.toFixed(hslPrecision)}-${color.l.toFixed(hslPrecision)}-hdr-${op.toString()}-${(peakNits ?? maxNits).toString()}-${mode ?? HdrMode.standard}`
2042
+ : `hsl-${color.h.toFixed(hslPrecision)}-${color.s.toFixed(hslPrecision)}-${color.l.toFixed(hslPrecision)}-sdr-${op.toString()}`;
1943
2043
  return getCachedStyle(key, () => hdr
1944
- ? getStyleFromRgb(hslToRgbFloat(color), true, opacity)
2044
+ ? getStyleFromRgb(hslToRgbFloat(color), true, opacity, peakNits, mode)
1945
2045
  : `hsla(${color.h.toString()}, ${color.s.toString()}%, ${color.l.toString()}%, ${op.toString()})`);
1946
2046
  }
1947
2047
  function getHslFromAnimation(animation) {
@@ -2004,7 +2104,7 @@
2004
2104
  colorValue.velocity = defaultVelocity;
2005
2105
  }
2006
2106
  }
2007
- function updateColorValue(data, decrease, delta, hdr) {
2107
+ function updateColorValue(data, decrease, delta, _hdr) {
2008
2108
  const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
2009
2109
  if (!data.enable ||
2010
2110
  ((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
@@ -2017,7 +2117,7 @@
2017
2117
  if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
2018
2118
  return;
2019
2119
  }
2020
- const offset = data.offset ? randomInRangeValue(data.offset) : minOffset, velocity = ((data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor) * (hdr ? hdrAnimationScale : identity), decay = data.decay ?? identity, max = data.max, min = data.min;
2120
+ const offset = data.offset ? randomInRangeValue(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = data.max, min = data.min;
2021
2121
  if (!decrease || data.status === AnimationStatus.increasing) {
2022
2122
  data.value += velocity;
2023
2123
  if (data.value > max) {
@@ -2049,9 +2149,9 @@
2049
2149
  return;
2050
2150
  }
2051
2151
  const { h, s, l } = color;
2052
- updateColorValue(h, false, delta, hdr);
2053
- updateColorValue(s, true, delta, hdr);
2054
- updateColorValue(l, true, delta, hdr);
2152
+ updateColorValue(h, false, delta);
2153
+ updateColorValue(s, true, delta);
2154
+ updateColorValue(l, true, delta);
2055
2155
  }
2056
2156
  function alterHsl(color, type, value) {
2057
2157
  return {
@@ -2101,7 +2201,7 @@
2101
2201
  }
2102
2202
 
2103
2203
  async function loadBlendPlugin(engine) {
2104
- engine.checkVersion("4.3.2");
2204
+ engine.checkVersion("4.4.0");
2105
2205
  await engine.pluginManager.register(e => {
2106
2206
  e.pluginManager.addPlugin(new BlendPlugin());
2107
2207
  });
@@ -2138,7 +2238,7 @@
2138
2238
  }
2139
2239
 
2140
2240
  async function loadCircleShape(engine) {
2141
- engine.checkVersion("4.3.2");
2241
+ engine.checkVersion("4.4.0");
2142
2242
  await engine.pluginManager.register(e => {
2143
2243
  e.pluginManager.addShape(["circle"], () => {
2144
2244
  return Promise.resolve(new CircleDrawer());
@@ -2186,7 +2286,7 @@
2186
2286
  }
2187
2287
 
2188
2288
  async function loadHexColorPlugin(engine) {
2189
- engine.checkVersion("4.3.2");
2289
+ engine.checkVersion("4.4.0");
2190
2290
  await engine.pluginManager.register(e => {
2191
2291
  e.pluginManager.addColorManager("hex", new HexColorManager());
2192
2292
  });
@@ -2239,7 +2339,7 @@
2239
2339
  }
2240
2340
 
2241
2341
  async function loadHslColorPlugin(engine) {
2242
- engine.checkVersion("4.3.2");
2342
+ engine.checkVersion("4.4.0");
2243
2343
  await engine.pluginManager.register(e => {
2244
2344
  e.pluginManager.addColorManager("hsl", new HslColorManager());
2245
2345
  });
@@ -2263,7 +2363,7 @@
2263
2363
  }
2264
2364
 
2265
2365
  async function loadMovePlugin(engine) {
2266
- engine.checkVersion("4.3.2");
2366
+ engine.checkVersion("4.4.0");
2267
2367
  await engine.pluginManager.register(e => {
2268
2368
  const moveEngine = e, movePluginManager = moveEngine.pluginManager;
2269
2369
  movePluginManager.initializers.pathGenerators ??= new Map();
@@ -2473,7 +2573,7 @@
2473
2573
  }
2474
2574
 
2475
2575
  async function loadOpacityUpdater(engine) {
2476
- engine.checkVersion("4.3.2");
2576
+ engine.checkVersion("4.4.0");
2477
2577
  await engine.pluginManager.register(e => {
2478
2578
  e.pluginManager.addParticleUpdater("opacity", container => {
2479
2579
  return Promise.resolve(new OpacityUpdater(container));
@@ -2818,7 +2918,7 @@
2818
2918
  }
2819
2919
 
2820
2920
  async function loadOutModesUpdater(engine) {
2821
- engine.checkVersion("4.3.2");
2921
+ engine.checkVersion("4.4.0");
2822
2922
  await engine.pluginManager.register(e => {
2823
2923
  e.pluginManager.addParticleUpdater("outModes", container => {
2824
2924
  return Promise.resolve(new OutOfCanvasUpdater(container));
@@ -2889,7 +2989,7 @@
2889
2989
  }
2890
2990
 
2891
2991
  async function loadPaintUpdater(engine) {
2892
- engine.checkVersion("4.3.2");
2992
+ engine.checkVersion("4.4.0");
2893
2993
  await engine.pluginManager.register(e => {
2894
2994
  e.pluginManager.addParticleUpdater("paint", container => {
2895
2995
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -2944,7 +3044,7 @@
2944
3044
  }
2945
3045
 
2946
3046
  async function loadRgbColorPlugin(engine) {
2947
- engine.checkVersion("4.3.2");
3047
+ engine.checkVersion("4.4.0");
2948
3048
  await engine.pluginManager.register(e => {
2949
3049
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
2950
3050
  });
@@ -3029,7 +3129,7 @@
3029
3129
  }
3030
3130
 
3031
3131
  async function loadSizeUpdater(engine) {
3032
- engine.checkVersion("4.3.2");
3132
+ engine.checkVersion("4.4.0");
3033
3133
  await engine.pluginManager.register(e => {
3034
3134
  e.pluginManager.addParticleUpdater("size", container => {
3035
3135
  return Promise.resolve(new SizeUpdater(container));
@@ -3038,7 +3138,7 @@
3038
3138
  }
3039
3139
 
3040
3140
  async function loadBasic(engine) {
3041
- engine.checkVersion("4.3.2");
3141
+ engine.checkVersion("4.4.0");
3042
3142
  await engine.pluginManager.register(async (e) => {
3043
3143
  await Promise.all([
3044
3144
  loadBlendPlugin(e),
@@ -3174,7 +3274,7 @@
3174
3274
  }
3175
3275
 
3176
3276
  async function loadWobbleUpdater(engine) {
3177
- engine.checkVersion("4.3.2");
3277
+ engine.checkVersion("4.4.0");
3178
3278
  await engine.pluginManager.register(e => {
3179
3279
  e.pluginManager.addParticleUpdater("wobble", container => {
3180
3280
  return Promise.resolve(new WobbleUpdater(container));
@@ -3341,7 +3441,11 @@
3341
3441
  if (!fColor && !sColor) {
3342
3442
  return;
3343
3443
  }
3344
- const container = this.#container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this.#reusableTransform, colorStyles = this.#reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity) : fill;
3444
+ const container = this.#container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this.#reusableTransform, colorStyles = this.#reusableColorStyles, fill = fColor
3445
+ ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity, container.peakNits, container.hdrMode)
3446
+ : undefined, stroke = sColor
3447
+ ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity, container.peakNits, container.hdrMode)
3448
+ : fill;
3345
3449
  transform.a = transform.b = transform.c = transform.d = undefined;
3346
3450
  colorStyles.fill = fill;
3347
3451
  colorStyles.stroke = stroke;
@@ -3675,7 +3779,9 @@
3675
3779
  if (typeof background.element === "string") {
3676
3780
  if (typeof document !== "undefined") {
3677
3781
  const node = document.querySelector(background.element);
3678
- if (node instanceof HTMLCanvasElement || node instanceof HTMLVideoElement || node instanceof HTMLImageElement) {
3782
+ if ((typeof HTMLCanvasElement !== "undefined" && node instanceof HTMLCanvasElement) ||
3783
+ (typeof HTMLVideoElement !== "undefined" && node instanceof HTMLVideoElement) ||
3784
+ (typeof HTMLImageElement !== "undefined" && node instanceof HTMLImageElement)) {
3679
3785
  this.#backgroundElement = node;
3680
3786
  }
3681
3787
  else if (node) {
@@ -3686,10 +3792,10 @@
3686
3792
  }
3687
3793
  }
3688
3794
  }
3689
- else if (background.element instanceof HTMLCanvasElement ||
3690
- background.element instanceof OffscreenCanvas ||
3691
- background.element instanceof HTMLVideoElement ||
3692
- background.element instanceof HTMLImageElement) {
3795
+ else if ((typeof HTMLCanvasElement !== "undefined" && background.element instanceof HTMLCanvasElement) ||
3796
+ (typeof OffscreenCanvas !== "undefined" && background.element instanceof OffscreenCanvas) ||
3797
+ (typeof HTMLVideoElement !== "undefined" && background.element instanceof HTMLVideoElement) ||
3798
+ (typeof HTMLImageElement !== "undefined" && background.element instanceof HTMLImageElement)) {
3693
3799
  this.#backgroundElement = background.element;
3694
3800
  }
3695
3801
  }
@@ -3757,6 +3863,7 @@
3757
3863
  zoom = defaultZoom;
3758
3864
  #container;
3759
3865
  #generated;
3866
+ #hdrMediaListeners;
3760
3867
  #mutationObserver;
3761
3868
  #originalStyle;
3762
3869
  #pluginManager;
@@ -3821,7 +3928,6 @@
3821
3928
  });
3822
3929
  this.resize();
3823
3930
  this.#initStyle();
3824
- this.initBackground();
3825
3931
  this.#safeMutationObserver(obs => {
3826
3932
  const element = this.domElement;
3827
3933
  if (!element || !(element instanceof Node)) {
@@ -3831,6 +3937,8 @@
3831
3937
  });
3832
3938
  this.initPlugins();
3833
3939
  this.#initContext();
3940
+ this.initBackground();
3941
+ this.#initHdrListeners();
3834
3942
  this.render.init();
3835
3943
  }
3836
3944
  initBackground() {
@@ -3840,7 +3948,8 @@
3840
3948
  }
3841
3949
  const elementStyle = element.style, color = rangeColorToRgb(this.#pluginManager, background.color);
3842
3950
  if (color) {
3843
- elementStyle.backgroundColor = getStyleFromRgb(color, container.actualOptions.hdr, background.opacity);
3951
+ const hdrOptions = container.actualOptions.hdr;
3952
+ elementStyle.backgroundColor = getStyleFromRgb(color, container.hdr, background.opacity, hdrOptions.peakNits, hdrOptions.mode);
3844
3953
  }
3845
3954
  else {
3846
3955
  elementStyle.backgroundColor = "";
@@ -3937,6 +4046,7 @@
3937
4046
  obs.disconnect();
3938
4047
  });
3939
4048
  this.#mutationObserver = undefined;
4049
+ this.#removeHdrListeners();
3940
4050
  this.render.stop();
3941
4051
  }
3942
4052
  async windowResize() {
@@ -3956,9 +4066,16 @@
3956
4066
  }
3957
4067
  }
3958
4068
  #initContext() {
3959
- const container = this.#container, canSupportHdr = container.actualOptions.hdr &&
4069
+ const container = this.#container, canSupportHdr = container.actualOptions.hdr.enable &&
3960
4070
  safeMatchMedia("(color-gamut: p3)")?.matches &&
3961
4071
  safeMatchMedia("(dynamic-range: high)")?.matches;
4072
+ container.hdr = canSupportHdr ?? false;
4073
+ container.hdrMode = container.actualOptions.hdr.mode;
4074
+ container.peakNits = container.actualOptions.hdr.peakNits;
4075
+ const renderCanvas = this.renderCanvas;
4076
+ if (!renderCanvas) {
4077
+ return;
4078
+ }
3962
4079
  this.render.setContextSettings({
3963
4080
  alpha: true,
3964
4081
  desynchronized: true,
@@ -3967,11 +4084,47 @@
3967
4084
  ? { colorSpace: "display-p3", colorType: "float16" }
3968
4085
  : { colorSpace: "srgb" }),
3969
4086
  });
3970
- const renderCanvas = this.renderCanvas;
3971
- if (!renderCanvas) {
3972
- return;
4087
+ let context;
4088
+ try {
4089
+ context = renderCanvas.getContext("2d", this.render.settings);
4090
+ }
4091
+ catch {
4092
+ context = null;
4093
+ }
4094
+ if (canSupportHdr && !context) {
4095
+ container.hdr = false;
4096
+ const sdrSettings = {
4097
+ alpha: true,
4098
+ desynchronized: true,
4099
+ willReadFrequently: false,
4100
+ colorSpace: "srgb",
4101
+ };
4102
+ this.render.setContextSettings(sdrSettings);
4103
+ try {
4104
+ context = renderCanvas.getContext("2d", sdrSettings);
4105
+ }
4106
+ catch {
4107
+ context = null;
4108
+ }
4109
+ }
4110
+ this.render.setContext(context);
4111
+ }
4112
+ #initHdrListeners() {
4113
+ this.#removeHdrListeners();
4114
+ const p3Query = safeMatchMedia("(color-gamut: p3)"), hdrQuery = safeMatchMedia("(dynamic-range: high)"), handleChange = () => {
4115
+ this.#recreateRenderCanvas();
4116
+ this.#initContext();
4117
+ this.initBackground();
4118
+ }, listeners = [];
4119
+ if (p3Query) {
4120
+ p3Query.addEventListener("change", handleChange);
4121
+ listeners.push({ handler: handleChange, mql: p3Query });
4122
+ }
4123
+ if (hdrQuery) {
4124
+ hdrQuery.addEventListener("change", handleChange);
4125
+ listeners.push({ handler: handleChange, mql: hdrQuery });
3973
4126
  }
3974
- this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
4127
+ this.#hdrMediaListeners = listeners;
3975
4128
  }
3976
4129
  #initStyle() {
3977
4130
  const element = this.domElement, options = this.#container.actualOptions;
@@ -3995,6 +4148,25 @@
3995
4148
  element.style.setProperty(key, value, "important");
3996
4149
  }
3997
4150
  }
4151
+ #recreateRenderCanvas() {
4152
+ const renderCanvas = this.renderCanvas;
4153
+ if (!renderCanvas) {
4154
+ return;
4155
+ }
4156
+ if (this.domElement) {
4157
+ return;
4158
+ }
4159
+ this.renderCanvas = new OffscreenCanvas(renderCanvas.width, renderCanvas.height);
4160
+ }
4161
+ #removeHdrListeners() {
4162
+ if (!this.#hdrMediaListeners) {
4163
+ return;
4164
+ }
4165
+ for (const { handler, mql } of this.#hdrMediaListeners) {
4166
+ mql.removeEventListener("change", handler);
4167
+ }
4168
+ this.#hdrMediaListeners = undefined;
4169
+ }
3998
4170
  #repairStyle() {
3999
4171
  const element = this.domElement;
4000
4172
  if (!element) {
@@ -4379,9 +4551,9 @@
4379
4551
  }
4380
4552
  getOpacity() {
4381
4553
  const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, baseOpacity = getRangeValue(this.opacity?.value ?? defaultOpacity$1), modifierOpacity = this.#applyModifiers(undefined, m => m.opacity), opacity = modifierOpacity ?? baseOpacity, fillOpacity = this.fillOpacity ?? defaultOpacity$1, strokeOpacity = this.strokeOpacity ?? defaultOpacity$1;
4382
- this.#cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
4554
+ this.#cachedOpacityData.fillOpacity = fillOpacity;
4383
4555
  this.#cachedOpacityData.opacity = opacity * zOpacityFactor;
4384
- this.#cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
4556
+ this.#cachedOpacityData.strokeOpacity = strokeOpacity;
4385
4557
  return this.#cachedOpacityData;
4386
4558
  }
4387
4559
  getPosition() {
@@ -5236,6 +5408,7 @@
5236
5408
  effectDrawers;
5237
5409
  fpsLimit;
5238
5410
  hdr;
5411
+ hdrMode;
5239
5412
  id;
5240
5413
  pageHidden;
5241
5414
  particleCreatedPlugins;
@@ -5243,6 +5416,7 @@
5243
5416
  particlePositionPlugins;
5244
5417
  particleUpdaters;
5245
5418
  particles;
5419
+ peakNits;
5246
5420
  plugins;
5247
5421
  retina;
5248
5422
  shapeDrawers;
@@ -5273,6 +5447,8 @@
5273
5447
  this.id = Symbol(id);
5274
5448
  this.fpsLimit = 120;
5275
5449
  this.hdr = false;
5450
+ this.hdrMode = HdrMode.standard;
5451
+ this.peakNits = 400;
5276
5452
  this.#smooth = false;
5277
5453
  this.#delay = 0;
5278
5454
  this.#duration = 0;
@@ -5412,8 +5588,9 @@
5412
5588
  this.updateActualOptions();
5413
5589
  this.canvas.initBackground();
5414
5590
  this.canvas.resize();
5415
- const { delay, duration, fpsLimit, hdr, smooth, zLayers } = this.actualOptions;
5416
- this.hdr = hdr;
5591
+ const { delay, duration, fpsLimit, smooth, zLayers } = this.actualOptions, hdrOptions = this.actualOptions.hdr;
5592
+ this.hdrMode = hdrOptions.mode;
5593
+ this.peakNits = hdrOptions.peakNits;
5417
5594
  this.zLayers = zLayers;
5418
5595
  this.#duration = getRangeValue(duration) * millisecondsToSeconds;
5419
5596
  this.#delay = getRangeValue(delay) * millisecondsToSeconds;