@tsparticles/engine 4.0.0-alpha.24 → 4.0.0-alpha.26

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.
Files changed (100) hide show
  1. package/622.min.js +1 -0
  2. package/README.md +2 -2
  3. package/browser/Core/Engine.js +1 -18
  4. package/browser/Core/Particle.js +2 -23
  5. package/browser/Core/Particles.js +8 -37
  6. package/browser/Core/Utils/Constants.js +1 -1
  7. package/browser/Core/Utils/Ranges.js +2 -2
  8. package/browser/Core/Utils/SpatialHashGrid.js +82 -0
  9. package/browser/Core/Utils/Vectors.js +12 -16
  10. package/browser/Options/Classes/Particles/Move/Move.js +0 -4
  11. package/browser/Utils/CanvasUtils.js +29 -32
  12. package/browser/Utils/MathUtils.js +8 -1
  13. package/browser/Utils/Utils.js +10 -14
  14. package/browser/exports.js +0 -2
  15. package/cjs/Core/Engine.js +1 -18
  16. package/cjs/Core/Particle.js +2 -23
  17. package/cjs/Core/Particles.js +8 -37
  18. package/cjs/Core/Utils/Constants.js +1 -1
  19. package/cjs/Core/Utils/Ranges.js +2 -2
  20. package/cjs/Core/Utils/SpatialHashGrid.js +82 -0
  21. package/cjs/Core/Utils/Vectors.js +12 -16
  22. package/cjs/Options/Classes/Particles/Move/Move.js +0 -4
  23. package/cjs/Utils/CanvasUtils.js +29 -32
  24. package/cjs/Utils/MathUtils.js +8 -1
  25. package/cjs/Utils/Utils.js +10 -14
  26. package/cjs/exports.js +0 -2
  27. package/dist_browser_Core_Container_js.js +8 -8
  28. package/esm/Core/Engine.js +1 -18
  29. package/esm/Core/Particle.js +2 -23
  30. package/esm/Core/Particles.js +8 -37
  31. package/esm/Core/Utils/Constants.js +1 -1
  32. package/esm/Core/Utils/Ranges.js +2 -2
  33. package/esm/Core/Utils/SpatialHashGrid.js +82 -0
  34. package/esm/Core/Utils/Vectors.js +12 -16
  35. package/esm/Options/Classes/Particles/Move/Move.js +0 -4
  36. package/esm/Utils/CanvasUtils.js +29 -32
  37. package/esm/Utils/MathUtils.js +8 -1
  38. package/esm/Utils/Utils.js +10 -14
  39. package/esm/exports.js +0 -2
  40. package/package.json +1 -1
  41. package/report.html +1 -1
  42. package/scripts/install.js +2 -2
  43. package/tsparticles.engine.js +11 -31
  44. package/tsparticles.engine.min.js +2 -2
  45. package/types/Core/Engine.d.ts +1 -9
  46. package/types/Core/Particle.d.ts +0 -4
  47. package/types/Core/Particles.d.ts +2 -7
  48. package/types/Core/Utils/Constants.d.ts +1 -1
  49. package/types/Core/Utils/SpatialHashGrid.d.ts +18 -0
  50. package/types/Core/Utils/Vectors.d.ts +8 -10
  51. package/types/Options/Classes/Particles/Move/Move.d.ts +0 -2
  52. package/types/Options/Interfaces/Particles/Move/IMove.d.ts +0 -2
  53. package/types/Types/EngineInitializers.d.ts +0 -6
  54. package/types/Utils/CanvasUtils.d.ts +6 -7
  55. package/types/Utils/MathUtils.d.ts +2 -0
  56. package/types/export-types.d.ts +1 -4
  57. package/types/exports.d.ts +0 -2
  58. package/umd/Core/Engine.js +1 -18
  59. package/umd/Core/Particle.js +3 -24
  60. package/umd/Core/Particles.js +8 -37
  61. package/umd/Core/Utils/Constants.js +2 -2
  62. package/umd/Core/Utils/Ranges.js +1 -1
  63. package/umd/Core/Utils/SpatialHashGrid.js +96 -0
  64. package/umd/Core/Utils/Vectors.js +12 -16
  65. package/umd/Options/Classes/Particles/Move/Move.js +1 -5
  66. package/umd/Utils/CanvasUtils.js +29 -32
  67. package/umd/Utils/MathUtils.js +10 -1
  68. package/umd/Utils/Utils.js +10 -14
  69. package/umd/exports.js +1 -3
  70. package/515.min.js +0 -1
  71. package/browser/Core/Interfaces/IMovePathGenerator.js +0 -1
  72. package/browser/Core/Interfaces/IParticleMover.js +0 -1
  73. package/browser/Core/Utils/Point.js +0 -8
  74. package/browser/Core/Utils/QuadTree.js +0 -85
  75. package/browser/Options/Classes/Particles/Move/MoveAttract.js +0 -36
  76. package/browser/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
  77. package/cjs/Core/Interfaces/IMovePathGenerator.js +0 -1
  78. package/cjs/Core/Interfaces/IParticleMover.js +0 -1
  79. package/cjs/Core/Utils/Point.js +0 -8
  80. package/cjs/Core/Utils/QuadTree.js +0 -85
  81. package/cjs/Options/Classes/Particles/Move/MoveAttract.js +0 -36
  82. package/cjs/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
  83. package/esm/Core/Interfaces/IMovePathGenerator.js +0 -1
  84. package/esm/Core/Interfaces/IParticleMover.js +0 -1
  85. package/esm/Core/Utils/Point.js +0 -8
  86. package/esm/Core/Utils/QuadTree.js +0 -85
  87. package/esm/Options/Classes/Particles/Move/MoveAttract.js +0 -36
  88. package/esm/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -1
  89. package/types/Core/Interfaces/IMovePathGenerator.d.ts +0 -9
  90. package/types/Core/Interfaces/IParticleMover.d.ts +0 -7
  91. package/types/Core/Utils/Point.d.ts +0 -7
  92. package/types/Core/Utils/QuadTree.d.ts +0 -17
  93. package/types/Options/Classes/Particles/Move/MoveAttract.d.ts +0 -12
  94. package/types/Options/Interfaces/Particles/Move/IMoveAttract.d.ts +0 -7
  95. package/umd/Core/Interfaces/IMovePathGenerator.js +0 -12
  96. package/umd/Core/Interfaces/IParticleMover.js +0 -12
  97. package/umd/Core/Utils/Point.js +0 -22
  98. package/umd/Core/Utils/QuadTree.js +0 -99
  99. package/umd/Options/Classes/Particles/Move/MoveAttract.js +0 -50
  100. package/umd/Options/Interfaces/Particles/Move/IMoveAttract.js +0 -12
