@json-to-office/jto 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/client/assets/{HomePage-ChJyDqzj.js → HomePage-CeUQIXch.js} +4 -4
- package/dist/client/assets/{HomePage-ChJyDqzj.js.map → HomePage-CeUQIXch.js.map} +1 -1
- package/dist/client/assets/{JsonEditorPage-COHI5Wez.js → JsonEditorPage-4LrF2fB9.js} +3 -3
- package/dist/client/assets/{JsonEditorPage-COHI5Wez.js.map → JsonEditorPage-4LrF2fB9.js.map} +1 -1
- package/dist/client/assets/{MonacoPluginProvider-prawCY6T.js → MonacoPluginProvider-Bx_V_FaE.js} +3 -3
- package/dist/client/assets/{MonacoPluginProvider-prawCY6T.js.map → MonacoPluginProvider-Bx_V_FaE.js.map} +1 -1
- package/dist/client/assets/{editor-BO-KsLDk.js → editor-D-REaAU9.js} +2 -2
- package/dist/client/assets/{editor-BO-KsLDk.js.map → editor-D-REaAU9.js.map} +1 -1
- package/dist/client/assets/{editor-monaco-json-CJh63Fsz.js → editor-monaco-json-BgziSLMV.js} +2 -2
- package/dist/client/assets/{editor-monaco-json-CJh63Fsz.js.map → editor-monaco-json-BgziSLMV.js.map} +1 -1
- package/dist/client/assets/{editor-refs-store-CVLA_D5G.js → editor-refs-store-vzLK2-Zo.js} +2 -2
- package/dist/client/assets/{editor-refs-store-CVLA_D5G.js.map → editor-refs-store-vzLK2-Zo.js.map} +1 -1
- package/dist/client/assets/{index-otgy8_us.js → index-B7bDnXoC.js} +4 -4
- package/dist/client/assets/index-B7bDnXoC.js.map +1 -0
- package/dist/client/assets/{preview-3fuCtJiz.js → preview-BGqIip90.js} +2 -2
- package/dist/client/assets/{preview-3fuCtJiz.js.map → preview-BGqIip90.js.map} +1 -1
- package/dist/client/assets/{useQualityAnalysis-Ci_jNmHv.js → useQualityAnalysis-CowAaoA9.js} +2 -2
- package/dist/client/assets/{useQualityAnalysis-Ci_jNmHv.js.map → useQualityAnalysis-CowAaoA9.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Bold.otf +0 -0
- package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Light.otf +0 -0
- package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Medium.otf +0 -0
- package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Regular.otf +0 -0
- package/dist/client/templates/media/vermilion-annual-report/fonts/ClashDisplay-Semibold.otf +0 -0
- package/dist/client/templates/media/vermilion-annual-report/fonts/FFL.txt +132 -0
- package/dist/client/templates/vermilion-annual-report.docx.json +10541 -0
- package/package.json +5 -5
- package/dist/client/assets/index-otgy8_us.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 tt,g as Rt,F as O,p as Tt,Q as At,A as Ce,u as Lt}from"./index-otgy8_us.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 It,g as Ve,B as Ot,P as Mt,h as Pt,D as Ft,i as Dt,j as zt,k as Bt}from"./HomePage-ChJyDqzj.js";import{B as st,u as nt}from"./editor-refs-store-CVLA_D5G.js";import{e as rt,Q as G,x as U,a4 as _t,a5 as at,a6 as Le,W as Ht,a7 as it,a8 as Qt,a9 as Gt,aa as Ut}from"./ui-vendor-Bq4-oNFL.js";import Vt from"./monaco-editor-DJsdM0WK.js";import{E as Je,p as Jt,c as $e,d as Wt,g as Yt,e as Xt,u as Kt,a as Zt}from"./useQualityAnalysis-Ci_jNmHv.js";import{d as F,u as I,a as ot,b as qt,h as es}from"./MonacoPluginProvider-prawCY6T.js";import{ad as lt,ae as ts}from"./radix-ui-DFNP5I4e.js";import"./query-vendor--rhYD8mC.js";import"./state-vendor-Cq67_JbF.js";function ct(t){const[s]=x.useState(()=>Date.now()),n=t??s,[r,a]=x.useState(()=>Date.now());return x.useEffect(()=>{const i=setInterval(()=>a(Date.now()),100);return()=>clearInterval(i)},[]),Math.max(0,(r-n)/1e3)}function ss(t){var s,n;if(!t)return null;try{const r=JSON.parse(t);if(!r||typeof r!="object")return null;const a=new Map,i=[r];for(;i.length>0;){const d=i.pop();if(!d||typeof d!="object")continue;const{name:f,children:m}=d;typeof f=="string"&&a.set(f,(a.get(f)??0)+1),Array.isArray(m)&&i.push(...m)}const o=[["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(([d,f,m])=>{const c=a.get(d)??0;return{label:c===1?f:m,count:c}}).filter(d=>d.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:o,visualCount:(a.get("visual")??0)+(a.get("chart")??0),imageCount:a.get("image")??0}}catch{return null}}function ns(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 rs=()=>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 as({className:t,currentStage:s="parsing",message:n,documentText:r,startedAt:a,onCancel:i}){const l=["parsing","building","rendering","finalizing"],o={parsing:"Validating JSON",building:"Building structure",rendering:"Rendering content",finalizing:"Finalizing document"},u=l.indexOf(s),d=ct(a),f=x.useMemo(()=>ss(r),[r]),m=x.useMemo(()=>ns(f),[f]),c=d>3,p=Math.floor(Math.max(0,d-3)/5)%m.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||`${o[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:[d.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:o[b]}),E?e.jsx(rs,{}):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:m[p]}),i&&e.jsx(st,{variant:"outline",size:"sm",onClick:i,className:"shrink-0",children:"Cancel"})]})]})}function is({mode:t,message:s,startedAt:n,onCancel:r,className:a}){const i=ct(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",a),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:[i.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(st,{variant:"outline",size:"sm",onClick:r,children:"Cancel"})]})}function os({renderingLibrary:t,className:s}){const n=i=>{switch(i){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:a}=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:a})]}),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 dt=N.forwardRef(({isLoading:t,iframeSrc:s,iframeSrcDoc:n,isGenerating:r,generationProgress:a,generationDocumentText:i,generationStartedAt:l,onCancelGeneration:o},u)=>{const[d,f]=x.useState(!1);x.useEffect(()=>{f(!1)},[s,n]);const m=()=>{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(as,{currentStage:a==null?void 0:a.stage,message:a==null?void 0:a.message,documentText:i,startedAt:l,onCancel:o})}):t&&!b?e.jsx("div",{className:"grow",children:e.jsx(os,{renderingLibrary:"LibreOffice"})}):b?e.jsxs("div",{className:"h-full w-full relative bg-white",children:[!d&&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(is,{mode:r?"generating":"rendering",message:r?a==null?void 0:a.message:void 0,startedAt:r?l:void 0,onCancel:r?o:void 0})}),e.jsx("iframe",{ref:u,className:"w-full h-full border-0",style:{backgroundColor:"white",opacity:d?1:0,transition:"opacity 0.2s ease-in-out"},src:s,srcDoc:n,onLoad:m,onError:c,sandbox:p,title:"Document preview","aria-label":`Preview of rendered ${tt.toLowerCase()}`},n?"srcdoc":"src")]}):null});dt.displayName="PreviewFrame";const ls=N.memo(dt);function cs({warnings:t,className:s}){const[n,r]=N.useState(!1),a=N.useMemo(()=>(t??[]).filter(i=>i.component!=="quality"),[t]);return a.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(rt,{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:[a.length," warning",a.length!==1?"s":""]})]}),n&&e.jsx("div",{className:"mt-1.5 space-y-1.5",children:a.map((i,l)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-card px-3 py-2",children:[i.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:i.component}),i.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:i.message}),i.context&&Object.keys(i.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(i.context,null,2)})]})]})]},l))})]})}function ds({className:t}){const{resolvedTheme:s}=Rt(),n=F(m=>m.qualityPolicies),r=F(m=>m.setSettings),a=n==null?void 0:n[O],[i,l]=x.useState(a??Je),o=x.useMemo(()=>Jt(i),[i]),u=x.useMemo(()=>Tt().map(m=>m.id),[]),d=x.useCallback(m=>{l(m),r({qualityPolicies:{...n,[O]:m}})},[n,r]),f=x.useCallback(()=>d(Je),[d]);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(_t,{className:"h-3 w-3","aria-hidden":"true"}),"Reset"]})]}),e.jsx("div",{className:"overflow-hidden rounded-sm border",children:e.jsx(Vt,{height:"180px",language:"json",path:At,theme:s==="dark"?"vs-dark":"vs",defaultValue:i,onChange:m=>d(m??""),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}})}),o.ok?e.jsx("p",{className:"text-[11px] leading-snug text-muted-foreground",children:o.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:[o.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(m=>e.jsx("li",{className:"font-mono text-[10px]",children:m},m))})]})]})}const Re="__default__",us={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"}]},ms={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",We={value:Re,label:"Default",description:`The format's own profile (${ms[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 fs({className:t}){const s=x.useId(),n=F(c=>c.qualityProfileIds),r=n==null?void 0:n[O],a=F(c=>c.qualityGate)??"none",i=F(c=>c.qualityMinSeverity)??"warning",l=F(c=>c.setSettings),o=us[O],d=o.find(c=>c.value===r)??We,f=be.find(c=>c.value===a)??be[0],m=ye.find(c=>c.value===i)??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(at,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Profile"]}),e.jsxs(pe,{value:d.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:d.label})})}),e.jsxs(je,{className:Ne,children:[e.jsx(ie,{value:Re,className:"text-xs",children:e.jsx(oe,{choice:We})}),o.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:d.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(ds,{})]}),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(Ht,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Show"]}),e.jsxs(pe,{value:m.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:m.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 xs=/^(?:0|[1-9][0-9]*)$/;function hs(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function ps(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=hs(n);return xs.test(r)?Number(r):r})}function gs(t){return t.map(s=>`/${ps(String(s))}`).join("")}function vs(t,s){const n=Ve(t,[s]);return n||typeof s!="number"?n:Ve(t,[String(s)])}function js(t,s){if(!t.trim())return null;let n;try{if(n=It(t,[],{allowTrailingComma:!0}),!n)return null;for(const r of Ie(s))if(n=vs(n,r),!n)return null}catch{return null}return{start:n.offset,end:n.offset+n.length}}const bs=["add","remove","replace","move","copy","test"];function ys(t,s){try{let n=t;for(let r=0;r<s.length;r++){const a=ws(n,s[r],r);if(!a.ok)return{ok:!1,error:a.error};n=a.value}return{ok:!0,doc:n,applied:s.length}}catch(n){return{ok:!1,error:`quality fix failed: ${Es(n)}`}}}function ut(t){return!t||t.length===0?!1:t.every(s=>mt(s.op)?s.op==="move"||s.op==="copy"?typeof s.from=="string":!0:!1)}function ws(t,s,n){const r=`fix #${n+1} (${String(s.op)} "${String(s.path)}")`,a=s.op;if(!mt(a))return j(`${r}: unsupported operation "${String(a)}"`);const i=Ie(s.path);switch(a){case"add":return Ee(t,i,s.value,r);case"replace":return Ns(t,i,s.value,r);case"remove":{const l=Ye(t,i,r);return l.ok?S(l.value.doc):l}case"copy":{const l=Ke(s,r);if(!l.ok)return l;const o=Xe(t,l.value.path);return o.ok?Ee(t,i,o.value,r):j(`${r}: ${o.error}`)}case"move":{const l=Ke(s,r);if(!l.ok)return l;if(Ss(l.value.path,i))return S(t);if(ks(l.value.path,i))return j(`${r}: ${M(l.value.path)} cannot be moved into its own child`);const o=Ye(t,l.value.path,r);return o.ok?Ee(o.value.doc,i,o.value.removed,r):o}case"test":{const l=Xe(t,i);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 a=s[s.length-1];return Oe(t,s,r,i=>{if(Array.isArray(i)){const l=a==="-"?i.length:K(a);if(l===null)return j(`${r}: "${String(a)}" is not an array index`);if(l>i.length)return j(`${r}: index ${l} is past the end of the array`);const o=D(i);return o.splice(l,0,n),S(o)}if(H(i)){const l=D(i);return l[String(a)]=n,S(l)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Ns(t,s,n,r){if(s.length===0)return S(n);const a=s[s.length-1];return Oe(t,s,r,i=>{if(Array.isArray(i)){const l=K(a);if(l===null||l>=i.length)return j(`${r}: "${String(a)}" is not an existing array index`);const o=D(i);return o[l]=n,S(o)}if(H(i)){const l=String(a);if(!Z(i,l))return j(`${r}: "${l}" does not exist`);const o=D(i);return o[l]=n,S(o)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Ye(t,s,n){if(s.length===0)return j(`${n}: the whole document cannot be removed`);const r=s[s.length-1];let a;const i=Oe(t,s,n,l=>{if(Array.isArray(l)){const o=K(r);if(o===null||o>=l.length)return j(`${n}: "${String(r)}" is not an existing array index`);const u=D(l);return a=u.splice(o,1)[0],S(u)}if(H(l)){const o=String(r);if(!Z(l,o))return j(`${n}: "${o}" does not exist`);const u=D(l);return a=u[o],delete u[o],S(u)}return j(`${n}: ${M(s.slice(0,-1))} is not an object or array`)});return i.ok?S({doc:i.value,removed:a}):i}function Oe(t,s,n,r){return Te(t,s.slice(0,-1),0,n,r)}function Te(t,s,n,r,a){if(n===s.length)return a(t);const i=()=>M(s.slice(0,n+1)),l=s[n];if(Array.isArray(t)){const o=K(l);if(o===null||o>=t.length)return j(`${r}: ${i()} does not exist`);const u=Te(t[o],s,n+1,r,a);if(!u.ok)return u;const d=D(t);return d[o]=u.value,S(d)}if(H(t)){const o=String(l);if(!Z(t,o))return j(`${r}: ${i()} does not exist`);const u=Te(t[o],s,n+1,r,a);if(!u.ok)return u;const d=D(t);return d[o]=u.value,S(d)}return j(`${r}: ${M(s.slice(0,n))} is not an object or array`)}function Xe(t,s){let n=t;for(let r=0;r<s.length;r++){const a=s[r];if(Array.isArray(n)){const i=K(a);if(i===null||i>=n.length)return j(`${M(s.slice(0,r+1))} does not exist`);n=n[i];continue}if(H(n)){const i=String(a);if(!Z(n,i))return j(`${M(s.slice(0,r+1))} does not exist`);n=n[i];continue}return j(`${M(s.slice(0,r))} is not an object or array`)}return S(n)}function Ke(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":`"${gs(t)}"`}function mt(t){return bs.includes(t)}function H(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Z(t,s){return Object.prototype.hasOwnProperty.call(t,s)}function Ss(t,s){return t.length===s.length&&t.every((n,r)=>String(n)===String(s[r]))}function ks(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(H(t)&&H(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 Es(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,ft=[],xt=["error","warning","info"],Cs={error:it,warning:G,info:U},ht={error:"text-destructive",warning:"text-warning",info:"text-data-blue"},$s=new Set(["actual","expected","unit"]);function pt(t,s){return t==="info"?`${s} info`:`${s} ${t}${s===1?"":"s"}`}function Ze(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 Rs(t){if(!t)return null;const s={};let n=!1;for(const[r,a]of Object.entries(t))$s.has(r)||(s[r]=a,n=!0);return n?s:null}function qe({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(Ut,{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 Ts({finding:t,onRevealPath:s,onApplyFixes:n,isApplying:r}){const a=Cs[t.severity]??U,i=ht[t.severity]??"text-muted-foreground",l=Xt(t.certainty),o=t.evidence,u=o!==void 0&&(o.actual!==void 0||o.expected!==void 0),d=Rs(o),f=!!n&&ut(t.fixes),m=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(a,{className:v("mt-0.5 h-3.5 w-3.5 flex-shrink-0",i)}),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&&o&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[o.expected!==void 0&&e.jsxs(e.Fragment,{children:["Expected"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:Ze(o.expected,o.unit)})]}),o.expected!==void 0&&o.actual!==void 0&&e.jsx("span",{className:"text-muted-foreground/50",children:" · "}),o.actual!==void 0&&e.jsxs(e.Fragment,{children:[o.expected===void 0?"Found":"found"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:Ze(o.actual,o.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(Gt,{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(qe,{path:t.path,onRevealPath:s}),m.map(c=>e.jsx(qe,{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})]}),d&&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(d,null,2)})]})]})]})}function As({quality:t,id:s,className:n,onRevealPath:r,onApplyFixes:a,applyingFindingId:i}){const l=F(y=>y.qualityMinSeverity),[o,u]=N.useState(!1),[d,f]=N.useState(!1),m=(t==null?void 0:t.findings)??ft,c=l??"warning",p=N.useMemo(()=>Wt(m,c),[m,c]),b=o?m:p,R=N.useMemo(()=>Yt(b),[b]),z=N.useMemo(()=>{if(d||b.length<=le)return R;let y=le;const C=[];for(const P of R){if(y<=0)break;const L=P.findings.slice(0,y);y-=L.length,C.push({category:P.category,findings:L})}return C},[R,d,b.length]),E=N.useMemo(()=>$e(m),[m]),V=N.useMemo(()=>$e(p),[p]),B=m.length-p.length,J=N.useMemo(()=>{const y=[];let C=0;for(const P of xt){const L=E[P]-V[P];L>0&&(y.push(pt(P,L)),C+=L)}return C<B&&y.push(`${B-C} other`),y.join(", ")},[E,V,B]);return!t||m.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,m.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."}),B>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:o?`${J} below the ${c} filter, now shown`:`${J} hidden by the ${c}-and-above filter`}),e.jsx("button",{type:"button",onClick:()=>u(!o),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:o?"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(Ts,{finding:C,onRevealPath:r,onApplyFixes:a,isApplying:i===C.id},C.id))]},y.category)),b.length>le&&e.jsx("button",{type:"button",onClick:()=>f(!d),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:d?`Show first ${le}`:`Show all ${b.length}`})]})]})}function gt(t){return t?t.findings.length>0||!!t.gateError||!!t.analysisError||!!t.truncated:!1}function Ls({quality:t,open:s=!1,onToggle:n,controlsId:r,className:a}){const i=N.useMemo(()=>$e((t==null?void 0:t.findings)??ft),[t==null?void 0:t.findings]);if(!t)return null;const l=!!(t.blocked||t.gateError),o=xt.filter(p=>i[p]>0),u=gt(t)&&!!n,d=l||i.error>0?"text-destructive":i.warning>0?"text-warning":t.analysisError?"text-muted-foreground":o.length===0?"text-success":"text-data-blue",f=l?Le:i.error>0?it:i.warning>0?G:t.analysisError?U:o.length===0?Qt:U,m=e.jsxs(e.Fragment,{children:[u&&e.jsx(rt,{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",d)}),e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Quality"}),o.length===0?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:t.analysisError?"Not available":"No findings"}):o.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",ht[p]),children:pt(p,i[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",a),children:m}):e.jsx("div",{className:v(c,a),children:m})}const et={pptx:["default","dark","minimal"],docx:["minimal","corporate","modern"]};function Is({className:t}){var l;const s=I(o=>o.activeTab),n=I(o=>o.documentTypes),r=I(o=>o.documents),a=ot(o=>o.customThemes),i=x.useMemo(()=>{var d,f,m;if(!s||n[s]==="application/json+theme")return null;const o=r.find(c=>c.name===s);if(!(o!=null&&o.text))return null;let u;try{u=(f=(d=JSON.parse(o.text))==null?void 0:d.props)==null?void 0:f.theme}catch{return null}if(typeof u!="string"||!u||(m=et[O])!=null&&m.includes(u))return null;for(const c of Object.values(a))if(c.valid&&c.name===u)return null;return u},[s,n,r,a]);return i?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:i})," ","is not available."]})," ",e.jsxs("span",{className:"text-warning/80",children:["Add it as a custom theme or use a built-in theme (",(l=et[O])==null?void 0:l.join(", "),"). The renderer will fall back to a default."]})]})]}):null}async function Os(t,s,n,r,a){const i=typeof n=="string"&&n.length>0;let l;if(i){let d;try{d=JSON.parse(n)}catch(m){throw new Error(`Invalid JSON document: ${m.message}`)}const f={jsonDefinition:d,customThemes:r??{},options:{sourceName:t,...a?{renderer:a}:{}}};l=await fetch(Ce.preview.libreofficeFromJson,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)})}else{const d=new FormData,f=O==="pptx"?".pptx":".docx";d.append("file",s,`${t}${f}`),l=await fetch(Ce.preview.libreoffice,{method:"POST",body:d})}if(!l.ok){let d=`LibreOffice preview failed (${l.status})`;try{const f=await l.json();f&&typeof f=="object"&&typeof f.error=="string"&&(d=f.error)}catch{}throw new Error(d)}const o=await l.blob();if(!o.size)throw new Error("LibreOffice preview returned an empty PDF");const u=URL.createObjectURL(o);return{iframeSrc:u,cleanup:()=>URL.revokeObjectURL(u)}}async function Ms(t,s,n,r,a){try{if(!s||s.size===0)throw new Error("Invalid or empty document blob");const i=await Os(t,s,n,r,a);return{status:"success",name:t,payload:i}}catch(i){const l=i instanceof Error?i.message:String(i);return{status:"error",name:t,payload:new Error(l)}}}function Ps(){const t=I(a=>a.activeTab),s=I(a=>a.documents),n=I(a=>a.documentTypes),r=I(a=>a.saveDocument);return x.useCallback((a,i)=>{var c;const l=a.fixes;if(!l||!ut(l))return{ok:!1,error:"This finding carries no applicable fix."};if(!t)return{ok:!1,error:"No active file"};if(i&&i!==t)return{ok:!1,error:`This finding belongs to ${i}, 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 o=s.find(p=>p.name===t);if(!o)return{ok:!1,error:"Active document not found"};const u=nt.getState().getEditor(t);(c=u==null?void 0:u.flushPendingSave)==null||c.call(u);const d=u?u.toStorageValue(u.editor.getValue()):o.text;let f;try{f=JSON.parse(d)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const m=ys(f,l);return m.ok?(r(t,JSON.stringify(m.doc,null,2)),{ok:!0}):{ok:!1,error:m.error}},[t,n,s,r])}const Me=x.forwardRef(({className:t,value:s,...n},r)=>e.jsx(lt,{ref:r,className:v("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...n,children:e.jsx(ts,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(s||0)}%)`}})}));Me.displayName=lt.displayName;function vt(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 Fs(){const[t,s]=x.useState(null),[n,r]=x.useState(!0),[a,i]=x.useState(null);if(x.useEffect(()=>{const u=new AbortController,d=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),i(null))}catch(c){u.signal.aborted||(c instanceof Error&&c.name!=="AbortError"?i(c.message):(!(c instanceof Error)||c.name!=="AbortError")&&i("Failed to load cache stats"))}finally{u.signal.aborted||r(!1)}};d();const f=setInterval(d,5e3),m=()=>d();return window.addEventListener("cache:cleared",m),()=>{u.abort(),clearInterval(f),window.removeEventListener("cache:cleared",m)}},[]),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(a)return e.jsxs("div",{className:"text-destructive p-4",children:["Error loading cache metrics: ",a]});if(!t)return null;const{document:l}=t,o=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:[o.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:vt(l.size)}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",l.itemCount," items)"]})]}),e.jsx(Ot,{variant:l.enabled?"default":"secondary",children:l.enabled?"Enabled":"Disabled"})]}),e.jsx(Me,{value:o,className:"h-2","aria-label":"Cache hit rate"}),t.rasterizer&&e.jsx(Ds,{data:t.rasterizer})]})}function Ds({data:t}){const s=t.diskHits+t.diskMisses;if(s+t.dedupedRequests+t.rendered+t.entries===0)return null;const r=t.hitRate*100,a=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, ",vt(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:[a," duplicate visual",a===1?"":"s"," deduped",t.prepass?` (${t.prepass.collected} collected → ${t.prepass.unique} unique)`:""]})]})]})]})}function Xs(){var ae,Ge;const{name:t,text:s,blob:n,renderer:r,isGenerating:a,generationProgress:i,generationStartedAt:l,cancelGeneration:o,globalError:u,cacheStatus:d,cacheHitRate:f,warnings:m,quality:c,isRendering:p,isPreviewStale:b,editSequence:R,lastBuiltSequence:z,setOutput:E}=qt(h=>h),V=I(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}),B=x.useContext(es),{toast:J}=Lt(),y=Ps(),{analyze:C}=Kt(),[P,L]=x.useState(null),[W,Pe]=x.useState(!1),[q,ee]=x.useState(!1),Fe=N.useId(),De=I(h=>h.activeTab),_=x.useMemo(()=>c&&c.documentName===De?c:null,[c,De]),de=W||q,ue=x.useCallback(()=>{Pe(!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 ze=_==null?void 0:_.gateError;x.useEffect(()=>{ze&&ee(!0)},[ze]);const Be=gt(_);x.useEffect(()=>{Be||ee(!1)},[Be]);const jt=x.useMemo(()=>Zt(m).others,[m]),bt=x.useCallback(h=>{if(!h)return;const g=nt.getState().getActiveEditor();if(!g)return;const{editor:k,monaco:T}=g,A=k.getModel();if(!A)return;const $=js(A.getValue(),h);if(!$)return;const w=A.getPositionAt($.start),Q=A.getPositionAt($.end),Ue=new T.Range(w.lineNumber,w.column,Q.lineNumber,Q.column);k.revealRangeNearTopIfOutsideViewport(Ue,T.editor.ScrollType.Smooth),k.setPosition(w),k.setSelection(Ue),k.focus()},[]),te=x.useRef(new Set);x.useEffect(()=>{te.current=new Set},[c==null?void 0:c.seq]);const yt=x.useCallback(h=>{var g;if(!te.current.has(h.id)){te.current.add(h.id),L(h.id);try{const k=y(h,c==null?void 0:c.documentName);if(!k.ok){te.current.delete(h.id),J({variant:"destructive",title:"Could not apply fix",description:k.error});return}const{activeTab:T,documents:A}=B.getState(),$=(g=A.find(w=>w.name===T))==null?void 0:g.text;$&&C(T,$,{immediate:!0})}finally{L(null)}}},[C,y,B,c==null?void 0:c.documentName,J]),_e=ot(h=>h.customThemes),He=x.useMemo(()=>{const h={};for(const g of Object.values(_e))g.valid&&g.name&&g.parsed&&(h[g.name]=g.parsed);return h},[_e]),[wt,Nt]=x.useState(void 0),[St,kt]=x.useState(void 0),[Et,me]=x.useState(!1),Ct=N.useRef(null),se=x.useRef(null),fe=x.useRef(!1),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 Ms(h,g,k,T,A);if($!=="success")throw w instanceof Error?w:new Error(String(w));ne(),Nt(w.iframeSrc||void 0),kt(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]),$t=x.useRef({name:t,blob:n,text:s,doRender:re});x.useEffect(()=>{$t.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,He,r);return}E({isPreviewStale:!0})}},[n,t,s,He,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 Qe=((Ge=(ae=F)==null?void 0:ae.getState)==null?void 0:Ge.call(ae).useGlobalPreviewHeader)===!1;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-full flex-col",children:[Qe&&e.jsx(Mt,{name:(t==null?void 0:t.trim())||"Preview",blob:n,onManualRender:xe,isGenerating:a,isRendering:p,onShowCacheMetrics:()=>me(!0),documentText:s,editorDocumentText:V,warnings:m}),!Qe&&e.jsx(Pt,{}),(()=>{const h=(R??0)>(z??0),g=(b||h)&&!a&&!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"})]}):d==="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"})]}):d==="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 ",tt.toLowerCase()]})]}):null,T=!!k&&(d&&d!=="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&&_&&e.jsx("div",{"aria-hidden":"true",className:"h-3 w-px flex-shrink-0 bg-border"}),e.jsx(Ls,{quality:_,open:q,onToggle:()=>ee(A=>!A),controlsId:Fe,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:()=>Pe(!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(at,{className:"h-3 w-3","aria-hidden":"true"}),e.jsx("span",{className:"hidden sm:inline",children:"Quality settings"})]})]})})(),e.jsx(cs,{warnings:jt,className:"mx-3 my-2"}),e.jsx(Is,{className:"mx-3 my-2"}),e.jsxs("div",{className:"relative min-h-0 flex-1",children:[u&&!a?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(ls,{ref:Ct,isLoading:!!p,iframeSrc:wt,iframeSrcDoc:St,isGenerating:!!a,generationProgress:i,generationDocumentText:V??s,generationStartedAt:l,onCancelGeneration:o}),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(fs,{}),W&&q&&e.jsx("div",{className:"my-4 border-t"}),q&&e.jsx(As,{id:Fe,quality:_,onRevealPath:bt,onApplyFixes:yt,applyingFindingId:P})]})]})]})]}),e.jsx(Ft,{open:Et,onOpenChange:me,children:e.jsxs(Dt,{className:"max-w-2xl",children:[e.jsx(zt,{children:e.jsx(Bt,{children:"Cache Performance"})}),e.jsx(Fs,{})]})})]})}export{Xs as Preview};
|
|
2
|
-
//# sourceMappingURL=preview-
|
|
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 tt,g as Rt,F as O,p as Tt,Q as At,A as Ce,u as Lt}from"./index-B7bDnXoC.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 It,g as Ve,B as Ot,P as Mt,h as Pt,D as Ft,i as Dt,j as zt,k as Bt}from"./HomePage-CeUQIXch.js";import{B as st,u as nt}from"./editor-refs-store-vzLK2-Zo.js";import{e as rt,Q as G,x as U,a4 as _t,a5 as at,a6 as Le,W as Ht,a7 as it,a8 as Qt,a9 as Gt,aa as Ut}from"./ui-vendor-Bq4-oNFL.js";import Vt from"./monaco-editor-DJsdM0WK.js";import{E as Je,p as Jt,c as $e,d as Wt,g as Yt,e as Xt,u as Kt,a as Zt}from"./useQualityAnalysis-CowAaoA9.js";import{d as F,u as I,a as ot,b as qt,h as es}from"./MonacoPluginProvider-Bx_V_FaE.js";import{ad as lt,ae as ts}from"./radix-ui-DFNP5I4e.js";import"./query-vendor--rhYD8mC.js";import"./state-vendor-Cq67_JbF.js";function ct(t){const[s]=x.useState(()=>Date.now()),n=t??s,[r,a]=x.useState(()=>Date.now());return x.useEffect(()=>{const i=setInterval(()=>a(Date.now()),100);return()=>clearInterval(i)},[]),Math.max(0,(r-n)/1e3)}function ss(t){var s,n;if(!t)return null;try{const r=JSON.parse(t);if(!r||typeof r!="object")return null;const a=new Map,i=[r];for(;i.length>0;){const d=i.pop();if(!d||typeof d!="object")continue;const{name:f,children:m}=d;typeof f=="string"&&a.set(f,(a.get(f)??0)+1),Array.isArray(m)&&i.push(...m)}const o=[["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(([d,f,m])=>{const c=a.get(d)??0;return{label:c===1?f:m,count:c}}).filter(d=>d.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:o,visualCount:(a.get("visual")??0)+(a.get("chart")??0),imageCount:a.get("image")??0}}catch{return null}}function ns(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 rs=()=>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 as({className:t,currentStage:s="parsing",message:n,documentText:r,startedAt:a,onCancel:i}){const l=["parsing","building","rendering","finalizing"],o={parsing:"Validating JSON",building:"Building structure",rendering:"Rendering content",finalizing:"Finalizing document"},u=l.indexOf(s),d=ct(a),f=x.useMemo(()=>ss(r),[r]),m=x.useMemo(()=>ns(f),[f]),c=d>3,p=Math.floor(Math.max(0,d-3)/5)%m.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||`${o[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:[d.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:o[b]}),E?e.jsx(rs,{}):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:m[p]}),i&&e.jsx(st,{variant:"outline",size:"sm",onClick:i,className:"shrink-0",children:"Cancel"})]})]})}function is({mode:t,message:s,startedAt:n,onCancel:r,className:a}){const i=ct(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",a),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:[i.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(st,{variant:"outline",size:"sm",onClick:r,children:"Cancel"})]})}function os({renderingLibrary:t,className:s}){const n=i=>{switch(i){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:a}=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:a})]}),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 dt=N.forwardRef(({isLoading:t,iframeSrc:s,iframeSrcDoc:n,isGenerating:r,generationProgress:a,generationDocumentText:i,generationStartedAt:l,onCancelGeneration:o},u)=>{const[d,f]=x.useState(!1);x.useEffect(()=>{f(!1)},[s,n]);const m=()=>{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(as,{currentStage:a==null?void 0:a.stage,message:a==null?void 0:a.message,documentText:i,startedAt:l,onCancel:o})}):t&&!b?e.jsx("div",{className:"grow",children:e.jsx(os,{renderingLibrary:"LibreOffice"})}):b?e.jsxs("div",{className:"h-full w-full relative bg-white",children:[!d&&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(is,{mode:r?"generating":"rendering",message:r?a==null?void 0:a.message:void 0,startedAt:r?l:void 0,onCancel:r?o:void 0})}),e.jsx("iframe",{ref:u,className:"w-full h-full border-0",style:{backgroundColor:"white",opacity:d?1:0,transition:"opacity 0.2s ease-in-out"},src:s,srcDoc:n,onLoad:m,onError:c,sandbox:p,title:"Document preview","aria-label":`Preview of rendered ${tt.toLowerCase()}`},n?"srcdoc":"src")]}):null});dt.displayName="PreviewFrame";const ls=N.memo(dt);function cs({warnings:t,className:s}){const[n,r]=N.useState(!1),a=N.useMemo(()=>(t??[]).filter(i=>i.component!=="quality"),[t]);return a.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(rt,{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:[a.length," warning",a.length!==1?"s":""]})]}),n&&e.jsx("div",{className:"mt-1.5 space-y-1.5",children:a.map((i,l)=>e.jsxs("div",{className:"flex items-start gap-2 rounded-sm border bg-card px-3 py-2",children:[i.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:i.component}),i.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:i.message}),i.context&&Object.keys(i.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(i.context,null,2)})]})]})]},l))})]})}function ds({className:t}){const{resolvedTheme:s}=Rt(),n=F(m=>m.qualityPolicies),r=F(m=>m.setSettings),a=n==null?void 0:n[O],[i,l]=x.useState(a??Je),o=x.useMemo(()=>Jt(i),[i]),u=x.useMemo(()=>Tt().map(m=>m.id),[]),d=x.useCallback(m=>{l(m),r({qualityPolicies:{...n,[O]:m}})},[n,r]),f=x.useCallback(()=>d(Je),[d]);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(_t,{className:"h-3 w-3","aria-hidden":"true"}),"Reset"]})]}),e.jsx("div",{className:"overflow-hidden rounded-sm border",children:e.jsx(Vt,{height:"180px",language:"json",path:At,theme:s==="dark"?"vs-dark":"vs",defaultValue:i,onChange:m=>d(m??""),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}})}),o.ok?e.jsx("p",{className:"text-[11px] leading-snug text-muted-foreground",children:o.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:[o.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(m=>e.jsx("li",{className:"font-mono text-[10px]",children:m},m))})]})]})}const Re="__default__",us={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"}]},ms={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",We={value:Re,label:"Default",description:`The format's own profile (${ms[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 fs({className:t}){const s=x.useId(),n=F(c=>c.qualityProfileIds),r=n==null?void 0:n[O],a=F(c=>c.qualityGate)??"none",i=F(c=>c.qualityMinSeverity)??"warning",l=F(c=>c.setSettings),o=us[O],d=o.find(c=>c.value===r)??We,f=be.find(c=>c.value===a)??be[0],m=ye.find(c=>c.value===i)??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(at,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Profile"]}),e.jsxs(pe,{value:d.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:d.label})})}),e.jsxs(je,{className:Ne,children:[e.jsx(ie,{value:Re,className:"text-xs",children:e.jsx(oe,{choice:We})}),o.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:d.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(ds,{})]}),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(Ht,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),"Show"]}),e.jsxs(pe,{value:m.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:m.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 xs=/^(?:0|[1-9][0-9]*)$/;function hs(t){return t.replace(/~1/g,"/").replace(/~0/g,"~")}function ps(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=hs(n);return xs.test(r)?Number(r):r})}function gs(t){return t.map(s=>`/${ps(String(s))}`).join("")}function vs(t,s){const n=Ve(t,[s]);return n||typeof s!="number"?n:Ve(t,[String(s)])}function js(t,s){if(!t.trim())return null;let n;try{if(n=It(t,[],{allowTrailingComma:!0}),!n)return null;for(const r of Ie(s))if(n=vs(n,r),!n)return null}catch{return null}return{start:n.offset,end:n.offset+n.length}}const bs=["add","remove","replace","move","copy","test"];function ys(t,s){try{let n=t;for(let r=0;r<s.length;r++){const a=ws(n,s[r],r);if(!a.ok)return{ok:!1,error:a.error};n=a.value}return{ok:!0,doc:n,applied:s.length}}catch(n){return{ok:!1,error:`quality fix failed: ${Es(n)}`}}}function ut(t){return!t||t.length===0?!1:t.every(s=>mt(s.op)?s.op==="move"||s.op==="copy"?typeof s.from=="string":!0:!1)}function ws(t,s,n){const r=`fix #${n+1} (${String(s.op)} "${String(s.path)}")`,a=s.op;if(!mt(a))return j(`${r}: unsupported operation "${String(a)}"`);const i=Ie(s.path);switch(a){case"add":return Ee(t,i,s.value,r);case"replace":return Ns(t,i,s.value,r);case"remove":{const l=Ye(t,i,r);return l.ok?S(l.value.doc):l}case"copy":{const l=Ke(s,r);if(!l.ok)return l;const o=Xe(t,l.value.path);return o.ok?Ee(t,i,o.value,r):j(`${r}: ${o.error}`)}case"move":{const l=Ke(s,r);if(!l.ok)return l;if(Ss(l.value.path,i))return S(t);if(ks(l.value.path,i))return j(`${r}: ${M(l.value.path)} cannot be moved into its own child`);const o=Ye(t,l.value.path,r);return o.ok?Ee(o.value.doc,i,o.value.removed,r):o}case"test":{const l=Xe(t,i);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 a=s[s.length-1];return Oe(t,s,r,i=>{if(Array.isArray(i)){const l=a==="-"?i.length:K(a);if(l===null)return j(`${r}: "${String(a)}" is not an array index`);if(l>i.length)return j(`${r}: index ${l} is past the end of the array`);const o=D(i);return o.splice(l,0,n),S(o)}if(H(i)){const l=D(i);return l[String(a)]=n,S(l)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Ns(t,s,n,r){if(s.length===0)return S(n);const a=s[s.length-1];return Oe(t,s,r,i=>{if(Array.isArray(i)){const l=K(a);if(l===null||l>=i.length)return j(`${r}: "${String(a)}" is not an existing array index`);const o=D(i);return o[l]=n,S(o)}if(H(i)){const l=String(a);if(!Z(i,l))return j(`${r}: "${l}" does not exist`);const o=D(i);return o[l]=n,S(o)}return j(`${r}: ${M(s.slice(0,-1))} is not an object or array`)})}function Ye(t,s,n){if(s.length===0)return j(`${n}: the whole document cannot be removed`);const r=s[s.length-1];let a;const i=Oe(t,s,n,l=>{if(Array.isArray(l)){const o=K(r);if(o===null||o>=l.length)return j(`${n}: "${String(r)}" is not an existing array index`);const u=D(l);return a=u.splice(o,1)[0],S(u)}if(H(l)){const o=String(r);if(!Z(l,o))return j(`${n}: "${o}" does not exist`);const u=D(l);return a=u[o],delete u[o],S(u)}return j(`${n}: ${M(s.slice(0,-1))} is not an object or array`)});return i.ok?S({doc:i.value,removed:a}):i}function Oe(t,s,n,r){return Te(t,s.slice(0,-1),0,n,r)}function Te(t,s,n,r,a){if(n===s.length)return a(t);const i=()=>M(s.slice(0,n+1)),l=s[n];if(Array.isArray(t)){const o=K(l);if(o===null||o>=t.length)return j(`${r}: ${i()} does not exist`);const u=Te(t[o],s,n+1,r,a);if(!u.ok)return u;const d=D(t);return d[o]=u.value,S(d)}if(H(t)){const o=String(l);if(!Z(t,o))return j(`${r}: ${i()} does not exist`);const u=Te(t[o],s,n+1,r,a);if(!u.ok)return u;const d=D(t);return d[o]=u.value,S(d)}return j(`${r}: ${M(s.slice(0,n))} is not an object or array`)}function Xe(t,s){let n=t;for(let r=0;r<s.length;r++){const a=s[r];if(Array.isArray(n)){const i=K(a);if(i===null||i>=n.length)return j(`${M(s.slice(0,r+1))} does not exist`);n=n[i];continue}if(H(n)){const i=String(a);if(!Z(n,i))return j(`${M(s.slice(0,r+1))} does not exist`);n=n[i];continue}return j(`${M(s.slice(0,r))} is not an object or array`)}return S(n)}function Ke(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":`"${gs(t)}"`}function mt(t){return bs.includes(t)}function H(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Z(t,s){return Object.prototype.hasOwnProperty.call(t,s)}function Ss(t,s){return t.length===s.length&&t.every((n,r)=>String(n)===String(s[r]))}function ks(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(H(t)&&H(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 Es(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,ft=[],xt=["error","warning","info"],Cs={error:it,warning:G,info:U},ht={error:"text-destructive",warning:"text-warning",info:"text-data-blue"},$s=new Set(["actual","expected","unit"]);function pt(t,s){return t==="info"?`${s} info`:`${s} ${t}${s===1?"":"s"}`}function Ze(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 Rs(t){if(!t)return null;const s={};let n=!1;for(const[r,a]of Object.entries(t))$s.has(r)||(s[r]=a,n=!0);return n?s:null}function qe({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(Ut,{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 Ts({finding:t,onRevealPath:s,onApplyFixes:n,isApplying:r}){const a=Cs[t.severity]??U,i=ht[t.severity]??"text-muted-foreground",l=Xt(t.certainty),o=t.evidence,u=o!==void 0&&(o.actual!==void 0||o.expected!==void 0),d=Rs(o),f=!!n&&ut(t.fixes),m=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(a,{className:v("mt-0.5 h-3.5 w-3.5 flex-shrink-0",i)}),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&&o&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[o.expected!==void 0&&e.jsxs(e.Fragment,{children:["Expected"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:Ze(o.expected,o.unit)})]}),o.expected!==void 0&&o.actual!==void 0&&e.jsx("span",{className:"text-muted-foreground/50",children:" · "}),o.actual!==void 0&&e.jsxs(e.Fragment,{children:[o.expected===void 0?"Found":"found"," ",e.jsx("span",{className:"font-mono font-medium text-foreground/90",children:Ze(o.actual,o.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(Gt,{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(qe,{path:t.path,onRevealPath:s}),m.map(c=>e.jsx(qe,{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})]}),d&&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(d,null,2)})]})]})]})}function As({quality:t,id:s,className:n,onRevealPath:r,onApplyFixes:a,applyingFindingId:i}){const l=F(y=>y.qualityMinSeverity),[o,u]=N.useState(!1),[d,f]=N.useState(!1),m=(t==null?void 0:t.findings)??ft,c=l??"warning",p=N.useMemo(()=>Wt(m,c),[m,c]),b=o?m:p,R=N.useMemo(()=>Yt(b),[b]),z=N.useMemo(()=>{if(d||b.length<=le)return R;let y=le;const C=[];for(const P of R){if(y<=0)break;const L=P.findings.slice(0,y);y-=L.length,C.push({category:P.category,findings:L})}return C},[R,d,b.length]),E=N.useMemo(()=>$e(m),[m]),V=N.useMemo(()=>$e(p),[p]),B=m.length-p.length,J=N.useMemo(()=>{const y=[];let C=0;for(const P of xt){const L=E[P]-V[P];L>0&&(y.push(pt(P,L)),C+=L)}return C<B&&y.push(`${B-C} other`),y.join(", ")},[E,V,B]);return!t||m.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,m.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."}),B>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:o?`${J} below the ${c} filter, now shown`:`${J} hidden by the ${c}-and-above filter`}),e.jsx("button",{type:"button",onClick:()=>u(!o),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:o?"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(Ts,{finding:C,onRevealPath:r,onApplyFixes:a,isApplying:i===C.id},C.id))]},y.category)),b.length>le&&e.jsx("button",{type:"button",onClick:()=>f(!d),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:d?`Show first ${le}`:`Show all ${b.length}`})]})]})}function gt(t){return t?t.findings.length>0||!!t.gateError||!!t.analysisError||!!t.truncated:!1}function Ls({quality:t,open:s=!1,onToggle:n,controlsId:r,className:a}){const i=N.useMemo(()=>$e((t==null?void 0:t.findings)??ft),[t==null?void 0:t.findings]);if(!t)return null;const l=!!(t.blocked||t.gateError),o=xt.filter(p=>i[p]>0),u=gt(t)&&!!n,d=l||i.error>0?"text-destructive":i.warning>0?"text-warning":t.analysisError?"text-muted-foreground":o.length===0?"text-success":"text-data-blue",f=l?Le:i.error>0?it:i.warning>0?G:t.analysisError?U:o.length===0?Qt:U,m=e.jsxs(e.Fragment,{children:[u&&e.jsx(rt,{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",d)}),e.jsx("span",{className:"text-xs font-medium text-foreground",children:"Quality"}),o.length===0?e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:t.analysisError?"Not available":"No findings"}):o.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",ht[p]),children:pt(p,i[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",a),children:m}):e.jsx("div",{className:v(c,a),children:m})}const et={pptx:["default","dark","minimal"],docx:["minimal","corporate","modern"]};function Is({className:t}){var l;const s=I(o=>o.activeTab),n=I(o=>o.documentTypes),r=I(o=>o.documents),a=ot(o=>o.customThemes),i=x.useMemo(()=>{var d,f,m;if(!s||n[s]==="application/json+theme")return null;const o=r.find(c=>c.name===s);if(!(o!=null&&o.text))return null;let u;try{u=(f=(d=JSON.parse(o.text))==null?void 0:d.props)==null?void 0:f.theme}catch{return null}if(typeof u!="string"||!u||(m=et[O])!=null&&m.includes(u))return null;for(const c of Object.values(a))if(c.valid&&c.name===u)return null;return u},[s,n,r,a]);return i?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:i})," ","is not available."]})," ",e.jsxs("span",{className:"text-warning/80",children:["Add it as a custom theme or use a built-in theme (",(l=et[O])==null?void 0:l.join(", "),"). The renderer will fall back to a default."]})]})]}):null}async function Os(t,s,n,r,a){const i=typeof n=="string"&&n.length>0;let l;if(i){let d;try{d=JSON.parse(n)}catch(m){throw new Error(`Invalid JSON document: ${m.message}`)}const f={jsonDefinition:d,customThemes:r??{},options:{sourceName:t,...a?{renderer:a}:{}}};l=await fetch(Ce.preview.libreofficeFromJson,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)})}else{const d=new FormData,f=O==="pptx"?".pptx":".docx";d.append("file",s,`${t}${f}`),l=await fetch(Ce.preview.libreoffice,{method:"POST",body:d})}if(!l.ok){let d=`LibreOffice preview failed (${l.status})`;try{const f=await l.json();f&&typeof f=="object"&&typeof f.error=="string"&&(d=f.error)}catch{}throw new Error(d)}const o=await l.blob();if(!o.size)throw new Error("LibreOffice preview returned an empty PDF");const u=URL.createObjectURL(o);return{iframeSrc:u,cleanup:()=>URL.revokeObjectURL(u)}}async function Ms(t,s,n,r,a){try{if(!s||s.size===0)throw new Error("Invalid or empty document blob");const i=await Os(t,s,n,r,a);return{status:"success",name:t,payload:i}}catch(i){const l=i instanceof Error?i.message:String(i);return{status:"error",name:t,payload:new Error(l)}}}function Ps(){const t=I(a=>a.activeTab),s=I(a=>a.documents),n=I(a=>a.documentTypes),r=I(a=>a.saveDocument);return x.useCallback((a,i)=>{var c;const l=a.fixes;if(!l||!ut(l))return{ok:!1,error:"This finding carries no applicable fix."};if(!t)return{ok:!1,error:"No active file"};if(i&&i!==t)return{ok:!1,error:`This finding belongs to ${i}, 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 o=s.find(p=>p.name===t);if(!o)return{ok:!1,error:"Active document not found"};const u=nt.getState().getEditor(t);(c=u==null?void 0:u.flushPendingSave)==null||c.call(u);const d=u?u.toStorageValue(u.editor.getValue()):o.text;let f;try{f=JSON.parse(d)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const m=ys(f,l);return m.ok?(r(t,JSON.stringify(m.doc,null,2)),{ok:!0}):{ok:!1,error:m.error}},[t,n,s,r])}const Me=x.forwardRef(({className:t,value:s,...n},r)=>e.jsx(lt,{ref:r,className:v("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t),...n,children:e.jsx(ts,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:`translateX(-${100-(s||0)}%)`}})}));Me.displayName=lt.displayName;function vt(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 Fs(){const[t,s]=x.useState(null),[n,r]=x.useState(!0),[a,i]=x.useState(null);if(x.useEffect(()=>{const u=new AbortController,d=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),i(null))}catch(c){u.signal.aborted||(c instanceof Error&&c.name!=="AbortError"?i(c.message):(!(c instanceof Error)||c.name!=="AbortError")&&i("Failed to load cache stats"))}finally{u.signal.aborted||r(!1)}};d();const f=setInterval(d,5e3),m=()=>d();return window.addEventListener("cache:cleared",m),()=>{u.abort(),clearInterval(f),window.removeEventListener("cache:cleared",m)}},[]),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(a)return e.jsxs("div",{className:"text-destructive p-4",children:["Error loading cache metrics: ",a]});if(!t)return null;const{document:l}=t,o=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:[o.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:vt(l.size)}),e.jsxs("span",{className:"text-muted-foreground ml-1",children:["(",l.itemCount," items)"]})]}),e.jsx(Ot,{variant:l.enabled?"default":"secondary",children:l.enabled?"Enabled":"Disabled"})]}),e.jsx(Me,{value:o,className:"h-2","aria-label":"Cache hit rate"}),t.rasterizer&&e.jsx(Ds,{data:t.rasterizer})]})}function Ds({data:t}){const s=t.diskHits+t.diskMisses;if(s+t.dedupedRequests+t.rendered+t.entries===0)return null;const r=t.hitRate*100,a=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, ",vt(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:[a," duplicate visual",a===1?"":"s"," deduped",t.prepass?` (${t.prepass.collected} collected → ${t.prepass.unique} unique)`:""]})]})]})]})}function Xs(){var ae,Ge;const{name:t,text:s,blob:n,renderer:r,isGenerating:a,generationProgress:i,generationStartedAt:l,cancelGeneration:o,globalError:u,cacheStatus:d,cacheHitRate:f,warnings:m,quality:c,isRendering:p,isPreviewStale:b,editSequence:R,lastBuiltSequence:z,setOutput:E}=qt(h=>h),V=I(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}),B=x.useContext(es),{toast:J}=Lt(),y=Ps(),{analyze:C}=Kt(),[P,L]=x.useState(null),[W,Pe]=x.useState(!1),[q,ee]=x.useState(!1),Fe=N.useId(),De=I(h=>h.activeTab),_=x.useMemo(()=>c&&c.documentName===De?c:null,[c,De]),de=W||q,ue=x.useCallback(()=>{Pe(!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 ze=_==null?void 0:_.gateError;x.useEffect(()=>{ze&&ee(!0)},[ze]);const Be=gt(_);x.useEffect(()=>{Be||ee(!1)},[Be]);const jt=x.useMemo(()=>Zt(m).others,[m]),bt=x.useCallback(h=>{if(!h)return;const g=nt.getState().getActiveEditor();if(!g)return;const{editor:k,monaco:T}=g,A=k.getModel();if(!A)return;const $=js(A.getValue(),h);if(!$)return;const w=A.getPositionAt($.start),Q=A.getPositionAt($.end),Ue=new T.Range(w.lineNumber,w.column,Q.lineNumber,Q.column);k.revealRangeNearTopIfOutsideViewport(Ue,T.editor.ScrollType.Smooth),k.setPosition(w),k.setSelection(Ue),k.focus()},[]),te=x.useRef(new Set);x.useEffect(()=>{te.current=new Set},[c==null?void 0:c.seq]);const yt=x.useCallback(h=>{var g;if(!te.current.has(h.id)){te.current.add(h.id),L(h.id);try{const k=y(h,c==null?void 0:c.documentName);if(!k.ok){te.current.delete(h.id),J({variant:"destructive",title:"Could not apply fix",description:k.error});return}const{activeTab:T,documents:A}=B.getState(),$=(g=A.find(w=>w.name===T))==null?void 0:g.text;$&&C(T,$,{immediate:!0})}finally{L(null)}}},[C,y,B,c==null?void 0:c.documentName,J]),_e=ot(h=>h.customThemes),He=x.useMemo(()=>{const h={};for(const g of Object.values(_e))g.valid&&g.name&&g.parsed&&(h[g.name]=g.parsed);return h},[_e]),[wt,Nt]=x.useState(void 0),[St,kt]=x.useState(void 0),[Et,me]=x.useState(!1),Ct=N.useRef(null),se=x.useRef(null),fe=x.useRef(!1),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 Ms(h,g,k,T,A);if($!=="success")throw w instanceof Error?w:new Error(String(w));ne(),Nt(w.iframeSrc||void 0),kt(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]),$t=x.useRef({name:t,blob:n,text:s,doRender:re});x.useEffect(()=>{$t.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,He,r);return}E({isPreviewStale:!0})}},[n,t,s,He,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 Qe=((Ge=(ae=F)==null?void 0:ae.getState)==null?void 0:Ge.call(ae).useGlobalPreviewHeader)===!1;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-full flex-col",children:[Qe&&e.jsx(Mt,{name:(t==null?void 0:t.trim())||"Preview",blob:n,onManualRender:xe,isGenerating:a,isRendering:p,onShowCacheMetrics:()=>me(!0),documentText:s,editorDocumentText:V,warnings:m}),!Qe&&e.jsx(Pt,{}),(()=>{const h=(R??0)>(z??0),g=(b||h)&&!a&&!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"})]}):d==="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"})]}):d==="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 ",tt.toLowerCase()]})]}):null,T=!!k&&(d&&d!=="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&&_&&e.jsx("div",{"aria-hidden":"true",className:"h-3 w-px flex-shrink-0 bg-border"}),e.jsx(Ls,{quality:_,open:q,onToggle:()=>ee(A=>!A),controlsId:Fe,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:()=>Pe(!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(at,{className:"h-3 w-3","aria-hidden":"true"}),e.jsx("span",{className:"hidden sm:inline",children:"Quality settings"})]})]})})(),e.jsx(cs,{warnings:jt,className:"mx-3 my-2"}),e.jsx(Is,{className:"mx-3 my-2"}),e.jsxs("div",{className:"relative min-h-0 flex-1",children:[u&&!a?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(ls,{ref:Ct,isLoading:!!p,iframeSrc:wt,iframeSrcDoc:St,isGenerating:!!a,generationProgress:i,generationDocumentText:V??s,generationStartedAt:l,onCancelGeneration:o}),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(fs,{}),W&&q&&e.jsx("div",{className:"my-4 border-t"}),q&&e.jsx(As,{id:Fe,quality:_,onRevealPath:bt,onApplyFixes:yt,applyingFindingId:P})]})]})]})]}),e.jsx(Ft,{open:Et,onOpenChange:me,children:e.jsxs(Dt,{className:"max-w-2xl",children:[e.jsx(zt,{children:e.jsx(Bt,{children:"Cache Performance"})}),e.jsx(Fs,{})]})})]})}export{Xs as Preview};
|
|
2
|
+
//# sourceMappingURL=preview-BGqIip90.js.map
|