1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DyVoA8ZA.js","assets/vendor-react-C_xdI0Ng.js","assets/index-BLFiW9lJ.js","assets/index-Ce2rXghS.css","assets/linear-icon-BS_Bu1OG.js","assets/vendor-icons-CmfhFn4k.js"])))=>i.map(i=>d[i]); 2import{u as M,_ as $}from"./index-BLFiW9lJ.js";import{i as B,u as J,r,j as p}from"./vendor-react-C_xdI0Ng.js";function V(l){return new Promise((u,c)=>{const t=new FileReader;t.onload=()=>u(String(t.result??"")),t.onerror=()=>c(t.error??new Error("Failed to read output blob")),t.readAsDataURL(l)})}function q(l){return l==="application/pdf"?"pdf":l==="text/plain"?"txt":l==="application/json"?"json":"bin"}async function G(l,u,c={}){if(typeof document>"u")throw new Error("Download is available only in browser runtime");let t=0;for(let i=0;i<u.length;i+=1){const h=u[i],d=await l.vfs.read(h),O=await d.getBlob(),n=await d.getType(),j=q(n),y=c.baseName?`${c.baseName}-${i+1}.${j}`:`${d.getName()||h}.${j}`,L=await V(O),a=document.createElement("a");a.href=L,a.download=y,a.style.display="none",document.body.append(a),a.click(),a.remove(),t+=1}return t}const H=r.lazy(()=>$(()=>import("./index-DyVoA8ZA.js"),__vite__mapDeps([0,1,2,3,4,5]))),K={userId:"ocr-test-user",plan:"pro",entitlements:["pdf.ocr"]};function X(){const l=B(),u=J(),{runtime:c}=M(),[t,i]=r.useState([]),[h,d]=r.useState([]),[O,n]=r.useState("idle"),[j,y]=r.useState(0),[L,a]=r.useState(null),[P,b]=r.useState(null),[s,v]=r.useState(null),[w,f]=r.useState({text:"",json:"",accuracy:null,language:null}),T=r.useMemo(()=>({accuracy:w.accuracy,pages:t.length,language:w.language,durationMs:P}),[P,t.length,w.accuracy,w.language]);r.useEffect(()=>()=>{s&&URL.revokeObjectURL(s)},[s]),r.useEffect(()=>{const e=u.state??null,m=Array.isArray(e==null?void 0:e.preloadedFileIds)?e.preloadedFileIds.filter(o=>typeof o=="string"&&o.length>0):[];(e==null?void 0:e.source)!=="studio"||m.length===0||(i(Array.from(new Set(m))),d([]),s&&(URL.revokeObjectURL(s),v(null)),f({text:"",json:"",accuracy:null,language:null}),y(0),b(null),a(null),n("idle"))},[u.key,u.state]);const _=async e=>{const m=[];for(const o of e){const R=await c.vfs.write(o);m.push(R.id)}i(m),d([]),s&&(URL.revokeObjectURL(s),v(null)),f({text:"",json:"",accuracy:null,language:null}),y(0),b(null),a(null),n("idle")},k=()=>{i([]),d([]),f({text:"",json:"",accuracy:null,language:null}),y(0),b(null),a(null),n("idle")},z=async e=>{var E,F;if(t.length===0){n("error"),a("Select at least one file before running OCR.");return}n("running"),y(0),a(null),s&&(URL.revokeObjectURL(s),v(null)),f({text:"",json:"",accuracy:null,language:null});const m=performance.now(),o=await c.runner.execute("ocr-pdf",{inputIds:t,options:e},K,g=>{y(g.progress)});if(b(performance.now()-m),o.type==="TOOL_ACCESS_DENIED"){n("error"),a(o.details??o.reason);return}if(o.type==="TOOL_ERROR"){n("error"),a(o.message);return}d(o.outputIds);const R=o.outputIds[0];if(!R){n("done");return}const D=await c.vfs.read(R),U=await D.getBlob(),S=await D.getType();if(S==="text/plain"){const g=await U.text();f({text:g,json:"",accuracy:null,language:null}),n("done");return}if(S==="application/json"){const g=await U.text();let I="",N=null,C=null;try{const x=JSON.parse(g);I=typeof x.recognizedText=="string"?x.recognizedText:"",N=typeof((E=x.ocr)==null?void 0:E.averageConfidence)=="number"?x.ocr.averageConfidence*100:null,C=typeof((F=x.languageDetection)==null?void 0:F.primaryLanguage)=="string"?x.languageDetection.primaryLanguage.toUpperCase():null}catch{I=""}f({text:I,json:g,accuracy:N,language:C}),n("done");return}if(S==="application/pdf"){const g=URL.createObjectURL(U);f({text:"Searchable PDF generated. Use Download to save the output file.",json:"",accuracy:null,language:null}),v(g),n("done");return}f({text:"",json:"",accuracy:null,language:null}),n("done")},A=async()=>{h.length!==0&&await G(c,h,{baseName:"ocr-result"})};return p.jsxs("div",{className:"wizard-shell ocr-test-shell",children:[p.jsx("div",{className:"wizard-header ocr-test-header",children:p.jsx("div",{children:p.jsx("h1",{className:"wizard-title",children:"OCR PDF"})})}),p.jsx("div",{className:"wizard-config-card animate-fade-in ocr-test-config-card",children:p.jsx(r.Suspense,{fallback:p.jsx("p",{className:"wizard-subtitle",children:"Loading OCR concept..."}),children:p.jsx(H,{inputFiles:t,onBack:()=>l("/ocr-pdf"),onStart:e=>{z(e)},onPickFiles:e=>{_(e)},onClearFiles:k,viewState:O,progress:j,errorMessage:L,resultText:w.text,resultJson:w.json,resultPdfUrl:s,resultMeta:T,onDownloadOutput:()=>{A()}})})})]})}export{X as OcrPdfTestPage};
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.