PageSourceSearch

https://localpdf.online/app/assets/AutoTocStudioPanel-BIqpsFXe.js

js localpdf.online collected 2026-09-24 14:26:38 UTC 8,270 bytes, 1 lines download raw bytes

1import{r as o,j as e}from"./vendor-react-C_xdI0Ng.js";import{L as i}from"./linear-icon-BS_Bu1OG.js";import{r as J,c as K,l as Q,a as V,T as X}from"./noto-sans-cyrillic-700-normal-B3rv6UnQ.js";import{a as Y,b as T,P as Z}from"./index-BLFiW9lJ.js";import ee from"./noto-sans-latin-400-normal-DZbyGt1h.js";import te from"./noto-sans-latin-ext-400-normal-ChgRUxkZ.js";import ae from"./noto-sans-cyrillic-400-normal-C2Ud1djk.js";import"./vendor-icons-CmfhFn4k.js";function me({onClose:p,inputFileId:j,fileName:A,runtime:s}){const[r,a]=o.useState("config"),[h,R]=o.useState(null),[E,w]=o.useState([]),[P,l]=o.useState(null),[U,D]=o.useState(null),[z,F]=o.useState(j),N=o.useRef(0),_=o.useRef(null),O=o.useSyncExternalStore(t=>s.billing.subscribe(t),()=>s.billing.getContext().plan),{requestDownload:L,overlay:q}=Y(O);o.useEffect(()=>()=>{var t;return(t=_.current)==null?void 0:t.abort()},[]);const W=o.useCallback(async()=>{var f,b,g,m,x,n;(f=_.current)==null||f.abort();const t=++N.current,u=new AbortController;_.current=u,a("parsing"),l(null),(b=window.posthog)==null||b.capture("app_tool_run_started",{toolId:"auto-toc",action:"parse"});try{const c=T.getState().activeDocumentId,S=T.getState().documents.find(y=>y.id===c);let I=j;if(S&&S.pages.length>0){const y=S.pages.map(v=>({sourceFileId:v.fileId,pageIndex:v.pageIndex,rotation:v.rotation})),H={inputs:Array.from(new Set(y.map(v=>v.sourceFileId))),operations:[{type:"reorder",sequence:y}],outputName:"studio-autotoc-input.pdf"},C=await new Z(s.vfs).execute(H),B=new Uint8Array(C.buffer.byteLength);B.set(C.buffer);const G=new Blob([B],{type:"application/pdf"});I=(await s.vfs.write(new File([G],C.fileName,{type:"application/pdf"}))).id}F(I);const d=await J(s,I,u.signal);if(t!==N.current)return;if(d.error){(g=window.posthog)==null||g.capture("app_tool_run_error",{toolId:"auto-toc",message:d.error}),l(d.error),a("config");return}(m=window.posthog)==null||m.capture("app_tool_run_success",{toolId:"auto-toc",action:"parse",headersFound:d.headingCandidatesFound});const M=s.billing.getContext().plan,k=d.totalPages??0;if(M==="basic"&&k>5){(x=window.posthog)==null||x.capture("app_upsell_shown",{toolId:"auto-toc",source:"page_limit",pageCount:k}),l(`Free plan limited to 5 pages (this document has ${k}). Upgrade to Pro for unlimited page TOC generation.`),a("config");return}R(d),w(d.headers),a("review")}catch(c){if(t!==N.current||c instanceof DOMException&&c.name==="AbortError")return;(n=window.posthog)==null||n.capture("app_tool_run_error",{toolId:"auto-toc",message:"Parse failed"}),l(c instanceof Error?c.message:"Parse failed"),a("config")}},[s,j]),$=o.useCallback(async t=>{var g,m,x;a("applying"),l(null),(g=window.posthog)==null||g.capture("app_tool_run_started",{toolId:"auto-toc",action:"apply"});const u="/app/",f=`${u}fonts/Roboto-Regular.ttf`.replace(/\/+/g,"/"),b=`${u}fonts/Roboto-Bold.ttf`.replace(/\/+/g,"/");try{const n=await s.runner.execute("auto-toc",{inputIds:[z],options:{action:"apply",headers:t.headers,generateTocPage:t.generateTocPage,fontUrls:{latinUrl:ee,latinExtUrl:te,cyrillicUrl:ae,latinBoldUrl:V,latinExtBoldUrl:Q,cyrillicBoldUrl:K,robotoUrl:f,robotoBoldUrl:b}}},s.billing.getContext());if(n.type==="TOOL_ACCESS_DENIED"){l("Upgrade to Pro to use this feature."),a("review");return}if(n.type==="TOOL_ERROR"){l(n.message),a("review");return}const c=URL.createObjectURL(await(await s.vfs.read(n.outputIds[0])).getBlob());D(c),(m=window.posthog)==null||m.capture("app_tool_run_success",{toolId:"auto-toc",action:"apply"}),a("result")}catch(n){(x=window.posthog)==null||x.capture("app_tool_run_error",{toolId:"auto-toc",message:"Apply failed"}),l(n instanceof Error?n.message:"Apply failed"),a("review")}},[s,z]);return e.jsxs("div",{className:"cvt-shell",children:[e.jsxs("nav",{className:"cvt-nav",children:[e.jsxs("a",{className:"studio-logo",href:"#",onClick:t=>{t.preventDefault(),p==null||p()},children:[e.jsx("div",{className:"studio-nav-logo-icon",children:"L"}),e.jsx("span",{className:"studio-logo-title",children:"LocalPDF"})]}),e.jsx("span",{className:"studio-nav-sep",children:"/"}),e.jsx("span",{className:"cvt-nav-tool",children:"Auto-TOC & Bookmarks"}),e.jsx("div",{style:{flex:1}}),e.jsxs("button",{type:"button",className:"cvt-nav-btn",onClick:p,disabled:r==="parsing"||r==="applying",children:[e.jsx(i,{name:"chevron-left",size:12}),"All tools"]}),e.jsx("button",{type:"button",className:"cvt-nav-btn",onClick:p,disabled:r==="parsing"||r==="applying",children:"Studio"})]}),e.jsx("div",{className:"cvt-page-wrap custom-scrollbar",children:e.jsxs("div",{className:"cvt-page",children:[e.jsxs("div",{className:"cvt-tool-header",children:[e.jsx("div",{className:"cvt-tool-icon",children:e.jsx(i,{name:"edit",size:20})}),e.jsxs("div",{children:[e.jsx("div",{className:"cvt-tool-title",children:"Auto-TOC & Bookmarks"}),e.jsx("div",{className:"cvt-tool-desc",children:"Detect headings and generate interactive bookmarks for your PDF."}),e.jsxs("div",{className:"cvt-privacy-badge",children:[e.jsx(i,{name:"lock",size:10}),"Processed locally · files never leave your device"]})]})]}),P&&e.jsxs("div",{className:"autoc-error",style:{marginBottom:16},children:[e.jsx(i,{name:"x",className:"linear-icon"}),e.jsx("span",{children:P})]}
1),r==="config"&&e.jsxs("div",{className:"cvt-stage",children:[e.jsxs("div",{className:"cvt-file-item",children:[e.jsx("div",{className:"cvt-file-icon",children:e.jsx(i,{name:"word",size:16})}),e.jsx("div",{children:e.jsx("div",{className:"cvt-file-name",children:A})})]}),e.jsx("div",{style:{textAlign:"center",padding:"24px 0"},children:e.jsx("button",{className:"btn-primary btn-premium-glow",onClick:W,children:e.jsxs("span",{className:"btn-inline",children:[e.jsx(i,{name:"play",className:"linear-icon"}),"Analyze Document"]})})})]}),r==="parsing"&&e.jsxs("div",{className:"cvt-stage",style:{textAlign:"center",padding:"40px 0"},children:[e.jsx("div",{style:{width:32,height:32,border:"3px solid var(--border)",borderTopColor:"var(--accent)",borderRadius:"50%",animation:"cvt-spin 0.8s linear infinite",margin:"0 auto 16px"}}),e.jsx("div",{style:{fontWeight:600},children:"Analyzing document…"}),e.jsx("div",{style:{fontSize:13,color:"var(--text-muted)",marginTop:4},children:"Extracting text and detecting headings"})]}),r==="review"&&h&&e.jsx("div",{className:"cvt-stage",children:e.jsx(X,{headers:E,bodyTextSize:h.bodyTextSize,headingCandidatesFound:h.headingCandidatesFound,totalSpansExtracted:h.totalSpansExtracted,onHeadersChange:w,onApply:$,onBack:()=>{a("config"),R(null),w([])},isProcessing:!1})}),r==="applying"&&e.jsxs("div",{className:"cvt-stage",style:{textAlign:"center",padding:"40px 0"},children:[e.jsx("div",{style:{width:32,height:32,border:"3px solid var(--border)",borderTopColor:"var(--accent)",borderRadius:"50%",animation:"cvt-spin 0.8s linear infinite",margin:"0 auto 16px"}}),e.jsx("div",{style:{fontWeight:600},children:"Generating bookmarks…"})]}),r==="result"&&U&&e.jsx("div",{className:"cvt-stage",style:{maxWidth:480,margin:"40px auto 0"},children:e.jsxs("div",{style:{textAlign:"center",padding:"36px 24px",background:"var(--bg-1)",borderRadius:8,border:"1px solid var(--border)",boxShadow:"var(--shadow-sm)"},children:[e.jsx("div",{style:{fontSize:40,marginBottom:16},children:"🎉"}),e.jsx("div",{style:{fontWeight:700,fontSize:18,marginBottom:6,color:"var(--text)"},children:"Bookmarks generated successfully"}),e.jsxs("div",{style:{fontSize:13,color:"var(--text-muted)",marginBottom:24},children:[E.filter(t=>t.enabled).length," headings added to your document outline."]}),e.jsxs("div",{style:{display:"flex",gap:10,justifyContent:"center",flexWrap:"wrap",alignItems:"center"},children:[e.jsxs("button",{type:"button",className:"cvt-btn-primary",onClick:()=>L("auto-toc",()=>{const t=document.createElement("a");t.href=U,t.download=`${A.replace(/\.pdf$/i,"")}-with-toc.pdf`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}),children:[e.jsx(i,{name:"download",size:14}),"Download PDF"]}),e.jsxs("button",{className:"cvt-btn-ghost",onClick:()=>a("review"),children:[e.jsx(i,{name:"chevron-left",size:14}),"Back to Edit"]}),e.jsxs("button",{className:"cvt-btn-ghost",onClick:p,children:[e.jsx(i,{name:"x",size:14}),"Close"]})]})]})})]})}),q]})}export{me as AutoTocStudioPanel};

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.