@tsparticles/fireworks 4.0.0-beta.15 → 4.0.0-beta.17

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
- /* tsParticles v4.0.0-beta.15 */
2
+ /* tsParticles v4.0.0-beta.17 */
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) :
@@ -1081,7 +1081,7 @@
1081
1081
  }
1082
1082
  }
1083
1083
  else {
1084
- const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases[canvasFirstIndex];
1084
+ const existingCanvases = domContainer.getElementsByTagName(canvasTag), foundCanvas = existingCanvases.item(canvasFirstIndex);
1085
1085
  if (foundCanvas) {
1086
1086
  canvasEl = foundCanvas;
1087
1087
  canvasEl.dataset[generatedAttribute] = generatedFalse;
@@ -1118,7 +1118,7 @@
1118
1118
  return this._domArray;
1119
1119
  }
1120
1120
  get version() {
1121
- return "4.0.0-beta.15";
1121
+ return "4.0.0-beta.17";
1122
1122
  }
1123
1123
  addEventListener(type, listener) {
1124
1124
  this._eventDispatcher.addEventListener(type, listener);
@@ -1149,7 +1149,11 @@
1149
1149
  }
1150
1150
  async load(params) {
1151
1151
  await this.init();
1152
- const { Container } = await Promise.resolve().then(function () { return Container$1; }), id = params.id ?? params.element?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
1152
+ let domSourceElement;
1153
+ if (typeof HTMLElement !== "undefined" && params.element instanceof HTMLElement) {
1154
+ domSourceElement = params.element;
1155
+ }
1156
+ const { Container } = await Promise.resolve().then(function () { return Container$1; }), id = params.id ?? domSourceElement?.id ?? `tsparticles${Math.floor(getRandom() * loadRandomFactor).toString()}`, { index, url } = params, options = url ? await getDataFromUrl({ fallback: params.options, url, index }) : params.options, currentOptions = itemFromSingleOrMultiple(options, index), { items } = this, oldIndex = items.findIndex(v => v.id.description === id), newItem = new Container({
1153
1157
  dispatchCallback: (eventType, args) => {
1154
1158
  this.dispatchEvent(eventType, args);
1155
1159
  },
@@ -1176,8 +1180,10 @@
1176
1180
  else {
1177
1181
  items.push(newItem);
1178
1182
  }
1179
- const domContainer = getDomContainer(id, params.element), canvasEl = getCanvasFromContainer(domContainer);
1180
- newItem.canvas.loadCanvas(canvasEl);
1183
+ const sourceCanvas = typeof OffscreenCanvas !== "undefined" && params.element instanceof OffscreenCanvas
1184
+ ? params.element
1185
+ : getCanvasFromContainer(getDomContainer(id, domSourceElement));
1186
+ newItem.canvas.loadCanvas(sourceCanvas);
1181
1187
  await newItem.start();
1182
1188
  return newItem;
1183
1189
  }
@@ -3339,7 +3345,7 @@
3339
3345
  }
3340
3346
 
3341
3347
  async function loadCircleShape(engine) {
3342
- engine.checkVersion("4.0.0-beta.15");
3348
+ engine.checkVersion("4.0.0-beta.17");
3343
3349
  await engine.pluginManager.register(e => {
3344
3350
  e.pluginManager.addShape(["circle"], () => {
3345
3351
  return Promise.resolve(new CircleDrawer());
@@ -3387,7 +3393,7 @@
3387
3393
  }
3388
3394
 
3389
3395
  async function loadHexColorPlugin(engine) {
3390
- engine.checkVersion("4.0.0-beta.15");
3396
+ engine.checkVersion("4.0.0-beta.17");
3391
3397
  await engine.pluginManager.register(e => {
3392
3398
  e.pluginManager.addColorManager("hex", new HexColorManager());
3393
3399
  });
@@ -3440,7 +3446,7 @@
3440
3446
  }
3441
3447
 
3442
3448
  async function loadHslColorPlugin(engine) {
3443
- engine.checkVersion("4.0.0-beta.15");
3449
+ engine.checkVersion("4.0.0-beta.17");
3444
3450
  await engine.pluginManager.register(e => {
3445
3451
  e.pluginManager.addColorManager("hsl", new HslColorManager());
3446
3452
  });
@@ -3464,7 +3470,7 @@
3464
3470
  }
3465
3471
 
3466
3472
  async function loadMovePlugin(engine) {
3467
- engine.checkVersion("4.0.0-beta.15");
3473
+ engine.checkVersion("4.0.0-beta.17");
3468
3474
  await engine.pluginManager.register(e => {
3469
3475
  const moveEngine = e, movePluginManager = moveEngine.pluginManager;
3470
3476
  movePluginManager.initializers.pathGenerators ??= new Map();
@@ -3525,7 +3531,7 @@
3525
3531
  }
3526
3532
 
3527
3533
  async function loadOpacityUpdater(engine) {
3528
- engine.checkVersion("4.0.0-beta.15");
3534
+ engine.checkVersion("4.0.0-beta.17");
3529
3535
  await engine.pluginManager.register(e => {
3530
3536
  e.pluginManager.addParticleUpdater("opacity", container => {
3531
3537
  return Promise.resolve(new OpacityUpdater(container));
@@ -3877,7 +3883,7 @@
3877
3883
  }
3878
3884
 
3879
3885
  async function loadOutModesUpdater(engine) {
3880
- engine.checkVersion("4.0.0-beta.15");
3886
+ engine.checkVersion("4.0.0-beta.17");
3881
3887
  await engine.pluginManager.register(e => {
3882
3888
  e.pluginManager.addParticleUpdater("outModes", container => {
3883
3889
  return Promise.resolve(new OutOfCanvasUpdater(container));
@@ -3948,7 +3954,7 @@
3948
3954
  }
3949
3955
 
3950
3956
  async function loadPaintUpdater(engine) {
3951
- engine.checkVersion("4.0.0-beta.15");
3957
+ engine.checkVersion("4.0.0-beta.17");
3952
3958
  await engine.pluginManager.register(e => {
3953
3959
  e.pluginManager.addParticleUpdater("paint", container => {
3954
3960
  return Promise.resolve(new PaintUpdater(e.pluginManager, container));
@@ -4003,7 +4009,7 @@
4003
4009
  }
4004
4010
 
4005
4011
  async function loadRgbColorPlugin(engine) {
4006
- engine.checkVersion("4.0.0-beta.15");
4012
+ engine.checkVersion("4.0.0-beta.17");
4007
4013
  await engine.pluginManager.register(e => {
4008
4014
  e.pluginManager.addColorManager("rgb", new RgbColorManager());
4009
4015
  });
@@ -4046,7 +4052,7 @@
4046
4052
  }
4047
4053
 
4048
4054
  async function loadSizeUpdater(engine) {
4049
- engine.checkVersion("4.0.0-beta.15");
4055
+ engine.checkVersion("4.0.0-beta.17");
4050
4056
  await engine.pluginManager.register(e => {
4051
4057
  e.pluginManager.addParticleUpdater("size", container => {
4052
4058
  return Promise.resolve(new SizeUpdater(container));
@@ -4055,7 +4061,7 @@
4055
4061
  }
4056
4062
 
4057
4063
  async function loadBasic(engine) {
4058
- engine.checkVersion("4.0.0-beta.15");
4064
+ engine.checkVersion("4.0.0-beta.17");
4059
4065
  await engine.pluginManager.register(async (e) => {
4060
4066
  await Promise.all([
4061
4067
  loadHexColorPlugin(e),
@@ -4117,7 +4123,7 @@
4117
4123
  }
4118
4124
 
4119
4125
  async function loadBlendPlugin(engine) {
4120
- engine.checkVersion("4.0.0-beta.15");
4126
+ engine.checkVersion("4.0.0-beta.17");
4121
4127
  await engine.pluginManager.register(e => {
4122
4128
  e.pluginManager.addPlugin(new BlendPlugin());
4123
4129
  });
@@ -4476,7 +4482,7 @@
4476
4482
  }
4477
4483
 
4478
4484
  async function loadDestroyUpdater(engine) {
4479
- engine.checkVersion("4.0.0-beta.15");
4485
+ engine.checkVersion("4.0.0-beta.17");
4480
4486
  await engine.pluginManager.register(e => {
4481
4487
  e.pluginManager.addParticleUpdater("destroy", container => {
4482
4488
  return Promise.resolve(new DestroyUpdater(e.pluginManager, container));
@@ -4769,7 +4775,7 @@
4769
4775
  })(EmitterClickMode || (EmitterClickMode = {}));
4770
4776
 
4771
4777
  async function loadEmittersPluginSimple(engine) {
4772
- engine.checkVersion("4.0.0-beta.15");
4778
+ engine.checkVersion("4.0.0-beta.17");
4773
4779
  await engine.pluginManager.register(async (e) => {
4774
4780
  const instancesManager = await getEmittersInstancesManager(e);
4775
4781
  await addEmittersShapesManager(e);
@@ -4857,7 +4863,7 @@
4857
4863
  }
4858
4864
 
4859
4865
  async function loadEmittersShapeSquare(engine) {
4860
- engine.checkVersion("4.0.0-beta.15");
4866
+ engine.checkVersion("4.0.0-beta.17");
4861
4867
  await engine.pluginManager.register((e) => {
4862
4868
  ensureEmittersPluginLoaded(e);
4863
4869
  e.pluginManager.addEmitterShapeGenerator?.("square", new EmittersSquareShapeGenerator());
@@ -5023,7 +5029,7 @@
5023
5029
  }
5024
5030
 
5025
5031
  async function loadLifeUpdater(engine) {
5026
- engine.checkVersion("4.0.0-beta.15");
5032
+ engine.checkVersion("4.0.0-beta.17");
5027
5033
  await engine.pluginManager.register(e => {
5028
5034
  e.pluginManager.addParticleUpdater("life", container => {
5029
5035
  return Promise.resolve(new LifeUpdater(container));
@@ -5049,7 +5055,7 @@
5049
5055
  }
5050
5056
 
5051
5057
  async function loadLineShape(engine) {
5052
- engine.checkVersion("4.0.0-beta.15");
5058
+ engine.checkVersion("4.0.0-beta.17");
5053
5059
  await engine.pluginManager.register(e => {
5054
5060
  e.pluginManager.addShape(["line"], () => Promise.resolve(new LineDrawer()));
5055
5061
  });
@@ -5181,7 +5187,7 @@
5181
5187
  }
5182
5188
 
5183
5189
  async function loadRotateUpdater(engine) {
5184
- engine.checkVersion("4.0.0-beta.15");
5190
+ engine.checkVersion("4.0.0-beta.17");
5185
5191
  await engine.pluginManager.register(e => {
5186
5192
  e.pluginManager.addParticleUpdater("rotate", container => {
5187
5193
  return Promise.resolve(new RotateUpdater(container));
@@ -5562,7 +5568,7 @@
5562
5568
  }
5563
5569
 
5564
5570
  async function loadSoundsPlugin(engine) {
5565
- engine.checkVersion("4.0.0-beta.15");
5571
+ engine.checkVersion("4.0.0-beta.17");
5566
5572
  await engine.pluginManager.register(e => {
5567
5573
  e.pluginManager.addPlugin(new SoundsPlugin(e));
5568
5574
  });
@@ -5570,7 +5576,7 @@
5570
5576
 
5571
5577
  let initPromise = null;
5572
5578
  async function doInitPlugins(engine) {
5573
- engine.checkVersion("4.0.0-beta.15");
5579
+ engine.checkVersion("4.0.0-beta.17");
5574
5580
  await engine.pluginManager.register(async (e) => {
5575
5581
  const loadEmittersForFireworks = async (e) => {
5576
5582
  await loadEmittersPluginSimple(e);
@@ -5617,7 +5623,7 @@
5617
5623
  fireworks.init = async () => {
5618
5624
  await initPlugins(tsParticles);
5619
5625
  };
5620
- fireworks.version = "4.0.0-beta.15";
5626
+ fireworks.version = "4.0.0-beta.17";
5621
5627
  globalThis.fireworks = fireworks;
5622
5628
 
5623
5629
  const globalObject = globalThis;
@@ -5925,6 +5931,25 @@
5925
5931
  };
5926
5932
  }
5927
5933
 
5934
+ const transferredCanvases = new WeakMap(), getTransferredCanvas = (canvas) => {
5935
+ const transferredCanvas = transferredCanvases.get(canvas);
5936
+ if (transferredCanvas) {
5937
+ return transferredCanvas;
5938
+ }
5939
+ if (typeof canvas.transferControlToOffscreen !== "function") {
5940
+ throw new TypeError("OffscreenCanvas is required but not supported by this browser");
5941
+ }
5942
+ try {
5943
+ const offscreenCanvas = canvas.transferControlToOffscreen();
5944
+ transferredCanvases.set(canvas, offscreenCanvas);
5945
+ return offscreenCanvas;
5946
+ }
5947
+ catch {
5948
+ throw new TypeError("OffscreenCanvas transfer failed");
5949
+ }
5950
+ }, isHtmlCanvasElement = (canvas) => {
5951
+ return typeof HTMLCanvasElement !== "undefined" && canvas instanceof HTMLCanvasElement;
5952
+ };
5928
5953
  function setStyle(canvas, style, important = false) {
5929
5954
  if (!style) {
5930
5955
  return;
@@ -5955,8 +5980,9 @@
5955
5980
  }
5956
5981
  }
5957
5982
  class CanvasManager {
5958
- element;
5983
+ domElement;
5959
5984
  render;
5985
+ renderCanvas;
5960
5986
  size;
5961
5987
  zoom = defaultZoom;
5962
5988
  _container;
@@ -5991,9 +6017,10 @@
5991
6017
  destroy() {
5992
6018
  this.stop();
5993
6019
  if (this._generated) {
5994
- const element = this.element;
6020
+ const element = this.domElement;
5995
6021
  element?.remove();
5996
- this.element = undefined;
6022
+ this.domElement = undefined;
6023
+ this.renderCanvas = undefined;
5997
6024
  }
5998
6025
  else {
5999
6026
  this._resetOriginalStyle();
@@ -6026,16 +6053,17 @@
6026
6053
  this._initStyle();
6027
6054
  this.initBackground();
6028
6055
  this._safeMutationObserver(obs => {
6029
- if (!this.element || !(this.element instanceof Node)) {
6056
+ const element = this.domElement;
6057
+ if (!element || !(element instanceof Node)) {
6030
6058
  return;
6031
6059
  }
6032
- obs.observe(this.element, { attributes: true });
6060
+ obs.observe(element, { attributes: true });
6033
6061
  });
6034
6062
  this.initPlugins();
6035
6063
  this.render.init();
6036
6064
  }
6037
6065
  initBackground() {
6038
- const { _container } = this, options = _container.actualOptions, background = options.background, element = this.element;
6066
+ const { _container } = this, options = _container.actualOptions, background = options.background, element = this.domElement;
6039
6067
  if (!element) {
6040
6068
  return;
6041
6069
  }
@@ -6060,21 +6088,30 @@
6060
6088
  }
6061
6089
  }
6062
6090
  loadCanvas(canvas) {
6063
- if (this._generated && this.element) {
6064
- this.element.remove();
6091
+ if (this._generated && this.domElement) {
6092
+ this.domElement.remove();
6093
+ }
6094
+ const container = this._container, domCanvas = isHtmlCanvasElement(canvas) ? canvas : undefined;
6095
+ this.domElement = domCanvas;
6096
+ this._generated = domCanvas ? domCanvas.dataset[generatedAttribute] === "true" : false;
6097
+ this.renderCanvas = domCanvas ? getTransferredCanvas(domCanvas) : canvas;
6098
+ const domElement = this.domElement;
6099
+ if (domElement) {
6100
+ domElement.ariaHidden = "true";
6101
+ this._originalStyle = cloneStyle(domElement.style);
6102
+ }
6103
+ const standardSize = this._standardSize, renderCanvas = this.renderCanvas;
6104
+ if (domElement) {
6105
+ standardSize.height = domElement.offsetHeight;
6106
+ standardSize.width = domElement.offsetWidth;
6107
+ }
6108
+ else {
6109
+ standardSize.height = renderCanvas.height;
6110
+ standardSize.width = renderCanvas.width;
6065
6111
  }
6066
- const container = this._container;
6067
- this._generated =
6068
- generatedAttribute in canvas.dataset ? canvas.dataset[generatedAttribute] === "true" : this._generated;
6069
- this.element = canvas;
6070
- this.element.ariaHidden = "true";
6071
- this._originalStyle = cloneStyle(this.element.style);
6072
- const standardSize = this._standardSize;
6073
- standardSize.height = canvas.offsetHeight;
6074
- standardSize.width = canvas.offsetWidth;
6075
6112
  const pxRatio = this._container.retina.pixelRatio, retinaSize = this.size;
6076
- canvas.height = retinaSize.height = standardSize.height * pxRatio;
6077
- canvas.width = retinaSize.width = standardSize.width * pxRatio;
6113
+ renderCanvas.height = retinaSize.height = standardSize.height * pxRatio;
6114
+ renderCanvas.width = retinaSize.width = standardSize.width * pxRatio;
6078
6115
  const canSupportHdrQuery = safeMatchMedia("(color-gamut: p3)");
6079
6116
  this.render.setContextSettings({
6080
6117
  alpha: true,
@@ -6082,42 +6119,48 @@
6082
6119
  desynchronized: true,
6083
6120
  willReadFrequently: false,
6084
6121
  });
6085
- this.render.setContext(this.element.getContext("2d", this.render.settings));
6122
+ this.render.setContext(renderCanvas.getContext("2d", this.render.settings));
6086
6123
  this._safeMutationObserver(obs => {
6087
6124
  obs.disconnect();
6088
6125
  });
6089
6126
  container.retina.init();
6090
6127
  this.initBackground();
6091
6128
  this._safeMutationObserver(obs => {
6092
- if (!this.element || !(this.element instanceof Node)) {
6129
+ const element = this.domElement;
6130
+ if (!element || !(element instanceof Node)) {
6093
6131
  return;
6094
6132
  }
6095
- obs.observe(this.element, { attributes: true });
6133
+ obs.observe(element, { attributes: true });
6096
6134
  });
6097
6135
  }
6098
6136
  resize() {
6099
- if (!this.element) {
6137
+ const element = this.domElement;
6138
+ if (!element) {
6139
+ return false;
6140
+ }
6141
+ const container = this._container, renderCanvas = this.renderCanvas;
6142
+ if (renderCanvas === undefined) {
6100
6143
  return false;
6101
6144
  }
6102
- const container = this._container, currentSize = container.canvas._standardSize, newSize = {
6103
- width: this.element.offsetWidth,
6104
- height: this.element.offsetHeight,
6145
+ const currentSize = container.canvas._standardSize, newSize = {
6146
+ width: element.offsetWidth,
6147
+ height: element.offsetHeight,
6105
6148
  }, pxRatio = container.retina.pixelRatio, retinaSize = {
6106
6149
  width: newSize.width * pxRatio,
6107
6150
  height: newSize.height * pxRatio,
6108
6151
  };
6109
6152
  if (newSize.height === currentSize.height &&
6110
6153
  newSize.width === currentSize.width &&
6111
- retinaSize.height === this.element.height &&
6112
- retinaSize.width === this.element.width) {
6154
+ retinaSize.height === renderCanvas.height &&
6155
+ retinaSize.width === renderCanvas.width) {
6113
6156
  return false;
6114
6157
  }
6115
6158
  const oldSize = { ...currentSize };
6116
6159
  currentSize.height = newSize.height;
6117
6160
  currentSize.width = newSize.width;
6118
6161
  const canvasSize = this.size;
6119
- this.element.width = canvasSize.width = retinaSize.width;
6120
- this.element.height = canvasSize.height = retinaSize.height;
6162
+ renderCanvas.width = canvasSize.width = retinaSize.width;
6163
+ renderCanvas.height = canvasSize.height = retinaSize.height;
6121
6164
  if (this._container.started) {
6122
6165
  container.particles.setResizeFactor({
6123
6166
  width: currentSize.width / oldSize.width,
@@ -6127,7 +6170,7 @@
6127
6170
  return true;
6128
6171
  }
6129
6172
  setPointerEvents(type) {
6130
- const element = this.element;
6173
+ const element = this.domElement;
6131
6174
  if (!element) {
6132
6175
  return;
6133
6176
  }
@@ -6146,7 +6189,7 @@
6146
6189
  this.render.stop();
6147
6190
  }
6148
6191
  async windowResize() {
6149
- if (!this.element || !this.resize()) {
6192
+ if (!this.domElement || !this.resize()) {
6150
6193
  return;
6151
6194
  }
6152
6195
  const container = this._container, needsRefresh = container.updateActualOptions();
@@ -6162,7 +6205,7 @@
6162
6205
  }
6163
6206
  };
6164
6207
  _initStyle = () => {
6165
- const element = this.element, options = this._container.actualOptions;
6208
+ const element = this.domElement, options = this._container.actualOptions;
6166
6209
  if (!element) {
6167
6210
  return;
6168
6211
  }
@@ -6184,7 +6227,7 @@
6184
6227
  }
6185
6228
  };
6186
6229
  _repairStyle = () => {
6187
- const element = this.element;
6230
+ const element = this.domElement;
6188
6231
  if (!element) {
6189
6232
  return;
6190
6233
  }
@@ -6204,7 +6247,7 @@
6204
6247
  });
6205
6248
  };
6206
6249
  _resetOriginalStyle = () => {
6207
- const element = this.element, originalStyle = this._originalStyle;
6250
+ const element = this.domElement, originalStyle = this._originalStyle;
6208
6251
  if (!element || !originalStyle) {
6209
6252
  return;
6210
6253
  }
@@ -6217,7 +6260,7 @@
6217
6260
  callback(this._mutationObserver);
6218
6261
  };
6219
6262
  _setFullScreenStyle = () => {
6220
- const element = this.element;
6263
+ const element = this.domElement;
6221
6264
  if (!element) {
6222
6265
  return;
6223
6266
  }
@@ -6291,7 +6334,7 @@
6291
6334
  manageListener(globalThis, resizeEvent, handlers.resize, add);
6292
6335
  return;
6293
6336
  }
6294
- const canvasEl = container.canvas.element;
6337
+ const canvasEl = container.canvas.domElement;
6295
6338
  if (this._resizeObserver && !add) {
6296
6339
  if (canvasEl) {
6297
6340
  this._resizeObserver.unobserve(canvasEl);
@@ -6546,8 +6589,6 @@
6546
6589
  this._initPosition(position);
6547
6590
  this.initialVelocity = this._calculateVelocity();
6548
6591
  this.velocity = this.initialVelocity.copy();
6549
- const particles = container.particles;
6550
- particles.setLastZIndex(this.position.z);
6551
6592
  this.zIndexFactor = this.position.z / container.zLayers;
6552
6593
  this.sides = 24;
6553
6594
  let effectDrawer, shapeDrawer;
@@ -6697,7 +6738,7 @@
6697
6738
  return color;
6698
6739
  };
6699
6740
  _initPosition = position => {
6700
- const container = this._container, zIndexValue = getRangeValue(this.options.zIndex.value), initialPosition = this._calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
6741
+ const container = this._container, zIndexValue = Math.floor(getRangeValue(this.options.zIndex.value)), initialPosition = this._calcPosition(position, clamp(zIndexValue, minZ, container.zLayers));
6701
6742
  if (!initialPosition) {
6702
6743
  throw new Error("a valid position cannot be found for particle");
6703
6744
  }
@@ -6831,10 +6872,8 @@
6831
6872
  _container;
6832
6873
  _groupLimits;
6833
6874
  _limit;
6834
- _maxZIndex;
6835
- _minZIndex;
6836
- _needsSort;
6837
6875
  _nextId;
6876
+ _particleBuckets;
6838
6877
  _particleResetPlugins;
6839
6878
  _particleUpdatePlugins;
6840
6879
  _pluginManager;
@@ -6843,19 +6882,17 @@
6843
6882
  _postUpdatePlugins;
6844
6883
  _resizeFactor;
6845
6884
  _updatePlugins;
6846
- _zArray;
6885
+ _zBuckets;
6847
6886
  constructor(pluginManager, container) {
6848
6887
  this._pluginManager = pluginManager;
6849
6888
  this._container = container;
6850
6889
  this._nextId = 0;
6851
6890
  this._array = [];
6852
- this._zArray = [];
6853
6891
  this._pool = [];
6854
6892
  this._limit = 0;
6855
6893
  this._groupLimits = new Map();
6856
- this._needsSort = false;
6857
- this._minZIndex = 0;
6858
- this._maxZIndex = 0;
6894
+ this._particleBuckets = new Map();
6895
+ this._zBuckets = this._createBuckets(this._container.zLayers);
6859
6896
  this.grid = new SpatialHashGrid(spatialHashGridCellSize);
6860
6897
  this.checkParticlePositionPlugins = [];
6861
6898
  this._particleResetPlugins = [];
@@ -6897,7 +6934,7 @@
6897
6934
  return;
6898
6935
  }
6899
6936
  this._array.push(particle);
6900
- this._zArray.push(particle);
6937
+ this._insertParticleIntoBucket(particle);
6901
6938
  this._nextId++;
6902
6939
  this._container.dispatchEvent(exports.EventType.particleAdded, {
6903
6940
  particle,
@@ -6911,12 +6948,14 @@
6911
6948
  }
6912
6949
  clear() {
6913
6950
  this._array = [];
6914
- this._zArray = [];
6951
+ this._particleBuckets.clear();
6952
+ this._resetBuckets(this._container.zLayers);
6915
6953
  }
6916
6954
  destroy() {
6917
6955
  this._array = [];
6918
6956
  this._pool.length = 0;
6919
- this._zArray = [];
6957
+ this._particleBuckets.clear();
6958
+ this._zBuckets = [];
6920
6959
  this.checkParticlePositionPlugins = [];
6921
6960
  this._particleResetPlugins = [];
6922
6961
  this._particleUpdatePlugins = [];
@@ -6925,8 +6964,14 @@
6925
6964
  this._updatePlugins = [];
6926
6965
  }
6927
6966
  drawParticles(delta) {
6928
- for (const particle of this._zArray) {
6929
- particle.draw(delta);
6967
+ for (let i = this._zBuckets.length - one; i >= minIndex; i--) {
6968
+ const bucket = this._zBuckets[i];
6969
+ if (!bucket) {
6970
+ continue;
6971
+ }
6972
+ for (const particle of bucket) {
6973
+ particle.draw(delta);
6974
+ }
6930
6975
  }
6931
6976
  }
6932
6977
  filter(condition) {
@@ -6940,15 +6985,14 @@
6940
6985
  }
6941
6986
  async init() {
6942
6987
  const container = this._container, options = container.actualOptions;
6943
- this._minZIndex = 0;
6944
- this._maxZIndex = 0;
6945
- this._needsSort = false;
6946
6988
  this.checkParticlePositionPlugins = [];
6947
6989
  this._updatePlugins = [];
6948
6990
  this._particleUpdatePlugins = [];
6949
6991
  this._postUpdatePlugins = [];
6950
6992
  this._particleResetPlugins = [];
6951
6993
  this._postParticleUpdatePlugins = [];
6994
+ this._particleBuckets.clear();
6995
+ this._resetBuckets(container.zLayers);
6952
6996
  this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
6953
6997
  for (const plugin of container.plugins) {
6954
6998
  if (plugin.redrawInit) {
@@ -7049,79 +7093,25 @@
7049
7093
  }
7050
7094
  this._applyDensity(options.particles, pluginsCount);
7051
7095
  }
7052
- setLastZIndex(zIndex) {
7053
- this._needsSort ||= zIndex >= this._maxZIndex || (zIndex > this._minZIndex && zIndex < this._maxZIndex);
7054
- }
7055
7096
  setResizeFactor(factor) {
7056
7097
  this._resizeFactor = factor;
7057
7098
  }
7058
7099
  update(delta) {
7059
- const particlesToDelete = new Set();
7060
7100
  this.grid.clear();
7061
7101
  for (const plugin of this._updatePlugins) {
7062
7102
  plugin.update?.(delta);
7063
7103
  }
7064
- const resizeFactor = this._resizeFactor;
7065
- for (const particle of this._array) {
7066
- if (resizeFactor && !particle.ignoresResizeRatio) {
7067
- particle.position.x *= resizeFactor.width;
7068
- particle.position.y *= resizeFactor.height;
7069
- particle.initialPosition.x *= resizeFactor.width;
7070
- particle.initialPosition.y *= resizeFactor.height;
7071
- }
7072
- particle.ignoresResizeRatio = false;
7073
- for (const plugin of this._particleResetPlugins) {
7074
- plugin.particleReset?.(particle);
7075
- }
7076
- for (const plugin of this._particleUpdatePlugins) {
7077
- if (particle.destroyed) {
7078
- break;
7079
- }
7080
- plugin.particleUpdate?.(particle, delta);
7081
- }
7082
- if (particle.destroyed) {
7083
- particlesToDelete.add(particle);
7084
- continue;
7085
- }
7086
- this.grid.insert(particle);
7087
- }
7104
+ const particlesToDelete = this._updateParticlesPhase1(delta);
7088
7105
  for (const plugin of this._postUpdatePlugins) {
7089
7106
  plugin.postUpdate?.(delta);
7090
7107
  }
7091
- for (const particle of this._array) {
7092
- if (particle.destroyed) {
7093
- particlesToDelete.add(particle);
7094
- continue;
7095
- }
7096
- for (const updater of this._container.particleUpdaters) {
7097
- updater.update(particle, delta);
7098
- }
7099
- if (!particle.destroyed && !particle.spawning) {
7100
- for (const plugin of this._postParticleUpdatePlugins) {
7101
- plugin.postParticleUpdate?.(particle, delta);
7102
- }
7103
- }
7104
- else if (particle.destroyed) {
7105
- particlesToDelete.add(particle);
7106
- }
7107
- }
7108
+ this._updateParticlesPhase2(delta, particlesToDelete);
7108
7109
  if (particlesToDelete.size) {
7109
7110
  for (const particle of particlesToDelete) {
7110
7111
  this.remove(particle);
7111
7112
  }
7112
7113
  }
7113
7114
  delete this._resizeFactor;
7114
- if (this._needsSort) {
7115
- const zArray = this._zArray;
7116
- zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
7117
- const firstItem = zArray[minIndex], lastItem = zArray[zArray.length - lengthOffset];
7118
- if (!firstItem || !lastItem) {
7119
- return;
7120
- }
7121
- this._maxZIndex = firstItem.position.z;
7122
- this._minZIndex = lastItem.position.z;
7123
- this._needsSort = false;
7124
- }
7125
7115
  }
7126
7116
  _addToPool = (...particles) => {
7127
7117
  this._pool.push(...particles);
@@ -7151,13 +7141,52 @@
7151
7141
  this.removeQuantity(particlesCount - particlesNumber, group);
7152
7142
  }
7153
7143
  };
7144
+ _createBuckets = (zLayers) => {
7145
+ const bucketCount = Math.max(Math.floor(zLayers), one);
7146
+ return Array.from({ length: bucketCount }, () => []);
7147
+ };
7148
+ _getBucketIndex = (zIndex) => {
7149
+ const maxBucketIndex = this._zBuckets.length - one;
7150
+ if (maxBucketIndex <= minIndex) {
7151
+ return minIndex;
7152
+ }
7153
+ return Math.min(Math.max(Math.floor(zIndex), minIndex), maxBucketIndex);
7154
+ };
7155
+ _getParticleInsertIndex = (bucket, particleId) => {
7156
+ let start = minIndex, end = bucket.length;
7157
+ while (start < end) {
7158
+ const middle = Math.floor((start + end) / double), middleParticle = bucket[middle];
7159
+ if (!middleParticle) {
7160
+ end = middle;
7161
+ continue;
7162
+ }
7163
+ if (middleParticle.id < particleId) {
7164
+ start = middle + one;
7165
+ }
7166
+ else {
7167
+ end = middle;
7168
+ }
7169
+ }
7170
+ return start;
7171
+ };
7154
7172
  _initDensityFactor = densityOptions => {
7155
7173
  const container = this._container;
7156
- if (!container.canvas.element || !densityOptions.enable) {
7174
+ if (!densityOptions.enable) {
7175
+ return defaultDensityFactor;
7176
+ }
7177
+ const canvasSize = container.canvas.size, pxRatio = container.retina.pixelRatio;
7178
+ if (!canvasSize.width || !canvasSize.height) {
7157
7179
  return defaultDensityFactor;
7158
7180
  }
7159
- const canvas = container.canvas.element, pxRatio = container.retina.pixelRatio;
7160
- return (canvas.width * canvas.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp);
7181
+ return ((canvasSize.width * canvasSize.height) / (densityOptions.height * densityOptions.width * pxRatio ** squareExp));
7182
+ };
7183
+ _insertParticleIntoBucket = (particle) => {
7184
+ const bucketIndex = this._getBucketIndex(particle.position.z), bucket = this._zBuckets[bucketIndex];
7185
+ if (!bucket) {
7186
+ return;
7187
+ }
7188
+ bucket.splice(this._getParticleInsertIndex(bucket, particle.id), empty, particle);
7189
+ this._particleBuckets.set(particle.id, bucketIndex);
7161
7190
  };
7162
7191
  _removeParticle = (index, group, override) => {
7163
7192
  const particle = this._array[index];
@@ -7167,9 +7196,8 @@
7167
7196
  if (particle.group !== group) {
7168
7197
  return false;
7169
7198
  }
7170
- const zIdx = this._zArray.indexOf(particle);
7171
7199
  this._array.splice(index, deleteCount);
7172
- this._zArray.splice(zIdx, deleteCount);
7200
+ this._removeParticleFromBucket(particle);
7173
7201
  particle.destroy(override);
7174
7202
  this._container.dispatchEvent(exports.EventType.particleRemoved, {
7175
7203
  particle,
@@ -7177,6 +7205,98 @@
7177
7205
  this._addToPool(particle);
7178
7206
  return true;
7179
7207
  };
7208
+ _removeParticleFromBucket = (particle) => {
7209
+ const bucketIndex = this._particleBuckets.get(particle.id) ?? this._getBucketIndex(particle.position.z), bucket = this._zBuckets[bucketIndex];
7210
+ if (!bucket) {
7211
+ this._particleBuckets.delete(particle.id);
7212
+ return;
7213
+ }
7214
+ const particleIndex = this._getParticleInsertIndex(bucket, particle.id);
7215
+ if (bucket[particleIndex]?.id !== particle.id) {
7216
+ this._particleBuckets.delete(particle.id);
7217
+ return;
7218
+ }
7219
+ bucket.splice(particleIndex, deleteCount);
7220
+ this._particleBuckets.delete(particle.id);
7221
+ };
7222
+ _resetBuckets = (zLayers) => {
7223
+ const bucketCount = Math.max(Math.floor(zLayers), one);
7224
+ if (this._zBuckets.length !== bucketCount) {
7225
+ this._zBuckets = this._createBuckets(bucketCount);
7226
+ return;
7227
+ }
7228
+ for (const bucket of this._zBuckets) {
7229
+ bucket.length = minIndex;
7230
+ }
7231
+ };
7232
+ _updateParticleBucket = (particle) => {
7233
+ const newBucketIndex = this._getBucketIndex(particle.position.z), currentBucketIndex = this._particleBuckets.get(particle.id);
7234
+ if (currentBucketIndex === undefined) {
7235
+ this._insertParticleIntoBucket(particle);
7236
+ return;
7237
+ }
7238
+ if (currentBucketIndex === newBucketIndex) {
7239
+ return;
7240
+ }
7241
+ const currentBucket = this._zBuckets[currentBucketIndex];
7242
+ if (currentBucket) {
7243
+ const particleIndex = this._getParticleInsertIndex(currentBucket, particle.id);
7244
+ if (currentBucket[particleIndex]?.id === particle.id) {
7245
+ currentBucket.splice(particleIndex, deleteCount);
7246
+ }
7247
+ }
7248
+ const newBucket = this._zBuckets[newBucketIndex];
7249
+ if (!newBucket) {
7250
+ this._particleBuckets.set(particle.id, newBucketIndex);
7251
+ return;
7252
+ }
7253
+ newBucket.splice(this._getParticleInsertIndex(newBucket, particle.id), empty, particle);
7254
+ this._particleBuckets.set(particle.id, newBucketIndex);
7255
+ };
7256
+ _updateParticlesPhase1 = (delta) => {
7257
+ const particlesToDelete = new Set(), resizeFactor = this._resizeFactor;
7258
+ for (const particle of this._array) {
7259
+ if (resizeFactor && !particle.ignoresResizeRatio) {
7260
+ particle.position.x *= resizeFactor.width;
7261
+ particle.position.y *= resizeFactor.height;
7262
+ particle.initialPosition.x *= resizeFactor.width;
7263
+ particle.initialPosition.y *= resizeFactor.height;
7264
+ }
7265
+ particle.ignoresResizeRatio = false;
7266
+ for (const plugin of this._particleResetPlugins) {
7267
+ plugin.particleReset?.(particle);
7268
+ }
7269
+ for (const plugin of this._particleUpdatePlugins) {
7270
+ if (particle.destroyed) {
7271
+ break;
7272
+ }
7273
+ plugin.particleUpdate?.(particle, delta);
7274
+ }
7275
+ if (particle.destroyed) {
7276
+ particlesToDelete.add(particle);
7277
+ continue;
7278
+ }
7279
+ this.grid.insert(particle);
7280
+ }
7281
+ return particlesToDelete;
7282
+ };
7283
+ _updateParticlesPhase2 = (delta, particlesToDelete) => {
7284
+ for (const particle of this._array) {
7285
+ if (particle.destroyed) {
7286
+ particlesToDelete.add(particle);
7287
+ continue;
7288
+ }
7289
+ for (const updater of this._container.particleUpdaters) {
7290
+ updater.update(particle, delta);
7291
+ }
7292
+ if (!particle.spawning) {
7293
+ for (const plugin of this._postParticleUpdatePlugins) {
7294
+ plugin.postParticleUpdate?.(particle, delta);
7295
+ }
7296
+ }
7297
+ this._updateParticleBucket(particle);
7298
+ }
7299
+ };
7180
7300
  }
7181
7301
 
7182
7302
  class Retina {
@@ -7192,9 +7312,8 @@
7192
7312
  const container = this.container, options = container.actualOptions;
7193
7313
  this.pixelRatio = options.detectRetina ? devicePixelRatio : defaultRatio;
7194
7314
  this.reduceFactor = defaultReduceFactor;
7195
- const ratio = this.pixelRatio, canvas = container.canvas;
7196
- if (canvas.element) {
7197
- const element = canvas.element;
7315
+ const ratio = this.pixelRatio, canvas = container.canvas, element = canvas.domElement;
7316
+ if (element) {
7198
7317
  canvas.size.width = element.offsetWidth * ratio;
7199
7318
  canvas.size.height = element.offsetHeight * ratio;
7200
7319
  }
@@ -8013,7 +8132,7 @@
8013
8132
  setIconStyle(img, pos.top + margin, pos.right -
8014
8133
  (margin * (rightOffsets.length + rightOffset) + width + rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
8015
8134
  img.src = path ?? (svg ? `data:image/svg+xml;base64,${btoa(svg)}` : "");
8016
- const parent = container.canvas.element?.parentNode ?? safeDocument().body;
8135
+ const parent = container.canvas.domElement?.parentNode ?? safeDocument().body;
8017
8136
  parent.append(img);
8018
8137
  img.addEventListener("click", () => {
8019
8138
  void clickCb();
@@ -8101,11 +8220,11 @@
8101
8220
  }
8102
8221
  async start() {
8103
8222
  const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
8104
- if (!soundsOptions?.enable || !container.canvas.element) {
8223
+ if (!soundsOptions?.enable || !container.canvas.domElement) {
8105
8224
  return;
8106
8225
  }
8107
8226
  container.muted = true;
8108
- const canvas = container.canvas.element, pos = {
8227
+ const canvas = container.canvas.domElement, pos = {
8109
8228
  top: canvas.offsetTop,
8110
8229
  right: canvas.offsetLeft + canvas.offsetWidth,
8111
8230
  }, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
@@ -8216,7 +8335,7 @@
8216
8335
  }
8217
8336
  _initEvents = () => {
8218
8337
  const container = this._container, soundsOptions = container.actualOptions.sounds;
8219
- if (!soundsOptions?.enable || !container.canvas.element) {
8338
+ if (!soundsOptions?.enable || !container.canvas.domElement) {
8220
8339
  return;
8221
8340
  }
8222
8341
  for (const event of soundsOptions.events) {