@tsparticles/plugin-sounds 3.0.3 → 3.2.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.
- package/265.min.js +2 -0
- package/265.min.js.LICENSE.txt +1 -0
- package/714.min.js +2 -0
- package/714.min.js.LICENSE.txt +1 -0
- package/browser/Options/Classes/Sounds.js +4 -0
- package/browser/Options/Classes/SoundsEvent.js +4 -3
- package/browser/Options/Classes/SoundsIcon.js +1 -0
- package/browser/Options/Classes/SoundsIcons.js +4 -0
- package/browser/SoundsInstance.js +130 -69
- package/browser/SoundsPlugin.js +37 -0
- package/browser/index.js +1 -24
- package/browser/utils.js +11 -4
- package/cjs/Options/Classes/Sounds.js +4 -0
- package/cjs/Options/Classes/SoundsEvent.js +4 -3
- package/cjs/Options/Classes/SoundsIcon.js +1 -0
- package/cjs/Options/Classes/SoundsIcons.js +4 -0
- package/cjs/SoundsInstance.js +128 -67
- package/cjs/SoundsPlugin.js +64 -0
- package/cjs/index.js +24 -24
- package/cjs/utils.js +14 -5
- package/dist_browser_SoundsInstance_js.js +30 -0
- package/dist_browser_SoundsPlugin_js.js +120 -0
- package/esm/Options/Classes/Sounds.js +4 -0
- package/esm/Options/Classes/SoundsEvent.js +4 -3
- package/esm/Options/Classes/SoundsIcon.js +1 -0
- package/esm/Options/Classes/SoundsIcons.js +4 -0
- package/esm/SoundsInstance.js +130 -69
- package/esm/SoundsPlugin.js +37 -0
- package/esm/index.js +1 -24
- package/esm/utils.js +11 -4
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.plugin.sounds.js +241 -738
- package/tsparticles.plugin.sounds.min.js +1 -1
- package/tsparticles.plugin.sounds.min.js.LICENSE.txt +1 -1
- package/types/Options/Classes/Sounds.d.ts +1 -0
- package/types/Options/Classes/SoundsEvent.d.ts +0 -5
- package/types/Options/Classes/SoundsIcon.d.ts +1 -0
- package/types/Options/Classes/SoundsIcons.d.ts +1 -0
- package/types/Options/Interfaces/ISounds.d.ts +1 -0
- package/types/Options/Interfaces/ISoundsIcon.d.ts +1 -0
- package/types/Options/Interfaces/ISoundsIcons.d.ts +1 -0
- package/types/SoundsInstance.d.ts +6 -0
- package/types/SoundsPlugin.d.ts +11 -0
- package/types/index.d.ts +1 -1
- package/types/types.d.ts +5 -5
- package/types/utils.d.ts +2 -0
- package/umd/Options/Classes/Sounds.js +4 -0
- package/umd/Options/Classes/SoundsEvent.js +4 -3
- package/umd/Options/Classes/SoundsIcon.js +1 -0
- package/umd/Options/Classes/SoundsIcons.js +4 -0
- package/umd/SoundsInstance.js +128 -67
- package/umd/SoundsPlugin.js +75 -0
- package/umd/index.js +26 -25
- package/umd/utils.js +14 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.plugin.sounds.min.js.LICENSE.txt */
|
|
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 c{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 l{constructor(){this.mute=new c,this.unmute=new c,this.volumeDown=new c,this.volumeUp=new c,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 l,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:c,pos:l,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,l.top+a,l.right-(a*(u.length+1)+r+u.reduce(((t,e)=>t+e),0)),o,c.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=s=>{(async()=>{const o=e.filter&&!e.filter(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(!o)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 c=i+1;s&&c>=e.length&&(c%=e.length),this._container.muted||await this._playNote(e,c,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=async()=>{const t=this._container;t.muted?(await(t.audioContext?.suspend()),this._mute()):(await(t.audioContext?.resume()),this._unmute(),this._playMuteSound())},this._updateVolume=async()=>{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(),await 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:c,volumeUp:l}=i.icons,u=async()=>{t.muted=!t.muted,this._updateMuteIcons(),await this._updateMuteStatus()};this._muteImg=p({container:t,options:e,pos:o,display:"block",iconOptions:n,margin:10,rightOffsets:[c.width,l.width],clickCb:u}),this._unmuteImg=p({container:t,options:e,pos:o,display:"none",iconOptions:a,margin:10,rightOffsets:[c.width,l.width],clickCb:u}),this._volumeDownImg=p({container:t,options:e,pos:o,display:"block",iconOptions:c,margin:10,rightOffsets:[l.width],clickCb:async()=>{t.muted&&(this._volume=0),this._volume-=i.volume.step,await this._updateVolume()}}),this._volumeUpImg=p({container:t,options:e,pos:o,display:"block",iconOptions:l,margin:10,rightOffsets:[],clickCb:async()=>{t.muted&&(this._volume=0),this._volume+=i.volume.step,await 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})()));
|
|
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 r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,(e=>(()=>{var t,r,o={533:t=>{t.exports=e}},n={};function i(e){var t=n[e];if(void 0!==t)return t.exports;var r=n[e]={exports:{}};return o[e](r,r.exports,i),r.exports}i.m=o,i.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var r in t)i.o(t,r)&&!i.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},i.f={},i.e=e=>Promise.all(Object.keys(i.f).reduce(((t,r)=>(i.f[r](e,t),t)),[])),i.u=e=>e+".min.js",i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/plugin-sounds:",i.l=(e,o,n,a)=>{if(t[e])t[e].push(o);else{var s,u;if(void 0!==n)for(var l=document.getElementsByTagName("script"),c=0;c<l.length;c++){var p=l[c];if(p.getAttribute("src")==e||p.getAttribute("data-webpack")==r+n){s=p;break}}s||(u=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,i.nc&&s.setAttribute("nonce",i.nc),s.setAttribute("data-webpack",r+n),s.src=e),t[e]=[o];var d=(r,o)=>{s.onerror=s.onload=null,clearTimeout(f);var n=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),n&&n.forEach((e=>e(o))),r)return r(o)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),u&&document.head.appendChild(s)}},i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;i.g.importScripts&&(e=i.g.location+"");var t=i.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var o=r.length-1;o>-1&&!e;)e=r[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i.p=e})(),(()=>{var e={405:0};i.f.j=(t,r)=>{var o=i.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else{var n=new Promise(((r,n)=>o=e[t]=[r,n]));r.push(o[2]=n);var a=i.p+i.u(t),s=new Error;i.l(a,(r=>{if(i.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var n=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+n+": "+a+")",s.name="ChunkLoadError",s.type=n,s.request=a,o[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var o,n,a=r[0],s=r[1],u=r[2],l=0;if(a.some((t=>0!==e[t]))){for(o in s)i.o(s,o)&&(i.m[o]=s[o]);if(u)u(i)}for(t&&t(r);l<a.length;l++)n=a[l],i.o(e,n)&&e[n]&&e[n][0](),e[n]=0},r=this.webpackChunk_tsparticles_plugin_sounds=this.webpackChunk_tsparticles_plugin_sounds||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var a={};return(()=>{async function e(e,t=!0){const{SoundsPlugin:r}=await i.e(714).then(i.bind(i,714));await e.addPlugin(new r(e),t)}i.r(a),i.d(a,{loadSoundsPlugin:()=>e})})(),a})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! tsParticles Sounds Plugin v3.0
|
|
1
|
+
/*! tsParticles Sounds Plugin v3.2.0 by Matteo Bruni */
|
|
@@ -4,6 +4,7 @@ import { SoundsEvent } from "./SoundsEvent.js";
|
|
|
4
4
|
import { SoundsIcons } from "./SoundsIcons.js";
|
|
5
5
|
import { SoundsVolume } from "./SoundsVolume.js";
|
|
6
6
|
export declare class Sounds implements ISounds, IOptionLoader<ISounds> {
|
|
7
|
+
autoPlay: boolean;
|
|
7
8
|
enable: boolean;
|
|
8
9
|
events: SoundsEvent[];
|
|
9
10
|
icons: SoundsIcons;
|
|
@@ -4,11 +4,6 @@ import type { ISoundsEvent } from "../Interfaces/ISoundsEvent.js";
|
|
|
4
4
|
import { SoundsAudio } from "./SoundsAudio.js";
|
|
5
5
|
import { SoundsMelody } from "./SoundsMelody.js";
|
|
6
6
|
import { SoundsNote } from "./SoundsNote.js";
|
|
7
|
-
declare global {
|
|
8
|
-
interface Window {
|
|
9
|
-
[key: string]: unknown;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
7
|
export declare class SoundsEvent implements ISoundsEvent, IOptionLoader<ISoundsEvent> {
|
|
13
8
|
audio?: SingleOrMultiple<SoundsAudio>;
|
|
14
9
|
event: SingleOrMultiple<string>;
|
|
@@ -2,6 +2,7 @@ import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
|
2
2
|
import type { ISoundsIcons } from "../Interfaces/ISoundsIcons.js";
|
|
3
3
|
import { SoundsIcon } from "./SoundsIcon.js";
|
|
4
4
|
export declare class SoundsIcons implements ISoundsIcons, IOptionLoader<ISoundsIcons> {
|
|
5
|
+
enable: boolean;
|
|
5
6
|
mute: SoundsIcon;
|
|
6
7
|
unmute: SoundsIcon;
|
|
7
8
|
volumeDown: SoundsIcon;
|
|
@@ -2,6 +2,7 @@ import type { ISoundsEvent } from "./ISoundsEvent.js";
|
|
|
2
2
|
import type { ISoundsIcons } from "./ISoundsIcons.js";
|
|
3
3
|
import type { ISoundsVolume } from "./ISoundsVolume.js";
|
|
4
4
|
export interface ISounds {
|
|
5
|
+
autoPlay: boolean;
|
|
5
6
|
enable: boolean;
|
|
6
7
|
events: ISoundsEvent[];
|
|
7
8
|
icons: ISoundsIcons;
|
|
@@ -13,10 +13,16 @@ export declare class SoundsInstance implements IContainerPlugin {
|
|
|
13
13
|
private _volumeUpImg?;
|
|
14
14
|
constructor(container: SoundsContainer, engine: Engine);
|
|
15
15
|
init(): Promise<void>;
|
|
16
|
+
mute(): Promise<void>;
|
|
16
17
|
start(): Promise<void>;
|
|
17
18
|
stop(): void;
|
|
19
|
+
toggleMute(): Promise<void>;
|
|
20
|
+
unmute(): Promise<void>;
|
|
21
|
+
volumeDown(): Promise<void>;
|
|
22
|
+
volumeUp(): Promise<void>;
|
|
18
23
|
private readonly _addBuffer;
|
|
19
24
|
private readonly _addOscillator;
|
|
25
|
+
private _getAudioContext;
|
|
20
26
|
private readonly _initEvents;
|
|
21
27
|
private readonly _mute;
|
|
22
28
|
private readonly _playBuffer;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Container, type Engine, type IPlugin, type RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import type { ISoundsOptions, SoundsOptions } from "./types.js";
|
|
3
|
+
import type { SoundsInstance } from "./SoundsInstance.js";
|
|
4
|
+
export declare class SoundsPlugin implements IPlugin {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
private readonly _engine;
|
|
7
|
+
constructor(engine: Engine);
|
|
8
|
+
getPlugin(container: Container): Promise<SoundsInstance>;
|
|
9
|
+
loadOptions(options: SoundsOptions, source?: RecursivePartial<ISoundsOptions>): void;
|
|
10
|
+
needsPlugin(options?: RecursivePartial<ISoundsOptions>): boolean;
|
|
11
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Engine } from "@tsparticles/engine";
|
|
2
2
|
export declare function loadSoundsPlugin(engine: Engine, refresh?: boolean): Promise<void>;
|
package/types/types.d.ts
CHANGED
|
@@ -15,12 +15,12 @@ export type SoundsContainer = Container & {
|
|
|
15
15
|
audioContext?: AudioContext;
|
|
16
16
|
muted?: boolean;
|
|
17
17
|
};
|
|
18
|
-
export
|
|
18
|
+
export interface ImageMargins {
|
|
19
19
|
right: number;
|
|
20
20
|
top: number;
|
|
21
|
-
}
|
|
22
|
-
export
|
|
23
|
-
clickCb: () => void
|
|
21
|
+
}
|
|
22
|
+
export interface InitImageData {
|
|
23
|
+
clickCb: () => Promise<void>;
|
|
24
24
|
container: SoundsContainer;
|
|
25
25
|
display: ImageDisplay;
|
|
26
26
|
iconOptions: SoundsIcon;
|
|
@@ -28,4 +28,4 @@ export type InitImageData = {
|
|
|
28
28
|
options: Options;
|
|
29
29
|
pos: ImageMargins;
|
|
30
30
|
rightOffsets: number[];
|
|
31
|
-
}
|
|
31
|
+
}
|
package/types/utils.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
const SoundsVolume_js_1 = require("./SoundsVolume.js");
|
|
16
16
|
class Sounds {
|
|
17
17
|
constructor() {
|
|
18
|
+
this.autoPlay = true;
|
|
18
19
|
this.enable = false;
|
|
19
20
|
this.events = [];
|
|
20
21
|
this.icons = new SoundsIcons_js_1.SoundsIcons();
|
|
@@ -24,6 +25,9 @@
|
|
|
24
25
|
if (!data) {
|
|
25
26
|
return;
|
|
26
27
|
}
|
|
28
|
+
if (data.autoPlay !== undefined) {
|
|
29
|
+
this.autoPlay = data.autoPlay;
|
|
30
|
+
}
|
|
27
31
|
if (data.enable !== undefined) {
|
|
28
32
|
this.enable = data.enable;
|
|
29
33
|
}
|
|
@@ -53,10 +53,11 @@
|
|
|
53
53
|
return tmp;
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
if (data.filter
|
|
56
|
+
if (data.filter) {
|
|
57
57
|
if ((0, engine_1.isString)(data.filter)) {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
const filterFunc = window[data.filter];
|
|
59
|
+
if ((0, engine_1.isFunction)(filterFunc)) {
|
|
60
|
+
this.filter = filterFunc;
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
this.unmute = new SoundsIcon_js_1.SoundsIcon();
|
|
18
18
|
this.volumeDown = new SoundsIcon_js_1.SoundsIcon();
|
|
19
19
|
this.volumeUp = new SoundsIcon_js_1.SoundsIcon();
|
|
20
|
+
this.enable = false;
|
|
20
21
|
this.mute.svg = `<?xml version="1.0"?>
|
|
21
22
|
<svg baseProfile="tiny" height="24px" version="1.2" viewBox="0 0 24 24" width="24px"
|
|
22
23
|
xml:space="preserve" xmlns="http://www.w3.org/2000/svg"
|
|
@@ -58,6 +59,9 @@
|
|
|
58
59
|
if (!data) {
|
|
59
60
|
return;
|
|
60
61
|
}
|
|
62
|
+
if (data.enable !== undefined) {
|
|
63
|
+
this.enable = data.enable;
|
|
64
|
+
}
|
|
61
65
|
this.mute.load(data.mute);
|
|
62
66
|
this.unmute.load(data.unmute);
|
|
63
67
|
this.volumeDown.load(data.volumeDown);
|
package/umd/SoundsInstance.js
CHANGED
|
@@ -12,13 +12,19 @@
|
|
|
12
12
|
exports.SoundsInstance = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const utils_js_1 = require("./utils.js");
|
|
15
|
+
const zIndexOffset = 1, rightOffset = 1, minVolume = 0;
|
|
15
16
|
function initImage(data) {
|
|
16
|
-
const img = document.createElement("img"), { clickCb, container, display, iconOptions, margin, options, pos, rightOffsets } = data, { width, path, svg } = iconOptions;
|
|
17
|
-
setIconStyle(img, pos.top + margin, pos.right -
|
|
17
|
+
const img = document.createElement("img"), { clickCb, container, display, iconOptions, margin, options, pos, rightOffsets } = data, { width, path, style, svg } = iconOptions, defaultAccumulator = 0;
|
|
18
|
+
setIconStyle(img, pos.top + margin, pos.right -
|
|
19
|
+
(margin * (rightOffsets.length + rightOffset) +
|
|
20
|
+
width +
|
|
21
|
+
rightOffsets.reduce((a, b) => a + b, defaultAccumulator)), display, options.fullScreen.zIndex + zIndexOffset, width, margin, style);
|
|
18
22
|
img.src = path ?? (svg ? `data:image/svg+xml;base64,${btoa(svg)}` : "");
|
|
19
|
-
const parent = container.canvas.element?.parentNode
|
|
23
|
+
const parent = container.canvas.element?.parentNode ?? document.body;
|
|
20
24
|
parent.append(img);
|
|
21
|
-
img.addEventListener("click",
|
|
25
|
+
img.addEventListener("click", () => {
|
|
26
|
+
void clickCb();
|
|
27
|
+
});
|
|
22
28
|
return img;
|
|
23
29
|
}
|
|
24
30
|
function removeImage(image) {
|
|
@@ -27,14 +33,15 @@
|
|
|
27
33
|
}
|
|
28
34
|
image.remove();
|
|
29
35
|
}
|
|
30
|
-
function setIconStyle(icon, top, left, display, zIndex, width, margin) {
|
|
36
|
+
function setIconStyle(icon, top, left, display, zIndex, width, margin, style) {
|
|
31
37
|
icon.style.userSelect = "none";
|
|
32
38
|
icon.style.webkitUserSelect = "none";
|
|
33
39
|
icon.style.position = "absolute";
|
|
34
40
|
icon.style.top = `${top + margin}px`;
|
|
35
41
|
icon.style.left = `${left - margin - width}px`;
|
|
36
42
|
icon.style.display = display;
|
|
37
|
-
icon.style.zIndex = `${zIndex +
|
|
43
|
+
icon.style.zIndex = `${zIndex + zIndexOffset}`;
|
|
44
|
+
icon.style.cssText += style;
|
|
38
45
|
}
|
|
39
46
|
class SoundsInstance {
|
|
40
47
|
constructor(container, engine) {
|
|
@@ -55,12 +62,12 @@
|
|
|
55
62
|
}
|
|
56
63
|
for (const event of soundsOptions.events) {
|
|
57
64
|
const cb = (args) => {
|
|
58
|
-
(async () => {
|
|
65
|
+
void (async () => {
|
|
59
66
|
const filterNotValid = event.filter && !event.filter(args);
|
|
60
67
|
if (this._container !== args.container) {
|
|
61
68
|
return;
|
|
62
69
|
}
|
|
63
|
-
if (!this._container || this._container.muted || this._container.destroyed) {
|
|
70
|
+
if (!this._container || !!this._container.muted || this._container.destroyed) {
|
|
64
71
|
(0, engine_1.executeOnSingleOrMultiple)(event.event, (item) => {
|
|
65
72
|
this._engine.removeEventListener(item, cb);
|
|
66
73
|
});
|
|
@@ -69,21 +76,22 @@
|
|
|
69
76
|
if (filterNotValid) {
|
|
70
77
|
return;
|
|
71
78
|
}
|
|
79
|
+
const defaultNoteIndex = 0;
|
|
72
80
|
if (event.audio) {
|
|
73
81
|
this._playBuffer((0, engine_1.itemFromSingleOrMultiple)(event.audio));
|
|
74
82
|
}
|
|
75
83
|
else if (event.melodies) {
|
|
76
84
|
const melody = (0, engine_1.itemFromArray)(event.melodies);
|
|
77
85
|
if (melody.melodies.length) {
|
|
78
|
-
await Promise.allSettled(melody.melodies.map((m) => this._playNote(m.notes,
|
|
86
|
+
await Promise.allSettled(melody.melodies.map((m) => this._playNote(m.notes, defaultNoteIndex, melody.loop)));
|
|
79
87
|
}
|
|
80
88
|
else {
|
|
81
|
-
await this._playNote(melody.notes,
|
|
89
|
+
await this._playNote(melody.notes, defaultNoteIndex, melody.loop);
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
else if (event.notes) {
|
|
85
93
|
const note = (0, engine_1.itemFromArray)(event.notes);
|
|
86
|
-
await this._playNote([note],
|
|
94
|
+
await this._playNote([note], defaultNoteIndex, false);
|
|
87
95
|
}
|
|
88
96
|
})();
|
|
89
97
|
};
|
|
@@ -92,18 +100,15 @@
|
|
|
92
100
|
});
|
|
93
101
|
}
|
|
94
102
|
};
|
|
95
|
-
this._mute = () => {
|
|
96
|
-
const container = this._container;
|
|
97
|
-
if (!container.audioContext) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
103
|
+
this._mute = async () => {
|
|
104
|
+
const container = this._container, audioContext = this._getAudioContext();
|
|
100
105
|
for (const source of this._audioSources) {
|
|
101
106
|
this._removeAudioSource(source);
|
|
102
107
|
}
|
|
103
108
|
if (this._gain) {
|
|
104
109
|
this._gain.disconnect();
|
|
105
110
|
}
|
|
106
|
-
|
|
111
|
+
await audioContext.close();
|
|
107
112
|
container.audioContext = undefined;
|
|
108
113
|
this._engine.dispatchEvent("soundsMuted", { container: this._container });
|
|
109
114
|
};
|
|
@@ -123,10 +128,10 @@
|
|
|
123
128
|
source.start();
|
|
124
129
|
};
|
|
125
130
|
this._playFrequency = async (frequency, duration) => {
|
|
126
|
-
if (!this.
|
|
131
|
+
if (!this._gain || this._container.muted) {
|
|
127
132
|
return;
|
|
128
133
|
}
|
|
129
|
-
const oscillator = this._addOscillator(
|
|
134
|
+
const audioContext = this._getAudioContext(), oscillator = this._addOscillator(audioContext);
|
|
130
135
|
oscillator.connect(this._gain);
|
|
131
136
|
oscillator.type = "sine";
|
|
132
137
|
oscillator.frequency.value = frequency;
|
|
@@ -139,14 +144,13 @@
|
|
|
139
144
|
});
|
|
140
145
|
};
|
|
141
146
|
this._playMuteSound = () => {
|
|
142
|
-
|
|
143
|
-
if (!container.audioContext) {
|
|
147
|
+
if (this._container.muted) {
|
|
144
148
|
return;
|
|
145
149
|
}
|
|
146
|
-
const gain =
|
|
147
|
-
gain.connect(
|
|
150
|
+
const audioContext = this._getAudioContext(), gain = audioContext.createGain();
|
|
151
|
+
gain.connect(audioContext.destination);
|
|
148
152
|
gain.gain.value = 0;
|
|
149
|
-
const oscillator =
|
|
153
|
+
const oscillator = audioContext.createOscillator();
|
|
150
154
|
oscillator.connect(gain);
|
|
151
155
|
oscillator.type = "sine";
|
|
152
156
|
oscillator.frequency.value = 1;
|
|
@@ -170,7 +174,8 @@
|
|
|
170
174
|
return this._playNoteValue(notes, noteIdx, idx);
|
|
171
175
|
});
|
|
172
176
|
await ((0, engine_1.isArray)(promises) ? Promise.allSettled(promises) : promises);
|
|
173
|
-
|
|
177
|
+
const indexOffset = 1;
|
|
178
|
+
let nextNoteIdx = noteIdx + indexOffset;
|
|
174
179
|
if (loop && nextNoteIdx >= notes.length) {
|
|
175
180
|
nextNoteIdx = nextNoteIdx % notes.length;
|
|
176
181
|
}
|
|
@@ -199,29 +204,31 @@
|
|
|
199
204
|
this._removeAudioSource = (source) => {
|
|
200
205
|
source.stop();
|
|
201
206
|
source.disconnect();
|
|
202
|
-
|
|
207
|
+
const deleteCount = 1;
|
|
208
|
+
this._audioSources.splice(this._audioSources.indexOf(source), deleteCount);
|
|
203
209
|
};
|
|
204
210
|
this._unmute = () => {
|
|
205
211
|
const container = this._container, options = container.actualOptions, soundsOptions = options.sounds;
|
|
206
212
|
if (!soundsOptions) {
|
|
207
213
|
return;
|
|
208
214
|
}
|
|
209
|
-
|
|
210
|
-
container.audioContext = new AudioContext();
|
|
211
|
-
}
|
|
212
|
-
const { audioContext } = container;
|
|
215
|
+
const audioContext = this._getAudioContext();
|
|
213
216
|
if (!this._audioSources) {
|
|
214
217
|
this._audioSources = [];
|
|
215
218
|
}
|
|
216
219
|
const gain = audioContext.createGain();
|
|
217
220
|
gain.connect(audioContext.destination);
|
|
218
|
-
gain.gain.value = soundsOptions.volume.value /
|
|
221
|
+
gain.gain.value = soundsOptions.volume.value / engine_1.percentDenominator;
|
|
219
222
|
this._gain = gain;
|
|
220
223
|
this._initEvents();
|
|
221
224
|
this._engine.dispatchEvent("soundsUnmuted", { container: this._container });
|
|
222
225
|
};
|
|
223
226
|
this._updateMuteIcons = () => {
|
|
224
|
-
const container = this._container,
|
|
227
|
+
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
228
|
+
if (!soundsOptions?.enable || !soundsOptions.icons.enable) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const muteImg = this._muteImg, unmuteImg = this._unmuteImg;
|
|
225
232
|
if (muteImg) {
|
|
226
233
|
muteImg.style.display = container.muted ? "block" : "none";
|
|
227
234
|
}
|
|
@@ -230,13 +237,13 @@
|
|
|
230
237
|
}
|
|
231
238
|
};
|
|
232
239
|
this._updateMuteStatus = async () => {
|
|
233
|
-
const container = this._container;
|
|
240
|
+
const container = this._container, audioContext = this._getAudioContext();
|
|
234
241
|
if (container.muted) {
|
|
235
|
-
await
|
|
236
|
-
this._mute();
|
|
242
|
+
await audioContext?.suspend();
|
|
243
|
+
await this._mute();
|
|
237
244
|
}
|
|
238
245
|
else {
|
|
239
|
-
await
|
|
246
|
+
await audioContext?.resume();
|
|
240
247
|
this._unmute();
|
|
241
248
|
this._playMuteSound();
|
|
242
249
|
}
|
|
@@ -248,12 +255,12 @@
|
|
|
248
255
|
}
|
|
249
256
|
(0, engine_1.clamp)(this._volume, soundsOptions.volume.min, soundsOptions.volume.max);
|
|
250
257
|
let stateChanged = false;
|
|
251
|
-
if (this._volume <=
|
|
258
|
+
if (this._volume <= minVolume && !container.muted) {
|
|
252
259
|
this._volume = 0;
|
|
253
260
|
container.muted = true;
|
|
254
261
|
stateChanged = true;
|
|
255
262
|
}
|
|
256
|
-
else if (this._volume >
|
|
263
|
+
else if (this._volume > minVolume && container.muted) {
|
|
257
264
|
container.muted = false;
|
|
258
265
|
stateChanged = true;
|
|
259
266
|
}
|
|
@@ -262,7 +269,7 @@
|
|
|
262
269
|
await this._updateMuteStatus();
|
|
263
270
|
}
|
|
264
271
|
if (this._gain?.gain) {
|
|
265
|
-
this._gain.gain.value = this._volume /
|
|
272
|
+
this._gain.gain.value = this._volume / engine_1.percentDenominator;
|
|
266
273
|
}
|
|
267
274
|
};
|
|
268
275
|
this._container = container;
|
|
@@ -276,6 +283,20 @@
|
|
|
276
283
|
if (!soundsOptions?.enable) {
|
|
277
284
|
return;
|
|
278
285
|
}
|
|
286
|
+
if (soundsOptions.autoPlay && (0, utils_js_1.isWindowMuted)()) {
|
|
287
|
+
const firstClickHandler = () => {
|
|
288
|
+
removeEventListener(engine_1.mouseDownEvent, firstClickHandler);
|
|
289
|
+
removeEventListener(engine_1.touchStartEvent, firstClickHandler);
|
|
290
|
+
(0, utils_js_1.unmuteWindow)();
|
|
291
|
+
void this.unmute();
|
|
292
|
+
};
|
|
293
|
+
const listenerOptions = {
|
|
294
|
+
capture: true,
|
|
295
|
+
once: true,
|
|
296
|
+
};
|
|
297
|
+
addEventListener(engine_1.mouseDownEvent, firstClickHandler, listenerOptions);
|
|
298
|
+
addEventListener(engine_1.touchStartEvent, firstClickHandler, listenerOptions);
|
|
299
|
+
}
|
|
279
300
|
this._volume = soundsOptions.volume.value;
|
|
280
301
|
const events = soundsOptions.events;
|
|
281
302
|
this._audioMap = new Map();
|
|
@@ -283,16 +304,25 @@
|
|
|
283
304
|
if (!event.audio) {
|
|
284
305
|
continue;
|
|
285
306
|
}
|
|
286
|
-
(0, engine_1.executeOnSingleOrMultiple)(event.audio, async (audio) => {
|
|
307
|
+
const promises = (0, engine_1.executeOnSingleOrMultiple)(event.audio, async (audio) => {
|
|
287
308
|
const response = await fetch(audio.source);
|
|
288
309
|
if (!response.ok) {
|
|
289
310
|
return;
|
|
290
311
|
}
|
|
291
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
292
|
-
container.audioContext = new AudioContext();
|
|
293
|
-
const audioBuffer = await container.audioContext.decodeAudioData(arrayBuffer);
|
|
312
|
+
const arrayBuffer = await response.arrayBuffer(), audioContext = this._getAudioContext(), audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
|
294
313
|
this._audioMap.set(audio.source, audioBuffer);
|
|
295
314
|
});
|
|
315
|
+
if (promises instanceof Promise) {
|
|
316
|
+
await promises;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
await Promise.allSettled(promises);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
async mute() {
|
|
324
|
+
if (!this._container.muted) {
|
|
325
|
+
await this.toggleMute();
|
|
296
326
|
}
|
|
297
327
|
}
|
|
298
328
|
async start() {
|
|
@@ -304,17 +334,14 @@
|
|
|
304
334
|
const canvas = container.canvas.element, pos = {
|
|
305
335
|
top: canvas.offsetTop,
|
|
306
336
|
right: canvas.offsetLeft + canvas.offsetWidth,
|
|
307
|
-
}, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
this._updateMuteIcons();
|
|
311
|
-
await this._updateMuteStatus();
|
|
312
|
-
};
|
|
337
|
+
}, { mute, unmute, volumeDown, volumeUp } = soundsOptions.icons, margin = 10, toggleMute = async () => {
|
|
338
|
+
await this.toggleMute();
|
|
339
|
+
}, enableIcons = soundsOptions.icons.enable, display = enableIcons ? "block" : "none";
|
|
313
340
|
this._muteImg = initImage({
|
|
314
341
|
container,
|
|
315
342
|
options,
|
|
316
343
|
pos,
|
|
317
|
-
display
|
|
344
|
+
display,
|
|
318
345
|
iconOptions: mute,
|
|
319
346
|
margin,
|
|
320
347
|
rightOffsets: [volumeDown.width, volumeUp.width],
|
|
@@ -334,42 +361,76 @@
|
|
|
334
361
|
container,
|
|
335
362
|
options,
|
|
336
363
|
pos,
|
|
337
|
-
display
|
|
364
|
+
display,
|
|
338
365
|
iconOptions: volumeDown,
|
|
339
366
|
margin,
|
|
340
367
|
rightOffsets: [volumeUp.width],
|
|
341
368
|
clickCb: async () => {
|
|
342
|
-
|
|
343
|
-
this._volume = 0;
|
|
344
|
-
}
|
|
345
|
-
this._volume -= soundsOptions.volume.step;
|
|
346
|
-
await this._updateVolume();
|
|
369
|
+
await this.volumeDown();
|
|
347
370
|
},
|
|
348
371
|
});
|
|
349
372
|
this._volumeUpImg = initImage({
|
|
350
373
|
container,
|
|
351
374
|
options,
|
|
352
375
|
pos,
|
|
353
|
-
display
|
|
376
|
+
display,
|
|
354
377
|
iconOptions: volumeUp,
|
|
355
378
|
margin,
|
|
356
379
|
rightOffsets: [],
|
|
357
380
|
clickCb: async () => {
|
|
358
|
-
|
|
359
|
-
this._volume = 0;
|
|
360
|
-
}
|
|
361
|
-
this._volume += soundsOptions.volume.step;
|
|
362
|
-
await this._updateVolume();
|
|
381
|
+
await this.volumeUp();
|
|
363
382
|
},
|
|
364
383
|
});
|
|
384
|
+
if (!(0, utils_js_1.isWindowMuted)() && soundsOptions.autoPlay) {
|
|
385
|
+
await this.unmute();
|
|
386
|
+
}
|
|
365
387
|
}
|
|
366
388
|
stop() {
|
|
367
389
|
this._container.muted = true;
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
390
|
+
void (async () => {
|
|
391
|
+
await this._mute();
|
|
392
|
+
removeImage(this._muteImg);
|
|
393
|
+
removeImage(this._unmuteImg);
|
|
394
|
+
removeImage(this._volumeDownImg);
|
|
395
|
+
removeImage(this._volumeUpImg);
|
|
396
|
+
})();
|
|
397
|
+
}
|
|
398
|
+
async toggleMute() {
|
|
399
|
+
const container = this._container;
|
|
400
|
+
container.muted = !container.muted;
|
|
401
|
+
this._updateMuteIcons();
|
|
402
|
+
await this._updateMuteStatus();
|
|
403
|
+
}
|
|
404
|
+
async unmute() {
|
|
405
|
+
if (this._container.muted) {
|
|
406
|
+
await this.toggleMute();
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async volumeDown() {
|
|
410
|
+
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
411
|
+
if (!soundsOptions?.enable) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (container.muted) {
|
|
415
|
+
this._volume = 0;
|
|
416
|
+
}
|
|
417
|
+
this._volume -= soundsOptions.volume.step;
|
|
418
|
+
await this._updateVolume();
|
|
419
|
+
}
|
|
420
|
+
async volumeUp() {
|
|
421
|
+
const container = this._container, soundsOptions = container.actualOptions.sounds;
|
|
422
|
+
if (!soundsOptions?.enable) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
this._volume += soundsOptions.volume.step;
|
|
426
|
+
await this._updateVolume();
|
|
427
|
+
}
|
|
428
|
+
_getAudioContext() {
|
|
429
|
+
const container = this._container;
|
|
430
|
+
if (!container.audioContext) {
|
|
431
|
+
container.audioContext = new AudioContext();
|
|
432
|
+
}
|
|
433
|
+
return container.audioContext;
|
|
373
434
|
}
|
|
374
435
|
}
|
|
375
436
|
exports.SoundsInstance = SoundsInstance;
|