@tsparticles/engine 4.0.0-alpha.26 → 4.0.0-alpha.27
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.
- package/164.min.js +1 -0
- package/README.md +1 -1
- package/browser/Core/Canvas.js +7 -4
- package/browser/Core/Engine.js +8 -1
- package/browser/Core/Interfaces/IPalette.js +1 -0
- package/browser/Core/Particle.js +8 -12
- package/browser/Core/Utils/Constants.js +1 -1
- package/browser/Options/Classes/ColorAnimation.js +11 -1
- package/browser/Options/Classes/HslAnimation.js +4 -3
- package/browser/Options/Classes/Options.js +38 -1
- package/browser/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/browser/Options/Classes/Particles/Fill.js +28 -0
- package/browser/Options/Classes/Particles/ParticlesOptions.js +12 -6
- package/browser/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/browser/Options/Interfaces/Particles/IFill.js +1 -0
- package/browser/Utils/CanvasUtils.js +5 -5
- package/browser/Utils/ColorUtils.js +22 -19
- package/browser/Utils/Utils.js +86 -13
- package/browser/exports.js +1 -0
- package/cjs/Core/Canvas.js +7 -4
- package/cjs/Core/Engine.js +8 -1
- package/cjs/Core/Interfaces/IPalette.js +1 -0
- package/cjs/Core/Particle.js +8 -12
- package/cjs/Core/Utils/Constants.js +1 -1
- package/cjs/Options/Classes/ColorAnimation.js +11 -1
- package/cjs/Options/Classes/HslAnimation.js +4 -3
- package/cjs/Options/Classes/Options.js +38 -1
- package/cjs/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/cjs/Options/Classes/Particles/Fill.js +28 -0
- package/cjs/Options/Classes/Particles/ParticlesOptions.js +12 -6
- package/cjs/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/cjs/Options/Interfaces/Particles/IFill.js +1 -0
- package/cjs/Utils/CanvasUtils.js +5 -5
- package/cjs/Utils/ColorUtils.js +22 -19
- package/cjs/Utils/Utils.js +86 -13
- package/cjs/exports.js +1 -0
- package/dist_browser_Core_Container_js.js +3 -3
- package/esm/Core/Canvas.js +7 -4
- package/esm/Core/Engine.js +8 -1
- package/esm/Core/Interfaces/IPalette.js +1 -0
- package/esm/Core/Particle.js +8 -12
- package/esm/Core/Utils/Constants.js +1 -1
- package/esm/Options/Classes/ColorAnimation.js +11 -1
- package/esm/Options/Classes/HslAnimation.js +4 -3
- package/esm/Options/Classes/Options.js +38 -1
- package/esm/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/esm/Options/Classes/Particles/Fill.js +28 -0
- package/esm/Options/Classes/Particles/ParticlesOptions.js +12 -6
- package/esm/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/esm/Options/Interfaces/Particles/IFill.js +1 -0
- package/esm/Utils/CanvasUtils.js +5 -5
- package/esm/Utils/ColorUtils.js +22 -19
- package/esm/Utils/Utils.js +86 -13
- package/esm/exports.js +1 -0
- package/package.json +1 -1
- package/report.html +1 -1
- package/scripts/install.js +2 -18
- package/tsparticles.engine.js +30 -20
- package/tsparticles.engine.min.js +2 -2
- package/types/Core/Engine.d.ts +4 -0
- package/types/Core/Interfaces/IPalette.d.ts +7 -0
- package/types/Core/Interfaces/IParticleOpacityData.d.ts +1 -0
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +3 -3
- package/types/Core/Interfaces/IShapeValues.d.ts +0 -1
- package/types/Core/Particle.d.ts +3 -3
- package/types/Core/Utils/Constants.d.ts +1 -1
- package/types/Options/Classes/ColorAnimation.d.ts +3 -1
- package/types/Options/Classes/Options.d.ts +2 -0
- package/types/Options/Classes/Particles/Effect/Effect.d.ts +0 -1
- package/types/Options/Classes/Particles/Fill.d.ts +12 -0
- package/types/Options/Classes/Particles/ParticlesOptions.d.ts +2 -2
- package/types/Options/Classes/Particles/Shape/Shape.d.ts +0 -1
- package/types/Options/Interfaces/IColorAnimation.d.ts +2 -0
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Particles/Effect/IEffect.d.ts +0 -1
- package/types/Options/Interfaces/Particles/IFill.d.ts +9 -0
- package/types/Options/Interfaces/Particles/IParticlesOptions.d.ts +2 -2
- package/types/Options/Interfaces/Particles/IStroke.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Shape/IShape.d.ts +0 -1
- package/types/Utils/ColorUtils.d.ts +1 -2
- package/types/Utils/Utils.d.ts +7 -0
- package/types/export-types.d.ts +2 -1
- package/types/exports.d.ts +1 -0
- package/umd/Core/Canvas.js +6 -3
- package/umd/Core/Engine.js +8 -1
- package/umd/Core/Interfaces/IPalette.js +12 -0
- package/umd/Core/Particle.js +8 -12
- package/umd/Core/Utils/Constants.js +2 -2
- package/umd/Options/Classes/ColorAnimation.js +11 -1
- package/umd/Options/Classes/HslAnimation.js +5 -4
- package/umd/Options/Classes/Options.js +38 -1
- package/umd/Options/Classes/Particles/Effect/Effect.js +0 -5
- package/umd/Options/Classes/Particles/Fill.js +42 -0
- package/umd/Options/Classes/Particles/ParticlesOptions.js +13 -7
- package/umd/Options/Classes/Particles/Shape/Shape.js +0 -5
- package/umd/Options/Interfaces/Particles/IFill.js +12 -0
- package/umd/Utils/CanvasUtils.js +5 -5
- package/umd/Utils/ColorUtils.js +21 -18
- package/umd/Utils/Utils.js +87 -13
- package/umd/exports.js +2 -1
- package/622.min.js +0 -1
package/164.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_engine=this.webpackChunk_tsparticles_engine||[]).push([[164],{8164(t,i,e){e.d(i,{Container:()=>O});var s=e(3884),a=e(1590),r=e(9854),n=e(4874),o=e(1339);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(),[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,{fillOpacity:u,opacity:_,strokeOpacity:g}=t.getOpacity(),f=this._reusableTransform,P=this._reusableColorStyles,m=l?(0,o.LC)(l,c.hdr,u*_):void 0,y=h?(0,o.LC)(h,c.hdr,g*_):m;f.a=f.b=f.c=f.d=void 0,P.fill=m,P.stroke=y,this.draw(s=>{for(let e of this._drawParticlesSetupPlugins)e.drawParticleSetup?.(s,t,i);for(let a of(this._applyPreDrawUpdaters(s,t,e,_,P,f),(0,r.p0)({container:c,context:s,particle:t,delta:i,colorStyles:P,radius:e*p**d.sizeRate,opacity:_,transform:f}),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._context&&(this._context.globalCompositeOperation=a.yj),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||!(e in i.style))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(8202),p=e(9289),u=e(3443),_=e(2067),g=e(7613),f=e(3652),P=e(6492),m=e(3692);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;destroyed;direction;effect;effectClose;effectData;fillColor;fillEnabled;fillOpacity;group;id;ignoresResizeRatio;initialPosition;initialVelocity;isRotating;lastPathTime;misplaced;moveCenter;offset;opacity;options;outType;pathRotation;position;randomIndexData;retina;roll;rotation;shape;shapeClose;shapeData;sides;size;slow;spawning;strokeColor;strokeOpacity;strokeWidth;unbreakable;velocity;zIndexFactor;_cachedOpacityData={fillOpacity:a.hv,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.fillColor))}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.fillOpacity??a.hv,o=this.strokeOpacity??a.hv;return this._cachedOpacityData.fillOpacity=r*n*e,this._cachedOpacityData.opacity=r*e,this._cachedOpacityData.strokeOpacity=r*o*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.shapeClose=!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},(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},(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.effectClose=x?.close??w.effect.close,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 O=g.particles;O.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 R=p?.getSidesCount;for(let t of(R&&(this.sides=R(this)),this.spawning=!1,O.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(5821);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(3112);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 O{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
package/browser/Core/Canvas.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clear, drawParticle, drawParticlePlugin, paintBase, paintImage } from "../Utils/CanvasUtils.js";
|
|
2
2
|
import { cloneStyle, getFullScreenStyle, safeMatchMedia, safeMutationObserver } from "../Utils/Utils.js";
|
|
3
|
-
import { defaultTransformValue, defaultZoom, generatedAttribute, half, minimumSize, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
3
|
+
import { defaultCompositeValue, defaultTransformValue, defaultZoom, generatedAttribute, half, minimumSize, zIndexFactorOffset, } from "./Utils/Constants.js";
|
|
4
4
|
import { getStyleFromHsl, getStyleFromRgb, rangeColorToHsl, rangeColorToRgb } from "../Utils/ColorUtils.js";
|
|
5
5
|
const fColorIndex = 0, sColorIndex = 1;
|
|
6
6
|
function setTransformValue(factor, newFactor, key) {
|
|
@@ -163,14 +163,14 @@ export class Canvas {
|
|
|
163
163
|
if (radius <= minimumSize) {
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor()
|
|
166
|
+
const pfColor = particle.getFillColor(), psColor = particle.getStrokeColor();
|
|
167
167
|
let [fColor, sColor] = this._getPluginParticleColors(particle);
|
|
168
168
|
fColor ??= pfColor;
|
|
169
169
|
sColor ??= psColor;
|
|
170
170
|
if (!fColor && !sColor) {
|
|
171
171
|
return;
|
|
172
172
|
}
|
|
173
|
-
const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity) : fill;
|
|
173
|
+
const container = this.container, zIndexOptions = particle.options.zIndex, zIndexFactor = zIndexFactorOffset - particle.zIndexFactor, { fillOpacity, opacity, strokeOpacity } = particle.getOpacity(), transform = this._reusableTransform, colorStyles = this._reusableColorStyles, fill = fColor ? getStyleFromHsl(fColor, container.hdr, fillOpacity * opacity) : undefined, stroke = sColor ? getStyleFromHsl(sColor, container.hdr, strokeOpacity * opacity) : fill;
|
|
174
174
|
transform.a = transform.b = transform.c = transform.d = undefined;
|
|
175
175
|
colorStyles.fill = fill;
|
|
176
176
|
colorStyles.stroke = stroke;
|
|
@@ -357,6 +357,9 @@ export class Canvas {
|
|
|
357
357
|
willReadFrequently: false,
|
|
358
358
|
};
|
|
359
359
|
this._context = this.element.getContext("2d", this._canvasSettings);
|
|
360
|
+
if (this._context) {
|
|
361
|
+
this._context.globalCompositeOperation = defaultCompositeValue;
|
|
362
|
+
}
|
|
360
363
|
this._safeMutationObserver(obs => {
|
|
361
364
|
obs.disconnect();
|
|
362
365
|
});
|
|
@@ -514,7 +517,7 @@ export class Canvas {
|
|
|
514
517
|
this._resetOriginalStyle();
|
|
515
518
|
}
|
|
516
519
|
for (const key in options.style) {
|
|
517
|
-
if (!key || !
|
|
520
|
+
if (!key || !(key in options.style)) {
|
|
518
521
|
continue;
|
|
519
522
|
}
|
|
520
523
|
const value = options.style[key];
|
package/browser/Core/Engine.js
CHANGED
|
@@ -60,6 +60,7 @@ export class Engine {
|
|
|
60
60
|
shapes: new Map(),
|
|
61
61
|
updaters: new Map(),
|
|
62
62
|
};
|
|
63
|
+
palettes = new Map();
|
|
63
64
|
plugins = [];
|
|
64
65
|
presets = new Map();
|
|
65
66
|
shapeDrawers = new Map();
|
|
@@ -83,7 +84,7 @@ export class Engine {
|
|
|
83
84
|
return this._domArray;
|
|
84
85
|
}
|
|
85
86
|
get version() {
|
|
86
|
-
return "4.0.0-alpha.
|
|
87
|
+
return "4.0.0-alpha.27";
|
|
87
88
|
}
|
|
88
89
|
addColorManager(name, manager) {
|
|
89
90
|
this.colorManagers.set(name, manager);
|
|
@@ -105,6 +106,9 @@ export class Engine {
|
|
|
105
106
|
addEventListener(type, listener) {
|
|
106
107
|
this._eventDispatcher.addEventListener(type, listener);
|
|
107
108
|
}
|
|
109
|
+
addPalette(name, palette) {
|
|
110
|
+
this.palettes.set(name, palette);
|
|
111
|
+
}
|
|
108
112
|
addParticleUpdater(name, updaterInitializer) {
|
|
109
113
|
this.initializers.updaters.set(name, updaterInitializer);
|
|
110
114
|
}
|
|
@@ -145,6 +149,9 @@ export class Engine {
|
|
|
145
149
|
getEffectDrawers(container, force = false) {
|
|
146
150
|
return getItemMapFromInitializer(container, this.effectDrawers, this.initializers.effects, force);
|
|
147
151
|
}
|
|
152
|
+
getPalette(name) {
|
|
153
|
+
return this.palettes.get(name);
|
|
154
|
+
}
|
|
148
155
|
getPlugin(plugin) {
|
|
149
156
|
return this.plugins.find(t => t.id === plugin);
|
|
150
157
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/Core/Particle.js
CHANGED
|
@@ -12,14 +12,12 @@ function loadEffectData(effect, effectOptions, id, reduceDuplicates) {
|
|
|
12
12
|
const effectData = effectOptions.options[effect];
|
|
13
13
|
return deepExtend({
|
|
14
14
|
close: effectOptions.close,
|
|
15
|
-
fill: effectOptions.fill,
|
|
16
15
|
}, itemFromSingleOrMultiple(effectData, id, reduceDuplicates));
|
|
17
16
|
}
|
|
18
17
|
function loadShapeData(shape, shapeOptions, id, reduceDuplicates) {
|
|
19
18
|
const shapeData = shapeOptions.options[shape];
|
|
20
19
|
return deepExtend({
|
|
21
20
|
close: shapeOptions.close,
|
|
22
|
-
fill: shapeOptions.fill,
|
|
23
21
|
}, itemFromSingleOrMultiple(shapeData, id, reduceDuplicates));
|
|
24
22
|
}
|
|
25
23
|
function fixOutMode(data) {
|
|
@@ -38,13 +36,14 @@ export class Particle {
|
|
|
38
36
|
container;
|
|
39
37
|
backColor;
|
|
40
38
|
bubble;
|
|
41
|
-
color;
|
|
42
39
|
destroyed;
|
|
43
40
|
direction;
|
|
44
41
|
effect;
|
|
45
42
|
effectClose;
|
|
46
43
|
effectData;
|
|
47
|
-
|
|
44
|
+
fillColor;
|
|
45
|
+
fillEnabled;
|
|
46
|
+
fillOpacity;
|
|
48
47
|
group;
|
|
49
48
|
id;
|
|
50
49
|
ignoresResizeRatio;
|
|
@@ -67,7 +66,6 @@ export class Particle {
|
|
|
67
66
|
shape;
|
|
68
67
|
shapeClose;
|
|
69
68
|
shapeData;
|
|
70
|
-
shapeFill;
|
|
71
69
|
sides;
|
|
72
70
|
size;
|
|
73
71
|
slow;
|
|
@@ -79,6 +77,7 @@ export class Particle {
|
|
|
79
77
|
velocity;
|
|
80
78
|
zIndexFactor;
|
|
81
79
|
_cachedOpacityData = {
|
|
80
|
+
fillOpacity: defaultOpacity,
|
|
82
81
|
opacity: defaultOpacity,
|
|
83
82
|
strokeOpacity: defaultOpacity,
|
|
84
83
|
};
|
|
@@ -126,15 +125,16 @@ export class Particle {
|
|
|
126
125
|
return this.rotation + (this.pathRotation ? this.velocity.angle : defaultAngle);
|
|
127
126
|
}
|
|
128
127
|
getFillColor() {
|
|
129
|
-
return this._getRollColor(this.bubble.color ?? getHslFromAnimation(this.
|
|
128
|
+
return this._getRollColor(this.bubble.color ?? getHslFromAnimation(this.fillColor));
|
|
130
129
|
}
|
|
131
130
|
getMass() {
|
|
132
131
|
return this.getRadius() ** squareExp * Math.PI * half;
|
|
133
132
|
}
|
|
134
133
|
getOpacity() {
|
|
135
|
-
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? getRangeValue(this.opacity?.value ?? defaultOpacity), strokeOpacity = this.strokeOpacity ??
|
|
134
|
+
const zIndexOptions = this.options.zIndex, zIndexFactor = zIndexFactorOffset - this.zIndexFactor, zOpacityFactor = zIndexFactor ** zIndexOptions.opacityRate, opacity = this.bubble.opacity ?? getRangeValue(this.opacity?.value ?? defaultOpacity), fillOpacity = this.fillOpacity ?? defaultOpacity, strokeOpacity = this.strokeOpacity ?? defaultOpacity;
|
|
135
|
+
this._cachedOpacityData.fillOpacity = opacity * fillOpacity * zOpacityFactor;
|
|
136
136
|
this._cachedOpacityData.opacity = opacity * zOpacityFactor;
|
|
137
|
-
this._cachedOpacityData.strokeOpacity = strokeOpacity * zOpacityFactor;
|
|
137
|
+
this._cachedOpacityData.strokeOpacity = opacity * strokeOpacity * zOpacityFactor;
|
|
138
138
|
return this._cachedOpacityData;
|
|
139
139
|
}
|
|
140
140
|
getPosition() {
|
|
@@ -172,9 +172,7 @@ export class Particle {
|
|
|
172
172
|
this.id = id;
|
|
173
173
|
this.group = group;
|
|
174
174
|
this.effectClose = true;
|
|
175
|
-
this.effectFill = true;
|
|
176
175
|
this.shapeClose = true;
|
|
177
|
-
this.shapeFill = true;
|
|
178
176
|
this.pathRotation = false;
|
|
179
177
|
this.lastPathTime = 0;
|
|
180
178
|
this.destroyed = false;
|
|
@@ -226,9 +224,7 @@ export class Particle {
|
|
|
226
224
|
if (shapeData) {
|
|
227
225
|
particlesOptions.load(shapeData.particles);
|
|
228
226
|
}
|
|
229
|
-
this.effectFill = effectData?.fill ?? particlesOptions.effect.fill;
|
|
230
227
|
this.effectClose = effectData?.close ?? particlesOptions.effect.close;
|
|
231
|
-
this.shapeFill = shapeData?.fill ?? particlesOptions.shape.fill;
|
|
232
228
|
this.shapeClose = shapeData?.close ?? particlesOptions.shape.close;
|
|
233
229
|
this.options = particlesOptions;
|
|
234
230
|
container.retina.initParticle(this);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const generatedAttribute = "generated", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
|
|
1
|
+
export const generatedAttribute = "generated", defaultCompositeValue = "source-over", resizeEvent = "resize", visibilityChangeEvent = "visibilitychange", percentDenominator = 100, half = 0.5, millisecondsToSeconds = 1000, originPoint = {
|
|
2
2
|
x: 0,
|
|
3
3
|
y: 0,
|
|
4
4
|
z: 0,
|
|
@@ -2,9 +2,13 @@ import { AnimationOptions } from "./AnimationOptions.js";
|
|
|
2
2
|
import { isNull } from "../../Utils/TypeUtils.js";
|
|
3
3
|
import { setRangeValue } from "../../Utils/MathUtils.js";
|
|
4
4
|
export class ColorAnimation extends AnimationOptions {
|
|
5
|
+
max;
|
|
6
|
+
min;
|
|
5
7
|
offset;
|
|
6
|
-
constructor() {
|
|
8
|
+
constructor(min, max) {
|
|
7
9
|
super();
|
|
10
|
+
this.min = min;
|
|
11
|
+
this.max = max;
|
|
8
12
|
this.offset = 0;
|
|
9
13
|
this.sync = true;
|
|
10
14
|
}
|
|
@@ -13,6 +17,12 @@ export class ColorAnimation extends AnimationOptions {
|
|
|
13
17
|
if (isNull(data)) {
|
|
14
18
|
return;
|
|
15
19
|
}
|
|
20
|
+
if (data.max !== undefined) {
|
|
21
|
+
this.max = data.max;
|
|
22
|
+
}
|
|
23
|
+
if (data.min !== undefined) {
|
|
24
|
+
this.min = data.min;
|
|
25
|
+
}
|
|
16
26
|
if (data.offset !== undefined) {
|
|
17
27
|
this.offset = setRangeValue(data.offset);
|
|
18
28
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { hMax, hMin, lMax, lMin, sMax, sMin } from "../../Core/Utils/Constants.js";
|
|
1
2
|
import { ColorAnimation } from "./ColorAnimation.js";
|
|
2
3
|
import { isNull } from "../../Utils/TypeUtils.js";
|
|
3
4
|
export class HslAnimation {
|
|
4
|
-
h = new ColorAnimation();
|
|
5
|
-
l = new ColorAnimation();
|
|
6
|
-
s = new ColorAnimation();
|
|
5
|
+
h = new ColorAnimation(hMin, hMax);
|
|
6
|
+
l = new ColorAnimation(lMin, lMax);
|
|
7
|
+
s = new ColorAnimation(sMin, sMax);
|
|
7
8
|
load(data) {
|
|
8
9
|
if (isNull(data)) {
|
|
9
10
|
return;
|
|
@@ -18,6 +18,7 @@ export class Options {
|
|
|
18
18
|
hdr;
|
|
19
19
|
key;
|
|
20
20
|
name;
|
|
21
|
+
palette;
|
|
21
22
|
particles;
|
|
22
23
|
pauseOnBlur;
|
|
23
24
|
pauseOnOutsideViewport;
|
|
@@ -54,10 +55,15 @@ export class Options {
|
|
|
54
55
|
return;
|
|
55
56
|
}
|
|
56
57
|
if (data.preset !== undefined) {
|
|
57
|
-
|
|
58
|
+
this.preset = data.preset;
|
|
59
|
+
executeOnSingleOrMultiple(this.preset, preset => {
|
|
58
60
|
this._importPreset(preset);
|
|
59
61
|
});
|
|
60
62
|
}
|
|
63
|
+
if (data.palette !== undefined) {
|
|
64
|
+
this.palette = data.palette;
|
|
65
|
+
this._importPalette(this.palette);
|
|
66
|
+
}
|
|
61
67
|
if (data.autoPlay !== undefined) {
|
|
62
68
|
this.autoPlay = data.autoPlay;
|
|
63
69
|
}
|
|
@@ -114,6 +120,37 @@ export class Options {
|
|
|
114
120
|
plugin.loadOptions(this._container, this, data);
|
|
115
121
|
});
|
|
116
122
|
}
|
|
123
|
+
_importPalette = palette => {
|
|
124
|
+
const paletteData = this._engine.getPalette(palette);
|
|
125
|
+
if (!paletteData) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.load({
|
|
129
|
+
background: {
|
|
130
|
+
color: paletteData.background,
|
|
131
|
+
},
|
|
132
|
+
blend: {
|
|
133
|
+
enable: true,
|
|
134
|
+
mode: paletteData.blendMode,
|
|
135
|
+
},
|
|
136
|
+
particles: {
|
|
137
|
+
fill: {
|
|
138
|
+
color: paletteData.fill
|
|
139
|
+
? {
|
|
140
|
+
value: paletteData.colors,
|
|
141
|
+
}
|
|
142
|
+
: undefined,
|
|
143
|
+
enable: paletteData.fill,
|
|
144
|
+
},
|
|
145
|
+
stroke: !paletteData.fill
|
|
146
|
+
? paletteData.colors.map(color => ({
|
|
147
|
+
color: { value: color },
|
|
148
|
+
width: 1,
|
|
149
|
+
}))
|
|
150
|
+
: undefined,
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
};
|
|
117
154
|
_importPreset = preset => {
|
|
118
155
|
this.load(this._engine.getPreset(preset));
|
|
119
156
|
};
|
|
@@ -2,12 +2,10 @@ import { deepExtend } from "../../../../Utils/Utils.js";
|
|
|
2
2
|
import { isNull } from "../../../../Utils/TypeUtils.js";
|
|
3
3
|
export class Effect {
|
|
4
4
|
close;
|
|
5
|
-
fill;
|
|
6
5
|
options;
|
|
7
6
|
type;
|
|
8
7
|
constructor() {
|
|
9
8
|
this.close = true;
|
|
10
|
-
this.fill = true;
|
|
11
9
|
this.options = {};
|
|
12
10
|
this.type = [];
|
|
13
11
|
}
|
|
@@ -27,9 +25,6 @@ export class Effect {
|
|
|
27
25
|
if (data.close !== undefined) {
|
|
28
26
|
this.close = data.close;
|
|
29
27
|
}
|
|
30
|
-
if (data.fill !== undefined) {
|
|
31
|
-
this.fill = data.fill;
|
|
32
|
-
}
|
|
33
28
|
if (data.type !== undefined) {
|
|
34
29
|
this.type = data.type;
|
|
35
30
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { AnimatableColor } from "../AnimatableColor.js";
|
|
2
|
+
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
3
|
+
import { setRangeValue } from "../../../Utils/MathUtils.js";
|
|
4
|
+
export class Fill {
|
|
5
|
+
color;
|
|
6
|
+
enable;
|
|
7
|
+
opacity;
|
|
8
|
+
constructor() {
|
|
9
|
+
this.enable = true;
|
|
10
|
+
this.color = new AnimatableColor();
|
|
11
|
+
this.color.value = "#fff";
|
|
12
|
+
this.opacity = 1;
|
|
13
|
+
}
|
|
14
|
+
load(data) {
|
|
15
|
+
if (isNull(data)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (data.color !== undefined) {
|
|
19
|
+
this.color = AnimatableColor.create(this.color, data.color);
|
|
20
|
+
}
|
|
21
|
+
if (data.enable !== undefined) {
|
|
22
|
+
this.enable = data.enable;
|
|
23
|
+
}
|
|
24
|
+
if (data.opacity !== undefined) {
|
|
25
|
+
this.opacity = setRangeValue(data.opacity);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { deepExtend, executeOnSingleOrMultiple } from "../../../Utils/Utils.js";
|
|
2
|
-
import { AnimatableColor } from "../AnimatableColor.js";
|
|
3
2
|
import { Effect } from "./Effect/Effect.js";
|
|
3
|
+
import { Fill } from "./Fill.js";
|
|
4
4
|
import { Move } from "./Move/Move.js";
|
|
5
5
|
import { Opacity } from "./Opacity/Opacity.js";
|
|
6
6
|
import { ParticlesBounce } from "./Bounce/ParticlesBounce.js";
|
|
@@ -12,8 +12,8 @@ import { ZIndex } from "./ZIndex/ZIndex.js";
|
|
|
12
12
|
import { isNull } from "../../../Utils/TypeUtils.js";
|
|
13
13
|
export class ParticlesOptions {
|
|
14
14
|
bounce;
|
|
15
|
-
color;
|
|
16
15
|
effect;
|
|
16
|
+
fill;
|
|
17
17
|
groups;
|
|
18
18
|
move;
|
|
19
19
|
number;
|
|
@@ -29,9 +29,8 @@ export class ParticlesOptions {
|
|
|
29
29
|
this._engine = engine;
|
|
30
30
|
this._container = container;
|
|
31
31
|
this.bounce = new ParticlesBounce();
|
|
32
|
-
this.color = new AnimatableColor();
|
|
33
|
-
this.color.value = "#fff";
|
|
34
32
|
this.effect = new Effect();
|
|
33
|
+
this.fill = new Fill();
|
|
35
34
|
this.groups = {};
|
|
36
35
|
this.move = new Move();
|
|
37
36
|
this.number = new ParticlesNumber();
|
|
@@ -48,7 +47,7 @@ export class ParticlesOptions {
|
|
|
48
47
|
}
|
|
49
48
|
if (data.groups !== undefined) {
|
|
50
49
|
for (const group of Object.keys(data.groups)) {
|
|
51
|
-
if (!
|
|
50
|
+
if (!(group in data.groups)) {
|
|
52
51
|
continue;
|
|
53
52
|
}
|
|
54
53
|
const item = data.groups[group];
|
|
@@ -61,7 +60,6 @@ export class ParticlesOptions {
|
|
|
61
60
|
this.reduceDuplicates = data.reduceDuplicates;
|
|
62
61
|
}
|
|
63
62
|
this.bounce.load(data.bounce);
|
|
64
|
-
this.color.load(AnimatableColor.create(this.color, data.color));
|
|
65
63
|
this.effect.load(data.effect);
|
|
66
64
|
this.move.load(data.move);
|
|
67
65
|
this.number.load(data.number);
|
|
@@ -69,6 +67,14 @@ export class ParticlesOptions {
|
|
|
69
67
|
this.shape.load(data.shape);
|
|
70
68
|
this.size.load(data.size);
|
|
71
69
|
this.zIndex.load(data.zIndex);
|
|
70
|
+
const fillToLoad = data.fill;
|
|
71
|
+
if (fillToLoad) {
|
|
72
|
+
this.fill = executeOnSingleOrMultiple(fillToLoad, t => {
|
|
73
|
+
const tmp = new Fill();
|
|
74
|
+
tmp.load(t);
|
|
75
|
+
return tmp;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
72
78
|
const strokeToLoad = data.stroke;
|
|
73
79
|
if (strokeToLoad) {
|
|
74
80
|
this.stroke = executeOnSingleOrMultiple(strokeToLoad, t => {
|
|
@@ -2,12 +2,10 @@ import { deepExtend } from "../../../../Utils/Utils.js";
|
|
|
2
2
|
import { isNull } from "../../../../Utils/TypeUtils.js";
|
|
3
3
|
export class Shape {
|
|
4
4
|
close;
|
|
5
|
-
fill;
|
|
6
5
|
options;
|
|
7
6
|
type;
|
|
8
7
|
constructor() {
|
|
9
8
|
this.close = true;
|
|
10
|
-
this.fill = true;
|
|
11
9
|
this.options = {};
|
|
12
10
|
this.type = "circle";
|
|
13
11
|
}
|
|
@@ -27,9 +25,6 @@ export class Shape {
|
|
|
27
25
|
if (data.close !== undefined) {
|
|
28
26
|
this.close = data.close;
|
|
29
27
|
}
|
|
30
|
-
if (data.fill !== undefined) {
|
|
31
|
-
this.fill = data.fill;
|
|
32
|
-
}
|
|
33
28
|
if (data.type !== undefined) {
|
|
34
29
|
this.type = data.type;
|
|
35
30
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -24,7 +24,7 @@ export function drawParticle(data) {
|
|
|
24
24
|
if (colorStyles.fill) {
|
|
25
25
|
context.fillStyle = colorStyles.fill;
|
|
26
26
|
}
|
|
27
|
-
const strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
27
|
+
const fillEnabled = !!particle.fillEnabled, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
28
28
|
context.lineWidth = strokeWidth;
|
|
29
29
|
if (colorStyles.stroke) {
|
|
30
30
|
context.strokeStyle = colorStyles.stroke;
|
|
@@ -37,8 +37,8 @@ export function drawParticle(data) {
|
|
|
37
37
|
opacity,
|
|
38
38
|
delta,
|
|
39
39
|
pixelRatio: container.retina.pixelRatio,
|
|
40
|
-
fill:
|
|
41
|
-
stroke: strokeWidth > minStrokeWidth
|
|
40
|
+
fill: fillEnabled,
|
|
41
|
+
stroke: strokeWidth > minStrokeWidth,
|
|
42
42
|
transformData,
|
|
43
43
|
position: { ...pos },
|
|
44
44
|
drawPosition,
|
|
@@ -79,7 +79,7 @@ export function drawShape(drawer, data) {
|
|
|
79
79
|
if (!drawer) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
|
-
const { context, particle, stroke } = data;
|
|
82
|
+
const { context, fill, particle, stroke } = data;
|
|
83
83
|
if (!particle.shape) {
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
@@ -91,7 +91,7 @@ export function drawShape(drawer, data) {
|
|
|
91
91
|
if (stroke) {
|
|
92
92
|
context.stroke();
|
|
93
93
|
}
|
|
94
|
-
if (
|
|
94
|
+
if (fill) {
|
|
95
95
|
context.fill();
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { clamp, getRandom, getRandomInRange,
|
|
1
|
+
import { clamp, getRandom, getRandomInRange, getRangeValue, mix, randomInRangeValue, setRangeValue, } from "./MathUtils.js";
|
|
2
2
|
import { decayOffset, defaultLoops, defaultOpacity, defaultRgbMin, defaultTime, defaultVelocity, double, hMax, hMin, hPhase, half, identity, lFactor, lMax, lMin, midColorValue, millisecondsToSeconds, percentDenominator, phaseNumerator, randomColorValue, rgbMax, sMax, sMin, sNormalizedOffset, sextuple, triple, } from "../Core/Utils/Constants.js";
|
|
3
3
|
import { isArray, isString } from "./TypeUtils.js";
|
|
4
4
|
import { AlterType } from "../Enums/Types/AlterType.js";
|
|
@@ -190,10 +190,10 @@ function getSdrStyleFromHsl(color, opacity) {
|
|
|
190
190
|
}
|
|
191
191
|
export function colorMix(color1, color2, size1, size2) {
|
|
192
192
|
let rgb1 = color1, rgb2 = color2;
|
|
193
|
-
if (!
|
|
193
|
+
if (!("r" in rgb1)) {
|
|
194
194
|
rgb1 = hslToRgb(color1);
|
|
195
195
|
}
|
|
196
|
-
if (!
|
|
196
|
+
if (!("r" in rgb2)) {
|
|
197
197
|
rgb2 = hslToRgb(color2);
|
|
198
198
|
}
|
|
199
199
|
return {
|
|
@@ -246,27 +246,33 @@ export function getLinkRandomColor(engine, optColor, blink, consent) {
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
export function getHslFromAnimation(animation) {
|
|
249
|
-
return animation
|
|
250
|
-
?
|
|
249
|
+
return animation === undefined
|
|
250
|
+
? undefined
|
|
251
|
+
: {
|
|
251
252
|
h: animation.h.value,
|
|
252
253
|
s: animation.s.value,
|
|
253
254
|
l: animation.l.value,
|
|
254
|
-
}
|
|
255
|
-
: undefined;
|
|
255
|
+
};
|
|
256
256
|
}
|
|
257
257
|
export function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
258
258
|
const resColor = {
|
|
259
259
|
h: {
|
|
260
260
|
enable: false,
|
|
261
261
|
value: hsl.h,
|
|
262
|
+
min: hMin,
|
|
263
|
+
max: hMax,
|
|
262
264
|
},
|
|
263
265
|
s: {
|
|
264
266
|
enable: false,
|
|
265
267
|
value: hsl.s,
|
|
268
|
+
min: sMin,
|
|
269
|
+
max: sMax,
|
|
266
270
|
},
|
|
267
271
|
l: {
|
|
268
272
|
enable: false,
|
|
269
273
|
value: hsl.l,
|
|
274
|
+
min: lMin,
|
|
275
|
+
max: lMax,
|
|
270
276
|
},
|
|
271
277
|
};
|
|
272
278
|
if (animationOptions) {
|
|
@@ -278,6 +284,8 @@ export function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
|
|
278
284
|
}
|
|
279
285
|
function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
280
286
|
colorValue.enable = colorAnimation.enable;
|
|
287
|
+
colorValue.min = colorAnimation.min;
|
|
288
|
+
colorValue.max = colorAnimation.max;
|
|
281
289
|
if (colorValue.enable) {
|
|
282
290
|
colorValue.velocity = (getRangeValue(colorAnimation.speed) / percentDenominator) * reduceFactor;
|
|
283
291
|
colorValue.decay = decayOffset - getRangeValue(colorAnimation.decay);
|
|
@@ -297,7 +305,7 @@ function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
|
|
297
305
|
colorValue.velocity = defaultVelocity;
|
|
298
306
|
}
|
|
299
307
|
}
|
|
300
|
-
export function updateColorValue(data,
|
|
308
|
+
export function updateColorValue(data, decrease, delta) {
|
|
301
309
|
const minLoops = 0, minDelay = 0, identity = 1, minVelocity = 0, minOffset = 0, velocityFactor = 3.6;
|
|
302
310
|
if (!data.enable ||
|
|
303
311
|
((data.maxLoops ?? minLoops) > minLoops && (data.loops ?? minLoops) > (data.maxLoops ?? minLoops))) {
|
|
@@ -310,7 +318,7 @@ export function updateColorValue(data, range, decrease, delta) {
|
|
|
310
318
|
if ((data.delayTime ?? minDelay) > minDelay && data.time < (data.delayTime ?? minDelay)) {
|
|
311
319
|
return;
|
|
312
320
|
}
|
|
313
|
-
const offset = data.offset ? randomInRangeValue(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max =
|
|
321
|
+
const offset = data.offset ? randomInRangeValue(data.offset) : minOffset, velocity = (data.velocity ?? minVelocity) * delta.factor + offset * velocityFactor, decay = data.decay ?? identity, max = data.max, min = data.min;
|
|
314
322
|
if (!decrease || data.status === AnimationStatus.increasing) {
|
|
315
323
|
data.value += velocity;
|
|
316
324
|
if (data.value > max) {
|
|
@@ -326,8 +334,7 @@ export function updateColorValue(data, range, decrease, delta) {
|
|
|
326
334
|
}
|
|
327
335
|
else {
|
|
328
336
|
data.value -= velocity;
|
|
329
|
-
|
|
330
|
-
if (data.value < minValue) {
|
|
337
|
+
if (data.value < min) {
|
|
331
338
|
data.loops ??= 0;
|
|
332
339
|
data.loops++;
|
|
333
340
|
data.status = AnimationStatus.increasing;
|
|
@@ -342,14 +349,10 @@ export function updateColor(color, delta) {
|
|
|
342
349
|
if (!color) {
|
|
343
350
|
return;
|
|
344
351
|
}
|
|
345
|
-
const { h, s, l } = color
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
};
|
|
350
|
-
updateColorValue(h, ranges.h, false, delta);
|
|
351
|
-
updateColorValue(s, ranges.s, true, delta);
|
|
352
|
-
updateColorValue(l, ranges.l, true, delta);
|
|
352
|
+
const { h, s, l } = color;
|
|
353
|
+
updateColorValue(h, false, delta);
|
|
354
|
+
updateColorValue(s, true, delta);
|
|
355
|
+
updateColorValue(l, true, delta);
|
|
353
356
|
}
|
|
354
357
|
export function alterHsl(color, type, value) {
|
|
355
358
|
return {
|