1var fe=Object.defineProperty;var me=(t,i,s)=>i in t?fe(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s;var H=(t,i,s)=>me(t,typeof i!="symbol"?i+"":i,s);import{r as l,j as e,i as xe,u as we}from"./vendor-react-C_xdI0Ng.js";import{g as ie,u as re,a as ve}from"./index-BLFiW9lJ.js";import{L as ye}from"./linear-icon-BS_Bu1OG.js";import{i as be,g as je}from"./pdf-loader-XNuiZneC.js";import{d as le}from"./preview-service-CXJMbUqg.js";import"./vendor-icons-CmfhFn4k.js";const X={step:"upload",fileIds:[],outputIds:[],progress:0,isValidating:!1,isProcessing:!1,currentRunId:null,error:null,toast:null,upsellReason:null};function Q(t,i){return t instanceof Error&&t.message.trim().length>0?t.message:i}function Ie(t){return be(t)}function Ne(t){const i=t.find(s=>typeof s.type=="string"&&s.type.trim().length>0);return i?i.type==="application/pdf"?"pdf":i.type.startsWith("image/")?"image":i.type.split("/")[0]||"unknown":"unknown"}async function K(t,i){await Promise.all(t.map(async s=>i(s)))}class ze{constructor(i){H(this,"state",{...X});H(this,"abortController",null);this.deps=i}getState(){return this.state}dismissToast(){return this.state={...this.state,toast:null},this.state}dismissUpsell(){return this.state={...this.state,upsellReason:null},this.state}cancelProcessing(i="cancel"){var s;this.state.currentRunId&&(this.deps.runtime.telemetry.track({type:"TOOL_RUN_ABANDONED",flowId:ie(),runId:this.state.currentRunId,toolId:this.deps.toolId,reason:i}),this.state={...this.state,currentRunId:null}),(s=this.abortController)==null||s.abort()}async resetFlow(i=!0){var s;return(s=this.abortController)==null||s.abort(),this.abortController=null,i&&this.state.fileIds.length>0&&await K(this.state.fileIds,async d=>{await this.deps.runtime.vfs.delete(d)}),this.state={...X},this.state}async handleFilesAdded(i){var d,n;if(i.length===0)return this.state;this.state={...this.state,isValidating:!0,error:null,toast:null,upsellReason:null};const s=[];try{for(const o of i){const u=await this.deps.runtime.vfs.write(o);s.push(u.id)}}catch(o){if(s.length>0&&await K(s,async u=>{await this.deps.runtime.vfs.delete(u)}),Ie(o)){const u="Storage quota exceeded. Free some space and retry.";return(n=(d=this.deps).onToast)==null||n.call(d,u),this.state={...this.state,step:"upload",isValidating:!1,toast:u},this.state}return this.state={...this.state,step:"upload",isValidating:!1,error:Q(o,"Failed to upload files")},this.state}try{const o=this.deps.runtime.registry.get(this.deps.toolId),u=await this.deps.limitService.check({runtime:this.deps.runtime,toolId:this.deps.toolId,toolLimits:o.limits,fileIds:s,context:this.deps.context});return u.allowed?(this.state={...this.state,step:"config",fileIds:s,outputIds:[],progress:0,isValidating:!1,error:null},this.deps.runtime.telemetry.track({type:"APP_FILE_UPLOADED",flowId:ie(),toolId:this.deps.toolId,fileCount:s.length,mimeCategory:Ne(i),totalBytes:i.reduce((f,p)=>f+p.size,0),source:"wizard"}),this.state):(await K(s,async f=>{await this.deps.runtime.vfs.delete(f)}),this.state={...this.state,step:"upload",fileIds:[],isValidating:!1,upsellReason:u.reason??"Plan limit reached"},this.state)}catch(o){return await K(s,async u=>{await this.deps.runtime.vfs.delete(u)}),this.state={...this.state,step:"upload",fileIds:[],isValidating:!1,error:Q(o,"Validation failed")},this.state}}async hydrateFromFileIds(i){const s=Array.from(new Set(i.filter(d=>typeof d=="string"&&d.length>0)));if(s.length===0)return this.state;if(this.state.fileIds.length===s.length&&this.state.fileIds.every((d,n)=>d===s[n])&&this.state.step!=="upload")return this.state;this.state={...this.state,isValidating:!0,error:null,toast:null,upsellReason:null};try{await Promise.all(s.map(async o=>this.deps.runtime.vfs.read(o)));const d=this.deps.runtime.registry.get(this.deps.toolId),n=await this.deps.limitService.check({runtime:this.deps.runtime,toolId:this.deps.toolId,toolLimits:d.limits,fileIds:s,context:this.deps.context});return n.allowed?(this.state={...this.state,step:"config",fileIds:s,outputIds:[],progress:0,isValidating:!1,isProcessing:!1,error:null},this.state):(this.state={...this.state,step:"upload",fileIds:[],outputIds:[],progress:0,isValidating:!1,upsellReason:n.reason??"Plan limit reached"},this.state)}catch(d){return this.state={...this.state,step:"upload",fileIds:[],outputIds:[],progress:0,isValidating:!1,error:Q(d,"Failed to open selected files")},this.state}}async startProcessing(i){if(this.state.fileIds.length===0)return this.state={...this.state,step:"upload",error:"No files selected"},this.state;const s=Array.isArray(i==null?void 0:i.inputIds)?i.inputIds.filter(w=>typeof w=="string"):null,d=s&&s.length>0?s:this.state.fileIds,n=new AbortController,o=crypto.randomUUID();this.abortController=n,this.state={...this.state,step:"processing",progress:0,isProcessing:!0,currentRunId:o,error:null};const u={id:o,type:"COMMAND",payload:{type:"PROCESS_TOOL",payload:{toolId:this.deps.toolId,inputIds:d,options:i}}},p=(await this.deps.runtime.workerOrchestrator.dispatch(u,w=>{if(n.signal.aborted)return;const a=w.payload;a.type==="PROGRESS"&&(this.state={...this.state,progress:a.payload.progress})},n.signal)).payload;return n.signal.aborted||p.type==="ERROR"&&p.payload.code==="WORKER_ABORTED"?(this.state={...this.state,step:"config",isProcessing:!1,progress:0,currentRunId:null,error:"Processing canceled"},this.state):p.type==="ERROR"?(this.state={...this.state,step:"config",isProcessing:!1,progress:0,currentRunId:null,error:p.payload.message},this.state):p.type!=="RESULT"?(this.state={...this.state,step:"config",isProcessing:!1,progress:0,currentRunId:null,error:"Unexpected worker event"},this.state):(this.state={...this.state,step:"result",outputIds:p.payload.outputIds,isProcessing:!1,progress:100,currentRunId:null,error:null},this.state)}}function Pe(t,i){const{runtime:s}=re(),[d,n]=l.useState(()=>s.billing.getContext()),[o,u]=l.useState(X),[f,p]=l.useState(0);l.useEffect(()=>s.billing.subscribe(x=>{n(x)}),[s.billing]);const w=l.useMemo(()=>i.limitService??{check:async({runtime:g,fileIds:x,toolId:C,context:S})=>{const N=await g.runner.validateAccess(C,x,S);return N?{allowed:!1,reason:N.details??N.reason}:{allowed:!0}}},[i.limitService]),a=l.useMemo(()=>new ze({runtime:s,toolId:t,context:i.context??d,limitService:w,onToast:i.onToast}),[s,t,i.context,d,w,i.onToast]);l.useEffect(()=>(u(a.getState()),()=>{a.cancelProcessing("navigation")}),[a]),l.useEffect(()=>{if(typeof window>"u"||!o.isProcessing||!o.currentRunId)return;const g=()=>{a.cancelProcessing("pagehide")},x=()=>{document.visibilityState==="hidden"&&a.cancelProcessing("visibility_hidden")};return window.addEventListener("pagehide",g),document.addEventListener("visibilitychange",x),()=>{window.removeEventListener("pagehide",g),document.removeEventListener("visibilitychange",x)}},[a,o.currentRunId,o.isProcessing]);const y=l.useMemo(()=>{const g=s.registry.get(t);return l.lazy(g.uiLoader)},[s.registry,t,f]),b=l.useCallback(async g=>{const x=await a.handleFilesAdded(g);u({...x})},[a]),c=l.useCallback(async g=>{const x=await a.startProcessing(g);u({...x})},[a]),D=l.useCallback(async g=>{const x=await a.hydrateFromFileIds(g);u({...x})},[a]),E=l.useCallback(async(g=!0)=>{const x=await a.resetFlow(g);u({...x})},[a]),B=l.useCallback((g="cancel")=>{a.cancelProcessing(g)},[a]),P=l.useCallback(()=>
1{const g=a.dismissToast();u({...g})},[a]),M=l.useCallback(()=>{const g=a.dismissUpsell();u({...g})},[a]),I=l.useCallback(()=>{p(g=>g+1)},[]);return{state:o,configComponent:y,handleFilesAdded:b,hydrateFromFileIds:D,startProcessing:c,cancelProcessing:B,resetFlow:E,retryConfigLoad:I,dismissToast:P,dismissUpsell:M}}function ne(t){return t instanceof Error&&t.message.trim().length>0?t.message:"Preview is unavailable for this file"}function Ce(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?`preview-${crypto.randomUUID()}`:`preview-${Math.random().toString(16).slice(2)}`}function ke(t,i,s){const d=l.useMemo(()=>[...s],[s]),n=l.useMemo(()=>Ce(),[]),[o,u]=l.useState([]),[f,p]=l.useState(!1);return l.useEffect(()=>{if(d.length===0){u([]),p(!1);return}const w=new AbortController;return p(!0),Promise.all(d.map(async a=>{const y=performance.now();try{const b=await le.getPreview(t,a,w.signal);return t.telemetry.track({type:"UI_PREVIEW_RENDERED",runId:n,toolId:i,fileId:a,durationMs:Math.max(0,Math.round(performance.now()-y)),pageCount:b.pageCount}),{...b,status:"ready"}}catch(b){return w.signal.aborted?null:(t.telemetry.track({type:"UI_PREVIEW_ERROR",runId:n,toolId:i,fileId:a,message:ne(b)}),{fileId:a,name:a,mimeType:"application/octet-stream",sizeBytes:0,kind:"file",thumbnailUrl:null,status:"error",errorMessage:ne(b)})}})).then(a=>{if(w.signal.aborted)return;const y=[];for(const b of a)b&&y.push(b);u(y),p(!1)}),()=>{w.abort()}},[n,t,d,i]),{previews:o,isLoading:f}}const Z=6,T=40;function Se(t){if(t<=0)return"0 B";const i=["B","KB","MB","GB"];let s=t,d=0;for(;s>=1024&&d<i.length-1;)s/=1024,d+=1;return`${s.toFixed(s>=10||d===0?0:1)} ${i[d]}`}function ae(t){return t==="application/pdf"?"PDF":t.startsWith("image/")?"Image":"File"}function Fe({src:t,alt:i}){const[s,d]=l.useState(!1),n=l.useRef(null);return l.useEffect(()=>{const o=n.current;if(!o)return;if(typeof IntersectionObserver>"u"){d(!0);return}const u=new IntersectionObserver(f=>{const p=f[0];p!=null&&p.isIntersecting&&(d(!0),u.disconnect())},{rootMargin:"80px"});return u.observe(o),()=>u.disconnect()},[]),e.jsx("div",{ref:n,className:"preview-image-host",children:s?e.jsx("img",{src:t,alt:i,className:"preview-image",loading:"lazy"}):e.jsx("div",{className:"preview-fallback",children:"Loading"})})}function J({runtime:t,previews:i,isLoading:s,toolId:d,title:n="Preview"}){var N;const[o,u]=l.useState(1),[f,p]=l.useState({}),[w,a]=l.useState({}),[y,b]=l.useState({}),[c,D]=l.useState({}),[E,B]=l.useState(null),P=Math.max(1,Math.ceil(i.length/Z));l.useEffect(()=>{u(r=>r>P?P:r)},[P]);const M=l.useMemo(()=>{const r=(o-1)*Z;return i.slice(r,r+Z)},[o,i]),I=M.length===1,g=((N=M[0])==null?void 0:N.kind)==="pdf",x=I&&g,C=d==="compress-pdf"&&I,S=C?3.2:x?2.6:1.15;return l.useEffect(()=>{const r=v=>{v.key==="Escape"&&B(null)};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[]),l.useEffect(()=>{const r=new AbortController;return Promise.all(M.map(async v=>{if(v.kind!=="pdf")return;const z=f[v.fileId]??1,k=await le.getPdfPagePreview(t,v.fileId,z,{scale:S},r.signal);r.signal.aborted||(b(m=>({...m,[v.fileId]:k.thumbnailUrl})),k.pageCount!==void 0&&D(m=>({...m,[v.fileId]:k.pageCount})))})),()=>{r.abort()}},[M,f,S,t]),i.length===0&&!s?null:e.jsxs("section",{className:`preview-panel${C?" preview-panel-full-page":""}`,"aria-label":"File preview",children:[e.jsxs("div",{className:"preview-panel-header",children:[e.jsx("h3",{className:"preview-panel-title",children:n}),e.jsxs("div",{className:"preview-panel-meta",children:[s&&e.jsx("span",{className:"preview-panel-status",children:"Loading preview..."}),i.length>Z&&e.jsxs("div",{className:"preview-pagination",children:[e.jsx("button",{className:"btn-ghost preview-page-btn",onClick:()=>u(r=>Math.max(1,r-1)),disabled:o===1,children:"Prev"}),e.jsxs("span",{className:"preview-page-copy",children:[o,"/",P]}),e.jsx("button",{className:"btn-ghost preview-page-btn",onClick:()=>u(r=>Math.min(P,r+1)),disabled:o===P,children:"Next"})]})]})]}),e.jsx("div",{className:`preview-grid${x?" focus":""}${C?" full-page":""}`,children:M.map(r=>{const v=Math.max(1,r.pageCount??c[r.fileId]??1),z=Math.min(v,f[r.fileId]??1),k=y[r.fileId]??r.thumbnailUrl;return e.jsxs("article",{className:`preview-card${x?" preview-card-focus":""}${C?" preview-card-full-page":""}`,style:{contentVisibility:"auto",containIntrinsicSize:"280px 200px"},children:[e.jsxs("div",{className:`preview-thumb${x?" preview-thumb-focus":""}${C?" preview-thumb-full-page":""}`,children:[k?e.jsx("button",{type:"button",className:"preview-open-btn",onClick:()=>B({src:k,alt:`Preview of ${r.name}`}),title:"Open large preview","aria-label":"Open large preview",children:e.jsx(Fe,{src:k,alt:`Preview of ${r.name}`})}):e.jsx("div",{className:"preview-fallback","aria-hidden":"true",children:ae(r.mimeType)}),r.kind==="pdf"&&v>
11&&e.jsxs("div",{className:`preview-thumb-controls${C?" preview-thumb-controls-inline":""}`,children:[e.jsx("button",{className:"btn-ghost preview-page-btn","aria-label":"Prev page",title:"Prev page",onClick:()=>p(m=>({...m,[r.fileId]:Math.max(1,z-1)})),disabled:z<=1,children:"Prev"}),e.jsxs("span",{className:"preview-thumb-page",children:[z,"/",v]}),e.jsx("button",{className:"btn-ghost preview-page-btn","aria-label":"Next page",title:"Next page",onClick:()=>p(m=>({...m,[r.fileId]:Math.min(v,z+1)})),disabled:z>=v,children:"Next"})]})]}),e.jsxs("div",{className:"preview-meta",children:[e.jsx("p",{className:"preview-name",title:r.name,children:r.name}),e.jsxs("p",{className:"preview-copy",children:[ae(r.mimeType)," · ",Se(r.sizeBytes)]}),r.kind==="pdf"&&e.jsxs("p",{className:"preview-copy",children:["Pages: ",v]}),r.kind==="pdf"&&v>1&&e.jsxs("div",{className:"preview-page-grid-wrap",children:[e.jsxs("div",{className:"preview-page-grid-header",children:[e.jsx("span",{className:"preview-copy",children:"Page grid"}),v>T&&e.jsxs("div",{className:"preview-pagination",children:[e.jsx("button",{className:"btn-ghost preview-page-btn",onClick:()=>a(m=>{const F=Math.max(1,(m[r.fileId]??1)-T);return{...m,[r.fileId]:F}}),disabled:(w[r.fileId]??1)<=1,children:"Prev pages"}),e.jsx("button",{className:"btn-ghost preview-page-btn",onClick:()=>a(m=>{const F=m[r.fileId]??1,V=Math.min(Math.max(1,v-T+1),F+T);return{...m,[r.fileId]:V}}),disabled:(w[r.fileId]??1)+T>v,children:"Next pages"})]})]}),e.jsx("div",{className:"preview-page-grid",role:"grid","aria-label":"PDF pages grid",children:Array.from({length:Math.max(0,Math.min(T,v-((w[r.fileId]??1)-1)))},(m,F)=>(w[r.fileId]??1)+F).map(m=>e.jsx("button",{type:"button",className:`preview-page-tile${m===z?" active":""}`,style:{contentVisibility:"auto",containIntrinsicSize:"48px 48px"},onClick:()=>p(F=>({...F,[r.fileId]:m})),"aria-label":`Go to page ${m}`,children:m},`${r.fileId}-page-${m}`))})]}),r.status==="error"&&r.errorMessage&&e.jsx("p",{className:"preview-error",children:r.errorMessage})]})]},r.fileId)})}),E&&e.jsx("div",{className:"preview-lightbox",role:"dialog","aria-modal":"true","aria-label":"Large page preview",onClick:()=>B(null),children:e.jsx("img",{src:E.src,alt:E.alt,className:"preview-lightbox-image",onClick:r=>r.stopPropagation()})})]})}function oe(...t){return t.filter(Boolean).join(" ")}function Re({children:t}){return e.jsx(e.Fragment,{children:t})}class Y extends l.Component{constructor(s){super(s);H(this,"handleRetry",()=>{this.setState({hasError:!1}),this.props.onRetry()});this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?e.jsxs("div",{className:"wz-card wz-card-body",style:{borderColor:"rgba(224,62,62,0.25)",background:"rgba(224,62,62,0.06)",color:"var(--red)"},children:[e.jsx("p",{style:{fontSize:13,marginBottom:12},children:"Failed to load tool settings."}),e.jsx("button",{className:"wz-btn wz-btn-ghost",onClick:this.handleRetry,children:"Retry"})]}):this.props.children}}function Ee({disabled:t,accept:i="application/pdf",multiple:s=!0,onFilesAdded:d}){const n=l.useRef(null),[o,u]=l.useState(!1),f=async a=>{!a||a.length===0||t||await d(Array.from(a))},p=async a=>{a.preventDefault(),u(!1),await f(a.dataTransfer.files)},w=async a=>{await f(a.target.files),a.target.value=""};return e.jsxs("div",{className:oe("wz-upload-zone",o&&"wz-upload-zone--dragging",t&&"wz-upload-zone--disabled"),onClick:()=>{var a;return(a=n.current)==null?void 0:a.click()},onKeyDown:a=>{var y;(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),(y=n.current)==null||y.click())},onDragOver:a=>{a.preventDefault(),u(!0)},onDragLeave:()=>u(!1),onDrop:p,role:"button",tabIndex:0,"aria-label":"Upload files",title:"Upload files",children:[e.jsx("div",{className:"wz-upload-icon",children:e.jsx(ye,{name:"upload",className:"linear-icon icon-md"})}),e.jsx("p",{className:"wz-upload-title",children:"Drop files here or click to upload"}),e.jsxs("p",{className:"wz-upload-hint",children:["Supports ",i.includes("image")?"PDF and images":"PDF files"]}),e.jsx("input",{ref:n,type:"file",accept:i,multiple:s,className:"hidden",onChange:w,disabled:t})]})}function Me(t){return{async save(i){const s=await t.vfs.read(i),d=await s.getBlob(),n=URL.createObjectURL(d),o=document.createElement("a");o.href=n,o.download=s.getName(),o.click(),URL.revokeObjectURL(n)}}}const Be={"merge-pdf":"Merging","split-pdf":"Splitting","rotate-pdf":"Rotating","delete-pages-pdf":"Deleting pages","pdf-editor":"Applying edits","compress-pdf":"Compressing","ocr-pdf":"Scanning","pdf-to-jpg":"Converting","word-to-pdf":"Converting","excel-to-pdf":"Converting","encrypt-pdf":"Encrypting","protect-pdf":"Protecting","unlock-pdf":"Unlocking","share-pdf":"Preparing share"},Le={"merge-pdf":"Merge complete","split-pdf":"Split complete","rotate-pdf":"Rotation complete","delete-pages-pdf":"Delete pages complete","pdf-editor":"Edits applied","compress-pdf":"Compression complete","ocr-pdf":"OCR complete","pdf-to-jpg":"Conversion complete","word-to-pdf":"Conversion complete","excel-to-pdf":"Conversion complete","encrypt-pdf":"Encryption complete","protect-pdf":"Protection complete","unlock-pdf":"Unlock complete","share-pdf":"Share ready"};function De(t){return Be[t]??"Processing"}function Oe(t){return Le[t]??"Action complete"}async function Ae(t,i){const s=new Map,d=[];for(const n of i){if(!Number.isInteger(n.pageIndex)||n.pageIndex<0)continue;let o=s.get(n.fileId);if(!o){const D=await(await t.vfs.read(n.fileId)).getBlob();o=new Uint8Array(await D.arrayBuffer()),s.set(n.fileId,o)}const{PDFDocument:u}=await je(),f=await u.load(o,{ignoreEncryption:!0}
1);if(n.pageIndex>=f.getPageCount())continue;const p=await u.create(),[w]=await p.copyPages(f,[n.pageIndex]);p.addPage(w);const a=new Uint8Array(await p.save()),y=new File([a],`studio-page-${n.pageIndex+1}.pdf`,{type:"application/pdf"}),b=await t.vfs.write(y);d.push(b.id)}return d}function Ue({step:t}){const i=["Configure","Processing","Result"],s=t==="upload"||t==="config"?0:t==="processing"?1:2;return e.jsx("div",{className:"wz-steps",children:i.map((d,n)=>{const o=n<s,u=n===s;return e.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[e.jsxs("div",{className:`wz-step${u?" wz-step--active":o?" wz-step--done":""}`,children:[e.jsx("div",{className:"wz-step-num",children:o?"â":n+1}),e.jsx("span",{className:"wz-step-label",children:d})]}),n<i.length-1&&e.jsx("div",{className:`wz-step-line${o?" wz-step-line--done":""}`})]},d)})})}const Te=[{label:"Compress PDF",path:"/compress-pdf"},{label:"PDF to JPG",path:"/pdf-to-jpg"},{label:"Merge PDF",path:"/merge-pdf"},{label:"Protect PDF",path:"/protect-pdf"},{label:"Auto-TOC",path:"/auto-toc"}];function Ye({toolId:t,context:i,ioAdapter:s,limitService:d}){const{runtime:n}=re(),o=xe(),u=we(),[f,p]=l.useState(0),w=i??n.billing.getContext(),a=l.useSyncExternalStore(h=>n.billing.subscribe(h),()=>n.billing.getContext().plan),{requestDownload:y,overlay:b}=ve(a),{state:c,configComponent:D,handleFilesAdded:E,hydrateFromFileIds:B,startProcessing:P,cancelProcessing:M,resetFlow:I,retryConfigLoad:g,dismissToast:x,dismissUpsell:C}=Pe(t,{context:w,limitService:d}),S=n.registry.get(t),N=D,r=N,v=c.step==="result"?c.outputIds:c.fileIds,{previews:z,isLoading:k}=ke(n,t,v),m=(c.step==="config"||c.step==="result")&&S.layout==="split",F=l.useMemo(()=>`wizard-ui-${crypto.randomUUID()}`,[]),V=l.useMemo(()=>s??Me(n),[s,n]),ce=l.useMemo(()=>t==="word-to-pdf"?".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document":t==="excel-to-pdf"?".xls,.xlsx,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":t==="ocr-pdf"?"application/pdf,image/*":"application/pdf",[t]),de=l.useMemo(()=>!["pdf-to-jpg","split-pdf"].includes(t),[t]),j=u.state??null,R=(j==null?void 0:j.source)==="studio",L=j==null?void 0:j.studioContext,ue=j==null?void 0:j.studioReturnContext,_=t==="word-to-pdf"||t==="excel-to-pdf"||t==="pdf-to-jpg"||t==="pdf-editor",O=t==="word-to-pdf"||t==="excel-to-pdf"||t==="pdf-to-jpg"&&!R||t==="pdf-editor",pe=!(t==="word-to-pdf"||t==="excel-to-pdf"),he=()=>ue,W=h=>{o("/studio",{state:{source:"studio",studioReturnContext:he(),...h?{studioToolResult:{toolId:t,outputIds:c.outputIds,studioContext:L}}:{}}})},U=()=>{if(R){W(!1);return}I(!0)},$=l.useCallback(async h=>{h.length!==0&&(c.fileIds.length>0&&await I(!0),await E(h))},[E,I,c.fileIds.length]);l.useEffect(()=>{let h=!1;return(async()=>{const ge=Array.isArray(j==null?void 0:j.preloadedFileIds)?j.preloadedFileIds.filter(A=>typeof A=="string"&&A.length>0):[],se=(L==null?void 0:L.mode)==="page-selection"?L.selectedPages:[];let q=ge;if(se.length>0)try{const A=await Ae(n,se);A.length>0&&(q=A)}catch(A){console.error("Failed to prepare selected Studio pages for tool input:",A)}h||q.length===0||await B(q)})(),()=>{h=!0}},[B,u.key,j==null?void 0:j.preloadedFileIds,L,n]);const G=h=>P(L?{...h??{},studioContext:L}:h);if(l.useEffect(()=>{c.toast&&(n.telemetry.track({type:"UI_TOAST_SHOWN",runId:F,toolId:t,message:c.toast,level:"error"}),x())},[x,n.telemetry,c.toast,t,F]),l.useEffect(()=>{c.upsellReason&&C()},[C,c.upsellReason]),pe&&!R)return e.jsxs("div",{className:"wz-page",children:[e.jsxs("div",{className:"wz-tool-header",children:[e.jsx("div",{className:"wz-tool-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("div",{children:[e.jsx("div",{className:"wz-tool-title",children:S.name}),e.jsx("div",{className:"wz-tool-desc",children:S.description})]})]}
1),e.jsxs("div",{className:"wz-card wz-card-body",children:[e.jsx("p",{style:{fontSize:13,color:"var(--text-muted)",marginBottom:16},children:"This workflow is Studio-first. Select a document in Studio and launch the tool from there."}),e.jsx("button",{className:"wz-btn wz-btn-primary",onClick:()=>o("/studio"),children:"Go to Studio"})]})]});const ee=De(t),te=Oe(t);return e.jsxs("div",{className:oe("wz-page",m&&"wz-page--split",(t==="word-to-pdf"||t==="excel-to-pdf")&&"wz-page--fullwidth"),children:[e.jsxs("div",{className:"wz-tool-header",children:[e.jsx("div",{className:"wz-tool-icon","aria-hidden":"true",children:e.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"var(--accent)",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"16",y1:"13",x2:"8",y2:"13"}),e.jsx("line",{x1:"16",y1:"17",x2:"8",y2:"17"})]})}),e.jsxs("div",{children:[e.jsx("div",{className:"wz-tool-title",children:S.name}),e.jsx("div",{className:"wz-tool-desc",children:S.description}),e.jsxs("div",{className:"wz-tool-privacy",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),"Processed locally · files never leave your device"]})]})]}),!O&&e.jsx(Ue,{step:c.step}),c.error&&e.jsxs("div",{className:"wz-error",children:[e.jsx("strong",{children:"Error:"})," ",c.error]}),!O&&!m&&t!=="excel-to-pdf"&&t!=="pdf-editor"&&e.jsx(J,{runtime:n,previews:z,isLoading:k,toolId:t,title:c.step==="result"?"Result Preview":"Preview"}),e.jsxs(Re,{children:[O&&r&&e.jsx("div",{className:"wz-stage-fade",children:e.jsx(Y,{onRetry:()=>{g(),p(h=>h+1)},children:e.jsx(l.Suspense,{fallback:e.jsx("p",{style:{color:"var(--text-muted)",fontSize:13},children:"Loading configurationâ¦"}),children:e.jsx(r,{inputFiles:c.fileIds,onStart:G,onBack:U,onPickFiles:c.isProcessing?void 0:$,onClearFiles:()=>void I(!0),currentStep:c.step,progress:c.progress,outputCount:c.outputIds.length,onDownload:R?void 0:()=>y(t,async()=>{await Promise.all(c.outputIds.map(async h=>V.save(h)))})})})},f)}),!O&&c.step==="upload"&&(_&&N?e.jsx("div",{className:"wz-stage-fade",children:e.jsx(Y,{onRetry:()=>{g(),p(h=>h+1)},children:e.jsx(l.Suspense,{fallback:e.jsx("p",{style:{color:"var(--text-muted)",fontSize:13},children:"Loading configurationâ¦"}),children:e.jsx(N,{inputFiles:c.fileIds,onStart:G,onBack:U,onPickFiles:$,onClearFiles:()=>void I(!0)})})},f)}):e.jsxs("div",{className:"wz-stage-fade",children:[e.jsx(Ee,{onFilesAdded:E,disabled:c.isValidating,multiple:de,accept:ce}),c.isValidating&&e.jsx("p",{style:{marginTop:12,fontSize:13,color:"var(--text-muted)"},children:"Validating access limitsâ¦"}),R&&e.jsx("div",{style:{marginTop:12},children:e.jsx("button",{className:"wz-btn wz-btn-ghost",onClick:U,children:"Back to Studio"})})]})),!O&&c.step==="config"&&N&&e.jsx("div",{className:"wz-stage-fade",children:m?e.jsxs("div",{className:"wizard-config-split",children:[e.jsx("div",{className:"wizard-config-preview-pane",children:e.jsx(J,{runtime:n,previews:z,isLoading:k,toolId:t,title:"Preview"})}),e.jsx("div",{className:"wizard-config-controls-pane",children:e.jsx(Y,{onRetry:()=>{g(),p(h=>h+1)},children:e.jsx(l.Suspense,{fallback:e.jsx("p",{style:{color:"var(--text-muted)",fontSize:13},children:"Loading configurationâ¦"}),children:e.jsx(N,{inputFiles:c.fileIds,onStart:G,onBack:U,onPickFiles:_?$:void 0,onClearFiles:_?(()=>void I(!0)):void 0})})},f)})]}):e.jsx(Y,{onRetry:()=>{g(),p(h=>h+1)},children:e.jsx(l.Suspense,{fallback:e.jsx("p",{style:{color:"var(--text-muted)",fontSize:13},children:"Loading configurationâ¦"}),children:e.jsx(N,{inputFiles:c.fileIds,onStart:G,onBack:U,onPickFiles:_?$:void 0,onClearFiles:_?(()=>void I(!0)):void 0})})},f)}),!O&&c.step==="processing"&&e.jsx("div",{className:"wz-stage-fade",children:e.jsx("div",{className:"wz-card",children:e.jsxs("div",{className:"wz-card-body",style:{padding:"24px 20px"},children:[e.jsxs("div",{style:{marginBottom:20},children:[e.jsxs("div",{style:{fontSize:14,fontWeight:600,marginBottom:5,color:"var(--text)"},children:[ee,"â¦"]}),e.jsx("div",{style:{fontSize:13,color:"var(--text-muted)"},children:"Processing in your browser. Your file stays on your device."})]}),e.jsx("div",{className:"wz-progress-track",children:e.jsx("div",{className:"wz-progress-fill",style:{width:`${Math.max(2,c.progress)}%`}})}),e.jsxs("div",{className:"wz-progress-labels",children:[e.jsxs("span",{children:[ee,"â¦"]}),e.jsxs("span",{className:"wz-progress-pct",children:[Math.round(c.progress),"%"]})]}),e.jsxs("div",{className:"wz-processing-note",children:[e.jsx("div",{className:"wz-spinner"}),"Worker executing in private sandbox · 0 bytes sent to server"]}),e.jsx("div",{style:{marginTop:18},children:e.jsx("button",{className:"wz-btn wz-btn-ghost wz-btn-danger",onClick:()=>M(),children:"Cancel"})})]})})}),!O&&c.step==="result"&&e.jsx("div",{className:"wz-stage-fade",children:m?e.jsxs("div",{className:"wizard-result-split",children:[e.jsx("div",{className:"wizard-result-preview-pane",children:e.jsx(J,{runtime:n,previews:z,isLoading:k,toolId:t,title:"Result Preview"})}
1),e.jsxs("div",{className:"wizard-result-controls-pane",children:[e.jsxs("div",{className:"wz-result-hero",style:{padding:"20px 0 16px"},children:[e.jsx("div",{className:"wz-result-check",children:"â"}),e.jsx("div",{className:"wz-result-title",children:"Done"}),e.jsxs("div",{className:"wz-result-sub",children:[te," · ",c.outputIds.length," file",c.outputIds.length!==1?"s":""," generated"]})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[!R&&e.jsxs("button",{className:"wz-btn wz-btn-primary",style:{width:"100%",justifyContent:"center"},onClick:()=>y(t,async()=>{await Promise.all(c.outputIds.map(async h=>V.save(h)))}),children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),c.outputIds.length>1?"Download ZIP":"Download File"]}),e.jsx("button",{className:"wz-btn wz-btn-ghost",style:{justifyContent:"center"},onClick:()=>void I(!0),children:"Run again"}),R&&e.jsx("button",{className:"wz-btn wz-btn-primary",style:{justifyContent:"center"},onClick:()=>W(!0),children:"Save to Studio"}),R&&e.jsx("button",{className:"wz-btn wz-btn-ghost",style:{justifyContent:"center"},onClick:()=>W(!1),children:"Discard and Return"})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"wz-card",children:[e.jsxs("div",{className:"wz-result-hero",children:[e.jsx("div",{className:"wz-result-check",children:"â"}),e.jsx("div",{className:"wz-result-title",children:"Done"}),e.jsxs("div",{className:"wz-result-sub",children:[te," · ",c.outputIds.length," file",c.outputIds.length!==1?"s":""," generated"]})]}),e.jsxs("div",{className:"wz-output-row",children:[e.jsx("div",{className:"wz-output-icon",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"#0f7b6c",strokeWidth:"2",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("div",{children:[e.jsxs("div",{className:"wz-output-name",children:[c.outputIds.length," file",c.outputIds.length!==1?"s":""," generated"]}),e.jsx("div",{className:"wz-output-meta",children:"Ready for download"})]}),!R&&e.jsxs("button",{className:"wz-btn-download",onClick:()=>y(t,async()=>{await Promise.all(c.outputIds.map(async h=>V.save(h)))}),children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),"Download"]})]}),e.jsxs("div",{className:"wz-result-actions",children:[e.jsxs("button",{className:"wz-btn wz-btn-ghost",onClick:()=>void I(!0),children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",children:[e.jsx("polyline",{points:"1 4 1 10 7 10"}),e.jsx("path",{d:"M3.51 15a9 9 0 1 0 .49-4.5"})]}),"Run again"]}),R?e.jsxs(e.Fragment,{children:[e.jsx("button",{className:"wz-btn wz-btn-primary",onClick:()=>W(!0),children:"Save to Studio"}),e.jsx("button",{className:"wz-btn wz-btn-ghost",style:{marginLeft:"auto"},onClick:()=>W(!1),children:"â Back to Studio"})]}):e.jsx("button",{className:"wz-btn wz-btn-ghost",style:{marginLeft:"auto"},onClick:U,children:"â Back to Studio"})]})]}),e.jsxs("div",{className:"wz-also-try",children:[e.jsx("div",{className:"wz-also-try-label",children:"Also try"}),e.jsx("div",{className:"wz-also-try-list",children:Te.filter(h=>!h.path.includes(t)).slice(0,4).map(h=>e.jsxs("div",{className:"wz-also-try-item",onClick:()=>o(h.path),children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"})}),h.label]},h.label))})]})]})})]}),b]})}export{Ee as SmartUploadZone,Ye as WizardShell};
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.