@json-to-office/jto 6.0.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/client/assets/{HomePage-cnVO2sFq.js → HomePage-Dzm2MeID.js} +4 -4
  3. package/dist/client/assets/{HomePage-cnVO2sFq.js.map → HomePage-Dzm2MeID.js.map} +1 -1
  4. package/dist/client/assets/{JsonEditorPage-nazV1RwE.js → JsonEditorPage-DOp1sE3p.js} +3 -3
  5. package/dist/client/assets/{JsonEditorPage-nazV1RwE.js.map → JsonEditorPage-DOp1sE3p.js.map} +1 -1
  6. package/dist/client/assets/{MonacoPluginProvider-CHlaWI7K.js → MonacoPluginProvider-Bc9nyqNY.js} +5 -5
  7. package/dist/client/assets/{MonacoPluginProvider-CHlaWI7K.js.map → MonacoPluginProvider-Bc9nyqNY.js.map} +1 -1
  8. package/dist/client/assets/{_virtual_jto-plugin-type-libs-ToC-eF7z.js → _virtual_jto-plugin-type-libs-Pc3DyHoX.js} +106 -38
  9. package/dist/client/assets/{_virtual_jto-plugin-type-libs-ToC-eF7z.js.map → _virtual_jto-plugin-type-libs-Pc3DyHoX.js.map} +1 -1
  10. package/dist/client/assets/_virtual_jto-sandbox-runtime-DUgi1ipv.js +2 -0
  11. package/dist/client/assets/_virtual_jto-sandbox-runtime-DUgi1ipv.js.map +1 -0
  12. package/dist/client/assets/{editor-BDFx5tyz.js → editor-BJWDd3uK.js} +2 -2
  13. package/dist/client/assets/{editor-BDFx5tyz.js.map → editor-BJWDd3uK.js.map} +1 -1
  14. package/dist/client/assets/{editor-monaco-json-Bs0Mrsdq.js → editor-monaco-json-FLZpeDZL.js} +2 -2
  15. package/dist/client/assets/{editor-monaco-json-Bs0Mrsdq.js.map → editor-monaco-json-FLZpeDZL.js.map} +1 -1
  16. package/dist/client/assets/{index-CooDRbV2.js → index-D5Xrk4Ze.js} +2 -2
  17. package/dist/client/assets/{index-CooDRbV2.js.map → index-D5Xrk4Ze.js.map} +1 -1
  18. package/dist/client/assets/{index-DJULKPqV.js → index-D6Nfjrjh.js} +13 -13
  19. package/dist/client/assets/index-D6Nfjrjh.js.map +1 -0
  20. package/dist/client/assets/{preview-1VQB3b7e.js → preview-C4ynYVMZ.js} +2 -2
  21. package/dist/client/assets/{preview-1VQB3b7e.js.map → preview-C4ynYVMZ.js.map} +1 -1
  22. package/dist/client/assets/{useQualityAnalysis-Cgw8FvPh.js → useQualityAnalysis-kUkZB_mW.js} +2 -2
  23. package/dist/client/assets/{useQualityAnalysis-Cgw8FvPh.js.map → useQualityAnalysis-kUkZB_mW.js.map} +1 -1
  24. package/dist/client/index.html +1 -1
  25. package/dist/client/templates/client-report-blocks.docx.json +2 -2
  26. package/dist/client/templates/consulting-deck-blocks.pptx.json +1 -2
  27. package/package.json +5 -5
  28. package/dist/client/assets/_virtual_jto-sandbox-runtime-DhfBorPd.js +0 -2
  29. package/dist/client/assets/_virtual_jto-sandbox-runtime-DhfBorPd.js.map +0 -1
  30. package/dist/client/assets/index-DJULKPqV.js.map +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-BDFx5tyz.js","assets/react-vendor-BmQ2Ko_D.js","assets/editor-monaco-json-Bs0Mrsdq.js","assets/index-DJULKPqV.js","assets/query-vendor--rhYD8mC.js","assets/radix-ui-BzbaiLpZ.js","assets/ui-vendor-BsAtAN16.js","assets/monaco-editor-DJsdM0WK.js","assets/state-vendor-Cq67_JbF.js","assets/index--kF4jVbp.css","assets/index-CooDRbV2.js","assets/MonacoPluginProvider-CHlaWI7K.js","assets/useQualityAnalysis-Cgw8FvPh.js","assets/preview-1VQB3b7e.js"])))=>i.map(i=>d[i]);
2
- var lg=Object.defineProperty;var cg=(e,t,n)=>t in e?lg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Or=(e,t,n)=>cg(e,typeof t!="symbol"?t+"":t,n);import{r as g,j as l,c as je,R as nd,g as ga}from"./react-vendor-BmQ2Ko_D.js";import{u as vn,s as rd,p as ug,a as ke,T as xa,v as dg,i as fg,b as Io,c as qs,d as an,g as pg,e as Jt,B as hg,f as gr,h as id,j as mg,k as gg,S as xg,O as yg,l as bg,M as vg,D as wg,m as kg}from"./MonacoPluginProvider-CHlaWI7K.js";import{A as Sg,F as at,c as W,u as _r,S as cn,a as oi,T as Oi,C as jg,E as _g,b as Ng,d as Cg,e as Ye,f as Xe,g as Qe,p as Eg,h as sd,i as od,_ as ad,j as Pi,k as Tg,l as Ig,m as Ag,n as Pr,s as Gs,W as ld,o as Hi}from"./index-DJULKPqV.js";import{b as cd,c as ya,d as ud,e as js,f as _s,D as Ns,O as Cs,g as zg,V as Og,G as Pg,h as dd,I as Dg,i as Rg,j as fd,k as $g,l as pd,m as Mg,n as Fg,L as hd,S as md,o as gd,p as xd,q as yd,r as Nr,s as Lg,t as Bg,u as Zg,v as bd,w as vd,x as wd,y as kd,z as Sd,B as jd,E as _d,F as Nd,H as Cd,J as Vg,K as Ug,M as Jg,N as Ed,Q as Td,U as Id,W as Ad,X as zd,Y as Od,Z as Pd,_ as Dd,$ as Rd,a0 as $d,a1 as Hg,a2 as Md,a3 as Wg,a4 as qg,a5 as Fd,a6 as Gg,a7 as Kg,a8 as Yg,a9 as Xg,aa as Ld,ab as Bd,ac as Zd}from"./radix-ui-BzbaiLpZ.js";import{X as wn,C as ki,a as un,b as Qg,d as Si,G as Vd,F as ex,e as Cr,f as Ud,P as tx,g as nx,h as Jd,i as Hd,E as ba,B as Qi,H as rx,T as Ao,L as zo,j as ix,k as sx,S as Wd,I as ox,l as ax,m as Oo,n as lx,o as cx,p as ux,q as dx,r as fx,s as px,t as hx,u as mx,v as Es,w as gx,M as xx,x as Dt,y as qd,z as yx,A as bx,D as vx,J as wx,K as Gd,N as kx,O as Sx,Q as jx,R as _x,U as Nx,V as Cx,W as Kd,Y as Ex,Z as Po,_ as va,$ as Yd,a0 as Tx,a1 as Xd,a2 as Jr,a3 as Ix,a4 as Ax,a5 as zx,a6 as gl,a7 as Do}from"./ui-vendor-BsAtAN16.js";import{B as Ce,d as xl}from"./index-CooDRbV2.js";import{u as wa,a as Ox,d as Px,p as Dx,b as Rx,e as $x}from"./state-vendor-Cq67_JbF.js";import{b as Mx}from"./query-vendor--rhYD8mC.js";let Di=null,Dr=null;const Fx=1e4;function Lx(e,t){return t.aborted?Promise.reject(yl(t)):new Promise((n,r)=>{const i=()=>r(yl(t));t.addEventListener("abort",i,{once:!0}),e.then(n,r).finally(()=>{t.removeEventListener("abort",i)})})}function yl(e){return e.reason??new DOMException("Aborted","AbortError")}async function Bx(e){return Di||(Dr||(Dr=(async()=>{const t=await fetch(`${Sg}/discovery/themes/builtin`,{signal:AbortSignal.timeout(Fx)});if(!t.ok)throw new Error(`Built-in themes unavailable (${t.status})`);const n=await t.json();if(!n.success||!n.data)throw new Error(n.error??"Built-in themes unavailable");return Di=n.data,Di})().finally(()=>{Dr=null})),e?Lx(Dr,e):Dr)}class hn extends Error{constructor(n,r,i){super(n);Or(this,"pluginName");Or(this,"path");this.name="PluginExpansionError",this.pluginName=r,this.path=i}}const Zx=20,Vx=1e4;function ai(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function bl(e,t){const n=new Set;if(t.size===0)return n;const r=i=>{if(Array.isArray(i)){i.forEach(r);return}ai(i)&&(typeof i.name=="string"&&t.has(i.name)&&n.add(i.name),Array.isArray(i.children)&&i.children.forEach(r))};return ai(e)&&Array.isArray(e.children)&&e.children.forEach(r),n}const Ux=/^https?:\/\/\S+/i;function es(e,t=new Set){if(typeof e=="string")Ux.test(e)&&t.add(e);else if(Array.isArray(e))for(const n of e)es(n,t);else if(ai(e))for(const n of Object.values(e))es(n,t);return t}function Jx(e,t){if(!e.startsWith("/")||t.size===0)return{path:e,insidePlugin:!1};const n=e.split("/");for(let r=n.length;r>1;r--){const i=n.slice(0,r).join("/"),s=t.get(i);if(!s)continue;if(s.synthetic)return{path:s.authored,insidePlugin:!0};const o=n.slice(r).join("/");return{path:o?`${s.authored}/${o}`:s.authored,insidePlugin:!1}}return{path:e,insidePlugin:!1}}async function Hx(e,t){const{plugins:n,theme:r,render:i,signal:s}=t,o=t.maxDepth??Zx,a=t.maxNodes??Vx,c=[],u=new Map,d=es(e);let f=0;function h(v){if(s!=null&&s.aborted)throw new hn("Expansion was cancelled",void 0,v)}async function p(v,k,y,_,x){if(k>o)throw new hn(`Maximum component nesting depth exceeded (${o}). Check for circular component references.`,void 0,y);const A=[],E=(w,S,O)=>{const B=`${_}/${A.length}`;return(O||B!==S)&&u.set(B,{authored:S,synthetic:O}),A.push(w),B};for(let w=0;w<v.length;w++){h(y);const S=v[w],O=x??`${y}/${w}`,B=x!==void 0;if(!ai(S)||typeof S.name!="string"){E(S,O,B);continue}const N=n.get(S.name);if(!N){if(Array.isArray(S.children)){const P=`${_}/${A.length}`,J=await p(S.children,k+1,`${O}/children`,`${P}/children`,B?x:void 0);E({...S,children:J},O,B)}else E(S,O,B);continue}if(S.enabled===!1)continue;if(S.props===void 0||S.props===null)throw new hn(`Custom component '${S.name}' must have a 'props' property. Use format: { name: '${S.name}', props: {...} }`,S.name,O);const R=typeof S.version=="string"?S.version:void 0;if(R!==void 0&&!N.versions.includes(R))throw new hn(`Component "${S.name}" does not have version "${R}". Available versions: ${N.versions.join(", ")}`,S.name,O);const T=Array.isArray(S.children)?await p(S.children,k+1,`${O}/children`,`${O}/children`,O):void 0,F=R?`${S.name}@${R}`:S.name;let $;try{$=await i({name:S.name,version:R,props:S.props,theme:r,children:T},s)}catch(P){throw s!=null&&s.aborted?P:new hn(`Error processing custom component '${S.name}': ${P instanceof Error?P.message:String(P)}`,S.name,O)}for(const P of $.warnings??[])c.push({component:F,message:P.message,severity:"warning",...P.context?{context:P.context}:{}});if(!Array.isArray($.components))throw new hn(`Custom component '${S.name}' must render an array of components.`,S.name,O);for(const P of es($.components))d.has(P)||c.push({component:F,message:`Plugin output references a remote source the document did not: ${P}`,severity:"warning",context:{code:"PLUGIN_REMOTE_SOURCE",url:P,path:O}});if(f+=$.components.length,f>a)throw new hn(`Plugin expansion produced more than ${a} components; stopping at '${S.name}'.`,S.name,O);const Z=await p($.components,k+1,O,_,O);for(const P of Z)E(P,O,!0)}return A}if(!ai(e)||!Array.isArray(e.children))return{document:e,warnings:c,pathMap:u};const m=await p(e.children,0,"/children","/children",void 0);return{document:{...e,children:m},warnings:c,pathMap:u}}function mt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Wx(e,t){if(!mt(t))return e;const n=mt(e.fonts)?e.fonts:{},r={...n};if(mt(t.fonts))for(const[o,a]of Object.entries(t.fonts)){const c=n[o],u=mt(c)?c:{};r[o]=mt(a)?{...u,...a}:a}const i=mt(e.styles)?e.styles:{},s={...i};if(mt(t.styles))for(const[o,a]of Object.entries(t.styles)){const c=i[o],u=mt(c)?c:{};s[o]=mt(a)?{...u,...a}:a}return{...e,colors:{...mt(e.colors)?e.colors:{},...mt(t.colors)?t.colors:{}},fonts:r,...Object.keys(s).length>0?{styles:s}:{}}}const vl={docx:"minimal",pptx:"default"};function qx(e,t){const{format:n,customThemes:r,builtinThemes:i}=t,s=mt(e)&&mt(e.props)?e.props:{},o=s.theme;if(n==="pptx"&&mt(o))return{theme:o};const a=typeof o=="string"&&o.length>0?o:vl[n];let c=r[a];if(c===void 0&&n==="docx"){const f=a.toLowerCase(),h=Object.keys(r).find(p=>p.toLowerCase()===f);h&&(c=r[h])}c===void 0&&(c=i[a]);let u;if(c===void 0){const f=vl[n],h=[...Object.keys(i),...Object.keys(r)].sort();u={message:`Theme "${a}" not found; falling back to "${f}". Available themes: ${h.join(", ")}.`,context:{code:"theme_not_found",requested:a,available:h}},c=i[f]}c===void 0&&(c=Object.values(i)[0]??{});const d=n==="docx"&&mt(c)&&s.themeOverrides?Wx(c,s.themeOverrides):c;return u?{theme:d,warning:u}:{theme:d}}const Ks=e=>({path:e,insidePlugin:!1});function Gx(e){if(!e.enabled)return"is turned off — enable it in the plugin header or the sidebar";if(e.status==="compiling"||e.status==="idle")return"is still compiling — try again in a moment";const t=e.diagnostics.filter(n=>n.severity==="error");return t.length>0?`has ${t.length} error${t.length===1?"":"s"} — open ${e.docName} to fix ${t.length===1?"it":"them"}`:`failed to load — open ${e.docName}`}async function Ro(e,t={}){var y;const n=vn.getState(),r=rd(n),i=Object.values(n.records).filter(_=>_.metadata);if(i.length===0)return{text:e,warnings:[],expanded:!1,remap:Ks};let s;try{s=JSON.parse(e)}catch{return{text:e,warnings:[],expanded:!1,remap:Ks}}const o=new Set(r.map(_=>_.metadata.name)),a=new Map;for(const _ of i){const x=_.metadata.name;!o.has(x)&&!a.has(x)&&a.set(x,_)}const c=bl(s,new Set(a.keys()));if(c.size>0){const[_]=c,x=a.get(_);throw new hn(`"${_}" is a browser plugin that ${Gx(x)}.`,_)}if(bl(s,o).size===0)return{text:e,warnings:[],expanded:!1,remap:Ks};const d=new Map,f=new Map;for(const _ of r)d.set(_.metadata.name,{name:_.metadata.name,versions:_.metadata.versions.map(x=>x.version)}),f.set(_.metadata.name,_.docName);let h={};try{h=await Bx(t.signal)}catch(_){if((y=t.signal)!=null&&y.aborted)throw _}const p=qx(s,{format:at,customThemes:t.customThemes??{},builtinThemes:h}),m=await Hx(s,{plugins:d,theme:p.theme,signal:t.signal,render:(_,x)=>ug.render(f.get(_.name),_,x)}),v=p.warning?[{component:"theme",message:p.warning.message,severity:"warning",context:p.warning.context},...m.warnings]:m.warnings,k=m.pathMap;return{text:JSON.stringify(m.document,null,2),warnings:v,expanded:!0,remap:_=>Jx(_,k)}}const ct=cd,Kx=ud,wl=ya,Qd=g.forwardRef(({className:e,...t},n)=>l.jsx(Cs,{ref:n,className:W("fixed inset-0 z-50 bg-black/50",e),...t}));Qd.displayName=Cs.displayName;const lt=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Kx,{children:[l.jsx(Qd,{}),l.jsxs(js,{ref:r,className:W("bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",e),...n,children:[t,l.jsxs(ya,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 cursor-pointer rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none",children:[l.jsx(wn,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));lt.displayName=js.displayName;const qt=({className:e,...t})=>l.jsx("div",{className:W("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});qt.displayName="DialogHeader";const kn=({className:e,...t})=>l.jsx("div",{className:W("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});kn.displayName="DialogFooter";const Gt=g.forwardRef(({className:e,...t},n)=>l.jsx(_s,{ref:n,className:W("text-lg leading-none font-semibold tracking-tight",e),...t}));Gt.displayName=_s.displayName;const dn=g.forwardRef(({className:e,...t},n)=>l.jsx(Ns,{ref:n,className:W("text-muted-foreground text-sm",e),...t}));dn.displayName=Ns.displayName;const li=zg,ef=Pg,ci=Og,xr=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(dd,{ref:r,className:W("border-input ring-offset-background placeholder:text-muted-foreground focus:ring-ring flex min-h-9 w-full min-w-0 items-center justify-between gap-2 rounded-sm border bg-background px-3 py-2 text-sm shadow-xs focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:min-w-0 [&>span]:whitespace-normal [&>span]:break-words text-left cursor-pointer",e),...n,children:[t,l.jsx(Dg,{asChild:!0,children:l.jsx(ki,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));xr.displayName=dd.displayName;const tf=g.forwardRef(({className:e,...t},n)=>l.jsx(md,{ref:n,className:W("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(Qg,{className:"h-4 w-4"})}));tf.displayName=md.displayName;const nf=g.forwardRef(({className:e,...t},n)=>l.jsx(gd,{ref:n,className:W("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(ki,{className:"h-4 w-4"})}));nf.displayName=gd.displayName;const yr=g.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>l.jsx(Rg,{children:l.jsxs(fd,{ref:i,className:W("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-lg border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[l.jsx(tf,{}),l.jsx($g,{className:W("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),l.jsx(nf,{})]})}));yr.displayName=fd.displayName;const ka=g.forwardRef(({className:e,...t},n)=>l.jsx(hd,{ref:n,className:W("px-2 py-1.5 text-sm font-semibold",e),...t}));ka.displayName=hd.displayName;const Mn=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(pd,{ref:r,className:W("focus:bg-accent focus:text-accent-foreground relative flex w-full cursor-pointer items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[l.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Mg,{children:l.jsx(un,{className:"h-4 w-4"})})}),l.jsx(Fg,{children:t})]}));Mn.displayName=pd.displayName;const Yx=g.forwardRef(({className:e,...t},n)=>l.jsx(xd,{ref:n,className:W("bg-muted -mx-1 my-1 h-px",e),...t}));Yx.displayName=xd.displayName;const br=g.forwardRef(({className:e,type:t,...n},r)=>l.jsx("input",{type:t,className:W("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-sm border bg-background px-3 py-1 text-sm shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));br.displayName="Input";const Xx=Si("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Xr=g.forwardRef(({className:e,...t},n)=>l.jsx(yd,{ref:n,className:W(Xx(),e),...t}));Xr.displayName=yd.displayName;const Qx=Si("inline-flex items-center rounded-md border px-2.5 py-1 text-xs font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function tn({className:e,variant:t,...n}){return l.jsx("div",{className:W(Qx({variant:t}),e),...n})}const ey=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:o}=ke(wa(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),a=g.useContext(xa),{toast:c}=_r(),u=g.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[d,f]=g.useState(""),[h,p]=g.useState(""),[m,v]=g.useState("playground"),[k,y]=g.useState(!1),[_,x]=g.useState(null),[A,E]=g.useState(null),[w,S]=g.useState(null),O=()=>{x(null),E(null),S(null)};g.useEffect(()=>{if(!e)return;x(null),E(null),S(null);const T=u.map($=>$.name),F=T.includes(i)?i:T[0]??"";p(F),f(T.find($=>$!==F)??"")},[e]);const B=async()=>{const T=u.find($=>$.name===d),F=u.find($=>$.name===h);if(!(!T||!F)){y(!0),x(null),E(null),S(null);try{const $=a?dg(a.getState().customThemes):{},[Z,P]=await Promise.all([Ro(T.text,{customThemes:$}),Ro(F.text,{customThemes:$})]),J=await fetch(oi.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:Z.text,newDefinition:P.text,options:{author:m||"playground"}})}),V=await J.json();if(!J.ok||!V.success){const X=Array.isArray(V.errors)?`: ${V.errors.slice(0,3).map(j=>j.message||String(j)).join("; ")}`:"";throw new Error((V.error||`Diff failed (${J.status})`)+X)}E(V.data.summary),S(V.data.document)}catch($){x($ instanceof Error?$.message:"Diff failed")}finally{y(!1)}}},N=()=>{if(!w)return;const T=new Set(n.map(Z=>Z.name));let F=`${h}-redline`,$=2;for(;T.has(F);)F=`${h}-redline-${$++}`;s(F,JSON.stringify(w,null,2)),o(F),c({title:`Redline created: ${F}`}),t(!1)},R=A?A.tracked.modified+A.tracked.inserted+A.tracked.deleted:0;return l.jsx(ct,{open:e,onOpenChange:t,children:l.jsxs(lt,{className:"sm:max-w-[560px]",children:[l.jsxs(qt,{children:[l.jsxs(Gt,{className:"flex items-center gap-2",children:[l.jsx(Vd,{className:"size-4"}),"Compare documents"]}),l.jsx(dn,{children:"Diff two versions into a redline with native Word tracked changes (accept/reject in Word)."})]}),l.jsxs("div",{className:"grid gap-4 py-2",children:[l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsxs("div",{className:"grid gap-1.5",children:[l.jsx(Xr,{htmlFor:"diff-base",children:"Base (old)"}),l.jsxs(li,{value:d,onValueChange:T=>{f(T),O()},children:[l.jsx(xr,{id:"diff-base",children:l.jsx(ci,{placeholder:"Select document"})}),l.jsx(yr,{children:u.map(T=>l.jsx(Mn,{value:T.name,children:T.name},T.name))})]})]}),l.jsxs("div",{className:"grid gap-1.5",children:[l.jsx(Xr,{htmlFor:"diff-revised",children:"Revised (new)"}),l.jsxs(li,{value:h,onValueChange:T=>{p(T),O()},children:[l.jsx(xr,{id:"diff-revised",children:l.jsx(ci,{placeholder:"Select document"})}),l.jsx(yr,{children:u.map(T=>l.jsx(Mn,{value:T.name,children:T.name},T.name))})]})]})]}),l.jsxs("div",{className:"grid gap-1.5",children:[l.jsx(Xr,{htmlFor:"diff-author",children:"Revision author"}),l.jsx(br,{id:"diff-author",value:m,onChange:T=>{v(T.target.value),O()},placeholder:"playground"})]}),_&&l.jsx("p",{className:"text-sm text-destructive",role:"alert",children:_}),A&&l.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsxs(tn,{variant:"secondary",children:[A.tracked.inserted," inserted"]}),l.jsxs(tn,{variant:"secondary",children:[A.tracked.deleted," deleted"]}),l.jsxs(tn,{variant:"secondary",children:[A.tracked.modified," modified"]}),l.jsxs("span",{className:"text-muted-foreground text-xs",children:[A.unchangedBlocks," blocks unchanged"]})]}),R===0&&A.untracked.length===0&&l.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),A.untracked.length>0&&l.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[l.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[A.untracked.length," change(s) not expressible as tracked changes:"]}),A.untracked.map((T,F)=>l.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},F))]}),A.notes.map((T,F)=>l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},F))]})]}),l.jsx(kn,{children:A&&R+A.untracked.length>0?l.jsxs(Ce,{onClick:N,children:[l.jsx(ex,{className:"size-4 mr-1"}),"Open redline"]}):l.jsxs(Ce,{onClick:B,disabled:k||!d||!h||d===h,children:[k&&l.jsx(cn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var ji=e=>e.type==="checkbox",On=e=>e instanceof Date,gt=e=>e==null;const rf=e=>typeof e=="object";var nt=e=>!gt(e)&&!Array.isArray(e)&&rf(e)&&!On(e),sf=e=>nt(e)&&e.target?ji(e.target)?e.target.checked:e.target.value:e,ty=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,of=(e,t)=>e.has(ty(t)),ny=e=>{const t=e.constructor&&e.constructor.prototype;return nt(t)&&t.hasOwnProperty("isPrototypeOf")},Sa=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function wt(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(Sa&&(e instanceof Blob||r))&&(n||nt(e)))if(t=n?[]:{},!n&&!ny(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=wt(e[i]));else return e;return t}var Ts=e=>Array.isArray(e)?e.filter(Boolean):[],tt=e=>e===void 0,ue=(e,t,n)=>{if(!t||!nt(e))return n;const r=Ts(t.split(/[,[\].]+?/)).reduce((i,s)=>gt(i)?i:i[s],e);return tt(r)||r===e?tt(e[t])?n:e[t]:r},Rt=e=>typeof e=="boolean",ja=e=>/^\w*$/.test(e),af=e=>Ts(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Le=(e,t,n)=>{let r=-1;const i=ja(t)?[t]:af(t),s=i.length,o=s-1;for(;++r<s;){const a=i[r];let c=n;if(r!==o){const u=e[a];c=nt(u)||Array.isArray(u)?u:isNaN(+i[r+1])?{}:[]}if(a==="__proto__"||a==="constructor"||a==="prototype")return;e[a]=c,e=e[a]}return e};const ts={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ut={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},sn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},lf=je.createContext(null),Is=()=>je.useContext(lf),ry=e=>{const{children:t,...n}=e;return je.createElement(lf.Provider,{value:n},t)};var cf=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const o=s;return t._proxyFormState[o]!==Ut.all&&(t._proxyFormState[o]=!r||Ut.all),n&&(n[o]=!0),e[o]}});return i},kt=e=>nt(e)&&!Object.keys(e).length,uf=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return kt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(o=>t[o]===(!r||Ut.all))},Qr=e=>Array.isArray(e)?e:[e],df=(e,t,n)=>!e||!t||e===t||Qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function _a(e){const t=je.useRef(e);t.current=e,je.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function iy(e){const t=Is(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[o,a]=je.useState(n._formState),c=je.useRef(!0),u=je.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=je.useRef(i);return d.current=i,_a({disabled:r,next:f=>c.current&&df(d.current,f.name,s)&&uf(f,u.current,n._updateFormState)&&a({...n._formState,...f}),subject:n._subjects.state}),je.useEffect(()=>(c.current=!0,u.current.isValid&&n._updateValid(!0),()=>{c.current=!1}),[n]),je.useMemo(()=>cf(o,n,u.current,!1),[o,n])}var en=e=>typeof e=="string",ff=(e,t,n,r,i)=>en(e)?(r&&t.watch.add(e),ue(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),ue(n,s))):(r&&(t.watchAll=!0),n);function sy(e){const t=Is(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:o}=e||{},a=je.useRef(r);a.current=r,_a({disabled:s,subject:n._subjects.values,next:d=>{df(a.current,d.name,o)&&u(wt(ff(a.current,n._names,d.values||n._formValues,!1,i)))}});const[c,u]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),c}function oy(e){const t=Is(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,o=of(i._names.array,n),a=sy({control:i,name:n,defaultValue:ue(i._formValues,n,ue(i._defaultValues,n,e.defaultValue)),exact:!0}),c=iy({control:i,name:n,exact:!0}),u=je.useRef(i.register(n,{...e.rules,value:a,...Rt(e.disabled)?{disabled:e.disabled}:{}})),d=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ue(c.errors,n)},isDirty:{enumerable:!0,get:()=>!!ue(c.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ue(c.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ue(c.validatingFields,n)},error:{enumerable:!0,get:()=>ue(c.errors,n)}}),[c,n]),f=je.useMemo(()=>({name:n,value:a,...Rt(r)||c.disabled?{disabled:c.disabled||r}:{},onChange:h=>u.current.onChange({target:{value:sf(h),name:n},type:ts.CHANGE}),onBlur:()=>u.current.onBlur({target:{value:ue(i._formValues,n),name:n},type:ts.BLUR}),ref:h=>{const p=ue(i._fields,n);p&&h&&(p._f.ref={focus:()=>h.focus(),select:()=>h.select(),setCustomValidity:m=>h.setCustomValidity(m),reportValidity:()=>h.reportValidity()})}}),[n,i._formValues,r,c.disabled,a,i._fields]);return je.useEffect(()=>{const h=i._options.shouldUnregister||s,p=(m,v)=>{const k=ue(i._fields,m);k&&k._f&&(k._f.mount=v)};if(p(n,!0),h){const m=wt(ue(i._options.defaultValues,n));Le(i._defaultValues,n,m),tt(ue(i._formValues,n))&&Le(i._formValues,n,m)}return!o&&i.register(n),()=>{(o?h&&!i._state.action:h)?i.unregister(n):p(n,!1)}},[n,i,o,s]),je.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),je.useMemo(()=>({field:f,formState:c,fieldState:d}),[f,c,d])}const ay=e=>e.render(oy(e));var ly=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},kl=e=>({isOnSubmit:!e||e===Ut.onSubmit,isOnBlur:e===Ut.onBlur,isOnChange:e===Ut.onChange,isOnAll:e===Ut.all,isOnTouch:e===Ut.onTouched}),Sl=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const ei=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=ue(e,i);if(s){const{_f:o,...a}=s;if(o){if(o.refs&&o.refs[0]&&t(o.refs[0],i)&&!r)return!0;if(o.ref&&t(o.ref,o.name)&&!r)return!0;if(ei(a,t))break}else if(nt(a)&&ei(a,t))break}}};var cy=(e,t,n)=>{const r=Qr(ue(e,n));return Le(r,"root",t[n]),Le(e,n,r),e},Na=e=>e.type==="file",Qt=e=>typeof e=="function",ns=e=>{if(!Sa)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Wi=e=>en(e),Ca=e=>e.type==="radio",rs=e=>e instanceof RegExp;const jl={value:!1,isValid:!1},_l={value:!0,isValid:!0};var pf=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!tt(e[0].attributes.value)?tt(e[0].value)||e[0].value===""?_l:{value:e[0].value,isValid:!0}:_l:jl}return jl};const Nl={isValid:!1,value:null};var hf=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Nl):Nl;function Cl(e,t,n="validate"){if(Wi(e)||Array.isArray(e)&&e.every(Wi)||Rt(e)&&!e)return{type:n,message:Wi(e)?e:"",ref:t}}var Jn=e=>nt(e)&&!rs(e)?e:{value:e,message:""},El=async(e,t,n,r,i,s)=>{const{ref:o,refs:a,required:c,maxLength:u,minLength:d,min:f,max:h,pattern:p,validate:m,name:v,valueAsNumber:k,mount:y}=e._f,_=ue(n,v);if(!y||t.has(v))return{};const x=a?a[0]:o,A=T=>{i&&x.reportValidity&&(x.setCustomValidity(Rt(T)?"":T||""),x.reportValidity())},E={},w=Ca(o),S=ji(o),O=w||S,B=(k||Na(o))&&tt(o.value)&&tt(_)||ns(o)&&o.value===""||_===""||Array.isArray(_)&&!_.length,N=ly.bind(null,v,r,E),R=(T,F,$,Z=sn.maxLength,P=sn.minLength)=>{const J=T?F:$;E[v]={type:T?Z:P,message:J,ref:o,...N(T?Z:P,J)}};if(s?!Array.isArray(_)||!_.length:c&&(!O&&(B||gt(_))||Rt(_)&&!_||S&&!pf(a).isValid||w&&!hf(a).isValid)){const{value:T,message:F}=Wi(c)?{value:!!c,message:c}:Jn(c);if(T&&(E[v]={type:sn.required,message:F,ref:x,...N(sn.required,F)},!r))return A(F),E}if(!B&&(!gt(f)||!gt(h))){let T,F;const $=Jn(h),Z=Jn(f);if(!gt(_)&&!isNaN(_)){const P=o.valueAsNumber||_&&+_;gt($.value)||(T=P>$.value),gt(Z.value)||(F=P<Z.value)}else{const P=o.valueAsDate||new Date(_),J=j=>new Date(new Date().toDateString()+" "+j),V=o.type=="time",X=o.type=="week";en($.value)&&_&&(T=V?J(_)>J($.value):X?_>$.value:P>new Date($.value)),en(Z.value)&&_&&(F=V?J(_)<J(Z.value):X?_<Z.value:P<new Date(Z.value))}if((T||F)&&(R(!!T,$.message,Z.message,sn.max,sn.min),!r))return A(E[v].message),E}if((u||d)&&!B&&(en(_)||s&&Array.isArray(_))){const T=Jn(u),F=Jn(d),$=!gt(T.value)&&_.length>+T.value,Z=!gt(F.value)&&_.length<+F.value;if(($||Z)&&(R($,T.message,F.message),!r))return A(E[v].message),E}if(p&&!B&&en(_)){const{value:T,message:F}=Jn(p);if(rs(T)&&!_.match(T)&&(E[v]={type:sn.pattern,message:F,ref:o,...N(sn.pattern,F)},!r))return A(F),E}if(m){if(Qt(m)){const T=await m(_,n),F=Cl(T,x);if(F&&(E[v]={...F,...N(sn.validate,F.message)},!r))return A(F.message),E}else if(nt(m)){let T={};for(const F in m){if(!kt(T)&&!r)break;const $=Cl(await m[F](_,n),x,F);$&&(T={...$,...N(F,$.message)},A($.message),r&&(E[v]=T))}if(!kt(T)&&(E[v]={ref:x,...T},!r))return E}}return A(!0),E};function uy(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=tt(e)?r++:e[t[r++]];return e}function dy(e){for(const t in e)if(e.hasOwnProperty(t)&&!tt(e[t]))return!1;return!0}function st(e,t){const n=Array.isArray(t)?t:ja(t)?[t]:af(t),r=n.length===1?e:uy(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(nt(r)&&kt(r)||Array.isArray(r)&&dy(r))&&st(e,n.slice(0,-1)),e}var Ys=()=>{let e=[];return{get observers(){return e},next:i=>{for(const s of e)s.next&&s.next(i)},subscribe:i=>(e.push(i),{unsubscribe:()=>{e=e.filter(s=>s!==i)}}),unsubscribe:()=>{e=[]}}},$o=e=>gt(e)||!rf(e);function xn(e,t){if($o(e)||$o(t))return e===t;if(On(e)&&On(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const s=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const o=t[i];if(On(s)&&On(o)||nt(s)&&nt(o)||Array.isArray(s)&&Array.isArray(o)?!xn(s,o):s!==o)return!1}}return!0}var mf=e=>e.type==="select-multiple",fy=e=>Ca(e)||ji(e),Xs=e=>ns(e)&&e.isConnected,gf=e=>{for(const t in e)if(Qt(e[t]))return!0;return!1};function is(e,t={}){const n=Array.isArray(e);if(nt(e)||n)for(const r in e)Array.isArray(e[r])||nt(e[r])&&!gf(e[r])?(t[r]=Array.isArray(e[r])?[]:{},is(e[r],t[r])):gt(e[r])||(t[r]=!0);return t}function xf(e,t,n){const r=Array.isArray(e);if(nt(e)||r)for(const i in e)Array.isArray(e[i])||nt(e[i])&&!gf(e[i])?tt(t)||$o(n[i])?n[i]=Array.isArray(e[i])?is(e[i],[]):{...is(e[i])}:xf(e[i],gt(t)?{}:t[i],n[i]):n[i]=!xn(e[i],t[i]);return n}var Rr=(e,t)=>xf(e,t,is(t)),yf=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>tt(e)?e:t?e===""?NaN:e&&+e:n&&en(e)?new Date(e):r?r(e):e;function Qs(e){const t=e.ref;return Na(t)?t.files:Ca(t)?hf(e.refs).value:mf(t)?[...t.selectedOptions].map(({value:n})=>n):ji(t)?pf(e.refs).value:yf(tt(t.value)?e.ref.value:t.value,e)}var py=(e,t,n,r)=>{const i={};for(const s of e){const o=ue(t,s);o&&Le(i,s,o._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},$r=e=>tt(e)?e:rs(e)?e.source:nt(e)?rs(e.value)?e.value.source:e.value:e;const Tl="AsyncFunction";var hy=e=>!!e&&!!e.validate&&!!(Qt(e.validate)&&e.validate.constructor.name===Tl||nt(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Tl)),my=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Il(e,t,n){const r=ue(e,n);if(r||ja(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),o=ue(t,s),a=ue(e,s);if(o&&!Array.isArray(o)&&n!==s)return{name:n};if(a&&a.type)return{name:s,error:a};i.pop()}return{name:n}}var gy=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,xy=(e,t)=>!Ts(ue(e,t)).length&&st(e,t);const yy={mode:Ut.onSubmit,reValidateMode:Ut.onChange,shouldFocusError:!0};function by(e={}){let t={...yy,...e},n={submitCount:0,isDirty:!1,isLoading:Qt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=nt(t.defaultValues)||nt(t.values)?wt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:wt(i),o={action:!1,mount:!1,watch:!1},a={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},c,u=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Ys(),array:Ys(),state:Ys()},h=kl(t.mode),p=kl(t.reValidateMode),m=t.criteriaMode===Ut.all,v=C=>z=>{clearTimeout(u),u=setTimeout(C,z)},k=async C=>{if(!t.disabled&&(d.isValid||C)){const z=t.resolver?kt((await O()).errors):await N(r,!0);z!==n.isValid&&f.state.next({isValid:z})}},y=(C,z)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((C||Array.from(a.mount)).forEach(L=>{L&&(z?Le(n.validatingFields,L,z):st(n.validatingFields,L))}),f.state.next({validatingFields:n.validatingFields,isValidating:!kt(n.validatingFields)}))},_=(C,z=[],L,se,ie=!0,ee=!0)=>{if(se&&L&&!t.disabled){if(o.action=!0,ee&&Array.isArray(ue(r,C))){const me=L(ue(r,C),se.argA,se.argB);ie&&Le(r,C,me)}if(ee&&Array.isArray(ue(n.errors,C))){const me=L(ue(n.errors,C),se.argA,se.argB);ie&&Le(n.errors,C,me),xy(n.errors,C)}if(d.touchedFields&&ee&&Array.isArray(ue(n.touchedFields,C))){const me=L(ue(n.touchedFields,C),se.argA,se.argB);ie&&Le(n.touchedFields,C,me)}d.dirtyFields&&(n.dirtyFields=Rr(i,s)),f.state.next({name:C,isDirty:T(C,z),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Le(s,C,z)},x=(C,z)=>{Le(n.errors,C,z),f.state.next({errors:n.errors})},A=C=>{n.errors=C,f.state.next({errors:n.errors,isValid:!1})},E=(C,z,L,se)=>{const ie=ue(r,C);if(ie){const ee=ue(s,C,tt(L)?ue(i,C):L);tt(ee)||se&&se.defaultChecked||z?Le(s,C,z?ee:Qs(ie._f)):Z(C,ee),o.mount&&k()}},w=(C,z,L,se,ie)=>{let ee=!1,me=!1;const we={name:C};if(!t.disabled){const U=!!(ue(r,C)&&ue(r,C)._f&&ue(r,C)._f.disabled);if(!L||se){d.isDirty&&(me=n.isDirty,n.isDirty=we.isDirty=T(),ee=me!==we.isDirty);const Y=U||xn(ue(i,C),z);me=!!(!U&&ue(n.dirtyFields,C)),Y||U?st(n.dirtyFields,C):Le(n.dirtyFields,C,!0),we.dirtyFields=n.dirtyFields,ee=ee||d.dirtyFields&&me!==!Y}if(L){const Y=ue(n.touchedFields,C);Y||(Le(n.touchedFields,C,L),we.touchedFields=n.touchedFields,ee=ee||d.touchedFields&&Y!==L)}ee&&ie&&f.state.next(we)}return ee?we:{}},S=(C,z,L,se)=>{const ie=ue(n.errors,C),ee=d.isValid&&Rt(z)&&n.isValid!==z;if(t.delayError&&L?(c=v(()=>x(C,L)),c(t.delayError)):(clearTimeout(u),c=null,L?Le(n.errors,C,L):st(n.errors,C)),(L?!xn(ie,L):ie)||!kt(se)||ee){const me={...se,...ee&&Rt(z)?{isValid:z}:{},errors:n.errors,name:C};n={...n,...me},f.state.next(me)}},O=async C=>{y(C,!0);const z=await t.resolver(s,t.context,py(C||a.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return y(C),z},B=async C=>{const{errors:z}=await O(C);if(C)for(const L of C){const se=ue(z,L);se?Le(n.errors,L,se):st(n.errors,L)}else n.errors=z;return z},N=async(C,z,L={valid:!0})=>{for(const se in C){const ie=C[se];if(ie){const{_f:ee,...me}=ie;if(ee){const we=a.array.has(ee.name),U=ie._f&&hy(ie._f);U&&d.validatingFields&&y([se],!0);const Y=await El(ie,a.disabled,s,m,t.shouldUseNativeValidation&&!z,we);if(U&&d.validatingFields&&y([se]),Y[ee.name]&&(L.valid=!1,z))break;!z&&(ue(Y,ee.name)?we?cy(n.errors,Y,ee.name):Le(n.errors,ee.name,Y[ee.name]):st(n.errors,ee.name))}!kt(me)&&await N(me,z,L)}}return L.valid},R=()=>{for(const C of a.unMount){const z=ue(r,C);z&&(z._f.refs?z._f.refs.every(L=>!Xs(L)):!Xs(z._f.ref))&&Q(C)}a.unMount=new Set},T=(C,z)=>!t.disabled&&(C&&z&&Le(s,C,z),!xn(ye(),i)),F=(C,z,L)=>ff(C,a,{...o.mount?s:tt(z)?i:en(C)?{[C]:z}:z},L,z),$=C=>Ts(ue(o.mount?s:i,C,t.shouldUnregister?ue(i,C,[]):[])),Z=(C,z,L={})=>{const se=ue(r,C);let ie=z;if(se){const ee=se._f;ee&&(!ee.disabled&&Le(s,C,yf(z,ee)),ie=ns(ee.ref)&&gt(z)?"":z,mf(ee.ref)?[...ee.ref.options].forEach(me=>me.selected=ie.includes(me.value)):ee.refs?ji(ee.ref)?ee.refs.length>1?ee.refs.forEach(me=>(!me.defaultChecked||!me.disabled)&&(me.checked=Array.isArray(ie)?!!ie.find(we=>we===me.value):ie===me.value)):ee.refs[0]&&(ee.refs[0].checked=!!ie):ee.refs.forEach(me=>me.checked=me.value===ie):Na(ee.ref)?ee.ref.value="":(ee.ref.value=ie,ee.ref.type||f.values.next({name:C,values:{...s}})))}(L.shouldDirty||L.shouldTouch)&&w(C,ie,L.shouldTouch,L.shouldDirty,!0),L.shouldValidate&&j(C)},P=(C,z,L)=>{for(const se in z){const ie=z[se],ee=`${C}.${se}`,me=ue(r,ee);(a.array.has(C)||nt(ie)||me&&!me._f)&&!On(ie)?P(ee,ie,L):Z(ee,ie,L)}},J=(C,z,L={})=>{const se=ue(r,C),ie=a.array.has(C),ee=wt(z);Le(s,C,ee),ie?(f.array.next({name:C,values:{...s}}),(d.isDirty||d.dirtyFields)&&L.shouldDirty&&f.state.next({name:C,dirtyFields:Rr(i,s),isDirty:T(C,ee)})):se&&!se._f&&!gt(ee)?P(C,ee,L):Z(C,ee,L),Sl(C,a)&&f.state.next({...n}),f.values.next({name:o.mount?C:void 0,values:{...s}})},V=async C=>{o.mount=!0;const z=C.target;let L=z.name,se=!0;const ie=ue(r,L),ee=()=>z.type?Qs(ie._f):sf(C),me=we=>{se=Number.isNaN(we)||On(we)&&isNaN(we.getTime())||xn(we,ue(s,L,we))};if(ie){let we,U;const Y=ee(),ge=C.type===ts.BLUR||C.type===ts.FOCUS_OUT,_e=!my(ie._f)&&!t.resolver&&!ue(n.errors,L)&&!ie._f.deps||gy(ge,ue(n.touchedFields,L),n.isSubmitted,p,h),M=Sl(L,a,ge);Le(s,L,Y),ge?(ie._f.onBlur&&ie._f.onBlur(C),c&&c(0)):ie._f.onChange&&ie._f.onChange(C);const D=w(L,Y,ge,!1),xe=!kt(D)||M;if(!ge&&f.values.next({name:L,type:C.type,values:{...s}}),_e)return d.isValid&&(t.mode==="onBlur"&&ge?k():ge||k()),xe&&f.state.next({name:L,...M?{}:D});if(!ge&&M&&f.state.next({...n}),t.resolver){const{errors:de}=await O([L]);if(me(Y),se){const Me=Il(n.errors,r,L),Je=Il(de,r,Me.name||L);we=Je.error,L=Je.name,U=kt(de)}}else y([L],!0),we=(await El(ie,a.disabled,s,m,t.shouldUseNativeValidation))[L],y([L]),me(Y),se&&(we?U=!1:d.isValid&&(U=await N(r,!0)));se&&(ie._f.deps&&j(ie._f.deps),S(L,U,we,D))}},X=(C,z)=>{if(ue(n.errors,z)&&C.focus)return C.focus(),1},j=async(C,z={})=>{let L,se;const ie=Qr(C);if(t.resolver){const ee=await B(tt(C)?C:ie);L=kt(ee),se=C?!ie.some(me=>ue(ee,me)):L}else C?(se=(await Promise.all(ie.map(async ee=>{const me=ue(r,ee);return await N(me&&me._f?{[ee]:me}:me)}))).every(Boolean),!(!se&&!n.isValid)&&k()):se=L=await N(r);return f.state.next({...!en(C)||d.isValid&&L!==n.isValid?{}:{name:C},...t.resolver||!C?{isValid:L}:{},errors:n.errors}),z.shouldFocus&&!se&&ei(r,X,C?ie:a.mount),se},ye=C=>{const z={...o.mount?s:i};return tt(C)?z:en(C)?ue(z,C):C.map(L=>ue(z,L))},ce=(C,z)=>({invalid:!!ue((z||n).errors,C),isDirty:!!ue((z||n).dirtyFields,C),error:ue((z||n).errors,C),isValidating:!!ue(n.validatingFields,C),isTouched:!!ue((z||n).touchedFields,C)}),b=C=>{C&&Qr(C).forEach(z=>st(n.errors,z)),f.state.next({errors:C?n.errors:{}})},G=(C,z,L)=>{const se=(ue(r,C,{_f:{}})._f||{}).ref,ie=ue(n.errors,C)||{},{ref:ee,message:me,type:we,...U}=ie;Le(n.errors,C,{...U,...z,ref:se}),f.state.next({name:C,errors:n.errors,isValid:!1}),L&&L.shouldFocus&&se&&se.focus&&se.focus()},ne=(C,z)=>Qt(C)?f.values.subscribe({next:L=>C(F(void 0,z),L)}):F(C,z,!0),Q=(C,z={})=>{for(const L of C?Qr(C):a.mount)a.mount.delete(L),a.array.delete(L),z.keepValue||(st(r,L),st(s,L)),!z.keepError&&st(n.errors,L),!z.keepDirty&&st(n.dirtyFields,L),!z.keepTouched&&st(n.touchedFields,L),!z.keepIsValidating&&st(n.validatingFields,L),!t.shouldUnregister&&!z.keepDefaultValue&&st(i,L);f.values.next({values:{...s}}),f.state.next({...n,...z.keepDirty?{isDirty:T()}:{}}),!z.keepIsValid&&k()},oe=({disabled:C,name:z,field:L,fields:se})=>{(Rt(C)&&o.mount||C||a.disabled.has(z))&&(C?a.disabled.add(z):a.disabled.delete(z),w(z,Qs(L?L._f:ue(se,z)._f),!1,!1,!0))},I=(C,z={})=>{let L=ue(r,C);const se=Rt(z.disabled)||Rt(t.disabled);return Le(r,C,{...L||{},_f:{...L&&L._f?L._f:{ref:{name:C}},name:C,mount:!0,...z}}),a.mount.add(C),L?oe({field:L,disabled:Rt(z.disabled)?z.disabled:t.disabled,name:C}):E(C,!0,z.value),{...se?{disabled:z.disabled||t.disabled}:{},...t.progressive?{required:!!z.required,min:$r(z.min),max:$r(z.max),minLength:$r(z.minLength),maxLength:$r(z.maxLength),pattern:$r(z.pattern)}:{},name:C,onChange:V,onBlur:V,ref:ie=>{if(ie){I(C,z),L=ue(r,C);const ee=tt(ie.value)&&ie.querySelectorAll&&ie.querySelectorAll("input,select,textarea")[0]||ie,me=fy(ee),we=L._f.refs||[];if(me?we.find(U=>U===ee):ee===L._f.ref)return;Le(r,C,{_f:{...L._f,...me?{refs:[...we.filter(Xs),ee,...Array.isArray(ue(i,C))?[{}]:[]],ref:{type:ee.type,name:C}}:{ref:ee}}}),E(C,!1,void 0,ee)}else L=ue(r,C,{}),L._f&&(L._f.mount=!1),(t.shouldUnregister||z.shouldUnregister)&&!(of(a.array,C)&&o.action)&&a.unMount.add(C)}}},re=()=>t.shouldFocusError&&ei(r,X,a.mount),ae=C=>{Rt(C)&&(f.state.next({disabled:C}),ei(r,(z,L)=>{const se=ue(r,L);se&&(z.disabled=se._f.disabled||C,Array.isArray(se._f.refs)&&se._f.refs.forEach(ie=>{ie.disabled=se._f.disabled||C}))},0,!1))},H=(C,z)=>async L=>{let se;L&&(L.preventDefault&&L.preventDefault(),L.persist&&L.persist());let ie=wt(s);if(a.disabled.size)for(const ee of a.disabled)Le(ie,ee,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:ee,values:me}=await O();n.errors=ee,ie=me}else await N(r);if(st(n.errors,"root"),kt(n.errors)){f.state.next({errors:{}});try{await C(ie,L)}catch(ee){se=ee}}else z&&await z({...n.errors},L),re(),setTimeout(re);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:kt(n.errors)&&!se,submitCount:n.submitCount+1,errors:n.errors}),se)throw se},K=(C,z={})=>{ue(r,C)&&(tt(z.defaultValue)?J(C,wt(ue(i,C))):(J(C,z.defaultValue),Le(i,C,wt(z.defaultValue))),z.keepTouched||st(n.touchedFields,C),z.keepDirty||(st(n.dirtyFields,C),n.isDirty=z.defaultValue?T(C,wt(ue(i,C))):T()),z.keepError||(st(n.errors,C),d.isValid&&k()),f.state.next({...n}))},pe=(C,z={})=>{const L=C?wt(C):i,se=wt(L),ie=kt(C),ee=ie?i:se;if(z.keepDefaultValues||(i=L),!z.keepValues){if(z.keepDirtyValues){const me=new Set([...a.mount,...Object.keys(Rr(i,s))]);for(const we of Array.from(me))ue(n.dirtyFields,we)?Le(ee,we,ue(s,we)):J(we,ue(ee,we))}else{if(Sa&&tt(C))for(const me of a.mount){const we=ue(r,me);if(we&&we._f){const U=Array.isArray(we._f.refs)?we._f.refs[0]:we._f.ref;if(ns(U)){const Y=U.closest("form");if(Y){Y.reset();break}}}}r={}}s=t.shouldUnregister?z.keepDefaultValues?wt(i):{}:wt(ee),f.array.next({values:{...ee}}),f.values.next({values:{...ee}})}a={mount:z.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!d.isValid||!!z.keepIsValid||!!z.keepDirtyValues,o.watch=!!t.shouldUnregister,f.state.next({submitCount:z.keepSubmitCount?n.submitCount:0,isDirty:ie?!1:z.keepDirty?n.isDirty:!!(z.keepDefaultValues&&!xn(C,i)),isSubmitted:z.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ie?{}:z.keepDirtyValues?z.keepDefaultValues&&s?Rr(i,s):n.dirtyFields:z.keepDefaultValues&&C?Rr(i,C):z.keepDirty?n.dirtyFields:{},touchedFields:z.keepTouched?n.touchedFields:{},errors:z.keepErrors?n.errors:{},isSubmitSuccessful:z.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},fe=(C,z)=>pe(Qt(C)?C(s):C,z);return{control:{register:I,unregister:Q,getFieldState:ce,handleSubmit:H,setError:G,_executeSchema:O,_getWatch:F,_getDirty:T,_updateValid:k,_removeUnmounted:R,_updateFieldArray:_,_updateDisabledField:oe,_getFieldArray:$,_reset:pe,_resetDefaultValues:()=>Qt(t.defaultValues)&&t.defaultValues().then(C=>{fe(C,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:C=>{n={...n,...C}},_disableForm:ae,_subjects:f,_proxyFormState:d,_setErrors:A,get _fields(){return r},get _formValues(){return s},get _state(){return o},set _state(C){o=C},get _defaultValues(){return i},get _names(){return a},set _names(C){a=C},get _formState(){return n},set _formState(C){n=C},get _options(){return t},set _options(C){t={...t,...C}}},trigger:j,register:I,handleSubmit:H,watch:ne,setValue:J,getValues:ye,reset:fe,resetField:K,clearErrors:b,unregister:Q,setError:G,setFocus:(C,z={})=>{const L=ue(r,C),se=L&&L._f;if(se){const ie=se.refs?se.refs[0]:se.ref;ie.focus&&(ie.focus(),z.shouldSelect&&Qt(ie.select)&&ie.select())}},getFieldState:ce}}function vy(e={}){const t=je.useRef(void 0),n=je.useRef(void 0),[r,i]=je.useState({isDirty:!1,isValidating:!1,isLoading:Qt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Qt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...by(e),formState:r});const s=t.current.control;return s._options=e,_a({subject:s._subjects.state,next:o=>{uf(o,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),je.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),je.useEffect(()=>{if(s._proxyFormState.isDirty){const o=s._getDirty();o!==r.isDirty&&s._subjects.state.next({isDirty:o})}},[s,r.isDirty]),je.useEffect(()=>{e.values&&!xn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(o=>({...o}))):s._resetDefaultValues()},[e.values,s]),je.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),je.useEffect(()=>{s._state.mount||(s._updateValid(),s._state.mount=!0),s._state.watch&&(s._state.watch=!1,s._subjects.state.next({...s._formState})),s._removeUnmounted()}),je.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=cf(r,s),t.current}function wy(e){return async t=>{const n=e(t);if(n.success&&n.data)return{values:n.data,errors:{}};const r={};if(n.errors)for(const i of n.errors){const s=i.path||"root";r[s]||(r[s]={type:"validation",message:i.message})}return{values:{},errors:r}}}const ky=ry,bf=g.createContext({}),Al=({...e})=>l.jsx(bf.Provider,{value:{name:e.name},children:l.jsx(ay,{...e})}),As=()=>{const e=g.useContext(bf),t=g.useContext(vf),{getFieldState:n,formState:r}=Is(),i=n(e.name,r);if(!e)throw new Error("useFormField should be used within <FormField>");const{id:s}=t;return{id:s,name:e.name,formItemId:`${s}-form-item`,formDescriptionId:`${s}-form-item-description`,formMessageId:`${s}-form-item-message`,...i}},vf=g.createContext({}),Mo=g.forwardRef(({className:e,...t},n)=>{const r=g.useId();return l.jsx(vf.Provider,{value:{id:r},children:l.jsx("div",{ref:n,className:W("space-y-2",e),...t})})});Mo.displayName="FormItem";const Fo=g.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=As();return l.jsx(Xr,{ref:n,className:W(r&&"text-destructive",e),htmlFor:i,...t})});Fo.displayName="FormLabel";const Lo=g.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=As();return l.jsx(Nr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Lo.displayName="FormControl";const wf=g.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=As();return l.jsx("p",{ref:n,id:r,className:W("text-muted-foreground text-[0.8rem]",e),...t})});wf.displayName="FormDescription";const Bo=g.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=As(),o=i?String(i==null?void 0:i.message):t;return o?l.jsx("p",{ref:r,id:s,className:W("text-destructive text-[0.8rem] font-medium",e),...n,children:o}):null});Bo.displayName="FormMessage";function Ea(){const e=new Date,t=n=>String(n).padStart(2,"0");return`Chat ${t(e.getMonth()+1)}/${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}const kf=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Sy=(e=kf())=>Ox()(Px(Dx((t,n)=>({...e,toggleChat:()=>t(r=>({chatOpen:!r.chatOpen})),openChat:()=>t({chatOpen:!0}),closeChat:()=>t({chatOpen:!1}),addContext:r=>t(i=>({contextAttachments:[...i.contextAttachments,r]})),removeContext:r=>t(i=>({contextAttachments:i.contextAttachments.filter((s,o)=>o!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),o={id:i,documentName:r,title:Ea(),messages:[],createdAt:s,updatedAt:s};return t(a=>({threads:{...a.threads,[i]:o},activeThreadId:{...a.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const o=Object.fromEntries(Object.entries(i.threads).filter(([u])=>u!==r)),a=s.documentName,c={...i.activeThreadId};if(c[a]===r){const u=Object.values(o).filter(d=>d.documentName===a);u.length>0?(u.sort((d,f)=>f.updatedAt-d.updatedAt),c[a]=u[0].id):delete c[a]}t({threads:o,activeThreadId:c})},switchThread:r=>{const s=n().threads[r];s&&t(o=>({activeThreadId:{...o.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},o={...i.activeThreadId};for(const[a,c]of Object.entries(s))c.documentName===r&&delete s[a];return delete o[r],{threads:s,activeThreadId:o}})},renameThreadsForDocument:(r,i)=>{t(s=>{const o={...s.threads},a={...s.activeThreadId};for(const[c,u]of Object.entries(o))u.documentName===r&&(o[c]={...u,documentName:i});return r in a&&(a[i]=a[r],delete a[r]),{threads:o,activeThreadId:a}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:2,storage:Rx(()=>fg),partialize:t=>({threads:t.threads,activeThreadId:t.activeThreadId,scope:t.scope,model:t.model}),migrate:(t,n)=>{if(n===0&&t){const r=t.chatMessages;if(Array.isArray(r)&&r.length>0){const i=crypto.randomUUID(),s=Date.now();return{threads:{[i]:{id:i,documentName:"__migrated__",title:"Migrated Chat",messages:r,createdAt:s,updatedAt:s}},activeThreadId:{__migrated__:i}}}return{threads:{},activeThreadId:{}}}return n<2&&(t==null?void 0:t.scope)==="templates"?{...t,scope:"blocks"}:t}}))),Sf=g.createContext(void 0),jy=({children:e})=>{const t=g.useRef(null);return t.current||(t.current=Sy(kf())),l.jsx(Sf.Provider,{value:t.current,children:e})},De=e=>{const t=g.useContext(Sf);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return $x(t,e)};function jf(e){return`${e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((n,r)=>r===0?n.charAt(0).toLowerCase()+n.slice(1):n.charAt(0).toUpperCase()+n.slice(1)).join("")||"custom"}Component`}function _y(e){const t=jf(e);return`import { Type } from '@sinclair/typebox';
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-BJWDd3uK.js","assets/react-vendor-BmQ2Ko_D.js","assets/editor-monaco-json-FLZpeDZL.js","assets/index-D6Nfjrjh.js","assets/query-vendor--rhYD8mC.js","assets/radix-ui-BzbaiLpZ.js","assets/ui-vendor-BsAtAN16.js","assets/monaco-editor-DJsdM0WK.js","assets/state-vendor-Cq67_JbF.js","assets/index--kF4jVbp.css","assets/index-D5Xrk4Ze.js","assets/MonacoPluginProvider-Bc9nyqNY.js","assets/useQualityAnalysis-kUkZB_mW.js","assets/preview-C4ynYVMZ.js"])))=>i.map(i=>d[i]);
2
+ var lg=Object.defineProperty;var cg=(e,t,n)=>t in e?lg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Or=(e,t,n)=>cg(e,typeof t!="symbol"?t+"":t,n);import{r as g,j as l,c as je,R as nd,g as ga}from"./react-vendor-BmQ2Ko_D.js";import{u as vn,s as rd,p as ug,a as ke,T as xa,v as dg,i as fg,b as Io,c as qs,d as an,g as pg,e as Jt,B as hg,f as gr,h as id,j as mg,k as gg,S as xg,O as yg,l as bg,M as vg,D as wg,m as kg}from"./MonacoPluginProvider-Bc9nyqNY.js";import{A as Sg,F as at,c as W,u as _r,S as cn,a as oi,T as Oi,C as jg,E as _g,b as Ng,d as Cg,e as Ye,f as Xe,g as Qe,p as Eg,h as sd,i as od,_ as ad,j as Pi,k as Tg,l as Ig,m as Ag,n as Pr,s as Gs,W as ld,o as Hi}from"./index-D6Nfjrjh.js";import{b as cd,c as ya,d as ud,e as js,f as _s,D as Ns,O as Cs,g as zg,V as Og,G as Pg,h as dd,I as Dg,i as Rg,j as fd,k as $g,l as pd,m as Mg,n as Fg,L as hd,S as md,o as gd,p as xd,q as yd,r as Nr,s as Lg,t as Bg,u as Zg,v as bd,w as vd,x as wd,y as kd,z as Sd,B as jd,E as _d,F as Nd,H as Cd,J as Vg,K as Ug,M as Jg,N as Ed,Q as Td,U as Id,W as Ad,X as zd,Y as Od,Z as Pd,_ as Dd,$ as Rd,a0 as $d,a1 as Hg,a2 as Md,a3 as Wg,a4 as qg,a5 as Fd,a6 as Gg,a7 as Kg,a8 as Yg,a9 as Xg,aa as Ld,ab as Bd,ac as Zd}from"./radix-ui-BzbaiLpZ.js";import{X as wn,C as ki,a as un,b as Qg,d as Si,G as Vd,F as ex,e as Cr,f as Ud,P as tx,g as nx,h as Jd,i as Hd,E as ba,B as Qi,H as rx,T as Ao,L as zo,j as ix,k as sx,S as Wd,I as ox,l as ax,m as Oo,n as lx,o as cx,p as ux,q as dx,r as fx,s as px,t as hx,u as mx,v as Es,w as gx,M as xx,x as Dt,y as qd,z as yx,A as bx,D as vx,J as wx,K as Gd,N as kx,O as Sx,Q as jx,R as _x,U as Nx,V as Cx,W as Kd,Y as Ex,Z as Po,_ as va,$ as Yd,a0 as Tx,a1 as Xd,a2 as Jr,a3 as Ix,a4 as Ax,a5 as zx,a6 as gl,a7 as Do}from"./ui-vendor-BsAtAN16.js";import{B as Ce,d as xl}from"./index-D5Xrk4Ze.js";import{u as wa,a as Ox,d as Px,p as Dx,b as Rx,e as $x}from"./state-vendor-Cq67_JbF.js";import{b as Mx}from"./query-vendor--rhYD8mC.js";let Di=null,Dr=null;const Fx=1e4;function Lx(e,t){return t.aborted?Promise.reject(yl(t)):new Promise((n,r)=>{const i=()=>r(yl(t));t.addEventListener("abort",i,{once:!0}),e.then(n,r).finally(()=>{t.removeEventListener("abort",i)})})}function yl(e){return e.reason??new DOMException("Aborted","AbortError")}async function Bx(e){return Di||(Dr||(Dr=(async()=>{const t=await fetch(`${Sg}/discovery/themes/builtin`,{signal:AbortSignal.timeout(Fx)});if(!t.ok)throw new Error(`Built-in themes unavailable (${t.status})`);const n=await t.json();if(!n.success||!n.data)throw new Error(n.error??"Built-in themes unavailable");return Di=n.data,Di})().finally(()=>{Dr=null})),e?Lx(Dr,e):Dr)}class hn extends Error{constructor(n,r,i){super(n);Or(this,"pluginName");Or(this,"path");this.name="PluginExpansionError",this.pluginName=r,this.path=i}}const Zx=20,Vx=1e4;function ai(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function bl(e,t){const n=new Set;if(t.size===0)return n;const r=i=>{if(Array.isArray(i)){i.forEach(r);return}ai(i)&&(typeof i.name=="string"&&t.has(i.name)&&n.add(i.name),Array.isArray(i.children)&&i.children.forEach(r))};return ai(e)&&Array.isArray(e.children)&&e.children.forEach(r),n}const Ux=/^https?:\/\/\S+/i;function es(e,t=new Set){if(typeof e=="string")Ux.test(e)&&t.add(e);else if(Array.isArray(e))for(const n of e)es(n,t);else if(ai(e))for(const n of Object.values(e))es(n,t);return t}function Jx(e,t){if(!e.startsWith("/")||t.size===0)return{path:e,insidePlugin:!1};const n=e.split("/");for(let r=n.length;r>1;r--){const i=n.slice(0,r).join("/"),s=t.get(i);if(!s)continue;if(s.synthetic)return{path:s.authored,insidePlugin:!0};const o=n.slice(r).join("/");return{path:o?`${s.authored}/${o}`:s.authored,insidePlugin:!1}}return{path:e,insidePlugin:!1}}async function Hx(e,t){const{plugins:n,theme:r,render:i,signal:s}=t,o=t.maxDepth??Zx,a=t.maxNodes??Vx,c=[],u=new Map,d=es(e);let f=0;function h(v){if(s!=null&&s.aborted)throw new hn("Expansion was cancelled",void 0,v)}async function p(v,k,y,_,x){if(k>o)throw new hn(`Maximum component nesting depth exceeded (${o}). Check for circular component references.`,void 0,y);const A=[],E=(w,S,O)=>{const B=`${_}/${A.length}`;return(O||B!==S)&&u.set(B,{authored:S,synthetic:O}),A.push(w),B};for(let w=0;w<v.length;w++){h(y);const S=v[w],O=x??`${y}/${w}`,B=x!==void 0;if(!ai(S)||typeof S.name!="string"){E(S,O,B);continue}const N=n.get(S.name);if(!N){if(Array.isArray(S.children)){const P=`${_}/${A.length}`,J=await p(S.children,k+1,`${O}/children`,`${P}/children`,B?x:void 0);E({...S,children:J},O,B)}else E(S,O,B);continue}if(S.enabled===!1)continue;if(S.props===void 0||S.props===null)throw new hn(`Custom component '${S.name}' must have a 'props' property. Use format: { name: '${S.name}', props: {...} }`,S.name,O);const R=typeof S.version=="string"?S.version:void 0;if(R!==void 0&&!N.versions.includes(R))throw new hn(`Component "${S.name}" does not have version "${R}". Available versions: ${N.versions.join(", ")}`,S.name,O);const T=Array.isArray(S.children)?await p(S.children,k+1,`${O}/children`,`${O}/children`,O):void 0,F=R?`${S.name}@${R}`:S.name;let $;try{$=await i({name:S.name,version:R,props:S.props,theme:r,children:T},s)}catch(P){throw s!=null&&s.aborted?P:new hn(`Error processing custom component '${S.name}': ${P instanceof Error?P.message:String(P)}`,S.name,O)}for(const P of $.warnings??[])c.push({component:F,message:P.message,severity:"warning",...P.context?{context:P.context}:{}});if(!Array.isArray($.components))throw new hn(`Custom component '${S.name}' must render an array of components.`,S.name,O);for(const P of es($.components))d.has(P)||c.push({component:F,message:`Plugin output references a remote source the document did not: ${P}`,severity:"warning",context:{code:"PLUGIN_REMOTE_SOURCE",url:P,path:O}});if(f+=$.components.length,f>a)throw new hn(`Plugin expansion produced more than ${a} components; stopping at '${S.name}'.`,S.name,O);const Z=await p($.components,k+1,O,_,O);for(const P of Z)E(P,O,!0)}return A}if(!ai(e)||!Array.isArray(e.children))return{document:e,warnings:c,pathMap:u};const m=await p(e.children,0,"/children","/children",void 0);return{document:{...e,children:m},warnings:c,pathMap:u}}function mt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Wx(e,t){if(!mt(t))return e;const n=mt(e.fonts)?e.fonts:{},r={...n};if(mt(t.fonts))for(const[o,a]of Object.entries(t.fonts)){const c=n[o],u=mt(c)?c:{};r[o]=mt(a)?{...u,...a}:a}const i=mt(e.styles)?e.styles:{},s={...i};if(mt(t.styles))for(const[o,a]of Object.entries(t.styles)){const c=i[o],u=mt(c)?c:{};s[o]=mt(a)?{...u,...a}:a}return{...e,colors:{...mt(e.colors)?e.colors:{},...mt(t.colors)?t.colors:{}},fonts:r,...Object.keys(s).length>0?{styles:s}:{}}}const vl={docx:"minimal",pptx:"default"};function qx(e,t){const{format:n,customThemes:r,builtinThemes:i}=t,s=mt(e)&&mt(e.props)?e.props:{},o=s.theme;if(n==="pptx"&&mt(o))return{theme:o};const a=typeof o=="string"&&o.length>0?o:vl[n];let c=r[a];if(c===void 0&&n==="docx"){const f=a.toLowerCase(),h=Object.keys(r).find(p=>p.toLowerCase()===f);h&&(c=r[h])}c===void 0&&(c=i[a]);let u;if(c===void 0){const f=vl[n],h=[...Object.keys(i),...Object.keys(r)].sort();u={message:`Theme "${a}" not found; falling back to "${f}". Available themes: ${h.join(", ")}.`,context:{code:"theme_not_found",requested:a,available:h}},c=i[f]}c===void 0&&(c=Object.values(i)[0]??{});const d=n==="docx"&&mt(c)&&s.themeOverrides?Wx(c,s.themeOverrides):c;return u?{theme:d,warning:u}:{theme:d}}const Ks=e=>({path:e,insidePlugin:!1});function Gx(e){if(!e.enabled)return"is turned off — enable it in the plugin header or the sidebar";if(e.status==="compiling"||e.status==="idle")return"is still compiling — try again in a moment";const t=e.diagnostics.filter(n=>n.severity==="error");return t.length>0?`has ${t.length} error${t.length===1?"":"s"} — open ${e.docName} to fix ${t.length===1?"it":"them"}`:`failed to load — open ${e.docName}`}async function Ro(e,t={}){var y;const n=vn.getState(),r=rd(n),i=Object.values(n.records).filter(_=>_.metadata);if(i.length===0)return{text:e,warnings:[],expanded:!1,remap:Ks};let s;try{s=JSON.parse(e)}catch{return{text:e,warnings:[],expanded:!1,remap:Ks}}const o=new Set(r.map(_=>_.metadata.name)),a=new Map;for(const _ of i){const x=_.metadata.name;!o.has(x)&&!a.has(x)&&a.set(x,_)}const c=bl(s,new Set(a.keys()));if(c.size>0){const[_]=c,x=a.get(_);throw new hn(`"${_}" is a browser plugin that ${Gx(x)}.`,_)}if(bl(s,o).size===0)return{text:e,warnings:[],expanded:!1,remap:Ks};const d=new Map,f=new Map;for(const _ of r)d.set(_.metadata.name,{name:_.metadata.name,versions:_.metadata.versions.map(x=>x.version)}),f.set(_.metadata.name,_.docName);let h={};try{h=await Bx(t.signal)}catch(_){if((y=t.signal)!=null&&y.aborted)throw _}const p=qx(s,{format:at,customThemes:t.customThemes??{},builtinThemes:h}),m=await Hx(s,{plugins:d,theme:p.theme,signal:t.signal,render:(_,x)=>ug.render(f.get(_.name),_,x)}),v=p.warning?[{component:"theme",message:p.warning.message,severity:"warning",context:p.warning.context},...m.warnings]:m.warnings,k=m.pathMap;return{text:JSON.stringify(m.document,null,2),warnings:v,expanded:!0,remap:_=>Jx(_,k)}}const ct=cd,Kx=ud,wl=ya,Qd=g.forwardRef(({className:e,...t},n)=>l.jsx(Cs,{ref:n,className:W("fixed inset-0 z-50 bg-black/50",e),...t}));Qd.displayName=Cs.displayName;const lt=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Kx,{children:[l.jsx(Qd,{}),l.jsxs(js,{ref:r,className:W("bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",e),...n,children:[t,l.jsxs(ya,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 cursor-pointer rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none",children:[l.jsx(wn,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));lt.displayName=js.displayName;const qt=({className:e,...t})=>l.jsx("div",{className:W("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});qt.displayName="DialogHeader";const kn=({className:e,...t})=>l.jsx("div",{className:W("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});kn.displayName="DialogFooter";const Gt=g.forwardRef(({className:e,...t},n)=>l.jsx(_s,{ref:n,className:W("text-lg leading-none font-semibold tracking-tight",e),...t}));Gt.displayName=_s.displayName;const dn=g.forwardRef(({className:e,...t},n)=>l.jsx(Ns,{ref:n,className:W("text-muted-foreground text-sm",e),...t}));dn.displayName=Ns.displayName;const li=zg,ef=Pg,ci=Og,xr=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(dd,{ref:r,className:W("border-input ring-offset-background placeholder:text-muted-foreground focus:ring-ring flex min-h-9 w-full min-w-0 items-center justify-between gap-2 rounded-sm border bg-background px-3 py-2 text-sm shadow-xs focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:min-w-0 [&>span]:whitespace-normal [&>span]:break-words text-left cursor-pointer",e),...n,children:[t,l.jsx(Dg,{asChild:!0,children:l.jsx(ki,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));xr.displayName=dd.displayName;const tf=g.forwardRef(({className:e,...t},n)=>l.jsx(md,{ref:n,className:W("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(Qg,{className:"h-4 w-4"})}));tf.displayName=md.displayName;const nf=g.forwardRef(({className:e,...t},n)=>l.jsx(gd,{ref:n,className:W("flex cursor-default items-center justify-center py-1",e),...t,children:l.jsx(ki,{className:"h-4 w-4"})}));nf.displayName=gd.displayName;const yr=g.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>l.jsx(Rg,{children:l.jsxs(fd,{ref:i,className:W("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-lg border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[l.jsx(tf,{}),l.jsx($g,{className:W("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),l.jsx(nf,{})]})}));yr.displayName=fd.displayName;const ka=g.forwardRef(({className:e,...t},n)=>l.jsx(hd,{ref:n,className:W("px-2 py-1.5 text-sm font-semibold",e),...t}));ka.displayName=hd.displayName;const Mn=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(pd,{ref:r,className:W("focus:bg-accent focus:text-accent-foreground relative flex w-full cursor-pointer items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[l.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Mg,{children:l.jsx(un,{className:"h-4 w-4"})})}),l.jsx(Fg,{children:t})]}));Mn.displayName=pd.displayName;const Yx=g.forwardRef(({className:e,...t},n)=>l.jsx(xd,{ref:n,className:W("bg-muted -mx-1 my-1 h-px",e),...t}));Yx.displayName=xd.displayName;const br=g.forwardRef(({className:e,type:t,...n},r)=>l.jsx("input",{type:t,className:W("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-sm border bg-background px-3 py-1 text-sm shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));br.displayName="Input";const Xx=Si("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Xr=g.forwardRef(({className:e,...t},n)=>l.jsx(yd,{ref:n,className:W(Xx(),e),...t}));Xr.displayName=yd.displayName;const Qx=Si("inline-flex items-center rounded-md border px-2.5 py-1 text-xs font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function tn({className:e,variant:t,...n}){return l.jsx("div",{className:W(Qx({variant:t}),e),...n})}const ey=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:o}=ke(wa(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),a=g.useContext(xa),{toast:c}=_r(),u=g.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[d,f]=g.useState(""),[h,p]=g.useState(""),[m,v]=g.useState("playground"),[k,y]=g.useState(!1),[_,x]=g.useState(null),[A,E]=g.useState(null),[w,S]=g.useState(null),O=()=>{x(null),E(null),S(null)};g.useEffect(()=>{if(!e)return;x(null),E(null),S(null);const T=u.map($=>$.name),F=T.includes(i)?i:T[0]??"";p(F),f(T.find($=>$!==F)??"")},[e]);const B=async()=>{const T=u.find($=>$.name===d),F=u.find($=>$.name===h);if(!(!T||!F)){y(!0),x(null),E(null),S(null);try{const $=a?dg(a.getState().customThemes):{},[Z,P]=await Promise.all([Ro(T.text,{customThemes:$}),Ro(F.text,{customThemes:$})]),J=await fetch(oi.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:Z.text,newDefinition:P.text,options:{author:m||"playground"}})}),V=await J.json();if(!J.ok||!V.success){const X=Array.isArray(V.errors)?`: ${V.errors.slice(0,3).map(j=>j.message||String(j)).join("; ")}`:"";throw new Error((V.error||`Diff failed (${J.status})`)+X)}E(V.data.summary),S(V.data.document)}catch($){x($ instanceof Error?$.message:"Diff failed")}finally{y(!1)}}},N=()=>{if(!w)return;const T=new Set(n.map(Z=>Z.name));let F=`${h}-redline`,$=2;for(;T.has(F);)F=`${h}-redline-${$++}`;s(F,JSON.stringify(w,null,2)),o(F),c({title:`Redline created: ${F}`}),t(!1)},R=A?A.tracked.modified+A.tracked.inserted+A.tracked.deleted:0;return l.jsx(ct,{open:e,onOpenChange:t,children:l.jsxs(lt,{className:"sm:max-w-[560px]",children:[l.jsxs(qt,{children:[l.jsxs(Gt,{className:"flex items-center gap-2",children:[l.jsx(Vd,{className:"size-4"}),"Compare documents"]}),l.jsx(dn,{children:"Diff two versions into a redline with native Word tracked changes (accept/reject in Word)."})]}),l.jsxs("div",{className:"grid gap-4 py-2",children:[l.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[l.jsxs("div",{className:"grid gap-1.5",children:[l.jsx(Xr,{htmlFor:"diff-base",children:"Base (old)"}),l.jsxs(li,{value:d,onValueChange:T=>{f(T),O()},children:[l.jsx(xr,{id:"diff-base",children:l.jsx(ci,{placeholder:"Select document"})}),l.jsx(yr,{children:u.map(T=>l.jsx(Mn,{value:T.name,children:T.name},T.name))})]})]}),l.jsxs("div",{className:"grid gap-1.5",children:[l.jsx(Xr,{htmlFor:"diff-revised",children:"Revised (new)"}),l.jsxs(li,{value:h,onValueChange:T=>{p(T),O()},children:[l.jsx(xr,{id:"diff-revised",children:l.jsx(ci,{placeholder:"Select document"})}),l.jsx(yr,{children:u.map(T=>l.jsx(Mn,{value:T.name,children:T.name},T.name))})]})]})]}),l.jsxs("div",{className:"grid gap-1.5",children:[l.jsx(Xr,{htmlFor:"diff-author",children:"Revision author"}),l.jsx(br,{id:"diff-author",value:m,onChange:T=>{v(T.target.value),O()},placeholder:"playground"})]}),_&&l.jsx("p",{className:"text-sm text-destructive",role:"alert",children:_}),A&&l.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsxs(tn,{variant:"secondary",children:[A.tracked.inserted," inserted"]}),l.jsxs(tn,{variant:"secondary",children:[A.tracked.deleted," deleted"]}),l.jsxs(tn,{variant:"secondary",children:[A.tracked.modified," modified"]}),l.jsxs("span",{className:"text-muted-foreground text-xs",children:[A.unchangedBlocks," blocks unchanged"]})]}),R===0&&A.untracked.length===0&&l.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),A.untracked.length>0&&l.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[l.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[A.untracked.length," change(s) not expressible as tracked changes:"]}),A.untracked.map((T,F)=>l.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},F))]}),A.notes.map((T,F)=>l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},F))]})]}),l.jsx(kn,{children:A&&R+A.untracked.length>0?l.jsxs(Ce,{onClick:N,children:[l.jsx(ex,{className:"size-4 mr-1"}),"Open redline"]}):l.jsxs(Ce,{onClick:B,disabled:k||!d||!h||d===h,children:[k&&l.jsx(cn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var ji=e=>e.type==="checkbox",On=e=>e instanceof Date,gt=e=>e==null;const rf=e=>typeof e=="object";var nt=e=>!gt(e)&&!Array.isArray(e)&&rf(e)&&!On(e),sf=e=>nt(e)&&e.target?ji(e.target)?e.target.checked:e.target.value:e,ty=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,of=(e,t)=>e.has(ty(t)),ny=e=>{const t=e.constructor&&e.constructor.prototype;return nt(t)&&t.hasOwnProperty("isPrototypeOf")},Sa=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function wt(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(Sa&&(e instanceof Blob||r))&&(n||nt(e)))if(t=n?[]:{},!n&&!ny(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=wt(e[i]));else return e;return t}var Ts=e=>Array.isArray(e)?e.filter(Boolean):[],tt=e=>e===void 0,ue=(e,t,n)=>{if(!t||!nt(e))return n;const r=Ts(t.split(/[,[\].]+?/)).reduce((i,s)=>gt(i)?i:i[s],e);return tt(r)||r===e?tt(e[t])?n:e[t]:r},Rt=e=>typeof e=="boolean",ja=e=>/^\w*$/.test(e),af=e=>Ts(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Le=(e,t,n)=>{let r=-1;const i=ja(t)?[t]:af(t),s=i.length,o=s-1;for(;++r<s;){const a=i[r];let c=n;if(r!==o){const u=e[a];c=nt(u)||Array.isArray(u)?u:isNaN(+i[r+1])?{}:[]}if(a==="__proto__"||a==="constructor"||a==="prototype")return;e[a]=c,e=e[a]}return e};const ts={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ut={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},sn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},lf=je.createContext(null),Is=()=>je.useContext(lf),ry=e=>{const{children:t,...n}=e;return je.createElement(lf.Provider,{value:n},t)};var cf=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const o=s;return t._proxyFormState[o]!==Ut.all&&(t._proxyFormState[o]=!r||Ut.all),n&&(n[o]=!0),e[o]}});return i},kt=e=>nt(e)&&!Object.keys(e).length,uf=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return kt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(o=>t[o]===(!r||Ut.all))},Qr=e=>Array.isArray(e)?e:[e],df=(e,t,n)=>!e||!t||e===t||Qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function _a(e){const t=je.useRef(e);t.current=e,je.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function iy(e){const t=Is(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[o,a]=je.useState(n._formState),c=je.useRef(!0),u=je.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=je.useRef(i);return d.current=i,_a({disabled:r,next:f=>c.current&&df(d.current,f.name,s)&&uf(f,u.current,n._updateFormState)&&a({...n._formState,...f}),subject:n._subjects.state}),je.useEffect(()=>(c.current=!0,u.current.isValid&&n._updateValid(!0),()=>{c.current=!1}),[n]),je.useMemo(()=>cf(o,n,u.current,!1),[o,n])}var en=e=>typeof e=="string",ff=(e,t,n,r,i)=>en(e)?(r&&t.watch.add(e),ue(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),ue(n,s))):(r&&(t.watchAll=!0),n);function sy(e){const t=Is(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:o}=e||{},a=je.useRef(r);a.current=r,_a({disabled:s,subject:n._subjects.values,next:d=>{df(a.current,d.name,o)&&u(wt(ff(a.current,n._names,d.values||n._formValues,!1,i)))}});const[c,u]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),c}function oy(e){const t=Is(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,o=of(i._names.array,n),a=sy({control:i,name:n,defaultValue:ue(i._formValues,n,ue(i._defaultValues,n,e.defaultValue)),exact:!0}),c=iy({control:i,name:n,exact:!0}),u=je.useRef(i.register(n,{...e.rules,value:a,...Rt(e.disabled)?{disabled:e.disabled}:{}})),d=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ue(c.errors,n)},isDirty:{enumerable:!0,get:()=>!!ue(c.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ue(c.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ue(c.validatingFields,n)},error:{enumerable:!0,get:()=>ue(c.errors,n)}}),[c,n]),f=je.useMemo(()=>({name:n,value:a,...Rt(r)||c.disabled?{disabled:c.disabled||r}:{},onChange:h=>u.current.onChange({target:{value:sf(h),name:n},type:ts.CHANGE}),onBlur:()=>u.current.onBlur({target:{value:ue(i._formValues,n),name:n},type:ts.BLUR}),ref:h=>{const p=ue(i._fields,n);p&&h&&(p._f.ref={focus:()=>h.focus(),select:()=>h.select(),setCustomValidity:m=>h.setCustomValidity(m),reportValidity:()=>h.reportValidity()})}}),[n,i._formValues,r,c.disabled,a,i._fields]);return je.useEffect(()=>{const h=i._options.shouldUnregister||s,p=(m,v)=>{const k=ue(i._fields,m);k&&k._f&&(k._f.mount=v)};if(p(n,!0),h){const m=wt(ue(i._options.defaultValues,n));Le(i._defaultValues,n,m),tt(ue(i._formValues,n))&&Le(i._formValues,n,m)}return!o&&i.register(n),()=>{(o?h&&!i._state.action:h)?i.unregister(n):p(n,!1)}},[n,i,o,s]),je.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),je.useMemo(()=>({field:f,formState:c,fieldState:d}),[f,c,d])}const ay=e=>e.render(oy(e));var ly=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},kl=e=>({isOnSubmit:!e||e===Ut.onSubmit,isOnBlur:e===Ut.onBlur,isOnChange:e===Ut.onChange,isOnAll:e===Ut.all,isOnTouch:e===Ut.onTouched}),Sl=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const ei=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=ue(e,i);if(s){const{_f:o,...a}=s;if(o){if(o.refs&&o.refs[0]&&t(o.refs[0],i)&&!r)return!0;if(o.ref&&t(o.ref,o.name)&&!r)return!0;if(ei(a,t))break}else if(nt(a)&&ei(a,t))break}}};var cy=(e,t,n)=>{const r=Qr(ue(e,n));return Le(r,"root",t[n]),Le(e,n,r),e},Na=e=>e.type==="file",Qt=e=>typeof e=="function",ns=e=>{if(!Sa)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Wi=e=>en(e),Ca=e=>e.type==="radio",rs=e=>e instanceof RegExp;const jl={value:!1,isValid:!1},_l={value:!0,isValid:!0};var pf=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!tt(e[0].attributes.value)?tt(e[0].value)||e[0].value===""?_l:{value:e[0].value,isValid:!0}:_l:jl}return jl};const Nl={isValid:!1,value:null};var hf=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Nl):Nl;function Cl(e,t,n="validate"){if(Wi(e)||Array.isArray(e)&&e.every(Wi)||Rt(e)&&!e)return{type:n,message:Wi(e)?e:"",ref:t}}var Jn=e=>nt(e)&&!rs(e)?e:{value:e,message:""},El=async(e,t,n,r,i,s)=>{const{ref:o,refs:a,required:c,maxLength:u,minLength:d,min:f,max:h,pattern:p,validate:m,name:v,valueAsNumber:k,mount:y}=e._f,_=ue(n,v);if(!y||t.has(v))return{};const x=a?a[0]:o,A=T=>{i&&x.reportValidity&&(x.setCustomValidity(Rt(T)?"":T||""),x.reportValidity())},E={},w=Ca(o),S=ji(o),O=w||S,B=(k||Na(o))&&tt(o.value)&&tt(_)||ns(o)&&o.value===""||_===""||Array.isArray(_)&&!_.length,N=ly.bind(null,v,r,E),R=(T,F,$,Z=sn.maxLength,P=sn.minLength)=>{const J=T?F:$;E[v]={type:T?Z:P,message:J,ref:o,...N(T?Z:P,J)}};if(s?!Array.isArray(_)||!_.length:c&&(!O&&(B||gt(_))||Rt(_)&&!_||S&&!pf(a).isValid||w&&!hf(a).isValid)){const{value:T,message:F}=Wi(c)?{value:!!c,message:c}:Jn(c);if(T&&(E[v]={type:sn.required,message:F,ref:x,...N(sn.required,F)},!r))return A(F),E}if(!B&&(!gt(f)||!gt(h))){let T,F;const $=Jn(h),Z=Jn(f);if(!gt(_)&&!isNaN(_)){const P=o.valueAsNumber||_&&+_;gt($.value)||(T=P>$.value),gt(Z.value)||(F=P<Z.value)}else{const P=o.valueAsDate||new Date(_),J=j=>new Date(new Date().toDateString()+" "+j),V=o.type=="time",X=o.type=="week";en($.value)&&_&&(T=V?J(_)>J($.value):X?_>$.value:P>new Date($.value)),en(Z.value)&&_&&(F=V?J(_)<J(Z.value):X?_<Z.value:P<new Date(Z.value))}if((T||F)&&(R(!!T,$.message,Z.message,sn.max,sn.min),!r))return A(E[v].message),E}if((u||d)&&!B&&(en(_)||s&&Array.isArray(_))){const T=Jn(u),F=Jn(d),$=!gt(T.value)&&_.length>+T.value,Z=!gt(F.value)&&_.length<+F.value;if(($||Z)&&(R($,T.message,F.message),!r))return A(E[v].message),E}if(p&&!B&&en(_)){const{value:T,message:F}=Jn(p);if(rs(T)&&!_.match(T)&&(E[v]={type:sn.pattern,message:F,ref:o,...N(sn.pattern,F)},!r))return A(F),E}if(m){if(Qt(m)){const T=await m(_,n),F=Cl(T,x);if(F&&(E[v]={...F,...N(sn.validate,F.message)},!r))return A(F.message),E}else if(nt(m)){let T={};for(const F in m){if(!kt(T)&&!r)break;const $=Cl(await m[F](_,n),x,F);$&&(T={...$,...N(F,$.message)},A($.message),r&&(E[v]=T))}if(!kt(T)&&(E[v]={ref:x,...T},!r))return E}}return A(!0),E};function uy(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=tt(e)?r++:e[t[r++]];return e}function dy(e){for(const t in e)if(e.hasOwnProperty(t)&&!tt(e[t]))return!1;return!0}function st(e,t){const n=Array.isArray(t)?t:ja(t)?[t]:af(t),r=n.length===1?e:uy(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(nt(r)&&kt(r)||Array.isArray(r)&&dy(r))&&st(e,n.slice(0,-1)),e}var Ys=()=>{let e=[];return{get observers(){return e},next:i=>{for(const s of e)s.next&&s.next(i)},subscribe:i=>(e.push(i),{unsubscribe:()=>{e=e.filter(s=>s!==i)}}),unsubscribe:()=>{e=[]}}},$o=e=>gt(e)||!rf(e);function xn(e,t){if($o(e)||$o(t))return e===t;if(On(e)&&On(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const s=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const o=t[i];if(On(s)&&On(o)||nt(s)&&nt(o)||Array.isArray(s)&&Array.isArray(o)?!xn(s,o):s!==o)return!1}}return!0}var mf=e=>e.type==="select-multiple",fy=e=>Ca(e)||ji(e),Xs=e=>ns(e)&&e.isConnected,gf=e=>{for(const t in e)if(Qt(e[t]))return!0;return!1};function is(e,t={}){const n=Array.isArray(e);if(nt(e)||n)for(const r in e)Array.isArray(e[r])||nt(e[r])&&!gf(e[r])?(t[r]=Array.isArray(e[r])?[]:{},is(e[r],t[r])):gt(e[r])||(t[r]=!0);return t}function xf(e,t,n){const r=Array.isArray(e);if(nt(e)||r)for(const i in e)Array.isArray(e[i])||nt(e[i])&&!gf(e[i])?tt(t)||$o(n[i])?n[i]=Array.isArray(e[i])?is(e[i],[]):{...is(e[i])}:xf(e[i],gt(t)?{}:t[i],n[i]):n[i]=!xn(e[i],t[i]);return n}var Rr=(e,t)=>xf(e,t,is(t)),yf=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>tt(e)?e:t?e===""?NaN:e&&+e:n&&en(e)?new Date(e):r?r(e):e;function Qs(e){const t=e.ref;return Na(t)?t.files:Ca(t)?hf(e.refs).value:mf(t)?[...t.selectedOptions].map(({value:n})=>n):ji(t)?pf(e.refs).value:yf(tt(t.value)?e.ref.value:t.value,e)}var py=(e,t,n,r)=>{const i={};for(const s of e){const o=ue(t,s);o&&Le(i,s,o._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},$r=e=>tt(e)?e:rs(e)?e.source:nt(e)?rs(e.value)?e.value.source:e.value:e;const Tl="AsyncFunction";var hy=e=>!!e&&!!e.validate&&!!(Qt(e.validate)&&e.validate.constructor.name===Tl||nt(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Tl)),my=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Il(e,t,n){const r=ue(e,n);if(r||ja(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),o=ue(t,s),a=ue(e,s);if(o&&!Array.isArray(o)&&n!==s)return{name:n};if(a&&a.type)return{name:s,error:a};i.pop()}return{name:n}}var gy=(e,t,n,r,i)=>i.isOnAll?!1:!n&&i.isOnTouch?!(t||e):(n?r.isOnBlur:i.isOnBlur)?!e:(n?r.isOnChange:i.isOnChange)?e:!0,xy=(e,t)=>!Ts(ue(e,t)).length&&st(e,t);const yy={mode:Ut.onSubmit,reValidateMode:Ut.onChange,shouldFocusError:!0};function by(e={}){let t={...yy,...e},n={submitCount:0,isDirty:!1,isLoading:Qt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=nt(t.defaultValues)||nt(t.values)?wt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:wt(i),o={action:!1,mount:!1,watch:!1},a={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},c,u=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Ys(),array:Ys(),state:Ys()},h=kl(t.mode),p=kl(t.reValidateMode),m=t.criteriaMode===Ut.all,v=C=>z=>{clearTimeout(u),u=setTimeout(C,z)},k=async C=>{if(!t.disabled&&(d.isValid||C)){const z=t.resolver?kt((await O()).errors):await N(r,!0);z!==n.isValid&&f.state.next({isValid:z})}},y=(C,z)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((C||Array.from(a.mount)).forEach(L=>{L&&(z?Le(n.validatingFields,L,z):st(n.validatingFields,L))}),f.state.next({validatingFields:n.validatingFields,isValidating:!kt(n.validatingFields)}))},_=(C,z=[],L,se,ie=!0,ee=!0)=>{if(se&&L&&!t.disabled){if(o.action=!0,ee&&Array.isArray(ue(r,C))){const me=L(ue(r,C),se.argA,se.argB);ie&&Le(r,C,me)}if(ee&&Array.isArray(ue(n.errors,C))){const me=L(ue(n.errors,C),se.argA,se.argB);ie&&Le(n.errors,C,me),xy(n.errors,C)}if(d.touchedFields&&ee&&Array.isArray(ue(n.touchedFields,C))){const me=L(ue(n.touchedFields,C),se.argA,se.argB);ie&&Le(n.touchedFields,C,me)}d.dirtyFields&&(n.dirtyFields=Rr(i,s)),f.state.next({name:C,isDirty:T(C,z),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Le(s,C,z)},x=(C,z)=>{Le(n.errors,C,z),f.state.next({errors:n.errors})},A=C=>{n.errors=C,f.state.next({errors:n.errors,isValid:!1})},E=(C,z,L,se)=>{const ie=ue(r,C);if(ie){const ee=ue(s,C,tt(L)?ue(i,C):L);tt(ee)||se&&se.defaultChecked||z?Le(s,C,z?ee:Qs(ie._f)):Z(C,ee),o.mount&&k()}},w=(C,z,L,se,ie)=>{let ee=!1,me=!1;const we={name:C};if(!t.disabled){const U=!!(ue(r,C)&&ue(r,C)._f&&ue(r,C)._f.disabled);if(!L||se){d.isDirty&&(me=n.isDirty,n.isDirty=we.isDirty=T(),ee=me!==we.isDirty);const Y=U||xn(ue(i,C),z);me=!!(!U&&ue(n.dirtyFields,C)),Y||U?st(n.dirtyFields,C):Le(n.dirtyFields,C,!0),we.dirtyFields=n.dirtyFields,ee=ee||d.dirtyFields&&me!==!Y}if(L){const Y=ue(n.touchedFields,C);Y||(Le(n.touchedFields,C,L),we.touchedFields=n.touchedFields,ee=ee||d.touchedFields&&Y!==L)}ee&&ie&&f.state.next(we)}return ee?we:{}},S=(C,z,L,se)=>{const ie=ue(n.errors,C),ee=d.isValid&&Rt(z)&&n.isValid!==z;if(t.delayError&&L?(c=v(()=>x(C,L)),c(t.delayError)):(clearTimeout(u),c=null,L?Le(n.errors,C,L):st(n.errors,C)),(L?!xn(ie,L):ie)||!kt(se)||ee){const me={...se,...ee&&Rt(z)?{isValid:z}:{},errors:n.errors,name:C};n={...n,...me},f.state.next(me)}},O=async C=>{y(C,!0);const z=await t.resolver(s,t.context,py(C||a.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return y(C),z},B=async C=>{const{errors:z}=await O(C);if(C)for(const L of C){const se=ue(z,L);se?Le(n.errors,L,se):st(n.errors,L)}else n.errors=z;return z},N=async(C,z,L={valid:!0})=>{for(const se in C){const ie=C[se];if(ie){const{_f:ee,...me}=ie;if(ee){const we=a.array.has(ee.name),U=ie._f&&hy(ie._f);U&&d.validatingFields&&y([se],!0);const Y=await El(ie,a.disabled,s,m,t.shouldUseNativeValidation&&!z,we);if(U&&d.validatingFields&&y([se]),Y[ee.name]&&(L.valid=!1,z))break;!z&&(ue(Y,ee.name)?we?cy(n.errors,Y,ee.name):Le(n.errors,ee.name,Y[ee.name]):st(n.errors,ee.name))}!kt(me)&&await N(me,z,L)}}return L.valid},R=()=>{for(const C of a.unMount){const z=ue(r,C);z&&(z._f.refs?z._f.refs.every(L=>!Xs(L)):!Xs(z._f.ref))&&Q(C)}a.unMount=new Set},T=(C,z)=>!t.disabled&&(C&&z&&Le(s,C,z),!xn(ye(),i)),F=(C,z,L)=>ff(C,a,{...o.mount?s:tt(z)?i:en(C)?{[C]:z}:z},L,z),$=C=>Ts(ue(o.mount?s:i,C,t.shouldUnregister?ue(i,C,[]):[])),Z=(C,z,L={})=>{const se=ue(r,C);let ie=z;if(se){const ee=se._f;ee&&(!ee.disabled&&Le(s,C,yf(z,ee)),ie=ns(ee.ref)&&gt(z)?"":z,mf(ee.ref)?[...ee.ref.options].forEach(me=>me.selected=ie.includes(me.value)):ee.refs?ji(ee.ref)?ee.refs.length>1?ee.refs.forEach(me=>(!me.defaultChecked||!me.disabled)&&(me.checked=Array.isArray(ie)?!!ie.find(we=>we===me.value):ie===me.value)):ee.refs[0]&&(ee.refs[0].checked=!!ie):ee.refs.forEach(me=>me.checked=me.value===ie):Na(ee.ref)?ee.ref.value="":(ee.ref.value=ie,ee.ref.type||f.values.next({name:C,values:{...s}})))}(L.shouldDirty||L.shouldTouch)&&w(C,ie,L.shouldTouch,L.shouldDirty,!0),L.shouldValidate&&j(C)},P=(C,z,L)=>{for(const se in z){const ie=z[se],ee=`${C}.${se}`,me=ue(r,ee);(a.array.has(C)||nt(ie)||me&&!me._f)&&!On(ie)?P(ee,ie,L):Z(ee,ie,L)}},J=(C,z,L={})=>{const se=ue(r,C),ie=a.array.has(C),ee=wt(z);Le(s,C,ee),ie?(f.array.next({name:C,values:{...s}}),(d.isDirty||d.dirtyFields)&&L.shouldDirty&&f.state.next({name:C,dirtyFields:Rr(i,s),isDirty:T(C,ee)})):se&&!se._f&&!gt(ee)?P(C,ee,L):Z(C,ee,L),Sl(C,a)&&f.state.next({...n}),f.values.next({name:o.mount?C:void 0,values:{...s}})},V=async C=>{o.mount=!0;const z=C.target;let L=z.name,se=!0;const ie=ue(r,L),ee=()=>z.type?Qs(ie._f):sf(C),me=we=>{se=Number.isNaN(we)||On(we)&&isNaN(we.getTime())||xn(we,ue(s,L,we))};if(ie){let we,U;const Y=ee(),ge=C.type===ts.BLUR||C.type===ts.FOCUS_OUT,_e=!my(ie._f)&&!t.resolver&&!ue(n.errors,L)&&!ie._f.deps||gy(ge,ue(n.touchedFields,L),n.isSubmitted,p,h),M=Sl(L,a,ge);Le(s,L,Y),ge?(ie._f.onBlur&&ie._f.onBlur(C),c&&c(0)):ie._f.onChange&&ie._f.onChange(C);const D=w(L,Y,ge,!1),xe=!kt(D)||M;if(!ge&&f.values.next({name:L,type:C.type,values:{...s}}),_e)return d.isValid&&(t.mode==="onBlur"&&ge?k():ge||k()),xe&&f.state.next({name:L,...M?{}:D});if(!ge&&M&&f.state.next({...n}),t.resolver){const{errors:de}=await O([L]);if(me(Y),se){const Me=Il(n.errors,r,L),Je=Il(de,r,Me.name||L);we=Je.error,L=Je.name,U=kt(de)}}else y([L],!0),we=(await El(ie,a.disabled,s,m,t.shouldUseNativeValidation))[L],y([L]),me(Y),se&&(we?U=!1:d.isValid&&(U=await N(r,!0)));se&&(ie._f.deps&&j(ie._f.deps),S(L,U,we,D))}},X=(C,z)=>{if(ue(n.errors,z)&&C.focus)return C.focus(),1},j=async(C,z={})=>{let L,se;const ie=Qr(C);if(t.resolver){const ee=await B(tt(C)?C:ie);L=kt(ee),se=C?!ie.some(me=>ue(ee,me)):L}else C?(se=(await Promise.all(ie.map(async ee=>{const me=ue(r,ee);return await N(me&&me._f?{[ee]:me}:me)}))).every(Boolean),!(!se&&!n.isValid)&&k()):se=L=await N(r);return f.state.next({...!en(C)||d.isValid&&L!==n.isValid?{}:{name:C},...t.resolver||!C?{isValid:L}:{},errors:n.errors}),z.shouldFocus&&!se&&ei(r,X,C?ie:a.mount),se},ye=C=>{const z={...o.mount?s:i};return tt(C)?z:en(C)?ue(z,C):C.map(L=>ue(z,L))},ce=(C,z)=>({invalid:!!ue((z||n).errors,C),isDirty:!!ue((z||n).dirtyFields,C),error:ue((z||n).errors,C),isValidating:!!ue(n.validatingFields,C),isTouched:!!ue((z||n).touchedFields,C)}),b=C=>{C&&Qr(C).forEach(z=>st(n.errors,z)),f.state.next({errors:C?n.errors:{}})},G=(C,z,L)=>{const se=(ue(r,C,{_f:{}})._f||{}).ref,ie=ue(n.errors,C)||{},{ref:ee,message:me,type:we,...U}=ie;Le(n.errors,C,{...U,...z,ref:se}),f.state.next({name:C,errors:n.errors,isValid:!1}),L&&L.shouldFocus&&se&&se.focus&&se.focus()},ne=(C,z)=>Qt(C)?f.values.subscribe({next:L=>C(F(void 0,z),L)}):F(C,z,!0),Q=(C,z={})=>{for(const L of C?Qr(C):a.mount)a.mount.delete(L),a.array.delete(L),z.keepValue||(st(r,L),st(s,L)),!z.keepError&&st(n.errors,L),!z.keepDirty&&st(n.dirtyFields,L),!z.keepTouched&&st(n.touchedFields,L),!z.keepIsValidating&&st(n.validatingFields,L),!t.shouldUnregister&&!z.keepDefaultValue&&st(i,L);f.values.next({values:{...s}}),f.state.next({...n,...z.keepDirty?{isDirty:T()}:{}}),!z.keepIsValid&&k()},oe=({disabled:C,name:z,field:L,fields:se})=>{(Rt(C)&&o.mount||C||a.disabled.has(z))&&(C?a.disabled.add(z):a.disabled.delete(z),w(z,Qs(L?L._f:ue(se,z)._f),!1,!1,!0))},I=(C,z={})=>{let L=ue(r,C);const se=Rt(z.disabled)||Rt(t.disabled);return Le(r,C,{...L||{},_f:{...L&&L._f?L._f:{ref:{name:C}},name:C,mount:!0,...z}}),a.mount.add(C),L?oe({field:L,disabled:Rt(z.disabled)?z.disabled:t.disabled,name:C}):E(C,!0,z.value),{...se?{disabled:z.disabled||t.disabled}:{},...t.progressive?{required:!!z.required,min:$r(z.min),max:$r(z.max),minLength:$r(z.minLength),maxLength:$r(z.maxLength),pattern:$r(z.pattern)}:{},name:C,onChange:V,onBlur:V,ref:ie=>{if(ie){I(C,z),L=ue(r,C);const ee=tt(ie.value)&&ie.querySelectorAll&&ie.querySelectorAll("input,select,textarea")[0]||ie,me=fy(ee),we=L._f.refs||[];if(me?we.find(U=>U===ee):ee===L._f.ref)return;Le(r,C,{_f:{...L._f,...me?{refs:[...we.filter(Xs),ee,...Array.isArray(ue(i,C))?[{}]:[]],ref:{type:ee.type,name:C}}:{ref:ee}}}),E(C,!1,void 0,ee)}else L=ue(r,C,{}),L._f&&(L._f.mount=!1),(t.shouldUnregister||z.shouldUnregister)&&!(of(a.array,C)&&o.action)&&a.unMount.add(C)}}},re=()=>t.shouldFocusError&&ei(r,X,a.mount),ae=C=>{Rt(C)&&(f.state.next({disabled:C}),ei(r,(z,L)=>{const se=ue(r,L);se&&(z.disabled=se._f.disabled||C,Array.isArray(se._f.refs)&&se._f.refs.forEach(ie=>{ie.disabled=se._f.disabled||C}))},0,!1))},H=(C,z)=>async L=>{let se;L&&(L.preventDefault&&L.preventDefault(),L.persist&&L.persist());let ie=wt(s);if(a.disabled.size)for(const ee of a.disabled)Le(ie,ee,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:ee,values:me}=await O();n.errors=ee,ie=me}else await N(r);if(st(n.errors,"root"),kt(n.errors)){f.state.next({errors:{}});try{await C(ie,L)}catch(ee){se=ee}}else z&&await z({...n.errors},L),re(),setTimeout(re);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:kt(n.errors)&&!se,submitCount:n.submitCount+1,errors:n.errors}),se)throw se},K=(C,z={})=>{ue(r,C)&&(tt(z.defaultValue)?J(C,wt(ue(i,C))):(J(C,z.defaultValue),Le(i,C,wt(z.defaultValue))),z.keepTouched||st(n.touchedFields,C),z.keepDirty||(st(n.dirtyFields,C),n.isDirty=z.defaultValue?T(C,wt(ue(i,C))):T()),z.keepError||(st(n.errors,C),d.isValid&&k()),f.state.next({...n}))},pe=(C,z={})=>{const L=C?wt(C):i,se=wt(L),ie=kt(C),ee=ie?i:se;if(z.keepDefaultValues||(i=L),!z.keepValues){if(z.keepDirtyValues){const me=new Set([...a.mount,...Object.keys(Rr(i,s))]);for(const we of Array.from(me))ue(n.dirtyFields,we)?Le(ee,we,ue(s,we)):J(we,ue(ee,we))}else{if(Sa&&tt(C))for(const me of a.mount){const we=ue(r,me);if(we&&we._f){const U=Array.isArray(we._f.refs)?we._f.refs[0]:we._f.ref;if(ns(U)){const Y=U.closest("form");if(Y){Y.reset();break}}}}r={}}s=t.shouldUnregister?z.keepDefaultValues?wt(i):{}:wt(ee),f.array.next({values:{...ee}}),f.values.next({values:{...ee}})}a={mount:z.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!d.isValid||!!z.keepIsValid||!!z.keepDirtyValues,o.watch=!!t.shouldUnregister,f.state.next({submitCount:z.keepSubmitCount?n.submitCount:0,isDirty:ie?!1:z.keepDirty?n.isDirty:!!(z.keepDefaultValues&&!xn(C,i)),isSubmitted:z.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ie?{}:z.keepDirtyValues?z.keepDefaultValues&&s?Rr(i,s):n.dirtyFields:z.keepDefaultValues&&C?Rr(i,C):z.keepDirty?n.dirtyFields:{},touchedFields:z.keepTouched?n.touchedFields:{},errors:z.keepErrors?n.errors:{},isSubmitSuccessful:z.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},fe=(C,z)=>pe(Qt(C)?C(s):C,z);return{control:{register:I,unregister:Q,getFieldState:ce,handleSubmit:H,setError:G,_executeSchema:O,_getWatch:F,_getDirty:T,_updateValid:k,_removeUnmounted:R,_updateFieldArray:_,_updateDisabledField:oe,_getFieldArray:$,_reset:pe,_resetDefaultValues:()=>Qt(t.defaultValues)&&t.defaultValues().then(C=>{fe(C,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:C=>{n={...n,...C}},_disableForm:ae,_subjects:f,_proxyFormState:d,_setErrors:A,get _fields(){return r},get _formValues(){return s},get _state(){return o},set _state(C){o=C},get _defaultValues(){return i},get _names(){return a},set _names(C){a=C},get _formState(){return n},set _formState(C){n=C},get _options(){return t},set _options(C){t={...t,...C}}},trigger:j,register:I,handleSubmit:H,watch:ne,setValue:J,getValues:ye,reset:fe,resetField:K,clearErrors:b,unregister:Q,setError:G,setFocus:(C,z={})=>{const L=ue(r,C),se=L&&L._f;if(se){const ie=se.refs?se.refs[0]:se.ref;ie.focus&&(ie.focus(),z.shouldSelect&&Qt(ie.select)&&ie.select())}},getFieldState:ce}}function vy(e={}){const t=je.useRef(void 0),n=je.useRef(void 0),[r,i]=je.useState({isDirty:!1,isValidating:!1,isLoading:Qt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Qt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...by(e),formState:r});const s=t.current.control;return s._options=e,_a({subject:s._subjects.state,next:o=>{uf(o,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),je.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),je.useEffect(()=>{if(s._proxyFormState.isDirty){const o=s._getDirty();o!==r.isDirty&&s._subjects.state.next({isDirty:o})}},[s,r.isDirty]),je.useEffect(()=>{e.values&&!xn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(o=>({...o}))):s._resetDefaultValues()},[e.values,s]),je.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),je.useEffect(()=>{s._state.mount||(s._updateValid(),s._state.mount=!0),s._state.watch&&(s._state.watch=!1,s._subjects.state.next({...s._formState})),s._removeUnmounted()}),je.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=cf(r,s),t.current}function wy(e){return async t=>{const n=e(t);if(n.success&&n.data)return{values:n.data,errors:{}};const r={};if(n.errors)for(const i of n.errors){const s=i.path||"root";r[s]||(r[s]={type:"validation",message:i.message})}return{values:{},errors:r}}}const ky=ry,bf=g.createContext({}),Al=({...e})=>l.jsx(bf.Provider,{value:{name:e.name},children:l.jsx(ay,{...e})}),As=()=>{const e=g.useContext(bf),t=g.useContext(vf),{getFieldState:n,formState:r}=Is(),i=n(e.name,r);if(!e)throw new Error("useFormField should be used within <FormField>");const{id:s}=t;return{id:s,name:e.name,formItemId:`${s}-form-item`,formDescriptionId:`${s}-form-item-description`,formMessageId:`${s}-form-item-message`,...i}},vf=g.createContext({}),Mo=g.forwardRef(({className:e,...t},n)=>{const r=g.useId();return l.jsx(vf.Provider,{value:{id:r},children:l.jsx("div",{ref:n,className:W("space-y-2",e),...t})})});Mo.displayName="FormItem";const Fo=g.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=As();return l.jsx(Xr,{ref:n,className:W(r&&"text-destructive",e),htmlFor:i,...t})});Fo.displayName="FormLabel";const Lo=g.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=As();return l.jsx(Nr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Lo.displayName="FormControl";const wf=g.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=As();return l.jsx("p",{ref:n,id:r,className:W("text-muted-foreground text-[0.8rem]",e),...t})});wf.displayName="FormDescription";const Bo=g.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=As(),o=i?String(i==null?void 0:i.message):t;return o?l.jsx("p",{ref:r,id:s,className:W("text-destructive text-[0.8rem] font-medium",e),...n,children:o}):null});Bo.displayName="FormMessage";function Ea(){const e=new Date,t=n=>String(n).padStart(2,"0");return`Chat ${t(e.getMonth()+1)}/${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}const kf=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Sy=(e=kf())=>Ox()(Px(Dx((t,n)=>({...e,toggleChat:()=>t(r=>({chatOpen:!r.chatOpen})),openChat:()=>t({chatOpen:!0}),closeChat:()=>t({chatOpen:!1}),addContext:r=>t(i=>({contextAttachments:[...i.contextAttachments,r]})),removeContext:r=>t(i=>({contextAttachments:i.contextAttachments.filter((s,o)=>o!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),o={id:i,documentName:r,title:Ea(),messages:[],createdAt:s,updatedAt:s};return t(a=>({threads:{...a.threads,[i]:o},activeThreadId:{...a.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const o=Object.fromEntries(Object.entries(i.threads).filter(([u])=>u!==r)),a=s.documentName,c={...i.activeThreadId};if(c[a]===r){const u=Object.values(o).filter(d=>d.documentName===a);u.length>0?(u.sort((d,f)=>f.updatedAt-d.updatedAt),c[a]=u[0].id):delete c[a]}t({threads:o,activeThreadId:c})},switchThread:r=>{const s=n().threads[r];s&&t(o=>({activeThreadId:{...o.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},o={...i.activeThreadId};for(const[a,c]of Object.entries(s))c.documentName===r&&delete s[a];return delete o[r],{threads:s,activeThreadId:o}})},renameThreadsForDocument:(r,i)=>{t(s=>{const o={...s.threads},a={...s.activeThreadId};for(const[c,u]of Object.entries(o))u.documentName===r&&(o[c]={...u,documentName:i});return r in a&&(a[i]=a[r],delete a[r]),{threads:o,activeThreadId:a}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:2,storage:Rx(()=>fg),partialize:t=>({threads:t.threads,activeThreadId:t.activeThreadId,scope:t.scope,model:t.model}),migrate:(t,n)=>{if(n===0&&t){const r=t.chatMessages;if(Array.isArray(r)&&r.length>0){const i=crypto.randomUUID(),s=Date.now();return{threads:{[i]:{id:i,documentName:"__migrated__",title:"Migrated Chat",messages:r,createdAt:s,updatedAt:s}},activeThreadId:{__migrated__:i}}}return{threads:{},activeThreadId:{}}}return n<2&&(t==null?void 0:t.scope)==="templates"?{...t,scope:"blocks"}:t}}))),Sf=g.createContext(void 0),jy=({children:e})=>{const t=g.useRef(null);return t.current||(t.current=Sy(kf())),l.jsx(Sf.Provider,{value:t.current,children:e})},De=e=>{const t=g.useContext(Sf);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return $x(t,e)};function jf(e){return`${e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((n,r)=>r===0?n.charAt(0).toLowerCase()+n.slice(1):n.charAt(0).toUpperCase()+n.slice(1)).join("")||"custom"}Component`}function _y(e){const t=jf(e);return`import { Type } from '@sinclair/typebox';
3
3
  import { createComponent, createVersion } from '@json-to-office/core-docx';
4
4
  import type { ComponentDefinition } from '@json-to-office/shared-docx';
5
5
 
@@ -145,7 +145,7 @@ export const ${t} = createComponent({
145
145
  },
146
146
  });
147
147
  `}function Cy(e,t){return e==="docx"?_y(t):Ny(t)}function Ey(e){const t=e.match(/createComponent\s*\(\s*\{[^}]*?\bname\s*:\s*(['"`])([^'"`]+)\1/);return t?t[2]:null}function Ty(e,t){return e.replace(/(createComponent\s*\(\s*\{[^}]*?\bname\s*:\s*)(['"`])([^'"`]+)\2/,(n,r,i)=>`${r}${i}${t}${i}`)}function Iy(e){const t=e.replace(/\.component\.ts$/i,"").replace(/\.ts$/i,"").trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return t?/^[a-z]/.test(t)?t:`x-${t}`:"custom-block"}function Ay(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function zy(e,t,n,r){const i={},s=[];e!=="delete"&&(i.name=Oi.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),s.push("name")),e==="create"&&(i.template=Oi.Optional(Oi.String({description:"Template selection"})));const o=Oi.Object(i,{additionalProperties:!1,required:s.length>0?s:void 0});return{schema:o,validate:a=>{const c=[];if(!jg(o,a))for(const d of _g(o,a))c.push({path:d.path.replace(/^\//,""),message:d.message});const u=a;if(e!=="delete"&&u.name){const d=u.name.trim();d?(u.name=d,t((r==null?void 0:r(d))??d)||c.push({path:"name",message:"Document with this name already exists"})):c.push({path:"name",message:"Name can't be empty"})}return e==="create"&&(n!=null&&n.length)&&u.template&&(n.some(d=>d.name===u.template)||c.push({path:"template",message:"You must select a valid template"})),{success:c.length===0,data:c.length===0?u:void 0,errors:c}}}}function Oy(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Py=e=>({create:{title:e==="theme"?"New Theme":e==="plugin"?"New Plugin":"New Document",description:e==="theme"?"Create a new theme from scratch or based on discovered themes.":e==="plugin"?"Write a custom component in TypeScript. It compiles and runs in your browser; documents use it by name like any built-in component.":"Create a new document from scratch or based on discovered documents.",button:"Create",buttonVariant:"default"},update:{title:"Rename Document",description:"Give your document a new name.",button:"Save",buttonVariant:"default"},delete:{title:"Are you absolutely sure?",description:"This action cannot be undone. Are you sure you want to permanently delete this document?",button:"Confirm",buttonVariant:"destructive"}}),Hn="__empty__";function Dy({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,discoveredPlugins:o,isTheme:a,isPlugin:c}){const[u,d]=g.useState(!1),[f,h]=g.useState(null),[p,m]=g.useState("idle"),{toast:v}=_r(),k=c?"plugin":a?"theme":"document",y=Py(k),{documents:_,openTabs:x,createDocument:A,renameDocument:E,deleteDocument:w,openDocument:S,closeDocument:O,documentTypes:B}=ke(I=>I),{updateTheme:N,removeTheme:R}=Io(I=>I),T=vn(I=>I.rename),F=vn(I=>I.remove),$=De(I=>I.renameThreadsForDocument),Z=De(I=>I.deleteThreadsForDocument),P=g.useMemo(()=>k==="plugin"?(o||[]).map(I=>({name:I.name,path:I.filePath,location:I.location==="current"?"current":"downstream",description:I.description})):k==="theme"?s||[]:i||[],[k,i,s,o]),J=g.useMemo(()=>{const I={current:[],downstream:[]};return P.forEach(re=>{I[re.location]&&I[re.location].push(re)}),I},[P]),V=g.useMemo(()=>P.map(I=>({name:I.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[P]),X=k==="plugin"||e==="update"&&!!r&&B[r]==="application/typescript+plugin",j=g.useMemo(()=>zy(e,I=>Ay(I,_,r),V,X?qs:void 0),[e,_,r,V,X]),ye=j.schema,ce=g.useMemo(()=>{const I=new Map;return P.forEach(re=>I.set(re.path,re)),I},[P]),b=Hn,G=vy({resolver:wy(j.validate),defaultValues:Oy(e,void 0,r)}),[ne,Q]=g.useState(b);g.useEffect(()=>{if(ne&&ne!==Hn&&e==="create"){const I=ce.get(ne);if(I){h(null),m("loading");let re=!1;const ae=k==="plugin"?`/api/discovery/plugins/${encodeURIComponent(I.name)}/source`:`/api/discovery/${k==="theme"?"themes":"documents"}/${encodeURIComponent(I.name)}/content`;return fetch(ae).then(H=>{if(!H.ok)throw new Error(`Failed to fetch content: ${H.statusText}`);return H.text()}).then(H=>{if(!re){if(k==="plugin"){const K=Ey(H);h(K?Ty(H,`${K}-custom`):H)}else{const K=JSON.parse(H);h(JSON.stringify(K,null,2))}m("idle")}}).catch(H=>{re||(console.error("Failed to copy template:",H),h(null),m("error"))}),()=>{re=!0}}}m("idle")},[ne,e,ce,k]),g.useEffect(()=>{t&&(G.reset(),h(null),m("idle"),Q(b))},[G,t]);const oe=G.handleSubmit(async({name:I,template:re})=>{d(!0);try{if(await new Promise(ae=>setTimeout(ae,200)),e==="create"){const ae=ne?ce.get(ne):P.find(z=>z.name===re);let H,K=I;if(!!ne&&ne!==Hn&&f===null){v({title:p==="loading"?"Template still loading":`Could not copy ${(ae==null?void 0:ae.name)??"the selected template"}`,description:p==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(k==="plugin")K=qs(K),H=f||Cy(at,Iy(K));else if(a){const z=K.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),L=at==="docx"?Ng(z):{name:z,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};H=f||JSON.stringify(L,null,2);const se=`.${at}.theme.json`;K.endsWith(se)||(K=K.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),K+=se)}else{const z=ae;H=f||JSON.stringify(at==="docx"?{name:"docx",props:{theme:(z==null?void 0:z.theme)||"default",metadata:{title:(z==null?void 0:z.title)||K.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(z==null?void 0:z.title)||K.replace(/\.(json|js)$/i,""),theme:(z==null?void 0:z.theme)||"default"},children:[{name:"slide",props:{},children:[{name:"text",props:{text:"Start writing your presentation content here...",fontSize:24,y:2,x:1,w:8}}]}]},null,2);const L=at==="docx"?".docx.json":".pptx.json";!K.endsWith(L)&&!K.endsWith(".json")&&(K+=L)}const fe=K.match(/(\.(pptx|docx)(\.theme)?\.json|\.json|\.component\.ts)$/i),Re=fe?fe[0]:"",Oe=K.slice(0,K.length-Re.length);let $e=K,C=1;for(;_.some(z=>z.name===$e);)C++,$e=`${Oe} (${C})${Re}`;K=$e,A(K,H),S(K),a&&N(K,H)}else if(e==="update"){const ae=r;let H=I;const K=B[ae]==="application/typescript+plugin";if(K&&(H=qs(H)),H!==ae&&_.some(fe=>fe.name===H)){v({title:`"${H}" already exists`,description:"Pick another name.",variant:"destructive"});return}const pe=x.includes(ae);pe&&O(ae),K&&T(ae,H),E(ae,H),$(ae,H),pe&&S(H)}else if(e==="delete"){const ae=r,H=B[ae]==="application/typescript+plugin";O(ae),w(ae),Z(ae),a&&R(ae),H&&F(ae)}n()}finally{d(!1)}});return l.jsx(ky,{...G,children:l.jsxs("form",{onSubmit:oe,children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:y[e].title}),l.jsx(dn,{children:y[e].description})]}),l.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[ye.properties&&"name"in ye.properties&&l.jsx(Al,{control:G.control,name:"name",render:({field:I})=>l.jsxs(Mo,{children:[l.jsx(Fo,{children:"Name"}),l.jsx(Lo,{children:l.jsx(br,{placeholder:"Enter a name or select a template below",autoComplete:"off",...I})}),l.jsx(Bo,{})]})}),e==="create"&&l.jsx(Al,{control:G.control,name:"template",render:({field:I})=>l.jsxs(Mo,{children:[l.jsx(Fo,{children:k==="theme"?"Base Theme":k==="plugin"?"Start from":"Base Document"}),l.jsxs(li,{onValueChange:re=>{if(re===Hn)I.onChange(void 0),G.setValue("name",""),Q(Hn),h(null);else{const ae=ce.get(re);ae&&(I.onChange(ae.name),G.setValue("name",ae.name),Q(re))}},defaultValue:b,children:[l.jsx(Lo,{children:l.jsx(xr,{children:l.jsx(ci,{placeholder:`Select a discovered ${k}`})})}),l.jsxs(yr,{className:"max-h-[300px]",children:[l.jsx(Mn,{value:Hn,children:k==="plugin"?`Starter ${at} component`:`Empty ${k}`}),Object.entries(J).map(([re,ae])=>ae.length===0?null:l.jsxs(ef,{children:[l.jsx(ka,{children:re==="current"?"📁 Current Directory":"📦 Project"}),ae.map(H=>{let K;return H.title&&H.title!==H.name?K=H.title:H.description&&(K=H.description.length>40?H.description.substring(0,40)+"...":H.description),l.jsx(Mn,{value:H.path,className:"pl-6",children:l.jsxs("span",{className:"flex flex-col",children:[l.jsx("span",{className:"font-medium",children:H.name}),K&&l.jsx("span",{className:"text-muted-foreground text-xs",children:K})]})},H.path)})]},re))]})]}),l.jsx(wf,{children:k==="plugin"?'Start from the starter component, or copy a plugin discovered on disk — the copy is renamed "<name>-custom" so both can exist':`Start empty or select a discovered ${k} as a starting point`}),l.jsx(Bo,{})]})})]}),l.jsx(kn,{children:l.jsx(Ce,{type:"submit",variant:y[e].buttonVariant,disabled:u,children:u?l.jsxs(l.Fragment,{children:[l.jsx(cn,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):y[e].button})})]})})}const Dn=je.memo(Dy);function on(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function zs({text:e,query:t}){if(!t)return l.jsx(l.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?l.jsx(l.Fragment,{children:e}):l.jsxs(l.Fragment,{children:[e.slice(0,n),l.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Zo({children:e,count:t,actions:n,className:r,open:i,onToggle:s}){const o=l.jsxs(l.Fragment,{children:[l.jsx(Cr,{"aria-hidden":!0,className:W("size-3 shrink-0 transition-transform duration-150 ease-out",i&&"rotate-90")}),l.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:e}),t!==void 0&&l.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t})]});return l.jsxs("div",{className:W("flex h-6 shrink-0 items-center gap-1.5 select-none",r),children:[l.jsx("button",{type:"button",onClick:s,"aria-expanded":i,className:W("flex h-6 min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-sm px-1","text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:o}),n&&l.jsx("div",{className:"flex shrink-0 items-center gap-0.5 pr-1",children:n})]})}const Et=je.forwardRef(({className:e,...t},n)=>l.jsx("button",{ref:n,type:"button",className:W("flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm","text-sidebar-foreground/55 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","disabled:pointer-events-none disabled:opacity-40","[&>svg]:size-3.5",e),...t}));Et.displayName="RailIconButton";function zl({tone:e,className:t}){return l.jsx("span",{"aria-hidden":!0,className:W("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function Vo({icon:e,label:t,onClick:n,hint:r}){return n?l.jsxs("button",{type:"button",onClick:n,title:r,className:W("flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[l.jsx(e,{className:"size-3.5 shrink-0"}),l.jsx("span",{className:"truncate",children:t})]}):l.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const _f=Lg,Nf=Bg,Ry=g.forwardRef(({className:e,inset:t,children:n,...r},i)=>l.jsxs(kd,{ref:i,className:W("focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none",t&&"pl-8",e),...r,children:[n,l.jsx(Cr,{className:"ml-auto h-4 w-4"})]}));Ry.displayName=kd.displayName;const $y=g.forwardRef(({className:e,...t},n)=>l.jsx(Sd,{ref:n,className:W("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));$y.displayName=Sd.displayName;const Ta=g.forwardRef(({className:e,...t},n)=>l.jsx(Zg,{children:l.jsx(bd,{ref:n,className:W("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md",e),...t})}));Ta.displayName=bd.displayName;const Ia=g.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(wd,{ref:r,className:W("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Ia.displayName=wd.displayName;const My=g.forwardRef(({className:e,children:t,checked:n,...r},i)=>l.jsxs(jd,{ref:i,className:W("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(_d,{children:l.jsx(un,{className:"h-4 w-4"})})}),t]}));My.displayName=jd.displayName;const Fy=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Nd,{ref:r,className:W("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(_d,{children:l.jsx(Ud,{className:"h-4 w-4 fill-current"})})}),t]}));Fy.displayName=Nd.displayName;const Ly=g.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Cd,{ref:r,className:W("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Ly.displayName=Cd.displayName;const Aa=g.forwardRef(({className:e,...t},n)=>l.jsx(vd,{ref:n,className:W("bg-border -mx-1 my-1 h-px",e),...t}));Aa.displayName=vd.displayName;const Cf=({className:e,...t})=>l.jsx("span",{className:W("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});Cf.displayName="ContextMenuShortcut";const _i=Vg,Ni=Ug,By=g.forwardRef(({className:e,inset:t,children:n,...r},i)=>l.jsxs(zd,{ref:i,className:W("focus:bg-accent data-[state=open]:bg-accent flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none select-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",e),...r,children:[n,l.jsx(Cr,{className:"ml-auto"})]}));By.displayName=zd.displayName;const Zy=g.forwardRef(({className:e,...t},n)=>l.jsx(Od,{ref:n,className:W("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));Zy.displayName=Od.displayName;const Er=g.forwardRef(({className:e,sideOffset:t=4,...n},r)=>l.jsx(Jg,{children:l.jsx(Ed,{ref:r,sideOffset:t,className:W("bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));Er.displayName=Ed.displayName;const $t=g.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Td,{ref:r,className:W("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",e),...n}));$t.displayName=Td.displayName;const Vy=g.forwardRef(({className:e,children:t,checked:n,...r},i)=>l.jsxs(Pd,{ref:i,className:W("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Dd,{children:l.jsx(un,{className:"h-4 w-4"})})}),t]}));Vy.displayName=Pd.displayName;const Uy=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Rd,{ref:r,className:W("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[l.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:l.jsx(Dd,{children:l.jsx(Ud,{className:"h-2 w-2 fill-current"})})}),t]}));Uy.displayName=Rd.displayName;const za=g.forwardRef(({className:e,inset:t,...n},r)=>l.jsx(Ad,{ref:r,className:W("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));za.displayName=Ad.displayName;const Fn=g.forwardRef(({className:e,...t},n)=>l.jsx(Id,{ref:n,className:W("bg-muted -mx-1 my-1 h-px",e),...t}));Fn.displayName=Id.displayName;const Ef=({className:e,...t})=>l.jsx("span",{className:W("ml-auto text-xs tracking-widest opacity-60",e),...t});Ef.displayName="DropdownMenuShortcut";const Tf=g.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>l.jsx($d,{ref:i,decorative:n,orientation:t,className:W("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Tf.displayName=$d.displayName;const If=cd,Jy=Hg,Hy=ud,Af=g.forwardRef(({className:e,...t},n)=>l.jsx(Cs,{className:W("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t,ref:n}));Af.displayName=Cs.displayName;const Wy=Si("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Oa=g.forwardRef(({side:e="right",className:t,children:n,...r},i)=>l.jsxs(Hy,{children:[l.jsx(Af,{}),l.jsxs(js,{ref:i,className:W(Wy({side:e}),t),...r,children:[l.jsxs(ya,{className:"ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none",children:[l.jsx(wn,{className:"h-4 w-4"}),l.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));Oa.displayName=js.displayName;const qy=g.forwardRef(({className:e,...t},n)=>l.jsx(_s,{ref:n,className:W("text-foreground text-lg font-semibold",e),...t}));qy.displayName=_s.displayName;const Gy=g.forwardRef(({className:e,...t},n)=>l.jsx(Ns,{ref:n,className:W("text-muted-foreground text-sm",e),...t}));Gy.displayName=Ns.displayName;function ti({className:e,...t}){return l.jsx("div",{className:W("bg-primary/10 animate-pulse rounded-md",e),...t})}const eo=768,to=1200;function zf(e){return typeof window<"u"?window.innerWidth<e:!1}function Of(){const[e,t]=g.useState(()=>zf(eo));return g.useEffect(()=>{const n=window.matchMedia(`(max-width: ${eo-1}px)`),r=()=>{t(window.innerWidth<eo)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function Ky(){const[e,t]=g.useState(()=>zf(to));return g.useEffect(()=>{const n=window.matchMedia(`(max-width: ${to-1}px)`),r=()=>{t(window.innerWidth<to)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const Yy="sidebar_state",Xy=60*60*24*7,Qy="16rem",eb="18rem",tb="3rem",nb="b",Pf=g.createContext(null);function Os(){const e=g.useContext(Pf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const Df=g.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...o},a)=>{const c=Of(),[u,d]=g.useState(!1),[f,h]=g.useState(e),p=t??f,m=g.useCallback(_=>{const x=typeof _=="function"?_(p):_;n?n(x):h(x),document.cookie=`${Yy}=${x}; path=/; max-age=${Xy}`},[n,p]),v=g.useCallback(()=>c?d(_=>!_):m(_=>!_),[c,m,d]);g.useEffect(()=>{const _=A=>{var S;const E=A;if(!E)return!1;const w=(S=E.tagName)==null?void 0:S.toLowerCase();return w==="input"||w==="textarea"||w==="select"||E.isContentEditable?!0:!!(E.closest&&E.closest(".monaco-editor"))},x=A=>{const E=A.metaKey||A.ctrlKey,w=A.key.toLowerCase();if(E&&w===nb){A.preventDefault(),v();return}E&&w==="s"&&!_(A.target)&&(A.preventDefault(),v())};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[v]);const k=p?"expanded":"collapsed",y=g.useMemo(()=>({state:k,open:p,setOpen:m,isMobile:c,openMobile:u,setOpenMobile:d,toggleSidebar:v}),[k,p,m,c,u,d,v]);return l.jsx(Pf.Provider,{value:y,children:l.jsx(Cg,{delayDuration:0,children:l.jsx("div",{style:{"--sidebar-width":Qy,"--sidebar-width-icon":tb,...i},className:W("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:a,...o,children:s})})})});Df.displayName="SidebarProvider";const Rf=g.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},o)=>{const{isMobile:a,state:c,openMobile:u,setOpenMobile:d}=Os();return n==="none"?l.jsx("div",{className:W("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:o,...s,children:i}):a?l.jsx(If,{open:u,onOpenChange:d,...s,children:l.jsx(Oa,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":eb},side:e,children:l.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):l.jsxs("div",{ref:o,className:"group peer text-sidebar-foreground hidden md:block","data-state":c,"data-collapsible":c==="collapsed"?n:"","data-variant":t,"data-side":e,children:[l.jsx("div",{className:W("relative h-svh w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),l.jsx("div",{className:W("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",e==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...s,children:l.jsx("div",{"data-sidebar":"sidebar",className:"bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow",children:i})})]})});Rf.displayName="Sidebar";const rb=g.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=Os();return l.jsxs(Ce,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:W("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[l.jsx(tx,{}),l.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});rb.displayName="SidebarTrigger";const ib=g.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=Os();return l.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:W("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:hover:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",e),...t})});ib.displayName="SidebarRail";const sb=g.forwardRef(({className:e,...t},n)=>l.jsx("main",{ref:n,className:W("bg-background relative flex min-h-svh flex-1 flex-col","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2",e),...t}));sb.displayName="SidebarInset";const ob=g.forwardRef(({className:e,...t},n)=>l.jsx(br,{ref:n,"data-sidebar":"input",className:W("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));ob.displayName="SidebarInput";const Uo=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,"data-sidebar":"header",className:W("flex flex-col gap-2 p-2",e),...t}));Uo.displayName="SidebarHeader";const $f=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,"data-sidebar":"footer",className:W("flex flex-col gap-2 p-2",e),...t}));$f.displayName="SidebarFooter";const ab=g.forwardRef(({className:e,...t},n)=>l.jsx(Tf,{ref:n,"data-sidebar":"separator",className:W("bg-sidebar-border mx-2 w-auto",e),...t}));ab.displayName="SidebarSeparator";const Jo=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,"data-sidebar":"content",className:W("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Jo.displayName="SidebarContent";const lb=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,"data-sidebar":"group",className:W("relative flex w-full min-w-0 flex-col p-2",e),...t}));lb.displayName="SidebarGroup";const cb=g.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Nr:"div";return l.jsx(i,{ref:r,"data-sidebar":"group-label",className:W("text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium transition-[margin,opa] duration-200 ease-linear outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",e),...n})});cb.displayName="SidebarGroupLabel";const ub=g.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Nr:"button";return l.jsx(i,{ref:r,"data-sidebar":"group-action",className:W("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",e),...n})});ub.displayName="SidebarGroupAction";const db=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,"data-sidebar":"group-content",className:W("w-full text-sm",e),...t}));db.displayName="SidebarGroupContent";const er=g.forwardRef(({className:e,...t},n)=>l.jsx("ul",{ref:n,"data-sidebar":"menu",className:W("flex w-full min-w-0 flex-col gap-1",e),...t}));er.displayName="SidebarMenu";const Mf=g.forwardRef(({className:e,...t},n)=>l.jsx("li",{ref:n,"data-sidebar":"menu-item",className:W("group/menu-item relative",e),...t}));Mf.displayName="SidebarMenuItem";const fb=Si("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),Ff=g.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...o},a)=>{const c=e?Nr:"button",{isMobile:u,state:d}=Os(),f=l.jsx(c,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:W(fb({variant:n,size:r}),s),...o});return i?(typeof i=="string"&&(i={children:i}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:f}),l.jsx(Qe,{side:"right",align:"center",hidden:d!=="collapsed"||u,...i})]})):f});Ff.displayName="SidebarMenuButton";const Lf=g.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?Nr:"button";return l.jsx(s,{ref:i,"data-sidebar":"menu-action",className:W("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",e),...r})});Lf.displayName="SidebarMenuAction";const pb=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:W("text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",e),...t}));pb.displayName="SidebarMenuBadge";const hb=g.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=g.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return l.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:W("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&l.jsx(ti,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),l.jsx(ti,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});hb.displayName="SidebarMenuSkeleton";const mb=g.forwardRef(({className:e,...t},n)=>l.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:W("border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",e),...t}));mb.displayName="SidebarMenuSub";const gb=g.forwardRef(({...e},t)=>l.jsx("li",{ref:t,...e}));gb.displayName="SidebarMenuSubItem";const xb=g.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const o=e?Nr:"a";return l.jsx(o,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:W("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...i})});xb.displayName="SidebarMenuSubButton";function ni(e,t){const n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.style.display="none",r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}const yb=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function bb({document:e,compact:t=!1,query:n=""}){const r=g.useRef(null),[i,s]=g.useState(!1),[o,a]=g.useState(!1),[c,u]=g.useState(!1),[d,f]=g.useState(!1),h=ke(b=>b.openDocument),p=ke(b=>b.documentTypes),m=ke(b=>b.activeTab),v=an(b=>b.name),k=an(b=>b.text),y=an(b=>b.isGenerating),_=p[e.name]||"application/json+report",x=_==="application/json+theme",A=_==="application/typescript+plugin",E=m===e.name,[w,S]=g.useState(v),[O,B]=g.useState(k),N=100,R=0;g.useEffect(()=>{const b=setTimeout(()=>{v&&k?(S(v),B(k)):y||(S(""),B(""))},y?N:R);return()=>clearTimeout(b)},[v,k,y]);const T=w===e.name,F=b=>{var ne;const G=new Set;try{const Q=JSON.parse(b);(ne=Q.props)!=null&&ne.theme&&G.add(Q.props.theme),Q.children&&Array.isArray(Q.children)&&Q.children.forEach(oe=>{var I;oe.name==="docx"&&((I=oe.props)!=null&&I.theme)&&G.add(oe.props.theme)})}catch{}return G},$=g.useMemo(()=>{if(!x||!O)return!1;try{const b=JSON.parse(e.text),G=pg(b);if(G)return F(O).has(G)}catch{}return!1},[x,O,e.text]),Z=g.useCallback(()=>{u(!1)},[]),P=g.useCallback(()=>{f(!1)},[]),J=E?null:T?"preview":$?"in-use":null,V=E?"Editing":T?"In preview":$?"Used by preview":null,X=g.useMemo(()=>[{key:"open",label:"Open",shortcut:yb?"⌘⏎":"⌃⏎",run:()=>h(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>ni(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>u(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>f(!0)}],[e.name,e.text,e.type,h]),j=x?nx:A?Jd:Hd,ye=i||o,ce=l.jsxs(Ff,{size:"sm",ref:r,"aria-label":V?`${e.name} — ${V}`:e.name,className:W("relative h-7 rounded-sm text-[13px] font-normal","text-sidebar-foreground/85 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground",t?"size-7 justify-center px-0":"gap-2 pr-7 pl-2",ye&&"bg-sidebar-accent/60 text-sidebar-foreground",E&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:V?`${e.name} — ${V}`:e.name,onClick:()=>{h(e.name)},onKeyDown:b=>{var G;(b.ctrlKey||b.metaKey)&&b.key==="Enter"?(h(e.name),b.preventDefault()):b.key==="Enter"?(u(!0),b.preventDefault()):b.key==="Backspace"||b.key==="Delete"?(f(!0),b.preventDefault()):b.key==="Escape"&&((G=r.current)==null||G.blur(),b.preventDefault())},children:[E&&l.jsx("span",{"aria-hidden":!0,className:W("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),l.jsx(j,{className:W("size-3.5 shrink-0",x?"text-accent2":"text-sidebar-foreground/60",E&&!x&&"text-sidebar-accent-foreground/70")}),!t&&l.jsx("span",{className:"flex-1 truncate",children:l.jsx(zs,{text:e.name,query:n})}),t&&J&&l.jsx(zl,{tone:J,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return l.jsxs(Mf,{children:[l.jsxs(_f,{onOpenChange:s,children:[l.jsx(Nf,{className:"block",children:t?l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:ce}),l.jsx(Qe,{side:"right",children:l.jsxs("div",{className:"text-xs",children:[l.jsx("div",{children:e.name}),l.jsx("div",{className:"opacity-70",children:V??(x?"Theme":A?"Plugin":"Document")})]})})]}):ce}),l.jsx(Ta,{className:"w-44",children:X.map(b=>l.jsxs(je.Fragment,{children:[b.separatorBefore&&l.jsx(Aa,{}),l.jsxs(Ia,{onClick:b.run,className:W(b.danger&&"text-destructive focus:text-destructive"),children:[b.label,b.shortcut&&l.jsx(Cf,{children:b.shortcut})]})]},b.key))})]}),!t&&l.jsxs(l.Fragment,{children:[J&&l.jsx(zl,{tone:J,className:W("pointer-events-none absolute top-1/2 right-2.5 -translate-y-1/2 transition-opacity","group-hover/menu-item:opacity-0 group-focus-within/menu-item:opacity-0",o&&"opacity-0")}),l.jsxs(_i,{onOpenChange:a,children:[l.jsx(Ni,{asChild:!0,children:l.jsx(Lf,{showOnHover:!0,"aria-label":`Actions for ${e.name}`,className:"top-1 size-5 rounded-sm text-sidebar-foreground/55 hover:text-sidebar-foreground [&>svg]:size-3.5",children:l.jsx(ba,{})})}),l.jsx(Er,{side:"right",align:"start",className:"w-44",children:X.map(b=>l.jsxs(je.Fragment,{children:[b.separatorBefore&&l.jsx(Fn,{}),l.jsxs($t,{onClick:b.run,className:W(b.danger&&"text-destructive focus:text-destructive"),children:[b.label,b.shortcut&&l.jsx(Ef,{children:b.shortcut})]})]},b.key))})]})]}),l.jsx(ct,{open:c,onOpenChange:u,children:l.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:b=>{var G;b.preventDefault(),(G=r.current)==null||G.focus()},children:l.jsx(Dn,{mode:"update",shouldReset:!c,postSubmit:Z,selectedName:e.name})})}),l.jsx(ct,{open:d,onOpenChange:f,children:l.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:b=>{var G;b.preventDefault(),(G=r.current)==null||G.focus()},children:l.jsx(Dn,{mode:"delete",shouldReset:!d,postSubmit:P,selectedName:e.name})})})]})}const Mr=je.memo(bb),vb=60,wb=/§jtoc:\d+§/g;function Ae(e,t){if(!(!e||e.type!=="object"||!e.children))for(const n of e.children){if(n.type!=="property"||!n.children)continue;const[r,i]=n.children;if((r==null?void 0:r.value)===t)return i}}function ot(e){return(e==null?void 0:e.type)==="string"&&typeof e.value=="string"?e.value:void 0}function Ho(e){return(e==null?void 0:e.type)==="number"&&typeof e.value=="number"?e.value:void 0}function It(e){return(e==null?void 0:e.type)==="array"&&e.children?e.children:[]}function St(e,t=vb,n=!1){const r=e.replace(wb,"…"),i=n?r.replace(/\s*\n\s*/g," ").trim():r.split(`
148
- `)[0].trim();return i.length>t?`${i.slice(0,t-1)}…`:i}function kb(e){const t=It(Ae(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>It(Ae(i,"cells")).length))}×${t.length}`;const n=It(Ae(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?It(r).length:It(Ae(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Sb(e){const t=ot(Ae(e,"alt"));if(t)return St(t);const n=ot(Ae(e,"src"));if(n){if(n.startsWith("data:")){const i=n.slice(5).split(/[;,]/)[0];return i?`image (${i.split("/").pop()})`:"image"}const r=n.split(/[?#]/)[0].split("/").pop();if(r)return St(r,40)}return"image"}function jb(e,t){var r;const n=ot(Ae(t,"text"));switch(e){case"heading":{const i=Ho(Ae(t,"level"))??1;return{label:n?St(n):"heading",detail:`H${i}`}}case"text":return{label:n?St(n):"text",detail:ot(Ae(t,"style"))};case"paragraph":return{label:n?St(n):"paragraph"};case"chart":case"highcharts":{const i=ot(Ae(t,"title"))??ot(Ae(Ae(t,"options"),"title"));return{label:i?St(i):e,detail:ot(Ae(t,"type"))}}case"table":return{label:"table",detail:kb(t)};case"image":return{label:Sb(t)};case"shape":return{label:ot(Ae(t,"type"))??"shape"};case"list":{const i=It(Ae(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=ot(Ae(Ae(t,"meta"),"title"))??ot(Ae(t,"title"));return{label:i?St(i):"section"}}case"statistic":{const i=ot(Ae(t,"value"))??((r=Ho(Ae(t,"value")))==null?void 0:r.toString()),s=ot(Ae(t,"label"));return{label:St(s??i??"statistic"),detail:i}}default:return{label:n?St(n):e}}}function Ci(e){if(e.type!=="object")return null;const t=ot(Ae(e,"name"));return t?{name:t,props:Ae(e,"props"),childrenArr:Ae(e,"children")}:null}function _b(e){let t;for(const n of It(e)){const r=Ci(n);if(!r)continue;const i=ot(Ae(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return St(i,48);r.name==="paragraph"&&t===void 0&&(t=St(i,48))}}return t}function ss(e,t,n){let{label:r,detail:i}=jb(t.name,t.props);return r===t.name&&t.childrenArr&&(r=_b(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:Bf(t.childrenArr),reorder:n}}function Bf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of It(e)){const i=Ci(r);i&&n.push(ss(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Nb(e){const t=Ae(e,"props"),n=ot(Ae(Ae(t,"meta"),"title"));if(n)return St(n,48,!0);let r;const i=(o,a)=>{a&&(!r||o<r.rank)&&(r={rank:o,text:a})},s=(o,a)=>{const c=Ci(o);if(c){if(c.name==="block"){const u=Ae(c.props,"slots");if((u==null?void 0:u.type)==="object"&&u.children)for(const d of u.children){if(d.type!=="property"||!d.children)continue;const[f,h]=d.children,p=typeof(f==null?void 0:f.value)=="string"?f.value:"",m=h?ot(h):void 0;i(p==="title"?0:p==="subtitle"||p.startsWith("heading")?1:2,m)}return}if(c.name==="text"||c.name==="heading"){const u=ot(Ae(c.props,"text"));if(u){const d=ot(Ae(c.props,"style"))??"";i(d==="title"?0:d.startsWith("heading")?1:2,u)}}if(a<1)for(const u of It(c.childrenArr))s(u,a+1)}};for(const o of It(Ae(e,"children")))s(o,0);return r?St(r.text,48,!0):void 0}function Cb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of It(t)){const o=Ci(s);if(!o)continue;const a={groupId:n,sliceStart:s.offset,sliceEnd:s.offset+s.length};o.name==="slide"?(i+=1,r.push({id:"",kind:"slide",label:Nb(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:Bf(o.childrenArr),reorder:a})):r.push(ss(s,o,a))}return r}function Eb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const o of It(t)){const a=Ci(o);if(!a)continue;const c={groupId:n,sliceStart:o.offset,sliceEnd:o.offset+o.length},u=()=>i.length?i[i.length-1].node.children:r;if(a.name==="heading"){const d=Ho(Ae(a.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=ss(o,a,c);u().push(f),i.push({level:d,node:f})}else u().push(ss(o,a,c))}const s=o=>{o.children.forEach(s);const a=o.children[o.children.length-1];o.kind==="heading"&&a&&(o.end=Math.max(o.end,a.end),o.reorder&&a.reorder&&(o.reorder.sliceEnd=Math.max(o.reorder.sliceEnd,a.reorder.sliceEnd)))};return r.forEach(s),r}function Ol(e){switch(e.type){case"string":return St(String(e.value??""),24);case"number":case"boolean":return String(e.value);case"array":return`${It(e).length} items`;case"object":return;default:return}}function Tb(e){if(e.type!=="object"||!e.children)return[];const t=[];for(const n of e.children){if(n.type!=="property"||!n.children)continue;const[r,i]=n.children,s=typeof(r==null?void 0:r.value)=="string"?r.value:void 0;if(!s||s==="$schema"||!i)continue;const o=[];if(i.type==="object"&&i.children)for(const a of i.children){if(a.type!=="property"||!a.children)continue;const[c,u]=a.children,d=typeof(c==null?void 0:c.value)=="string"?c.value:void 0;!d||!u||o.push({id:"",kind:"key",label:d,detail:Ol(u),start:a.offset,end:a.offset+a.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:o.length===0?Ol(i):void 0,start:n.offset,end:n.offset+n.length,children:o})}return t}function Pl(e,t,n){if(!e.trim())return[];const r=Eg(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Tb(r):t==="pptx"?Cb(r):Eb(r);return Zf(i,""),i}function Zf(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,Zf(n.children,n.id)})}function Vf(e,t){const n=[];let r=e;for(;;){const i=r.find(s=>t>=s.start&&t<s.end);if(!i)return n;n.push(i.id),r=i.children}}function Ib(e,t){const n=new Set;for(const r of t)for(const i of Vf(e,r))n.add(i);return n}function Ab(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(d=>d.reorder);if(i.some(d=>!d))return null;const s=i[0].groupId;if(i.some(d=>d.groupId!==s))return null;for(let d=1;d<i.length;d++)if(i[d].sliceStart<i[d-1].sliceEnd)return null;const o=i.map(d=>e.slice(d.sliceStart,d.sliceEnd)),a=[];for(let d=1;d<i.length;d++){const f=e.slice(i[d-1].sliceEnd,i[d].sliceStart);if((f.match(/,/g)??[]).length!==1)return null;a.push(f)}const c=o.map((d,f)=>f);c.splice(r,0,c.splice(n,1)[0]);let u="";return c.forEach((d,f)=>{u+=o[d],f<a.length&&(u+=a[f])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:u}}const zb={slide:ux,heading:cx,text:Ao,paragraph:lx,chart:Oo,highcharts:Oo,table:ax,image:ox,shape:Wd,list:sx,toc:ix,section:zo,columns:zo,"text-box":Ao,statistic:rx,key:Qi};function Ob(e,t){let n=e,r=null;for(const i of t.split(".")){if(r=n[Number(i)]??null,!r)return null;n=r.children}return r}function Pb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function Db(){const{activeTab:e,documentTypes:t}=ke(wa(S=>({activeTab:S.activeTab,documentTypes:S.documentTypes}))),n=ke(S=>{var O;return S.activeTab?(O=S.documents.find(B=>B.name===S.activeTab))==null?void 0:O.text:void 0}),r=sd(S=>e?S.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,o]=g.useState([]),[a,c]=g.useState(null),[u,d]=g.useState(()=>new Set),[f,h]=g.useState(()=>new Set),[p,m]=g.useState(null),v=g.useRef(s);v.current=s;const k=g.useRef(null),y=g.useRef(null),_=g.useCallback(()=>{var B;if(!e){o([]);return}const S=((B=r==null?void 0:r.editor.getModel())==null?void 0:B.getValue())??n??"",O=Pl(S,at,i);if(o(O),y.current!==e){y.current=e;const N=new Set;if(i==="document"&&at==="docx")for(const R of O)R.kind==="heading"&&N.add(R.id);h(N),c(null)}},[e,r,n,i]);g.useEffect(()=>{_();const S=r==null?void 0:r.editor.getModel();if(!S)return;const O=xl(_,300),B=S.onDidChangeContent(()=>O());return()=>{O.cancel(),B.dispose()}},[_,r]),g.useEffect(()=>{if(!r)return;const{editor:S}=r,O=xl(()=>{const N=S.getModel(),R=S.getPosition();if(!N||!R)return;const T=N.getOffsetAt(R),F=Vf(v.current,T);if(F.length===0){c(null);return}c(F[F.length-1]);const $=F.slice(0,-1);$.length&&h(Z=>{if($.every(J=>Z.has(J)))return Z;const P=new Set(Z);for(const J of $)P.add(J);return P})},150),B=S.onDidChangeCursorPosition(()=>O());return()=>{O.cancel(),B.dispose()}},[r]),g.useEffect(()=>{if(!a||!k.current)return;const S=k.current.querySelector(`[data-oid="${CSS.escape(a)}"]`);S==null||S.scrollIntoView({block:"nearest"})},[a]),g.useEffect(()=>{if(!r){d(new Set);return}const{editor:S,monaco:O}=r,B=()=>{const R=S.getModel();if(!R)return;const T=O.editor.getModelMarkers({resource:R.uri}).filter(F=>F.severity===O.MarkerSeverity.Error).map(F=>R.getOffsetAt({lineNumber:F.startLineNumber,column:F.startColumn}));d(Ib(v.current,T))};B();const N=O.editor.onDidChangeMarkers(R=>{const T=S.getModel();T&&R.some(F=>F.toString()===T.uri.toString())&&B()});return()=>N.dispose()},[r,s]);const x=g.useCallback(S=>{h(O=>{const B=new Set(O);return B.has(S)?B.delete(S):B.add(S),B})},[]),A=g.useCallback(S=>{if(c(S.id),!r)return;const{editor:O,monaco:B}=r,N=O.getModel();if(!N)return;const R=N.getPositionAt(S.start),T=N.getPositionAt(S.end),F=new B.Range(R.lineNumber,R.column,T.lineNumber,T.column);O.revealRangeNearTopIfOutsideViewport(F,B.editor.ScrollType.Smooth),O.setPosition(R),O.focus();const $=O.deltaDecorations([],[{range:F,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>O.deltaDecorations($,[]),700)},[r]),E=g.useCallback(S=>{var ye;if(!r||!S.overId)return;const{editor:O,monaco:B,collapse:N}=r,R=O.getModel();if(!R)return;const T=R.getValue(),F=Pl(T,at,i),$=S.parentId?((ye=Ob(F,S.parentId))==null?void 0:ye.children)??[]:F,Z=$.findIndex(ce=>ce.id===S.dragId),P=$.findIndex(ce=>ce.id===S.overId);if(Z===-1||P===-1)return;let J=P+(S.overHalf==="after"?1:0);Z<J&&(J-=1);const V=Ab(T,$,Z,J);if(!V)return;const X=R.getPositionAt(V.start),j=R.getPositionAt(V.end);O.executeEdits("outline-reorder",[{range:new B.Range(X.lineNumber,X.column,j.lineNumber,j.column),text:V.text}]),N==null||N.resyncDecorations()},[r,i]),w=g.useMemo(()=>{const S=[],O=(B,N,R)=>{var $,Z;const T=(Z=($=B[0])==null?void 0:$.reorder)==null?void 0:Z.groupId,F=B.length>1&&T!==void 0&&B.every(P=>{var J;return((J=P.reorder)==null?void 0:J.groupId)===T});B.forEach(P=>{const J=zb[P.kind]??dx,V=P.children.length>0,X=f.has(P.id),j=a===P.id,ye=(p==null?void 0:p.overId)===P.id;S.push(l.jsxs("div",{"data-oid":P.id,role:"treeitem","aria-selected":j,"aria-expanded":V?X:void 0,tabIndex:0,draggable:F,onClick:()=>A(P),onKeyDown:ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),A(P)),ce.key==="ArrowRight"&&V&&!X&&x(P.id),ce.key==="ArrowLeft"&&V&&X&&x(P.id)},onDragStart:ce=>{ce.dataTransfer.setData("text/plain",P.id),ce.dataTransfer.effectAllowed="move",m({dragId:P.id,parentId:R,overId:null,overHalf:"before"})},onDragOver:ce=>{if(!p||p.dragId===P.id||Pb(p.dragId)!==R)return;ce.preventDefault(),ce.dataTransfer.dropEffect="move";const b=ce.currentTarget.getBoundingClientRect(),G=ce.clientY<b.top+b.height/2?"before":"after";(p.overId!==P.id||p.overHalf!==G)&&m({...p,overId:P.id,overHalf:G})},onDrop:ce=>{ce.preventDefault(),p&&E({...p,overId:P.id,overHalf:p.overHalf}),m(null)},onDragEnd:()=>m(null),className:W("group flex h-6 w-full cursor-pointer items-center gap-1 rounded-sm pr-1","text-[12px] text-sidebar-foreground/80 transition-colors select-none","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none",j&&"bg-sidebar-accent font-medium text-sidebar-foreground",ye&&(p==null?void 0:p.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",ye&&(p==null?void 0:p.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+N*12},children:[V?l.jsx("span",{role:"button","aria-label":X?"Collapse":"Expand",onClick:ce=>{ce.stopPropagation(),x(P.id)},className:"flex size-3.5 shrink-0 items-center justify-center rounded-xs text-sidebar-foreground/55 hover:text-sidebar-foreground",children:l.jsx(Cr,{className:W("size-3 transition-transform",X&&"rotate-90")})}):l.jsx("span",{className:"size-3.5 shrink-0"}),P.kind==="slide"&&l.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:P.detail}),l.jsx(J,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),l.jsx("span",{className:"min-w-0 flex-1 truncate",children:P.label}),P.kind!=="slide"&&P.detail&&l.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:P.detail}),u.has(P.id)&&l.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},P.id)),V&&X&&O(P.children,N+1,P.id)})};return O(s,0,""),S},[s,f,a,u,p,A,x,E]);return!e||s.length===0?null:l.jsx("li",{className:"list-none",children:l.jsx("div",{ref:k,role:"tree","aria-label":`Outline of ${e}`,className:"border-sidebar-border/70 my-0.5 ml-[15px] max-h-[38vh] overflow-y-auto border-l pl-1",children:w})})}const Dl=g.memo(Db);async function Rb(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const ui=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Md,{ref:r,className:W("relative overflow-hidden",e),...n,children:[l.jsx(Wg,{className:"h-full w-full rounded-[inherit]",children:t}),l.jsx(Uf,{}),l.jsx(qg,{})]}));ui.displayName=Md.displayName;const Uf=g.forwardRef(({className:e,orientation:t="vertical",...n},r)=>l.jsx(Fd,{ref:r,orientation:t,className:W("flex touch-none transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:l.jsx(Gg,{className:"bg-border relative flex-1 rounded-full"})}));Uf.displayName=Fd.displayName;function Pa({className:e,...t}){return l.jsx(Kg,{"data-slot":"switch",className:W("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-switch-off focus-visible:ring-ring inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent transition-colors outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:l.jsx(Yg,{"data-slot":"switch-thumb",className:W("bg-background pointer-events-none block size-4 rounded-full shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const $b=Si("relative w-full rounded-sm border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-card text-foreground",destructive:"border-transparent bg-destructive-bg text-destructive-bg-foreground [&>svg]:text-destructive-bg-foreground",warning:"border-transparent bg-warning-bg text-warning-bg-foreground [&>svg]:text-warning-bg-foreground",success:"border-transparent bg-success-bg text-success-bg-foreground [&>svg]:text-success-bg-foreground",info:"border-transparent bg-data-blue-bg text-data-blue-bg-foreground [&>svg]:text-data-blue-bg-foreground"}},defaultVariants:{variant:"default"}}),lr=g.forwardRef(({className:e,variant:t,...n},r)=>l.jsx("div",{ref:r,role:"alert",className:W($b({variant:t}),e),...n}));lr.displayName="Alert";const Mb=g.forwardRef(({className:e,...t},n)=>l.jsx("h5",{ref:n,className:W("mb-1 font-medium leading-none tracking-tight",e),...t}));Mb.displayName="AlertTitle";const cr=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:W("text-sm [&_p]:leading-relaxed",e),...t}));cr.displayName="AlertDescription";const os=g.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=g.useState(n<2),o=t!==null&&typeof t=="object",a=Array.isArray(t),c=()=>s(!i),u=()=>t===null?l.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?l.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?l.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?l.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?l.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?l.jsxs("span",{className:"text-warning",children:['"',t,'"']}):l.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,d=o?Object.keys(t).length:0;return l.jsxs("div",{className:W("text-sm",n>0&&"ml-4"),children:[l.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[o&&l.jsx("button",{onClick:c,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?l.jsx(ki,{className:"h-3 w-3"}):l.jsx(Cr,{className:"h-3 w-3"})}),!o&&l.jsx("span",{className:"w-4"}),e&&l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),l.jsx("span",{className:"mx-1",children:":"})]}),o?l.jsxs("span",{className:"text-muted-foreground",children:[a?"[":"{",!i&&l.jsxs("span",{className:"mx-1 text-xs",children:[d," ",a?"items":"properties"]}),!i&&(a?"]":"}")]}):u(),!o&&!r&&l.jsx("span",{className:"text-muted-foreground",children:","})]}),o&&i&&l.jsxs("div",{className:"ml-4",children:[a?t.map((f,h)=>l.jsx(os,{keyName:String(h),value:f,depth:n+1,isLast:h===t.length-1},h)):Object.entries(t).map(([f,h],p,m)=>l.jsx(os,{keyName:f,value:h,depth:n+1,isLast:p===m.length-1},f)),l.jsx("div",{className:"ml-4",children:l.jsxs("span",{className:"text-muted-foreground",children:[a?"]":"}",!r&&","]})})]})]})});os.displayName="JsonNode";const as=g.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?l.jsxs("div",{className:W("space-y-4",r),children:[l.jsx(ti,{className:"h-8 w-64"}),l.jsx(ti,{className:"h-4 w-full"}),l.jsx(ti,{className:"h-64 w-full"})]}):n?l.jsx(lr,{variant:"destructive",className:r,children:l.jsx(cr,{children:n})}):e?l.jsx(ui,{className:W("h-full w-full rounded-md border bg-muted/10 p-4",r),children:l.jsx("div",{className:"font-mono text-xs",children:l.jsx(os,{value:e})})}):l.jsx(lr,{className:r,children:l.jsx(cr,{children:"No schema available"})}));as.displayName="SchemaViewer";function Fb({plugins:e,initialFocusedPlugin:t}){var x,A;const n=Jt(E=>E.togglePlugin),r=Jt(E=>E.isPluginSelected),i=Jt(E=>E.selectedPlugins),s=Jt(E=>E.isApplyingPlugins),[o,a]=g.useState(null),[c,u]=g.useState(null),[d,f]=g.useState("properties");g.useEffect(()=>{if(t){const E=e.find(w=>w.name===t);if(E){a(E);return}}e.length>0&&!o&&a(e[0])},[t,e]);const h=g.useMemo(()=>{const E={current:[],downstream:[],upstream:[]};return e.forEach(w=>{E[w.location]&&E[w.location].push(w)}),E},[e]),p=async(E,w)=>{o&&(await Rb(o.name,E.props),u(w),setTimeout(()=>u(null),2e3))},m=E=>{switch(E){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return E}},v=E=>{switch(E){case"current":return l.jsx(xx,{className:"size-3"});case"downstream":return l.jsx(gx,{className:"size-3"});case"upstream":return l.jsx(Hd,{className:"size-3"});default:return null}},k=((x=o==null?void 0:o.schema)==null?void 0:x.properties)&&Object.keys(o.schema.properties).length>0,y=(A=o==null?void 0:o.schema)==null?void 0:A.jsonSchema,_=(o==null?void 0:o.examples)&&o.examples.length>0;return l.jsxs(l.Fragment,{children:[l.jsxs(qt,{children:[l.jsxs(Gt,{className:"flex items-center gap-2",children:[l.jsx(fx,{className:"size-5 text-warning"}),"Plugins",l.jsxs(tn,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),l.jsxs(dn,{children:[e.length," plugin",e.length!==1?"s":""," discovered in your project"]})]}),l.jsxs("div",{className:"mt-3 flex gap-0 h-[600px] border rounded-lg overflow-hidden",children:[l.jsx("div",{className:"w-[240px] flex-none border-r bg-muted/30",children:l.jsx(ui,{className:"h-full",children:l.jsx("div",{className:"p-2 space-y-3",children:Object.entries(h).map(([E,w])=>w.length===0?null:l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[v(E),m(E)]}),l.jsx("div",{className:"space-y-0.5",children:w.map(S=>{const O=r(S.name),B=(o==null?void 0:o.name)===S.name;return l.jsxs("button",{onClick:()=>a(S),className:W("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",B?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[l.jsx("div",{className:W("size-1.5 rounded-full flex-none transition-colors",O?"bg-warning":"bg-muted-foreground/30")}),l.jsx("span",{className:"text-sm font-medium truncate flex-1",children:S.name})]},S.name)})})]},E))})})}),o?l.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[l.jsxs("div",{className:"flex-none px-5 py-4 border-b bg-background",children:[l.jsxs("div",{className:"flex items-start justify-between gap-3",children:[l.jsxs("div",{className:"min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx("h3",{className:"text-base font-semibold truncate",children:o.name}),o.version&&l.jsxs(tn,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",o.version]})]}),o.description&&l.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:o.description})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-none pt-0.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:r(o.name)?"On":"Off"}),l.jsx(Pa,{checked:r(o.name),onCheckedChange:()=>n(o),disabled:s,"aria-label":`Toggle ${o.name}`})]})]}),l.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[v(o.location),l.jsx("span",{children:m(o.location)}),l.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),l.jsx("span",{className:"font-mono truncate",children:o.relativePath})]})]}),l.jsxs("div",{className:"flex-none px-5 pt-3 pb-0 flex gap-1 border-b bg-background",children:[k&&l.jsx("button",{onClick:()=>f("properties"),className:W("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[l.jsx(Qi,{className:"size-3.5"}),"Properties"]})}),y&&l.jsx("button",{onClick:()=>f("schema"),className:W("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[l.jsx(px,{className:"size-3.5"}),"Schema"]})}),_&&l.jsx("button",{onClick:()=>f("examples"),className:W("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[l.jsx(hx,{className:"size-3.5"}),"Examples",l.jsx(tn,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:o.examples.length})]})})]}),l.jsx(ui,{className:"flex-1",children:l.jsxs("div",{className:"p-5",children:[d==="properties"&&k&&l.jsx("div",{className:"space-y-1",children:Object.entries(o.schema.properties).map(([E,w])=>l.jsx(Lb,{name:E,prop:w},E))}),d==="schema"&&y&&l.jsx(as,{schema:o.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&_&&o.examples.map((E,w)=>l.jsxs("div",{className:W(w>0&&"mt-4 pt-4 border-t"),children:[l.jsxs("div",{className:"flex items-center justify-between mb-2",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[E.title&&l.jsx("span",{className:"font-medium text-sm truncate",children:E.title}),!E.title&&l.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),l.jsx(Ce,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>p(E,w),children:c===w?l.jsxs(l.Fragment,{children:[l.jsx(mx,{className:"size-3 mr-1 text-success"}),"Copied"]}):l.jsxs(l.Fragment,{children:[l.jsx(Es,{className:"size-3 mr-1"}),"Copy"]})})]}),E.description&&l.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:E.description}),l.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(E.props,null,2)})]},w)),!k&&!y&&!_&&l.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[l.jsx(Qi,{className:"size-10 mx-auto mb-3 opacity-20"}),l.jsx("p",{className:"text-sm",children:"No schema or examples available for this plugin"})]})]})})]}):l.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:l.jsx("p",{className:"text-sm",children:"Select a plugin to view details"})})]})]})}function Lb({name:e,prop:t}){var o;const[n,r]=g.useState(!1),i=t.description||t.enum||t.default!==void 0||t.items||t.properties,s=t.type||(t.enum?"enum":t.oneOf?"oneOf":"—");return l.jsxs("div",{className:"rounded-md border",children:[l.jsxs("button",{onClick:()=>i&&r(!n),className:W("w-full text-left flex items-center gap-2 px-3 py-2 text-sm",i&&"cursor-pointer hover:bg-muted/50"),children:[i?n?l.jsx(ki,{className:"size-3 text-muted-foreground flex-none"}):l.jsx(Cr,{className:"size-3 text-muted-foreground flex-none"}):l.jsx("span",{className:"size-3 flex-none"}),l.jsx("span",{className:"font-mono font-medium text-xs",children:e}),l.jsx(tn,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&l.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),l.jsx("span",{className:"flex-1"}),t.default!==void 0&&l.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&l.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&l.jsx("p",{children:t.description}),t.enum&&l.jsxs("p",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((a,c)=>l.jsxs("span",{children:[c>0&&", ",l.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(a)})]},c))]}),((o=t.items)==null?void 0:o.type)&&l.jsxs("p",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const Bb={current:"Current directory",downstream:"Project"};function Rl({location:e}){return l.jsx("li",{className:"list-none px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:Bb[e]??e})}function $l({name:e,subtitle:t,query:n,onSelect:r}){return l.jsx("li",{className:"list-none",children:l.jsxs("button",{type:"button",onClick:r,title:t?`${e} — ${t}`:e,"aria-label":`Add ${e} to workspace`,className:W("group/row flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm pr-1 pl-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[l.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:l.jsx(zs,{text:e,query:n})}),l.jsx(Dt,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-sidebar-foreground/45 opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100"})]})})}function Ml({children:e}){return l.jsx("div",{className:"px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:e})}function Zb({document:e,query:t}){var B;const n=g.useRef(null),[r,i]=g.useState(!1),[s,o]=g.useState(!1),[a,c]=g.useState(!1),[u,d]=g.useState(!1),f=ke(N=>N.openDocument),h=ke(N=>N.activeTab),p=vn(N=>N.records[e.name]),m=vn(N=>N.setEnabled),v=h===e.name,k=(p==null?void 0:p.enabled)??!0,y=(p==null?void 0:p.status)??"idle",_=(B=p==null?void 0:p.metadata)==null?void 0:B.name,x=((p==null?void 0:p.diagnostics)??[]).filter(N=>N.severity==="error").length,A=y==="ready"?`Ready${_?` — used as "${_}"`:""}`:y==="error"?x>0?`${x} error${x===1?"":"s"} — open to fix`:"Failed to load — open to fix":y==="compiling"?"Compiling…":"Not compiled yet",E=g.useCallback(N=>{m(e.name,N),window.dispatchEvent(new CustomEvent(hg,{detail:{docName:e.name}}))},[e.name,m]),w=g.useMemo(()=>[{key:"open",label:"Open",run:()=>f(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>ni(e.name,new Blob([e.text],{type:"text/typescript"}))},{key:"rename",label:"Rename…",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",danger:!0,run:()=>d(!0)}],[e.name,e.text,f]),S=`browser-plugin-${e.name}`,O=r||s;return l.jsxs("li",{className:"group/menu-item relative list-none",children:[l.jsxs(_f,{onOpenChange:o,children:[l.jsx(Nf,{className:"block",children:l.jsxs("div",{className:W("flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2 transition-colors","hover:bg-sidebar-accent/60",O&&"bg-sidebar-accent/60",v&&"bg-sidebar-accent font-medium"),title:`${e.name} — ${A}`,children:[v&&l.jsx("span",{"aria-hidden":!0,className:"bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full"}),l.jsxs("button",{ref:n,type:"button",onClick:()=>f(e.name),"aria-label":`${e.name} — ${A}`,className:W("flex h-7 min-w-0 flex-1 cursor-pointer items-center gap-2 text-[13px]","focus-visible:ring-sidebar-ring rounded-sm focus-visible:ring-1 focus-visible:outline-none",k?"text-sidebar-foreground/85":"text-sidebar-foreground/60"),children:[l.jsx(Jd,{className:W("size-3.5 shrink-0",v?"text-sidebar-accent-foreground/70":"text-sidebar-foreground/60")}),l.jsx("span",{className:"truncate",children:l.jsx(zs,{text:e.name,query:t})}),y==="compiling"&&l.jsx(cn,{size:"sm",className:"shrink-0"}),y==="ready"&&l.jsx(yx,{"aria-hidden":!0,className:"size-3 shrink-0 text-success"}),y==="error"&&l.jsx(bx,{"aria-hidden":!0,className:"size-3 shrink-0 text-destructive"})]}),l.jsxs(_i,{onOpenChange:i,children:[l.jsx(Ni,{asChild:!0,children:l.jsx(Et,{"aria-label":`Actions for ${e.name}`,className:W("opacity-0 group-hover/menu-item:opacity-100 focus-visible:opacity-100",O&&"opacity-100"),children:l.jsx(ba,{})})}),l.jsx(Er,{side:"right",align:"start",className:"w-44",children:w.map(N=>l.jsxs(je.Fragment,{children:[N.separatorBefore&&l.jsx(Fn,{}),l.jsx($t,{onClick:N.run,className:W(N.danger&&"text-destructive focus:text-destructive"),children:N.label})]},N.key))})]}),l.jsx(Pa,{id:S,checked:k,onCheckedChange:E,className:"shrink-0","aria-label":`Enable ${e.name}`,title:"On: expanded in every build. Off: a document that names it fails to build until it is switched back on."})]})}),l.jsx(Ta,{className:"w-44",children:w.map(N=>l.jsxs(je.Fragment,{children:[N.separatorBefore&&l.jsx(Aa,{}),l.jsx(Ia,{onClick:N.run,className:W(N.danger&&"text-destructive focus:text-destructive"),children:N.label})]},N.key))})]}),l.jsx(ct,{open:a,onOpenChange:c,children:l.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:N=>{var R;N.preventDefault(),(R=n.current)==null||R.focus()},children:l.jsx(Dn,{mode:"update",shouldReset:!a,postSubmit:()=>c(!1),selectedName:e.name,isPlugin:!0})})}),l.jsx(ct,{open:u,onOpenChange:d,children:l.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:N=>{var R;N.preventDefault(),(R=n.current)==null||R.focus()},children:l.jsx(Dn,{mode:"delete",shouldReset:!u,postSubmit:()=>d(!1),selectedName:e.name,isPlugin:!0})})})]})}const Vb=je.memo(Zb);function Ub({plugins:e,browserPlugins:t,query:n,open:r,onToggleSection:i,onShowPluginDetails:s,onNewPlugin:o,isPluginSelected:a,onTogglePlugin:c,isApplyingPlugins:u,diskPluginsLoadable:d,activeCount:f,totalCount:h}){const p=e.length>0&&t.length>0;return l.jsxs("section",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:[l.jsx(Zo,{open:r,onToggle:i,count:h>0?`${f}/${h}`:void 0,actions:l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"New plugin",onClick:o,children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"bottom",children:"New plugin"})]}),children:"Plugins"}),r&&l.jsxs("div",{className:"flex flex-col gap-0.5",children:[p&&l.jsx(Ml,{children:"In this browser"}),l.jsx("ul",{className:"flex flex-col gap-0.5",children:t.map(m=>l.jsx(Vb,{document:m,query:n},m.name))}),p&&l.jsx(Ml,{children:"On disk"}),e.length>0&&!d&&l.jsxs("p",{className:"text-sidebar-foreground/60 px-2 pt-0.5 pb-1 text-[11px] leading-snug",children:["This server does not load plugins from disk, so these cannot be switched on. Set ",l.jsx("code",{children:"PLUGIN_AUTOLOAD=true"})," on the deployment, or write one in the browser."]}),e.map(m=>{const v=a(m.name)&&d,k=`plugin-switch-${m.filePath||m.name}`;return l.jsxs("div",{title:m.description?`${m.name} — ${m.description}`:m.name,className:W("group/row flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2","transition-colors hover:bg-sidebar-accent/60"),children:[l.jsx("button",{type:"button",onClick:()=>s(m.name),"aria-label":`Details for ${m.name}`,className:W("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]","focus-visible:ring-sidebar-ring rounded-sm focus-visible:ring-1 focus-visible:outline-none",v?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:l.jsx("span",{className:"truncate",children:l.jsx(zs,{text:m.name,query:n})})}),l.jsx(Et,{"aria-label":`Details for ${m.name}`,onClick:y=>{y.stopPropagation(),s(m.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:l.jsx(qd,{})}),l.jsx(Pa,{id:k,checked:v,onCheckedChange:()=>c(m),disabled:u||!d,className:"shrink-0","aria-label":`Toggle ${m.name} plugin`,title:d?"On: the server loads this plugin from disk for every build.":"This server does not load plugins from disk (PLUGIN_AUTOLOAD is off)."})]},m.filePath||m.name)}),e.length+t.length===0&&l.jsx(Vo,{icon:Dt,label:"New plugin",hint:"Write a custom component in TypeScript, in the browser",onClick:o})]})]})}function Fl(e){return g.useMemo(()=>{const t=["current","downstream"],n=new Map;return e.forEach(r=>{const i=n.get(r.location);i?i.push(r):n.set(r.location,[r])}),[...n.entries()].sort(([r],[i])=>t.indexOf(r)-t.indexOf(i))},[e])}function Jf({children:e,className:t}){return l.jsx("kbd",{"data-slot":"kbd",className:W("pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground",t),children:e})}function Jb({children:e,className:t}){return l.jsx("span",{className:W("inline-flex items-center gap-0.5",t),children:e})}const Ri=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function di({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return Ri?"⌘":"Ctrl";case"shift":return Ri?"⇧":"Shift";case"alt":return Ri?"⌥":"Alt";case"ctrl":return Ri?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return l.jsx(Jb,{className:t,children:r.map((i,s)=>l.jsx(Jf,{children:i},s))})}function Hb({className:e}={}){const{theme:t,setTheme:n}=od(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=g.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(Ce,{variant:"ghost",size:"icon",onClick:i,className:e,children:[l.jsx(vx,{className:"hidden dark:block"}),l.jsx(wx,{className:"block dark:hidden"}),l.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),l.jsx(Qe,{children:l.jsx("p",{children:"Toggle theme"})})]})}function Wb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:o,openDocument:a,activeTab:c}=ke(wa(D=>({documents:D.documents,documentTypes:D.documentTypes,createDocument:D.createDocument,openDocument:D.openDocument,activeTab:D.activeTab}))),u=Io(D=>D.updateTheme),d=Io(D=>D.removeTheme),f=g.useContext(xa),[h,p]=g.useState(!1),[m,v]=g.useState(!1),[k,y]=g.useState(!1),[_,x]=g.useState(!1),A=vn(D=>rd(D).length),[E,w]=g.useState(null),S=Jt(D=>D.togglePlugin),O=Jt(D=>D.isPluginSelected),B=Jt(D=>D.selectedPlugins),N=Jt(D=>D.isApplyingPlugins),[R,T]=g.useState(!1),[F,$]=g.useState(new Set(["documents","themes"])),[Z,P]=g.useState(""),J=g.useRef(null),{toast:V}=_r(),X=i.filter(D=>(s[D.name]??"application/json+report")==="application/json+report"),j=i.filter(D=>s[D.name]==="application/json+theme"),ye=i.filter(D=>s[D.name]==="application/typescript+plugin"),ce=g.useCallback(()=>{p(!1)},[]),b=g.useCallback(()=>{v(!1)},[]),G=g.useCallback(()=>{y(!1),$(D=>new Set(D).add("plugins"))},[]),ne=g.useRef(new Map);g.useEffect(()=>{const D=ne.current,xe=new Map;j.forEach(de=>{xe.set(de.name,de.text),D.get(de.name)!==de.text&&u(de.name,de.text)}),D.forEach((de,Me)=>{xe.has(Me)||d(Me)}),ne.current=xe},[j,u,d]);const Q=g.useRef(!1);g.useEffect(()=>{if(Q.current||!f)return;Q.current=!0;const D=new Set(j.map(de=>de.name));Object.keys(f.getState().customThemes).forEach(de=>{D.has(de)||d(de)})},[j,d,f]);const oe=g.useCallback(D=>{$(xe=>{const de=new Set(xe);return de.has(D)?de.delete(D):de.add(D),de})},[]),{resolvedTheme:I}=od(),re=I==="dark"?"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo-white.svg?updatedAt=1751359555877":"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo.svg?updatedAt=1749817149276",ae=g.useCallback(async(D,xe)=>{if(i.some(de=>de.name===D)){a(D);return}try{const de=await fetch(`/api/discovery/${xe?"themes":"documents"}/${encodeURIComponent(D)}/content`);if(!de.ok)throw new Error(de.statusText);const Me=await de.text(),Je=JSON.parse(Me);o(D,JSON.stringify(Je,null,2),{templateSource:D}),a(D),V({title:`Added ${xe?"theme":"document"}: ${D}`})}catch{V({title:"Failed to load",description:`Could not load ${D}`,variant:"destructive"})}},[i,o,a,V]);g.useEffect(()=>{if(n)return;const D=xe=>{var Je,it,Lt,Ot,ml;if(xe.key!=="/"||xe.metaKey||xe.ctrlKey||xe.altKey)return;const de=xe.target,Me=(Je=de==null?void 0:de.tagName)==null?void 0:Je.toLowerCase();Me==="input"||Me==="textarea"||Me==="select"||de!=null&&de.isContentEditable||(it=de==null?void 0:de.closest)!=null&&it.call(de,".monaco-editor")||(Lt=J.current)!=null&&Lt.closest('[aria-hidden="true"], [inert]')||(xe.preventDefault(),(Ot=J.current)==null||Ot.focus(),(ml=J.current)==null||ml.select())};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[n]);const H=Z.trim(),K=g.useMemo(()=>new Set(i.map(D=>D.name)),[i]),pe=g.useMemo(()=>X.filter(D=>on(D.name,H)),[X,H]),fe=g.useMemo(()=>j.filter(D=>on(D.name,H)),[j,H]),Re=g.useMemo(()=>ye.filter(D=>on(D.name,H)),[ye,H]),Oe=g.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(D=>!K.has(D.name)&&(on(D.name,H)||on(D.title??"",H))),[e,H,K]),$e=g.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(D=>!K.has(D.name)&&(on(D.name,H)||on(D.description??"",H))),[e,H,K]),C=Fl(Oe),z=Fl($e),L=(e==null?void 0:e.pluginAutoload)??!0,se=g.useMemo(()=>(L?((e==null?void 0:e.plugins)??[]).filter(xe=>B.has(xe.name)).length:0)+A,[e,B,L,A]),ie=((e==null?void 0:e.plugins.length)??0)+ye.length,ee=g.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(D=>on(D.name,H)||on(D.description??"",H)),[e,H]),me=D=>H.length>0||F.has(D),we=me("documents"),U=me("themes"),Y=pe.length+Oe.length,ge=fe.length+$e.length,_e=H.length>0&&pe.length===0&&fe.length===0&&Re.length===0&&Oe.length===0&&$e.length===0&&ee.length===0,M=W("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return l.jsxs(l.Fragment,{children:[l.jsxs(Rf,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?l.jsxs(l.Fragment,{children:[l.jsx(Uo,{className:W("gap-0 p-1.5",M),children:l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:l.jsx(Gd,{})})}),l.jsxs(Qe,{side:"right",className:"flex items-center gap-2",children:[l.jsx("span",{children:"Expand sidebar"}),l.jsx(di,{shortcut:"mod+b"})]})]})}),l.jsxs(Jo,{className:W("gap-2 px-1 py-1",M),children:[l.jsxs(er,{className:"items-center gap-0.5",children:[X.map(D=>l.jsx(Mr,{document:D,compact:!0},D.name)),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"right",children:"New document"})]})]}),l.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),l.jsxs(er,{className:"items-center gap-0.5",children:[j.map(D=>l.jsx(Mr,{document:D,compact:!0},D.name)),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"size-7","aria-label":"New theme",onClick:()=>v(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"right",children:"New theme"})]})]}),l.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),l.jsxs(er,{className:"items-center gap-0.5",children:[ye.map(D=>l.jsx(Mr,{document:D,compact:!0},D.name)),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"size-7","aria-label":"New plugin",onClick:()=>y(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"right",children:"New plugin"})]})]})]})]}):l.jsxs(l.Fragment,{children:[l.jsxs(Uo,{className:W("gap-0 p-2",M),children:[l.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[l.jsx("a",{href:"/","aria-label":"JSON to Office home",className:"focus-visible:ring-sidebar-ring flex items-center rounded-sm pl-1 focus-visible:ring-1 focus-visible:outline-none",children:l.jsx("img",{src:re,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:l.jsx(kx,{})})}),l.jsxs(Qe,{side:"right",className:"flex items-center gap-2",children:[l.jsx("span",{children:"Collapse sidebar"}),l.jsx(di,{shortcut:"mod+b"})]})]})]}),l.jsxs("div",{className:"relative mt-2",children:[l.jsx(Sx,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),l.jsx("input",{ref:J,type:"text",value:Z,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:D=>P(D.target.value),onKeyDown:D=>{D.key==="Escape"&&(D.preventDefault(),P(""),D.currentTarget.blur())},className:W("border-sidebar-border/70 bg-sidebar-accent/40 h-7 w-full rounded-sm border","pr-7 pl-7 text-[13px] text-sidebar-foreground transition-colors","placeholder:text-sidebar-foreground/60","focus-visible:border-sidebar-ring focus-visible:bg-sidebar-accent/60","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none")}),H?l.jsx(Et,{"aria-label":"Clear filter",onClick:()=>{var D;P(""),(D=J.current)==null||D.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:l.jsx(wn,{})}):l.jsx(Jf,{className:"absolute top-1/2 right-1.5 h-4 min-w-4 -translate-y-1/2 bg-transparent px-0 text-[10px] text-sidebar-foreground/65",children:"/"})]})]}),l.jsx(Jo,{className:W("gap-0 px-2 pb-2",M),children:_e?l.jsxs("div",{className:"px-1 py-6 text-center",children:[l.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",H,"”"]}),l.jsx("button",{type:"button",onClick:()=>{var D;P(""),(D=J.current)==null||D.focus()},className:"text-sidebar-foreground/70 hover:text-sidebar-foreground focus-visible:ring-sidebar-ring mt-1 cursor-pointer rounded-sm text-[12px] underline-offset-2 hover:underline focus-visible:ring-1 focus-visible:outline-none",children:"Clear filter"})]}):l.jsxs(l.Fragment,{children:[(Y>0||!H)&&l.jsxs("section",{children:[l.jsx(Zo,{open:we,onToggle:()=>oe("documents"),count:Y||void 0,actions:l.jsxs(l.Fragment,{children:[at==="docx"&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"Compare documents",disabled:X.length<2,onClick:()=>T(!0),children:l.jsx(Vd,{})})}),l.jsx(Qe,{side:"bottom",children:X.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"New document",onClick:()=>p(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),we&&l.jsxs(er,{className:"gap-0.5",children:[pe.map(D=>l.jsxs(g.Fragment,{children:[l.jsx(Mr,{document:D,query:H}),!H&&c===D.name&&l.jsx(Dl,{})]},D.name)),C.map(([D,xe])=>l.jsxs(g.Fragment,{children:[C.length>1&&l.jsx(Rl,{location:D}),xe.map(de=>l.jsx($l,{name:de.name,subtitle:de.title,query:H,onSelect:()=>ae(de.name,!1)},de.path||de.name))]},D)),Y===0&&l.jsx("li",{className:"list-none",children:l.jsx(Vo,{icon:Dt,label:"New document",onClick:()=>p(!0)})})]})]}),(ge>0||!H)&&l.jsxs("section",{className:"mt-3",children:[l.jsx(Zo,{open:U,onToggle:()=>oe("themes"),count:ge||void 0,actions:l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"New theme",onClick:()=>v(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"bottom",children:"New theme"})]}),children:"Themes"}),U&&l.jsxs(er,{className:"gap-0.5",children:[fe.map(D=>l.jsxs(g.Fragment,{children:[l.jsx(Mr,{document:D,query:H}),!H&&c===D.name&&l.jsx(Dl,{})]},D.name)),z.map(([D,xe])=>l.jsxs(g.Fragment,{children:[z.length>1&&l.jsx(Rl,{location:D}),xe.map(de=>l.jsx($l,{name:de.name,subtitle:de.description,query:H,onSelect:()=>ae(de.name,!0)},de.path||de.name))]},D)),ge===0&&l.jsx("li",{className:"list-none",children:l.jsx(Vo,{icon:Dt,label:"New theme",onClick:()=>v(!0)})})]})]}),l.jsx(Ub,{plugins:ee,browserPlugins:Re,query:H,open:me("plugins"),onToggleSection:()=>oe("plugins"),onShowPluginDetails:D=>{w(D),x(!0)},onNewPlugin:()=>y(!0),isPluginSelected:O,onTogglePlugin:S,isApplyingPlugins:N,diskPluginsLoadable:L,activeCount:se,totalCount:ie})]})})]}),l.jsx($f,{className:W("border-sidebar-border/70 gap-0 border-t p-1.5",M),children:l.jsx("div",{className:W("flex items-center",n?"justify-center":"justify-start"),children:l.jsx(Hb,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),l.jsx(ct,{open:h,onOpenChange:p,children:l.jsx(lt,{className:"sm:max-w-[525px]",children:l.jsx(Dn,{mode:"create",shouldReset:!h,postSubmit:ce,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),l.jsx(ct,{open:m,onOpenChange:v,children:l.jsx(lt,{className:"sm:max-w-[525px]",children:l.jsx(Dn,{mode:"create",shouldReset:!m,postSubmit:b,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),l.jsx(ct,{open:k,onOpenChange:y,children:l.jsx(lt,{className:"sm:max-w-[525px]",children:l.jsx(Dn,{mode:"create",shouldReset:!k,postSubmit:G,discoveredPlugins:(e==null?void 0:e.plugins)||[],isPlugin:!0})})}),l.jsx(ct,{open:_,onOpenChange:D=>{x(D),D||w(null)},children:l.jsx(lt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:l.jsx(Fb,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:E})})}),l.jsx(ey,{open:R,onOpenChange:T})]})}const Ll=g.memo(Wb),qb=g.lazy(()=>ad(()=>import("./editor-BDFx5tyz.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(e=>({default:e.Editor})));function Bl(){return l.jsx(g.Suspense,{fallback:l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsxs("div",{className:"text-center",children:[l.jsx(cn,{className:"w-8 h-8 mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:l.jsx(qb,{})})}const Gb=g.lazy(()=>ad(()=>import("./preview-1VQB3b7e.js"),__vite__mapDeps([13,1,3,4,5,6,7,8,9,10,12,11])).then(e=>({default:e.Preview})));function Zl(){return l.jsx(g.Suspense,{fallback:l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsxs("div",{className:"text-center",children:[l.jsx(cn,{className:"w-8 h-8 mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:l.jsx(Gb,{})})}const{createElement:vr,createContext:Kb,forwardRef:Hf,useCallback:bt,useContext:Wf,useEffect:Rn,useImperativeHandle:qf,useLayoutEffect:Yb,useMemo:Xb,useRef:jt,useState:ur}=nd,Vl=nd[`useId${Math.random()}`.slice(0,5)],Qb=Yb,Ps=Kb(null);Ps.displayName="PanelGroupContext";const $n=Qb,ev=typeof Vl=="function"?Vl:()=>null;let tv=0;function Da(e=null){const t=ev(),n=jt(e||t||null);return n.current===null&&(n.current=""+tv++),e??n.current}function Gf({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:o,maxSize:a,minSize:c,onCollapse:u,onExpand:d,onResize:f,order:h,style:p,tagName:m="div",...v}){const k=Wf(Ps);if(k===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:_,getPanelSize:x,getPanelStyle:A,groupId:E,isPanelCollapsed:w,reevaluatePanelConstraints:S,registerPanel:O,resizePanel:B,unregisterPanel:N}=k,R=Da(o),T=jt({callbacks:{onCollapse:u,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:a,minSize:c},id:R,idIsFromProps:o!==void 0,order:h});jt({didLogMissingDefaultSizeWarning:!1}),$n(()=>{const{callbacks:$,constraints:Z}=T.current,P={...Z};T.current.id=R,T.current.idIsFromProps=o!==void 0,T.current.order=h,$.onCollapse=u,$.onExpand=d,$.onResize=f,Z.collapsedSize=n,Z.collapsible=r,Z.defaultSize=i,Z.maxSize=a,Z.minSize=c,(P.collapsedSize!==Z.collapsedSize||P.collapsible!==Z.collapsible||P.maxSize!==Z.maxSize||P.minSize!==Z.minSize)&&S(T.current,P)}),$n(()=>{const $=T.current;return O($),()=>{N($)}},[h,R,O,N]),qf(s,()=>({collapse:()=>{y(T.current)},expand:$=>{_(T.current,$)},getId(){return R},getSize(){return x(T.current)},isCollapsed(){return w(T.current)},isExpanded(){return!w(T.current)},resize:$=>{B(T.current,$)}}),[y,_,x,w,R,B]);const F=A(T.current,i);return vr(m,{...v,children:e,className:t,id:o,style:{...F,...p},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":E,"data-panel-id":R,"data-panel-size":parseFloat(""+F.flexGrow).toFixed(1)})}const Kf=Hf((e,t)=>vr(Gf,{...e,forwardedRef:t}));Gf.displayName="Panel";Kf.displayName="forwardRef(Panel)";let Wo=null,Pn=null;function nv(e,t){if(t){const n=(t&tp)!==0,r=(t&np)!==0,i=(t&rp)!==0,s=(t&ip)!==0;if(n)return i?"se-resize":s?"ne-resize":"e-resize";if(r)return i?"sw-resize":s?"nw-resize":"w-resize";if(i)return"s-resize";if(s)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function rv(){Pn!==null&&(document.head.removeChild(Pn),Wo=null,Pn=null)}function no(e,t){const n=nv(e,t);Wo!==n&&(Wo=n,Pn===null&&(Pn=document.createElement("style"),document.head.appendChild(Pn)),Pn.innerHTML=`*{cursor: ${n}!important;}`)}function Yf(e){return e.type==="keydown"}function Xf(e){return e.type.startsWith("pointer")}function Qf(e){return e.type.startsWith("mouse")}function Ds(e){if(Xf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Qf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function iv(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function sv(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function ov(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Hl(e),b:Hl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ee(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Jl(Ul(n.a)),b:Jl(Ul(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const c=s[a];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const av=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function lv(e){var t;const n=getComputedStyle((t=ep(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function cv(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||lv(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||av.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Ul(e){let t=e.length;for(;t--;){const n=e[t];if(Ee(n,"Missing node"),cv(n))return n}return null}function Jl(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Hl(e){const t=[];for(;e;)t.push(e),e=ep(e);return t}function ep(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const tp=1,np=2,rp=4,ip=8,uv=iv()==="coarse";let Ht=[],dr=!1,yn=new Map,Rs=new Map;const fi=new Set;function dv(e,t,n,r,i){var s;const{ownerDocument:o}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},c=(s=yn.get(o))!==null&&s!==void 0?s:0;return yn.set(o,c+1),fi.add(a),ls(),function(){var d;Rs.delete(e),fi.delete(a);const f=(d=yn.get(o))!==null&&d!==void 0?d:1;if(yn.set(o,f-1),ls(),f===1&&yn.delete(o),Ht.includes(a)){const h=Ht.indexOf(a);h>=0&&Ht.splice(h,1),$a(),i("up",!0,null)}}}function Wl(e){const{target:t}=e,{x:n,y:r}=Ds(e);dr=!0,Ra({target:t,x:n,y:r}),ls(),Ht.length>0&&(cs("down",e),e.preventDefault(),e.stopPropagation())}function Fr(e){const{x:t,y:n}=Ds(e);if(dr&&e.buttons===0&&(dr=!1,cs("up",e)),!dr){const{target:r}=e;Ra({target:r,x:t,y:n})}cs("move",e),$a(),Ht.length>0&&e.preventDefault()}function Wn(e){const{target:t}=e,{x:n,y:r}=Ds(e);Rs.clear(),dr=!1,Ht.length>0&&e.preventDefault(),cs("up",e),Ra({target:t,x:n,y:r}),$a(),ls()}function Ra({target:e,x:t,y:n}){Ht.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),fi.forEach(i=>{const{element:s,hitAreaMargins:o}=i,a=s.getBoundingClientRect(),{bottom:c,left:u,right:d,top:f}=a,h=uv?o.coarse:o.fine;if(t>=u-h&&t<=d+h&&n>=f-h&&n<=c+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&ov(r,s)>0){let m=r,v=!1;for(;m&&!m.contains(s);){if(sv(m.getBoundingClientRect(),a)){v=!0;break}m=m.parentElement}if(v)return}Ht.push(i)}})}function ro(e,t){Rs.set(e,t)}function $a(){let e=!1,t=!1;Ht.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;Rs.forEach(r=>{n|=r}),e&&t?no("intersection",n):e?no("horizontal",n):t?no("vertical",n):rv()}function ls(){yn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Wn),n.removeEventListener("pointerdown",Wl),n.removeEventListener("pointerleave",Fr),n.removeEventListener("pointermove",Fr)}),window.removeEventListener("pointerup",Wn),window.removeEventListener("pointercancel",Wn),fi.size>0&&(dr?(Ht.length>0&&yn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Wn),n.addEventListener("pointerleave",Fr),n.addEventListener("pointermove",Fr))}),window.addEventListener("pointerup",Wn),window.addEventListener("pointercancel",Wn)):yn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Wl,{capture:!0}),n.addEventListener("pointermove",Fr))}))}function cs(e,t){fi.forEach(n=>{const{setResizeHandlerState:r}=n,i=Ht.includes(n);r(e,i,t)})}function fv(){const[e,t]=ur(0);return bt(()=>t(n=>n+1),[])}function Ee(e,t){if(!e)throw console.error(t),Error(t)}const Ma=10;function Ln(e,t,n=Ma){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function ln(e,t,n=Ma){return Ln(e,t,n)===0}function Tt(e,t,n){return Ln(e,t,n)===0}function pv(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],s=t[r];if(!Tt(i,s,n))return!1}return!0}function sr({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ee(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:o=100,minSize:a=0}=r;if(Ln(n,a)<0)if(s){const c=(i+a)/2;Ln(n,c)<0?n=i:n=a}else n=a;return n=Math.min(o,n),n=parseFloat(n.toFixed(Ma)),n}function Hr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Tt(e,0))return t;const o=[...t],[a,c]=r;Ee(a!=null,"Invalid first pivot index"),Ee(c!=null,"Invalid second pivot index");let u=0;if(s==="keyboard"){{const f=e<0?c:a,h=n[f];Ee(h,`Panel constraints not found for index ${f}`);const{collapsedSize:p=0,collapsible:m,minSize:v=0}=h;if(m){const k=t[f];if(Ee(k!=null,`Previous layout not found for panel index ${f}`),Tt(k,p)){const y=v-k;Ln(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const f=e<0?a:c,h=n[f];Ee(h,`No panel constraints found for index ${f}`);const{collapsedSize:p=0,collapsible:m,minSize:v=0}=h;if(m){const k=t[f];if(Ee(k!=null,`Previous layout not found for panel index ${f}`),Tt(k,v)){const y=k-p;Ln(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const f=e<0?1:-1;let h=e<0?c:a,p=0;for(;;){const v=t[h];Ee(v!=null,`Previous layout not found for panel index ${h}`);const y=sr({panelConstraints:n,panelIndex:h,size:100})-v;if(p+=y,h+=f,h<0||h>=n.length)break}const m=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-m:m}{let h=e<0?a:c;for(;h>=0&&h<n.length;){const p=Math.abs(e)-Math.abs(u),m=t[h];Ee(m!=null,`Previous layout not found for panel index ${h}`);const v=m-p,k=sr({panelConstraints:n,panelIndex:h,size:v});if(!Tt(m,k)&&(u+=m-k,o[h]=k,u.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(pv(i,o))return i;{const f=e<0?c:a,h=t[f];Ee(h!=null,`Previous layout not found for panel index ${f}`);const p=h+u,m=sr({panelConstraints:n,panelIndex:f,size:p});if(o[f]=m,!Tt(m,p)){let v=p-m,y=e<0?c:a;for(;y>=0&&y<n.length;){const _=o[y];Ee(_!=null,`Previous layout not found for panel index ${y}`);const x=_+v,A=sr({panelConstraints:n,panelIndex:y,size:x});if(Tt(_,A)||(v-=A-_,o[y]=A),Tt(v,0))break;e>0?y--:y++}}}const d=o.reduce((f,h)=>h+f,0);return Tt(d,100)?o:i}function hv({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,o=0;const a=n[0];Ee(a!=null,"No pivot index found"),t.forEach((f,h)=>{const{constraints:p}=f,{maxSize:m=100,minSize:v=0}=p;h===a?(r=v,i=m):(s+=v,o+=m)});const c=Math.min(i,100-s),u=Math.max(r,100-o),d=e[a];return{valueMax:c,valueMin:u,valueNow:d}}function pi(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function sp(e,t,n=document){const i=pi(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function op(e,t,n){const r=sp(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function ap(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function $s(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function mv(e,t,n,r=document){var i,s,o,a;const c=$s(t,r),u=pi(e,r),d=c?u.indexOf(c):-1,f=(i=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,h=(o=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&o!==void 0?o:null;return[f,h]}function gv({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:o}){jt({didWarnAboutMissingResizeHandle:!1}),$n(()=>{if(!s)return;const a=pi(n,s);for(let c=0;c<i.length-1;c++){const{valueMax:u,valueMin:d,valueNow:f}=hv({layout:r,panelsArray:i,pivotIndices:[c,c+1]}),h=a[c];if(h!=null){const p=i[c];Ee(p,`No panel data found for index "${c}"`),h.setAttribute("aria-controls",p.id),h.setAttribute("aria-valuemax",""+Math.round(u)),h.setAttribute("aria-valuemin",""+Math.round(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((c,u)=>{c.removeAttribute("aria-controls"),c.removeAttribute("aria-valuemax"),c.removeAttribute("aria-valuemin"),c.removeAttribute("aria-valuenow")})}},[n,r,i,s]),Rn(()=>{if(!s)return;const a=t.current;Ee(a,"Eager values not found");const{panelDataArray:c}=a,u=ap(n,s);Ee(u!=null,`No group found for id "${n}"`);const d=pi(n,s);Ee(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const p=h.getAttribute("data-panel-resize-handle-id");Ee(p,"Resize handle element has no handle id attribute");const[m,v]=mv(n,p,c,s);if(m==null||v==null)return()=>{};const k=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const _=c.findIndex(x=>x.id===m);if(_>=0){const x=c[_];Ee(x,`No panel data found for index ${_}`);const A=r[_],{collapsedSize:E=0,collapsible:w,minSize:S=0}=x.constraints;if(A!=null&&w){const O=Hr({delta:Tt(A,E)?S-E:E-A,initialLayout:r,panelConstraints:c.map(B=>B.constraints),pivotIndices:op(n,p,s),prevLayout:r,trigger:"keyboard"});r!==O&&o(O)}}break}}};return h.addEventListener("keydown",k),()=>{h.removeEventListener("keydown",k)}});return()=>{f.forEach(h=>h())}},[s,e,t,n,r,i,o])}function ql(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function lp(e,t){const n=e==="horizontal",{x:r,y:i}=Ds(t);return n?r:i}function xv(e,t,n,r,i){const s=n==="horizontal",o=$s(t,i);Ee(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute("data-panel-group-id");Ee(a,"Resize handle element has no group id attribute");let{initialCursorPosition:c}=r;const u=lp(n,e),d=ap(a,i);Ee(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),h=s?f.width:f.height;return(u-c)/h*100}function yv(e,t,n,r,i,s){if(Yf(e)){const o=n==="horizontal";let a=0;e.shiftKey?a=100:i!=null?a=i:a=10;let c=0;switch(e.key){case"ArrowDown":c=o?0:a;break;case"ArrowLeft":c=o?-a:0;break;case"ArrowRight":c=o?a:0;break;case"ArrowUp":c=o?0:-a;break;case"End":c=100;break;case"Home":c=-100;break}return c}else return r==null?0:xv(e,t,n,r,s)}function bv({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,i=100;for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;a!=null&&(r++,t[s]=a,i-=a)}for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;if(a!=null)continue;const c=e.length-r,u=i/c;r++,t[s]=u,i-=u}return t}function qn(e,t,n){t.forEach((r,i)=>{const s=e[i];Ee(s,`Panel data not found for index ${i}`);const{callbacks:o,constraints:a,id:c}=s,{collapsedSize:u=0,collapsible:d}=a,f=n[c];if(f==null||r!==f){n[c]=r;const{onCollapse:h,onExpand:p,onResize:m}=o;m&&m(r,f),d&&(h||p)&&(p&&(f==null||ln(f,u))&&!ln(r,u)&&p(),h&&(f==null||!ln(f,u))&&ln(r,u)&&h())}})}function $i(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function vv({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const o=n[i];let a;return o==null?a=e!=null?e.toPrecision(s):"1":r.length===1?a="1":a=o.toPrecision(s),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function wv(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Gl(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function cp(e){return`react-resizable-panels:${e}`}function up(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:i,order:s}=t;return i?r:s?`${s}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function dp(e,t){try{const n=cp(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function kv(e,t,n){var r,i;const s=(r=dp(e,n))!==null&&r!==void 0?r:{},o=up(t);return(i=s[o])!==null&&i!==void 0?i:null}function Sv(e,t,n,r,i){var s;const o=cp(e),a=up(t),c=(s=dp(e,i))!==null&&s!==void 0?s:{};c[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(o,JSON.stringify(c))}catch(u){console.error(u)}}function Kl({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,o)=>s+o,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Tt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=100/r*o;n[s]=a}let i=0;for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=sr({panelConstraints:t,panelIndex:s,size:o});o!=a&&(i+=o-a,n[s]=a)}if(!Tt(i,0))for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=o+i,c=sr({panelConstraints:t,panelIndex:s,size:a});if(o!==c&&(i-=c-o,n[s]=c,Tt(i,0)))break}return n}const jv=100,Wr={getItem:e=>(Gl(Wr),Wr.getItem(e)),setItem:(e,t)=>{Gl(Wr),Wr.setItem(e,t)}},Yl={};function fp({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:o=null,keyboardResizeBy:a=null,storage:c=Wr,style:u,tagName:d="div",...f}){const h=Da(s),p=jt(null),[m,v]=ur(null),[k,y]=ur([]),_=fv(),x=jt({}),A=jt(new Map),E=jt(0),w=jt({autoSaveId:e,direction:r,dragState:m,id:h,keyboardResizeBy:a,onLayout:o,storage:c}),S=jt({layout:k,panelDataArray:[],panelDataArrayChanged:!1});jt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),qf(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:b}=S.current;return b},setLayout:b=>{const{onLayout:G}=w.current,{layout:ne,panelDataArray:Q}=S.current,oe=Kl({layout:b,panelConstraints:Q.map(I=>I.constraints)});ql(ne,oe)||(y(oe),S.current.layout=oe,G&&G(oe),qn(Q,oe,x.current))}}),[]),$n(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=m,w.current.id=h,w.current.onLayout=o,w.current.storage=c}),gv({committedValuesRef:w,eagerValuesRef:S,groupId:h,layout:k,panelDataArray:S.current.panelDataArray,setLayout:y,panelGroupElement:p.current}),Rn(()=>{const{panelDataArray:b}=S.current;if(e){if(k.length===0||k.length!==b.length)return;let G=Yl[e];G==null&&(G=wv(Sv,jv),Yl[e]=G);const ne=[...b],Q=new Map(A.current);G(e,ne,Q,k,c)}},[e,k,c]),Rn(()=>{});const O=bt(b=>{const{onLayout:G}=w.current,{layout:ne,panelDataArray:Q}=S.current;if(b.constraints.collapsible){const oe=Q.map(H=>H.constraints),{collapsedSize:I=0,panelSize:re,pivotIndices:ae}=En(Q,b,ne);if(Ee(re!=null,`Panel size not found for panel "${b.id}"`),!ln(re,I)){A.current.set(b.id,re);const K=tr(Q,b)===Q.length-1?re-I:I-re,pe=Hr({delta:K,initialLayout:ne,panelConstraints:oe,pivotIndices:ae,prevLayout:ne,trigger:"imperative-api"});$i(ne,pe)||(y(pe),S.current.layout=pe,G&&G(pe),qn(Q,pe,x.current))}}},[]),B=bt((b,G)=>{const{onLayout:ne}=w.current,{layout:Q,panelDataArray:oe}=S.current;if(b.constraints.collapsible){const I=oe.map(fe=>fe.constraints),{collapsedSize:re=0,panelSize:ae=0,minSize:H=0,pivotIndices:K}=En(oe,b,Q),pe=G??H;if(ln(ae,re)){const fe=A.current.get(b.id),Re=fe!=null&&fe>=pe?fe:pe,$e=tr(oe,b)===oe.length-1?ae-Re:Re-ae,C=Hr({delta:$e,initialLayout:Q,panelConstraints:I,pivotIndices:K,prevLayout:Q,trigger:"imperative-api"});$i(Q,C)||(y(C),S.current.layout=C,ne&&ne(C),qn(oe,C,x.current))}}},[]),N=bt(b=>{const{layout:G,panelDataArray:ne}=S.current,{panelSize:Q}=En(ne,b,G);return Ee(Q!=null,`Panel size not found for panel "${b.id}"`),Q},[]),R=bt((b,G)=>{const{panelDataArray:ne}=S.current,Q=tr(ne,b);return vv({defaultSize:G,dragState:m,layout:k,panelData:ne,panelIndex:Q})},[m,k]),T=bt(b=>{const{layout:G,panelDataArray:ne}=S.current,{collapsedSize:Q=0,collapsible:oe,panelSize:I}=En(ne,b,G);return Ee(I!=null,`Panel size not found for panel "${b.id}"`),oe===!0&&ln(I,Q)},[]),F=bt(b=>{const{layout:G,panelDataArray:ne}=S.current,{collapsedSize:Q=0,collapsible:oe,panelSize:I}=En(ne,b,G);return Ee(I!=null,`Panel size not found for panel "${b.id}"`),!oe||Ln(I,Q)>0},[]),$=bt(b=>{const{panelDataArray:G}=S.current;G.push(b),G.sort((ne,Q)=>{const oe=ne.order,I=Q.order;return oe==null&&I==null?0:oe==null?-1:I==null?1:oe-I}),S.current.panelDataArrayChanged=!0,_()},[_]);$n(()=>{if(S.current.panelDataArrayChanged){S.current.panelDataArrayChanged=!1;const{autoSaveId:b,onLayout:G,storage:ne}=w.current,{layout:Q,panelDataArray:oe}=S.current;let I=null;if(b){const ae=kv(b,oe,ne);ae&&(A.current=new Map(Object.entries(ae.expandToSizes)),I=ae.layout)}I==null&&(I=bv({panelDataArray:oe}));const re=Kl({layout:I,panelConstraints:oe.map(ae=>ae.constraints)});ql(Q,re)||(y(re),S.current.layout=re,G&&G(re),qn(oe,re,x.current))}}),$n(()=>{const b=S.current;return()=>{b.layout=[]}},[]);const Z=bt(b=>{let G=!1;const ne=p.current;return ne&&window.getComputedStyle(ne,null).getPropertyValue("direction")==="rtl"&&(G=!0),function(oe){oe.preventDefault();const I=p.current;if(!I)return()=>null;const{direction:re,dragState:ae,id:H,keyboardResizeBy:K,onLayout:pe}=w.current,{layout:fe,panelDataArray:Re}=S.current,{initialLayout:Oe}=ae??{},$e=op(H,b,I);let C=yv(oe,b,re,ae,K,I);const z=re==="horizontal";z&&G&&(C=-C);const L=Re.map(ee=>ee.constraints),se=Hr({delta:C,initialLayout:Oe??fe,panelConstraints:L,pivotIndices:$e,prevLayout:fe,trigger:Yf(oe)?"keyboard":"mouse-or-touch"}),ie=!$i(fe,se);(Xf(oe)||Qf(oe))&&E.current!=C&&(E.current=C,!ie&&C!==0?z?ro(b,C<0?tp:np):ro(b,C<0?rp:ip):ro(b,0)),ie&&(y(se),S.current.layout=se,pe&&pe(se),qn(Re,se,x.current))}},[]),P=bt((b,G)=>{const{onLayout:ne}=w.current,{layout:Q,panelDataArray:oe}=S.current,I=oe.map(fe=>fe.constraints),{panelSize:re,pivotIndices:ae}=En(oe,b,Q);Ee(re!=null,`Panel size not found for panel "${b.id}"`);const K=tr(oe,b)===oe.length-1?re-G:G-re,pe=Hr({delta:K,initialLayout:Q,panelConstraints:I,pivotIndices:ae,prevLayout:Q,trigger:"imperative-api"});$i(Q,pe)||(y(pe),S.current.layout=pe,ne&&ne(pe),qn(oe,pe,x.current))},[]),J=bt((b,G)=>{const{layout:ne,panelDataArray:Q}=S.current,{collapsedSize:oe=0,collapsible:I}=G,{collapsedSize:re=0,collapsible:ae,maxSize:H=100,minSize:K=0}=b.constraints,{panelSize:pe}=En(Q,b,ne);pe!=null&&(I&&ae&&ln(pe,oe)?ln(oe,re)||P(b,re):pe<K?P(b,K):pe>H&&P(b,H))},[P]),V=bt((b,G)=>{const{direction:ne}=w.current,{layout:Q}=S.current;if(!p.current)return;const oe=$s(b,p.current);Ee(oe,`Drag handle element not found for id "${b}"`);const I=lp(ne,G);v({dragHandleId:b,dragHandleRect:oe.getBoundingClientRect(),initialCursorPosition:I,initialLayout:Q})},[]),X=bt(()=>{v(null)},[]),j=bt(b=>{const{panelDataArray:G}=S.current,ne=tr(G,b);ne>=0&&(G.splice(ne,1),delete x.current[b.id],S.current.panelDataArrayChanged=!0,_())},[_]),ye=Xb(()=>({collapsePanel:O,direction:r,dragState:m,expandPanel:B,getPanelSize:N,getPanelStyle:R,groupId:h,isPanelCollapsed:T,isPanelExpanded:F,reevaluatePanelConstraints:J,registerPanel:$,registerResizeHandle:Z,resizePanel:P,startDragging:V,stopDragging:X,unregisterPanel:j,panelGroupElement:p.current}),[O,m,r,B,N,R,h,T,F,J,$,Z,P,V,X,j]),ce={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return vr(Ps.Provider,{value:ye},vr(d,{...f,children:t,className:n,id:s,ref:p,style:{...ce,...u},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":h}))}const pp=Hf((e,t)=>vr(fp,{...e,forwardedRef:t}));fp.displayName="PanelGroup";pp.displayName="forwardRef(PanelGroup)";function tr(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function En(e,t,n){const r=tr(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],o=n[r];return{...t.constraints,panelSize:o,pivotIndices:s}}function _v({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){Rn(()=>{if(e||n==null||r==null)return;const i=$s(t,r);if(i==null)return;const s=o=>{if(!o.defaultPrevented)switch(o.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{o.preventDefault(),n(o);break}case"F6":{o.preventDefault();const a=i.getAttribute("data-panel-group-id");Ee(a,`No group element found for id "${a}"`);const c=pi(a,r),u=sp(a,t,r);Ee(u!==null,`No resize element found for id "${t}"`);const d=o.shiftKey?u>0?u-1:c.length-1:u+1<c.length?u+1:0;c[d].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function hp({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:o,onFocus:a,style:c={},tabIndex:u=0,tagName:d="div",...f}){var h,p;const m=jt(null),v=jt({onDragging:o});Rn(()=>{v.current.onDragging=o});const k=Wf(Ps);if(k===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:y,groupId:_,registerResizeHandle:x,startDragging:A,stopDragging:E,panelGroupElement:w}=k,S=Da(i),[O,B]=ur("inactive"),[N,R]=ur(!1),[T,F]=ur(null),$=jt({state:O});$n(()=>{$.current.state=O}),Rn(()=>{if(n)F(null);else{const V=x(S);F(()=>V)}},[n,S,x]);const Z=(h=r==null?void 0:r.coarse)!==null&&h!==void 0?h:15,P=(p=r==null?void 0:r.fine)!==null&&p!==void 0?p:5;return Rn(()=>{if(n||T==null)return;const V=m.current;return Ee(V,"Element ref not attached"),dv(S,V,y,{coarse:Z,fine:P},(j,ye,ce)=>{if(ye)switch(j){case"down":{B("drag"),Ee(ce,'Expected event to be defined for "down" action'),A(S,ce);const{onDragging:b}=v.current;b&&b(!0);break}case"move":{const{state:b}=$.current;b!=="drag"&&B("hover"),Ee(ce,'Expected event to be defined for "move" action'),T(ce);break}case"up":{B("hover"),E();const{onDragging:b}=v.current;b&&b(!1);break}}else B("inactive")})},[Z,y,n,P,x,S,T,A,E]),_v({disabled:n,handleId:S,resizeHandler:T,panelGroupElement:w}),vr(d,{...f,children:e,className:t,id:i,onBlur:()=>{R(!1),s==null||s()},onFocus:()=>{R(!0),a==null||a()},ref:m,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...c},tabIndex:u,"data-panel-group-direction":y,"data-panel-group-id":_,"data-resize-handle":"","data-resize-handle-active":O==="drag"?"pointer":N?"keyboard":void 0,"data-resize-handle-state":O,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":S})}hp.displayName="PanelResizeHandle";const Nv=({className:e,...t})=>l.jsx(pp,{className:W("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),io=Kf,Xl=({withHandle:e,className:t,...n})=>l.jsx(hp,{className:W("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-none data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&l.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:l.jsx(jx,{className:"h-2.5 w-2.5"})})}),mp=g.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:W("flex min-h-[80px] w-full rounded-sm border border-input bg-background px-3 py-2 text-sm shadow-xs","placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));mp.displayName="Textarea";class Cv{constructor(t){Or(this,"client");this.client=Mx.create({baseURL:t||void 0||"/api",headers:{"Content-Type":"application/json"}})}get(t,n){return this.client.get(t,n)}post(t,n,r){return this.client.post(t,n,r)}put(t,n,r){return this.client.put(t,n,r)}delete(t,n){return this.client.delete(t,n)}patch(t,n,r){return this.client.patch(t,n,r)}}const Ev=new Cv;class Tv extends Error{constructor(n,r){super(n);Or(this,"quality");this.name="QualityGateFailedError",this.quality=r}}function Iv(e,t){return e??t}function Av(e){var n;const t=(n=e==null?void 0:e.split(";",1)[0])==null?void 0:n.trim().toLowerCase();return t?t==="application/json"||t.startsWith("application/")&&t.endsWith("+json"):!1}async function zv(e){if(Av(e.headers.get("content-type")))try{return await e.json()}catch{return}}function Ql(e,t){if(t!=null&&t.error)return t.error;if(t!=null&&t.message)return t.message;if(e.ok)return`The server answered ${e.status} but not with a document. This usually means a proxy or extension replaced the response.`;switch(e.status){case 502:case 503:case 504:return`The server did not finish generating (${e.status}). It usually ran out of memory or restarted mid-request — documents with many full-page images or inline SVGs are the common cause. Try again, or split the document and generate it in parts.`;case 413:return"The document is too large for the server to accept (413). Remove or shrink its largest embedded assets.";case 429:return"Too many requests (429). Wait a moment before generating again.";default:return`Generation failed (${e.status}${e.statusText?` ${e.statusText}`:""}).`}}function Ov(){const e=g.useRef(null),t=gr(s=>s.generationBackend),n=id(),r=g.useCallback(async(s,o,a,c,u)=>{e.current&&e.current.abort();const d=new AbortController;e.current=d;const f=Iv(u==null?void 0:u.renderer,t);try{c==null||c("parsing","Validating JSON structure...");let h;try{h=JSON.parse(o)}catch(B){throw new Error(`Invalid JSON: ${B instanceof Error?B.message:"Unknown parse error"}`)}c==null||c("building",`Building ${Pi.toLowerCase()} structure...`);const p={jsonDefinition:h,options:{...u,sourceName:n(s),...f?{renderer:f}:{}}};p.customThemes=a??{},c==null||c("rendering",`Generating ${at.toUpperCase()} content...`);const m={"Content-Type":"application/json"};u!=null&&u.bypassCache&&(m["X-Bypass-Cache"]="true");const v=await fetch(oi.generate,{method:"POST",headers:m,body:JSON.stringify(p),signal:d.signal}),k=await zv(v);if(v.status===400&&(k==null?void 0:k.code)==="QUALITY_GATE_FAILED")throw new Tv(Ql(v,k),k.quality);if(!v.ok||!(k!=null&&k.success))throw new Error(Ql(v,k));const{data:y,cache:_,warnings:x}=k,A=_.status==="HIT"?"HIT":_.status==="MISS"?"MISS":"UNKNOWN",E=A==="HIT"?`Served from cache (Hit rate: ${_.hitRate})`:`Generated fresh ${Pi.toLowerCase()}`;c==null||c("finalizing",E);const w=globalThis.atob(y.document),S=new Uint8Array(w.length);for(let B=0;B<w.length;B++)S[B]=w.charCodeAt(B);const O=new Blob([S],{type:y.contentType});if(O.size===0)throw new Error(`Received empty ${Pi.toLowerCase()} from API`);return{name:s,text:o,blob:O,...f?{renderer:f}:{},filename:y.filename,fileId:y.fileId,cacheStatus:A,cacheHitRate:_.hitRate,warnings:x}}catch(h){throw h instanceof Error&&h.name==="AbortError"?new Error(`${Pi} generation was cancelled`):h}finally{e.current===d&&(e.current=null)}},[t,n]),i=g.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:r,generateDocument:r,cancelGeneration:i}}const qi={ids:[],default:null};let ec;function Pv(){return ec??(ec=(async()=>{var e;try{const t=await fetch(oi.renderers);if(!t.ok)return qi;const n=await t.json();return!(n!=null&&n.success)||!Array.isArray((e=n.data)==null?void 0:e.ids)?qi:n.data}catch{return qi}})()),ec}function Dv(){const[e,t]=g.useState(qi);return g.useEffect(()=>{let n=!1;return Pv().then(r=>{n||t(r)}),()=>{n=!0}},[]),e}function Rv(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const o of i){let a=o.message;if(o.context&&Object.keys(o.context).length>0){const c=Object.entries(o.context).map(([u,d])=>`${u}: ${JSON.stringify(d)}`).join(", ");a+=` (${c})`}s.push(a)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function $v({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=je.useState("custom");je.useEffect(()=>{e&&s("custom")},[e]);const o=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),a=[{value:"custom",title:"Keep custom fonts",desc:"Recipients with the font installed see the authored typeface. Others get a generic fallback."},{value:"substitute",title:"Convert to safe fonts",desc:"Rewrite non-safe families to Calibri / Georgia / Consolas so every recipient sees the same glyphs."}];return l.jsx(ct,{open:e,onOpenChange:c=>!c&&t(),children:l.jsxs(lt,{className:"max-w-md",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Non-safe fonts in this document"}),l.jsxs(dn,{children:[o," ",n.length===1?"is":"are"," not in the built-in safe list. Choose how to export."]})]}),l.jsx("div",{className:"grid gap-2 py-2",children:a.map(c=>{const u=i===c.value;return l.jsxs("button",{type:"button",onClick:()=>s(c.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${u?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${u?"border-primary":"border-muted-foreground/50"}`,children:u&&l.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),l.jsx("span",{className:"text-sm font-medium",children:c.title})]}),l.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:c.desc})]},c.value)})}),l.jsxs(kn,{children:[l.jsx(Ce,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),l.jsx(Ce,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}function Mv(e){const t=e.hasPendingDiff?"Review the proposed change first":e.parses?void 0:"The visual view needs the JSON to parse";return{view:t?"json":e.preferred??"visual",forcedReason:t}}function Fv(e){try{const t=JSON.parse(e);return!!t&&typeof t=="object"&&!Array.isArray(t)}catch{return!1}}function Lv(){const e=gr(c=>c.setSettings),t=gr(c=>c.themeEditorView),n=ke(c=>c.activeTab&&c.documentTypes[c.activeTab]==="application/json+theme"?c.activeTab:""),r=ke(c=>{if(!n)return!0;const u=c.documents.find(d=>d.name===n);return u?Fv(u.text):!0}),i=ke(c=>!!n&&c.pendingDiffs[n]!==void 0),s=g.useCallback(c=>e({themeEditorView:c}),[e]);if(!n)return null;const{view:o,forcedReason:a}=Mv({preferred:t,parses:r,hasPendingDiff:i});return l.jsxs("div",{role:"tablist","aria-label":"Theme editor view",title:a,className:"flex h-7 shrink-0 items-center rounded-sm border border-border/70 bg-muted/60 p-0.5",children:[l.jsx(tc,{active:o==="visual",disabled:a!==void 0,onClick:()=>s("visual"),icon:_x,label:"Visual"}),l.jsx(tc,{active:o==="json",onClick:()=>s("json"),icon:Qi,label:"JSON"})]})}function tc({active:e,disabled:t,onClick:n,icon:r,label:i}){return l.jsxs("button",{type:"button",role:"tab","aria-selected":e,"aria-label":i,disabled:t,onClick:n,className:W("flex h-6 cursor-pointer items-center gap-1.5 rounded-[3px] px-2 text-xs transition-colors","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none","disabled:cursor-not-allowed disabled:opacity-50",e?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[l.jsx(r,{className:"size-3.5"}),l.jsx("span",{className:"hidden md:inline",children:i})]})}const Bv=je.memo(Lv);function so(){return l.jsx("span",{className:"rounded-sm bg-warning/15 px-1 py-px text-[10px] font-semibold uppercase leading-none tracking-wide text-warning",children:"experimental"})}function nc(){return l.jsx("span",{className:"rounded-sm bg-muted px-1 py-px text-[10px] font-semibold uppercase leading-none tracking-wide text-muted-foreground",children:"default"})}function Zv({name:e,blob:t,onManualRender:n,isGenerating:r,isRendering:i,onShowCacheMetrics:s,onShowSchemas:o,onShowFonts:a,documentText:c,editorDocumentText:u,editorDocumentName:d,warnings:f,onToggleChat:h,chatOpen:p,onTogglePreview:m,previewOpen:v}){const[k,y]=g.useState(!1),[_,x]=g.useState(!1),[A,E]=g.useState(!1),[w,S]=g.useState(!1),[O,B]=g.useState(!1),[N,R]=g.useState(null),{toast:T}=_r(),F=id(),{generateDocument:$}=Ov(),Z=g.useContext(xa),P=Dv(),J=gr(K=>K.generationBackend),V=gr(K=>K.setSettings),X=J??P.default??void 0,j=g.useCallback(()=>{const K={},{customThemes:pe}=Z.getState();return Object.values(pe).forEach(fe=>{fe.valid&&fe.parsed&&(K[fe.name]=fe.parsed)}),K},[Z]),ye=je.useMemo(()=>{if(!c)return[];try{const K=JSON.parse(c);return[...(at==="pptx"?Tg:Ig)(K)].filter(fe=>!Ag(fe))}catch{return[]}},[c]),[ce,b]=g.useState(!1),G=g.useCallback(async()=>{if(t){y(!0);try{await new Promise(K=>setTimeout(K,100)),ni(`${e}${Pr}`,t)}finally{setTimeout(()=>y(!1),500)}}},[t,e]),ne=g.useCallback(async()=>{if(t){if(ye.length===0){await G();return}b(!0)}},[t,ye.length,G]),Q=g.useCallback(async K=>{var pe;if(c){y(!0);try{const fe=await $(e,c,j(),void 0,{bypassCache:!0,fonts:{mode:K}});if(fe.blob.size===0)T({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{ni(`${e}${Pr}`,fe.blob);const Re=(pe=fe.warnings)==null?void 0:pe.find(Oe=>{var $e,C;return(($e=Oe.context)==null?void 0:$e.code)==="FONT_MODE_SUBSTITUTED"||((C=Oe.context)==null?void 0:C.code)==="FONT_MODE_CUSTOM"});Re&&T({title:K==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:Re.message})}}catch(fe){T({title:"Export failed",description:fe instanceof Error?fe.message:String(fe),variant:"destructive"})}finally{setTimeout(()=>y(!1),500)}}},[c,e,$,T,j]),oe=g.useCallback(async()=>{if(!(!f||f.length===0)){x(!0);try{const K=Rv(f);if(!K){T({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const pe=await $("warnings",JSON.stringify(K,null,2),{});pe&&typeof pe=="object"&&"blob"in pe&&pe.blob&&(ni(`${e}-warnings${Pr}`,pe.blob),T({title:"Warnings downloaded",description:`Downloaded warnings document with ${f.length} warning(s).`}))}catch(K){console.error("Failed to generate warnings document:",K),T({title:"Download failed",description:K instanceof Error?K.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>x(!1),500)}}},[f,e,$,T]),I=g.useCallback(async()=>{E(!0);try{await Ev.delete(`/${at}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),T({title:"Cache Cleared",description:"All active caches have been successfully cleared.",variant:"default"})}catch(K){console.error("Failed to clear cache:",K),T({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{E(!1)}},[T]),re=u??c,ae=g.useCallback(()=>{var fe,Re;if(!re){T({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(re)}catch{T({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}B(!0);const K=(async()=>{const Oe=j(),$e=await Ro(re,{customThemes:Oe}),C=await fetch(`/api/${at}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:$e.text,customThemes:Oe,options:{sourceName:F(d??e)}})});if(!C.ok){let L=`Request failed with status ${C.status}`;try{const se=await C.json(),ie=se.error??se.message;typeof ie=="string"&&ie&&(L=ie)}catch{}throw new Error(L)}const z=await C.json();return JSON.stringify(z.data,null,2)})();let pe;typeof ClipboardItem<"u"&&((fe=navigator.clipboard)!=null&&fe.write)?pe=navigator.clipboard.write([new ClipboardItem({"text/plain":K.then(Oe=>new Blob([Oe],{type:"text/plain"}))})]):(Re=navigator.clipboard)!=null&&Re.writeText?pe=K.then(Oe=>navigator.clipboard.writeText(Oe)):pe=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await pe,T({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(Oe){let $e=null;try{$e=await K}catch(C){console.error("Error fetching standard components:",C),T({title:"Failed to get standard components",description:C instanceof Error?C.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",Oe),R($e)}finally{B(!1)}})()},[re,e,d,F,j,T]),H=g.useCallback(async()=>{if(N!=null)try{await navigator.clipboard.writeText(N),T({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),R(null)}catch{T({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[N,T]);return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"bg-sidebar border-b flex flex-row flex-nowrap items-center justify-between gap-x-2 px-3 py-1.5",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[l.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":"Preview disclaimer",className:"cursor-help inline-flex items-center justify-center h-6 w-6 rounded-sm hover:bg-muted/60 shrink-0",children:l.jsx(qd,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),l.jsx(Qe,{className:"max-w-sm",children:l.jsxs("p",{className:"text-sm",children:["Preview converts the file to a PDF with LibreOffice. Download the ",Pr," to verify fidelity."]})})]})]}),l.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[l.jsx(Bv,{}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(Ce,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:n,"aria-label":"Render preview",disabled:r||i||v===!1,children:[i?l.jsx(cn,{size:"sm"}):l.jsx(Nx,{className:"h-3.5 w-3.5"}),l.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),l.jsx(Qe,{children:l.jsx("p",{children:v===!1?"Open preview to run":i?"Rendering preview...":"Render preview"})})]}),l.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(Ce,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||k||r,onClick:ne,children:[k?l.jsx(cn,{size:"sm"}):l.jsx(Cx,{className:"h-3.5 w-3.5"}),l.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),l.jsx(Qe,{children:l.jsxs("p",{children:["Download ",Pr]})})]}),f&&f.length>0&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ce,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:_||r,onClick:oe,children:_?l.jsx(cn,{size:"sm"}):l.jsx(Kd,{className:"h-3.5 w-3.5"})})}),l.jsx(Qe,{children:l.jsxs("p",{children:["Download warnings (",f.length,")"]})})]}),P.ids.length>1&&l.jsxs(li,{value:X,onValueChange:K=>V({generationBackend:K}),children:[l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(xr,{"aria-label":"Renderer",className:"hidden h-7 w-auto min-h-0 gap-1.5 px-2 text-xs lg:flex [&>span]:flex [&>span]:items-center [&>span]:gap-1.5 [&>span]:whitespace-nowrap",children:[l.jsx(zo,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),l.jsxs(ci,{placeholder:"Renderer",children:[l.jsx("span",{className:"font-medium",children:X}),X!==P.default&&l.jsx(so,{})]})]})}),l.jsx(Qe,{children:l.jsxs("p",{children:["Renderer that writes the ",at.toUpperCase()," file. A non-default one may refuse a document it cannot express."]})})]}),l.jsx(yr,{className:"min-w-[var(--radix-select-trigger-width)] text-sidebar-foreground",children:l.jsxs(ef,{children:[l.jsx(ka,{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),P.ids.map(K=>l.jsx(Mn,{value:K,className:"text-xs",children:l.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap",children:[l.jsx("span",{className:"font-medium",children:K}),K===P.default?l.jsx(nc,{}):l.jsx(so,{})]})},K))]})})]}),l.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),l.jsxs(_i,{children:[l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ni,{asChild:!0,children:l.jsx(Ce,{variant:"ghost",size:"icon",className:"h-7 w-7",children:l.jsx(ba,{className:"h-3.5 w-3.5"})})})}),l.jsx(Qe,{children:l.jsx("p",{children:"More actions"})})]}),l.jsxs(Er,{align:"end",className:"w-52",children:[o&&l.jsxs($t,{onClick:o,children:[l.jsx(Ex,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),a&&l.jsxs($t,{onClick:a,children:[l.jsx(Ao,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),s&&l.jsxs($t,{onClick:s,children:[l.jsx(Oo,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),re?l.jsxs($t,{onClick:ae,disabled:O,children:[l.jsx(Po,{className:"h-4 w-4 mr-2"}),O?"Copying...":"Copy standard components"]}):l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx("span",{className:"block",children:l.jsxs($t,{disabled:!0,children:[l.jsx(Po,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),l.jsx(Qe,{side:"left",children:l.jsx("p",{children:"No document selected — open or select a document first"})})]}),l.jsx(Fn,{}),l.jsxs($t,{onClick:()=>S(!0),disabled:A,className:"text-destructive focus:text-destructive",children:[l.jsx(va,{className:"h-4 w-4 mr-2"}),A?"Clearing...":"Clear all caches"]}),P.ids.length>1&&l.jsxs(l.Fragment,{children:[l.jsx(Fn,{className:"lg:hidden"}),l.jsx(za,{className:"lg:hidden px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),P.ids.map(K=>l.jsxs($t,{className:"lg:hidden gap-1.5",onClick:()=>V({generationBackend:K}),children:[l.jsx(un,{className:`h-3.5 w-3.5 shrink-0 ${X===K?"opacity-100":"opacity-0"}`}),l.jsx("span",{className:"font-medium",children:K}),K===P.default?l.jsx(nc,{}):l.jsx(so,{})]},K))]})]})]}),m&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ce,{variant:v?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:m,children:v?l.jsx(Yd,{className:"h-3.5 w-3.5"}):l.jsx(Tx,{className:"h-3.5 w-3.5"})})}),l.jsx(Qe,{children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[v?"Hide":"Show"," Preview"," ",l.jsx(di,{shortcut:"mod+shift+p"})]})})]}),h&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ce,{variant:p?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:h,children:l.jsx(Xd,{className:"h-3.5 w-3.5"})})}),l.jsx(Qe,{children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[p?"Close":"Open"," AI Chat"," ",l.jsx(di,{shortcut:"mod+shift+j"})]})})]})]})]}),l.jsx($v,{open:ce,onClose:()=>b(!1),nonSafeFonts:ye,onChoose:Q}),l.jsx(ct,{open:N!=null,onOpenChange:K=>{K||R(null)},children:l.jsxs(lt,{className:"max-w-lg",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Standard components"}),l.jsx(dn,{children:"The browser blocked the automatic clipboard write. Copy the JSON from here instead."})]}),l.jsx(mp,{readOnly:!0,value:N??"",className:"h-64 font-mono text-xs",onFocus:K=>K.currentTarget.select()}),l.jsxs(kn,{children:[l.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>R(null),children:"Close"}),l.jsx(Ce,{size:"sm",onClick:H,children:"Copy to clipboard"})]})]})}),l.jsx(ct,{open:w,onOpenChange:S,children:l.jsxs(lt,{className:"max-w-sm",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Clear all caches?"}),l.jsx(dn,{children:"This will clear the document, component, and rasterized-visual caches. Next generation will be uncached."})]}),l.jsxs(kn,{children:[l.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>S(!1),children:"Cancel"}),l.jsx(Ce,{variant:"destructive",size:"sm",disabled:A,onClick:async()=>{await I(),S(!1)},children:A?l.jsx(cn,{size:"sm"}):"Clear"})]})]})})]})}const Vv=je.memo(Zv),gp=Xg,Fa=g.forwardRef(({className:e,...t},n)=>l.jsx(Ld,{ref:n,className:W("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Fa.displayName=Ld.displayName;const fr=g.forwardRef(({className:e,...t},n)=>l.jsx(Bd,{ref:n,className:W("ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex cursor-pointer items-center justify-center rounded-sm px-3 py-1 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",e),...t}));fr.displayName=Bd.displayName;const pr=g.forwardRef(({className:e,...t},n)=>l.jsx(Zd,{ref:n,className:W("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));pr.displayName=Zd.displayName;async function Uv(e){if(navigator.clipboard&&navigator.clipboard.writeText)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="2em",t.style.height="2em",t.style.padding="0",t.style.border="none",t.style.outline="none",t.style.boxShadow="none",t.style.background="transparent",document.body.appendChild(t),t.focus(),t.select();const n=document.execCommand("copy");return document.body.removeChild(t),n}catch(t){return console.error("Failed to copy text to clipboard:",t),!1}}function Jv(e){try{const t=typeof e=="string"?JSON.parse(e):e;return JSON.stringify(t,null,2)}catch(t){return console.error("Failed to format schema:",t),typeof e=="string"?e:JSON.stringify(e)}}async function Hv(e){const t=Jv(e);return Uv(t)}const Wv=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=g.useState(n),[s,o]=g.useState(null),[a,c]=g.useState(null),[u,d]=g.useState(!1),[f,h]=g.useState(!1),[p,m]=g.useState(null),[v,k]=g.useState(null),[y,_]=g.useState(!1),{toast:x}=_r(),A=Jt(P=>P.selectedPlugins),E=Array.from(A),w=vn(mg);g.useEffect(()=>{n&&i(n)},[n]);const S=g.useCallback(async()=>{d(!0),m(null);try{const P=await Gs.fetchDocumentSchema(E,gg(vn.getState()));o(P)}catch(P){const J=P instanceof Error?P.message:"Failed to load document schema";m(J),x({variant:"destructive",title:"Error loading schema",description:J})}finally{d(!1)}},[E,w,x]),O=g.useCallback(async()=>{if(!a){h(!0),k(null);try{const P=await Gs.fetchThemeSchema();c(P)}catch(P){const J=P instanceof Error?P.message:"Failed to load theme schema";k(J),x({variant:"destructive",title:"Error loading schema",description:J})}finally{h(!1)}}},[a,x]),[B,N]=g.useState([]),[R,T]=g.useState(w);g.useEffect(()=>{e||(o(null),m(null))},[e]),g.useEffect(()=>{if(!e)return;const P=E.length!==B.length||E.some((V,X)=>V!==B[X]),J=w!==R;r==="document"?(!s||P||J)&&((P||J)&&(Gs.clearPluginSchemaCache(),N([...E]),T(w)),u||S()):r==="theme"&&!a&&!f&&O()},[r,e,s,a,u,f,E,B,w,R,S,O]);const F=E.length,$=r==="document"?s:a,Z=async()=>{if($)try{await Hv($)&&(_(!0),x({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>_(!1),2e3))}catch(P){console.error("Copy failed:",P)}};return l.jsx(ct,{open:e,onOpenChange:t,children:l.jsxs(lt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[l.jsx(qt,{children:l.jsx(Gt,{children:"Schema Viewer"})}),l.jsxs(gp,{value:r,onValueChange:P=>i(P),className:"flex-1 overflow-hidden flex flex-col",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(Fa,{children:[l.jsxs(fr,{value:"document",className:"flex items-center gap-1",children:["Document",F>0&&l.jsxs(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",F]})]}),l.jsx(fr,{value:"theme",children:"Theme"})]}),l.jsx("div",{className:"ml-auto",children:l.jsx(Ce,{variant:"ghost",size:"icon",onClick:Z,disabled:y||!$,"aria-label":"Copy schema",children:y?l.jsx(un,{className:"h-4 w-4"}):l.jsx(Es,{className:"h-4 w-4"})})})]}),l.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[l.jsx(pr,{value:"document",className:"h-full",children:l.jsx(as,{schema:s,loading:u,error:p||void 0})}),l.jsx(pr,{value:"theme",className:"h-full",children:l.jsx(as,{schema:a,loading:f,error:v||void 0})})]})]})]})})};function La(e,t){var r;const n=sd.getState().getEditor(e);return(r=n==null?void 0:n.flushPendingSave)==null||r.call(n),n?n.toStorageValue(n.editor.getValue()):t}function xp(e,t,n){if(t.length===0)return n;const r=rc(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const o=t[s],a=t[s+1],c=i[o],u=rc(c,a);i[o]=u,i=u}return i[t[t.length-1]]=n,r}function rc(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const ic=2*1024*1024,sc=12*1024*1024;function qv(e){if(e.length<4)return"unknown";const[t,n,r,i]=e;return t===0&&n===1&&r===0&&i===0||t===116&&n===114&&r===117&&i===101||t===116&&n===116&&r===99&&i===102?"ttf":t===79&&n===84&&r===84&&i===79?"otf":t===119&&n===79&&r===70&&i===70?"woff":t===119&&n===79&&r===70&&i===50?"woff2":"unknown"}function Gv(e){let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function us(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.round(e/1024)} KB`}function Kv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>ic)return{ok:!1,message:`"${e}" is ${us(t.length)}. The limit is ${us(ic)} per font, because the bytes travel inside the document JSON.`};const n=qv(t);return n==="woff"||n==="woff2"?{ok:!1,message:`"${e}" is a ${n.toUpperCase()} file. Upload the TTF or OTF instead — the preview renderer cannot register web font formats.`}:n!=="ttf"&&n!=="otf"?{ok:!1,message:`"${e}" does not look like a TTF or OTF font file.`}:{ok:!0,format:n,base64:Gv(t)}}const Yv=new Set(["italic","oblique"]);function Xv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[o,a]of Object.entries(ld))r.set(a.toLowerCase(),Number(o));let i=400,s=!1;for(;n.length>1;){const o=n[n.length-1].toLowerCase();if(Yv.has(o)){s=!0,n.pop();continue}const a=r.get(o);if(a!==void 0){i=a,n.pop();continue}break}return{family:n.join(" ")||t,weight:i,italic:s}}function Qv(e,t){const n=Array.isArray(e)?[...e]:[],r=n.findIndex(i=>{var s;return((s=i==null?void 0:i.family)==null?void 0:s.toLowerCase())===t.family.toLowerCase()});return r>=0?n[r]=t:n.push(t),n}function ew(e){return e.kind==="safe"||e.kind==="google"?null:{weight:"weight"in e&&e.weight?e.weight:400,italic:"italic"in e?!!e.italic:!1}}function tw(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(a=>{const c=ew(a);return c?!n.some(u=>u.weight===c.weight&&u.italic===c.italic):!0}),s=n.map(a=>({kind:"data",data:a.data,weight:a.weight,italic:a.italic})),o=r??(e==null?void 0:e.category);return{id:(e==null?void 0:e.id)??t,family:t,...o?{category:o}:{},sources:[...i,...s]}}function nw(e,t){let n=Array.isArray(e)?[...e]:[];for(const r of t){const i=r.sources.filter(o=>o.kind==="data").map(o=>({data:o.data,weight:o.weight??400,italic:o.italic??!1}));if(i.length===0)continue;const s=n.find(o=>{var a;return((a=o==null?void 0:o.family)==null?void 0:a.toLowerCase())===r.family.toLowerCase()});n=Qv(n,tw(s,r.family,i,r.category))}return n}function rw(e,t){const n=(e.sources??[]).filter(r=>r.format==="ttf"||r.format==="otf").map(r=>({kind:"data",data:r.data,weight:r.weight,italic:r.italic}));return n.length===0?null:{id:e.family,family:e.family,...t?{category:t}:{},sources:n}}function iw(e){const t=new TextEncoder().encode(e).length;return t<=sc?null:`Adding this font would push the document to ${us(t)}, past the ${us(sc)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const oc=new Set,sw=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function ac(e,t){var d;if(typeof document>"u"||!e.trim())return;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((d=r==null?void 0:r.dataset.weights)==null?void 0:d.split(",").map(Number).filter(f=>!Number.isNaN(f)))??[]),o=new Set([...s,...i]);if(r&&o.size===s.size)return;const a=[...o].sort((f,h)=>f-h).join(";"),c=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${a}&display=swap`,u=r??document.createElement("link");r||(u.id=n,u.rel="stylesheet",document.head.appendChild(u)),u.href=c,u.dataset.weights=[...o].sort((f,h)=>f-h).join(",")}function ow(e){const t=e.startsWith("data:")?e.slice(e.indexOf(",")+1):e,n=atob(t),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r}async function aw(e,t,n,r){const i=sw(e,n,r);if(!oc.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=ow(t),o=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await o.load(),document.fonts.add(o),oc.add(i)}catch{}}const lw={safe:[],google:[]};function cw(){const e=ke(i=>i.activeTab),t=ke(i=>i.documents),n=ke(i=>i.documentTypes),r=ke(i=>i.saveDocument);return g.useCallback(i=>{if(!e)return{ok:!1,error:"No active file"};if(n[e]!=="application/json+theme")return{ok:!1,error:"Fonts are registered on themes, not documents. Open a .theme.json file and try again."};const s=t.find(u=>u.name===e);if(!s)return{ok:!1,error:"Active theme not found"};const o=La(e,s.text);let a;try{a=JSON.parse(o)}catch(u){return{ok:!1,error:`Active theme is not valid JSON: ${u.message}`}}const c=i(a);return r(e,JSON.stringify(c,null,2)),{ok:!0,name:e}},[e,t,n,r])}function uw(){const e=ke(r=>r.activeTab),t=ke(r=>r.documents),n=ke(r=>r.saveDocument);return g.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(u=>u.name===e);if(!s)return{ok:!1,error:"Active document not found"};const o=La(e,s.text);let a;try{a=JSON.parse(o)}catch(u){return{ok:!1,error:`Active document is not valid JSON: ${u.message}`}}const c=xp(a,r,i);return n(e,JSON.stringify(c,null,2)),{ok:!0,name:e}},[e,t,n])}function dw(){const e=ke(i=>i.activeTab),t=ke(i=>i.documents),n=ke(i=>i.documentTypes),r=ke(i=>i.saveDocument);return g.useCallback(i=>{var h;if(i.length===0)return{ok:!0,name:e};if(!e)return{ok:!1,error:"No active file"};if(n[e]==="application/json+theme")return{ok:!1,error:"Custom fonts are registered on the document, not the theme. Open the .docx.json / .pptx.json tab and try again."};const s=t.find(p=>p.name===e);if(!s)return{ok:!1,error:"Active document not found"};const o=La(e,s.text);let a;try{a=JSON.parse(o)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const c=nw((h=a==null?void 0:a.props)==null?void 0:h.fontRegistry,i),u=xp(a,["props","fontRegistry"],c),d=JSON.stringify(u,null,2),f=iw(d);return f?{ok:!1,error:f}:(r(e,d),{ok:!0,name:e})},[e,t,n,r])}function fw(e,t,n){(!e.fonts||typeof e.fonts!="object")&&(e.fonts={});const r=e.fonts[t];r&&typeof r=="object"?e.fonts[t]={...r,family:n}:e.fonts[t]=n}function lc(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const pw=({open:e,onOpenChange:t})=>{const n=Hi(I=>I.open),r=Hi(I=>I.contextual),i=Hi(I=>I.close),s=e??n,o=r,a=g.useCallback(I=>{t&&t(I),I||i()},[t,i]),[c,u]=g.useState(lw),[d,f]=g.useState(!1),[h,p]=g.useState(""),[m,v]=g.useState("safe"),[k,y]=g.useState(null),[_,x]=g.useState(null),[A,E]=g.useState(!1),[w,S]=g.useState(!1),[O,B]=g.useState(""),[N,R]=g.useState([]),T=g.useRef(null),{toast:F}=_r(),$=cw(),Z=uw(),P=dw(),J=ke(I=>I.activeTab),V=ke(I=>I.documentTypes),X=J&&V[J]==="application/json+theme",j=!!o||X;g.useEffect(()=>{s&&(c.safe.length>0||c.google.length>0||(f(!0),fetch(oi.fonts.catalog).then(I=>I.json()).then(I=>u(I)).catch(I=>{F({variant:"destructive",title:"Font catalog unavailable",description:I.message})}).finally(()=>f(!1))))},[s,c,F]),g.useEffect(()=>{if(!(m!=="google"||c.google.length===0))for(const I of c.google)ac(I.family,I.weights)},[m,c]);const ye=g.useMemo(()=>c.safe.filter(I=>I.toLowerCase().includes(h.toLowerCase())),[c.safe,h]),ce=g.useMemo(()=>c.google.filter(I=>I.family.toLowerCase().includes(h.toLowerCase())),[c.google,h]),b=g.useCallback(async I=>{try{await navigator.clipboard.writeText(I),x(I),setTimeout(()=>x(null),1500)}catch{F({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[F]),G=g.useCallback(async(I,re,ae)=>{y(I);try{const H=$(K=>(fw(K,ae,I),K));if(!H.ok){F({variant:"destructive",title:"Could not insert font",description:H.error});return}F({title:"Font inserted",description:`${I} set as ${ae} font in "${H.name}".`})}finally{y(null)}},[$,F]),ne=g.useCallback(async I=>{if(o){y(I);try{const re=Z(o.jsonPath,I);if(!re.ok){F({variant:"destructive",title:"Could not insert font",description:re.error});return}F({title:"Font inserted",description:`${I} set at ${lc(o.jsonPath)}.`}),a(!1)}finally{y(null)}}},[o,Z,F,a]),Q=g.useCallback(async I=>{if(!(!I||I.length===0)){E(!0);try{const re=[];for(const H of Array.from(I)){const K=new Uint8Array(await H.arrayBuffer()),pe=Kv(H.name,K);if(!pe.ok){F({variant:"destructive",title:"Font rejected",description:pe.message});continue}re.push({identity:Xv(H.name),base64:pe.base64})}if(re.length===0)return;const ae=P(re.map(({identity:H,base64:K})=>({id:H.family,family:H.family,sources:[{kind:"data",data:K,weight:H.weight,italic:H.italic}]})));if(!ae.ok){F({variant:"destructive",title:"Could not register font",description:ae.error});return}for(const{identity:H,base64:K}of re)aw(H.family,K,H.weight,H.italic),F({title:`Added ${H.family}`,description:`Registered at weight ${H.weight}${H.italic?" italic":""} in props.fontRegistry. Reference it as "${H.family}".`})}catch(re){F({variant:"destructive",title:"Upload failed",description:re.message})}finally{E(!1),T.current&&(T.current.value="")}}},[P,F]),oe=g.useCallback(async()=>{var re,ae;const I=O.trim();if(I){S(!0),R([]);try{const H=await fetch(oi.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:I,weights:[400,700],italics:!1})});if(H.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!H.ok){const Oe=await H.json().catch(()=>({}));throw new Error(Oe.error??`Materialize failed (${H.status})`)}const K=await H.json();R(K.warnings??[]);const pe=(re=c.google.find(Oe=>Oe.family.toLowerCase()===K.family.toLowerCase()))==null?void 0:re.category,fe=rw(K,pe);if(!fe){F({variant:"destructive",title:"Nothing to embed",description:((ae=K.warnings)==null?void 0:ae.join(" · "))||`Google Fonts has no family named "${I}".`});return}const Re=P([fe]);if(!Re.ok){F({variant:"destructive",title:"Could not register font",description:Re.error});return}ac(K.family,[400,700]),F({title:`Added ${K.family}`,description:`Embedded ${fe.sources.length} weight(s) in props.fontRegistry.`})}catch(H){F({variant:"destructive",title:"Google Fonts fetch failed",description:H.message})}finally{S(!1)}}},[O,c.google,P,F]);return l.jsx(ct,{open:s,onOpenChange:a,children:l.jsxs(lt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[l.jsx(qt,{children:l.jsx(Gt,{children:o?`Font for ${lc(o.jsonPath)}`:"Fonts"})}),!o&&!X&&m!=="custom"&&l.jsx(lr,{children:l.jsxs(cr,{children:["Fonts are registered on themes. Open a ",l.jsx("code",{children:".theme.json"})," ","file to apply a font — the buttons below are disabled until you do."]})}),l.jsxs(gp,{value:m,onValueChange:I=>v(I),className:"flex-1 overflow-hidden flex flex-col",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(Fa,{children:[l.jsxs(fr,{value:"safe",children:["Safe",l.jsx(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:c.safe.length})]}),l.jsxs(fr,{value:"google",children:["Google",l.jsx(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:c.google.length})]}),l.jsx(fr,{value:"custom",children:"Custom"})]}),l.jsx(br,{type:"search",placeholder:"Search fonts...",value:h,onChange:I=>p(I.target.value),className:"ml-auto max-w-xs"})]}),l.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[l.jsx(pr,{value:"safe",className:"m-0",children:d&&ye.length===0?l.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[l.jsx(Jr,{className:"animate-spin mr-2"})," Loading catalog..."]}):l.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ye.map(I=>l.jsx(cc,{family:I,meta:l.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${I}", sans-serif`},onCopy:()=>b(I),copied:_===I,contextual:!!o,onUseThis:()=>ne(I),onInsertHeading:()=>G(I,"safe","heading"),onInsertBody:()=>G(I,"safe","body"),applying:k===I,disabled:!j},I))})}),l.jsx(pr,{value:"google",className:"m-0",children:d&&ce.length===0?l.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[l.jsx(Jr,{className:"animate-spin mr-2"})," Loading catalog..."]}):l.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ce.map(I=>l.jsx(cc,{family:I.family,meta:l.jsxs("span",{className:"text-xs",children:[I.category," · ",I.weights.length," weights"]}),previewStyle:{fontFamily:`"${I.family}", sans-serif`},onCopy:()=>b(I.family),copied:_===I.family,contextual:!!o,onUseThis:()=>ne(I.family),onInsertHeading:()=>G(I.family,"google","heading"),onInsertBody:()=>G(I.family,"google","body"),applying:k===I.family,disabled:!j,extraAction:l.jsx(mw,{family:I.family,weights:I.weights,hasItalic:I.hasItalic})},I.family))})}),l.jsx(pr,{value:"custom",className:"m-0 flex flex-col gap-6",children:X?l.jsx(lr,{children:l.jsxs(cr,{children:["Custom fonts are stored on the document (",l.jsx("code",{children:"props.fontRegistry"}),"), because the bytes travel with the JSON. Open a document tab to add one."]})}):l.jsxs(l.Fragment,{children:[l.jsxs("section",{className:"flex flex-col gap-2",children:[l.jsx("h3",{className:"text-sm font-medium",children:"Upload a font file"}),l.jsxs("p",{className:"text-xs text-muted-foreground",children:["TTF or OTF, up to 2 MB each. The font is embedded in the document as base64, so it survives export and re-import — and renders in the preview. The family and weight are guessed from the filename (e.g."," ",l.jsx("code",{children:"Geist-SemiBold.ttf"}),")."]}),l.jsxs("div",{onDragOver:I=>I.preventDefault(),onDrop:I=>{I.preventDefault(),Q(I.dataTransfer.files)},className:"rounded-md border border-dashed p-6 text-center",children:[l.jsx("input",{ref:T,type:"file",accept:".ttf,.otf,font/ttf,font/otf",multiple:!0,className:"hidden",onChange:I=>void Q(I.target.files)}),l.jsxs(Ce,{variant:"secondary",disabled:A,onClick:()=>{var I;return(I=T.current)==null?void 0:I.click()},children:[A?l.jsx(Jr,{className:"animate-spin mr-2 h-4 w-4"}):l.jsx(Ix,{className:"mr-2 h-4 w-4"}),"Choose font files"]}),l.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"or drop them here"})]})]}),l.jsxs("section",{className:"flex flex-col gap-2",children:[l.jsx("h3",{className:"text-sm font-medium",children:"Embed any Google font"}),l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not limited to the ",c.google.length," curated families — type any Google Fonts family name and its regular and bold weights are fetched and embedded."]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(br,{placeholder:"e.g. Geist",value:O,onChange:I=>B(I.target.value),onKeyDown:I=>{I.key==="Enter"&&oe()}}),l.jsxs(Ce,{onClick:()=>void oe(),disabled:w||O.trim()==="",children:[w&&l.jsx(Jr,{className:"animate-spin mr-2 h-4 w-4"}),"Embed"]})]}),N.length>0&&l.jsx(lr,{children:l.jsx(cr,{className:"text-xs",children:N.join(" · ")})})]})]})})]})]})]})})},hw="The quick brown fox jumps over the lazy dog",mw=({family:e,weights:t,hasItalic:n})=>{const r=g.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return l.jsxs(_i,{children:[l.jsx(Ni,{asChild:!0,children:l.jsx(Ce,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),l.jsxs(Er,{align:"end",className:"min-w-[260px]",children:[l.jsxs(za,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),l.jsx(Fn,{}),r.map(i=>{const s=ld[i]??String(i);return l.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-1.5",children:[l.jsx("span",{className:"truncate",style:{fontFamily:`"${e}", sans-serif`,fontWeight:i},children:s}),l.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:["fontWeight: ",i]})]},i)})]})]})},cc=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:o,onInsertHeading:a,onInsertBody:c,applying:u,disabled:d,extraAction:f})=>l.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[l.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[l.jsx("div",{className:"font-medium truncate",children:e}),l.jsx("div",{className:"text-muted-foreground",children:t})]}),l.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:hw}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?l.jsx(Ce,{size:"sm",onClick:o,disabled:u||d,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):l.jsxs(l.Fragment,{children:[l.jsx(Ce,{size:"sm",variant:"secondary",onClick:a,disabled:u||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),l.jsx(Ce,{size:"sm",variant:"secondary",onClick:c,disabled:u||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,l.jsx(Ce,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?l.jsx(un,{className:"h-4 w-4"}):l.jsx(Es,{className:"h-4 w-4"})})]})]});function uc({previewOpen:e,onTogglePreview:t}){const n=an(w=>w.name||""),r=an(w=>w.blob),i=an(w=>w.isGenerating),s=an(w=>w.text),o=an(w=>w.warnings),a=an(w=>w.isRendering),c=gr(w=>w.useGlobalPreviewHeader??!0),u=ke(w=>w.activeTab),d=ke(w=>w.documentTypes),f=u&&d[u]==="application/json+theme"?"theme":"document",h=ke(w=>{var S;return w.activeTab&&(w.documentTypes[w.activeTab]??"application/json+report")==="application/json+report"?(S=w.documents.find(O=>O.name===w.activeTab))==null?void 0:S.text:void 0}),p=ke(w=>w.activeTab&&(w.documentTypes[w.activeTab]??"application/json+report")==="application/json+report"?w.activeTab:void 0),m=De(w=>w.chatOpen),v=De(w=>w.toggleChat),[k,y]=je.useState(!1),_=Hi(w=>w.openFor);if(!c)return null;const x=g.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),A=g.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),E=(n==null?void 0:n.trim())||"Preview";return l.jsxs("div",{className:"sticky top-0 z-20",children:[l.jsx(Vv,{name:E,blob:r,onManualRender:x,isGenerating:i,isRendering:!!a,onShowCacheMetrics:A,onShowSchemas:()=>y(!0),onShowFonts:()=>_(),documentText:s,editorDocumentText:h,editorDocumentName:p,warnings:o,onToggleChat:v,chatOpen:m,onTogglePreview:t,previewOpen:e}),l.jsx(Wv,{open:k,onOpenChange:y,defaultTab:f==="theme"?"theme":"document"}),l.jsx(pw,{})]})}function gw(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const xw=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,yw=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,bw={};function dc(e,t){return(bw.jsx?yw:xw).test(e)}const vw=/[ \t\n\f\r]/g;function ww(e){return typeof e=="object"?e.type==="text"?fc(e.value):!1:fc(e)}function fc(e){return e.replace(vw,"")===""}class Ei{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}Ei.prototype.normal={};Ei.prototype.property={};Ei.prototype.space=void 0;function yp(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new Ei(n,r,t)}function qo(e){return e.toLowerCase()}class _t{constructor(t,n){this.attribute=n,this.property=t}}_t.prototype.attribute="";_t.prototype.booleanish=!1;_t.prototype.boolean=!1;_t.prototype.commaOrSpaceSeparated=!1;_t.prototype.commaSeparated=!1;_t.prototype.defined=!1;_t.prototype.mustUseProperty=!1;_t.prototype.number=!1;_t.prototype.overloadedBoolean=!1;_t.prototype.property="";_t.prototype.spaceSeparated=!1;_t.prototype.space=void 0;let kw=0;const Ne=Vn(),rt=Vn(),Go=Vn(),te=Vn(),Ve=Vn(),hr=Vn(),Ct=Vn();function Vn(){return 2**++kw}const Ko=Object.freeze(Object.defineProperty({__proto__:null,boolean:Ne,booleanish:rt,commaOrSpaceSeparated:Ct,commaSeparated:hr,number:te,overloadedBoolean:Go,spaceSeparated:Ve},Symbol.toStringTag,{value:"Module"})),oo=Object.keys(Ko);class Ba extends _t{constructor(t,n,r,i){let s=-1;if(super(t,n),pc(this,"space",i),typeof r=="number")for(;++s<oo.length;){const o=oo[s];pc(this,oo[s],(r&Ko[o])===Ko[o])}}}Ba.prototype.defined=!0;function pc(e,t,n){n&&(e[t]=n)}function Tr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Ba(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[qo(r)]=r,n[qo(s.attribute)]=r}return new Ei(t,n,e.space)}const bp=Tr({properties:{ariaActiveDescendant:null,ariaAtomic:rt,ariaAutoComplete:null,ariaBusy:rt,ariaChecked:rt,ariaColCount:te,ariaColIndex:te,ariaColSpan:te,ariaControls:Ve,ariaCurrent:null,ariaDescribedBy:Ve,ariaDetails:null,ariaDisabled:rt,ariaDropEffect:Ve,ariaErrorMessage:null,ariaExpanded:rt,ariaFlowTo:Ve,ariaGrabbed:rt,ariaHasPopup:null,ariaHidden:rt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Ve,ariaLevel:te,ariaLive:null,ariaModal:rt,ariaMultiLine:rt,ariaMultiSelectable:rt,ariaOrientation:null,ariaOwns:Ve,ariaPlaceholder:null,ariaPosInSet:te,ariaPressed:rt,ariaReadOnly:rt,ariaRelevant:null,ariaRequired:rt,ariaRoleDescription:Ve,ariaRowCount:te,ariaRowIndex:te,ariaRowSpan:te,ariaSelected:rt,ariaSetSize:te,ariaSort:null,ariaValueMax:te,ariaValueMin:te,ariaValueNow:te,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function vp(e,t){return t in e?e[t]:t}function wp(e,t){return vp(e,t.toLowerCase())}const Sw=Tr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:hr,acceptCharset:Ve,accessKey:Ve,action:null,allow:null,allowFullScreen:Ne,allowPaymentRequest:Ne,allowUserMedia:Ne,alt:null,as:null,async:Ne,autoCapitalize:null,autoComplete:Ve,autoFocus:Ne,autoPlay:Ne,blocking:Ve,capture:null,charSet:null,checked:Ne,cite:null,className:Ve,cols:te,colSpan:null,content:null,contentEditable:rt,controls:Ne,controlsList:Ve,coords:te|hr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Ne,defer:Ne,dir:null,dirName:null,disabled:Ne,download:Go,draggable:rt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Ne,formTarget:null,headers:Ve,height:te,hidden:Go,high:te,href:null,hrefLang:null,htmlFor:Ve,httpEquiv:Ve,id:null,imageSizes:null,imageSrcSet:null,inert:Ne,inputMode:null,integrity:null,is:null,isMap:Ne,itemId:null,itemProp:Ve,itemRef:Ve,itemScope:Ne,itemType:Ve,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Ne,low:te,manifest:null,max:null,maxLength:te,media:null,method:null,min:null,minLength:te,multiple:Ne,muted:Ne,name:null,nonce:null,noModule:Ne,noValidate:Ne,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Ne,optimum:te,pattern:null,ping:Ve,placeholder:null,playsInline:Ne,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Ne,referrerPolicy:null,rel:Ve,required:Ne,reversed:Ne,rows:te,rowSpan:te,sandbox:Ve,scope:null,scoped:Ne,seamless:Ne,selected:Ne,shadowRootClonable:Ne,shadowRootDelegatesFocus:Ne,shadowRootMode:null,shape:null,size:te,sizes:null,slot:null,span:te,spellCheck:rt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:te,step:null,style:null,tabIndex:te,target:null,title:null,translate:null,type:null,typeMustMatch:Ne,useMap:null,value:rt,width:te,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ve,axis:null,background:null,bgColor:null,border:te,borderColor:null,bottomMargin:te,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Ne,declare:Ne,event:null,face:null,frame:null,frameBorder:null,hSpace:te,leftMargin:te,link:null,longDesc:null,lowSrc:null,marginHeight:te,marginWidth:te,noResize:Ne,noHref:Ne,noShade:Ne,noWrap:Ne,object:null,profile:null,prompt:null,rev:null,rightMargin:te,rules:null,scheme:null,scrolling:rt,standby:null,summary:null,text:null,topMargin:te,valueType:null,version:null,vAlign:null,vLink:null,vSpace:te,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Ne,disableRemotePlayback:Ne,prefix:null,property:null,results:te,security:null,unselectable:null},space:"html",transform:wp}),jw=Tr({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:Ct,accentHeight:te,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:te,amplitude:te,arabicForm:null,ascent:te,attributeName:null,attributeType:null,azimuth:te,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:te,by:null,calcMode:null,capHeight:te,className:Ve,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:te,diffuseConstant:te,direction:null,display:null,dur:null,divisor:te,dominantBaseline:null,download:Ne,dx:null,dy:null,edgeMode:null,editable:null,elevation:te,enableBackground:null,end:null,event:null,exponent:te,externalResourcesRequired:null,fill:null,fillOpacity:te,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:hr,g2:hr,glyphName:hr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:te,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:te,horizOriginX:te,horizOriginY:te,id:null,ideographic:te,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:te,k:te,k1:te,k2:te,k3:te,k4:te,kernelMatrix:Ct,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:te,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:te,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:te,overlineThickness:te,paintOrder:null,panose1:null,path:null,pathLength:te,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ve,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:te,pointsAtY:te,pointsAtZ:te,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Ct,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Ct,rev:Ct,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Ct,requiredFeatures:Ct,requiredFonts:Ct,requiredFormats:Ct,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:te,specularExponent:te,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:te,strikethroughThickness:te,string:null,stroke:null,strokeDashArray:Ct,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:te,strokeOpacity:te,strokeWidth:null,style:null,surfaceScale:te,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Ct,tabIndex:te,tableValues:null,target:null,targetX:te,targetY:te,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Ct,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:te,underlineThickness:te,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:te,values:null,vAlphabetic:te,vMathematical:te,vectorEffect:null,vHanging:te,vIdeographic:te,version:null,vertAdvY:te,vertOriginX:te,vertOriginY:te,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:te,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:vp}),kp=Tr({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),Sp=Tr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:wp}),jp=Tr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),_w={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},Nw=/[A-Z]/g,hc=/-[a-z]/g,Cw=/^data[-\w.:]+$/i;function Ew(e,t){const n=qo(t);let r=t,i=_t;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Cw.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(hc,Iw);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!hc.test(s)){let o=s.replace(Nw,Tw);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=Ba}return new i(r,t)}function Tw(e){return"-"+e.toLowerCase()}function Iw(e){return e.charAt(1).toUpperCase()}const Aw=yp([bp,Sw,kp,Sp,jp],"html"),Za=yp([bp,jw,kp,Sp,jp],"svg");function zw(e){return e.join(" ").trim()}var Gn={},ao,mc;function Ow(){if(mc)return ao;mc=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,c=`
148
+ `)[0].trim();return i.length>t?`${i.slice(0,t-1)}…`:i}function kb(e){const t=It(Ae(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>It(Ae(i,"cells")).length))}×${t.length}`;const n=It(Ae(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?It(r).length:It(Ae(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Sb(e){const t=ot(Ae(e,"alt"));if(t)return St(t);const n=ot(Ae(e,"src"));if(n){if(n.startsWith("data:")){const i=n.slice(5).split(/[;,]/)[0];return i?`image (${i.split("/").pop()})`:"image"}const r=n.split(/[?#]/)[0].split("/").pop();if(r)return St(r,40)}return"image"}function jb(e,t){var r;const n=ot(Ae(t,"text"));switch(e){case"heading":{const i=Ho(Ae(t,"level"))??1;return{label:n?St(n):"heading",detail:`H${i}`}}case"text":return{label:n?St(n):"text",detail:ot(Ae(t,"style"))};case"paragraph":return{label:n?St(n):"paragraph"};case"chart":case"highcharts":{const i=ot(Ae(t,"title"))??ot(Ae(Ae(t,"options"),"title"));return{label:i?St(i):e,detail:ot(Ae(t,"type"))}}case"table":return{label:"table",detail:kb(t)};case"image":return{label:Sb(t)};case"shape":return{label:ot(Ae(t,"type"))??"shape"};case"list":{const i=It(Ae(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=ot(Ae(Ae(t,"meta"),"title"))??ot(Ae(t,"title"));return{label:i?St(i):"section"}}case"statistic":{const i=ot(Ae(t,"value"))??((r=Ho(Ae(t,"value")))==null?void 0:r.toString()),s=ot(Ae(t,"label"));return{label:St(s??i??"statistic"),detail:i}}default:return{label:n?St(n):e}}}function Ci(e){if(e.type!=="object")return null;const t=ot(Ae(e,"name"));return t?{name:t,props:Ae(e,"props"),childrenArr:Ae(e,"children")}:null}function _b(e){let t;for(const n of It(e)){const r=Ci(n);if(!r)continue;const i=ot(Ae(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return St(i,48);r.name==="paragraph"&&t===void 0&&(t=St(i,48))}}return t}function ss(e,t,n){let{label:r,detail:i}=jb(t.name,t.props);return r===t.name&&t.childrenArr&&(r=_b(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:Bf(t.childrenArr),reorder:n}}function Bf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of It(e)){const i=Ci(r);i&&n.push(ss(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Nb(e){const t=Ae(e,"props"),n=ot(Ae(Ae(t,"meta"),"title"));if(n)return St(n,48,!0);let r;const i=(o,a)=>{a&&(!r||o<r.rank)&&(r={rank:o,text:a})},s=(o,a)=>{const c=Ci(o);if(c){if(c.name==="block"){const u=Ae(c.props,"slots");if((u==null?void 0:u.type)==="object"&&u.children)for(const d of u.children){if(d.type!=="property"||!d.children)continue;const[f,h]=d.children,p=typeof(f==null?void 0:f.value)=="string"?f.value:"",m=h?ot(h):void 0;i(p==="title"?0:p==="subtitle"||p.startsWith("heading")?1:2,m)}return}if(c.name==="text"||c.name==="heading"){const u=ot(Ae(c.props,"text"));if(u){const d=ot(Ae(c.props,"style"))??"";i(d==="title"?0:d.startsWith("heading")?1:2,u)}}if(a<1)for(const u of It(c.childrenArr))s(u,a+1)}};for(const o of It(Ae(e,"children")))s(o,0);return r?St(r.text,48,!0):void 0}function Cb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of It(t)){const o=Ci(s);if(!o)continue;const a={groupId:n,sliceStart:s.offset,sliceEnd:s.offset+s.length};o.name==="slide"?(i+=1,r.push({id:"",kind:"slide",label:Nb(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:Bf(o.childrenArr),reorder:a})):r.push(ss(s,o,a))}return r}function Eb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const o of It(t)){const a=Ci(o);if(!a)continue;const c={groupId:n,sliceStart:o.offset,sliceEnd:o.offset+o.length},u=()=>i.length?i[i.length-1].node.children:r;if(a.name==="heading"){const d=Ho(Ae(a.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=ss(o,a,c);u().push(f),i.push({level:d,node:f})}else u().push(ss(o,a,c))}const s=o=>{o.children.forEach(s);const a=o.children[o.children.length-1];o.kind==="heading"&&a&&(o.end=Math.max(o.end,a.end),o.reorder&&a.reorder&&(o.reorder.sliceEnd=Math.max(o.reorder.sliceEnd,a.reorder.sliceEnd)))};return r.forEach(s),r}function Ol(e){switch(e.type){case"string":return St(String(e.value??""),24);case"number":case"boolean":return String(e.value);case"array":return`${It(e).length} items`;case"object":return;default:return}}function Tb(e){if(e.type!=="object"||!e.children)return[];const t=[];for(const n of e.children){if(n.type!=="property"||!n.children)continue;const[r,i]=n.children,s=typeof(r==null?void 0:r.value)=="string"?r.value:void 0;if(!s||s==="$schema"||!i)continue;const o=[];if(i.type==="object"&&i.children)for(const a of i.children){if(a.type!=="property"||!a.children)continue;const[c,u]=a.children,d=typeof(c==null?void 0:c.value)=="string"?c.value:void 0;!d||!u||o.push({id:"",kind:"key",label:d,detail:Ol(u),start:a.offset,end:a.offset+a.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:o.length===0?Ol(i):void 0,start:n.offset,end:n.offset+n.length,children:o})}return t}function Pl(e,t,n){if(!e.trim())return[];const r=Eg(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Tb(r):t==="pptx"?Cb(r):Eb(r);return Zf(i,""),i}function Zf(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,Zf(n.children,n.id)})}function Vf(e,t){const n=[];let r=e;for(;;){const i=r.find(s=>t>=s.start&&t<s.end);if(!i)return n;n.push(i.id),r=i.children}}function Ib(e,t){const n=new Set;for(const r of t)for(const i of Vf(e,r))n.add(i);return n}function Ab(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(d=>d.reorder);if(i.some(d=>!d))return null;const s=i[0].groupId;if(i.some(d=>d.groupId!==s))return null;for(let d=1;d<i.length;d++)if(i[d].sliceStart<i[d-1].sliceEnd)return null;const o=i.map(d=>e.slice(d.sliceStart,d.sliceEnd)),a=[];for(let d=1;d<i.length;d++){const f=e.slice(i[d-1].sliceEnd,i[d].sliceStart);if((f.match(/,/g)??[]).length!==1)return null;a.push(f)}const c=o.map((d,f)=>f);c.splice(r,0,c.splice(n,1)[0]);let u="";return c.forEach((d,f)=>{u+=o[d],f<a.length&&(u+=a[f])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:u}}const zb={slide:ux,heading:cx,text:Ao,paragraph:lx,chart:Oo,highcharts:Oo,table:ax,image:ox,shape:Wd,list:sx,toc:ix,section:zo,columns:zo,"text-box":Ao,statistic:rx,key:Qi};function Ob(e,t){let n=e,r=null;for(const i of t.split(".")){if(r=n[Number(i)]??null,!r)return null;n=r.children}return r}function Pb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function Db(){const{activeTab:e,documentTypes:t}=ke(wa(S=>({activeTab:S.activeTab,documentTypes:S.documentTypes}))),n=ke(S=>{var O;return S.activeTab?(O=S.documents.find(B=>B.name===S.activeTab))==null?void 0:O.text:void 0}),r=sd(S=>e?S.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,o]=g.useState([]),[a,c]=g.useState(null),[u,d]=g.useState(()=>new Set),[f,h]=g.useState(()=>new Set),[p,m]=g.useState(null),v=g.useRef(s);v.current=s;const k=g.useRef(null),y=g.useRef(null),_=g.useCallback(()=>{var B;if(!e){o([]);return}const S=((B=r==null?void 0:r.editor.getModel())==null?void 0:B.getValue())??n??"",O=Pl(S,at,i);if(o(O),y.current!==e){y.current=e;const N=new Set;if(i==="document"&&at==="docx")for(const R of O)R.kind==="heading"&&N.add(R.id);h(N),c(null)}},[e,r,n,i]);g.useEffect(()=>{_();const S=r==null?void 0:r.editor.getModel();if(!S)return;const O=xl(_,300),B=S.onDidChangeContent(()=>O());return()=>{O.cancel(),B.dispose()}},[_,r]),g.useEffect(()=>{if(!r)return;const{editor:S}=r,O=xl(()=>{const N=S.getModel(),R=S.getPosition();if(!N||!R)return;const T=N.getOffsetAt(R),F=Vf(v.current,T);if(F.length===0){c(null);return}c(F[F.length-1]);const $=F.slice(0,-1);$.length&&h(Z=>{if($.every(J=>Z.has(J)))return Z;const P=new Set(Z);for(const J of $)P.add(J);return P})},150),B=S.onDidChangeCursorPosition(()=>O());return()=>{O.cancel(),B.dispose()}},[r]),g.useEffect(()=>{if(!a||!k.current)return;const S=k.current.querySelector(`[data-oid="${CSS.escape(a)}"]`);S==null||S.scrollIntoView({block:"nearest"})},[a]),g.useEffect(()=>{if(!r){d(new Set);return}const{editor:S,monaco:O}=r,B=()=>{const R=S.getModel();if(!R)return;const T=O.editor.getModelMarkers({resource:R.uri}).filter(F=>F.severity===O.MarkerSeverity.Error).map(F=>R.getOffsetAt({lineNumber:F.startLineNumber,column:F.startColumn}));d(Ib(v.current,T))};B();const N=O.editor.onDidChangeMarkers(R=>{const T=S.getModel();T&&R.some(F=>F.toString()===T.uri.toString())&&B()});return()=>N.dispose()},[r,s]);const x=g.useCallback(S=>{h(O=>{const B=new Set(O);return B.has(S)?B.delete(S):B.add(S),B})},[]),A=g.useCallback(S=>{if(c(S.id),!r)return;const{editor:O,monaco:B}=r,N=O.getModel();if(!N)return;const R=N.getPositionAt(S.start),T=N.getPositionAt(S.end),F=new B.Range(R.lineNumber,R.column,T.lineNumber,T.column);O.revealRangeNearTopIfOutsideViewport(F,B.editor.ScrollType.Smooth),O.setPosition(R),O.focus();const $=O.deltaDecorations([],[{range:F,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>O.deltaDecorations($,[]),700)},[r]),E=g.useCallback(S=>{var ye;if(!r||!S.overId)return;const{editor:O,monaco:B,collapse:N}=r,R=O.getModel();if(!R)return;const T=R.getValue(),F=Pl(T,at,i),$=S.parentId?((ye=Ob(F,S.parentId))==null?void 0:ye.children)??[]:F,Z=$.findIndex(ce=>ce.id===S.dragId),P=$.findIndex(ce=>ce.id===S.overId);if(Z===-1||P===-1)return;let J=P+(S.overHalf==="after"?1:0);Z<J&&(J-=1);const V=Ab(T,$,Z,J);if(!V)return;const X=R.getPositionAt(V.start),j=R.getPositionAt(V.end);O.executeEdits("outline-reorder",[{range:new B.Range(X.lineNumber,X.column,j.lineNumber,j.column),text:V.text}]),N==null||N.resyncDecorations()},[r,i]),w=g.useMemo(()=>{const S=[],O=(B,N,R)=>{var $,Z;const T=(Z=($=B[0])==null?void 0:$.reorder)==null?void 0:Z.groupId,F=B.length>1&&T!==void 0&&B.every(P=>{var J;return((J=P.reorder)==null?void 0:J.groupId)===T});B.forEach(P=>{const J=zb[P.kind]??dx,V=P.children.length>0,X=f.has(P.id),j=a===P.id,ye=(p==null?void 0:p.overId)===P.id;S.push(l.jsxs("div",{"data-oid":P.id,role:"treeitem","aria-selected":j,"aria-expanded":V?X:void 0,tabIndex:0,draggable:F,onClick:()=>A(P),onKeyDown:ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),A(P)),ce.key==="ArrowRight"&&V&&!X&&x(P.id),ce.key==="ArrowLeft"&&V&&X&&x(P.id)},onDragStart:ce=>{ce.dataTransfer.setData("text/plain",P.id),ce.dataTransfer.effectAllowed="move",m({dragId:P.id,parentId:R,overId:null,overHalf:"before"})},onDragOver:ce=>{if(!p||p.dragId===P.id||Pb(p.dragId)!==R)return;ce.preventDefault(),ce.dataTransfer.dropEffect="move";const b=ce.currentTarget.getBoundingClientRect(),G=ce.clientY<b.top+b.height/2?"before":"after";(p.overId!==P.id||p.overHalf!==G)&&m({...p,overId:P.id,overHalf:G})},onDrop:ce=>{ce.preventDefault(),p&&E({...p,overId:P.id,overHalf:p.overHalf}),m(null)},onDragEnd:()=>m(null),className:W("group flex h-6 w-full cursor-pointer items-center gap-1 rounded-sm pr-1","text-[12px] text-sidebar-foreground/80 transition-colors select-none","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none",j&&"bg-sidebar-accent font-medium text-sidebar-foreground",ye&&(p==null?void 0:p.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",ye&&(p==null?void 0:p.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+N*12},children:[V?l.jsx("span",{role:"button","aria-label":X?"Collapse":"Expand",onClick:ce=>{ce.stopPropagation(),x(P.id)},className:"flex size-3.5 shrink-0 items-center justify-center rounded-xs text-sidebar-foreground/55 hover:text-sidebar-foreground",children:l.jsx(Cr,{className:W("size-3 transition-transform",X&&"rotate-90")})}):l.jsx("span",{className:"size-3.5 shrink-0"}),P.kind==="slide"&&l.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:P.detail}),l.jsx(J,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),l.jsx("span",{className:"min-w-0 flex-1 truncate",children:P.label}),P.kind!=="slide"&&P.detail&&l.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:P.detail}),u.has(P.id)&&l.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},P.id)),V&&X&&O(P.children,N+1,P.id)})};return O(s,0,""),S},[s,f,a,u,p,A,x,E]);return!e||s.length===0?null:l.jsx("li",{className:"list-none",children:l.jsx("div",{ref:k,role:"tree","aria-label":`Outline of ${e}`,className:"border-sidebar-border/70 my-0.5 ml-[15px] max-h-[38vh] overflow-y-auto border-l pl-1",children:w})})}const Dl=g.memo(Db);async function Rb(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const ui=g.forwardRef(({className:e,children:t,...n},r)=>l.jsxs(Md,{ref:r,className:W("relative overflow-hidden",e),...n,children:[l.jsx(Wg,{className:"h-full w-full rounded-[inherit]",children:t}),l.jsx(Uf,{}),l.jsx(qg,{})]}));ui.displayName=Md.displayName;const Uf=g.forwardRef(({className:e,orientation:t="vertical",...n},r)=>l.jsx(Fd,{ref:r,orientation:t,className:W("flex touch-none transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:l.jsx(Gg,{className:"bg-border relative flex-1 rounded-full"})}));Uf.displayName=Fd.displayName;function Pa({className:e,...t}){return l.jsx(Kg,{"data-slot":"switch",className:W("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-switch-off focus-visible:ring-ring inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent transition-colors outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:l.jsx(Yg,{"data-slot":"switch-thumb",className:W("bg-background pointer-events-none block size-4 rounded-full shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const $b=Si("relative w-full rounded-sm border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-card text-foreground",destructive:"border-transparent bg-destructive-bg text-destructive-bg-foreground [&>svg]:text-destructive-bg-foreground",warning:"border-transparent bg-warning-bg text-warning-bg-foreground [&>svg]:text-warning-bg-foreground",success:"border-transparent bg-success-bg text-success-bg-foreground [&>svg]:text-success-bg-foreground",info:"border-transparent bg-data-blue-bg text-data-blue-bg-foreground [&>svg]:text-data-blue-bg-foreground"}},defaultVariants:{variant:"default"}}),lr=g.forwardRef(({className:e,variant:t,...n},r)=>l.jsx("div",{ref:r,role:"alert",className:W($b({variant:t}),e),...n}));lr.displayName="Alert";const Mb=g.forwardRef(({className:e,...t},n)=>l.jsx("h5",{ref:n,className:W("mb-1 font-medium leading-none tracking-tight",e),...t}));Mb.displayName="AlertTitle";const cr=g.forwardRef(({className:e,...t},n)=>l.jsx("div",{ref:n,className:W("text-sm [&_p]:leading-relaxed",e),...t}));cr.displayName="AlertDescription";const os=g.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=g.useState(n<2),o=t!==null&&typeof t=="object",a=Array.isArray(t),c=()=>s(!i),u=()=>t===null?l.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?l.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?l.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?l.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?l.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?l.jsxs("span",{className:"text-warning",children:['"',t,'"']}):l.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,d=o?Object.keys(t).length:0;return l.jsxs("div",{className:W("text-sm",n>0&&"ml-4"),children:[l.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[o&&l.jsx("button",{onClick:c,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?l.jsx(ki,{className:"h-3 w-3"}):l.jsx(Cr,{className:"h-3 w-3"})}),!o&&l.jsx("span",{className:"w-4"}),e&&l.jsxs(l.Fragment,{children:[l.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),l.jsx("span",{className:"mx-1",children:":"})]}),o?l.jsxs("span",{className:"text-muted-foreground",children:[a?"[":"{",!i&&l.jsxs("span",{className:"mx-1 text-xs",children:[d," ",a?"items":"properties"]}),!i&&(a?"]":"}")]}):u(),!o&&!r&&l.jsx("span",{className:"text-muted-foreground",children:","})]}),o&&i&&l.jsxs("div",{className:"ml-4",children:[a?t.map((f,h)=>l.jsx(os,{keyName:String(h),value:f,depth:n+1,isLast:h===t.length-1},h)):Object.entries(t).map(([f,h],p,m)=>l.jsx(os,{keyName:f,value:h,depth:n+1,isLast:p===m.length-1},f)),l.jsx("div",{className:"ml-4",children:l.jsxs("span",{className:"text-muted-foreground",children:[a?"]":"}",!r&&","]})})]})]})});os.displayName="JsonNode";const as=g.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?l.jsxs("div",{className:W("space-y-4",r),children:[l.jsx(ti,{className:"h-8 w-64"}),l.jsx(ti,{className:"h-4 w-full"}),l.jsx(ti,{className:"h-64 w-full"})]}):n?l.jsx(lr,{variant:"destructive",className:r,children:l.jsx(cr,{children:n})}):e?l.jsx(ui,{className:W("h-full w-full rounded-md border bg-muted/10 p-4",r),children:l.jsx("div",{className:"font-mono text-xs",children:l.jsx(os,{value:e})})}):l.jsx(lr,{className:r,children:l.jsx(cr,{children:"No schema available"})}));as.displayName="SchemaViewer";function Fb({plugins:e,initialFocusedPlugin:t}){var x,A;const n=Jt(E=>E.togglePlugin),r=Jt(E=>E.isPluginSelected),i=Jt(E=>E.selectedPlugins),s=Jt(E=>E.isApplyingPlugins),[o,a]=g.useState(null),[c,u]=g.useState(null),[d,f]=g.useState("properties");g.useEffect(()=>{if(t){const E=e.find(w=>w.name===t);if(E){a(E);return}}e.length>0&&!o&&a(e[0])},[t,e]);const h=g.useMemo(()=>{const E={current:[],downstream:[],upstream:[]};return e.forEach(w=>{E[w.location]&&E[w.location].push(w)}),E},[e]),p=async(E,w)=>{o&&(await Rb(o.name,E.props),u(w),setTimeout(()=>u(null),2e3))},m=E=>{switch(E){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return E}},v=E=>{switch(E){case"current":return l.jsx(xx,{className:"size-3"});case"downstream":return l.jsx(gx,{className:"size-3"});case"upstream":return l.jsx(Hd,{className:"size-3"});default:return null}},k=((x=o==null?void 0:o.schema)==null?void 0:x.properties)&&Object.keys(o.schema.properties).length>0,y=(A=o==null?void 0:o.schema)==null?void 0:A.jsonSchema,_=(o==null?void 0:o.examples)&&o.examples.length>0;return l.jsxs(l.Fragment,{children:[l.jsxs(qt,{children:[l.jsxs(Gt,{className:"flex items-center gap-2",children:[l.jsx(fx,{className:"size-5 text-warning"}),"Plugins",l.jsxs(tn,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),l.jsxs(dn,{children:[e.length," plugin",e.length!==1?"s":""," discovered in your project"]})]}),l.jsxs("div",{className:"mt-3 flex gap-0 h-[600px] border rounded-lg overflow-hidden",children:[l.jsx("div",{className:"w-[240px] flex-none border-r bg-muted/30",children:l.jsx(ui,{className:"h-full",children:l.jsx("div",{className:"p-2 space-y-3",children:Object.entries(h).map(([E,w])=>w.length===0?null:l.jsxs("div",{children:[l.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[v(E),m(E)]}),l.jsx("div",{className:"space-y-0.5",children:w.map(S=>{const O=r(S.name),B=(o==null?void 0:o.name)===S.name;return l.jsxs("button",{onClick:()=>a(S),className:W("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",B?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[l.jsx("div",{className:W("size-1.5 rounded-full flex-none transition-colors",O?"bg-warning":"bg-muted-foreground/30")}),l.jsx("span",{className:"text-sm font-medium truncate flex-1",children:S.name})]},S.name)})})]},E))})})}),o?l.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[l.jsxs("div",{className:"flex-none px-5 py-4 border-b bg-background",children:[l.jsxs("div",{className:"flex items-start justify-between gap-3",children:[l.jsxs("div",{className:"min-w-0",children:[l.jsxs("div",{className:"flex items-center gap-2.5",children:[l.jsx("h3",{className:"text-base font-semibold truncate",children:o.name}),o.version&&l.jsxs(tn,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",o.version]})]}),o.description&&l.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:o.description})]}),l.jsxs("div",{className:"flex items-center gap-2 flex-none pt-0.5",children:[l.jsx("span",{className:"text-xs text-muted-foreground",children:r(o.name)?"On":"Off"}),l.jsx(Pa,{checked:r(o.name),onCheckedChange:()=>n(o),disabled:s,"aria-label":`Toggle ${o.name}`})]})]}),l.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[v(o.location),l.jsx("span",{children:m(o.location)}),l.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),l.jsx("span",{className:"font-mono truncate",children:o.relativePath})]})]}),l.jsxs("div",{className:"flex-none px-5 pt-3 pb-0 flex gap-1 border-b bg-background",children:[k&&l.jsx("button",{onClick:()=>f("properties"),className:W("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[l.jsx(Qi,{className:"size-3.5"}),"Properties"]})}),y&&l.jsx("button",{onClick:()=>f("schema"),className:W("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[l.jsx(px,{className:"size-3.5"}),"Schema"]})}),_&&l.jsx("button",{onClick:()=>f("examples"),className:W("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[l.jsx(hx,{className:"size-3.5"}),"Examples",l.jsx(tn,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:o.examples.length})]})})]}),l.jsx(ui,{className:"flex-1",children:l.jsxs("div",{className:"p-5",children:[d==="properties"&&k&&l.jsx("div",{className:"space-y-1",children:Object.entries(o.schema.properties).map(([E,w])=>l.jsx(Lb,{name:E,prop:w},E))}),d==="schema"&&y&&l.jsx(as,{schema:o.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&_&&o.examples.map((E,w)=>l.jsxs("div",{className:W(w>0&&"mt-4 pt-4 border-t"),children:[l.jsxs("div",{className:"flex items-center justify-between mb-2",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[E.title&&l.jsx("span",{className:"font-medium text-sm truncate",children:E.title}),!E.title&&l.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),l.jsx(Ce,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>p(E,w),children:c===w?l.jsxs(l.Fragment,{children:[l.jsx(mx,{className:"size-3 mr-1 text-success"}),"Copied"]}):l.jsxs(l.Fragment,{children:[l.jsx(Es,{className:"size-3 mr-1"}),"Copy"]})})]}),E.description&&l.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:E.description}),l.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(E.props,null,2)})]},w)),!k&&!y&&!_&&l.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[l.jsx(Qi,{className:"size-10 mx-auto mb-3 opacity-20"}),l.jsx("p",{className:"text-sm",children:"No schema or examples available for this plugin"})]})]})})]}):l.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:l.jsx("p",{className:"text-sm",children:"Select a plugin to view details"})})]})]})}function Lb({name:e,prop:t}){var o;const[n,r]=g.useState(!1),i=t.description||t.enum||t.default!==void 0||t.items||t.properties,s=t.type||(t.enum?"enum":t.oneOf?"oneOf":"—");return l.jsxs("div",{className:"rounded-md border",children:[l.jsxs("button",{onClick:()=>i&&r(!n),className:W("w-full text-left flex items-center gap-2 px-3 py-2 text-sm",i&&"cursor-pointer hover:bg-muted/50"),children:[i?n?l.jsx(ki,{className:"size-3 text-muted-foreground flex-none"}):l.jsx(Cr,{className:"size-3 text-muted-foreground flex-none"}):l.jsx("span",{className:"size-3 flex-none"}),l.jsx("span",{className:"font-mono font-medium text-xs",children:e}),l.jsx(tn,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&l.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),l.jsx("span",{className:"flex-1"}),t.default!==void 0&&l.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&l.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&l.jsx("p",{children:t.description}),t.enum&&l.jsxs("p",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((a,c)=>l.jsxs("span",{children:[c>0&&", ",l.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(a)})]},c))]}),((o=t.items)==null?void 0:o.type)&&l.jsxs("p",{children:[l.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const Bb={current:"Current directory",downstream:"Project"};function Rl({location:e}){return l.jsx("li",{className:"list-none px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:Bb[e]??e})}function $l({name:e,subtitle:t,query:n,onSelect:r}){return l.jsx("li",{className:"list-none",children:l.jsxs("button",{type:"button",onClick:r,title:t?`${e} — ${t}`:e,"aria-label":`Add ${e} to workspace`,className:W("group/row flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm pr-1 pl-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[l.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:l.jsx(zs,{text:e,query:n})}),l.jsx(Dt,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-sidebar-foreground/45 opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100"})]})})}function Ml({children:e}){return l.jsx("div",{className:"px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:e})}function Zb({document:e,query:t}){var B;const n=g.useRef(null),[r,i]=g.useState(!1),[s,o]=g.useState(!1),[a,c]=g.useState(!1),[u,d]=g.useState(!1),f=ke(N=>N.openDocument),h=ke(N=>N.activeTab),p=vn(N=>N.records[e.name]),m=vn(N=>N.setEnabled),v=h===e.name,k=(p==null?void 0:p.enabled)??!0,y=(p==null?void 0:p.status)??"idle",_=(B=p==null?void 0:p.metadata)==null?void 0:B.name,x=((p==null?void 0:p.diagnostics)??[]).filter(N=>N.severity==="error").length,A=y==="ready"?`Ready${_?` — used as "${_}"`:""}`:y==="error"?x>0?`${x} error${x===1?"":"s"} — open to fix`:"Failed to load — open to fix":y==="compiling"?"Compiling…":"Not compiled yet",E=g.useCallback(N=>{m(e.name,N),window.dispatchEvent(new CustomEvent(hg,{detail:{docName:e.name}}))},[e.name,m]),w=g.useMemo(()=>[{key:"open",label:"Open",run:()=>f(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>ni(e.name,new Blob([e.text],{type:"text/typescript"}))},{key:"rename",label:"Rename…",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",danger:!0,run:()=>d(!0)}],[e.name,e.text,f]),S=`browser-plugin-${e.name}`,O=r||s;return l.jsxs("li",{className:"group/menu-item relative list-none",children:[l.jsxs(_f,{onOpenChange:o,children:[l.jsx(Nf,{className:"block",children:l.jsxs("div",{className:W("flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2 transition-colors","hover:bg-sidebar-accent/60",O&&"bg-sidebar-accent/60",v&&"bg-sidebar-accent font-medium"),title:`${e.name} — ${A}`,children:[v&&l.jsx("span",{"aria-hidden":!0,className:"bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full"}),l.jsxs("button",{ref:n,type:"button",onClick:()=>f(e.name),"aria-label":`${e.name} — ${A}`,className:W("flex h-7 min-w-0 flex-1 cursor-pointer items-center gap-2 text-[13px]","focus-visible:ring-sidebar-ring rounded-sm focus-visible:ring-1 focus-visible:outline-none",k?"text-sidebar-foreground/85":"text-sidebar-foreground/60"),children:[l.jsx(Jd,{className:W("size-3.5 shrink-0",v?"text-sidebar-accent-foreground/70":"text-sidebar-foreground/60")}),l.jsx("span",{className:"truncate",children:l.jsx(zs,{text:e.name,query:t})}),y==="compiling"&&l.jsx(cn,{size:"sm",className:"shrink-0"}),y==="ready"&&l.jsx(yx,{"aria-hidden":!0,className:"size-3 shrink-0 text-success"}),y==="error"&&l.jsx(bx,{"aria-hidden":!0,className:"size-3 shrink-0 text-destructive"})]}),l.jsxs(_i,{onOpenChange:i,children:[l.jsx(Ni,{asChild:!0,children:l.jsx(Et,{"aria-label":`Actions for ${e.name}`,className:W("opacity-0 group-hover/menu-item:opacity-100 focus-visible:opacity-100",O&&"opacity-100"),children:l.jsx(ba,{})})}),l.jsx(Er,{side:"right",align:"start",className:"w-44",children:w.map(N=>l.jsxs(je.Fragment,{children:[N.separatorBefore&&l.jsx(Fn,{}),l.jsx($t,{onClick:N.run,className:W(N.danger&&"text-destructive focus:text-destructive"),children:N.label})]},N.key))})]}),l.jsx(Pa,{id:S,checked:k,onCheckedChange:E,className:"shrink-0","aria-label":`Enable ${e.name}`,title:"On: expanded in every build. Off: a document that names it fails to build until it is switched back on."})]})}),l.jsx(Ta,{className:"w-44",children:w.map(N=>l.jsxs(je.Fragment,{children:[N.separatorBefore&&l.jsx(Aa,{}),l.jsx(Ia,{onClick:N.run,className:W(N.danger&&"text-destructive focus:text-destructive"),children:N.label})]},N.key))})]}),l.jsx(ct,{open:a,onOpenChange:c,children:l.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:N=>{var R;N.preventDefault(),(R=n.current)==null||R.focus()},children:l.jsx(Dn,{mode:"update",shouldReset:!a,postSubmit:()=>c(!1),selectedName:e.name,isPlugin:!0})})}),l.jsx(ct,{open:u,onOpenChange:d,children:l.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:N=>{var R;N.preventDefault(),(R=n.current)==null||R.focus()},children:l.jsx(Dn,{mode:"delete",shouldReset:!u,postSubmit:()=>d(!1),selectedName:e.name,isPlugin:!0})})})]})}const Vb=je.memo(Zb);function Ub({plugins:e,browserPlugins:t,query:n,open:r,onToggleSection:i,onShowPluginDetails:s,onNewPlugin:o,isPluginSelected:a,onTogglePlugin:c,isApplyingPlugins:u,diskPluginsLoadable:d,activeCount:f,totalCount:h}){const p=e.length>0&&t.length>0;return l.jsxs("section",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:[l.jsx(Zo,{open:r,onToggle:i,count:h>0?`${f}/${h}`:void 0,actions:l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"New plugin",onClick:o,children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"bottom",children:"New plugin"})]}),children:"Plugins"}),r&&l.jsxs("div",{className:"flex flex-col gap-0.5",children:[p&&l.jsx(Ml,{children:"In this browser"}),l.jsx("ul",{className:"flex flex-col gap-0.5",children:t.map(m=>l.jsx(Vb,{document:m,query:n},m.name))}),p&&l.jsx(Ml,{children:"On disk"}),e.length>0&&!d&&l.jsxs("p",{className:"text-sidebar-foreground/60 px-2 pt-0.5 pb-1 text-[11px] leading-snug",children:["This server does not load plugins from disk, so these cannot be switched on. Set ",l.jsx("code",{children:"PLUGIN_AUTOLOAD=true"})," on the deployment, or write one in the browser."]}),e.map(m=>{const v=a(m.name)&&d,k=`plugin-switch-${m.filePath||m.name}`;return l.jsxs("div",{title:m.description?`${m.name} — ${m.description}`:m.name,className:W("group/row flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2","transition-colors hover:bg-sidebar-accent/60"),children:[l.jsx("button",{type:"button",onClick:()=>s(m.name),"aria-label":`Details for ${m.name}`,className:W("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]","focus-visible:ring-sidebar-ring rounded-sm focus-visible:ring-1 focus-visible:outline-none",v?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:l.jsx("span",{className:"truncate",children:l.jsx(zs,{text:m.name,query:n})})}),l.jsx(Et,{"aria-label":`Details for ${m.name}`,onClick:y=>{y.stopPropagation(),s(m.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:l.jsx(qd,{})}),l.jsx(Pa,{id:k,checked:v,onCheckedChange:()=>c(m),disabled:u||!d,className:"shrink-0","aria-label":`Toggle ${m.name} plugin`,title:d?"On: the server loads this plugin from disk for every build.":"This server does not load plugins from disk (PLUGIN_AUTOLOAD is off)."})]},m.filePath||m.name)}),e.length+t.length===0&&l.jsx(Vo,{icon:Dt,label:"New plugin",hint:"Write a custom component in TypeScript, in the browser",onClick:o})]})]})}function Fl(e){return g.useMemo(()=>{const t=["current","downstream"],n=new Map;return e.forEach(r=>{const i=n.get(r.location);i?i.push(r):n.set(r.location,[r])}),[...n.entries()].sort(([r],[i])=>t.indexOf(r)-t.indexOf(i))},[e])}function Jf({children:e,className:t}){return l.jsx("kbd",{"data-slot":"kbd",className:W("pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground",t),children:e})}function Jb({children:e,className:t}){return l.jsx("span",{className:W("inline-flex items-center gap-0.5",t),children:e})}const Ri=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function di({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return Ri?"⌘":"Ctrl";case"shift":return Ri?"⇧":"Shift";case"alt":return Ri?"⌥":"Alt";case"ctrl":return Ri?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return l.jsx(Jb,{className:t,children:r.map((i,s)=>l.jsx(Jf,{children:i},s))})}function Hb({className:e}={}){const{theme:t,setTheme:n}=od(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=g.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(Ce,{variant:"ghost",size:"icon",onClick:i,className:e,children:[l.jsx(vx,{className:"hidden dark:block"}),l.jsx(wx,{className:"block dark:hidden"}),l.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),l.jsx(Qe,{children:l.jsx("p",{children:"Toggle theme"})})]})}function Wb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:o,openDocument:a,activeTab:c}=ke(wa(D=>({documents:D.documents,documentTypes:D.documentTypes,createDocument:D.createDocument,openDocument:D.openDocument,activeTab:D.activeTab}))),u=Io(D=>D.updateTheme),d=Io(D=>D.removeTheme),f=g.useContext(xa),[h,p]=g.useState(!1),[m,v]=g.useState(!1),[k,y]=g.useState(!1),[_,x]=g.useState(!1),A=vn(D=>rd(D).length),[E,w]=g.useState(null),S=Jt(D=>D.togglePlugin),O=Jt(D=>D.isPluginSelected),B=Jt(D=>D.selectedPlugins),N=Jt(D=>D.isApplyingPlugins),[R,T]=g.useState(!1),[F,$]=g.useState(new Set(["documents","themes"])),[Z,P]=g.useState(""),J=g.useRef(null),{toast:V}=_r(),X=i.filter(D=>(s[D.name]??"application/json+report")==="application/json+report"),j=i.filter(D=>s[D.name]==="application/json+theme"),ye=i.filter(D=>s[D.name]==="application/typescript+plugin"),ce=g.useCallback(()=>{p(!1)},[]),b=g.useCallback(()=>{v(!1)},[]),G=g.useCallback(()=>{y(!1),$(D=>new Set(D).add("plugins"))},[]),ne=g.useRef(new Map);g.useEffect(()=>{const D=ne.current,xe=new Map;j.forEach(de=>{xe.set(de.name,de.text),D.get(de.name)!==de.text&&u(de.name,de.text)}),D.forEach((de,Me)=>{xe.has(Me)||d(Me)}),ne.current=xe},[j,u,d]);const Q=g.useRef(!1);g.useEffect(()=>{if(Q.current||!f)return;Q.current=!0;const D=new Set(j.map(de=>de.name));Object.keys(f.getState().customThemes).forEach(de=>{D.has(de)||d(de)})},[j,d,f]);const oe=g.useCallback(D=>{$(xe=>{const de=new Set(xe);return de.has(D)?de.delete(D):de.add(D),de})},[]),{resolvedTheme:I}=od(),re=I==="dark"?"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo-white.svg?updatedAt=1751359555877":"https://ik.imagekit.io/wiseair/Brand%20assets/wiseair-logo.svg?updatedAt=1749817149276",ae=g.useCallback(async(D,xe)=>{if(i.some(de=>de.name===D)){a(D);return}try{const de=await fetch(`/api/discovery/${xe?"themes":"documents"}/${encodeURIComponent(D)}/content`);if(!de.ok)throw new Error(de.statusText);const Me=await de.text(),Je=JSON.parse(Me);o(D,JSON.stringify(Je,null,2),{templateSource:D}),a(D),V({title:`Added ${xe?"theme":"document"}: ${D}`})}catch{V({title:"Failed to load",description:`Could not load ${D}`,variant:"destructive"})}},[i,o,a,V]);g.useEffect(()=>{if(n)return;const D=xe=>{var Je,it,Lt,Ot,ml;if(xe.key!=="/"||xe.metaKey||xe.ctrlKey||xe.altKey)return;const de=xe.target,Me=(Je=de==null?void 0:de.tagName)==null?void 0:Je.toLowerCase();Me==="input"||Me==="textarea"||Me==="select"||de!=null&&de.isContentEditable||(it=de==null?void 0:de.closest)!=null&&it.call(de,".monaco-editor")||(Lt=J.current)!=null&&Lt.closest('[aria-hidden="true"], [inert]')||(xe.preventDefault(),(Ot=J.current)==null||Ot.focus(),(ml=J.current)==null||ml.select())};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[n]);const H=Z.trim(),K=g.useMemo(()=>new Set(i.map(D=>D.name)),[i]),pe=g.useMemo(()=>X.filter(D=>on(D.name,H)),[X,H]),fe=g.useMemo(()=>j.filter(D=>on(D.name,H)),[j,H]),Re=g.useMemo(()=>ye.filter(D=>on(D.name,H)),[ye,H]),Oe=g.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(D=>!K.has(D.name)&&(on(D.name,H)||on(D.title??"",H))),[e,H,K]),$e=g.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(D=>!K.has(D.name)&&(on(D.name,H)||on(D.description??"",H))),[e,H,K]),C=Fl(Oe),z=Fl($e),L=(e==null?void 0:e.pluginAutoload)??!0,se=g.useMemo(()=>(L?((e==null?void 0:e.plugins)??[]).filter(xe=>B.has(xe.name)).length:0)+A,[e,B,L,A]),ie=((e==null?void 0:e.plugins.length)??0)+ye.length,ee=g.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(D=>on(D.name,H)||on(D.description??"",H)),[e,H]),me=D=>H.length>0||F.has(D),we=me("documents"),U=me("themes"),Y=pe.length+Oe.length,ge=fe.length+$e.length,_e=H.length>0&&pe.length===0&&fe.length===0&&Re.length===0&&Oe.length===0&&$e.length===0&&ee.length===0,M=W("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return l.jsxs(l.Fragment,{children:[l.jsxs(Rf,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?l.jsxs(l.Fragment,{children:[l.jsx(Uo,{className:W("gap-0 p-1.5",M),children:l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:l.jsx(Gd,{})})}),l.jsxs(Qe,{side:"right",className:"flex items-center gap-2",children:[l.jsx("span",{children:"Expand sidebar"}),l.jsx(di,{shortcut:"mod+b"})]})]})}),l.jsxs(Jo,{className:W("gap-2 px-1 py-1",M),children:[l.jsxs(er,{className:"items-center gap-0.5",children:[X.map(D=>l.jsx(Mr,{document:D,compact:!0},D.name)),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"right",children:"New document"})]})]}),l.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),l.jsxs(er,{className:"items-center gap-0.5",children:[j.map(D=>l.jsx(Mr,{document:D,compact:!0},D.name)),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"size-7","aria-label":"New theme",onClick:()=>v(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"right",children:"New theme"})]})]}),l.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),l.jsxs(er,{className:"items-center gap-0.5",children:[ye.map(D=>l.jsx(Mr,{document:D,compact:!0},D.name)),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{className:"size-7","aria-label":"New plugin",onClick:()=>y(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"right",children:"New plugin"})]})]})]})]}):l.jsxs(l.Fragment,{children:[l.jsxs(Uo,{className:W("gap-0 p-2",M),children:[l.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[l.jsx("a",{href:"/","aria-label":"JSON to Office home",className:"focus-visible:ring-sidebar-ring flex items-center rounded-sm pl-1 focus-visible:ring-1 focus-visible:outline-none",children:l.jsx("img",{src:re,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:l.jsx(kx,{})})}),l.jsxs(Qe,{side:"right",className:"flex items-center gap-2",children:[l.jsx("span",{children:"Collapse sidebar"}),l.jsx(di,{shortcut:"mod+b"})]})]})]}),l.jsxs("div",{className:"relative mt-2",children:[l.jsx(Sx,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),l.jsx("input",{ref:J,type:"text",value:Z,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:D=>P(D.target.value),onKeyDown:D=>{D.key==="Escape"&&(D.preventDefault(),P(""),D.currentTarget.blur())},className:W("border-sidebar-border/70 bg-sidebar-accent/40 h-7 w-full rounded-sm border","pr-7 pl-7 text-[13px] text-sidebar-foreground transition-colors","placeholder:text-sidebar-foreground/60","focus-visible:border-sidebar-ring focus-visible:bg-sidebar-accent/60","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none")}),H?l.jsx(Et,{"aria-label":"Clear filter",onClick:()=>{var D;P(""),(D=J.current)==null||D.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:l.jsx(wn,{})}):l.jsx(Jf,{className:"absolute top-1/2 right-1.5 h-4 min-w-4 -translate-y-1/2 bg-transparent px-0 text-[10px] text-sidebar-foreground/65",children:"/"})]})]}),l.jsx(Jo,{className:W("gap-0 px-2 pb-2",M),children:_e?l.jsxs("div",{className:"px-1 py-6 text-center",children:[l.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",H,"”"]}),l.jsx("button",{type:"button",onClick:()=>{var D;P(""),(D=J.current)==null||D.focus()},className:"text-sidebar-foreground/70 hover:text-sidebar-foreground focus-visible:ring-sidebar-ring mt-1 cursor-pointer rounded-sm text-[12px] underline-offset-2 hover:underline focus-visible:ring-1 focus-visible:outline-none",children:"Clear filter"})]}):l.jsxs(l.Fragment,{children:[(Y>0||!H)&&l.jsxs("section",{children:[l.jsx(Zo,{open:we,onToggle:()=>oe("documents"),count:Y||void 0,actions:l.jsxs(l.Fragment,{children:[at==="docx"&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"Compare documents",disabled:X.length<2,onClick:()=>T(!0),children:l.jsx(Vd,{})})}),l.jsx(Qe,{side:"bottom",children:X.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"New document",onClick:()=>p(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),we&&l.jsxs(er,{className:"gap-0.5",children:[pe.map(D=>l.jsxs(g.Fragment,{children:[l.jsx(Mr,{document:D,query:H}),!H&&c===D.name&&l.jsx(Dl,{})]},D.name)),C.map(([D,xe])=>l.jsxs(g.Fragment,{children:[C.length>1&&l.jsx(Rl,{location:D}),xe.map(de=>l.jsx($l,{name:de.name,subtitle:de.title,query:H,onSelect:()=>ae(de.name,!1)},de.path||de.name))]},D)),Y===0&&l.jsx("li",{className:"list-none",children:l.jsx(Vo,{icon:Dt,label:"New document",onClick:()=>p(!0)})})]})]}),(ge>0||!H)&&l.jsxs("section",{className:"mt-3",children:[l.jsx(Zo,{open:U,onToggle:()=>oe("themes"),count:ge||void 0,actions:l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Et,{"aria-label":"New theme",onClick:()=>v(!0),children:l.jsx(Dt,{})})}),l.jsx(Qe,{side:"bottom",children:"New theme"})]}),children:"Themes"}),U&&l.jsxs(er,{className:"gap-0.5",children:[fe.map(D=>l.jsxs(g.Fragment,{children:[l.jsx(Mr,{document:D,query:H}),!H&&c===D.name&&l.jsx(Dl,{})]},D.name)),z.map(([D,xe])=>l.jsxs(g.Fragment,{children:[z.length>1&&l.jsx(Rl,{location:D}),xe.map(de=>l.jsx($l,{name:de.name,subtitle:de.description,query:H,onSelect:()=>ae(de.name,!0)},de.path||de.name))]},D)),ge===0&&l.jsx("li",{className:"list-none",children:l.jsx(Vo,{icon:Dt,label:"New theme",onClick:()=>v(!0)})})]})]}),l.jsx(Ub,{plugins:ee,browserPlugins:Re,query:H,open:me("plugins"),onToggleSection:()=>oe("plugins"),onShowPluginDetails:D=>{w(D),x(!0)},onNewPlugin:()=>y(!0),isPluginSelected:O,onTogglePlugin:S,isApplyingPlugins:N,diskPluginsLoadable:L,activeCount:se,totalCount:ie})]})})]}),l.jsx($f,{className:W("border-sidebar-border/70 gap-0 border-t p-1.5",M),children:l.jsx("div",{className:W("flex items-center",n?"justify-center":"justify-start"),children:l.jsx(Hb,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),l.jsx(ct,{open:h,onOpenChange:p,children:l.jsx(lt,{className:"sm:max-w-[525px]",children:l.jsx(Dn,{mode:"create",shouldReset:!h,postSubmit:ce,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),l.jsx(ct,{open:m,onOpenChange:v,children:l.jsx(lt,{className:"sm:max-w-[525px]",children:l.jsx(Dn,{mode:"create",shouldReset:!m,postSubmit:b,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),l.jsx(ct,{open:k,onOpenChange:y,children:l.jsx(lt,{className:"sm:max-w-[525px]",children:l.jsx(Dn,{mode:"create",shouldReset:!k,postSubmit:G,discoveredPlugins:(e==null?void 0:e.plugins)||[],isPlugin:!0})})}),l.jsx(ct,{open:_,onOpenChange:D=>{x(D),D||w(null)},children:l.jsx(lt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:l.jsx(Fb,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:E})})}),l.jsx(ey,{open:R,onOpenChange:T})]})}const Ll=g.memo(Wb),qb=g.lazy(()=>ad(()=>import("./editor-BJWDd3uK.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(e=>({default:e.Editor})));function Bl(){return l.jsx(g.Suspense,{fallback:l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsxs("div",{className:"text-center",children:[l.jsx(cn,{className:"w-8 h-8 mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:l.jsx(qb,{})})}const Gb=g.lazy(()=>ad(()=>import("./preview-C4ynYVMZ.js"),__vite__mapDeps([13,1,3,4,5,6,7,8,9,10,12,11])).then(e=>({default:e.Preview})));function Zl(){return l.jsx(g.Suspense,{fallback:l.jsx("div",{className:"flex items-center justify-center h-full",children:l.jsxs("div",{className:"text-center",children:[l.jsx(cn,{className:"w-8 h-8 mx-auto mb-2"}),l.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:l.jsx(Gb,{})})}const{createElement:vr,createContext:Kb,forwardRef:Hf,useCallback:bt,useContext:Wf,useEffect:Rn,useImperativeHandle:qf,useLayoutEffect:Yb,useMemo:Xb,useRef:jt,useState:ur}=nd,Vl=nd[`useId${Math.random()}`.slice(0,5)],Qb=Yb,Ps=Kb(null);Ps.displayName="PanelGroupContext";const $n=Qb,ev=typeof Vl=="function"?Vl:()=>null;let tv=0;function Da(e=null){const t=ev(),n=jt(e||t||null);return n.current===null&&(n.current=""+tv++),e??n.current}function Gf({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:o,maxSize:a,minSize:c,onCollapse:u,onExpand:d,onResize:f,order:h,style:p,tagName:m="div",...v}){const k=Wf(Ps);if(k===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:_,getPanelSize:x,getPanelStyle:A,groupId:E,isPanelCollapsed:w,reevaluatePanelConstraints:S,registerPanel:O,resizePanel:B,unregisterPanel:N}=k,R=Da(o),T=jt({callbacks:{onCollapse:u,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:a,minSize:c},id:R,idIsFromProps:o!==void 0,order:h});jt({didLogMissingDefaultSizeWarning:!1}),$n(()=>{const{callbacks:$,constraints:Z}=T.current,P={...Z};T.current.id=R,T.current.idIsFromProps=o!==void 0,T.current.order=h,$.onCollapse=u,$.onExpand=d,$.onResize=f,Z.collapsedSize=n,Z.collapsible=r,Z.defaultSize=i,Z.maxSize=a,Z.minSize=c,(P.collapsedSize!==Z.collapsedSize||P.collapsible!==Z.collapsible||P.maxSize!==Z.maxSize||P.minSize!==Z.minSize)&&S(T.current,P)}),$n(()=>{const $=T.current;return O($),()=>{N($)}},[h,R,O,N]),qf(s,()=>({collapse:()=>{y(T.current)},expand:$=>{_(T.current,$)},getId(){return R},getSize(){return x(T.current)},isCollapsed(){return w(T.current)},isExpanded(){return!w(T.current)},resize:$=>{B(T.current,$)}}),[y,_,x,w,R,B]);const F=A(T.current,i);return vr(m,{...v,children:e,className:t,id:o,style:{...F,...p},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":E,"data-panel-id":R,"data-panel-size":parseFloat(""+F.flexGrow).toFixed(1)})}const Kf=Hf((e,t)=>vr(Gf,{...e,forwardedRef:t}));Gf.displayName="Panel";Kf.displayName="forwardRef(Panel)";let Wo=null,Pn=null;function nv(e,t){if(t){const n=(t&tp)!==0,r=(t&np)!==0,i=(t&rp)!==0,s=(t&ip)!==0;if(n)return i?"se-resize":s?"ne-resize":"e-resize";if(r)return i?"sw-resize":s?"nw-resize":"w-resize";if(i)return"s-resize";if(s)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function rv(){Pn!==null&&(document.head.removeChild(Pn),Wo=null,Pn=null)}function no(e,t){const n=nv(e,t);Wo!==n&&(Wo=n,Pn===null&&(Pn=document.createElement("style"),document.head.appendChild(Pn)),Pn.innerHTML=`*{cursor: ${n}!important;}`)}function Yf(e){return e.type==="keydown"}function Xf(e){return e.type.startsWith("pointer")}function Qf(e){return e.type.startsWith("mouse")}function Ds(e){if(Xf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Qf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function iv(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function sv(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function ov(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Hl(e),b:Hl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ee(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Jl(Ul(n.a)),b:Jl(Ul(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const c=s[a];if(c===o.a)return 1;if(c===o.b)return-1}}return Math.sign(i.a-i.b)}const av=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function lv(e){var t;const n=getComputedStyle((t=ep(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function cv(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||lv(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||av.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Ul(e){let t=e.length;for(;t--;){const n=e[t];if(Ee(n,"Missing node"),cv(n))return n}return null}function Jl(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Hl(e){const t=[];for(;e;)t.push(e),e=ep(e);return t}function ep(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const tp=1,np=2,rp=4,ip=8,uv=iv()==="coarse";let Ht=[],dr=!1,yn=new Map,Rs=new Map;const fi=new Set;function dv(e,t,n,r,i){var s;const{ownerDocument:o}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},c=(s=yn.get(o))!==null&&s!==void 0?s:0;return yn.set(o,c+1),fi.add(a),ls(),function(){var d;Rs.delete(e),fi.delete(a);const f=(d=yn.get(o))!==null&&d!==void 0?d:1;if(yn.set(o,f-1),ls(),f===1&&yn.delete(o),Ht.includes(a)){const h=Ht.indexOf(a);h>=0&&Ht.splice(h,1),$a(),i("up",!0,null)}}}function Wl(e){const{target:t}=e,{x:n,y:r}=Ds(e);dr=!0,Ra({target:t,x:n,y:r}),ls(),Ht.length>0&&(cs("down",e),e.preventDefault(),e.stopPropagation())}function Fr(e){const{x:t,y:n}=Ds(e);if(dr&&e.buttons===0&&(dr=!1,cs("up",e)),!dr){const{target:r}=e;Ra({target:r,x:t,y:n})}cs("move",e),$a(),Ht.length>0&&e.preventDefault()}function Wn(e){const{target:t}=e,{x:n,y:r}=Ds(e);Rs.clear(),dr=!1,Ht.length>0&&e.preventDefault(),cs("up",e),Ra({target:t,x:n,y:r}),$a(),ls()}function Ra({target:e,x:t,y:n}){Ht.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),fi.forEach(i=>{const{element:s,hitAreaMargins:o}=i,a=s.getBoundingClientRect(),{bottom:c,left:u,right:d,top:f}=a,h=uv?o.coarse:o.fine;if(t>=u-h&&t<=d+h&&n>=f-h&&n<=c+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&ov(r,s)>0){let m=r,v=!1;for(;m&&!m.contains(s);){if(sv(m.getBoundingClientRect(),a)){v=!0;break}m=m.parentElement}if(v)return}Ht.push(i)}})}function ro(e,t){Rs.set(e,t)}function $a(){let e=!1,t=!1;Ht.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;Rs.forEach(r=>{n|=r}),e&&t?no("intersection",n):e?no("horizontal",n):t?no("vertical",n):rv()}function ls(){yn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Wn),n.removeEventListener("pointerdown",Wl),n.removeEventListener("pointerleave",Fr),n.removeEventListener("pointermove",Fr)}),window.removeEventListener("pointerup",Wn),window.removeEventListener("pointercancel",Wn),fi.size>0&&(dr?(Ht.length>0&&yn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Wn),n.addEventListener("pointerleave",Fr),n.addEventListener("pointermove",Fr))}),window.addEventListener("pointerup",Wn),window.addEventListener("pointercancel",Wn)):yn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Wl,{capture:!0}),n.addEventListener("pointermove",Fr))}))}function cs(e,t){fi.forEach(n=>{const{setResizeHandlerState:r}=n,i=Ht.includes(n);r(e,i,t)})}function fv(){const[e,t]=ur(0);return bt(()=>t(n=>n+1),[])}function Ee(e,t){if(!e)throw console.error(t),Error(t)}const Ma=10;function Ln(e,t,n=Ma){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function ln(e,t,n=Ma){return Ln(e,t,n)===0}function Tt(e,t,n){return Ln(e,t,n)===0}function pv(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],s=t[r];if(!Tt(i,s,n))return!1}return!0}function sr({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ee(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:o=100,minSize:a=0}=r;if(Ln(n,a)<0)if(s){const c=(i+a)/2;Ln(n,c)<0?n=i:n=a}else n=a;return n=Math.min(o,n),n=parseFloat(n.toFixed(Ma)),n}function Hr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Tt(e,0))return t;const o=[...t],[a,c]=r;Ee(a!=null,"Invalid first pivot index"),Ee(c!=null,"Invalid second pivot index");let u=0;if(s==="keyboard"){{const f=e<0?c:a,h=n[f];Ee(h,`Panel constraints not found for index ${f}`);const{collapsedSize:p=0,collapsible:m,minSize:v=0}=h;if(m){const k=t[f];if(Ee(k!=null,`Previous layout not found for panel index ${f}`),Tt(k,p)){const y=v-k;Ln(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const f=e<0?a:c,h=n[f];Ee(h,`No panel constraints found for index ${f}`);const{collapsedSize:p=0,collapsible:m,minSize:v=0}=h;if(m){const k=t[f];if(Ee(k!=null,`Previous layout not found for panel index ${f}`),Tt(k,v)){const y=k-p;Ln(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const f=e<0?1:-1;let h=e<0?c:a,p=0;for(;;){const v=t[h];Ee(v!=null,`Previous layout not found for panel index ${h}`);const y=sr({panelConstraints:n,panelIndex:h,size:100})-v;if(p+=y,h+=f,h<0||h>=n.length)break}const m=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-m:m}{let h=e<0?a:c;for(;h>=0&&h<n.length;){const p=Math.abs(e)-Math.abs(u),m=t[h];Ee(m!=null,`Previous layout not found for panel index ${h}`);const v=m-p,k=sr({panelConstraints:n,panelIndex:h,size:v});if(!Tt(m,k)&&(u+=m-k,o[h]=k,u.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(pv(i,o))return i;{const f=e<0?c:a,h=t[f];Ee(h!=null,`Previous layout not found for panel index ${f}`);const p=h+u,m=sr({panelConstraints:n,panelIndex:f,size:p});if(o[f]=m,!Tt(m,p)){let v=p-m,y=e<0?c:a;for(;y>=0&&y<n.length;){const _=o[y];Ee(_!=null,`Previous layout not found for panel index ${y}`);const x=_+v,A=sr({panelConstraints:n,panelIndex:y,size:x});if(Tt(_,A)||(v-=A-_,o[y]=A),Tt(v,0))break;e>0?y--:y++}}}const d=o.reduce((f,h)=>h+f,0);return Tt(d,100)?o:i}function hv({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,o=0;const a=n[0];Ee(a!=null,"No pivot index found"),t.forEach((f,h)=>{const{constraints:p}=f,{maxSize:m=100,minSize:v=0}=p;h===a?(r=v,i=m):(s+=v,o+=m)});const c=Math.min(i,100-s),u=Math.max(r,100-o),d=e[a];return{valueMax:c,valueMin:u,valueNow:d}}function pi(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function sp(e,t,n=document){const i=pi(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function op(e,t,n){const r=sp(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function ap(e,t=document){var n;if(t instanceof HTMLElement&&(t==null||(n=t.dataset)===null||n===void 0?void 0:n.panelGroupId)==e)return t;const r=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return r||null}function $s(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function mv(e,t,n,r=document){var i,s,o,a;const c=$s(t,r),u=pi(e,r),d=c?u.indexOf(c):-1,f=(i=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,h=(o=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&o!==void 0?o:null;return[f,h]}function gv({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:o}){jt({didWarnAboutMissingResizeHandle:!1}),$n(()=>{if(!s)return;const a=pi(n,s);for(let c=0;c<i.length-1;c++){const{valueMax:u,valueMin:d,valueNow:f}=hv({layout:r,panelsArray:i,pivotIndices:[c,c+1]}),h=a[c];if(h!=null){const p=i[c];Ee(p,`No panel data found for index "${c}"`),h.setAttribute("aria-controls",p.id),h.setAttribute("aria-valuemax",""+Math.round(u)),h.setAttribute("aria-valuemin",""+Math.round(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((c,u)=>{c.removeAttribute("aria-controls"),c.removeAttribute("aria-valuemax"),c.removeAttribute("aria-valuemin"),c.removeAttribute("aria-valuenow")})}},[n,r,i,s]),Rn(()=>{if(!s)return;const a=t.current;Ee(a,"Eager values not found");const{panelDataArray:c}=a,u=ap(n,s);Ee(u!=null,`No group found for id "${n}"`);const d=pi(n,s);Ee(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const p=h.getAttribute("data-panel-resize-handle-id");Ee(p,"Resize handle element has no handle id attribute");const[m,v]=mv(n,p,c,s);if(m==null||v==null)return()=>{};const k=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const _=c.findIndex(x=>x.id===m);if(_>=0){const x=c[_];Ee(x,`No panel data found for index ${_}`);const A=r[_],{collapsedSize:E=0,collapsible:w,minSize:S=0}=x.constraints;if(A!=null&&w){const O=Hr({delta:Tt(A,E)?S-E:E-A,initialLayout:r,panelConstraints:c.map(B=>B.constraints),pivotIndices:op(n,p,s),prevLayout:r,trigger:"keyboard"});r!==O&&o(O)}}break}}};return h.addEventListener("keydown",k),()=>{h.removeEventListener("keydown",k)}});return()=>{f.forEach(h=>h())}},[s,e,t,n,r,i,o])}function ql(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function lp(e,t){const n=e==="horizontal",{x:r,y:i}=Ds(t);return n?r:i}function xv(e,t,n,r,i){const s=n==="horizontal",o=$s(t,i);Ee(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute("data-panel-group-id");Ee(a,"Resize handle element has no group id attribute");let{initialCursorPosition:c}=r;const u=lp(n,e),d=ap(a,i);Ee(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),h=s?f.width:f.height;return(u-c)/h*100}function yv(e,t,n,r,i,s){if(Yf(e)){const o=n==="horizontal";let a=0;e.shiftKey?a=100:i!=null?a=i:a=10;let c=0;switch(e.key){case"ArrowDown":c=o?0:a;break;case"ArrowLeft":c=o?-a:0;break;case"ArrowRight":c=o?a:0;break;case"ArrowUp":c=o?0:-a;break;case"End":c=100;break;case"Home":c=-100;break}return c}else return r==null?0:xv(e,t,n,r,s)}function bv({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,i=100;for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;a!=null&&(r++,t[s]=a,i-=a)}for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;if(a!=null)continue;const c=e.length-r,u=i/c;r++,t[s]=u,i-=u}return t}function qn(e,t,n){t.forEach((r,i)=>{const s=e[i];Ee(s,`Panel data not found for index ${i}`);const{callbacks:o,constraints:a,id:c}=s,{collapsedSize:u=0,collapsible:d}=a,f=n[c];if(f==null||r!==f){n[c]=r;const{onCollapse:h,onExpand:p,onResize:m}=o;m&&m(r,f),d&&(h||p)&&(p&&(f==null||ln(f,u))&&!ln(r,u)&&p(),h&&(f==null||!ln(f,u))&&ln(r,u)&&h())}})}function $i(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function vv({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const o=n[i];let a;return o==null?a=e!=null?e.toPrecision(s):"1":r.length===1?a="1":a=o.toPrecision(s),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function wv(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Gl(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function cp(e){return`react-resizable-panels:${e}`}function up(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:i,order:s}=t;return i?r:s?`${s}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function dp(e,t){try{const n=cp(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function kv(e,t,n){var r,i;const s=(r=dp(e,n))!==null&&r!==void 0?r:{},o=up(t);return(i=s[o])!==null&&i!==void 0?i:null}function Sv(e,t,n,r,i){var s;const o=cp(e),a=up(t),c=(s=dp(e,i))!==null&&s!==void 0?s:{};c[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(o,JSON.stringify(c))}catch(u){console.error(u)}}function Kl({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,o)=>s+o,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Tt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=100/r*o;n[s]=a}let i=0;for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=sr({panelConstraints:t,panelIndex:s,size:o});o!=a&&(i+=o-a,n[s]=a)}if(!Tt(i,0))for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=o+i,c=sr({panelConstraints:t,panelIndex:s,size:a});if(o!==c&&(i-=c-o,n[s]=c,Tt(i,0)))break}return n}const jv=100,Wr={getItem:e=>(Gl(Wr),Wr.getItem(e)),setItem:(e,t)=>{Gl(Wr),Wr.setItem(e,t)}},Yl={};function fp({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:o=null,keyboardResizeBy:a=null,storage:c=Wr,style:u,tagName:d="div",...f}){const h=Da(s),p=jt(null),[m,v]=ur(null),[k,y]=ur([]),_=fv(),x=jt({}),A=jt(new Map),E=jt(0),w=jt({autoSaveId:e,direction:r,dragState:m,id:h,keyboardResizeBy:a,onLayout:o,storage:c}),S=jt({layout:k,panelDataArray:[],panelDataArrayChanged:!1});jt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),qf(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:b}=S.current;return b},setLayout:b=>{const{onLayout:G}=w.current,{layout:ne,panelDataArray:Q}=S.current,oe=Kl({layout:b,panelConstraints:Q.map(I=>I.constraints)});ql(ne,oe)||(y(oe),S.current.layout=oe,G&&G(oe),qn(Q,oe,x.current))}}),[]),$n(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=m,w.current.id=h,w.current.onLayout=o,w.current.storage=c}),gv({committedValuesRef:w,eagerValuesRef:S,groupId:h,layout:k,panelDataArray:S.current.panelDataArray,setLayout:y,panelGroupElement:p.current}),Rn(()=>{const{panelDataArray:b}=S.current;if(e){if(k.length===0||k.length!==b.length)return;let G=Yl[e];G==null&&(G=wv(Sv,jv),Yl[e]=G);const ne=[...b],Q=new Map(A.current);G(e,ne,Q,k,c)}},[e,k,c]),Rn(()=>{});const O=bt(b=>{const{onLayout:G}=w.current,{layout:ne,panelDataArray:Q}=S.current;if(b.constraints.collapsible){const oe=Q.map(H=>H.constraints),{collapsedSize:I=0,panelSize:re,pivotIndices:ae}=En(Q,b,ne);if(Ee(re!=null,`Panel size not found for panel "${b.id}"`),!ln(re,I)){A.current.set(b.id,re);const K=tr(Q,b)===Q.length-1?re-I:I-re,pe=Hr({delta:K,initialLayout:ne,panelConstraints:oe,pivotIndices:ae,prevLayout:ne,trigger:"imperative-api"});$i(ne,pe)||(y(pe),S.current.layout=pe,G&&G(pe),qn(Q,pe,x.current))}}},[]),B=bt((b,G)=>{const{onLayout:ne}=w.current,{layout:Q,panelDataArray:oe}=S.current;if(b.constraints.collapsible){const I=oe.map(fe=>fe.constraints),{collapsedSize:re=0,panelSize:ae=0,minSize:H=0,pivotIndices:K}=En(oe,b,Q),pe=G??H;if(ln(ae,re)){const fe=A.current.get(b.id),Re=fe!=null&&fe>=pe?fe:pe,$e=tr(oe,b)===oe.length-1?ae-Re:Re-ae,C=Hr({delta:$e,initialLayout:Q,panelConstraints:I,pivotIndices:K,prevLayout:Q,trigger:"imperative-api"});$i(Q,C)||(y(C),S.current.layout=C,ne&&ne(C),qn(oe,C,x.current))}}},[]),N=bt(b=>{const{layout:G,panelDataArray:ne}=S.current,{panelSize:Q}=En(ne,b,G);return Ee(Q!=null,`Panel size not found for panel "${b.id}"`),Q},[]),R=bt((b,G)=>{const{panelDataArray:ne}=S.current,Q=tr(ne,b);return vv({defaultSize:G,dragState:m,layout:k,panelData:ne,panelIndex:Q})},[m,k]),T=bt(b=>{const{layout:G,panelDataArray:ne}=S.current,{collapsedSize:Q=0,collapsible:oe,panelSize:I}=En(ne,b,G);return Ee(I!=null,`Panel size not found for panel "${b.id}"`),oe===!0&&ln(I,Q)},[]),F=bt(b=>{const{layout:G,panelDataArray:ne}=S.current,{collapsedSize:Q=0,collapsible:oe,panelSize:I}=En(ne,b,G);return Ee(I!=null,`Panel size not found for panel "${b.id}"`),!oe||Ln(I,Q)>0},[]),$=bt(b=>{const{panelDataArray:G}=S.current;G.push(b),G.sort((ne,Q)=>{const oe=ne.order,I=Q.order;return oe==null&&I==null?0:oe==null?-1:I==null?1:oe-I}),S.current.panelDataArrayChanged=!0,_()},[_]);$n(()=>{if(S.current.panelDataArrayChanged){S.current.panelDataArrayChanged=!1;const{autoSaveId:b,onLayout:G,storage:ne}=w.current,{layout:Q,panelDataArray:oe}=S.current;let I=null;if(b){const ae=kv(b,oe,ne);ae&&(A.current=new Map(Object.entries(ae.expandToSizes)),I=ae.layout)}I==null&&(I=bv({panelDataArray:oe}));const re=Kl({layout:I,panelConstraints:oe.map(ae=>ae.constraints)});ql(Q,re)||(y(re),S.current.layout=re,G&&G(re),qn(oe,re,x.current))}}),$n(()=>{const b=S.current;return()=>{b.layout=[]}},[]);const Z=bt(b=>{let G=!1;const ne=p.current;return ne&&window.getComputedStyle(ne,null).getPropertyValue("direction")==="rtl"&&(G=!0),function(oe){oe.preventDefault();const I=p.current;if(!I)return()=>null;const{direction:re,dragState:ae,id:H,keyboardResizeBy:K,onLayout:pe}=w.current,{layout:fe,panelDataArray:Re}=S.current,{initialLayout:Oe}=ae??{},$e=op(H,b,I);let C=yv(oe,b,re,ae,K,I);const z=re==="horizontal";z&&G&&(C=-C);const L=Re.map(ee=>ee.constraints),se=Hr({delta:C,initialLayout:Oe??fe,panelConstraints:L,pivotIndices:$e,prevLayout:fe,trigger:Yf(oe)?"keyboard":"mouse-or-touch"}),ie=!$i(fe,se);(Xf(oe)||Qf(oe))&&E.current!=C&&(E.current=C,!ie&&C!==0?z?ro(b,C<0?tp:np):ro(b,C<0?rp:ip):ro(b,0)),ie&&(y(se),S.current.layout=se,pe&&pe(se),qn(Re,se,x.current))}},[]),P=bt((b,G)=>{const{onLayout:ne}=w.current,{layout:Q,panelDataArray:oe}=S.current,I=oe.map(fe=>fe.constraints),{panelSize:re,pivotIndices:ae}=En(oe,b,Q);Ee(re!=null,`Panel size not found for panel "${b.id}"`);const K=tr(oe,b)===oe.length-1?re-G:G-re,pe=Hr({delta:K,initialLayout:Q,panelConstraints:I,pivotIndices:ae,prevLayout:Q,trigger:"imperative-api"});$i(Q,pe)||(y(pe),S.current.layout=pe,ne&&ne(pe),qn(oe,pe,x.current))},[]),J=bt((b,G)=>{const{layout:ne,panelDataArray:Q}=S.current,{collapsedSize:oe=0,collapsible:I}=G,{collapsedSize:re=0,collapsible:ae,maxSize:H=100,minSize:K=0}=b.constraints,{panelSize:pe}=En(Q,b,ne);pe!=null&&(I&&ae&&ln(pe,oe)?ln(oe,re)||P(b,re):pe<K?P(b,K):pe>H&&P(b,H))},[P]),V=bt((b,G)=>{const{direction:ne}=w.current,{layout:Q}=S.current;if(!p.current)return;const oe=$s(b,p.current);Ee(oe,`Drag handle element not found for id "${b}"`);const I=lp(ne,G);v({dragHandleId:b,dragHandleRect:oe.getBoundingClientRect(),initialCursorPosition:I,initialLayout:Q})},[]),X=bt(()=>{v(null)},[]),j=bt(b=>{const{panelDataArray:G}=S.current,ne=tr(G,b);ne>=0&&(G.splice(ne,1),delete x.current[b.id],S.current.panelDataArrayChanged=!0,_())},[_]),ye=Xb(()=>({collapsePanel:O,direction:r,dragState:m,expandPanel:B,getPanelSize:N,getPanelStyle:R,groupId:h,isPanelCollapsed:T,isPanelExpanded:F,reevaluatePanelConstraints:J,registerPanel:$,registerResizeHandle:Z,resizePanel:P,startDragging:V,stopDragging:X,unregisterPanel:j,panelGroupElement:p.current}),[O,m,r,B,N,R,h,T,F,J,$,Z,P,V,X,j]),ce={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return vr(Ps.Provider,{value:ye},vr(d,{...f,children:t,className:n,id:s,ref:p,style:{...ce,...u},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":h}))}const pp=Hf((e,t)=>vr(fp,{...e,forwardedRef:t}));fp.displayName="PanelGroup";pp.displayName="forwardRef(PanelGroup)";function tr(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function En(e,t,n){const r=tr(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],o=n[r];return{...t.constraints,panelSize:o,pivotIndices:s}}function _v({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){Rn(()=>{if(e||n==null||r==null)return;const i=$s(t,r);if(i==null)return;const s=o=>{if(!o.defaultPrevented)switch(o.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{o.preventDefault(),n(o);break}case"F6":{o.preventDefault();const a=i.getAttribute("data-panel-group-id");Ee(a,`No group element found for id "${a}"`);const c=pi(a,r),u=sp(a,t,r);Ee(u!==null,`No resize element found for id "${t}"`);const d=o.shiftKey?u>0?u-1:c.length-1:u+1<c.length?u+1:0;c[d].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function hp({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:o,onFocus:a,style:c={},tabIndex:u=0,tagName:d="div",...f}){var h,p;const m=jt(null),v=jt({onDragging:o});Rn(()=>{v.current.onDragging=o});const k=Wf(Ps);if(k===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:y,groupId:_,registerResizeHandle:x,startDragging:A,stopDragging:E,panelGroupElement:w}=k,S=Da(i),[O,B]=ur("inactive"),[N,R]=ur(!1),[T,F]=ur(null),$=jt({state:O});$n(()=>{$.current.state=O}),Rn(()=>{if(n)F(null);else{const V=x(S);F(()=>V)}},[n,S,x]);const Z=(h=r==null?void 0:r.coarse)!==null&&h!==void 0?h:15,P=(p=r==null?void 0:r.fine)!==null&&p!==void 0?p:5;return Rn(()=>{if(n||T==null)return;const V=m.current;return Ee(V,"Element ref not attached"),dv(S,V,y,{coarse:Z,fine:P},(j,ye,ce)=>{if(ye)switch(j){case"down":{B("drag"),Ee(ce,'Expected event to be defined for "down" action'),A(S,ce);const{onDragging:b}=v.current;b&&b(!0);break}case"move":{const{state:b}=$.current;b!=="drag"&&B("hover"),Ee(ce,'Expected event to be defined for "move" action'),T(ce);break}case"up":{B("hover"),E();const{onDragging:b}=v.current;b&&b(!1);break}}else B("inactive")})},[Z,y,n,P,x,S,T,A,E]),_v({disabled:n,handleId:S,resizeHandler:T,panelGroupElement:w}),vr(d,{...f,children:e,className:t,id:i,onBlur:()=>{R(!1),s==null||s()},onFocus:()=>{R(!0),a==null||a()},ref:m,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...c},tabIndex:u,"data-panel-group-direction":y,"data-panel-group-id":_,"data-resize-handle":"","data-resize-handle-active":O==="drag"?"pointer":N?"keyboard":void 0,"data-resize-handle-state":O,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":S})}hp.displayName="PanelResizeHandle";const Nv=({className:e,...t})=>l.jsx(pp,{className:W("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),io=Kf,Xl=({withHandle:e,className:t,...n})=>l.jsx(hp,{className:W("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-none data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&l.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:l.jsx(jx,{className:"h-2.5 w-2.5"})})}),mp=g.forwardRef(({className:e,...t},n)=>l.jsx("textarea",{className:W("flex min-h-[80px] w-full rounded-sm border border-input bg-background px-3 py-2 text-sm shadow-xs","placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));mp.displayName="Textarea";class Cv{constructor(t){Or(this,"client");this.client=Mx.create({baseURL:t||void 0||"/api",headers:{"Content-Type":"application/json"}})}get(t,n){return this.client.get(t,n)}post(t,n,r){return this.client.post(t,n,r)}put(t,n,r){return this.client.put(t,n,r)}delete(t,n){return this.client.delete(t,n)}patch(t,n,r){return this.client.patch(t,n,r)}}const Ev=new Cv;class Tv extends Error{constructor(n,r){super(n);Or(this,"quality");this.name="QualityGateFailedError",this.quality=r}}function Iv(e,t){return e??t}function Av(e){var n;const t=(n=e==null?void 0:e.split(";",1)[0])==null?void 0:n.trim().toLowerCase();return t?t==="application/json"||t.startsWith("application/")&&t.endsWith("+json"):!1}async function zv(e){if(Av(e.headers.get("content-type")))try{return await e.json()}catch{return}}function Ql(e,t){if(t!=null&&t.error)return t.error;if(t!=null&&t.message)return t.message;if(e.ok)return`The server answered ${e.status} but not with a document. This usually means a proxy or extension replaced the response.`;switch(e.status){case 502:case 503:case 504:return`The server did not finish generating (${e.status}). It usually ran out of memory or restarted mid-request — documents with many full-page images or inline SVGs are the common cause. Try again, or split the document and generate it in parts.`;case 413:return"The document is too large for the server to accept (413). Remove or shrink its largest embedded assets.";case 429:return"Too many requests (429). Wait a moment before generating again.";default:return`Generation failed (${e.status}${e.statusText?` ${e.statusText}`:""}).`}}function Ov(){const e=g.useRef(null),t=gr(s=>s.generationBackend),n=id(),r=g.useCallback(async(s,o,a,c,u)=>{e.current&&e.current.abort();const d=new AbortController;e.current=d;const f=Iv(u==null?void 0:u.renderer,t);try{c==null||c("parsing","Validating JSON structure...");let h;try{h=JSON.parse(o)}catch(B){throw new Error(`Invalid JSON: ${B instanceof Error?B.message:"Unknown parse error"}`)}c==null||c("building",`Building ${Pi.toLowerCase()} structure...`);const p={jsonDefinition:h,options:{...u,sourceName:n(s),...f?{renderer:f}:{}}};p.customThemes=a??{},c==null||c("rendering",`Generating ${at.toUpperCase()} content...`);const m={"Content-Type":"application/json"};u!=null&&u.bypassCache&&(m["X-Bypass-Cache"]="true");const v=await fetch(oi.generate,{method:"POST",headers:m,body:JSON.stringify(p),signal:d.signal}),k=await zv(v);if(v.status===400&&(k==null?void 0:k.code)==="QUALITY_GATE_FAILED")throw new Tv(Ql(v,k),k.quality);if(!v.ok||!(k!=null&&k.success))throw new Error(Ql(v,k));const{data:y,cache:_,warnings:x}=k,A=_.status==="HIT"?"HIT":_.status==="MISS"?"MISS":"UNKNOWN",E=A==="HIT"?`Served from cache (Hit rate: ${_.hitRate})`:`Generated fresh ${Pi.toLowerCase()}`;c==null||c("finalizing",E);const w=globalThis.atob(y.document),S=new Uint8Array(w.length);for(let B=0;B<w.length;B++)S[B]=w.charCodeAt(B);const O=new Blob([S],{type:y.contentType});if(O.size===0)throw new Error(`Received empty ${Pi.toLowerCase()} from API`);return{name:s,text:o,blob:O,...f?{renderer:f}:{},filename:y.filename,fileId:y.fileId,cacheStatus:A,cacheHitRate:_.hitRate,warnings:x}}catch(h){throw h instanceof Error&&h.name==="AbortError"?new Error(`${Pi} generation was cancelled`):h}finally{e.current===d&&(e.current=null)}},[t,n]),i=g.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:r,generateDocument:r,cancelGeneration:i}}const qi={ids:[],default:null};let ec;function Pv(){return ec??(ec=(async()=>{var e;try{const t=await fetch(oi.renderers);if(!t.ok)return qi;const n=await t.json();return!(n!=null&&n.success)||!Array.isArray((e=n.data)==null?void 0:e.ids)?qi:n.data}catch{return qi}})()),ec}function Dv(){const[e,t]=g.useState(qi);return g.useEffect(()=>{let n=!1;return Pv().then(r=>{n||t(r)}),()=>{n=!0}},[]),e}function Rv(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const o of i){let a=o.message;if(o.context&&Object.keys(o.context).length>0){const c=Object.entries(o.context).map(([u,d])=>`${u}: ${JSON.stringify(d)}`).join(", ");a+=` (${c})`}s.push(a)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function $v({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=je.useState("custom");je.useEffect(()=>{e&&s("custom")},[e]);const o=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),a=[{value:"custom",title:"Keep custom fonts",desc:"Recipients with the font installed see the authored typeface. Others get a generic fallback."},{value:"substitute",title:"Convert to safe fonts",desc:"Rewrite non-safe families to Calibri / Georgia / Consolas so every recipient sees the same glyphs."}];return l.jsx(ct,{open:e,onOpenChange:c=>!c&&t(),children:l.jsxs(lt,{className:"max-w-md",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Non-safe fonts in this document"}),l.jsxs(dn,{children:[o," ",n.length===1?"is":"are"," not in the built-in safe list. Choose how to export."]})]}),l.jsx("div",{className:"grid gap-2 py-2",children:a.map(c=>{const u=i===c.value;return l.jsxs("button",{type:"button",onClick:()=>s(c.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${u?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${u?"border-primary":"border-muted-foreground/50"}`,children:u&&l.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),l.jsx("span",{className:"text-sm font-medium",children:c.title})]}),l.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:c.desc})]},c.value)})}),l.jsxs(kn,{children:[l.jsx(Ce,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),l.jsx(Ce,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}function Mv(e){const t=e.hasPendingDiff?"Review the proposed change first":e.parses?void 0:"The visual view needs the JSON to parse";return{view:t?"json":e.preferred??"visual",forcedReason:t}}function Fv(e){try{const t=JSON.parse(e);return!!t&&typeof t=="object"&&!Array.isArray(t)}catch{return!1}}function Lv(){const e=gr(c=>c.setSettings),t=gr(c=>c.themeEditorView),n=ke(c=>c.activeTab&&c.documentTypes[c.activeTab]==="application/json+theme"?c.activeTab:""),r=ke(c=>{if(!n)return!0;const u=c.documents.find(d=>d.name===n);return u?Fv(u.text):!0}),i=ke(c=>!!n&&c.pendingDiffs[n]!==void 0),s=g.useCallback(c=>e({themeEditorView:c}),[e]);if(!n)return null;const{view:o,forcedReason:a}=Mv({preferred:t,parses:r,hasPendingDiff:i});return l.jsxs("div",{role:"tablist","aria-label":"Theme editor view",title:a,className:"flex h-7 shrink-0 items-center rounded-sm border border-border/70 bg-muted/60 p-0.5",children:[l.jsx(tc,{active:o==="visual",disabled:a!==void 0,onClick:()=>s("visual"),icon:_x,label:"Visual"}),l.jsx(tc,{active:o==="json",onClick:()=>s("json"),icon:Qi,label:"JSON"})]})}function tc({active:e,disabled:t,onClick:n,icon:r,label:i}){return l.jsxs("button",{type:"button",role:"tab","aria-selected":e,"aria-label":i,disabled:t,onClick:n,className:W("flex h-6 cursor-pointer items-center gap-1.5 rounded-[3px] px-2 text-xs transition-colors","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none","disabled:cursor-not-allowed disabled:opacity-50",e?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[l.jsx(r,{className:"size-3.5"}),l.jsx("span",{className:"hidden md:inline",children:i})]})}const Bv=je.memo(Lv);function so(){return l.jsx("span",{className:"rounded-sm bg-warning/15 px-1 py-px text-[10px] font-semibold uppercase leading-none tracking-wide text-warning",children:"experimental"})}function nc(){return l.jsx("span",{className:"rounded-sm bg-muted px-1 py-px text-[10px] font-semibold uppercase leading-none tracking-wide text-muted-foreground",children:"default"})}function Zv({name:e,blob:t,onManualRender:n,isGenerating:r,isRendering:i,onShowCacheMetrics:s,onShowSchemas:o,onShowFonts:a,documentText:c,editorDocumentText:u,editorDocumentName:d,warnings:f,onToggleChat:h,chatOpen:p,onTogglePreview:m,previewOpen:v}){const[k,y]=g.useState(!1),[_,x]=g.useState(!1),[A,E]=g.useState(!1),[w,S]=g.useState(!1),[O,B]=g.useState(!1),[N,R]=g.useState(null),{toast:T}=_r(),F=id(),{generateDocument:$}=Ov(),Z=g.useContext(xa),P=Dv(),J=gr(K=>K.generationBackend),V=gr(K=>K.setSettings),X=J??P.default??void 0,j=g.useCallback(()=>{const K={},{customThemes:pe}=Z.getState();return Object.values(pe).forEach(fe=>{fe.valid&&fe.parsed&&(K[fe.name]=fe.parsed)}),K},[Z]),ye=je.useMemo(()=>{if(!c)return[];try{const K=JSON.parse(c);return[...(at==="pptx"?Tg:Ig)(K)].filter(fe=>!Ag(fe))}catch{return[]}},[c]),[ce,b]=g.useState(!1),G=g.useCallback(async()=>{if(t){y(!0);try{await new Promise(K=>setTimeout(K,100)),ni(`${e}${Pr}`,t)}finally{setTimeout(()=>y(!1),500)}}},[t,e]),ne=g.useCallback(async()=>{if(t){if(ye.length===0){await G();return}b(!0)}},[t,ye.length,G]),Q=g.useCallback(async K=>{var pe;if(c){y(!0);try{const fe=await $(e,c,j(),void 0,{bypassCache:!0,fonts:{mode:K}});if(fe.blob.size===0)T({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{ni(`${e}${Pr}`,fe.blob);const Re=(pe=fe.warnings)==null?void 0:pe.find(Oe=>{var $e,C;return(($e=Oe.context)==null?void 0:$e.code)==="FONT_MODE_SUBSTITUTED"||((C=Oe.context)==null?void 0:C.code)==="FONT_MODE_CUSTOM"});Re&&T({title:K==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:Re.message})}}catch(fe){T({title:"Export failed",description:fe instanceof Error?fe.message:String(fe),variant:"destructive"})}finally{setTimeout(()=>y(!1),500)}}},[c,e,$,T,j]),oe=g.useCallback(async()=>{if(!(!f||f.length===0)){x(!0);try{const K=Rv(f);if(!K){T({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const pe=await $("warnings",JSON.stringify(K,null,2),{});pe&&typeof pe=="object"&&"blob"in pe&&pe.blob&&(ni(`${e}-warnings${Pr}`,pe.blob),T({title:"Warnings downloaded",description:`Downloaded warnings document with ${f.length} warning(s).`}))}catch(K){console.error("Failed to generate warnings document:",K),T({title:"Download failed",description:K instanceof Error?K.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>x(!1),500)}}},[f,e,$,T]),I=g.useCallback(async()=>{E(!0);try{await Ev.delete(`/${at}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),T({title:"Cache Cleared",description:"All active caches have been successfully cleared.",variant:"default"})}catch(K){console.error("Failed to clear cache:",K),T({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{E(!1)}},[T]),re=u??c,ae=g.useCallback(()=>{var fe,Re;if(!re){T({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(re)}catch{T({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}B(!0);const K=(async()=>{const Oe=j(),$e=await Ro(re,{customThemes:Oe}),C=await fetch(`/api/${at}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:$e.text,customThemes:Oe,options:{sourceName:F(d??e)}})});if(!C.ok){let L=`Request failed with status ${C.status}`;try{const se=await C.json(),ie=se.error??se.message;typeof ie=="string"&&ie&&(L=ie)}catch{}throw new Error(L)}const z=await C.json();return JSON.stringify(z.data,null,2)})();let pe;typeof ClipboardItem<"u"&&((fe=navigator.clipboard)!=null&&fe.write)?pe=navigator.clipboard.write([new ClipboardItem({"text/plain":K.then(Oe=>new Blob([Oe],{type:"text/plain"}))})]):(Re=navigator.clipboard)!=null&&Re.writeText?pe=K.then(Oe=>navigator.clipboard.writeText(Oe)):pe=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await pe,T({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(Oe){let $e=null;try{$e=await K}catch(C){console.error("Error fetching standard components:",C),T({title:"Failed to get standard components",description:C instanceof Error?C.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",Oe),R($e)}finally{B(!1)}})()},[re,e,d,F,j,T]),H=g.useCallback(async()=>{if(N!=null)try{await navigator.clipboard.writeText(N),T({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),R(null)}catch{T({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[N,T]);return l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"bg-sidebar border-b flex flex-row flex-nowrap items-center justify-between gap-x-2 px-3 py-1.5",children:[l.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[l.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx("button",{type:"button","aria-label":"Preview disclaimer",className:"cursor-help inline-flex items-center justify-center h-6 w-6 rounded-sm hover:bg-muted/60 shrink-0",children:l.jsx(qd,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),l.jsx(Qe,{className:"max-w-sm",children:l.jsxs("p",{className:"text-sm",children:["Preview converts the file to a PDF with LibreOffice. Download the ",Pr," to verify fidelity."]})})]})]}),l.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[l.jsx(Bv,{}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(Ce,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:n,"aria-label":"Render preview",disabled:r||i||v===!1,children:[i?l.jsx(cn,{size:"sm"}):l.jsx(Nx,{className:"h-3.5 w-3.5"}),l.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),l.jsx(Qe,{children:l.jsx("p",{children:v===!1?"Open preview to run":i?"Rendering preview...":"Render preview"})})]}),l.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(Ce,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||k||r,onClick:ne,children:[k?l.jsx(cn,{size:"sm"}):l.jsx(Cx,{className:"h-3.5 w-3.5"}),l.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),l.jsx(Qe,{children:l.jsxs("p",{children:["Download ",Pr]})})]}),f&&f.length>0&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ce,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:_||r,onClick:oe,children:_?l.jsx(cn,{size:"sm"}):l.jsx(Kd,{className:"h-3.5 w-3.5"})})}),l.jsx(Qe,{children:l.jsxs("p",{children:["Download warnings (",f.length,")"]})})]}),P.ids.length>1&&l.jsxs(li,{value:X,onValueChange:K=>V({generationBackend:K}),children:[l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsxs(xr,{"aria-label":"Renderer",className:"hidden h-7 w-auto min-h-0 gap-1.5 px-2 text-xs lg:flex [&>span]:flex [&>span]:items-center [&>span]:gap-1.5 [&>span]:whitespace-nowrap",children:[l.jsx(zo,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),l.jsxs(ci,{placeholder:"Renderer",children:[l.jsx("span",{className:"font-medium",children:X}),X!==P.default&&l.jsx(so,{})]})]})}),l.jsx(Qe,{children:l.jsxs("p",{children:["Renderer that writes the ",at.toUpperCase()," file. A non-default one may refuse a document it cannot express."]})})]}),l.jsx(yr,{className:"min-w-[var(--radix-select-trigger-width)] text-sidebar-foreground",children:l.jsxs(ef,{children:[l.jsx(ka,{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),P.ids.map(K=>l.jsx(Mn,{value:K,className:"text-xs",children:l.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap",children:[l.jsx("span",{className:"font-medium",children:K}),K===P.default?l.jsx(nc,{}):l.jsx(so,{})]})},K))]})})]}),l.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),l.jsxs(_i,{children:[l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ni,{asChild:!0,children:l.jsx(Ce,{variant:"ghost",size:"icon",className:"h-7 w-7",children:l.jsx(ba,{className:"h-3.5 w-3.5"})})})}),l.jsx(Qe,{children:l.jsx("p",{children:"More actions"})})]}),l.jsxs(Er,{align:"end",className:"w-52",children:[o&&l.jsxs($t,{onClick:o,children:[l.jsx(Ex,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),a&&l.jsxs($t,{onClick:a,children:[l.jsx(Ao,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),s&&l.jsxs($t,{onClick:s,children:[l.jsx(Oo,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),re?l.jsxs($t,{onClick:ae,disabled:O,children:[l.jsx(Po,{className:"h-4 w-4 mr-2"}),O?"Copying...":"Copy standard components"]}):l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx("span",{className:"block",children:l.jsxs($t,{disabled:!0,children:[l.jsx(Po,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),l.jsx(Qe,{side:"left",children:l.jsx("p",{children:"No document selected — open or select a document first"})})]}),l.jsx(Fn,{}),l.jsxs($t,{onClick:()=>S(!0),disabled:A,className:"text-destructive focus:text-destructive",children:[l.jsx(va,{className:"h-4 w-4 mr-2"}),A?"Clearing...":"Clear all caches"]}),P.ids.length>1&&l.jsxs(l.Fragment,{children:[l.jsx(Fn,{className:"lg:hidden"}),l.jsx(za,{className:"lg:hidden px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),P.ids.map(K=>l.jsxs($t,{className:"lg:hidden gap-1.5",onClick:()=>V({generationBackend:K}),children:[l.jsx(un,{className:`h-3.5 w-3.5 shrink-0 ${X===K?"opacity-100":"opacity-0"}`}),l.jsx("span",{className:"font-medium",children:K}),K===P.default?l.jsx(nc,{}):l.jsx(so,{})]},K))]})]})]}),m&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ce,{variant:v?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:m,children:v?l.jsx(Yd,{className:"h-3.5 w-3.5"}):l.jsx(Tx,{className:"h-3.5 w-3.5"})})}),l.jsx(Qe,{children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[v?"Hide":"Show"," Preview"," ",l.jsx(di,{shortcut:"mod+shift+p"})]})})]}),h&&l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx(Ce,{variant:p?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:h,children:l.jsx(Xd,{className:"h-3.5 w-3.5"})})}),l.jsx(Qe,{children:l.jsxs("span",{className:"flex items-center gap-1.5",children:[p?"Close":"Open"," AI Chat"," ",l.jsx(di,{shortcut:"mod+shift+j"})]})})]})]})]}),l.jsx($v,{open:ce,onClose:()=>b(!1),nonSafeFonts:ye,onChoose:Q}),l.jsx(ct,{open:N!=null,onOpenChange:K=>{K||R(null)},children:l.jsxs(lt,{className:"max-w-lg",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Standard components"}),l.jsx(dn,{children:"The browser blocked the automatic clipboard write. Copy the JSON from here instead."})]}),l.jsx(mp,{readOnly:!0,value:N??"",className:"h-64 font-mono text-xs",onFocus:K=>K.currentTarget.select()}),l.jsxs(kn,{children:[l.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>R(null),children:"Close"}),l.jsx(Ce,{size:"sm",onClick:H,children:"Copy to clipboard"})]})]})}),l.jsx(ct,{open:w,onOpenChange:S,children:l.jsxs(lt,{className:"max-w-sm",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Clear all caches?"}),l.jsx(dn,{children:"This will clear the document, component, and rasterized-visual caches. Next generation will be uncached."})]}),l.jsxs(kn,{children:[l.jsx(Ce,{variant:"outline",size:"sm",onClick:()=>S(!1),children:"Cancel"}),l.jsx(Ce,{variant:"destructive",size:"sm",disabled:A,onClick:async()=>{await I(),S(!1)},children:A?l.jsx(cn,{size:"sm"}):"Clear"})]})]})})]})}const Vv=je.memo(Zv),gp=Xg,Fa=g.forwardRef(({className:e,...t},n)=>l.jsx(Ld,{ref:n,className:W("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Fa.displayName=Ld.displayName;const fr=g.forwardRef(({className:e,...t},n)=>l.jsx(Bd,{ref:n,className:W("ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex cursor-pointer items-center justify-center rounded-sm px-3 py-1 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",e),...t}));fr.displayName=Bd.displayName;const pr=g.forwardRef(({className:e,...t},n)=>l.jsx(Zd,{ref:n,className:W("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));pr.displayName=Zd.displayName;async function Uv(e){if(navigator.clipboard&&navigator.clipboard.writeText)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="2em",t.style.height="2em",t.style.padding="0",t.style.border="none",t.style.outline="none",t.style.boxShadow="none",t.style.background="transparent",document.body.appendChild(t),t.focus(),t.select();const n=document.execCommand("copy");return document.body.removeChild(t),n}catch(t){return console.error("Failed to copy text to clipboard:",t),!1}}function Jv(e){try{const t=typeof e=="string"?JSON.parse(e):e;return JSON.stringify(t,null,2)}catch(t){return console.error("Failed to format schema:",t),typeof e=="string"?e:JSON.stringify(e)}}async function Hv(e){const t=Jv(e);return Uv(t)}const Wv=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=g.useState(n),[s,o]=g.useState(null),[a,c]=g.useState(null),[u,d]=g.useState(!1),[f,h]=g.useState(!1),[p,m]=g.useState(null),[v,k]=g.useState(null),[y,_]=g.useState(!1),{toast:x}=_r(),A=Jt(P=>P.selectedPlugins),E=Array.from(A),w=vn(mg);g.useEffect(()=>{n&&i(n)},[n]);const S=g.useCallback(async()=>{d(!0),m(null);try{const P=await Gs.fetchDocumentSchema(E,gg(vn.getState()));o(P)}catch(P){const J=P instanceof Error?P.message:"Failed to load document schema";m(J),x({variant:"destructive",title:"Error loading schema",description:J})}finally{d(!1)}},[E,w,x]),O=g.useCallback(async()=>{if(!a){h(!0),k(null);try{const P=await Gs.fetchThemeSchema();c(P)}catch(P){const J=P instanceof Error?P.message:"Failed to load theme schema";k(J),x({variant:"destructive",title:"Error loading schema",description:J})}finally{h(!1)}}},[a,x]),[B,N]=g.useState([]),[R,T]=g.useState(w);g.useEffect(()=>{e||(o(null),m(null))},[e]),g.useEffect(()=>{if(!e)return;const P=E.length!==B.length||E.some((V,X)=>V!==B[X]),J=w!==R;r==="document"?(!s||P||J)&&((P||J)&&(Gs.clearPluginSchemaCache(),N([...E]),T(w)),u||S()):r==="theme"&&!a&&!f&&O()},[r,e,s,a,u,f,E,B,w,R,S,O]);const F=E.length,$=r==="document"?s:a,Z=async()=>{if($)try{await Hv($)&&(_(!0),x({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>_(!1),2e3))}catch(P){console.error("Copy failed:",P)}};return l.jsx(ct,{open:e,onOpenChange:t,children:l.jsxs(lt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[l.jsx(qt,{children:l.jsx(Gt,{children:"Schema Viewer"})}),l.jsxs(gp,{value:r,onValueChange:P=>i(P),className:"flex-1 overflow-hidden flex flex-col",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(Fa,{children:[l.jsxs(fr,{value:"document",className:"flex items-center gap-1",children:["Document",F>0&&l.jsxs(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",F]})]}),l.jsx(fr,{value:"theme",children:"Theme"})]}),l.jsx("div",{className:"ml-auto",children:l.jsx(Ce,{variant:"ghost",size:"icon",onClick:Z,disabled:y||!$,"aria-label":"Copy schema",children:y?l.jsx(un,{className:"h-4 w-4"}):l.jsx(Es,{className:"h-4 w-4"})})})]}),l.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[l.jsx(pr,{value:"document",className:"h-full",children:l.jsx(as,{schema:s,loading:u,error:p||void 0})}),l.jsx(pr,{value:"theme",className:"h-full",children:l.jsx(as,{schema:a,loading:f,error:v||void 0})})]})]})]})})};function La(e,t){var r;const n=sd.getState().getEditor(e);return(r=n==null?void 0:n.flushPendingSave)==null||r.call(n),n?n.toStorageValue(n.editor.getValue()):t}function xp(e,t,n){if(t.length===0)return n;const r=rc(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const o=t[s],a=t[s+1],c=i[o],u=rc(c,a);i[o]=u,i=u}return i[t[t.length-1]]=n,r}function rc(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const ic=2*1024*1024,sc=12*1024*1024;function qv(e){if(e.length<4)return"unknown";const[t,n,r,i]=e;return t===0&&n===1&&r===0&&i===0||t===116&&n===114&&r===117&&i===101||t===116&&n===116&&r===99&&i===102?"ttf":t===79&&n===84&&r===84&&i===79?"otf":t===119&&n===79&&r===70&&i===70?"woff":t===119&&n===79&&r===70&&i===50?"woff2":"unknown"}function Gv(e){let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function us(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.round(e/1024)} KB`}function Kv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>ic)return{ok:!1,message:`"${e}" is ${us(t.length)}. The limit is ${us(ic)} per font, because the bytes travel inside the document JSON.`};const n=qv(t);return n==="woff"||n==="woff2"?{ok:!1,message:`"${e}" is a ${n.toUpperCase()} file. Upload the TTF or OTF instead — the preview renderer cannot register web font formats.`}:n!=="ttf"&&n!=="otf"?{ok:!1,message:`"${e}" does not look like a TTF or OTF font file.`}:{ok:!0,format:n,base64:Gv(t)}}const Yv=new Set(["italic","oblique"]);function Xv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[o,a]of Object.entries(ld))r.set(a.toLowerCase(),Number(o));let i=400,s=!1;for(;n.length>1;){const o=n[n.length-1].toLowerCase();if(Yv.has(o)){s=!0,n.pop();continue}const a=r.get(o);if(a!==void 0){i=a,n.pop();continue}break}return{family:n.join(" ")||t,weight:i,italic:s}}function Qv(e,t){const n=Array.isArray(e)?[...e]:[],r=n.findIndex(i=>{var s;return((s=i==null?void 0:i.family)==null?void 0:s.toLowerCase())===t.family.toLowerCase()});return r>=0?n[r]=t:n.push(t),n}function ew(e){return e.kind==="safe"||e.kind==="google"?null:{weight:"weight"in e&&e.weight?e.weight:400,italic:"italic"in e?!!e.italic:!1}}function tw(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(a=>{const c=ew(a);return c?!n.some(u=>u.weight===c.weight&&u.italic===c.italic):!0}),s=n.map(a=>({kind:"data",data:a.data,weight:a.weight,italic:a.italic})),o=r??(e==null?void 0:e.category);return{id:(e==null?void 0:e.id)??t,family:t,...o?{category:o}:{},sources:[...i,...s]}}function nw(e,t){let n=Array.isArray(e)?[...e]:[];for(const r of t){const i=r.sources.filter(o=>o.kind==="data").map(o=>({data:o.data,weight:o.weight??400,italic:o.italic??!1}));if(i.length===0)continue;const s=n.find(o=>{var a;return((a=o==null?void 0:o.family)==null?void 0:a.toLowerCase())===r.family.toLowerCase()});n=Qv(n,tw(s,r.family,i,r.category))}return n}function rw(e,t){const n=(e.sources??[]).filter(r=>r.format==="ttf"||r.format==="otf").map(r=>({kind:"data",data:r.data,weight:r.weight,italic:r.italic}));return n.length===0?null:{id:e.family,family:e.family,...t?{category:t}:{},sources:n}}function iw(e){const t=new TextEncoder().encode(e).length;return t<=sc?null:`Adding this font would push the document to ${us(t)}, past the ${us(sc)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const oc=new Set,sw=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function ac(e,t){var d;if(typeof document>"u"||!e.trim())return;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((d=r==null?void 0:r.dataset.weights)==null?void 0:d.split(",").map(Number).filter(f=>!Number.isNaN(f)))??[]),o=new Set([...s,...i]);if(r&&o.size===s.size)return;const a=[...o].sort((f,h)=>f-h).join(";"),c=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${a}&display=swap`,u=r??document.createElement("link");r||(u.id=n,u.rel="stylesheet",document.head.appendChild(u)),u.href=c,u.dataset.weights=[...o].sort((f,h)=>f-h).join(",")}function ow(e){const t=e.startsWith("data:")?e.slice(e.indexOf(",")+1):e,n=atob(t),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r}async function aw(e,t,n,r){const i=sw(e,n,r);if(!oc.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=ow(t),o=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await o.load(),document.fonts.add(o),oc.add(i)}catch{}}const lw={safe:[],google:[]};function cw(){const e=ke(i=>i.activeTab),t=ke(i=>i.documents),n=ke(i=>i.documentTypes),r=ke(i=>i.saveDocument);return g.useCallback(i=>{if(!e)return{ok:!1,error:"No active file"};if(n[e]!=="application/json+theme")return{ok:!1,error:"Fonts are registered on themes, not documents. Open a .theme.json file and try again."};const s=t.find(u=>u.name===e);if(!s)return{ok:!1,error:"Active theme not found"};const o=La(e,s.text);let a;try{a=JSON.parse(o)}catch(u){return{ok:!1,error:`Active theme is not valid JSON: ${u.message}`}}const c=i(a);return r(e,JSON.stringify(c,null,2)),{ok:!0,name:e}},[e,t,n,r])}function uw(){const e=ke(r=>r.activeTab),t=ke(r=>r.documents),n=ke(r=>r.saveDocument);return g.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(u=>u.name===e);if(!s)return{ok:!1,error:"Active document not found"};const o=La(e,s.text);let a;try{a=JSON.parse(o)}catch(u){return{ok:!1,error:`Active document is not valid JSON: ${u.message}`}}const c=xp(a,r,i);return n(e,JSON.stringify(c,null,2)),{ok:!0,name:e}},[e,t,n])}function dw(){const e=ke(i=>i.activeTab),t=ke(i=>i.documents),n=ke(i=>i.documentTypes),r=ke(i=>i.saveDocument);return g.useCallback(i=>{var h;if(i.length===0)return{ok:!0,name:e};if(!e)return{ok:!1,error:"No active file"};if(n[e]==="application/json+theme")return{ok:!1,error:"Custom fonts are registered on the document, not the theme. Open the .docx.json / .pptx.json tab and try again."};const s=t.find(p=>p.name===e);if(!s)return{ok:!1,error:"Active document not found"};const o=La(e,s.text);let a;try{a=JSON.parse(o)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const c=nw((h=a==null?void 0:a.props)==null?void 0:h.fontRegistry,i),u=xp(a,["props","fontRegistry"],c),d=JSON.stringify(u,null,2),f=iw(d);return f?{ok:!1,error:f}:(r(e,d),{ok:!0,name:e})},[e,t,n,r])}function fw(e,t,n){(!e.fonts||typeof e.fonts!="object")&&(e.fonts={});const r=e.fonts[t];r&&typeof r=="object"?e.fonts[t]={...r,family:n}:e.fonts[t]=n}function lc(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const pw=({open:e,onOpenChange:t})=>{const n=Hi(I=>I.open),r=Hi(I=>I.contextual),i=Hi(I=>I.close),s=e??n,o=r,a=g.useCallback(I=>{t&&t(I),I||i()},[t,i]),[c,u]=g.useState(lw),[d,f]=g.useState(!1),[h,p]=g.useState(""),[m,v]=g.useState("safe"),[k,y]=g.useState(null),[_,x]=g.useState(null),[A,E]=g.useState(!1),[w,S]=g.useState(!1),[O,B]=g.useState(""),[N,R]=g.useState([]),T=g.useRef(null),{toast:F}=_r(),$=cw(),Z=uw(),P=dw(),J=ke(I=>I.activeTab),V=ke(I=>I.documentTypes),X=J&&V[J]==="application/json+theme",j=!!o||X;g.useEffect(()=>{s&&(c.safe.length>0||c.google.length>0||(f(!0),fetch(oi.fonts.catalog).then(I=>I.json()).then(I=>u(I)).catch(I=>{F({variant:"destructive",title:"Font catalog unavailable",description:I.message})}).finally(()=>f(!1))))},[s,c,F]),g.useEffect(()=>{if(!(m!=="google"||c.google.length===0))for(const I of c.google)ac(I.family,I.weights)},[m,c]);const ye=g.useMemo(()=>c.safe.filter(I=>I.toLowerCase().includes(h.toLowerCase())),[c.safe,h]),ce=g.useMemo(()=>c.google.filter(I=>I.family.toLowerCase().includes(h.toLowerCase())),[c.google,h]),b=g.useCallback(async I=>{try{await navigator.clipboard.writeText(I),x(I),setTimeout(()=>x(null),1500)}catch{F({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[F]),G=g.useCallback(async(I,re,ae)=>{y(I);try{const H=$(K=>(fw(K,ae,I),K));if(!H.ok){F({variant:"destructive",title:"Could not insert font",description:H.error});return}F({title:"Font inserted",description:`${I} set as ${ae} font in "${H.name}".`})}finally{y(null)}},[$,F]),ne=g.useCallback(async I=>{if(o){y(I);try{const re=Z(o.jsonPath,I);if(!re.ok){F({variant:"destructive",title:"Could not insert font",description:re.error});return}F({title:"Font inserted",description:`${I} set at ${lc(o.jsonPath)}.`}),a(!1)}finally{y(null)}}},[o,Z,F,a]),Q=g.useCallback(async I=>{if(!(!I||I.length===0)){E(!0);try{const re=[];for(const H of Array.from(I)){const K=new Uint8Array(await H.arrayBuffer()),pe=Kv(H.name,K);if(!pe.ok){F({variant:"destructive",title:"Font rejected",description:pe.message});continue}re.push({identity:Xv(H.name),base64:pe.base64})}if(re.length===0)return;const ae=P(re.map(({identity:H,base64:K})=>({id:H.family,family:H.family,sources:[{kind:"data",data:K,weight:H.weight,italic:H.italic}]})));if(!ae.ok){F({variant:"destructive",title:"Could not register font",description:ae.error});return}for(const{identity:H,base64:K}of re)aw(H.family,K,H.weight,H.italic),F({title:`Added ${H.family}`,description:`Registered at weight ${H.weight}${H.italic?" italic":""} in props.fontRegistry. Reference it as "${H.family}".`})}catch(re){F({variant:"destructive",title:"Upload failed",description:re.message})}finally{E(!1),T.current&&(T.current.value="")}}},[P,F]),oe=g.useCallback(async()=>{var re,ae;const I=O.trim();if(I){S(!0),R([]);try{const H=await fetch(oi.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:I,weights:[400,700],italics:!1})});if(H.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!H.ok){const Oe=await H.json().catch(()=>({}));throw new Error(Oe.error??`Materialize failed (${H.status})`)}const K=await H.json();R(K.warnings??[]);const pe=(re=c.google.find(Oe=>Oe.family.toLowerCase()===K.family.toLowerCase()))==null?void 0:re.category,fe=rw(K,pe);if(!fe){F({variant:"destructive",title:"Nothing to embed",description:((ae=K.warnings)==null?void 0:ae.join(" · "))||`Google Fonts has no family named "${I}".`});return}const Re=P([fe]);if(!Re.ok){F({variant:"destructive",title:"Could not register font",description:Re.error});return}ac(K.family,[400,700]),F({title:`Added ${K.family}`,description:`Embedded ${fe.sources.length} weight(s) in props.fontRegistry.`})}catch(H){F({variant:"destructive",title:"Google Fonts fetch failed",description:H.message})}finally{S(!1)}}},[O,c.google,P,F]);return l.jsx(ct,{open:s,onOpenChange:a,children:l.jsxs(lt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[l.jsx(qt,{children:l.jsx(Gt,{children:o?`Font for ${lc(o.jsonPath)}`:"Fonts"})}),!o&&!X&&m!=="custom"&&l.jsx(lr,{children:l.jsxs(cr,{children:["Fonts are registered on themes. Open a ",l.jsx("code",{children:".theme.json"})," ","file to apply a font — the buttons below are disabled until you do."]})}),l.jsxs(gp,{value:m,onValueChange:I=>v(I),className:"flex-1 overflow-hidden flex flex-col",children:[l.jsxs("div",{className:"flex items-center gap-2",children:[l.jsxs(Fa,{children:[l.jsxs(fr,{value:"safe",children:["Safe",l.jsx(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:c.safe.length})]}),l.jsxs(fr,{value:"google",children:["Google",l.jsx(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:c.google.length})]}),l.jsx(fr,{value:"custom",children:"Custom"})]}),l.jsx(br,{type:"search",placeholder:"Search fonts...",value:h,onChange:I=>p(I.target.value),className:"ml-auto max-w-xs"})]}),l.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[l.jsx(pr,{value:"safe",className:"m-0",children:d&&ye.length===0?l.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[l.jsx(Jr,{className:"animate-spin mr-2"})," Loading catalog..."]}):l.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ye.map(I=>l.jsx(cc,{family:I,meta:l.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${I}", sans-serif`},onCopy:()=>b(I),copied:_===I,contextual:!!o,onUseThis:()=>ne(I),onInsertHeading:()=>G(I,"safe","heading"),onInsertBody:()=>G(I,"safe","body"),applying:k===I,disabled:!j},I))})}),l.jsx(pr,{value:"google",className:"m-0",children:d&&ce.length===0?l.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[l.jsx(Jr,{className:"animate-spin mr-2"})," Loading catalog..."]}):l.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ce.map(I=>l.jsx(cc,{family:I.family,meta:l.jsxs("span",{className:"text-xs",children:[I.category," · ",I.weights.length," weights"]}),previewStyle:{fontFamily:`"${I.family}", sans-serif`},onCopy:()=>b(I.family),copied:_===I.family,contextual:!!o,onUseThis:()=>ne(I.family),onInsertHeading:()=>G(I.family,"google","heading"),onInsertBody:()=>G(I.family,"google","body"),applying:k===I.family,disabled:!j,extraAction:l.jsx(mw,{family:I.family,weights:I.weights,hasItalic:I.hasItalic})},I.family))})}),l.jsx(pr,{value:"custom",className:"m-0 flex flex-col gap-6",children:X?l.jsx(lr,{children:l.jsxs(cr,{children:["Custom fonts are stored on the document (",l.jsx("code",{children:"props.fontRegistry"}),"), because the bytes travel with the JSON. Open a document tab to add one."]})}):l.jsxs(l.Fragment,{children:[l.jsxs("section",{className:"flex flex-col gap-2",children:[l.jsx("h3",{className:"text-sm font-medium",children:"Upload a font file"}),l.jsxs("p",{className:"text-xs text-muted-foreground",children:["TTF or OTF, up to 2 MB each. The font is embedded in the document as base64, so it survives export and re-import — and renders in the preview. The family and weight are guessed from the filename (e.g."," ",l.jsx("code",{children:"Geist-SemiBold.ttf"}),")."]}),l.jsxs("div",{onDragOver:I=>I.preventDefault(),onDrop:I=>{I.preventDefault(),Q(I.dataTransfer.files)},className:"rounded-md border border-dashed p-6 text-center",children:[l.jsx("input",{ref:T,type:"file",accept:".ttf,.otf,font/ttf,font/otf",multiple:!0,className:"hidden",onChange:I=>void Q(I.target.files)}),l.jsxs(Ce,{variant:"secondary",disabled:A,onClick:()=>{var I;return(I=T.current)==null?void 0:I.click()},children:[A?l.jsx(Jr,{className:"animate-spin mr-2 h-4 w-4"}):l.jsx(Ix,{className:"mr-2 h-4 w-4"}),"Choose font files"]}),l.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"or drop them here"})]})]}),l.jsxs("section",{className:"flex flex-col gap-2",children:[l.jsx("h3",{className:"text-sm font-medium",children:"Embed any Google font"}),l.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not limited to the ",c.google.length," curated families — type any Google Fonts family name and its regular and bold weights are fetched and embedded."]}),l.jsxs("div",{className:"flex gap-2",children:[l.jsx(br,{placeholder:"e.g. Geist",value:O,onChange:I=>B(I.target.value),onKeyDown:I=>{I.key==="Enter"&&oe()}}),l.jsxs(Ce,{onClick:()=>void oe(),disabled:w||O.trim()==="",children:[w&&l.jsx(Jr,{className:"animate-spin mr-2 h-4 w-4"}),"Embed"]})]}),N.length>0&&l.jsx(lr,{children:l.jsx(cr,{className:"text-xs",children:N.join(" · ")})})]})]})})]})]})]})})},hw="The quick brown fox jumps over the lazy dog",mw=({family:e,weights:t,hasItalic:n})=>{const r=g.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return l.jsxs(_i,{children:[l.jsx(Ni,{asChild:!0,children:l.jsx(Ce,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),l.jsxs(Er,{align:"end",className:"min-w-[260px]",children:[l.jsxs(za,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),l.jsx(Fn,{}),r.map(i=>{const s=ld[i]??String(i);return l.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-1.5",children:[l.jsx("span",{className:"truncate",style:{fontFamily:`"${e}", sans-serif`,fontWeight:i},children:s}),l.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:["fontWeight: ",i]})]},i)})]})]})},cc=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:o,onInsertHeading:a,onInsertBody:c,applying:u,disabled:d,extraAction:f})=>l.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[l.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[l.jsx("div",{className:"font-medium truncate",children:e}),l.jsx("div",{className:"text-muted-foreground",children:t})]}),l.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:hw}),l.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?l.jsx(Ce,{size:"sm",onClick:o,disabled:u||d,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):l.jsxs(l.Fragment,{children:[l.jsx(Ce,{size:"sm",variant:"secondary",onClick:a,disabled:u||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),l.jsx(Ce,{size:"sm",variant:"secondary",onClick:c,disabled:u||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,l.jsx(Ce,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?l.jsx(un,{className:"h-4 w-4"}):l.jsx(Es,{className:"h-4 w-4"})})]})]});function uc({previewOpen:e,onTogglePreview:t}){const n=an(w=>w.name||""),r=an(w=>w.blob),i=an(w=>w.isGenerating),s=an(w=>w.text),o=an(w=>w.warnings),a=an(w=>w.isRendering),c=gr(w=>w.useGlobalPreviewHeader??!0),u=ke(w=>w.activeTab),d=ke(w=>w.documentTypes),f=u&&d[u]==="application/json+theme"?"theme":"document",h=ke(w=>{var S;return w.activeTab&&(w.documentTypes[w.activeTab]??"application/json+report")==="application/json+report"?(S=w.documents.find(O=>O.name===w.activeTab))==null?void 0:S.text:void 0}),p=ke(w=>w.activeTab&&(w.documentTypes[w.activeTab]??"application/json+report")==="application/json+report"?w.activeTab:void 0),m=De(w=>w.chatOpen),v=De(w=>w.toggleChat),[k,y]=je.useState(!1),_=Hi(w=>w.openFor);if(!c)return null;const x=g.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),A=g.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),E=(n==null?void 0:n.trim())||"Preview";return l.jsxs("div",{className:"sticky top-0 z-20",children:[l.jsx(Vv,{name:E,blob:r,onManualRender:x,isGenerating:i,isRendering:!!a,onShowCacheMetrics:A,onShowSchemas:()=>y(!0),onShowFonts:()=>_(),documentText:s,editorDocumentText:h,editorDocumentName:p,warnings:o,onToggleChat:v,chatOpen:m,onTogglePreview:t,previewOpen:e}),l.jsx(Wv,{open:k,onOpenChange:y,defaultTab:f==="theme"?"theme":"document"}),l.jsx(pw,{})]})}function gw(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const xw=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,yw=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,bw={};function dc(e,t){return(bw.jsx?yw:xw).test(e)}const vw=/[ \t\n\f\r]/g;function ww(e){return typeof e=="object"?e.type==="text"?fc(e.value):!1:fc(e)}function fc(e){return e.replace(vw,"")===""}class Ei{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}Ei.prototype.normal={};Ei.prototype.property={};Ei.prototype.space=void 0;function yp(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new Ei(n,r,t)}function qo(e){return e.toLowerCase()}class _t{constructor(t,n){this.attribute=n,this.property=t}}_t.prototype.attribute="";_t.prototype.booleanish=!1;_t.prototype.boolean=!1;_t.prototype.commaOrSpaceSeparated=!1;_t.prototype.commaSeparated=!1;_t.prototype.defined=!1;_t.prototype.mustUseProperty=!1;_t.prototype.number=!1;_t.prototype.overloadedBoolean=!1;_t.prototype.property="";_t.prototype.spaceSeparated=!1;_t.prototype.space=void 0;let kw=0;const Ne=Vn(),rt=Vn(),Go=Vn(),te=Vn(),Ve=Vn(),hr=Vn(),Ct=Vn();function Vn(){return 2**++kw}const Ko=Object.freeze(Object.defineProperty({__proto__:null,boolean:Ne,booleanish:rt,commaOrSpaceSeparated:Ct,commaSeparated:hr,number:te,overloadedBoolean:Go,spaceSeparated:Ve},Symbol.toStringTag,{value:"Module"})),oo=Object.keys(Ko);class Ba extends _t{constructor(t,n,r,i){let s=-1;if(super(t,n),pc(this,"space",i),typeof r=="number")for(;++s<oo.length;){const o=oo[s];pc(this,oo[s],(r&Ko[o])===Ko[o])}}}Ba.prototype.defined=!0;function pc(e,t,n){n&&(e[t]=n)}function Tr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Ba(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[qo(r)]=r,n[qo(s.attribute)]=r}return new Ei(t,n,e.space)}const bp=Tr({properties:{ariaActiveDescendant:null,ariaAtomic:rt,ariaAutoComplete:null,ariaBusy:rt,ariaChecked:rt,ariaColCount:te,ariaColIndex:te,ariaColSpan:te,ariaControls:Ve,ariaCurrent:null,ariaDescribedBy:Ve,ariaDetails:null,ariaDisabled:rt,ariaDropEffect:Ve,ariaErrorMessage:null,ariaExpanded:rt,ariaFlowTo:Ve,ariaGrabbed:rt,ariaHasPopup:null,ariaHidden:rt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Ve,ariaLevel:te,ariaLive:null,ariaModal:rt,ariaMultiLine:rt,ariaMultiSelectable:rt,ariaOrientation:null,ariaOwns:Ve,ariaPlaceholder:null,ariaPosInSet:te,ariaPressed:rt,ariaReadOnly:rt,ariaRelevant:null,ariaRequired:rt,ariaRoleDescription:Ve,ariaRowCount:te,ariaRowIndex:te,ariaRowSpan:te,ariaSelected:rt,ariaSetSize:te,ariaSort:null,ariaValueMax:te,ariaValueMin:te,ariaValueNow:te,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function vp(e,t){return t in e?e[t]:t}function wp(e,t){return vp(e,t.toLowerCase())}const Sw=Tr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:hr,acceptCharset:Ve,accessKey:Ve,action:null,allow:null,allowFullScreen:Ne,allowPaymentRequest:Ne,allowUserMedia:Ne,alt:null,as:null,async:Ne,autoCapitalize:null,autoComplete:Ve,autoFocus:Ne,autoPlay:Ne,blocking:Ve,capture:null,charSet:null,checked:Ne,cite:null,className:Ve,cols:te,colSpan:null,content:null,contentEditable:rt,controls:Ne,controlsList:Ve,coords:te|hr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Ne,defer:Ne,dir:null,dirName:null,disabled:Ne,download:Go,draggable:rt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Ne,formTarget:null,headers:Ve,height:te,hidden:Go,high:te,href:null,hrefLang:null,htmlFor:Ve,httpEquiv:Ve,id:null,imageSizes:null,imageSrcSet:null,inert:Ne,inputMode:null,integrity:null,is:null,isMap:Ne,itemId:null,itemProp:Ve,itemRef:Ve,itemScope:Ne,itemType:Ve,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Ne,low:te,manifest:null,max:null,maxLength:te,media:null,method:null,min:null,minLength:te,multiple:Ne,muted:Ne,name:null,nonce:null,noModule:Ne,noValidate:Ne,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:Ne,optimum:te,pattern:null,ping:Ve,placeholder:null,playsInline:Ne,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Ne,referrerPolicy:null,rel:Ve,required:Ne,reversed:Ne,rows:te,rowSpan:te,sandbox:Ve,scope:null,scoped:Ne,seamless:Ne,selected:Ne,shadowRootClonable:Ne,shadowRootDelegatesFocus:Ne,shadowRootMode:null,shape:null,size:te,sizes:null,slot:null,span:te,spellCheck:rt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:te,step:null,style:null,tabIndex:te,target:null,title:null,translate:null,type:null,typeMustMatch:Ne,useMap:null,value:rt,width:te,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ve,axis:null,background:null,bgColor:null,border:te,borderColor:null,bottomMargin:te,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Ne,declare:Ne,event:null,face:null,frame:null,frameBorder:null,hSpace:te,leftMargin:te,link:null,longDesc:null,lowSrc:null,marginHeight:te,marginWidth:te,noResize:Ne,noHref:Ne,noShade:Ne,noWrap:Ne,object:null,profile:null,prompt:null,rev:null,rightMargin:te,rules:null,scheme:null,scrolling:rt,standby:null,summary:null,text:null,topMargin:te,valueType:null,version:null,vAlign:null,vLink:null,vSpace:te,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Ne,disableRemotePlayback:Ne,prefix:null,property:null,results:te,security:null,unselectable:null},space:"html",transform:wp}),jw=Tr({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:Ct,accentHeight:te,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:te,amplitude:te,arabicForm:null,ascent:te,attributeName:null,attributeType:null,azimuth:te,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:te,by:null,calcMode:null,capHeight:te,className:Ve,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:te,diffuseConstant:te,direction:null,display:null,dur:null,divisor:te,dominantBaseline:null,download:Ne,dx:null,dy:null,edgeMode:null,editable:null,elevation:te,enableBackground:null,end:null,event:null,exponent:te,externalResourcesRequired:null,fill:null,fillOpacity:te,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:hr,g2:hr,glyphName:hr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:te,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:te,horizOriginX:te,horizOriginY:te,id:null,ideographic:te,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:te,k:te,k1:te,k2:te,k3:te,k4:te,kernelMatrix:Ct,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:te,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:te,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:te,overlineThickness:te,paintOrder:null,panose1:null,path:null,pathLength:te,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ve,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:te,pointsAtY:te,pointsAtZ:te,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Ct,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Ct,rev:Ct,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Ct,requiredFeatures:Ct,requiredFonts:Ct,requiredFormats:Ct,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:te,specularExponent:te,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:te,strikethroughThickness:te,string:null,stroke:null,strokeDashArray:Ct,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:te,strokeOpacity:te,strokeWidth:null,style:null,surfaceScale:te,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Ct,tabIndex:te,tableValues:null,target:null,targetX:te,targetY:te,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Ct,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:te,underlineThickness:te,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:te,values:null,vAlphabetic:te,vMathematical:te,vectorEffect:null,vHanging:te,vIdeographic:te,version:null,vertAdvY:te,vertOriginX:te,vertOriginY:te,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:te,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:vp}),kp=Tr({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),Sp=Tr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:wp}),jp=Tr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),_w={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},Nw=/[A-Z]/g,hc=/-[a-z]/g,Cw=/^data[-\w.:]+$/i;function Ew(e,t){const n=qo(t);let r=t,i=_t;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Cw.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(hc,Iw);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!hc.test(s)){let o=s.replace(Nw,Tw);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=Ba}return new i(r,t)}function Tw(e){return"-"+e.toLowerCase()}function Iw(e){return e.charAt(1).toUpperCase()}const Aw=yp([bp,Sw,kp,Sp,jp],"html"),Za=yp([bp,jw,kp,Sp,jp],"svg");function zw(e){return e.join(" ").trim()}var Gn={},ao,mc;function Ow(){if(mc)return ao;mc=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,c=`
149
149
  `,u="/",d="*",f="",h="comment",p="declaration";function m(k,y){if(typeof k!="string")throw new TypeError("First argument must be a string");if(!k)return[];y=y||{};var _=1,x=1;function A($){var Z=$.match(t);Z&&(_+=Z.length);var P=$.lastIndexOf(c);x=~P?$.length-P:x+$.length}function E(){var $={line:_,column:x};return function(Z){return Z.position=new w($),B(),Z}}function w($){this.start=$,this.end={line:_,column:x},this.source=y.source}w.prototype.content=k;function S($){var Z=new Error(y.source+":"+_+":"+x+": "+$);if(Z.reason=$,Z.filename=y.source,Z.line=_,Z.column=x,Z.source=k,!y.silent)throw Z}function O($){var Z=$.exec(k);if(Z){var P=Z[0];return A(P),k=k.slice(P.length),Z}}function B(){O(n)}function N($){var Z;for($=$||[];Z=R();)Z!==!1&&$.push(Z);return $}function R(){var $=E();if(!(u!=k.charAt(0)||d!=k.charAt(1))){for(var Z=2;f!=k.charAt(Z)&&(d!=k.charAt(Z)||u!=k.charAt(Z+1));)++Z;if(Z+=2,f===k.charAt(Z-1))return S("End of comment missing");var P=k.slice(2,Z-2);return x+=2,A(P),k=k.slice(Z),x+=2,$({type:h,comment:P})}}function T(){var $=E(),Z=O(r);if(Z){if(R(),!O(i))return S("property missing ':'");var P=O(s),J=$({type:p,property:v(Z[0].replace(e,f)),value:P?v(P[0].replace(e,f)):f});return O(o),J}}function F(){var $=[];N($);for(var Z;Z=T();)Z!==!1&&($.push(Z),N($));return $}return B(),F()}function v(k){return k?k.replace(a,f):f}return ao=m,ao}var gc;function Pw(){if(gc)return Gn;gc=1;var e=Gn&&Gn.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Gn,"__esModule",{value:!0}),Gn.default=n;const t=e(Ow());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const o=(0,t.default)(r),a=typeof i=="function";return o.forEach(c=>{if(c.type!=="declaration")return;const{property:u,value:d}=c;a?i(u,d,c):d&&(s=s||{},s[u]=d)}),s}return Gn}var Lr={},xc;function Dw(){if(xc)return Lr;xc=1,Object.defineProperty(Lr,"__esModule",{value:!0}),Lr.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(u){return!u||n.test(u)||e.test(u)},o=function(u,d){return d.toUpperCase()},a=function(u,d){return"".concat(d,"-")},c=function(u,d){return d===void 0&&(d={}),s(u)?u:(u=u.toLowerCase(),d.reactCompat?u=u.replace(i,a):u=u.replace(r,a),u.replace(t,o))};return Lr.camelCase=c,Lr}var Br,yc;function Rw(){if(yc)return Br;yc=1;var e=Br&&Br.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Pw()),n=Dw();function r(i,s){var o={};return!i||typeof i!="string"||(0,t.default)(i,function(a,c){a&&c&&(o[(0,n.camelCase)(a,s)]=c)}),o}return r.default=r,Br=r,Br}var $w=Rw();const Mw=ga($w),_p=Np("end"),Va=Np("start");function Np(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function Fw(e){const t=Va(e),n=_p(e);if(t&&n)return{start:t,end:n}}function ri(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?bc(e.position):"start"in e||"end"in e?bc(e):"line"in e||"column"in e?Yo(e):""}function Yo(e){return vc(e&&e.line)+":"+vc(e&&e.column)}function bc(e){return Yo(e&&e.start)+"-"+Yo(e&&e.end)}function vc(e){return e&&typeof e=="number"?e:1}class dt extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},o=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(o=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const c=r.indexOf(":");c===-1?s.ruleId=r:(s.source=r.slice(0,c),s.ruleId=r.slice(c+1))}if(!s.place&&s.ancestors&&s.ancestors){const c=s.ancestors[s.ancestors.length-1];c&&(s.place=c.position)}const a=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=ri(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=o&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}dt.prototype.file="";dt.prototype.name="";dt.prototype.reason="";dt.prototype.message="";dt.prototype.stack="";dt.prototype.column=void 0;dt.prototype.line=void 0;dt.prototype.ancestors=void 0;dt.prototype.cause=void 0;dt.prototype.fatal=void 0;dt.prototype.place=void 0;dt.prototype.ruleId=void 0;dt.prototype.source=void 0;const Ua={}.hasOwnProperty,Lw=new Map,Bw=/[A-Z]/g,Zw=new Set(["table","tbody","thead","tfoot","tr"]),Vw=new Set(["td","th"]),Cp="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function Uw(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=Xw(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=Yw(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?Za:Aw,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=Ep(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function Ep(e,t,n){if(t.type==="element")return Jw(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return Hw(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return qw(e,t,n);if(t.type==="mdxjsEsm")return Ww(e,t);if(t.type==="root")return Gw(e,t,n);if(t.type==="text")return Kw(e,t)}function Jw(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=Za,e.schema=i),e.ancestors.push(t);const s=Ip(e,t.tagName,!1),o=Qw(e,t);let a=Ha(e,t);return Zw.has(t.tagName)&&(a=a.filter(function(c){return typeof c=="string"?!ww(c):!0})),Tp(e,o,s,t),Ja(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function Hw(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}hi(e,t.position)}function Ww(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);hi(e,t.position)}function qw(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=Za,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:Ip(e,t.name,!0),o=e0(e,t),a=Ha(e,t);return Tp(e,o,s,t),Ja(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function Gw(e,t,n){const r={};return Ja(r,Ha(e,t)),e.create(t,e.Fragment,r,n)}function Kw(e,t){return t.value}function Tp(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Ja(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function Yw(e,t,n){return r;function r(i,s,o,a){const u=Array.isArray(o.children)?n:t;return a?u(s,o,a):u(s,o)}}function Xw(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),c=Va(r);return t(i,s,o,a,{columnNumber:c?c.column-1:void 0,fileName:e,lineNumber:c?c.line:void 0},void 0)}}function Qw(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&Ua.call(t.properties,i)){const s=t0(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&Vw.has(t.tagName)?r=a:n[o]=a}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function e0(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const o=s.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else hi(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,s=e.evaluater.evaluateExpression(a.expression)}else hi(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function Ha(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:Lw;for(;++r<t.children.length;){const s=t.children[r];let o;if(e.passKeys){const c=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(c){const u=i.get(c)||0;o=c+"-"+u,i.set(c,u+1)}}const a=Ep(e,s,o);a!==void 0&&n.push(a)}return n}function t0(e,t,n){const r=Ew(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?gw(n):zw(n)),r.property==="style"){let i=typeof n=="object"?n:n0(e,String(n));return e.stylePropertyNameCase==="css"&&(i=r0(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?_w[r.property]||r.property:r.attribute,n]}}function n0(e,t){try{return Mw(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new dt("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=e.filePath||void 0,i.url=Cp+"#cannot-parse-style-attribute",i}}function Ip(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,o;for(;++s<i.length;){const a=dc(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(s&&a.type==="Literal"),optional:!1}:a}r=o}else r=dc(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return Ua.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);hi(e)}function hi(e,t){const n=new dt("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=Cp+"#cannot-handle-mdx-estrees-without-createevaluater",n}function r0(e){const t={};let n;for(n in e)Ua.call(e,n)&&(t[i0(n)]=e[n]);return t}function i0(e){let t=e.replace(Bw,s0);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function s0(e){return"-"+e.toLowerCase()}const lo={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},o0={};function Wa(e,t){const n=o0,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Ap(e,r,i)}function Ap(e,t,n){if(a0(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return wc(e.children,t,n)}return Array.isArray(e)?wc(e,t,n):""}function wc(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=Ap(e[i],t,n);return r.join("")}function a0(e){return!!(e&&typeof e=="object")}const kc=document.createElement("i");function qa(e){const t="&"+e+";";kc.innerHTML=t;const n=kc.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function At(e,t,n,r){const i=e.length;let s=0,o;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);s<r.length;)o=r.slice(s,s+1e4),o.unshift(t,0),e.splice(...o),s+=1e4,t+=1e4}function Mt(e,t){return e.length>0?(At(e,e.length,0,t),e):t}const Sc={}.hasOwnProperty;function zp(e){const t={};let n=-1;for(;++n<e.length;)l0(t,e[n]);return t}function l0(e,t){let n;for(n in t){const i=(Sc.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){Sc.call(i,o)||(i[o]=[]);const a=s[o];c0(i[o],Array.isArray(a)?a:a?[a]:[])}}}function c0(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);At(e,0,0,r)}function Op(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function Wt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const xt=_n(/[A-Za-z]/),ut=_n(/[\dA-Za-z]/),u0=_n(/[#-'*+\--9=?A-Z^-~]/);function ds(e){return e!==null&&(e<32||e===127)}const Xo=_n(/\d/),d0=_n(/[\dA-Fa-f]/),f0=_n(/[!-/:-@[-`{-~]/);function be(e){return e!==null&&e<-2}function Ze(e){return e!==null&&(e<0||e===32)}function Ie(e){return e===-2||e===-1||e===32}const Ms=_n(new RegExp("\\p{P}|\\p{S}","u")),Bn=_n(/\s/);function _n(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Ir(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let o="";if(s===37&&ut(e.charCodeAt(n+1))&&ut(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(o=String.fromCharCode(s));else if(s>55295&&s<57344){const a=e.charCodeAt(n+1);s<56320&&a>56319&&a<57344?(o=String.fromCharCode(s,a),i=1):o="�"}else o=String.fromCharCode(s);o&&(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,o=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function Pe(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return o;function o(c){return Ie(c)?(e.enter(n),a(c)):t(c)}function a(c){return Ie(c)&&s++<i?(e.consume(c),a):(e.exit(n),t(c))}}const p0={tokenize:h0};function h0(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),Pe(e,t,"linePrefix")}function i(a){return e.enter("paragraph"),s(a)}function s(a){const c=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=c),n=c,o(a)}function o(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return be(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const m0={tokenize:g0},jc={tokenize:x0};function g0(e){const t=this,n=[];let r=0,i,s,o;return a;function a(x){if(r<n.length){const A=n[r];return t.containerState=A[1],e.attempt(A[0].continuation,c,u)(x)}return u(x)}function c(x){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&_();const A=t.events.length;let E=A,w;for(;E--;)if(t.events[E][0]==="exit"&&t.events[E][1].type==="chunkFlow"){w=t.events[E][1].end;break}y(r);let S=A;for(;S<t.events.length;)t.events[S][1].end={...w},S++;return At(t.events,E+1,0,t.events.slice(A)),t.events.length=S,u(x)}return a(x)}function u(x){if(r===n.length){if(!i)return h(x);if(i.currentConstruct&&i.currentConstruct.concrete)return m(x);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(jc,d,f)(x)}function d(x){return i&&_(),y(r),h(x)}function f(x){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,m(x)}function h(x){return t.containerState={},e.attempt(jc,p,m)(x)}function p(x){return r++,n.push([t.currentConstruct,t.containerState]),h(x)}function m(x){if(x===null){i&&_(),y(0),e.consume(x);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),v(x)}function v(x){if(x===null){k(e.exit("chunkFlow"),!0),y(0),e.consume(x);return}return be(x)?(e.consume(x),k(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(x),v)}function k(x,A){const E=t.sliceStream(x);if(A&&E.push(null),x.previous=s,s&&(s.next=x),s=x,i.defineSkip(x.start),i.write(E),t.parser.lazy[x.start.line]){let w=i.events.length;for(;w--;)if(i.events[w][1].start.offset<o&&(!i.events[w][1].end||i.events[w][1].end.offset>o))return;const S=t.events.length;let O=S,B,N;for(;O--;)if(t.events[O][0]==="exit"&&t.events[O][1].type==="chunkFlow"){if(B){N=t.events[O][1].end;break}B=!0}for(y(r),w=S;w<t.events.length;)t.events[w][1].end={...N},w++;At(t.events,O+1,0,t.events.slice(S)),t.events.length=w}}function y(x){let A=n.length;for(;A-- >x;){const E=n[A];t.containerState=E[1],E[0].exit.call(t,e)}n.length=x}function _(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function x0(e,t,n){return Pe(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function wr(e){if(e===null||Ze(e)||Bn(e))return 1;if(Ms(e))return 2}function Fs(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const s=e[i].resolveAll;s&&!r.includes(s)&&(t=s(t,n),r.push(s))}return t}const Qo={name:"attention",resolveAll:y0,tokenize:b0};function y0(e,t){let n=-1,r,i,s,o,a,c,u,d;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;c=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},h={...e[n][1].start};_c(f,-c),_c(h,c),o={type:c>1?"strongSequence":"emphasisSequence",start:f,end:{...e[r][1].end}},a={type:c>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:h},s={type:c>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:c>1?"strong":"emphasis",start:{...o.start},end:{...a.end}},e[r][1].end={...o.start},e[n][1].start={...a.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=Mt(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=Mt(u,[["enter",i,t],["enter",o,t],["exit",o,t],["enter",s,t]]),u=Mt(u,Fs(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=Mt(u,[["exit",s,t],["enter",a,t],["exit",a,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(d=2,u=Mt(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):d=0,At(e,r-1,n-r+3,u),n=r+u.length-d-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function b0(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=wr(r);let s;return o;function o(c){return s=c,e.enter("attentionSequence"),a(c)}function a(c){if(c===s)return e.consume(c),a;const u=e.exit("attentionSequence"),d=wr(c),f=!d||d===2&&i||n.includes(c),h=!i||i===2&&d||n.includes(r);return u._open=!!(s===42?f:f&&(i||!h)),u._close=!!(s===42?h:h&&(d||!f)),t(c)}}function _c(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const v0={name:"autolink",tokenize:w0};function w0(e,t,n){let r=0;return i;function i(p){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(p){return xt(p)?(e.consume(p),o):p===64?n(p):u(p)}function o(p){return p===43||p===45||p===46||ut(p)?(r=1,a(p)):u(p)}function a(p){return p===58?(e.consume(p),r=0,c):(p===43||p===45||p===46||ut(p))&&r++<32?(e.consume(p),a):(r=0,u(p))}function c(p){return p===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):p===null||p===32||p===60||ds(p)?n(p):(e.consume(p),c)}function u(p){return p===64?(e.consume(p),d):u0(p)?(e.consume(p),u):n(p)}function d(p){return ut(p)?f(p):n(p)}function f(p){return p===46?(e.consume(p),r=0,d):p===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):h(p)}function h(p){if((p===45||ut(p))&&r++<63){const m=p===45?h:f;return e.consume(p),m}return n(p)}}const Ti={partial:!0,tokenize:k0};function k0(e,t,n){return r;function r(s){return Ie(s)?Pe(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||be(s)?t(s):n(s)}}const Pp={continuation:{tokenize:j0},exit:_0,name:"blockQuote",tokenize:S0};function S0(e,t,n){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),s}return n(o)}function s(o){return Ie(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function j0(e,t,n){const r=this;return i;function i(o){return Ie(o)?Pe(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(Pp,t,n)(o)}}function _0(e){e.exit("blockQuote")}const Dp={name:"characterEscape",tokenize:N0};function N0(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return f0(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const Rp={name:"characterReference",tokenize:C0};function C0(e,t,n){const r=this;let i=0,s,o;return a;function a(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),c}function c(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),s=31,o=ut,d(f))}function u(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,o=d0,d):(e.enter("characterReferenceValue"),s=7,o=Xo,d(f))}function d(f){if(f===59&&i){const h=e.exit("characterReferenceValue");return o===ut&&!qa(r.sliceSerialize(h))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return o(f)&&i++<s?(e.consume(f),d):n(f)}}const Nc={partial:!0,tokenize:T0},Cc={concrete:!0,name:"codeFenced",tokenize:E0};function E0(e,t,n){const r=this,i={partial:!0,tokenize:E};let s=0,o=0,a;return c;function c(w){return u(w)}function u(w){const S=r.events[r.events.length-1];return s=S&&S[1].type==="linePrefix"?S[2].sliceSerialize(S[1],!0).length:0,a=w,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),d(w)}function d(w){return w===a?(o++,e.consume(w),d):o<3?n(w):(e.exit("codeFencedFenceSequence"),Ie(w)?Pe(e,f,"whitespace")(w):f(w))}function f(w){return w===null||be(w)?(e.exit("codeFencedFence"),r.interrupt?t(w):e.check(Nc,v,A)(w)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),h(w))}function h(w){return w===null||be(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(w)):Ie(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),Pe(e,p,"whitespace")(w)):w===96&&w===a?n(w):(e.consume(w),h)}function p(w){return w===null||be(w)?f(w):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),m(w))}function m(w){return w===null||be(w)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(w)):w===96&&w===a?n(w):(e.consume(w),m)}function v(w){return e.attempt(i,A,k)(w)}function k(w){return e.enter("lineEnding"),e.consume(w),e.exit("lineEnding"),y}function y(w){return s>0&&Ie(w)?Pe(e,_,"linePrefix",s+1)(w):_(w)}function _(w){return w===null||be(w)?e.check(Nc,v,A)(w):(e.enter("codeFlowValue"),x(w))}function x(w){return w===null||be(w)?(e.exit("codeFlowValue"),_(w)):(e.consume(w),x)}function A(w){return e.exit("codeFenced"),t(w)}function E(w,S,O){let B=0;return N;function N(Z){return w.enter("lineEnding"),w.consume(Z),w.exit("lineEnding"),R}function R(Z){return w.enter("codeFencedFence"),Ie(Z)?Pe(w,T,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(Z):T(Z)}function T(Z){return Z===a?(w.enter("codeFencedFenceSequence"),F(Z)):O(Z)}function F(Z){return Z===a?(B++,w.consume(Z),F):B>=o?(w.exit("codeFencedFenceSequence"),Ie(Z)?Pe(w,$,"whitespace")(Z):$(Z)):O(Z)}function $(Z){return Z===null||be(Z)?(w.exit("codeFencedFence"),S(Z)):O(Z)}}}function T0(e,t,n){const r=this;return i;function i(o){return o===null?n(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}const co={name:"codeIndented",tokenize:A0},I0={partial:!0,tokenize:z0};function A0(e,t,n){const r=this;return i;function i(u){return e.enter("codeIndented"),Pe(e,s,"linePrefix",5)(u)}function s(u){const d=r.events[r.events.length-1];return d&&d[1].type==="linePrefix"&&d[2].sliceSerialize(d[1],!0).length>=4?o(u):n(u)}function o(u){return u===null?c(u):be(u)?e.attempt(I0,o,c)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||be(u)?(e.exit("codeFlowValue"),o(u)):(e.consume(u),a)}function c(u){return e.exit("codeIndented"),t(u)}}function z0(e,t,n){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):be(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):Pe(e,s,"linePrefix",5)(o)}function s(o){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):be(o)?i(o):n(o)}}const O0={name:"codeText",previous:D0,resolve:P0,tokenize:R0};function P0(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function D0(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function R0(e,t,n){let r=0,i,s;return o;function o(f){return e.enter("codeText"),e.enter("codeTextSequence"),a(f)}function a(f){return f===96?(e.consume(f),r++,a):(e.exit("codeTextSequence"),c(f))}function c(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),c):f===96?(s=e.enter("codeTextSequence"),i=0,d(f)):be(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),c):(e.enter("codeTextData"),u(f))}function u(f){return f===null||f===32||f===96||be(f)?(e.exit("codeTextData"),c(f)):(e.consume(f),u)}function d(f){return f===96?(e.consume(f),i++,d):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(s.type="codeTextData",u(f))}}class $0{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Zr(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Zr(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Zr(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Zr(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Zr(this.left,n.reverse())}}}function Zr(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function $p(e){const t={};let n=-1,r,i,s,o,a,c,u;const d=new $0(e);for(;++n<d.length;){for(;n in t;)n=t[n];if(r=d.get(n),n&&r[1].type==="chunkFlow"&&d.get(n-1)[1].type==="listItemPrefix"&&(c=r[1]._tokenizer.events,s=0,s<c.length&&c[s][1].type==="lineEndingBlank"&&(s+=2),s<c.length&&c[s][1].type==="content"))for(;++s<c.length&&c[s][1].type!=="content";)c[s][1].type==="chunkText"&&(c[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,M0(d,n)),n=t[n],u=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(o=d.get(s),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(i&&(d.get(i)[1].type="lineEndingBlank"),o[1].type="lineEnding",i=s);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;i&&(r[1].end={...d.get(i)[1].start},a=d.slice(i,n),a.unshift(r),d.splice(i,n-i+1,a))}}return At(e,0,Number.POSITIVE_INFINITY,d.slice(0)),!u}function M0(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));const a=o.events,c=[],u={};let d,f,h=-1,p=n,m=0,v=0;const k=[v];for(;p;){for(;e.get(++i)[1]!==p;);s.push(i),p._tokenizer||(d=r.sliceStream(p),p.next||d.push(null),f&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(d),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),f=p,p=p.next}for(p=n;++h<a.length;)a[h][0]==="exit"&&a[h-1][0]==="enter"&&a[h][1].type===a[h-1][1].type&&a[h][1].start.line!==a[h][1].end.line&&(v=h+1,k.push(v),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):k.pop(),h=k.length;h--;){const y=a.slice(k[h],k[h+1]),_=s.pop();c.push([_,_+y.length-1]),e.splice(_,2,y)}for(c.reverse(),h=-1;++h<c.length;)u[m+c[h][0]]=m+c[h][1],m+=c[h][1]-c[h][0]-1;return u}const F0={resolve:B0,tokenize:Z0},L0={partial:!0,tokenize:V0};function B0(e){return $p(e),e}function Z0(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?s(a):be(a)?e.check(L0,o,s)(a):(e.consume(a),i)}function s(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function o(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function V0(e,t,n){const r=this;return i;function i(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),Pe(e,s,"linePrefix")}function s(o){if(o===null||be(o))return n(o);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):e.interrupt(r.parser.constructs.flow,n,t)(o)}}function Mp(e,t,n,r,i,s,o,a,c){const u=c||Number.POSITIVE_INFINITY;let d=0;return f;function f(y){return y===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(y),e.exit(s),h):y===null||y===32||y===41||ds(y)?n(y):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),v(y))}function h(y){return y===62?(e.enter(s),e.consume(y),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),p(y))}function p(y){return y===62?(e.exit("chunkString"),e.exit(a),h(y)):y===null||y===60||be(y)?n(y):(e.consume(y),y===92?m:p)}function m(y){return y===60||y===62||y===92?(e.consume(y),p):p(y)}function v(y){return!d&&(y===null||y===41||Ze(y))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(y)):d<u&&y===40?(e.consume(y),d++,v):y===41?(e.consume(y),d--,v):y===null||y===32||y===40||ds(y)?n(y):(e.consume(y),y===92?k:v)}function k(y){return y===40||y===41||y===92?(e.consume(y),v):v(y)}}function Fp(e,t,n,r,i,s){const o=this;let a=0,c;return u;function u(p){return e.enter(r),e.enter(i),e.consume(p),e.exit(i),e.enter(s),d}function d(p){return a>999||p===null||p===91||p===93&&!c||p===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(p):p===93?(e.exit(s),e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):be(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),d):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||be(p)||a++>999?(e.exit("chunkString"),d(p)):(e.consume(p),c||(c=!Ie(p)),p===92?h:f)}function h(p){return p===91||p===92||p===93?(e.consume(p),a++,f):f(p)}}function Lp(e,t,n,r,i,s){let o;return a;function a(h){return h===34||h===39||h===40?(e.enter(r),e.enter(i),e.consume(h),e.exit(i),o=h===40?41:h,c):n(h)}function c(h){return h===o?(e.enter(i),e.consume(h),e.exit(i),e.exit(r),t):(e.enter(s),u(h))}function u(h){return h===o?(e.exit(s),c(o)):h===null?n(h):be(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),Pe(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===o||h===null||be(h)?(e.exit("chunkString"),u(h)):(e.consume(h),h===92?f:d)}function f(h){return h===o||h===92?(e.consume(h),d):d(h)}}function ii(e,t){let n;return r;function r(i){return be(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):Ie(i)?Pe(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const U0={name:"definition",tokenize:H0},J0={partial:!0,tokenize:W0};function H0(e,t,n){const r=this;let i;return s;function s(p){return e.enter("definition"),o(p)}function o(p){return Fp.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Wt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),c):n(p)}function c(p){return Ze(p)?ii(e,u)(p):u(p)}function u(p){return Mp(e,d,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function d(p){return e.attempt(J0,f,f)(p)}function f(p){return Ie(p)?Pe(e,h,"whitespace")(p):h(p)}function h(p){return p===null||be(p)?(e.exit("definition"),r.parser.defined.push(i),t(p)):n(p)}}function W0(e,t,n){return r;function r(a){return Ze(a)?ii(e,i)(a):n(a)}function i(a){return Lp(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return Ie(a)?Pe(e,o,"whitespace")(a):o(a)}function o(a){return a===null||be(a)?t(a):n(a)}}const q0={name:"hardBreakEscape",tokenize:G0};function G0(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return be(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const K0={name:"headingAtx",resolve:Y0,tokenize:X0};function Y0(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},At(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function X0(e,t,n){let r=0;return i;function i(d){return e.enter("atxHeading"),s(d)}function s(d){return e.enter("atxHeadingSequence"),o(d)}function o(d){return d===35&&r++<6?(e.consume(d),o):d===null||Ze(d)?(e.exit("atxHeadingSequence"),a(d)):n(d)}function a(d){return d===35?(e.enter("atxHeadingSequence"),c(d)):d===null||be(d)?(e.exit("atxHeading"),t(d)):Ie(d)?Pe(e,a,"whitespace")(d):(e.enter("atxHeadingText"),u(d))}function c(d){return d===35?(e.consume(d),c):(e.exit("atxHeadingSequence"),a(d))}function u(d){return d===null||d===35||Ze(d)?(e.exit("atxHeadingText"),a(d)):(e.consume(d),u)}}const Q0=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],Ec=["pre","script","style","textarea"],ek={concrete:!0,name:"htmlFlow",resolveTo:rk,tokenize:ik},tk={partial:!0,tokenize:ok},nk={partial:!0,tokenize:sk};function rk(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function ik(e,t,n){const r=this;let i,s,o,a,c;return u;function u(b){return d(b)}function d(b){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(b),f}function f(b){return b===33?(e.consume(b),h):b===47?(e.consume(b),s=!0,v):b===63?(e.consume(b),i=3,r.interrupt?t:j):xt(b)?(e.consume(b),o=String.fromCharCode(b),k):n(b)}function h(b){return b===45?(e.consume(b),i=2,p):b===91?(e.consume(b),i=5,a=0,m):xt(b)?(e.consume(b),i=4,r.interrupt?t:j):n(b)}function p(b){return b===45?(e.consume(b),r.interrupt?t:j):n(b)}function m(b){const G="CDATA[";return b===G.charCodeAt(a++)?(e.consume(b),a===G.length?r.interrupt?t:T:m):n(b)}function v(b){return xt(b)?(e.consume(b),o=String.fromCharCode(b),k):n(b)}function k(b){if(b===null||b===47||b===62||Ze(b)){const G=b===47,ne=o.toLowerCase();return!G&&!s&&Ec.includes(ne)?(i=1,r.interrupt?t(b):T(b)):Q0.includes(o.toLowerCase())?(i=6,G?(e.consume(b),y):r.interrupt?t(b):T(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):s?_(b):x(b))}return b===45||ut(b)?(e.consume(b),o+=String.fromCharCode(b),k):n(b)}function y(b){return b===62?(e.consume(b),r.interrupt?t:T):n(b)}function _(b){return Ie(b)?(e.consume(b),_):N(b)}function x(b){return b===47?(e.consume(b),N):b===58||b===95||xt(b)?(e.consume(b),A):Ie(b)?(e.consume(b),x):N(b)}function A(b){return b===45||b===46||b===58||b===95||ut(b)?(e.consume(b),A):E(b)}function E(b){return b===61?(e.consume(b),w):Ie(b)?(e.consume(b),E):x(b)}function w(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(e.consume(b),c=b,S):Ie(b)?(e.consume(b),w):O(b)}function S(b){return b===c?(e.consume(b),c=null,B):b===null||be(b)?n(b):(e.consume(b),S)}function O(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||Ze(b)?E(b):(e.consume(b),O)}function B(b){return b===47||b===62||Ie(b)?x(b):n(b)}function N(b){return b===62?(e.consume(b),R):n(b)}function R(b){return b===null||be(b)?T(b):Ie(b)?(e.consume(b),R):n(b)}function T(b){return b===45&&i===2?(e.consume(b),P):b===60&&i===1?(e.consume(b),J):b===62&&i===4?(e.consume(b),ye):b===63&&i===3?(e.consume(b),j):b===93&&i===5?(e.consume(b),X):be(b)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(tk,ce,F)(b)):b===null||be(b)?(e.exit("htmlFlowData"),F(b)):(e.consume(b),T)}function F(b){return e.check(nk,$,ce)(b)}function $(b){return e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),Z}function Z(b){return b===null||be(b)?F(b):(e.enter("htmlFlowData"),T(b))}function P(b){return b===45?(e.consume(b),j):T(b)}function J(b){return b===47?(e.consume(b),o="",V):T(b)}function V(b){if(b===62){const G=o.toLowerCase();return Ec.includes(G)?(e.consume(b),ye):T(b)}return xt(b)&&o.length<8?(e.consume(b),o+=String.fromCharCode(b),V):T(b)}function X(b){return b===93?(e.consume(b),j):T(b)}function j(b){return b===62?(e.consume(b),ye):b===45&&i===2?(e.consume(b),j):T(b)}function ye(b){return b===null||be(b)?(e.exit("htmlFlowData"),ce(b)):(e.consume(b),ye)}function ce(b){return e.exit("htmlFlow"),t(b)}}function sk(e,t,n){const r=this;return i;function i(o){return be(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s):n(o)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}function ok(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(Ti,t,n)}}const ak={name:"htmlText",tokenize:lk};function lk(e,t,n){const r=this;let i,s,o;return a;function a(j){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(j),c}function c(j){return j===33?(e.consume(j),u):j===47?(e.consume(j),E):j===63?(e.consume(j),x):xt(j)?(e.consume(j),O):n(j)}function u(j){return j===45?(e.consume(j),d):j===91?(e.consume(j),s=0,m):xt(j)?(e.consume(j),_):n(j)}function d(j){return j===45?(e.consume(j),p):n(j)}function f(j){return j===null?n(j):j===45?(e.consume(j),h):be(j)?(o=f,J(j)):(e.consume(j),f)}function h(j){return j===45?(e.consume(j),p):f(j)}function p(j){return j===62?P(j):j===45?h(j):f(j)}function m(j){const ye="CDATA[";return j===ye.charCodeAt(s++)?(e.consume(j),s===ye.length?v:m):n(j)}function v(j){return j===null?n(j):j===93?(e.consume(j),k):be(j)?(o=v,J(j)):(e.consume(j),v)}function k(j){return j===93?(e.consume(j),y):v(j)}function y(j){return j===62?P(j):j===93?(e.consume(j),y):v(j)}function _(j){return j===null||j===62?P(j):be(j)?(o=_,J(j)):(e.consume(j),_)}function x(j){return j===null?n(j):j===63?(e.consume(j),A):be(j)?(o=x,J(j)):(e.consume(j),x)}function A(j){return j===62?P(j):x(j)}function E(j){return xt(j)?(e.consume(j),w):n(j)}function w(j){return j===45||ut(j)?(e.consume(j),w):S(j)}function S(j){return be(j)?(o=S,J(j)):Ie(j)?(e.consume(j),S):P(j)}function O(j){return j===45||ut(j)?(e.consume(j),O):j===47||j===62||Ze(j)?B(j):n(j)}function B(j){return j===47?(e.consume(j),P):j===58||j===95||xt(j)?(e.consume(j),N):be(j)?(o=B,J(j)):Ie(j)?(e.consume(j),B):P(j)}function N(j){return j===45||j===46||j===58||j===95||ut(j)?(e.consume(j),N):R(j)}function R(j){return j===61?(e.consume(j),T):be(j)?(o=R,J(j)):Ie(j)?(e.consume(j),R):B(j)}function T(j){return j===null||j===60||j===61||j===62||j===96?n(j):j===34||j===39?(e.consume(j),i=j,F):be(j)?(o=T,J(j)):Ie(j)?(e.consume(j),T):(e.consume(j),$)}function F(j){return j===i?(e.consume(j),i=void 0,Z):j===null?n(j):be(j)?(o=F,J(j)):(e.consume(j),F)}function $(j){return j===null||j===34||j===39||j===60||j===61||j===96?n(j):j===47||j===62||Ze(j)?B(j):(e.consume(j),$)}function Z(j){return j===47||j===62||Ze(j)?B(j):n(j)}function P(j){return j===62?(e.consume(j),e.exit("htmlTextData"),e.exit("htmlText"),t):n(j)}function J(j){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(j),e.exit("lineEnding"),V}function V(j){return Ie(j)?Pe(e,X,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(j):X(j)}function X(j){return e.enter("htmlTextData"),o(j)}}const Ga={name:"labelEnd",resolveAll:fk,resolveTo:pk,tokenize:hk},ck={tokenize:mk},uk={tokenize:gk},dk={tokenize:xk};function fk(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&At(e,0,e.length,n),e}function pk(e,t){let n=e.length,r=0,i,s,o,a;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(o){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(o=n);const c={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[s][1].start},end:{...e[o][1].end}},d={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[o-2][1].start}};return a=[["enter",c,t],["enter",u,t]],a=Mt(a,e.slice(s+1,s+r+3)),a=Mt(a,[["enter",d,t]]),a=Mt(a,Fs(t.parser.constructs.insideSpan.null,e.slice(s+r+4,o-3),t)),a=Mt(a,[["exit",d,t],e[o-2],e[o-1],["exit",u,t]]),a=Mt(a,e.slice(o+1)),a=Mt(a,[["exit",c,t]]),At(e,s,e.length,a),e}function hk(e,t,n){const r=this;let i=r.events.length,s,o;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return a;function a(h){return s?s._inactive?f(h):(o=r.parser.defined.includes(Wt(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(h),e.exit("labelMarker"),e.exit("labelEnd"),c):n(h)}function c(h){return h===40?e.attempt(ck,d,o?d:f)(h):h===91?e.attempt(uk,d,o?u:f)(h):o?d(h):f(h)}function u(h){return e.attempt(dk,d,f)(h)}function d(h){return t(h)}function f(h){return s._balanced=!0,n(h)}}function mk(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),i}function i(f){return Ze(f)?ii(e,s)(f):s(f)}function s(f){return f===41?d(f):Mp(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function o(f){return Ze(f)?ii(e,c)(f):d(f)}function a(f){return n(f)}function c(f){return f===34||f===39||f===40?Lp(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):d(f)}function u(f){return Ze(f)?ii(e,d)(f):d(f)}function d(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function gk(e,t,n){const r=this;return i;function i(a){return Fp.call(r,e,s,o,"reference","referenceMarker","referenceString")(a)}function s(a){return r.parser.defined.includes(Wt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function xk(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const yk={name:"labelStartImage",resolveAll:Ga.resolveAll,tokenize:bk};function bk(e,t,n){const r=this;return i;function i(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),s}function s(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),o):n(a)}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const vk={name:"labelStartLink",resolveAll:Ga.resolveAll,tokenize:wk};function wk(e,t,n){const r=this;return i;function i(o){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelLink"),s}function s(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const uo={name:"lineEnding",tokenize:kk};function kk(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),Pe(e,t,"linePrefix")}}const Gi={name:"thematicBreak",tokenize:Sk};function Sk(e,t,n){let r=0,i;return s;function s(u){return e.enter("thematicBreak"),o(u)}function o(u){return i=u,a(u)}function a(u){return u===i?(e.enter("thematicBreakSequence"),c(u)):r>=3&&(u===null||be(u))?(e.exit("thematicBreak"),t(u)):n(u)}function c(u){return u===i?(e.consume(u),r++,c):(e.exit("thematicBreakSequence"),Ie(u)?Pe(e,a,"whitespace")(u):a(u))}}const vt={continuation:{tokenize:Ck},exit:Tk,name:"list",tokenize:Nk},jk={partial:!0,tokenize:Ik},_k={partial:!0,tokenize:Ek};function Nk(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,o=0;return a;function a(p){const m=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(m==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:Xo(p)){if(r.containerState.type||(r.containerState.type=m,e.enter(m,{_container:!0})),m==="listUnordered")return e.enter("listItemPrefix"),p===42||p===45?e.check(Gi,n,u)(p):u(p);if(!r.interrupt||p===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),c(p)}return n(p)}function c(p){return Xo(p)&&++o<10?(e.consume(p),c):(!r.interrupt||o<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(e.exit("listItemValue"),u(p)):n(p)}function u(p){return e.enter("listItemMarker"),e.consume(p),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,e.check(Ti,r.interrupt?n:d,e.attempt(jk,h,f))}function d(p){return r.containerState.initialBlankLine=!0,s++,h(p)}function f(p){return Ie(p)?(e.enter("listItemPrefixWhitespace"),e.consume(p),e.exit("listItemPrefixWhitespace"),h):n(p)}function h(p){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(p)}}function Ck(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(Ti,i,s);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Pe(e,t,"listItemIndent",r.containerState.size+1)(a)}function s(a){return r.containerState.furtherBlankLines||!Ie(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(_k,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,Pe(e,e.attempt(vt,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function Ek(e,t,n){const r=this;return Pe(e,i,"listItemIndent",r.containerState.size+1);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="listItemIndent"&&o[2].sliceSerialize(o[1],!0).length===r.containerState.size?t(s):n(s)}}function Tk(e){e.exit(this.containerState.type)}function Ik(e,t,n){const r=this;return Pe(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const o=r.events[r.events.length-1];return!Ie(s)&&o&&o[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const Tc={name:"setextUnderline",resolveTo:Ak,tokenize:zk};function Ak(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const o={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",o,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=o,e.push(["exit",o,t]),e}function zk(e,t,n){const r=this;let i;return s;function s(u){let d=r.events.length,f;for(;d--;)if(r.events[d][1].type!=="lineEnding"&&r.events[d][1].type!=="linePrefix"&&r.events[d][1].type!=="content"){f=r.events[d][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),i=u,o(u)):n(u)}function o(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===i?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),Ie(u)?Pe(e,c,"lineSuffix")(u):c(u))}function c(u){return u===null||be(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const Ok={tokenize:Pk};function Pk(e){const t=this,n=e.attempt(Ti,r,e.attempt(this.parser.constructs.flowInitial,i,Pe(e,e.attempt(this.parser.constructs.flow,i,e.attempt(F0,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const Dk={resolveAll:Zp()},Rk=Bp("string"),$k=Bp("text");function Bp(e){return{resolveAll:Zp(e==="text"?Mk:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,o,a);return o;function o(d){return u(d)?s(d):a(d)}function a(d){if(d===null){n.consume(d);return}return n.enter("data"),n.consume(d),c}function c(d){return u(d)?(n.exit("data"),s(d)):(n.consume(d),c)}function u(d){if(d===null)return!0;const f=i[d];let h=-1;if(f)for(;++h<f.length;){const p=f[h];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function Zp(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function Mk(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,o=-1,a=0,c;for(;s--;){const u=i[s];if(typeof u=="string"){for(o=u.length;u.charCodeAt(o-1)===32;)a++,o--;if(o)break;o=-1}else if(u===-2)c=!0,a++;else if(u!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={type:n===e.length||c||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?o:r.start._bufferIndex+o,_index:r.start._index+s,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const Fk={42:vt,43:vt,45:vt,48:vt,49:vt,50:vt,51:vt,52:vt,53:vt,54:vt,55:vt,56:vt,57:vt,62:Pp},Lk={91:U0},Bk={[-2]:co,[-1]:co,32:co},Zk={35:K0,42:Gi,45:[Tc,Gi],60:ek,61:Tc,95:Gi,96:Cc,126:Cc},Vk={38:Rp,92:Dp},Uk={[-5]:uo,[-4]:uo,[-3]:uo,33:yk,38:Rp,42:Qo,60:[v0,ak],91:vk,92:[q0,Dp],93:Ga,95:Qo,96:O0},Jk={null:[Qo,Dk]},Hk={null:[42,95]},Wk={null:[]},qk=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:Hk,contentInitial:Lk,disable:Wk,document:Fk,flow:Zk,flowInitial:Bk,insideSpan:Jk,string:Vk,text:Uk},Symbol.toStringTag,{value:"Module"}));function Gk(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let o=[],a=[];const c={attempt:S(E),check:S(w),consume:_,enter:x,exit:A,interrupt:S(w,{interrupt:!0})},u={code:null,containerState:{},defineSkip:v,events:[],now:m,parser:e,previous:null,sliceSerialize:h,sliceStream:p,write:f};let d=t.tokenize.call(u,c);return t.resolveAll&&s.push(t),u;function f(R){return o=Mt(o,R),k(),o[o.length-1]!==null?[]:(O(t,0),u.events=Fs(s,u.events,u),u.events)}function h(R,T){return Yk(p(R),T)}function p(R){return Kk(o,R)}function m(){const{_bufferIndex:R,_index:T,line:F,column:$,offset:Z}=r;return{_bufferIndex:R,_index:T,line:F,column:$,offset:Z}}function v(R){i[R.line]=R.column,N()}function k(){let R;for(;r._index<o.length;){const T=o[r._index];if(typeof T=="string")for(R=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===R&&r._bufferIndex<T.length;)y(T.charCodeAt(r._bufferIndex));else y(T)}}function y(R){d=d(R)}function _(R){be(R)?(r.line++,r.column=1,r.offset+=R===-3?2:1,N()):R!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=R}function x(R,T){const F=T||{};return F.type=R,F.start=m(),u.events.push(["enter",F,u]),a.push(F),F}function A(R){const T=a.pop();return T.end=m(),u.events.push(["exit",T,u]),T}function E(R,T){O(R,T.from)}function w(R,T){T.restore()}function S(R,T){return F;function F($,Z,P){let J,V,X,j;return Array.isArray($)?ce($):"tokenize"in $?ce([$]):ye($);function ye(Q){return oe;function oe(I){const re=I!==null&&Q[I],ae=I!==null&&Q.null,H=[...Array.isArray(re)?re:re?[re]:[],...Array.isArray(ae)?ae:ae?[ae]:[]];return ce(H)(I)}}function ce(Q){return J=Q,V=0,Q.length===0?P:b(Q[V])}function b(Q){return oe;function oe(I){return j=B(),X=Q,Q.partial||(u.currentConstruct=Q),Q.name&&u.parser.constructs.disable.null.includes(Q.name)?ne():Q.tokenize.call(T?Object.assign(Object.create(u),T):u,c,G,ne)(I)}}function G(Q){return R(X,j),Z}function ne(Q){return j.restore(),++V<J.length?b(J[V]):P}}}function O(R,T){R.resolveAll&&!s.includes(R)&&s.push(R),R.resolve&&At(u.events,T,u.events.length-T,R.resolve(u.events.slice(T),u)),R.resolveTo&&(u.events=R.resolveTo(u.events,u))}function B(){const R=m(),T=u.previous,F=u.currentConstruct,$=u.events.length,Z=Array.from(a);return{from:$,restore:P};function P(){r=R,u.previous=T,u.currentConstruct=F,u.events.length=$,a=Z,N()}}function N(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function Kk(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let o;if(n===i)o=[e[n].slice(r,s)];else{if(o=e.slice(n,i),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}s>0&&o.push(e[i].slice(0,s))}return o}function Yk(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let o;if(typeof s=="string")o=s;else switch(s){case-5:{o="\r";break}case-4:{o=`
150
150
  `;break}case-3:{o=`\r
151
151
  `;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&i)continue;o=" ";break}default:o=String.fromCharCode(s)}i=s===-2,r.push(o)}return r.join("")}function Xk(e){const r={constructs:zp([qk,...(e||{}).extensions||[]]),content:i(p0),defined:[],document:i(m0),flow:i(Ok),lazy:{},string:i(Rk),text:i($k)};return r;function i(s){return o;function o(a){return Gk(r,s,a)}}}function Qk(e){for(;!$p(e););return e}const Ic=/[\0\t\n\r]/g;function eS(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const c=[];let u,d,f,h,p;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(o||void 0).decode(s)),f=0,t="",n&&(s.charCodeAt(0)===65279&&f++,n=void 0);f<s.length;){if(Ic.lastIndex=f,u=Ic.exec(s),h=u&&u.index!==void 0?u.index:s.length,p=s.charCodeAt(h),!u){t=s.slice(f);break}if(p===10&&f===h&&r)c.push(-3),r=void 0;else switch(r&&(c.push(-5),r=void 0),f<h&&(c.push(s.slice(f,h)),e+=h-f),p){case 0:{c.push(65533),e++;break}case 9:{for(d=Math.ceil(e/4)*4,c.push(-2);e++<d;)c.push(-1);break}case 10:{c.push(-4),e=1;break}default:r=!0,e=1}f=h+1}return a&&(r&&c.push(-5),t&&c.push(t),c.push(null)),c}}const tS=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function nS(e){return e.replace(tS,rS)}function rS(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Op(n.slice(s?2:1),s?16:10)}return qa(n)||e}const Vp={}.hasOwnProperty;function iS(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),sS(n)(Qk(Xk(n).document().write(eS()(e,t,!0))))}function sS(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(z),autolinkProtocol:B,autolinkEmail:B,atxHeading:s(Re),blockQuote:s(ae),characterEscape:B,characterReference:B,codeFenced:s(H),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(H,o),codeText:s(K,o),codeTextData:B,data:B,codeFlowValue:B,definition:s(pe),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(fe),hardBreakEscape:s(Oe),hardBreakTrailing:s(Oe),htmlFlow:s($e,o),htmlFlowData:B,htmlText:s($e,o),htmlTextData:B,image:s(C),label:o,link:s(z),listItem:s(se),listItemValue:h,listOrdered:s(L,f),listUnordered:s(L),paragraph:s(ie),reference:b,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Re),strong:s(ee),thematicBreak:s(we)},exit:{atxHeading:c(),atxHeadingSequence:E,autolink:c(),autolinkEmail:re,autolinkProtocol:I,blockQuote:c(),characterEscapeValue:N,characterReferenceMarkerHexadecimal:ne,characterReferenceMarkerNumeric:ne,characterReferenceValue:Q,characterReference:oe,codeFenced:c(k),codeFencedFence:v,codeFencedFenceInfo:p,codeFencedFenceMeta:m,codeFlowValue:N,codeIndented:c(y),codeText:c(Z),codeTextData:N,data:N,definition:c(),definitionDestinationString:A,definitionLabelString:_,definitionTitleString:x,emphasis:c(),hardBreakEscape:c(T),hardBreakTrailing:c(T),htmlFlow:c(F),htmlFlowData:N,htmlText:c($),htmlTextData:N,image:c(J),label:X,labelText:V,lineEnding:R,link:c(P),listItem:c(),listOrdered:c(),listUnordered:c(),paragraph:c(),referenceString:G,resourceDestinationString:j,resourceTitleString:ye,resource:ce,setextHeading:c(O),setextHeadingLineSequence:S,setextHeadingText:w,strong:c(),thematicBreak:c()}};Up(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(U){let Y={type:"root",children:[]};const ge={stack:[Y],tokenStack:[],config:t,enter:a,exit:u,buffer:o,resume:d,data:n},_e=[];let M=-1;for(;++M<U.length;)if(U[M][1].type==="listOrdered"||U[M][1].type==="listUnordered")if(U[M][0]==="enter")_e.push(M);else{const D=_e.pop();M=i(U,D,M)}for(M=-1;++M<U.length;){const D=t[U[M][0]];Vp.call(D,U[M][1].type)&&D[U[M][1].type].call(Object.assign({sliceSerialize:U[M][2].sliceSerialize},ge),U[M][1])}if(ge.tokenStack.length>0){const D=ge.tokenStack[ge.tokenStack.length-1];(D[1]||Ac).call(ge,void 0,D[0])}for(Y.position={start:pn(U.length>0?U[0][1].start:{line:1,column:1,offset:0}),end:pn(U.length>0?U[U.length-2][1].end:{line:1,column:1,offset:0})},M=-1;++M<t.transforms.length;)Y=t.transforms[M](Y)||Y;return Y}function i(U,Y,ge){let _e=Y-1,M=-1,D=!1,xe,de,Me,Je;for(;++_e<=ge;){const it=U[_e];switch(it[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{it[0]==="enter"?M++:M--,Je=void 0;break}case"lineEndingBlank":{it[0]==="enter"&&(xe&&!Je&&!M&&!Me&&(Me=_e),Je=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Je=void 0}if(!M&&it[0]==="enter"&&it[1].type==="listItemPrefix"||M===-1&&it[0]==="exit"&&(it[1].type==="listUnordered"||it[1].type==="listOrdered")){if(xe){let Lt=_e;for(de=void 0;Lt--;){const Ot=U[Lt];if(Ot[1].type==="lineEnding"||Ot[1].type==="lineEndingBlank"){if(Ot[0]==="exit")continue;de&&(U[de][1].type="lineEndingBlank",D=!0),Ot[1].type="lineEnding",de=Lt}else if(!(Ot[1].type==="linePrefix"||Ot[1].type==="blockQuotePrefix"||Ot[1].type==="blockQuotePrefixWhitespace"||Ot[1].type==="blockQuoteMarker"||Ot[1].type==="listItemIndent"))break}Me&&(!de||Me<de)&&(xe._spread=!0),xe.end=Object.assign({},de?U[de][1].start:it[1].end),U.splice(de||_e,0,["exit",xe,it[2]]),_e++,ge++}if(it[1].type==="listItemPrefix"){const Lt={type:"listItem",_spread:!1,start:Object.assign({},it[1].start),end:void 0};xe=Lt,U.splice(_e,0,["enter",Lt,it[2]]),_e++,ge++,Me=void 0,Je=!0}}}return U[Y][1]._spread=D,ge}function s(U,Y){return ge;function ge(_e){a.call(this,U(_e),_e),Y&&Y.call(this,_e)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(U,Y,ge){this.stack[this.stack.length-1].children.push(U),this.stack.push(U),this.tokenStack.push([Y,ge||void 0]),U.position={start:pn(Y.start),end:void 0}}function c(U){return Y;function Y(ge){U&&U.call(this,ge),u.call(this,ge)}}function u(U,Y){const ge=this.stack.pop(),_e=this.tokenStack.pop();if(_e)_e[0].type!==U.type&&(Y?Y.call(this,U,_e[0]):(_e[1]||Ac).call(this,U,_e[0]));else throw new Error("Cannot close `"+U.type+"` ("+ri({start:U.start,end:U.end})+"): it’s not open");ge.position.end=pn(U.end)}function d(){return Wa(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function h(U){if(this.data.expectingFirstListItemValue){const Y=this.stack[this.stack.length-2];Y.start=Number.parseInt(this.sliceSerialize(U),10),this.data.expectingFirstListItemValue=void 0}}function p(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.lang=U}function m(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.meta=U}function v(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function k(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function y(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U.replace(/(\r?\n|\r)$/g,"")}function _(U){const Y=this.resume(),ge=this.stack[this.stack.length-1];ge.label=Y,ge.identifier=Wt(this.sliceSerialize(U)).toLowerCase()}function x(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.title=U}function A(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.url=U}function E(U){const Y=this.stack[this.stack.length-1];if(!Y.depth){const ge=this.sliceSerialize(U).length;Y.depth=ge}}function w(){this.data.setextHeadingSlurpLineEnding=!0}function S(U){const Y=this.stack[this.stack.length-1];Y.depth=this.sliceSerialize(U).codePointAt(0)===61?1:2}function O(){this.data.setextHeadingSlurpLineEnding=void 0}function B(U){const ge=this.stack[this.stack.length-1].children;let _e=ge[ge.length-1];(!_e||_e.type!=="text")&&(_e=me(),_e.position={start:pn(U.start),end:void 0},ge.push(_e)),this.stack.push(_e)}function N(U){const Y=this.stack.pop();Y.value+=this.sliceSerialize(U),Y.position.end=pn(U.end)}function R(U){const Y=this.stack[this.stack.length-1];if(this.data.atHardBreak){const ge=Y.children[Y.children.length-1];ge.position.end=pn(U.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(Y.type)&&(B.call(this,U),N.call(this,U))}function T(){this.data.atHardBreak=!0}function F(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U}function $(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U}function Z(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U}function P(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Y=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Y,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function J(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Y=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Y,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function V(U){const Y=this.sliceSerialize(U),ge=this.stack[this.stack.length-2];ge.label=nS(Y),ge.identifier=Wt(Y).toLowerCase()}function X(){const U=this.stack[this.stack.length-1],Y=this.resume(),ge=this.stack[this.stack.length-1];if(this.data.inReference=!0,ge.type==="link"){const _e=U.children;ge.children=_e}else ge.alt=Y}function j(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.url=U}function ye(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.title=U}function ce(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function G(U){const Y=this.resume(),ge=this.stack[this.stack.length-1];ge.label=Y,ge.identifier=Wt(this.sliceSerialize(U)).toLowerCase(),this.data.referenceType="full"}function ne(U){this.data.characterReferenceType=U.type}function Q(U){const Y=this.sliceSerialize(U),ge=this.data.characterReferenceType;let _e;ge?(_e=Op(Y,ge==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):_e=qa(Y);const M=this.stack[this.stack.length-1];M.value+=_e}function oe(U){const Y=this.stack.pop();Y.position.end=pn(U.end)}function I(U){N.call(this,U);const Y=this.stack[this.stack.length-1];Y.url=this.sliceSerialize(U)}function re(U){N.call(this,U);const Y=this.stack[this.stack.length-1];Y.url="mailto:"+this.sliceSerialize(U)}function ae(){return{type:"blockquote",children:[]}}function H(){return{type:"code",lang:null,meta:null,value:""}}function K(){return{type:"inlineCode",value:""}}function pe(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function fe(){return{type:"emphasis",children:[]}}function Re(){return{type:"heading",depth:0,children:[]}}function Oe(){return{type:"break"}}function $e(){return{type:"html",value:""}}function C(){return{type:"image",title:null,url:"",alt:null}}function z(){return{type:"link",title:null,url:"",children:[]}}function L(U){return{type:"list",ordered:U.type==="listOrdered",start:null,spread:U._spread,children:[]}}function se(U){return{type:"listItem",spread:U._spread,checked:null,children:[]}}function ie(){return{type:"paragraph",children:[]}}function ee(){return{type:"strong",children:[]}}function me(){return{type:"text",value:""}}function we(){return{type:"thematicBreak"}}}function pn(e){return{line:e.line,column:e.column,offset:e.offset}}function Up(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Up(e,r):oS(e,r)}}function oS(e,t){let n;for(n in t)if(Vp.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function Ac(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+ri({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+ri({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+ri({start:t.start,end:t.end})+") is still open")}function aS(e){const t=this;t.parser=n;function n(r){return iS(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function lS(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function cS(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
@@ -242,4 +242,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
242
242
  `;)t++;return!0}return!1}function u(V){if(d(V)){if(Vu(e[t]))for(;t<e.length&&Uu(e[t]);)t++;return o(),!0}return!1}function d(V){a(!0);for(const X of V){const j=t+X.length;if(e.slice(t,j)===X)return t=j,!0}return!1}function f(V){return e[t]===V?(n+=e[t],t++,!0):!1}function h(V){return e[t]===V?(t++,!0):!1}function p(){return h("\\")}function m(){return o(),e[t]==="."&&e[t+1]==="."&&e[t+2]==="."?(t+=3,o(),h(","),!0):!1}function v(){if(e[t]==="{"){n+="{",t++,o(),h(",")&&o();let V=!0;for(;t<e.length&&e[t]!=="}";){let X;if(V?(X=!0,V=!1):(X=f(","),X||(n=Vt(n,",")),o()),m(),!(_()||S(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=Ur(n,","):Z();break}o();const ye=f(":"),ce=t>=e.length;ye||(qu(e[t])||ce?n=Vt(n,":"):P()),s()||(ye||ce?n+="null":P())}return e[t]==="}"?(n+="}",t++):n=Vt(n,"}"),!0}return!1}function k(){if(e[t]==="["){n+="[",t++,o(),h(",")&&o();let V=!0;for(;t<e.length&&e[t]!=="]";)if(V?V=!1:f(",")||(n=Vt(n,",")),m(),!s()){n=Ur(n,",");break}return e[t]==="]"?(n+="]",t++):n=Vt(n,"]"),!0}return!1}function y(){let V=!0,X=!0;for(;X;)V?V=!1:f(",")||(n=Vt(n,",")),X=s();X||(n=Ur(n,",")),n=`[
243
243
  ${n}
244
244
  ]`}function _(){let V=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1,X=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1,j=e[t]==="\\";if(j&&(t++,j=!0),Xi(e[t])){const ye=Gu(e[t])?Gu:Ku(e[t])?Ku:ma(e[t])?ma:sg,ce=t,b=n.length;let G='"';for(t++;;){if(t>=e.length){const ne=B(t-1);return!V&&Ji(e.charAt(ne))?(t=ce,n=n.substring(0,b),_(!0)):(G=Vt(G,'"'),n+=G,!0)}if(t===X)return G=Vt(G,'"'),n+=G,!0;if(ye(e[t])){const ne=t,Q=G.length;if(G+='"',t++,n+=G,o(!1),V||t>=e.length||Ji(e[t])||Xi(e[t])||An(e[t]))return x(),!0;const oe=B(ne-1),I=e.charAt(oe);if(I===",")return t=ce,n=n.substring(0,b),_(!1,oe);if(Ji(I))return t=ce,n=n.substring(0,b),_(!0);n=n.substring(0,b),t=ne+1,G=`${G.substring(0,Q)}\\${G.substring(Q)}`}else if(V&&Wu(e[t])){if(e[t-1]===":"&&Ju.test(e.substring(ce+1,t+2)))for(;t<e.length&&Hu.test(e[t]);)G+=e[t],t++;return G=Vt(G,'"'),n+=G,x(),!0}else if(e[t]==="\\"){const ne=e.charAt(t+1);if(Hz[ne]!==void 0)G+=e.slice(t,t+2),t+=2;else if(ne==="u"){let oe=2;for(;oe<6&&$z(e[t+oe]);)oe++;oe===6?(G+=e.slice(t,t+6),t+=6):t+oe>=e.length?t=e.length:J()}else G+=ne,t+=2}else{const ne=e.charAt(t);ne==='"'&&e[t-1]!=="\\"?(G+=`\\${ne}`,t++):Lz(ne)?(G+=Jz[ne],t++):(Mz(ne)||T(ne),G+=ne,t++)}j&&p()}}return!1}function x(){let V=!1;for(o();e[t]==="+";){V=!0,t++,o(),n=Ur(n,'"',!0);const X=n.length;_()?n=Vz(n,X,1):n=Vt(n,'"')}return V}function A(){const V=t;if(e[t]==="-"){if(t++,N())return R(V),!0;if(!An(e[t]))return t=V,!1}for(;An(e[t]);)t++;if(e[t]==="."){if(t++,N())return R(V),!0;if(!An(e[t]))return t=V,!1;for(;An(e[t]);)t++}if(e[t]==="e"||e[t]==="E"){if(t++,(e[t]==="-"||e[t]==="+")&&t++,N())return R(V),!0;if(!An(e[t]))return t=V,!1;for(;An(e[t]);)t++}if(!N())return t=V,!1;if(t>V){const X=e.slice(V,t),j=/^0\d/.test(X);return n+=j?`"${X}"`:X,!0}return!1}function E(){return w("true","true")||w("false","false")||w("null","null")||w("True","true")||w("False","false")||w("None","null")}function w(V,X){return e.slice(t,t+V.length)===V?(n+=X,t+=V.length,!0):!1}function S(V){const X=t;if(Vu(e[t])){for(;t<e.length&&Uu(e[t]);)t++;let j=t;for(;zn(e,j);)j++;if(e[j]==="(")return t=j+1,s(),e[t]===")"&&(t++,e[t]===";"&&t++),!0}for(;t<e.length&&!Wu(e[t])&&!Xi(e[t])&&(!V||e[t]!==":");)t++;if(e[t-1]===":"&&Ju.test(e.substring(X,t+2)))for(;t<e.length&&Hu.test(e[t]);)t++;if(t>X){for(;zn(e,t-1)&&t>0;)t--;const j=e.slice(X,t);return n+=j==="undefined"?"null":JSON.stringify(j),e[t]==='"'&&t++,!0}}function O(){if(e[t]==="/"){const V=t;for(t++;t<e.length&&(e[t]!=="/"||e[t-1]==="\\");)t++;return t++,n+=JSON.stringify(e.substring(V,t)),!0}}function B(V){let X=V;for(;X>0&&zn(e,X);)X--;return X}function N(){return t>=e.length||Ji(e[t])||zn(e,t)}function R(V){n+=`${e.slice(V,t)}0`}function T(V){throw new Qn(`Invalid character ${JSON.stringify(V)}`,t)}function F(){throw new Qn(`Unexpected character ${JSON.stringify(e[t])}`,t)}function $(){throw new Qn("Unexpected end of json string",e.length)}function Z(){throw new Qn("Object key expected",t)}function P(){throw new Qn("Colon expected",t)}function J(){const V=e.slice(t,t+6);throw new Qn(`Invalid unicode character "${V}"`,t)}}function Wz(e,t){return e[t]==="*"&&e[t+1]==="/"}function qz({json:e,context:t,scope:n}){const[r,i]=g.useState(!1),[s,o]=g.useState(null),a=g.useMemo(()=>{try{return JSON.parse(e),e}catch{}try{return Yu(e)}catch{}const y=`{${e}}`;try{return JSON.parse(y),y}catch{}try{return Yu(y)}catch{return null}},[e]),c=g.useMemo(()=>Xm(a||e),[a,e]),u=ke(y=>y.activeTab),d=ke(y=>y.documents),f=ke(y=>(y.acceptedApplyIds||[]).includes(c)),h=ke(y=>y.setPendingDiff),p=ke(y=>y.createDocument),m=ke(y=>y.openDocument),v=g.useCallback(()=>{if(a){o(null);try{if(u){const y=d.find(w=>w.name===u),_=(y==null?void 0:y.text)||"";if(n==="blocks")try{const w=Ym(JSON.parse(_),JSON.parse(a));if(w){const S=JSON.stringify(w,null,2);h(u,_,S,c);return}}catch{}const x=t==null?void 0:t[0],{original:A,modified:E}=Qm(_,a,x);h(u,A,E,c)}else{const y=`ai-generated-${Date.now()}`;p(y,a),m(y)}}catch(y){o(y instanceof Error?y.message:"Merge failed")}}},[a,u,d,h,p,m,t,n,c]),k=g.useCallback(async()=>{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)},[e]);return l.jsxs("div",{className:"flex flex-col gap-1 px-3 py-2 border-t",children:[l.jsxs("div",{className:"flex gap-1.5",children:[l.jsx(Ce,{variant:"secondary",size:"sm",onClick:v,disabled:f||!a,children:f?"Applied":a?"Apply to Editor":"Invalid JSON"}),l.jsx(Ce,{variant:"ghost",size:"sm",onClick:k,children:r?l.jsx(un,{className:"h-3.5 w-3.5"}):l.jsx(Es,{className:"h-3.5 w-3.5"})})]}),s&&l.jsx("p",{className:"text-xs text-destructive m-0",children:s})]})}function Gz({threads:e,activeThread:t,disabled:n,onSwitch:r,onCreate:i,onDelete:s,onRename:o}){const[a,c]=g.useState(null),[u,d]=g.useState(""),[f,h]=g.useState(null),p=g.useRef(null),m=(t==null?void 0:t.title)||"New Chat",v=m.length>24?m.slice(0,24)+"...":m;g.useEffect(()=>{a&&requestAnimationFrame(()=>{var S;return(S=p.current)==null?void 0:S.focus()})},[a]);const k=g.useCallback((S,O)=>{O.stopPropagation(),O.preventDefault(),c(S.id),d(S.title),h(null)},[]),y=g.useCallback(()=>{a&&u.trim()&&o(a,u.trim()),c(null),d("")},[a,u,o]),_=g.useCallback(()=>{c(null),d("")},[]),x=g.useCallback(S=>{S.stopPropagation(),S.key==="Enter"?(S.preventDefault(),y()):S.key==="Escape"&&(S.preventDefault(),_())},[y,_]),A=g.useCallback((S,O)=>{O.stopPropagation(),O.preventDefault(),h(S),c(null)},[]),E=g.useCallback(S=>{S.stopPropagation(),S.preventDefault(),f&&(s(f),h(null))},[f,s]),w=g.useCallback(S=>{S.stopPropagation(),S.preventDefault(),h(null)},[]);return l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsxs(_i,{onOpenChange:S=>{S||(c(null),h(null))},children:[l.jsx(Ni,{asChild:!0,disabled:n,children:l.jsxs("button",{className:"flex items-center gap-1 text-sm font-semibold tracking-tight hover:text-foreground/80 transition-colors max-w-[180px] cursor-pointer",children:[l.jsx("div",{className:"h-2 w-2 rounded-full bg-primary/70 shrink-0"}),l.jsx("span",{className:"truncate",children:v}),l.jsx(ki,{className:"h-3 w-3 shrink-0 opacity-60"})]})}),l.jsxs(Er,{align:"start",className:"w-64",children:[e.map(S=>{const O=a===S.id;return f===S.id?l.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-sm",children:[l.jsx("span",{className:"text-destructive text-xs flex-1 truncate",children:"Delete this thread?"}),l.jsx("button",{className:"shrink-0 text-destructive hover:text-destructive/80 transition-colors cursor-pointer",onClick:E,children:l.jsx(un,{className:"h-3.5 w-3.5"})}),l.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:w,children:l.jsx(wn,{className:"h-3.5 w-3.5"})})]},S.id):O?l.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1",onClick:N=>N.stopPropagation(),onPointerDown:N=>N.stopPropagation(),children:[l.jsx("input",{ref:p,type:"text",value:u,onChange:N=>d(N.target.value),onKeyDown:x,onBlur:y,className:"flex-1 min-w-0 text-sm rounded-sm border border-border bg-background px-1.5 py-0.5 outline-none focus:ring-1 focus:ring-primary/40"}),l.jsx("button",{className:"shrink-0 text-primary hover:text-primary/80 transition-colors cursor-pointer",onMouseDown:N=>{N.preventDefault(),y()},children:l.jsx(un,{className:"h-3.5 w-3.5"})}),l.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onMouseDown:N=>{N.preventDefault(),_()},children:l.jsx(wn,{className:"h-3.5 w-3.5"})})]},S.id):l.jsxs($t,{onSelect:()=>r(S.id),className:`group ${S.id===(t==null?void 0:t.id)?"bg-accent":""}`,children:[l.jsx("span",{className:"truncate flex-1",children:S.title.length>30?S.title.slice(0,30)+"...":S.title}),l.jsxs("div",{className:"ml-auto shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[l.jsx("button",{className:"text-muted-foreground hover:text-foreground transition-colors p-0.5 cursor-pointer",onClick:N=>k(S,N),children:l.jsx(zx,{className:"h-3 w-3"})}),e.length>1&&l.jsx("button",{className:"text-muted-foreground hover:text-destructive transition-colors p-0.5 cursor-pointer",onClick:N=>A(S.id,N),children:l.jsx(va,{className:"h-3 w-3"})})]})]},S.id)}),l.jsx(Fn,{}),l.jsxs($t,{onSelect:S=>{S.preventDefault();const O=i();O&&(c(O),d(Ea()),h(null))},children:[l.jsx(Dt,{className:"h-3.5 w-3.5 mr-1.5"}),"New Chat"]})]})]}),l.jsx(Ce,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",onClick:()=>i(),disabled:n,title:"New chat thread",children:l.jsx(Dt,{className:"h-3.5 w-3.5"})})]})}const og=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),Kz=Array.from(og).join(","),Yz=20*1024*1024,Xu=10;function Xz(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t({type:"file",mediaType:e.type,filename:e.name,url:r.result}),r.onerror=n,r.readAsDataURL(e)})}function Qu(e){return Array.from(e).filter(t=>og.has(t.type)&&t.size<=Yz)}function ag(e){return e.startsWith("image/")}function ed(){var Y,ge,_e;const e=De(M=>M.contextAttachments),t=De(M=>M.addContext),n=De(M=>M.removeContext),r=De(M=>M.scope),i=De(M=>M.setScope),s=De(M=>M.model),o=De(M=>M.setModel),a=De(M=>M.openChat),c=De(M=>M.closeChat),u=De(M=>M.threads),d=De(M=>M.activeThreadId),f=De(M=>M.createThread),h=De(M=>M.deleteThread),p=De(M=>M.switchThread),m=De(M=>M.updateThreadMessages),v=De(M=>M.updateThreadTitle),k=De(M=>M.deleteThreadsForDocument),y=ke(M=>M.activeTab),_=ke(M=>M.documents),{messages:x,sendMessage:A,status:E,error:w,setMessages:S,stop:O,getMessageContext:B,getMessageScope:N}=_z(),[R,T]=g.useState(""),[F,$]=g.useState([]),[Z,P]=g.useState(!1),[J,V]=g.useState(!1),X=g.useRef(null),j=g.useRef(null),ye=g.useRef(null),ce=g.useCallback(async M=>{const D=Qu(M);if(D.length===0)return;const xe=await Promise.all(D.map(Xz));$(de=>{const Me=[...de,...xe];return Me.length>Xu?Me.slice(0,Xu):Me})},[]),b=g.useCallback(M=>{$(D=>D.filter((xe,de)=>de!==M))},[]),G=g.useCallback(M=>{var xe;const D=(xe=M.clipboardData)==null?void 0:xe.files;if(D&&D.length>0){const de=Qu(D);de.length>0&&(M.preventDefault(),ce(de))}},[ce]),ne=g.useCallback(M=>{var xe;M.preventDefault(),V(!1);const D=(xe=M.dataTransfer)==null?void 0:xe.files;D&&D.length>0&&ce(Array.from(D))},[ce]),Q=g.useCallback(M=>{M.preventDefault(),V(!0)},[]),oe=g.useCallback(()=>V(!1),[]),I=y?d[y]:void 0,re=I?u[I]:void 0,ae=g.useMemo(()=>y?Object.values(u).filter(M=>M.documentName===y).sort((M,D)=>D.updatedAt-M.updatedAt):[],[u,y]);g.useEffect(()=>{y&&ae.length===0&&f(y)},[y,ae.length,f]);const H=g.useRef(u);H.current=u,g.useEffect(()=>{const M=new Set(_.map(xe=>xe.name)),D=new Set;for(const xe of Object.values(H.current))!M.has(xe.documentName)&&xe.documentName!=="__migrated__"&&D.add(xe.documentName);for(const xe of D)k(xe)},[_,k]);const K=g.useRef(null);g.useEffect(()=>{K.current!==I&&(K.current=I,S((re==null?void 0:re.messages)??[]))},[I,re,S]),g.useEffect(()=>{var M;(M=X.current)==null||M.scrollIntoView({behavior:"smooth"})},[x,E]),g.useEffect(()=>{const M=D=>{var Me;const{documentName:xe,selection:de}=D.detail;t({...de,documentName:xe}),a(),(Me=j.current)==null||Me.focus()};return window.addEventListener("monaco-selection-to-ai",M),()=>window.removeEventListener("monaco-selection-to-ai",M)},[t,a]);const pe=E==="streaming",fe=E==="submitted"||pe,Re=g.useCallback(M=>{M.preventDefault(),!(!R.trim()&&F.length===0||fe)&&(A(R,F.length>0?F:void 0),T(""),$([]))},[R,F,fe,A]),Oe=g.useCallback(M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),Re(M))},[Re]),$e=g.useCallback(()=>{x.length!==0&&P(!0)},[x.length]),C=g.useCallback(()=>{P(!1),S([]),I&&(m(I,[]),v(I,Ea()))},[S,I,m,v]),[z,L]=g.useState(null),se=g.useCallback(M=>{L(M)},[]),ie=g.useCallback(()=>{var Me,Je;if(!z)return;const M=x.findIndex(it=>it.id===z);if(M===-1){L(null);return}const D=x[M],xe=new Set([M]);D.role==="user"&&((Me=x[M+1])==null?void 0:Me.role)==="assistant"?xe.add(M+1):D.role==="assistant"&&M>0&&((Je=x[M-1])==null?void 0:Je.role)==="user"&&xe.add(M-1);const de=x.filter((it,Lt)=>!xe.has(Lt));S(de),I&&m(I,de),L(null)},[z,x,S,I,m]),ee=g.useCallback(M=>{if(!fe){if(ae.length<=1){$e();return}h(M)}},[fe,ae.length,$e,h]),me=g.useCallback(()=>{if(!(!y||fe))return f(y)},[y,fe,f]),we=g.useCallback(M=>{fe||M===I||p(M)},[fe,I,p]),U=g.useCallback((M,D)=>{v(M,D)},[v]);return l.jsxs("div",{className:"flex flex-col h-full border-l bg-surface-chat",children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-surface-chat",children:[l.jsx(Gz,{threads:ae,activeThread:re,disabled:fe,onSwitch:we,onCreate:me,onDelete:ee,onRename:U}),l.jsxs("div",{className:"flex items-center gap-1",children:[l.jsx(Ce,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:$e,disabled:fe||x.length===0,children:"Clear"}),l.jsx(Ce,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:c,title:"Close chat",children:l.jsx(wn,{className:"h-3.5 w-3.5"})})]})]}),l.jsx(ui,{className:"flex-1 min-h-0 [&_[data-radix-scroll-area-viewport]>div]:!block",children:l.jsxs("div",{className:"p-3 space-y-4 min-w-0",children:[x.length===0&&l.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4",children:[l.jsx("div",{className:"rounded-xl bg-primary/10 p-3 mb-4",children:l.jsx(gl,{className:"h-5 w-5 text-primary"})}),l.jsx("p",{className:"text-sm font-medium text-foreground/80 mb-1",children:"JSON Assistant"}),l.jsx("p",{className:"text-xs text-muted-foreground text-center max-w-[200px] mb-4",children:"Generate, edit, and refine your JSON document definitions with AI."}),l.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-muted/50 px-2.5 py-1.5",children:[l.jsx(di,{shortcut:"mod+k"}),l.jsx("span",{className:"text-xs text-muted-foreground",children:"to send a selection"})]})]}),x.map((M,D)=>{let xe;if(M.role==="user"){const Je=B(M.id);Je&&Je.length>0&&(xe=Je)}else if(M.role==="assistant"){for(let Je=D-1;Je>=0;Je--)if(x[Je].role==="user"){xe=B(x[Je].id);break}}const de=pe&&D===x.length-1&&M.role==="assistant",Me=M.role==="user"?N(M.id):void 0;return l.jsx(Qz,{msg:M,isStreaming:de,context:xe,scope:Me,onDelete:fe?void 0:se},M.id)}),fe&&((Y=x[x.length-1])==null?void 0:Y.role)!=="assistant"&&l.jsx("div",{className:"flex justify-start",children:l.jsx("div",{className:"rounded-lg px-3 py-2 bg-muted/60 border border-border/40",children:l.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[l.jsx(Jr,{className:"h-3.5 w-3.5 animate-spin text-primary"}),l.jsx("span",{children:"Thinking..."})]})})}),w&&!fe&&l.jsx("div",{className:"flex justify-start",children:l.jsx("div",{className:"rounded-lg px-3 py-2 bg-destructive/10 border border-destructive/30 text-destructive text-sm max-w-[90%]",children:w.message||"Something went wrong"})}),l.jsx("div",{ref:X})]})}),l.jsxs("div",{className:`border-t border-border/60 p-2.5 space-y-2 bg-surface-chat transition-colors ${J?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:ne,onDragOver:Q,onDragLeave:oe,children:[e.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((M,D)=>l.jsx(tg,{context:M,onRemove:()=>n(D)},D))}),l.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[l.jsx(nO,{model:s,setModel:o}),at==="pptx"&&y&&l.jsx(iO,{scope:r,setScope:i,docSize:((_e=(ge=_.find(M=>M.name===y))==null?void 0:ge.text)==null?void 0:_e.length)??0})]}),F.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1.5",children:F.map((M,D)=>l.jsxs("div",{className:"relative group",children:[ag(M.mediaType)?l.jsx("img",{src:M.url,alt:M.filename||"attachment",className:"h-14 w-14 rounded-md object-cover border border-border/60"}):l.jsxs("div",{className:"h-14 px-2.5 flex items-center gap-1.5 rounded-md border border-border/60 bg-muted/60 max-w-[140px]",children:[l.jsx(Do,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),l.jsx("span",{className:"text-xs truncate text-muted-foreground",children:M.filename||"file"})]}),l.jsx("button",{type:"button",onClick:()=>b(D),className:"absolute -top-1.5 -right-1.5 rounded-full bg-destructive text-destructive-foreground p-0.5 opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer",children:l.jsx(wn,{className:"h-3 w-3"})})]},D))}),l.jsxs("form",{onSubmit:Re,className:"flex items-end gap-2",children:[l.jsx("input",{ref:ye,type:"file",accept:Kz,multiple:!0,className:"hidden",onChange:M=>{M.target.files&&ce(Array.from(M.target.files)),M.target.value=""}}),l.jsx(Ce,{type:"button",variant:"ghost",size:"icon",className:"shrink-0 h-9 w-9 rounded-lg text-muted-foreground hover:text-foreground",onClick:()=>{var M;return(M=ye.current)==null?void 0:M.click()},title:"Attach file",children:l.jsx(Do,{className:"h-4 w-4"})}),l.jsx("textarea",{ref:j,value:R,onChange:M=>{T(M.target.value);const D=M.target;D.style.height="auto",D.style.height=`${Math.min(D.scrollHeight,128)}px`},onKeyDown:Oe,onPaste:G,placeholder:e.length>0?"Describe how to edit the selection...":r==="slides"?"Add, edit, or remove slides...":r==="blocks"?"Edit block definitions: layouts and slots...":"Ask AI to generate or edit JSON...",className:"flex-1 min-h-[36px] max-h-32 resize-none overflow-y-auto rounded-lg border border-border/60 bg-background px-3 py-1.5 text-sm placeholder:text-muted-foreground placeholder:whitespace-nowrap placeholder:overflow-hidden placeholder:text-ellipsis focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30 focus-visible:border-primary/50 transition-shadow",rows:1}),fe?l.jsx(Ce,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:O,title:"Stop generating",children:l.jsx(Wd,{className:"h-4 w-4"})}):l.jsx(Ce,{type:"submit",size:"icon",disabled:!R.trim()&&F.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:l.jsx(gl,{className:"h-4 w-4"})})]})]}),l.jsx(ct,{open:Z,onOpenChange:P,children:l.jsxs(lt,{className:"max-w-sm",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Clear thread"}),l.jsx(dn,{children:"This will delete all messages in this thread. This action cannot be undone."})]}),l.jsxs(kn,{children:[l.jsx(wl,{asChild:!0,children:l.jsx(Ce,{variant:"ghost",size:"sm",children:"Cancel"})}),l.jsx(Ce,{variant:"destructive",size:"sm",onClick:C,children:"Clear"})]})]})}),l.jsx(ct,{open:z!==null,onOpenChange:M=>{M||L(null)},children:l.jsxs(lt,{className:"max-w-sm",children:[l.jsxs(qt,{children:[l.jsx(Gt,{children:"Delete message"}),l.jsx(dn,{children:"This will delete the message and its paired response. This action cannot be undone."})]}),l.jsxs(kn,{children:[l.jsx(wl,{asChild:!0,children:l.jsx(Ce,{variant:"ghost",size:"sm",children:"Cancel"})}),l.jsx(Ce,{variant:"destructive",size:"sm",onClick:ie,children:"Delete"})]})]})})]})}const Qz=g.memo(function({msg:t,isStreaming:n,context:r,scope:i,onDelete:s}){var c,u;const o=((c=t.parts)==null?void 0:c.filter(d=>d.type==="text").map(d=>d.text).join(""))||"",a=((u=t.parts)==null?void 0:u.filter(d=>d.type==="file"))||[];return l.jsx("div",{className:`group/msg flex ${t.role==="user"?"justify-end":"justify-start"}`,children:l.jsxs("div",{className:`rounded-lg px-3 py-2 max-w-[90%] overflow-hidden min-w-0 ${t.role==="user"?"bg-primary text-primary-foreground":"bg-muted/60 border border-border/40"}`,children:[t.role==="user"?l.jsxs("div",{children:[a.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:a.map((d,f)=>ag(d.mediaType)?l.jsx("img",{src:d.url,alt:d.filename||"image",className:"h-20 max-w-[160px] rounded-sm object-cover"},f):l.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm bg-primary-foreground/20 px-2 py-1",children:[l.jsx(Do,{className:"h-3 w-3 shrink-0"}),l.jsx("span",{className:"text-xs truncate max-w-[120px]",children:d.filename||"file"})]},f))}),r&&r.length>0&&l.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:r.map((d,f)=>l.jsx(tg,{context:d,variant:"sent"},f))}),o&&l.jsx("div",{className:"whitespace-pre-wrap text-sm break-words",children:o}),i&&i!=="global"&&l.jsx("span",{className:"text-[10px] text-primary-foreground/60 mt-0.5 block text-right",children:i})]}):l.jsx(eO,{text:o,isStreaming:n,context:r,scope:i}),s&&!n&&l.jsx("div",{className:"opacity-0 transition-opacity group-hover/msg:opacity-100 focus-within:opacity-100 mt-1",children:l.jsx("button",{type:"button","aria-label":"Delete message",onClick:()=>s(t.id),className:`p-0.5 rounded-sm cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring ${t.role==="user"?"text-primary-foreground/50 hover:text-primary-foreground/80":"text-muted-foreground hover:text-destructive"}`,children:l.jsx(va,{className:"h-3 w-3"})})})]})})},(e,t)=>e.msg.id===t.msg.id&&e.msg===t.msg&&e.isStreaming===t.isStreaming&&e.scope===t.scope&&e.onDelete===t.onDelete&&e.context===t.context);function eO({text:e,isStreaming:t,context:n,scope:r}){return t?l.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1",children:l.jsx("pre",{className:"whitespace-pre-wrap font-sans text-sm m-0 p-0 bg-transparent border-none",children:e})}):l.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5 [&_h1]:text-base [&_h2]:text-sm [&_h3]:text-sm [&_h1]:my-2 [&_h2]:my-1.5 [&_h3]:my-1",children:l.jsx(N1,{remarkPlugins:[F_],components:{pre:({children:i})=>l.jsx(l.Fragment,{children:i}),code:({className:i,children:s})=>{const o=i==null?void 0:i.startsWith("language-"),a=(i==null?void 0:i.replace("language-",""))||"",c=String(s).replace(/\n$/,"");if(!o)return l.jsx("code",{className:"rounded-sm bg-muted px-1 py-0.5 text-xs font-mono",children:s});const u=a==="json"||a==="jsonc";return l.jsxs("div",{className:"my-2 rounded-lg border bg-card",children:[l.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-muted/60 border-b text-xs text-muted-foreground",children:[l.jsx("span",{className:"font-mono",children:a||"code"}),!u&&l.jsx(sO,{text:c})]}),l.jsx("pre",{className:"p-3 text-xs font-mono overflow-x-auto max-h-80 overflow-y-auto m-0",children:l.jsx("code",{children:c})}),u&&l.jsx(qz,{json:c,context:n,scope:r})]})}},children:e})})}const tO=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function nO({model:e,setModel:t}){return l.jsxs(li,{value:e,onValueChange:n=>t(n),children:[l.jsx(xr,{className:"h-6 w-auto gap-1 border-none bg-muted/40 px-2 py-0 text-[10px] shadow-none focus:ring-0",children:l.jsx(ci,{})}),l.jsx(yr,{children:tO.map(n=>l.jsx(Mn,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const td={global:"AI sees and edits the entire document",slides:"AI sees and edits only slides — block definitions stay unchanged",blocks:"AI sees and edits only block definitions — slides stay unchanged"},rO=1e5;function iO({scope:e,setScope:t,docSize:n}){return l.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[l.jsxs("div",{className:"flex items-center gap-1.5",children:[l.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Scope"}),l.jsx("div",{className:"flex items-center bg-muted/40 rounded-md p-0.5 gap-px",children:Object.keys(td).map(r=>l.jsxs(Ye,{children:[l.jsx(Xe,{asChild:!0,children:l.jsx("button",{type:"button",onClick:()=>t(r),className:`px-2 py-0.5 rounded-sm text-[10px] cursor-pointer transition-colors ${e===r?"bg-background text-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:r})}),l.jsx(Qe,{side:"top",className:"text-xs max-w-[200px]",children:td[r]})]},r))})]}),e==="global"&&n>rO&&l.jsxs("div",{className:"text-[10px] text-warning flex items-center gap-1",children:[l.jsx(Kd,{className:"h-3 w-3 shrink-0"}),l.jsxs("span",{children:["Large doc — switch to"," ",l.jsx("button",{type:"button",onClick:()=>t("slides"),className:"underline cursor-pointer hover:text-warning/80",children:"slides"})," ","or"," ",l.jsx("button",{type:"button",onClick:()=>t("blocks"),className:"underline cursor-pointer hover:text-warning/80",children:"blocks"})]})]})]})}function sO({text:e}){const[t,n]=g.useState(!1),r=g.useCallback(async()=>{await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},[e]);return l.jsx("button",{onClick:r,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:t?"Copied!":"Copy"})}function oO({discoveryData:e}){const t=Of(),n=Ky(),r=De(N=>N.chatOpen),i=De(N=>N.toggleChat),[s,o]=g.useState(()=>{try{const N=localStorage.getItem("dev-env.sidebar-open");return n?!1:N?N==="true":!0}catch{return!n}}),[a,c]=g.useState(()=>{try{const N=localStorage.getItem("dev-env.preview-open");return N?N==="true":!0}catch{return!0}}),[u,d]=g.useState("editor"),[f,h]=g.useState(!1),p=150,[m,v]=g.useState(!s),[k,y]=g.useState(!1);g.useEffect(()=>{try{localStorage.setItem("dev-env.sidebar-open",String(s))}catch{}},[s]),g.useEffect(()=>{try{localStorage.setItem("dev-env.preview-open",String(a))}catch{}},[a]);const _=g.useRef(n);g.useEffect(()=>{n&&!_.current&&s&&(y(!0),o(!1),setTimeout(()=>{v(!0),y(!1)},p)),!n&&_.current&&!s&&(y(!0),o(!0),setTimeout(()=>{v(!1),y(!1)},p)),_.current=n},[n,s]);const x=g.useCallback(()=>{if(t){h(N=>!N);return}y(!0),o(N=>!N),setTimeout(()=>{v(N=>!N),y(!1)},p)},[t]),A=g.useCallback(()=>c(N=>!N),[]),E=g.useRef(i),w=g.useRef(x),S=g.useRef(A);g.useEffect(()=>{E.current=i}),g.useEffect(()=>{w.current=x}),g.useEffect(()=>{S.current=A}),g.useEffect(()=>{const N=R=>{(R.metaKey||R.ctrlKey)&&(R.code==="KeyB"&&!R.shiftKey&&(R.preventDefault(),w.current()),R.code==="KeyJ"&&R.shiftKey&&(R.preventDefault(),R.stopPropagation(),E.current()),R.code==="KeyP"&&R.shiftKey&&(R.preventDefault(),S.current()))};return window.addEventListener("keydown",N,!0),()=>window.removeEventListener("keydown",N,!0)},[]);const O=jz,B=[{key:"editor",icon:Po,label:"Editor"},{key:"preview",icon:Yd,label:"Preview"},{key:"chat",icon:Xd,label:"Chat"}];return t?l.jsx(O,{children:l.jsxs("div",{className:"flex flex-col h-full w-full overflow-hidden",children:[l.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b bg-sidebar shrink-0",children:[l.jsxs(If,{open:f,onOpenChange:h,children:[l.jsx(Jy,{asChild:!0,children:l.jsx(Ce,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:l.jsx(Gd,{className:"h-4 w-4"})})}),l.jsx(Oa,{side:"left",className:"p-0 w-72",children:l.jsx(Ll,{discoveryData:e,onToggleSidebar:()=>h(!1),isCollapsed:!1})})]}),l.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:B.map(({key:N,icon:R,label:T})=>l.jsxs(Ce,{variant:u===N?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>d(N),children:[l.jsx(R,{className:"h-3.5 w-3.5"}),l.jsx("span",{className:"hidden xs:inline",children:T})]},N))})]}),u!=="chat"&&l.jsx(uc,{previewOpen:a,onTogglePreview:A}),l.jsxs("div",{className:"flex-1 min-h-0",children:[u==="editor"&&l.jsx("div",{className:"h-full bg-surface-editor",children:l.jsx(Bl,{})}),u==="preview"&&l.jsx("div",{className:"h-full bg-surface-preview",children:l.jsx(Zl,{})}),u==="chat"&&l.jsx(ed,{})]})]})}):l.jsx(O,{children:l.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[l.jsx("div",{className:W("shrink-0 overflow-hidden border-r bg-sidebar","transition-[width] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]",s?"w-64":"w-12"),children:l.jsx(Ll,{discoveryData:e,onToggleSidebar:x,isCollapsed:m,isAnimating:k})}),l.jsxs("div",{className:"flex-1 min-w-0 flex flex-col h-full",children:[l.jsx(uc,{previewOpen:a,onTogglePreview:A}),l.jsxs(Nv,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[l.jsx(io,{defaultSize:a?50:100,minSize:20,id:"editor",order:1,children:l.jsx("div",{className:"h-full bg-surface-editor",children:l.jsx(Bl,{})})}),a&&l.jsxs(l.Fragment,{children:[l.jsx(Xl,{withHandle:!0}),l.jsx(io,{defaultSize:50,minSize:20,id:"preview",order:2,children:l.jsx("div",{className:"h-full bg-surface-preview",children:l.jsx(Zl,{})})})]}),r&&l.jsxs(l.Fragment,{children:[l.jsx(Xl,{withHandle:!0}),l.jsx(io,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:l.jsx(ed,{})})]})]})]})]})})}function aO(){const[e,t]=g.useState(null),[n,r]=g.useState(!0),[i,s]=g.useState(null),o=g.useCallback(async()=>{r(!0),s(null);try{const a=await fetch("/api/discovery/all");if(!a.ok)throw new Error(`Discovery failed: ${a.statusText}`);const c=await a.json();if(!c.success)throw new Error(c.error||"Discovery failed");t({pluginAutoload:!0,...c.data})}catch(a){console.error("Discovery error:",a),s(a instanceof Error?a.message:"Failed to fetch discovered items"),t({plugins:[],documents:[],themes:[],pluginAutoload:!0})}finally{r(!1)}},[]);return g.useEffect(()=>{o()},[o]),{data:e,loading:n,error:i,refetch:o}}function lO(){const{data:e,loading:t,error:n}=aO(),r=Jt(s=>s.applyPluginsWithValidation),i=g.useMemo(()=>(e==null?void 0:e.plugins.map(s=>s.name))??[],[e]);return g.useEffect(()=>{if(!e)return;Jt.getState().selectedPlugins.size>0&&r()},[e,r]),t?l.jsx("div",{className:"flex items-center justify-center h-screen",children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"text-lg font-medium",children:"Discovering project resources..."}),l.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:"Searching for documents, themes, and plugins"})]})}):n?l.jsx("div",{className:"flex items-center justify-center h-screen",children:l.jsxs("div",{className:"text-center",children:[l.jsx("div",{className:"text-lg font-medium text-destructive",children:"Discovery failed"}),l.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:n}),l.jsx("div",{className:"text-xs text-muted-foreground mt-4",children:"The playground will work with limited functionality."})]})}):l.jsx(xg,{children:l.jsx(yg,{children:l.jsx(bg,{children:l.jsx(vg,{children:l.jsx(wg,{children:l.jsx(kg,{diskPluginNames:i,children:l.jsx(jy,{children:l.jsx(Df,{children:l.jsx("section",{className:"flex h-screen w-full flex-col",children:l.jsx("div",{className:"grow overflow-hidden",children:l.jsx(oO,{discoveryData:e})})})})})})})})})})})}const yO=Object.freeze(Object.defineProperty({__proto__:null,HomePage:lO},Symbol.toStringTag,{value:"Module"}));export{Av as A,tn as B,_i as D,yO as H,br as I,Xr as L,Vv as P,Tv as Q,li as S,mp as T,xr as a,ci as b,yr as c,Mn as d,ui as e,Ni as f,Er as g,za as h,Fn as i,$t as j,Pa as k,ni as l,pr as m,Ro as n,gp as o,ti as p,ac as q,La as r,Tf as s,Mv as t,Ov as u,ct as v,lt as w,qt as x,Gt as y,xp as z};
245
- //# sourceMappingURL=HomePage-cnVO2sFq.js.map
245
+ //# sourceMappingURL=HomePage-Dzm2MeID.js.map