import{p as b,a as C,G as S,j as s,A as w,B as D,I as M,c as B,r as l,y as q,L as P,u as Z,b as Y,M as K,R as V}from"./globals-iCg_yXGa.js";const x={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(w,{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(w,{tooltipText:"Limpiar historial de subtítulos",children:s.jsx(D,{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(w,{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(w,{tooltipText:"Tamaño de fuente (16–72px)",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:"¿Se congelan los subtítulos 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:B("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})`},ge=({text:e,opacity:n,fontSize:t,color:r,bgColor:a})=>s.jsx("p",{className:B("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}),me=()=>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"})}),fe=({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ágina 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ón…"}),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ón 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í para iniciar…",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=>{x.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 xe=(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){x.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){x.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,g)=>{if(!g||!e.current)return;o.current&&(await o.current.cancel(),o.current=null);const f=e.current.translateStreaming(u).getReader();o.current=f;let m="";try{for(;;){const{done:p,value:T}=await f.read();if(p)break;m=T}m&&t(p=>[...p.slice(-(be-1)),m])}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 g=u.resultIndex;g<u.results.length;g++){const h=u.results[g];t(h[0].transcript,h.isFinal)}},c.onend=r,c.onerror=a,c}},we=1e4,Te=({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)},f=()=>{h(),o.current=setInterval(()=>{var p;(p=r.current)==null||p.stop()},we)},m=L.create({lang:e,onSpeechStart:n,onResult:t,onEnd:()=>{if(!a.current&&r.current)try{r.current.start(),f()}catch(p){x.error(p.message)}},onError:p=>{p.error==="not-allowed"&&c("Permiso de micrófono denegado. Habilítalo en la configuración del navegador.")}});return r.current=m,m.start(),f(),()=>{a.current=!0,h(),m.stop()}},[e,n,t,u]);const g=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:g}},A=S.SPEECH_TO_TRANSLATE_CONFIG.SOURCE_LANGUAGE,ye=e=>{const{translatorRef:n,error:t,retry:r}=xe(A,e),{lines:a,isTranslating:o,setIsTranslating:i,handleTranscript:c,clearLines:u}=Se(n),g=l.useCallback(()=>i(!0),[i]),{error:h,stop:f}=Te({lang:A,onSpeechStart:g,onResult:c}),m=(t==null?void 0:t.kind)==="user-gesture-required"?h:(t==null?void 0:t.message)??h;return{lines:a,isTranslating:o,error:m,translatorError:t,retry:r,stop:f,clearLines:u}},Ee=()=>{const e=P(),n=Z(),t=Y(),r=oe(),a=ae(),o=re(),[i,c]=l.useState("en"),[u,g]=l.useState(24),[h,f]=l.useState("#ffffff"),[m,p]=l.useState("#000000");l.useEffect(()=>{e.getItem().then(c),e.watchItem(c)},[e]),l.useEffect(()=>{r.getItem().then(g),r.watchItem(g)},[r]),l.useEffect(()=>{a.getItem().then(f),a.watchItem(f)},[a]),l.useEffect(()=>{o.getItem().then(p),o.watchItem(p)},[o]);const{lines:T,isTranslating:F,error:y,translatorError:E,retry:O,stop:v,clearLines:G}=ye(i);l.useEffect(()=>{n.watchItem(d=>{d||(v(),window.close())})},[n,v,y]),l.useEffect(()=>{const d=()=>{n.setItem(!1),t.setItem(null)};return window.addEventListener("beforeunload",d),()=>window.removeEventListener("beforeunload",d)},[n,t]);const z=d=>{g(d),r.setItem(d)},U=d=>{f(d),a.setItem(d)},H=d=>{p(d),o.setItem(d)},R=T.slice(-8);return(E==null?void 0:E.kind)==="user-gesture-required"?s.jsx(fe,{onRetry:O}):y?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:y})}):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:U,bgColor:m,onBgColorChange:H,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 $=.3+.7*(N+1)/R.length;return s.jsx(ge,{text:d,opacity:$,fontSize:u,color:h,bgColor:m},`${N}-${d}`)}),F?s.jsx(me,{}):s.jsx("div",{className:"h-10"})]})]})};K.createRoot(document.getElementById("root")).render(s.jsx(V.StrictMode,{children:s.jsx(Ee,{})}));
