PageSourceSearch

https://uniai.ai/assets/DocumentTranslatePage--jx6Zr2t.js

js uniai.ai collected 2026-10-05 13:11:38 UTC 25,576 bytes, 28 lines download raw bytes

1import{b as gt,aZ as xt,r as c,aQ as pt,bI as L,z as H,j as e,bu as ht,F as E,X as He,D as ft,w as yt,T as bt,a2 as xe,ak as vt,L as jt,as as Ee,bG as wt,bH as Nt,bX as pe,b5 as St}from"./index-BawMCgu8.js";import{L as Fe}from"./LanguageDropdown-CjWQVSie.js";import{u as kt}from"./chat-Cp3tSG9E.js";import{F as $t}from"./file-down-BLVBqil9.js";import{H as Ae}from"./history-CWHZzLwH.js";import{A as Oe}from"./arrow-right-left-6Rvk9MW1.js";import{F as Ue}from"./file-type-nKRGBr5R.js";import"./locale-en-B8Z5F_o1.js";import"./locale-zh-CN-CFdD1mPv.js";import"./locale-fr-j4CMJpfE.js";import"./locale-de-DuE2gagy.js";import"./locale-it-C6yb6RzN.js";import"./locale-ja-VjZBy5eF.js";import"./locale-ko-Cl0W-Az5.js";import"./locale-es-DwboUZze.js";import"./locale-zh-Hant-uT5aTnfX.js";import"./locale-ru-DEr1xfTZ.js";import"./locale-id-Buh3Uolz.js";import"./locale-pt-BR-CqD5J4_0.js";function Be(r){if(!r)return"";let o=r;o=o.replace(/\$\$([\s\S]+?)\$\$/g,(d,l)=>{try{return pe.renderToString(l.trim(),{displayMode:!0,throwOnError:!1})}catch{return`<pre>${l}</pre>`}}),o=o.replace(/\\\[([\s\S]+?)\\\]/g,(d,l)=>{try{return pe.renderToString(l.trim(),{displayMode:!0,throwOnError:!1})}catch{return`<pre>${l}</pre>`}}),o=o.replace(/(^|[^$\\])\$(?!\s)([^$]+?)\$(?!\w)/g,(d,l,i)=>{try{return l+pe.renderToString(i.trim(),{displayMode:!1,throwOnError:!1})}catch{return`${l}<code>${i}</code>`}});try{return St.parse(o,{async:!1,gfm:!0,breaks:!0})}catch{return r}}const ze=1500,Lt=8,Tt=6e3;function _t(r){const o=r.trim();return/^!\[.*\]\(.*\)$/.test(o)||/^<img\s[^>]*\/?>$/i.test(o)}function Ct(r){const o=r.trim();return/^\$\$[\s\S]+\$\$$/.test(o)||/^\\\[[\s\S]+\\\]$/.test(o)||/^<mjx-container[\s\S]*<\/mjx-container>$/i.test(o)}function Ge(r){return r?r.replace(/\r\n/g,`
2`).split(/\n{2,}/).map(o=>o.trim()).filter(o=>o.length>0):[]}function Rt(r,o){const d=r.split(new RegExp("(?<=[.!?。!?])\\s+"));if(d.length>1){const i=[];let n="";for(const h of d)n.length+h.length>o&&n?(i.push(n.trim()),n=h):n+=(n?" ":"")+h;return n&&i.push(n.trim()),i}const l=[];for(let i=0;i<r.length;i+=o)l.push(r.slice(i,i+o));return l}function Mt(r){if(!r)return{processed:"",mathPlaceholders:{}};let o=0;const d={};let l=r;return l=l.replace(/<mjx-container[^>]*>[\s\S]*?<\/mjx-container>/gi,i=>{const n=`_mh_${o}_`;return d[n]=i,o++,n}),l=l.replace(/<\/?(table|thead|tbody|tr|td|th)[^>]*>/gi,i=>{const n=`_ht_${o}_`;return d[n]=i,o++,n}),l=l.replace(/\$\$[\s\S]+?\$\$/g,i=>{const n=`_mh_${o}_`;return d[n]=i,o++,n}),l=l.replace(/\\\[[\s\S]+?\\\]/g,i=>{const n=`_mh_${o}_`;return d[n]=i,o++,n}),l=l.replace(/(^|[^$])\$(?!\s)([^$]+?)\$(?!\w)/g,(i,n,h)=>{const x=`_mh_${o}_`;return d[x]=`$${h}$`,o++,`${n}${x}`}),{processed:l,mathPlaceholders:d}}function It(r,o){return!r||!o?r:r.replace(/_\s*(ht|mh)\s*_\s*(\d+)\s*_/gi,(d,l,i)=>{const n=`_${l.toLowerCase()}_${i}_`;return o[n]||d})}function ee(r){const o=Ge(r),d=[],l=new Set;return o.forEach((i,n)=>{if(i){if(_t(i)||Ct(i)){l.add(n);return}if(i.length<=ze){d.push({segmentId:d.length,paragraphIndex:n,text:i,chunkOrder:0});return}Rt(i,ze).forEach((h,x)=>{d.push({segmentId:d.length,paragraphIndex:n,text:h,chunkOrder:x})})}}),{paragraphs:o,segments:d,skipIndices:l}}function Pt(r){if(!r.length)return[];const o=[];let d=[],l=0;const i=()=>{d.length&&(o.push({payload:d.map(n=>n.processedText||n.text),segments:[...d]}),d=[],l=0)};for(const n of r){const{processed:h,mathPlaceholders:x}=Mt(n.text),b={...n,processedText:h,mathPlaceholders:x},I=h.length||1;d.length&&(d.length>=Lt||l+I>Tt)&&i(),d.push(b),l+=I}return i(),o}const X="prose prose-sm max-w-none dark:prose-invert text-[var(--text-primary)]",te=c.memo(()=>e.jsx("div",{className:"flex flex-col gap-2.5 py-1",children:[0,1,2].map(r=>e.jsx("div",{className:`h-[22px] rounded-lg ${r===2?"w-[70%]":"w-full"}`,style:{background:"linear-gradient(90deg,rgba(156,163,175,.15) 10%,rgba(156,163,175,.3) 35%,rgba(156,163,175,.5) 50%,rgba(156,163,175,.3) 65%,rgba(156,163,175,.15) 90%)",backgroundSize:"600% 100%",animation:"skeleton-wave 1.2s ease-in-out infinite"}},r))})),Dt=c.memo(function({original:o,translation:d,isTranslating:l,isSkipped:i,displayMode:n}){const h=c.useMemo(()=>Be(o),[o]),x=c.useMemo(()=>d?Be(d):"",[d]),b=x?e.jsx("div",{className:`${X} rounded-lg px-3 py-2 bg-[var(--bg-tertiary)] [&_h1]:mt-0 [&_h2]:mt-0 [&_h3]:mt-0`,dangerouslySetInnerHTML:{__html:x}}):l&&!i?e.jsx("div",{className:"rounded-lg px-3 py-2 bg-[var(--bg-tertiary)]",children:e.jsx(te,{})}):null;return n==="translationOnly"?x?e.jsx("div",{className:X,dangerouslySetInnerHTML:{__html:x}}):l&&!i?e.jsx(te,{}):null:n==="sideBySide"?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 py-3 px-3 rounded-md hover:bg-[var(--bg-tertiary)] transition-colors items-start",children:[e.jsx("div",{className:X,dangerouslySetInnerHTML:{__html:h}}),e.jsx("div",{className:X,children:x?e.jsx("div",{dangerouslySetInnerHTML:{__html:x}}):l&&!i?e.jsx(te,{}):null})]}):e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx("div",{className:X,dangerouslySetInnerHTML:{__html:h}}),b]})}),he=[{ext:".pdf",name:"PDF",icon:E},{ext:".docx",name:"DOCX",icon:Ue},{ext:".doc",name:"DOC",icon:Ue},{ext:".pptx",name:"PPTX",icon:E},{ext:".ppt",name:"PPT",icon:E},{ext:".png",name:"PNG",icon:xe},{ext:".jpg",name:"JPG",icon:xe},{ext:".jpeg",name:"JPEG",icon:xe}],Xe="doc_translate_page_state";function Ht(){try{const r=localStorage.getItem(Xe);return r?JSON.parse(r):null}catch{return null}}function sr(){var Me;const{t:r,i18n:o}=gt(),{requireAuth:d}=xt(),{selectedModel:l,setSelectedModel:i}=kt(),n=c.useRef(Ht()).current,h=c.useRef(null),x=c.useRef(null),b=c.useRef(null),I=c.useRef(!1),[S,fe]=c.useState((n==null?void 0:n.sourceLang)||"auto"),[k,ye]=c.useState((n==null?void 0:n.targetLang)||"en-US"),[F]=c.useState((n==null?void 0:n.style)||"direct"),[P,qe]=c.useState((n==null?void 0:n.displayMode)||"bilingual"),re=c.useRef(S),se=c.useRef(k),ae=c.useRef(F),be=c.useRef(l);c.useEffect(()=>{re.current=S},[S]),c.useEffect(()=>{se.current=k},[k]),c.useEffect(()=>{ae.current=F},[F]),c.useEffect(()=>{be.current=l},[l]);const{models:ve,isLoading:Je}=pt("translate"),We=c.useMemo(()=>[...ve.map(s=>({id:s.canonicalId,displayName:s.displayName,description:s.description,logoUrl:s.logoUrl,tier:s.tier,isDefault:s.isDefault})),{id:"google-translate",displayName:"Google Translate",tier:"free",logoUrl:"/model-logos/google-translate.svg"},{id:"microsoft-translate",displayName:"Microsoft Translate",tier:"free",logoUrl:"/model-logos/microsoft-translate.svg"}],[ve]),[f,ne]=c.useState(null),[g,C]=c.useState(null),[je,R]=c.useState(!1),[we,oe]=c.useState(!1),A=c.useRef([]),$=c.useRef([]),ce=c.useRef(new Set),T=c.useRef(""),O=c.useRef(new Map),[Ne,U]=c.useState(0),[Ye,B]=c.useState(!1),[Se,D]=c.useState(""),[ke,q]=c.useState(!1),[J,Ke]=c.useState([]),[le,W]=c.useState(!1),[Y,ie]=c.useState(null),z=c.useRef(null),G=Ne>0,Ze=$.current.some(Boolean);c.useEffect(()=>{localStorage.setItem(Xe,JSON.stringify({sourceLang:S,targetLang:k,style:F,displayMode:P}))},[S,k,F,P]),c.useEffect(()=>{Ve(),K();const s=new URLSearchParams(window.location.search).get("historyId");return s&&($e(s),window.history.replaceState({},"",window.location.pathname)),()=>{x.current&&clearTimeout(x.current)}},[]);const K=async()=>{try{const t=await L.getHistory({type:"document",limit:20});
2Ke(t.data.items||[])}catch{}},$e=async t=>{try{const a=(await L.getHistoryItem(t)).data;if(!a)return;Z(),ne(null),C(null),R(!1),D(""),x.current&&clearTimeout(x.current),h.current&&(h.current.value="");const u=a.sourceLanguage||"auto",m=a.targetLanguage||"en-US";de.current={sourceLang:u,targetLang:m,model:l},fe(u),ye(m),ie(a.sourceFile||"document"),z.current=t;const p=a.sourceText||"",M=a.translatedText||"",{paragraphs:v}=ee(p),j=Ge(M),_=new Array(v.length).fill("");j.forEach((w,N)=>{N<_.length&&(_[N]=w)}),A.current=v,$.current=_,ce.current=new Set,T.current=p,I.current=!0,U(v.length)}catch{H.error(r("common.loadFailed"))}};c.useEffect(()=>{if(g&&(g.status==="pending"||g.status==="processing")){let t=!1;const s=g.id,a=async()=>{if(!t){try{const u=await L.getParseTask(s);if(t)return;const m=u.data;if(m.status==="completed"){try{const p=await L.getParseTaskContent(s);if(t)return;const M=p.data.content||"";C(m),Qe(M,m.fileName),R(!1)}catch{C(m),R(!1),H.error(r("document.parseFailed"))}return}if(m.status==="failed"){C(m),R(!1),H.error(m.errorMessage||r("document.parseFailed"));return}C(p=>p&&{...p,progress:m.progress})}catch{}t||(x.current=setTimeout(a,3e3))}};return x.current=setTimeout(a,1e3),()=>{t=!0,x.current&&clearTimeout(x.current)}}},[g==null?void 0:g.id]);const Qe=c.useCallback((t,s)=>{const{paragraphs:a,segments:u,skipIndices:m}=ee(t);A.current=a,$.current=new Array(a.length).fill(""),ce.current=m,T.current=t;const p=20,M=50;if(U(Math.min(p,a.length)),a.length>p){let v=p;const j=()=>{v=Math.min(v+M,a.length),U(v),v<a.length&&requestAnimationFrame(j)};requestAnimationFrame(j)}if(!I.current){const v=s||"document";L.saveDocumentHistory({sourceLanguage:re.current||"auto",targetLanguage:se.current,style:ae.current,sourceText:t,sourceFile:v,characterCount:t.length}).then(j=>{z.current=j.data.id,K()}).catch(j=>{var _;console.error("saveDocumentHistory (initial) failed:",((_=j.response)==null?void 0:_.data)||j.message)})}I.current?I.current=!1:ue(t,a,u,m)},[]),de=c.useRef({sourceLang:S,targetLang:k,model:l});c.useEffect(()=>{const t=de.current,s=t.sourceLang!==S||t.targetLang!==k||t.model!==l;if(de.current={sourceLang:S,targetLang:k,model:l},s&&T.current&&!je){Z();const{paragraphs:a,segments:u,skipIndices:m}=ee(T.current);$.current=new Array(a.length).fill(""),O.current.forEach(p=>p()),ue(T.current,a,u,m)}},[S,k,l]);const Ve=async()=>{try{const a=((await L.getParseTasks()).data||[]).find(u=>u.status==="pending"||u.status==="processing");a&&(C(a),R(!0))}catch{}},Le=t=>{var a;const s="."+((a=t.name.split(".").pop())==null?void 0:a.toLowerCase());if(!he.some(u=>u.ext===s)){H.error(r("document.unsupportedFormat"));return}if(t.size>200*1024*1024){H.error(r("document.fileTooLarge"));return}Z(),A.current=[],$.current=[],T.current="",D(""),ie(null),U(0),ne(t),Te(t)},Te=async t=>{var s,a;if(d()){R(!0);try{const u=await L.parseDocument(t);C({...u.data,fileName:t.name})}catch(u){R(!1),H.error(((a=(s=u.response)==null?void 0:s.data)==null?void 0:a.message)||r("document.parseFailed"))}}},et=t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&&Le(s)},tt=t=>{var a;t.preventDefault(),oe(!1);const s=(a=t.dataTransfer.files)==null?void 0:a[0];s&&Le(s)},rt=t=>{t.preventDefault(),oe(!0)},st=t=>{t.preventDefault(),oe(!1)},Z=c.useCallback(()=>{b.current=Symbol("cancelled"),B(!1)},[]),ue=async(t,s,a,u)=>{var M,v,j,_;if(!t||!a.length){const w=s.map((N,me)=>u.has(me)?N:"");$.current=w,O.current.forEach(N=>N()),B(!1);return}const m=Symbol("translation");b.current=m,B(!0),D("");const p=s.map((w,N)=>u.has(N)?w:"");$.current=p;try{const w=Pt(a);if(!w.length){B(!1);return}let N=0;for(const y of w){if(b.current!==m)return;const Ie=await L.batchTranslate({texts:y.payload,sourceLanguage:re.current||"auto",targetLanguage:se.current,style:ae.current,model:be.current||void 0});if(b.current!==m)return;const mt=Ie.data.translations||[];N+=Ie.data.creditsUsed||0;for(let Q=0;Q<y.segments.length;Q++){const ge=y.segments[Q],Pe=(mt[Q]||"").trim();if(!Pe)continue;const De=It(Pe,ge.mathPlaceholders||{}),V=ge.paragraphIndex;p[V]=ge.chunkOrder>0&&p[V]?`${p[V]}
3
4${De}`:De,(M=O.current.get(V))==null||M()}}if(b.current!==m)return;for(let y=0;y<p.length;y++)p[y]||(p[y]=s[y]||"");$.current=p,O.current.forEach(y=>y());
4const me=p.filter(Boolean).join(`
5
6`);if(z.current)try{await L.updateDocumentHistory(z.current,{translatedText:me,creditsUsed:N}),K()}catch(y){console.error("updateDocumentHistory failed:",((v=y.response)==null?void 0:v.data)||y.message)}}catch(w){if(b.current!==m)return;D(((_=(j=w.response)==null?void 0:j.data)==null?void 0:_.message)||w.message||r("document.translationError"))}finally{b.current===m&&B(!1)}},at=()=>{Z(),ne(null),C(null),R(!1),A.current=[],$.current=[],T.current="",U(0),D(""),ie(null),z.current=null,x.current&&clearTimeout(x.current),h.current&&(h.current.value="")},_e=t=>{if(t==="auto")return r("translate.detectLanguage");const s=wt.find(a=>a.code===t);return s?Nt(s,o.language):t},nt=t=>{const s=Date.now()-new Date(t).getTime(),a=Math.floor(s/6e4),u=Math.floor(s/36e5),m=Math.floor(s/864e5);return a<1?r("common.justNow"):a<60?r("common.minutesAgo",{count:a}):u<24?r("common.hoursAgo",{count:u}):r("common.daysAgo",{count:m})},ot=t=>t<1024?t+" B":t<1048576?(t/1024).toFixed(1)+" KB":(t/1048576).toFixed(1)+" MB",ct=()=>{var t,s;return((t=f==null?void 0:f.name)==null?void 0:t.replace(/\.[^/.]+$/,""))||((s=g==null?void 0:g.fileName)==null?void 0:s.replace(/\.[^/.]+$/,""))||"document"},Ce=c.useRef(null),Re=()=>{var u;const t=(f==null?void 0:f.name)||(g==null?void 0:g.fileName)||Y||"Document Translation",s=((u=Ce.current)==null?void 0:u.innerHTML)||"";return`<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${t}</title><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"><style>
7      * { box-sizing: border-box; }
8      body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif; color: #111827; line-height: 1.7; padding: 40px; max-width: 960px; margin: 0 auto; }
9      h1 { font-size: 1.8em; font-weight: 700; margin: 0.6em 0 0.3em; }
10      h2 { font-size: 1.4em; font-weight: 600; margin: 0.5em 0 0.3em; }
11      h3 { font-size: 1.15em; font-weight: 600; margin: 0.4em 0 0.2em; }
12      p { margin: 0.3em 0; }
13      a { color: #2563eb; }
14      img { max-width: 100%; display: block; margin: 16px auto; }
15      table { width: 100%; border-collapse: collapse; margin: 12px 0; }
16      th, td { border: 1px solid #d1d5db; padding: 8px 12px; text-align: left; }
17      th { background: #f3f4f6; font-weight: 600; }
18      pre { background: #f3f4f6; padding: 12px; border-radius: 6px; overflow: auto; margin: 8px 0; }
19      code { background: #f3f4f6; padding: 2px 5px; border-radius: 3px; font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 0.9em; }
20      blockquote { border-left: 4px solid #d1d5db; padding-left: 16px; color: #6b7280; margin: 8px 0; }
21      .katex-display { overflow-x: auto; }
22      [class*="bg-"] { background: #f3f4f6; border-radius: 8px; padding: 12px 16px; margin-top: 8px; }
23      [class*="grid-cols-2"] { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
24      [class*="flex-col"] { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
25      [class*="skeleton"] { display: none; }
26      @media print { body { padding: 0; max-width: 100%; } @page { size: A4; margin: 15mm; } }
27      @media (max-width: 768px) { [class*="grid-cols-2"] { grid-template-columns: 1fr; } body { padding: 20px; } }
28    </style></head><body>${s}</body></html>`},lt=()=>{const t=Re(),s=new Blob([t],{type:"text/html;charset=utf-8"}),a=URL.createObjectURL(s),u=document.createElement("a");u.href=a,u.download=`${ct()}.html`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(a),q(!1)},it=()=>{var u;const t=Re(),s=document.createElement("iframe");s.style.cssText="position:fixed;top:-9999px;left:-9999px;width:0;height:0;",document.body.appendChild(s);const a=s.contentDocument||((u=s.contentWindow)==null?void 0:u.document);if(!a){document.body.removeChild(s);return}a.open(),a.write(t),a.close(),s.onload=()=>{setTimeout(()=>{var m;(m=s.contentWindow)==null||m.print(),setTimeout(()=>document.body.removeChild(s),1e3)},500)},q(!1)},dt=!f&&!g&&!Y,ut=je&&!G;return e.jsxs("div",{className:"h-full flex flex-col bg-[var(--bg-primary)]",children:[e.jsx("style",{children:"@keyframes skeleton-wave { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }"}),e.jsxs("div",{className:"px-4 md:px-6 pt-4 pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"flex items-center gap-3 shrink-0",children:e.jsx(ht,{items:We,externalLoading:Je,value:l,onCh
28ange:i})}),(f||g||Y)&&e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-sm min-w-0 flex-1",children:[e.jsx(E,{className:"w-3.5 h-3.5 text-[var(--text-tertiary)] shrink-0"}),e.jsx("span",{className:"text-[var(--text-primary)] font-medium truncate max-w-[240px]",children:(f==null?void 0:f.name)||(g==null?void 0:g.fileName)||Y}),f&&e.jsxs("span",{className:"text-[var(--text-tertiary)] shrink-0",children:["(",ot(f.size),")"]}),e.jsx("button",{className:"p-0.5 rounded text-[var(--text-tertiary)] hover:text-red-500 shrink-0",onClick:at,children:e.jsx(He,{className:"w-3.5 h-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[Ze&&e.jsxs("div",{className:"relative",children:[e.jsxs("button",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm font-medium bg-[var(--bg-tertiary)] text-[var(--text-primary)] hover:bg-[var(--bg-hover)] border border-ui-border",onClick:()=>q(!ke),children:[e.jsx(ft,{className:"w-3.5 h-3.5"})," ",r("common.download")," ",e.jsx(yt,{className:"w-3 h-3"})]}),ke&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>q(!1)}),e.jsxs("div",{className:"absolute right-0 top-full mt-1 w-44 bg-[var(--bg-primary)] border border-ui-border rounded-lg shadow-lg z-50 py-1",children:[e.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-[var(--text-primary)] hover:bg-[var(--bg-hover)]",onClick:it,children:[e.jsx(E,{className:"w-4 h-4 text-[var(--text-tertiary)]"})," PDF"]}),e.jsxs("button",{className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-[var(--text-primary)] hover:bg-[var(--bg-hover)]",onClick:lt,children:[e.jsx($t,{className:"w-4 h-4 text-[var(--text-tertiary)]"})," HTML"]})]})]})]}),e.jsx("button",{className:`relative p-2 rounded-lg transition-colors ${le?"bg-[var(--bg-tertiary)] text-[var(--text-primary)]":"text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"}`,onClick:()=>W(!le),title:r("translate.history"),children:e.jsx(Ae,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"flex items-center justify-center gap-3 mt-8",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{value:S,onChange:fe,allowAuto:!0}),e.jsx(Oe,{className:"w-3 h-3 text-[var(--text-tertiary)] shrink-0"}),e.jsx(Fe,{value:k,onChange:ye})]}),e.jsx("div",{className:"flex items-center gap-1 p-1 rounded-lg bg-[var(--bg-tertiary)]",children:["bilingual","sideBySide","translationOnly"].map(t=>e.jsx("button",{className:`px-2.5 py-1 rounded-md text-xs font-medium transition-colors ${P===t?"bg-[var(--bg-primary)] text-[var(--text-primary)] shadow-sm":"text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"}`,onClick:()=>qe(t),children:r(`document.mode${t.charAt(0).toUpperCase()+t.slice(1)}`)},t))})]})]}),le&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-md z-40",onClick:()=>W(!1)}),e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-xl rounded-2xl shadow-2xl overflow-hidden border border-ui-border bg-[var(--bg-primary)]",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-ui-border flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg text-[var(--text-primary)]",children:r("translate.recentDocuments")}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] mt-0.5",children:J.length>0?`${J.length} ${r("common.items")}`:r("translate.noHistory")})]}),e.jsx("button",{className:"p-2 rounded-lg hover:bg-[var(--bg-tertiary)] text-[var(--text-tertiary)]",onClick:()=>W(!1),children:e.jsx(He,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"p-5 max-h-[65vh] overflow-y-auto",children:J.length>0?e.jsx("div",{className:"space-y-2",children:J.map(t=>e.jsx("button",{className:"w-full p-4 rounded-lg bg-[var(--bg-secondary)] hover:bg-[var(--bg-tertiary)] transition-colors text-left border border-ui-border group",onClick:()=>{W(!1),$e(t.id)},children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(E,{className:"w-4 h-4 text-[var(--text-tertiary)] shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-sm text-[var(--text-primary)] truncate",children:t.sourceFile}),e.jsxs("div",{className:"flex items-center gap-2 text-xs mt-1",children:[e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-[var(--bg-tertiary)] text-[var(--text-primary)] font-medium border border-ui-border",children:_e(t.sourceLanguage)}),e.jsx(Oe,{className:"w-3 h-3 text-[var(--text-tertiary)]"}),e.jsx("span",{className:"px-2 py-0.5 rounded-md bg-[var(--bg-tertiary)] text-[var(--text-primary)] font-medium border border-ui-border",children:_e(t.targetLanguage)})]})]}),e.jsx("span",{className:"text-[11px] text-[var(--text-tertiary)] shrink-0",children:nt(t.createdAt)}),e.jsx("span",{className:"p-1 rounded text-[var(--text-tertiary)] hover:text-red-500 transition-colors shrink-0",onClick:async s=>{s.stopPropagation();try{await L.deleteHistoryItem(t.id),K()}catch{}},title:r("common.delete"),children:e.jsx(bt,{className:"w-3.5 h-3.5"})})]})},t.id))}):e.jsxs("div",{className:"text-center py-16",children:[e.jsx(Ae,{className:"w-8 h-8 text-[var(--text-tertiary)] mx-auto mb-4"}),e.jsx("p",{className:"text-[var(--text-primary)]",children:r("translate.noHistory")})]})})]})})]}),e.jsx("div",{className:`flex-1 overflow-y-auto ${G?"":"p-6"}`,children:e.jsxs("div",{className:G?"max-w-[960px] mx-auto py-8 px-6":"",style:P==="sideBySide"&&G?{maxWidth:"96%"}:void 0,children:[dt&&e.jsxs("div",{className:`relative cursor-pointer border-2 border-dashed rounded-lg p-8 transition-all duration-200 ${we?"border-[var(--text-primary)] bg-[var(--bg-tertiary)]":"border-ui-border hover:bg-[var(--bg-hover)]"}`,onDrop:tt,onDragOver:rt,onDragLeave:st,onClick:()=>{var t;return(t=h.current)==null?void 0:t.click()},children:[e.jsx("input",{ref:h,type:"file",accept:he.map(t=>t.ext).join(","),onChange:et,hidden:!0}),e.jsxs("div",{className:"flex flex-col items-center py-8",children:[e.jsx("div",{className:`p-4 rounded-xl bg-[var(--bg-tertiary)] mb-4 transition-transform ${we?"scale-110":""}`,children:e.jsx(vt,{className:"w-8 h-8 text-[var(--text-tertiary)]"})}),e.jsx("p",{className:"text-lg font-medium text-[var(--text-primary)] mb-1",children:r("document.dropOrClick")}),e.jsx("p",{className:"text-sm text-[var(--text-tertiary)] mb-6",children:r("document.maxSize",{size:"200MB"})}),e.jsx("div",{className:"flex flex-wrap items-center justify-center gap-2",children:he.map(t=>{const s=t.icon;return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-ui-border bg-[var(--bg-tertiary)] text-[var(--text-secondary)]",children:[e.jsx(s,{className:"w-4 h-4 text-[var(--text-tertiary)]"}),e.jsx("span",{className:"text-sm font-medium",children:t.name})]},t.ext)})})]})]}),ut&&e.jsxs("div",{className:"rounded-xl border border-ui-border bg-[var(--bg-primary)] p-8",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsx(jt,{className:"w-5 h-5 text-[var(--theme)] animate-spin"}),e.jsx("span",{className:"text-sm font-medium text-[var(--text-secondary)]",children:r("document.extracting")}),((Me=g==null?void 0:g.progress)==null?void 0:Me.totalPages)&&e.jsx("span",{className:"text-xs text-[var(--text-tertiary)]",children:r("document.parseProgress",{current:g.progress.extractedPages||0,total:g.progress.totalPages})})]}),e.jsx("div",{className:"flex flex-col gap-6",children:Array.from({length:8}).map((t,s)=>e.jsx(te,{},s))})]}),(g==null?void 0:g.status)==="failed"&&e.jsxs("div",{className:"rounded-xl border border-red-200 dark:border-red-800 bg-red-50 dark:bg-red-900/10 p-6 text-center",children:[e.jsx("p",{className:"text-red-700 dark:text-red-400 text-sm mb-3",children:g.errorMessage||r("document.parseFailed")}),f&&e.jsxs("button",{className:"px-4 py-2 text-sm font-medium rounded-lg bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400 hover:bg-red-200",onClick:()=>Te(f),children:[e.jsx(Ee,{className:"w-3.5 h-3.5 inline mr-1.5"}),r("common.retry")]})]}),Se&&e.jsxs("div",{className:"rounded-xl border border-red-200 dark:border-red-800 bg-red-50 dark:bg-red-900/10 p-4 mb-4 flex items-center justify-between",children:[e.jsx("span",{className:"text-red-700 dark:text-red-400 text-sm",children:Se}),e.jsxs("button",{className:"px-3 py-1.5 text-sm font-medium rounded-lg bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-400",onClick:()=>{D("");const{paragraphs:t,segments:s,skipIndices:a}=ee(T.current);ue(T.current,t,s,a)},children:[e.jsx(Ee,{className:"w-3.5 h-3.5 inline mr-1"}),r("common.retry")]})]}),G&&e.jsx("div",{ref:Ce,className:P==="sideBySide"?"flex flex-col gap-0":"flex flex-col gap-5",children:Array.from({length:Ne}).map((t,s)=>e.jsx(Et,{index:s,paragraphsRef:A,translationsRef:$,skipIndicesRef:ce,updatersRef:O,isTranslating:Ye,displayMode:P},s))})]})})]})}function Et({index:r,paragraphsRef:o,translationsRef:d,skipIndicesRef:l,updatersRef:i,isTranslating:n,displayMode:h}){const[,x]=c.useReducer(b=>b+1,0);return c.useEffect(()=>(i.current.set(r,x),()=>{i.current.delete(r)}),[r,i]),e.jsx(Dt,{index:r,original:o.current[r]||"",translation:d.current[r]||"",isTranslating:n,isSkipped:l.current.has(r),displayMode:h})}export{sr as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.