@tsparticles/effect-trail
Version:
tsParticles trail effect
2 lines (1 loc) • 5.75 kB
JavaScript
!function(t){t.__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.bundles=t.__tsParticlesInternals.bundles||{},t.__tsParticlesInternals.effects=t.__tsParticlesInternals.effects||{},t.__tsParticlesInternals.engine=t.__tsParticlesInternals.engine||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.palettes=t.__tsParticlesInternals.palettes||{},t.__tsParticlesInternals.paths=t.__tsParticlesInternals.paths||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins.emittersShapes=t.__tsParticlesInternals.plugins.emittersShapes||{},t.__tsParticlesInternals.presets=t.__tsParticlesInternals.presets||{},t.__tsParticlesInternals.shapes=t.__tsParticlesInternals.shapes||{},t.__tsParticlesInternals.updaters=t.__tsParticlesInternals.updaters||{},t.__tsParticlesInternals.utils=t.__tsParticlesInternals.utils||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas.utils=t.__tsParticlesInternals.canvas.utils||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path.utils=t.__tsParticlesInternals.path.utils||{};var s="undefined"!=typeof Proxy?function(t){return new Proxy(t,{get:function(t,s){return s in t||(t[s]={}),t[s]}})}:function(t){return t};t.__tsParticlesInternals.bundles=s(t.__tsParticlesInternals.bundles),t.__tsParticlesInternals.effects=s(t.__tsParticlesInternals.effects),t.__tsParticlesInternals.interactions=s(t.__tsParticlesInternals.interactions),t.__tsParticlesInternals.palettes=s(t.__tsParticlesInternals.palettes),t.__tsParticlesInternals.paths=s(t.__tsParticlesInternals.paths),t.__tsParticlesInternals.plugins=s(t.__tsParticlesInternals.plugins),t.__tsParticlesInternals.plugins.emittersShapes=s(t.__tsParticlesInternals.plugins.emittersShapes),t.__tsParticlesInternals.presets=s(t.__tsParticlesInternals.presets),t.__tsParticlesInternals.shapes=s(t.__tsParticlesInternals.shapes),t.__tsParticlesInternals.updaters=s(t.__tsParticlesInternals.updaters),t.__tsParticlesInternals.utils=s(t.__tsParticlesInternals.utils),t.__tsParticlesInternals.canvas=s(t.__tsParticlesInternals.canvas),t.__tsParticlesInternals.path=s(t.__tsParticlesInternals.path),t.tsparticlesInternalExports=t.tsparticlesInternalExports||{}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this),function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("@tsparticles/engine")):"function"==typeof define&&define.amd?define(["exports","@tsparticles/engine"],s):s(((t="undefined"!=typeof globalThis?globalThis:t||self).__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.effects=t.__tsParticlesInternals.effects||{},t.__tsParticlesInternals.effects.trail=t.__tsParticlesInternals.effects.trail||{}),t.__tsParticlesInternals.engine)}(this,function(t,s){"use strict";const e={a:1,b:0,c:0,d:1};class a{#t;constructor(t){this.#t=t}drawAfter(t){const{context:a,drawPosition:n,drawRadius:r,drawScale:i,particle:l,transformData:c}=t,_=this.#t,o=r*s.double,p=_.retina.pixelRatio,h=l.trail;if(!h||!l.trailLength)return;const P=n,I=l.trailLength*i+r;if(h.push({break:l.justWarped,color:a.fillStyle||a.strokeStyle,position:{x:P.x,y:P.y},transformData:c}),h.length<3)return;const f=Math.floor(I);h.length>f&&h.splice(0,h.length-f);const d=Math.min(h.length,I);a.save(),a.lineCap="butt",a.lineJoin="round";for(let t=d-2;t>0;t--){const n=h[t+1],r=h[t],c=h[t-1];if(!n||!r||!c)continue;const _=n.position,P=r.position,I=c.position,f=l.trailTransform?r.transformData??e:e;if(r.break||n.break||c.break)continue;a.setTransform(f.a,f.b,f.c,f.d,P.x,P.y);const u=(_.x+P.x)*s.half-P.x,g=(_.y+P.y)*s.half-P.y,x=(P.x+I.x)*s.half-P.x,y=(P.y+I.y)*s.half-P.y;a.beginPath(),a.moveTo(u,g),a.quadraticCurveTo(s.originPoint.x,s.originPoint.y,x,y);const b=Math.max(t/d*o,p,(l.trailMinWidth??-1)*i),m=a.globalAlpha;a.globalAlpha=l.trailFade?t/d:s.defaultAlpha,a.lineWidth=l.trailMaxWidth?Math.min(b,l.trailMaxWidth*i):b,a.strokeStyle=r.color,a.stroke(),a.globalAlpha=m}a.restore()}isInsideCanvas(t){const{canvasSize:e,direction:a,outMode:n,particle:r,radius:i}=t,l=r.position,c=r.trail;let _=l.x-i,o=l.x+i,p=l.y-i,h=l.y+i;if(c?.length){const t=Math.max(i,r.trailMaxWidth??0,r.trailMinWidth??0);for(const s of c)_=Math.min(_,s.position.x-t),o=Math.max(o,s.position.x+t),p=Math.min(p,s.position.y-t),h=Math.max(h,s.position.y+t)}const P=n===s.OutMode.destroy;return a===s.OutModeDirection.bottom?p<=e.height:a===s.OutModeDirection.left?o>=0:a===s.OutModeDirection.right?_<=e.width:a===s.OutModeDirection.top?h>=0:P?o>=0&&h>=0&&_<=e.width&&p<=e.height:l.x+i>=0&&l.y+i>=0&&l.x-i<=e.width&&l.y-i<=e.height}particleInit(t,e){e.trail=[];const a=e.effectData;e.trailFade=a?.fade??!0,e.trailLength=s.getRangeValue(a?.length??10)*t.retina.pixelRatio,e.trailMaxWidth=a?.maxWidth?s.getRangeValue(a.maxWidth)*t.retina.pixelRatio:void 0,e.trailMinWidth=a?.minWidth?s.getRangeValue(a.minWidth)*t.retina.pixelRatio:void 0,e.trailTransform=a?.transform??!1}}async function n(t){t.checkVersion("4.3.2"),await t.pluginManager.register(t=>{t.pluginManager.addEffect("trail",t=>Promise.resolve(new a(t)))})}const r=globalThis;r.__tsParticlesInternals=r.__tsParticlesInternals??{},r.loadTrailEffect=n,t.loadTrailEffect=n}),Object.assign(globalThis.window||globalThis,{loadTrailEffect:(globalThis.__tsParticlesInternals.effects.trail||{}).loadTrailEffect}),delete(globalThis.window||globalThis).tsparticlesInternalExports;