import{p as b,a as C,G as S,j as s,A as E,B as $,I as M,c as F,r as l,y as q,L as P,u as Z,b as Y,M as K,R as V}from"./globals-D5qvHE40.js";const f={log:e=>{},warn:e=>{},error:(e,n)=>{}};/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Q=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3",key:"1u773s"}],["path",{d:"M12 17h.01",key:"p32p05"}]],W=b("circle-question-mark",Q);/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const X=[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],J=b("loader-circle",X);/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ee=[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]],te=b("mic",ee);/**
 * @license lucide-react v0.562.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const se=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],ne=b("trash-2",se),re=C(S.STORAGE_KEYS.SUBTITLE_BG_COLOR,"#000000"),ae=C(S.STORAGE_KEYS.SUBTITLE_FONT_COLOR,"#ffffff"),oe=C(S.STORAGE_KEYS.SUBTITLE_FONT_SIZE,24),ce=({bgColor:e,onBgColorChange:n})=>s.jsx(E,{tooltipText:"Color de fondo",children:s.jsx("input",{type:"color",value:e,onChange:t=>n(t.target.value),className:"h-7 w-7 cursor-pointer rounded border-0 bg-transparent p-0.5"})}),le=({onClear:e})=>s.jsx(E,{tooltipText:"Limpiar historial de subt\xEDtulos",children:s.jsx($,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:e,children:s.jsx(ne,{className:"h-4 w-4"})})}),ie=({fontColor:e,onFontColorChange:n})=>s.jsx(E,{tooltipText:"Color de fuente",children:s.jsx("input",{type:"color",value:e,onChange:t=>n(t.target.value),className:"h-7 w-7 cursor-pointer rounded border-0 bg-transparent p-0.5"})}),ue=({fontSize:e,onFontSizeChange:n})=>s.jsx(E,{tooltipText:"Tama\xF1o de fuente (16\u201372px)",children:s.jsx(M,{type:"number",min:16,max:72,step:2,value:e,onChange:t=>{const r=Math.min(72,Math.max(16,Number(t.target.value)));n(r)},className:"h-7 w-16 text-xs"})}),de=({fontSize:e,onFontSizeChange:n,fontColor:t,onFontColorChange:r,bgColor:a,onBgColorChange:o,onClear:i})=>s.jsxs("div",{className:"absolute top-1 right-1 z-50 flex items-center gap-1.5 rounded-md bg-black/30 px-2 py-1 opacity-30 transition-opacity hover:opacity-100",children:[s.jsx(ue,{fontSize:e,onFontSizeChange:n}),s.jsx(ie,{fontColor:t,onFontColorChange:r}),s.jsx(ce,{bgColor:a,onBgColorChange:o}),s.jsx(le,{onClear:i})]}),I={FREEZE_HELP_LABEL:"\xBFSe congelan los subt\xEDtulos en OBS?",FREEZE_HELP_URL:"https://estrellaswebcam.com/guides/extensiones/redna-models/funcionalidades/traductor-voz/#los-subt%C3%ADtulos-se-congelan-cuando-otra-ventana-cubre-chrome"},he=({href:e,label:n,className:t})=>s.jsxs("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:F("flex items-center gap-1.5 rounded-md bg-black/30 px-2 py-1 text-xs text-white no-underline opacity-30 transition-opacity hover:opacity-100",t),children:[s.jsx(W,{className:"size-4 shrink-0"}),n]}),pe=(e,n)=>{const t=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16);return`rgba(${t}, ${r}, ${a}, ${n})`},xe=({text:e,opacity:n,fontSize:t,color:r,bgColor:a})=>s.jsx("p",{className:F("m-0 px-6 py-1 leading-tight font-bold drop-shadow-lg","rounded-lg",!a&&"bg-black/80",!t&&"text-4xl",!r&&"text-white"),style:{opacity:n,transition:"opacity 0.3s ease",...a&&{backgroundColor:pe(a,.8)},...t&&{fontSize:`${t}px`},...r&&{color:r}},children:e}),ge=()=>s.jsx("div",{className:"flex w-full items-center justify-end px-6",children:s.jsx(te,{className:"h-10 w-10 animate-pulse rounded-md bg-white/60 p-2"})}),me=({onRetry:e})=>{const[n,t]=l.useState("idle"),[r,a]=l.useState(0),o=l.useRef(!1),i=()=>{o.current||(o.current=!0,t("downloading"),e(c=>a(c)).catch(()=>{t("error"),o.current=!1}))};if(n==="error")return s.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-black",children:s.jsx("p",{className:"px-8 text-center text-2xl text-red-400",children:"No se pudo descargar el modelo. Recarga la p\xE1gina e intenta de nuevo."})});if(n==="downloading"){const c=Math.round(r*100);return s.jsxs("div",{className:"flex h-screen w-screen flex-col items-center justify-center gap-6 bg-black",children:[s.jsx(J,{className:"h-12 w-12 animate-spin text-white/70"}),s.jsx("p",{className:"text-xl text-white/80",children:"Descargando modelo de traducci\xF3n\u2026"}),c>0&&s.jsxs("p",{className:"text-lg text-white/50",children:[c,"%"]})]})}return s.jsxs("div",{className:"flex h-screen w-screen flex-col items-center justify-center gap-6 bg-black",children:[s.jsx(q,{className:"h-12 w-12 text-white/60"}),s.jsxs("div",{className:"flex max-w-md flex-col items-center gap-3 px-8 text-center",children:[s.jsx("p",{className:"text-2xl font-medium text-white",children:"Modelo de traducci\xF3n no descargado"}),s.jsx("p",{className:"text-base text-white/60",children:"Escribe algo en el campo de abajo para iniciar la descarga."})]}),s.jsx(M,{className:"w-64 border-white/30 bg-white/10 text-white placeholder:text-white/40",placeholder:"Escribe aqu\xED para iniciar\u2026",onChange:i})]})},k=async({sourceLanguage:e,targetLanguage:n})=>await Translator.availability({sourceLanguage:e,targetLanguage:n}),j={isAvailable:()=>"Translator"in globalThis,isModelAvailable:k,create:async({sourceLanguage:e,targetLanguage:n,onProgress:t})=>{const r=await k({sourceLanguage:e,targetLanguage:n});return await Translator.create({sourceLanguage:e,targetLanguage:n,monitor(o){r!=="available"&&o.addEventListener("downloadprogress",i=>{f.log(`Downloaded ${i.loaded*100}%`),t==null||t(i.loaded)})}})}};function _(e){return e instanceof DOMException&&e.name==="NotAllowedError"?{kind:"user-gesture-required",message:e.message}:{kind:"generic",message:"Error al inicializar el traductor."}}const fe=(e,n)=>{const t=l.useRef(null),[r,a]=l.useState(null);l.useEffect(()=>{let i=!0;return(async()=>{if(!j.isAvailable()){a({kind:"unavailable",message:"Translator API no disponible. Requiere Chrome 138+."});return}try{const u=await j.create({sourceLanguage:e,targetLanguage:n});i&&(t.current=u)}catch(u){f.error(u.message),i&&a(_(u))}})(),()=>{i=!1}},[e,n]);const o=l.useCallback(async i=>{a(null);try{const c=await j.create({sourceLanguage:e,targetLanguage:n,onProgress:i});t.current=c}catch(c){f.error(c.message),a(_(c))}},[e,n]);return{translatorRef:t,error:r,retry:o}},be=8,Se=e=>{const[n,t]=l.useState([]),[r,a]=l.useState(!1),o=l.useRef(null),i=l.useCallback(async(u,x)=>{if(!x||!e.current)return;o.current&&(await o.current.cancel(),o.current=null);const m=e.current.translateStreaming(u).getReader();o.current=m;let g="";try{for(;;){const{done:p,value:w}=await m.read();if(p)break;g=w}g&&t(p=>[...p.slice(-(be-1)),g])}catch{}finally{a(!1)}},[e]),c=l.useCallback(()=>t([]),[]);return{lines:n,isTranslating:r,setIsTranslating:a,handleTranscript:i,clearLines:c}},L={isAvailable:()=>typeof globalThis<"u"&&("SpeechRecognition"in globalThis||"webkitSpeechRecognition"in globalThis),create:({lang:e,onSpeechStart:n,onResult:t,onEnd:r,onError:a})=>{const o=globalThis,i=o.SpeechRecognition??o.webkitSpeechRecognition,c=new i;return c.lang=e,c.continuous=!0,c.interimResults=!0,c.onspeechstart=n,c.onresult=u=>{for(let x=u.resultIndex;x<u.results.length;x++){const h=u.results[x];t(h[0].transcript,h.isFinal)}},c.onend=r,c.onerror=a,c}},Ee=1e4,we=({lang:e,onSpeechStart:n,onResult:t})=>{const r=l.useRef(null),a=l.useRef(!1),o=l.useRef(null),[i,c]=l.useState(null),u=L.isAvailable();l.useEffect(()=>{if(a.current=!1,!u){c("Web Speech API no disponible en este entorno.");return}const h=()=>{o.current!==null&&(clearInterval(o.current),o.current=null)},m=()=>{h(),o.current=setInterval(()=>{var p;(p=r.current)==null||p.stop()},Ee)},g=L.create({lang:e,onSpeechStart:n,onResult:t,onEnd:()=>{if(!a.current&&r.current)try{r.current.start(),m()}catch(p){f.error(p.message)}},onError:p=>{p.error==="not-allowed"&&c("Permiso de micr\xF3fono denegado. Habil\xEDtalo en la configuraci\xF3n del navegador.")}});return r.current=g,g.start(),m(),()=>{a.current=!0,h(),g.stop()}},[e,n,t,u]);const x=l.useCallback(()=>{var h;a.current=!0,o.current!==null&&(clearInterval(o.current),o.current=null),(h=r.current)==null||h.stop()},[]);return{error:i,stop:x}},A=S.SPEECH_TO_TRANSLATE_CONFIG.SOURCE_LANGUAGE,Te=e=>{const{translatorRef:n,error:t,retry:r}=fe(A,e),{lines:a,isTranslating:o,setIsTranslating:i,handleTranscript:c,clearLines:u}=Se(n),x=l.useCallback(()=>i(!0),[i]),{error:h,stop:m}=we({lang:A,onSpeechStart:x,onResult:c}),g=(t==null?void 0:t.kind)==="user-gesture-required"?h:(t==null?void 0:t.message)??h;return{lines:a,isTranslating:o,error:g,translatorError:t,retry:r,stop:m,clearLines:u}},ye=()=>{const e=P(),n=Z(),t=Y(),r=oe(),a=ae(),o=re(),[i,c]=l.useState("en"),[u,x]=l.useState(24),[h,m]=l.useState("#ffffff"),[g,p]=l.useState("#000000");l.useEffect(()=>{e.getItem().then(c),e.watchItem(c)},[e]),l.useEffect(()=>{r.getItem().then(x),r.watchItem(x)},[r]),l.useEffect(()=>{a.getItem().then(m),a.watchItem(m)},[a]),l.useEffect(()=>{o.getItem().then(p),o.watchItem(p)},[o]);const{lines:w,isTranslating:B,error:T,translatorError:y,retry:O,stop:v,clearLines:G}=Te(i);l.useEffect(()=>{n.watchItem(d=>{d||(v(),window.close())})},[n,v,T]),l.useEffect(()=>{const d=()=>{n.setItem(!1),t.setItem(null)};return window.addEventListener("beforeunload",d),()=>window.removeEventListener("beforeunload",d)},[n,t]);const z=d=>{x(d),r.setItem(d)},D=d=>{m(d),a.setItem(d)},U=d=>{p(d),o.setItem(d)},R=w.slice(-8);return(y==null?void 0:y.kind)==="user-gesture-required"?s.jsx(me,{onRetry:O}):T?s.jsx("div",{className:"flex h-screen w-screen items-center justify-center bg-black",children:s.jsx("p",{className:"px-8 text-center text-2xl text-red-400",children:T})}):s.jsxs("div",{className:"relative flex h-screen w-screen flex-col justify-end bg-green-400 pb-8",children:[s.jsx(de,{fontSize:u,onFontSizeChange:z,fontColor:h,onFontColorChange:D,bgColor:g,onBgColorChange:U,onClear:G}),s.jsx(he,{href:I.FREEZE_HELP_URL,label:I.FREEZE_HELP_LABEL,className:"absolute top-1 left-1 z-50"}),s.jsxs("div",{className:"flex flex-col items-start justify-center gap-2 py-4",children:[R.map((d,N)=>{const H=.3+.7*(N+1)/R.length;return s.jsx(xe,{text:d,opacity:H,fontSize:u,color:h,bgColor:g},`${N}-${d}`)}),B?s.jsx(ge,{}):s.jsx("div",{className:"h-10"})]})]})};K.createRoot(document.getElementById("root")).render(s.jsx(V.StrictMode,{children:s.jsx(ye,{})}));
