@json-to-office/jto 1.7.0 → 1.11.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.
Files changed (30) hide show
  1. package/dist/cli.js +14 -3
  2. package/dist/cli.js.map +1 -1
  3. package/dist/client/assets/{HomePage-fDrbL-5G.js → HomePage-r7ryeW_v.js} +4 -4
  4. package/dist/client/assets/{HomePage-fDrbL-5G.js.map → HomePage-r7ryeW_v.js.map} +1 -1
  5. package/dist/client/assets/{JsonEditorPage-CRY9589Y.js → JsonEditorPage-BxUyYH8Z.js} +3 -3
  6. package/dist/client/assets/{JsonEditorPage-CRY9589Y.js.map → JsonEditorPage-BxUyYH8Z.js.map} +1 -1
  7. package/dist/client/assets/{MonacoPluginProvider-n1_V7jsc.js → MonacoPluginProvider-CGvtVJKz.js} +3 -3
  8. package/dist/client/assets/{MonacoPluginProvider-n1_V7jsc.js.map → MonacoPluginProvider-CGvtVJKz.js.map} +1 -1
  9. package/dist/client/assets/{editor-Y9dek093.js → editor-gT4UjmPk.js} +2 -2
  10. package/dist/client/assets/{editor-Y9dek093.js.map → editor-gT4UjmPk.js.map} +1 -1
  11. package/dist/client/assets/{editor-monaco-json-oBxvTIvi.js → editor-monaco-json-BYUK4OUI.js} +2 -2
  12. package/dist/client/assets/{editor-monaco-json-oBxvTIvi.js.map → editor-monaco-json-BYUK4OUI.js.map} +1 -1
  13. package/dist/client/assets/{editor-refs-store-BMwl0ejj.js → editor-refs-store-ChL2fzuX.js} +2 -2
  14. package/dist/client/assets/{editor-refs-store-BMwl0ejj.js.map → editor-refs-store-ChL2fzuX.js.map} +1 -1
  15. package/dist/client/assets/{index-B4R-AAtI.js → index-CgCY8SiY.js} +4 -4
  16. package/dist/client/assets/index-CgCY8SiY.js.map +1 -0
  17. package/dist/client/assets/{preview-zCYkbgdR.js → preview-ZqhmQZJG.js} +2 -2
  18. package/dist/client/assets/{preview-zCYkbgdR.js.map → preview-ZqhmQZJG.js.map} +1 -1
  19. package/dist/client/assets/{useQualityAnalysis-BFG1bJDp.js → useQualityAnalysis-eKT8VcIt.js} +2 -2
  20. package/dist/client/assets/{useQualityAnalysis-BFG1bJDp.js.map → useQualityAnalysis-eKT8VcIt.js.map} +1 -1
  21. package/dist/client/index.html +1 -1
  22. package/dist/client/templates/minimalist-pitch-deck.pptx.json +431 -7
  23. package/dist/client/templates/modern-annual-report-1.docx.json +4128 -168
  24. package/dist/client/templates/modern-annual-report-2.docx.json +5122 -4648
  25. package/dist/client/templates/modern-annual-report-3.docx.json +4540 -2755
  26. package/dist/client/templates/standard-annual-report.docx.json +6609 -234
  27. package/dist/client/templates/tech-report.docx.json +6404 -213
  28. package/dist/client/templates/vermilion-annual-report.docx.json +726 -106
  29. package/package.json +5 -5
  30. package/dist/client/assets/index-B4R-AAtI.js.map +0 -1