package/622.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_engine=this.webpackChunk_tsparticles_engine||[]).push([[622],{3622(t,i,e){e.d(i,{Container:()=>R});var s=e(8937),a=e(1873),r=e(3447),n=e(2211),o=e(8124);function l(t,i,e=!1){if(!i)return;let s=t.style,a=new Set;for(let t=0;t<s.length;t++){let i=s.item(t);i&&a.add(i)}for(let t=0;t<i.length;t++){let e=i.item(t);e&&a.add(e)}for(let t of a){let a=i.getPropertyValue(t);a?s.setProperty(t,a,e?"important":""):s.removeProperty(t)}}class h{container;element;size;zoom=a.Pf;_canvasClearPlugins;_canvasPaintPlugins;_canvasSettings;_clearDrawPlugins;_colorPlugins;_context;_drawParticlePlugins;_drawParticlesCleanupPlugins;_drawParticlesSetupPlugins;_drawPlugins;_drawSettingsCleanupPlugins;_drawSettingsSetupPlugins;_engine;_generated;_mutationObserver;_originalStyle;_pointerEvents;_postDrawUpdaters;_preDrawUpdaters;_resizePlugins;_reusableColorStyles={};_reusablePluginColors=[void 0,void 0];_reusableTransform={};_standardSize;_zoomCenter;constructor(t,i){this.container=t,this._engine=i,this._standardSize={height:0,width:0};const e=t.retina.pixelRatio,s=this._standardSize;this.size={height:s.height*e,width:s.width*e},this._context=null,this._generated=!1,this._preDrawUpdaters=[],this._postDrawUpdaters=[],this._resizePlugins=[],this._colorPlugins=[],this._canvasClearPlugins=[],this._canvasPaintPlugins=[],this._clearDrawPlugins=[],this._drawParticlePlugins=[],this._drawParticlesCleanupPlugins=[],this._drawParticlesSetupPlugins=[],this._drawPlugins=[],this._drawSettingsSetupPlugins=[],this._drawSettingsCleanupPlugins=[],this._pointerEvents="none"}get settings(){return this._canvasSettings}get _fullScreen(){return this.container.actualOptions.fullScreen.enable}canvasClear(){this.container.actualOptions.clear&&this.draw(t=>{(0,r.IU)(t,this.size)})}clear(){let t=!1;for(let i of this._canvasClearPlugins)if(t=i.canvasClear?.()??!1)break;t||this.canvasClear()}destroy(){if(this.stop(),this._generated){let t=this.element;t?.remove(),this.element=void 0}else this._resetOriginalStyle();this._preDrawUpdaters=[],this._postDrawUpdaters=[],this._resizePlugins=[],this._colorPlugins=[],this._canvasClearPlugins=[],this._canvasPaintPlugins=[],this._clearDrawPlugins=[],this._drawParticlePlugins=[],this._drawParticlesCleanupPlugins=[],this._drawParticlesSetupPlugins=[],this._drawPlugins=[],this._drawSettingsSetupPlugins=[],this._drawSettingsCleanupPlugins=[]}draw(t){let i=this._context;if(i)return t(i)}drawParticle(t,i){if(t.spawning||t.destroyed)return;let e=t.getRadius();if(e<=a.w2)return;let s=t.getFillColor(),n=t.getStrokeColor()??s,[l,h]=this._getPluginParticleColors(t);if(l??=s,h??=n,!l&&!h)return;let c=this.container,d=t.options.zIndex,p=a.RV-t.zIndexFactor,{opacity:u,strokeOpacity:_}=t.getOpacity(),g=this._reusableTransform,f=this._reusableColorStyles,P=l?(0,o.LC)(l,c.hdr,u):void 0,m=h?(0,o.LC)(h,c.hdr,_):P;g.a=g.b=g.c=g.d=void 0,f.fill=P,f.stroke=m,this.draw(s=>{for(let e of this._drawParticlesSetupPlugins)e.drawParticleSetup?.(s,t,i);for(let a of(this._applyPreDrawUpdaters(s,t,e,u,f,g),(0,r.p0)({container:c,context:s,particle:t,delta:i,colorStyles:f,radius:e*p**d.sizeRate,opacity:u,transform:g}),this._applyPostDrawUpdaters(t),this._drawParticlesCleanupPlugins))a.drawParticleCleanup?.(s,t,i)})}drawParticlePlugins(t,i){this.draw(e=>{for(let s of this._drawParticlePlugins)(0,r.Wb)(e,s,t,i)})}drawParticles(t){let{particles:i}=this.container;this.clear(),i.update(t),this.draw(e=>{for(let i of this._drawSettingsSetupPlugins)i.drawSettingsSetup?.(e,t);for(let i of this._drawPlugins)i.draw?.(e,t);for(let s of(i.drawParticles(t),this._clearDrawPlugins))s.clearDraw?.(e,t);for(let i of this._drawSettingsCleanupPlugins)i.drawSettingsCleanup?.(e,t)})}getZoomCenter(){let t=this.container.retina.pixelRatio,{width:i,height:e}=this.size;return this._zoomCenter?this._zoomCenter:{x:i*a.MX/t,y:e*a.MX/t}}init(){this._safeMutationObserver(t=>{t.disconnect()}),this._mutationObserver=(0,n.tG)(t=>{for(let i of t)"attributes"===i.type&&"style"===i.attributeName&&this._repairStyle()}),this.resize(),this._initStyle(),this.initBackground(),this._safeMutationObserver(t=>{this.element&&this.element instanceof Node&&t.observe(this.element,{attributes:!0})}),this.initUpdaters(),this.initPlugins(),this.paint()}initBackground(){let{container:t}=this,i=t.actualOptions.background,e=this.element;if(!e)return;let s=e.style,a=(0,o.BN)(this._engine,i.color);a?s.backgroundColor=(0,o.xx)(a,t.hdr,i.opacity):s.backgroundColor="",s.backgroundImage=i.image||"",s.backgroundPosition=i.position||"",s.backgroundRepeat=i.repeat||"",s.backgroundSize=i.size||""}initPlugins(){for(let t of(this._resizePlugins=[],this._colorPlugins=[],this._canvasClearPlugins=[],this._canvasPaintPlugins=[],this._clearDrawPlugins=[],this._drawParticlePlugins=[],this._drawParticlesSetupPlugins=[],this._drawParticlesCleanupPlugins=[],this._drawPlugins=[],this._drawSettingsSetupPlugins=[],this._drawSettingsCleanupPlugins=[],this.container.plugins))t.resize&&this._resizePlugins.push(t),(t.particleFillColor??t.particleStrokeColor)&&this._colorPlugins.push(t),t.canvasClear&&this._canvasClearPlugins.push(t),t.canvasPaint&&this._canvasPaintPlugins.push(t),t.drawParticle&&this._drawParticlePlugins.push(t),t.drawParticleSetup&&this._drawParticlesSetupPlugins.push(t),t.drawParticleCleanup&&this._drawParticlesCleanupPlugins.push(t),t.draw&&this._drawPlugins.push(t),t.drawSettingsSetup&&this._drawSettingsSetupPlugins.push(t),t.drawSettingsCleanup&&this._drawSettingsCleanupPlugins.push(t),t.clearDraw&&this._clearDrawPlugins.push(t)}initUpdaters(){for(let t of(this._preDrawUpdaters=[],this._postDrawUpdaters=[],this.container.particles.updaters))t.afterDraw&&this._postDrawUpdaters.push(t),(t.getColorStyles??t.getTransformValues??t.beforeDraw)&&this._preDrawUpdaters.push(t)}loadCanvas(t){this._generated&&this.element&&this.element.remove();let i=this.container;this._generated=a.eb in t.dataset?"true"===t.dataset[a.eb]:this._generated,this.element=t,this.element.ariaHidden="true",this._originalStyle=(0,n.td)(this.element.style);let e=this._standardSize;e.height=t.offsetHeight,e.width=t.offsetWidth;let s=this.container.retina.pixelRatio,r=this.size;t.height=r.height=e.height*s,t.width=r.width=e.width*s;let o=(0,n.lV)("(color-gamut: p3)");this._canvasSettings={alpha:!0,colorSpace:o?.matches&&i.hdr?"display-p3":"srgb",desynchronized:!0,willReadFrequently:!1},this._context=this.element.getContext("2d",this._canvasSettings),this._safeMutationObserver(t=>{t.disconnect()}),i.retina.init(),this.initBackground(),this._safeMutationObserver(t=>{this.element&&this.element instanceof Node&&t.observe(this.element,{attributes:!0})})}paint(){let t=!1;for(let i of this._canvasPaintPlugins)if(t=i.canvasPaint?.()??!1)break;t||this.paintBase()}paintBase(t){this.draw(i=>{(0,r.Sn)(i,this.size,t)})}paintImage(t,i){this.draw(e=>{(0,r.Md)(e,this.size,t,i)})}resize(){if(!this.element)return!1;let t=this.container,i=t.canvas._standardSize,e={width:this.element.offsetWidth,height:this.element.offsetHeight},s=t.retina.pixelRatio,a={width:e.width*s,height:e.height*s};if(e.height===i.height&&e.width===i.width&&a.height===this.element.height&&a.width===this.element.width)return!1;let r={...i};i.height=e.height,i.width=e.width;let n=this.size;return this.element.width=n.width=a.width,this.element.height=n.height=a.height,this.container.started&&t.particles.setResizeFactor({width:i.width/r.width,height:i.height/r.height}),!0}setPointerEvents(t){this.element&&(this._pointerEvents=t,this._repairStyle())}setZoom(t,i){this.zoom=t,this._zoomCenter=i}stop(){this._safeMutationObserver(t=>{t.disconnect()}),this._mutationObserver=void 0,this.draw(t=>{(0,r.IU)(t,this.size)})}async windowResize(){if(!this.element||!this.resize())return;let t=this.container,i=t.updateActualOptions();t.particles.setDensity(),this._applyResizePlugins(),i&&await t.refresh()}_applyPostDrawUpdaters=t=>{for(let i of this._postDrawUpdaters)i.afterDraw?.(t)};_applyPreDrawUpdaters=(t,i,e,s,r,n)=>{for(let o of this._preDrawUpdaters){if(o.getColorStyles){let{fill:a,stroke:n}=o.getColorStyles(i,t,e,s);a&&(r.fill=a),n&&(r.stroke=n)}if(o.getTransformValues){let t=o.getTransformValues(i);for(let i in t)!function(t,i,e){let s=i[e];void 0!==s&&(t[e]=(t[e]??a.zs)*s)}(n,t,i)}o.beforeDraw?.(i)}};_applyResizePlugins=()=>{for(let t of this._resizePlugins)t.resize?.()};_getPluginParticleColors=t=>{let i,e;for(let s of this._colorPlugins)if(!i&&s.particleFillColor&&(i=(0,o.R5)(this._engine,s.particleFillColor(t))),!e&&s.particleStrokeColor&&(e=(0,o.R5)(this._engine,s.particleStrokeColor(t))),i&&e)break;return this._reusablePluginColors[0]=i,this._reusablePluginColors[1]=e,this._reusablePluginColors};_initStyle=()=>{let t=this.element,i=this.container.actualOptions;if(t)for(let e in this._fullScreen?this._setFullScreenStyle():this._resetOriginalStyle(),i.style){if(!e||!Object.hasOwn(i.style,e))continue;let s=i.style[e];s&&t.style.setProperty(e,s,"important")}};_repairStyle=()=>{let t=this.element;if(!t)return;this._safeMutationObserver(t=>{t.disconnect()}),this._initStyle(),this.initBackground();let i=this._pointerEvents;t.style.pointerEvents=i,t.setAttribute("pointer-events",i),this._safeMutationObserver(i=>{t instanceof Node&&i.observe(t,{attributes:!0})})};_resetOriginalStyle=()=>{let t=this.element,i=this._originalStyle;t&&i&&l(t,i,!0)};_safeMutationObserver=t=>{this._mutationObserver&&t(this._mutationObserver)};_setFullScreenStyle=()=>{let t=this.element;t&&l(t,(0,n.hJ)(this.container.actualOptions.fullScreen.zIndex),!0)}}class c{container;_handlers;_resizeObserver;_resizeTimeout;constructor(t){this.container=t,this._handlers={visibilityChange:()=>{this._handleVisibilityChange()},resize:()=>{this._handleWindowResize()}}}addListeners(){this._manageListeners(!0)}removeListeners(){this._manageListeners(!1)}_handleVisibilityChange=()=>{let t=this.container;t.actualOptions.pauseOnBlur&&((0,n.T5)().hidden?(t.pageHidden=!0,t.pause()):(t.pageHidden=!1,t.animationStatus?t.play(!0):t.draw(!0)))};_handleWindowResize=()=>{this._resizeTimeout&&(clearTimeout(this._resizeTimeout),delete this._resizeTimeout);let t=async()=>{let t=this.container.canvas;await t.windowResize()};this._resizeTimeout=setTimeout(()=>void t(),this.container.actualOptions.resize.delay*a.Xu)};_manageListeners=t=>{let i=this._handlers;this._manageResize(t),(0,n.Kp)(document,a.nK,i.visibilityChange,t,!1)};_manageResize=t=>{let i=this._handlers,e=this.container;if(!e.actualOptions.resize.enable)return;if("u"<typeof ResizeObserver)return void(0,n.Kp)(globalThis,a.NF,i.resize,t);let s=e.canvas.element;this._resizeObserver&&!t?(s&&this._resizeObserver.unobserve(s),this._resizeObserver.disconnect(),delete this._resizeObserver):!this._resizeObserver&&t&&s&&(this._resizeObserver=new ResizeObserver(t=>{t.find(t=>t.target===s)&&this._handleWindowResize()}),this._resizeObserver.observe(s))}}var d=e(3595),p=e(7028),u=e(1334),_=e(8212),g=e(8674),f=e(1429),P=e(7461),m=e(7);function y(t){if(!(0,n.hn)(t.outMode,t.checkModes))return;let i=t.radius*a.gd;t.coord>t.maxCoord-i?t.setCb(-t.radius):t.coord<i&&t.setCb(t.radius)}class w{container;backColor;bubble;color;destroyed;direction;effect;effectClose;effectData;effectFill;group;id;ignoresResizeRatio;initialPosition;initialVelocity;isRotating;lastPathTime;misplaced;moveCenter;offset;opacity;options;outType;pathRotation;position;randomIndexData;retina;roll;rotation;shape;shapeClose;shapeData;shapeFill;sides;size;slow;spawning;strokeColor;strokeOpacity;strokeWidth;unbreakable;velocity;zIndexFactor;_cachedOpacityData={opacity:a.hv,strokeOpacity:a.hv};_cachedPosition=_.p.origin;_cachedRotateData={sin:0,cos:0};_cachedTransform={a:1,b:0,c:0,d:1};_engine;constructor(t,i){this.container=i,this._engine=t}destroy(t){if(this.unbreakable||this.destroyed)return;this.destroyed=!0,this.bubble.inRange=!1,this.slow.inRange=!1;let i=this.container,e=this.shape?i.particles.shapeDrawers.get(this.shape):void 0;for(let s of(e?.particleDestroy?.(this),i.particleDestroyedPlugins))s.particleDestroyed?.(this,t);for(let e of i.particles.updaters)e.particleDestroyed?.(this,t);this._engine.dispatchEvent(d.B.particleDestroyed,{container:this.container,data:{particle:this}})}draw(t){let i=this.container.canvas;i.drawParticlePlugins(this,t),i.drawParticle(this,t)}getAngle(){return this.rotation+(this.pathRotation?this.velocity.angle:a.tA)}getFillColor(){return this._getRollColor(this.bubble.color??(0,o.O_)(this.color))}getMass(){return this.getRadius()**a.dm*Math.PI*a.MX}getOpacity(){let t=this.options.zIndex,i=a.RV-this.zIndexFactor,e=i**t.opacityRate,r=this.bubble.opacity??(0,s.VG)(this.opacity?.value??a.hv),n=this.strokeOpacity??r;return this._cachedOpacityData.opacity=r*e,this._cachedOpacityData.strokeOpacity=n*e,this._cachedOpacityData}getPosition(){return this._cachedPosition.x=this.position.x+this.offset.x,this._cachedPosition.y=this.position.y+this.offset.y,this._cachedPosition.z=this.position.z,this._cachedPosition}getRadius(){return this.bubble.radius??this.size.value}getRotateData(){let t=this.getAngle();return this._cachedRotateData.sin=Math.sin(t),this._cachedRotateData.cos=Math.cos(t),this._cachedRotateData}getStrokeColor(){return this._getRollColor(this.bubble.color??(0,o.O_)(this.strokeColor))}getTransformData(t){let i=this.getRotateData(),e=this.isRotating;return this._cachedTransform.a=i.cos*(t.a??a.Ug.a),this._cachedTransform.b=e?i.sin*(t.b??a.D_):t.b??a.Ug.b,this._cachedTransform.c=e?-i.sin*(t.c??a.D_):t.c??a.Ug.c,this._cachedTransform.d=i.cos*(t.d??a.Ug.d),this._cachedTransform}init(t,i,e,r){var o,l,h,c;let d,p,u,_,g=this.container;this.id=t,this.group=r,this.effectClose=!0,this.effectFill=!0,this.shapeClose=!0,this.shapeFill=!0,this.pathRotation=!1,this.lastPathTime=0,this.destroyed=!1,this.unbreakable=!1,this.isRotating=!1,this.rotation=0,this.misplaced=!1,this.retina={maxDistance:{}},this.outType=P.x.normal,this.ignoresResizeRatio=!0;let f=g.retina.pixelRatio,y=g.actualOptions,w=(0,m.y)(this._engine,g,y.particles),v=w.reduceDuplicates,z=w.effect.type,b=w.shape.type;this.effect=(0,n.TA)(z,this.id,v),this.shape=(0,n.TA)(b,this.id,v);let S=w.effect,C=w.shape;if(e){if(e.effect?.type){let t=e.effect.type,i=(0,n.TA)(t,this.id,v);i&&(this.effect=i,S.load(e.effect))}if(e.shape?.type){let t=e.shape.type,i=(0,n.TA)(t,this.id,v);i&&(this.shape=i,C.load(e.shape))}}if(this.effect===a.mR){let t=[...this.container.particles.effectDrawers.keys()];this.effect=t[Math.floor((0,s.G0)()*t.length)]}if(this.shape===a.mR){let t=[...this.container.particles.shapeDrawers.keys()];this.shape=t[Math.floor((0,s.G0)()*t.length)]}this.effectData=this.effect?(o=this.effect,l=this.id,u=S.options[o],(0,n.zw)({close:S.close,fill:S.fill},(0,n.TA)(u,l,v))):void 0,this.shapeData=this.shape?(h=this.shape,c=this.id,_=C.options[h],(0,n.zw)({close:C.close,fill:C.fill},(0,n.TA)(_,c,v))):void 0,w.load(e);let x=this.effectData;x&&w.load(x.particles);let D=this.shapeData;D&&w.load(D.particles),this.effectFill=x?.fill??w.effect.fill,this.effectClose=x?.close??w.effect.close,this.shapeFill=D?.fill??w.shape.fill,this.shapeClose=D?.close??w.shape.close,this.options=w,g.retina.initParticle(this),this.size=(0,n.Xs)(this.options.size,f),this.bubble={inRange:!1},this.slow={inRange:!1,factor:1},this._initPosition(i),this.initialVelocity=this._calculateVelocity(),this.velocity=this.initialVelocity.copy();let R=g.particles;R.setLastZIndex(this.position.z),this.zIndexFactor=this.position.z/g.zLayers,this.sides=24,this.effect&&(d=g.particles.effectDrawers.get(this.effect)),d?.loadEffect&&d.loadEffect(this),this.shape&&(p=g.particles.shapeDrawers.get(this.shape)),p?.loadShape&&p.loadShape(this);let O=p?.getSidesCount;for(let t of(O&&(this.sides=O(this)),this.spawning=!1,R.updaters))t.init(this);for(let t of(d?.particleInit?.(g,this),p?.particleInit?.(g,this),g.particleCreatedPlugins))t.particleCreated?.(this)}isInsideCanvas(){let t=this.getRadius(),i=this.container.canvas.size,e=this.position;return e.x>=-t&&e.y>=-t&&e.y<=i.height+t&&e.x<=i.width+t}isShowingBack(){if(!this.roll)return!1;let t=this.roll.angle;if(this.roll.horizontal&&this.roll.vertical){let i=t%a.R1,e=i<a.tA?i+a.R1:i;return e>=Math.PI*a.MX&&e<Math.PI*a.Nu*a.MX}if(this.roll.horizontal){let i=(t+Math.PI*a.MX)%(Math.PI*a.gd),e=i<a.tA?i+Math.PI*a.gd:i;return e>=Math.PI&&e<Math.PI*a.gd}if(this.roll.vertical){let i=t%(Math.PI*a.gd),e=i<a.tA?i+Math.PI*a.gd:i;return e>=Math.PI&&e<Math.PI*a.gd}return!1}isVisible(){return!this.destroyed&&!this.spawning&&this.isInsideCanvas()}reset(){for(let t of this.container.particles.updaters)t.reset?.(this)}_calcPosition=(t,i)=>{let e=a.rq,r=t?_.p.create(t.x,t.y,i):void 0,n=this.container,o=n.particlePositionPlugins,l=this.options.move.outModes,h=this.getRadius(),c=n.canvas.size,{signal:d}=new AbortController;for(;!d.aborted;){for(let t of o){let e=t.particlePosition?.(r,this);if(e)return _.p.create(e.x,e.y,i)}let t=(0,s.Nx)({size:c,position:r}),d=_.p.create(t.x,t.y,i);this._fixHorizontal(d,h,l.left??l.default),this._fixHorizontal(d,h,l.right??l.default),this._fixVertical(d,h,l.top??l.default),this._fixVertical(d,h,l.bottom??l.default);let p=!0;for(let t of n.particles.checkParticlePositionPlugins)if(!(p=t.checkParticlePosition?.(this,d,e)??!0))break;if(p)return d;e+=a.Eo,r=void 0}return r};_calculateVelocity=()=>{let t=(0,s.$m)(this.direction).copy(),i=this.options.move;if(i.direction===g.F.inside||i.direction===g.F.outside)return t;let e=(0,s.pu)((0,s.VG)(i.angle.value)),r=(0,s.pu)((0,s.VG)(i.angle.offset)),n={left:r-e*a.MX,right:r+e*a.MX};return i.straight||(t.angle+=(0,s.vE)((0,s.DT)(n.left,n.right))),i.random&&"number"==typeof i.speed&&(t.length*=(0,s.G0)()),t};_fixHorizontal=(t,i,e)=>{y({outMode:e,checkModes:[f.Y.bounce],coord:t.x,maxCoord:this.container.canvas.size.width,setCb:i=>t.x+=i,radius:i})};_fixVertical=(t,i,e)=>{y({outMode:e,checkModes:[f.Y.bounce],coord:t.y,maxCoord:this.container.canvas.size.height,setCb:i=>t.y+=i,radius:i})};_getRollColor=t=>t&&this.roll&&(this.backColor||this.roll.alter)&&this.isShowingBack()?this.backColor?this.backColor:this.roll.alter?(0,o.yx)(t,this.roll.alter.type,this.roll.alter.value):t:t;_initPosition=t=>{let i=this.container,e=(0,s.VG)(this.options.zIndex.value),r=this._calcPosition(t,(0,s.qE)(e,a.X_,i.zLayers));if(!r)throw Error("a valid position cannot be found for particle");this.position=r,this.initialPosition=this.position.copy();let o=i.canvas.size;switch(this.moveCenter={...(0,n.E9)(this.options.move.center,o),radius:this.options.move.center.radius,mode:this.options.move.center.mode},this.direction=(0,s.JY)(this.options.move.direction,this.position,this.moveCenter),this.options.move.direction){case g.F.inside:this.outType=P.x.inside;break;case g.F.outside:this.outType=P.x.outside}this.offset=_.M.origin}}var v=e(8031);class z{_cellSize;_cells=new Map;_pendingCellSize;constructor(t){this._cellSize=t}clear(){this._cells.clear();let t=this._pendingCellSize;t&&(this._cellSize=t),this._pendingCellSize=void 0}insert(t){let{x:i,y:e}=t.getPosition(),s=this._cellKeyFromCoords(i,e);this._cells.has(s)||this._cells.set(s,[]),this._cells.get(s)?.push(t)}query(t,i,e=[]){let s=this._getRangeBounds(t);if(!s)return e;let a=Math.floor(s.minX/this._cellSize),r=Math.floor(s.maxX/this._cellSize),n=Math.floor(s.minY/this._cellSize),o=Math.floor(s.maxY/this._cellSize);for(let s=a;s<=r;s++)for(let a=n;a<=o;a++){let r=`${s}_${a}`,n=this._cells.get(r);if(n)for(let s of n)(!i||i(s))&&t.contains(s.getPosition())&&e.push(s)}return e}queryCircle(t,i,e,s=[]){return this.query(new v.jl(t.x,t.y,i),e,s)}queryRectangle(t,i,e,s=[]){return this.query(new v.M_(t.x,t.y,i.width,i.height),e,s)}setCellSize(t){this._pendingCellSize=t}_cellKeyFromCoords(t,i){let e=Math.floor(t/this._cellSize),s=Math.floor(i/this._cellSize);return`${e}_${s}`}_getRangeBounds(t){if(t instanceof v.jl){let i=t.radius,{x:e,y:s}=t.position;return{minX:e-i,maxX:e+i,minY:s-i,maxY:s+i}}if(t instanceof v.M_){let{x:i,y:e}=t.position,{width:s,height:a}=t.size;return{minX:i,maxX:i+s,minY:e,maxY:e+a}}return null}}var b=e(4019);class S{checkParticlePositionPlugins;effectDrawers;grid;shapeDrawers;updaters;_array;_container;_engine;_groupLimits;_limit;_maxZIndex;_minZIndex;_needsSort;_nextId;_particleResetPlugins;_particleUpdatePlugins;_pool;_postParticleUpdatePlugins;_postUpdatePlugins;_resizeFactor;_updatePlugins;_zArray;constructor(t,i){this._engine=t,this._container=i,this._nextId=0,this._array=[],this._zArray=[],this._pool=[],this._limit=0,this._groupLimits=new Map,this._needsSort=!1,this._minZIndex=0,this._maxZIndex=0,this.grid=new z(a.iX),this.effectDrawers=new Map,this.shapeDrawers=new Map,this.updaters=[],this.checkParticlePositionPlugins=[],this._particleResetPlugins=[],this._particleUpdatePlugins=[],this._postUpdatePlugins=[],this._postParticleUpdatePlugins=[],this._updatePlugins=[]}get count(){return this._array.length}addParticle(t,i,e,s){let r=this._container.actualOptions.particles.number.limit.mode,n=void 0===e?this._limit:this._groupLimits.get(e)??this._limit,o=this.count;if(n>a.ou)switch(r){case u.d.delete:{let t=o+a.nq-n;t>a.wM&&this.removeQuantity(t);break}case u.d.wait:if(o>=n)return}try{let a=this._pool.pop()??new w(this._engine,this._container);a.init(this._nextId,t,i,e);let r=!0;if(s&&(r=s(a)),!r)return void this._pool.push(a);return this._array.push(a),this._zArray.push(a),this._nextId++,this._engine.dispatchEvent(d.B.particleAdded,{container:this._container,data:{particle:a}}),a}catch(t){(0,b.t)().warning(`error adding particle: ${t}`)}}clear(){this._array=[],this._zArray=[]}destroy(){let t=this._container;for(let[,i]of this.effectDrawers)i.destroy?.(t);for(let[,i]of this.shapeDrawers)i.destroy?.(t);this._array=[],this._pool.length=0,this._zArray=[],this.effectDrawers=new Map,this.shapeDrawers=new Map,this.updaters=[],this.checkParticlePositionPlugins=[],this._particleResetPlugins=[],this._particleUpdatePlugins=[],this._postUpdatePlugins=[],this._postParticleUpdatePlugins=[],this._updatePlugins=[]}drawParticles(t){for(let i of this._zArray)i.draw(t)}filter(t){return this._array.filter(t)}find(t){return this._array.find(t)}get(t){return this._array[t]}async init(){let t=this._container,i=t.actualOptions;for(let i of(this._minZIndex=0,this._maxZIndex=0,this._needsSort=!1,this.checkParticlePositionPlugins=[],this._updatePlugins=[],this._particleUpdatePlugins=[],this._postUpdatePlugins=[],this._particleResetPlugins=[],this._postParticleUpdatePlugins=[],this.grid=new z(a.iX*t.retina.pixelRatio),t.plugins))i.redrawInit&&await i.redrawInit(),i.checkParticlePosition&&this.checkParticlePositionPlugins.push(i),i.update&&this._updatePlugins.push(i),i.particleUpdate&&this._particleUpdatePlugins.push(i),i.postUpdate&&this._postUpdatePlugins.push(i),i.particleReset&&this._particleResetPlugins.push(i),i.postParticleUpdate&&this._postParticleUpdatePlugins.push(i);for(let i of(await this.initPlugins(),this.effectDrawers.values()))await i.init?.(t);for(let i of this.shapeDrawers.values())await i.init?.(t);let e=!1;for(let i of t.plugins)if(e=i.particlesInitialization?.()??e)break;if(!e){let t=i.particles,e=t.groups;for(let i in e){let s=e[i];if(s)for(let e=this.count,a=0;a<s.number.value&&e<t.number.value;e++,a++)this.addParticle(void 0,s,i)}for(let i=this.count;i<t.number.value;i++)this.addParticle()}}async initPlugins(){let t=this._container;this.effectDrawers=await this._engine.getEffectDrawers(t,!0),this.shapeDrawers=await this._engine.getShapeDrawers(t,!0),this.updaters=await this._engine.getUpdaters(t,!0)}push(t,i,e,s){for(let a=0;a<t;a++)this.addParticle(i,e,s)}async redraw(){this.clear(),await this.init(),this._container.canvas.drawParticles({value:0,factor:0})}remove(t,i,e){this.removeAt(this._array.indexOf(t),void 0,i,e)}removeAt(t,i=a.xd,e,s){if(t<a.z9||t>this.count)return;let r=0;for(let a=t;r<i&&a<this.count;a++)this._removeParticle(a,e,s)&&(a--,r++)}removeQuantity(t,i){this.removeAt(a.z9,t,i)}setDensity(){let t=this._container.actualOptions,i=t.particles.groups,e=0;for(let t of this._container.plugins)t.particlesDensityCount&&(e+=t.particlesDensityCount());for(let t in i){let s=i[t];if(!s)continue;let a=(0,m.y)(this._engine,this._container,s);this._applyDensity(a,e,t)}this._applyDensity(t.particles,e)}setLastZIndex(t){this._needsSort||=t>=this._maxZIndex||t>this._minZIndex&&t<this._maxZIndex}setResizeFactor(t){this._resizeFactor=t}update(t){let i=new Set;for(let i of(this.grid.clear(),this._updatePlugins))i.update?.(t);let e=this._resizeFactor;for(let s of this._array){for(let t of(e&&!s.ignoresResizeRatio&&(s.position.x*=e.width,s.position.y*=e.height,s.initialPosition.x*=e.width,s.initialPosition.y*=e.height),s.ignoresResizeRatio=!1,this._particleResetPlugins))t.particleReset?.(s);for(let i of this._particleUpdatePlugins){if(s.destroyed)break;i.particleUpdate?.(s,t)}if(s.destroyed){i.add(s);continue}this.grid.insert(s)}if(i.size){let t=t=>!i.has(t);for(let e of(this._array=this.filter(t),this._zArray=this._zArray.filter(t),i))this._engine.dispatchEvent(d.B.particleRemoved,{container:this._container,data:{particle:e}});this._addToPool(...i)}for(let i of this._postUpdatePlugins)i.postUpdate?.(t);for(let i of this._array){for(let e of this.updaters)e.update(i,t);if(!i.destroyed&&!i.spawning)for(let e of this._postParticleUpdatePlugins)e.postParticleUpdate?.(i,t)}if(delete this._resizeFactor,this._needsSort){let t=this._zArray;t.sort((t,i)=>i.position.z-t.position.z||t.id-i.id);let i=t[a.z9],e=t[t.length-a.K3];if(!i||!e)return;this._maxZIndex=i.position.z,this._minZIndex=e.position.z,this._needsSort=!1}}_addToPool=(...t)=>{this._pool.push(...t)};_applyDensity=(t,i,e,s)=>{let r=t.number;if(!r.density.enable)return void(void 0===e?this._limit=r.limit.value:(s?.number.limit.value??r.limit.value)&&this._groupLimits.set(e,s?.number.limit.value??r.limit.value));let n=this._initDensityFactor(r.density),o=r.value,l=r.limit.value>a.ou?r.limit.value:o,h=Math.min(o,l)*n+i,c=Math.min(this.count,this.filter(t=>t.group===e).length);void 0===e?this._limit=r.limit.value*n:this._groupLimits.set(e,r.limit.value*n),c<h?this.push(Math.abs(h-c),void 0,t,e):c>h&&this.removeQuantity(c-h,e)};_initDensityFactor=t=>{let i=this._container;if(!i.canvas.element||!t.enable)return a.lA;let e=i.canvas.element,s=i.retina.pixelRatio;return e.width*e.height/(t.height*t.width*s**a.dm)};_removeParticle=(t,i,e)=>{let s=this._array[t];if(!s||s.group!==i)return!1;let r=this._zArray.indexOf(s);return this._array.splice(t,a.LD),this._zArray.splice(r,a.LD),s.destroy(e),this._engine.dispatchEvent(d.B.particleRemoved,{container:this._container,data:{particle:s}}),this._addToPool(s),!0}}class C{container;maxSpeed;pixelRatio;reduceFactor;sizeAnimationSpeed;constructor(t){this.container=t,this.pixelRatio=a.$x,this.reduceFactor=a.Zp}init(){let t=this.container,i=t.actualOptions;this.pixelRatio=i.detectRetina?devicePixelRatio:a.$x,this.reduceFactor=a.Zp;let e=this.pixelRatio,r=t.canvas;if(r.element){let t=r.element;r.size.width=t.offsetWidth*e,r.size.height=t.offsetHeight*e}let n=i.particles,o=n.move;this.maxSpeed=(0,s.VG)(o.gravity.maxSpeed)*e,this.sizeAnimationSpeed=(0,s.VG)(n.size.animation.speed)*e}initParticle(t){let i=t.options,e=this.pixelRatio,a=i.move,r=a.distance,n=t.retina;n.moveDrift=(0,s.VG)(a.drift)*e,n.moveSpeed=(0,s.VG)(a.speed)*e,n.sizeAnimationSpeed=(0,s.VG)(i.size.animation.speed)*e;let o=n.maxDistance;o.horizontal=void 0!==r.horizontal?r.horizontal*e:void 0,o.vertical=void 0!==r.vertical?r.vertical*e:void 0,n.maxSpeed=(0,s.VG)(a.gravity.maxSpeed)*e}}function x(t){return!t.destroyed}function D(t,i,...e){let s=new p.J(t,i);return(0,m.Z)(s,...e),s}class R{actualOptions;canvas;destroyed;fpsLimit;hdr;id;pageHidden;particleCreatedPlugins;particleDestroyedPlugins;particlePositionPlugins;particles;plugins;retina;started;zLayers;_delay;_delayTimeout;_delta={value:0,factor:0};_drawAnimationFrame;_duration;_engine;_eventListeners;_firstStart;_initialSourceOptions;_lastFrameTime;_lifeTime;_options;_paused;_smooth;_sourceOptions;constructor(t,i,e){this._engine=t,this.id=Symbol(i),this.fpsLimit=120,this.hdr=!1,this._smooth=!1,this._delay=0,this._duration=0,this._lifeTime=0,this._firstStart=!0,this.started=!1,this.destroyed=!1,this._paused=!0,this._lastFrameTime=0,this.zLayers=100,this.pageHidden=!1,this._sourceOptions=e,this._initialSourceOptions=e,this.retina=new C(this),this.canvas=new h(this,this._engine),this.particles=new S(this._engine,this),this.plugins=[],this.particleDestroyedPlugins=[],this.particleCreatedPlugins=[],this.particlePositionPlugins=[],this._options=D(this._engine,this),this.actualOptions=D(this._engine,this),this._eventListeners=new c(this),this._engine.dispatchEvent(d.B.containerBuilt,{container:this})}get animationStatus(){return!this._paused&&!this.pageHidden&&x(this)}get options(){return this._options}get sourceOptions(){return this._sourceOptions}addLifeTime(t){this._lifeTime+=t}alive(){return!this._duration||this._lifeTime<=this._duration}destroy(t=!0){if(x(this)){for(let t of(this.stop(),this.particles.destroy(),this.canvas.destroy(),this.plugins))t.destroy?.();if(this.plugins.length=0,this._engine.clearPlugins(this),this.destroyed=!0,t){let t=this._engine.items,i=t.indexOf(this);i>=a.vF&&t.splice(i,a.JC)}this._engine.dispatchEvent(d.B.containerDestroyed,{container:this})}}draw(t){if(!x(this))return;let i=t;this._drawAnimationFrame=(0,s.i0)(t=>{i&&(this._lastFrameTime=void 0,i=!1),this._nextFrame(t)})}async export(t,i={}){for(let e of this.plugins){if(!e.export)continue;let s=await e.export(t,i);if(s.supported)return s.blob}(0,b.t)().error(`Export plugin with type ${t} not found`)}async init(){if(!x(this))return;let t=new Map;for(let i of this._engine.plugins){let e=await i.getPlugin(this);e.preInit&&await e.preInit(),t.set(i,e)}for(let[i,e]of(await this.particles.initPlugins(),this._options=D(this._engine,this,this._initialSourceOptions,this.sourceOptions),this.actualOptions=D(this._engine,this,this._options),this.plugins.length=0,this.particleDestroyedPlugins.length=0,this.particleCreatedPlugins.length=0,this.particlePositionPlugins.length=0,t))i.needsPlugin(this.actualOptions)&&(this.plugins.push(e),e.particleCreated&&this.particleCreatedPlugins.push(e),e.particleDestroyed&&this.particleDestroyedPlugins.push(e),e.particlePosition&&this.particlePositionPlugins.push(e));this.retina.init(),this.canvas.init(),this.updateActualOptions(),this.canvas.initBackground(),this.canvas.resize();let{delay:i,duration:e,fpsLimit:r,hdr:n,smooth:o,zLayers:l}=this.actualOptions;for(let t of(this.hdr=n,this.zLayers=l,this._duration=(0,s.VG)(e)*a.Xu,this._delay=(0,s.VG)(i)*a.Xu,this._lifeTime=0,this.fpsLimit=r>a.DN?r:a.i8,this._smooth=o,this.plugins))await t.init?.();for(let t of(await this.particles.init(),this._engine.dispatchEvent(d.B.containerInit,{container:this}),this.particles.setDensity(),this.plugins))t.particlesSetup?.();this._engine.dispatchEvent(d.B.particlesSetup,{container:this})}pause(){if(x(this)&&(void 0!==this._drawAnimationFrame&&((0,s.px)(this._drawAnimationFrame),delete this._drawAnimationFrame),!this._paused)){for(let t of this.plugins)t.pause?.();this.pageHidden||(this._paused=!0),this._engine.dispatchEvent(d.B.containerPaused,{container:this})}}play(t){if(!x(this))return;let i=this._paused||t;if(this._firstStart&&!this.actualOptions.autoPlay){this._firstStart=!1;return}if(this._paused&&(this._paused=!1),i)for(let t of this.plugins)t.play&&t.play();this._engine.dispatchEvent(d.B.containerPlay,{container:this}),this.draw(i??!1)}async refresh(){if(x(this))return this.stop(),this.start()}async reset(t){if(x(this))return this._initialSourceOptions=t,this._sourceOptions=t,this._options=D(this._engine,this,this._initialSourceOptions,this.sourceOptions),this.actualOptions=D(this._engine,this,this._options),this.refresh()}async start(){x(this)&&!this.started&&(await this.init(),this.started=!0,await new Promise(t=>{let i=async()=>{for(let t of(this._eventListeners.addListeners(),this.plugins))await t.start?.();this._engine.dispatchEvent(d.B.containerStarted,{container:this}),this.play(),t()};this._delayTimeout=setTimeout(()=>void i(),this._delay)}))}stop(){if(x(this)&&this.started){for(let t of(this._delayTimeout&&(clearTimeout(this._delayTimeout),delete this._delayTimeout),this._firstStart=!0,this.started=!1,this._eventListeners.removeListeners(),this.pause(),this.particles.clear(),this.canvas.stop(),this.plugins))t.stop?.();this.particleCreatedPlugins.length=0,this.particleDestroyedPlugins.length=0,this.particlePositionPlugins.length=0,this._sourceOptions=this._options,this._engine.dispatchEvent(d.B.containerStopped,{container:this})}}updateActualOptions(){let t=!1;for(let i of this.plugins)i.updateActualOptions&&(t=i.updateActualOptions()||t);return t}_nextFrame=t=>{try{if(!this._smooth&&void 0!==this._lastFrameTime&&t<this._lastFrameTime+a.Xu/this.fpsLimit||(this._lastFrameTime??=t,!function(t,i,e=a.z$,s=!1){t.value=i,t.factor=s?a.z$/e:a.z$*i/a.Xu}(this._delta,t-this._lastFrameTime,this.fpsLimit,this._smooth),this.addLifeTime(this._delta.value),this._lastFrameTime=t,this._delta.value>a.Xu))return void this.draw(!1);if(this.canvas.drawParticles(this._delta),!this.alive())return void this.destroy();this.animationStatus&&this.draw(!1)}catch(t){(0,b.t)().error("error in animation loop",t)}}}}}]);
package/README.md CHANGED
@@ -697,8 +697,8 @@ flowchart TD
697
697
 
