ttsreader
Version:
Text to Speech wrapper, player and helpers for the web-speech-api speech synthesis
2 lines (1 loc) • 27.8 kB
JavaScript
!function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,(function(r){return o(e[i][1][r]||r)}),p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(require,module,exports){window.wsGlobals=window.wsGlobals||{},window.wsGlobals.TtsEngine=require("./index").TtsEngine},{"./index":5}],2:[function(require,module,exports){const{ServerVoices:ServerVoices}=require("./serverVoices"),SERVER_TTS_ENDPOINT=("localhost"===location.hostname||location.hostname,"https://us-central1-ttsreader.cloudfunctions.net/tts");window.SERVER_TTS_ENDPOINT=SERVER_TTS_ENDPOINT;class ServerTts{static voices=ServerVoices.voices;static buffer=[];static currentAudio=null;static listener={onInit:voices=>{},onStart:id=>{},onDone:id=>{},onError:(id,error)=>{},onReady:id=>{}};static getVoices(){return ServerTts.voices}static init(listener){listener&&(ServerTts.listener=listener),ServerTts.listener.onInit(ServerTts.voices)}static async bufferNewUtterance(text,voiceURI,langBCP47,rate,id,authToken,onSuccess,onError,isTest=!1,tryCount=0){let utterance={text:text,voiceURI:voiceURI,langBCP47:langBCP47,rate:rate,id:id,wasPlayed:!1,audio:null,renderStatus:"waiting",onSuccess:onSuccess,onError:onError};async function tryAgain(waitInMs,maxTries){await new Promise((resolve=>setTimeout(resolve,waitInMs))),tryCount<maxTries?ServerTts.bufferNewUtterance(text,voiceURI,langBCP47,rate,id,authToken,onSuccess,onError,isTest,tryCount+1):(ServerTts.buffer=ServerTts.buffer.filter((u=>u.id!==id)),onError("Failed buffering ",utterance.id))}tryCount=tryCount||0,ServerTts.buffer=ServerTts.buffer.filter((u=>u.id!==id)),ServerTts.buffer.push(utterance),fetch(SERVER_TTS_ENDPOINT,{method:"POST",headers:{Authorization:`Bearer ${authToken}`,"Content-Type":"application/json"},body:JSON.stringify({text:text,lang:langBCP47,voice:voiceURI,rate:utterance.rate>=.95?1:utterance.rate,isTest:Boolean(isTest)})}).then((response=>response.ok?response.blob():(429===response.status?(ServerTts.buffer=ServerTts.buffer.filter((u=>u.id!==id)),onError(429)):tryAgain(500,3),Promise.reject()))).then((blob=>{const url=URL.createObjectURL(blob);utterance.audio=new Audio(url),utterance.blob=blob,utterance.audio.playbackRate=utterance.rate>=.95?utterance.rate:1,utterance.renderStatus="done",utterance.onSuccess();try{for(;ServerTts.buffer.length>50&&ServerTts.buffer[0].wasPlayed||ServerTts.buffer.length>50;)ServerTts.buffer.shift()}catch(e){}})).catch((err=>{tryAgain(500,3)}))}static async generateAudioSync(text,voiceURI,langBCP47,rate,id,authToken,onSuccess,onError,optionalParamsAsJson){let quality="48khz_192kbps";optionalParamsAsJson&&optionalParamsAsJson.quality&&(quality=optionalParamsAsJson.quality);try{const response=await fetch(SERVER_TTS_ENDPOINT,{method:"POST",headers:{Authorization:`Bearer ${authToken}`,"Content-Type":"application/json"},body:JSON.stringify({text:text,lang:langBCP47,voice:voiceURI,rate:rate,quality:quality})});if(!response.ok)throw new Error(`Server returned status ${response.status}`);const blob=await response.blob();onSuccess(URL.createObjectURL(blob))}catch(error){return void onError(error.message)}}static async speak(id,listener){ServerTts.stop();const getUtterance=()=>ServerTts.buffer.find((u=>u.id===id));let utterance=getUtterance();if(!utterance)return ServerTts.listener.onError(id,"Utterance not found in buffer");let waited=0;for(;!utterance.audio&&waited<1e4;)await new Promise((r=>setTimeout(r,200))),waited+=200,utterance=getUtterance();utterance.audio?(ServerTts.currentAudio=utterance.audio,ServerTts.currentAudio.onended=()=>{utterance.wasPlayed=!0,listener.onDone(id)},ServerTts.currentAudio.onerror=()=>{listener.onError(id,"Audio playback failed"),listener.onDone(id)},listener.onStart(id),ServerTts.currentAudio.play().catch((err=>{listener.onError(id,err.message),utterance.wasPlayed=!0,listener.onDone(id)}))):listener.onError(id,"Audio not available after 10s")}static stop(){ServerTts.currentAudio&&(ServerTts.currentAudio.pause(),ServerTts.currentAudio.currentTime=0),ServerTts.buffer&&ServerTts.buffer.length>0&&ServerTts.buffer.forEach((u=>{u.onSuccess&&(u.onSuccess=()=>{})}))}}void 0!==module&&(module.exports={ServerTts:ServerTts})},{"./serverVoices":3}],3:[function(require,module,exports){class ServerVoices{static voices=[{voiceURI:"ttsreaderServer.azure.en-GB-OllieMultilingualNeural",name:"Ollie",lang:"en-GB",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.en-GB-SoniaNeural",name:"Sonia",lang:"en-GB",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.en-GB-AbbiNeural",name:"Abbi",lang:"en-GB",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.es-ES-SaulNeural",name:"Saul",lang:"es-ES",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.es-ES-VeraNeural",name:"Vera",lang:"es-ES",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.es-ES-AlvaroNeural",name:"Alvaro",lang:"es-ES",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.es-ES-ElviraNeural",name:"Elvira",lang:"es-ES",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.it-IT-MarcelloMultilingualNeural",name:"Marcello Premium",lang:"it-IT",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.it-IT-IsabellaNeural",name:"Isabella Premium",lang:"it-IT",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.hi-IN-ArjunNeural",name:"Arjun Premium",lang:"hi-IN",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.hi-IN-AartiNeural",name:"Aarti Premium",lang:"hi-IN",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.ar-EG-SalmaNeural",name:"Salma Premium",lang:"ar-EG",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.ar-EG-ShakirNeural",name:"Shakir Premium",lang:"ar-EG",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.en-US-AriaNeural",name:"Aria Premium",lang:"en-US",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.en-US-NovaTurboMultilingualNeural",name:"Nova Premium",lang:"en-US",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.en-US-AdamMultilingualNeural",name:"Adam Premium",lang:"en-US",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.core1.f1",name:"נעמי חדש נסיוני",lang:"he-IL",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.core1.f3",name:"רחל חדש נסיוני",lang:"he-IL",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.core1.f2",name:"אסתר חדש נסיוני",lang:"he-IL",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.core1.m1",name:"דודו חדש נסיוני",lang:"he-IL",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.fr-FR-VivienneMultilingualNeural",name:"Vivienne Premium",lang:"fr-FR",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.fr-FR-HenriNeural",name:"Henri Premium",lang:"fr-FR",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.de-DE-ConradNeural",name:"Conrad Premium",lang:"de-DE",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.de-DE-SeraphinaMultilingualNeural",name:"Seraphina Premium",lang:"de-DE",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.en-GB-AdaMultilingualNeural",name:"Ada Premium",lang:"en-GB",localService:!1,default:!0,premiumLevel:2,gender:"f"},{voiceURI:"ttsreaderServer.azure.he-IL-AvriNeural",name:"אברי",lang:"he-IL",localService:!1,default:!0,premiumLevel:2,gender:"m"},{voiceURI:"ttsreaderServer.azure.he-IL-HilaNeural",name:"הילה",lang:"he-IL",localService:!1,default:!0,premiumLevel:2,gender:"f",avatar:"/images/avatars/ttsreaderServer.azure.he-IL-HilaNeural.webp",demo:"/audio/ttsreaderServer.azure.he-IL-HilaNeural.mp3"},{voiceURI:"ttsreaderServer.azure.es-MX-JorgeNeural",name:"Jorge Premium",lang:"es-MX",localService:!1,default:!0,premiumLevel:2,gender:"m",avatar:"/images/avatars/ttsreaderServer.azure.es-MX-JorgeNeural.webp",demo:"/audio/ttsreaderServer.azure.es-MX-JorgeNeural.mp3"},{voiceURI:"ttsreaderServer.azure.es-MX-DaliaNeural",name:"Dalia Premium",lang:"es-MX",localService:!1,default:!0,premiumLevel:2,gender:"f",avatar:"/images/avatars/ttsreaderServer.azure.es-MX-DaliaNeural.webp",demo:"/audio/ttsreaderServer.azure.es-MX-DaliaNeural.mp3"},{voiceURI:"ttsreaderServer.gcp.en-GB-Standard-A",name:"Olivia Premium",lang:"en-GB",localService:!1,default:!0,premiumLevel:1,gender:"f",avatar:"/images/avatars/ttsreaderServer.gcp.en-GB-Standard-A.webp",demo:"/audio/ttsreaderServer.gcp.en-GB-Standard-A.mp3"},{voiceURI:"ttsreaderServer.gcp.en-GB-Standard-D",name:"Noah Premium",lang:"en-GB",localService:!1,default:!0,premiumLevel:1,gender:"m",avatar:"/images/avatars/ttsreaderServer.gcp.en-GB-Standard-D.webp",demo:"/audio/ttsreaderServer.gcp.en-GB-Standard-D.mp3"},{voiceURI:"ttsreaderServer.gcp.en-GB-Standard-N",name:"Lilly Premium",lang:"en-GB",localService:!1,default:!0,premiumLevel:1,gender:"f",avatar:"/images/avatars/ttsreaderServer.gcp.en-GB-Standard-N.webp",demo:"/audio/ttsreaderServer.gcp.en-GB-Standard-N.mp3"},{voiceURI:"ttsreaderServer.gcp.en-US-Chirp-HD-D",name:"John Premium",lang:"en-US",localService:!1,default:!0,premiumLevel:2,gender:"m",avatar:"/images/avatars/ttsreaderServer.gcp.en-US-Chirp-HD-D.webp",demo:"/audio/ttsreaderServer.gcp.en-US-Chirp-HD-D.mp3"}]}void 0!==module&&(module.exports={ServerVoices:ServerVoices})},{}],4:[function(require,module,exports){const SHA256=require("crypto-js/sha256"),{ServerTts:ServerTts}=require("./serverTts");function codeToLanguageCodeOnly(code){return null==code||code.length<2?"":code.toLowerCase().split("-")[0].split("_")[0]}function doCodesShareLanguage(a,b){return codeToLanguageCodeOnly(a)==codeToLanguageCodeOnly(b)}exports.TtsEngine={DEFAULT_LANG:"en",voice:{},voices:[],rate:1,utteranceId:0,startedAndNotTerminatedCounter:0,listener:null,utterance:{},_googleBugTimeout:null,_speakTimeout:null,_canceledAtMs:0,_isServerTTS:!1,_defaultListener:{onInit:voices=>{},onStart:()=>{},onDone:()=>{},onError:error=>{},onVoicesChanged:updatedVoices=>{}},init:function(listener,isToAddServerTTS){listener&&this.setListener(listener,isToAddServerTTS),this._isServerTTS=isToAddServerTTS||!1,this._populateVoices(isToAddServerTTS),speechSynthesis.onvoiceschanged=()=>{this._populateVoices(isToAddServerTTS)}},setListener:function(listener,isToAddServerTTS){this.listener=listener||this._defaultListener},removeLocalGoogleVoices:function(){if(this.voicesIncludingGoogle=[...this.voices],this.voices=this.voices.filter((v=>!v.voiceURI.includes("Google "))),this.voice&&!this.voices.includes(this.voice)){let lang=this.voice.lang;this.voice=null,this.setBestMatchingVoice(null,null,lang)}this.listener.onVoicesChanged(this.voices)},bringBackGoogleVoices:function(){this.voices=[...this.voicesIncludingGoogle],this.voicesIncludingGoogle=null,this.listener.onVoicesChanged(this.voices)},runSilentTest:function(){let timer;Date.now();const utterance=new SpeechSynthesisUtterance("hi");utterance.volume=0;let voice=speechSynthesis.getVoices().find((v=>"Google UK English Male"===v.voiceURI));voice&&(utterance.voice=voice,utterance.voiceURI=voice.voiceURI,utterance.lang=voice.lang,timer=setTimeout((()=>{this.removeLocalGoogleVoices(),window.gtag&>ag("event","silent_test_failed",{value:"1"})}),3e3),utterance.onstart=()=>{clearTimeout(timer),window.gtag&>ag("event","silent_test_success",{value:"1"}),this.voicesIncludingGoogle&&this.bringBackGoogleVoices(),speechSynthesis.cancel()},utterance.onend=()=>{window.gtag&>ag("event","silent_test_success",{value:"1"}),clearTimeout(timer)},speechSynthesis.speak(utterance))},setBestMatchingVoice:function(voice,voiceURI,lang){if(null==this.voices||0==this.voices.length)return"";if(voice&&voice.voiceURI||voiceURI||lang||(this.voice&&this.voice.voiceURI?voiceURI=this.voice.voiceURI:lang=this.DEFAULT_LANG),voice&&(voiceURI=voice.voiceURI||voiceURI),voiceURI)for(const iVoice of this.voices)if(iVoice.voiceURI==voiceURI)return this.voice=iVoice,iVoice.voiceURI;if(lang){if(this.voice&&doCodesShareLanguage(this.voice.lang,lang))return this.voice.voiceURI;let filteredVoices=this.voices.filter((iVoice=>doCodesShareLanguage(iVoice.lang,lang)));if(filteredVoices&&filteredVoices.length>0){if(1==filteredVoices.length)return this.voice=filteredVoices[0],this.voice.voiceURI;if(!lang.startsWith("en")&&!lang.startsWith("es"))return this.voice=filteredVoices[0],this.voice.voiceURI;{let selectedVoice,selectedVoiceScore=-1;for(const iVoice of filteredVoices){let score=0;iVoice.localService&&(score+=1.5),2==iVoice.lang.length?score+=3:-1!=["en-us","en-uk","en-gb","es-es"].indexOf(iVoice.lang.toLowerCase().replace("_","-"))?score+=4:-1==["en-in"].indexOf(iVoice.lang.toLowerCase().replace("_","-"))&&(score+=2),score>selectedVoiceScore&&(selectedVoiceScore=score,selectedVoice=iVoice)}if(selectedVoice)return this.voice=selectedVoice,this.voice.voiceURI}}}for(const iVoice of this.voices)if(this.voice=iVoice,iVoice.localService)return iVoice.voiceURI;return this.voice.voiceURI},_populateVoices:function(isToAddServerTTS){let voices=window.speechSynthesis.getVoices();if(voices&&!(voices.length<1)){if(isToAddServerTTS){let additionalVoices=ServerTts.getVoices();for(const additionalVoice of additionalVoices)voices.push(additionalVoice)}voices&&voices.length>0&&(this.voices=voices.filter((voice=>{if(!voice.voiceURI.includes("com.apple.eloquence")&&!voice.voiceURI.includes("com.apple.speech.synthesis"))return voice})),this.setBestMatchingVoice(this.voice,null,null),this.listener&&this.listener.onInit&&this.listener.onInit(this.voices))}},setVoiceByUri:function(voiceURI){this.setBestMatchingVoice(null,voiceURI,null)},getVoiceURI:function(){return this.voice||this.setBestMatchingVoice(),this.voice?this.voice.voiceURI:""},setRate:function(rate){"string"==typeof rate&&(rate=Number(rate)),isNaN(rate)||(rate<.1&&(rate=.1),rate>4&&(rate=4),this.rate=rate)},isInitiated:function(){return null!=this.voices},_runOnWebspeechApiStart:function(ev){this.startedAndNotTerminatedCounter++,this._solveChromeBug()},_runOnWebspeechApiEnd:function(ev){this.startedAndNotTerminatedCounter>0&&this.startedAndNotTerminatedCounter--,this._clearUtteranceTimeouts()},_runOnWebspeechApiError:function(ev){this.startedAndNotTerminatedCounter>0&&this.startedAndNotTerminatedCounter--,this._clearUtteranceTimeouts()},_clearUtteranceTimeouts:function(){null!=this._googleBugTimeout&&(window.clearTimeout(this._googleBugTimeout),this._googleBugTimeout=null)},_solveChromeBug:function(){if(!this.voice)return;if(-1===this.voice.voiceURI.toLowerCase().indexOf("google"))return;this._clearUtteranceTimeouts();let self=this;this._googleBugTimeout=window.setTimeout((function(){window.speechSynthesis.pause(),window.speechSynthesis.resume(),self._solveChromeBug()}),1e4)},_prepareTextForSynthesis:function(text){let decodedText=text;return decodedText=decodedText.replace("·",", "),decodedText=decodedText.replace("- ",", "),decodedText.trim(),decodedText},generateAudioSync:function(utt,authToken,onDone,onError,optionalParamsAsJson){let id=""+SHA256(utt.text+utt.langBCP47+utt.voiceURI+utt.rate);ServerTts.generateAudioSync(utt.text,utt.voiceURI,utt.langBCP47,utt.rate,id,authToken,onDone,onError,optionalParamsAsJson)},speakAndBuffer:function(utt,bufferArray,authToken){if(utt.voiceURI.startsWith("ttsreaderServer")){let text=this._prepareTextForSynthesis(utt.text);if(!text)return this.listener.onStart(),void this.listener.onDone();let id=""+SHA256(text+utt.langBCP47+utt.voiceURI+utt.rate);const existingUtt=ServerTts.buffer.find((u=>u.id===id));existingUtt&&"done"===existingUtt.renderStatus?(existingUtt.wasPlayed=!1,existingUtt.onSuccess=()=>{},ServerTts.speak(id,{onStart:this.listener.onStart,onDone:this.listener.onDone,onError:this.listener.onError})):existingUtt&&"waiting"===existingUtt.renderStatus?(existingUtt.wasPlayed=!1,existingUtt.onSuccess=()=>{ServerTts.speak(id,{onStart:this.listener.onStart,onDone:this.listener.onDone,onError:this.listener.onError})},existingUtt.onError=()=>{this.listener.onError(error)}):ServerTts.bufferNewUtterance(text,utt.voiceURI,utt.langBCP47,utt.rate,id,authToken,(()=>{ServerTts.speak(id,{onStart:this.listener.onStart,onDone:this.listener.onDone,onError:this.listener.onError})}),(error=>{this.listener.onError(error)}),utt.isTest);for(const bufferUtt of bufferArray){let bufferText=this._prepareTextForSynthesis(bufferUtt.text),bufferId=""+SHA256(bufferText+bufferUtt.langBCP47+bufferUtt.voiceURI+bufferUtt.rate),existingBufferUtt=ServerTts.buffer.find((u=>u.id===bufferId));existingBufferUtt&&"error"!==existingBufferUtt.renderStatus||ServerTts.bufferNewUtterance(bufferText,bufferUtt.voiceURI,bufferUtt.langBCP47,bufferUtt.rate,bufferId,authToken,(()=>{}),(error=>{}),bufferUtt.isTest)}}else this.setVoiceByUri(utt.voiceURI),utt.rate=Math.min(utt.rate,2),utt.rate=Math.max(utt.rate,.5),this.setRate(utt.rate),this.speakOut(utt.text)},speakOut:function(text){let instance=this;if(this.startedAndNotTerminatedCounter>0||window.speechSynthesis.paused||window.speechSynthesis.pending||window.speechSynthesis.speaking)return this.stop(),void(this._speakTimeout=window.setTimeout((function(){instance.speakOut(text)}),200));if(!text)return void(this.utterance&&this.utterance.onend());if(text=this._prepareTextForSynthesis(text),!this.isInitiated())return!1;this.utteranceId++;let utterance=new SpeechSynthesisUtterance;this.utterance=utterance,utterance.text=text,null==this.voice&&this.setBestMatchingVoice(null,null,null),this.voice&&(utterance.lang=this.voice.lang,utterance.voiceURI=this.voice.voiceURI,utterance.voice=this.voice),utterance.rate=this.rate;let self=this;utterance.onmark=function(ev){},utterance.onstart=function(ev){(utterance.voice.voiceURI.toLowerCase().includes("google")||utterance.voiceURI?.toLowerCase()?.includes("google"))&&(self.removeLocalGoogleVoices=function(){}),self._runOnWebspeechApiStart(ev),self.listener&&self.listener.onStart&&self.listener.onStart()},utterance.onboundary=function(event){},utterance.onend=function(ev){self._runOnWebspeechApiEnd(ev),self.listener&&self.listener.onDone&&self.listener.onDone(),utterance=null},utterance.onerror=function(ev){self._runOnWebspeechApiError(ev),utterance=null},this._speakUtterance(utterance)},stop(){ServerTts.stop(),null!=this._speakTimeout&&(window.clearTimeout(this._speakTimeout),this._speakTimeout=null),window.speechSynthesis.cancel(),this.startedAndNotTerminatedCounter=0,this._canceledAtMs=Date.now()},_speakUtterance(utterance){null!=this._speakTimeout&&(window.clearTimeout(this._speakTimeout),this._speakTimeout=null),window.speechSynthesis.paused&&window.speechSynthesis.resume(),Date.now()-this._canceledAtMs>100?window.speechSynthesis.speak(utterance):this._speakTimeout=window.setTimeout((function(){window.speechSynthesis.speak(utterance)}),200)}}},{"./serverTts":2,"crypto-js/sha256":7}],5:[function(require,module,exports){exports.TtsEngine=require("./helpers/ttsEngine").TtsEngine},{"./helpers/ttsEngine":4}],6:[function(require,module,exports){(function(global){(function(){var root,factory;root=this,factory=function(){var CryptoJS=CryptoJS||function(Math,undefined){var crypto;if("undefined"!=typeof window&&window.crypto&&(crypto=window.crypto),"undefined"!=typeof self&&self.crypto&&(crypto=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(crypto=globalThis.crypto),!crypto&&"undefined"!=typeof window&&window.msCrypto&&(crypto=window.msCrypto),!crypto&&void 0!==global&&global.crypto&&(crypto=global.crypto),!crypto&&"function"==typeof require)try{crypto=require("crypto")}catch(err){}var cryptoSecureRandomInt=function(){if(crypto){if("function"==typeof crypto.getRandomValues)try{return crypto.getRandomValues(new Uint32Array(1))[0]}catch(err){}if("function"==typeof crypto.randomBytes)try{return crypto.randomBytes(4).readInt32LE()}catch(err){}}throw new Error("Native crypto module could not be used to get secure random number.")},create=Object.create||function(){function F(){}return function(obj){var subtype;return F.prototype=obj,subtype=new F,F.prototype=null,subtype}}(),C={},C_lib=C.lib={},Base=C_lib.Base={extend:function(overrides){var subtype=create(this);return overrides&&subtype.mixIn(overrides),subtype.hasOwnProperty("init")&&this.init!==subtype.init||(subtype.init=function(){subtype.$super.init.apply(this,arguments)}),subtype.init.prototype=subtype,subtype.$super=this,subtype},create:function(){var instance=this.extend();return instance.init.apply(instance,arguments),instance},init:function(){},mixIn:function(properties){for(var propertyName in properties)properties.hasOwnProperty(propertyName)&&(this[propertyName]=properties[propertyName]);properties.hasOwnProperty("toString")&&(this.toString=properties.toString)},clone:function(){return this.init.prototype.extend(this)}},WordArray=C_lib.WordArray=Base.extend({init:function(words,sigBytes){words=this.words=words||[],this.sigBytes=null!=sigBytes?sigBytes:4*words.length},toString:function(encoder){return(encoder||Hex).stringify(this)},concat:function(wordArray){var thisWords=this.words,thatWords=wordArray.words,thisSigBytes=this.sigBytes,thatSigBytes=wordArray.sigBytes;if(this.clamp(),thisSigBytes%4)for(var i=0;i<thatSigBytes;i++){var thatByte=thatWords[i>>>2]>>>24-i%4*8&255;thisWords[thisSigBytes+i>>>2]|=thatByte<<24-(thisSigBytes+i)%4*8}else for(var j=0;j<thatSigBytes;j+=4)thisWords[thisSigBytes+j>>>2]=thatWords[j>>>2];return this.sigBytes+=thatSigBytes,this},clamp:function(){var words=this.words,sigBytes=this.sigBytes;words[sigBytes>>>2]&=4294967295<<32-sigBytes%4*8,words.length=Math.ceil(sigBytes/4)},clone:function(){var clone=Base.clone.call(this);return clone.words=this.words.slice(0),clone},random:function(nBytes){for(var words=[],i=0;i<nBytes;i+=4)words.push(cryptoSecureRandomInt());return new WordArray.init(words,nBytes)}}),C_enc=C.enc={},Hex=C_enc.Hex={stringify:function(wordArray){for(var words=wordArray.words,sigBytes=wordArray.sigBytes,hexChars=[],i=0;i<sigBytes;i++){var bite=words[i>>>2]>>>24-i%4*8&255;hexChars.push((bite>>>4).toString(16)),hexChars.push((15&bite).toString(16))}return hexChars.join("")},parse:function(hexStr){for(var hexStrLength=hexStr.length,words=[],i=0;i<hexStrLength;i+=2)words[i>>>3]|=parseInt(hexStr.substr(i,2),16)<<24-i%8*4;return new WordArray.init(words,hexStrLength/2)}},Latin1=C_enc.Latin1={stringify:function(wordArray){for(var words=wordArray.words,sigBytes=wordArray.sigBytes,latin1Chars=[],i=0;i<sigBytes;i++){var bite=words[i>>>2]>>>24-i%4*8&255;latin1Chars.push(String.fromCharCode(bite))}return latin1Chars.join("")},parse:function(latin1Str){for(var latin1StrLength=latin1Str.length,words=[],i=0;i<latin1StrLength;i++)words[i>>>2]|=(255&latin1Str.charCodeAt(i))<<24-i%4*8;return new WordArray.init(words,latin1StrLength)}},Utf8=C_enc.Utf8={stringify:function(wordArray){try{return decodeURIComponent(escape(Latin1.stringify(wordArray)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(utf8Str){return Latin1.parse(unescape(encodeURIComponent(utf8Str)))}},BufferedBlockAlgorithm=C_lib.BufferedBlockAlgorithm=Base.extend({reset:function(){this._data=new WordArray.init,this._nDataBytes=0},_append:function(data){"string"==typeof data&&(data=Utf8.parse(data)),this._data.concat(data),this._nDataBytes+=data.sigBytes},_process:function(doFlush){var processedWords,data=this._data,dataWords=data.words,dataSigBytes=data.sigBytes,blockSize=this.blockSize,nBlocksReady=dataSigBytes/(4*blockSize),nWordsReady=(nBlocksReady=doFlush?Math.ceil(nBlocksReady):Math.max((0|nBlocksReady)-this._minBufferSize,0))*blockSize,nBytesReady=Math.min(4*nWordsReady,dataSigBytes);if(nWordsReady){for(var offset=0;offset<nWordsReady;offset+=blockSize)this._doProcessBlock(dataWords,offset);processedWords=dataWords.splice(0,nWordsReady),data.sigBytes-=nBytesReady}return new WordArray.init(processedWords,nBytesReady)},clone:function(){var clone=Base.clone.call(this);return clone._data=this._data.clone(),clone},_minBufferSize:0}),C_algo=(C_lib.Hasher=BufferedBlockAlgorithm.extend({cfg:Base.extend(),init:function(cfg){this.cfg=this.cfg.extend(cfg),this.reset()},reset:function(){BufferedBlockAlgorithm.reset.call(this),this._doReset()},update:function(messageUpdate){return this._append(messageUpdate),this._process(),this},finalize:function(messageUpdate){return messageUpdate&&this._append(messageUpdate),this._doFinalize()},blockSize:16,_createHelper:function(hasher){return function(message,cfg){return new hasher.init(cfg).finalize(message)}},_createHmacHelper:function(hasher){return function(message,key){return new C_algo.HMAC.init(hasher,key).finalize(message)}}}),C.algo={});return C}(Math);return CryptoJS},"object"==typeof exports?module.exports=exports=factory():"function"==typeof define&&define.amd?define([],factory):root.CryptoJS=factory()}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{crypto:8}],7:[function(require,module,exports){var root,factory;root=this,factory=function(CryptoJS){return function(Math){var C=CryptoJS,C_lib=C.lib,WordArray=C_lib.WordArray,Hasher=C_lib.Hasher,C_algo=C.algo,H=[],K=[];!function(){function isPrime(n){for(var sqrtN=Math.sqrt(n),factor=2;factor<=sqrtN;factor++)if(!(n%factor))return!1;return!0}function getFractionalBits(n){return 4294967296*(n-(0|n))|0}for(var n=2,nPrime=0;nPrime<64;)isPrime(n)&&(nPrime<8&&(H[nPrime]=getFractionalBits(Math.pow(n,.5))),K[nPrime]=getFractionalBits(Math.pow(n,1/3)),nPrime++),n++}();var W=[],SHA256=C_algo.SHA256=Hasher.extend({_doReset:function(){this._hash=new WordArray.init(H.slice(0))},_doProcessBlock:function(M,offset){for(var H=this._hash.words,a=H[0],b=H[1],c=H[2],d=H[3],e=H[4],f=H[5],g=H[6],h=H[7],i=0;i<64;i++){if(i<16)W[i]=0|M[offset+i];else{var gamma0x=W[i-15],gamma0=(gamma0x<<25|gamma0x>>>7)^(gamma0x<<14|gamma0x>>>18)^gamma0x>>>3,gamma1x=W[i-2],gamma1=(gamma1x<<15|gamma1x>>>17)^(gamma1x<<13|gamma1x>>>19)^gamma1x>>>10;W[i]=gamma0+W[i-7]+gamma1+W[i-16]}var maj=a&b^a&c^b&c,sigma0=(a<<30|a>>>2)^(a<<19|a>>>13)^(a<<10|a>>>22),t1=h+((e<<26|e>>>6)^(e<<21|e>>>11)^(e<<7|e>>>25))+(e&f^~e&g)+K[i]+W[i];h=g,g=f,f=e,e=d+t1|0,d=c,c=b,b=a,a=t1+(sigma0+maj)|0}H[0]=H[0]+a|0,H[1]=H[1]+b|0,H[2]=H[2]+c|0,H[3]=H[3]+d|0,H[4]=H[4]+e|0,H[5]=H[5]+f|0,H[6]=H[6]+g|0,H[7]=H[7]+h|0},_doFinalize:function(){var data=this._data,dataWords=data.words,nBitsTotal=8*this._nDataBytes,nBitsLeft=8*data.sigBytes;return dataWords[nBitsLeft>>>5]|=128<<24-nBitsLeft%32,dataWords[14+(nBitsLeft+64>>>9<<4)]=Math.floor(nBitsTotal/4294967296),dataWords[15+(nBitsLeft+64>>>9<<4)]=nBitsTotal,data.sigBytes=4*dataWords.length,this._process(),this._hash},clone:function(){var clone=Hasher.clone.call(this);return clone._hash=this._hash.clone(),clone}});C.SHA256=Hasher._createHelper(SHA256),C.HmacSHA256=Hasher._createHmacHelper(SHA256)}(Math),CryptoJS.SHA256},"object"==typeof exports?module.exports=exports=factory(require("./core")):"function"==typeof define&&define.amd?define(["./core"],factory):factory(root.CryptoJS)},{"./core":6}],8:[function(require,module,exports){},{}]},{},[1]);