@@ -1,2 +1,2 @@
1
- import{r as x,j as e,c as N}from"./react-vendor-BmQ2Ko_D.js";import{S as X,c as v,h as nt,g as At,F as O,p as Lt,Q as It,A as Ce,u as Ot}from"./index-B4R-AAtI.js";import{S as Y,L as he,b as pe,c as ge,d as ve,e as je,f as ie,p as Mt,g as We,B as Pt,P as Ft,h as Dt,D as zt,i as Bt,j as _t,k as Ht}from"./HomePage-fDrbL-5G.js";import{B as rt,u as at}from"./editor-refs-store-BMwl0ejj.js";import{e as it,Q as G,x as U,a4 as Qt,a5 as ot,a6 as Le,W as Gt,a7 as lt,a8 as Ut,a9 as Vt,aa as Jt}from"./ui-vendor-Bq4-oNFL.js";import Wt from"./monaco-editor-DJsdM0WK.js";import{E as Ye,p as Yt,c as $e,d as Xt,g as Kt,e as Zt,u as qt,a as es}from"./useQualityAnalysis-BFG1bJDp.js";import{d as F,u as L,a as ct,b as ts,j as ss,e as ns}from"./MonacoPluginProvider-n1_V7jsc.js";import{ad as dt,ae as rs}from"./radix-ui-DFNP5I4e.js";import"./query-vendor--rhYD8mC.js";import"./state-vendor-Cq67_JbF.js";function ut(t){const[s]=x.useState(()=>Date.now()),n=t??s,[r,i]=x.useState(()=>Date.now());return x.useEffect(()=>{const o=setInterval(()=>i(Date.now()),100);return()=>clearInterval(o)},[]),Math.max(0,(r-n)/1e3)}function as(t){var s,n;if(!t)return null;try{const r=JSON.parse(t);if(!r||typeof r!="object")return null;const i=new Map,o=[r];for(;o.length>0;){const m=o.pop();if(!m||typeof m!="object")continue;const{name:f,children:d}=m;typeof f=="string"&&i.set(f,(i.get(f)??0)+1),Array.isArray(d)&&o.push(...d)}const a=[["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(([m,f,d])=>{const c=i.get(m)??0;return{label:c===1?f:d,count:c}}).filter(m=>m.count>0).slice(0,5),u=(n=(s=r.props)==null?void 0:s.metadata)==null?void 0:n.title;return{title:typeof u=="string"?u:void 0,counts:a,visualCount:(i.get("visual")??0)+(i.get("chart")??0),imageCount:i.get("image")??0}}catch{return null}}function is(t){const s=[];return t&&t.visualCount>0&&s.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&&s.push("Large embedded images dominate build time — downscaling them speeds up iteration."),s.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."),s}const os=()=>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 ls({className:t,currentStage:s="parsing",message:n,documentText:r,startedAt:i,onCancel:o}){const l=["parsing","building","rendering","finalizing"],a={parsing:"Validating JSON",building:"Building structure",rendering:"Rendering content",finalizing:"Finalizing document"},u=l.indexOf(s),m=ut(i),f=x.useMemo(()=>as(r),[r]),d=x.useMemo(()=>is(f),[f]),c=m>3,p=Math.floor(Math.max(0,m-3)/5)%d.length;return e.jsxs("div",{className:v("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(X,{size:"md"}),e.jsxs("div",{className:"space-y-0.5 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:f!=null&&f.title?`Generating “${f.title}”`:"Generating document"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",role:"status","aria-live":"polite",children:n||`${a[s]}...`})]})]}),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:[m.toFixed(1),"s"]})]}),f&&f.counts.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5","aria-label":"Document contents",children:f.counts.map(({label:b,count:R})=>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:R}),b]},b))}),e.jsx("div",{className:"space-y-3",children:l.map((b,R)=>{const z=R===u,E=R<u;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:v(z?"text-primary font-medium":E?"text-muted-foreground":"text-muted-foreground/60"),children:a[b]}),E?e.jsx(os,{}):z?e.jsx(X,{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:E?e.jsx("div",{className:"h-full w-full rounded-full bg-success"}):z?e.jsx("div",{className:"h-full w-2/5 rounded-full bg-primary animate-progress-indeterminate"}):null})]},b)})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 min-h-8",children:[e.jsx("p",{className:v("text-xs text-muted-foreground/80 italic transition-opacity duration-500",c?"opacity-100":"opacity-0"),children:d[p]}),o&&e.jsx(rt,{variant:"outline",size:"sm",onClick:o,className:"shrink-0",children:"Cancel"})]})]})}function cs({mode:t,message:s,startedAt:n,onCancel:r,className:i}){const o=ut(n);return e.jsxs("div",{className:v("flex flex-col items-center gap-2 rounded-md border bg-background/95 px-6 py-4 shadow-sm",i),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{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:[o.toFixed(1),"s"]})]}),s&&e.jsx("p",{className:"max-w-xs text-center text-xs text-muted-foreground truncate",children:s}),t==="generating"&&r&&e.jsx(rt,{variant:"outline",size:"sm",onClick:r,children:"Cancel"})]})}function ds({renderingLibrary:t,className:s}){const n=o=>{switch(o){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:r,description:i}=n(t);return e.jsxs("div",{className:v("flex flex-col items-center justify-center h-full p-8 space-y-4",s),children:[e.jsx(X,{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 ",r," renderer"]}),e.jsx("p",{className:"text-xs text-muted-foreground/80",children:i})]}),e.jsxs("div",{className:"w-full max-w-md space-y-3",children:[e.jsx(Y,{className:"h-16 w-full"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{className:"h-4 w-full"}),e.jsx(Y,{className:"h-4 w-3/4"}),e.jsx(Y,{className:"h-4 w-1/2"})]}),e.jsx(Y,{className:"h-12 w-full"})]})]})}const mt=N.forwardRef(({isLoading:t,iframeSrc:s,iframeSrcDoc:n,isGenerating:r,generationProgress:i,generationDocumentText:o,generationStartedAt:l,onCancelGeneration:a},u)=>{const[m,f]=x.useState(!1);x.useEffect(()=>{f(!1)},[s,n]);const d=()=>{f(!0)},c=()=>{console.warn("Iframe failed to load content"),f(!1)},p=n?"allow-scripts allow-popups allow-forms":void 0,b=!!(s||n);return r&&!b?e.jsx("div",{className:"grow",children:e.jsx(ls,{currentStage:i==null?void 0:i.stage,message:i==null?void 0:i.message,documentText:o,startedAt:l,onCancel:a})}):t&&!b?e.jsx("div",{className:"grow",children:e.jsx(ds,{renderingLibrary:"LibreOffice"})}):b?e.jsxs("div",{className:"h-full w-full relative bg-white",children:[!m&&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..."})]})}),(r||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(cs,{mode:r?"generating":"rendering",message:r?i==null?void 0:i.message:void 0,startedAt:r?l:void 0,onCancel:r?a:void 0})}),e.jsx("iframe",{ref:u,className:"w-full h-full border-0",style:{backgroundColor:"white",opacity:m?1:0,transition:"opacity 0.2s ease-in-out"},src:s,srcDoc:n,onLoad:d,onError:c,sandbox:p,title:"Document preview","aria-label":`Preview of rendered ${nt.toLowerCase()}`},n?"srcdoc":"src")]}):null});mt.displayName="PreviewFrame";const us=N.memo(mt);function ms({warnings:t,className:s}){const[n,r]=N.useState(!1),i=N.useMemo(()=>(t??[]).filter(o=>o.component!=="quality"),[t]);return i.length===0?null:e.jsxs("div",{className:s,children:[e.jsxs("button",{type:"button",onClick:()=>r(!n),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(it,{className:`h-3.5 w-3.5 text-warning transition-transform flex-shrink-0 ${n?"rotate-90":""}`}),e.jsx(G,{className:"h-3.5 w-3.5 text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-medium text-warning",children:[i.length," warning",i.length!==1?"s":""]})]}),n&&e.jsx("div",{className:"mt-1.5 space-y-1.5",children:i.map((o,l)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-card px-3 py-2",children:[o.severity==="info"?e.jsx(U,{className:"h-3.5 w-3.5 mt-0.5 text-data-blue flex-shrink-0"}):e.jsx(G,{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:o.component}),o.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:o.message}),o.context&&Object.keys(o.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(o.context,null,2)})]})]})]},l))})]})}function fs({className:t}){const{resolvedTheme:s}=At(),n=F(d=>d.qualityPolicies),r=F(d=>d.setSettings),i=n==null?void 0:n[O],[o,l]=x.useState(i??Ye),a=x.useMemo(()=>Yt(o),[o]),u=x.useMemo(()=>Lt().map(d=>d.id),[]),m=x.useCallback(d=>{l(d),r({qualityPolicies:{...n,[O]:d}})},[n,r]),f=x.useCallback(()=>m(Ye),[m]);return e.jsxs("div",{className:v("flex min-w-0 flex-col gap-2",t),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[11px] leading-snug text-muted-foreground",children:"Rule severity, parameters and suppressions. The gate and profile stay with their controls above."}),e.jsxs("button",{type:"button",onClick:f,className:v("flex flex-shrink-0 items-center gap-1 rounded-sm px-1.5 py-0.5","text-[11px] font-medium text-muted-foreground transition-colors","hover:bg-accent hover:text-foreground","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:[e.jsx(Qt,{className:"h-3 w-3","aria-hidden":"true"}),"Reset"]})]}),e.jsx("div",{className:"overflow-hidden rounded-sm border",children:e.jsx(Wt,{height:"180px",language:"json",path:It,theme:s==="dark"?"vs-dark":"vs",defaultValue:o,onChange:d=>m(d??""),options:{minimap:{enabled:!1},lineNumbers:"off",folding:!1,scrollBeyondLastLine:!1,fontSize:11,lineHeight:17,tabSize:2,renderLineHighlight:"none",overviewRulerLanes:0,scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8},padding:{top:8,bottom:8},automaticLayout:!0}})}),a.ok?e.jsx("p",{className:"text-[11px] leading-snug text-muted-foreground",children:a.policy?"Applied to every analysis and build.":"Empty — the profile decides on its own."}):e.jsxs("p",{className:"flex items-start gap-1.5 text-[11px] leading-snug text-destructive",children:[e.jsx(G,{className:"mt-0.5 h-3 w-3 flex-shrink-0","aria-hidden":"true"}),e.jsxs("span",{children:[a.error," Until this parses, the run ignores it."]})]}),e.jsxs("details",{className:"text-[11px] text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer hover:text-foreground",children:"Rules in this format"}),e.jsx("ul",{className:"mt-1 space-y-0.5 pl-3",children:u.map(d=>e.jsx("li",{className:"font-mono text-[10px]",children:d},d))})]})]})}const Re="__default__",xs={docx:[{value:"executive-report",label:"Executive report",description:"Short decision document with strict outline continuity"},{value:"technical-report",label:"Technical report",description:"Portable professional report defaults"},{value:"legal-appendix",label:"Legal appendix",description:"Dense appendix: preserve integrity without editorial taste"}],pptx:[{value:"executive-presentation",label:"Executive presentation",description:"Decision deck optimized for scan speed and projection"},{value:"technical-presentation",label:"Technical presentation",description:"Portable professional presentation defaults"}]},hs={docx:"technical-report",pptx:"technical-presentation"},be=[{value:"none",label:"Never blocks",description:"Findings are reported and the run always finishes"},{value:"error",label:"Blocks on errors",description:"Generation fails when a finding is an error"},{value:"warning",label:"Blocks on warnings",description:"Generation fails on any warning or error"},{value:"info",label:"Blocks on anything",description:"Generation fails on any finding, info included"}],ye=[{value:"error",label:"Errors only",description:"Warnings and info stay hidden"},{value:"warning",label:"Warnings and errors",description:"Info stays hidden"},{value:"info",label:"Everything",description:"Every finding the analysis produced"}],we="h-8 min-h-0 w-full gap-1.5 px-2 text-xs [&>span]:truncate [&>span]:whitespace-nowrap",Ne="max-w-[min(20rem,var(--radix-select-content-available-width))]",Se="flex items-center gap-1.5 text-xs",ce="text-[11px] leading-snug text-muted-foreground",Xe={value:Re,label:"Default",description:`The format's own profile (${hs[O]})`};function ke({children:t}){return e.jsx("span",{className:"text-[10px] font-semibold tracking-wide text-muted-foreground uppercase",children:t})}function oe({choice:t}){return e.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"font-medium",children:t.label}),e.jsx("span",{className:ce,children:t.description})]})}function ps({className:t}){const s=x.useId(),n=F(c=>c.qualityProfileIds),r=n==null?void 0:n[O],i=F(c=>c.qualityGate)??"none",o=F(c=>c.qualityMinSeverity)??"warning",l=F(c=>c.setSettings),a=xs[O],m=a.find(c=>c.value===r)??Xe,f=be.find(c=>c.value===i)??be[0],d=ye.find(c=>c.value===o)??ye[1];return e.jsxs("div",{className:v("flex w-full min-w-0 flex-col gap-5",t),children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx(ke,{children:"Run policy"}),e.jsxs("div",{className:"grid min-w-0 gap-1.5",children:[e.jsxs(he,{htmlFor:`${s}-profile`,className:Se,children:[e.jsx(ot,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Profile"]}),e.jsxs(pe,{value:m.value,onValueChange:c=>l({qualityProfileIds:{...n,[O]:c===Re?void 0:c}}),children:[e.jsx(ge,{id:`${s}-profile`,"aria-describedby":`${s}-profile-help`,className:we,children:e.jsx(ve,{children:e.jsx("span",{className:"font-medium",children:m.label})})}),e.jsxs(je,{className:Ne,children:[e.jsx(ie,{value:Re,className:"text-xs",children:e.jsx(oe,{choice:Xe})}),a.map(c=>e.jsx(ie,{value:c.value,className:"text-xs",children:e.jsx(oe,{choice:c})},c.value))]})]}),e.jsx("p",{id:`${s}-profile-help`,className:ce,children:m.description})]}),e.jsxs("div",{className:"grid min-w-0 gap-1.5",children:[e.jsxs(he,{htmlFor:`${s}-gate`,className:Se,children:[e.jsx(Le,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Gate"]}),e.jsxs(pe,{value:f.value,onValueChange:c=>l({qualityGate:c}),children:[e.jsx(ge,{id:`${s}-gate`,"aria-describedby":`${s}-gate-help`,className:we,children:e.jsx(ve,{children:e.jsx("span",{className:"font-medium",children:f.label})})}),e.jsx(je,{className:Ne,children:be.map(c=>e.jsx(ie,{value:c.value,className:"text-xs",children:e.jsx(oe,{choice:c})},c.value))})]}),e.jsxs("p",{id:`${s}-gate-help`,className:ce,children:[f.description,"."]})]})]}),e.jsx("div",{className:"h-px shrink-0 bg-border/60"}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx(ke,{children:"Rule policy"}),e.jsx(fs,{})]}),e.jsx("div",{className:"h-px shrink-0 bg-border/60"}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx(ke,{children:"Panel display"}),e.jsxs("div",{className:"grid min-w-0 gap-1.5",children:[e.jsxs(he,{htmlFor:`${s}-severity`,className:Se,children:[e.jsx(Gt,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Show"]}),e.jsxs(pe,{value:d.value,onValueChange:c=>l({qualityMinSeverity:c}),children:[e.jsx(ge,{id:`${s}-severity`,"aria-describedby":`${s}-severity-help`,className:we,children:e.jsx(ve,{children:e.jsx("span",{className:"font-medium",children:d.label})})}),e.jsx(je,{className:Ne,children:ye.map(c=>e.jsx(ie,{value:c.value,className:"text-xs",children:e.jsx(oe,{choice:c})},c.value))})]}),e.jsx("p",{id:`${s}-severity-help`,className:ce,children:"Filters this panel only. It never changes what the run does."})]})]})]})}const gs=/^(?:0|[1-9][0-9]*)$/;function vs(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function js(t){return t.replace(/~/g,"~0").replace(/\//g,"~1")}function Ie(t){return t===""?[]:(t.startsWith("/")?t.slice(1):t).split("/").map(n=>{const r=vs(n);return gs.test(r)?Number(r):r})}function bs(t){return t.map(s=>`/${js(String(s))}`).join("")}function ys(t,s){const n=We(t,[s]);return n||typeof s!="number"?n:We(t,[String(s)])}function ws(t,s){if(!t.trim())return null;let n;try{if(n=Mt(t,[],{allowTrailingComma:!0}),!n)return null;for(const r of Ie(s))if(n=ys(n,r),!n)return null}catch{return null}return{start:n.offset,end:n.offset+n.length}}const Ns=["add","remove","replace","move","copy","test"];function Ss(t,s){try{let n=t;for(let r=0;r<s.length;r++){const i=ks(n,s[r],r);if(!i.ok)return{ok:!1,error:i.error};n=i.value}return{ok:!0,doc:n,applied:s.length}}catch(n){return{ok:!1,error:`quality fix failed: ${Rs(n)}`}}}function ft(t){return!t||t.length===0?!1:t.every(s=>xt(s.op)?s.op==="move"||s.op==="copy"?typeof s.from=="string":!0:!1)}function ks(t,s,n){const r=`fix #${n+1} (${String(s.op)} "${String(s.path)}")`,i=s.op;if(!xt(i))return j(`${r}: unsupported operation "${String(i)}"`);const o=Ie(s.path);switch(i){case"add":return Ee(t,o,s.value,r);case"replace":return Es(t,o,s.value,r);case"remove":{const l=Ke(t,o,r);return l.ok?S(l.value.doc):l}case"copy":{const l=qe(s,r);if(!l.ok)return l;const a=Ze(t,l.value.path);return a.ok?Ee(t,o,a.value,r):j(`${r}: ${a.error}`)}case"move":{const l=qe(s,r);if(!l.ok)return l;if(Cs(l.value.path,o))return S(t);if($s(l.value.path,o))return j(`${r}: ${M(l.value.path)} cannot be moved into its own child`);const a=Ke(t,l.value.path,r);return a.ok?Ee(a.value.doc,o,a.value.removed,r):a}case"test":{const l=Ze(t,o);return l.ok?Ae(l.value,s.value)?S(t):j(`${r}: test failed, the value at the path differs`):j(`${r}: ${l.error}`)}}}function Ee(t,s,n,r){if(s.length===0)return S(n);const i=s[s.length-1];return Oe(t,s,r,o=>{if(Array.isArray(o)){const l=i==="-"?o.length:K(i);if(l===null)return j(`${r}: "${String(i)}" is not an array index`);if(l>o.length)return j(`${r}: index ${l} is past the end of the array`);const a=D(o);return a.splice(l,0,n),S(a)}if(_(o)){const l=D(o);return l[String(i)]=n,S(l)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Es(t,s,n,r){if(s.length===0)return S(n);const i=s[s.length-1];return Oe(t,s,r,o=>{if(Array.isArray(o)){const l=K(i);if(l===null||l>=o.length)return j(`${r}: "${String(i)}" is not an existing array index`);const a=D(o);return a[l]=n,S(a)}if(_(o)){const l=String(i);if(!Z(o,l))return j(`${r}: "${l}" does not exist`);const a=D(o);return a[l]=n,S(a)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Ke(t,s,n){if(s.length===0)return j(`${n}: the whole document cannot be removed`);const r=s[s.length-1];let i;const o=Oe(t,s,n,l=>{if(Array.isArray(l)){const a=K(r);if(a===null||a>=l.length)return j(`${n}: "${String(r)}" is not an existing array index`);const u=D(l);return i=u.splice(a,1)[0],S(u)}if(_(l)){const a=String(r);if(!Z(l,a))return j(`${n}: "${a}" does not exist`);const u=D(l);return i=u[a],delete u[a],S(u)}return j(`${n}: ${M(s.slice(0,-1))} is not an object or array`)});return o.ok?S({doc:o.value,removed:i}):o}function Oe(t,s,n,r){return Te(t,s.slice(0,-1),0,n,r)}function Te(t,s,n,r,i){if(n===s.length)return i(t);const o=()=>M(s.slice(0,n+1)),l=s[n];if(Array.isArray(t)){const a=K(l);if(a===null||a>=t.length)return j(`${r}: ${o()} does not exist`);const u=Te(t[a],s,n+1,r,i);if(!u.ok)return u;const m=D(t);return m[a]=u.value,S(m)}if(_(t)){const a=String(l);if(!Z(t,a))return j(`${r}: ${o()} does not exist`);const u=Te(t[a],s,n+1,r,i);if(!u.ok)return u;const m=D(t);return m[a]=u.value,S(m)}return j(`${r}: ${M(s.slice(0,n))} is not an object or array`)}function Ze(t,s){let n=t;for(let r=0;r<s.length;r++){const i=s[r];if(Array.isArray(n)){const o=K(i);if(o===null||o>=n.length)return j(`${M(s.slice(0,r+1))} does not exist`);n=n[o];continue}if(_(n)){const o=String(i);if(!Z(n,o))return j(`${M(s.slice(0,r+1))} does not exist`);n=n[o];continue}return j(`${M(s.slice(0,r))} is not an object or array`)}return S(n)}function qe(t,s){const n=t.from;return typeof n!="string"?j(`${s}: a "from" pointer is required`):S({pointer:n,path:Ie(n)})}function D(t){return Array.isArray(t)?[...t]:{...t}}function K(t){return typeof t=="number"?Number.isInteger(t)&&t>=0?t:null:/^(?:0|[1-9][0-9]*)$/.test(t)?Number(t):null}function M(t){return t.length===0?"the document root":`"${bs(t)}"`}function xt(t){return Ns.includes(t)}function _(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Z(t,s){return Object.prototype.hasOwnProperty.call(t,s)}function Cs(t,s){return t.length===s.length&&t.every((n,r)=>String(n)===String(s[r]))}function $s(t,s){return t.length>=s.length?!1:t.every((n,r)=>String(n)===String(s[r]))}function Ae(t,s){if(t===s)return!0;if(Array.isArray(t)||Array.isArray(s))return!Array.isArray(t)||!Array.isArray(s)||t.length!==s.length?!1:t.every((n,r)=>Ae(n,s[r]));if(_(t)&&_(s)){const n=Object.keys(t);return n.length!==Object.keys(s).length?!1:n.every(r=>Z(s,r)&&Ae(t[r],s[r]))}return!1}function Rs(t){return t instanceof Error?t.message:String(t)}function S(t){return{ok:!0,value:t}}function j(t){return{ok:!1,error:t}}const le=50,ht=[],pt=["error","warning","info"],Ts={error:lt,warning:G,info:U},gt={error:"text-destructive",warning:"text-warning",info:"text-data-blue"},As=new Set(["actual","expected","unit"]);function vt(t,s){return t==="info"?`${s} info`:`${s} ${t}${s===1?"":"s"}`}function et(t,s){const n=typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t);return s?`${n} ${s}`:n}function Ls(t){if(!t)return null;const s={};let n=!1;for(const[r,i]of Object.entries(t))As.has(r)||(s[r]=i,n=!0);return n?s:null}function tt({path:t,onRevealPath:s,muted:n}){const r=v("inline-flex max-w-full items-center gap-1 rounded-sm font-mono text-[10px]",n?"text-muted-foreground/60":"text-muted-foreground/80");return s?e.jsxs("button",{type:"button",onClick:()=>s(t),title:`Reveal ${t} in the editor`,className:v(r,"-mx-1 px-1 py-0.5 transition-colors","hover:bg-accent hover:text-foreground hover:underline","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:[e.jsx(Jt,{className:"h-2.5 w-2.5 flex-shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:t})]}):e.jsx("span",{className:r,children:e.jsx("span",{className:"truncate",children:t})})}function Is({finding:t,onRevealPath:s,onApplyFixes:n,isApplying:r}){const i=Ts[t.severity]??U,o=gt[t.severity]??"text-muted-foreground",l=Zt(t.certainty),a=t.evidence,u=a!==void 0&&(a.actual!==void 0||a.expected!==void 0),m=Ls(a),f=!!n&&ft(t.fixes),d=t.relatedPaths??[];return e.jsxs("div",{className:"rounded-sm border bg-card px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(i,{className:v("mt-0.5 h-3.5 w-3.5 flex-shrink-0",o)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[t.blocking&&e.jsx("span",{className:"mr-1.5 rounded-sm bg-destructive/15 px-1 py-0.5 align-[1px] text-[10px] font-medium tracking-wide text-destructive uppercase",children:"blocking"}),e.jsx("span",{className:"text-xs leading-relaxed text-foreground",children:t.message})]})]}),e.jsxs("div",{className:"mt-1.5 pl-[1.375rem]",children:[u&&a&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[a.expected!==void 0&&e.jsxs(e.Fragment,{children:["Expected"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:et(a.expected,a.unit)})]}),a.expected!==void 0&&a.actual!==void 0&&e.jsx("span",{className:"text-muted-foreground/50",children:" · "}),a.actual!==void 0&&e.jsxs(e.Fragment,{children:[a.expected===void 0?"Found":"found"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:et(a.actual,a.unit)})]})]}),(t.suggestion||f)&&e.jsxs("div",{className:v("mt-1.5 flex items-center gap-2 rounded-sm bg-header-bg/70 px-2 py-1.5",!t.suggestion&&"justify-end"),children:[t.suggestion&&e.jsx("p",{className:"min-w-0 flex-1 text-[11px] leading-relaxed text-muted-foreground",children:t.suggestion}),f&&e.jsxs("button",{type:"button",onClick:()=>n==null?void 0:n(t),disabled:r,className:v("flex flex-shrink-0 items-center gap-1 rounded-sm border bg-card px-1.5 py-1","text-[11px] font-medium text-foreground transition-colors","hover:bg-accent focus-visible:ring-1 focus-visible:ring-ring","focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-60"),children:[r?e.jsx(X,{size:"sm",variant:"muted",className:"h-3 w-3"}):e.jsx(Vt,{className:"h-3 w-3","aria-hidden":"true"}),"Apply fix"]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-2.5 gap-y-1",children:[t.path&&e.jsx(tt,{path:t.path,onRevealPath:s}),d.map(c=>e.jsx(tt,{path:c,onRevealPath:s,muted:!0},c)),l&&e.jsx("span",{className:"text-[10px] text-muted-foreground/70",title:"How the analysis reached this finding",children:l}),t.code&&e.jsx("code",{className:"text-[10px] text-muted-foreground/60",children:t.code})]}),m&&e.jsxs("details",{className:"mt-1.5",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground/70 hover:text-foreground",children:"More evidence"}),e.jsx("pre",{className:"mt-1 overflow-x-auto rounded-sm bg-header-bg p-1.5 text-[11px] text-muted-foreground",children:JSON.stringify(m,null,2)})]})]})]})}function Os({quality:t,id:s,className:n,onRevealPath:r,onApplyFixes:i,applyingFindingId:o}){const l=F(y=>y.qualityMinSeverity),[a,u]=N.useState(!1),[m,f]=N.useState(!1),d=(t==null?void 0:t.findings)??ht,c=l??"warning",p=N.useMemo(()=>Xt(d,c),[d,c]),b=a?d:p,R=N.useMemo(()=>Kt(b),[b]),z=N.useMemo(()=>{if(m||b.length<=le)return R;let y=le;const C=[];for(const I of R){if(y<=0)break;const P=I.findings.slice(0,y);y-=P.length,C.push({category:I.category,findings:P})}return C},[R,m,b.length]),E=N.useMemo(()=>$e(d),[d]),V=N.useMemo(()=>$e(p),[p]),H=d.length-p.length,J=N.useMemo(()=>{const y=[];let C=0;for(const I of pt){const P=E[I]-V[I];P>0&&(y.push(vt(I,P)),C+=P)}return C<H&&y.push(`${H-C} other`),y.join(", ")},[E,V,H]);return!t||d.length===0&&!t.gateError&&!t.analysisError&&!t.truncated?null:e.jsxs("div",{id:s,className:v("space-y-1.5",n),children:[t.gateError&&e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border border-destructive/40 bg-destructive/10 px-3 py-2",children:[e.jsx(Le,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-destructive"}),e.jsx("p",{className:"text-xs leading-relaxed text-destructive",children:t.gateError})]}),t.analysisError&&e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-muted/60 px-3 py-2",children:[e.jsx(U,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),e.jsxs("p",{className:"text-xs leading-relaxed text-muted-foreground",children:[t.analysisError,d.length>0&&" Showing the last completed analysis."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[t.truncated&&e.jsx("p",{className:"px-0.5 text-[11px] text-muted-foreground/80",children:"The analysis stopped early — not every finding is listed."}),H>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-sm border border-dashed px-3 py-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] text-muted-foreground",children:a?`${J} below the ${c} filter, now shown`:`${J} hidden by the ${c}-and-above filter`}),e.jsx("button",{type:"button",onClick:()=>u(!a),className:v("flex-shrink-0 rounded-sm px-1.5 py-0.5 text-[11px] font-medium","text-foreground transition-colors hover:bg-accent","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:a?"Hide again":"Show all"})]}),z.map(y=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"px-0.5 text-[10px] font-medium tracking-wide text-muted-foreground/70 uppercase",children:y.category}),y.findings.map(C=>e.jsx(Is,{finding:C,onRevealPath:r,onApplyFixes:i,isApplying:o===C.id},C.id))]},y.category)),b.length>le&&e.jsx("button",{type:"button",onClick:()=>f(!m),className:v("w-full rounded-sm border border-dashed px-3 py-1.5 text-[11px]","font-medium text-muted-foreground transition-colors","hover:bg-accent hover:text-foreground","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:m?`Show first ${le}`:`Show all ${b.length}`})]})]})}function jt(t){return t?t.findings.length>0||!!t.gateError||!!t.analysisError||!!t.truncated:!1}function Ms({quality:t,open:s=!1,onToggle:n,controlsId:r,className:i}){const o=N.useMemo(()=>$e((t==null?void 0:t.findings)??ht),[t==null?void 0:t.findings]);if(!t)return null;const l=!!(t.blocked||t.gateError),a=pt.filter(p=>o[p]>0),u=jt(t)&&!!n,m=l||o.error>0?"text-destructive":o.warning>0?"text-warning":t.analysisError?"text-muted-foreground":a.length===0?"text-success":"text-data-blue",f=l?Le:o.error>0?lt:o.warning>0?G:t.analysisError?U:a.length===0?Ut:U,d=e.jsxs(e.Fragment,{children:[u&&e.jsx(it,{className:v("h-3.5 w-3.5 flex-shrink-0 text-muted-foreground transition-transform",s&&"rotate-90"),"aria-hidden":"true"}),e.jsx(f,{className:v("h-3.5 w-3.5 flex-shrink-0",m)}),e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Quality"}),a.length===0?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:t.analysisError?"Not available":"No findings"}):a.map((p,b)=>e.jsxs(N.Fragment,{children:[b>0&&e.jsx("span",{"aria-hidden":"true",className:"text-muted-foreground/40",children:"·"}),e.jsx("span",{className:v("text-xs font-medium",gt[p]),children:vt(p,o[p])})]},p)),l&&e.jsx("span",{className:"flex-shrink-0 rounded-sm bg-destructive/15 px-1.5 py-0.5 text-[10px] font-medium tracking-wide text-destructive uppercase",children:"blocked"}),t.profileId&&e.jsx("span",{className:"ml-auto truncate pl-2 font-mono text-[10px] text-muted-foreground",title:`Quality profile: ${t.profileId}`,children:t.profileId})]}),c="flex min-w-0 items-center gap-2 rounded-sm px-1.5 py-0.5";return u?e.jsx("button",{type:"button",onClick:n,"aria-expanded":s,"aria-controls":s?r:void 0,className:v(c,"text-left transition-colors hover:bg-accent","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none",i),children:d}):e.jsx("div",{className:v(c,i),children:d})}const st={pptx:["default","dark","minimal"],docx:["minimal","corporate","modern"]};function Ps({className:t}){var l;const s=L(a=>a.activeTab),n=L(a=>a.documentTypes),r=L(a=>a.documents),i=ct(a=>a.customThemes),o=x.useMemo(()=>{var m,f,d;if(!s||n[s]==="application/json+theme")return null;const a=r.find(c=>c.name===s);if(!(a!=null&&a.text))return null;let u;try{u=(f=(m=JSON.parse(a.text))==null?void 0:m.props)==null?void 0:f.theme}catch{return null}if(typeof u!="string"||!u||(d=st[O])!=null&&d.includes(u))return null;for(const c of Object.values(i))if(c.valid&&c.name===u)return null;return u},[s,n,r,i]);return o?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(G,{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:o})," ","is not available."]})," ",e.jsxs("span",{className:"text-warning/80",children:["Add it as a custom theme or use a built-in theme (",(l=st[O])==null?void 0:l.join(", "),"). The renderer will fall back to a default."]})]})]}):null}async function Fs(t,s,n,r,i,o){const l=typeof n=="string"&&n.length>0;let a;if(l){let f;try{f=JSON.parse(n)}catch(c){throw new Error(`Invalid JSON document: ${c.message}`)}const d={jsonDefinition:f,customThemes:r??{},options:{sourceName:o??t,...i?{renderer:i}:{}}};a=await fetch(Ce.preview.libreofficeFromJson,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})}else{const f=new FormData,d=O==="pptx"?".pptx":".docx";f.append("file",s,`${t}${d}`),a=await fetch(Ce.preview.libreoffice,{method:"POST",body:f})}if(!a.ok){let f=`LibreOffice preview failed (${a.status})`;try{const d=await a.json();d&&typeof d=="object"&&typeof d.error=="string"&&(f=d.error)}catch{}throw new Error(f)}const u=await a.blob();if(!u.size)throw new Error("LibreOffice preview returned an empty PDF");const m=URL.createObjectURL(u);return{iframeSrc:m,cleanup:()=>URL.revokeObjectURL(m)}}async function Ds(t,s,n,r,i,o){try{if(!s||s.size===0)throw new Error("Invalid or empty document blob");const l=await Fs(t,s,n,r,i,o);return{status:"success",name:t,payload:l}}catch(l){const a=l instanceof Error?l.message:String(l);return{status:"error",name:t,payload:new Error(a)}}}function zs(){const t=L(i=>i.activeTab),s=L(i=>i.documents),n=L(i=>i.documentTypes),r=L(i=>i.saveDocument);return x.useCallback((i,o)=>{var c;const l=i.fixes;if(!l||!ft(l))return{ok:!1,error:"This finding carries no applicable fix."};if(!t)return{ok:!1,error:"No active file"};if(o&&o!==t)return{ok:!1,error:`This finding belongs to ${o}, which is no longer the active file.`};if(n[t]==="application/json+theme")return{ok:!1,error:"Quality fixes apply to a document, not to a theme."};const a=s.find(p=>p.name===t);if(!a)return{ok:!1,error:"Active document not found"};const u=at.getState().getEditor(t);(c=u==null?void 0:u.flushPendingSave)==null||c.call(u);const m=u?u.toStorageValue(u.editor.getValue()):a.text;let f;try{f=JSON.parse(m)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const d=Ss(f,l);return d.ok?(r(t,JSON.stringify(d.doc,null,2)),{ok:!0}):{ok:!1,error:d.error}},[t,n,s,r])}const Me=x.forwardRef(({className:t,value:s,...n},r)=>e.jsx(dt,{ref:r,className:v("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...n,children:e.jsx(rs,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(s||0)}%)`}})}));Me.displayName=dt.displayName;function bt(t){if(t===0)return"0 B";const s=1024,n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(s));return parseFloat((t/Math.pow(s,r)).toFixed(2))+" "+n[r]}function Bs(){const[t,s]=x.useState(null),[n,r]=x.useState(!0),[i,o]=x.useState(null);if(x.useEffect(()=>{const u=new AbortController,m=async()=>{try{const c=await fetch(Ce.cacheStats,{signal:u.signal});if(!c.ok)throw new Error("Failed to fetch cache stats");const p=await c.json();u.signal.aborted||(s(p.data),o(null))}catch(c){u.signal.aborted||(c instanceof Error&&c.name!=="AbortError"?o(c.message):(!(c instanceof Error)||c.name!=="AbortError")&&o("Failed to load cache stats"))}finally{u.signal.aborted||r(!1)}};m();const f=setInterval(m,5e3),d=()=>m();return window.addEventListener("cache:cleared",d),()=>{u.abort(),clearInterval(f),window.removeEventListener("cache:cleared",d)}},[]),n)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(i)return e.jsxs("div",{className:"text-destructive p-4",children:["Error loading cache metrics: ",i]});if(!t)return null;const{document:l}=t,a=l.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:[a.toFixed(1),"%"]}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",l.hits," hits / ",l.misses," misses)"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Size"})," ",e.jsx("span",{className:"font-semibold",children:bt(l.size)}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",l.itemCount," items)"]})]}),e.jsx(Pt,{variant:l.enabled?"default":"secondary",children:l.enabled?"Enabled":"Disabled"})]}),e.jsx(Me,{value:a,className:"h-2","aria-label":"Cache hit rate"}),t.rasterizer&&e.jsx(_s,{data:t.rasterizer})]})}function _s({data:t}){const s=t.diskHits+t.diskMisses;if(s+t.dedupedRequests+t.rendered+t.entries===0)return null;const r=t.hitRate*100,i=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:s>0?`${r.toFixed(0)}% hit`:"no lookups"}),e.jsxs("span",{children:["(",t.diskHits," hits / ",t.diskMisses," misses)"]}),e.jsxs("span",{children:[t.entries," PNGs, ",bt(t.bytes)]})]})]}),e.jsx(Me,{value:r,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:[i," duplicate visual",i===1?"":"s"," deduped",t.prepass?` (${t.prepass.collected} collected → ${t.prepass.unique} unique)`:""]})]})]})]})}function qs(){var ae,Ve;const{name:t,text:s,blob:n,renderer:r,isGenerating:i,generationProgress:o,generationStartedAt:l,cancelGeneration:a,globalError:u,cacheStatus:m,cacheHitRate:f,warnings:d,quality:c,isRendering:p,isPreviewStale:b,editSequence:R,lastBuiltSequence:z,setOutput:E}=ts(h=>h),V=L(h=>{var g;return h.activeTab&&h.documentTypes[h.activeTab]!=="application/json+theme"?(g=h.documents.find(k=>k.name===h.activeTab))==null?void 0:g.text:void 0}),H=L(h=>h.activeTab&&h.documentTypes[h.activeTab]!=="application/json+theme"?h.activeTab:void 0),J=x.useContext(ss),{toast:y}=Ot(),C=zs(),{analyze:I}=qt(),[P,Pe]=x.useState(null),[W,Fe]=x.useState(!1),[q,ee]=x.useState(!1),De=N.useId(),ze=L(h=>h.activeTab),B=x.useMemo(()=>c&&c.documentName===ze?c:null,[c,ze]),de=W||q,ue=x.useCallback(()=>{Fe(!1),ee(!1)},[]);x.useEffect(()=>{if(!de)return;const h=g=>{g.key==="Escape"&&ue()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[de,ue]);const Be=B==null?void 0:B.gateError;x.useEffect(()=>{Be&&ee(!0)},[Be]);const _e=jt(B);x.useEffect(()=>{_e||ee(!1)},[_e]);const yt=x.useMemo(()=>es(d).others,[d]),wt=x.useCallback(h=>{if(!h)return;const g=at.getState().getActiveEditor();if(!g)return;const{editor:k,monaco:T}=g,A=k.getModel();if(!A)return;const $=ws(A.getValue(),h);if(!$)return;const w=A.getPositionAt($.start),Q=A.getPositionAt($.end),Je=new T.Range(w.lineNumber,w.column,Q.lineNumber,Q.column);k.revealRangeNearTopIfOutsideViewport(Je,T.editor.ScrollType.Smooth),k.setPosition(w),k.setSelection(Je),k.focus()},[]),te=x.useRef(new Set);x.useEffect(()=>{te.current=new Set},[c==null?void 0:c.seq]);const Nt=x.useCallback(h=>{var g;if(!te.current.has(h.id)){te.current.add(h.id),Pe(h.id);try{const k=C(h,c==null?void 0:c.documentName);if(!k.ok){te.current.delete(h.id),y({variant:"destructive",title:"Could not apply fix",description:k.error});return}const{activeTab:T,documents:A}=J.getState(),$=(g=A.find(w=>w.name===T))==null?void 0:g.text;$&&I(T,$,{immediate:!0})}finally{Pe(null)}}},[I,C,J,c==null?void 0:c.documentName,y]),He=ct(h=>h.customThemes),Qe=x.useMemo(()=>{const h={};for(const g of Object.values(He))g.valid&&g.name&&g.parsed&&(h[g.name]=g.parsed);return h},[He]),[St,kt]=x.useState(void 0),[Et,Ct]=x.useState(void 0),[$t,me]=x.useState(!1),Rt=N.useRef(null),se=x.useRef(null),fe=x.useRef(!1),Ge=ns(),ne=x.useCallback(()=>{se.current&&(se.current(),se.current=null)},[]),re=x.useCallback(async(h,g,k,T,A)=>{E({isRendering:!0,isPreviewStale:!1,globalError:void 0});try{const{status:$,payload:w}=await Ds(h,g,k,T,A,Ge(h));if($!=="success")throw w instanceof Error?w:new Error(String(w));ne(),kt(w.iframeSrc||void 0),Ct(w.iframeSrcDoc||void 0),se.current=w.cleanup||null}catch($){const w=$ instanceof Error?$.message:String($);let Q=w;w.includes("Failed to fetch")?Q="Network error: Unable to load required resources. Check if the server is running properly.":w.includes("timeout")&&(Q="Render timeout: The rendering process took too long."),E({globalError:Q})}finally{E({isRendering:!1})}},[E,ne,Ge]),Tt=x.useRef({name:t,blob:n,text:s,doRender:re});x.useEffect(()=>{Tt.current={name:t,blob:n,text:s,doRender:re}});const xe=x.useCallback(async()=>{fe.current=!0,window.dispatchEvent(new CustomEvent("preview:flushAndBuild"))},[]);x.useEffect(()=>{if(!(!n||!t)){if(fe.current){fe.current=!1,re(t,n,s,Qe,r);return}E({isPreviewStale:!0})}},[n,t,s,Qe,r,re,E]),x.useEffect(()=>()=>{ne()},[ne]),x.useEffect(()=>{const h=()=>xe(),g=()=>me(!0);return window.addEventListener("preview:manualRender",h),window.addEventListener("preview:showCacheMetrics",g),()=>{window.removeEventListener("preview:manualRender",h),window.removeEventListener("preview:showCacheMetrics",g)}},[xe]);const Ue=((Ve=(ae=F)==null?void 0:ae.getState)==null?void 0:Ve.call(ae).useGlobalPreviewHeader)===!1;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-full flex-col",children:[Ue&&e.jsx(Ft,{name:(t==null?void 0:t.trim())||"Preview",blob:n,onManualRender:xe,isGenerating:i,isRendering:p,onShowCacheMetrics:()=>me(!0),documentText:s,editorDocumentText:V,editorDocumentName:H,warnings:d}),!Ue&&e.jsx(Dt,{}),(()=>{const h=(R??0)>(z??0),g=(b||h)&&!i&&!p,k=g?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full bg-warning"}),e.jsx("span",{className:"truncate text-xs text-warning",children:"Outdated — click Run"})]}):m==="HIT"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full bg-success"}),e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:"Cached"})]}):m==="MISS"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full bg-accent2"}),e.jsxs("span",{className:"truncate text-xs text-muted-foreground",children:["Fresh ",nt.toLowerCase()]})]}):null,T=!!k&&(m&&m!=="UNKNOWN"||g);return e.jsxs("div",{className:"flex items-center gap-2 overflow-hidden border-b bg-header-bg px-3 py-1.5",children:[T&&e.jsx("div",{className:"flex min-w-0 flex-shrink items-center gap-2",children:k}),T&&B&&e.jsx("div",{"aria-hidden":"true",className:"h-3 w-px flex-shrink-0 bg-border"}),e.jsx(Ms,{quality:B,open:q,onToggle:()=>ee(A=>!A),controlsId:De,className:"min-w-0 flex-1"}),!g&&f&&f!=="0.0%"&&e.jsxs("span",{className:"hidden flex-shrink-0 text-xs text-muted-foreground lg:inline",children:[f," hit rate"]}),e.jsxs("button",{type:"button",onClick:()=>Fe(!W),"aria-expanded":W,className:v("flex flex-shrink-0 items-center gap-1.5 rounded-sm px-1.5 py-0.5","text-[11px] font-medium text-muted-foreground","transition-colors hover:bg-accent hover:text-foreground","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:[e.jsx(ot,{className:"h-3 w-3","aria-hidden":"true"}),e.jsx("span",{className:"hidden sm:inline",children:"Quality settings"})]})]})})(),e.jsx(ms,{warnings:yt,className:"mx-3 my-2"}),e.jsx(Ps,{className:"mx-3 my-2"}),e.jsxs("div",{className:"relative min-h-0 flex-1",children:[u&&!i?e.jsx("div",{className:"flex h-full 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:u})]})}):e.jsx(us,{ref:Rt,isLoading:!!p,iframeSrc:St,iframeSrcDoc:Et,isGenerating:!!i,generationProgress:o,generationDocumentText:V??s,generationStartedAt:l,onCancelGeneration:a}),de&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 z-30",onClick:ue,"aria-hidden":"true"}),e.jsxs("div",{className:v("absolute inset-x-3 top-2 bottom-2 z-40 overflow-y-auto","rounded-sm border bg-card p-4 shadow-lg"),children:[W&&e.jsx(ps,{}),W&&q&&e.jsx("div",{className:"my-4 border-t"}),q&&e.jsx(Os,{id:De,quality:B,onRevealPath:wt,onApplyFixes:Nt,applyingFindingId:P})]})]})]})]}),e.jsx(zt,{open:$t,onOpenChange:me,children:e.jsxs(Bt,{className:"max-w-2xl",children:[e.jsx(_t,{children:e.jsx(Ht,{children:"Cache Performance"})}),e.jsx(Bs,{})]})})]})}export{qs as Preview};
2
- //# sourceMappingURL=preview-zCYkbgdR.js.map
1
+ import{r as x,j as e,c as N}from"./react-vendor-BmQ2Ko_D.js";import{S as X,c as v,h as nt,g as At,F as O,p as Lt,Q as It,A as Ce,u as Ot}from"./index-CgCY8SiY.js";import{S as Y,L as he,b as pe,c as ge,d as ve,e as je,f as ie,p as Mt,g as We,B as Pt,P as Ft,h as Dt,D as zt,i as Bt,j as _t,k as Ht}from"./HomePage-r7ryeW_v.js";import{B as rt,u as at}from"./editor-refs-store-ChL2fzuX.js";import{e as it,Q as G,x as U,a4 as Qt,a5 as ot,a6 as Le,W as Gt,a7 as lt,a8 as Ut,a9 as Vt,aa as Jt}from"./ui-vendor-Bq4-oNFL.js";import Wt from"./monaco-editor-DJsdM0WK.js";import{E as Ye,p as Yt,c as $e,d as Xt,g as Kt,e as Zt,u as qt,a as es}from"./useQualityAnalysis-eKT8VcIt.js";import{d as F,u as L,a as ct,b as ts,j as ss,e as ns}from"./MonacoPluginProvider-CGvtVJKz.js";import{ad as dt,ae as rs}from"./radix-ui-DFNP5I4e.js";import"./query-vendor--rhYD8mC.js";import"./state-vendor-Cq67_JbF.js";function ut(t){const[s]=x.useState(()=>Date.now()),n=t??s,[r,i]=x.useState(()=>Date.now());return x.useEffect(()=>{const o=setInterval(()=>i(Date.now()),100);return()=>clearInterval(o)},[]),Math.max(0,(r-n)/1e3)}function as(t){var s,n;if(!t)return null;try{const r=JSON.parse(t);if(!r||typeof r!="object")return null;const i=new Map,o=[r];for(;o.length>0;){const m=o.pop();if(!m||typeof m!="object")continue;const{name:f,children:d}=m;typeof f=="string"&&i.set(f,(i.get(f)??0)+1),Array.isArray(d)&&o.push(...d)}const a=[["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(([m,f,d])=>{const c=i.get(m)??0;return{label:c===1?f:d,count:c}}).filter(m=>m.count>0).slice(0,5),u=(n=(s=r.props)==null?void 0:s.metadata)==null?void 0:n.title;return{title:typeof u=="string"?u:void 0,counts:a,visualCount:(i.get("visual")??0)+(i.get("chart")??0),imageCount:i.get("image")??0}}catch{return null}}function is(t){const s=[];return t&&t.visualCount>0&&s.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&&s.push("Large embedded images dominate build time — downscaling them speeds up iteration."),s.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."),s}const os=()=>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 ls({className:t,currentStage:s="parsing",message:n,documentText:r,startedAt:i,onCancel:o}){const l=["parsing","building","rendering","finalizing"],a={parsing:"Validating JSON",building:"Building structure",rendering:"Rendering content",finalizing:"Finalizing document"},u=l.indexOf(s),m=ut(i),f=x.useMemo(()=>as(r),[r]),d=x.useMemo(()=>is(f),[f]),c=m>3,p=Math.floor(Math.max(0,m-3)/5)%d.length;return e.jsxs("div",{className:v("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(X,{size:"md"}),e.jsxs("div",{className:"space-y-0.5 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:f!=null&&f.title?`Generating “${f.title}”`:"Generating document"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",role:"status","aria-live":"polite",children:n||`${a[s]}...`})]})]}),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:[m.toFixed(1),"s"]})]}),f&&f.counts.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5","aria-label":"Document contents",children:f.counts.map(({label:b,count:R})=>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:R}),b]},b))}),e.jsx("div",{className:"space-y-3",children:l.map((b,R)=>{const z=R===u,E=R<u;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:v(z?"text-primary font-medium":E?"text-muted-foreground":"text-muted-foreground/60"),children:a[b]}),E?e.jsx(os,{}):z?e.jsx(X,{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:E?e.jsx("div",{className:"h-full w-full rounded-full bg-success"}):z?e.jsx("div",{className:"h-full w-2/5 rounded-full bg-primary animate-progress-indeterminate"}):null})]},b)})}),e.jsxs("div",{className:"flex items-center justify-between gap-3 min-h-8",children:[e.jsx("p",{className:v("text-xs text-muted-foreground/80 italic transition-opacity duration-500",c?"opacity-100":"opacity-0"),children:d[p]}),o&&e.jsx(rt,{variant:"outline",size:"sm",onClick:o,className:"shrink-0",children:"Cancel"})]})]})}function cs({mode:t,message:s,startedAt:n,onCancel:r,className:i}){const o=ut(n);return e.jsxs("div",{className:v("flex flex-col items-center gap-2 rounded-md border bg-background/95 px-6 py-4 shadow-sm",i),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{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:[o.toFixed(1),"s"]})]}),s&&e.jsx("p",{className:"max-w-xs text-center text-xs text-muted-foreground truncate",children:s}),t==="generating"&&r&&e.jsx(rt,{variant:"outline",size:"sm",onClick:r,children:"Cancel"})]})}function ds({renderingLibrary:t,className:s}){const n=o=>{switch(o){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:r,description:i}=n(t);return e.jsxs("div",{className:v("flex flex-col items-center justify-center h-full p-8 space-y-4",s),children:[e.jsx(X,{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 ",r," renderer"]}),e.jsx("p",{className:"text-xs text-muted-foreground/80",children:i})]}),e.jsxs("div",{className:"w-full max-w-md space-y-3",children:[e.jsx(Y,{className:"h-16 w-full"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{className:"h-4 w-full"}),e.jsx(Y,{className:"h-4 w-3/4"}),e.jsx(Y,{className:"h-4 w-1/2"})]}),e.jsx(Y,{className:"h-12 w-full"})]})]})}const mt=N.forwardRef(({isLoading:t,iframeSrc:s,iframeSrcDoc:n,isGenerating:r,generationProgress:i,generationDocumentText:o,generationStartedAt:l,onCancelGeneration:a},u)=>{const[m,f]=x.useState(!1);x.useEffect(()=>{f(!1)},[s,n]);const d=()=>{f(!0)},c=()=>{console.warn("Iframe failed to load content"),f(!1)},p=n?"allow-scripts allow-popups allow-forms":void 0,b=!!(s||n);return r&&!b?e.jsx("div",{className:"grow",children:e.jsx(ls,{currentStage:i==null?void 0:i.stage,message:i==null?void 0:i.message,documentText:o,startedAt:l,onCancel:a})}):t&&!b?e.jsx("div",{className:"grow",children:e.jsx(ds,{renderingLibrary:"LibreOffice"})}):b?e.jsxs("div",{className:"h-full w-full relative bg-white",children:[!m&&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..."})]})}),(r||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(cs,{mode:r?"generating":"rendering",message:r?i==null?void 0:i.message:void 0,startedAt:r?l:void 0,onCancel:r?a:void 0})}),e.jsx("iframe",{ref:u,className:"w-full h-full border-0",style:{backgroundColor:"white",opacity:m?1:0,transition:"opacity 0.2s ease-in-out"},src:s,srcDoc:n,onLoad:d,onError:c,sandbox:p,title:"Document preview","aria-label":`Preview of rendered ${nt.toLowerCase()}`},n?"srcdoc":"src")]}):null});mt.displayName="PreviewFrame";const us=N.memo(mt);function ms({warnings:t,className:s}){const[n,r]=N.useState(!1),i=N.useMemo(()=>(t??[]).filter(o=>o.component!=="quality"),[t]);return i.length===0?null:e.jsxs("div",{className:s,children:[e.jsxs("button",{type:"button",onClick:()=>r(!n),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(it,{className:`h-3.5 w-3.5 text-warning transition-transform flex-shrink-0 ${n?"rotate-90":""}`}),e.jsx(G,{className:"h-3.5 w-3.5 text-warning flex-shrink-0"}),e.jsxs("span",{className:"text-xs font-medium text-warning",children:[i.length," warning",i.length!==1?"s":""]})]}),n&&e.jsx("div",{className:"mt-1.5 space-y-1.5",children:i.map((o,l)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-card px-3 py-2",children:[o.severity==="info"?e.jsx(U,{className:"h-3.5 w-3.5 mt-0.5 text-data-blue flex-shrink-0"}):e.jsx(G,{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:o.component}),o.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:o.message}),o.context&&Object.keys(o.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(o.context,null,2)})]})]})]},l))})]})}function fs({className:t}){const{resolvedTheme:s}=At(),n=F(d=>d.qualityPolicies),r=F(d=>d.setSettings),i=n==null?void 0:n[O],[o,l]=x.useState(i??Ye),a=x.useMemo(()=>Yt(o),[o]),u=x.useMemo(()=>Lt().map(d=>d.id),[]),m=x.useCallback(d=>{l(d),r({qualityPolicies:{...n,[O]:d}})},[n,r]),f=x.useCallback(()=>m(Ye),[m]);return e.jsxs("div",{className:v("flex min-w-0 flex-col gap-2",t),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[11px] leading-snug text-muted-foreground",children:"Rule severity, parameters and suppressions. The gate and profile stay with their controls above."}),e.jsxs("button",{type:"button",onClick:f,className:v("flex flex-shrink-0 items-center gap-1 rounded-sm px-1.5 py-0.5","text-[11px] font-medium text-muted-foreground transition-colors","hover:bg-accent hover:text-foreground","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:[e.jsx(Qt,{className:"h-3 w-3","aria-hidden":"true"}),"Reset"]})]}),e.jsx("div",{className:"overflow-hidden rounded-sm border",children:e.jsx(Wt,{height:"180px",language:"json",path:It,theme:s==="dark"?"vs-dark":"vs",defaultValue:o,onChange:d=>m(d??""),options:{minimap:{enabled:!1},lineNumbers:"off",folding:!1,scrollBeyondLastLine:!1,fontSize:11,lineHeight:17,tabSize:2,renderLineHighlight:"none",overviewRulerLanes:0,scrollbar:{verticalScrollbarSize:8,horizontalScrollbarSize:8},padding:{top:8,bottom:8},automaticLayout:!0}})}),a.ok?e.jsx("p",{className:"text-[11px] leading-snug text-muted-foreground",children:a.policy?"Applied to every analysis and build.":"Empty — the profile decides on its own."}):e.jsxs("p",{className:"flex items-start gap-1.5 text-[11px] leading-snug text-destructive",children:[e.jsx(G,{className:"mt-0.5 h-3 w-3 flex-shrink-0","aria-hidden":"true"}),e.jsxs("span",{children:[a.error," Until this parses, the run ignores it."]})]}),e.jsxs("details",{className:"text-[11px] text-muted-foreground",children:[e.jsx("summary",{className:"cursor-pointer hover:text-foreground",children:"Rules in this format"}),e.jsx("ul",{className:"mt-1 space-y-0.5 pl-3",children:u.map(d=>e.jsx("li",{className:"font-mono text-[10px]",children:d},d))})]})]})}const Re="__default__",xs={docx:[{value:"executive-report",label:"Executive report",description:"Short decision document with strict outline continuity"},{value:"technical-report",label:"Technical report",description:"Portable professional report defaults"},{value:"legal-appendix",label:"Legal appendix",description:"Dense appendix: preserve integrity without editorial taste"}],pptx:[{value:"executive-presentation",label:"Executive presentation",description:"Decision deck optimized for scan speed and projection"},{value:"technical-presentation",label:"Technical presentation",description:"Portable professional presentation defaults"}]},hs={docx:"technical-report",pptx:"technical-presentation"},be=[{value:"none",label:"Never blocks",description:"Findings are reported and the run always finishes"},{value:"error",label:"Blocks on errors",description:"Generation fails when a finding is an error"},{value:"warning",label:"Blocks on warnings",description:"Generation fails on any warning or error"},{value:"info",label:"Blocks on anything",description:"Generation fails on any finding, info included"}],ye=[{value:"error",label:"Errors only",description:"Warnings and info stay hidden"},{value:"warning",label:"Warnings and errors",description:"Info stays hidden"},{value:"info",label:"Everything",description:"Every finding the analysis produced"}],we="h-8 min-h-0 w-full gap-1.5 px-2 text-xs [&>span]:truncate [&>span]:whitespace-nowrap",Ne="max-w-[min(20rem,var(--radix-select-content-available-width))]",Se="flex items-center gap-1.5 text-xs",ce="text-[11px] leading-snug text-muted-foreground",Xe={value:Re,label:"Default",description:`The format's own profile (${hs[O]})`};function ke({children:t}){return e.jsx("span",{className:"text-[10px] font-semibold tracking-wide text-muted-foreground uppercase",children:t})}function oe({choice:t}){return e.jsxs("span",{className:"flex min-w-0 flex-col gap-0.5",children:[e.jsx("span",{className:"font-medium",children:t.label}),e.jsx("span",{className:ce,children:t.description})]})}function ps({className:t}){const s=x.useId(),n=F(c=>c.qualityProfileIds),r=n==null?void 0:n[O],i=F(c=>c.qualityGate)??"none",o=F(c=>c.qualityMinSeverity)??"warning",l=F(c=>c.setSettings),a=xs[O],m=a.find(c=>c.value===r)??Xe,f=be.find(c=>c.value===i)??be[0],d=ye.find(c=>c.value===o)??ye[1];return e.jsxs("div",{className:v("flex w-full min-w-0 flex-col gap-5",t),children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx(ke,{children:"Run policy"}),e.jsxs("div",{className:"grid min-w-0 gap-1.5",children:[e.jsxs(he,{htmlFor:`${s}-profile`,className:Se,children:[e.jsx(ot,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Profile"]}),e.jsxs(pe,{value:m.value,onValueChange:c=>l({qualityProfileIds:{...n,[O]:c===Re?void 0:c}}),children:[e.jsx(ge,{id:`${s}-profile`,"aria-describedby":`${s}-profile-help`,className:we,children:e.jsx(ve,{children:e.jsx("span",{className:"font-medium",children:m.label})})}),e.jsxs(je,{className:Ne,children:[e.jsx(ie,{value:Re,className:"text-xs",children:e.jsx(oe,{choice:Xe})}),a.map(c=>e.jsx(ie,{value:c.value,className:"text-xs",children:e.jsx(oe,{choice:c})},c.value))]})]}),e.jsx("p",{id:`${s}-profile-help`,className:ce,children:m.description})]}),e.jsxs("div",{className:"grid min-w-0 gap-1.5",children:[e.jsxs(he,{htmlFor:`${s}-gate`,className:Se,children:[e.jsx(Le,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Gate"]}),e.jsxs(pe,{value:f.value,onValueChange:c=>l({qualityGate:c}),children:[e.jsx(ge,{id:`${s}-gate`,"aria-describedby":`${s}-gate-help`,className:we,children:e.jsx(ve,{children:e.jsx("span",{className:"font-medium",children:f.label})})}),e.jsx(je,{className:Ne,children:be.map(c=>e.jsx(ie,{value:c.value,className:"text-xs",children:e.jsx(oe,{choice:c})},c.value))})]}),e.jsxs("p",{id:`${s}-gate-help`,className:ce,children:[f.description,"."]})]})]}),e.jsx("div",{className:"h-px shrink-0 bg-border/60"}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx(ke,{children:"Rule policy"}),e.jsx(fs,{})]}),e.jsx("div",{className:"h-px shrink-0 bg-border/60"}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx(ke,{children:"Panel display"}),e.jsxs("div",{className:"grid min-w-0 gap-1.5",children:[e.jsxs(he,{htmlFor:`${s}-severity`,className:Se,children:[e.jsx(Gt,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Show"]}),e.jsxs(pe,{value:d.value,onValueChange:c=>l({qualityMinSeverity:c}),children:[e.jsx(ge,{id:`${s}-severity`,"aria-describedby":`${s}-severity-help`,className:we,children:e.jsx(ve,{children:e.jsx("span",{className:"font-medium",children:d.label})})}),e.jsx(je,{className:Ne,children:ye.map(c=>e.jsx(ie,{value:c.value,className:"text-xs",children:e.jsx(oe,{choice:c})},c.value))})]}),e.jsx("p",{id:`${s}-severity-help`,className:ce,children:"Filters this panel only. It never changes what the run does."})]})]})]})}const gs=/^(?:0|[1-9][0-9]*)$/;function vs(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function js(t){return t.replace(/~/g,"~0").replace(/\//g,"~1")}function Ie(t){return t===""?[]:(t.startsWith("/")?t.slice(1):t).split("/").map(n=>{const r=vs(n);return gs.test(r)?Number(r):r})}function bs(t){return t.map(s=>`/${js(String(s))}`).join("")}function ys(t,s){const n=We(t,[s]);return n||typeof s!="number"?n:We(t,[String(s)])}function ws(t,s){if(!t.trim())return null;let n;try{if(n=Mt(t,[],{allowTrailingComma:!0}),!n)return null;for(const r of Ie(s))if(n=ys(n,r),!n)return null}catch{return null}return{start:n.offset,end:n.offset+n.length}}const Ns=["add","remove","replace","move","copy","test"];function Ss(t,s){try{let n=t;for(let r=0;r<s.length;r++){const i=ks(n,s[r],r);if(!i.ok)return{ok:!1,error:i.error};n=i.value}return{ok:!0,doc:n,applied:s.length}}catch(n){return{ok:!1,error:`quality fix failed: ${Rs(n)}`}}}function ft(t){return!t||t.length===0?!1:t.every(s=>xt(s.op)?s.op==="move"||s.op==="copy"?typeof s.from=="string":!0:!1)}function ks(t,s,n){const r=`fix #${n+1} (${String(s.op)} "${String(s.path)}")`,i=s.op;if(!xt(i))return j(`${r}: unsupported operation "${String(i)}"`);const o=Ie(s.path);switch(i){case"add":return Ee(t,o,s.value,r);case"replace":return Es(t,o,s.value,r);case"remove":{const l=Ke(t,o,r);return l.ok?S(l.value.doc):l}case"copy":{const l=qe(s,r);if(!l.ok)return l;const a=Ze(t,l.value.path);return a.ok?Ee(t,o,a.value,r):j(`${r}: ${a.error}`)}case"move":{const l=qe(s,r);if(!l.ok)return l;if(Cs(l.value.path,o))return S(t);if($s(l.value.path,o))return j(`${r}: ${M(l.value.path)} cannot be moved into its own child`);const a=Ke(t,l.value.path,r);return a.ok?Ee(a.value.doc,o,a.value.removed,r):a}case"test":{const l=Ze(t,o);return l.ok?Ae(l.value,s.value)?S(t):j(`${r}: test failed, the value at the path differs`):j(`${r}: ${l.error}`)}}}function Ee(t,s,n,r){if(s.length===0)return S(n);const i=s[s.length-1];return Oe(t,s,r,o=>{if(Array.isArray(o)){const l=i==="-"?o.length:K(i);if(l===null)return j(`${r}: "${String(i)}" is not an array index`);if(l>o.length)return j(`${r}: index ${l} is past the end of the array`);const a=D(o);return a.splice(l,0,n),S(a)}if(_(o)){const l=D(o);return l[String(i)]=n,S(l)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Es(t,s,n,r){if(s.length===0)return S(n);const i=s[s.length-1];return Oe(t,s,r,o=>{if(Array.isArray(o)){const l=K(i);if(l===null||l>=o.length)return j(`${r}: "${String(i)}" is not an existing array index`);const a=D(o);return a[l]=n,S(a)}if(_(o)){const l=String(i);if(!Z(o,l))return j(`${r}: "${l}" does not exist`);const a=D(o);return a[l]=n,S(a)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Ke(t,s,n){if(s.length===0)return j(`${n}: the whole document cannot be removed`);const r=s[s.length-1];let i;const o=Oe(t,s,n,l=>{if(Array.isArray(l)){const a=K(r);if(a===null||a>=l.length)return j(`${n}: "${String(r)}" is not an existing array index`);const u=D(l);return i=u.splice(a,1)[0],S(u)}if(_(l)){const a=String(r);if(!Z(l,a))return j(`${n}: "${a}" does not exist`);const u=D(l);return i=u[a],delete u[a],S(u)}return j(`${n}: ${M(s.slice(0,-1))} is not an object or array`)});return o.ok?S({doc:o.value,removed:i}):o}function Oe(t,s,n,r){return Te(t,s.slice(0,-1),0,n,r)}function Te(t,s,n,r,i){if(n===s.length)return i(t);const o=()=>M(s.slice(0,n+1)),l=s[n];if(Array.isArray(t)){const a=K(l);if(a===null||a>=t.length)return j(`${r}: ${o()} does not exist`);const u=Te(t[a],s,n+1,r,i);if(!u.ok)return u;const m=D(t);return m[a]=u.value,S(m)}if(_(t)){const a=String(l);if(!Z(t,a))return j(`${r}: ${o()} does not exist`);const u=Te(t[a],s,n+1,r,i);if(!u.ok)return u;const m=D(t);return m[a]=u.value,S(m)}return j(`${r}: ${M(s.slice(0,n))} is not an object or array`)}function Ze(t,s){let n=t;for(let r=0;r<s.length;r++){const i=s[r];if(Array.isArray(n)){const o=K(i);if(o===null||o>=n.length)return j(`${M(s.slice(0,r+1))} does not exist`);n=n[o];continue}if(_(n)){const o=String(i);if(!Z(n,o))return j(`${M(s.slice(0,r+1))} does not exist`);n=n[o];continue}return j(`${M(s.slice(0,r))} is not an object or array`)}return S(n)}function qe(t,s){const n=t.from;return typeof n!="string"?j(`${s}: a "from" pointer is required`):S({pointer:n,path:Ie(n)})}function D(t){return Array.isArray(t)?[...t]:{...t}}function K(t){return typeof t=="number"?Number.isInteger(t)&&t>=0?t:null:/^(?:0|[1-9][0-9]*)$/.test(t)?Number(t):null}function M(t){return t.length===0?"the document root":`"${bs(t)}"`}function xt(t){return Ns.includes(t)}function _(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Z(t,s){return Object.prototype.hasOwnProperty.call(t,s)}function Cs(t,s){return t.length===s.length&&t.every((n,r)=>String(n)===String(s[r]))}function $s(t,s){return t.length>=s.length?!1:t.every((n,r)=>String(n)===String(s[r]))}function Ae(t,s){if(t===s)return!0;if(Array.isArray(t)||Array.isArray(s))return!Array.isArray(t)||!Array.isArray(s)||t.length!==s.length?!1:t.every((n,r)=>Ae(n,s[r]));if(_(t)&&_(s)){const n=Object.keys(t);return n.length!==Object.keys(s).length?!1:n.every(r=>Z(s,r)&&Ae(t[r],s[r]))}return!1}function Rs(t){return t instanceof Error?t.message:String(t)}function S(t){return{ok:!0,value:t}}function j(t){return{ok:!1,error:t}}const le=50,ht=[],pt=["error","warning","info"],Ts={error:lt,warning:G,info:U},gt={error:"text-destructive",warning:"text-warning",info:"text-data-blue"},As=new Set(["actual","expected","unit"]);function vt(t,s){return t==="info"?`${s} info`:`${s} ${t}${s===1?"":"s"}`}function et(t,s){const n=typeof t=="string"?t:typeof t=="number"||typeof t=="boolean"?String(t):JSON.stringify(t);return s?`${n} ${s}`:n}function Ls(t){if(!t)return null;const s={};let n=!1;for(const[r,i]of Object.entries(t))As.has(r)||(s[r]=i,n=!0);return n?s:null}function tt({path:t,onRevealPath:s,muted:n}){const r=v("inline-flex max-w-full items-center gap-1 rounded-sm font-mono text-[10px]",n?"text-muted-foreground/60":"text-muted-foreground/80");return s?e.jsxs("button",{type:"button",onClick:()=>s(t),title:`Reveal ${t} in the editor`,className:v(r,"-mx-1 px-1 py-0.5 transition-colors","hover:bg-accent hover:text-foreground hover:underline","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:[e.jsx(Jt,{className:"h-2.5 w-2.5 flex-shrink-0","aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:t})]}):e.jsx("span",{className:r,children:e.jsx("span",{className:"truncate",children:t})})}function Is({finding:t,onRevealPath:s,onApplyFixes:n,isApplying:r}){const i=Ts[t.severity]??U,o=gt[t.severity]??"text-muted-foreground",l=Zt(t.certainty),a=t.evidence,u=a!==void 0&&(a.actual!==void 0||a.expected!==void 0),m=Ls(a),f=!!n&&ft(t.fixes),d=t.relatedPaths??[];return e.jsxs("div",{className:"rounded-sm border bg-card px-3 py-2.5",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(i,{className:v("mt-0.5 h-3.5 w-3.5 flex-shrink-0",o)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[t.blocking&&e.jsx("span",{className:"mr-1.5 rounded-sm bg-destructive/15 px-1 py-0.5 align-[1px] text-[10px] font-medium tracking-wide text-destructive uppercase",children:"blocking"}),e.jsx("span",{className:"text-xs leading-relaxed text-foreground",children:t.message})]})]}),e.jsxs("div",{className:"mt-1.5 pl-[1.375rem]",children:[u&&a&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[a.expected!==void 0&&e.jsxs(e.Fragment,{children:["Expected"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:et(a.expected,a.unit)})]}),a.expected!==void 0&&a.actual!==void 0&&e.jsx("span",{className:"text-muted-foreground/50",children:" · "}),a.actual!==void 0&&e.jsxs(e.Fragment,{children:[a.expected===void 0?"Found":"found"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:et(a.actual,a.unit)})]})]}),(t.suggestion||f)&&e.jsxs("div",{className:v("mt-1.5 flex items-center gap-2 rounded-sm bg-header-bg/70 px-2 py-1.5",!t.suggestion&&"justify-end"),children:[t.suggestion&&e.jsx("p",{className:"min-w-0 flex-1 text-[11px] leading-relaxed text-muted-foreground",children:t.suggestion}),f&&e.jsxs("button",{type:"button",onClick:()=>n==null?void 0:n(t),disabled:r,className:v("flex flex-shrink-0 items-center gap-1 rounded-sm border bg-card px-1.5 py-1","text-[11px] font-medium text-foreground transition-colors","hover:bg-accent focus-visible:ring-1 focus-visible:ring-ring","focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-60"),children:[r?e.jsx(X,{size:"sm",variant:"muted",className:"h-3 w-3"}):e.jsx(Vt,{className:"h-3 w-3","aria-hidden":"true"}),"Apply fix"]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-x-2.5 gap-y-1",children:[t.path&&e.jsx(tt,{path:t.path,onRevealPath:s}),d.map(c=>e.jsx(tt,{path:c,onRevealPath:s,muted:!0},c)),l&&e.jsx("span",{className:"text-[10px] text-muted-foreground/70",title:"How the analysis reached this finding",children:l}),t.code&&e.jsx("code",{className:"text-[10px] text-muted-foreground/60",children:t.code})]}),m&&e.jsxs("details",{className:"mt-1.5",children:[e.jsx("summary",{className:"cursor-pointer text-[11px] text-muted-foreground/70 hover:text-foreground",children:"More evidence"}),e.jsx("pre",{className:"mt-1 overflow-x-auto rounded-sm bg-header-bg p-1.5 text-[11px] text-muted-foreground",children:JSON.stringify(m,null,2)})]})]})]})}function Os({quality:t,id:s,className:n,onRevealPath:r,onApplyFixes:i,applyingFindingId:o}){const l=F(y=>y.qualityMinSeverity),[a,u]=N.useState(!1),[m,f]=N.useState(!1),d=(t==null?void 0:t.findings)??ht,c=l??"warning",p=N.useMemo(()=>Xt(d,c),[d,c]),b=a?d:p,R=N.useMemo(()=>Kt(b),[b]),z=N.useMemo(()=>{if(m||b.length<=le)return R;let y=le;const C=[];for(const I of R){if(y<=0)break;const P=I.findings.slice(0,y);y-=P.length,C.push({category:I.category,findings:P})}return C},[R,m,b.length]),E=N.useMemo(()=>$e(d),[d]),V=N.useMemo(()=>$e(p),[p]),H=d.length-p.length,J=N.useMemo(()=>{const y=[];let C=0;for(const I of pt){const P=E[I]-V[I];P>0&&(y.push(vt(I,P)),C+=P)}return C<H&&y.push(`${H-C} other`),y.join(", ")},[E,V,H]);return!t||d.length===0&&!t.gateError&&!t.analysisError&&!t.truncated?null:e.jsxs("div",{id:s,className:v("space-y-1.5",n),children:[t.gateError&&e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border border-destructive/40 bg-destructive/10 px-3 py-2",children:[e.jsx(Le,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-destructive"}),e.jsx("p",{className:"text-xs leading-relaxed text-destructive",children:t.gateError})]}),t.analysisError&&e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-muted/60 px-3 py-2",children:[e.jsx(U,{className:"mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-muted-foreground"}),e.jsxs("p",{className:"text-xs leading-relaxed text-muted-foreground",children:[t.analysisError,d.length>0&&" Showing the last completed analysis."]})]}),e.jsxs("div",{className:"space-y-1.5",children:[t.truncated&&e.jsx("p",{className:"px-0.5 text-[11px] text-muted-foreground/80",children:"The analysis stopped early — not every finding is listed."}),H>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-sm border border-dashed px-3 py-1.5",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-[11px] text-muted-foreground",children:a?`${J} below the ${c} filter, now shown`:`${J} hidden by the ${c}-and-above filter`}),e.jsx("button",{type:"button",onClick:()=>u(!a),className:v("flex-shrink-0 rounded-sm px-1.5 py-0.5 text-[11px] font-medium","text-foreground transition-colors hover:bg-accent","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:a?"Hide again":"Show all"})]}),z.map(y=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"px-0.5 text-[10px] font-medium tracking-wide text-muted-foreground/70 uppercase",children:y.category}),y.findings.map(C=>e.jsx(Is,{finding:C,onRevealPath:r,onApplyFixes:i,isApplying:o===C.id},C.id))]},y.category)),b.length>le&&e.jsx("button",{type:"button",onClick:()=>f(!m),className:v("w-full rounded-sm border border-dashed px-3 py-1.5 text-[11px]","font-medium text-muted-foreground transition-colors","hover:bg-accent hover:text-foreground","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:m?`Show first ${le}`:`Show all ${b.length}`})]})]})}function jt(t){return t?t.findings.length>0||!!t.gateError||!!t.analysisError||!!t.truncated:!1}function Ms({quality:t,open:s=!1,onToggle:n,controlsId:r,className:i}){const o=N.useMemo(()=>$e((t==null?void 0:t.findings)??ht),[t==null?void 0:t.findings]);if(!t)return null;const l=!!(t.blocked||t.gateError),a=pt.filter(p=>o[p]>0),u=jt(t)&&!!n,m=l||o.error>0?"text-destructive":o.warning>0?"text-warning":t.analysisError?"text-muted-foreground":a.length===0?"text-success":"text-data-blue",f=l?Le:o.error>0?lt:o.warning>0?G:t.analysisError?U:a.length===0?Ut:U,d=e.jsxs(e.Fragment,{children:[u&&e.jsx(it,{className:v("h-3.5 w-3.5 flex-shrink-0 text-muted-foreground transition-transform",s&&"rotate-90"),"aria-hidden":"true"}),e.jsx(f,{className:v("h-3.5 w-3.5 flex-shrink-0",m)}),e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Quality"}),a.length===0?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:t.analysisError?"Not available":"No findings"}):a.map((p,b)=>e.jsxs(N.Fragment,{children:[b>0&&e.jsx("span",{"aria-hidden":"true",className:"text-muted-foreground/40",children:"·"}),e.jsx("span",{className:v("text-xs font-medium",gt[p]),children:vt(p,o[p])})]},p)),l&&e.jsx("span",{className:"flex-shrink-0 rounded-sm bg-destructive/15 px-1.5 py-0.5 text-[10px] font-medium tracking-wide text-destructive uppercase",children:"blocked"}),t.profileId&&e.jsx("span",{className:"ml-auto truncate pl-2 font-mono text-[10px] text-muted-foreground",title:`Quality profile: ${t.profileId}`,children:t.profileId})]}),c="flex min-w-0 items-center gap-2 rounded-sm px-1.5 py-0.5";return u?e.jsx("button",{type:"button",onClick:n,"aria-expanded":s,"aria-controls":s?r:void 0,className:v(c,"text-left transition-colors hover:bg-accent","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none",i),children:d}):e.jsx("div",{className:v(c,i),children:d})}const st={pptx:["default","dark","minimal"],docx:["minimal","corporate","modern"]};function Ps({className:t}){var l;const s=L(a=>a.activeTab),n=L(a=>a.documentTypes),r=L(a=>a.documents),i=ct(a=>a.customThemes),o=x.useMemo(()=>{var m,f,d;if(!s||n[s]==="application/json+theme")return null;const a=r.find(c=>c.name===s);if(!(a!=null&&a.text))return null;let u;try{u=(f=(m=JSON.parse(a.text))==null?void 0:m.props)==null?void 0:f.theme}catch{return null}if(typeof u!="string"||!u||(d=st[O])!=null&&d.includes(u))return null;for(const c of Object.values(i))if(c.valid&&c.name===u)return null;return u},[s,n,r,i]);return o?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(G,{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:o})," ","is not available."]})," ",e.jsxs("span",{className:"text-warning/80",children:["Add it as a custom theme or use a built-in theme (",(l=st[O])==null?void 0:l.join(", "),"). The renderer will fall back to a default."]})]})]}):null}async function Fs(t,s,n,r,i,o){const l=typeof n=="string"&&n.length>0;let a;if(l){let f;try{f=JSON.parse(n)}catch(c){throw new Error(`Invalid JSON document: ${c.message}`)}const d={jsonDefinition:f,customThemes:r??{},options:{sourceName:o??t,...i?{renderer:i}:{}}};a=await fetch(Ce.preview.libreofficeFromJson,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(d)})}else{const f=new FormData,d=O==="pptx"?".pptx":".docx";f.append("file",s,`${t}${d}`),a=await fetch(Ce.preview.libreoffice,{method:"POST",body:f})}if(!a.ok){let f=`LibreOffice preview failed (${a.status})`;try{const d=await a.json();d&&typeof d=="object"&&typeof d.error=="string"&&(f=d.error)}catch{}throw new Error(f)}const u=await a.blob();if(!u.size)throw new Error("LibreOffice preview returned an empty PDF");const m=URL.createObjectURL(u);return{iframeSrc:m,cleanup:()=>URL.revokeObjectURL(m)}}async function Ds(t,s,n,r,i,o){try{if(!s||s.size===0)throw new Error("Invalid or empty document blob");const l=await Fs(t,s,n,r,i,o);return{status:"success",name:t,payload:l}}catch(l){const a=l instanceof Error?l.message:String(l);return{status:"error",name:t,payload:new Error(a)}}}function zs(){const t=L(i=>i.activeTab),s=L(i=>i.documents),n=L(i=>i.documentTypes),r=L(i=>i.saveDocument);return x.useCallback((i,o)=>{var c;const l=i.fixes;if(!l||!ft(l))return{ok:!1,error:"This finding carries no applicable fix."};if(!t)return{ok:!1,error:"No active file"};if(o&&o!==t)return{ok:!1,error:`This finding belongs to ${o}, which is no longer the active file.`};if(n[t]==="application/json+theme")return{ok:!1,error:"Quality fixes apply to a document, not to a theme."};const a=s.find(p=>p.name===t);if(!a)return{ok:!1,error:"Active document not found"};const u=at.getState().getEditor(t);(c=u==null?void 0:u.flushPendingSave)==null||c.call(u);const m=u?u.toStorageValue(u.editor.getValue()):a.text;let f;try{f=JSON.parse(m)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const d=Ss(f,l);return d.ok?(r(t,JSON.stringify(d.doc,null,2)),{ok:!0}):{ok:!1,error:d.error}},[t,n,s,r])}const Me=x.forwardRef(({className:t,value:s,...n},r)=>e.jsx(dt,{ref:r,className:v("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...n,children:e.jsx(rs,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(s||0)}%)`}})}));Me.displayName=dt.displayName;function bt(t){if(t===0)return"0 B";const s=1024,n=["B","KB","MB","GB"],r=Math.floor(Math.log(t)/Math.log(s));return parseFloat((t/Math.pow(s,r)).toFixed(2))+" "+n[r]}function Bs(){const[t,s]=x.useState(null),[n,r]=x.useState(!0),[i,o]=x.useState(null);if(x.useEffect(()=>{const u=new AbortController,m=async()=>{try{const c=await fetch(Ce.cacheStats,{signal:u.signal});if(!c.ok)throw new Error("Failed to fetch cache stats");const p=await c.json();u.signal.aborted||(s(p.data),o(null))}catch(c){u.signal.aborted||(c instanceof Error&&c.name!=="AbortError"?o(c.message):(!(c instanceof Error)||c.name!=="AbortError")&&o("Failed to load cache stats"))}finally{u.signal.aborted||r(!1)}};m();const f=setInterval(m,5e3),d=()=>m();return window.addEventListener("cache:cleared",d),()=>{u.abort(),clearInterval(f),window.removeEventListener("cache:cleared",d)}},[]),n)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(i)return e.jsxs("div",{className:"text-destructive p-4",children:["Error loading cache metrics: ",i]});if(!t)return null;const{document:l}=t,a=l.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:[a.toFixed(1),"%"]}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",l.hits," hits / ",l.misses," misses)"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Size"})," ",e.jsx("span",{className:"font-semibold",children:bt(l.size)}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",l.itemCount," items)"]})]}),e.jsx(Pt,{variant:l.enabled?"default":"secondary",children:l.enabled?"Enabled":"Disabled"})]}),e.jsx(Me,{value:a,className:"h-2","aria-label":"Cache hit rate"}),t.rasterizer&&e.jsx(_s,{data:t.rasterizer})]})}function _s({data:t}){const s=t.diskHits+t.diskMisses;if(s+t.dedupedRequests+t.rendered+t.entries===0)return null;const r=t.hitRate*100,i=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:s>0?`${r.toFixed(0)}% hit`:"no lookups"}),e.jsxs("span",{children:["(",t.diskHits," hits / ",t.diskMisses," misses)"]}),e.jsxs("span",{children:[t.entries," PNGs, ",bt(t.bytes)]})]})]}),e.jsx(Me,{value:r,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:[i," duplicate visual",i===1?"":"s"," deduped",t.prepass?` (${t.prepass.collected} collected → ${t.prepass.unique} unique)`:""]})]})]})]})}function qs(){var ae,Ve;const{name:t,text:s,blob:n,renderer:r,isGenerating:i,generationProgress:o,generationStartedAt:l,cancelGeneration:a,globalError:u,cacheStatus:m,cacheHitRate:f,warnings:d,quality:c,isRendering:p,isPreviewStale:b,editSequence:R,lastBuiltSequence:z,setOutput:E}=ts(h=>h),V=L(h=>{var g;return h.activeTab&&h.documentTypes[h.activeTab]!=="application/json+theme"?(g=h.documents.find(k=>k.name===h.activeTab))==null?void 0:g.text:void 0}),H=L(h=>h.activeTab&&h.documentTypes[h.activeTab]!=="application/json+theme"?h.activeTab:void 0),J=x.useContext(ss),{toast:y}=Ot(),C=zs(),{analyze:I}=qt(),[P,Pe]=x.useState(null),[W,Fe]=x.useState(!1),[q,ee]=x.useState(!1),De=N.useId(),ze=L(h=>h.activeTab),B=x.useMemo(()=>c&&c.documentName===ze?c:null,[c,ze]),de=W||q,ue=x.useCallback(()=>{Fe(!1),ee(!1)},[]);x.useEffect(()=>{if(!de)return;const h=g=>{g.key==="Escape"&&ue()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[de,ue]);const Be=B==null?void 0:B.gateError;x.useEffect(()=>{Be&&ee(!0)},[Be]);const _e=jt(B);x.useEffect(()=>{_e||ee(!1)},[_e]);const yt=x.useMemo(()=>es(d).others,[d]),wt=x.useCallback(h=>{if(!h)return;const g=at.getState().getActiveEditor();if(!g)return;const{editor:k,monaco:T}=g,A=k.getModel();if(!A)return;const $=ws(A.getValue(),h);if(!$)return;const w=A.getPositionAt($.start),Q=A.getPositionAt($.end),Je=new T.Range(w.lineNumber,w.column,Q.lineNumber,Q.column);k.revealRangeNearTopIfOutsideViewport(Je,T.editor.ScrollType.Smooth),k.setPosition(w),k.setSelection(Je),k.focus()},[]),te=x.useRef(new Set);x.useEffect(()=>{te.current=new Set},[c==null?void 0:c.seq]);const Nt=x.useCallback(h=>{var g;if(!te.current.has(h.id)){te.current.add(h.id),Pe(h.id);try{const k=C(h,c==null?void 0:c.documentName);if(!k.ok){te.current.delete(h.id),y({variant:"destructive",title:"Could not apply fix",description:k.error});return}const{activeTab:T,documents:A}=J.getState(),$=(g=A.find(w=>w.name===T))==null?void 0:g.text;$&&I(T,$,{immediate:!0})}finally{Pe(null)}}},[I,C,J,c==null?void 0:c.documentName,y]),He=ct(h=>h.customThemes),Qe=x.useMemo(()=>{const h={};for(const g of Object.values(He))g.valid&&g.name&&g.parsed&&(h[g.name]=g.parsed);return h},[He]),[St,kt]=x.useState(void 0),[Et,Ct]=x.useState(void 0),[$t,me]=x.useState(!1),Rt=N.useRef(null),se=x.useRef(null),fe=x.useRef(!1),Ge=ns(),ne=x.useCallback(()=>{se.current&&(se.current(),se.current=null)},[]),re=x.useCallback(async(h,g,k,T,A)=>{E({isRendering:!0,isPreviewStale:!1,globalError:void 0});try{const{status:$,payload:w}=await Ds(h,g,k,T,A,Ge(h));if($!=="success")throw w instanceof Error?w:new Error(String(w));ne(),kt(w.iframeSrc||void 0),Ct(w.iframeSrcDoc||void 0),se.current=w.cleanup||null}catch($){const w=$ instanceof Error?$.message:String($);let Q=w;w.includes("Failed to fetch")?Q="Network error: Unable to load required resources. Check if the server is running properly.":w.includes("timeout")&&(Q="Render timeout: The rendering process took too long."),E({globalError:Q})}finally{E({isRendering:!1})}},[E,ne,Ge]),Tt=x.useRef({name:t,blob:n,text:s,doRender:re});x.useEffect(()=>{Tt.current={name:t,blob:n,text:s,doRender:re}});const xe=x.useCallback(async()=>{fe.current=!0,window.dispatchEvent(new CustomEvent("preview:flushAndBuild"))},[]);x.useEffect(()=>{if(!(!n||!t)){if(fe.current){fe.current=!1,re(t,n,s,Qe,r);return}E({isPreviewStale:!0})}},[n,t,s,Qe,r,re,E]),x.useEffect(()=>()=>{ne()},[ne]),x.useEffect(()=>{const h=()=>xe(),g=()=>me(!0);return window.addEventListener("preview:manualRender",h),window.addEventListener("preview:showCacheMetrics",g),()=>{window.removeEventListener("preview:manualRender",h),window.removeEventListener("preview:showCacheMetrics",g)}},[xe]);const Ue=((Ve=(ae=F)==null?void 0:ae.getState)==null?void 0:Ve.call(ae).useGlobalPreviewHeader)===!1;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-full flex-col",children:[Ue&&e.jsx(Ft,{name:(t==null?void 0:t.trim())||"Preview",blob:n,onManualRender:xe,isGenerating:i,isRendering:p,onShowCacheMetrics:()=>me(!0),documentText:s,editorDocumentText:V,editorDocumentName:H,warnings:d}),!Ue&&e.jsx(Dt,{}),(()=>{const h=(R??0)>(z??0),g=(b||h)&&!i&&!p,k=g?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full bg-warning"}),e.jsx("span",{className:"truncate text-xs text-warning",children:"Outdated — click Run"})]}):m==="HIT"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full bg-success"}),e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:"Cached"})]}):m==="MISS"?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"h-1.5 w-1.5 flex-shrink-0 rounded-full bg-accent2"}),e.jsxs("span",{className:"truncate text-xs text-muted-foreground",children:["Fresh ",nt.toLowerCase()]})]}):null,T=!!k&&(m&&m!=="UNKNOWN"||g);return e.jsxs("div",{className:"flex items-center gap-2 overflow-hidden border-b bg-header-bg px-3 py-1.5",children:[T&&e.jsx("div",{className:"flex min-w-0 flex-shrink items-center gap-2",children:k}),T&&B&&e.jsx("div",{"aria-hidden":"true",className:"h-3 w-px flex-shrink-0 bg-border"}),e.jsx(Ms,{quality:B,open:q,onToggle:()=>ee(A=>!A),controlsId:De,className:"min-w-0 flex-1"}),!g&&f&&f!=="0.0%"&&e.jsxs("span",{className:"hidden flex-shrink-0 text-xs text-muted-foreground lg:inline",children:[f," hit rate"]}),e.jsxs("button",{type:"button",onClick:()=>Fe(!W),"aria-expanded":W,className:v("flex flex-shrink-0 items-center gap-1.5 rounded-sm px-1.5 py-0.5","text-[11px] font-medium text-muted-foreground","transition-colors hover:bg-accent hover:text-foreground","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"),children:[e.jsx(ot,{className:"h-3 w-3","aria-hidden":"true"}),e.jsx("span",{className:"hidden sm:inline",children:"Quality settings"})]})]})})(),e.jsx(ms,{warnings:yt,className:"mx-3 my-2"}),e.jsx(Ps,{className:"mx-3 my-2"}),e.jsxs("div",{className:"relative min-h-0 flex-1",children:[u&&!i?e.jsx("div",{className:"flex h-full 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:u})]})}):e.jsx(us,{ref:Rt,isLoading:!!p,iframeSrc:St,iframeSrcDoc:Et,isGenerating:!!i,generationProgress:o,generationDocumentText:V??s,generationStartedAt:l,onCancelGeneration:a}),de&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 z-30",onClick:ue,"aria-hidden":"true"}),e.jsxs("div",{className:v("absolute inset-x-3 top-2 bottom-2 z-40 overflow-y-auto","rounded-sm border bg-card p-4 shadow-lg"),children:[W&&e.jsx(ps,{}),W&&q&&e.jsx("div",{className:"my-4 border-t"}),q&&e.jsx(Os,{id:De,quality:B,onRevealPath:wt,onApplyFixes:Nt,applyingFindingId:P})]})]})]})]}),e.jsx(zt,{open:$t,onOpenChange:me,children:e.jsxs(Bt,{className:"max-w-2xl",children:[e.jsx(_t,{children:e.jsx(Ht,{children:"Cache Performance"})}),e.jsx(Bs,{})]})})]})}export{qs as Preview};
2
+ //# sourceMappingURL=preview-ZqhmQZJG.js.map