var background=function(){"use strict";var _,g;function I(t){return t==null||typeof t=="function"?{main:t}:t}const A=(g=(_=globalThis.browser)==null?void 0:_.runtime)!=null&&g.id?globalThis.browser:globalThis.chrome,s={STORAGE_KEYS:{QUICK_MENU_IS_ACTIVE:"quickMenuIsActive",QUICK_MESSAGES_IS_ACTIVE:"quickMessagesIsActive",QUICK_MESSAGES:"quickMessages",LOCAL_TRANSLATOR_TARGET_LANGUAGE:"localTranslatorTargetLanguage",TRANSLATOR_IS_ACTIVE:"translatorIsActive",UPDATE_NOTIFICATION_LAST_SHOWN:"updateNotificationLastShown",SPEECH_TO_TRANSLATE_IS_ACTIVE:"speechToTranslateIsActive",SPEECH_TO_TRANSLATE_TAB_ID:"speechToTranslateTabId",SUBTITLE_FONT_SIZE:"subtitleFontSize",SUBTITLE_FONT_COLOR:"subtitleFontColor",SUBTITLE_BG_COLOR:"subtitleBgColor",SELECTION_TRANSLATOR_IS_ACTIVE:"selectionTranslatorIsActive",SELECTION_TRANSLATOR_TARGET_LANGUAGE:"selectionTranslatorTargetLanguage",CHATUR_CLEAN_CHAT_IS_ACTIVE:"chaturCleanChatIsActive"},SPEECH_TO_TRANSLATE_CONFIG:{SOURCE_LANGUAGE:"es"},ERROR_MESSAGES:{SC_ELEMENTS_NOT_READY:"Some elements are not available yet.",QM_NOT_MESSAGES:"No messages found."},BG_MESSAGE_TYPE:{CHAT_MESSAGE:"CHAT_MESSAGE",INPUT_MESSAGE:"INPUT_MESSAGE",CHECK_EXT_UPLOAD:"CHECK_EXT_UPLOAD",SELECTION_MESSAGE:"SELECTION_MESSAGE"},APP_INFORMATION:{APP_NAME:"Redna Models",APP_NAME_SHORT:"Redna",APP_DIVISION:"Models",APP_PROVIDER:"Estrellas Webcam"},ESTRELLAS_WEB_BASEURL:{PRODUCTION:"https://www.estrellaswebcam.com",DEV:"http://localhost:4321"}};Object.freeze(s);const C=(t,r)=>{const e=t.split(".").map(Number),a=r.split(".").map(Number);for(;e.length<3;)e.push(0);for(;a.length<3;)a.push(0);for(let n=0;n<3;n++){if(e[n]>a[n])return!0;if(e[n]<a[n])return!1}return!1},d={log:t=>{},warn:t=>{},error:(t,r)=>{}},T={isAvailable:()=>"LanguageDetector"in self,create:async()=>await LanguageDetector.create({monitor(r){r.addEventListener("downloadprogress",e=>{d.log(`Downloaded ${e.loaded*100}%`)})}}),detectLanguage:async t=>{var a;return(a=(await(await T.create()).detect(t)).at(0))==null?void 0:a.detectedLanguage}},S=async({sourceLanguage:t,targetLanguage:r})=>await Translator.availability({sourceLanguage:t,targetLanguage:r}),o={isAvailable:()=>"Translator"in globalThis,isModelAvailable:S,create:async({sourceLanguage:t,targetLanguage:r,onProgress:e})=>{const a=await S({sourceLanguage:t,targetLanguage:r});return await Translator.create({sourceLanguage:t,targetLanguage:r,monitor(E){a!=="available"&&E.addEventListener("downloadprogress",L=>{d.log(`Downloaded ${L.loaded*100}%`),e==null||e(L.loaded)})}})}};class c{static async _detectAndTranslate(r,e){if(!o.isAvailable()||!T.isAvailable())return;const a=await T.detectLanguage(r);return a===e?{translatedText:r,sourceLanguage:a}:{translatedText:await(await o.create({sourceLanguage:a??"en",targetLanguage:e})).translate(r),sourceLanguage:a??"en"}}static async handleChatMessage(r){try{if(!r)return;const e=await c._detectAndTranslate(r,"es");return e?e.translatedText:void 0}catch{return}}static async handleInputMessage(r,e){try{return o.isAvailable()?await(await o.create({sourceLanguage:"es",targetLanguage:e||"en"})).translate(r):void 0}catch{return}}static async handleSelectionMessage(r,e){try{return await c._detectAndTranslate(r,e)}catch{return}}static async handleCheckExtUpload(){const r=A.runtime.getManifest().version,e=s.ESTRELLAS_WEB_BASEURL.PRODUCTION;try{const{version:a}=await fetch(`${e}/downloads/redna/models/metadata.json`).then(E=>E.json());if(C(a,r))return{latestVersion:a,downloadUrl:`${e}/descargas`}}catch{}}}const l=c,h=I(()=>{A.runtime.onMessage.addListener((t,r,e)=>{switch(t.type){case s.BG_MESSAGE_TYPE.CHAT_MESSAGE:(async()=>{const a=await l.handleChatMessage(t.data);e(a)})();break;case s.BG_MESSAGE_TYPE.INPUT_MESSAGE:(async()=>{const a=await l.handleInputMessage(t.data,t.target);e(a)})();break;case s.BG_MESSAGE_TYPE.CHECK_EXT_UPLOAD:(async()=>{const a=await l.handleCheckExtUpload();e(a)})();break;case s.BG_MESSAGE_TYPE.SELECTION_MESSAGE:(async()=>{const a=await l.handleSelectionMessage(t.data,t.target);e(a)})();break}return!0})});function O(){}function i(t,...r){}const b={debug:(...t)=>i(console.debug,...t),log:(...t)=>i(console.log,...t),warn:(...t)=>i(console.warn,...t),error:(...t)=>i(console.error,...t)};let u;try{u=h.main(),u instanceof Promise&&console.warn("The background's main() function return a promise, but it must be synchronous")}catch(t){throw b.error("The background crashed on startup!"),t}return u}();
