@tsparticles/plugin-sounds 3.0.0-alpha.0 → 3.0.0-beta.0

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 (37) hide show
  1. package/README.md +15 -11
  2. package/browser/Options/Classes/SoundsAudio.js +2 -1
  3. package/browser/Options/Classes/SoundsEvent.js +4 -3
  4. package/browser/Options/Classes/SoundsVolume.js +2 -1
  5. package/browser/SoundsInstance.js +300 -279
  6. package/browser/index.js +6 -8
  7. package/browser/utils.js +0 -1
  8. package/cjs/Options/Classes/SoundsAudio.js +2 -1
  9. package/cjs/Options/Classes/SoundsEvent.js +4 -3
  10. package/cjs/Options/Classes/SoundsVolume.js +2 -1
  11. package/cjs/SoundsInstance.js +283 -281
  12. package/cjs/index.js +6 -19
  13. package/cjs/utils.js +0 -1
  14. package/esm/Options/Classes/SoundsAudio.js +2 -1
  15. package/esm/Options/Classes/SoundsEvent.js +4 -3
  16. package/esm/Options/Classes/SoundsVolume.js +2 -1
  17. package/esm/SoundsInstance.js +300 -279
  18. package/esm/index.js +6 -8
  19. package/esm/utils.js +0 -1
  20. package/package.json +6 -5
  21. package/report.html +4 -4
  22. package/tsparticles.plugin.sounds.js +343 -305
  23. package/tsparticles.plugin.sounds.min.js +1 -1
  24. package/tsparticles.plugin.sounds.min.js.LICENSE.txt +1 -8
  25. package/types/Options/Classes/SoundsAudio.d.ts +1 -1
  26. package/types/Options/Classes/SoundsEvent.d.ts +1 -1
  27. package/types/Options/Classes/SoundsVolume.d.ts +1 -1
  28. package/types/SoundsInstance.d.ts +15 -15
  29. package/types/enums.d.ts +4 -0
  30. package/types/index.d.ts +1 -1
  31. package/types/types.d.ts +16 -0
  32. package/umd/Options/Classes/SoundsAudio.js +3 -2
  33. package/umd/Options/Classes/SoundsEvent.js +5 -4
  34. package/umd/Options/Classes/SoundsVolume.js +3 -2
  35. package/umd/SoundsInstance.js +301 -280
  36. package/umd/index.js +6 -8
  37. package/umd/utils.js +0 -1
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see tsparticles.plugin.sounds.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var i="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in i)("object"==typeof exports?exports:e)[o]=i[o]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},i={};function o(e){var n=i[e];if(void 0!==n)return n.exports;var s=i[e]={exports:{}};return t[e](s,s.exports,o),s.exports}o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadSoundsPlugin:()=>f});class e{constructor(){this.loop=!1,this.source=""}load(e){void 0!==e&&("object"==typeof e?(void 0!==e.loop&&(this.loop=e.loop),void 0!==e.source&&(this.source=e.source)):this.source=e)}}class t{constructor(){this.duration=500,this.value=[]}load(e){e&&(void 0!==e.duration&&(this.duration=e.duration),void 0!==e.value&&(this.value=e.value))}}class i{constructor(){this.loop=!1,this.melodies=[],this.notes=[]}load(e){void 0!==e&&(void 0!==e.loop&&(this.loop=e.loop),void 0!==e.melodies&&(this.melodies=e.melodies.map((e=>{const t=new i;return t.load(e),t}))),void 0!==e.notes&&(this.notes=e.notes.map((e=>{const i=new t;return i.load(e),i}))))}}class s{constructor(){this.event=[],this.notes=[]}load(o){o&&(void 0!==o.event&&(this.event=o.event),void 0!==o.audio&&(o.audio instanceof Array?this.audio=o.audio.map((t=>{const i=new e;return i.load(t),i})):(this.audio=new e,this.audio.load(o.audio))),void 0!==o.notes&&(this.notes=o.notes.map((e=>{const i=new t;return i.load(e),i}))),void 0!==o.melodies&&(this.melodies=o.melodies.map((e=>{const t=new i;return t.load(e),t}))),void 0!==o.filter&&("string"==typeof o.filter?"function"==typeof window[o.filter]&&(this.filter=window[o.filter]):this.filter=o.filter))}}class a{constructor(){this.width=24,this.height=24}load(e){e&&(void 0!==e.path&&(this.path=e.path),void 0!==e.svg&&(this.svg=e.svg),void 0!==e.width&&(this.width=e.width),void 0!==e.height&&(this.height=e.height))}}class l{constructor(){this.mute=new a,this.unmute=new a,this.volumeDown=new a,this.volumeUp=new a,this.mute.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M19.707,5.293c-0.391-0.391-1.023-0.391-1.414,0l-1.551,1.551c-0.345-0.688-0.987-1.02-1.604-1.02c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C10.357,8.561,8.904,9,8,9c-1.654,0-3,1.346-3,3v2c0,1.237,0.754,2.302,1.826,2.76l-1.533,1.533c-0.391,0.391-0.391,1.023,0,1.414C5.488,19.902,5.744,20,6,20s0.512-0.098,0.707-0.293l2.527-2.527c0.697,0.174,1.416,0.455,1.875,0.762l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C16.035,20.176,17,19.495,17,18V9.414l2.707-2.707C20.098,6.316,20.098,5.684,19.707,5.293z M14.891,7.941c0.038-0.025,0.073-0.046,0.104-0.062C14.998,7.914,15,7.954,15,8v1.293l-2,2V9.202L14.891,7.941z M7,12c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v2.439l-2.83,2.83C8.757,15.046,8.356,15,8,15c-0.552,0-1-0.448-1-1V12z M10.301,15.406L12,13.707v2.439C11.519,15.859,10.925,15.604,10.301,15.406z M14.994,18.12c-0.03-0.016-0.065-0.036-0.104-0.062L13,16.798v-4.091l2-2V18C15,18.046,14.998,18.086,14.994,18.12z"/>\n </g>\n</svg>',this.unmute.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M17.138,5.824c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C12.357,8.561,10.904,9,10,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C18.035,20.176,19,19.495,19,18V8C19,6.505,18.035,5.824,17.138,5.824z M14,16.146C12.907,15.495,11.211,15,10,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146V16.146z M17,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L15,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C16.998,7.914,17,7.954,17,8V18z"/>\n </g>\n</svg>',this.volumeDown.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M15.138,5.824c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C10.357,8.561,8.904,9,8,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C16.035,20.176,17,19.495,17,18V8C17,6.505,16.035,5.824,15.138,5.824z M8,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v6.293C10.907,15.495,9.211,15,8,15z M15,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L13,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C14.998,7.914,15,7.954,15,8V18z"/>\n <path fill="#fff" d="M18.292,10.294c-0.39,0.391-0.39,1.023,0.002,1.414c0.345,0.345,0.535,0.803,0.535,1.291c0,0.489-0.19,0.948-0.536,1.294c-0.391,0.39-0.391,1.023,0,1.414C18.488,15.902,18.744,16,19,16s0.512-0.098,0.707-0.293c0.724-0.723,1.122-1.685,1.122-2.708s-0.398-1.984-1.123-2.707C19.317,9.903,18.683,9.901,18.292,10.294z"/>\n </g>\n</svg>',this.volumeUp.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M16.706,10.292c-0.389-0.389-1.023-0.391-1.414,0.002c-0.39,0.391-0.39,1.023,0.002,1.414c0.345,0.345,0.535,0.803,0.535,1.291c0,0.489-0.19,0.948-0.536,1.294c-0.391,0.39-0.391,1.023,0,1.414C15.488,15.902,15.744,16,16,16s0.512-0.098,0.707-0.293c0.724-0.723,1.122-1.685,1.122-2.708S17.431,11.015,16.706,10.292z"/>\n <path fill="#fff" d="M18.706,8.292c-0.391-0.389-1.023-0.39-1.414,0.002c-0.39,0.391-0.39,1.024,0.002,1.414c0.879,0.877,1.363,2.044,1.364,3.287c0.001,1.246-0.484,2.417-1.365,3.298c-0.391,0.391-0.391,1.023,0,1.414C17.488,17.902,17.744,18,18,18s0.512-0.098,0.707-0.293c1.259-1.259,1.952-2.933,1.951-4.713C20.657,11.217,19.964,9.547,18.706,8.292z"/>\n <path fill="#fff" d="M20.706,6.292c-0.391-0.389-1.023-0.39-1.414,0.002c-0.39,0.391-0.39,1.024,0.002,1.414c1.412,1.409,2.191,3.285,2.192,5.284c0.002,2.002-0.777,3.885-2.193,5.301c-0.391,0.391-0.391,1.023,0,1.414C19.488,19.902,19.744,20,20,20s0.512-0.098,0.707-0.293c1.794-1.794,2.781-4.18,2.779-6.717C23.485,10.457,22.497,8.078,20.706,6.292z"/>\n <path fill="#fff" d="M12.138,5.824c-0.449,0-0.905,0.152-1.356,0.453L8.109,8.059C7.357,8.561,5.904,9,5,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C13.035,20.176,14,19.495,14,18V8C14,6.505,13.035,5.824,12.138,5.824z M5,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v6.293C7.907,15.495,6.211,15,5,15z M12,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L10,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C11.998,7.914,12,7.954,12,8V18z"/>\n </g>\n</svg>'}load(e){e&&(this.mute.load(e.mute),this.unmute.load(e.unmute),this.volumeDown.load(e.volumeDown),this.volumeUp.load(e.volumeUp))}}class u{constructor(){this.value=100,this.max=100,this.min=0,this.step=10}load(e){void 0!==e&&("object"==typeof e?(void 0!==e.max&&(this.max=e.max),void 0!==e.min&&(this.min=e.min),void 0!==e.step&&(this.step=e.step),void 0!==e.value&&(this.value=e.value)):this.value=e)}}class c{constructor(){this.enable=!1,this.events=[],this.icons=new l,this.volume=new u}load(e){e&&(void 0!==e.enable&&(this.enable=e.enable),void 0!==e.events&&(this.events=e.events.map((e=>{const t=new s;return t.load(e),t}))),this.icons.load(e.icons),void 0!==e.volume&&this.volume.load(e.volume))}}var r=o(533);const d=new Map;function h(e){const t=/(([A-G]b?)(\d))|pause/i.exec(e);if(!t||!t.length)return;console.log(t);const i=t[2]||t[0],o=d.get(i);return o?o[parseInt(t[3]||"0")]:void 0}function v(e,t,i,o,n,s,a){e.style.userSelect="none",e.style.webkitUserSelect="none",e.style.position="absolute",e.style.top=`${t+a}px`,e.style.left=i-a-s+"px",e.style.display=o,e.style.zIndex=`${n+1}`}d.set("C",[16.35,32.7,65.41,130.81,261.63,523.25,1046.5,2093,4186.01]),d.set("Db",[17.32,34.65,69.3,138.59,277.18,554.37,1108.73,2217.46,4434.92]),d.set("D",[18.35,36.71,73.42,146.83,293.66,587.33,1174.66,2349.32,4698.63]),d.set("Eb",[19.45,38.89,77.78,155.56,311.13,622.25,1244.51,2489.02,4978.03]),d.set("E",[20.6,41.2,82.41,164.81,329.63,659.25,1318.51,2637.02,5274.04]),d.set("F",[21.83,43.65,87.31,174.61,349.23,698.46,1396.91,2793.83,5587.65]),d.set("Gb",[23.12,46.25,92.5,185,369.99,739.99,1479.98,2959.96,5919.91]),d.set("G",[24.5,49,98,196,392,783.99,1567.98,3135.96,6271.93]),d.set("Ab",[25.96,51.91,103.83,207.65,415.3,830.61,1661.22,3322.44,6644.88]),d.set("A",[27.5,55,110,220,440,880,1760,3520,7040]),d.set("Bb",[29.14,58.27,116.54,233.08,466.16,932.33,1864.66,3729.31,7458.62]),d.set("B",[30.87,61.74,123.47,246.94,493.88,987.77,1975.53,3951.07,7902.13]),d.set("pause",[0]);class m{constructor(e,t){this._container=e,this._engine=t,this._volume=0,this._audioSources=[],this._audioMap=new Map}async init(){const e=this._container,t=e.actualOptions.sounds;if(!(null==t?void 0:t.enable))return;this._volume=t.volume.value;const i=t.events;this._audioMap=new Map;for(const t of i)t.audio&&(0,r.executeOnSingleOrMultiple)(t.audio,(async t=>{const i=await fetch(t.source);if(!i.ok)return;const o=await i.arrayBuffer();e.audioContext=new AudioContext;const n=await e.audioContext.decodeAudioData(o);this._audioMap.set(t.source,n)}))}async start(){var e,t,i,o;const n=this._container,s=n.actualOptions,a=s.sounds;if(!(null==a?void 0:a.enable)||!n.canvas.element)return;n.muted=!0,this._muteImg=document.createElement("img"),this._unmuteImg=document.createElement("img"),this._volumeDownImg=document.createElement("img"),this._volumeUpImg=document.createElement("img");const l=this._muteImg,u=this._unmuteImg,c=this._volumeDownImg,r=this._volumeUpImg,d=n.canvas.element.offsetTop,h=n.canvas.element.offsetLeft+n.canvas.element.offsetWidth,m=a.icons,p=m.mute,f=m.unmute,g=m.volumeDown,_=m.volumeUp,w=10;v(l,d+w,h-30-p.width-g.width-_.width,"block",s.fullScreen.zIndex+1,p.width,w),v(u,d+w,h-30-f.width-g.width-_.width,"none",s.fullScreen.zIndex+1,f.width,w),v(c,d+w,h-20-g.width-_.width,"block",s.fullScreen.zIndex+1,g.width,w),v(r,d+w,h-w-_.width,"block",s.fullScreen.zIndex+1,_.width,w),l.src=null!==(e=p.path)&&void 0!==e?e:p.svg?`data:image/svg+xml;base64,${btoa(p.svg)}`:"",u.src=null!==(t=f.path)&&void 0!==t?t:f.svg?`data:image/svg+xml;base64,${btoa(f.svg)}`:"",c.src=null!==(i=g.path)&&void 0!==i?i:g.svg?`data:image/svg+xml;base64,${btoa(g.svg)}`:"",r.src=null!==(o=_.path)&&void 0!==o?o:_.svg?`data:image/svg+xml;base64,${btoa(_.svg)}`:"";const x=n.canvas.element.parentNode||document.body;x.append(l),x.append(u),x.append(c),x.append(r);const y=()=>{n.muted=!n.muted,this._updateMuteIcons(),this._updateMuteStatus()};l.addEventListener("click",y),u.addEventListener("click",y),c.addEventListener("click",(()=>{n.muted&&(this._volume=0),this._volume-=a.volume.step,this._updateVolume()})),r.addEventListener("click",(()=>{n.muted&&(this._volume=0),this._volume+=a.volume.step,this._updateVolume()}))}stop(){this._container.muted=!0,this._mute(),this._muteImg&&this._muteImg.remove(),this._unmuteImg&&this._unmuteImg.remove(),this._volumeDownImg&&this._volumeDownImg.remove(),this._volumeUpImg&&this._volumeUpImg.remove()}_addBuffer(e){const t=e.createBufferSource();return this._audioSources.push(t),t}_addOscillator(e){const t=e.createOscillator();return this._audioSources.push(t),t}_initEvents(){const e=this._container,t=e.actualOptions.sounds;if((null==t?void 0:t.enable)&&e.canvas.element)for(const e of t.events){const t=async i=>{if(this._container===i.container)if(!this._container||this._container.muted||this._container.destroyed)(0,r.executeOnSingleOrMultiple)(e.event,(e=>{this._engine.removeEventListener(e,t)}));else if(!e.filter||e.filter(i))if(e.audio)this._playBuffer((0,r.itemFromSingleOrMultiple)(e.audio));else if(e.melodies){const t=(0,r.itemFromArray)(e.melodies);t.melodies.length?await Promise.allSettled(t.melodies.map((e=>this._playNote(e.notes,0,t.loop)))):await this._playNote(t.notes,0,t.loop)}else if(e.notes){const t=(0,r.itemFromArray)(e.notes);await this._playNote([t],0,!1)}};(0,r.executeOnSingleOrMultiple)(e.event,(e=>{this._engine.addEventListener(e,t)}))}}_mute(){const e=this._container;if(e.audioContext){for(const e of this._audioSources)this._removeAudioSource(e);this._gain&&this._gain.disconnect(),e.audioContext.close(),e.audioContext=void 0,this._engine.dispatchEvent("soundsMuted",{container:this._container})}}_playBuffer(e){var t;const i=this._audioMap.get(e.source);if(!i)return;const o=this._container.audioContext;if(!o)return;const n=this._addBuffer(o);n.loop=e.loop,n.buffer=i,n.connect(null!==(t=this._gain)&&void 0!==t?t:o.destination),n.start()}async _playFrequency(e,t){if(!this._container.audioContext||!this._gain)return;const i=this._addOscillator(this._container.audioContext);return i.connect(this._gain),i.type="sine",i.frequency.value=e,i.start(),new Promise((e=>{setTimeout((()=>{this._removeAudioSource(i),e()}),t)}))}_playMuteSound(){const e=this._container;if(!e.audioContext)return;const t=e.audioContext.createGain();t.connect(e.audioContext.destination),t.gain.value=0;const i=e.audioContext.createOscillator();i.connect(t),i.type="sine",i.frequency.value=1,i.start(),setTimeout((()=>{i.stop(),i.disconnect(),t.disconnect()}))}async _playNote(e,t,i){if(this._container.muted)return;const o=e[t];if(!o)return;const n=o.value,s=(0,r.executeOnSingleOrMultiple)(n,(async(i,o)=>this._playNoteValue(e,t,o)));await(s instanceof Array?Promise.allSettled(s):s);let a=t+1;i&&a>=e.length&&(a%=e.length),this._container.muted||await this._playNote(e,a,i)}async _playNoteValue(e,t,i){const o=e[t];if(!o)return;const n=(0,r.itemFromSingleOrMultiple)(o.value,i,!0);try{const e=h(n);if("number"!=typeof e)return;await this._playFrequency(e,o.duration)}catch(e){console.error(e)}}_removeAudioSource(e){e.stop(),e.disconnect(),this._audioSources.splice(this._audioSources.indexOf(e),1)}_unmute(){const e=this._container,t=e.actualOptions.sounds;if(!t)return;e.audioContext||(e.audioContext=new AudioContext),this._audioSources||(this._audioSources=[]);const i=e.audioContext.createGain();i.connect(e.audioContext.destination),i.gain.value=t.volume.value/100,this._gain=i,this._initEvents(),this._engine.dispatchEvent("soundsUnmuted",{container:this._container})}_updateMuteIcons(){const e=this._container,t=this._muteImg,i=this._unmuteImg;t&&(t.style.display=e.muted?"block":"none"),i&&(i.style.display=e.muted?"none":"block")}_updateMuteStatus(){this._container.muted?this._mute():(this._unmute(),this._playMuteSound())}_updateVolume(){var e;const t=this._container,i=t.actualOptions.sounds;if(!(null==i?void 0:i.enable))return;(0,r.clamp)(this._volume,i.volume.min,i.volume.max);let o=!1;this._volume<=0&&!t.muted?(this._volume=0,t.muted=!0,o=!0):this._volume>0&&t.muted&&(t.muted=!1,o=!0),o&&(this._updateMuteIcons(),this._updateMuteStatus()),(null===(e=this._gain)||void 0===e?void 0:e.gain)&&(this._gain.gain.value=this._volume/100)}}class p{constructor(e){this.id="sounds",this._engine=e}getPlugin(e){return new m(e,this._engine)}loadOptions(e,t){if(!this.needsPlugin(t))return;let i=e.sounds;void 0===(null==i?void 0:i.load)&&(e.sounds=i=new c),i.load(null==t?void 0:t.sounds)}needsPlugin(e){var t,i;return null!==(i=null===(t=null==e?void 0:e.sounds)||void 0===t?void 0:t.enable)&&void 0!==i&&i}}async function f(e){const t=new p(e);await e.addPlugin(t)}})(),n})()));
2
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function s(t){var o=i[t];if(void 0!==o)return o.exports;var n=i[t]={exports:{}};return e[t](n,n.exports,s),n.exports}s.d=(t,e)=>{for(var i in e)s.o(e,i)&&!s.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},s.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),s.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return(()=>{s.r(o),s.d(o,{loadSoundsPlugin:()=>g});var t=s(533);class e{constructor(){this.loop=!1,this.source=""}load(e){void 0!==e&&((0,t.isObject)(e)?(void 0!==e.loop&&(this.loop=e.loop),void 0!==e.source&&(this.source=e.source)):this.source=e)}}class i{constructor(){this.duration=500,this.value=[]}load(t){t&&(void 0!==t.duration&&(this.duration=t.duration),void 0!==t.value&&(this.value=t.value))}}class n{constructor(){this.loop=!1,this.melodies=[],this.notes=[]}load(t){void 0!==t&&(void 0!==t.loop&&(this.loop=t.loop),void 0!==t.melodies&&(this.melodies=t.melodies.map((t=>{const e=new n;return e.load(t),e}))),void 0!==t.notes&&(this.notes=t.notes.map((t=>{const e=new i;return e.load(t),e}))))}}class a{constructor(){this.event=[],this.notes=[]}load(s){s&&(void 0!==s.event&&(this.event=s.event),void 0!==s.audio&&((0,t.isArray)(s.audio)?this.audio=s.audio.map((t=>{const i=new e;return i.load(t),i})):(this.audio=new e,this.audio.load(s.audio))),void 0!==s.notes&&(this.notes=s.notes.map((t=>{const e=new i;return e.load(t),e}))),void 0!==s.melodies&&(this.melodies=s.melodies.map((t=>{const e=new n;return e.load(t),e}))),void 0!==s.filter&&((0,t.isString)(s.filter)?(0,t.isFunction)(window[s.filter])&&(this.filter=window[s.filter]):this.filter=s.filter))}}class l{constructor(){this.width=24,this.height=24}load(t){t&&(void 0!==t.path&&(this.path=t.path),void 0!==t.svg&&(this.svg=t.svg),void 0!==t.width&&(this.width=t.width),void 0!==t.height&&(this.height=t.height))}}class c{constructor(){this.mute=new l,this.unmute=new l,this.volumeDown=new l,this.volumeUp=new l,this.mute.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M19.707,5.293c-0.391-0.391-1.023-0.391-1.414,0l-1.551,1.551c-0.345-0.688-0.987-1.02-1.604-1.02c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C10.357,8.561,8.904,9,8,9c-1.654,0-3,1.346-3,3v2c0,1.237,0.754,2.302,1.826,2.76l-1.533,1.533c-0.391,0.391-0.391,1.023,0,1.414C5.488,19.902,5.744,20,6,20s0.512-0.098,0.707-0.293l2.527-2.527c0.697,0.174,1.416,0.455,1.875,0.762l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C16.035,20.176,17,19.495,17,18V9.414l2.707-2.707C20.098,6.316,20.098,5.684,19.707,5.293z M14.891,7.941c0.038-0.025,0.073-0.046,0.104-0.062C14.998,7.914,15,7.954,15,8v1.293l-2,2V9.202L14.891,7.941z M7,12c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v2.439l-2.83,2.83C8.757,15.046,8.356,15,8,15c-0.552,0-1-0.448-1-1V12z M10.301,15.406L12,13.707v2.439C11.519,15.859,10.925,15.604,10.301,15.406z M14.994,18.12c-0.03-0.016-0.065-0.036-0.104-0.062L13,16.798v-4.091l2-2V18C15,18.046,14.998,18.086,14.994,18.12z"/>\n </g>\n</svg>',this.unmute.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M17.138,5.824c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C12.357,8.561,10.904,9,10,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C18.035,20.176,19,19.495,19,18V8C19,6.505,18.035,5.824,17.138,5.824z M14,16.146C12.907,15.495,11.211,15,10,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146V16.146z M17,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L15,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C16.998,7.914,17,7.954,17,8V18z"/>\n </g>\n</svg>',this.volumeDown.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M15.138,5.824c-0.449,0-0.905,0.152-1.356,0.453l-2.672,1.781C10.357,8.561,8.904,9,8,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C16.035,20.176,17,19.495,17,18V8C17,6.505,16.035,5.824,15.138,5.824z M8,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v6.293C10.907,15.495,9.211,15,8,15z M15,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L13,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C14.998,7.914,15,7.954,15,8V18z"/>\n <path fill="#fff" d="M18.292,10.294c-0.39,0.391-0.39,1.023,0.002,1.414c0.345,0.345,0.535,0.803,0.535,1.291c0,0.489-0.19,0.948-0.536,1.294c-0.391,0.39-0.391,1.023,0,1.414C18.488,15.902,18.744,16,19,16s0.512-0.098,0.707-0.293c0.724-0.723,1.122-1.685,1.122-2.708s-0.398-1.984-1.123-2.707C19.317,9.903,18.683,9.901,18.292,10.294z"/>\n </g>\n</svg>',this.volumeUp.svg='<?xml version="1.0"?>\n<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"\n xml:space="preserve" xmlns="http://www.w3.org/2000/svg"\n xmlns:xlink="http://www.w3.org/1999/xlink">\n <g id="Layer_1">\n <path fill="#fff" d="M16.706,10.292c-0.389-0.389-1.023-0.391-1.414,0.002c-0.39,0.391-0.39,1.023,0.002,1.414c0.345,0.345,0.535,0.803,0.535,1.291c0,0.489-0.19,0.948-0.536,1.294c-0.391,0.39-0.391,1.023,0,1.414C15.488,15.902,15.744,16,16,16s0.512-0.098,0.707-0.293c0.724-0.723,1.122-1.685,1.122-2.708S17.431,11.015,16.706,10.292z"/>\n <path fill="#fff" d="M18.706,8.292c-0.391-0.389-1.023-0.39-1.414,0.002c-0.39,0.391-0.39,1.024,0.002,1.414c0.879,0.877,1.363,2.044,1.364,3.287c0.001,1.246-0.484,2.417-1.365,3.298c-0.391,0.391-0.391,1.023,0,1.414C17.488,17.902,17.744,18,18,18s0.512-0.098,0.707-0.293c1.259-1.259,1.952-2.933,1.951-4.713C20.657,11.217,19.964,9.547,18.706,8.292z"/>\n <path fill="#fff" d="M20.706,6.292c-0.391-0.389-1.023-0.39-1.414,0.002c-0.39,0.391-0.39,1.024,0.002,1.414c1.412,1.409,2.191,3.285,2.192,5.284c0.002,2.002-0.777,3.885-2.193,5.301c-0.391,0.391-0.391,1.023,0,1.414C19.488,19.902,19.744,20,20,20s0.512-0.098,0.707-0.293c1.794-1.794,2.781-4.18,2.779-6.717C23.485,10.457,22.497,8.078,20.706,6.292z"/>\n <path fill="#fff" d="M12.138,5.824c-0.449,0-0.905,0.152-1.356,0.453L8.109,8.059C7.357,8.561,5.904,9,5,9c-1.654,0-3,1.346-3,3v2c0,1.654,1.346,3,3,3c0.904,0,2.357,0.439,3.109,0.941l2.672,1.781c0.451,0.301,0.907,0.453,1.356,0.453C13.035,20.176,14,19.495,14,18V8C14,6.505,13.035,5.824,12.138,5.824z M5,15c-0.552,0-1-0.448-1-1v-2c0-0.552,0.448-1,1-1c1.211,0,2.907-0.495,4-1.146v6.293C7.907,15.495,6.211,15,5,15z M12,18c0,0.046-0.002,0.086-0.006,0.12c-0.03-0.016-0.065-0.036-0.104-0.062L10,16.798V9.202l1.891-1.261c0.038-0.025,0.073-0.046,0.104-0.062C11.998,7.914,12,7.954,12,8V18z"/>\n </g>\n</svg>'}load(t){t&&(this.mute.load(t.mute),this.unmute.load(t.unmute),this.volumeDown.load(t.volumeDown),this.volumeUp.load(t.volumeUp))}}class u{constructor(){this.value=100,this.max=100,this.min=0,this.step=10}load(e){void 0!==e&&((0,t.isObject)(e)?(void 0!==e.max&&(this.max=e.max),void 0!==e.min&&(this.min=e.min),void 0!==e.step&&(this.step=e.step),void 0!==e.value&&(this.value=e.value)):this.value=e)}}class r{constructor(){this.enable=!1,this.events=[],this.icons=new c,this.volume=new u}load(t){t&&(void 0!==t.enable&&(this.enable=t.enable),void 0!==t.events&&(this.events=t.events.map((t=>{const e=new a;return e.load(t),e}))),this.icons.load(t.icons),void 0!==t.volume&&this.volume.load(t.volume))}}const d=new Map;function h(t){const e=/(([A-G]b?)(\d))|pause/i.exec(t);if(!e||!e.length)return;const i=e[2]||e[0],s=d.get(i);return s?s[parseInt(e[3]||"0")]:void 0}function p(t){const e=document.createElement("img"),{clickCb:i,container:s,display:o,iconOptions:n,margin:a,options:l,pos:c,rightOffsets:u}=t,{width:r,path:d,svg:h}=n;!function(t,e,i,s,o,n,a){t.style.userSelect="none",t.style.webkitUserSelect="none",t.style.position="absolute",t.style.top=`${e+a}px`,t.style.left=i-a-n+"px",t.style.display=s,t.style.zIndex=`${o+1}`}(e,c.top+a,c.right-(a*(u.length+1)+r+u.reduce(((t,e)=>t+e),0)),o,l.fullScreen.zIndex+1,r,a),e.src=d??(h?`data:image/svg+xml;base64,${btoa(h)}`:"");return(s.canvas.element?.parentNode||document.body).append(e),e.addEventListener("click",i),e}function m(t){t&&t.remove()}d.set("C",[16.35,32.7,65.41,130.81,261.63,523.25,1046.5,2093,4186.01]),d.set("Db",[17.32,34.65,69.3,138.59,277.18,554.37,1108.73,2217.46,4434.92]),d.set("D",[18.35,36.71,73.42,146.83,293.66,587.33,1174.66,2349.32,4698.63]),d.set("Eb",[19.45,38.89,77.78,155.56,311.13,622.25,1244.51,2489.02,4978.03]),d.set("E",[20.6,41.2,82.41,164.81,329.63,659.25,1318.51,2637.02,5274.04]),d.set("F",[21.83,43.65,87.31,174.61,349.23,698.46,1396.91,2793.83,5587.65]),d.set("Gb",[23.12,46.25,92.5,185,369.99,739.99,1479.98,2959.96,5919.91]),d.set("G",[24.5,49,98,196,392,783.99,1567.98,3135.96,6271.93]),d.set("Ab",[25.96,51.91,103.83,207.65,415.3,830.61,1661.22,3322.44,6644.88]),d.set("A",[27.5,55,110,220,440,880,1760,3520,7040]),d.set("Bb",[29.14,58.27,116.54,233.08,466.16,932.33,1864.66,3729.31,7458.62]),d.set("B",[30.87,61.74,123.47,246.94,493.88,987.77,1975.53,3951.07,7902.13]),d.set("pause",[0]);class v{constructor(e,i){this._addBuffer=t=>{const e=t.createBufferSource();return this._audioSources.push(e),e},this._addOscillator=t=>{const e=t.createOscillator();return this._audioSources.push(e),e},this._initEvents=()=>{const e=this._container,i=e.actualOptions.sounds;if(i?.enable&&e.canvas.element)for(const e of i.events){const i=async s=>{if(this._container===s.container)if(!this._container||this._container.muted||this._container.destroyed)(0,t.executeOnSingleOrMultiple)(e.event,(t=>{this._engine.removeEventListener(t,i)}));else if(!e.filter||e.filter(s))if(e.audio)this._playBuffer((0,t.itemFromSingleOrMultiple)(e.audio));else if(e.melodies){const i=(0,t.itemFromArray)(e.melodies);i.melodies.length?await Promise.allSettled(i.melodies.map((t=>this._playNote(t.notes,0,i.loop)))):await this._playNote(i.notes,0,i.loop)}else if(e.notes){const i=(0,t.itemFromArray)(e.notes);await this._playNote([i],0,!1)}};(0,t.executeOnSingleOrMultiple)(e.event,(t=>{this._engine.addEventListener(t,i)}))}},this._mute=()=>{const t=this._container;if(t.audioContext){for(const t of this._audioSources)this._removeAudioSource(t);this._gain&&this._gain.disconnect(),t.audioContext.close(),t.audioContext=void 0,this._engine.dispatchEvent("soundsMuted",{container:this._container})}},this._playBuffer=t=>{const e=this._audioMap.get(t.source);if(!e)return;const i=this._container.audioContext;if(!i)return;const s=this._addBuffer(i);s.loop=t.loop,s.buffer=e,s.connect(this._gain??i.destination),s.start()},this._playFrequency=async(t,e)=>{if(!this._container.audioContext||!this._gain)return;const i=this._addOscillator(this._container.audioContext);return i.connect(this._gain),i.type="sine",i.frequency.value=t,i.start(),new Promise((t=>{setTimeout((()=>{this._removeAudioSource(i),t()}),e)}))},this._playMuteSound=()=>{const t=this._container;if(!t.audioContext)return;const e=t.audioContext.createGain();e.connect(t.audioContext.destination),e.gain.value=0;const i=t.audioContext.createOscillator();i.connect(e),i.type="sine",i.frequency.value=1,i.start(),setTimeout((()=>{i.stop(),i.disconnect(),e.disconnect()}))},this._playNote=async(e,i,s)=>{if(this._container.muted)return;const o=e[i];if(!o)return;const n=o.value,a=(0,t.executeOnSingleOrMultiple)(n,(async(t,s)=>this._playNoteValue(e,i,s)));await((0,t.isArray)(a)?Promise.allSettled(a):a);let l=i+1;s&&l>=e.length&&(l%=e.length),this._container.muted||await this._playNote(e,l,s)},this._playNoteValue=async(e,i,s)=>{const o=e[i];if(!o)return;const n=(0,t.itemFromSingleOrMultiple)(o.value,s,!0);try{const e=h(n);if(!(0,t.isNumber)(e))return;await this._playFrequency(e,o.duration)}catch(e){(0,t.getLogger)().error(e)}},this._removeAudioSource=t=>{t.stop(),t.disconnect(),this._audioSources.splice(this._audioSources.indexOf(t),1)},this._unmute=()=>{const t=this._container,e=t.actualOptions.sounds;if(!e)return;t.audioContext||(t.audioContext=new AudioContext);const{audioContext:i}=t;this._audioSources||(this._audioSources=[]);const s=i.createGain();s.connect(i.destination),s.gain.value=e.volume.value/100,this._gain=s,this._initEvents(),this._engine.dispatchEvent("soundsUnmuted",{container:this._container})},this._updateMuteIcons=()=>{const t=this._container,e=this._muteImg,i=this._unmuteImg;e&&(e.style.display=t.muted?"block":"none"),i&&(i.style.display=t.muted?"none":"block")},this._updateMuteStatus=()=>{this._container.muted?this._mute():(this._unmute(),this._playMuteSound())},this._updateVolume=()=>{const e=this._container,i=e.actualOptions.sounds;if(!i?.enable)return;(0,t.clamp)(this._volume,i.volume.min,i.volume.max);let s=!1;this._volume<=0&&!e.muted?(this._volume=0,e.muted=!0,s=!0):this._volume>0&&e.muted&&(e.muted=!1,s=!0),s&&(this._updateMuteIcons(),this._updateMuteStatus()),this._gain?.gain&&(this._gain.gain.value=this._volume/100)},this._container=e,this._engine=i,this._volume=0,this._audioSources=[],this._audioMap=new Map}async init(){const e=this._container,i=e.actualOptions.sounds;if(!i?.enable)return;this._volume=i.volume.value;const s=i.events;this._audioMap=new Map;for(const i of s)i.audio&&(0,t.executeOnSingleOrMultiple)(i.audio,(async t=>{const i=await fetch(t.source);if(!i.ok)return;const s=await i.arrayBuffer();e.audioContext=new AudioContext;const o=await e.audioContext.decodeAudioData(s);this._audioMap.set(t.source,o)}))}async start(){const t=this._container,e=t.actualOptions,i=e.sounds;if(!i?.enable||!t.canvas.element)return;t.muted=!0;const s=t.canvas.element,o={top:s.offsetTop,right:s.offsetLeft+s.offsetWidth},{mute:n,unmute:a,volumeDown:l,volumeUp:c}=i.icons,u=()=>{t.muted=!t.muted,this._updateMuteIcons(),this._updateMuteStatus()};this._muteImg=p({container:t,options:e,pos:o,display:"block",iconOptions:n,margin:10,rightOffsets:[l.width,c.width],clickCb:u}),this._unmuteImg=p({container:t,options:e,pos:o,display:"none",iconOptions:a,margin:10,rightOffsets:[l.width,c.width],clickCb:u}),this._volumeDownImg=p({container:t,options:e,pos:o,display:"block",iconOptions:l,margin:10,rightOffsets:[c.width],clickCb:()=>{t.muted&&(this._volume=0),this._volume-=i.volume.step,this._updateVolume()}}),this._volumeUpImg=p({container:t,options:e,pos:o,display:"block",iconOptions:c,margin:10,rightOffsets:[],clickCb:()=>{t.muted&&(this._volume=0),this._volume+=i.volume.step,this._updateVolume()}})}stop(){this._container.muted=!0,this._mute(),m(this._muteImg),m(this._unmuteImg),m(this._volumeDownImg),m(this._volumeUpImg)}}class f{constructor(t){this.id="sounds",this._engine=t}getPlugin(t){return new v(t,this._engine)}loadOptions(t,e){if(!this.needsPlugin(t)&&!this.needsPlugin(e))return;let i=t.sounds;void 0===i?.load&&(t.sounds=i=new r),i.load(e?.sounds)}needsPlugin(t){return t?.sounds?.enable??!1}}async function g(t,e=!0){await t.addPlugin(new f(t),e)}})(),o})()));
@@ -1,8 +1 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v3.0.0-alpha.0
8
- */
1
+ /*! tsParticles Sounds Plugin v3.0.0-beta.0 by Matteo Bruni */
@@ -1,4 +1,4 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { ISoundsAudio } from "../Interfaces/ISoundsAudio";
3
3
  export declare class SoundsAudio implements ISoundsAudio, IOptionLoader<ISoundsAudio> {
4
4
  loop: boolean;
@@ -1,4 +1,4 @@
1
- import type { IOptionLoader, RecursivePartial, SingleOrMultiple } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type RecursivePartial, type SingleOrMultiple } from "@tsparticles/engine";
2
2
  import type { FilterFunction } from "../../types";