698
698
  subgraph bundle-basic [tsParticles Basic]
699
699
 
700
- subgraph basic-movers [Movers]
701
- move-base[Base]
700
+ subgraph basic-plugins [Plugins]
701
+ plugin-move[Move]
702
702
  end
703
703
 
704
704
  subgraph basic-shapes [Shapes]
@@ -57,13 +57,9 @@ export class Engine {
57
57
  effectDrawers = new Map();
58
58
  initializers = {
59
59
  effects: new Map(),
60
- movers: new Map(),
61
- pathGenerators: new Map(),
62
60
  shapes: new Map(),
63
61
  updaters: new Map(),
64
62
  };
65
- movers = new Map();
66
- pathGenerators = new Map();
67
63
  plugins = [];
68
64
  presets = new Map();
69
65
  shapeDrawers = new Map();
@@ -87,7 +83,7 @@ export class Engine {
87
83
  return this._domArray;
88
84
  }
89
85
  get version() {
90
- return "4.0.0-alpha.24";
86
+ return "4.0.0-alpha.26";
91
87
  }
92
88
  addColorManager(name, manager) {
93
89
  this.colorManagers.set(name, manager);
@@ -109,15 +105,9 @@ export class Engine {
109
105
  addEventListener(type, listener) {
110
106
  this._eventDispatcher.addEventListener(type, listener);
111
107
  }
112
- addMover(name, moverInitializer) {
113
- this.initializers.movers.set(name, moverInitializer);
114
- }
115
108
  addParticleUpdater(name, updaterInitializer) {
116
109
  this.initializers.updaters.set(name, updaterInitializer);
117
110
  }
118
- addPathGenerator(name, generator) {
119
- this.initializers.pathGenerators.set(name, generator);
120
- }
121
111
  addPlugin(plugin) {
122
112
  if (this.getPlugin(plugin.id)) {
123
113
  return;
@@ -143,7 +133,6 @@ export class Engine {
143
133
  }
144
134
  clearPlugins(container) {
145
135
  this.effectDrawers.delete(container);
146
- this.movers.delete(container);
147
136
  this.shapeDrawers.delete(container);
148
137
  this.updaters.delete(container);
149
138
  }
@@ -156,12 +145,6 @@ export class Engine {
156
145
  getEffectDrawers(container, force = false) {
157
146
  return getItemMapFromInitializer(container, this.effectDrawers, this.initializers.effects, force);
158
147
  }
159
- getMovers(container, force = false) {
160
- return getItemsFromInitializer(container, this.movers, this.initializers.movers, force);
161
- }
162
- getPathGenerators(container, force = false) {
163
- return getItemMapFromInitializer(container, this.pathGenerators, this.initializers.pathGenerators, force);
164
- }
165
148
  getPlugin(plugin) {
166
149
  return this.plugins.find(t => t.id === plugin);
167
150
  }
@@ -1,8 +1,8 @@
1
1
  import { Vector, Vector3d } from "./Utils/Vectors.js";
2
2
  import { alterHsl, getHslFromAnimation } from "../Utils/ColorUtils.js";
3
3
  import { calcExactPositionOrRandomFromSize, clamp, degToRad, getParticleBaseVelocity, getParticleDirectionAngle, getRandom, getRangeValue, randomInRangeValue, setRangeValue, } from "../Utils/MathUtils.js";
4
- import { decayOffset, defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, doublePI, half, identity, millisecondsToSeconds, minZ, randomColorValue, squareExp, triple, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
5
4
  import { deepExtend, getPosition, initParticleNumericAnimationValue, isInArray, itemFromSingleOrMultiple, } from "../Utils/Utils.js";
5
+ import { defaultAngle, defaultOpacity, defaultRetryCount, defaultTransform, double, doublePI, half, identity, minZ, randomColorValue, squareExp, triple, tryCountIncrement, zIndexFactorOffset, } from "./Utils/Constants.js";
6
6
  import { EventType } from "../Enums/Types/EventType.js";
7
7
  import { MoveDirection } from "../Enums/Directions/MoveDirection.js";
8
8
  import { OutMode } from "../Enums/Modes/OutMode.js";
@@ -54,13 +54,10 @@ export class Particle {
54
54
  lastPathTime;
55
55
  misplaced;
56
56
  moveCenter;
57
- moveDecay;
58
57
  offset;
59
58
  opacity;
60
59
  options;
61
60
  outType;
62
- pathDelay;
63
- pathGenerator;
64
61
  pathRotation;
65
62
  position;
66
63
  randomIndexData;
@@ -105,7 +102,7 @@ export class Particle {
105
102
  this.destroyed = true;
106
103
  this.bubble.inRange = false;
107
104
  this.slow.inRange = false;
108
- const container = this.container, pathGenerator = this.pathGenerator, shapeDrawer = this.shape ? container.particles.shapeDrawers.get(this.shape) : undefined;
105
+ const container = this.container, shapeDrawer = this.shape ? container.particles.shapeDrawers.get(this.shape) : undefined;
109
106
  shapeDrawer?.particleDestroy?.(this);
110
107
  for (const plugin of container.particleDestroyedPlugins) {
111
108
  plugin.particleDestroyed?.(this, override);
@@ -113,7 +110,6 @@ export class Particle {
113
110
  for (const updater of container.particles.updaters) {
114
111
  updater.particleDestroyed?.(this, override);
115
112
  }
116
- pathGenerator?.reset(this);
117
113
  this._engine.dispatchEvent(EventType.particleDestroyed, {
118
114
  container: this.container,
119
115
  data: {
@@ -235,19 +231,6 @@ export class Particle {
235
231
  this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
236
232
  this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
237
233
  this.options = particlesOptions;
238
- const pathOptions = this.options.move.path;
239
- this.pathDelay = getRangeValue(pathOptions.delay.value) * millisecondsToSeconds;
240
- if (pathOptions.generator) {
241
- let pathGenerator = this.container.particles.pathGenerators.get(pathOptions.generator);
242
- if (!pathGenerator) {
243
- pathGenerator = this.container.particles.availablePathGenerators.get(pathOptions.generator);
244
- if (pathGenerator) {
245
- this.container.particles.pathGenerators.set(pathOptions.generator, pathGenerator);
246
- pathGenerator.init();
247
- }
248
- }
249
- this.pathGenerator = pathGenerator;
250
- }
251
234
  container.retina.initParticle(this);
252
235
  this.size = initParticleNumericAnimationValue(this.options.size, pxRatio);
253
236
  this.bubble = {
@@ -260,7 +243,6 @@ export class Particle {
260
243
  this._initPosition(position);
261
244
  this.initialVelocity = this._calculateVelocity();
262
245
  this.velocity = this.initialVelocity.copy();
263
- this.moveDecay = decayOffset - getRangeValue(this.options.move.decay);
264
246
  const particles = container.particles;
265
247
  particles.setLastZIndex(this.position.z);
266
248
  this.zIndexFactor = this.position.z / container.zLayers;
@@ -286,9 +268,6 @@ export class Particle {
286
268
  for (const updater of particles.updaters) {
287
269
  updater.init(this);
288
270
  }
289
- for (const mover of particles.movers) {
290
- mover.init(this);
291
- }
292
271
  effectDrawer?.particleInit?.(container, this);
293
272
  shapeDrawer?.particleInit?.(container, this);
294
273
  for (const plugin of container.particleCreatedPlugins) {
@@ -1,23 +1,14 @@
1
- import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit, posOffset, qTreeCapacity, sizeFactor, squareExp, } from "./Utils/Constants.js";
1
+ import { countOffset, defaultDensityFactor, defaultRemoveQuantity, deleteCount, lengthOffset, minCount, minIndex, minLimit, spatialHashGridCellSize, squareExp, } from "./Utils/Constants.js";
2
2
  import { EventType } from "../Enums/Types/EventType.js";
3
3
  import { LimitMode } from "../Enums/Modes/LimitMode.js";
4
4
  import { Particle } from "./Particle.js";
5
- import { Point } from "./Utils/Point.js";
6
- import { QuadTree } from "./Utils/QuadTree.js";
7
- import { Rectangle } from "./Utils/Ranges.js";
5
+ import { SpatialHashGrid } from "./Utils/SpatialHashGrid.js";
8
6
  import { getLogger } from "../Utils/LogUtils.js";
9
7
  import { loadParticlesOptions } from "../Utils/OptionsUtils.js";
10
- const qTreeRectangle = (canvasSize) => {
11
- const { height, width } = canvasSize;
12
- return new Rectangle(posOffset * width, posOffset * height, sizeFactor * width, sizeFactor * height);
13
- };
14
8
  export class Particles {
15
- availablePathGenerators;
16
9
  checkParticlePositionPlugins;
17
10
  effectDrawers;
18
- movers;
19
- pathGenerators;
20
- quadTree;
11
+ grid;
21
12
  shapeDrawers;
22
13
  updaters;
23
14
  _array;
@@ -49,12 +40,8 @@ export class Particles {
49
40
  this._needsSort = false;
50
41
  this._minZIndex = 0;
51
42
  this._maxZIndex = 0;
52
- const canvasSize = container.canvas.size;
53
- this.quadTree = new QuadTree(qTreeRectangle(canvasSize), qTreeCapacity);
43
+ this.grid = new SpatialHashGrid(spatialHashGridCellSize);
54
44
  this.effectDrawers = new Map();
55
- this.movers = [];
56
- this.availablePathGenerators = new Map();
57
- this.pathGenerators = new Map();
58
45
  this.shapeDrawers = new Map();
59
46
  this.updaters = [];
60
47
  this.checkParticlePositionPlugins = [];
@@ -130,9 +117,6 @@ export class Particles {
130
117
  this._pool.length = 0;
131
118
  this._zArray = [];
132
119
  this.effectDrawers = new Map();
133
- this.movers = [];
134
- this.availablePathGenerators = new Map();
135
- this.pathGenerators = new Map();
136
120
  this.shapeDrawers = new Map();
137
121
  this.updaters = [];
138
122
  this.checkParticlePositionPlugins = [];
@@ -167,6 +151,7 @@ export class Particles {
167
151
  this._postUpdatePlugins = [];
168
152
  this._particleResetPlugins = [];
169
153
  this._postParticleUpdatePlugins = [];
154
+ this.grid = new SpatialHashGrid(spatialHashGridCellSize * container.retina.pixelRatio);
170
155
  for (const plugin of container.plugins) {
171
156
  if (plugin.redrawInit) {
172
157
  await plugin.redrawInit();
@@ -223,14 +208,8 @@ export class Particles {
223
208
  async initPlugins() {
224
209
  const container = this._container;
225
210
  this.effectDrawers = await this._engine.getEffectDrawers(container, true);
226
- this.movers = await this._engine.getMovers(container, true);
227
- this.availablePathGenerators = await this._engine.getPathGenerators(container, true);
228
- this.pathGenerators = new Map();
229
211
  this.shapeDrawers = await this._engine.getShapeDrawers(container, true);
230
212
  this.updaters = await this._engine.getUpdaters(container, true);
231
- for (const pathGenerator of this.pathGenerators.values()) {
232
- pathGenerator.init();
233
- }
234
213
  }
235
214
  push(nb, position, overrideOptions, group) {
236
215
  for (let i = 0; i < nb; i++) {
@@ -285,11 +264,8 @@ export class Particles {
285
264
  this._resizeFactor = factor;
286
265
  }
287
266
  update(delta) {
288
- const container = this._container, particlesToDelete = new Set();
289
- this.quadTree = new QuadTree(qTreeRectangle(container.canvas.size), qTreeCapacity);
290
- for (const pathGenerator of this.pathGenerators.values()) {
291
- pathGenerator.update();
292
- }
267
+ const particlesToDelete = new Set();
268
+ this.grid.clear();
293
269
  for (const plugin of this._updatePlugins) {
294
270
  plugin.update?.(delta);
295
271
  }
@@ -311,16 +287,11 @@ export class Particles {
311
287
  }
312
288
  plugin.particleUpdate?.(particle, delta);
313
289
  }
314
- for (const mover of this.movers) {
315
- if (mover.isEnabled(particle)) {
316
- mover.move(particle, delta);
317
- }
318
- }
319
290
  if (particle.destroyed) {
320
291
  particlesToDelete.add(particle);
321
292
  continue;
322
293
  }
323
- this.quadTree.insert(new Point(particle.getPosition(), particle));
294
+ this.grid.insert(particle);
324
295
  }
325
296
  if (particlesToDelete.size) {
326
297
  const checkDelete = (p) => !particlesToDelete.has(p);
@@ -7,4 +7,4 @@ export const generatedAttribute = "generated", resizeEvent = "resize", visibilit
7
7
  b: 0,
8
8
  c: 0,
9
9
  d: 1,
10
- }, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, 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, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, touchDelay = 500, manualDefaultPosition = 50, defaultAngle = 0, identity = 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;
10
+ }, randomColorValue = "random", midColorValue = "mid", double = 2, doublePI = Math.PI * double, defaultFps = 60, defaultAlpha = 1, generatedTrue = "true", generatedFalse = "false", canvasTag = "canvas", defaultRetryCount = 0, squareExp = 2, qTreeCapacity = 4, spatialHashGridCellSize = 100, defaultRemoveQuantity = 1, defaultRatio = 1, defaultReduceFactor = 1, subdivideCount = 4, 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, defaultTransformValue = 1, minimumSize = 0, minimumLength = 0, zIndexFactorOffset = 1, defaultOpacity = 1, clickRadius = 1, touchEndLengthOffset = 1, minCoordinate = 0, removeDeleteCount = 1, removeMinIndex = 0, defaultFpsLimit = 120, minFpsLimit = 0, canvasFirstIndex = 0, loadRandomFactor = 10000, loadMinIndex = 0, one = 1, none = 0, decayOffset = 1, tryCountIncrement = 1, minRetries = 0, minZ = 0, defaultRadius = 0, posOffset = -quarter, sizeFactor = 1.5, minLimit = 0, countOffset = 1, minCount = 0, minIndex = 0, lengthOffset = 1, defaultDensityFactor = 1, deleteCount = 1, touchDelay = 500, manualDefaultPosition = 50, defaultAngle = 0, identity = 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;
@@ -1,5 +1,5 @@
1
1
  import { RangeType } from "../../Enums/RangeType.js";
2
- import { getDistance } from "../../Utils/MathUtils.js";
2
+ import { checkDistance } from "../../Utils/MathUtils.js";
3
3
  import { squareExp } from "./Constants.js";
4
4
  export class BaseRange {
5
5
  position;
@@ -19,7 +19,7 @@ export class Circle extends BaseRange {
19
19
  this.radius = radius;
20
20
  }
21
21
  contains(point) {
22
- return getDistance(point, this.position) <= this.radius;
22
+ return checkDistance(point, this.position, this.radius);
23
23
  }
24
24
  intersects(range) {
25
25
  const pos1 = this.position, pos2 = range.position, distPos = { x: Math.abs(pos2.x - pos1.x), y: Math.abs(pos2.y - pos1.y) }, r = this.radius;
@@ -0,0 +1,82 @@
1
+ import { Circle, Rectangle } from "./Ranges.js";
2
+ export class SpatialHashGrid {
3
+ _cellSize;
4
+ _cells = new Map();
5
+ _pendingCellSize;
6
+ constructor(cellSize) {
7
+ this._cellSize = cellSize;
8
+ }
9
+ clear() {
10
+ this._cells.clear();
11
+ const pendingCellSize = this._pendingCellSize;
12
+ if (pendingCellSize) {
13
+ this._cellSize = pendingCellSize;
14
+ }
15
+ this._pendingCellSize = undefined;
16
+ }
17
+ insert(particle) {
18
+ const { x, y } = particle.getPosition(), key = this._cellKeyFromCoords(x, y);
19
+ if (!this._cells.has(key)) {
20
+ this._cells.set(key, []);
21
+ }
22
+ this._cells.get(key)?.push(particle);
23
+ }
24
+ query(range, check, out = []) {
25
+ const bounds = this._getRangeBounds(range);
26
+ if (!bounds) {
27
+ return out;
28
+ }
29
+ const minCellX = Math.floor(bounds.minX / this._cellSize), maxCellX = Math.floor(bounds.maxX / this._cellSize), minCellY = Math.floor(bounds.minY / this._cellSize), maxCellY = Math.floor(bounds.maxY / this._cellSize);
30
+ for (let cx = minCellX; cx <= maxCellX; cx++) {
31
+ for (let cy = minCellY; cy <= maxCellY; cy++) {
32
+ const key = `${cx}_${cy}`, cellParticles = this._cells.get(key);
33
+ if (!cellParticles) {
34
+ continue;
35
+ }
36
+ for (const p of cellParticles) {
37
+ if (check && !check(p)) {
38
+ continue;
39
+ }
40
+ if (range.contains(p.getPosition())) {
41
+ out.push(p);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ return out;
47
+ }
48
+ queryCircle(position, radius, check, out = []) {
49
+ return this.query(new Circle(position.x, position.y, radius), check, out);
50
+ }
51
+ queryRectangle(position, size, check, out = []) {
52
+ return this.query(new Rectangle(position.x, position.y, size.width, size.height), check, out);
53
+ }
54
+ setCellSize(cellSize) {
55
+ this._pendingCellSize = cellSize;
56
+ }
57
+ _cellKeyFromCoords(x, y) {
58
+ const cellX = Math.floor(x / this._cellSize), cellY = Math.floor(y / this._cellSize);
59
+ return `${cellX}_${cellY}`;
60
+ }
61
+ _getRangeBounds(range) {
62
+ if (range instanceof Circle) {
63
+ const r = range.radius, { x, y } = range.position;
64
+ return {
65
+ minX: x - r,
66
+ maxX: x + r,
67
+ minY: y - r,
68
+ maxY: y + r,
69
+ };
70
+ }
71
+ if (range instanceof Rectangle) {
72
+ const { x, y } = range.position, { width, height } = range.size;
73
+ return {
74
+ minX: x,
75
+ maxX: x + width,
76
+ minY: y,
77
+ maxY: y + height,
78
+ };
79
+ }
80
+ return null;
81
+ }
82
+ }
@@ -1,4 +1,7 @@
1
1
  import { inverseFactorNumerator, none, originPoint, squareExp } from "./Constants.js";
2
+ function getZ(source) {
3
+ return "z" in source ? source.z : originPoint.z;
4
+ }
2
5
  export class Vector3d {
3
6
  x;
4
7
  y;
@@ -24,31 +27,25 @@ export class Vector3d {
24
27
  this._updateFromAngle(this.angle, length);
25
28
  }
26
29
  static clone(source) {
27
- return Vector3d.create(source.x, source.y, source.z);
30
+ return Vector3d.create(source.x, source.y, getZ(source));
28
31
  }
29
32
  static create(x, y, z) {
30
33
  if (typeof x === "number") {
31
34
  return new Vector3d(x, y ?? originPoint.y, z ?? originPoint.z);
32
35
  }
33
- return new Vector3d(x.x, x.y, Object.hasOwn(x, "z") ? x.z : originPoint.z);
36
+ return new Vector3d(x.x, x.y, getZ(x));
34
37
  }
35
38
  add(v) {
36
- return Vector3d.create(this.x + v.x, this.y + v.y, this.z + v.z);
39
+ return Vector3d.create(this.x + v.x, this.y + v.y, this.z + getZ(v));
37
40
  }
38
41
  addTo(v) {
39
42
  this.x += v.x;
40
43
  this.y += v.y;
41
- this.z += v.z;
44
+ this.z += getZ(v);
42
45
  }
43
46
  copy() {
44
47
  return Vector3d.clone(this);
45
48
  }
46
- distanceTo(v) {
47
- return this.sub(v).length;
48
- }
49
- distanceToSq(v) {
50
- return this.sub(v).getLengthSq();
51
- }
52
49
  div(n) {
53
50
  return Vector3d.create(this.x / n, this.y / n, this.z / n);
54
51
  }
@@ -80,21 +77,20 @@ export class Vector3d {
80
77
  setTo(c) {
81
78
  this.x = c.x;
82
79
  this.y = c.y;
83
- const v3d = c;
84
- this.z = v3d.z ? v3d.z : originPoint.z;
80
+ this.z = getZ(c);
85
81
  }
86
82
  sub(v) {
87
- return Vector3d.create(this.x - v.x, this.y - v.y, this.z - v.z);
83
+ return Vector3d.create(this.x - v.x, this.y - v.y, this.z - getZ(v));
88
84
  }
89
85
  subFrom(v) {
90
86
  this.x -= v.x;
91
87
  this.y -= v.y;
92
- this.z -= v.z;
88
+ this.z -= getZ(v);
93
89
  }
94
- _updateFromAngle = (angle, length) => {
90
+ _updateFromAngle(angle, length) {
95
91
  this.x = Math.cos(angle) * length;
96
92
  this.y = Math.sin(angle) * length;
97
- };
93
+ }
98
94
  }
99
95
  export class Vector extends Vector3d {
100
96
  constructor(x = originPoint.x, y = originPoint.y) {
@@ -1,7 +1,6 @@
1
1
  import { MoveDirection } from "../../../../Enums/Directions/MoveDirection.js";
2
2
  import { isNull, isNumber, isObject } from "../../../../Utils/TypeUtils.js";
3
3
  import { MoveAngle } from "./MoveAngle.js";
4
- import { MoveAttract } from "./MoveAttract.js";
5
4
  import { MoveCenter } from "./MoveCenter.js";
6
5
  import { MoveGravity } from "./MoveGravity.js";
7
6
  import { MovePath } from "./Path/MovePath.js";
@@ -10,7 +9,6 @@ import { Spin } from "./Spin.js";
10
9
  import { setRangeValue } from "../../../../Utils/MathUtils.js";
11
10
  export class Move {
12
11
  angle;
13
- attract;
14
12
  center;
15
13
  decay;
16
14
  direction;
@@ -29,7 +27,6 @@ export class Move {
29
27
  warp;
30
28
  constructor() {
31
29
  this.angle = new MoveAngle();
32
- this.attract = new MoveAttract();
33
30
  this.center = new MoveCenter();
34
31
  this.decay = 0;
35
32
  this.distance = {};
@@ -52,7 +49,6 @@ export class Move {
52
49
  return;
53
50
  }
54
51
  this.angle.load(isNumber(data.angle) ? { value: data.angle } : data.angle);
55
- this.attract.load(data.attract);
56
52
  this.center.load(data.center);
57
53
  if (data.decay !== undefined) {
58
54
  this.decay = setRangeValue(data.decay);
@@ -7,15 +7,16 @@ export function paintImage(context, dimension, image, opacity) {
7
7
  if (!image) {
8
8
  return;
9
9
  }
10
+ const prevAlpha = context.globalAlpha;
10
11
  context.globalAlpha = opacity;
11
12
  context.drawImage(image, originPoint.x, originPoint.y, dimension.width, dimension.height);
12
- context.globalAlpha = 1;
13
+ context.globalAlpha = prevAlpha;
13
14
  }
14
15
  export function clear(context, dimension) {
15
16
  context.clearRect(originPoint.x, originPoint.y, dimension.width, dimension.height);
16
17
  }
17
18
  export function drawParticle(data) {
18
- const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = defaultZoom, drawPosition = {
19
+ const { container, context, particle, delta, colorStyles, radius, opacity, transform } = data, { effectDrawers, shapeDrawers } = container.particles, pos = particle.getPosition(), transformData = particle.getTransformData(transform), drawScale = defaultZoom, drawPosition = {
19
20
  x: pos.x,
20
21
  y: pos.y,
21
22
  };
@@ -46,42 +47,40 @@ export function drawParticle(data) {
46
47
  for (const plugin of container.plugins) {
47
48
  plugin.drawParticleTransform?.(drawData);
48
49
  }
49
- drawBeforeEffect(container, drawData);
50
- drawShapeBeforeDraw(container, drawData);
51
- drawShape(container, drawData);
52
- drawShapeAfterDraw(container, drawData);
53
- drawAfterEffect(container, drawData);
50
+ const effect = particle.effect ? effectDrawers.get(particle.effect) : undefined, shape = particle.shape ? shapeDrawers.get(particle.shape) : undefined;
51
+ drawBeforeEffect(effect, drawData);
52
+ drawShapeBeforeDraw(shape, drawData);
53
+ drawShape(shape, drawData);
54
+ drawShapeAfterDraw(shape, drawData);
55
+ drawAfterEffect(effect, drawData);
54
56
  context.resetTransform();
55
57
  }
56
- export function drawAfterEffect(container, data) {
58
+ export function drawAfterEffect(drawer, data) {
59
+ if (!drawer?.drawAfter) {
60
+ return;
61
+ }
57
62
  const { particle } = data;
58
63
  if (!particle.effect) {
59
64
  return;
60
65
  }
61
- const drawer = container.particles.effectDrawers.get(particle.effect), drawFunc = drawer?.drawAfter;
62
- if (!drawFunc) {
66
+ drawer.drawAfter(data);
67
+ }
68
+ export function drawBeforeEffect(drawer, data) {
69
+ if (!drawer?.drawBefore) {
63
70
  return;
64
71
  }
65
- drawFunc(data);
66
- }
67
- export function drawBeforeEffect(container, data) {
68
72
  const { particle } = data;
69
73
  if (!particle.effect) {
70
74
  return;
71
75
  }
72
- const drawer = container.particles.effectDrawers.get(particle.effect);
73
- if (!drawer?.drawBefore) {
74
- return;
75
- }
76
76
  drawer.drawBefore(data);
77
77
  }
78
- export function drawShape(container, data) {
79
- const { context, particle, stroke } = data;
80
- if (!particle.shape) {
78
+ export function drawShape(drawer, data) {
79
+ if (!drawer) {
81
80
  return;
82
81
  }
83
- const drawer = container.particles.shapeDrawers.get(particle.shape);
84
- if (!drawer) {
82
+ const { context, particle, stroke } = data;
83
+ if (!particle.shape) {
85
84
  return;
86
85
  }
87
86
  context.beginPath();
@@ -96,26 +95,24 @@ export function drawShape(container, data) {
96
95
  context.fill();
97
96
  }
98
97
  }
99
- export function drawShapeAfterDraw(container, data) {
100
- const { particle } = data;
101
- if (!particle.shape) {
102
- return;
103
- }
104
- const drawer = container.particles.shapeDrawers.get(particle.shape);
98
+ export function drawShapeAfterDraw(drawer, data) {
105
99
  if (!drawer?.afterDraw) {
106
100
  return;
107
101
  }
108
- drawer.afterDraw(data);
109
- }
110
- export function drawShapeBeforeDraw(container, data) {
111
102
  const { particle } = data;
112
103
  if (!particle.shape) {
113
104
  return;
114
105
  }
115
- const drawer = container.particles.shapeDrawers.get(particle.shape);
106
+ drawer.afterDraw(data);
107
+ }
108
+ export function drawShapeBeforeDraw(drawer, data) {
116
109
  if (!drawer?.beforeDraw) {
117
110
  return;
118
111
  }
112
+ const { particle } = data;
113
+ if (!particle.shape) {
114
+ return;
115
+ }
119
116
  drawer.beforeDraw(data);
120
117
  }
121
118
  export function drawParticlePlugin(context, plugin, particle, delta) {