const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-BnEvgIXZ.js","assets/vendor-codemirror-D0yxdRpg.js","assets/rolldown-runtime-aKtaBQYM.js","assets/docx-preview-Dxj1EkCO.js","assets/jszip.min-DT31yWkU.js"])))=>i.map(i=>d[i]);
import{g as e}from"./vendor-codemirror-D0yxdRpg.js";import{t}from"./excel-worksheet-utils-EyvwNT4X.js";var n=!1,r=5,i=5;async function a(){let t=await e(()=>import(`./pdf-BnEvgIXZ.js`),__vite__mapDeps([0,1,2]));return n||=(t.GlobalWorkerOptions.workerSrc=new URL(`/assets/pdf.worker.min-iDqQPrd3.mjs`,``+import.meta.url).toString(),!0),t}function o(){return new Promise(e=>requestAnimationFrame(()=>e()))}async function s(e,t,n){let s=(await a()).getDocument({data:t}),c=s;e.innerHTML=``;let l=document.createElement(`p`);l.className=`p-4 text-sm text-fg-muted`,l.textContent=n?.loadingText??`…`,e.appendChild(l);let u=null,d=null;try{u=await s.promise}catch(e){throw c?.destroy(),c=null,e}c=null,e.innerHTML=``;let f=document.createElement(`div`);e.appendChild(f);let p=document.createElement(`div`);f.appendChild(p);let m=async(e,t)=>{if(!u)return null;let n=await u.getPage(e),r=document.createElement(`div`);r.className=`mb-4 last:mb-0`;let i=document.createElement(`canvas`),a=i.getContext(`2d`),o=n.getViewport({scale:1.5});if(i.height=o.height,i.width=o.width,i.className=`mx-auto block h-auto w-full max-w-full rounded border border-edge bg-white shadow-sm dark:border-edge`,a&&(a.fillStyle=`white`,a.fillRect(0,0,i.width,i.height)),await n.render({canvasContext:a,viewport:o,canvas:i}).promise,r.appendChild(i),e<t){let e=document.createElement(`div`);e.className=`my-4 h-px bg-edge`,r.appendChild(e)}return r},h=async(e,t)=>{let n=await Promise.all(e.map(e=>m(e,t)));for(let e of n)e&&p.appendChild(e);await o()},g=u.numPages,_=Math.min(r,g);_>0&&await h(Array.from({length:_},(e,t)=>t+1),g);let v=_+1;if(v<=g){let t=document.createElement(`p`);t.className=`py-2 text-center text-xs text-fg-muted`,t.textContent=n?.loadMoreHint??``,f.appendChild(t);let r=document.createElement(`div`);r.className=`pdf-lazy-sentinel h-12 w-full shrink-0`,r.setAttribute(`aria-hidden`,`true`),f.appendChild(r);let a=!1;d=new IntersectionObserver(async e=>{if(!(!e[0]?.isIntersecting||a||!u)){a=!0;try{let e=Math.min(v+i-1,g);await h(Array.from({length:e-v+1},(e,t)=>v+t),g),v=e+1,v>g&&(d?.disconnect(),d=null,t.remove(),r.remove())}finally{a=!1}}},{root:e,rootMargin:`320px`,threshold:0}),d.observe(r)}return{cleanup:()=>{if(d?.disconnect(),d=null,c){try{c.destroy()}catch{}c=null}u&&=(u.destroy(),null),e.innerHTML=``}}}async function c(t,n){let{renderAsync:r,defaultOptions:i}=await e(async()=>{let{renderAsync:e,defaultOptions:t}=await import(`./docx-preview-Dxj1EkCO.js`);return{renderAsync:e,defaultOptions:t}},__vite__mapDeps([3,2,4]));t.innerHTML=``;let a=document.createElement(`div`);a.className=`docx-wrapper-custom max-w-full overflow-x-auto`,t.appendChild(a),await r(n,a,void 0,{...i,className:`docx`,inWrapper:!0,ignoreWidth:!0,ignoreHeight:!1,ignoreFonts:!0,breakPages:!0,ignoreLastRenderedPageBreak:!0,experimental:!1,trimXmlDeclaration:!0,useBase64URL:!1,renderHeaders:!0,renderFooters:!0,renderFootnotes:!0,renderEndnotes:!0});let o=document.createElement(`style`);return o.textContent=`
    .docx-preview-host { padding: 0; }
    .docx-preview-host .docx-wrapper-custom { max-width: 100%; overflow-x: auto; }
    .docx-preview-host .docx-wrapper { max-width: 100% !important; margin: 0 !important; background: transparent !important; padding: 0em !important; }
    .docx-preview-host .docx-wrapper > section.docx { box-shadow: none !important; border: none !important; border-radius: 0 !important; margin: 0 !important; padding: 2em !important; background: white !important; color: black !important; max-width: 100% !important; width: 100% !important; min-width: 0 !important; overflow-x: auto !important; font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans CJK JP", sans-serif !important; }
    .docx-preview-host table { max-width: 100% !important; width: auto !important; overflow-x: auto !important; display: block !important; font-family: inherit !important; }
    .docx-preview-host img { max-width: 100% !important; height: auto !important; }
    .docx-preview-host p, .docx-preview-host span, .docx-preview-host div, .docx-preview-host td, .docx-preview-host th { max-width: 100% !important; word-wrap: break-word !important; overflow-wrap: break-word !important; font-family: inherit !important; }
    .docx-preview-host .docx-page-break { display: none !important; }
  `,t.classList.add(`docx-preview-host`),t.appendChild(o),{cleanup:()=>{t.innerHTML=``,t.classList.remove(`docx-preview-host`)}}}async function l(t,n,r){let i=await e(()=>import(`./xlsx-CKkngM-o.js`),[]),a=i.read(n,{type:`array`});t.innerHTML=``;let o=document.createElement(`div`);o.className=`flex h-full min-h-0 flex-col overflow-auto`,t.appendChild(o);let s=a.SheetNames??[];if(s.length===0){let e=document.createElement(`p`);return e.className=`p-4 text-sm text-fg-muted`,e.textContent=`(No sheets in workbook.)`,o.appendChild(e),{truncated:!1,cleanup:()=>{t.innerHTML=``}}}let c=!1;if(s.length>1){let e=document.createElement(`div`);e.className=`sticky top-0 z-10 mb-4 flex gap-2 border-b border-edge bg-surface-panel dark:border-edge`;let t=[];s.forEach((n,o)=>{let s=document.createElement(`button`);s.type=`button`,s.textContent=n,s.className=o===0?`border-b-2 border-accent px-4 py-2 text-sm font-medium text-accent`:`border-b-2 border-transparent px-4 py-2 text-sm font-medium text-fg-muted hover:border-edge hover:text-fg`;let l=document.createElement(`div`);l.style.display=o===0?`flex`:`none`,l.className=`min-h-0 flex-1 overflow-auto`;let d=u(i,a.Sheets[n],n,r?.truncationNotice);d.truncated&&(c=!0),l.appendChild(d.element),t.push(l),s.onclick=()=>{e.querySelectorAll(`button`).forEach((e,t)=>{t===o?e.className=`border-b-2 border-accent px-4 py-2 text-sm font-medium text-accent`:e.className=`border-b-2 border-transparent px-4 py-2 text-sm font-medium text-fg-muted hover:border-edge hover:text-fg`}),t.forEach((e,t)=>{e.style.display=t===o?`flex`:`none`})},e.appendChild(s)}),o.appendChild(e),t.forEach(e=>{o.appendChild(e)})}else{let e=s[0],t=u(i,a.Sheets[e],e,r?.truncationNotice);c=t.truncated,o.appendChild(t.element)}return{truncated:c,cleanup:()=>{t.innerHTML=``}}}function u(e,n,r,i){let a=document.createElement(`div`);if(!n){let e=document.createElement(`p`);return e.className=`p-4 text-sm text-fg-muted`,e.textContent=`Sheet "${r}" is missing from the workbook.`,a.appendChild(e),{element:a,truncated:!1}}if(!t(n)){let e=document.createElement(`p`);return e.className=`p-4 text-sm text-fg-muted`,e.textContent=`(Empty sheet — no cell range.)`,a.appendChild(e),{element:a,truncated:!1}}try{let t=e.utils.sheet_to_json(n,{header:1,defval:``}),r=t.reduce((e,t)=>Math.max(e,t.length),0),o=t.length>500||r>64;if(o&&i){let e=document.createElement(`p`);e.className=`mb-2 border-b border-edge-subtle px-1 pb-2 text-xs text-fg-muted dark:border-edge`,e.textContent=i,a.appendChild(e)}let s=t.slice(0,500).map(e=>e.slice(0,64)),c=document.createElement(`table`);return c.className=`w-full border-collapse text-fg`,s.forEach((e,t)=>{let n=document.createElement(`tr`);t%2==1&&(n.className=`bg-surface-hover/40`),e.forEach(e=>{let t=document.createElement(`td`);t.className=`border border-edge px-3 py-2 text-left text-sm dark:border-edge`,t.textContent=e==null?``:String(e),n.appendChild(t)}),c.appendChild(n)}),a.appendChild(c),{element:a,truncated:o}}catch(e){let t=document.createElement(`p`);return t.className=`p-4 text-sm text-red-600 dark:text-red-400`,t.textContent=e instanceof Error?e.message:String(e),a.appendChild(t),{element:a,truncated:!1}}}export{c as renderDocxInContainer,l as renderExcelInContainer,s as renderPdfInContainer};