UNPKG

@tsparticles/updater-orbit

Version:

tsParticles particles orbit updater

2 lines 3.38 kB
/*! For license information please see tsparticles.updater.orbit.min.js.LICENSE.txt */ !function(t,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],o);else{var e="object"==typeof exports?o(require("@tsparticles/engine")):o(t.window);for(var i in e)("object"==typeof exports?exports:t)[i]=e[i]}}(this,(t=>(()=>{var o={303:o=>{o.exports=t}},e={};function i(t){var a=e[t];if(void 0!==a)return a.exports;var r=e[t]={exports:{}};return o[t](r,r.exports,i),r.exports}i.d=(t,o)=>{for(var e in o)i.o(o,e)&&!i.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:o[e]})},i.o=(t,o)=>Object.prototype.hasOwnProperty.call(t,o),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var a={};i.r(a),i.d(a,{loadOrbitUpdater:()=>p});var r,n=i(303);class s extends n.ValueWithRandom{constructor(){super(),this.value=45}load(t){(0,n.isNull)(t)||super.load(t)}}class l{constructor(){this.animation=new n.AnimationOptions,this.enable=!1,this.opacity=1,this.rotation=new s,this.width=1}load(t){(0,n.isNull)(t)||(this.animation.load(t.animation),this.rotation.load(t.rotation),void 0!==t.enable&&(this.enable=t.enable),void 0!==t.opacity&&(this.opacity=(0,n.setRangeValue)(t.opacity)),void 0!==t.width&&(this.width=(0,n.setRangeValue)(t.width)),void 0!==t.radius&&(this.radius=(0,n.setRangeValue)(t.radius)),void 0!==t.color&&(this.color=n.OptionsColor.create(this.color,t.color)))}}!function(t){t.front="front",t.back="back"}(r||(r={}));const d=2*Math.PI,c=.5*Math.PI,b=Math.PI+c;class u{constructor(t,o){this._engine=o,this._container=t}afterDraw(t){const o=t.options.orbit;o?.enable&&this.drawOrbit(t,r.front)}beforeDraw(t){const o=t.options.orbit;o?.enable&&this.drawOrbit(t,r.back)}drawOrbit(t,o){const e=this._container;let i,a;switch(o){case r.back:i=c,a=b;break;case r.front:i=b,a=c;break;default:i=0,a=d}e.canvas.draw((o=>{!function(t,o,e,i,a,r,s,l,d){if(r<=0)return;const c=o.getPosition();e&&(t.strokeStyle=(0,n.getStyleFromHsl)(e,a)),t.lineWidth=r;const b=(0,n.degToRad)(s);t.beginPath(),t.ellipse(c.x,c.y,.5*i,2*i,b,l,d),t.stroke()}(o,t,t.orbitColor??t.getFillColor(),t.retina.orbitRadius??e.retina.orbitRadius??t.getRadius(),t.orbitOpacity??1,t.orbitWidth??1,(t.orbitRotation??0)*e.retina.pixelRatio,i,a)}))}init(t){const o=this._container,e=t.options.orbit;e?.enable&&(t.orbitRotation=(0,n.getRangeValue)(e.rotation.value),t.orbitColor=(0,n.rangeColorToHsl)(this._engine,e.color),t.retina.orbitRadius=void 0!==e.radius?(0,n.getRangeValue)(e.radius)*o.retina.pixelRatio:void 0,o.retina.orbitRadius=t.retina.orbitRadius,t.orbitAnimationSpeed=e.animation.enable?(0,n.getRangeValue)(e.animation.speed):0,t.orbitWidth=(0,n.getRangeValue)(e.width),t.orbitOpacity=(0,n.getRangeValue)(e.opacity))}isEnabled(t){const o=t.options.orbit?.animation;return!t.destroyed&&!t.spawning&&!!o?.enable}loadOptions(t,...o){t.orbit||(t.orbit=new l);for(const e of o)t.orbit.load(e?.orbit)}update(t,o){this.isEnabled(t)&&(void 0===t.orbitRotation&&(t.orbitRotation=0),t.orbitRotation+=(t.orbitAnimationSpeed??0/d)*o.factor)}}async function p(t,o=!0){t.checkVersion("3.9.1"),await t.addParticleUpdater("orbit",(o=>Promise.resolve(new u(o,t))),o)}return a})()));