@json-to-office/jto 0.35.0 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/client/assets/{HomePage-DgVVosCp.js → HomePage-C4xj6RnX.js} +4 -4
- package/dist/client/assets/{HomePage-DgVVosCp.js.map → HomePage-C4xj6RnX.js.map} +1 -1
- package/dist/client/assets/{JsonEditorPage-13oxEHfY.js → JsonEditorPage-DcXk6s88.js} +3 -3
- package/dist/client/assets/{JsonEditorPage-13oxEHfY.js.map → JsonEditorPage-DcXk6s88.js.map} +1 -1
- package/dist/client/assets/{MonacoPluginProvider-DiUyU9px.js → MonacoPluginProvider-iwEEsKo7.js} +3 -3
- package/dist/client/assets/{MonacoPluginProvider-DiUyU9px.js.map → MonacoPluginProvider-iwEEsKo7.js.map} +1 -1
- package/dist/client/assets/{editor-monaco-json-CTrPZKuA.js → editor-monaco-json-Dg4yC3gC.js} +2 -2
- package/dist/client/assets/{editor-monaco-json-CTrPZKuA.js.map → editor-monaco-json-Dg4yC3gC.js.map} +1 -1
- package/dist/client/assets/{editor-ouhvdGgK.js → editor-p__9lo1t.js} +2 -2
- package/dist/client/assets/{editor-ouhvdGgK.js.map → editor-p__9lo1t.js.map} +1 -1
- package/dist/client/assets/{editor-refs-store-DNQzN0_z.js → editor-refs-store-B2riWLl0.js} +2 -2
- package/dist/client/assets/{editor-refs-store-DNQzN0_z.js.map → editor-refs-store-B2riWLl0.js.map} +1 -1
- package/dist/client/assets/{index-CRuLxurM.js → index-CboJPFqh.js} +3 -3
- package/dist/client/assets/index-CboJPFqh.js.map +1 -0
- package/dist/client/assets/{preview-D3QYaLPp.js → preview-Qj-FLOiI.js} +2 -2
- package/dist/client/assets/{preview-D3QYaLPp.js.map → preview-Qj-FLOiI.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +5 -5
- package/dist/client/assets/index-CRuLxurM.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/docx-preview-DQa8jhzH.js","assets/react-vendor-CTFDOf2G.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as x,j as e,c as A}from"./react-vendor-CTFDOf2G.js";import{S as T,c as S,h as ce,F as b,j as te,k as Ee,P as Re,W as ke,_ as Ce,p as Le,A as H}from"./index-CRuLxurM.js";import{S as O,B as Fe,P as Oe,b as $e,D as Me,c as De,d as Te,e as Ae}from"./HomePage-DgVVosCp.js";import{B as le}from"./editor-refs-store-DNQzN0_z.js";import{e as Ie,Q as J,w as de}from"./ui-vendor-DyQLnWB8.js";import{u as E,a as ue,d as se,b as Be}from"./MonacoPluginProvider-DiUyU9px.js";import{ag as me,ah as Pe}from"./radix-ui-Bq-7y_Sq.js";import"./query-vendor-Df8-oete.js";import"./monaco-editor-BcgxPCqT.js";import"./state-vendor-ByFYl9bq.js";var ze=["fonts.gstatic.com","fonts.googleapis.com","cdn.jsdelivr.net"];function _e(t){let r;try{r=new URL(t)}catch{return!1}return r.protocol!=="https:"?!1:ze.includes(r.hostname.toLowerCase())}function fe(t){const[r]=x.useState(()=>Date.now()),s=t??r,[o,n]=x.useState(()=>Date.now());return x.useEffect(()=>{const a=setInterval(()=>n(Date.now()),100);return()=>clearInterval(a)},[]),Math.max(0,(o-s)/1e3)}function Ue(t){var r,s;if(!t)return null;try{const o=JSON.parse(t);if(!o||typeof o!="object")return null;const n=new Map,a=[o];for(;a.length>0;){const c=a.pop();if(!c||typeof c!="object")continue;const{name:u,children:f}=c;typeof u=="string"&&n.set(u,(n.get(u)??0)+1),Array.isArray(f)&&a.push(...f)}const l=[["slide","slide","slides"],["section","section","sections"],["visual","visual","visuals"],["chart","chart","charts"],["image","image","images"],["table","table","tables"],["shape","shape","shapes"],["paragraph","paragraph","paragraphs"]].map(([c,u,f])=>{const m=n.get(c)??0;return{label:m===1?u:f,count:m}}).filter(c=>c.count>0).slice(0,5),d=(s=(r=o.props)==null?void 0:r.metadata)==null?void 0:s.title;return{title:typeof d=="string"?d:void 0,counts:l,visualCount:(n.get("visual")??0)+(n.get("chart")??0),imageCount:n.get("image")??0}}catch{return null}}function We(t){const r=[];return t&&t.visualCount>0&&r.push(`${t.visualCount} visual${t.visualCount===1?"":"s"} in this document ${t.visualCount===1?"is":"are"} rasterized on first build — later builds reuse the cached renders.`),t&&t.imageCount>3&&r.push("Large embedded images dominate build time — downscaling them speeds up iteration."),r.push("Re-running an unchanged document is served from the cache almost instantly.","Generation warnings, if any, will appear above the preview when the build completes."),r}const Ge=()=>e.jsx("svg",{className:"h-3.5 w-3.5 text-success",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M3 8.5L6.5 12L13 4.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})});function He({className:t,currentStage:r="parsing",message:s,documentText:o,startedAt:n,onCancel:a}){const i=["parsing","building","rendering","finalizing"],l={parsing:"Validating JSON",building:"Building structure",rendering:"Rendering content",finalizing:"Finalizing document"},d=i.indexOf(r),c=fe(n),u=x.useMemo(()=>Ue(o),[o]),f=x.useMemo(()=>We(u),[u]),m=c>3,g=Math.floor(Math.max(0,c-3)/5)%f.length;return e.jsxs("div",{className:S("p-6 max-w-lg mx-auto space-y-5",t),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(T,{size:"md"}),e.jsxs("div",{className:"space-y-0.5 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:u!=null&&u.title?`Generating “${u.title}”`:"Generating document"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",role:"status","aria-live":"polite",children:s||`${l[r]}...`})]})]}),e.jsxs("span",{className:"shrink-0 rounded-full bg-secondary px-2 py-0.5 text-xs text-muted-foreground tabular-nums","aria-hidden":"true",children:[c.toFixed(1),"s"]})]}),u&&u.counts.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5","aria-label":"Document contents",children:u.counts.map(({label:w,count:j})=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:j}),w]},w))}),e.jsx("div",{className:"space-y-3",children:i.map((w,j)=>{const R=j===d,k=j<d;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:S(R?"text-primary font-medium":k?"text-muted-foreground":"text-muted-foreground/60"),children:l[w]}),k?e.jsx(Ge,{}):R?e.jsx(T,{size:"sm",className:"h-3.5 w-3.5"}):e.jsx("span",{className:"h-3.5 w-3.5 rounded-full border border-muted-foreground/40"})]}),e.jsx("div",{className:"w-full bg-secondary rounded-full h-1.5 overflow-hidden",children:k?e.jsx("div",{className:"h-full w-full rounded-full bg-success"}):R?e.jsx("div",{className:"h-full w-2/5 rounded-full bg-primary animate-progress-indeterminate"}):null})]},w)})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 min-h-8",children:[e.jsx("p",{className:S("text-xs text-muted-foreground/80 italic transition-opacity duration-500",m?"opacity-100":"opacity-0"),children:f[g]}),a&&e.jsx(le,{variant:"outline",size:"sm",onClick:a,className:"shrink-0",children:"Cancel"})]})]})}function Je({mode:t,message:r,startedAt:s,onCancel:o,className:n}){const a=fe(s);return e.jsxs("div",{className:S("flex flex-col items-center gap-2 rounded-md border bg-background/95 px-6 py-4 shadow-sm",n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{size:"md"}),e.jsx("p",{className:"text-sm font-medium",role:"status","aria-live":"polite",children:t==="generating"?"Generating":"Rendering"}),e.jsxs("span",{className:"rounded-full bg-secondary px-2 py-0.5 text-xs text-muted-foreground tabular-nums","aria-hidden":"true",children:[a.toFixed(1),"s"]})]}),r&&e.jsx("p",{className:"max-w-xs text-center text-xs text-muted-foreground truncate",children:r}),t==="generating"&&o&&e.jsx(le,{variant:"outline",size:"sm",onClick:o,children:"Cancel"})]})}function qe({renderingLibrary:t,className:r}){const s=a=>{switch(a){case"LibreOffice":return{name:"LibreOffice",description:"Converting document to PDF locally..."};case"Office":return{name:"Microsoft Office",description:"Uploading file and loading Office viewer..."};case"Docs":return{name:"Google Docs",description:"Uploading file and loading Docs viewer..."};default:return{name:"Default",description:"Processing document..."}}},{name:o,description:n}=s(t);return e.jsxs("div",{className:S("flex flex-col items-center justify-center h-full p-8 space-y-4",r),children:[e.jsx(T,{size:"lg"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Rendering Preview"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Using ",o," renderer"]}),e.jsx("p",{className:"text-xs text-muted-foreground/80",children:n})]}),e.jsxs("div",{className:"w-full max-w-md space-y-3",children:[e.jsx(O,{className:"h-16 w-full"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"h-4 w-full"}),e.jsx(O,{className:"h-4 w-3/4"}),e.jsx(O,{className:"h-4 w-1/2"})]}),e.jsx(O,{className:"h-12 w-full"})]})]})}const he=A.forwardRef(({isLoading:t,iframeSrc:r,iframeSrcDoc:s,isGenerating:o,generationProgress:n,generationDocumentText:a,generationStartedAt:i,onCancelGeneration:l},d)=>{const[c,u]=x.useState(!1);x.useEffect(()=>{u(!1)},[r,s]);const f=()=>{u(!0)},m=()=>{console.warn("Iframe failed to load content"),u(!1)},g=s?"allow-scripts allow-popups allow-forms":void 0,w=!!(r||s);return o&&!w?e.jsx("div",{className:"grow",children:e.jsx(He,{currentStage:n==null?void 0:n.stage,message:n==null?void 0:n.message,documentText:a,startedAt:i,onCancel:l})}):t&&!w?e.jsx("div",{className:"grow",children:e.jsx(qe,{renderingLibrary:"LibreOffice"})}):w?e.jsxs("div",{className:"h-full w-full relative bg-white",children:[!c&&e.jsx("div",{className:"absolute inset-0 bg-muted/80 flex items-center justify-center z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-foreground mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),(o||t)&&e.jsx("div",{className:"absolute inset-0 bg-background/60 backdrop-blur-[2px] flex items-center justify-center z-20 transition-opacity duration-200",children:e.jsx(Je,{mode:o?"generating":"rendering",message:o?n==null?void 0:n.message:void 0,startedAt:o?i:void 0,onCancel:o?l:void 0})}),e.jsx("iframe",{ref:d,className:"w-full h-full border-0",style:{backgroundColor:"white",opacity:c?1:0,transition:"opacity 0.2s ease-in-out"},src:r,srcDoc:s,onLoad:f,onError:m,sandbox:g,title:"Document preview","aria-label":`Preview of rendered ${ce.toLowerCase()}`},s?"srcdoc":"src")]}):null});he.displayName="PreviewFrame";const Ve=A.memo(he);function Ke({warnings:t,className:r}){const[s,o]=A.useState(!1);return!t||t.length===0?null:e.jsxs("div",{className:r,children:[e.jsxs("button",{type:"button",onClick:()=>o(!s),className:"flex w-full items-center gap-2 rounded-sm border border-transparent bg-warning/10 px-3 py-1.5 text-left transition-colors hover:bg-warning/20",children:[e.jsx(Ie,{className:`h-3.5 w-3.5 text-warning transition-transform flex-shrink-0 ${s?"rotate-90":""}`}),e.jsx(J,{className:"h-3.5 w-3.5 text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-medium text-warning",children:[t.length," warning",t.length!==1?"s":""]})]}),s&&e.jsx("div",{className:"mt-1.5 space-y-1.5",children:t.map((n,a)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-card px-3 py-2",children:[n.severity==="info"?e.jsx(de,{className:"h-3.5 w-3.5 mt-0.5 text-data-blue flex-shrink-0"}):e.jsx(J,{className:"h-3.5 w-3.5 mt-0.5 text-warning flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:"text-[11px] font-medium text-warning bg-warning/15 px-1 py-0.5 rounded-sm",children:n.component}),n.severity==="info"&&e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-data-blue font-medium",children:"info"})]}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground leading-relaxed",children:n.message}),n.context&&Object.keys(n.context).length>0&&e.jsxs("details",{className:"mt-1.5",children:[e.jsx("summary",{className:"text-[11px] text-muted-foreground/70 cursor-pointer hover:text-foreground",children:"Context"}),e.jsx("pre",{className:"mt-1 text-[11px] bg-header-bg p-1.5 rounded-sm overflow-x-auto text-muted-foreground",children:JSON.stringify(n.context,null,2)})]})]})]},a))})]})}const ne={pptx:["default","dark","minimal"],docx:["minimal","corporate","modern"]};function Xe({className:t}){var i;const r=E(l=>l.activeTab),s=E(l=>l.documentTypes),o=E(l=>l.documents),n=ue(l=>l.customThemes),a=x.useMemo(()=>{var c,u,f;if(!r||s[r]==="application/json+theme")return null;const l=o.find(m=>m.name===r);if(!(l!=null&&l.text))return null;let d;try{d=(u=(c=JSON.parse(l.text))==null?void 0:c.props)==null?void 0:u.theme}catch{return null}if(typeof d!="string"||!d||(f=ne[b])!=null&&f.includes(d))return null;for(const m of Object.values(n))if(m.valid&&m.name===d)return null;return d},[r,s,o,n]);return a?e.jsxs("div",{className:`flex items-start gap-2 rounded-sm border border-transparent bg-warning/10 px-3 py-2 ${t??""}`,children:[e.jsx(J,{className:"h-3.5 w-3.5 mt-0.5 text-warning flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 text-xs leading-relaxed",children:[e.jsxs("span",{className:"font-medium text-warning",children:["Theme"," ",e.jsx("code",{className:"bg-warning/20 px-1 py-0.5 rounded-sm text-warning",children:a})," ","is not available."]})," ",e.jsxs("span",{className:"text-warning/80",children:["Add it as a custom theme or use a built-in theme (",(i=ne[b])==null?void 0:i.join(", "),"). The renderer will fall back to a default."]})]})]}):null}const Ye=8*1024*1024;function re(t){return Array.isArray(t)?t:[]}function Qe(t,r){var a;let s=[];if(typeof t=="string"&&t.length>0)try{const i=JSON.parse(t);s=re((a=i==null?void 0:i.props)==null?void 0:a.fontRegistry)}catch{return[]}const o=[];for(const i of Object.values(r??{}))o.push(...re(i==null?void 0:i.fontRegistry));const n=new Map;for(const i of[...o,...s])i&&typeof i.family=="string"&&n.set(i.family.toLowerCase(),i);return[...n.values()]}function Ze(t,r,s){const o=[{family:t,cssWeight:r,cssStyle:s?"italic":"normal"}],n=ke[r];return r!==400&&r!==700&&n&&o.push({family:`${t} ${n}${s?" Italic":""}`,cssWeight:400,cssStyle:"normal"}),o}const et=/^(?:data:[a-z0-9.+-]+\/[a-z0-9.+-]+;base64,)?[A-Za-z0-9+/=\s]+$/i;function tt(t){return et.test(t)?t.startsWith("data:")?t:`data:font/ttf;base64,${t}`:null}function xe(t){const r=[];for(const s of t.sources??[]){if(s.kind==="safe"||s.kind==="file"||s.kind==="google")continue;const o="italic"in s?!!s.italic:!1,n="weight"in s&&s.weight?s.weight:400;if(s.kind==="data"){const a=tt(s.data);if(!a)continue;r.push({family:t.family,weight:n,italic:o,url:a});continue}_e(s.url)&&r.push({family:t.family,weight:n,italic:o,url:s.url,variable:s.kind==="variable"})}return r}function st(t,r,s){const o=new Map;for(const i of r)for(const l of xe(i)){const d=l.family.toLowerCase();let c=o.get(d);c||o.set(d,c=new Set),c.add(l.weight)}const n=[],a=new Set;for(const i of t){if(Ee(i))continue;const l=i.toLowerCase();if(a.has(l))continue;const d=Re.find(m=>m.family.toLowerCase()===l);if(!d)continue;a.add(l);const c=o.get(l),u=new Set([400,700,...s]),f=d.weights.filter(m=>u.has(m)&&!(c!=null&&c.has(m)));f.length!==0&&n.push({family:d.family,weights:f,italics:d.hasItalic})}return n}function pe(t,r,s){const o=[...new Set(r)].sort((a,i)=>a-i),n=s?`ital,wght@${[...o.map(a=>`0,${a}`),...o.map(a=>`1,${a}`)].join(";")}`:`wght@${o.join(";")}`;return`https://fonts.googleapis.com/css2?family=${encodeURIComponent(t)}:${n}&display=swap`}const G=new Map,nt=3e3;async function rt(t,r,s,o=fetch,n=nt){const a=pe(t,r,s),i=G.get(a);if(i)return i;const l=(async()=>{const d=new AbortController;let c;const u=new Promise((f,m)=>{c=setTimeout(()=>{d.abort(),m(new Error(`Google Fonts CSS timed out after ${n}ms`))},n)});try{const f=await Promise.race([o(a,{signal:d.signal}),u]);if(!f.ok)throw new Error(`Google Fonts CSS ${f.status}`);const m=await Promise.race([f.text(),u]);return at(m,t)}finally{c&&clearTimeout(c)}})();return G.set(a,l),l.catch(()=>G.delete(a)),l}function at(t,r){var o,n,a,i,l,d;const s=[];for(const c of t.split("@font-face")){const u=(n=(o=/src:\s*([^;]+);/.exec(c))==null?void 0:o[1])==null?void 0:n.trim();if(!u)continue;const f=((a=/font-style:\s*(\w+)/.exec(c))==null?void 0:a[1])??"normal",m=Number(((i=/font-weight:\s*(\d+)/.exec(c))==null?void 0:i[1])??"400"),g=(d=(l=/unicode-range:\s*([^;]+);/.exec(c))==null?void 0:l[1])==null?void 0:d.trim(),w=g&&/^[Uu]\+[0-9A-Fa-f?,+\-Uu\s]*$/.test(g)?g:void 0;s.push({family:r,weight:Number.isFinite(m)?m:400,italic:f==="italic",src:u,...w?{unicodeRange:w}:{}})}return s}function ae(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/</g,"\\3c ")}function it(t,r=Ye){const s=new Set,o=[];let n=0,a=0;for(const i of t){const l=i.url?`url("${ae(i.url)}")`:i.src&&!i.src.includes("<")?i.src:void 0;if(l)for(const d of Ze(i.family,i.weight,i.italic)){const c=`${d.family}|${d.cssWeight}|${d.cssStyle}|${l}`;if(s.has(c))continue;s.add(c);const u=d.family!==i.family,f=i.variable&&u?`font-variation-settings:"wght" ${i.weight};`:"",m=`@font-face{font-family:"${ae(d.family)}";src:${l};font-weight:${d.cssWeight};font-style:${d.cssStyle};font-display:swap;`+f+(i.unicodeRange?`unicode-range:${i.unicodeRange};`:"")+"}";if(n+m.length>r){a++;continue}n+=m.length,o.push(m)}}return a>0&&console.warn(`Preview fonts: dropped ${a} @font-face rule(s) over the ${r}-byte budget.`),o.join(`
|
|
2
|
+
import{r as x,j as e,c as A}from"./react-vendor-CTFDOf2G.js";import{S as T,c as S,h as ce,F as b,j as te,k as Ee,P as Re,W as ke,_ as Ce,p as Le,A as H}from"./index-CboJPFqh.js";import{S as O,B as Fe,P as Oe,b as $e,D as Me,c as De,d as Te,e as Ae}from"./HomePage-C4xj6RnX.js";import{B as le}from"./editor-refs-store-B2riWLl0.js";import{e as Ie,Q as J,w as de}from"./ui-vendor-DyQLnWB8.js";import{u as E,a as ue,d as se,b as Be}from"./MonacoPluginProvider-iwEEsKo7.js";import{ag as me,ah as Pe}from"./radix-ui-Bq-7y_Sq.js";import"./query-vendor-Df8-oete.js";import"./monaco-editor-BcgxPCqT.js";import"./state-vendor-ByFYl9bq.js";var ze=["fonts.gstatic.com","fonts.googleapis.com","cdn.jsdelivr.net"];function _e(t){let r;try{r=new URL(t)}catch{return!1}return r.protocol!=="https:"?!1:ze.includes(r.hostname.toLowerCase())}function fe(t){const[r]=x.useState(()=>Date.now()),s=t??r,[o,n]=x.useState(()=>Date.now());return x.useEffect(()=>{const a=setInterval(()=>n(Date.now()),100);return()=>clearInterval(a)},[]),Math.max(0,(o-s)/1e3)}function Ue(t){var r,s;if(!t)return null;try{const o=JSON.parse(t);if(!o||typeof o!="object")return null;const n=new Map,a=[o];for(;a.length>0;){const c=a.pop();if(!c||typeof c!="object")continue;const{name:u,children:f}=c;typeof u=="string"&&n.set(u,(n.get(u)??0)+1),Array.isArray(f)&&a.push(...f)}const l=[["slide","slide","slides"],["section","section","sections"],["visual","visual","visuals"],["chart","chart","charts"],["image","image","images"],["table","table","tables"],["shape","shape","shapes"],["paragraph","paragraph","paragraphs"]].map(([c,u,f])=>{const m=n.get(c)??0;return{label:m===1?u:f,count:m}}).filter(c=>c.count>0).slice(0,5),d=(s=(r=o.props)==null?void 0:r.metadata)==null?void 0:s.title;return{title:typeof d=="string"?d:void 0,counts:l,visualCount:(n.get("visual")??0)+(n.get("chart")??0),imageCount:n.get("image")??0}}catch{return null}}function We(t){const r=[];return t&&t.visualCount>0&&r.push(`${t.visualCount} visual${t.visualCount===1?"":"s"} in this document ${t.visualCount===1?"is":"are"} rasterized on first build — later builds reuse the cached renders.`),t&&t.imageCount>3&&r.push("Large embedded images dominate build time — downscaling them speeds up iteration."),r.push("Re-running an unchanged document is served from the cache almost instantly.","Generation warnings, if any, will appear above the preview when the build completes."),r}const Ge=()=>e.jsx("svg",{className:"h-3.5 w-3.5 text-success",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:e.jsx("path",{d:"M3 8.5L6.5 12L13 4.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})});function He({className:t,currentStage:r="parsing",message:s,documentText:o,startedAt:n,onCancel:a}){const i=["parsing","building","rendering","finalizing"],l={parsing:"Validating JSON",building:"Building structure",rendering:"Rendering content",finalizing:"Finalizing document"},d=i.indexOf(r),c=fe(n),u=x.useMemo(()=>Ue(o),[o]),f=x.useMemo(()=>We(u),[u]),m=c>3,g=Math.floor(Math.max(0,c-3)/5)%f.length;return e.jsxs("div",{className:S("p-6 max-w-lg mx-auto space-y-5",t),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx(T,{size:"md"}),e.jsxs("div",{className:"space-y-0.5 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:u!=null&&u.title?`Generating “${u.title}”`:"Generating document"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",role:"status","aria-live":"polite",children:s||`${l[r]}...`})]})]}),e.jsxs("span",{className:"shrink-0 rounded-full bg-secondary px-2 py-0.5 text-xs text-muted-foreground tabular-nums","aria-hidden":"true",children:[c.toFixed(1),"s"]})]}),u&&u.counts.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5","aria-label":"Document contents",children:u.counts.map(({label:w,count:j})=>e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground tabular-nums",children:j}),w]},w))}),e.jsx("div",{className:"space-y-3",children:i.map((w,j)=>{const R=j===d,k=j<d;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:S(R?"text-primary font-medium":k?"text-muted-foreground":"text-muted-foreground/60"),children:l[w]}),k?e.jsx(Ge,{}):R?e.jsx(T,{size:"sm",className:"h-3.5 w-3.5"}):e.jsx("span",{className:"h-3.5 w-3.5 rounded-full border border-muted-foreground/40"})]}),e.jsx("div",{className:"w-full bg-secondary rounded-full h-1.5 overflow-hidden",children:k?e.jsx("div",{className:"h-full w-full rounded-full bg-success"}):R?e.jsx("div",{className:"h-full w-2/5 rounded-full bg-primary animate-progress-indeterminate"}):null})]},w)})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 min-h-8",children:[e.jsx("p",{className:S("text-xs text-muted-foreground/80 italic transition-opacity duration-500",m?"opacity-100":"opacity-0"),children:f[g]}),a&&e.jsx(le,{variant:"outline",size:"sm",onClick:a,className:"shrink-0",children:"Cancel"})]})]})}function Je({mode:t,message:r,startedAt:s,onCancel:o,className:n}){const a=fe(s);return e.jsxs("div",{className:S("flex flex-col items-center gap-2 rounded-md border bg-background/95 px-6 py-4 shadow-sm",n),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{size:"md"}),e.jsx("p",{className:"text-sm font-medium",role:"status","aria-live":"polite",children:t==="generating"?"Generating":"Rendering"}),e.jsxs("span",{className:"rounded-full bg-secondary px-2 py-0.5 text-xs text-muted-foreground tabular-nums","aria-hidden":"true",children:[a.toFixed(1),"s"]})]}),r&&e.jsx("p",{className:"max-w-xs text-center text-xs text-muted-foreground truncate",children:r}),t==="generating"&&o&&e.jsx(le,{variant:"outline",size:"sm",onClick:o,children:"Cancel"})]})}function qe({renderingLibrary:t,className:r}){const s=a=>{switch(a){case"LibreOffice":return{name:"LibreOffice",description:"Converting document to PDF locally..."};case"Office":return{name:"Microsoft Office",description:"Uploading file and loading Office viewer..."};case"Docs":return{name:"Google Docs",description:"Uploading file and loading Docs viewer..."};default:return{name:"Default",description:"Processing document..."}}},{name:o,description:n}=s(t);return e.jsxs("div",{className:S("flex flex-col items-center justify-center h-full p-8 space-y-4",r),children:[e.jsx(T,{size:"lg"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Rendering Preview"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Using ",o," renderer"]}),e.jsx("p",{className:"text-xs text-muted-foreground/80",children:n})]}),e.jsxs("div",{className:"w-full max-w-md space-y-3",children:[e.jsx(O,{className:"h-16 w-full"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{className:"h-4 w-full"}),e.jsx(O,{className:"h-4 w-3/4"}),e.jsx(O,{className:"h-4 w-1/2"})]}),e.jsx(O,{className:"h-12 w-full"})]})]})}const he=A.forwardRef(({isLoading:t,iframeSrc:r,iframeSrcDoc:s,isGenerating:o,generationProgress:n,generationDocumentText:a,generationStartedAt:i,onCancelGeneration:l},d)=>{const[c,u]=x.useState(!1);x.useEffect(()=>{u(!1)},[r,s]);const f=()=>{u(!0)},m=()=>{console.warn("Iframe failed to load content"),u(!1)},g=s?"allow-scripts allow-popups allow-forms":void 0,w=!!(r||s);return o&&!w?e.jsx("div",{className:"grow",children:e.jsx(He,{currentStage:n==null?void 0:n.stage,message:n==null?void 0:n.message,documentText:a,startedAt:i,onCancel:l})}):t&&!w?e.jsx("div",{className:"grow",children:e.jsx(qe,{renderingLibrary:"LibreOffice"})}):w?e.jsxs("div",{className:"h-full w-full relative bg-white",children:[!c&&e.jsx("div",{className:"absolute inset-0 bg-muted/80 flex items-center justify-center z-10",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-foreground mx-auto mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),(o||t)&&e.jsx("div",{className:"absolute inset-0 bg-background/60 backdrop-blur-[2px] flex items-center justify-center z-20 transition-opacity duration-200",children:e.jsx(Je,{mode:o?"generating":"rendering",message:o?n==null?void 0:n.message:void 0,startedAt:o?i:void 0,onCancel:o?l:void 0})}),e.jsx("iframe",{ref:d,className:"w-full h-full border-0",style:{backgroundColor:"white",opacity:c?1:0,transition:"opacity 0.2s ease-in-out"},src:r,srcDoc:s,onLoad:f,onError:m,sandbox:g,title:"Document preview","aria-label":`Preview of rendered ${ce.toLowerCase()}`},s?"srcdoc":"src")]}):null});he.displayName="PreviewFrame";const Ve=A.memo(he);function Ke({warnings:t,className:r}){const[s,o]=A.useState(!1);return!t||t.length===0?null:e.jsxs("div",{className:r,children:[e.jsxs("button",{type:"button",onClick:()=>o(!s),className:"flex w-full items-center gap-2 rounded-sm border border-transparent bg-warning/10 px-3 py-1.5 text-left transition-colors hover:bg-warning/20",children:[e.jsx(Ie,{className:`h-3.5 w-3.5 text-warning transition-transform flex-shrink-0 ${s?"rotate-90":""}`}),e.jsx(J,{className:"h-3.5 w-3.5 text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-medium text-warning",children:[t.length," warning",t.length!==1?"s":""]})]}),s&&e.jsx("div",{className:"mt-1.5 space-y-1.5",children:t.map((n,a)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-card px-3 py-2",children:[n.severity==="info"?e.jsx(de,{className:"h-3.5 w-3.5 mt-0.5 text-data-blue flex-shrink-0"}):e.jsx(J,{className:"h-3.5 w-3.5 mt-0.5 text-warning flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("code",{className:"text-[11px] font-medium text-warning bg-warning/15 px-1 py-0.5 rounded-sm",children:n.component}),n.severity==="info"&&e.jsx("span",{className:"text-[10px] uppercase tracking-wide text-data-blue font-medium",children:"info"})]}),e.jsx("p",{className:"mt-0.5 text-xs text-muted-foreground leading-relaxed",children:n.message}),n.context&&Object.keys(n.context).length>0&&e.jsxs("details",{className:"mt-1.5",children:[e.jsx("summary",{className:"text-[11px] text-muted-foreground/70 cursor-pointer hover:text-foreground",children:"Context"}),e.jsx("pre",{className:"mt-1 text-[11px] bg-header-bg p-1.5 rounded-sm overflow-x-auto text-muted-foreground",children:JSON.stringify(n.context,null,2)})]})]})]},a))})]})}const ne={pptx:["default","dark","minimal"],docx:["minimal","corporate","modern"]};function Xe({className:t}){var i;const r=E(l=>l.activeTab),s=E(l=>l.documentTypes),o=E(l=>l.documents),n=ue(l=>l.customThemes),a=x.useMemo(()=>{var c,u,f;if(!r||s[r]==="application/json+theme")return null;const l=o.find(m=>m.name===r);if(!(l!=null&&l.text))return null;let d;try{d=(u=(c=JSON.parse(l.text))==null?void 0:c.props)==null?void 0:u.theme}catch{return null}if(typeof d!="string"||!d||(f=ne[b])!=null&&f.includes(d))return null;for(const m of Object.values(n))if(m.valid&&m.name===d)return null;return d},[r,s,o,n]);return a?e.jsxs("div",{className:`flex items-start gap-2 rounded-sm border border-transparent bg-warning/10 px-3 py-2 ${t??""}`,children:[e.jsx(J,{className:"h-3.5 w-3.5 mt-0.5 text-warning flex-shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 text-xs leading-relaxed",children:[e.jsxs("span",{className:"font-medium text-warning",children:["Theme"," ",e.jsx("code",{className:"bg-warning/20 px-1 py-0.5 rounded-sm text-warning",children:a})," ","is not available."]})," ",e.jsxs("span",{className:"text-warning/80",children:["Add it as a custom theme or use a built-in theme (",(i=ne[b])==null?void 0:i.join(", "),"). The renderer will fall back to a default."]})]})]}):null}const Ye=8*1024*1024;function re(t){return Array.isArray(t)?t:[]}function Qe(t,r){var a;let s=[];if(typeof t=="string"&&t.length>0)try{const i=JSON.parse(t);s=re((a=i==null?void 0:i.props)==null?void 0:a.fontRegistry)}catch{return[]}const o=[];for(const i of Object.values(r??{}))o.push(...re(i==null?void 0:i.fontRegistry));const n=new Map;for(const i of[...o,...s])i&&typeof i.family=="string"&&n.set(i.family.toLowerCase(),i);return[...n.values()]}function Ze(t,r,s){const o=[{family:t,cssWeight:r,cssStyle:s?"italic":"normal"}],n=ke[r];return r!==400&&r!==700&&n&&o.push({family:`${t} ${n}${s?" Italic":""}`,cssWeight:400,cssStyle:"normal"}),o}const et=/^(?:data:[a-z0-9.+-]+\/[a-z0-9.+-]+;base64,)?[A-Za-z0-9+/=\s]+$/i;function tt(t){return et.test(t)?t.startsWith("data:")?t:`data:font/ttf;base64,${t}`:null}function xe(t){const r=[];for(const s of t.sources??[]){if(s.kind==="safe"||s.kind==="file"||s.kind==="google")continue;const o="italic"in s?!!s.italic:!1,n="weight"in s&&s.weight?s.weight:400;if(s.kind==="data"){const a=tt(s.data);if(!a)continue;r.push({family:t.family,weight:n,italic:o,url:a});continue}_e(s.url)&&r.push({family:t.family,weight:n,italic:o,url:s.url,variable:s.kind==="variable"})}return r}function st(t,r,s){const o=new Map;for(const i of r)for(const l of xe(i)){const d=l.family.toLowerCase();let c=o.get(d);c||o.set(d,c=new Set),c.add(l.weight)}const n=[],a=new Set;for(const i of t){if(Ee(i))continue;const l=i.toLowerCase();if(a.has(l))continue;const d=Re.find(m=>m.family.toLowerCase()===l);if(!d)continue;a.add(l);const c=o.get(l),u=new Set([400,700,...s]),f=d.weights.filter(m=>u.has(m)&&!(c!=null&&c.has(m)));f.length!==0&&n.push({family:d.family,weights:f,italics:d.hasItalic})}return n}function pe(t,r,s){const o=[...new Set(r)].sort((a,i)=>a-i),n=s?`ital,wght@${[...o.map(a=>`0,${a}`),...o.map(a=>`1,${a}`)].join(";")}`:`wght@${o.join(";")}`;return`https://fonts.googleapis.com/css2?family=${encodeURIComponent(t)}:${n}&display=swap`}const G=new Map,nt=3e3;async function rt(t,r,s,o=fetch,n=nt){const a=pe(t,r,s),i=G.get(a);if(i)return i;const l=(async()=>{const d=new AbortController;let c;const u=new Promise((f,m)=>{c=setTimeout(()=>{d.abort(),m(new Error(`Google Fonts CSS timed out after ${n}ms`))},n)});try{const f=await Promise.race([o(a,{signal:d.signal}),u]);if(!f.ok)throw new Error(`Google Fonts CSS ${f.status}`);const m=await Promise.race([f.text(),u]);return at(m,t)}finally{c&&clearTimeout(c)}})();return G.set(a,l),l.catch(()=>G.delete(a)),l}function at(t,r){var o,n,a,i,l,d;const s=[];for(const c of t.split("@font-face")){const u=(n=(o=/src:\s*([^;]+);/.exec(c))==null?void 0:o[1])==null?void 0:n.trim();if(!u)continue;const f=((a=/font-style:\s*(\w+)/.exec(c))==null?void 0:a[1])??"normal",m=Number(((i=/font-weight:\s*(\d+)/.exec(c))==null?void 0:i[1])??"400"),g=(d=(l=/unicode-range:\s*([^;]+);/.exec(c))==null?void 0:l[1])==null?void 0:d.trim(),w=g&&/^[Uu]\+[0-9A-Fa-f?,+\-Uu\s]*$/.test(g)?g:void 0;s.push({family:r,weight:Number.isFinite(m)?m:400,italic:f==="italic",src:u,...w?{unicodeRange:w}:{}})}return s}function ae(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/</g,"\\3c ")}function it(t,r=Ye){const s=new Set,o=[];let n=0,a=0;for(const i of t){const l=i.url?`url("${ae(i.url)}")`:i.src&&!i.src.includes("<")?i.src:void 0;if(l)for(const d of Ze(i.family,i.weight,i.italic)){const c=`${d.family}|${d.cssWeight}|${d.cssStyle}|${l}`;if(s.has(c))continue;s.add(c);const u=d.family!==i.family,f=i.variable&&u?`font-variation-settings:"wght" ${i.weight};`:"",m=`@font-face{font-family:"${ae(d.family)}";src:${l};font-weight:${d.cssWeight};font-style:${d.cssStyle};font-display:swap;`+f+(i.unicodeRange?`unicode-range:${i.unicodeRange};`:"")+"}";if(n+m.length>r){a++;continue}n+=m.length,o.push(m)}}return a>0&&console.warn(`Preview fonts: dropped ${a} @font-face rule(s) over the ${r}-byte budget.`),o.join(`
|
|
3
3
|
`)}function ie(t){const r=new Set,s=o=>{if(!(!o||typeof o!="object")){if(Array.isArray(o)){for(const n of o)s(n);return}for(const[n,a]of Object.entries(o))n==="fontWeight"&&typeof a=="number"?r.add(a):s(a)}};return s(t),r}async function ot(t,r,s){const o=Qe(t,r);let n;if(typeof t=="string"&&t.length>0)try{n=JSON.parse(t)}catch{n=void 0}const a=new Set,i=new Set;if(n!==void 0){for(const c of te(n))a.add(c);for(const c of ie(n))i.add(c)}for(const c of Object.values(r??{})){for(const u of te(c))a.add(u);for(const u of ie(c))i.add(u)}const l=[];for(const c of o)l.push(...xe(c));const d=[];for(const c of st(a,o,i))try{l.push(...await rt(c.family,c.weights,c.italics,(s==null?void 0:s.fetchImpl)??fetch,s==null?void 0:s.googleTimeoutMs))}catch{d.push(pe(c.family,c.weights,c.italics))}return{css:it(l,s==null?void 0:s.maxBytes),googleHrefs:d}}async function ct(t,r,s){const o=await Ce(()=>import("./docx-preview-DQa8jhzH.js"),__vite__mapDeps([0,1])),n=document.createElement("body"),a=document.createElement("head"),i=o.renderAsync(t,n,a,{inWrapper:!0}),l=new Promise((u,f)=>{setTimeout(()=>{f(new Error("DocxJS renderAsync timed out after 10 seconds"))},1e4)});await Promise.race([i,l]);try{const{css:u,googleHrefs:f}=await ot(r,s);for(const m of f){const g=document.createElement("link");g.rel="stylesheet",g.href=m,a.appendChild(g)}if(u){const m=document.createElement("style");m.textContent=u,a.appendChild(m)}}catch(u){console.warn("Preview font injection failed; using host fonts",u)}const d=document.createElement("link");d.rel="stylesheet",d.href=`${Le.basePath}/css/preview/docxjs.css`,a.appendChild(d);const c=document.createElement("html");return c.appendChild(a),c.appendChild(n),{iframeSrcDoc:c.outerHTML}}async function lt(t,r,s,o){const n=typeof s=="string"&&s.length>0;let a;if(n){let d;try{d=JSON.parse(s)}catch(u){throw new Error(`Invalid JSON document: ${u.message}`)}const c={jsonDefinition:d,customThemes:o??{},options:{sourceName:t}};a=await fetch(H.preview.libreofficeFromJson,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)})}else{const d=new FormData,c=b==="pptx"?".pptx":".docx";d.append("file",r,`${t}${c}`),a=await fetch(H.preview.libreoffice,{method:"POST",body:d})}if(!a.ok){let d=`LibreOffice preview failed (${a.status})`;try{const c=await a.json();c&&typeof c=="object"&&typeof c.error=="string"&&(d=c.error)}catch{}throw new Error(d)}const i=await a.blob();if(!i.size)throw new Error("LibreOffice preview returned an empty PDF");const l=URL.createObjectURL(i);return{iframeSrc:l,cleanup:()=>URL.revokeObjectURL(l)}}async function dt(t,r,s=b==="docx"?"docxjs":"LibreOffice",o,n,a){try{if(!r||r.size===0)throw new Error("Invalid or empty document blob");let i;return b==="docx"&&s==="docxjs"?i=await ct(r,n,a):i=await lt(t,r,n,a),{status:"success",name:t,payload:i}}catch(i){const l=i instanceof Error?i.message:String(i);return{status:"error",name:t,payload:new Error(l)}}}const I=x.forwardRef(({className:t,value:r,...s},o)=>e.jsx(me,{ref:o,className:S("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...s,children:e.jsx(Pe,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(r||0)}%)`}})}));I.displayName=me.displayName;const oe={"dynamic-context":"depends on render-time context","bookmark-id":"carries a bookmark id","revision-ids":"carries revision ids"};function q(t){if(t===0)return"0 B";const r=1024,s=["B","KB","MB","GB"],o=Math.floor(Math.log(t)/Math.log(r));return parseFloat((t/Math.pow(r,o)).toFixed(2))+" "+s[o]}function ut(){const[t,r]=x.useState(null),[s,o]=x.useState(!0),[n,a]=x.useState(null);if(x.useEffect(()=>{const d=new AbortController,c=async()=>{try{const m=await fetch(H.cacheStats,{signal:d.signal});if(!m.ok)throw new Error("Failed to fetch cache stats");const g=await m.json();d.signal.aborted||(r(g.data),a(null))}catch(m){d.signal.aborted||(m instanceof Error&&m.name!=="AbortError"?a(m.message):(!(m instanceof Error)||m.name!=="AbortError")&&a("Failed to load cache stats"))}finally{d.signal.aborted||o(!1)}};c();const u=setInterval(c,5e3),f=()=>c();return window.addEventListener("cache:cleared",f),()=>{d.abort(),clearInterval(u),window.removeEventListener("cache:cleared",f)}},[]),s)return e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})});if(n)return e.jsxs("div",{className:"text-destructive p-4",children:["Error loading cache metrics: ",n]});if(!t)return null;const{document:i}=t,l=i.hitRate*100;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Hit Rate"})," ",e.jsxs("span",{className:"font-semibold text-base",children:[l.toFixed(1),"%"]}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",i.hits," hits / ",i.misses," misses)"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Size"})," ",e.jsx("span",{className:"font-semibold",children:q(i.size)}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",i.itemCount," items)"]})]}),e.jsx(Fe,{variant:i.enabled?"default":"secondary",children:i.enabled?"Enabled":"Disabled"})]}),e.jsx(I,{value:l,className:"h-2","aria-label":"Cache hit rate"}),b==="docx"&&t.components&&e.jsx(mt,{data:t.components}),t.rasterizer&&e.jsx(ft,{data:t.rasterizer})]})}function mt({data:t}){const r=t.bypassedComponents??[];return t.componentStats.length===0&&r.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Module Breakdown"}),e.jsxs("div",{className:"space-y-1",children:[t.componentStats.map(s=>{const o=(s.hitRate||0)*100,n=s.totalRequests||s.hits+s.misses,a=s.memoryUsage||s.entries*s.avgSize||0;return e.jsxs("div",{className:"px-3 py-1.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"font-medium",children:s.type}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[o.toFixed(0),"% hit"]}),e.jsxs("span",{children:[n," req"]}),e.jsx("span",{children:q(a)})]})]}),e.jsx(I,{value:o,className:"h-1.5"})]},s.type)}),r.map(s=>e.jsx("div",{className:"px-3 py-1.5 text-sm",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:s.type}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["uncached by design",oe[s.reason]?` — ${oe[s.reason]}`:""]}),e.jsxs("span",{children:[s.renders," renders"]})]})]})},`bypass-${s.type}`))]})]})}function ft({data:t}){const r=t.diskHits+t.diskMisses;if(r+t.dedupedRequests+t.rendered+t.entries===0)return null;const o=t.hitRate*100,n=t.prepass?t.prepass.collected-t.prepass.unique:t.dedupedRequests;return e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Visual Rasterizer"}),e.jsxs("div",{className:"px-3 py-1.5 text-sm space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Disk cache"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("span",{children:r>0?`${o.toFixed(0)}% hit`:"no lookups"}),e.jsxs("span",{children:["(",t.diskHits," hits / ",t.diskMisses," misses)"]}),e.jsxs("span",{children:[t.entries," PNGs, ",q(t.bytes)]})]})]}),e.jsx(I,{value:o,className:"h-1.5","aria-label":"Rasterizer disk cache hit rate"}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsxs("span",{children:[t.rendered," rendered",t.failed>0?`, ${t.failed} failed`:""]}),e.jsxs("span",{children:[n," duplicate visual",n===1?"":"s"," deduped",t.prepass?` (${t.prepass.collected} collected → ${t.prepass.unique} unique)`:""]})]})]})]})}const ht=x.memo(function({editTimestamp:r,debounceMs:s}){const[o,n]=x.useState(()=>Math.max(0,r+s-Date.now()));if(x.useEffect(()=>{let l;const d=()=>{const c=Math.max(0,r+s-Date.now());n(c),c<=0&&l!=null&&clearInterval(l)};return d(),l=setInterval(d,100),()=>{l!=null&&clearInterval(l)}},[r,s]),o<=0)return null;const a=(o/1e3).toFixed(1),i=Math.min(100,o/s*100);return e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-warning tabular-nums",children:[e.jsx("span",{className:"h-1 rounded-full bg-warning/60 transition-[width] duration-100",style:{width:`${Math.round(i*.4)}px`}}),a,"s"]})});function Et(){var D,ee;const{autoReload:t,renderingLibrary:r,saveDocumentDebounceWait:s,setSettings:o}=se(h=>h),{name:n,text:a,blob:i,isGenerating:l,generationProgress:d,generationStartedAt:c,cancelGeneration:u,globalError:f,cacheStatus:m,cacheHitRate:g,warnings:w,isRendering:j,isPreviewStale:R,editSequence:k,lastBuiltSequence:ge,editTimestamp:V,hasValidationErrors:we,setOutput:N}=Be(h=>h),y=E(h=>h.activeTab),K=E(h=>h.documentTypes),X=E(h=>{var p;return h.activeTab&&h.documentTypes[h.activeTab]!=="application/json+theme"?(p=h.documents.find(U=>U.name===h.activeTab))==null?void 0:p.text:void 0}),Y=ue(h=>h.customThemes),B=x.useMemo(()=>{const h={};for(const p of Object.values(Y))p.valid&&p.name&&p.parsed&&(h[p.name]=p.parsed);return h},[Y]),[C,ve]=x.useState(void 0),[je,ye]=x.useState(void 0),[be,P]=x.useState(!1),Q=A.useRef(null),$=x.useRef(null),z=x.useRef(!1),M=x.useCallback(()=>{$.current&&($.current(),$.current=null)},[]),L=x.useCallback(async(h,p,U,Se)=>{N({isRendering:!0,isPreviewStale:!1,globalError:void 0});try{const{status:F,payload:v}=await dt(h,p,r,void 0,U,Se);if(F!=="success")throw v instanceof Error?v:new Error(String(v));M(),ve(v.iframeSrc||void 0),ye(v.iframeSrcDoc||void 0),$.current=v.cleanup||null}catch(F){const v=F instanceof Error?F.message:String(F);let W=v;v.includes("Failed to fetch")?W="Network error: Unable to load required resources. Check if the server is running properly.":v.includes("timeout")&&(W="Render timeout: The rendering process took too long."),N({globalError:W})}finally{N({isRendering:!1})}},[N,M,r]),Ne=x.useRef({name:n,blob:i,text:a,doRender:L});x.useEffect(()=>{Ne.current={name:n,blob:i,text:a,doRender:L}});const _=x.useCallback(async()=>{z.current=!0,window.dispatchEvent(new CustomEvent("preview:flushAndBuild"))},[]);x.useEffect(()=>{i&&n&&t&&r==="docxjs"?L(n,i,a,B):i&&n&&z.current?(z.current=!1,L(n,i,a,B)):i&&n&&N({isPreviewStale:!0})},[i,n,a,B,t,r,L,N]),x.useEffect(()=>()=>{M()},[M]),x.useEffect(()=>{const h=()=>_(),p=()=>P(!0);return window.addEventListener("preview:manualRender",h),window.addEventListener("preview:showCacheMetrics",p),()=>{window.removeEventListener("preview:manualRender",h),window.removeEventListener("preview:showCacheMetrics",p)}},[_]);const Z=((ee=(D=se)==null?void 0:D.getState)==null?void 0:ee.call(D).useGlobalPreviewHeader)===!1;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-full flex-col",children:[Z&&e.jsx(Oe,{iframeRef:Q,displayReloadButton:!!C&&!((C==null?void 0:C.startsWith("blob:"))??!1),name:(n==null?void 0:n.trim())||"Preview",blob:i,autoReload:t,onToggleAutoReload:()=>o({autoReload:!t}),onManualRender:_,isGenerating:l,isRendering:j,onShowCacheMetrics:()=>P(!0),documentText:a,editorDocumentText:X,warnings:w,renderingLibrary:r,setRenderingLibrary:h=>o({renderingLibrary:h})}),!Z&&e.jsx($e,{}),b==="docx"&&r==="docxjs"&&e.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 border-b bg-data-blue/10 text-xs text-data-blue",children:[e.jsx(de,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:"The docxjs renderer is not 100% representative of the actual .docx. Use LibreOffice for higher fidelity."})]}),(()=>{const h=(k??0)>(ge??0),p=(R||h)&&!l&&!j;return(m&&m!=="UNKNOWN"||p)&&e.jsxs("div",{className:`px-3 py-1.5 flex items-center justify-between border-b overflow-hidden ${p?"bg-warning/10":"bg-header-bg"}`,children:[e.jsx("div",{className:"flex items-center gap-2 min-w-0 truncate",children:m==="HIT"&&!p?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-success flex-shrink-0"}),e.jsx("span",{className:"text-xs text-muted-foreground truncate",children:"Cached"})]}):m==="MISS"&&!p?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-accent2 flex-shrink-0"}),e.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["Fresh ",ce.toLowerCase()]})]}):p?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-warning flex-shrink-0"}),e.jsx("span",{className:"text-xs text-warning truncate",children:"Outdated — click Run"}),V&&h&&!l&&!we&&t&&r==="docxjs"&&e.jsx(ht,{editTimestamp:V,debounceMs:s+200})]}):null}),!p&&g&&g!=="0.0%"&&e.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0 ml-2",children:[g," hit rate"]})]})})(),e.jsx(Ke,{warnings:w,className:"mx-3 my-2"}),e.jsx(Xe,{className:"mx-3 my-2"}),f&&!l?e.jsx("div",{className:"flex-1 flex items-center justify-center p-6",children:e.jsxs("div",{className:"max-w-md rounded-sm border-l-4 border-l-destructive bg-destructive/10 px-4 py-3 text-sm text-destructive",children:[e.jsx("p",{className:"font-medium mb-1",children:"Generation failed"}),e.jsx("p",{className:"text-xs text-destructive/80 break-words",children:f})]})}):e.jsx(Ve,{ref:Q,isLoading:!!j,iframeSrc:C,iframeSrcDoc:je,isGenerating:(()=>{const h=t&&r==="docxjs",p=y&&n&&y!==n&&K[y]!=="application/json+theme";return!!l||!!(h&&p)})(),generationProgress:(()=>{const h=t&&r==="docxjs",p=y&&n&&y!==n&&K[y]!=="application/json+theme";return h&&p&&!l?{stage:"parsing",message:`Building preview for ${y}...`}:d})(),generationDocumentText:X??a,generationStartedAt:c,onCancelGeneration:u})]}),e.jsx(Me,{open:be,onOpenChange:P,children:e.jsxs(De,{className:"max-w-2xl",children:[e.jsx(Te,{children:e.jsx(Ae,{children:"Cache Performance"})}),e.jsx(ut,{})]})})]})}export{Et as Preview};
|
|
4
|
-
//# sourceMappingURL=preview-
|
|
4
|
+
//# sourceMappingURL=preview-Qj-FLOiI.js.map
|