3
3
  import type { ISoundsEvent } from "../Interfaces/ISoundsEvent";
4
4
  import { SoundsAudio } from "./SoundsAudio";
@@ -1,4 +1,4 @@
1
- import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
1
+ import { type IOptionLoader, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { ISoundsVolume } from "../Interfaces/ISoundsVolume";
3
3
  export declare class SoundsVolume implements ISoundsVolume, IOptionLoader<ISoundsVolume> {
4
4
  max: number;
@@ -1,4 +1,4 @@
1
- import type { Engine, IContainerPlugin } from "@tsparticles/engine";
1
+ import { type Engine, type IContainerPlugin } from "@tsparticles/engine";
2
2
  import type { SoundsContainer } from "./types";
3
3
  export declare class SoundsInstance implements IContainerPlugin {
4
4
  private _audioMap;
@@ -15,18 +15,18 @@ export declare class SoundsInstance implements IContainerPlugin {
15
15
  init(): Promise<void>;
16
16
  start(): Promise<void>;
17
17
  stop(): void;
18
- private _addBuffer;
19
- private _addOscillator;
20
- private _initEvents;
21
- private _mute;
22
- private _playBuffer;
23
- private _playFrequency;
24
- private _playMuteSound;
25
- private _playNote;
26
- private _playNoteValue;
27
- private _removeAudioSource;
28
- private _unmute;
29
- private _updateMuteIcons;
30
- private _updateMuteStatus;
31
- private _updateVolume;
18
+ private readonly _addBuffer;
19
+ private readonly _addOscillator;
20
+ private readonly _initEvents;
21
+ private readonly _mute;
22
+ private readonly _playBuffer;
23
+ private readonly _playFrequency;
24
+ private readonly _playMuteSound;
25
+ private readonly _playNote;
26
+ private readonly _playNoteValue;
27
+ private readonly _removeAudioSource;
28
+ private readonly _unmute;
29
+ private readonly _updateMuteIcons;
30
+ private readonly _updateMuteStatus;
31
+ private readonly _updateVolume;
32
32
  }
package/types/enums.d.ts CHANGED
@@ -2,3 +2,7 @@ export declare const enum SoundsEventType {
2
2
  mute = "soundsMuted",
3
3
  unmute = "soundsUnmuted"
4
4
  }
5
+ export declare const enum ImageDisplay {
6
+ Block = "block",
7
+ None = "none"
8
+ }
package/types/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import type { Engine } from "@tsparticles/engine";
2
- export declare function loadSoundsPlugin(engine: Engine): Promise<void>;
2
+ export declare function loadSoundsPlugin(engine: Engine, refresh?: boolean): Promise<void>;
package/types/types.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { Container, CustomEventArgs, IOptions, Options } from "@tsparticles/engine";
2
2
  import type { ISounds } from "./Options/Interfaces/ISounds";
3
+ import type { ImageDisplay } from "./enums";
3
4
  import type { Sounds } from "./Options/Classes/Sounds";
5
+ import type { SoundsIcon } from "./Options/Classes/SoundsIcon";
4
6
  export type FilterFunction = (args: CustomEventArgs) => boolean;
5
7
  export type ISoundsOptions = IOptions & {
6
8
  sounds?: ISounds;
@@ -13,3 +15,17 @@ export type SoundsContainer = Container & {
13
15
  audioContext?: AudioContext;
14
16
  muted?: boolean;
15
17
  };
18
+ export type ImageMargins = {
19
+ right: number;
20
+ top: number;
21
+ };
22
+ export type InitImageData = {
23
+ clickCb: () => void;
24
+ container: SoundsContainer;
25
+ display: ImageDisplay;
26
+ iconOptions: SoundsIcon;
27
+ margin: number;
28
+ options: Options;
29
+ pos: ImageMargins;
30
+ rightOffsets: number[];
31
+ };
@@ -4,12 +4,13 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SoundsAudio = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
13
14
  class SoundsAudio {
14
15
  constructor() {
15
16
  this.loop = false;
@@ -19,7 +20,7 @@
19
20
  if (data === undefined) {
20
21
  return;
21
22
  }
22
- if (typeof data === "object") {
23
+ if ((0, engine_1.isObject)(data)) {
23
24
  if (data.loop !== undefined) {
24
25
  this.loop = data.loop;
25
26
  }
@@ -4,12 +4,13 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./SoundsAudio", "./SoundsMelody", "./SoundsNote"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "./SoundsAudio", "./SoundsMelody", "./SoundsNote"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SoundsEvent = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
13
14
  const SoundsAudio_1 = require("./SoundsAudio");
14
15
  const SoundsMelody_1 = require("./SoundsMelody");
15
16
  const SoundsNote_1 = require("./SoundsNote");
@@ -26,7 +27,7 @@
26
27
  this.event = data.event;
27
28
  }
28
29
  if (data.audio !== undefined) {
29
- if (data.audio instanceof Array) {
30
+ if ((0, engine_1.isArray)(data.audio)) {
30
31
  this.audio = data.audio.map((s) => {
31
32
  const tmp = new SoundsAudio_1.SoundsAudio();
32
33
  tmp.load(s);
@@ -53,8 +54,8 @@
53
54
  });
54
55
  }
55
56
  if (data.filter !== undefined) {
56
- if (typeof data.filter === "string") {
57
- if (typeof window[data.filter] === "function") {
57
+ if ((0, engine_1.isString)(data.filter)) {
58
+ if ((0, engine_1.isFunction)(window[data.filter])) {
58
59
  this.filter = window[data.filter];
59
60
  }
60
61
  }
@@ -4,12 +4,13 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports"], factory);
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SoundsVolume = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
13
14
  class SoundsVolume {
14
15
  constructor() {
15
16
  this.value = 100;
@@ -21,7 +22,7 @@
21
22
  if (data === undefined) {
22
23
  return;
23
24
  }
24
- if (typeof data === "object") {
25
+ if ((0, engine_1.isObject)(data)) {
25
26
  if (data.max !== undefined) {
26
27
  this.max = data.max;
27
28
  }