@json-to-office/jto 1.7.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/cli.js +14 -3
  2. package/dist/cli.js.map +1 -1
  3. package/dist/client/assets/{HomePage-fDrbL-5G.js → HomePage-r7ryeW_v.js} +4 -4
  4. package/dist/client/assets/{HomePage-fDrbL-5G.js.map → HomePage-r7ryeW_v.js.map} +1 -1
  5. package/dist/client/assets/{JsonEditorPage-CRY9589Y.js → JsonEditorPage-BxUyYH8Z.js} +3 -3
  6. package/dist/client/assets/{JsonEditorPage-CRY9589Y.js.map → JsonEditorPage-BxUyYH8Z.js.map} +1 -1
  7. package/dist/client/assets/{MonacoPluginProvider-n1_V7jsc.js → MonacoPluginProvider-CGvtVJKz.js} +3 -3
  8. package/dist/client/assets/{MonacoPluginProvider-n1_V7jsc.js.map → MonacoPluginProvider-CGvtVJKz.js.map} +1 -1
  9. package/dist/client/assets/{editor-Y9dek093.js → editor-gT4UjmPk.js} +2 -2
  10. package/dist/client/assets/{editor-Y9dek093.js.map → editor-gT4UjmPk.js.map} +1 -1
  11. package/dist/client/assets/{editor-monaco-json-oBxvTIvi.js → editor-monaco-json-BYUK4OUI.js} +2 -2
  12. package/dist/client/assets/{editor-monaco-json-oBxvTIvi.js.map → editor-monaco-json-BYUK4OUI.js.map} +1 -1
  13. package/dist/client/assets/{editor-refs-store-BMwl0ejj.js → editor-refs-store-ChL2fzuX.js} +2 -2
  14. package/dist/client/assets/{editor-refs-store-BMwl0ejj.js.map → editor-refs-store-ChL2fzuX.js.map} +1 -1
  15. package/dist/client/assets/{index-B4R-AAtI.js → index-CgCY8SiY.js} +4 -4
  16. package/dist/client/assets/index-CgCY8SiY.js.map +1 -0
  17. package/dist/client/assets/{preview-zCYkbgdR.js → preview-ZqhmQZJG.js} +2 -2
  18. package/dist/client/assets/{preview-zCYkbgdR.js.map → preview-ZqhmQZJG.js.map} +1 -1
  19. package/dist/client/assets/{useQualityAnalysis-BFG1bJDp.js → useQualityAnalysis-eKT8VcIt.js} +2 -2
  20. package/dist/client/assets/{useQualityAnalysis-BFG1bJDp.js.map → useQualityAnalysis-eKT8VcIt.js.map} +1 -1
  21. package/dist/client/index.html +1 -1
  22. package/dist/client/templates/minimalist-pitch-deck.pptx.json +431 -7
  23. package/dist/client/templates/modern-annual-report-1.docx.json +4128 -168
  24. package/dist/client/templates/modern-annual-report-2.docx.json +5122 -4648
  25. package/dist/client/templates/modern-annual-report-3.docx.json +4540 -2755
  26. package/dist/client/templates/standard-annual-report.docx.json +6609 -234
  27. package/dist/client/templates/tech-report.docx.json +6404 -213
  28. package/dist/client/templates/vermilion-annual-report.docx.json +726 -106
  29. package/package.json +5 -5
  30. package/dist/client/assets/index-B4R-AAtI.js.map +0 -1
@@ -1,12 +1,12 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-Y9dek093.js","assets/react-vendor-BmQ2Ko_D.js","assets/editor-monaco-json-oBxvTIvi.js","assets/index-B4R-AAtI.js","assets/query-vendor--rhYD8mC.js","assets/radix-ui-DFNP5I4e.js","assets/ui-vendor-Bq4-oNFL.js","assets/monaco-editor-DJsdM0WK.js","assets/state-vendor-Cq67_JbF.js","assets/index-CrzIwHLS.css","assets/editor-refs-store-BMwl0ejj.js","assets/MonacoPluginProvider-n1_V7jsc.js","assets/useQualityAnalysis-BFG1bJDp.js","assets/preview-zCYkbgdR.js"])))=>i.map(i=>d[i]);
2
- var Km=Object.defineProperty;var Xm=(e,t,n)=>t in e?Km(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Vs=(e,t,n)=>Xm(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as je,R as Uc,g as uo}from"./react-vendor-BmQ2Ko_D.js";import{b as Jc,c as co,d as Hc,e as ys,f as bs,D as vs,O as ws,g as Qm,V as eg,G as tg,h as Wc,I as ng,i as rg,j as qc,k as ig,l as Gc,m as sg,n as ag,L as Yc,S as Kc,o as Xc,p as Qc,q as ed,r as kr,s as og,t as lg,u as ug,v as td,w as nd,x as rd,y as id,z as sd,B as ad,E as od,F as ld,H as ud,J as cg,K as dg,M as fg,N as cd,Q as dd,U as fd,W as pd,X as hd,Y as md,Z as gd,_ as xd,$ as yd,a0 as bd,a1 as pg,a2 as vd,a3 as hg,a4 as mg,a5 as wd,a6 as gg,a7 as xg,a8 as yg,a9 as bg,aa as kd,ab as Sd,ac as _d}from"./radix-ui-DFNP5I4e.js";import{c as G,u as Sr,S as gn,A as ei,T as _i,C as vg,E as wg,F as ht,a as kg,b as Sg,d as Ye,e as Ke,f as Xe,g as jd,_ as Nd,h as ji,i as _g,j as jg,k as Ng,l as Tr,s as Us,W as Ed,m as $i}from"./index-B4R-AAtI.js";import{X as yn,C as mi,a as an,b as Eg,d as gi,G as Cd,F as Cg,e as _r,f as Td,P as Tg,g as Ig,h as Id,E as Ad,B as _a,H as Ag,T as ja,L as Na,i as zg,j as Og,S as zd,I as Pg,k as Dg,l as Ea,m as Rg,n as Mg,o as $g,p as Fg,q as Lg,r as Bg,s as Zg,t as Vg,u as ks,v as Ug,M as Jg,w as nn,x as Od,y as Hg,z as Wg,A as Pd,D as qg,J as Gg,K as Yg,N as Kg,O as Xg,Q as Dd,R as Qg,U as Ca,V as fo,W as Rd,Y as ex,Z as Md,_ as Fr,$ as tx,a0 as nx,a1 as rx,a2 as il,a3 as Ta}from"./ui-vendor-Bq4-oNFL.js";import{B as Se,u as $d,d as sl}from"./editor-refs-store-BMwl0ejj.js";import{u as Ne,i as ix,a as Ia,b as rn,g as sx,c as Lt,T as Fd,d as Hi,e as Ld,S as ax,O as ox,f as lx,M as ux,D as cx}from"./MonacoPluginProvider-n1_V7jsc.js";import{u as po,a as dx,d as fx,p as px,b as hx,e as mx}from"./state-vendor-Cq67_JbF.js";import{b as gx}from"./query-vendor--rhYD8mC.js";const Ct=Jc,xx=Hc,al=co,Bd=x.forwardRef(({className:e,...t},n)=>u.jsx(ws,{ref:n,className:G("fixed inset-0 z-50 bg-black/50",e),...t}));Bd.displayName=ws.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xx,{children:[u.jsx(Bd,{}),u.jsxs(ys,{ref:r,className:G("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,u.jsxs(co,{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:[u.jsx(yn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));kt.displayName=ys.displayName;const Vt=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Vt.displayName="DialogHeader";const bn=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});bn.displayName="DialogFooter";const Ut=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-lg leading-none font-semibold tracking-tight",e),...t}));Ut.displayName=bs.displayName;const on=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));on.displayName=vs.displayName;const ti=Qm,Zd=tg,ni=eg,fr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Wc,{ref:r,className:G("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,u.jsx(ng,{asChild:!0,children:u.jsx(mi,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));fr.displayName=Wc.displayName;const Vd=x.forwardRef(({className:e,...t},n)=>u.jsx(Kc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Eg,{className:"h-4 w-4"})}));Vd.displayName=Kc.displayName;const Ud=x.forwardRef(({className:e,...t},n)=>u.jsx(Xc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(mi,{className:"h-4 w-4"})}));Ud.displayName=Xc.displayName;const pr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(rg,{children:u.jsxs(qc,{ref:i,className:G("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:[u.jsx(Vd,{}),u.jsx(ig,{className:G("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ud,{})]})}));pr.displayName=qc.displayName;const ho=x.forwardRef(({className:e,...t},n)=>u.jsx(Yc,{ref:n,className:G("px-2 py-1.5 text-sm font-semibold",e),...t}));ho.displayName=Yc.displayName;const Pn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Gc,{ref:r,className:G("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:[u.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(sg,{children:u.jsx(an,{className:"h-4 w-4"})})}),u.jsx(ag,{children:t})]}));Pn.displayName=Gc.displayName;const yx=x.forwardRef(({className:e,...t},n)=>u.jsx(Qc,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));yx.displayName=Qc.displayName;const hr=x.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:G("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}));hr.displayName="Input";const bx=gi("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Wr=x.forwardRef(({className:e,...t},n)=>u.jsx(ed,{ref:n,className:G(bx(),e),...t}));Wr.displayName=ed.displayName;const vx=gi("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 Kt({className:e,variant:t,...n}){return u.jsx("div",{className:G(vx({variant:t}),e),...n})}const wx=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Ne(po(I=>({documents:I.documents,documentTypes:I.documentTypes,activeTab:I.activeTab,createDocument:I.createDocument,openDocument:I.openDocument}))),{toast:o}=Sr(),l=x.useMemo(()=>n.filter(I=>r[I.name]!=="application/json+theme"),[n,r]),[c,f]=x.useState(""),[d,h]=x.useState(""),[p,g]=x.useState("playground"),[w,_]=x.useState(!1),[b,N]=x.useState(null),[m,O]=x.useState(null),[C,v]=x.useState(null),k=()=>{N(null),O(null),v(null)};x.useEffect(()=>{if(!e)return;N(null),O(null),v(null);const I=l.map(P=>P.name),T=I.includes(i)?i:I[0]??"";h(T),f(I.find(P=>P!==T)??"")},[e]);const $=async()=>{const I=l.find(P=>P.name===c),T=l.find(P=>P.name===d);if(!(!I||!T)){_(!0),N(null),O(null),v(null);try{const P=await fetch(ei.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:I.text,newDefinition:T.text,options:{author:p||"playground"}})}),A=await P.json();if(!P.ok||!A.success){const M=Array.isArray(A.errors)?`: ${A.errors.slice(0,3).map(V=>V.message||String(V)).join("; ")}`:"";throw new Error((A.error||`Diff failed (${P.status})`)+M)}O(A.data.summary),v(A.data.document)}catch(P){N(P instanceof Error?P.message:"Diff failed")}finally{_(!1)}}},H=()=>{if(!C)return;const I=new Set(n.map(A=>A.name));let T=`${d}-redline`,P=2;for(;I.has(T);)T=`${d}-redline-${P++}`;s(T,JSON.stringify(C,null,2)),a(T),o({title:`Redline created: ${T}`}),t(!1)},j=m?m.tracked.modified+m.tracked.inserted+m.tracked.deleted:0;return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"sm:max-w-[560px]",children:[u.jsxs(Vt,{children:[u.jsxs(Ut,{className:"flex items-center gap-2",children:[u.jsx(Cd,{className:"size-4"}),"Compare documents"]}),u.jsx(on,{children:"Diff two versions into a redline with native Word tracked changes (accept/reject in Word)."})]}),u.jsxs("div",{className:"grid gap-4 py-2",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(ti,{value:c,onValueChange:I=>{f(I),k()},children:[u.jsx(fr,{id:"diff-base",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(I=>u.jsx(Pn,{value:I.name,children:I.name},I.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(ti,{value:d,onValueChange:I=>{h(I),k()},children:[u.jsx(fr,{id:"diff-revised",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(I=>u.jsx(Pn,{value:I.name,children:I.name},I.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(hr,{id:"diff-author",value:p,onChange:I=>{g(I.target.value),k()},placeholder:"playground"})]}),b&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:b}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Kt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),j===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((I,T)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[I.path," [",I.component,"] ",I.detail]},T))]}),m.notes.map((I,T)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",I]},T))]})]}),u.jsx(bn,{children:m&&j+m.untracked.length>0?u.jsxs(Se,{onClick:H,children:[u.jsx(Cg,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Se,{onClick:$,disabled:w||!c||!d||c===d,children:[w&&u.jsx(gn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var xi=e=>e.type==="checkbox",In=e=>e instanceof Date,ft=e=>e==null;const Jd=e=>typeof e=="object";var et=e=>!ft(e)&&!Array.isArray(e)&&Jd(e)&&!In(e),Hd=e=>et(e)&&e.target?xi(e.target)?e.target.checked:e.target.value:e,kx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Wd=(e,t)=>e.has(kx(t)),Sx=e=>{const t=e.constructor&&e.constructor.prototype;return et(t)&&t.hasOwnProperty("isPrototypeOf")},mo=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function yt(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(!(mo&&(e instanceof Blob||r))&&(n||et(e)))if(t=n?[]:{},!n&&!Sx(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=yt(e[i]));else return e;return t}var Ss=e=>Array.isArray(e)?e.filter(Boolean):[],Qe=e=>e===void 0,le=(e,t,n)=>{if(!t||!et(e))return n;const r=Ss(t.split(/[,[\].]+?/)).reduce((i,s)=>ft(i)?i:i[s],e);return Qe(r)||r===e?Qe(e[t])?n:e[t]:r},zt=e=>typeof e=="boolean",go=e=>/^\w*$/.test(e),qd=e=>Ss(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Me=(e,t,n)=>{let r=-1;const i=go(t)?[t]:qd(t),s=i.length,a=s-1;for(;++r<s;){const o=i[r];let l=n;if(r!==a){const c=e[o];l=et(c)||Array.isArray(c)?c:isNaN(+i[r+1])?{}:[]}if(o==="__proto__"||o==="constructor"||o==="prototype")return;e[o]=l,e=e[o]}return e};const Wi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ft={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},tn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Gd=je.createContext(null),_s=()=>je.useContext(Gd),_x=e=>{const{children:t,...n}=e;return je.createElement(Gd.Provider,{value:n},t)};var Yd=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const a=s;return t._proxyFormState[a]!==Ft.all&&(t._proxyFormState[a]=!r||Ft.all),n&&(n[a]=!0),e[a]}});return i},bt=e=>et(e)&&!Object.keys(e).length,Kd=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return bt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(a=>t[a]===(!r||Ft.all))},qr=e=>Array.isArray(e)?e:[e],Xd=(e,t,n)=>!e||!t||e===t||qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function xo(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 jx(e){const t=_s(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[a,o]=je.useState(n._formState),l=je.useRef(!0),c=je.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),f=je.useRef(i);return f.current=i,xo({disabled:r,next:d=>l.current&&Xd(f.current,d.name,s)&&Kd(d,c.current,n._updateFormState)&&o({...n._formState,...d}),subject:n._subjects.state}),je.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),je.useMemo(()=>Yd(a,n,c.current,!1),[a,n])}var Yt=e=>typeof e=="string",Qd=(e,t,n,r,i)=>Yt(e)?(r&&t.watch.add(e),le(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),le(n,s))):(r&&(t.watchAll=!0),n);function Nx(e){const t=_s(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=je.useRef(r);o.current=r,xo({disabled:s,subject:n._subjects.values,next:f=>{Xd(o.current,f.name,a)&&c(yt(Qd(o.current,n._names,f.values||n._formValues,!1,i)))}});const[l,c]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),l}function Ex(e){const t=_s(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=Wd(i._names.array,n),o=Nx({control:i,name:n,defaultValue:le(i._formValues,n,le(i._defaultValues,n,e.defaultValue)),exact:!0}),l=jx({control:i,name:n,exact:!0}),c=je.useRef(i.register(n,{...e.rules,value:o,...zt(e.disabled)?{disabled:e.disabled}:{}})),f=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!le(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!le(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!le(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!le(l.validatingFields,n)},error:{enumerable:!0,get:()=>le(l.errors,n)}}),[l,n]),d=je.useMemo(()=>({name:n,value:o,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:h=>c.current.onChange({target:{value:Hd(h),name:n},type:Wi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:le(i._formValues,n),name:n},type:Wi.BLUR}),ref:h=>{const p=le(i._fields,n);p&&h&&(p._f.ref={focus:()=>h.focus(),select:()=>h.select(),setCustomValidity:g=>h.setCustomValidity(g),reportValidity:()=>h.reportValidity()})}}),[n,i._formValues,r,l.disabled,o,i._fields]);return je.useEffect(()=>{const h=i._options.shouldUnregister||s,p=(g,w)=>{const _=le(i._fields,g);_&&_._f&&(_._f.mount=w)};if(p(n,!0),h){const g=yt(le(i._options.defaultValues,n));Me(i._defaultValues,n,g),Qe(le(i._formValues,n))&&Me(i._formValues,n,g)}return!a&&i.register(n),()=>{(a?h&&!i._state.action:h)?i.unregister(n):p(n,!1)}},[n,i,a,s]),je.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),je.useMemo(()=>({field:d,formState:l,fieldState:f}),[d,l,f])}const Cx=e=>e.render(Ex(e));var Tx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},ol=e=>({isOnSubmit:!e||e===Ft.onSubmit,isOnBlur:e===Ft.onBlur,isOnChange:e===Ft.onChange,isOnAll:e===Ft.all,isOnTouch:e===Ft.onTouched}),ll=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Gr=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=le(e,i);if(s){const{_f:a,...o}=s;if(a){if(a.refs&&a.refs[0]&&t(a.refs[0],i)&&!r)return!0;if(a.ref&&t(a.ref,a.name)&&!r)return!0;if(Gr(o,t))break}else if(et(o)&&Gr(o,t))break}}};var Ix=(e,t,n)=>{const r=qr(le(e,n));return Me(r,"root",t[n]),Me(e,n,r),e},yo=e=>e.type==="file",Gt=e=>typeof e=="function",qi=e=>{if(!mo)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Fi=e=>Yt(e),bo=e=>e.type==="radio",Gi=e=>e instanceof RegExp;const ul={value:!1,isValid:!1},cl={value:!0,isValid:!0};var ef=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&&!Qe(e[0].attributes.value)?Qe(e[0].value)||e[0].value===""?cl:{value:e[0].value,isValid:!0}:cl:ul}return ul};const dl={isValid:!1,value:null};var tf=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,dl):dl;function fl(e,t,n="validate"){if(Fi(e)||Array.isArray(e)&&e.every(Fi)||zt(e)&&!e)return{type:n,message:Fi(e)?e:"",ref:t}}var Ln=e=>et(e)&&!Gi(e)?e:{value:e,message:""},pl=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:f,min:d,max:h,pattern:p,validate:g,name:w,valueAsNumber:_,mount:b}=e._f,N=le(n,w);if(!b||t.has(w))return{};const m=o?o[0]:a,O=T=>{i&&m.reportValidity&&(m.setCustomValidity(zt(T)?"":T||""),m.reportValidity())},C={},v=bo(a),k=xi(a),$=v||k,H=(_||yo(a))&&Qe(a.value)&&Qe(N)||qi(a)&&a.value===""||N===""||Array.isArray(N)&&!N.length,j=Tx.bind(null,w,r,C),I=(T,P,A,M=tn.maxLength,V=tn.minLength)=>{const U=T?P:A;C[w]={type:T?M:V,message:U,ref:a,...j(T?M:V,U)}};if(s?!Array.isArray(N)||!N.length:l&&(!$&&(H||ft(N))||zt(N)&&!N||k&&!ef(o).isValid||v&&!tf(o).isValid)){const{value:T,message:P}=Fi(l)?{value:!!l,message:l}:Ln(l);if(T&&(C[w]={type:tn.required,message:P,ref:m,...j(tn.required,P)},!r))return O(P),C}if(!H&&(!ft(d)||!ft(h))){let T,P;const A=Ln(h),M=Ln(d);if(!ft(N)&&!isNaN(N)){const V=a.valueAsNumber||N&&+N;ft(A.value)||(T=V>A.value),ft(M.value)||(P=V<M.value)}else{const V=a.valueAsDate||new Date(N),U=S=>new Date(new Date().toDateString()+" "+S),J=a.type=="time",ne=a.type=="week";Yt(A.value)&&N&&(T=J?U(N)>U(A.value):ne?N>A.value:V>new Date(A.value)),Yt(M.value)&&N&&(P=J?U(N)<U(M.value):ne?N<M.value:V<new Date(M.value))}if((T||P)&&(I(!!T,A.message,M.message,tn.max,tn.min),!r))return O(C[w].message),C}if((c||f)&&!H&&(Yt(N)||s&&Array.isArray(N))){const T=Ln(c),P=Ln(f),A=!ft(T.value)&&N.length>+T.value,M=!ft(P.value)&&N.length<+P.value;if((A||M)&&(I(A,T.message,P.message),!r))return O(C[w].message),C}if(p&&!H&&Yt(N)){const{value:T,message:P}=Ln(p);if(Gi(T)&&!N.match(T)&&(C[w]={type:tn.pattern,message:P,ref:a,...j(tn.pattern,P)},!r))return O(P),C}if(g){if(Gt(g)){const T=await g(N,n),P=fl(T,m);if(P&&(C[w]={...P,...j(tn.validate,P.message)},!r))return O(P.message),C}else if(et(g)){let T={};for(const P in g){if(!bt(T)&&!r)break;const A=fl(await g[P](N,n),m,P);A&&(T={...A,...j(P,A.message)},O(A.message),r&&(C[w]=T))}if(!bt(T)&&(C[w]={ref:m,...T},!r))return C}}return O(!0),C};function Ax(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Qe(e)?r++:e[t[r++]];return e}function zx(e){for(const t in e)if(e.hasOwnProperty(t)&&!Qe(e[t]))return!1;return!0}function it(e,t){const n=Array.isArray(t)?t:go(t)?[t]:qd(t),r=n.length===1?e:Ax(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(et(r)&&bt(r)||Array.isArray(r)&&zx(r))&&it(e,n.slice(0,-1)),e}var Js=()=>{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=[]}}},Aa=e=>ft(e)||!Jd(e);function hn(e,t){if(Aa(e)||Aa(t))return e===t;if(In(e)&&In(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 a=t[i];if(In(s)&&In(a)||et(s)&&et(a)||Array.isArray(s)&&Array.isArray(a)?!hn(s,a):s!==a)return!1}}return!0}var nf=e=>e.type==="select-multiple",Ox=e=>bo(e)||xi(e),Hs=e=>qi(e)&&e.isConnected,rf=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Yi(e,t={}){const n=Array.isArray(e);if(et(e)||n)for(const r in e)Array.isArray(e[r])||et(e[r])&&!rf(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Yi(e[r],t[r])):ft(e[r])||(t[r]=!0);return t}function sf(e,t,n){const r=Array.isArray(e);if(et(e)||r)for(const i in e)Array.isArray(e[i])||et(e[i])&&!rf(e[i])?Qe(t)||Aa(n[i])?n[i]=Array.isArray(e[i])?Yi(e[i],[]):{...Yi(e[i])}:sf(e[i],ft(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Ir=(e,t)=>sf(e,t,Yi(t)),af=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Qe(e)?e:t?e===""?NaN:e&&+e:n&&Yt(e)?new Date(e):r?r(e):e;function Ws(e){const t=e.ref;return yo(t)?t.files:bo(t)?tf(e.refs).value:nf(t)?[...t.selectedOptions].map(({value:n})=>n):xi(t)?ef(e.refs).value:af(Qe(t.value)?e.ref.value:t.value,e)}var Px=(e,t,n,r)=>{const i={};for(const s of e){const a=le(t,s);a&&Me(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Ar=e=>Qe(e)?e:Gi(e)?e.source:et(e)?Gi(e.value)?e.value.source:e.value:e;const hl="AsyncFunction";var Dx=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===hl||et(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===hl)),Rx=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function ml(e,t,n){const r=le(e,n);if(r||go(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=le(t,s),o=le(e,s);if(a&&!Array.isArray(a)&&n!==s)return{name:n};if(o&&o.type)return{name:s,error:o};i.pop()}return{name:n}}var Mx=(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,$x=(e,t)=>!Ss(le(e,t)).length&&it(e,t);const Fx={mode:Ft.onSubmit,reValidateMode:Ft.onChange,shouldFocusError:!0};function Lx(e={}){let t={...Fx,...e},n={submitCount:0,isDirty:!1,isLoading:Gt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=et(t.defaultValues)||et(t.values)?yt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:yt(i),a={action:!1,mount:!1,watch:!1},o={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const f={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={values:Js(),array:Js(),state:Js()},h=ol(t.mode),p=ol(t.reValidateMode),g=t.criteriaMode===Ft.all,w=E=>R=>{clearTimeout(c),c=setTimeout(E,R)},_=async E=>{if(!t.disabled&&(f.isValid||E)){const R=t.resolver?bt((await $()).errors):await j(r,!0);R!==n.isValid&&d.state.next({isValid:R})}},b=(E,R)=>{!t.disabled&&(f.isValidating||f.validatingFields)&&((E||Array.from(o.mount)).forEach(Z=>{Z&&(R?Me(n.validatingFields,Z,R):it(n.validatingFields,Z))}),d.state.next({validatingFields:n.validatingFields,isValidating:!bt(n.validatingFields)}))},N=(E,R=[],Z,se,z=!0,K=!0)=>{if(se&&Z&&!t.disabled){if(a.action=!0,K&&Array.isArray(le(r,E))){const te=Z(le(r,E),se.argA,se.argB);z&&Me(r,E,te)}if(K&&Array.isArray(le(n.errors,E))){const te=Z(le(n.errors,E),se.argA,se.argB);z&&Me(n.errors,E,te),$x(n.errors,E)}if(f.touchedFields&&K&&Array.isArray(le(n.touchedFields,E))){const te=Z(le(n.touchedFields,E),se.argA,se.argB);z&&Me(n.touchedFields,E,te)}f.dirtyFields&&(n.dirtyFields=Ir(i,s)),d.state.next({name:E,isDirty:T(E,R),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Me(s,E,R)},m=(E,R)=>{Me(n.errors,E,R),d.state.next({errors:n.errors})},O=E=>{n.errors=E,d.state.next({errors:n.errors,isValid:!1})},C=(E,R,Z,se)=>{const z=le(r,E);if(z){const K=le(s,E,Qe(Z)?le(i,E):Z);Qe(K)||se&&se.defaultChecked||R?Me(s,E,R?K:Ws(z._f)):M(E,K),a.mount&&_()}},v=(E,R,Z,se,z)=>{let K=!1,te=!1;const xe={name:E};if(!t.disabled){const L=!!(le(r,E)&&le(r,E)._f&&le(r,E)._f.disabled);if(!Z||se){f.isDirty&&(te=n.isDirty,n.isDirty=xe.isDirty=T(),K=te!==xe.isDirty);const Q=L||hn(le(i,E),R);te=!!(!L&&le(n.dirtyFields,E)),Q||L?it(n.dirtyFields,E):Me(n.dirtyFields,E,!0),xe.dirtyFields=n.dirtyFields,K=K||f.dirtyFields&&te!==!Q}if(Z){const Q=le(n.touchedFields,E);Q||(Me(n.touchedFields,E,Z),xe.touchedFields=n.touchedFields,K=K||f.touchedFields&&Q!==Z)}K&&z&&d.state.next(xe)}return K?xe:{}},k=(E,R,Z,se)=>{const z=le(n.errors,E),K=f.isValid&&zt(R)&&n.isValid!==R;if(t.delayError&&Z?(l=w(()=>m(E,Z)),l(t.delayError)):(clearTimeout(c),l=null,Z?Me(n.errors,E,Z):it(n.errors,E)),(Z?!hn(z,Z):z)||!bt(se)||K){const te={...se,...K&&zt(R)?{isValid:R}:{},errors:n.errors,name:E};n={...n,...te},d.state.next(te)}},$=async E=>{b(E,!0);const R=await t.resolver(s,t.context,Px(E||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(E),R},H=async E=>{const{errors:R}=await $(E);if(E)for(const Z of E){const se=le(R,Z);se?Me(n.errors,Z,se):it(n.errors,Z)}else n.errors=R;return R},j=async(E,R,Z={valid:!0})=>{for(const se in E){const z=E[se];if(z){const{_f:K,...te}=z;if(K){const xe=o.array.has(K.name),L=z._f&&Dx(z._f);L&&f.validatingFields&&b([se],!0);const Q=await pl(z,o.disabled,s,g,t.shouldUseNativeValidation&&!R,xe);if(L&&f.validatingFields&&b([se]),Q[K.name]&&(Z.valid=!1,R))break;!R&&(le(Q,K.name)?xe?Ix(n.errors,Q,K.name):Me(n.errors,K.name,Q[K.name]):it(n.errors,K.name))}!bt(te)&&await j(te,R,Z)}}return Z.valid},I=()=>{for(const E of o.unMount){const R=le(r,E);R&&(R._f.refs?R._f.refs.every(Z=>!Hs(Z)):!Hs(R._f.ref))&&Y(E)}o.unMount=new Set},T=(E,R)=>!t.disabled&&(E&&R&&Me(s,E,R),!hn(oe(),i)),P=(E,R,Z)=>Qd(E,o,{...a.mount?s:Qe(R)?i:Yt(E)?{[E]:R}:R},Z,R),A=E=>Ss(le(a.mount?s:i,E,t.shouldUnregister?le(i,E,[]):[])),M=(E,R,Z={})=>{const se=le(r,E);let z=R;if(se){const K=se._f;K&&(!K.disabled&&Me(s,E,af(R,K)),z=qi(K.ref)&&ft(R)?"":R,nf(K.ref)?[...K.ref.options].forEach(te=>te.selected=z.includes(te.value)):K.refs?xi(K.ref)?K.refs.length>1?K.refs.forEach(te=>(!te.defaultChecked||!te.disabled)&&(te.checked=Array.isArray(z)?!!z.find(xe=>xe===te.value):z===te.value)):K.refs[0]&&(K.refs[0].checked=!!z):K.refs.forEach(te=>te.checked=te.value===z):yo(K.ref)?K.ref.value="":(K.ref.value=z,K.ref.type||d.values.next({name:E,values:{...s}})))}(Z.shouldDirty||Z.shouldTouch)&&v(E,z,Z.shouldTouch,Z.shouldDirty,!0),Z.shouldValidate&&S(E)},V=(E,R,Z)=>{for(const se in R){const z=R[se],K=`${E}.${se}`,te=le(r,K);(o.array.has(E)||et(z)||te&&!te._f)&&!In(z)?V(K,z,Z):M(K,z,Z)}},U=(E,R,Z={})=>{const se=le(r,E),z=o.array.has(E),K=yt(R);Me(s,E,K),z?(d.array.next({name:E,values:{...s}}),(f.isDirty||f.dirtyFields)&&Z.shouldDirty&&d.state.next({name:E,dirtyFields:Ir(i,s),isDirty:T(E,K)})):se&&!se._f&&!ft(K)?V(E,K,Z):M(E,K,Z),ll(E,o)&&d.state.next({...n}),d.values.next({name:a.mount?E:void 0,values:{...s}})},J=async E=>{a.mount=!0;const R=E.target;let Z=R.name,se=!0;const z=le(r,Z),K=()=>R.type?Ws(z._f):Hd(E),te=xe=>{se=Number.isNaN(xe)||In(xe)&&isNaN(xe.getTime())||hn(xe,le(s,Z,xe))};if(z){let xe,L;const Q=K(),me=E.type===Wi.BLUR||E.type===Wi.FOCUS_OUT,ve=!Rx(z._f)&&!t.resolver&&!le(n.errors,Z)&&!z._f.deps||Mx(me,le(n.touchedFields,Z),n.isSubmitted,p,h),F=ll(Z,o,me);Me(s,Z,Q),me?(z._f.onBlur&&z._f.onBlur(E),l&&l(0)):z._f.onChange&&z._f.onChange(E);const ge=v(Z,Q,me,!1),Te=!bt(ge)||F;if(!me&&d.values.next({name:Z,type:E.type,values:{...s}}),ve)return f.isValid&&(t.mode==="onBlur"&&me?_():me||_()),Te&&d.state.next({name:Z,...F?{}:ge});if(!me&&F&&d.state.next({...n}),t.resolver){const{errors:Le}=await $([Z]);if(te(Q),se){const rt=ml(n.errors,r,Z),tt=ml(Le,r,rt.name||Z);xe=tt.error,Z=tt.name,L=bt(Le)}}else b([Z],!0),xe=(await pl(z,o.disabled,s,g,t.shouldUseNativeValidation))[Z],b([Z]),te(Q),se&&(xe?L=!1:f.isValid&&(L=await j(r,!0)));se&&(z._f.deps&&S(z._f.deps),k(Z,L,xe,ge))}},ne=(E,R)=>{if(le(n.errors,R)&&E.focus)return E.focus(),1},S=async(E,R={})=>{let Z,se;const z=qr(E);if(t.resolver){const K=await H(Qe(E)?E:z);Z=bt(K),se=E?!z.some(te=>le(K,te)):Z}else E?(se=(await Promise.all(z.map(async K=>{const te=le(r,K);return await j(te&&te._f?{[K]:te}:te)}))).every(Boolean),!(!se&&!n.isValid)&&_()):se=Z=await j(r);return d.state.next({...!Yt(E)||f.isValid&&Z!==n.isValid?{}:{name:E},...t.resolver||!E?{isValid:Z}:{},errors:n.errors}),R.shouldFocus&&!se&&Gr(r,ne,E?z:o.mount),se},oe=E=>{const R={...a.mount?s:i};return Qe(E)?R:Yt(E)?le(R,E):E.map(Z=>le(R,Z))},B=(E,R)=>({invalid:!!le((R||n).errors,E),isDirty:!!le((R||n).dirtyFields,E),error:le((R||n).errors,E),isValidating:!!le(n.validatingFields,E),isTouched:!!le((R||n).touchedFields,E)}),y=E=>{E&&qr(E).forEach(R=>it(n.errors,R)),d.state.next({errors:E?n.errors:{}})},q=(E,R,Z)=>{const se=(le(r,E,{_f:{}})._f||{}).ref,z=le(n.errors,E)||{},{ref:K,message:te,type:xe,...L}=z;Me(n.errors,E,{...L,...R,ref:se}),d.state.next({name:E,errors:n.errors,isValid:!1}),Z&&Z.shouldFocus&&se&&se.focus&&se.focus()},X=(E,R)=>Gt(E)?d.values.subscribe({next:Z=>E(P(void 0,R),Z)}):P(E,R,!0),Y=(E,R={})=>{for(const Z of E?qr(E):o.mount)o.mount.delete(Z),o.array.delete(Z),R.keepValue||(it(r,Z),it(s,Z)),!R.keepError&&it(n.errors,Z),!R.keepDirty&&it(n.dirtyFields,Z),!R.keepTouched&&it(n.touchedFields,Z),!R.keepIsValidating&&it(n.validatingFields,Z),!t.shouldUnregister&&!R.keepDefaultValue&&it(i,Z);d.values.next({values:{...s}}),d.state.next({...n,...R.keepDirty?{isDirty:T()}:{}}),!R.keepIsValid&&_()},ie=({disabled:E,name:R,field:Z,fields:se})=>{(zt(E)&&a.mount||E||o.disabled.has(R))&&(E?o.disabled.add(R):o.disabled.delete(R),v(R,Ws(Z?Z._f:le(se,R)._f),!1,!1,!0))},D=(E,R={})=>{let Z=le(r,E);const se=zt(R.disabled)||zt(t.disabled);return Me(r,E,{...Z||{},_f:{...Z&&Z._f?Z._f:{ref:{name:E}},name:E,mount:!0,...R}}),o.mount.add(E),Z?ie({field:Z,disabled:zt(R.disabled)?R.disabled:t.disabled,name:E}):C(E,!0,R.value),{...se?{disabled:R.disabled||t.disabled}:{},...t.progressive?{required:!!R.required,min:Ar(R.min),max:Ar(R.max),minLength:Ar(R.minLength),maxLength:Ar(R.maxLength),pattern:Ar(R.pattern)}:{},name:E,onChange:J,onBlur:J,ref:z=>{if(z){D(E,R),Z=le(r,E);const K=Qe(z.value)&&z.querySelectorAll&&z.querySelectorAll("input,select,textarea")[0]||z,te=Ox(K),xe=Z._f.refs||[];if(te?xe.find(L=>L===K):K===Z._f.ref)return;Me(r,E,{_f:{...Z._f,...te?{refs:[...xe.filter(Hs),K,...Array.isArray(le(i,E))?[{}]:[]],ref:{type:K.type,name:E}}:{ref:K}}}),C(E,!1,void 0,K)}else Z=le(r,E,{}),Z._f&&(Z._f.mount=!1),(t.shouldUnregister||R.shouldUnregister)&&!(Wd(o.array,E)&&a.action)&&o.unMount.add(E)}}},ue=()=>t.shouldFocusError&&Gr(r,ne,o.mount),he=E=>{zt(E)&&(d.state.next({disabled:E}),Gr(r,(R,Z)=>{const se=le(r,Z);se&&(R.disabled=se._f.disabled||E,Array.isArray(se._f.refs)&&se._f.refs.forEach(z=>{z.disabled=se._f.disabled||E}))},0,!1))},ce=(E,R)=>async Z=>{let se;Z&&(Z.preventDefault&&Z.preventDefault(),Z.persist&&Z.persist());let z=yt(s);if(o.disabled.size)for(const K of o.disabled)Me(z,K,void 0);if(d.state.next({isSubmitting:!0}),t.resolver){const{errors:K,values:te}=await $();n.errors=K,z=te}else await j(r);if(it(n.errors,"root"),bt(n.errors)){d.state.next({errors:{}});try{await E(z,Z)}catch(K){se=K}}else R&&await R({...n.errors},Z),ue(),setTimeout(ue);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bt(n.errors)&&!se,submitCount:n.submitCount+1,errors:n.errors}),se)throw se},ee=(E,R={})=>{le(r,E)&&(Qe(R.defaultValue)?U(E,yt(le(i,E))):(U(E,R.defaultValue),Me(i,E,yt(R.defaultValue))),R.keepTouched||it(n.touchedFields,E),R.keepDirty||(it(n.dirtyFields,E),n.isDirty=R.defaultValue?T(E,yt(le(i,E))):T()),R.keepError||(it(n.errors,E),f.isValid&&_()),d.state.next({...n}))},de=(E,R={})=>{const Z=E?yt(E):i,se=yt(Z),z=bt(E),K=z?i:se;if(R.keepDefaultValues||(i=Z),!R.keepValues){if(R.keepDirtyValues){const te=new Set([...o.mount,...Object.keys(Ir(i,s))]);for(const xe of Array.from(te))le(n.dirtyFields,xe)?Me(K,xe,le(s,xe)):U(xe,le(K,xe))}else{if(mo&&Qe(E))for(const te of o.mount){const xe=le(r,te);if(xe&&xe._f){const L=Array.isArray(xe._f.refs)?xe._f.refs[0]:xe._f.ref;if(qi(L)){const Q=L.closest("form");if(Q){Q.reset();break}}}}r={}}s=t.shouldUnregister?R.keepDefaultValues?yt(i):{}:yt(K),d.array.next({values:{...K}}),d.values.next({values:{...K}})}o={mount:R.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!f.isValid||!!R.keepIsValid||!!R.keepDirtyValues,a.watch=!!t.shouldUnregister,d.state.next({submitCount:R.keepSubmitCount?n.submitCount:0,isDirty:z?!1:R.keepDirty?n.isDirty:!!(R.keepDefaultValues&&!hn(E,i)),isSubmitted:R.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:z?{}:R.keepDirtyValues?R.keepDefaultValues&&s?Ir(i,s):n.dirtyFields:R.keepDefaultValues&&E?Ir(i,E):R.keepDirty?n.dirtyFields:{},touchedFields:R.keepTouched?n.touchedFields:{},errors:R.keepErrors?n.errors:{},isSubmitSuccessful:R.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},fe=(E,R)=>de(Gt(E)?E(s):E,R);return{control:{register:D,unregister:Y,getFieldState:B,handleSubmit:ce,setError:q,_executeSchema:$,_getWatch:P,_getDirty:T,_updateValid:_,_removeUnmounted:I,_updateFieldArray:N,_updateDisabledField:ie,_getFieldArray:A,_reset:de,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(E=>{fe(E,t.resetOptions),d.state.next({isLoading:!1})}),_updateFormState:E=>{n={...n,...E}},_disableForm:he,_subjects:d,_proxyFormState:f,_setErrors:O,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(E){a=E},get _defaultValues(){return i},get _names(){return o},set _names(E){o=E},get _formState(){return n},set _formState(E){n=E},get _options(){return t},set _options(E){t={...t,...E}}},trigger:S,register:D,handleSubmit:ce,watch:X,setValue:U,getValues:oe,reset:fe,resetField:ee,clearErrors:y,unregister:Y,setError:q,setFocus:(E,R={})=>{const Z=le(r,E),se=Z&&Z._f;if(se){const z=se.refs?se.refs[0]:se.ref;z.focus&&(z.focus(),R.shouldSelect&&Gt(z.select)&&z.select())}},getFieldState:B}}function Bx(e={}){const t=je.useRef(void 0),n=je.useRef(void 0),[r,i]=je.useState({isDirty:!1,isValidating:!1,isLoading:Gt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Gt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Lx(e),formState:r});const s=t.current.control;return s._options=e,xo({subject:s._subjects.state,next:a=>{Kd(a,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),je.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),je.useEffect(()=>{if(s._proxyFormState.isDirty){const a=s._getDirty();a!==r.isDirty&&s._subjects.state.next({isDirty:a})}},[s,r.isDirty]),je.useEffect(()=>{e.values&&!hn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(a=>({...a}))):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=Yd(r,s),t.current}function Zx(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 Vx=_x,of=x.createContext({}),gl=({...e})=>u.jsx(of.Provider,{value:{name:e.name},children:u.jsx(Cx,{...e})}),js=()=>{const e=x.useContext(of),t=x.useContext(lf),{getFieldState:n,formState:r}=_s(),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}},lf=x.createContext({}),za=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(lf.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:G("space-y-2",e),...t})})});za.displayName="FormItem";const Oa=x.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=js();return u.jsx(Wr,{ref:n,className:G(r&&"text-destructive",e),htmlFor:i,...t})});Oa.displayName="FormLabel";const Pa=x.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=js();return u.jsx(kr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Pa.displayName="FormControl";const uf=x.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=js();return u.jsx("p",{ref:n,id:r,className:G("text-muted-foreground text-[0.8rem]",e),...t})});uf.displayName="FormDescription";const Da=x.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=js(),a=i?String(i==null?void 0:i.message):t;return a?u.jsx("p",{ref:r,id:s,className:G("text-destructive text-[0.8rem] font-medium",e),...n,children:a}):null});Da.displayName="FormMessage";function vo(){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 cf=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Ux=(e=cf())=>dx()(fx(px((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,a)=>a!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),a={id:i,documentName:r,title:vo(),messages:[],createdAt:s,updatedAt:s};return t(o=>({threads:{...o.threads,[i]:a},activeThreadId:{...o.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const a=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),o=s.documentName,l={...i.activeThreadId};if(l[o]===r){const c=Object.values(a).filter(f=>f.documentName===o);c.length>0?(c.sort((f,d)=>d.updatedAt-f.updatedAt),l[o]=c[0].id):delete l[o]}t({threads:a,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(a=>({activeThreadId:{...a.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},a={...i.activeThreadId};for(const[o,l]of Object.entries(s))l.documentName===r&&delete s[o];return delete a[r],{threads:s,activeThreadId:a}})},renameThreadsForDocument:(r,i)=>{t(s=>{const a={...s.threads},o={...s.activeThreadId};for(const[l,c]of Object.entries(a))c.documentName===r&&(a[l]={...c,documentName:i});return r in o&&(o[i]=o[r],delete o[r]),{threads:a,activeThreadId:o}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:hx(()=>ix),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 t}}))),df=x.createContext(void 0),Jx=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Ux(cf())),u.jsx(df.Provider,{value:t.current,children:e})},Pe=e=>{const t=x.useContext(df);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return mx(t,e)};function Hx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Wx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=_i.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),i.push("name")),e==="create"&&(r.template=_i.Optional(_i.String({description:"Template selection"})));const s=_i.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:a=>{const o=[];if(!vg(s,a))for(const c of wg(s,a))o.push({path:c.path.replace(/^\//,""),message:c.message});const l=a;if(e!=="delete"&&l.name){const c=l.name.trim();c?(l.name=c,t(c)||o.push({path:"name",message:"Document with this name already exists"})):o.push({path:"name",message:"Name can't be empty"})}return e==="create"&&(n!=null&&n.length)&&l.template&&(n.some(c=>c.name===l.template)||o.push({path:"template",message:"You must select a valid template"})),{success:o.length===0,data:o.length===0?l:void 0,errors:o}}}}function qx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Gx=e=>({create:{title:e?"New Theme":"New Document",description:e?"Create a new theme from scratch or based on discovered themes.":"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"}}),Bn="__empty__";function Yx({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=x.useState(!1),[c,f]=x.useState(null),[d,h]=x.useState("idle"),{toast:p}=Sr(),g=Gx(a),{documents:w,openTabs:_,createDocument:b,renameDocument:N,deleteDocument:m,openDocument:O,closeDocument:C}=Ne(oe=>oe),{updateTheme:v,removeTheme:k}=Ia(oe=>oe),$=Pe(oe=>oe.renameThreadsForDocument),H=Pe(oe=>oe.deleteThreadsForDocument),j=x.useMemo(()=>a?s||[]:i||[],[a,i,s]),I=x.useMemo(()=>{const oe={current:[],downstream:[]};return j.forEach(B=>{oe[B.location]&&oe[B.location].push(B)}),oe},[j]),T=x.useMemo(()=>j.map(oe=>({name:oe.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[j]),P=x.useMemo(()=>Wx(e,oe=>Hx(oe,w,r),T),[e,w,r,T]),A=P.schema,M=x.useMemo(()=>{const oe=new Map;return j.forEach(B=>oe.set(B.path,B)),oe},[j]),V=Bn,U=Bx({resolver:Zx(P.validate),defaultValues:qx(e,void 0,r)}),[J,ne]=x.useState(V);x.useEffect(()=>{if(J&&J!==Bn&&e==="create"){const oe=M.get(J);if(oe){f(null),h("loading");let B=!1;return fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(oe.name)}/content`).then(y=>{if(!y.ok)throw new Error(`Failed to fetch content: ${y.statusText}`);return y.text()}).then(y=>{if(B)return;const q=JSON.parse(y);f(JSON.stringify(q,null,2)),h("idle")}).catch(y=>{B||(console.error("Failed to copy template:",y),f(null),h("error"))}),()=>{B=!0}}}h("idle")},[J,e,M,a]),x.useEffect(()=>{t&&(U.reset(),f(null),h("idle"),ne(V))},[U,t]);const S=U.handleSubmit(async({name:oe,template:B})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=J?M.get(J):j.find(ee=>ee.name===B);let q,X=oe;if(!!J&&J!==Bn&&c===null){p({title:d==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:d==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(a){const ee=X.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),de=ht==="docx"?kg(ee):{name:ee,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};q=c||JSON.stringify(de,null,2);const fe=`.${ht}.theme.json`;X.endsWith(fe)||(X=X.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),X+=fe)}else{const ee=y;q=c||JSON.stringify(ht==="docx"?{name:"docx",props:{theme:(ee==null?void 0:ee.theme)||"default",metadata:{title:(ee==null?void 0:ee.title)||X.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(ee==null?void 0:ee.title)||X.replace(/\.(json|js)$/i,""),theme:(ee==null?void 0:ee.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 de=ht==="docx"?".docx.json":".pptx.json";!X.endsWith(de)&&!X.endsWith(".json")&&(X+=de)}const ie=X.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),D=ie?ie[0]:"",ue=X.slice(0,X.length-D.length);let he=X,ce=1;for(;w.some(ee=>ee.name===he);)ce++,he=`${ue} (${ce})${D}`;X=he,b(X,q),O(X),a&&v(X,q)}else if(e==="update"){const y=r,q=oe,X=_.includes(y);X&&C(y),N(y,q),$(y,q),X&&O(q)}else if(e==="delete"){const y=r;C(y),m(y),H(y),a&&k(y)}n()}finally{l(!1)}});return u.jsx(Vx,{...U,children:u.jsxs("form",{onSubmit:S,children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:g[e].title}),u.jsx(on,{children:g[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[A.properties&&"name"in A.properties&&u.jsx(gl,{control:U.control,name:"name",render:({field:oe})=>u.jsxs(za,{children:[u.jsx(Oa,{children:"Name"}),u.jsx(Pa,{children:u.jsx(hr,{placeholder:"Enter a name or select a template below",autoComplete:"off",...oe})}),u.jsx(Da,{})]})}),e==="create"&&u.jsx(gl,{control:U.control,name:"template",render:({field:oe})=>u.jsxs(za,{children:[u.jsx(Oa,{children:a?"Base Theme":"Base Document"}),u.jsxs(ti,{onValueChange:B=>{if(B===Bn)oe.onChange(void 0),U.setValue("name",""),ne(Bn),f(null);else{const y=M.get(B);y&&(oe.onChange(y.name),U.setValue("name",y.name),ne(B))}},defaultValue:V,children:[u.jsx(Pa,{children:u.jsx(fr,{children:u.jsx(ni,{placeholder:`Select a discovered ${a?"theme":"document"}`})})}),u.jsxs(pr,{className:"max-h-[300px]",children:[u.jsxs(Pn,{value:Bn,children:["Empty ",a?"theme":"document"]}),Object.entries(I).map(([B,y])=>y.length===0?null:u.jsxs(Zd,{children:[u.jsx(ho,{children:B==="current"?"📁 Current Directory":"📦 Project"}),y.map(q=>{let X;return q.title&&q.title!==q.name?X=q.title:q.description&&(X=q.description.length>40?q.description.substring(0,40)+"...":q.description),u.jsx(Pn,{value:q.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:q.name}),X&&u.jsx("span",{className:"text-muted-foreground text-xs",children:X})]})},q.path)})]},B))]})]}),u.jsxs(uf,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(Da,{})]})})]}),u.jsx(bn,{children:u.jsx(Se,{type:"submit",variant:g[e].buttonVariant,disabled:o,children:o?u.jsxs(u.Fragment,{children:[u.jsx(gn,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):g[e].button})})]})})}const Ki=je.memo(Yx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function wo({text:e,query:t}){if(!t)return u.jsx(u.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?u.jsx(u.Fragment,{children:e}):u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Ra({children:e,count:t,actions:n,className:r,open:i,onToggle:s}){const a=u.jsxs(u.Fragment,{children:[u.jsx(_r,{"aria-hidden":!0,className:G("size-3 shrink-0 transition-transform duration-150 ease-out",i&&"rotate-90")}),u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:e}),t!==void 0&&u.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t})]});return u.jsxs("div",{className:G("flex h-6 shrink-0 items-center gap-1.5 select-none",r),children:[u.jsx("button",{type:"button",onClick:s,"aria-expanded":i,className:G("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:a}),n&&u.jsx("div",{className:"flex shrink-0 items-center gap-0.5 pr-1",children:n})]})}const Ht=je.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:G("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}));Ht.displayName="RailIconButton";function xl({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:G("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function yl({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:G("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:[u.jsx(e,{className:"size-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:t})]}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const Kx=og,Xx=lg,Qx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(id,{ref:i,className:G("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,u.jsx(_r,{className:"ml-auto h-4 w-4"})]}));Qx.displayName=id.displayName;const ey=x.forwardRef(({className:e,...t},n)=>u.jsx(sd,{ref:n,className:G("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}));ey.displayName=sd.displayName;const ff=x.forwardRef(({className:e,...t},n)=>u.jsx(ug,{children:u.jsx(td,{ref:n,className:G("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})}));ff.displayName=td.displayName;const pf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(rd,{ref:r,className:G("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}));pf.displayName=rd.displayName;const ty=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(ad,{ref:i,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(od,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));ty.displayName=ad.displayName;const ny=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ld,{ref:r,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(od,{children:u.jsx(Td,{className:"h-4 w-4 fill-current"})})}),t]}));ny.displayName=ld.displayName;const ry=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{ref:r,className:G("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ry.displayName=ud.displayName;const hf=x.forwardRef(({className:e,...t},n)=>u.jsx(nd,{ref:n,className:G("bg-border -mx-1 my-1 h-px",e),...t}));hf.displayName=nd.displayName;const mf=({className:e,...t})=>u.jsx("span",{className:G("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});mf.displayName="ContextMenuShortcut";const Ns=cg,Es=dg,iy=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(hd,{ref:i,className:G("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,u.jsx(_r,{className:"ml-auto"})]}));iy.displayName=hd.displayName;const sy=x.forwardRef(({className:e,...t},n)=>u.jsx(md,{ref:n,className:G("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}));sy.displayName=md.displayName;const yi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(fg,{children:u.jsx(cd,{ref:r,sideOffset:t,className:G("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})}));yi.displayName=cd.displayName;const $t=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:G("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=dd.displayName;const ay=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(gd,{ref:i,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));ay.displayName=gd.displayName;const oy=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(yd,{ref:r,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(Td,{className:"h-2 w-2 fill-current"})})}),t]}));oy.displayName=yd.displayName;const ko=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(pd,{ref:r,className:G("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ko.displayName=pd.displayName;const mr=x.forwardRef(({className:e,...t},n)=>u.jsx(fd,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));mr.displayName=fd.displayName;const gf=({className:e,...t})=>u.jsx("span",{className:G("ml-auto text-xs tracking-widest opacity-60",e),...t});gf.displayName="DropdownMenuShortcut";const xf=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(bd,{ref:i,decorative:n,orientation:t,className:G("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));xf.displayName=bd.displayName;const yf=Jc,ly=pg,uy=Hc,bf=x.forwardRef(({className:e,...t},n)=>u.jsx(ws,{className:G("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}));bf.displayName=ws.displayName;const cy=gi("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"}}),So=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(uy,{children:[u.jsx(bf,{}),u.jsxs(ys,{ref:i,className:G(cy({side:e}),t),...r,children:[u.jsxs(co,{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:[u.jsx(yn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));So.displayName=ys.displayName;const dy=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-foreground text-lg font-semibold",e),...t}));dy.displayName=bs.displayName;const fy=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));fy.displayName=vs.displayName;function Yr({className:e,...t}){return u.jsx("div",{className:G("bg-primary/10 animate-pulse rounded-md",e),...t})}const qs=768,Gs=1200;function vf(e){return typeof window<"u"?window.innerWidth<e:!1}function wf(){const[e,t]=x.useState(()=>vf(qs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${qs-1}px)`),r=()=>{t(window.innerWidth<qs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function py(){const[e,t]=x.useState(()=>vf(Gs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Gs-1}px)`),r=()=>{t(window.innerWidth<Gs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const hy="sidebar_state",my=60*60*24*7,gy="16rem",xy="18rem",yy="3rem",by="b",kf=x.createContext(null);function Cs(){const e=x.useContext(kf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const Sf=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=wf(),[c,f]=x.useState(!1),[d,h]=x.useState(e),p=t??d,g=x.useCallback(N=>{const m=typeof N=="function"?N(p):N;n?n(m):h(m),document.cookie=`${hy}=${m}; path=/; max-age=${my}`},[n,p]),w=x.useCallback(()=>l?f(N=>!N):g(N=>!N),[l,g,f]);x.useEffect(()=>{const N=O=>{var k;const C=O;if(!C)return!1;const v=(k=C.tagName)==null?void 0:k.toLowerCase();return v==="input"||v==="textarea"||v==="select"||C.isContentEditable?!0:!!(C.closest&&C.closest(".monaco-editor"))},m=O=>{const C=O.metaKey||O.ctrlKey,v=O.key.toLowerCase();if(C&&v===by){O.preventDefault(),w();return}C&&v==="s"&&!N(O.target)&&(O.preventDefault(),w())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[w]);const _=p?"expanded":"collapsed",b=x.useMemo(()=>({state:_,open:p,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:f,toggleSidebar:w}),[_,p,g,l,c,f,w]);return u.jsx(kf.Provider,{value:b,children:u.jsx(Sg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":gy,"--sidebar-width-icon":yy,...i},className:G("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});Sf.displayName="SidebarProvider";const _f=x.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},a)=>{const{isMobile:o,state:l,openMobile:c,setOpenMobile:f}=Cs();return n==="none"?u.jsx("div",{className:G("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:a,...s,children:i}):o?u.jsx(yf,{open:c,onOpenChange:f,...s,children:u.jsx(So,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":xy},side:e,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):u.jsxs("div",{ref:a,className:"group peer text-sidebar-foreground hidden md:block","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":t,"data-side":e,children:[u.jsx("div",{className:G("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]")}),u.jsx("div",{className:G("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:u.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})})]})});_f.displayName="Sidebar";const vy=x.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=Cs();return u.jsxs(Se,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:G("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(Tg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});vy.displayName="SidebarTrigger";const wy=x.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=Cs();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:G("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})});wy.displayName="SidebarRail";const ky=x.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:G("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}));ky.displayName="SidebarInset";const Sy=x.forwardRef(({className:e,...t},n)=>u.jsx(hr,{ref:n,"data-sidebar":"input",className:G("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));Sy.displayName="SidebarInput";const Ma=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:G("flex flex-col gap-2 p-2",e),...t}));Ma.displayName="SidebarHeader";const jf=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:G("flex flex-col gap-2 p-2",e),...t}));jf.displayName="SidebarFooter";const _y=x.forwardRef(({className:e,...t},n)=>u.jsx(xf,{ref:n,"data-sidebar":"separator",className:G("bg-sidebar-border mx-2 w-auto",e),...t}));_y.displayName="SidebarSeparator";const $a=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:G("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));$a.displayName="SidebarContent";const jy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:G("relative flex w-full min-w-0 flex-col p-2",e),...t}));jy.displayName="SidebarGroup";const Ny=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?kr:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:G("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})});Ny.displayName="SidebarGroupLabel";const Ey=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?kr:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:G("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})});Ey.displayName="SidebarGroupAction";const Cy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:G("w-full text-sm",e),...t}));Cy.displayName="SidebarGroupContent";const Lr=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:G("flex w-full min-w-0 flex-col gap-1",e),...t}));Lr.displayName="SidebarMenu";const Nf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:G("group/menu-item relative",e),...t}));Nf.displayName="SidebarMenuItem";const Ty=gi("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"}}),Ef=x.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...a},o)=>{const l=e?kr:"button",{isMobile:c,state:f}=Cs(),d=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:G(Ty({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:d}),u.jsx(Xe,{side:"right",align:"center",hidden:f!=="collapsed"||c,...i})]})):d});Ef.displayName="SidebarMenuButton";const Cf=x.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?kr:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:G("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})});Cf.displayName="SidebarMenuAction";const Iy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:G("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}));Iy.displayName="SidebarMenuBadge";const Ay=x.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=x.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:G("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Yr,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Yr,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Ay.displayName="SidebarMenuSkeleton";const zy=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:G("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}));zy.displayName="SidebarMenuSub";const Oy=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Oy.displayName="SidebarMenuSubItem";const Py=x.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const a=e?kr:"a";return u.jsx(a,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:G("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})});Py.displayName="SidebarMenuSubButton";function Li(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 Dy=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Ry({document:e,compact:t=!1,query:n=""}){const r=x.useRef(null),[i,s]=x.useState(!1),[a,o]=x.useState(!1),[l,c]=x.useState(!1),[f,d]=x.useState(!1),h=Ne(B=>B.openDocument),p=Ne(B=>B.documentTypes),g=Ne(B=>B.activeTab),w=rn(B=>B.name),_=rn(B=>B.text),b=rn(B=>B.isGenerating),m=(p[e.name]||"application/json+report")==="application/json+theme",O=g===e.name,[C,v]=x.useState(w),[k,$]=x.useState(_),H=100,j=0;x.useEffect(()=>{const B=setTimeout(()=>{w&&_?(v(w),$(_)):b||(v(""),$(""))},b?H:j);return()=>clearTimeout(B)},[w,_,b]);const I=C===e.name,T=B=>{var q;const y=new Set;try{const X=JSON.parse(B);(q=X.props)!=null&&q.theme&&y.add(X.props.theme),X.children&&Array.isArray(X.children)&&X.children.forEach(Y=>{var ie;Y.name==="docx"&&((ie=Y.props)!=null&&ie.theme)&&y.add(Y.props.theme)})}catch{}return y},P=x.useMemo(()=>{if(!m||!k)return!1;try{const B=JSON.parse(e.text),y=sx(B);if(y)return T(k).has(y)}catch{}return!1},[m,k,e.text]),A=x.useCallback(()=>{c(!1)},[]),M=x.useCallback(()=>{d(!1)},[]),V=O?null:I?"preview":P?"in-use":null,U=O?"Editing":I?"In preview":P?"Used by preview":null,J=x.useMemo(()=>[{key:"open",label:"Open",shortcut:Dy?"⌘⏎":"⌃⏎",run:()=>h(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Li(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>d(!0)}],[e.name,e.text,e.type,h]),ne=m?Ig:Id,S=i||a,oe=u.jsxs(Ef,{size:"sm",ref:r,"aria-label":U?`${e.name} — ${U}`:e.name,className:G("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",S&&"bg-sidebar-accent/60 text-sidebar-foreground",O&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:U?`${e.name} — ${U}`:e.name,onClick:()=>{h(e.name)},onKeyDown:B=>{var y;(B.ctrlKey||B.metaKey)&&B.key==="Enter"?(h(e.name),B.preventDefault()):B.key==="Enter"?(c(!0),B.preventDefault()):B.key==="Backspace"||B.key==="Delete"?(d(!0),B.preventDefault()):B.key==="Escape"&&((y=r.current)==null||y.blur(),B.preventDefault())},children:[O&&u.jsx("span",{"aria-hidden":!0,className:G("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(ne,{className:G("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",O&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(wo,{text:e.name,query:n})}),t&&V&&u.jsx(xl,{tone:V,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(Nf,{children:[u.jsxs(Kx,{onOpenChange:s,children:[u.jsx(Xx,{className:"block",children:t?u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:oe}),u.jsx(Xe,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:U??(m?"Theme":"Document")})]})})]}):oe}),u.jsx(ff,{className:"w-44",children:J.map(B=>u.jsxs(je.Fragment,{children:[B.separatorBefore&&u.jsx(hf,{}),u.jsxs(pf,{onClick:B.run,className:G(B.danger&&"text-destructive focus:text-destructive"),children:[B.label,B.shortcut&&u.jsx(mf,{children:B.shortcut})]})]},B.key))})]}),!t&&u.jsxs(u.Fragment,{children:[V&&u.jsx(xl,{tone:V,className:G("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",a&&"opacity-0")}),u.jsxs(Ns,{onOpenChange:o,children:[u.jsx(Es,{asChild:!0,children:u.jsx(Cf,{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:u.jsx(Ad,{})})}),u.jsx(yi,{side:"right",align:"start",className:"w-44",children:J.map(B=>u.jsxs(je.Fragment,{children:[B.separatorBefore&&u.jsx(mr,{}),u.jsxs($t,{onClick:B.run,className:G(B.danger&&"text-destructive focus:text-destructive"),children:[B.label,B.shortcut&&u.jsx(gf,{children:B.shortcut})]})]},B.key))})]})]}),u.jsx(Ct,{open:l,onOpenChange:c,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:B=>{var y;B.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Ki,{mode:"update",shouldReset:!l,postSubmit:A,selectedName:e.name})})}),u.jsx(Ct,{open:f,onOpenChange:d,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:B=>{var y;B.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Ki,{mode:"delete",shouldReset:!f,postSubmit:M,selectedName:e.name})})})]})}const Ni=je.memo(Ry);function My(e,t=!1){const n=e.length;let r=0,i="",s=0,a=16,o=0,l=0,c=0,f=0,d=0;function h(m,O){let C=0,v=0;for(;C<m;){let k=e.charCodeAt(r);if(k>=48&&k<=57)v=v*16+k-48;else if(k>=65&&k<=70)v=v*16+k-65+10;else if(k>=97&&k<=102)v=v*16+k-97+10;else break;r++,C++}return C<m&&(v=-1),v}function p(m){r=m,i="",s=0,a=16,d=0}function g(){let m=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Zn(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Zn(e.charCodeAt(r)))for(r++;r<e.length&&Zn(e.charCodeAt(r));)r++;else return d=3,e.substring(m,r);let O=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Zn(e.charCodeAt(r))){for(r++;r<e.length&&Zn(e.charCodeAt(r));)r++;O=r}else d=3;return e.substring(m,O)}function w(){let m="",O=r;for(;;){if(r>=n){m+=e.substring(O,r),d=2;break}const C=e.charCodeAt(r);if(C===34){m+=e.substring(O,r),r++;break}if(C===92){if(m+=e.substring(O,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:m+='"';break;case 92:m+="\\";break;case 47:m+="/";break;case 98:m+="\b";break;case 102:m+="\f";break;case 110:m+=`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-gT4UjmPk.js","assets/react-vendor-BmQ2Ko_D.js","assets/editor-monaco-json-BYUK4OUI.js","assets/index-CgCY8SiY.js","assets/query-vendor--rhYD8mC.js","assets/radix-ui-DFNP5I4e.js","assets/ui-vendor-Bq4-oNFL.js","assets/monaco-editor-DJsdM0WK.js","assets/state-vendor-Cq67_JbF.js","assets/index-CrzIwHLS.css","assets/editor-refs-store-ChL2fzuX.js","assets/MonacoPluginProvider-CGvtVJKz.js","assets/useQualityAnalysis-eKT8VcIt.js","assets/preview-ZqhmQZJG.js"])))=>i.map(i=>d[i]);
2
+ var Km=Object.defineProperty;var Xm=(e,t,n)=>t in e?Km(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Vs=(e,t,n)=>Xm(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as je,R as Uc,g as uo}from"./react-vendor-BmQ2Ko_D.js";import{b as Jc,c as co,d as Hc,e as ys,f as bs,D as vs,O as ws,g as Qm,V as eg,G as tg,h as Wc,I as ng,i as rg,j as qc,k as ig,l as Gc,m as sg,n as ag,L as Yc,S as Kc,o as Xc,p as Qc,q as ed,r as kr,s as og,t as lg,u as ug,v as td,w as nd,x as rd,y as id,z as sd,B as ad,E as od,F as ld,H as ud,J as cg,K as dg,M as fg,N as cd,Q as dd,U as fd,W as pd,X as hd,Y as md,Z as gd,_ as xd,$ as yd,a0 as bd,a1 as pg,a2 as vd,a3 as hg,a4 as mg,a5 as wd,a6 as gg,a7 as xg,a8 as yg,a9 as bg,aa as kd,ab as Sd,ac as _d}from"./radix-ui-DFNP5I4e.js";import{c as G,u as Sr,S as gn,A as ei,T as _i,C as vg,E as wg,F as ht,a as kg,b as Sg,d as Ye,e as Ke,f as Xe,g as jd,_ as Nd,h as ji,i as _g,j as jg,k as Ng,l as Tr,s as Us,W as Ed,m as $i}from"./index-CgCY8SiY.js";import{X as yn,C as mi,a as an,b as Eg,d as gi,G as Cd,F as Cg,e as _r,f as Td,P as Tg,g as Ig,h as Id,E as Ad,B as _a,H as Ag,T as ja,L as Na,i as zg,j as Og,S as zd,I as Pg,k as Dg,l as Ea,m as Rg,n as Mg,o as $g,p as Fg,q as Lg,r as Bg,s as Zg,t as Vg,u as ks,v as Ug,M as Jg,w as nn,x as Od,y as Hg,z as Wg,A as Pd,D as qg,J as Gg,K as Yg,N as Kg,O as Xg,Q as Dd,R as Qg,U as Ca,V as fo,W as Rd,Y as ex,Z as Md,_ as Fr,$ as tx,a0 as nx,a1 as rx,a2 as il,a3 as Ta}from"./ui-vendor-Bq4-oNFL.js";import{B as Se,u as $d,d as sl}from"./editor-refs-store-ChL2fzuX.js";import{u as Ne,i as ix,a as Ia,b as rn,g as sx,c as Lt,T as Fd,d as Hi,e as Ld,S as ax,O as ox,f as lx,M as ux,D as cx}from"./MonacoPluginProvider-CGvtVJKz.js";import{u as po,a as dx,d as fx,p as px,b as hx,e as mx}from"./state-vendor-Cq67_JbF.js";import{b as gx}from"./query-vendor--rhYD8mC.js";const Ct=Jc,xx=Hc,al=co,Bd=x.forwardRef(({className:e,...t},n)=>u.jsx(ws,{ref:n,className:G("fixed inset-0 z-50 bg-black/50",e),...t}));Bd.displayName=ws.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(xx,{children:[u.jsx(Bd,{}),u.jsxs(ys,{ref:r,className:G("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,u.jsxs(co,{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:[u.jsx(yn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));kt.displayName=ys.displayName;const Vt=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Vt.displayName="DialogHeader";const bn=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});bn.displayName="DialogFooter";const Ut=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-lg leading-none font-semibold tracking-tight",e),...t}));Ut.displayName=bs.displayName;const on=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));on.displayName=vs.displayName;const ti=Qm,Zd=tg,ni=eg,fr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Wc,{ref:r,className:G("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,u.jsx(ng,{asChild:!0,children:u.jsx(mi,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));fr.displayName=Wc.displayName;const Vd=x.forwardRef(({className:e,...t},n)=>u.jsx(Kc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Eg,{className:"h-4 w-4"})}));Vd.displayName=Kc.displayName;const Ud=x.forwardRef(({className:e,...t},n)=>u.jsx(Xc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(mi,{className:"h-4 w-4"})}));Ud.displayName=Xc.displayName;const pr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(rg,{children:u.jsxs(qc,{ref:i,className:G("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:[u.jsx(Vd,{}),u.jsx(ig,{className:G("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Ud,{})]})}));pr.displayName=qc.displayName;const ho=x.forwardRef(({className:e,...t},n)=>u.jsx(Yc,{ref:n,className:G("px-2 py-1.5 text-sm font-semibold",e),...t}));ho.displayName=Yc.displayName;const Pn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Gc,{ref:r,className:G("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:[u.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(sg,{children:u.jsx(an,{className:"h-4 w-4"})})}),u.jsx(ag,{children:t})]}));Pn.displayName=Gc.displayName;const yx=x.forwardRef(({className:e,...t},n)=>u.jsx(Qc,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));yx.displayName=Qc.displayName;const hr=x.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:G("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}));hr.displayName="Input";const bx=gi("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Wr=x.forwardRef(({className:e,...t},n)=>u.jsx(ed,{ref:n,className:G(bx(),e),...t}));Wr.displayName=ed.displayName;const vx=gi("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 Kt({className:e,variant:t,...n}){return u.jsx("div",{className:G(vx({variant:t}),e),...n})}const wx=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Ne(po(I=>({documents:I.documents,documentTypes:I.documentTypes,activeTab:I.activeTab,createDocument:I.createDocument,openDocument:I.openDocument}))),{toast:o}=Sr(),l=x.useMemo(()=>n.filter(I=>r[I.name]!=="application/json+theme"),[n,r]),[c,f]=x.useState(""),[d,h]=x.useState(""),[p,g]=x.useState("playground"),[w,_]=x.useState(!1),[b,N]=x.useState(null),[m,O]=x.useState(null),[C,v]=x.useState(null),k=()=>{N(null),O(null),v(null)};x.useEffect(()=>{if(!e)return;N(null),O(null),v(null);const I=l.map(P=>P.name),T=I.includes(i)?i:I[0]??"";h(T),f(I.find(P=>P!==T)??"")},[e]);const $=async()=>{const I=l.find(P=>P.name===c),T=l.find(P=>P.name===d);if(!(!I||!T)){_(!0),N(null),O(null),v(null);try{const P=await fetch(ei.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:I.text,newDefinition:T.text,options:{author:p||"playground"}})}),A=await P.json();if(!P.ok||!A.success){const M=Array.isArray(A.errors)?`: ${A.errors.slice(0,3).map(V=>V.message||String(V)).join("; ")}`:"";throw new Error((A.error||`Diff failed (${P.status})`)+M)}O(A.data.summary),v(A.data.document)}catch(P){N(P instanceof Error?P.message:"Diff failed")}finally{_(!1)}}},H=()=>{if(!C)return;const I=new Set(n.map(A=>A.name));let T=`${d}-redline`,P=2;for(;I.has(T);)T=`${d}-redline-${P++}`;s(T,JSON.stringify(C,null,2)),a(T),o({title:`Redline created: ${T}`}),t(!1)},j=m?m.tracked.modified+m.tracked.inserted+m.tracked.deleted:0;return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"sm:max-w-[560px]",children:[u.jsxs(Vt,{children:[u.jsxs(Ut,{className:"flex items-center gap-2",children:[u.jsx(Cd,{className:"size-4"}),"Compare documents"]}),u.jsx(on,{children:"Diff two versions into a redline with native Word tracked changes (accept/reject in Word)."})]}),u.jsxs("div",{className:"grid gap-4 py-2",children:[u.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(ti,{value:c,onValueChange:I=>{f(I),k()},children:[u.jsx(fr,{id:"diff-base",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(I=>u.jsx(Pn,{value:I.name,children:I.name},I.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(ti,{value:d,onValueChange:I=>{h(I),k()},children:[u.jsx(fr,{id:"diff-revised",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(I=>u.jsx(Pn,{value:I.name,children:I.name},I.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(hr,{id:"diff-author",value:p,onChange:I=>{g(I.target.value),k()},placeholder:"playground"})]}),b&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:b}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Kt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),j===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((I,T)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[I.path," [",I.component,"] ",I.detail]},T))]}),m.notes.map((I,T)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",I]},T))]})]}),u.jsx(bn,{children:m&&j+m.untracked.length>0?u.jsxs(Se,{onClick:H,children:[u.jsx(Cg,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Se,{onClick:$,disabled:w||!c||!d||c===d,children:[w&&u.jsx(gn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var xi=e=>e.type==="checkbox",In=e=>e instanceof Date,ft=e=>e==null;const Jd=e=>typeof e=="object";var et=e=>!ft(e)&&!Array.isArray(e)&&Jd(e)&&!In(e),Hd=e=>et(e)&&e.target?xi(e.target)?e.target.checked:e.target.value:e,kx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Wd=(e,t)=>e.has(kx(t)),Sx=e=>{const t=e.constructor&&e.constructor.prototype;return et(t)&&t.hasOwnProperty("isPrototypeOf")},mo=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function yt(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(!(mo&&(e instanceof Blob||r))&&(n||et(e)))if(t=n?[]:{},!n&&!Sx(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=yt(e[i]));else return e;return t}var Ss=e=>Array.isArray(e)?e.filter(Boolean):[],Qe=e=>e===void 0,le=(e,t,n)=>{if(!t||!et(e))return n;const r=Ss(t.split(/[,[\].]+?/)).reduce((i,s)=>ft(i)?i:i[s],e);return Qe(r)||r===e?Qe(e[t])?n:e[t]:r},zt=e=>typeof e=="boolean",go=e=>/^\w*$/.test(e),qd=e=>Ss(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Me=(e,t,n)=>{let r=-1;const i=go(t)?[t]:qd(t),s=i.length,a=s-1;for(;++r<s;){const o=i[r];let l=n;if(r!==a){const c=e[o];l=et(c)||Array.isArray(c)?c:isNaN(+i[r+1])?{}:[]}if(o==="__proto__"||o==="constructor"||o==="prototype")return;e[o]=l,e=e[o]}return e};const Wi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ft={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},tn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Gd=je.createContext(null),_s=()=>je.useContext(Gd),_x=e=>{const{children:t,...n}=e;return je.createElement(Gd.Provider,{value:n},t)};var Yd=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const a=s;return t._proxyFormState[a]!==Ft.all&&(t._proxyFormState[a]=!r||Ft.all),n&&(n[a]=!0),e[a]}});return i},bt=e=>et(e)&&!Object.keys(e).length,Kd=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return bt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(a=>t[a]===(!r||Ft.all))},qr=e=>Array.isArray(e)?e:[e],Xd=(e,t,n)=>!e||!t||e===t||qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function xo(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 jx(e){const t=_s(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[a,o]=je.useState(n._formState),l=je.useRef(!0),c=je.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),f=je.useRef(i);return f.current=i,xo({disabled:r,next:d=>l.current&&Xd(f.current,d.name,s)&&Kd(d,c.current,n._updateFormState)&&o({...n._formState,...d}),subject:n._subjects.state}),je.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),je.useMemo(()=>Yd(a,n,c.current,!1),[a,n])}var Yt=e=>typeof e=="string",Qd=(e,t,n,r,i)=>Yt(e)?(r&&t.watch.add(e),le(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),le(n,s))):(r&&(t.watchAll=!0),n);function Nx(e){const t=_s(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=je.useRef(r);o.current=r,xo({disabled:s,subject:n._subjects.values,next:f=>{Xd(o.current,f.name,a)&&c(yt(Qd(o.current,n._names,f.values||n._formValues,!1,i)))}});const[l,c]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),l}function Ex(e){const t=_s(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=Wd(i._names.array,n),o=Nx({control:i,name:n,defaultValue:le(i._formValues,n,le(i._defaultValues,n,e.defaultValue)),exact:!0}),l=jx({control:i,name:n,exact:!0}),c=je.useRef(i.register(n,{...e.rules,value:o,...zt(e.disabled)?{disabled:e.disabled}:{}})),f=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!le(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!le(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!le(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!le(l.validatingFields,n)},error:{enumerable:!0,get:()=>le(l.errors,n)}}),[l,n]),d=je.useMemo(()=>({name:n,value:o,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:h=>c.current.onChange({target:{value:Hd(h),name:n},type:Wi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:le(i._formValues,n),name:n},type:Wi.BLUR}),ref:h=>{const p=le(i._fields,n);p&&h&&(p._f.ref={focus:()=>h.focus(),select:()=>h.select(),setCustomValidity:g=>h.setCustomValidity(g),reportValidity:()=>h.reportValidity()})}}),[n,i._formValues,r,l.disabled,o,i._fields]);return je.useEffect(()=>{const h=i._options.shouldUnregister||s,p=(g,w)=>{const _=le(i._fields,g);_&&_._f&&(_._f.mount=w)};if(p(n,!0),h){const g=yt(le(i._options.defaultValues,n));Me(i._defaultValues,n,g),Qe(le(i._formValues,n))&&Me(i._formValues,n,g)}return!a&&i.register(n),()=>{(a?h&&!i._state.action:h)?i.unregister(n):p(n,!1)}},[n,i,a,s]),je.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),je.useMemo(()=>({field:d,formState:l,fieldState:f}),[d,l,f])}const Cx=e=>e.render(Ex(e));var Tx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},ol=e=>({isOnSubmit:!e||e===Ft.onSubmit,isOnBlur:e===Ft.onBlur,isOnChange:e===Ft.onChange,isOnAll:e===Ft.all,isOnTouch:e===Ft.onTouched}),ll=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Gr=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=le(e,i);if(s){const{_f:a,...o}=s;if(a){if(a.refs&&a.refs[0]&&t(a.refs[0],i)&&!r)return!0;if(a.ref&&t(a.ref,a.name)&&!r)return!0;if(Gr(o,t))break}else if(et(o)&&Gr(o,t))break}}};var Ix=(e,t,n)=>{const r=qr(le(e,n));return Me(r,"root",t[n]),Me(e,n,r),e},yo=e=>e.type==="file",Gt=e=>typeof e=="function",qi=e=>{if(!mo)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Fi=e=>Yt(e),bo=e=>e.type==="radio",Gi=e=>e instanceof RegExp;const ul={value:!1,isValid:!1},cl={value:!0,isValid:!0};var ef=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&&!Qe(e[0].attributes.value)?Qe(e[0].value)||e[0].value===""?cl:{value:e[0].value,isValid:!0}:cl:ul}return ul};const dl={isValid:!1,value:null};var tf=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,dl):dl;function fl(e,t,n="validate"){if(Fi(e)||Array.isArray(e)&&e.every(Fi)||zt(e)&&!e)return{type:n,message:Fi(e)?e:"",ref:t}}var Ln=e=>et(e)&&!Gi(e)?e:{value:e,message:""},pl=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:f,min:d,max:h,pattern:p,validate:g,name:w,valueAsNumber:_,mount:b}=e._f,N=le(n,w);if(!b||t.has(w))return{};const m=o?o[0]:a,O=T=>{i&&m.reportValidity&&(m.setCustomValidity(zt(T)?"":T||""),m.reportValidity())},C={},v=bo(a),k=xi(a),$=v||k,H=(_||yo(a))&&Qe(a.value)&&Qe(N)||qi(a)&&a.value===""||N===""||Array.isArray(N)&&!N.length,j=Tx.bind(null,w,r,C),I=(T,P,A,M=tn.maxLength,V=tn.minLength)=>{const U=T?P:A;C[w]={type:T?M:V,message:U,ref:a,...j(T?M:V,U)}};if(s?!Array.isArray(N)||!N.length:l&&(!$&&(H||ft(N))||zt(N)&&!N||k&&!ef(o).isValid||v&&!tf(o).isValid)){const{value:T,message:P}=Fi(l)?{value:!!l,message:l}:Ln(l);if(T&&(C[w]={type:tn.required,message:P,ref:m,...j(tn.required,P)},!r))return O(P),C}if(!H&&(!ft(d)||!ft(h))){let T,P;const A=Ln(h),M=Ln(d);if(!ft(N)&&!isNaN(N)){const V=a.valueAsNumber||N&&+N;ft(A.value)||(T=V>A.value),ft(M.value)||(P=V<M.value)}else{const V=a.valueAsDate||new Date(N),U=S=>new Date(new Date().toDateString()+" "+S),J=a.type=="time",ne=a.type=="week";Yt(A.value)&&N&&(T=J?U(N)>U(A.value):ne?N>A.value:V>new Date(A.value)),Yt(M.value)&&N&&(P=J?U(N)<U(M.value):ne?N<M.value:V<new Date(M.value))}if((T||P)&&(I(!!T,A.message,M.message,tn.max,tn.min),!r))return O(C[w].message),C}if((c||f)&&!H&&(Yt(N)||s&&Array.isArray(N))){const T=Ln(c),P=Ln(f),A=!ft(T.value)&&N.length>+T.value,M=!ft(P.value)&&N.length<+P.value;if((A||M)&&(I(A,T.message,P.message),!r))return O(C[w].message),C}if(p&&!H&&Yt(N)){const{value:T,message:P}=Ln(p);if(Gi(T)&&!N.match(T)&&(C[w]={type:tn.pattern,message:P,ref:a,...j(tn.pattern,P)},!r))return O(P),C}if(g){if(Gt(g)){const T=await g(N,n),P=fl(T,m);if(P&&(C[w]={...P,...j(tn.validate,P.message)},!r))return O(P.message),C}else if(et(g)){let T={};for(const P in g){if(!bt(T)&&!r)break;const A=fl(await g[P](N,n),m,P);A&&(T={...A,...j(P,A.message)},O(A.message),r&&(C[w]=T))}if(!bt(T)&&(C[w]={ref:m,...T},!r))return C}}return O(!0),C};function Ax(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Qe(e)?r++:e[t[r++]];return e}function zx(e){for(const t in e)if(e.hasOwnProperty(t)&&!Qe(e[t]))return!1;return!0}function it(e,t){const n=Array.isArray(t)?t:go(t)?[t]:qd(t),r=n.length===1?e:Ax(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(et(r)&&bt(r)||Array.isArray(r)&&zx(r))&&it(e,n.slice(0,-1)),e}var Js=()=>{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=[]}}},Aa=e=>ft(e)||!Jd(e);function hn(e,t){if(Aa(e)||Aa(t))return e===t;if(In(e)&&In(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 a=t[i];if(In(s)&&In(a)||et(s)&&et(a)||Array.isArray(s)&&Array.isArray(a)?!hn(s,a):s!==a)return!1}}return!0}var nf=e=>e.type==="select-multiple",Ox=e=>bo(e)||xi(e),Hs=e=>qi(e)&&e.isConnected,rf=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Yi(e,t={}){const n=Array.isArray(e);if(et(e)||n)for(const r in e)Array.isArray(e[r])||et(e[r])&&!rf(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Yi(e[r],t[r])):ft(e[r])||(t[r]=!0);return t}function sf(e,t,n){const r=Array.isArray(e);if(et(e)||r)for(const i in e)Array.isArray(e[i])||et(e[i])&&!rf(e[i])?Qe(t)||Aa(n[i])?n[i]=Array.isArray(e[i])?Yi(e[i],[]):{...Yi(e[i])}:sf(e[i],ft(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Ir=(e,t)=>sf(e,t,Yi(t)),af=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Qe(e)?e:t?e===""?NaN:e&&+e:n&&Yt(e)?new Date(e):r?r(e):e;function Ws(e){const t=e.ref;return yo(t)?t.files:bo(t)?tf(e.refs).value:nf(t)?[...t.selectedOptions].map(({value:n})=>n):xi(t)?ef(e.refs).value:af(Qe(t.value)?e.ref.value:t.value,e)}var Px=(e,t,n,r)=>{const i={};for(const s of e){const a=le(t,s);a&&Me(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Ar=e=>Qe(e)?e:Gi(e)?e.source:et(e)?Gi(e.value)?e.value.source:e.value:e;const hl="AsyncFunction";var Dx=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===hl||et(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===hl)),Rx=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function ml(e,t,n){const r=le(e,n);if(r||go(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=le(t,s),o=le(e,s);if(a&&!Array.isArray(a)&&n!==s)return{name:n};if(o&&o.type)return{name:s,error:o};i.pop()}return{name:n}}var Mx=(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,$x=(e,t)=>!Ss(le(e,t)).length&&it(e,t);const Fx={mode:Ft.onSubmit,reValidateMode:Ft.onChange,shouldFocusError:!0};function Lx(e={}){let t={...Fx,...e},n={submitCount:0,isDirty:!1,isLoading:Gt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=et(t.defaultValues)||et(t.values)?yt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:yt(i),a={action:!1,mount:!1,watch:!1},o={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const f={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={values:Js(),array:Js(),state:Js()},h=ol(t.mode),p=ol(t.reValidateMode),g=t.criteriaMode===Ft.all,w=E=>R=>{clearTimeout(c),c=setTimeout(E,R)},_=async E=>{if(!t.disabled&&(f.isValid||E)){const R=t.resolver?bt((await $()).errors):await j(r,!0);R!==n.isValid&&d.state.next({isValid:R})}},b=(E,R)=>{!t.disabled&&(f.isValidating||f.validatingFields)&&((E||Array.from(o.mount)).forEach(Z=>{Z&&(R?Me(n.validatingFields,Z,R):it(n.validatingFields,Z))}),d.state.next({validatingFields:n.validatingFields,isValidating:!bt(n.validatingFields)}))},N=(E,R=[],Z,se,z=!0,K=!0)=>{if(se&&Z&&!t.disabled){if(a.action=!0,K&&Array.isArray(le(r,E))){const te=Z(le(r,E),se.argA,se.argB);z&&Me(r,E,te)}if(K&&Array.isArray(le(n.errors,E))){const te=Z(le(n.errors,E),se.argA,se.argB);z&&Me(n.errors,E,te),$x(n.errors,E)}if(f.touchedFields&&K&&Array.isArray(le(n.touchedFields,E))){const te=Z(le(n.touchedFields,E),se.argA,se.argB);z&&Me(n.touchedFields,E,te)}f.dirtyFields&&(n.dirtyFields=Ir(i,s)),d.state.next({name:E,isDirty:T(E,R),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Me(s,E,R)},m=(E,R)=>{Me(n.errors,E,R),d.state.next({errors:n.errors})},O=E=>{n.errors=E,d.state.next({errors:n.errors,isValid:!1})},C=(E,R,Z,se)=>{const z=le(r,E);if(z){const K=le(s,E,Qe(Z)?le(i,E):Z);Qe(K)||se&&se.defaultChecked||R?Me(s,E,R?K:Ws(z._f)):M(E,K),a.mount&&_()}},v=(E,R,Z,se,z)=>{let K=!1,te=!1;const xe={name:E};if(!t.disabled){const L=!!(le(r,E)&&le(r,E)._f&&le(r,E)._f.disabled);if(!Z||se){f.isDirty&&(te=n.isDirty,n.isDirty=xe.isDirty=T(),K=te!==xe.isDirty);const Q=L||hn(le(i,E),R);te=!!(!L&&le(n.dirtyFields,E)),Q||L?it(n.dirtyFields,E):Me(n.dirtyFields,E,!0),xe.dirtyFields=n.dirtyFields,K=K||f.dirtyFields&&te!==!Q}if(Z){const Q=le(n.touchedFields,E);Q||(Me(n.touchedFields,E,Z),xe.touchedFields=n.touchedFields,K=K||f.touchedFields&&Q!==Z)}K&&z&&d.state.next(xe)}return K?xe:{}},k=(E,R,Z,se)=>{const z=le(n.errors,E),K=f.isValid&&zt(R)&&n.isValid!==R;if(t.delayError&&Z?(l=w(()=>m(E,Z)),l(t.delayError)):(clearTimeout(c),l=null,Z?Me(n.errors,E,Z):it(n.errors,E)),(Z?!hn(z,Z):z)||!bt(se)||K){const te={...se,...K&&zt(R)?{isValid:R}:{},errors:n.errors,name:E};n={...n,...te},d.state.next(te)}},$=async E=>{b(E,!0);const R=await t.resolver(s,t.context,Px(E||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(E),R},H=async E=>{const{errors:R}=await $(E);if(E)for(const Z of E){const se=le(R,Z);se?Me(n.errors,Z,se):it(n.errors,Z)}else n.errors=R;return R},j=async(E,R,Z={valid:!0})=>{for(const se in E){const z=E[se];if(z){const{_f:K,...te}=z;if(K){const xe=o.array.has(K.name),L=z._f&&Dx(z._f);L&&f.validatingFields&&b([se],!0);const Q=await pl(z,o.disabled,s,g,t.shouldUseNativeValidation&&!R,xe);if(L&&f.validatingFields&&b([se]),Q[K.name]&&(Z.valid=!1,R))break;!R&&(le(Q,K.name)?xe?Ix(n.errors,Q,K.name):Me(n.errors,K.name,Q[K.name]):it(n.errors,K.name))}!bt(te)&&await j(te,R,Z)}}return Z.valid},I=()=>{for(const E of o.unMount){const R=le(r,E);R&&(R._f.refs?R._f.refs.every(Z=>!Hs(Z)):!Hs(R._f.ref))&&Y(E)}o.unMount=new Set},T=(E,R)=>!t.disabled&&(E&&R&&Me(s,E,R),!hn(oe(),i)),P=(E,R,Z)=>Qd(E,o,{...a.mount?s:Qe(R)?i:Yt(E)?{[E]:R}:R},Z,R),A=E=>Ss(le(a.mount?s:i,E,t.shouldUnregister?le(i,E,[]):[])),M=(E,R,Z={})=>{const se=le(r,E);let z=R;if(se){const K=se._f;K&&(!K.disabled&&Me(s,E,af(R,K)),z=qi(K.ref)&&ft(R)?"":R,nf(K.ref)?[...K.ref.options].forEach(te=>te.selected=z.includes(te.value)):K.refs?xi(K.ref)?K.refs.length>1?K.refs.forEach(te=>(!te.defaultChecked||!te.disabled)&&(te.checked=Array.isArray(z)?!!z.find(xe=>xe===te.value):z===te.value)):K.refs[0]&&(K.refs[0].checked=!!z):K.refs.forEach(te=>te.checked=te.value===z):yo(K.ref)?K.ref.value="":(K.ref.value=z,K.ref.type||d.values.next({name:E,values:{...s}})))}(Z.shouldDirty||Z.shouldTouch)&&v(E,z,Z.shouldTouch,Z.shouldDirty,!0),Z.shouldValidate&&S(E)},V=(E,R,Z)=>{for(const se in R){const z=R[se],K=`${E}.${se}`,te=le(r,K);(o.array.has(E)||et(z)||te&&!te._f)&&!In(z)?V(K,z,Z):M(K,z,Z)}},U=(E,R,Z={})=>{const se=le(r,E),z=o.array.has(E),K=yt(R);Me(s,E,K),z?(d.array.next({name:E,values:{...s}}),(f.isDirty||f.dirtyFields)&&Z.shouldDirty&&d.state.next({name:E,dirtyFields:Ir(i,s),isDirty:T(E,K)})):se&&!se._f&&!ft(K)?V(E,K,Z):M(E,K,Z),ll(E,o)&&d.state.next({...n}),d.values.next({name:a.mount?E:void 0,values:{...s}})},J=async E=>{a.mount=!0;const R=E.target;let Z=R.name,se=!0;const z=le(r,Z),K=()=>R.type?Ws(z._f):Hd(E),te=xe=>{se=Number.isNaN(xe)||In(xe)&&isNaN(xe.getTime())||hn(xe,le(s,Z,xe))};if(z){let xe,L;const Q=K(),me=E.type===Wi.BLUR||E.type===Wi.FOCUS_OUT,ve=!Rx(z._f)&&!t.resolver&&!le(n.errors,Z)&&!z._f.deps||Mx(me,le(n.touchedFields,Z),n.isSubmitted,p,h),F=ll(Z,o,me);Me(s,Z,Q),me?(z._f.onBlur&&z._f.onBlur(E),l&&l(0)):z._f.onChange&&z._f.onChange(E);const ge=v(Z,Q,me,!1),Te=!bt(ge)||F;if(!me&&d.values.next({name:Z,type:E.type,values:{...s}}),ve)return f.isValid&&(t.mode==="onBlur"&&me?_():me||_()),Te&&d.state.next({name:Z,...F?{}:ge});if(!me&&F&&d.state.next({...n}),t.resolver){const{errors:Le}=await $([Z]);if(te(Q),se){const rt=ml(n.errors,r,Z),tt=ml(Le,r,rt.name||Z);xe=tt.error,Z=tt.name,L=bt(Le)}}else b([Z],!0),xe=(await pl(z,o.disabled,s,g,t.shouldUseNativeValidation))[Z],b([Z]),te(Q),se&&(xe?L=!1:f.isValid&&(L=await j(r,!0)));se&&(z._f.deps&&S(z._f.deps),k(Z,L,xe,ge))}},ne=(E,R)=>{if(le(n.errors,R)&&E.focus)return E.focus(),1},S=async(E,R={})=>{let Z,se;const z=qr(E);if(t.resolver){const K=await H(Qe(E)?E:z);Z=bt(K),se=E?!z.some(te=>le(K,te)):Z}else E?(se=(await Promise.all(z.map(async K=>{const te=le(r,K);return await j(te&&te._f?{[K]:te}:te)}))).every(Boolean),!(!se&&!n.isValid)&&_()):se=Z=await j(r);return d.state.next({...!Yt(E)||f.isValid&&Z!==n.isValid?{}:{name:E},...t.resolver||!E?{isValid:Z}:{},errors:n.errors}),R.shouldFocus&&!se&&Gr(r,ne,E?z:o.mount),se},oe=E=>{const R={...a.mount?s:i};return Qe(E)?R:Yt(E)?le(R,E):E.map(Z=>le(R,Z))},B=(E,R)=>({invalid:!!le((R||n).errors,E),isDirty:!!le((R||n).dirtyFields,E),error:le((R||n).errors,E),isValidating:!!le(n.validatingFields,E),isTouched:!!le((R||n).touchedFields,E)}),y=E=>{E&&qr(E).forEach(R=>it(n.errors,R)),d.state.next({errors:E?n.errors:{}})},q=(E,R,Z)=>{const se=(le(r,E,{_f:{}})._f||{}).ref,z=le(n.errors,E)||{},{ref:K,message:te,type:xe,...L}=z;Me(n.errors,E,{...L,...R,ref:se}),d.state.next({name:E,errors:n.errors,isValid:!1}),Z&&Z.shouldFocus&&se&&se.focus&&se.focus()},X=(E,R)=>Gt(E)?d.values.subscribe({next:Z=>E(P(void 0,R),Z)}):P(E,R,!0),Y=(E,R={})=>{for(const Z of E?qr(E):o.mount)o.mount.delete(Z),o.array.delete(Z),R.keepValue||(it(r,Z),it(s,Z)),!R.keepError&&it(n.errors,Z),!R.keepDirty&&it(n.dirtyFields,Z),!R.keepTouched&&it(n.touchedFields,Z),!R.keepIsValidating&&it(n.validatingFields,Z),!t.shouldUnregister&&!R.keepDefaultValue&&it(i,Z);d.values.next({values:{...s}}),d.state.next({...n,...R.keepDirty?{isDirty:T()}:{}}),!R.keepIsValid&&_()},ie=({disabled:E,name:R,field:Z,fields:se})=>{(zt(E)&&a.mount||E||o.disabled.has(R))&&(E?o.disabled.add(R):o.disabled.delete(R),v(R,Ws(Z?Z._f:le(se,R)._f),!1,!1,!0))},D=(E,R={})=>{let Z=le(r,E);const se=zt(R.disabled)||zt(t.disabled);return Me(r,E,{...Z||{},_f:{...Z&&Z._f?Z._f:{ref:{name:E}},name:E,mount:!0,...R}}),o.mount.add(E),Z?ie({field:Z,disabled:zt(R.disabled)?R.disabled:t.disabled,name:E}):C(E,!0,R.value),{...se?{disabled:R.disabled||t.disabled}:{},...t.progressive?{required:!!R.required,min:Ar(R.min),max:Ar(R.max),minLength:Ar(R.minLength),maxLength:Ar(R.maxLength),pattern:Ar(R.pattern)}:{},name:E,onChange:J,onBlur:J,ref:z=>{if(z){D(E,R),Z=le(r,E);const K=Qe(z.value)&&z.querySelectorAll&&z.querySelectorAll("input,select,textarea")[0]||z,te=Ox(K),xe=Z._f.refs||[];if(te?xe.find(L=>L===K):K===Z._f.ref)return;Me(r,E,{_f:{...Z._f,...te?{refs:[...xe.filter(Hs),K,...Array.isArray(le(i,E))?[{}]:[]],ref:{type:K.type,name:E}}:{ref:K}}}),C(E,!1,void 0,K)}else Z=le(r,E,{}),Z._f&&(Z._f.mount=!1),(t.shouldUnregister||R.shouldUnregister)&&!(Wd(o.array,E)&&a.action)&&o.unMount.add(E)}}},ue=()=>t.shouldFocusError&&Gr(r,ne,o.mount),he=E=>{zt(E)&&(d.state.next({disabled:E}),Gr(r,(R,Z)=>{const se=le(r,Z);se&&(R.disabled=se._f.disabled||E,Array.isArray(se._f.refs)&&se._f.refs.forEach(z=>{z.disabled=se._f.disabled||E}))},0,!1))},ce=(E,R)=>async Z=>{let se;Z&&(Z.preventDefault&&Z.preventDefault(),Z.persist&&Z.persist());let z=yt(s);if(o.disabled.size)for(const K of o.disabled)Me(z,K,void 0);if(d.state.next({isSubmitting:!0}),t.resolver){const{errors:K,values:te}=await $();n.errors=K,z=te}else await j(r);if(it(n.errors,"root"),bt(n.errors)){d.state.next({errors:{}});try{await E(z,Z)}catch(K){se=K}}else R&&await R({...n.errors},Z),ue(),setTimeout(ue);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bt(n.errors)&&!se,submitCount:n.submitCount+1,errors:n.errors}),se)throw se},ee=(E,R={})=>{le(r,E)&&(Qe(R.defaultValue)?U(E,yt(le(i,E))):(U(E,R.defaultValue),Me(i,E,yt(R.defaultValue))),R.keepTouched||it(n.touchedFields,E),R.keepDirty||(it(n.dirtyFields,E),n.isDirty=R.defaultValue?T(E,yt(le(i,E))):T()),R.keepError||(it(n.errors,E),f.isValid&&_()),d.state.next({...n}))},de=(E,R={})=>{const Z=E?yt(E):i,se=yt(Z),z=bt(E),K=z?i:se;if(R.keepDefaultValues||(i=Z),!R.keepValues){if(R.keepDirtyValues){const te=new Set([...o.mount,...Object.keys(Ir(i,s))]);for(const xe of Array.from(te))le(n.dirtyFields,xe)?Me(K,xe,le(s,xe)):U(xe,le(K,xe))}else{if(mo&&Qe(E))for(const te of o.mount){const xe=le(r,te);if(xe&&xe._f){const L=Array.isArray(xe._f.refs)?xe._f.refs[0]:xe._f.ref;if(qi(L)){const Q=L.closest("form");if(Q){Q.reset();break}}}}r={}}s=t.shouldUnregister?R.keepDefaultValues?yt(i):{}:yt(K),d.array.next({values:{...K}}),d.values.next({values:{...K}})}o={mount:R.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!f.isValid||!!R.keepIsValid||!!R.keepDirtyValues,a.watch=!!t.shouldUnregister,d.state.next({submitCount:R.keepSubmitCount?n.submitCount:0,isDirty:z?!1:R.keepDirty?n.isDirty:!!(R.keepDefaultValues&&!hn(E,i)),isSubmitted:R.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:z?{}:R.keepDirtyValues?R.keepDefaultValues&&s?Ir(i,s):n.dirtyFields:R.keepDefaultValues&&E?Ir(i,E):R.keepDirty?n.dirtyFields:{},touchedFields:R.keepTouched?n.touchedFields:{},errors:R.keepErrors?n.errors:{},isSubmitSuccessful:R.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},fe=(E,R)=>de(Gt(E)?E(s):E,R);return{control:{register:D,unregister:Y,getFieldState:B,handleSubmit:ce,setError:q,_executeSchema:$,_getWatch:P,_getDirty:T,_updateValid:_,_removeUnmounted:I,_updateFieldArray:N,_updateDisabledField:ie,_getFieldArray:A,_reset:de,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(E=>{fe(E,t.resetOptions),d.state.next({isLoading:!1})}),_updateFormState:E=>{n={...n,...E}},_disableForm:he,_subjects:d,_proxyFormState:f,_setErrors:O,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(E){a=E},get _defaultValues(){return i},get _names(){return o},set _names(E){o=E},get _formState(){return n},set _formState(E){n=E},get _options(){return t},set _options(E){t={...t,...E}}},trigger:S,register:D,handleSubmit:ce,watch:X,setValue:U,getValues:oe,reset:fe,resetField:ee,clearErrors:y,unregister:Y,setError:q,setFocus:(E,R={})=>{const Z=le(r,E),se=Z&&Z._f;if(se){const z=se.refs?se.refs[0]:se.ref;z.focus&&(z.focus(),R.shouldSelect&&Gt(z.select)&&z.select())}},getFieldState:B}}function Bx(e={}){const t=je.useRef(void 0),n=je.useRef(void 0),[r,i]=je.useState({isDirty:!1,isValidating:!1,isLoading:Gt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Gt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Lx(e),formState:r});const s=t.current.control;return s._options=e,xo({subject:s._subjects.state,next:a=>{Kd(a,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),je.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),je.useEffect(()=>{if(s._proxyFormState.isDirty){const a=s._getDirty();a!==r.isDirty&&s._subjects.state.next({isDirty:a})}},[s,r.isDirty]),je.useEffect(()=>{e.values&&!hn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(a=>({...a}))):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=Yd(r,s),t.current}function Zx(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 Vx=_x,of=x.createContext({}),gl=({...e})=>u.jsx(of.Provider,{value:{name:e.name},children:u.jsx(Cx,{...e})}),js=()=>{const e=x.useContext(of),t=x.useContext(lf),{getFieldState:n,formState:r}=_s(),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}},lf=x.createContext({}),za=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(lf.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:G("space-y-2",e),...t})})});za.displayName="FormItem";const Oa=x.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=js();return u.jsx(Wr,{ref:n,className:G(r&&"text-destructive",e),htmlFor:i,...t})});Oa.displayName="FormLabel";const Pa=x.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=js();return u.jsx(kr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Pa.displayName="FormControl";const uf=x.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=js();return u.jsx("p",{ref:n,id:r,className:G("text-muted-foreground text-[0.8rem]",e),...t})});uf.displayName="FormDescription";const Da=x.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=js(),a=i?String(i==null?void 0:i.message):t;return a?u.jsx("p",{ref:r,id:s,className:G("text-destructive text-[0.8rem] font-medium",e),...n,children:a}):null});Da.displayName="FormMessage";function vo(){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 cf=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Ux=(e=cf())=>dx()(fx(px((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,a)=>a!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),a={id:i,documentName:r,title:vo(),messages:[],createdAt:s,updatedAt:s};return t(o=>({threads:{...o.threads,[i]:a},activeThreadId:{...o.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const a=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),o=s.documentName,l={...i.activeThreadId};if(l[o]===r){const c=Object.values(a).filter(f=>f.documentName===o);c.length>0?(c.sort((f,d)=>d.updatedAt-f.updatedAt),l[o]=c[0].id):delete l[o]}t({threads:a,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(a=>({activeThreadId:{...a.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},a={...i.activeThreadId};for(const[o,l]of Object.entries(s))l.documentName===r&&delete s[o];return delete a[r],{threads:s,activeThreadId:a}})},renameThreadsForDocument:(r,i)=>{t(s=>{const a={...s.threads},o={...s.activeThreadId};for(const[l,c]of Object.entries(a))c.documentName===r&&(a[l]={...c,documentName:i});return r in o&&(o[i]=o[r],delete o[r]),{threads:a,activeThreadId:o}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:hx(()=>ix),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 t}}))),df=x.createContext(void 0),Jx=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Ux(cf())),u.jsx(df.Provider,{value:t.current,children:e})},Pe=e=>{const t=x.useContext(df);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return mx(t,e)};function Hx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Wx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=_i.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),i.push("name")),e==="create"&&(r.template=_i.Optional(_i.String({description:"Template selection"})));const s=_i.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:a=>{const o=[];if(!vg(s,a))for(const c of wg(s,a))o.push({path:c.path.replace(/^\//,""),message:c.message});const l=a;if(e!=="delete"&&l.name){const c=l.name.trim();c?(l.name=c,t(c)||o.push({path:"name",message:"Document with this name already exists"})):o.push({path:"name",message:"Name can't be empty"})}return e==="create"&&(n!=null&&n.length)&&l.template&&(n.some(c=>c.name===l.template)||o.push({path:"template",message:"You must select a valid template"})),{success:o.length===0,data:o.length===0?l:void 0,errors:o}}}}function qx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Gx=e=>({create:{title:e?"New Theme":"New Document",description:e?"Create a new theme from scratch or based on discovered themes.":"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"}}),Bn="__empty__";function Yx({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=x.useState(!1),[c,f]=x.useState(null),[d,h]=x.useState("idle"),{toast:p}=Sr(),g=Gx(a),{documents:w,openTabs:_,createDocument:b,renameDocument:N,deleteDocument:m,openDocument:O,closeDocument:C}=Ne(oe=>oe),{updateTheme:v,removeTheme:k}=Ia(oe=>oe),$=Pe(oe=>oe.renameThreadsForDocument),H=Pe(oe=>oe.deleteThreadsForDocument),j=x.useMemo(()=>a?s||[]:i||[],[a,i,s]),I=x.useMemo(()=>{const oe={current:[],downstream:[]};return j.forEach(B=>{oe[B.location]&&oe[B.location].push(B)}),oe},[j]),T=x.useMemo(()=>j.map(oe=>({name:oe.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[j]),P=x.useMemo(()=>Wx(e,oe=>Hx(oe,w,r),T),[e,w,r,T]),A=P.schema,M=x.useMemo(()=>{const oe=new Map;return j.forEach(B=>oe.set(B.path,B)),oe},[j]),V=Bn,U=Bx({resolver:Zx(P.validate),defaultValues:qx(e,void 0,r)}),[J,ne]=x.useState(V);x.useEffect(()=>{if(J&&J!==Bn&&e==="create"){const oe=M.get(J);if(oe){f(null),h("loading");let B=!1;return fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(oe.name)}/content`).then(y=>{if(!y.ok)throw new Error(`Failed to fetch content: ${y.statusText}`);return y.text()}).then(y=>{if(B)return;const q=JSON.parse(y);f(JSON.stringify(q,null,2)),h("idle")}).catch(y=>{B||(console.error("Failed to copy template:",y),f(null),h("error"))}),()=>{B=!0}}}h("idle")},[J,e,M,a]),x.useEffect(()=>{t&&(U.reset(),f(null),h("idle"),ne(V))},[U,t]);const S=U.handleSubmit(async({name:oe,template:B})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=J?M.get(J):j.find(ee=>ee.name===B);let q,X=oe;if(!!J&&J!==Bn&&c===null){p({title:d==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:d==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(a){const ee=X.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),de=ht==="docx"?kg(ee):{name:ee,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};q=c||JSON.stringify(de,null,2);const fe=`.${ht}.theme.json`;X.endsWith(fe)||(X=X.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),X+=fe)}else{const ee=y;q=c||JSON.stringify(ht==="docx"?{name:"docx",props:{theme:(ee==null?void 0:ee.theme)||"default",metadata:{title:(ee==null?void 0:ee.title)||X.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(ee==null?void 0:ee.title)||X.replace(/\.(json|js)$/i,""),theme:(ee==null?void 0:ee.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 de=ht==="docx"?".docx.json":".pptx.json";!X.endsWith(de)&&!X.endsWith(".json")&&(X+=de)}const ie=X.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),D=ie?ie[0]:"",ue=X.slice(0,X.length-D.length);let he=X,ce=1;for(;w.some(ee=>ee.name===he);)ce++,he=`${ue} (${ce})${D}`;X=he,b(X,q),O(X),a&&v(X,q)}else if(e==="update"){const y=r,q=oe,X=_.includes(y);X&&C(y),N(y,q),$(y,q),X&&O(q)}else if(e==="delete"){const y=r;C(y),m(y),H(y),a&&k(y)}n()}finally{l(!1)}});return u.jsx(Vx,{...U,children:u.jsxs("form",{onSubmit:S,children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:g[e].title}),u.jsx(on,{children:g[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[A.properties&&"name"in A.properties&&u.jsx(gl,{control:U.control,name:"name",render:({field:oe})=>u.jsxs(za,{children:[u.jsx(Oa,{children:"Name"}),u.jsx(Pa,{children:u.jsx(hr,{placeholder:"Enter a name or select a template below",autoComplete:"off",...oe})}),u.jsx(Da,{})]})}),e==="create"&&u.jsx(gl,{control:U.control,name:"template",render:({field:oe})=>u.jsxs(za,{children:[u.jsx(Oa,{children:a?"Base Theme":"Base Document"}),u.jsxs(ti,{onValueChange:B=>{if(B===Bn)oe.onChange(void 0),U.setValue("name",""),ne(Bn),f(null);else{const y=M.get(B);y&&(oe.onChange(y.name),U.setValue("name",y.name),ne(B))}},defaultValue:V,children:[u.jsx(Pa,{children:u.jsx(fr,{children:u.jsx(ni,{placeholder:`Select a discovered ${a?"theme":"document"}`})})}),u.jsxs(pr,{className:"max-h-[300px]",children:[u.jsxs(Pn,{value:Bn,children:["Empty ",a?"theme":"document"]}),Object.entries(I).map(([B,y])=>y.length===0?null:u.jsxs(Zd,{children:[u.jsx(ho,{children:B==="current"?"📁 Current Directory":"📦 Project"}),y.map(q=>{let X;return q.title&&q.title!==q.name?X=q.title:q.description&&(X=q.description.length>40?q.description.substring(0,40)+"...":q.description),u.jsx(Pn,{value:q.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:q.name}),X&&u.jsx("span",{className:"text-muted-foreground text-xs",children:X})]})},q.path)})]},B))]})]}),u.jsxs(uf,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(Da,{})]})})]}),u.jsx(bn,{children:u.jsx(Se,{type:"submit",variant:g[e].buttonVariant,disabled:o,children:o?u.jsxs(u.Fragment,{children:[u.jsx(gn,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):g[e].button})})]})})}const Ki=je.memo(Yx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function wo({text:e,query:t}){if(!t)return u.jsx(u.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?u.jsx(u.Fragment,{children:e}):u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Ra({children:e,count:t,actions:n,className:r,open:i,onToggle:s}){const a=u.jsxs(u.Fragment,{children:[u.jsx(_r,{"aria-hidden":!0,className:G("size-3 shrink-0 transition-transform duration-150 ease-out",i&&"rotate-90")}),u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:e}),t!==void 0&&u.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t})]});return u.jsxs("div",{className:G("flex h-6 shrink-0 items-center gap-1.5 select-none",r),children:[u.jsx("button",{type:"button",onClick:s,"aria-expanded":i,className:G("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:a}),n&&u.jsx("div",{className:"flex shrink-0 items-center gap-0.5 pr-1",children:n})]})}const Ht=je.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:G("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}));Ht.displayName="RailIconButton";function xl({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:G("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function yl({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:G("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:[u.jsx(e,{className:"size-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:t})]}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const Kx=og,Xx=lg,Qx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(id,{ref:i,className:G("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,u.jsx(_r,{className:"ml-auto h-4 w-4"})]}));Qx.displayName=id.displayName;const ey=x.forwardRef(({className:e,...t},n)=>u.jsx(sd,{ref:n,className:G("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}));ey.displayName=sd.displayName;const ff=x.forwardRef(({className:e,...t},n)=>u.jsx(ug,{children:u.jsx(td,{ref:n,className:G("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})}));ff.displayName=td.displayName;const pf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(rd,{ref:r,className:G("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}));pf.displayName=rd.displayName;const ty=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(ad,{ref:i,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(od,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));ty.displayName=ad.displayName;const ny=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ld,{ref:r,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(od,{children:u.jsx(Td,{className:"h-4 w-4 fill-current"})})}),t]}));ny.displayName=ld.displayName;const ry=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{ref:r,className:G("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ry.displayName=ud.displayName;const hf=x.forwardRef(({className:e,...t},n)=>u.jsx(nd,{ref:n,className:G("bg-border -mx-1 my-1 h-px",e),...t}));hf.displayName=nd.displayName;const mf=({className:e,...t})=>u.jsx("span",{className:G("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});mf.displayName="ContextMenuShortcut";const Ns=cg,Es=dg,iy=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(hd,{ref:i,className:G("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,u.jsx(_r,{className:"ml-auto"})]}));iy.displayName=hd.displayName;const sy=x.forwardRef(({className:e,...t},n)=>u.jsx(md,{ref:n,className:G("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}));sy.displayName=md.displayName;const yi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(fg,{children:u.jsx(cd,{ref:r,sideOffset:t,className:G("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})}));yi.displayName=cd.displayName;const $t=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:G("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=dd.displayName;const ay=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(gd,{ref:i,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));ay.displayName=gd.displayName;const oy=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(yd,{ref:r,className:G("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:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(xd,{children:u.jsx(Td,{className:"h-2 w-2 fill-current"})})}),t]}));oy.displayName=yd.displayName;const ko=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(pd,{ref:r,className:G("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ko.displayName=pd.displayName;const mr=x.forwardRef(({className:e,...t},n)=>u.jsx(fd,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));mr.displayName=fd.displayName;const gf=({className:e,...t})=>u.jsx("span",{className:G("ml-auto text-xs tracking-widest opacity-60",e),...t});gf.displayName="DropdownMenuShortcut";const xf=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(bd,{ref:i,decorative:n,orientation:t,className:G("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));xf.displayName=bd.displayName;const yf=Jc,ly=pg,uy=Hc,bf=x.forwardRef(({className:e,...t},n)=>u.jsx(ws,{className:G("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}));bf.displayName=ws.displayName;const cy=gi("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"}}),So=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(uy,{children:[u.jsx(bf,{}),u.jsxs(ys,{ref:i,className:G(cy({side:e}),t),...r,children:[u.jsxs(co,{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:[u.jsx(yn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));So.displayName=ys.displayName;const dy=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-foreground text-lg font-semibold",e),...t}));dy.displayName=bs.displayName;const fy=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));fy.displayName=vs.displayName;function Yr({className:e,...t}){return u.jsx("div",{className:G("bg-primary/10 animate-pulse rounded-md",e),...t})}const qs=768,Gs=1200;function vf(e){return typeof window<"u"?window.innerWidth<e:!1}function wf(){const[e,t]=x.useState(()=>vf(qs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${qs-1}px)`),r=()=>{t(window.innerWidth<qs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function py(){const[e,t]=x.useState(()=>vf(Gs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Gs-1}px)`),r=()=>{t(window.innerWidth<Gs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const hy="sidebar_state",my=60*60*24*7,gy="16rem",xy="18rem",yy="3rem",by="b",kf=x.createContext(null);function Cs(){const e=x.useContext(kf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const Sf=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=wf(),[c,f]=x.useState(!1),[d,h]=x.useState(e),p=t??d,g=x.useCallback(N=>{const m=typeof N=="function"?N(p):N;n?n(m):h(m),document.cookie=`${hy}=${m}; path=/; max-age=${my}`},[n,p]),w=x.useCallback(()=>l?f(N=>!N):g(N=>!N),[l,g,f]);x.useEffect(()=>{const N=O=>{var k;const C=O;if(!C)return!1;const v=(k=C.tagName)==null?void 0:k.toLowerCase();return v==="input"||v==="textarea"||v==="select"||C.isContentEditable?!0:!!(C.closest&&C.closest(".monaco-editor"))},m=O=>{const C=O.metaKey||O.ctrlKey,v=O.key.toLowerCase();if(C&&v===by){O.preventDefault(),w();return}C&&v==="s"&&!N(O.target)&&(O.preventDefault(),w())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[w]);const _=p?"expanded":"collapsed",b=x.useMemo(()=>({state:_,open:p,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:f,toggleSidebar:w}),[_,p,g,l,c,f,w]);return u.jsx(kf.Provider,{value:b,children:u.jsx(Sg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":gy,"--sidebar-width-icon":yy,...i},className:G("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});Sf.displayName="SidebarProvider";const _f=x.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},a)=>{const{isMobile:o,state:l,openMobile:c,setOpenMobile:f}=Cs();return n==="none"?u.jsx("div",{className:G("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:a,...s,children:i}):o?u.jsx(yf,{open:c,onOpenChange:f,...s,children:u.jsx(So,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":xy},side:e,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):u.jsxs("div",{ref:a,className:"group peer text-sidebar-foreground hidden md:block","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":t,"data-side":e,children:[u.jsx("div",{className:G("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]")}),u.jsx("div",{className:G("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:u.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})})]})});_f.displayName="Sidebar";const vy=x.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=Cs();return u.jsxs(Se,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:G("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(Tg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});vy.displayName="SidebarTrigger";const wy=x.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=Cs();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:G("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})});wy.displayName="SidebarRail";const ky=x.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:G("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}));ky.displayName="SidebarInset";const Sy=x.forwardRef(({className:e,...t},n)=>u.jsx(hr,{ref:n,"data-sidebar":"input",className:G("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));Sy.displayName="SidebarInput";const Ma=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:G("flex flex-col gap-2 p-2",e),...t}));Ma.displayName="SidebarHeader";const jf=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:G("flex flex-col gap-2 p-2",e),...t}));jf.displayName="SidebarFooter";const _y=x.forwardRef(({className:e,...t},n)=>u.jsx(xf,{ref:n,"data-sidebar":"separator",className:G("bg-sidebar-border mx-2 w-auto",e),...t}));_y.displayName="SidebarSeparator";const $a=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:G("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));$a.displayName="SidebarContent";const jy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:G("relative flex w-full min-w-0 flex-col p-2",e),...t}));jy.displayName="SidebarGroup";const Ny=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?kr:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:G("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})});Ny.displayName="SidebarGroupLabel";const Ey=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?kr:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:G("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})});Ey.displayName="SidebarGroupAction";const Cy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:G("w-full text-sm",e),...t}));Cy.displayName="SidebarGroupContent";const Lr=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:G("flex w-full min-w-0 flex-col gap-1",e),...t}));Lr.displayName="SidebarMenu";const Nf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:G("group/menu-item relative",e),...t}));Nf.displayName="SidebarMenuItem";const Ty=gi("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"}}),Ef=x.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...a},o)=>{const l=e?kr:"button",{isMobile:c,state:f}=Cs(),d=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:G(Ty({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:d}),u.jsx(Xe,{side:"right",align:"center",hidden:f!=="collapsed"||c,...i})]})):d});Ef.displayName="SidebarMenuButton";const Cf=x.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?kr:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:G("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})});Cf.displayName="SidebarMenuAction";const Iy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:G("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}));Iy.displayName="SidebarMenuBadge";const Ay=x.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=x.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:G("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Yr,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Yr,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Ay.displayName="SidebarMenuSkeleton";const zy=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:G("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}));zy.displayName="SidebarMenuSub";const Oy=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Oy.displayName="SidebarMenuSubItem";const Py=x.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const a=e?kr:"a";return u.jsx(a,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:G("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})});Py.displayName="SidebarMenuSubButton";function Li(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 Dy=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Ry({document:e,compact:t=!1,query:n=""}){const r=x.useRef(null),[i,s]=x.useState(!1),[a,o]=x.useState(!1),[l,c]=x.useState(!1),[f,d]=x.useState(!1),h=Ne(B=>B.openDocument),p=Ne(B=>B.documentTypes),g=Ne(B=>B.activeTab),w=rn(B=>B.name),_=rn(B=>B.text),b=rn(B=>B.isGenerating),m=(p[e.name]||"application/json+report")==="application/json+theme",O=g===e.name,[C,v]=x.useState(w),[k,$]=x.useState(_),H=100,j=0;x.useEffect(()=>{const B=setTimeout(()=>{w&&_?(v(w),$(_)):b||(v(""),$(""))},b?H:j);return()=>clearTimeout(B)},[w,_,b]);const I=C===e.name,T=B=>{var q;const y=new Set;try{const X=JSON.parse(B);(q=X.props)!=null&&q.theme&&y.add(X.props.theme),X.children&&Array.isArray(X.children)&&X.children.forEach(Y=>{var ie;Y.name==="docx"&&((ie=Y.props)!=null&&ie.theme)&&y.add(Y.props.theme)})}catch{}return y},P=x.useMemo(()=>{if(!m||!k)return!1;try{const B=JSON.parse(e.text),y=sx(B);if(y)return T(k).has(y)}catch{}return!1},[m,k,e.text]),A=x.useCallback(()=>{c(!1)},[]),M=x.useCallback(()=>{d(!1)},[]),V=O?null:I?"preview":P?"in-use":null,U=O?"Editing":I?"In preview":P?"Used by preview":null,J=x.useMemo(()=>[{key:"open",label:"Open",shortcut:Dy?"⌘⏎":"⌃⏎",run:()=>h(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Li(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>d(!0)}],[e.name,e.text,e.type,h]),ne=m?Ig:Id,S=i||a,oe=u.jsxs(Ef,{size:"sm",ref:r,"aria-label":U?`${e.name} — ${U}`:e.name,className:G("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",S&&"bg-sidebar-accent/60 text-sidebar-foreground",O&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:U?`${e.name} — ${U}`:e.name,onClick:()=>{h(e.name)},onKeyDown:B=>{var y;(B.ctrlKey||B.metaKey)&&B.key==="Enter"?(h(e.name),B.preventDefault()):B.key==="Enter"?(c(!0),B.preventDefault()):B.key==="Backspace"||B.key==="Delete"?(d(!0),B.preventDefault()):B.key==="Escape"&&((y=r.current)==null||y.blur(),B.preventDefault())},children:[O&&u.jsx("span",{"aria-hidden":!0,className:G("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(ne,{className:G("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",O&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(wo,{text:e.name,query:n})}),t&&V&&u.jsx(xl,{tone:V,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(Nf,{children:[u.jsxs(Kx,{onOpenChange:s,children:[u.jsx(Xx,{className:"block",children:t?u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:oe}),u.jsx(Xe,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:U??(m?"Theme":"Document")})]})})]}):oe}),u.jsx(ff,{className:"w-44",children:J.map(B=>u.jsxs(je.Fragment,{children:[B.separatorBefore&&u.jsx(hf,{}),u.jsxs(pf,{onClick:B.run,className:G(B.danger&&"text-destructive focus:text-destructive"),children:[B.label,B.shortcut&&u.jsx(mf,{children:B.shortcut})]})]},B.key))})]}),!t&&u.jsxs(u.Fragment,{children:[V&&u.jsx(xl,{tone:V,className:G("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",a&&"opacity-0")}),u.jsxs(Ns,{onOpenChange:o,children:[u.jsx(Es,{asChild:!0,children:u.jsx(Cf,{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:u.jsx(Ad,{})})}),u.jsx(yi,{side:"right",align:"start",className:"w-44",children:J.map(B=>u.jsxs(je.Fragment,{children:[B.separatorBefore&&u.jsx(mr,{}),u.jsxs($t,{onClick:B.run,className:G(B.danger&&"text-destructive focus:text-destructive"),children:[B.label,B.shortcut&&u.jsx(gf,{children:B.shortcut})]})]},B.key))})]})]}),u.jsx(Ct,{open:l,onOpenChange:c,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:B=>{var y;B.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Ki,{mode:"update",shouldReset:!l,postSubmit:A,selectedName:e.name})})}),u.jsx(Ct,{open:f,onOpenChange:d,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:B=>{var y;B.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Ki,{mode:"delete",shouldReset:!f,postSubmit:M,selectedName:e.name})})})]})}const Ni=je.memo(Ry);function My(e,t=!1){const n=e.length;let r=0,i="",s=0,a=16,o=0,l=0,c=0,f=0,d=0;function h(m,O){let C=0,v=0;for(;C<m;){let k=e.charCodeAt(r);if(k>=48&&k<=57)v=v*16+k-48;else if(k>=65&&k<=70)v=v*16+k-65+10;else if(k>=97&&k<=102)v=v*16+k-97+10;else break;r++,C++}return C<m&&(v=-1),v}function p(m){r=m,i="",s=0,a=16,d=0}function g(){let m=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Zn(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Zn(e.charCodeAt(r)))for(r++;r<e.length&&Zn(e.charCodeAt(r));)r++;else return d=3,e.substring(m,r);let O=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Zn(e.charCodeAt(r))){for(r++;r<e.length&&Zn(e.charCodeAt(r));)r++;O=r}else d=3;return e.substring(m,O)}function w(){let m="",O=r;for(;;){if(r>=n){m+=e.substring(O,r),d=2;break}const C=e.charCodeAt(r);if(C===34){m+=e.substring(O,r),r++;break}if(C===92){if(m+=e.substring(O,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:m+='"';break;case 92:m+="\\";break;case 47:m+="/";break;case 98:m+="\b";break;case 102:m+="\f";break;case 110:m+=`
3
3
  `;break;case 114:m+="\r";break;case 116:m+=" ";break;case 117:const k=h(4);k>=0?m+=String.fromCharCode(k):d=4;break;default:d=5}O=r;continue}if(C>=0&&C<=31)if(zr(C)){m+=e.substring(O,r),d=2;break}else d=6;r++}return m}function _(){if(i="",d=0,s=r,l=o,f=c,r>=n)return s=n,a=17;let m=e.charCodeAt(r);if(Ys(m)){do r++,i+=String.fromCharCode(m),m=e.charCodeAt(r);while(Ys(m));return a=15}if(zr(m))return r++,i+=String.fromCharCode(m),m===13&&e.charCodeAt(r)===10&&(r++,i+=`
4
4
  `),o++,c=r,a=14;switch(m){case 123:return r++,a=1;case 125:return r++,a=2;case 91:return r++,a=3;case 93:return r++,a=4;case 58:return r++,a=6;case 44:return r++,a=5;case 34:return r++,i=w(),a=10;case 47:const O=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!zr(e.charCodeAt(r));)r++;return i=e.substring(O,r),a=12}if(e.charCodeAt(r+1)===42){r+=2;const C=n-1;let v=!1;for(;r<C;){const k=e.charCodeAt(r);if(k===42&&e.charCodeAt(r+1)===47){r+=2,v=!0;break}r++,zr(k)&&(k===13&&e.charCodeAt(r)===10&&r++,o++,c=r)}return v||(r++,d=1),i=e.substring(O,r),a=13}return i+=String.fromCharCode(m),r++,a=16;case 45:if(i+=String.fromCharCode(m),r++,r===n||!Zn(e.charCodeAt(r)))return a=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=g(),a=11;default:for(;r<n&&b(m);)r++,m=e.charCodeAt(r);if(s!==r){switch(i=e.substring(s,r),i){case"true":return a=8;case"false":return a=9;case"null":return a=7}return a=16}return i+=String.fromCharCode(m),r++,a=16}}function b(m){if(Ys(m)||zr(m))return!1;switch(m){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function N(){let m;do m=_();while(m>=12&&m<=15);return m}return{setPosition:p,getPosition:()=>r,scan:t?N:_,getToken:()=>a,getTokenValue:()=>i,getTokenOffset:()=>s,getTokenLength:()=>r-s,getTokenStartLine:()=>l,getTokenStartCharacter:()=>s-f,getTokenError:()=>d}}function Ys(e){return e===32||e===9}function zr(e){return e===10||e===13}function Zn(e){return e>=48&&e<=57}var bl;(function(e){e[e.lineFeed=10]="lineFeed",e[e.carriageReturn=13]="carriageReturn",e[e.space=32]="space",e[e._0=48]="_0",e[e._1=49]="_1",e[e._2=50]="_2",e[e._3=51]="_3",e[e._4=52]="_4",e[e._5=53]="_5",e[e._6=54]="_6",e[e._7=55]="_7",e[e._8=56]="_8",e[e._9=57]="_9",e[e.a=97]="a",e[e.b=98]="b",e[e.c=99]="c",e[e.d=100]="d",e[e.e=101]="e",e[e.f=102]="f",e[e.g=103]="g",e[e.h=104]="h",e[e.i=105]="i",e[e.j=106]="j",e[e.k=107]="k",e[e.l=108]="l",e[e.m=109]="m",e[e.n=110]="n",e[e.o=111]="o",e[e.p=112]="p",e[e.q=113]="q",e[e.r=114]="r",e[e.s=115]="s",e[e.t=116]="t",e[e.u=117]="u",e[e.v=118]="v",e[e.w=119]="w",e[e.x=120]="x",e[e.y=121]="y",e[e.z=122]="z",e[e.A=65]="A",e[e.B=66]="B",e[e.C=67]="C",e[e.D=68]="D",e[e.E=69]="E",e[e.F=70]="F",e[e.G=71]="G",e[e.H=72]="H",e[e.I=73]="I",e[e.J=74]="J",e[e.K=75]="K",e[e.L=76]="L",e[e.M=77]="M",e[e.N=78]="N",e[e.O=79]="O",e[e.P=80]="P",e[e.Q=81]="Q",e[e.R=82]="R",e[e.S=83]="S",e[e.T=84]="T",e[e.U=85]="U",e[e.V=86]="V",e[e.W=87]="W",e[e.X=88]="X",e[e.Y=89]="Y",e[e.Z=90]="Z",e[e.asterisk=42]="asterisk",e[e.backslash=92]="backslash",e[e.closeBrace=125]="closeBrace",e[e.closeBracket=93]="closeBracket",e[e.colon=58]="colon",e[e.comma=44]="comma",e[e.dot=46]="dot",e[e.doubleQuote=34]="doubleQuote",e[e.minus=45]="minus",e[e.openBrace=123]="openBrace",e[e.openBracket=91]="openBracket",e[e.plus=43]="plus",e[e.slash=47]="slash",e[e.formFeed=12]="formFeed",e[e.tab=9]="tab"})(bl||(bl={}));new Array(20).fill(0).map((e,t)=>" ".repeat(t));const Vn=200;new Array(Vn).fill(0).map((e,t)=>`
5
5
  `+" ".repeat(t)),new Array(Vn).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(Vn).fill(0).map((e,t)=>`\r
6
6
  `+" ".repeat(t)),new Array(Vn).fill(0).map((e,t)=>`
7
7
  `+" ".repeat(t)),new Array(Vn).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(Vn).fill(0).map((e,t)=>`\r
8
8
  `+" ".repeat(t));var Xi;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Xi||(Xi={}));function $y(e,t=[],n=Xi.DEFAULT){let r={type:"array",offset:-1,length:-1,children:[],parent:void 0};function i(l){r.type==="property"&&(r.length=l-r.offset,r=r.parent)}function s(l){return r.children.push(l),l}Ly(e,{onObjectBegin:l=>{r=s({type:"object",offset:l,length:-1,parent:r,children:[]})},onObjectProperty:(l,c,f)=>{r=s({type:"property",offset:c,length:-1,parent:r,children:[]}),r.children.push({type:"string",value:l,offset:c,length:f,parent:r})},onObjectEnd:(l,c)=>{i(l+c),r.length=l+c-r.offset,r=r.parent,i(l+c)},onArrayBegin:(l,c)=>{r=s({type:"array",offset:l,length:-1,parent:r,children:[]})},onArrayEnd:(l,c)=>{r.length=l+c-r.offset,r=r.parent,i(l+c)},onLiteralValue:(l,c,f)=>{s({type:By(l),offset:c,length:f,parent:r,value:l}),i(c+f)},onSeparator:(l,c,f)=>{r.type==="property"&&(l===":"?r.colonOffset=c:l===","&&i(c))},onError:(l,c,f)=>{t.push({error:l,offset:c,length:f})}},n);const o=r.children[0];return o&&delete o.parent,o}function Fy(e,t){if(!e)return;let n=e;for(let r of t)if(typeof r=="string"){if(n.type!=="object"||!Array.isArray(n.children))return;let i=!1;for(const s of n.children)if(Array.isArray(s.children)&&s.children[0].value===r&&s.children.length===2){n=s.children[1],i=!0;break}if(!i)return}else{const i=r;if(n.type!=="array"||i<0||!Array.isArray(n.children)||i>=n.children.length)return;n=n.children[i]}return n}function Ly(e,t,n=Xi.DEFAULT){const r=My(e,!1),i=[];let s=0;function a(A){return A?()=>s===0&&A(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function o(A){return A?M=>s===0&&A(M,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function l(A){return A?M=>s===0&&A(M,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function c(A){return A?()=>{s>0?s++:A(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(s=1)}:()=>!0}function f(A){return A?()=>{s>0&&s--,s===0&&A(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}const d=c(t.onObjectBegin),h=l(t.onObjectProperty),p=f(t.onObjectEnd),g=c(t.onArrayBegin),w=f(t.onArrayEnd),_=l(t.onLiteralValue),b=o(t.onSeparator),N=a(t.onComment),m=o(t.onError),O=n&&n.disallowComments,C=n&&n.allowTrailingComma;function v(){for(;;){const A=r.scan();switch(r.getTokenError()){case 4:k(14);break;case 5:k(15);break;case 3:k(13);break;case 1:O||k(11);break;case 2:k(12);break;case 6:k(16);break}switch(A){case 12:case 13:O?k(10):N();break;case 16:k(1);break;case 15:case 14:break;default:return A}}}function k(A,M=[],V=[]){if(m(A),M.length+V.length>0){let U=r.getToken();for(;U!==17;){if(M.indexOf(U)!==-1){v();break}else if(V.indexOf(U)!==-1)break;U=v()}}}function $(A){const M=r.getTokenValue();return A?_(M):(h(M),i.push(M)),v(),!0}function H(){switch(r.getToken()){case 11:const A=r.getTokenValue();let M=Number(A);isNaN(M)&&(k(2),M=0),_(M);break;case 7:_(null);break;case 8:_(!0);break;case 9:_(!1);break;default:return!1}return v(),!0}function j(){return r.getToken()!==10?(k(3,[],[2,5]),!1):($(!1),r.getToken()===6?(b(":"),v(),P()||k(4,[],[2,5])):k(5,[],[2,5]),i.pop(),!0)}function I(){d(),v();let A=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(A||k(4,[],[]),b(","),v(),r.getToken()===2&&C)break}else A&&k(6,[],[]);j()||k(4,[],[2,5]),A=!0}return p(),r.getToken()!==2?k(7,[2],[]):v(),!0}function T(){g(),v();let A=!0,M=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(M||k(4,[],[]),b(","),v(),r.getToken()===4&&C)break}else M&&k(6,[],[]);A?(i.push(0),A=!1):i[i.length-1]++,P()||k(4,[],[4,5]),M=!0}return w(),A||i.pop(),r.getToken()!==4?k(8,[4],[]):v(),!0}function P(){switch(r.getToken()){case 3:return T();case 1:return I();case 10:return $(!0);default:return H()}}return v(),r.getToken()===17?n.allowEmptyContent?!0:(k(4,[],[]),!1):P()?(r.getToken()!==17&&k(9,[],[]),!0):(k(4,[],[]),!1)}function By(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(e){if(Array.isArray(e))return"array"}else return"null";return"object"}default:return"null"}}var vl;(function(e){e[e.None=0]="None",e[e.UnexpectedEndOfComment=1]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=2]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=3]="UnexpectedEndOfNumber",e[e.InvalidUnicode=4]="InvalidUnicode",e[e.InvalidEscapeCharacter=5]="InvalidEscapeCharacter",e[e.InvalidCharacter=6]="InvalidCharacter"})(vl||(vl={}));var wl;(function(e){e[e.OpenBraceToken=1]="OpenBraceToken",e[e.CloseBraceToken=2]="CloseBraceToken",e[e.OpenBracketToken=3]="OpenBracketToken",e[e.CloseBracketToken=4]="CloseBracketToken",e[e.CommaToken=5]="CommaToken",e[e.ColonToken=6]="ColonToken",e[e.NullKeyword=7]="NullKeyword",e[e.TrueKeyword=8]="TrueKeyword",e[e.FalseKeyword=9]="FalseKeyword",e[e.StringLiteral=10]="StringLiteral",e[e.NumericLiteral=11]="NumericLiteral",e[e.LineCommentTrivia=12]="LineCommentTrivia",e[e.BlockCommentTrivia=13]="BlockCommentTrivia",e[e.LineBreakTrivia=14]="LineBreakTrivia",e[e.Trivia=15]="Trivia",e[e.Unknown=16]="Unknown",e[e.EOF=17]="EOF"})(wl||(wl={}));const Zy=$y,Rz=Fy;var kl;(function(e){e[e.InvalidSymbol=1]="InvalidSymbol",e[e.InvalidNumberFormat=2]="InvalidNumberFormat",e[e.PropertyNameExpected=3]="PropertyNameExpected",e[e.ValueExpected=4]="ValueExpected",e[e.ColonExpected=5]="ColonExpected",e[e.CommaExpected=6]="CommaExpected",e[e.CloseBraceExpected=7]="CloseBraceExpected",e[e.CloseBracketExpected=8]="CloseBracketExpected",e[e.EndOfFileExpected=9]="EndOfFileExpected",e[e.InvalidCommentToken=10]="InvalidCommentToken",e[e.UnexpectedEndOfComment=11]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=12]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=13]="UnexpectedEndOfNumber",e[e.InvalidUnicode=14]="InvalidUnicode",e[e.InvalidEscapeCharacter=15]="InvalidEscapeCharacter",e[e.InvalidCharacter=16]="InvalidCharacter"})(kl||(kl={}));const Vy=60,Uy=/§jtoc:\d+§/g;function Ie(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 st(e){return(e==null?void 0:e.type)==="string"&&typeof e.value=="string"?e.value:void 0}function Fa(e){return(e==null?void 0:e.type)==="number"&&typeof e.value=="number"?e.value:void 0}function Et(e){return(e==null?void 0:e.type)==="array"&&e.children?e.children:[]}function vt(e,t=Vy,n=!1){const r=e.replace(Uy,"…"),i=n?r.replace(/\s*\n\s*/g," ").trim():r.split(`
9
- `)[0].trim();return i.length>t?`${i.slice(0,t-1)}…`:i}function Jy(e){const t=Et(Ie(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>Et(Ie(i,"cells")).length))}×${t.length}`;const n=Et(Ie(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?Et(r).length:Et(Ie(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Hy(e){const t=st(Ie(e,"alt"));if(t)return vt(t);const n=st(Ie(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 vt(r,40)}return"image"}function Wy(e,t){var r;const n=st(Ie(t,"text"));switch(e){case"heading":{const i=Fa(Ie(t,"level"))??1;return{label:n?vt(n):"heading",detail:`H${i}`}}case"text":return{label:n?vt(n):"text",detail:st(Ie(t,"style"))};case"paragraph":return{label:n?vt(n):"paragraph"};case"chart":case"highcharts":{const i=st(Ie(t,"title"))??st(Ie(Ie(t,"options"),"title"));return{label:i?vt(i):e,detail:st(Ie(t,"type"))}}case"table":return{label:"table",detail:Jy(t)};case"image":return{label:Hy(t)};case"shape":return{label:st(Ie(t,"type"))??"shape"};case"list":{const i=Et(Ie(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=st(Ie(Ie(t,"meta"),"title"))??st(Ie(t,"title"));return{label:i?vt(i):"section"}}case"statistic":{const i=st(Ie(t,"value"))??((r=Fa(Ie(t,"value")))==null?void 0:r.toString()),s=st(Ie(t,"label"));return{label:vt(s??i??"statistic"),detail:i}}default:return{label:n?vt(n):e}}}function gr(e){if(e.type!=="object")return null;const t=st(Ie(e,"name"));return t?{name:t,props:Ie(e,"props"),childrenArr:Ie(e,"children")}:null}function qy(e){let t;for(const n of Et(e)){const r=gr(n);if(!r)continue;const i=st(Ie(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return vt(i,48);r.name==="paragraph"&&t===void 0&&(t=vt(i,48))}}return t}function Qi(e,t,n){let{label:r,detail:i}=Wy(t.name,t.props);return r===t.name&&t.childrenArr&&(r=qy(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:Tf(t.childrenArr),reorder:n}}function Tf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of Et(e)){const i=gr(r);i&&n.push(Qi(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Gy(e){const t=Ie(e,"props"),n=st(Ie(Ie(t,"meta"),"title"));if(n)return vt(n,48,!0);let r;const i=(o,l)=>{l&&(!r||o<r.rank)&&(r={rank:o,text:l})},s=Ie(t,"placeholders");if((s==null?void 0:s.type)==="object"&&s.children)for(const o of s.children){if(o.type!=="property"||!o.children)continue;const[l,c]=o.children,f=typeof(l==null?void 0:l.value)=="string"?l.value:"",d=c?gr(c):null,h=d?st(Ie(d.props,"text")):void 0;i(f==="title"?0:f==="subtitle"||f.startsWith("heading")?1:2,h)}const a=(o,l)=>{const c=gr(o);if(c){if(c.name==="text"||c.name==="heading"){const f=st(Ie(c.props,"text"));if(f){const d=st(Ie(c.props,"style"))??"";i(d==="title"?0:d.startsWith("heading")?1:2,f)}}if(l<1)for(const f of Et(c.childrenArr))a(f,l+1)}};for(const o of Et(Ie(e,"children")))a(o,0);return r?vt(r.text,48,!0):void 0}function Yy(e){const t=Ie(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of Et(t)){const a=gr(s);if(!a)continue;const o={groupId:n,sliceStart:s.offset,sliceEnd:s.offset+s.length};a.name==="slide"?(i+=1,r.push({id:"",kind:"slide",label:Gy(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:Tf(a.childrenArr),reorder:o})):r.push(Qi(s,a,o))}return r}function Ky(e){const t=Ie(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const a of Et(t)){const o=gr(a);if(!o)continue;const l={groupId:n,sliceStart:a.offset,sliceEnd:a.offset+a.length},c=()=>i.length?i[i.length-1].node.children:r;if(o.name==="heading"){const f=Fa(Ie(o.props,"level"))??1;for(;i.length&&i[i.length-1].level>=f;)i.pop();const d=Qi(a,o,l);c().push(d),i.push({level:f,node:d})}else c().push(Qi(a,o,l))}const s=a=>{a.children.forEach(s);const o=a.children[a.children.length-1];a.kind==="heading"&&o&&(a.end=Math.max(a.end,o.end),a.reorder&&o.reorder&&(a.reorder.sliceEnd=Math.max(a.reorder.sliceEnd,o.reorder.sliceEnd)))};return r.forEach(s),r}function Sl(e){switch(e.type){case"string":return vt(String(e.value??""),24);case"number":case"boolean":return String(e.value);case"array":return`${Et(e).length} items`;case"object":return;default:return}}function Xy(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 a=[];if(i.type==="object"&&i.children)for(const o of i.children){if(o.type!=="property"||!o.children)continue;const[l,c]=o.children,f=typeof(l==null?void 0:l.value)=="string"?l.value:void 0;!f||!c||a.push({id:"",kind:"key",label:f,detail:Sl(c),start:o.offset,end:o.offset+o.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:a.length===0?Sl(i):void 0,start:n.offset,end:n.offset+n.length,children:a})}return t}function _l(e,t,n){if(!e.trim())return[];const r=Zy(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Xy(r):t==="pptx"?Yy(r):Ky(r);return If(i,""),i}function If(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,If(n.children,n.id)})}function Af(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 Qy(e,t){const n=new Set;for(const r of t)for(const i of Af(e,r))n.add(i);return n}function eb(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(f=>f.reorder);if(i.some(f=>!f))return null;const s=i[0].groupId;if(i.some(f=>f.groupId!==s))return null;for(let f=1;f<i.length;f++)if(i[f].sliceStart<i[f-1].sliceEnd)return null;const a=i.map(f=>e.slice(f.sliceStart,f.sliceEnd)),o=[];for(let f=1;f<i.length;f++){const d=e.slice(i[f-1].sliceEnd,i[f].sliceStart);if((d.match(/,/g)??[]).length!==1)return null;o.push(d)}const l=a.map((f,d)=>d);l.splice(r,0,l.splice(n,1)[0]);let c="";return l.forEach((f,d)=>{c+=a[f],d<o.length&&(c+=o[d])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:c}}const tb={slide:$g,heading:Mg,text:ja,paragraph:Rg,chart:Ea,highcharts:Ea,table:Dg,image:Pg,shape:zd,list:Og,toc:zg,section:Na,columns:Na,"text-box":ja,statistic:Ag,key:_a};function nb(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 rb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function ib(){const{activeTab:e,documentTypes:t}=Ne(po(k=>({activeTab:k.activeTab,documentTypes:k.documentTypes}))),n=Ne(k=>{var $;return k.activeTab?($=k.documents.find(H=>H.name===k.activeTab))==null?void 0:$.text:void 0}),r=$d(k=>e?k.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,a]=x.useState([]),[o,l]=x.useState(null),[c,f]=x.useState(()=>new Set),[d,h]=x.useState(()=>new Set),[p,g]=x.useState(null),w=x.useRef(s);w.current=s;const _=x.useRef(null),b=x.useRef(null),N=x.useCallback(()=>{var H;if(!e){a([]);return}const k=((H=r==null?void 0:r.editor.getModel())==null?void 0:H.getValue())??n??"",$=_l(k,ht,i);if(a($),b.current!==e){b.current=e;const j=new Set;if(i==="document"&&ht==="docx")for(const I of $)I.kind==="heading"&&j.add(I.id);h(j),l(null)}},[e,r,n,i]);x.useEffect(()=>{N();const k=r==null?void 0:r.editor.getModel();if(!k)return;const $=sl(N,300),H=k.onDidChangeContent(()=>$());return()=>{$.cancel(),H.dispose()}},[N,r]),x.useEffect(()=>{if(!r)return;const{editor:k}=r,$=sl(()=>{const j=k.getModel(),I=k.getPosition();if(!j||!I)return;const T=j.getOffsetAt(I),P=Af(w.current,T);if(P.length===0){l(null);return}l(P[P.length-1]);const A=P.slice(0,-1);A.length&&h(M=>{if(A.every(U=>M.has(U)))return M;const V=new Set(M);for(const U of A)V.add(U);return V})},150),H=k.onDidChangeCursorPosition(()=>$());return()=>{$.cancel(),H.dispose()}},[r]),x.useEffect(()=>{if(!o||!_.current)return;const k=_.current.querySelector(`[data-oid="${CSS.escape(o)}"]`);k==null||k.scrollIntoView({block:"nearest"})},[o]),x.useEffect(()=>{if(!r){f(new Set);return}const{editor:k,monaco:$}=r,H=()=>{const I=k.getModel();if(!I)return;const T=$.editor.getModelMarkers({resource:I.uri}).filter(P=>P.severity===$.MarkerSeverity.Error).map(P=>I.getOffsetAt({lineNumber:P.startLineNumber,column:P.startColumn}));f(Qy(w.current,T))};H();const j=$.editor.onDidChangeMarkers(I=>{const T=k.getModel();T&&I.some(P=>P.toString()===T.uri.toString())&&H()});return()=>j.dispose()},[r,s]);const m=x.useCallback(k=>{h($=>{const H=new Set($);return H.has(k)?H.delete(k):H.add(k),H})},[]),O=x.useCallback(k=>{if(l(k.id),!r)return;const{editor:$,monaco:H}=r,j=$.getModel();if(!j)return;const I=j.getPositionAt(k.start),T=j.getPositionAt(k.end),P=new H.Range(I.lineNumber,I.column,T.lineNumber,T.column);$.revealRangeNearTopIfOutsideViewport(P,H.editor.ScrollType.Smooth),$.setPosition(I),$.focus();const A=$.deltaDecorations([],[{range:P,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>$.deltaDecorations(A,[]),700)},[r]),C=x.useCallback(k=>{var oe;if(!r||!k.overId)return;const{editor:$,monaco:H,collapse:j}=r,I=$.getModel();if(!I)return;const T=I.getValue(),P=_l(T,ht,i),A=k.parentId?((oe=nb(P,k.parentId))==null?void 0:oe.children)??[]:P,M=A.findIndex(B=>B.id===k.dragId),V=A.findIndex(B=>B.id===k.overId);if(M===-1||V===-1)return;let U=V+(k.overHalf==="after"?1:0);M<U&&(U-=1);const J=eb(T,A,M,U);if(!J)return;const ne=I.getPositionAt(J.start),S=I.getPositionAt(J.end);$.executeEdits("outline-reorder",[{range:new H.Range(ne.lineNumber,ne.column,S.lineNumber,S.column),text:J.text}]),j==null||j.resyncDecorations()},[r,i]),v=x.useMemo(()=>{const k=[],$=(H,j,I)=>{var A,M;const T=(M=(A=H[0])==null?void 0:A.reorder)==null?void 0:M.groupId,P=H.length>1&&T!==void 0&&H.every(V=>{var U;return((U=V.reorder)==null?void 0:U.groupId)===T});H.forEach(V=>{const U=tb[V.kind]??Fg,J=V.children.length>0,ne=d.has(V.id),S=o===V.id,oe=(p==null?void 0:p.overId)===V.id;k.push(u.jsxs("div",{"data-oid":V.id,role:"treeitem","aria-selected":S,"aria-expanded":J?ne:void 0,tabIndex:0,draggable:P,onClick:()=>O(V),onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),O(V)),B.key==="ArrowRight"&&J&&!ne&&m(V.id),B.key==="ArrowLeft"&&J&&ne&&m(V.id)},onDragStart:B=>{B.dataTransfer.setData("text/plain",V.id),B.dataTransfer.effectAllowed="move",g({dragId:V.id,parentId:I,overId:null,overHalf:"before"})},onDragOver:B=>{if(!p||p.dragId===V.id||rb(p.dragId)!==I)return;B.preventDefault(),B.dataTransfer.dropEffect="move";const y=B.currentTarget.getBoundingClientRect(),q=B.clientY<y.top+y.height/2?"before":"after";(p.overId!==V.id||p.overHalf!==q)&&g({...p,overId:V.id,overHalf:q})},onDrop:B=>{B.preventDefault(),p&&C({...p,overId:V.id,overHalf:p.overHalf}),g(null)},onDragEnd:()=>g(null),className:G("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",S&&"bg-sidebar-accent font-medium text-sidebar-foreground",oe&&(p==null?void 0:p.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",oe&&(p==null?void 0:p.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+j*12},children:[J?u.jsx("span",{role:"button","aria-label":ne?"Collapse":"Expand",onClick:B=>{B.stopPropagation(),m(V.id)},className:"flex size-3.5 shrink-0 items-center justify-center rounded-xs text-sidebar-foreground/55 hover:text-sidebar-foreground",children:u.jsx(_r,{className:G("size-3 transition-transform",ne&&"rotate-90")})}):u.jsx("span",{className:"size-3.5 shrink-0"}),V.kind==="slide"&&u.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:V.detail}),u.jsx(U,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.label}),V.kind!=="slide"&&V.detail&&u.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:V.detail}),c.has(V.id)&&u.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},V.id)),J&&ne&&$(V.children,j+1,V.id)})};return $(s,0,""),k},[s,d,o,c,p,O,m,C]);return!e||s.length===0?null:u.jsx("li",{className:"list-none",children:u.jsx("div",{ref:_,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:v})})}const jl=x.memo(ib);async function sb(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const ri=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vd,{ref:r,className:G("relative overflow-hidden",e),...n,children:[u.jsx(hg,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(zf,{}),u.jsx(mg,{})]}));ri.displayName=vd.displayName;const zf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(wd,{ref:r,orientation:t,className:G("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:u.jsx(gg,{className:"bg-border relative flex-1 rounded-full"})}));zf.displayName=wd.displayName;function Of({className:e,...t}){return u.jsx(xg,{"data-slot":"switch",className:G("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:u.jsx(yg,{"data-slot":"switch-thumb",className:G("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 ab=gi("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"}}),ir=x.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:G(ab({variant:t}),e),...n}));ir.displayName="Alert";const ob=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:G("mb-1 font-medium leading-none tracking-tight",e),...t}));ob.displayName="AlertTitle";const sr=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:G("text-sm [&_p]:leading-relaxed",e),...t}));sr.displayName="AlertDescription";const es=x.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=x.useState(n<2),a=t!==null&&typeof t=="object",o=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?u.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-warning",children:['"',t,'"']}):u.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,f=a?Object.keys(t).length:0;return u.jsxs("div",{className:G("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[a&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(mi,{className:"h-3 w-3"}):u.jsx(_r,{className:"h-3 w-3"})}),!a&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),a?u.jsxs("span",{className:"text-muted-foreground",children:[o?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[f," ",o?"items":"properties"]}),!i&&(o?"]":"}")]}):c(),!a&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),a&&i&&u.jsxs("div",{className:"ml-4",children:[o?t.map((d,h)=>u.jsx(es,{keyName:String(h),value:d,depth:n+1,isLast:h===t.length-1},h)):Object.entries(t).map(([d,h],p,g)=>u.jsx(es,{keyName:d,value:h,depth:n+1,isLast:p===g.length-1},d)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[o?"]":"}",!r&&","]})})]})]})});es.displayName="JsonNode";const ts=x.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:G("space-y-4",r),children:[u.jsx(Yr,{className:"h-8 w-64"}),u.jsx(Yr,{className:"h-4 w-full"}),u.jsx(Yr,{className:"h-64 w-full"})]}):n?u.jsx(ir,{variant:"destructive",className:r,children:u.jsx(sr,{children:n})}):e?u.jsx(ri,{className:G("h-full w-full rounded-md border bg-muted/10 p-4",r),children:u.jsx("div",{className:"font-mono text-xs",children:u.jsx(es,{value:e})})}):u.jsx(ir,{className:r,children:u.jsx(sr,{children:"No schema available"})}));ts.displayName="SchemaViewer";function lb({plugins:e,initialFocusedPlugin:t}){var m,O;const n=Lt(C=>C.togglePlugin),r=Lt(C=>C.isPluginSelected),i=Lt(C=>C.selectedPlugins),s=Lt(C=>C.isApplyingPlugins),[a,o]=x.useState(null),[l,c]=x.useState(null),[f,d]=x.useState("properties");x.useEffect(()=>{if(t){const C=e.find(v=>v.name===t);if(C){o(C);return}}e.length>0&&!a&&o(e[0])},[t,e]);const h=x.useMemo(()=>{const C={current:[],downstream:[],upstream:[]};return e.forEach(v=>{C[v.location]&&C[v.location].push(v)}),C},[e]),p=async(C,v)=>{a&&(await sb(a.name,C.props),c(v),setTimeout(()=>c(null),2e3))},g=C=>{switch(C){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return C}},w=C=>{switch(C){case"current":return u.jsx(Jg,{className:"size-3"});case"downstream":return u.jsx(Ug,{className:"size-3"});case"upstream":return u.jsx(Id,{className:"size-3"});default:return null}},_=((m=a==null?void 0:a.schema)==null?void 0:m.properties)&&Object.keys(a.schema.properties).length>0,b=(O=a==null?void 0:a.schema)==null?void 0:O.jsonSchema,N=(a==null?void 0:a.examples)&&a.examples.length>0;return u.jsxs(u.Fragment,{children:[u.jsxs(Vt,{children:[u.jsxs(Ut,{className:"flex items-center gap-2",children:[u.jsx(Lg,{className:"size-5 text-warning"}),"Plugins",u.jsxs(Kt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(on,{children:[e.length," plugin",e.length!==1?"s":""," discovered in your project"]})]}),u.jsxs("div",{className:"mt-3 flex gap-0 h-[600px] border rounded-lg overflow-hidden",children:[u.jsx("div",{className:"w-[240px] flex-none border-r bg-muted/30",children:u.jsx(ri,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(h).map(([C,v])=>v.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[w(C),g(C)]}),u.jsx("div",{className:"space-y-0.5",children:v.map(k=>{const $=r(k.name),H=(a==null?void 0:a.name)===k.name;return u.jsxs("button",{onClick:()=>o(k),className:G("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",H?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:G("size-1.5 rounded-full flex-none transition-colors",$?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:k.name})]},k.name)})})]},C))})})}),a?u.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[u.jsxs("div",{className:"flex-none px-5 py-4 border-b bg-background",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2.5",children:[u.jsx("h3",{className:"text-base font-semibold truncate",children:a.name}),a.version&&u.jsxs(Kt,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",a.version]})]}),a.description&&u.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:a.description})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-none pt-0.5",children:[u.jsx("span",{className:"text-xs text-muted-foreground",children:r(a.name)?"On":"Off"}),u.jsx(Of,{checked:r(a.name),onCheckedChange:()=>n(a),disabled:s,"aria-label":`Toggle ${a.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[w(a.location),u.jsx("span",{children:g(a.location)}),u.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),u.jsx("span",{className:"font-mono truncate",children:a.relativePath})]})]}),u.jsxs("div",{className:"flex-none px-5 pt-3 pb-0 flex gap-1 border-b bg-background",children:[_&&u.jsx("button",{onClick:()=>d("properties"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(_a,{className:"size-3.5"}),"Properties"]})}),b&&u.jsx("button",{onClick:()=>d("schema"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Bg,{className:"size-3.5"}),"Schema"]})}),N&&u.jsx("button",{onClick:()=>d("examples"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Zg,{className:"size-3.5"}),"Examples",u.jsx(Kt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:a.examples.length})]})})]}),u.jsx(ri,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[f==="properties"&&_&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([C,v])=>u.jsx(ub,{name:C,prop:v},C))}),f==="schema"&&b&&u.jsx(ts,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),f==="examples"&&N&&a.examples.map((C,v)=>u.jsxs("div",{className:G(v>0&&"mt-4 pt-4 border-t"),children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[C.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:C.title}),!C.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",v+1]})]}),u.jsx(Se,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>p(C,v),children:l===v?u.jsxs(u.Fragment,{children:[u.jsx(Vg,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(ks,{className:"size-3 mr-1"}),"Copy"]})})]}),C.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:C.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(C.props,null,2)})]},v)),!_&&!b&&!N&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(_a,{className:"size-10 mx-auto mb-3 opacity-20"}),u.jsx("p",{className:"text-sm",children:"No schema or examples available for this plugin"})]})]})})]}):u.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:u.jsx("p",{className:"text-sm",children:"Select a plugin to view details"})})]})]})}function ub({name:e,prop:t}){var a;const[n,r]=x.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 u.jsxs("div",{className:"rounded-md border",children:[u.jsxs("button",{onClick:()=>i&&r(!n),className:G("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?u.jsx(mi,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(_r,{className:"size-3 text-muted-foreground flex-none"}):u.jsx("span",{className:"size-3 flex-none"}),u.jsx("span",{className:"font-mono font-medium text-xs",children:e}),u.jsx(Kt,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&u.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),u.jsx("span",{className:"flex-1"}),t.default!==void 0&&u.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&u.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&u.jsx("p",{children:t.description}),t.enum&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((o,l)=>u.jsxs("span",{children:[l>0&&", ",u.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(o)})]},l))]}),((a=t.items)==null?void 0:a.type)&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const cb={current:"Current directory",downstream:"Project"};function Nl({location:e}){return u.jsx("li",{className:"list-none px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:cb[e]??e})}function El({name:e,subtitle:t,query:n,onSelect:r}){return u.jsx("li",{className:"list-none",children:u.jsxs("button",{type:"button",onClick:r,title:t?`${e} — ${t}`:e,"aria-label":`Add ${e} to workspace`,className:G("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:[u.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:u.jsx(wo,{text:e,query:n})}),u.jsx(nn,{"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 db({plugins:e,query:t,open:n,onToggleSection:r,onShowPluginDetails:i,isPluginSelected:s,onTogglePlugin:a,isApplyingPlugins:o,selectedPluginCount:l}){return e.length===0?null:u.jsxs("section",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:[u.jsx(Ra,{open:n,onToggle:r,count:`${l}/${e.length}`,children:"Plugins"}),n&&u.jsx("div",{className:"flex flex-col gap-0.5",children:e.map(c=>{const f=s(c.name),d=`plugin-switch-${c.filePath||c.name}`;return u.jsxs("div",{title:c.description?`${c.name} — ${c.description}`:c.name,className:G("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:[u.jsx("label",{htmlFor:d,className:G("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",f?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(wo,{text:c.name,query:t})})}),u.jsx(Ht,{"aria-label":`Details for ${c.name}`,onClick:h=>{h.stopPropagation(),i(c.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(Od,{})}),u.jsx(Of,{id:d,checked:f,onCheckedChange:()=>a(c),disabled:o,className:"shrink-0","aria-label":`Toggle ${c.name} plugin`})]},c.filePath||c.name)})})]})}function Cl(e){return x.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 Pf({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:G("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","[[data-slot=tooltip-content]_&]:bg-primary-foreground/20 [[data-slot=tooltip-content]_&]:text-primary-foreground",t),children:e})}function fb({children:e,className:t}){return u.jsx("span",{className:G("inline-flex items-center gap-0.5",t),children:e})}const Ei=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function ii({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return Ei?"⌘":"Ctrl";case"shift":return Ei?"⇧":"Shift";case"alt":return Ei?"⌥":"Alt";case"ctrl":return Ei?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(fb,{className:t,children:r.map((i,s)=>u.jsx(Pf,{children:i},s))})}function pb({className:e}={}){const{theme:t,setTheme:n}=jd(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=x.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(Se,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Hg,{className:"hidden dark:block"}),u.jsx(Wg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Xe,{children:u.jsx("p",{children:"Toggle theme"})})]})}function hb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o,activeTab:l}=Ne(po(z=>({documents:z.documents,documentTypes:z.documentTypes,createDocument:z.createDocument,openDocument:z.openDocument,activeTab:z.activeTab}))),c=Ia(z=>z.updateTheme),f=Ia(z=>z.removeTheme),d=x.useContext(Fd),[h,p]=x.useState(!1),[g,w]=x.useState(!1),[_,b]=x.useState(!1),[N,m]=x.useState(null),O=Lt(z=>z.togglePlugin),C=Lt(z=>z.isPluginSelected),v=Lt(z=>z.selectedPlugins),k=Lt(z=>z.isApplyingPlugins),[$,H]=x.useState(!1),[j,I]=x.useState(new Set(["documents","themes"])),[T,P]=x.useState(""),A=x.useRef(null),{toast:M}=Sr(),V=i.filter(z=>s[z.name]!=="application/json+theme"),U=i.filter(z=>s[z.name]==="application/json+theme"),J=x.useCallback(()=>{p(!1)},[]),ne=x.useCallback(()=>{w(!1)},[]),S=x.useRef(new Map);x.useEffect(()=>{const z=S.current,K=new Map;U.forEach(te=>{K.set(te.name,te.text),z.get(te.name)!==te.text&&c(te.name,te.text)}),z.forEach((te,xe)=>{K.has(xe)||f(xe)}),S.current=K},[U,c,f]);const oe=x.useRef(!1);x.useEffect(()=>{if(oe.current||!d)return;oe.current=!0;const z=new Set(U.map(te=>te.name));Object.keys(d.getState().customThemes).forEach(te=>{z.has(te)||f(te)})},[U,f,d]);const B=x.useCallback(z=>{I(K=>{const te=new Set(K);return te.has(z)?te.delete(z):te.add(z),te})},[]),{resolvedTheme:y}=jd(),q=y==="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",X=x.useCallback(async(z,K)=>{if(i.some(te=>te.name===z)){o(z);return}try{const te=await fetch(`/api/discovery/${K?"themes":"documents"}/${encodeURIComponent(z)}/content`);if(!te.ok)throw new Error(te.statusText);const xe=await te.text(),L=JSON.parse(xe);a(z,JSON.stringify(L,null,2),{templateSource:z}),o(z),M({title:`Added ${K?"theme":"document"}: ${z}`})}catch{M({title:"Failed to load",description:`Could not load ${z}`,variant:"destructive"})}},[i,a,o,M]);x.useEffect(()=>{if(n)return;const z=K=>{var L,Q,me,ve,F;if(K.key!=="/"||K.metaKey||K.ctrlKey||K.altKey)return;const te=K.target,xe=(L=te==null?void 0:te.tagName)==null?void 0:L.toLowerCase();xe==="input"||xe==="textarea"||xe==="select"||te!=null&&te.isContentEditable||(Q=te==null?void 0:te.closest)!=null&&Q.call(te,".monaco-editor")||(me=A.current)!=null&&me.closest('[aria-hidden="true"], [inert]')||(K.preventDefault(),(ve=A.current)==null||ve.focus(),(F=A.current)==null||F.select())};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[n]);const Y=T.trim(),ie=x.useMemo(()=>new Set(i.map(z=>z.name)),[i]),D=x.useMemo(()=>V.filter(z=>cn(z.name,Y)),[V,Y]),ue=x.useMemo(()=>U.filter(z=>cn(z.name,Y)),[U,Y]),he=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(z=>!ie.has(z.name)&&(cn(z.name,Y)||cn(z.title??"",Y))),[e,Y,ie]),ce=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(z=>!ie.has(z.name)&&(cn(z.name,Y)||cn(z.description??"",Y))),[e,Y,ie]),ee=Cl(he),de=Cl(ce),fe=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(z=>cn(z.name,Y)||cn(z.description??"",Y)),[e,Y]),Re=z=>Y.length>0||j.has(z),Oe=Re("documents"),We=Re("themes"),E=D.length+he.length,R=ue.length+ce.length,Z=Y.length>0&&D.length===0&&ue.length===0&&he.length===0&&ce.length===0&&fe.length===0,se=G("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(_f,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Ma,{className:G("gap-0 p-1.5",se),children:u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Pd,{})})}),u.jsxs(Xe,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(ii,{shortcut:"mod+b"})]})]})}),u.jsxs($a,{className:G("gap-2 px-1 py-1",se),children:[u.jsxs(Lr,{className:"items-center gap-0.5",children:[V.map(z=>u.jsx(Ni,{document:z,compact:!0},z.name)),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"right",children:"New document"})]})]}),u.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),u.jsxs(Lr,{className:"items-center gap-0.5",children:[U.map(z=>u.jsx(Ni,{document:z,compact:!0},z.name)),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New theme",onClick:()=>w(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(Ma,{className:G("gap-0 p-2",se),children:[u.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[u.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:u.jsx("img",{src:q,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(qg,{})})}),u.jsxs(Xe,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(ii,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(Gg,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),u.jsx("input",{ref:A,type:"text",value:T,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:z=>P(z.target.value),onKeyDown:z=>{z.key==="Escape"&&(z.preventDefault(),P(""),z.currentTarget.blur())},className:G("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")}),Y?u.jsx(Ht,{"aria-label":"Clear filter",onClick:()=>{var z;P(""),(z=A.current)==null||z.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(yn,{})}):u.jsx(Pf,{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:"/"})]})]}),u.jsx($a,{className:G("gap-0 px-2 pb-2",se),children:Z?u.jsxs("div",{className:"px-1 py-6 text-center",children:[u.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",Y,"”"]}),u.jsx("button",{type:"button",onClick:()=>{var z;P(""),(z=A.current)==null||z.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"})]}):u.jsxs(u.Fragment,{children:[(E>0||!Y)&&u.jsxs("section",{children:[u.jsx(Ra,{open:Oe,onToggle:()=>B("documents"),count:E||void 0,actions:u.jsxs(u.Fragment,{children:[ht==="docx"&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Compare documents",disabled:V.length<2,onClick:()=>H(!0),children:u.jsx(Cd,{})})}),u.jsx(Xe,{side:"bottom",children:V.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),Oe&&u.jsxs(Lr,{className:"gap-0.5",children:[D.map(z=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:z,query:Y}),!Y&&l===z.name&&u.jsx(jl,{})]},z.name)),ee.map(([z,K])=>u.jsxs(x.Fragment,{children:[ee.length>1&&u.jsx(Nl,{location:z}),K.map(te=>u.jsx(El,{name:te.name,subtitle:te.title,query:Y,onSelect:()=>X(te.name,!1)},te.path||te.name))]},z)),E===0&&u.jsx("li",{className:"list-none",children:u.jsx(yl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]})]}),(R>0||!Y)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Ra,{open:We,onToggle:()=>B("themes"),count:R||void 0,actions:u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New theme",onClick:()=>w(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"bottom",children:"New theme"})]}),children:"Themes"}),We&&u.jsxs(Lr,{className:"gap-0.5",children:[ue.map(z=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:z,query:Y}),!Y&&l===z.name&&u.jsx(jl,{})]},z.name)),de.map(([z,K])=>u.jsxs(x.Fragment,{children:[de.length>1&&u.jsx(Nl,{location:z}),K.map(te=>u.jsx(El,{name:te.name,subtitle:te.description,query:Y,onSelect:()=>X(te.name,!0)},te.path||te.name))]},z)),R===0&&u.jsx("li",{className:"list-none",children:u.jsx(yl,{icon:nn,label:"New theme",onClick:()=>w(!0)})})]})]}),u.jsx(db,{plugins:fe,query:Y,open:Re("plugins"),onToggleSection:()=>B("plugins"),onShowPluginDetails:z=>{m(z),b(!0)},isPluginSelected:C,onTogglePlugin:O,isApplyingPlugins:k,selectedPluginCount:v.size})]})})]}),u.jsx(jf,{className:G("border-sidebar-border/70 gap-0 border-t p-1.5",se),children:u.jsx("div",{className:G("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(pb,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),u.jsx(Ct,{open:h,onOpenChange:p,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Ki,{mode:"create",shouldReset:!h,postSubmit:J,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(Ct,{open:g,onOpenChange:w,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Ki,{mode:"create",shouldReset:!g,postSubmit:ne,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(Ct,{open:_,onOpenChange:z=>{b(z),z||m(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(lb,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:N})})}),u.jsx(wx,{open:$,onOpenChange:H})]})}const Tl=x.memo(hb),mb=x.lazy(()=>Nd(()=>import("./editor-Y9dek093.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(e=>({default:e.Editor})));function Il(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(gn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(mb,{})})}const gb=x.lazy(()=>Nd(()=>import("./preview-zCYkbgdR.js"),__vite__mapDeps([13,1,3,4,5,6,7,8,9,10,12,11])).then(e=>({default:e.Preview})));function Al(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(gn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(gb,{})})}const{createElement:xr,createContext:xb,forwardRef:Df,useCallback:gt,useContext:Rf,useEffect:zn,useImperativeHandle:Mf,useLayoutEffect:yb,useMemo:bb,useRef:wt,useState:ar}=Uc,zl=Uc[`useId${Math.random()}`.slice(0,5)],vb=yb,Ts=xb(null);Ts.displayName="PanelGroupContext";const On=vb,wb=typeof zl=="function"?zl:()=>null;let kb=0;function _o(e=null){const t=wb(),n=wt(e||t||null);return n.current===null&&(n.current=""+kb++),e??n.current}function $f({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:f,onResize:d,order:h,style:p,tagName:g="div",...w}){const _=Rf(Ts);if(_===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:N,getPanelSize:m,getPanelStyle:O,groupId:C,isPanelCollapsed:v,reevaluatePanelConstraints:k,registerPanel:$,resizePanel:H,unregisterPanel:j}=_,I=_o(a),T=wt({callbacks:{onCollapse:c,onExpand:f,onResize:d},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:I,idIsFromProps:a!==void 0,order:h});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:A,constraints:M}=T.current,V={...M};T.current.id=I,T.current.idIsFromProps=a!==void 0,T.current.order=h,A.onCollapse=c,A.onExpand=f,A.onResize=d,M.collapsedSize=n,M.collapsible=r,M.defaultSize=i,M.maxSize=o,M.minSize=l,(V.collapsedSize!==M.collapsedSize||V.collapsible!==M.collapsible||V.maxSize!==M.maxSize||V.minSize!==M.minSize)&&k(T.current,V)}),On(()=>{const A=T.current;return $(A),()=>{j(A)}},[h,I,$,j]),Mf(s,()=>({collapse:()=>{b(T.current)},expand:A=>{N(T.current,A)},getId(){return I},getSize(){return m(T.current)},isCollapsed(){return v(T.current)},isExpanded(){return!v(T.current)},resize:A=>{H(T.current,A)}}),[b,N,m,v,I,H]);const P=O(T.current,i);return xr(g,{...w,children:e,className:t,id:a,style:{...P,...p},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":C,"data-panel-id":I,"data-panel-size":parseFloat(""+P.flexGrow).toFixed(1)})}const Ff=Df((e,t)=>xr($f,{...e,forwardedRef:t}));$f.displayName="Panel";Ff.displayName="forwardRef(Panel)";let La=null,An=null;function Sb(e,t){if(t){const n=(t&Uf)!==0,r=(t&Jf)!==0,i=(t&Hf)!==0,s=(t&Wf)!==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 _b(){An!==null&&(document.head.removeChild(An),La=null,An=null)}function Ks(e,t){const n=Sb(e,t);La!==n&&(La=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Lf(e){return e.type==="keydown"}function Bf(e){return e.type.startsWith("pointer")}function Zf(e){return e.type.startsWith("mouse")}function Is(e){if(Bf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Zf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function jb(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Nb(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 Eb(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Dl(e),b:Dl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;_e(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Pl(Ol(n.a)),b:Pl(Ol(n.b))};if(i.a===i.b){const s=r.childNodes,a={a:n.a.at(-1),b:n.b.at(-1)};let o=s.length;for(;o--;){const l=s[o];if(l===a.a)return 1;if(l===a.b)return-1}}return Math.sign(i.a-i.b)}const Cb=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Tb(e){var t;const n=getComputedStyle((t=Vf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function Ib(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Tb(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"||Cb.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Ol(e){let t=e.length;for(;t--;){const n=e[t];if(_e(n,"Missing node"),Ib(n))return n}return null}function Pl(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Dl(e){const t=[];for(;e;)t.push(e),e=Vf(e);return t}function Vf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Uf=1,Jf=2,Hf=4,Wf=8,Ab=jb()==="coarse";let Bt=[],or=!1,mn=new Map,As=new Map;const si=new Set;function zb(e,t,n,r,i){var s;const{ownerDocument:a}=t,o={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=mn.get(a))!==null&&s!==void 0?s:0;return mn.set(a,l+1),si.add(o),ns(),function(){var f;As.delete(e),si.delete(o);const d=(f=mn.get(a))!==null&&f!==void 0?f:1;if(mn.set(a,d-1),ns(),d===1&&mn.delete(a),Bt.includes(o)){const h=Bt.indexOf(o);h>=0&&Bt.splice(h,1),No(),i("up",!0,null)}}}function Rl(e){const{target:t}=e,{x:n,y:r}=Is(e);or=!0,jo({target:t,x:n,y:r}),ns(),Bt.length>0&&(rs("down",e),e.preventDefault(),e.stopPropagation())}function Or(e){const{x:t,y:n}=Is(e);if(or&&e.buttons===0&&(or=!1,rs("up",e)),!or){const{target:r}=e;jo({target:r,x:t,y:n})}rs("move",e),No(),Bt.length>0&&e.preventDefault()}function Un(e){const{target:t}=e,{x:n,y:r}=Is(e);As.clear(),or=!1,Bt.length>0&&e.preventDefault(),rs("up",e),jo({target:t,x:n,y:r}),No(),ns()}function jo({target:e,x:t,y:n}){Bt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),si.forEach(i=>{const{element:s,hitAreaMargins:a}=i,o=s.getBoundingClientRect(),{bottom:l,left:c,right:f,top:d}=o,h=Ab?a.coarse:a.fine;if(t>=c-h&&t<=f+h&&n>=d-h&&n<=l+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&Eb(r,s)>0){let g=r,w=!1;for(;g&&!g.contains(s);){if(Nb(g.getBoundingClientRect(),o)){w=!0;break}g=g.parentElement}if(w)return}Bt.push(i)}})}function Xs(e,t){As.set(e,t)}function No(){let e=!1,t=!1;Bt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;As.forEach(r=>{n|=r}),e&&t?Ks("intersection",n):e?Ks("horizontal",n):t?Ks("vertical",n):_b()}function ns(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Un),n.removeEventListener("pointerdown",Rl),n.removeEventListener("pointerleave",Or),n.removeEventListener("pointermove",Or)}),window.removeEventListener("pointerup",Un),window.removeEventListener("pointercancel",Un),si.size>0&&(or?(Bt.length>0&&mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Un),n.addEventListener("pointerleave",Or),n.addEventListener("pointermove",Or))}),window.addEventListener("pointerup",Un),window.addEventListener("pointercancel",Un)):mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Rl,{capture:!0}),n.addEventListener("pointermove",Or))}))}function rs(e,t){si.forEach(n=>{const{setResizeHandlerState:r}=n,i=Bt.includes(n);r(e,i,t)})}function Ob(){const[e,t]=ar(0);return gt(()=>t(n=>n+1),[])}function _e(e,t){if(!e)throw console.error(t),Error(t)}const Eo=10;function Dn(e,t,n=Eo){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function sn(e,t,n=Eo){return Dn(e,t,n)===0}function Nt(e,t,n){return Dn(e,t,n)===0}function Pb(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(!Nt(i,s,n))return!1}return!0}function tr({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];_e(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:a=100,minSize:o=0}=r;if(Dn(n,o)<0)if(s){const l=(i+o)/2;Dn(n,l)<0?n=i:n=o}else n=o;return n=Math.min(a,n),n=parseFloat(n.toFixed(Eo)),n}function Br({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Nt(e,0))return t;const a=[...t],[o,l]=r;_e(o!=null,"Invalid first pivot index"),_e(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?l:o,h=n[d];_e(h,`Panel constraints not found for index ${d}`);const{collapsedSize:p=0,collapsible:g,minSize:w=0}=h;if(g){const _=t[d];if(_e(_!=null,`Previous layout not found for panel index ${d}`),Nt(_,p)){const b=w-_;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const d=e<0?o:l,h=n[d];_e(h,`No panel constraints found for index ${d}`);const{collapsedSize:p=0,collapsible:g,minSize:w=0}=h;if(g){const _=t[d];if(_e(_!=null,`Previous layout not found for panel index ${d}`),Nt(_,w)){const b=_-p;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const d=e<0?1:-1;let h=e<0?l:o,p=0;for(;;){const w=t[h];_e(w!=null,`Previous layout not found for panel index ${h}`);const b=tr({panelConstraints:n,panelIndex:h,size:100})-w;if(p+=b,h+=d,h<0||h>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-g:g}{let h=e<0?o:l;for(;h>=0&&h<n.length;){const p=Math.abs(e)-Math.abs(c),g=t[h];_e(g!=null,`Previous layout not found for panel index ${h}`);const w=g-p,_=tr({panelConstraints:n,panelIndex:h,size:w});if(!Nt(g,_)&&(c+=g-_,a[h]=_,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(Pb(i,a))return i;{const d=e<0?l:o,h=t[d];_e(h!=null,`Previous layout not found for panel index ${d}`);const p=h+c,g=tr({panelConstraints:n,panelIndex:d,size:p});if(a[d]=g,!Nt(g,p)){let w=p-g,b=e<0?l:o;for(;b>=0&&b<n.length;){const N=a[b];_e(N!=null,`Previous layout not found for panel index ${b}`);const m=N+w,O=tr({panelConstraints:n,panelIndex:b,size:m});if(Nt(N,O)||(w-=O-N,a[b]=O),Nt(w,0))break;e>0?b--:b++}}}const f=a.reduce((d,h)=>h+d,0);return Nt(f,100)?a:i}function Db({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,a=0;const o=n[0];_e(o!=null,"No pivot index found"),t.forEach((d,h)=>{const{constraints:p}=d,{maxSize:g=100,minSize:w=0}=p;h===o?(r=w,i=g):(s+=w,a+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-a),f=e[o];return{valueMax:l,valueMin:c,valueNow:f}}function ai(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function qf(e,t,n=document){const i=ai(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Gf(e,t,n){const r=qf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Yf(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 zs(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function Rb(e,t,n,r=document){var i,s,a,o;const l=zs(t,r),c=ai(e,r),f=l?c.indexOf(l):-1,d=(i=(s=n[f])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,h=(a=(o=n[f+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[d,h]}function Mb({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:a}){wt({didWarnAboutMissingResizeHandle:!1}),On(()=>{if(!s)return;const o=ai(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:f,valueNow:d}=Db({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),h=o[l];if(h!=null){const p=i[l];_e(p,`No panel data found for index "${l}"`),h.setAttribute("aria-controls",p.id),h.setAttribute("aria-valuemax",""+Math.round(c)),h.setAttribute("aria-valuemin",""+Math.round(f)),h.setAttribute("aria-valuenow",d!=null?""+Math.round(d):"")}}return()=>{o.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),zn(()=>{if(!s)return;const o=t.current;_e(o,"Eager values not found");const{panelDataArray:l}=o,c=Yf(n,s);_e(c!=null,`No group found for id "${n}"`);const f=ai(n,s);_e(f,`No resize handles found for group id "${n}"`);const d=f.map(h=>{const p=h.getAttribute("data-panel-resize-handle-id");_e(p,"Resize handle element has no handle id attribute");const[g,w]=Rb(n,p,l,s);if(g==null||w==null)return()=>{};const _=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const N=l.findIndex(m=>m.id===g);if(N>=0){const m=l[N];_e(m,`No panel data found for index ${N}`);const O=r[N],{collapsedSize:C=0,collapsible:v,minSize:k=0}=m.constraints;if(O!=null&&v){const $=Br({delta:Nt(O,C)?k-C:C-O,initialLayout:r,panelConstraints:l.map(H=>H.constraints),pivotIndices:Gf(n,p,s),prevLayout:r,trigger:"keyboard"});r!==$&&a($)}}break}}};return h.addEventListener("keydown",_),()=>{h.removeEventListener("keydown",_)}});return()=>{d.forEach(h=>h())}},[s,e,t,n,r,i,a])}function Ml(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 Kf(e,t){const n=e==="horizontal",{x:r,y:i}=Is(t);return n?r:i}function $b(e,t,n,r,i){const s=n==="horizontal",a=zs(t,i);_e(a,`No resize handle element found for id "${t}"`);const o=a.getAttribute("data-panel-group-id");_e(o,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=Kf(n,e),f=Yf(o,i);_e(f,`No group element found for id "${o}"`);const d=f.getBoundingClientRect(),h=s?d.width:d.height;return(c-l)/h*100}function Fb(e,t,n,r,i,s){if(Lf(e)){const a=n==="horizontal";let o=0;e.shiftKey?o=100:i!=null?o=i:o=10;let l=0;switch(e.key){case"ArrowDown":l=a?0:o;break;case"ArrowLeft":l=a?-o:0;break;case"ArrowRight":l=a?o:0;break;case"ArrowUp":l=a?0:-o;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:$b(e,t,n,r,s)}function Lb({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 a=n[s];_e(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;o!=null&&(r++,t[s]=o,i-=o)}for(let s=0;s<e.length;s++){const a=n[s];_e(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;if(o!=null)continue;const l=e.length-r,c=i/l;r++,t[s]=c,i-=c}return t}function Jn(e,t,n){t.forEach((r,i)=>{const s=e[i];_e(s,`Panel data not found for index ${i}`);const{callbacks:a,constraints:o,id:l}=s,{collapsedSize:c=0,collapsible:f}=o,d=n[l];if(d==null||r!==d){n[l]=r;const{onCollapse:h,onExpand:p,onResize:g}=a;g&&g(r,d),f&&(h||p)&&(p&&(d==null||sn(d,c))&&!sn(r,c)&&p(),h&&(d==null||!sn(d,c))&&sn(r,c)&&h())}})}function Ci(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 Bb({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const a=n[i];let o;return a==null?o=e!=null?e.toPrecision(s):"1":r.length===1?o="1":o=a.toPrecision(s),{flexBasis:0,flexGrow:o,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function Zb(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function $l(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 Xf(e){return`react-resizable-panels:${e}`}function Qf(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 ep(e,t){try{const n=Xf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Vb(e,t,n){var r,i;const s=(r=ep(e,n))!==null&&r!==void 0?r:{},a=Qf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Ub(e,t,n,r,i){var s;const a=Xf(e),o=Qf(t),l=(s=ep(e,i))!==null&&s!==void 0?s:{};l[o]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(a,JSON.stringify(l))}catch(c){console.error(c)}}function Fl({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,a)=>s+a,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Nt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const a=n[s];_e(a!=null,`No layout data found for index ${s}`);const o=100/r*a;n[s]=o}let i=0;for(let s=0;s<t.length;s++){const a=n[s];_e(a!=null,`No layout data found for index ${s}`);const o=tr({panelConstraints:t,panelIndex:s,size:a});a!=o&&(i+=a-o,n[s]=o)}if(!Nt(i,0))for(let s=0;s<t.length;s++){const a=n[s];_e(a!=null,`No layout data found for index ${s}`);const o=a+i,l=tr({panelConstraints:t,panelIndex:s,size:o});if(a!==l&&(i-=l-a,n[s]=l,Nt(i,0)))break}return n}const Jb=100,Zr={getItem:e=>($l(Zr),Zr.getItem(e)),setItem:(e,t)=>{$l(Zr),Zr.setItem(e,t)}},Ll={};function tp({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:a=null,keyboardResizeBy:o=null,storage:l=Zr,style:c,tagName:f="div",...d}){const h=_o(s),p=wt(null),[g,w]=ar(null),[_,b]=ar([]),N=Ob(),m=wt({}),O=wt(new Map),C=wt(0),v=wt({autoSaveId:e,direction:r,dragState:g,id:h,keyboardResizeBy:o,onLayout:a,storage:l}),k=wt({layout:_,panelDataArray:[],panelDataArrayChanged:!1});wt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),Mf(i,()=>({getId:()=>v.current.id,getLayout:()=>{const{layout:y}=k.current;return y},setLayout:y=>{const{onLayout:q}=v.current,{layout:X,panelDataArray:Y}=k.current,ie=Fl({layout:y,panelConstraints:Y.map(D=>D.constraints)});Ml(X,ie)||(b(ie),k.current.layout=ie,q&&q(ie),Jn(Y,ie,m.current))}}),[]),On(()=>{v.current.autoSaveId=e,v.current.direction=r,v.current.dragState=g,v.current.id=h,v.current.onLayout=a,v.current.storage=l}),Mb({committedValuesRef:v,eagerValuesRef:k,groupId:h,layout:_,panelDataArray:k.current.panelDataArray,setLayout:b,panelGroupElement:p.current}),zn(()=>{const{panelDataArray:y}=k.current;if(e){if(_.length===0||_.length!==y.length)return;let q=Ll[e];q==null&&(q=Zb(Ub,Jb),Ll[e]=q);const X=[...y],Y=new Map(O.current);q(e,X,Y,_,l)}},[e,_,l]),zn(()=>{});const $=gt(y=>{const{onLayout:q}=v.current,{layout:X,panelDataArray:Y}=k.current;if(y.constraints.collapsible){const ie=Y.map(ce=>ce.constraints),{collapsedSize:D=0,panelSize:ue,pivotIndices:he}=jn(Y,y,X);if(_e(ue!=null,`Panel size not found for panel "${y.id}"`),!sn(ue,D)){O.current.set(y.id,ue);const ee=Kn(Y,y)===Y.length-1?ue-D:D-ue,de=Br({delta:ee,initialLayout:X,panelConstraints:ie,pivotIndices:he,prevLayout:X,trigger:"imperative-api"});Ci(X,de)||(b(de),k.current.layout=de,q&&q(de),Jn(Y,de,m.current))}}},[]),H=gt((y,q)=>{const{onLayout:X}=v.current,{layout:Y,panelDataArray:ie}=k.current;if(y.constraints.collapsible){const D=ie.map(fe=>fe.constraints),{collapsedSize:ue=0,panelSize:he=0,minSize:ce=0,pivotIndices:ee}=jn(ie,y,Y),de=q??ce;if(sn(he,ue)){const fe=O.current.get(y.id),Re=fe!=null&&fe>=de?fe:de,We=Kn(ie,y)===ie.length-1?he-Re:Re-he,E=Br({delta:We,initialLayout:Y,panelConstraints:D,pivotIndices:ee,prevLayout:Y,trigger:"imperative-api"});Ci(Y,E)||(b(E),k.current.layout=E,X&&X(E),Jn(ie,E,m.current))}}},[]),j=gt(y=>{const{layout:q,panelDataArray:X}=k.current,{panelSize:Y}=jn(X,y,q);return _e(Y!=null,`Panel size not found for panel "${y.id}"`),Y},[]),I=gt((y,q)=>{const{panelDataArray:X}=k.current,Y=Kn(X,y);return Bb({defaultSize:q,dragState:g,layout:_,panelData:X,panelIndex:Y})},[g,_]),T=gt(y=>{const{layout:q,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:ie,panelSize:D}=jn(X,y,q);return _e(D!=null,`Panel size not found for panel "${y.id}"`),ie===!0&&sn(D,Y)},[]),P=gt(y=>{const{layout:q,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:ie,panelSize:D}=jn(X,y,q);return _e(D!=null,`Panel size not found for panel "${y.id}"`),!ie||Dn(D,Y)>0},[]),A=gt(y=>{const{panelDataArray:q}=k.current;q.push(y),q.sort((X,Y)=>{const ie=X.order,D=Y.order;return ie==null&&D==null?0:ie==null?-1:D==null?1:ie-D}),k.current.panelDataArrayChanged=!0,N()},[N]);On(()=>{if(k.current.panelDataArrayChanged){k.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:q,storage:X}=v.current,{layout:Y,panelDataArray:ie}=k.current;let D=null;if(y){const he=Vb(y,ie,X);he&&(O.current=new Map(Object.entries(he.expandToSizes)),D=he.layout)}D==null&&(D=Lb({panelDataArray:ie}));const ue=Fl({layout:D,panelConstraints:ie.map(he=>he.constraints)});Ml(Y,ue)||(b(ue),k.current.layout=ue,q&&q(ue),Jn(ie,ue,m.current))}}),On(()=>{const y=k.current;return()=>{y.layout=[]}},[]);const M=gt(y=>{let q=!1;const X=p.current;return X&&window.getComputedStyle(X,null).getPropertyValue("direction")==="rtl"&&(q=!0),function(ie){ie.preventDefault();const D=p.current;if(!D)return()=>null;const{direction:ue,dragState:he,id:ce,keyboardResizeBy:ee,onLayout:de}=v.current,{layout:fe,panelDataArray:Re}=k.current,{initialLayout:Oe}=he??{},We=Gf(ce,y,D);let E=Fb(ie,y,ue,he,ee,D);const R=ue==="horizontal";R&&q&&(E=-E);const Z=Re.map(K=>K.constraints),se=Br({delta:E,initialLayout:Oe??fe,panelConstraints:Z,pivotIndices:We,prevLayout:fe,trigger:Lf(ie)?"keyboard":"mouse-or-touch"}),z=!Ci(fe,se);(Bf(ie)||Zf(ie))&&C.current!=E&&(C.current=E,!z&&E!==0?R?Xs(y,E<0?Uf:Jf):Xs(y,E<0?Hf:Wf):Xs(y,0)),z&&(b(se),k.current.layout=se,de&&de(se),Jn(Re,se,m.current))}},[]),V=gt((y,q)=>{const{onLayout:X}=v.current,{layout:Y,panelDataArray:ie}=k.current,D=ie.map(fe=>fe.constraints),{panelSize:ue,pivotIndices:he}=jn(ie,y,Y);_e(ue!=null,`Panel size not found for panel "${y.id}"`);const ee=Kn(ie,y)===ie.length-1?ue-q:q-ue,de=Br({delta:ee,initialLayout:Y,panelConstraints:D,pivotIndices:he,prevLayout:Y,trigger:"imperative-api"});Ci(Y,de)||(b(de),k.current.layout=de,X&&X(de),Jn(ie,de,m.current))},[]),U=gt((y,q)=>{const{layout:X,panelDataArray:Y}=k.current,{collapsedSize:ie=0,collapsible:D}=q,{collapsedSize:ue=0,collapsible:he,maxSize:ce=100,minSize:ee=0}=y.constraints,{panelSize:de}=jn(Y,y,X);de!=null&&(D&&he&&sn(de,ie)?sn(ie,ue)||V(y,ue):de<ee?V(y,ee):de>ce&&V(y,ce))},[V]),J=gt((y,q)=>{const{direction:X}=v.current,{layout:Y}=k.current;if(!p.current)return;const ie=zs(y,p.current);_e(ie,`Drag handle element not found for id "${y}"`);const D=Kf(X,q);w({dragHandleId:y,dragHandleRect:ie.getBoundingClientRect(),initialCursorPosition:D,initialLayout:Y})},[]),ne=gt(()=>{w(null)},[]),S=gt(y=>{const{panelDataArray:q}=k.current,X=Kn(q,y);X>=0&&(q.splice(X,1),delete m.current[y.id],k.current.panelDataArrayChanged=!0,N())},[N]),oe=bb(()=>({collapsePanel:$,direction:r,dragState:g,expandPanel:H,getPanelSize:j,getPanelStyle:I,groupId:h,isPanelCollapsed:T,isPanelExpanded:P,reevaluatePanelConstraints:U,registerPanel:A,registerResizeHandle:M,resizePanel:V,startDragging:J,stopDragging:ne,unregisterPanel:S,panelGroupElement:p.current}),[$,g,r,H,j,I,h,T,P,U,A,M,V,J,ne,S]),B={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return xr(Ts.Provider,{value:oe},xr(f,{...d,children:t,className:n,id:s,ref:p,style:{...B,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":h}))}const np=Df((e,t)=>xr(tp,{...e,forwardedRef:t}));tp.displayName="PanelGroup";np.displayName="forwardRef(PanelGroup)";function Kn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function jn(e,t,n){const r=Kn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],a=n[r];return{...t.constraints,panelSize:a,pivotIndices:s}}function Hb({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){zn(()=>{if(e||n==null||r==null)return;const i=zs(t,r);if(i==null)return;const s=a=>{if(!a.defaultPrevented)switch(a.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{a.preventDefault(),n(a);break}case"F6":{a.preventDefault();const o=i.getAttribute("data-panel-group-id");_e(o,`No group element found for id "${o}"`);const l=ai(o,r),c=qf(o,t,r);_e(c!==null,`No resize element found for id "${t}"`);const f=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[f].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function rp({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:f="div",...d}){var h,p;const g=wt(null),w=wt({onDragging:a});zn(()=>{w.current.onDragging=a});const _=Rf(Ts);if(_===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:b,groupId:N,registerResizeHandle:m,startDragging:O,stopDragging:C,panelGroupElement:v}=_,k=_o(i),[$,H]=ar("inactive"),[j,I]=ar(!1),[T,P]=ar(null),A=wt({state:$});On(()=>{A.current.state=$}),zn(()=>{if(n)P(null);else{const J=m(k);P(()=>J)}},[n,k,m]);const M=(h=r==null?void 0:r.coarse)!==null&&h!==void 0?h:15,V=(p=r==null?void 0:r.fine)!==null&&p!==void 0?p:5;return zn(()=>{if(n||T==null)return;const J=g.current;return _e(J,"Element ref not attached"),zb(k,J,b,{coarse:M,fine:V},(S,oe,B)=>{if(oe)switch(S){case"down":{H("drag"),_e(B,'Expected event to be defined for "down" action'),O(k,B);const{onDragging:y}=w.current;y&&y(!0);break}case"move":{const{state:y}=A.current;y!=="drag"&&H("hover"),_e(B,'Expected event to be defined for "move" action'),T(B);break}case"up":{H("hover"),C();const{onDragging:y}=w.current;y&&y(!1);break}}else H("inactive")})},[M,b,n,V,m,k,T,O,C]),Hb({disabled:n,handleId:k,resizeHandler:T,panelGroupElement:v}),xr(f,{...d,children:e,className:t,id:i,onBlur:()=>{I(!1),s==null||s()},onFocus:()=>{I(!0),o==null||o()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":b,"data-panel-group-id":N,"data-resize-handle":"","data-resize-handle-active":$==="drag"?"pointer":j?"keyboard":void 0,"data-resize-handle-state":$,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":k})}rp.displayName="PanelResizeHandle";const Wb=({className:e,...t})=>u.jsx(np,{className:G("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Qs=Ff,Bl=({withHandle:e,className:t,...n})=>u.jsx(rp,{className:G("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&&u.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:u.jsx(Yg,{className:"h-2.5 w-2.5"})})}),ip=x.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:G("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}));ip.displayName="Textarea";class qb{constructor(t){Vs(this,"client");this.client=gx.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 Gb=new qb;class Yb extends Error{constructor(n,r){super(n);Vs(this,"quality");this.name="QualityGateFailedError",this.quality=r}}function Kb(e,t){return e??t}function Xb(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 Qb(e){if(Xb(e.headers.get("content-type")))try{return await e.json()}catch{return}}function Zl(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 ev(){const e=x.useRef(null),t=Hi(s=>s.generationBackend),n=Ld(),r=x.useCallback(async(s,a,o,l,c)=>{e.current&&e.current.abort();const f=new AbortController;e.current=f;const d=Kb(c==null?void 0:c.renderer,t);try{l==null||l("parsing","Validating JSON structure...");let h;try{h=JSON.parse(a)}catch(H){throw new Error(`Invalid JSON: ${H instanceof Error?H.message:"Unknown parse error"}`)}l==null||l("building",`Building ${ji.toLowerCase()} structure...`);const p={jsonDefinition:h,options:{...c,sourceName:n(s),...d?{renderer:d}:{}}};p.customThemes=o??{},l==null||l("rendering",`Generating ${ht.toUpperCase()} content...`);const g={"Content-Type":"application/json"};c!=null&&c.bypassCache&&(g["X-Bypass-Cache"]="true");const w=await fetch(ei.generate,{method:"POST",headers:g,body:JSON.stringify(p),signal:f.signal}),_=await Qb(w);if(w.status===400&&(_==null?void 0:_.code)==="QUALITY_GATE_FAILED")throw new Yb(Zl(w,_),_.quality);if(!w.ok||!(_!=null&&_.success))throw new Error(Zl(w,_));const{data:b,cache:N,warnings:m}=_,O=N.status==="HIT"?"HIT":N.status==="MISS"?"MISS":"UNKNOWN",C=O==="HIT"?`Served from cache (Hit rate: ${N.hitRate})`:`Generated fresh ${ji.toLowerCase()}`;l==null||l("finalizing",C);const v=globalThis.atob(b.document),k=new Uint8Array(v.length);for(let H=0;H<v.length;H++)k[H]=v.charCodeAt(H);const $=new Blob([k],{type:b.contentType});if($.size===0)throw new Error(`Received empty ${ji.toLowerCase()} from API`);return{name:s,text:a,blob:$,...d?{renderer:d}:{},filename:b.filename,fileId:b.fileId,cacheStatus:O,cacheHitRate:N.hitRate,warnings:m}}catch(h){throw h instanceof Error&&h.name==="AbortError"?new Error(`${ji} generation was cancelled`):h}finally{e.current===f&&(e.current=null)}},[t,n]),i=x.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:r,generateDocument:r,cancelGeneration:i}}const Bi={ids:[],default:null};let Vl;function tv(){return Vl??(Vl=(async()=>{var e;try{const t=await fetch(ei.renderers);if(!t.ok)return Bi;const n=await t.json();return!(n!=null&&n.success)||!Array.isArray((e=n.data)==null?void 0:e.ids)?Bi:n.data}catch{return Bi}})()),Vl}function nv(){const[e,t]=x.useState(Bi);return x.useEffect(()=>{let n=!1;return tv().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 a of i){let o=a.message;if(a.context&&Object.keys(a.context).length>0){const l=Object.entries(a.context).map(([c,f])=>`${c}: ${JSON.stringify(f)}`).join(", ");o+=` (${l})`}s.push(o)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function iv({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=je.useState("custom");je.useEffect(()=>{e&&s("custom")},[e]);const a=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),o=[{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 u.jsx(Ct,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(kt,{className:"max-w-md",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Non-safe fonts in this document"}),u.jsxs(on,{children:[a," ",n.length===1?"is":"are"," not in the built-in safe list. Choose how to export."]})]}),u.jsx("div",{className:"grid gap-2 py-2",children:o.map(l=>{const c=i===l.value;return u.jsxs("button",{type:"button",onClick:()=>s(l.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${c?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${c?"border-primary":"border-muted-foreground/50"}`,children:c&&u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),u.jsx("span",{className:"text-sm font-medium",children:l.title})]}),u.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:l.desc})]},l.value)})}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(Se,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}function ea(){return u.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 Ul(){return u.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 sv({name:e,blob:t,onManualRender:n,isGenerating:r,isRendering:i,onShowCacheMetrics:s,onShowSchemas:a,onShowFonts:o,documentText:l,editorDocumentText:c,editorDocumentName:f,warnings:d,onToggleChat:h,chatOpen:p,onTogglePreview:g,previewOpen:w}){const[_,b]=x.useState(!1),[N,m]=x.useState(!1),[O,C]=x.useState(!1),[v,k]=x.useState(!1),[$,H]=x.useState(!1),[j,I]=x.useState(null),{toast:T}=Sr(),P=Ld(),{generateDocument:A}=ev(),M=x.useContext(Fd),V=nv(),U=Hi(ee=>ee.generationBackend),J=Hi(ee=>ee.setSettings),ne=U??V.default??void 0,S=x.useCallback(()=>{const ee={},{customThemes:de}=M.getState();return Object.values(de).forEach(fe=>{fe.valid&&fe.parsed&&(ee[fe.name]=fe.parsed)}),ee},[M]),oe=je.useMemo(()=>{if(!l)return[];try{const ee=JSON.parse(l);return[...(ht==="pptx"?_g:jg)(ee)].filter(fe=>!Ng(fe))}catch{return[]}},[l]),[B,y]=x.useState(!1),q=x.useCallback(async()=>{if(t){b(!0);try{await new Promise(ee=>setTimeout(ee,100)),Li(`${e}${Tr}`,t)}finally{setTimeout(()=>b(!1),500)}}},[t,e]),X=x.useCallback(async()=>{if(t){if(oe.length===0){await q();return}y(!0)}},[t,oe.length,q]),Y=x.useCallback(async ee=>{var de;if(l){b(!0);try{const fe=await A(e,l,S(),void 0,{bypassCache:!0,fonts:{mode:ee}});if(fe.blob.size===0)T({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Li(`${e}${Tr}`,fe.blob);const Re=(de=fe.warnings)==null?void 0:de.find(Oe=>{var We,E;return((We=Oe.context)==null?void 0:We.code)==="FONT_MODE_SUBSTITUTED"||((E=Oe.context)==null?void 0:E.code)==="FONT_MODE_CUSTOM"});Re&&T({title:ee==="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(()=>b(!1),500)}}},[l,e,A,T,S]),ie=x.useCallback(async()=>{if(!(!d||d.length===0)){m(!0);try{const ee=rv(d);if(!ee){T({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const de=await A("warnings",JSON.stringify(ee,null,2),{});de&&typeof de=="object"&&"blob"in de&&de.blob&&(Li(`${e}-warnings${Tr}`,de.blob),T({title:"Warnings downloaded",description:`Downloaded warnings document with ${d.length} warning(s).`}))}catch(ee){console.error("Failed to generate warnings document:",ee),T({title:"Download failed",description:ee instanceof Error?ee.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>m(!1),500)}}},[d,e,A,T]),D=x.useCallback(async()=>{C(!0);try{await Gb.delete(`/${ht}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),T({title:"Cache Cleared",description:"All active caches have been successfully cleared.",variant:"default"})}catch(ee){console.error("Failed to clear cache:",ee),T({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{C(!1)}},[T]),ue=c??l,he=x.useCallback(()=>{var fe,Re;if(!ue){T({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(ue)}catch{T({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}H(!0);const ee=(async()=>{const Oe=await fetch(`/api/${ht}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:ue,customThemes:S(),options:{sourceName:P(f??e)}})});if(!Oe.ok){let E=`Request failed with status ${Oe.status}`;try{const R=await Oe.json(),Z=R.error??R.message;typeof Z=="string"&&Z&&(E=Z)}catch{}throw new Error(E)}const We=await Oe.json();return JSON.stringify(We.data,null,2)})();let de;typeof ClipboardItem<"u"&&((fe=navigator.clipboard)!=null&&fe.write)?de=navigator.clipboard.write([new ClipboardItem({"text/plain":ee.then(Oe=>new Blob([Oe],{type:"text/plain"}))})]):(Re=navigator.clipboard)!=null&&Re.writeText?de=ee.then(Oe=>navigator.clipboard.writeText(Oe)):de=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await de,T({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(Oe){let We=null;try{We=await ee}catch(E){console.error("Error fetching standard components:",E),T({title:"Failed to get standard components",description:E instanceof Error?E.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",Oe),I(We)}finally{H(!1)}})()},[ue,e,f,P,S,T]),ce=x.useCallback(async()=>{if(j!=null)try{await navigator.clipboard.writeText(j),T({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),I(null)}catch{T({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[j,T]);return u.jsxs(u.Fragment,{children:[u.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:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[u.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.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:u.jsx(Od,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Xe,{className:"max-w-sm",children:u.jsxs("p",{className:"text-sm",children:["Preview converts the file to a PDF with LibreOffice. Download the ",Tr," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(Se,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:n,"aria-label":"Render preview",disabled:r||i||w===!1,children:[i?u.jsx(gn,{size:"sm"}):u.jsx(Kg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Xe,{children:u.jsx("p",{children:w===!1?"Open preview to run":i?"Rendering preview...":"Render preview"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(Se,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||_||r,onClick:X,children:[_?u.jsx(gn,{size:"sm"}):u.jsx(Xg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Xe,{children:u.jsxs("p",{children:["Download ",Tr]})})]}),d&&d.length>0&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Se,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:N||r,onClick:ie,children:N?u.jsx(gn,{size:"sm"}):u.jsx(Dd,{className:"h-3.5 w-3.5"})})}),u.jsx(Xe,{children:u.jsxs("p",{children:["Download warnings (",d.length,")"]})})]}),V.ids.length>1&&u.jsxs(ti,{value:ne,onValueChange:ee=>J({generationBackend:ee}),children:[u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(fr,{"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:[u.jsx(Na,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),u.jsxs(ni,{placeholder:"Renderer",children:[u.jsx("span",{className:"font-medium",children:ne}),ne!==V.default&&u.jsx(ea,{})]})]})}),u.jsx(Xe,{children:u.jsxs("p",{children:["Renderer that writes the ",ht.toUpperCase()," file. A non-default one may refuse a document it cannot express."]})})]}),u.jsx(pr,{className:"min-w-[var(--radix-select-trigger-width)] text-sidebar-foreground",children:u.jsxs(Zd,{children:[u.jsx(ho,{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),V.ids.map(ee=>u.jsx(Pn,{value:ee,className:"text-xs",children:u.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap",children:[u.jsx("span",{className:"font-medium",children:ee}),ee===V.default?u.jsx(Ul,{}):u.jsx(ea,{})]})},ee))]})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(Ns,{children:[u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Es,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Ad,{className:"h-3.5 w-3.5"})})})}),u.jsx(Xe,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(yi,{align:"end",className:"w-52",children:[a&&u.jsxs($t,{onClick:a,children:[u.jsx(Qg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),o&&u.jsxs($t,{onClick:o,children:[u.jsx(ja,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),s&&u.jsxs($t,{onClick:s,children:[u.jsx(Ea,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),ue?u.jsxs($t,{onClick:he,disabled:$,children:[u.jsx(Ca,{className:"h-4 w-4 mr-2"}),$?"Copying...":"Copy standard components"]}):u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs($t,{disabled:!0,children:[u.jsx(Ca,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),u.jsx(Xe,{side:"left",children:u.jsx("p",{children:"No document selected — open or select a document first"})})]}),u.jsx(mr,{}),u.jsxs($t,{onClick:()=>k(!0),disabled:O,className:"text-destructive focus:text-destructive",children:[u.jsx(fo,{className:"h-4 w-4 mr-2"}),O?"Clearing...":"Clear all caches"]}),V.ids.length>1&&u.jsxs(u.Fragment,{children:[u.jsx(mr,{className:"lg:hidden"}),u.jsx(ko,{className:"lg:hidden px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),V.ids.map(ee=>u.jsxs($t,{className:"lg:hidden gap-1.5",onClick:()=>J({generationBackend:ee}),children:[u.jsx(an,{className:`h-3.5 w-3.5 shrink-0 ${ne===ee?"opacity-100":"opacity-0"}`}),u.jsx("span",{className:"font-medium",children:ee}),ee===V.default?u.jsx(Ul,{}):u.jsx(ea,{})]},ee))]})]})]}),g&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Se,{variant:w?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:g,children:w?u.jsx(Rd,{className:"h-3.5 w-3.5"}):u.jsx(ex,{className:"h-3.5 w-3.5"})})}),u.jsx(Xe,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[w?"Hide":"Show"," Preview"," ",u.jsx(ii,{shortcut:"mod+shift+p"})]})})]}),h&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Se,{variant:p?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:h,children:u.jsx(Md,{className:"h-3.5 w-3.5"})})}),u.jsx(Xe,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[p?"Close":"Open"," AI Chat"," ",u.jsx(ii,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(iv,{open:B,onClose:()=>y(!1),nonSafeFonts:oe,onChoose:Y}),u.jsx(Ct,{open:j!=null,onOpenChange:ee=>{ee||I(null)},children:u.jsxs(kt,{className:"max-w-lg",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Standard components"}),u.jsx(on,{children:"The browser blocked the automatic clipboard write. Copy the JSON from here instead."})]}),u.jsx(ip,{readOnly:!0,value:j??"",className:"h-64 font-mono text-xs",onFocus:ee=>ee.currentTarget.select()}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:()=>I(null),children:"Close"}),u.jsx(Se,{size:"sm",onClick:ce,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:v,onOpenChange:k,children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Clear all caches?"}),u.jsx(on,{children:"This will clear the document, component, and rasterized-visual caches. Next generation will be uncached."})]}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:()=>k(!1),children:"Cancel"}),u.jsx(Se,{variant:"destructive",size:"sm",disabled:O,onClick:async()=>{await D(),k(!1)},children:O?u.jsx(gn,{size:"sm"}):"Clear"})]})]})})]})}const av=je.memo(sv),sp=bg,Co=x.forwardRef(({className:e,...t},n)=>u.jsx(kd,{ref:n,className:G("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Co.displayName=kd.displayName;const lr=x.forwardRef(({className:e,...t},n)=>u.jsx(Sd,{ref:n,className:G("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}));lr.displayName=Sd.displayName;const ur=x.forwardRef(({className:e,...t},n)=>u.jsx(_d,{ref:n,className:G("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));ur.displayName=_d.displayName;async function ov(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 lv(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 uv(e){const t=lv(e);return ov(t)}const cv=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=x.useState(n),[s,a]=x.useState(null),[o,l]=x.useState(null),[c,f]=x.useState(!1),[d,h]=x.useState(!1),[p,g]=x.useState(null),[w,_]=x.useState(null),[b,N]=x.useState(!1),{toast:m}=Sr(),O=Lt(P=>P.selectedPlugins),C=Array.from(O);x.useEffect(()=>{n&&i(n)},[n]);const v=x.useCallback(async()=>{f(!0),g(null);try{const P=await Us.fetchDocumentSchema(C);a(P)}catch(P){const A=P instanceof Error?P.message:"Failed to load document schema";g(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{f(!1)}},[C,m]),k=x.useCallback(async()=>{if(!o){h(!0),_(null);try{const P=await Us.fetchThemeSchema();l(P)}catch(P){const A=P instanceof Error?P.message:"Failed to load theme schema";_(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{h(!1)}}},[o,m]),[$,H]=x.useState([]);x.useEffect(()=>{e||(a(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const P=C.length!==$.length||C.some((A,M)=>A!==$[M]);r==="document"?(!s||P)&&(P&&(Us.clearPluginSchemaCache(),H([...C])),c||v()):r==="theme"&&!o&&!d&&k()},[r,e,s,o,c,d,C,$,v,k]);const j=C.length,I=r==="document"?s:o,T=async()=>{if(I)try{await uv(I)&&(N(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>N(!1),2e3))}catch(P){console.error("Copy failed:",P)}};return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Vt,{children:u.jsx(Ut,{children:"Schema Viewer"})}),u.jsxs(sp,{value:r,onValueChange:P=>i(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Co,{children:[u.jsxs(lr,{value:"document",className:"flex items-center gap-1",children:["Document",j>0&&u.jsxs(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",j]})]}),u.jsx(lr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(Se,{variant:"ghost",size:"icon",onClick:T,disabled:b||!I,"aria-label":"Copy schema",children:b?u.jsx(an,{className:"h-4 w-4"}):u.jsx(ks,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(ur,{value:"document",className:"h-full",children:u.jsx(ts,{schema:s,loading:c,error:p||void 0})}),u.jsx(ur,{value:"theme",className:"h-full",children:u.jsx(ts,{schema:o,loading:d,error:w||void 0})})]})]})]})})};function To(e,t){var r;const n=$d.getState().getEditor(e);return(r=n==null?void 0:n.flushPendingSave)==null||r.call(n),n?n.toStorageValue(n.editor.getValue()):t}function ap(e,t,n){if(t.length===0)return n;const r=Jl(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const a=t[s],o=t[s+1],l=i[a],c=Jl(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function Jl(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Hl=2*1024*1024,Wl=12*1024*1024;function dv(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 fv(e){let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function is(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.round(e/1024)} KB`}function pv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>Hl)return{ok:!1,message:`"${e}" is ${is(t.length)}. The limit is ${is(Hl)} per font, because the bytes travel inside the document JSON.`};const n=dv(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:fv(t)}}const hv=new Set(["italic","oblique"]);function mv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[a,o]of Object.entries(Ed))r.set(o.toLowerCase(),Number(a));let i=400,s=!1;for(;n.length>1;){const a=n[n.length-1].toLowerCase();if(hv.has(a)){s=!0,n.pop();continue}const o=r.get(a);if(o!==void 0){i=o,n.pop();continue}break}return{family:n.join(" ")||t,weight:i,italic:s}}function gv(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 xv(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 yv(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(o=>{const l=xv(o);return l?!n.some(c=>c.weight===l.weight&&c.italic===l.italic):!0}),s=n.map(o=>({kind:"data",data:o.data,weight:o.weight,italic:o.italic})),a=r??(e==null?void 0:e.category);return{id:(e==null?void 0:e.id)??t,family:t,...a?{category:a}:{},sources:[...i,...s]}}function bv(e,t){let n=Array.isArray(e)?[...e]:[];for(const r of t){const i=r.sources.filter(a=>a.kind==="data").map(a=>({data:a.data,weight:a.weight??400,italic:a.italic??!1}));if(i.length===0)continue;const s=n.find(a=>{var o;return((o=a==null?void 0:a.family)==null?void 0:o.toLowerCase())===r.family.toLowerCase()});n=gv(n,yv(s,r.family,i,r.category))}return n}function vv(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 wv(e){const t=new TextEncoder().encode(e).length;return t<=Wl?null:`Adding this font would push the document to ${is(t)}, past the ${is(Wl)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const ql=new Set,kv=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function Sv(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 _v(e,t,n,r){const i=kv(e,n,r);if(!ql.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=Sv(t),a=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await a.load(),document.fonts.add(a),ql.add(i)}catch{}}const jv={safe:[],google:[]};function Gl(e,t){var f;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((f=r==null?void 0:r.dataset.weights)==null?void 0:f.split(",").map(Number).filter(d=>!Number.isNaN(d)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((d,h)=>d-h).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${o}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...a].sort((d,h)=>d-h).join(",")}function Nv(){const e=Ne(i=>i.activeTab),t=Ne(i=>i.documents),n=Ne(i=>i.documentTypes),r=Ne(i=>i.saveDocument);return x.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(c=>c.name===e);if(!s)return{ok:!1,error:"Active theme not found"};const a=To(e,s.text);let o;try{o=JSON.parse(a)}catch(c){return{ok:!1,error:`Active theme is not valid JSON: ${c.message}`}}const l=i(o);return r(e,JSON.stringify(l,null,2)),{ok:!0,name:e}},[e,t,n,r])}function Ev(){const e=Ne(r=>r.activeTab),t=Ne(r=>r.documents),n=Ne(r=>r.saveDocument);return x.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(c=>c.name===e);if(!s)return{ok:!1,error:"Active document not found"};const a=To(e,s.text);let o;try{o=JSON.parse(a)}catch(c){return{ok:!1,error:`Active document is not valid JSON: ${c.message}`}}const l=ap(o,r,i);return n(e,JSON.stringify(l,null,2)),{ok:!0,name:e}},[e,t,n])}function Cv(){const e=Ne(i=>i.activeTab),t=Ne(i=>i.documents),n=Ne(i=>i.documentTypes),r=Ne(i=>i.saveDocument);return x.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 a=To(e,s.text);let o;try{o=JSON.parse(a)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const l=bv((h=o==null?void 0:o.props)==null?void 0:h.fontRegistry,i),c=ap(o,["props","fontRegistry"],l),f=JSON.stringify(c,null,2),d=wv(f);return d?{ok:!1,error:d}:(r(e,f),{ok:!0,name:e})},[e,t,n,r])}function Tv(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 Yl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Iv=({open:e,onOpenChange:t})=>{const n=$i(D=>D.open),r=$i(D=>D.contextual),i=$i(D=>D.close),s=e??n,a=r,o=x.useCallback(D=>{t&&t(D),D||i()},[t,i]),[l,c]=x.useState(jv),[f,d]=x.useState(!1),[h,p]=x.useState(""),[g,w]=x.useState("safe"),[_,b]=x.useState(null),[N,m]=x.useState(null),[O,C]=x.useState(!1),[v,k]=x.useState(!1),[$,H]=x.useState(""),[j,I]=x.useState([]),T=x.useRef(null),{toast:P}=Sr(),A=Nv(),M=Ev(),V=Cv(),U=Ne(D=>D.activeTab),J=Ne(D=>D.documentTypes),ne=U&&J[U]==="application/json+theme",S=!!a||ne;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(d(!0),fetch(ei.fonts.catalog).then(D=>D.json()).then(D=>c(D)).catch(D=>{P({variant:"destructive",title:"Font catalog unavailable",description:D.message})}).finally(()=>d(!1))))},[s,l,P]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const D of l.google)Gl(D.family,D.weights)},[g,l]);const oe=x.useMemo(()=>l.safe.filter(D=>D.toLowerCase().includes(h.toLowerCase())),[l.safe,h]),B=x.useMemo(()=>l.google.filter(D=>D.family.toLowerCase().includes(h.toLowerCase())),[l.google,h]),y=x.useCallback(async D=>{try{await navigator.clipboard.writeText(D),m(D),setTimeout(()=>m(null),1500)}catch{P({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[P]),q=x.useCallback(async(D,ue,he)=>{b(D);try{const ce=A(ee=>(Tv(ee,he,D),ee));if(!ce.ok){P({variant:"destructive",title:"Could not insert font",description:ce.error});return}P({title:"Font inserted",description:`${D} set as ${he} font in "${ce.name}".`})}finally{b(null)}},[A,P]),X=x.useCallback(async D=>{if(a){b(D);try{const ue=M(a.jsonPath,D);if(!ue.ok){P({variant:"destructive",title:"Could not insert font",description:ue.error});return}P({title:"Font inserted",description:`${D} set at ${Yl(a.jsonPath)}.`}),o(!1)}finally{b(null)}}},[a,M,P,o]),Y=x.useCallback(async D=>{if(!(!D||D.length===0)){C(!0);try{const ue=[];for(const ce of Array.from(D)){const ee=new Uint8Array(await ce.arrayBuffer()),de=pv(ce.name,ee);if(!de.ok){P({variant:"destructive",title:"Font rejected",description:de.message});continue}ue.push({identity:mv(ce.name),base64:de.base64})}if(ue.length===0)return;const he=V(ue.map(({identity:ce,base64:ee})=>({id:ce.family,family:ce.family,sources:[{kind:"data",data:ee,weight:ce.weight,italic:ce.italic}]})));if(!he.ok){P({variant:"destructive",title:"Could not register font",description:he.error});return}for(const{identity:ce,base64:ee}of ue)_v(ce.family,ee,ce.weight,ce.italic),P({title:`Added ${ce.family}`,description:`Registered at weight ${ce.weight}${ce.italic?" italic":""} in props.fontRegistry. Reference it as "${ce.family}".`})}catch(ue){P({variant:"destructive",title:"Upload failed",description:ue.message})}finally{C(!1),T.current&&(T.current.value="")}}},[V,P]),ie=x.useCallback(async()=>{var ue,he;const D=$.trim();if(D){k(!0),I([]);try{const ce=await fetch(ei.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:D,weights:[400,700],italics:!1})});if(ce.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!ce.ok){const Oe=await ce.json().catch(()=>({}));throw new Error(Oe.error??`Materialize failed (${ce.status})`)}const ee=await ce.json();I(ee.warnings??[]);const de=(ue=l.google.find(Oe=>Oe.family.toLowerCase()===ee.family.toLowerCase()))==null?void 0:ue.category,fe=vv(ee,de);if(!fe){P({variant:"destructive",title:"Nothing to embed",description:((he=ee.warnings)==null?void 0:he.join(" · "))||`Google Fonts has no family named "${D}".`});return}const Re=V([fe]);if(!Re.ok){P({variant:"destructive",title:"Could not register font",description:Re.error});return}Gl(ee.family,[400,700]),P({title:`Added ${ee.family}`,description:`Embedded ${fe.sources.length} weight(s) in props.fontRegistry.`})}catch(ce){P({variant:"destructive",title:"Google Fonts fetch failed",description:ce.message})}finally{k(!1)}}},[$,l.google,V,P]);return u.jsx(Ct,{open:s,onOpenChange:o,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Vt,{children:u.jsx(Ut,{children:a?`Font for ${Yl(a.jsonPath)}`:"Fonts"})}),!a&&!ne&&g!=="custom"&&u.jsx(ir,{children:u.jsxs(sr,{children:["Fonts are registered on themes. Open a ",u.jsx("code",{children:".theme.json"})," ","file to apply a font — the buttons below are disabled until you do."]})}),u.jsxs(sp,{value:g,onValueChange:D=>w(D),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Co,{children:[u.jsxs(lr,{value:"safe",children:["Safe",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(lr,{value:"google",children:["Google",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]}),u.jsx(lr,{value:"custom",children:"Custom"})]}),u.jsx(hr,{type:"search",placeholder:"Search fonts...",value:h,onChange:D=>p(D.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(ur,{value:"safe",className:"m-0",children:f&&oe.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Fr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:oe.map(D=>u.jsx(Kl,{family:D,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${D}", sans-serif`},onCopy:()=>y(D),copied:N===D,contextual:!!a,onUseThis:()=>X(D),onInsertHeading:()=>q(D,"safe","heading"),onInsertBody:()=>q(D,"safe","body"),applying:_===D,disabled:!S},D))})}),u.jsx(ur,{value:"google",className:"m-0",children:f&&B.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Fr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:B.map(D=>u.jsx(Kl,{family:D.family,meta:u.jsxs("span",{className:"text-xs",children:[D.category," · ",D.weights.length," weights"]}),previewStyle:{fontFamily:`"${D.family}", sans-serif`},onCopy:()=>y(D.family),copied:N===D.family,contextual:!!a,onUseThis:()=>X(D.family),onInsertHeading:()=>q(D.family,"google","heading"),onInsertBody:()=>q(D.family,"google","body"),applying:_===D.family,disabled:!S,extraAction:u.jsx(zv,{family:D.family,weights:D.weights,hasItalic:D.hasItalic})},D.family))})}),u.jsx(ur,{value:"custom",className:"m-0 flex flex-col gap-6",children:ne?u.jsx(ir,{children:u.jsxs(sr,{children:["Custom fonts are stored on the document (",u.jsx("code",{children:"props.fontRegistry"}),"), because the bytes travel with the JSON. Open a document tab to add one."]})}):u.jsxs(u.Fragment,{children:[u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Upload a font file"}),u.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."," ",u.jsx("code",{children:"Geist-SemiBold.ttf"}),")."]}),u.jsxs("div",{onDragOver:D=>D.preventDefault(),onDrop:D=>{D.preventDefault(),Y(D.dataTransfer.files)},className:"rounded-md border border-dashed p-6 text-center",children:[u.jsx("input",{ref:T,type:"file",accept:".ttf,.otf,font/ttf,font/otf",multiple:!0,className:"hidden",onChange:D=>void Y(D.target.files)}),u.jsxs(Se,{variant:"secondary",disabled:O,onClick:()=>{var D;return(D=T.current)==null?void 0:D.click()},children:[O?u.jsx(Fr,{className:"animate-spin mr-2 h-4 w-4"}):u.jsx(tx,{className:"mr-2 h-4 w-4"}),"Choose font files"]}),u.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"or drop them here"})]})]}),u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Embed any Google font"}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not limited to the ",l.google.length," curated families — type any Google Fonts family name and its regular and bold weights are fetched and embedded."]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(hr,{placeholder:"e.g. Geist",value:$,onChange:D=>H(D.target.value),onKeyDown:D=>{D.key==="Enter"&&ie()}}),u.jsxs(Se,{onClick:()=>void ie(),disabled:v||$.trim()==="",children:[v&&u.jsx(Fr,{className:"animate-spin mr-2 h-4 w-4"}),"Embed"]})]}),j.length>0&&u.jsx(ir,{children:u.jsx(sr,{className:"text-xs",children:j.join(" · ")})})]})]})})]})]})]})})},Av="The quick brown fox jumps over the lazy dog",zv=({family:e,weights:t,hasItalic:n})=>{const r=x.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(Ns,{children:[u.jsx(Es,{asChild:!0,children:u.jsx(Se,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(yi,{align:"end",className:"min-w-[260px]",children:[u.jsxs(ko,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(mr,{}),r.map(i=>{const s=Ed[i]??String(i);return u.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-1.5",children:[u.jsx("span",{className:"truncate",style:{fontFamily:`"${e}", sans-serif`,fontWeight:i},children:s}),u.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:["fontWeight: ",i]})]},i)})]})]})},Kl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:f,extraAction:d})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:Av}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Se,{size:"sm",onClick:a,disabled:c||f,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(Se,{size:"sm",variant:"secondary",onClick:o,disabled:c||f,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Se,{size:"sm",variant:"secondary",onClick:l,disabled:c||f,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),d,u.jsx(Se,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(an,{className:"h-4 w-4"}):u.jsx(ks,{className:"h-4 w-4"})})]})]});function Xl({previewOpen:e,onTogglePreview:t}){const n=rn(v=>v.name||""),r=rn(v=>v.blob),i=rn(v=>v.isGenerating),s=rn(v=>v.text),a=rn(v=>v.warnings),o=rn(v=>v.isRendering),l=Hi(v=>v.useGlobalPreviewHeader??!0),c=Ne(v=>v.activeTab),f=Ne(v=>v.documentTypes),d=c&&f[c]==="application/json+theme"?"theme":"document",h=Ne(v=>{var k;return v.activeTab&&v.documentTypes[v.activeTab]!=="application/json+theme"?(k=v.documents.find($=>$.name===v.activeTab))==null?void 0:k.text:void 0}),p=Ne(v=>v.activeTab&&v.documentTypes[v.activeTab]!=="application/json+theme"?v.activeTab:void 0),g=Pe(v=>v.chatOpen),w=Pe(v=>v.toggleChat),[_,b]=je.useState(!1),N=$i(v=>v.openFor);if(!l)return null;const m=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),O=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),C=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(av,{name:C,blob:r,onManualRender:m,isGenerating:i,isRendering:!!o,onShowCacheMetrics:O,onShowSchemas:()=>b(!0),onShowFonts:()=>N(),documentText:s,editorDocumentText:h,editorDocumentName:p,warnings:a,onToggleChat:w,chatOpen:g,onTogglePreview:t,previewOpen:e}),u.jsx(cv,{open:_,onOpenChange:b,defaultTab:d==="theme"?"theme":"document"}),u.jsx(Iv,{})]})}function Ov(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Pv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Dv=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Rv={};function Ql(e,t){return(Rv.jsx?Dv:Pv).test(e)}const Mv=/[ \t\n\f\r]/g;function $v(e){return typeof e=="object"?e.type==="text"?eu(e.value):!1:eu(e)}function eu(e){return e.replace(Mv,"")===""}class bi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}bi.prototype.normal={};bi.prototype.property={};bi.prototype.space=void 0;function op(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new bi(n,r,t)}function Ba(e){return e.toLowerCase()}class St{constructor(t,n){this.attribute=n,this.property=t}}St.prototype.attribute="";St.prototype.booleanish=!1;St.prototype.boolean=!1;St.prototype.commaOrSpaceSeparated=!1;St.prototype.commaSeparated=!1;St.prototype.defined=!1;St.prototype.mustUseProperty=!1;St.prototype.number=!1;St.prototype.overloadedBoolean=!1;St.prototype.property="";St.prototype.spaceSeparated=!1;St.prototype.space=void 0;let Fv=0;const ke=$n(),nt=$n(),Za=$n(),re=$n(),Be=$n(),cr=$n(),jt=$n();function $n(){return 2**++Fv}const Va=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:nt,commaOrSpaceSeparated:jt,commaSeparated:cr,number:re,overloadedBoolean:Za,spaceSeparated:Be},Symbol.toStringTag,{value:"Module"})),ta=Object.keys(Va);class Io extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),tu(this,"space",i),typeof r=="number")for(;++s<ta.length;){const a=ta[s];tu(this,ta[s],(r&Va[a])===Va[a])}}}Io.prototype.defined=!0;function tu(e,t,n){n&&(e[t]=n)}function jr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Io(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Ba(r)]=r,n[Ba(s.attribute)]=r}return new bi(t,n,e.space)}const lp=jr({properties:{ariaActiveDescendant:null,ariaAtomic:nt,ariaAutoComplete:null,ariaBusy:nt,ariaChecked:nt,ariaColCount:re,ariaColIndex:re,ariaColSpan:re,ariaControls:Be,ariaCurrent:null,ariaDescribedBy:Be,ariaDetails:null,ariaDisabled:nt,ariaDropEffect:Be,ariaErrorMessage:null,ariaExpanded:nt,ariaFlowTo:Be,ariaGrabbed:nt,ariaHasPopup:null,ariaHidden:nt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Be,ariaLevel:re,ariaLive:null,ariaModal:nt,ariaMultiLine:nt,ariaMultiSelectable:nt,ariaOrientation:null,ariaOwns:Be,ariaPlaceholder:null,ariaPosInSet:re,ariaPressed:nt,ariaReadOnly:nt,ariaRelevant:null,ariaRequired:nt,ariaRoleDescription:Be,ariaRowCount:re,ariaRowIndex:re,ariaRowSpan:re,ariaSelected:nt,ariaSetSize:re,ariaSort:null,ariaValueMax:re,ariaValueMin:re,ariaValueNow:re,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function up(e,t){return t in e?e[t]:t}function cp(e,t){return up(e,t.toLowerCase())}const Lv=jr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:cr,acceptCharset:Be,accessKey:Be,action:null,allow:null,allowFullScreen:ke,allowPaymentRequest:ke,allowUserMedia:ke,alt:null,as:null,async:ke,autoCapitalize:null,autoComplete:Be,autoFocus:ke,autoPlay:ke,blocking:Be,capture:null,charSet:null,checked:ke,cite:null,className:Be,cols:re,colSpan:null,content:null,contentEditable:nt,controls:ke,controlsList:Be,coords:re|cr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Za,draggable:nt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Be,height:re,hidden:Za,high:re,href:null,hrefLang:null,htmlFor:Be,httpEquiv:Be,id:null,imageSizes:null,imageSrcSet:null,inert:ke,inputMode:null,integrity:null,is:null,isMap:ke,itemId:null,itemProp:Be,itemRef:Be,itemScope:ke,itemType:Be,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:ke,low:re,manifest:null,max:null,maxLength:re,media:null,method:null,min:null,minLength:re,multiple:ke,muted:ke,name:null,nonce:null,noModule:ke,noValidate:ke,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:ke,optimum:re,pattern:null,ping:Be,placeholder:null,playsInline:ke,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:ke,referrerPolicy:null,rel:Be,required:ke,reversed:ke,rows:re,rowSpan:re,sandbox:Be,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:re,sizes:null,slot:null,span:re,spellCheck:nt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:re,step:null,style:null,tabIndex:re,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:nt,width:re,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Be,axis:null,background:null,bgColor:null,border:re,borderColor:null,bottomMargin:re,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:ke,declare:ke,event:null,face:null,frame:null,frameBorder:null,hSpace:re,leftMargin:re,link:null,longDesc:null,lowSrc:null,marginHeight:re,marginWidth:re,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:re,rules:null,scheme:null,scrolling:nt,standby:null,summary:null,text:null,topMargin:re,valueType:null,version:null,vAlign:null,vLink:null,vSpace:re,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:re,security:null,unselectable:null},space:"html",transform:cp}),Bv=jr({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:jt,accentHeight:re,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:re,amplitude:re,arabicForm:null,ascent:re,attributeName:null,attributeType:null,azimuth:re,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:re,by:null,calcMode:null,capHeight:re,className:Be,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:re,diffuseConstant:re,direction:null,display:null,dur:null,divisor:re,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:re,enableBackground:null,end:null,event:null,exponent:re,externalResourcesRequired:null,fill:null,fillOpacity:re,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:cr,g2:cr,glyphName:cr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:re,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:re,horizOriginX:re,horizOriginY:re,id:null,ideographic:re,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:re,k:re,k1:re,k2:re,k3:re,k4:re,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:re,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:re,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:re,overlineThickness:re,paintOrder:null,panose1:null,path:null,pathLength:re,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Be,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:re,pointsAtY:re,pointsAtZ:re,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:jt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:jt,rev:jt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:jt,requiredFeatures:jt,requiredFonts:jt,requiredFormats:jt,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:re,specularExponent:re,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:re,strikethroughThickness:re,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:re,strokeOpacity:re,strokeWidth:null,style:null,surfaceScale:re,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:re,tableValues:null,target:null,targetX:re,targetY:re,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:jt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:re,underlineThickness:re,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:re,values:null,vAlphabetic:re,vMathematical:re,vectorEffect:null,vHanging:re,vIdeographic:re,version:null,vertAdvY:re,vertOriginX:re,vertOriginY:re,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:re,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:up}),dp=jr({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()}}),fp=jr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:cp}),pp=jr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Zv={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"},Vv=/[A-Z]/g,nu=/-[a-z]/g,Uv=/^data[-\w.:]+$/i;function Jv(e,t){const n=Ba(t);let r=t,i=St;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Uv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(nu,Wv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!nu.test(s)){let a=s.replace(Vv,Hv);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=Io}return new i(r,t)}function Hv(e){return"-"+e.toLowerCase()}function Wv(e){return e.charAt(1).toUpperCase()}const qv=op([lp,Lv,dp,fp,pp],"html"),Ao=op([lp,Bv,dp,fp,pp],"svg");function Gv(e){return e.join(" ").trim()}var Hn={},na,ru;function Yv(){if(ru)return na;ru=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,a=/^[;\s]*/,o=/^\s+|\s+$/g,l=`
9
+ `)[0].trim();return i.length>t?`${i.slice(0,t-1)}…`:i}function Jy(e){const t=Et(Ie(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>Et(Ie(i,"cells")).length))}×${t.length}`;const n=Et(Ie(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?Et(r).length:Et(Ie(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Hy(e){const t=st(Ie(e,"alt"));if(t)return vt(t);const n=st(Ie(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 vt(r,40)}return"image"}function Wy(e,t){var r;const n=st(Ie(t,"text"));switch(e){case"heading":{const i=Fa(Ie(t,"level"))??1;return{label:n?vt(n):"heading",detail:`H${i}`}}case"text":return{label:n?vt(n):"text",detail:st(Ie(t,"style"))};case"paragraph":return{label:n?vt(n):"paragraph"};case"chart":case"highcharts":{const i=st(Ie(t,"title"))??st(Ie(Ie(t,"options"),"title"));return{label:i?vt(i):e,detail:st(Ie(t,"type"))}}case"table":return{label:"table",detail:Jy(t)};case"image":return{label:Hy(t)};case"shape":return{label:st(Ie(t,"type"))??"shape"};case"list":{const i=Et(Ie(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=st(Ie(Ie(t,"meta"),"title"))??st(Ie(t,"title"));return{label:i?vt(i):"section"}}case"statistic":{const i=st(Ie(t,"value"))??((r=Fa(Ie(t,"value")))==null?void 0:r.toString()),s=st(Ie(t,"label"));return{label:vt(s??i??"statistic"),detail:i}}default:return{label:n?vt(n):e}}}function gr(e){if(e.type!=="object")return null;const t=st(Ie(e,"name"));return t?{name:t,props:Ie(e,"props"),childrenArr:Ie(e,"children")}:null}function qy(e){let t;for(const n of Et(e)){const r=gr(n);if(!r)continue;const i=st(Ie(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return vt(i,48);r.name==="paragraph"&&t===void 0&&(t=vt(i,48))}}return t}function Qi(e,t,n){let{label:r,detail:i}=Wy(t.name,t.props);return r===t.name&&t.childrenArr&&(r=qy(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:Tf(t.childrenArr),reorder:n}}function Tf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of Et(e)){const i=gr(r);i&&n.push(Qi(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Gy(e){const t=Ie(e,"props"),n=st(Ie(Ie(t,"meta"),"title"));if(n)return vt(n,48,!0);let r;const i=(o,l)=>{l&&(!r||o<r.rank)&&(r={rank:o,text:l})},s=Ie(t,"placeholders");if((s==null?void 0:s.type)==="object"&&s.children)for(const o of s.children){if(o.type!=="property"||!o.children)continue;const[l,c]=o.children,f=typeof(l==null?void 0:l.value)=="string"?l.value:"",d=c?gr(c):null,h=d?st(Ie(d.props,"text")):void 0;i(f==="title"?0:f==="subtitle"||f.startsWith("heading")?1:2,h)}const a=(o,l)=>{const c=gr(o);if(c){if(c.name==="text"||c.name==="heading"){const f=st(Ie(c.props,"text"));if(f){const d=st(Ie(c.props,"style"))??"";i(d==="title"?0:d.startsWith("heading")?1:2,f)}}if(l<1)for(const f of Et(c.childrenArr))a(f,l+1)}};for(const o of Et(Ie(e,"children")))a(o,0);return r?vt(r.text,48,!0):void 0}function Yy(e){const t=Ie(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of Et(t)){const a=gr(s);if(!a)continue;const o={groupId:n,sliceStart:s.offset,sliceEnd:s.offset+s.length};a.name==="slide"?(i+=1,r.push({id:"",kind:"slide",label:Gy(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:Tf(a.childrenArr),reorder:o})):r.push(Qi(s,a,o))}return r}function Ky(e){const t=Ie(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const a of Et(t)){const o=gr(a);if(!o)continue;const l={groupId:n,sliceStart:a.offset,sliceEnd:a.offset+a.length},c=()=>i.length?i[i.length-1].node.children:r;if(o.name==="heading"){const f=Fa(Ie(o.props,"level"))??1;for(;i.length&&i[i.length-1].level>=f;)i.pop();const d=Qi(a,o,l);c().push(d),i.push({level:f,node:d})}else c().push(Qi(a,o,l))}const s=a=>{a.children.forEach(s);const o=a.children[a.children.length-1];a.kind==="heading"&&o&&(a.end=Math.max(a.end,o.end),a.reorder&&o.reorder&&(a.reorder.sliceEnd=Math.max(a.reorder.sliceEnd,o.reorder.sliceEnd)))};return r.forEach(s),r}function Sl(e){switch(e.type){case"string":return vt(String(e.value??""),24);case"number":case"boolean":return String(e.value);case"array":return`${Et(e).length} items`;case"object":return;default:return}}function Xy(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 a=[];if(i.type==="object"&&i.children)for(const o of i.children){if(o.type!=="property"||!o.children)continue;const[l,c]=o.children,f=typeof(l==null?void 0:l.value)=="string"?l.value:void 0;!f||!c||a.push({id:"",kind:"key",label:f,detail:Sl(c),start:o.offset,end:o.offset+o.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:a.length===0?Sl(i):void 0,start:n.offset,end:n.offset+n.length,children:a})}return t}function _l(e,t,n){if(!e.trim())return[];const r=Zy(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Xy(r):t==="pptx"?Yy(r):Ky(r);return If(i,""),i}function If(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,If(n.children,n.id)})}function Af(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 Qy(e,t){const n=new Set;for(const r of t)for(const i of Af(e,r))n.add(i);return n}function eb(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(f=>f.reorder);if(i.some(f=>!f))return null;const s=i[0].groupId;if(i.some(f=>f.groupId!==s))return null;for(let f=1;f<i.length;f++)if(i[f].sliceStart<i[f-1].sliceEnd)return null;const a=i.map(f=>e.slice(f.sliceStart,f.sliceEnd)),o=[];for(let f=1;f<i.length;f++){const d=e.slice(i[f-1].sliceEnd,i[f].sliceStart);if((d.match(/,/g)??[]).length!==1)return null;o.push(d)}const l=a.map((f,d)=>d);l.splice(r,0,l.splice(n,1)[0]);let c="";return l.forEach((f,d)=>{c+=a[f],d<o.length&&(c+=o[d])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:c}}const tb={slide:$g,heading:Mg,text:ja,paragraph:Rg,chart:Ea,highcharts:Ea,table:Dg,image:Pg,shape:zd,list:Og,toc:zg,section:Na,columns:Na,"text-box":ja,statistic:Ag,key:_a};function nb(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 rb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function ib(){const{activeTab:e,documentTypes:t}=Ne(po(k=>({activeTab:k.activeTab,documentTypes:k.documentTypes}))),n=Ne(k=>{var $;return k.activeTab?($=k.documents.find(H=>H.name===k.activeTab))==null?void 0:$.text:void 0}),r=$d(k=>e?k.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,a]=x.useState([]),[o,l]=x.useState(null),[c,f]=x.useState(()=>new Set),[d,h]=x.useState(()=>new Set),[p,g]=x.useState(null),w=x.useRef(s);w.current=s;const _=x.useRef(null),b=x.useRef(null),N=x.useCallback(()=>{var H;if(!e){a([]);return}const k=((H=r==null?void 0:r.editor.getModel())==null?void 0:H.getValue())??n??"",$=_l(k,ht,i);if(a($),b.current!==e){b.current=e;const j=new Set;if(i==="document"&&ht==="docx")for(const I of $)I.kind==="heading"&&j.add(I.id);h(j),l(null)}},[e,r,n,i]);x.useEffect(()=>{N();const k=r==null?void 0:r.editor.getModel();if(!k)return;const $=sl(N,300),H=k.onDidChangeContent(()=>$());return()=>{$.cancel(),H.dispose()}},[N,r]),x.useEffect(()=>{if(!r)return;const{editor:k}=r,$=sl(()=>{const j=k.getModel(),I=k.getPosition();if(!j||!I)return;const T=j.getOffsetAt(I),P=Af(w.current,T);if(P.length===0){l(null);return}l(P[P.length-1]);const A=P.slice(0,-1);A.length&&h(M=>{if(A.every(U=>M.has(U)))return M;const V=new Set(M);for(const U of A)V.add(U);return V})},150),H=k.onDidChangeCursorPosition(()=>$());return()=>{$.cancel(),H.dispose()}},[r]),x.useEffect(()=>{if(!o||!_.current)return;const k=_.current.querySelector(`[data-oid="${CSS.escape(o)}"]`);k==null||k.scrollIntoView({block:"nearest"})},[o]),x.useEffect(()=>{if(!r){f(new Set);return}const{editor:k,monaco:$}=r,H=()=>{const I=k.getModel();if(!I)return;const T=$.editor.getModelMarkers({resource:I.uri}).filter(P=>P.severity===$.MarkerSeverity.Error).map(P=>I.getOffsetAt({lineNumber:P.startLineNumber,column:P.startColumn}));f(Qy(w.current,T))};H();const j=$.editor.onDidChangeMarkers(I=>{const T=k.getModel();T&&I.some(P=>P.toString()===T.uri.toString())&&H()});return()=>j.dispose()},[r,s]);const m=x.useCallback(k=>{h($=>{const H=new Set($);return H.has(k)?H.delete(k):H.add(k),H})},[]),O=x.useCallback(k=>{if(l(k.id),!r)return;const{editor:$,monaco:H}=r,j=$.getModel();if(!j)return;const I=j.getPositionAt(k.start),T=j.getPositionAt(k.end),P=new H.Range(I.lineNumber,I.column,T.lineNumber,T.column);$.revealRangeNearTopIfOutsideViewport(P,H.editor.ScrollType.Smooth),$.setPosition(I),$.focus();const A=$.deltaDecorations([],[{range:P,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>$.deltaDecorations(A,[]),700)},[r]),C=x.useCallback(k=>{var oe;if(!r||!k.overId)return;const{editor:$,monaco:H,collapse:j}=r,I=$.getModel();if(!I)return;const T=I.getValue(),P=_l(T,ht,i),A=k.parentId?((oe=nb(P,k.parentId))==null?void 0:oe.children)??[]:P,M=A.findIndex(B=>B.id===k.dragId),V=A.findIndex(B=>B.id===k.overId);if(M===-1||V===-1)return;let U=V+(k.overHalf==="after"?1:0);M<U&&(U-=1);const J=eb(T,A,M,U);if(!J)return;const ne=I.getPositionAt(J.start),S=I.getPositionAt(J.end);$.executeEdits("outline-reorder",[{range:new H.Range(ne.lineNumber,ne.column,S.lineNumber,S.column),text:J.text}]),j==null||j.resyncDecorations()},[r,i]),v=x.useMemo(()=>{const k=[],$=(H,j,I)=>{var A,M;const T=(M=(A=H[0])==null?void 0:A.reorder)==null?void 0:M.groupId,P=H.length>1&&T!==void 0&&H.every(V=>{var U;return((U=V.reorder)==null?void 0:U.groupId)===T});H.forEach(V=>{const U=tb[V.kind]??Fg,J=V.children.length>0,ne=d.has(V.id),S=o===V.id,oe=(p==null?void 0:p.overId)===V.id;k.push(u.jsxs("div",{"data-oid":V.id,role:"treeitem","aria-selected":S,"aria-expanded":J?ne:void 0,tabIndex:0,draggable:P,onClick:()=>O(V),onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),O(V)),B.key==="ArrowRight"&&J&&!ne&&m(V.id),B.key==="ArrowLeft"&&J&&ne&&m(V.id)},onDragStart:B=>{B.dataTransfer.setData("text/plain",V.id),B.dataTransfer.effectAllowed="move",g({dragId:V.id,parentId:I,overId:null,overHalf:"before"})},onDragOver:B=>{if(!p||p.dragId===V.id||rb(p.dragId)!==I)return;B.preventDefault(),B.dataTransfer.dropEffect="move";const y=B.currentTarget.getBoundingClientRect(),q=B.clientY<y.top+y.height/2?"before":"after";(p.overId!==V.id||p.overHalf!==q)&&g({...p,overId:V.id,overHalf:q})},onDrop:B=>{B.preventDefault(),p&&C({...p,overId:V.id,overHalf:p.overHalf}),g(null)},onDragEnd:()=>g(null),className:G("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",S&&"bg-sidebar-accent font-medium text-sidebar-foreground",oe&&(p==null?void 0:p.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",oe&&(p==null?void 0:p.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+j*12},children:[J?u.jsx("span",{role:"button","aria-label":ne?"Collapse":"Expand",onClick:B=>{B.stopPropagation(),m(V.id)},className:"flex size-3.5 shrink-0 items-center justify-center rounded-xs text-sidebar-foreground/55 hover:text-sidebar-foreground",children:u.jsx(_r,{className:G("size-3 transition-transform",ne&&"rotate-90")})}):u.jsx("span",{className:"size-3.5 shrink-0"}),V.kind==="slide"&&u.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:V.detail}),u.jsx(U,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:V.label}),V.kind!=="slide"&&V.detail&&u.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:V.detail}),c.has(V.id)&&u.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},V.id)),J&&ne&&$(V.children,j+1,V.id)})};return $(s,0,""),k},[s,d,o,c,p,O,m,C]);return!e||s.length===0?null:u.jsx("li",{className:"list-none",children:u.jsx("div",{ref:_,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:v})})}const jl=x.memo(ib);async function sb(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const ri=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(vd,{ref:r,className:G("relative overflow-hidden",e),...n,children:[u.jsx(hg,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(zf,{}),u.jsx(mg,{})]}));ri.displayName=vd.displayName;const zf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(wd,{ref:r,orientation:t,className:G("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:u.jsx(gg,{className:"bg-border relative flex-1 rounded-full"})}));zf.displayName=wd.displayName;function Of({className:e,...t}){return u.jsx(xg,{"data-slot":"switch",className:G("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:u.jsx(yg,{"data-slot":"switch-thumb",className:G("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 ab=gi("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"}}),ir=x.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:G(ab({variant:t}),e),...n}));ir.displayName="Alert";const ob=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:G("mb-1 font-medium leading-none tracking-tight",e),...t}));ob.displayName="AlertTitle";const sr=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:G("text-sm [&_p]:leading-relaxed",e),...t}));sr.displayName="AlertDescription";const es=x.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=x.useState(n<2),a=t!==null&&typeof t=="object",o=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?u.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-warning",children:['"',t,'"']}):u.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,f=a?Object.keys(t).length:0;return u.jsxs("div",{className:G("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[a&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(mi,{className:"h-3 w-3"}):u.jsx(_r,{className:"h-3 w-3"})}),!a&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),a?u.jsxs("span",{className:"text-muted-foreground",children:[o?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[f," ",o?"items":"properties"]}),!i&&(o?"]":"}")]}):c(),!a&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),a&&i&&u.jsxs("div",{className:"ml-4",children:[o?t.map((d,h)=>u.jsx(es,{keyName:String(h),value:d,depth:n+1,isLast:h===t.length-1},h)):Object.entries(t).map(([d,h],p,g)=>u.jsx(es,{keyName:d,value:h,depth:n+1,isLast:p===g.length-1},d)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[o?"]":"}",!r&&","]})})]})]})});es.displayName="JsonNode";const ts=x.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:G("space-y-4",r),children:[u.jsx(Yr,{className:"h-8 w-64"}),u.jsx(Yr,{className:"h-4 w-full"}),u.jsx(Yr,{className:"h-64 w-full"})]}):n?u.jsx(ir,{variant:"destructive",className:r,children:u.jsx(sr,{children:n})}):e?u.jsx(ri,{className:G("h-full w-full rounded-md border bg-muted/10 p-4",r),children:u.jsx("div",{className:"font-mono text-xs",children:u.jsx(es,{value:e})})}):u.jsx(ir,{className:r,children:u.jsx(sr,{children:"No schema available"})}));ts.displayName="SchemaViewer";function lb({plugins:e,initialFocusedPlugin:t}){var m,O;const n=Lt(C=>C.togglePlugin),r=Lt(C=>C.isPluginSelected),i=Lt(C=>C.selectedPlugins),s=Lt(C=>C.isApplyingPlugins),[a,o]=x.useState(null),[l,c]=x.useState(null),[f,d]=x.useState("properties");x.useEffect(()=>{if(t){const C=e.find(v=>v.name===t);if(C){o(C);return}}e.length>0&&!a&&o(e[0])},[t,e]);const h=x.useMemo(()=>{const C={current:[],downstream:[],upstream:[]};return e.forEach(v=>{C[v.location]&&C[v.location].push(v)}),C},[e]),p=async(C,v)=>{a&&(await sb(a.name,C.props),c(v),setTimeout(()=>c(null),2e3))},g=C=>{switch(C){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return C}},w=C=>{switch(C){case"current":return u.jsx(Jg,{className:"size-3"});case"downstream":return u.jsx(Ug,{className:"size-3"});case"upstream":return u.jsx(Id,{className:"size-3"});default:return null}},_=((m=a==null?void 0:a.schema)==null?void 0:m.properties)&&Object.keys(a.schema.properties).length>0,b=(O=a==null?void 0:a.schema)==null?void 0:O.jsonSchema,N=(a==null?void 0:a.examples)&&a.examples.length>0;return u.jsxs(u.Fragment,{children:[u.jsxs(Vt,{children:[u.jsxs(Ut,{className:"flex items-center gap-2",children:[u.jsx(Lg,{className:"size-5 text-warning"}),"Plugins",u.jsxs(Kt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(on,{children:[e.length," plugin",e.length!==1?"s":""," discovered in your project"]})]}),u.jsxs("div",{className:"mt-3 flex gap-0 h-[600px] border rounded-lg overflow-hidden",children:[u.jsx("div",{className:"w-[240px] flex-none border-r bg-muted/30",children:u.jsx(ri,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(h).map(([C,v])=>v.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[w(C),g(C)]}),u.jsx("div",{className:"space-y-0.5",children:v.map(k=>{const $=r(k.name),H=(a==null?void 0:a.name)===k.name;return u.jsxs("button",{onClick:()=>o(k),className:G("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",H?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:G("size-1.5 rounded-full flex-none transition-colors",$?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:k.name})]},k.name)})})]},C))})})}),a?u.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[u.jsxs("div",{className:"flex-none px-5 py-4 border-b bg-background",children:[u.jsxs("div",{className:"flex items-start justify-between gap-3",children:[u.jsxs("div",{className:"min-w-0",children:[u.jsxs("div",{className:"flex items-center gap-2.5",children:[u.jsx("h3",{className:"text-base font-semibold truncate",children:a.name}),a.version&&u.jsxs(Kt,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",a.version]})]}),a.description&&u.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:a.description})]}),u.jsxs("div",{className:"flex items-center gap-2 flex-none pt-0.5",children:[u.jsx("span",{className:"text-xs text-muted-foreground",children:r(a.name)?"On":"Off"}),u.jsx(Of,{checked:r(a.name),onCheckedChange:()=>n(a),disabled:s,"aria-label":`Toggle ${a.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[w(a.location),u.jsx("span",{children:g(a.location)}),u.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),u.jsx("span",{className:"font-mono truncate",children:a.relativePath})]})]}),u.jsxs("div",{className:"flex-none px-5 pt-3 pb-0 flex gap-1 border-b bg-background",children:[_&&u.jsx("button",{onClick:()=>d("properties"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(_a,{className:"size-3.5"}),"Properties"]})}),b&&u.jsx("button",{onClick:()=>d("schema"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Bg,{className:"size-3.5"}),"Schema"]})}),N&&u.jsx("button",{onClick:()=>d("examples"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Zg,{className:"size-3.5"}),"Examples",u.jsx(Kt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:a.examples.length})]})})]}),u.jsx(ri,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[f==="properties"&&_&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([C,v])=>u.jsx(ub,{name:C,prop:v},C))}),f==="schema"&&b&&u.jsx(ts,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),f==="examples"&&N&&a.examples.map((C,v)=>u.jsxs("div",{className:G(v>0&&"mt-4 pt-4 border-t"),children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[C.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:C.title}),!C.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",v+1]})]}),u.jsx(Se,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>p(C,v),children:l===v?u.jsxs(u.Fragment,{children:[u.jsx(Vg,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(ks,{className:"size-3 mr-1"}),"Copy"]})})]}),C.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:C.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(C.props,null,2)})]},v)),!_&&!b&&!N&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(_a,{className:"size-10 mx-auto mb-3 opacity-20"}),u.jsx("p",{className:"text-sm",children:"No schema or examples available for this plugin"})]})]})})]}):u.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:u.jsx("p",{className:"text-sm",children:"Select a plugin to view details"})})]})]})}function ub({name:e,prop:t}){var a;const[n,r]=x.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 u.jsxs("div",{className:"rounded-md border",children:[u.jsxs("button",{onClick:()=>i&&r(!n),className:G("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?u.jsx(mi,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(_r,{className:"size-3 text-muted-foreground flex-none"}):u.jsx("span",{className:"size-3 flex-none"}),u.jsx("span",{className:"font-mono font-medium text-xs",children:e}),u.jsx(Kt,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&u.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),u.jsx("span",{className:"flex-1"}),t.default!==void 0&&u.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&u.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&u.jsx("p",{children:t.description}),t.enum&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((o,l)=>u.jsxs("span",{children:[l>0&&", ",u.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(o)})]},l))]}),((a=t.items)==null?void 0:a.type)&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const cb={current:"Current directory",downstream:"Project"};function Nl({location:e}){return u.jsx("li",{className:"list-none px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:cb[e]??e})}function El({name:e,subtitle:t,query:n,onSelect:r}){return u.jsx("li",{className:"list-none",children:u.jsxs("button",{type:"button",onClick:r,title:t?`${e} — ${t}`:e,"aria-label":`Add ${e} to workspace`,className:G("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:[u.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:u.jsx(wo,{text:e,query:n})}),u.jsx(nn,{"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 db({plugins:e,query:t,open:n,onToggleSection:r,onShowPluginDetails:i,isPluginSelected:s,onTogglePlugin:a,isApplyingPlugins:o,selectedPluginCount:l}){return e.length===0?null:u.jsxs("section",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:[u.jsx(Ra,{open:n,onToggle:r,count:`${l}/${e.length}`,children:"Plugins"}),n&&u.jsx("div",{className:"flex flex-col gap-0.5",children:e.map(c=>{const f=s(c.name),d=`plugin-switch-${c.filePath||c.name}`;return u.jsxs("div",{title:c.description?`${c.name} — ${c.description}`:c.name,className:G("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:[u.jsx("label",{htmlFor:d,className:G("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",f?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(wo,{text:c.name,query:t})})}),u.jsx(Ht,{"aria-label":`Details for ${c.name}`,onClick:h=>{h.stopPropagation(),i(c.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(Od,{})}),u.jsx(Of,{id:d,checked:f,onCheckedChange:()=>a(c),disabled:o,className:"shrink-0","aria-label":`Toggle ${c.name} plugin`})]},c.filePath||c.name)})})]})}function Cl(e){return x.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 Pf({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:G("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","[[data-slot=tooltip-content]_&]:bg-primary-foreground/20 [[data-slot=tooltip-content]_&]:text-primary-foreground",t),children:e})}function fb({children:e,className:t}){return u.jsx("span",{className:G("inline-flex items-center gap-0.5",t),children:e})}const Ei=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function ii({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return Ei?"⌘":"Ctrl";case"shift":return Ei?"⇧":"Shift";case"alt":return Ei?"⌥":"Alt";case"ctrl":return Ei?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(fb,{className:t,children:r.map((i,s)=>u.jsx(Pf,{children:i},s))})}function pb({className:e}={}){const{theme:t,setTheme:n}=jd(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=x.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(Se,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Hg,{className:"hidden dark:block"}),u.jsx(Wg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Xe,{children:u.jsx("p",{children:"Toggle theme"})})]})}function hb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o,activeTab:l}=Ne(po(z=>({documents:z.documents,documentTypes:z.documentTypes,createDocument:z.createDocument,openDocument:z.openDocument,activeTab:z.activeTab}))),c=Ia(z=>z.updateTheme),f=Ia(z=>z.removeTheme),d=x.useContext(Fd),[h,p]=x.useState(!1),[g,w]=x.useState(!1),[_,b]=x.useState(!1),[N,m]=x.useState(null),O=Lt(z=>z.togglePlugin),C=Lt(z=>z.isPluginSelected),v=Lt(z=>z.selectedPlugins),k=Lt(z=>z.isApplyingPlugins),[$,H]=x.useState(!1),[j,I]=x.useState(new Set(["documents","themes"])),[T,P]=x.useState(""),A=x.useRef(null),{toast:M}=Sr(),V=i.filter(z=>s[z.name]!=="application/json+theme"),U=i.filter(z=>s[z.name]==="application/json+theme"),J=x.useCallback(()=>{p(!1)},[]),ne=x.useCallback(()=>{w(!1)},[]),S=x.useRef(new Map);x.useEffect(()=>{const z=S.current,K=new Map;U.forEach(te=>{K.set(te.name,te.text),z.get(te.name)!==te.text&&c(te.name,te.text)}),z.forEach((te,xe)=>{K.has(xe)||f(xe)}),S.current=K},[U,c,f]);const oe=x.useRef(!1);x.useEffect(()=>{if(oe.current||!d)return;oe.current=!0;const z=new Set(U.map(te=>te.name));Object.keys(d.getState().customThemes).forEach(te=>{z.has(te)||f(te)})},[U,f,d]);const B=x.useCallback(z=>{I(K=>{const te=new Set(K);return te.has(z)?te.delete(z):te.add(z),te})},[]),{resolvedTheme:y}=jd(),q=y==="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",X=x.useCallback(async(z,K)=>{if(i.some(te=>te.name===z)){o(z);return}try{const te=await fetch(`/api/discovery/${K?"themes":"documents"}/${encodeURIComponent(z)}/content`);if(!te.ok)throw new Error(te.statusText);const xe=await te.text(),L=JSON.parse(xe);a(z,JSON.stringify(L,null,2),{templateSource:z}),o(z),M({title:`Added ${K?"theme":"document"}: ${z}`})}catch{M({title:"Failed to load",description:`Could not load ${z}`,variant:"destructive"})}},[i,a,o,M]);x.useEffect(()=>{if(n)return;const z=K=>{var L,Q,me,ve,F;if(K.key!=="/"||K.metaKey||K.ctrlKey||K.altKey)return;const te=K.target,xe=(L=te==null?void 0:te.tagName)==null?void 0:L.toLowerCase();xe==="input"||xe==="textarea"||xe==="select"||te!=null&&te.isContentEditable||(Q=te==null?void 0:te.closest)!=null&&Q.call(te,".monaco-editor")||(me=A.current)!=null&&me.closest('[aria-hidden="true"], [inert]')||(K.preventDefault(),(ve=A.current)==null||ve.focus(),(F=A.current)==null||F.select())};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[n]);const Y=T.trim(),ie=x.useMemo(()=>new Set(i.map(z=>z.name)),[i]),D=x.useMemo(()=>V.filter(z=>cn(z.name,Y)),[V,Y]),ue=x.useMemo(()=>U.filter(z=>cn(z.name,Y)),[U,Y]),he=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(z=>!ie.has(z.name)&&(cn(z.name,Y)||cn(z.title??"",Y))),[e,Y,ie]),ce=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(z=>!ie.has(z.name)&&(cn(z.name,Y)||cn(z.description??"",Y))),[e,Y,ie]),ee=Cl(he),de=Cl(ce),fe=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(z=>cn(z.name,Y)||cn(z.description??"",Y)),[e,Y]),Re=z=>Y.length>0||j.has(z),Oe=Re("documents"),We=Re("themes"),E=D.length+he.length,R=ue.length+ce.length,Z=Y.length>0&&D.length===0&&ue.length===0&&he.length===0&&ce.length===0&&fe.length===0,se=G("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(_f,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Ma,{className:G("gap-0 p-1.5",se),children:u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Pd,{})})}),u.jsxs(Xe,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(ii,{shortcut:"mod+b"})]})]})}),u.jsxs($a,{className:G("gap-2 px-1 py-1",se),children:[u.jsxs(Lr,{className:"items-center gap-0.5",children:[V.map(z=>u.jsx(Ni,{document:z,compact:!0},z.name)),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"right",children:"New document"})]})]}),u.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),u.jsxs(Lr,{className:"items-center gap-0.5",children:[U.map(z=>u.jsx(Ni,{document:z,compact:!0},z.name)),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New theme",onClick:()=>w(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(Ma,{className:G("gap-0 p-2",se),children:[u.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[u.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:u.jsx("img",{src:q,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(qg,{})})}),u.jsxs(Xe,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(ii,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(Gg,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),u.jsx("input",{ref:A,type:"text",value:T,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:z=>P(z.target.value),onKeyDown:z=>{z.key==="Escape"&&(z.preventDefault(),P(""),z.currentTarget.blur())},className:G("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")}),Y?u.jsx(Ht,{"aria-label":"Clear filter",onClick:()=>{var z;P(""),(z=A.current)==null||z.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(yn,{})}):u.jsx(Pf,{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:"/"})]})]}),u.jsx($a,{className:G("gap-0 px-2 pb-2",se),children:Z?u.jsxs("div",{className:"px-1 py-6 text-center",children:[u.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",Y,"”"]}),u.jsx("button",{type:"button",onClick:()=>{var z;P(""),(z=A.current)==null||z.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"})]}):u.jsxs(u.Fragment,{children:[(E>0||!Y)&&u.jsxs("section",{children:[u.jsx(Ra,{open:Oe,onToggle:()=>B("documents"),count:E||void 0,actions:u.jsxs(u.Fragment,{children:[ht==="docx"&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Compare documents",disabled:V.length<2,onClick:()=>H(!0),children:u.jsx(Cd,{})})}),u.jsx(Xe,{side:"bottom",children:V.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),Oe&&u.jsxs(Lr,{className:"gap-0.5",children:[D.map(z=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:z,query:Y}),!Y&&l===z.name&&u.jsx(jl,{})]},z.name)),ee.map(([z,K])=>u.jsxs(x.Fragment,{children:[ee.length>1&&u.jsx(Nl,{location:z}),K.map(te=>u.jsx(El,{name:te.name,subtitle:te.title,query:Y,onSelect:()=>X(te.name,!1)},te.path||te.name))]},z)),E===0&&u.jsx("li",{className:"list-none",children:u.jsx(yl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]})]}),(R>0||!Y)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Ra,{open:We,onToggle:()=>B("themes"),count:R||void 0,actions:u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New theme",onClick:()=>w(!0),children:u.jsx(nn,{})})}),u.jsx(Xe,{side:"bottom",children:"New theme"})]}),children:"Themes"}),We&&u.jsxs(Lr,{className:"gap-0.5",children:[ue.map(z=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:z,query:Y}),!Y&&l===z.name&&u.jsx(jl,{})]},z.name)),de.map(([z,K])=>u.jsxs(x.Fragment,{children:[de.length>1&&u.jsx(Nl,{location:z}),K.map(te=>u.jsx(El,{name:te.name,subtitle:te.description,query:Y,onSelect:()=>X(te.name,!0)},te.path||te.name))]},z)),R===0&&u.jsx("li",{className:"list-none",children:u.jsx(yl,{icon:nn,label:"New theme",onClick:()=>w(!0)})})]})]}),u.jsx(db,{plugins:fe,query:Y,open:Re("plugins"),onToggleSection:()=>B("plugins"),onShowPluginDetails:z=>{m(z),b(!0)},isPluginSelected:C,onTogglePlugin:O,isApplyingPlugins:k,selectedPluginCount:v.size})]})})]}),u.jsx(jf,{className:G("border-sidebar-border/70 gap-0 border-t p-1.5",se),children:u.jsx("div",{className:G("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(pb,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),u.jsx(Ct,{open:h,onOpenChange:p,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Ki,{mode:"create",shouldReset:!h,postSubmit:J,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(Ct,{open:g,onOpenChange:w,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Ki,{mode:"create",shouldReset:!g,postSubmit:ne,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(Ct,{open:_,onOpenChange:z=>{b(z),z||m(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(lb,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:N})})}),u.jsx(wx,{open:$,onOpenChange:H})]})}const Tl=x.memo(hb),mb=x.lazy(()=>Nd(()=>import("./editor-gT4UjmPk.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(e=>({default:e.Editor})));function Il(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(gn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(mb,{})})}const gb=x.lazy(()=>Nd(()=>import("./preview-ZqhmQZJG.js"),__vite__mapDeps([13,1,3,4,5,6,7,8,9,10,12,11])).then(e=>({default:e.Preview})));function Al(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(gn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(gb,{})})}const{createElement:xr,createContext:xb,forwardRef:Df,useCallback:gt,useContext:Rf,useEffect:zn,useImperativeHandle:Mf,useLayoutEffect:yb,useMemo:bb,useRef:wt,useState:ar}=Uc,zl=Uc[`useId${Math.random()}`.slice(0,5)],vb=yb,Ts=xb(null);Ts.displayName="PanelGroupContext";const On=vb,wb=typeof zl=="function"?zl:()=>null;let kb=0;function _o(e=null){const t=wb(),n=wt(e||t||null);return n.current===null&&(n.current=""+kb++),e??n.current}function $f({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:f,onResize:d,order:h,style:p,tagName:g="div",...w}){const _=Rf(Ts);if(_===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:N,getPanelSize:m,getPanelStyle:O,groupId:C,isPanelCollapsed:v,reevaluatePanelConstraints:k,registerPanel:$,resizePanel:H,unregisterPanel:j}=_,I=_o(a),T=wt({callbacks:{onCollapse:c,onExpand:f,onResize:d},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:I,idIsFromProps:a!==void 0,order:h});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:A,constraints:M}=T.current,V={...M};T.current.id=I,T.current.idIsFromProps=a!==void 0,T.current.order=h,A.onCollapse=c,A.onExpand=f,A.onResize=d,M.collapsedSize=n,M.collapsible=r,M.defaultSize=i,M.maxSize=o,M.minSize=l,(V.collapsedSize!==M.collapsedSize||V.collapsible!==M.collapsible||V.maxSize!==M.maxSize||V.minSize!==M.minSize)&&k(T.current,V)}),On(()=>{const A=T.current;return $(A),()=>{j(A)}},[h,I,$,j]),Mf(s,()=>({collapse:()=>{b(T.current)},expand:A=>{N(T.current,A)},getId(){return I},getSize(){return m(T.current)},isCollapsed(){return v(T.current)},isExpanded(){return!v(T.current)},resize:A=>{H(T.current,A)}}),[b,N,m,v,I,H]);const P=O(T.current,i);return xr(g,{...w,children:e,className:t,id:a,style:{...P,...p},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":C,"data-panel-id":I,"data-panel-size":parseFloat(""+P.flexGrow).toFixed(1)})}const Ff=Df((e,t)=>xr($f,{...e,forwardedRef:t}));$f.displayName="Panel";Ff.displayName="forwardRef(Panel)";let La=null,An=null;function Sb(e,t){if(t){const n=(t&Uf)!==0,r=(t&Jf)!==0,i=(t&Hf)!==0,s=(t&Wf)!==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 _b(){An!==null&&(document.head.removeChild(An),La=null,An=null)}function Ks(e,t){const n=Sb(e,t);La!==n&&(La=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Lf(e){return e.type==="keydown"}function Bf(e){return e.type.startsWith("pointer")}function Zf(e){return e.type.startsWith("mouse")}function Is(e){if(Bf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Zf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function jb(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Nb(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 Eb(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Dl(e),b:Dl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;_e(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Pl(Ol(n.a)),b:Pl(Ol(n.b))};if(i.a===i.b){const s=r.childNodes,a={a:n.a.at(-1),b:n.b.at(-1)};let o=s.length;for(;o--;){const l=s[o];if(l===a.a)return 1;if(l===a.b)return-1}}return Math.sign(i.a-i.b)}const Cb=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Tb(e){var t;const n=getComputedStyle((t=Vf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function Ib(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Tb(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"||Cb.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Ol(e){let t=e.length;for(;t--;){const n=e[t];if(_e(n,"Missing node"),Ib(n))return n}return null}function Pl(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Dl(e){const t=[];for(;e;)t.push(e),e=Vf(e);return t}function Vf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Uf=1,Jf=2,Hf=4,Wf=8,Ab=jb()==="coarse";let Bt=[],or=!1,mn=new Map,As=new Map;const si=new Set;function zb(e,t,n,r,i){var s;const{ownerDocument:a}=t,o={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=mn.get(a))!==null&&s!==void 0?s:0;return mn.set(a,l+1),si.add(o),ns(),function(){var f;As.delete(e),si.delete(o);const d=(f=mn.get(a))!==null&&f!==void 0?f:1;if(mn.set(a,d-1),ns(),d===1&&mn.delete(a),Bt.includes(o)){const h=Bt.indexOf(o);h>=0&&Bt.splice(h,1),No(),i("up",!0,null)}}}function Rl(e){const{target:t}=e,{x:n,y:r}=Is(e);or=!0,jo({target:t,x:n,y:r}),ns(),Bt.length>0&&(rs("down",e),e.preventDefault(),e.stopPropagation())}function Or(e){const{x:t,y:n}=Is(e);if(or&&e.buttons===0&&(or=!1,rs("up",e)),!or){const{target:r}=e;jo({target:r,x:t,y:n})}rs("move",e),No(),Bt.length>0&&e.preventDefault()}function Un(e){const{target:t}=e,{x:n,y:r}=Is(e);As.clear(),or=!1,Bt.length>0&&e.preventDefault(),rs("up",e),jo({target:t,x:n,y:r}),No(),ns()}function jo({target:e,x:t,y:n}){Bt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),si.forEach(i=>{const{element:s,hitAreaMargins:a}=i,o=s.getBoundingClientRect(),{bottom:l,left:c,right:f,top:d}=o,h=Ab?a.coarse:a.fine;if(t>=c-h&&t<=f+h&&n>=d-h&&n<=l+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&Eb(r,s)>0){let g=r,w=!1;for(;g&&!g.contains(s);){if(Nb(g.getBoundingClientRect(),o)){w=!0;break}g=g.parentElement}if(w)return}Bt.push(i)}})}function Xs(e,t){As.set(e,t)}function No(){let e=!1,t=!1;Bt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;As.forEach(r=>{n|=r}),e&&t?Ks("intersection",n):e?Ks("horizontal",n):t?Ks("vertical",n):_b()}function ns(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Un),n.removeEventListener("pointerdown",Rl),n.removeEventListener("pointerleave",Or),n.removeEventListener("pointermove",Or)}),window.removeEventListener("pointerup",Un),window.removeEventListener("pointercancel",Un),si.size>0&&(or?(Bt.length>0&&mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Un),n.addEventListener("pointerleave",Or),n.addEventListener("pointermove",Or))}),window.addEventListener("pointerup",Un),window.addEventListener("pointercancel",Un)):mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Rl,{capture:!0}),n.addEventListener("pointermove",Or))}))}function rs(e,t){si.forEach(n=>{const{setResizeHandlerState:r}=n,i=Bt.includes(n);r(e,i,t)})}function Ob(){const[e,t]=ar(0);return gt(()=>t(n=>n+1),[])}function _e(e,t){if(!e)throw console.error(t),Error(t)}const Eo=10;function Dn(e,t,n=Eo){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function sn(e,t,n=Eo){return Dn(e,t,n)===0}function Nt(e,t,n){return Dn(e,t,n)===0}function Pb(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(!Nt(i,s,n))return!1}return!0}function tr({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];_e(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:a=100,minSize:o=0}=r;if(Dn(n,o)<0)if(s){const l=(i+o)/2;Dn(n,l)<0?n=i:n=o}else n=o;return n=Math.min(a,n),n=parseFloat(n.toFixed(Eo)),n}function Br({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Nt(e,0))return t;const a=[...t],[o,l]=r;_e(o!=null,"Invalid first pivot index"),_e(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?l:o,h=n[d];_e(h,`Panel constraints not found for index ${d}`);const{collapsedSize:p=0,collapsible:g,minSize:w=0}=h;if(g){const _=t[d];if(_e(_!=null,`Previous layout not found for panel index ${d}`),Nt(_,p)){const b=w-_;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const d=e<0?o:l,h=n[d];_e(h,`No panel constraints found for index ${d}`);const{collapsedSize:p=0,collapsible:g,minSize:w=0}=h;if(g){const _=t[d];if(_e(_!=null,`Previous layout not found for panel index ${d}`),Nt(_,w)){const b=_-p;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const d=e<0?1:-1;let h=e<0?l:o,p=0;for(;;){const w=t[h];_e(w!=null,`Previous layout not found for panel index ${h}`);const b=tr({panelConstraints:n,panelIndex:h,size:100})-w;if(p+=b,h+=d,h<0||h>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-g:g}{let h=e<0?o:l;for(;h>=0&&h<n.length;){const p=Math.abs(e)-Math.abs(c),g=t[h];_e(g!=null,`Previous layout not found for panel index ${h}`);const w=g-p,_=tr({panelConstraints:n,panelIndex:h,size:w});if(!Nt(g,_)&&(c+=g-_,a[h]=_,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(Pb(i,a))return i;{const d=e<0?l:o,h=t[d];_e(h!=null,`Previous layout not found for panel index ${d}`);const p=h+c,g=tr({panelConstraints:n,panelIndex:d,size:p});if(a[d]=g,!Nt(g,p)){let w=p-g,b=e<0?l:o;for(;b>=0&&b<n.length;){const N=a[b];_e(N!=null,`Previous layout not found for panel index ${b}`);const m=N+w,O=tr({panelConstraints:n,panelIndex:b,size:m});if(Nt(N,O)||(w-=O-N,a[b]=O),Nt(w,0))break;e>0?b--:b++}}}const f=a.reduce((d,h)=>h+d,0);return Nt(f,100)?a:i}function Db({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,a=0;const o=n[0];_e(o!=null,"No pivot index found"),t.forEach((d,h)=>{const{constraints:p}=d,{maxSize:g=100,minSize:w=0}=p;h===o?(r=w,i=g):(s+=w,a+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-a),f=e[o];return{valueMax:l,valueMin:c,valueNow:f}}function ai(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function qf(e,t,n=document){const i=ai(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Gf(e,t,n){const r=qf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Yf(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 zs(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function Rb(e,t,n,r=document){var i,s,a,o;const l=zs(t,r),c=ai(e,r),f=l?c.indexOf(l):-1,d=(i=(s=n[f])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,h=(a=(o=n[f+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[d,h]}function Mb({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:a}){wt({didWarnAboutMissingResizeHandle:!1}),On(()=>{if(!s)return;const o=ai(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:f,valueNow:d}=Db({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),h=o[l];if(h!=null){const p=i[l];_e(p,`No panel data found for index "${l}"`),h.setAttribute("aria-controls",p.id),h.setAttribute("aria-valuemax",""+Math.round(c)),h.setAttribute("aria-valuemin",""+Math.round(f)),h.setAttribute("aria-valuenow",d!=null?""+Math.round(d):"")}}return()=>{o.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),zn(()=>{if(!s)return;const o=t.current;_e(o,"Eager values not found");const{panelDataArray:l}=o,c=Yf(n,s);_e(c!=null,`No group found for id "${n}"`);const f=ai(n,s);_e(f,`No resize handles found for group id "${n}"`);const d=f.map(h=>{const p=h.getAttribute("data-panel-resize-handle-id");_e(p,"Resize handle element has no handle id attribute");const[g,w]=Rb(n,p,l,s);if(g==null||w==null)return()=>{};const _=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const N=l.findIndex(m=>m.id===g);if(N>=0){const m=l[N];_e(m,`No panel data found for index ${N}`);const O=r[N],{collapsedSize:C=0,collapsible:v,minSize:k=0}=m.constraints;if(O!=null&&v){const $=Br({delta:Nt(O,C)?k-C:C-O,initialLayout:r,panelConstraints:l.map(H=>H.constraints),pivotIndices:Gf(n,p,s),prevLayout:r,trigger:"keyboard"});r!==$&&a($)}}break}}};return h.addEventListener("keydown",_),()=>{h.removeEventListener("keydown",_)}});return()=>{d.forEach(h=>h())}},[s,e,t,n,r,i,a])}function Ml(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 Kf(e,t){const n=e==="horizontal",{x:r,y:i}=Is(t);return n?r:i}function $b(e,t,n,r,i){const s=n==="horizontal",a=zs(t,i);_e(a,`No resize handle element found for id "${t}"`);const o=a.getAttribute("data-panel-group-id");_e(o,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=Kf(n,e),f=Yf(o,i);_e(f,`No group element found for id "${o}"`);const d=f.getBoundingClientRect(),h=s?d.width:d.height;return(c-l)/h*100}function Fb(e,t,n,r,i,s){if(Lf(e)){const a=n==="horizontal";let o=0;e.shiftKey?o=100:i!=null?o=i:o=10;let l=0;switch(e.key){case"ArrowDown":l=a?0:o;break;case"ArrowLeft":l=a?-o:0;break;case"ArrowRight":l=a?o:0;break;case"ArrowUp":l=a?0:-o;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:$b(e,t,n,r,s)}function Lb({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 a=n[s];_e(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;o!=null&&(r++,t[s]=o,i-=o)}for(let s=0;s<e.length;s++){const a=n[s];_e(a,`Panel constraints not found for index ${s}`);const{defaultSize:o}=a;if(o!=null)continue;const l=e.length-r,c=i/l;r++,t[s]=c,i-=c}return t}function Jn(e,t,n){t.forEach((r,i)=>{const s=e[i];_e(s,`Panel data not found for index ${i}`);const{callbacks:a,constraints:o,id:l}=s,{collapsedSize:c=0,collapsible:f}=o,d=n[l];if(d==null||r!==d){n[l]=r;const{onCollapse:h,onExpand:p,onResize:g}=a;g&&g(r,d),f&&(h||p)&&(p&&(d==null||sn(d,c))&&!sn(r,c)&&p(),h&&(d==null||!sn(d,c))&&sn(r,c)&&h())}})}function Ci(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 Bb({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const a=n[i];let o;return a==null?o=e!=null?e.toPrecision(s):"1":r.length===1?o="1":o=a.toPrecision(s),{flexBasis:0,flexGrow:o,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function Zb(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function $l(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 Xf(e){return`react-resizable-panels:${e}`}function Qf(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 ep(e,t){try{const n=Xf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Vb(e,t,n){var r,i;const s=(r=ep(e,n))!==null&&r!==void 0?r:{},a=Qf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Ub(e,t,n,r,i){var s;const a=Xf(e),o=Qf(t),l=(s=ep(e,i))!==null&&s!==void 0?s:{};l[o]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(a,JSON.stringify(l))}catch(c){console.error(c)}}function Fl({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,a)=>s+a,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Nt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const a=n[s];_e(a!=null,`No layout data found for index ${s}`);const o=100/r*a;n[s]=o}let i=0;for(let s=0;s<t.length;s++){const a=n[s];_e(a!=null,`No layout data found for index ${s}`);const o=tr({panelConstraints:t,panelIndex:s,size:a});a!=o&&(i+=a-o,n[s]=o)}if(!Nt(i,0))for(let s=0;s<t.length;s++){const a=n[s];_e(a!=null,`No layout data found for index ${s}`);const o=a+i,l=tr({panelConstraints:t,panelIndex:s,size:o});if(a!==l&&(i-=l-a,n[s]=l,Nt(i,0)))break}return n}const Jb=100,Zr={getItem:e=>($l(Zr),Zr.getItem(e)),setItem:(e,t)=>{$l(Zr),Zr.setItem(e,t)}},Ll={};function tp({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:a=null,keyboardResizeBy:o=null,storage:l=Zr,style:c,tagName:f="div",...d}){const h=_o(s),p=wt(null),[g,w]=ar(null),[_,b]=ar([]),N=Ob(),m=wt({}),O=wt(new Map),C=wt(0),v=wt({autoSaveId:e,direction:r,dragState:g,id:h,keyboardResizeBy:o,onLayout:a,storage:l}),k=wt({layout:_,panelDataArray:[],panelDataArrayChanged:!1});wt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),Mf(i,()=>({getId:()=>v.current.id,getLayout:()=>{const{layout:y}=k.current;return y},setLayout:y=>{const{onLayout:q}=v.current,{layout:X,panelDataArray:Y}=k.current,ie=Fl({layout:y,panelConstraints:Y.map(D=>D.constraints)});Ml(X,ie)||(b(ie),k.current.layout=ie,q&&q(ie),Jn(Y,ie,m.current))}}),[]),On(()=>{v.current.autoSaveId=e,v.current.direction=r,v.current.dragState=g,v.current.id=h,v.current.onLayout=a,v.current.storage=l}),Mb({committedValuesRef:v,eagerValuesRef:k,groupId:h,layout:_,panelDataArray:k.current.panelDataArray,setLayout:b,panelGroupElement:p.current}),zn(()=>{const{panelDataArray:y}=k.current;if(e){if(_.length===0||_.length!==y.length)return;let q=Ll[e];q==null&&(q=Zb(Ub,Jb),Ll[e]=q);const X=[...y],Y=new Map(O.current);q(e,X,Y,_,l)}},[e,_,l]),zn(()=>{});const $=gt(y=>{const{onLayout:q}=v.current,{layout:X,panelDataArray:Y}=k.current;if(y.constraints.collapsible){const ie=Y.map(ce=>ce.constraints),{collapsedSize:D=0,panelSize:ue,pivotIndices:he}=jn(Y,y,X);if(_e(ue!=null,`Panel size not found for panel "${y.id}"`),!sn(ue,D)){O.current.set(y.id,ue);const ee=Kn(Y,y)===Y.length-1?ue-D:D-ue,de=Br({delta:ee,initialLayout:X,panelConstraints:ie,pivotIndices:he,prevLayout:X,trigger:"imperative-api"});Ci(X,de)||(b(de),k.current.layout=de,q&&q(de),Jn(Y,de,m.current))}}},[]),H=gt((y,q)=>{const{onLayout:X}=v.current,{layout:Y,panelDataArray:ie}=k.current;if(y.constraints.collapsible){const D=ie.map(fe=>fe.constraints),{collapsedSize:ue=0,panelSize:he=0,minSize:ce=0,pivotIndices:ee}=jn(ie,y,Y),de=q??ce;if(sn(he,ue)){const fe=O.current.get(y.id),Re=fe!=null&&fe>=de?fe:de,We=Kn(ie,y)===ie.length-1?he-Re:Re-he,E=Br({delta:We,initialLayout:Y,panelConstraints:D,pivotIndices:ee,prevLayout:Y,trigger:"imperative-api"});Ci(Y,E)||(b(E),k.current.layout=E,X&&X(E),Jn(ie,E,m.current))}}},[]),j=gt(y=>{const{layout:q,panelDataArray:X}=k.current,{panelSize:Y}=jn(X,y,q);return _e(Y!=null,`Panel size not found for panel "${y.id}"`),Y},[]),I=gt((y,q)=>{const{panelDataArray:X}=k.current,Y=Kn(X,y);return Bb({defaultSize:q,dragState:g,layout:_,panelData:X,panelIndex:Y})},[g,_]),T=gt(y=>{const{layout:q,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:ie,panelSize:D}=jn(X,y,q);return _e(D!=null,`Panel size not found for panel "${y.id}"`),ie===!0&&sn(D,Y)},[]),P=gt(y=>{const{layout:q,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:ie,panelSize:D}=jn(X,y,q);return _e(D!=null,`Panel size not found for panel "${y.id}"`),!ie||Dn(D,Y)>0},[]),A=gt(y=>{const{panelDataArray:q}=k.current;q.push(y),q.sort((X,Y)=>{const ie=X.order,D=Y.order;return ie==null&&D==null?0:ie==null?-1:D==null?1:ie-D}),k.current.panelDataArrayChanged=!0,N()},[N]);On(()=>{if(k.current.panelDataArrayChanged){k.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:q,storage:X}=v.current,{layout:Y,panelDataArray:ie}=k.current;let D=null;if(y){const he=Vb(y,ie,X);he&&(O.current=new Map(Object.entries(he.expandToSizes)),D=he.layout)}D==null&&(D=Lb({panelDataArray:ie}));const ue=Fl({layout:D,panelConstraints:ie.map(he=>he.constraints)});Ml(Y,ue)||(b(ue),k.current.layout=ue,q&&q(ue),Jn(ie,ue,m.current))}}),On(()=>{const y=k.current;return()=>{y.layout=[]}},[]);const M=gt(y=>{let q=!1;const X=p.current;return X&&window.getComputedStyle(X,null).getPropertyValue("direction")==="rtl"&&(q=!0),function(ie){ie.preventDefault();const D=p.current;if(!D)return()=>null;const{direction:ue,dragState:he,id:ce,keyboardResizeBy:ee,onLayout:de}=v.current,{layout:fe,panelDataArray:Re}=k.current,{initialLayout:Oe}=he??{},We=Gf(ce,y,D);let E=Fb(ie,y,ue,he,ee,D);const R=ue==="horizontal";R&&q&&(E=-E);const Z=Re.map(K=>K.constraints),se=Br({delta:E,initialLayout:Oe??fe,panelConstraints:Z,pivotIndices:We,prevLayout:fe,trigger:Lf(ie)?"keyboard":"mouse-or-touch"}),z=!Ci(fe,se);(Bf(ie)||Zf(ie))&&C.current!=E&&(C.current=E,!z&&E!==0?R?Xs(y,E<0?Uf:Jf):Xs(y,E<0?Hf:Wf):Xs(y,0)),z&&(b(se),k.current.layout=se,de&&de(se),Jn(Re,se,m.current))}},[]),V=gt((y,q)=>{const{onLayout:X}=v.current,{layout:Y,panelDataArray:ie}=k.current,D=ie.map(fe=>fe.constraints),{panelSize:ue,pivotIndices:he}=jn(ie,y,Y);_e(ue!=null,`Panel size not found for panel "${y.id}"`);const ee=Kn(ie,y)===ie.length-1?ue-q:q-ue,de=Br({delta:ee,initialLayout:Y,panelConstraints:D,pivotIndices:he,prevLayout:Y,trigger:"imperative-api"});Ci(Y,de)||(b(de),k.current.layout=de,X&&X(de),Jn(ie,de,m.current))},[]),U=gt((y,q)=>{const{layout:X,panelDataArray:Y}=k.current,{collapsedSize:ie=0,collapsible:D}=q,{collapsedSize:ue=0,collapsible:he,maxSize:ce=100,minSize:ee=0}=y.constraints,{panelSize:de}=jn(Y,y,X);de!=null&&(D&&he&&sn(de,ie)?sn(ie,ue)||V(y,ue):de<ee?V(y,ee):de>ce&&V(y,ce))},[V]),J=gt((y,q)=>{const{direction:X}=v.current,{layout:Y}=k.current;if(!p.current)return;const ie=zs(y,p.current);_e(ie,`Drag handle element not found for id "${y}"`);const D=Kf(X,q);w({dragHandleId:y,dragHandleRect:ie.getBoundingClientRect(),initialCursorPosition:D,initialLayout:Y})},[]),ne=gt(()=>{w(null)},[]),S=gt(y=>{const{panelDataArray:q}=k.current,X=Kn(q,y);X>=0&&(q.splice(X,1),delete m.current[y.id],k.current.panelDataArrayChanged=!0,N())},[N]),oe=bb(()=>({collapsePanel:$,direction:r,dragState:g,expandPanel:H,getPanelSize:j,getPanelStyle:I,groupId:h,isPanelCollapsed:T,isPanelExpanded:P,reevaluatePanelConstraints:U,registerPanel:A,registerResizeHandle:M,resizePanel:V,startDragging:J,stopDragging:ne,unregisterPanel:S,panelGroupElement:p.current}),[$,g,r,H,j,I,h,T,P,U,A,M,V,J,ne,S]),B={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return xr(Ts.Provider,{value:oe},xr(f,{...d,children:t,className:n,id:s,ref:p,style:{...B,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":h}))}const np=Df((e,t)=>xr(tp,{...e,forwardedRef:t}));tp.displayName="PanelGroup";np.displayName="forwardRef(PanelGroup)";function Kn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function jn(e,t,n){const r=Kn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],a=n[r];return{...t.constraints,panelSize:a,pivotIndices:s}}function Hb({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){zn(()=>{if(e||n==null||r==null)return;const i=zs(t,r);if(i==null)return;const s=a=>{if(!a.defaultPrevented)switch(a.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{a.preventDefault(),n(a);break}case"F6":{a.preventDefault();const o=i.getAttribute("data-panel-group-id");_e(o,`No group element found for id "${o}"`);const l=ai(o,r),c=qf(o,t,r);_e(c!==null,`No resize element found for id "${t}"`);const f=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[f].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function rp({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:f="div",...d}){var h,p;const g=wt(null),w=wt({onDragging:a});zn(()=>{w.current.onDragging=a});const _=Rf(Ts);if(_===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:b,groupId:N,registerResizeHandle:m,startDragging:O,stopDragging:C,panelGroupElement:v}=_,k=_o(i),[$,H]=ar("inactive"),[j,I]=ar(!1),[T,P]=ar(null),A=wt({state:$});On(()=>{A.current.state=$}),zn(()=>{if(n)P(null);else{const J=m(k);P(()=>J)}},[n,k,m]);const M=(h=r==null?void 0:r.coarse)!==null&&h!==void 0?h:15,V=(p=r==null?void 0:r.fine)!==null&&p!==void 0?p:5;return zn(()=>{if(n||T==null)return;const J=g.current;return _e(J,"Element ref not attached"),zb(k,J,b,{coarse:M,fine:V},(S,oe,B)=>{if(oe)switch(S){case"down":{H("drag"),_e(B,'Expected event to be defined for "down" action'),O(k,B);const{onDragging:y}=w.current;y&&y(!0);break}case"move":{const{state:y}=A.current;y!=="drag"&&H("hover"),_e(B,'Expected event to be defined for "move" action'),T(B);break}case"up":{H("hover"),C();const{onDragging:y}=w.current;y&&y(!1);break}}else H("inactive")})},[M,b,n,V,m,k,T,O,C]),Hb({disabled:n,handleId:k,resizeHandler:T,panelGroupElement:v}),xr(f,{...d,children:e,className:t,id:i,onBlur:()=>{I(!1),s==null||s()},onFocus:()=>{I(!0),o==null||o()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":b,"data-panel-group-id":N,"data-resize-handle":"","data-resize-handle-active":$==="drag"?"pointer":j?"keyboard":void 0,"data-resize-handle-state":$,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":k})}rp.displayName="PanelResizeHandle";const Wb=({className:e,...t})=>u.jsx(np,{className:G("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Qs=Ff,Bl=({withHandle:e,className:t,...n})=>u.jsx(rp,{className:G("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&&u.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:u.jsx(Yg,{className:"h-2.5 w-2.5"})})}),ip=x.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:G("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}));ip.displayName="Textarea";class qb{constructor(t){Vs(this,"client");this.client=gx.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 Gb=new qb;class Yb extends Error{constructor(n,r){super(n);Vs(this,"quality");this.name="QualityGateFailedError",this.quality=r}}function Kb(e,t){return e??t}function Xb(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 Qb(e){if(Xb(e.headers.get("content-type")))try{return await e.json()}catch{return}}function Zl(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 ev(){const e=x.useRef(null),t=Hi(s=>s.generationBackend),n=Ld(),r=x.useCallback(async(s,a,o,l,c)=>{e.current&&e.current.abort();const f=new AbortController;e.current=f;const d=Kb(c==null?void 0:c.renderer,t);try{l==null||l("parsing","Validating JSON structure...");let h;try{h=JSON.parse(a)}catch(H){throw new Error(`Invalid JSON: ${H instanceof Error?H.message:"Unknown parse error"}`)}l==null||l("building",`Building ${ji.toLowerCase()} structure...`);const p={jsonDefinition:h,options:{...c,sourceName:n(s),...d?{renderer:d}:{}}};p.customThemes=o??{},l==null||l("rendering",`Generating ${ht.toUpperCase()} content...`);const g={"Content-Type":"application/json"};c!=null&&c.bypassCache&&(g["X-Bypass-Cache"]="true");const w=await fetch(ei.generate,{method:"POST",headers:g,body:JSON.stringify(p),signal:f.signal}),_=await Qb(w);if(w.status===400&&(_==null?void 0:_.code)==="QUALITY_GATE_FAILED")throw new Yb(Zl(w,_),_.quality);if(!w.ok||!(_!=null&&_.success))throw new Error(Zl(w,_));const{data:b,cache:N,warnings:m}=_,O=N.status==="HIT"?"HIT":N.status==="MISS"?"MISS":"UNKNOWN",C=O==="HIT"?`Served from cache (Hit rate: ${N.hitRate})`:`Generated fresh ${ji.toLowerCase()}`;l==null||l("finalizing",C);const v=globalThis.atob(b.document),k=new Uint8Array(v.length);for(let H=0;H<v.length;H++)k[H]=v.charCodeAt(H);const $=new Blob([k],{type:b.contentType});if($.size===0)throw new Error(`Received empty ${ji.toLowerCase()} from API`);return{name:s,text:a,blob:$,...d?{renderer:d}:{},filename:b.filename,fileId:b.fileId,cacheStatus:O,cacheHitRate:N.hitRate,warnings:m}}catch(h){throw h instanceof Error&&h.name==="AbortError"?new Error(`${ji} generation was cancelled`):h}finally{e.current===f&&(e.current=null)}},[t,n]),i=x.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:r,generateDocument:r,cancelGeneration:i}}const Bi={ids:[],default:null};let Vl;function tv(){return Vl??(Vl=(async()=>{var e;try{const t=await fetch(ei.renderers);if(!t.ok)return Bi;const n=await t.json();return!(n!=null&&n.success)||!Array.isArray((e=n.data)==null?void 0:e.ids)?Bi:n.data}catch{return Bi}})()),Vl}function nv(){const[e,t]=x.useState(Bi);return x.useEffect(()=>{let n=!1;return tv().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 a of i){let o=a.message;if(a.context&&Object.keys(a.context).length>0){const l=Object.entries(a.context).map(([c,f])=>`${c}: ${JSON.stringify(f)}`).join(", ");o+=` (${l})`}s.push(o)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function iv({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=je.useState("custom");je.useEffect(()=>{e&&s("custom")},[e]);const a=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),o=[{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 u.jsx(Ct,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(kt,{className:"max-w-md",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Non-safe fonts in this document"}),u.jsxs(on,{children:[a," ",n.length===1?"is":"are"," not in the built-in safe list. Choose how to export."]})]}),u.jsx("div",{className:"grid gap-2 py-2",children:o.map(l=>{const c=i===l.value;return u.jsxs("button",{type:"button",onClick:()=>s(l.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${c?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${c?"border-primary":"border-muted-foreground/50"}`,children:c&&u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),u.jsx("span",{className:"text-sm font-medium",children:l.title})]}),u.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:l.desc})]},l.value)})}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(Se,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}function ea(){return u.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 Ul(){return u.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 sv({name:e,blob:t,onManualRender:n,isGenerating:r,isRendering:i,onShowCacheMetrics:s,onShowSchemas:a,onShowFonts:o,documentText:l,editorDocumentText:c,editorDocumentName:f,warnings:d,onToggleChat:h,chatOpen:p,onTogglePreview:g,previewOpen:w}){const[_,b]=x.useState(!1),[N,m]=x.useState(!1),[O,C]=x.useState(!1),[v,k]=x.useState(!1),[$,H]=x.useState(!1),[j,I]=x.useState(null),{toast:T}=Sr(),P=Ld(),{generateDocument:A}=ev(),M=x.useContext(Fd),V=nv(),U=Hi(ee=>ee.generationBackend),J=Hi(ee=>ee.setSettings),ne=U??V.default??void 0,S=x.useCallback(()=>{const ee={},{customThemes:de}=M.getState();return Object.values(de).forEach(fe=>{fe.valid&&fe.parsed&&(ee[fe.name]=fe.parsed)}),ee},[M]),oe=je.useMemo(()=>{if(!l)return[];try{const ee=JSON.parse(l);return[...(ht==="pptx"?_g:jg)(ee)].filter(fe=>!Ng(fe))}catch{return[]}},[l]),[B,y]=x.useState(!1),q=x.useCallback(async()=>{if(t){b(!0);try{await new Promise(ee=>setTimeout(ee,100)),Li(`${e}${Tr}`,t)}finally{setTimeout(()=>b(!1),500)}}},[t,e]),X=x.useCallback(async()=>{if(t){if(oe.length===0){await q();return}y(!0)}},[t,oe.length,q]),Y=x.useCallback(async ee=>{var de;if(l){b(!0);try{const fe=await A(e,l,S(),void 0,{bypassCache:!0,fonts:{mode:ee}});if(fe.blob.size===0)T({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Li(`${e}${Tr}`,fe.blob);const Re=(de=fe.warnings)==null?void 0:de.find(Oe=>{var We,E;return((We=Oe.context)==null?void 0:We.code)==="FONT_MODE_SUBSTITUTED"||((E=Oe.context)==null?void 0:E.code)==="FONT_MODE_CUSTOM"});Re&&T({title:ee==="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(()=>b(!1),500)}}},[l,e,A,T,S]),ie=x.useCallback(async()=>{if(!(!d||d.length===0)){m(!0);try{const ee=rv(d);if(!ee){T({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const de=await A("warnings",JSON.stringify(ee,null,2),{});de&&typeof de=="object"&&"blob"in de&&de.blob&&(Li(`${e}-warnings${Tr}`,de.blob),T({title:"Warnings downloaded",description:`Downloaded warnings document with ${d.length} warning(s).`}))}catch(ee){console.error("Failed to generate warnings document:",ee),T({title:"Download failed",description:ee instanceof Error?ee.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>m(!1),500)}}},[d,e,A,T]),D=x.useCallback(async()=>{C(!0);try{await Gb.delete(`/${ht}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),T({title:"Cache Cleared",description:"All active caches have been successfully cleared.",variant:"default"})}catch(ee){console.error("Failed to clear cache:",ee),T({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{C(!1)}},[T]),ue=c??l,he=x.useCallback(()=>{var fe,Re;if(!ue){T({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(ue)}catch{T({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}H(!0);const ee=(async()=>{const Oe=await fetch(`/api/${ht}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:ue,customThemes:S(),options:{sourceName:P(f??e)}})});if(!Oe.ok){let E=`Request failed with status ${Oe.status}`;try{const R=await Oe.json(),Z=R.error??R.message;typeof Z=="string"&&Z&&(E=Z)}catch{}throw new Error(E)}const We=await Oe.json();return JSON.stringify(We.data,null,2)})();let de;typeof ClipboardItem<"u"&&((fe=navigator.clipboard)!=null&&fe.write)?de=navigator.clipboard.write([new ClipboardItem({"text/plain":ee.then(Oe=>new Blob([Oe],{type:"text/plain"}))})]):(Re=navigator.clipboard)!=null&&Re.writeText?de=ee.then(Oe=>navigator.clipboard.writeText(Oe)):de=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await de,T({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(Oe){let We=null;try{We=await ee}catch(E){console.error("Error fetching standard components:",E),T({title:"Failed to get standard components",description:E instanceof Error?E.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",Oe),I(We)}finally{H(!1)}})()},[ue,e,f,P,S,T]),ce=x.useCallback(async()=>{if(j!=null)try{await navigator.clipboard.writeText(j),T({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),I(null)}catch{T({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[j,T]);return u.jsxs(u.Fragment,{children:[u.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:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[u.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.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:u.jsx(Od,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Xe,{className:"max-w-sm",children:u.jsxs("p",{className:"text-sm",children:["Preview converts the file to a PDF with LibreOffice. Download the ",Tr," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(Se,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:n,"aria-label":"Render preview",disabled:r||i||w===!1,children:[i?u.jsx(gn,{size:"sm"}):u.jsx(Kg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Xe,{children:u.jsx("p",{children:w===!1?"Open preview to run":i?"Rendering preview...":"Render preview"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(Se,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||_||r,onClick:X,children:[_?u.jsx(gn,{size:"sm"}):u.jsx(Xg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Xe,{children:u.jsxs("p",{children:["Download ",Tr]})})]}),d&&d.length>0&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Se,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:N||r,onClick:ie,children:N?u.jsx(gn,{size:"sm"}):u.jsx(Dd,{className:"h-3.5 w-3.5"})})}),u.jsx(Xe,{children:u.jsxs("p",{children:["Download warnings (",d.length,")"]})})]}),V.ids.length>1&&u.jsxs(ti,{value:ne,onValueChange:ee=>J({generationBackend:ee}),children:[u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsxs(fr,{"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:[u.jsx(Na,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),u.jsxs(ni,{placeholder:"Renderer",children:[u.jsx("span",{className:"font-medium",children:ne}),ne!==V.default&&u.jsx(ea,{})]})]})}),u.jsx(Xe,{children:u.jsxs("p",{children:["Renderer that writes the ",ht.toUpperCase()," file. A non-default one may refuse a document it cannot express."]})})]}),u.jsx(pr,{className:"min-w-[var(--radix-select-trigger-width)] text-sidebar-foreground",children:u.jsxs(Zd,{children:[u.jsx(ho,{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),V.ids.map(ee=>u.jsx(Pn,{value:ee,className:"text-xs",children:u.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap",children:[u.jsx("span",{className:"font-medium",children:ee}),ee===V.default?u.jsx(Ul,{}):u.jsx(ea,{})]})},ee))]})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(Ns,{children:[u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Es,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Ad,{className:"h-3.5 w-3.5"})})})}),u.jsx(Xe,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(yi,{align:"end",className:"w-52",children:[a&&u.jsxs($t,{onClick:a,children:[u.jsx(Qg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),o&&u.jsxs($t,{onClick:o,children:[u.jsx(ja,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),s&&u.jsxs($t,{onClick:s,children:[u.jsx(Ea,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),ue?u.jsxs($t,{onClick:he,disabled:$,children:[u.jsx(Ca,{className:"h-4 w-4 mr-2"}),$?"Copying...":"Copy standard components"]}):u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs($t,{disabled:!0,children:[u.jsx(Ca,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),u.jsx(Xe,{side:"left",children:u.jsx("p",{children:"No document selected — open or select a document first"})})]}),u.jsx(mr,{}),u.jsxs($t,{onClick:()=>k(!0),disabled:O,className:"text-destructive focus:text-destructive",children:[u.jsx(fo,{className:"h-4 w-4 mr-2"}),O?"Clearing...":"Clear all caches"]}),V.ids.length>1&&u.jsxs(u.Fragment,{children:[u.jsx(mr,{className:"lg:hidden"}),u.jsx(ko,{className:"lg:hidden px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),V.ids.map(ee=>u.jsxs($t,{className:"lg:hidden gap-1.5",onClick:()=>J({generationBackend:ee}),children:[u.jsx(an,{className:`h-3.5 w-3.5 shrink-0 ${ne===ee?"opacity-100":"opacity-0"}`}),u.jsx("span",{className:"font-medium",children:ee}),ee===V.default?u.jsx(Ul,{}):u.jsx(ea,{})]},ee))]})]})]}),g&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Se,{variant:w?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:g,children:w?u.jsx(Rd,{className:"h-3.5 w-3.5"}):u.jsx(ex,{className:"h-3.5 w-3.5"})})}),u.jsx(Xe,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[w?"Hide":"Show"," Preview"," ",u.jsx(ii,{shortcut:"mod+shift+p"})]})})]}),h&&u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.jsx(Se,{variant:p?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:h,children:u.jsx(Md,{className:"h-3.5 w-3.5"})})}),u.jsx(Xe,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[p?"Close":"Open"," AI Chat"," ",u.jsx(ii,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(iv,{open:B,onClose:()=>y(!1),nonSafeFonts:oe,onChoose:Y}),u.jsx(Ct,{open:j!=null,onOpenChange:ee=>{ee||I(null)},children:u.jsxs(kt,{className:"max-w-lg",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Standard components"}),u.jsx(on,{children:"The browser blocked the automatic clipboard write. Copy the JSON from here instead."})]}),u.jsx(ip,{readOnly:!0,value:j??"",className:"h-64 font-mono text-xs",onFocus:ee=>ee.currentTarget.select()}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:()=>I(null),children:"Close"}),u.jsx(Se,{size:"sm",onClick:ce,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:v,onOpenChange:k,children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Clear all caches?"}),u.jsx(on,{children:"This will clear the document, component, and rasterized-visual caches. Next generation will be uncached."})]}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:()=>k(!1),children:"Cancel"}),u.jsx(Se,{variant:"destructive",size:"sm",disabled:O,onClick:async()=>{await D(),k(!1)},children:O?u.jsx(gn,{size:"sm"}):"Clear"})]})]})})]})}const av=je.memo(sv),sp=bg,Co=x.forwardRef(({className:e,...t},n)=>u.jsx(kd,{ref:n,className:G("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Co.displayName=kd.displayName;const lr=x.forwardRef(({className:e,...t},n)=>u.jsx(Sd,{ref:n,className:G("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}));lr.displayName=Sd.displayName;const ur=x.forwardRef(({className:e,...t},n)=>u.jsx(_d,{ref:n,className:G("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));ur.displayName=_d.displayName;async function ov(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 lv(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 uv(e){const t=lv(e);return ov(t)}const cv=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=x.useState(n),[s,a]=x.useState(null),[o,l]=x.useState(null),[c,f]=x.useState(!1),[d,h]=x.useState(!1),[p,g]=x.useState(null),[w,_]=x.useState(null),[b,N]=x.useState(!1),{toast:m}=Sr(),O=Lt(P=>P.selectedPlugins),C=Array.from(O);x.useEffect(()=>{n&&i(n)},[n]);const v=x.useCallback(async()=>{f(!0),g(null);try{const P=await Us.fetchDocumentSchema(C);a(P)}catch(P){const A=P instanceof Error?P.message:"Failed to load document schema";g(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{f(!1)}},[C,m]),k=x.useCallback(async()=>{if(!o){h(!0),_(null);try{const P=await Us.fetchThemeSchema();l(P)}catch(P){const A=P instanceof Error?P.message:"Failed to load theme schema";_(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{h(!1)}}},[o,m]),[$,H]=x.useState([]);x.useEffect(()=>{e||(a(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const P=C.length!==$.length||C.some((A,M)=>A!==$[M]);r==="document"?(!s||P)&&(P&&(Us.clearPluginSchemaCache(),H([...C])),c||v()):r==="theme"&&!o&&!d&&k()},[r,e,s,o,c,d,C,$,v,k]);const j=C.length,I=r==="document"?s:o,T=async()=>{if(I)try{await uv(I)&&(N(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>N(!1),2e3))}catch(P){console.error("Copy failed:",P)}};return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Vt,{children:u.jsx(Ut,{children:"Schema Viewer"})}),u.jsxs(sp,{value:r,onValueChange:P=>i(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Co,{children:[u.jsxs(lr,{value:"document",className:"flex items-center gap-1",children:["Document",j>0&&u.jsxs(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",j]})]}),u.jsx(lr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(Se,{variant:"ghost",size:"icon",onClick:T,disabled:b||!I,"aria-label":"Copy schema",children:b?u.jsx(an,{className:"h-4 w-4"}):u.jsx(ks,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(ur,{value:"document",className:"h-full",children:u.jsx(ts,{schema:s,loading:c,error:p||void 0})}),u.jsx(ur,{value:"theme",className:"h-full",children:u.jsx(ts,{schema:o,loading:d,error:w||void 0})})]})]})]})})};function To(e,t){var r;const n=$d.getState().getEditor(e);return(r=n==null?void 0:n.flushPendingSave)==null||r.call(n),n?n.toStorageValue(n.editor.getValue()):t}function ap(e,t,n){if(t.length===0)return n;const r=Jl(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const a=t[s],o=t[s+1],l=i[a],c=Jl(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function Jl(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Hl=2*1024*1024,Wl=12*1024*1024;function dv(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 fv(e){let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function is(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.round(e/1024)} KB`}function pv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>Hl)return{ok:!1,message:`"${e}" is ${is(t.length)}. The limit is ${is(Hl)} per font, because the bytes travel inside the document JSON.`};const n=dv(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:fv(t)}}const hv=new Set(["italic","oblique"]);function mv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[a,o]of Object.entries(Ed))r.set(o.toLowerCase(),Number(a));let i=400,s=!1;for(;n.length>1;){const a=n[n.length-1].toLowerCase();if(hv.has(a)){s=!0,n.pop();continue}const o=r.get(a);if(o!==void 0){i=o,n.pop();continue}break}return{family:n.join(" ")||t,weight:i,italic:s}}function gv(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 xv(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 yv(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(o=>{const l=xv(o);return l?!n.some(c=>c.weight===l.weight&&c.italic===l.italic):!0}),s=n.map(o=>({kind:"data",data:o.data,weight:o.weight,italic:o.italic})),a=r??(e==null?void 0:e.category);return{id:(e==null?void 0:e.id)??t,family:t,...a?{category:a}:{},sources:[...i,...s]}}function bv(e,t){let n=Array.isArray(e)?[...e]:[];for(const r of t){const i=r.sources.filter(a=>a.kind==="data").map(a=>({data:a.data,weight:a.weight??400,italic:a.italic??!1}));if(i.length===0)continue;const s=n.find(a=>{var o;return((o=a==null?void 0:a.family)==null?void 0:o.toLowerCase())===r.family.toLowerCase()});n=gv(n,yv(s,r.family,i,r.category))}return n}function vv(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 wv(e){const t=new TextEncoder().encode(e).length;return t<=Wl?null:`Adding this font would push the document to ${is(t)}, past the ${is(Wl)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const ql=new Set,kv=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function Sv(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 _v(e,t,n,r){const i=kv(e,n,r);if(!ql.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=Sv(t),a=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await a.load(),document.fonts.add(a),ql.add(i)}catch{}}const jv={safe:[],google:[]};function Gl(e,t){var f;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((f=r==null?void 0:r.dataset.weights)==null?void 0:f.split(",").map(Number).filter(d=>!Number.isNaN(d)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((d,h)=>d-h).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${o}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...a].sort((d,h)=>d-h).join(",")}function Nv(){const e=Ne(i=>i.activeTab),t=Ne(i=>i.documents),n=Ne(i=>i.documentTypes),r=Ne(i=>i.saveDocument);return x.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(c=>c.name===e);if(!s)return{ok:!1,error:"Active theme not found"};const a=To(e,s.text);let o;try{o=JSON.parse(a)}catch(c){return{ok:!1,error:`Active theme is not valid JSON: ${c.message}`}}const l=i(o);return r(e,JSON.stringify(l,null,2)),{ok:!0,name:e}},[e,t,n,r])}function Ev(){const e=Ne(r=>r.activeTab),t=Ne(r=>r.documents),n=Ne(r=>r.saveDocument);return x.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(c=>c.name===e);if(!s)return{ok:!1,error:"Active document not found"};const a=To(e,s.text);let o;try{o=JSON.parse(a)}catch(c){return{ok:!1,error:`Active document is not valid JSON: ${c.message}`}}const l=ap(o,r,i);return n(e,JSON.stringify(l,null,2)),{ok:!0,name:e}},[e,t,n])}function Cv(){const e=Ne(i=>i.activeTab),t=Ne(i=>i.documents),n=Ne(i=>i.documentTypes),r=Ne(i=>i.saveDocument);return x.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 a=To(e,s.text);let o;try{o=JSON.parse(a)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const l=bv((h=o==null?void 0:o.props)==null?void 0:h.fontRegistry,i),c=ap(o,["props","fontRegistry"],l),f=JSON.stringify(c,null,2),d=wv(f);return d?{ok:!1,error:d}:(r(e,f),{ok:!0,name:e})},[e,t,n,r])}function Tv(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 Yl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Iv=({open:e,onOpenChange:t})=>{const n=$i(D=>D.open),r=$i(D=>D.contextual),i=$i(D=>D.close),s=e??n,a=r,o=x.useCallback(D=>{t&&t(D),D||i()},[t,i]),[l,c]=x.useState(jv),[f,d]=x.useState(!1),[h,p]=x.useState(""),[g,w]=x.useState("safe"),[_,b]=x.useState(null),[N,m]=x.useState(null),[O,C]=x.useState(!1),[v,k]=x.useState(!1),[$,H]=x.useState(""),[j,I]=x.useState([]),T=x.useRef(null),{toast:P}=Sr(),A=Nv(),M=Ev(),V=Cv(),U=Ne(D=>D.activeTab),J=Ne(D=>D.documentTypes),ne=U&&J[U]==="application/json+theme",S=!!a||ne;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(d(!0),fetch(ei.fonts.catalog).then(D=>D.json()).then(D=>c(D)).catch(D=>{P({variant:"destructive",title:"Font catalog unavailable",description:D.message})}).finally(()=>d(!1))))},[s,l,P]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const D of l.google)Gl(D.family,D.weights)},[g,l]);const oe=x.useMemo(()=>l.safe.filter(D=>D.toLowerCase().includes(h.toLowerCase())),[l.safe,h]),B=x.useMemo(()=>l.google.filter(D=>D.family.toLowerCase().includes(h.toLowerCase())),[l.google,h]),y=x.useCallback(async D=>{try{await navigator.clipboard.writeText(D),m(D),setTimeout(()=>m(null),1500)}catch{P({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[P]),q=x.useCallback(async(D,ue,he)=>{b(D);try{const ce=A(ee=>(Tv(ee,he,D),ee));if(!ce.ok){P({variant:"destructive",title:"Could not insert font",description:ce.error});return}P({title:"Font inserted",description:`${D} set as ${he} font in "${ce.name}".`})}finally{b(null)}},[A,P]),X=x.useCallback(async D=>{if(a){b(D);try{const ue=M(a.jsonPath,D);if(!ue.ok){P({variant:"destructive",title:"Could not insert font",description:ue.error});return}P({title:"Font inserted",description:`${D} set at ${Yl(a.jsonPath)}.`}),o(!1)}finally{b(null)}}},[a,M,P,o]),Y=x.useCallback(async D=>{if(!(!D||D.length===0)){C(!0);try{const ue=[];for(const ce of Array.from(D)){const ee=new Uint8Array(await ce.arrayBuffer()),de=pv(ce.name,ee);if(!de.ok){P({variant:"destructive",title:"Font rejected",description:de.message});continue}ue.push({identity:mv(ce.name),base64:de.base64})}if(ue.length===0)return;const he=V(ue.map(({identity:ce,base64:ee})=>({id:ce.family,family:ce.family,sources:[{kind:"data",data:ee,weight:ce.weight,italic:ce.italic}]})));if(!he.ok){P({variant:"destructive",title:"Could not register font",description:he.error});return}for(const{identity:ce,base64:ee}of ue)_v(ce.family,ee,ce.weight,ce.italic),P({title:`Added ${ce.family}`,description:`Registered at weight ${ce.weight}${ce.italic?" italic":""} in props.fontRegistry. Reference it as "${ce.family}".`})}catch(ue){P({variant:"destructive",title:"Upload failed",description:ue.message})}finally{C(!1),T.current&&(T.current.value="")}}},[V,P]),ie=x.useCallback(async()=>{var ue,he;const D=$.trim();if(D){k(!0),I([]);try{const ce=await fetch(ei.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:D,weights:[400,700],italics:!1})});if(ce.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!ce.ok){const Oe=await ce.json().catch(()=>({}));throw new Error(Oe.error??`Materialize failed (${ce.status})`)}const ee=await ce.json();I(ee.warnings??[]);const de=(ue=l.google.find(Oe=>Oe.family.toLowerCase()===ee.family.toLowerCase()))==null?void 0:ue.category,fe=vv(ee,de);if(!fe){P({variant:"destructive",title:"Nothing to embed",description:((he=ee.warnings)==null?void 0:he.join(" · "))||`Google Fonts has no family named "${D}".`});return}const Re=V([fe]);if(!Re.ok){P({variant:"destructive",title:"Could not register font",description:Re.error});return}Gl(ee.family,[400,700]),P({title:`Added ${ee.family}`,description:`Embedded ${fe.sources.length} weight(s) in props.fontRegistry.`})}catch(ce){P({variant:"destructive",title:"Google Fonts fetch failed",description:ce.message})}finally{k(!1)}}},[$,l.google,V,P]);return u.jsx(Ct,{open:s,onOpenChange:o,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Vt,{children:u.jsx(Ut,{children:a?`Font for ${Yl(a.jsonPath)}`:"Fonts"})}),!a&&!ne&&g!=="custom"&&u.jsx(ir,{children:u.jsxs(sr,{children:["Fonts are registered on themes. Open a ",u.jsx("code",{children:".theme.json"})," ","file to apply a font — the buttons below are disabled until you do."]})}),u.jsxs(sp,{value:g,onValueChange:D=>w(D),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Co,{children:[u.jsxs(lr,{value:"safe",children:["Safe",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(lr,{value:"google",children:["Google",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]}),u.jsx(lr,{value:"custom",children:"Custom"})]}),u.jsx(hr,{type:"search",placeholder:"Search fonts...",value:h,onChange:D=>p(D.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(ur,{value:"safe",className:"m-0",children:f&&oe.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Fr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:oe.map(D=>u.jsx(Kl,{family:D,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${D}", sans-serif`},onCopy:()=>y(D),copied:N===D,contextual:!!a,onUseThis:()=>X(D),onInsertHeading:()=>q(D,"safe","heading"),onInsertBody:()=>q(D,"safe","body"),applying:_===D,disabled:!S},D))})}),u.jsx(ur,{value:"google",className:"m-0",children:f&&B.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Fr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:B.map(D=>u.jsx(Kl,{family:D.family,meta:u.jsxs("span",{className:"text-xs",children:[D.category," · ",D.weights.length," weights"]}),previewStyle:{fontFamily:`"${D.family}", sans-serif`},onCopy:()=>y(D.family),copied:N===D.family,contextual:!!a,onUseThis:()=>X(D.family),onInsertHeading:()=>q(D.family,"google","heading"),onInsertBody:()=>q(D.family,"google","body"),applying:_===D.family,disabled:!S,extraAction:u.jsx(zv,{family:D.family,weights:D.weights,hasItalic:D.hasItalic})},D.family))})}),u.jsx(ur,{value:"custom",className:"m-0 flex flex-col gap-6",children:ne?u.jsx(ir,{children:u.jsxs(sr,{children:["Custom fonts are stored on the document (",u.jsx("code",{children:"props.fontRegistry"}),"), because the bytes travel with the JSON. Open a document tab to add one."]})}):u.jsxs(u.Fragment,{children:[u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Upload a font file"}),u.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."," ",u.jsx("code",{children:"Geist-SemiBold.ttf"}),")."]}),u.jsxs("div",{onDragOver:D=>D.preventDefault(),onDrop:D=>{D.preventDefault(),Y(D.dataTransfer.files)},className:"rounded-md border border-dashed p-6 text-center",children:[u.jsx("input",{ref:T,type:"file",accept:".ttf,.otf,font/ttf,font/otf",multiple:!0,className:"hidden",onChange:D=>void Y(D.target.files)}),u.jsxs(Se,{variant:"secondary",disabled:O,onClick:()=>{var D;return(D=T.current)==null?void 0:D.click()},children:[O?u.jsx(Fr,{className:"animate-spin mr-2 h-4 w-4"}):u.jsx(tx,{className:"mr-2 h-4 w-4"}),"Choose font files"]}),u.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"or drop them here"})]})]}),u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Embed any Google font"}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not limited to the ",l.google.length," curated families — type any Google Fonts family name and its regular and bold weights are fetched and embedded."]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(hr,{placeholder:"e.g. Geist",value:$,onChange:D=>H(D.target.value),onKeyDown:D=>{D.key==="Enter"&&ie()}}),u.jsxs(Se,{onClick:()=>void ie(),disabled:v||$.trim()==="",children:[v&&u.jsx(Fr,{className:"animate-spin mr-2 h-4 w-4"}),"Embed"]})]}),j.length>0&&u.jsx(ir,{children:u.jsx(sr,{className:"text-xs",children:j.join(" · ")})})]})]})})]})]})]})})},Av="The quick brown fox jumps over the lazy dog",zv=({family:e,weights:t,hasItalic:n})=>{const r=x.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(Ns,{children:[u.jsx(Es,{asChild:!0,children:u.jsx(Se,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(yi,{align:"end",className:"min-w-[260px]",children:[u.jsxs(ko,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(mr,{}),r.map(i=>{const s=Ed[i]??String(i);return u.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-1.5",children:[u.jsx("span",{className:"truncate",style:{fontFamily:`"${e}", sans-serif`,fontWeight:i},children:s}),u.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:["fontWeight: ",i]})]},i)})]})]})},Kl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:f,extraAction:d})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:Av}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Se,{size:"sm",onClick:a,disabled:c||f,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(Se,{size:"sm",variant:"secondary",onClick:o,disabled:c||f,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Se,{size:"sm",variant:"secondary",onClick:l,disabled:c||f,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),d,u.jsx(Se,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(an,{className:"h-4 w-4"}):u.jsx(ks,{className:"h-4 w-4"})})]})]});function Xl({previewOpen:e,onTogglePreview:t}){const n=rn(v=>v.name||""),r=rn(v=>v.blob),i=rn(v=>v.isGenerating),s=rn(v=>v.text),a=rn(v=>v.warnings),o=rn(v=>v.isRendering),l=Hi(v=>v.useGlobalPreviewHeader??!0),c=Ne(v=>v.activeTab),f=Ne(v=>v.documentTypes),d=c&&f[c]==="application/json+theme"?"theme":"document",h=Ne(v=>{var k;return v.activeTab&&v.documentTypes[v.activeTab]!=="application/json+theme"?(k=v.documents.find($=>$.name===v.activeTab))==null?void 0:k.text:void 0}),p=Ne(v=>v.activeTab&&v.documentTypes[v.activeTab]!=="application/json+theme"?v.activeTab:void 0),g=Pe(v=>v.chatOpen),w=Pe(v=>v.toggleChat),[_,b]=je.useState(!1),N=$i(v=>v.openFor);if(!l)return null;const m=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),O=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),C=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(av,{name:C,blob:r,onManualRender:m,isGenerating:i,isRendering:!!o,onShowCacheMetrics:O,onShowSchemas:()=>b(!0),onShowFonts:()=>N(),documentText:s,editorDocumentText:h,editorDocumentName:p,warnings:a,onToggleChat:w,chatOpen:g,onTogglePreview:t,previewOpen:e}),u.jsx(cv,{open:_,onOpenChange:b,defaultTab:d==="theme"?"theme":"document"}),u.jsx(Iv,{})]})}function Ov(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Pv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Dv=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Rv={};function Ql(e,t){return(Rv.jsx?Dv:Pv).test(e)}const Mv=/[ \t\n\f\r]/g;function $v(e){return typeof e=="object"?e.type==="text"?eu(e.value):!1:eu(e)}function eu(e){return e.replace(Mv,"")===""}class bi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}bi.prototype.normal={};bi.prototype.property={};bi.prototype.space=void 0;function op(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new bi(n,r,t)}function Ba(e){return e.toLowerCase()}class St{constructor(t,n){this.attribute=n,this.property=t}}St.prototype.attribute="";St.prototype.booleanish=!1;St.prototype.boolean=!1;St.prototype.commaOrSpaceSeparated=!1;St.prototype.commaSeparated=!1;St.prototype.defined=!1;St.prototype.mustUseProperty=!1;St.prototype.number=!1;St.prototype.overloadedBoolean=!1;St.prototype.property="";St.prototype.spaceSeparated=!1;St.prototype.space=void 0;let Fv=0;const ke=$n(),nt=$n(),Za=$n(),re=$n(),Be=$n(),cr=$n(),jt=$n();function $n(){return 2**++Fv}const Va=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:nt,commaOrSpaceSeparated:jt,commaSeparated:cr,number:re,overloadedBoolean:Za,spaceSeparated:Be},Symbol.toStringTag,{value:"Module"})),ta=Object.keys(Va);class Io extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),tu(this,"space",i),typeof r=="number")for(;++s<ta.length;){const a=ta[s];tu(this,ta[s],(r&Va[a])===Va[a])}}}Io.prototype.defined=!0;function tu(e,t,n){n&&(e[t]=n)}function jr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Io(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Ba(r)]=r,n[Ba(s.attribute)]=r}return new bi(t,n,e.space)}const lp=jr({properties:{ariaActiveDescendant:null,ariaAtomic:nt,ariaAutoComplete:null,ariaBusy:nt,ariaChecked:nt,ariaColCount:re,ariaColIndex:re,ariaColSpan:re,ariaControls:Be,ariaCurrent:null,ariaDescribedBy:Be,ariaDetails:null,ariaDisabled:nt,ariaDropEffect:Be,ariaErrorMessage:null,ariaExpanded:nt,ariaFlowTo:Be,ariaGrabbed:nt,ariaHasPopup:null,ariaHidden:nt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Be,ariaLevel:re,ariaLive:null,ariaModal:nt,ariaMultiLine:nt,ariaMultiSelectable:nt,ariaOrientation:null,ariaOwns:Be,ariaPlaceholder:null,ariaPosInSet:re,ariaPressed:nt,ariaReadOnly:nt,ariaRelevant:null,ariaRequired:nt,ariaRoleDescription:Be,ariaRowCount:re,ariaRowIndex:re,ariaRowSpan:re,ariaSelected:nt,ariaSetSize:re,ariaSort:null,ariaValueMax:re,ariaValueMin:re,ariaValueNow:re,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function up(e,t){return t in e?e[t]:t}function cp(e,t){return up(e,t.toLowerCase())}const Lv=jr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:cr,acceptCharset:Be,accessKey:Be,action:null,allow:null,allowFullScreen:ke,allowPaymentRequest:ke,allowUserMedia:ke,alt:null,as:null,async:ke,autoCapitalize:null,autoComplete:Be,autoFocus:ke,autoPlay:ke,blocking:Be,capture:null,charSet:null,checked:ke,cite:null,className:Be,cols:re,colSpan:null,content:null,contentEditable:nt,controls:ke,controlsList:Be,coords:re|cr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Za,draggable:nt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Be,height:re,hidden:Za,high:re,href:null,hrefLang:null,htmlFor:Be,httpEquiv:Be,id:null,imageSizes:null,imageSrcSet:null,inert:ke,inputMode:null,integrity:null,is:null,isMap:ke,itemId:null,itemProp:Be,itemRef:Be,itemScope:ke,itemType:Be,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:ke,low:re,manifest:null,max:null,maxLength:re,media:null,method:null,min:null,minLength:re,multiple:ke,muted:ke,name:null,nonce:null,noModule:ke,noValidate:ke,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:ke,optimum:re,pattern:null,ping:Be,placeholder:null,playsInline:ke,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:ke,referrerPolicy:null,rel:Be,required:ke,reversed:ke,rows:re,rowSpan:re,sandbox:Be,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:re,sizes:null,slot:null,span:re,spellCheck:nt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:re,step:null,style:null,tabIndex:re,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:nt,width:re,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Be,axis:null,background:null,bgColor:null,border:re,borderColor:null,bottomMargin:re,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:ke,declare:ke,event:null,face:null,frame:null,frameBorder:null,hSpace:re,leftMargin:re,link:null,longDesc:null,lowSrc:null,marginHeight:re,marginWidth:re,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:re,rules:null,scheme:null,scrolling:nt,standby:null,summary:null,text:null,topMargin:re,valueType:null,version:null,vAlign:null,vLink:null,vSpace:re,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:re,security:null,unselectable:null},space:"html",transform:cp}),Bv=jr({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:jt,accentHeight:re,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:re,amplitude:re,arabicForm:null,ascent:re,attributeName:null,attributeType:null,azimuth:re,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:re,by:null,calcMode:null,capHeight:re,className:Be,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:re,diffuseConstant:re,direction:null,display:null,dur:null,divisor:re,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:re,enableBackground:null,end:null,event:null,exponent:re,externalResourcesRequired:null,fill:null,fillOpacity:re,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:cr,g2:cr,glyphName:cr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:re,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:re,horizOriginX:re,horizOriginY:re,id:null,ideographic:re,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:re,k:re,k1:re,k2:re,k3:re,k4:re,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:re,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:re,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:re,overlineThickness:re,paintOrder:null,panose1:null,path:null,pathLength:re,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Be,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:re,pointsAtY:re,pointsAtZ:re,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:jt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:jt,rev:jt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:jt,requiredFeatures:jt,requiredFonts:jt,requiredFormats:jt,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:re,specularExponent:re,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:re,strikethroughThickness:re,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:re,strokeOpacity:re,strokeWidth:null,style:null,surfaceScale:re,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:re,tableValues:null,target:null,targetX:re,targetY:re,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:jt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:re,underlineThickness:re,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:re,values:null,vAlphabetic:re,vMathematical:re,vectorEffect:null,vHanging:re,vIdeographic:re,version:null,vertAdvY:re,vertOriginX:re,vertOriginY:re,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:re,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:up}),dp=jr({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()}}),fp=jr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:cp}),pp=jr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Zv={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"},Vv=/[A-Z]/g,nu=/-[a-z]/g,Uv=/^data[-\w.:]+$/i;function Jv(e,t){const n=Ba(t);let r=t,i=St;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Uv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(nu,Wv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!nu.test(s)){let a=s.replace(Vv,Hv);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=Io}return new i(r,t)}function Hv(e){return"-"+e.toLowerCase()}function Wv(e){return e.charAt(1).toUpperCase()}const qv=op([lp,Lv,dp,fp,pp],"html"),Ao=op([lp,Bv,dp,fp,pp],"svg");function Gv(e){return e.join(" ").trim()}var Hn={},na,ru;function Yv(){if(ru)return na;ru=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,a=/^[;\s]*/,o=/^\s+|\s+$/g,l=`
10
10
  `,c="/",f="*",d="",h="comment",p="declaration";function g(_,b){if(typeof _!="string")throw new TypeError("First argument must be a string");if(!_)return[];b=b||{};var N=1,m=1;function O(A){var M=A.match(t);M&&(N+=M.length);var V=A.lastIndexOf(l);m=~V?A.length-V:m+A.length}function C(){var A={line:N,column:m};return function(M){return M.position=new v(A),H(),M}}function v(A){this.start=A,this.end={line:N,column:m},this.source=b.source}v.prototype.content=_;function k(A){var M=new Error(b.source+":"+N+":"+m+": "+A);if(M.reason=A,M.filename=b.source,M.line=N,M.column=m,M.source=_,!b.silent)throw M}function $(A){var M=A.exec(_);if(M){var V=M[0];return O(V),_=_.slice(V.length),M}}function H(){$(n)}function j(A){var M;for(A=A||[];M=I();)M!==!1&&A.push(M);return A}function I(){var A=C();if(!(c!=_.charAt(0)||f!=_.charAt(1))){for(var M=2;d!=_.charAt(M)&&(f!=_.charAt(M)||c!=_.charAt(M+1));)++M;if(M+=2,d===_.charAt(M-1))return k("End of comment missing");var V=_.slice(2,M-2);return m+=2,O(V),_=_.slice(M),m+=2,A({type:h,comment:V})}}function T(){var A=C(),M=$(r);if(M){if(I(),!$(i))return k("property missing ':'");var V=$(s),U=A({type:p,property:w(M[0].replace(e,d)),value:V?w(V[0].replace(e,d)):d});return $(a),U}}function P(){var A=[];j(A);for(var M;M=T();)M!==!1&&(A.push(M),j(A));return A}return H(),P()}function w(_){return _?_.replace(o,d):d}return na=g,na}var iu;function Kv(){if(iu)return Hn;iu=1;var e=Hn&&Hn.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Hn,"__esModule",{value:!0}),Hn.default=n;const t=e(Yv());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const a=(0,t.default)(r),o=typeof i=="function";return a.forEach(l=>{if(l.type!=="declaration")return;const{property:c,value:f}=l;o?i(c,f,l):f&&(s=s||{},s[c]=f)}),s}return Hn}var Pr={},su;function Xv(){if(su)return Pr;su=1,Object.defineProperty(Pr,"__esModule",{value:!0}),Pr.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(c){return!c||n.test(c)||e.test(c)},a=function(c,f){return f.toUpperCase()},o=function(c,f){return"".concat(f,"-")},l=function(c,f){return f===void 0&&(f={}),s(c)?c:(c=c.toLowerCase(),f.reactCompat?c=c.replace(i,o):c=c.replace(r,o),c.replace(t,a))};return Pr.camelCase=l,Pr}var Dr,au;function Qv(){if(au)return Dr;au=1;var e=Dr&&Dr.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Kv()),n=Xv();function r(i,s){var a={};return!i||typeof i!="string"||(0,t.default)(i,function(o,l){o&&l&&(a[(0,n.camelCase)(o,s)]=l)}),a}return r.default=r,Dr=r,Dr}var ew=Qv();const tw=uo(ew),hp=mp("end"),zo=mp("start");function mp(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 nw(e){const t=zo(e),n=hp(e);if(t&&n)return{start:t,end:n}}function Kr(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?ou(e.position):"start"in e||"end"in e?ou(e):"line"in e||"column"in e?Ua(e):""}function Ua(e){return lu(e&&e.line)+":"+lu(e&&e.column)}function ou(e){return Ua(e&&e.start)+"-"+Ua(e&&e.end)}function lu(e){return e&&typeof e=="number"?e:1}class lt extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},a=!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&&(a=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?s.ruleId=r:(s.source=r.slice(0,l),s.ruleId=r.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){const l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}const o=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=o?o.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=o?o.line:void 0,this.name=Kr(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=a&&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}}lt.prototype.file="";lt.prototype.name="";lt.prototype.reason="";lt.prototype.message="";lt.prototype.stack="";lt.prototype.column=void 0;lt.prototype.line=void 0;lt.prototype.ancestors=void 0;lt.prototype.cause=void 0;lt.prototype.fatal=void 0;lt.prototype.place=void 0;lt.prototype.ruleId=void 0;lt.prototype.source=void 0;const Oo={}.hasOwnProperty,rw=new Map,iw=/[A-Z]/g,sw=new Set(["table","tbody","thead","tfoot","tr"]),aw=new Set(["td","th"]),gp="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function ow(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=mw(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=hw(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"?Ao:qv,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=xp(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function xp(e,t,n){if(t.type==="element")return lw(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return uw(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return dw(e,t,n);if(t.type==="mdxjsEsm")return cw(e,t);if(t.type==="root")return fw(e,t,n);if(t.type==="text")return pw(e,t)}function lw(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=Ao,e.schema=i),e.ancestors.push(t);const s=bp(e,t.tagName,!1),a=gw(e,t);let o=Do(e,t);return sw.has(t.tagName)&&(o=o.filter(function(l){return typeof l=="string"?!$v(l):!0})),yp(e,a,s,t),Po(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function uw(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)}oi(e,t.position)}function cw(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);oi(e,t.position)}function dw(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=Ao,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:bp(e,t.name,!0),a=xw(e,t),o=Do(e,t);return yp(e,a,s,t),Po(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function fw(e,t,n){const r={};return Po(r,Do(e,t)),e.create(t,e.Fragment,r,n)}function pw(e,t){return t.value}function yp(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Po(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function hw(e,t,n){return r;function r(i,s,a,o){const c=Array.isArray(a.children)?n:t;return o?c(s,a,o):c(s,a)}}function mw(e,t){return n;function n(r,i,s,a){const o=Array.isArray(s.children),l=zo(r);return t(i,s,a,o,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function gw(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&Oo.call(t.properties,i)){const s=yw(e,i,t.properties[i]);if(s){const[a,o]=s;e.tableCellAlignToStyle&&a==="align"&&typeof o=="string"&&aw.has(t.tagName)?r=o:n[a]=o}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function xw(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 a=s.expression;a.type;const o=a.properties[0];o.type,Object.assign(n,e.evaluater.evaluateExpression(o.argument))}else oi(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 o=r.value.data.estree.body[0];o.type,s=e.evaluater.evaluateExpression(o.expression)}else oi(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function Do(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:rw;for(;++r<t.children.length;){const s=t.children[r];let a;if(e.passKeys){const l=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(l){const c=i.get(l)||0;a=l+"-"+c,i.set(l,c+1)}}const o=xp(e,s,a);o!==void 0&&n.push(o)}return n}function yw(e,t,n){const r=Jv(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Ov(n):Gv(n)),r.property==="style"){let i=typeof n=="object"?n:bw(e,String(n));return e.stylePropertyNameCase==="css"&&(i=vw(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?Zv[r.property]||r.property:r.attribute,n]}}function bw(e,t){try{return tw(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new lt("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=gp+"#cannot-parse-style-attribute",i}}function bp(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,a;for(;++s<i.length;){const o=Ql(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};a=a?{type:"MemberExpression",object:a,property:o,computed:!!(s&&o.type==="Literal"),optional:!1}:o}r=a}else r=Ql(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return Oo.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);oi(e)}function oi(e,t){const n=new lt("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=gp+"#cannot-handle-mdx-estrees-without-createevaluater",n}function vw(e){const t={};let n;for(n in e)Oo.call(e,n)&&(t[ww(n)]=e[n]);return t}function ww(e){let t=e.replace(iw,kw);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function kw(e){return"-"+e.toLowerCase()}const ra={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"]},Sw={};function Ro(e,t){const n=Sw,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return vp(e,r,i)}function vp(e,t,n){if(_w(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 uu(e.children,t,n)}return Array.isArray(e)?uu(e,t,n):""}function uu(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=vp(e[i],t,n);return r.join("")}function _w(e){return!!(e&&typeof e=="object")}const cu=document.createElement("i");function Mo(e){const t="&"+e+";";cu.innerHTML=t;const n=cu.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function Tt(e,t,n,r){const i=e.length;let s=0,a;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)a=Array.from(r),a.unshift(t,n),e.splice(...a);else for(n&&e.splice(t,n);s<r.length;)a=r.slice(s,s+1e4),a.unshift(t,0),e.splice(...a),s+=1e4,t+=1e4}function Ot(e,t){return e.length>0?(Tt(e,e.length,0,t),e):t}const du={}.hasOwnProperty;function wp(e){const t={};let n=-1;for(;++n<e.length;)jw(t,e[n]);return t}function jw(e,t){let n;for(n in t){const i=(du.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let a;if(s)for(a in s){du.call(i,a)||(i[a]=[]);const o=s[a];Nw(i[a],Array.isArray(o)?o:o?[o]:[])}}}function Nw(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);Tt(e,0,0,r)}function kp(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 Zt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const pt=kn(/[A-Za-z]/),ot=kn(/[\dA-Za-z]/),Ew=kn(/[#-'*+\--9=?A-Z^-~]/);function ss(e){return e!==null&&(e<32||e===127)}const Ja=kn(/\d/),Cw=kn(/[\dA-Fa-f]/),Tw=kn(/[!-/:-@[-`{-~]/);function ye(e){return e!==null&&e<-2}function Fe(e){return e!==null&&(e<0||e===32)}function Ce(e){return e===-2||e===-1||e===32}const Os=kn(new RegExp("\\p{P}|\\p{S}","u")),Rn=kn(/\s/);function kn(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Nr(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let a="";if(s===37&&ot(e.charCodeAt(n+1))&&ot(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(a=String.fromCharCode(s));else if(s>55295&&s<57344){const o=e.charCodeAt(n+1);s<56320&&o>56319&&o<57344?(a=String.fromCharCode(s,o),i=1):a="�"}else a=String.fromCharCode(s);a&&(t.push(e.slice(r,n),encodeURIComponent(a)),r=n+i+1,a=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function ze(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return a;function a(l){return Ce(l)?(e.enter(n),o(l)):t(l)}function o(l){return Ce(l)&&s++<i?(e.consume(l),o):(e.exit(n),t(l))}}const Iw={tokenize:Aw};function Aw(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(o){if(o===null){e.consume(o);return}return e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),ze(e,t,"linePrefix")}function i(o){return e.enter("paragraph"),s(o)}function s(o){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,a(o)}function a(o){if(o===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(o);return}return ye(o)?(e.consume(o),e.exit("chunkText"),s):(e.consume(o),a)}}const zw={tokenize:Ow},fu={tokenize:Pw};function Ow(e){const t=this,n=[];let r=0,i,s,a;return o;function o(m){if(r<n.length){const O=n[r];return t.containerState=O[1],e.attempt(O[0].continuation,l,c)(m)}return c(m)}function l(m){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&N();const O=t.events.length;let C=O,v;for(;C--;)if(t.events[C][0]==="exit"&&t.events[C][1].type==="chunkFlow"){v=t.events[C][1].end;break}b(r);let k=O;for(;k<t.events.length;)t.events[k][1].end={...v},k++;return Tt(t.events,C+1,0,t.events.slice(O)),t.events.length=k,c(m)}return o(m)}function c(m){if(r===n.length){if(!i)return h(m);if(i.currentConstruct&&i.currentConstruct.concrete)return g(m);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(fu,f,d)(m)}function f(m){return i&&N(),b(r),h(m)}function d(m){return t.parser.lazy[t.now().line]=r!==n.length,a=t.now().offset,g(m)}function h(m){return t.containerState={},e.attempt(fu,p,g)(m)}function p(m){return r++,n.push([t.currentConstruct,t.containerState]),h(m)}function g(m){if(m===null){i&&N(),b(0),e.consume(m);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),w(m)}function w(m){if(m===null){_(e.exit("chunkFlow"),!0),b(0),e.consume(m);return}return ye(m)?(e.consume(m),_(e.exit("chunkFlow")),r=0,t.interrupt=void 0,o):(e.consume(m),w)}function _(m,O){const C=t.sliceStream(m);if(O&&C.push(null),m.previous=s,s&&(s.next=m),s=m,i.defineSkip(m.start),i.write(C),t.parser.lazy[m.start.line]){let v=i.events.length;for(;v--;)if(i.events[v][1].start.offset<a&&(!i.events[v][1].end||i.events[v][1].end.offset>a))return;const k=t.events.length;let $=k,H,j;for(;$--;)if(t.events[$][0]==="exit"&&t.events[$][1].type==="chunkFlow"){if(H){j=t.events[$][1].end;break}H=!0}for(b(r),v=k;v<t.events.length;)t.events[v][1].end={...j},v++;Tt(t.events,$+1,0,t.events.slice(k)),t.events.length=v}}function b(m){let O=n.length;for(;O-- >m;){const C=n[O];t.containerState=C[1],C[0].exit.call(t,e)}n.length=m}function N(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Pw(e,t,n){return ze(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function yr(e){if(e===null||Fe(e)||Rn(e))return 1;if(Os(e))return 2}function Ps(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 Ha={name:"attention",resolveAll:Dw,tokenize:Rw};function Dw(e,t){let n=-1,r,i,s,a,o,l,c,f;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;l=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 d={...e[r][1].end},h={...e[n][1].start};pu(d,-l),pu(h,l),a={type:l>1?"strongSequence":"emphasisSequence",start:d,end:{...e[r][1].end}},o={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:h},s={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...a.start},end:{...o.end}},e[r][1].end={...a.start},e[n][1].start={...o.end},c=[],e[r][1].end.offset-e[r][1].start.offset&&(c=Ot(c,[["enter",e[r][1],t],["exit",e[r][1],t]])),c=Ot(c,[["enter",i,t],["enter",a,t],["exit",a,t],["enter",s,t]]),c=Ot(c,Ps(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),c=Ot(c,[["exit",s,t],["enter",o,t],["exit",o,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(f=2,c=Ot(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):f=0,Tt(e,r-1,n-r+3,c),n=r+c.length-f-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function Rw(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=yr(r);let s;return a;function a(l){return s=l,e.enter("attentionSequence"),o(l)}function o(l){if(l===s)return e.consume(l),o;const c=e.exit("attentionSequence"),f=yr(l),d=!f||f===2&&i||n.includes(l),h=!i||i===2&&f||n.includes(r);return c._open=!!(s===42?d:d&&(i||!h)),c._close=!!(s===42?h:h&&(f||!d)),t(l)}}function pu(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Mw={name:"autolink",tokenize:$w};function $w(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 pt(p)?(e.consume(p),a):p===64?n(p):c(p)}function a(p){return p===43||p===45||p===46||ot(p)?(r=1,o(p)):c(p)}function o(p){return p===58?(e.consume(p),r=0,l):(p===43||p===45||p===46||ot(p))&&r++<32?(e.consume(p),o):(r=0,c(p))}function l(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||ss(p)?n(p):(e.consume(p),l)}function c(p){return p===64?(e.consume(p),f):Ew(p)?(e.consume(p),c):n(p)}function f(p){return ot(p)?d(p):n(p)}function d(p){return p===46?(e.consume(p),r=0,f):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||ot(p))&&r++<63){const g=p===45?h:d;return e.consume(p),g}return n(p)}}const vi={partial:!0,tokenize:Fw};function Fw(e,t,n){return r;function r(s){return Ce(s)?ze(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||ye(s)?t(s):n(s)}}const Sp={continuation:{tokenize:Bw},exit:Zw,name:"blockQuote",tokenize:Lw};function Lw(e,t,n){const r=this;return i;function i(a){if(a===62){const o=r.containerState;return o.open||(e.enter("blockQuote",{_container:!0}),o.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(a),e.exit("blockQuoteMarker"),s}return n(a)}function s(a){return Ce(a)?(e.enter("blockQuotePrefixWhitespace"),e.consume(a),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(a))}}function Bw(e,t,n){const r=this;return i;function i(a){return Ce(a)?ze(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a):s(a)}function s(a){return e.attempt(Sp,t,n)(a)}}function Zw(e){e.exit("blockQuote")}const _p={name:"characterEscape",tokenize:Vw};function Vw(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 Tw(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const jp={name:"characterReference",tokenize:Uw};function Uw(e,t,n){const r=this;let i=0,s,a;return o;function o(d){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),l}function l(d){return d===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(d),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),s=31,a=ot,f(d))}function c(d){return d===88||d===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(d),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,a=Cw,f):(e.enter("characterReferenceValue"),s=7,a=Ja,f(d))}function f(d){if(d===59&&i){const h=e.exit("characterReferenceValue");return a===ot&&!Mo(r.sliceSerialize(h))?n(d):(e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return a(d)&&i++<s?(e.consume(d),f):n(d)}}const hu={partial:!0,tokenize:Hw},mu={concrete:!0,name:"codeFenced",tokenize:Jw};function Jw(e,t,n){const r=this,i={partial:!0,tokenize:C};let s=0,a=0,o;return l;function l(v){return c(v)}function c(v){const k=r.events[r.events.length-1];return s=k&&k[1].type==="linePrefix"?k[2].sliceSerialize(k[1],!0).length:0,o=v,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),f(v)}function f(v){return v===o?(a++,e.consume(v),f):a<3?n(v):(e.exit("codeFencedFenceSequence"),Ce(v)?ze(e,d,"whitespace")(v):d(v))}function d(v){return v===null||ye(v)?(e.exit("codeFencedFence"),r.interrupt?t(v):e.check(hu,w,O)(v)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),h(v))}function h(v){return v===null||ye(v)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),d(v)):Ce(v)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),ze(e,p,"whitespace")(v)):v===96&&v===o?n(v):(e.consume(v),h)}function p(v){return v===null||ye(v)?d(v):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(v))}function g(v){return v===null||ye(v)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),d(v)):v===96&&v===o?n(v):(e.consume(v),g)}function w(v){return e.attempt(i,O,_)(v)}function _(v){return e.enter("lineEnding"),e.consume(v),e.exit("lineEnding"),b}function b(v){return s>0&&Ce(v)?ze(e,N,"linePrefix",s+1)(v):N(v)}function N(v){return v===null||ye(v)?e.check(hu,w,O)(v):(e.enter("codeFlowValue"),m(v))}function m(v){return v===null||ye(v)?(e.exit("codeFlowValue"),N(v)):(e.consume(v),m)}function O(v){return e.exit("codeFenced"),t(v)}function C(v,k,$){let H=0;return j;function j(M){return v.enter("lineEnding"),v.consume(M),v.exit("lineEnding"),I}function I(M){return v.enter("codeFencedFence"),Ce(M)?ze(v,T,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(M):T(M)}function T(M){return M===o?(v.enter("codeFencedFenceSequence"),P(M)):$(M)}function P(M){return M===o?(H++,v.consume(M),P):H>=a?(v.exit("codeFencedFenceSequence"),Ce(M)?ze(v,A,"whitespace")(M):A(M)):$(M)}function A(M){return M===null||ye(M)?(v.exit("codeFencedFence"),k(M)):$(M)}}}function Hw(e,t,n){const r=this;return i;function i(a){return a===null?n(a):(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),s)}function s(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}const ia={name:"codeIndented",tokenize:qw},Ww={partial:!0,tokenize:Gw};function qw(e,t,n){const r=this;return i;function i(c){return e.enter("codeIndented"),ze(e,s,"linePrefix",5)(c)}function s(c){const f=r.events[r.events.length-1];return f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?a(c):n(c)}function a(c){return c===null?l(c):ye(c)?e.attempt(Ww,a,l)(c):(e.enter("codeFlowValue"),o(c))}function o(c){return c===null||ye(c)?(e.exit("codeFlowValue"),a(c)):(e.consume(c),o)}function l(c){return e.exit("codeIndented"),t(c)}}function Gw(e,t,n){const r=this;return i;function i(a){return r.parser.lazy[r.now().line]?n(a):ye(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),i):ze(e,s,"linePrefix",5)(a)}function s(a){const o=r.events[r.events.length-1];return o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(a):ye(a)?i(a):n(a)}}const Yw={name:"codeText",previous:Xw,resolve:Kw,tokenize:Qw};function Kw(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 Xw(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Qw(e,t,n){let r=0,i,s;return a;function a(d){return e.enter("codeText"),e.enter("codeTextSequence"),o(d)}function o(d){return d===96?(e.consume(d),r++,o):(e.exit("codeTextSequence"),l(d))}function l(d){return d===null?n(d):d===32?(e.enter("space"),e.consume(d),e.exit("space"),l):d===96?(s=e.enter("codeTextSequence"),i=0,f(d)):ye(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),l):(e.enter("codeTextData"),c(d))}function c(d){return d===null||d===32||d===96||ye(d)?(e.exit("codeTextData"),l(d)):(e.consume(d),c)}function f(d){return d===96?(e.consume(d),i++,f):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(d)):(s.type="codeTextData",c(d))}}class e0{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&&Rr(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),Rr(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Rr(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);Rr(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Rr(this.left,n.reverse())}}}function Rr(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 Np(e){const t={};let n=-1,r,i,s,a,o,l,c;const f=new e0(e);for(;++n<f.length;){for(;n in t;)n=t[n];if(r=f.get(n),n&&r[1].type==="chunkFlow"&&f.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,t0(f,n)),n=t[n],c=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(a=f.get(s),a[1].type==="lineEnding"||a[1].type==="lineEndingBlank")a[0]==="enter"&&(i&&(f.get(i)[1].type="lineEndingBlank"),a[1].type="lineEnding",i=s);else if(!(a[1].type==="linePrefix"||a[1].type==="listItemIndent"))break;i&&(r[1].end={...f.get(i)[1].start},o=f.slice(i,n),o.unshift(r),f.splice(i,n-i+1,o))}}return Tt(e,0,Number.POSITIVE_INFINITY,f.slice(0)),!c}function t0(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let a=n._tokenizer;a||(a=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(a._contentTypeTextTrailing=!0));const o=a.events,l=[],c={};let f,d,h=-1,p=n,g=0,w=0;const _=[w];for(;p;){for(;e.get(++i)[1]!==p;);s.push(i),p._tokenizer||(f=r.sliceStream(p),p.next||f.push(null),d&&a.defineSkip(p.start),p._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=!0),a.write(f),p._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=void 0)),d=p,p=p.next}for(p=n;++h<o.length;)o[h][0]==="exit"&&o[h-1][0]==="enter"&&o[h][1].type===o[h-1][1].type&&o[h][1].start.line!==o[h][1].end.line&&(w=h+1,_.push(w),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(a.events=[],p?(p._tokenizer=void 0,p.previous=void 0):_.pop(),h=_.length;h--;){const b=o.slice(_[h],_[h+1]),N=s.pop();l.push([N,N+b.length-1]),e.splice(N,2,b)}for(l.reverse(),h=-1;++h<l.length;)c[g+l[h][0]]=g+l[h][1],g+=l[h][1]-l[h][0]-1;return c}const n0={resolve:i0,tokenize:s0},r0={partial:!0,tokenize:a0};function i0(e){return Np(e),e}function s0(e,t){let n;return r;function r(o){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(o)}function i(o){return o===null?s(o):ye(o)?e.check(r0,a,s)(o):(e.consume(o),i)}function s(o){return e.exit("chunkContent"),e.exit("content"),t(o)}function a(o){return e.consume(o),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function a0(e,t,n){const r=this;return i;function i(a){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),ze(e,s,"linePrefix")}function s(a){if(a===null||ye(a))return n(a);const o=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&o&&o[1].type==="linePrefix"&&o[2].sliceSerialize(o[1],!0).length>=4?t(a):e.interrupt(r.parser.constructs.flow,n,t)(a)}}function Ep(e,t,n,r,i,s,a,o,l){const c=l||Number.POSITIVE_INFINITY;let f=0;return d;function d(b){return b===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(b),e.exit(s),h):b===null||b===32||b===41||ss(b)?n(b):(e.enter(r),e.enter(a),e.enter(o),e.enter("chunkString",{contentType:"string"}),w(b))}function h(b){return b===62?(e.enter(s),e.consume(b),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(o),e.enter("chunkString",{contentType:"string"}),p(b))}function p(b){return b===62?(e.exit("chunkString"),e.exit(o),h(b)):b===null||b===60||ye(b)?n(b):(e.consume(b),b===92?g:p)}function g(b){return b===60||b===62||b===92?(e.consume(b),p):p(b)}function w(b){return!f&&(b===null||b===41||Fe(b))?(e.exit("chunkString"),e.exit(o),e.exit(a),e.exit(r),t(b)):f<c&&b===40?(e.consume(b),f++,w):b===41?(e.consume(b),f--,w):b===null||b===32||b===40||ss(b)?n(b):(e.consume(b),b===92?_:w)}function _(b){return b===40||b===41||b===92?(e.consume(b),w):w(b)}}function Cp(e,t,n,r,i,s){const a=this;let o=0,l;return c;function c(p){return e.enter(r),e.enter(i),e.consume(p),e.exit(i),e.enter(s),f}function f(p){return o>999||p===null||p===91||p===93&&!l||p===94&&!o&&"_hiddenFootnoteSupport"in a.parser.constructs?n(p):p===93?(e.exit(s),e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):ye(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),f):(e.enter("chunkString",{contentType:"string"}),d(p))}function d(p){return p===null||p===91||p===93||ye(p)||o++>999?(e.exit("chunkString"),f(p)):(e.consume(p),l||(l=!Ce(p)),p===92?h:d)}function h(p){return p===91||p===92||p===93?(e.consume(p),o++,d):d(p)}}function Tp(e,t,n,r,i,s){let a;return o;function o(h){return h===34||h===39||h===40?(e.enter(r),e.enter(i),e.consume(h),e.exit(i),a=h===40?41:h,l):n(h)}function l(h){return h===a?(e.enter(i),e.consume(h),e.exit(i),e.exit(r),t):(e.enter(s),c(h))}function c(h){return h===a?(e.exit(s),l(a)):h===null?n(h):ye(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),ze(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),f(h))}function f(h){return h===a||h===null||ye(h)?(e.exit("chunkString"),c(h)):(e.consume(h),h===92?d:f)}function d(h){return h===a||h===92?(e.consume(h),f):f(h)}}function Xr(e,t){let n;return r;function r(i){return ye(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):Ce(i)?ze(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const o0={name:"definition",tokenize:u0},l0={partial:!0,tokenize:c0};function u0(e,t,n){const r=this;let i;return s;function s(p){return e.enter("definition"),a(p)}function a(p){return Cp.call(r,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function o(p){return i=Zt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),l):n(p)}function l(p){return Fe(p)?Xr(e,c)(p):c(p)}function c(p){return Ep(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function f(p){return e.attempt(l0,d,d)(p)}function d(p){return Ce(p)?ze(e,h,"whitespace")(p):h(p)}function h(p){return p===null||ye(p)?(e.exit("definition"),r.parser.defined.push(i),t(p)):n(p)}}function c0(e,t,n){return r;function r(o){return Fe(o)?Xr(e,i)(o):n(o)}function i(o){return Tp(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(o)}function s(o){return Ce(o)?ze(e,a,"whitespace")(o):a(o)}function a(o){return o===null||ye(o)?t(o):n(o)}}const d0={name:"hardBreakEscape",tokenize:f0};function f0(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return ye(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const p0={name:"headingAtx",resolve:h0,tokenize:m0};function h0(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"},Tt(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function m0(e,t,n){let r=0;return i;function i(f){return e.enter("atxHeading"),s(f)}function s(f){return e.enter("atxHeadingSequence"),a(f)}function a(f){return f===35&&r++<6?(e.consume(f),a):f===null||Fe(f)?(e.exit("atxHeadingSequence"),o(f)):n(f)}function o(f){return f===35?(e.enter("atxHeadingSequence"),l(f)):f===null||ye(f)?(e.exit("atxHeading"),t(f)):Ce(f)?ze(e,o,"whitespace")(f):(e.enter("atxHeadingText"),c(f))}function l(f){return f===35?(e.consume(f),l):(e.exit("atxHeadingSequence"),o(f))}function c(f){return f===null||f===35||Fe(f)?(e.exit("atxHeadingText"),o(f)):(e.consume(f),c)}}const g0=["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"],gu=["pre","script","style","textarea"],x0={concrete:!0,name:"htmlFlow",resolveTo:v0,tokenize:w0},y0={partial:!0,tokenize:S0},b0={partial:!0,tokenize:k0};function v0(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 w0(e,t,n){const r=this;let i,s,a,o,l;return c;function c(y){return f(y)}function f(y){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(y),d}function d(y){return y===33?(e.consume(y),h):y===47?(e.consume(y),s=!0,w):y===63?(e.consume(y),i=3,r.interrupt?t:S):pt(y)?(e.consume(y),a=String.fromCharCode(y),_):n(y)}function h(y){return y===45?(e.consume(y),i=2,p):y===91?(e.consume(y),i=5,o=0,g):pt(y)?(e.consume(y),i=4,r.interrupt?t:S):n(y)}function p(y){return y===45?(e.consume(y),r.interrupt?t:S):n(y)}function g(y){const q="CDATA[";return y===q.charCodeAt(o++)?(e.consume(y),o===q.length?r.interrupt?t:T:g):n(y)}function w(y){return pt(y)?(e.consume(y),a=String.fromCharCode(y),_):n(y)}function _(y){if(y===null||y===47||y===62||Fe(y)){const q=y===47,X=a.toLowerCase();return!q&&!s&&gu.includes(X)?(i=1,r.interrupt?t(y):T(y)):g0.includes(a.toLowerCase())?(i=6,q?(e.consume(y),b):r.interrupt?t(y):T(y)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(y):s?N(y):m(y))}return y===45||ot(y)?(e.consume(y),a+=String.fromCharCode(y),_):n(y)}function b(y){return y===62?(e.consume(y),r.interrupt?t:T):n(y)}function N(y){return Ce(y)?(e.consume(y),N):j(y)}function m(y){return y===47?(e.consume(y),j):y===58||y===95||pt(y)?(e.consume(y),O):Ce(y)?(e.consume(y),m):j(y)}function O(y){return y===45||y===46||y===58||y===95||ot(y)?(e.consume(y),O):C(y)}function C(y){return y===61?(e.consume(y),v):Ce(y)?(e.consume(y),C):m(y)}function v(y){return y===null||y===60||y===61||y===62||y===96?n(y):y===34||y===39?(e.consume(y),l=y,k):Ce(y)?(e.consume(y),v):$(y)}function k(y){return y===l?(e.consume(y),l=null,H):y===null||ye(y)?n(y):(e.consume(y),k)}function $(y){return y===null||y===34||y===39||y===47||y===60||y===61||y===62||y===96||Fe(y)?C(y):(e.consume(y),$)}function H(y){return y===47||y===62||Ce(y)?m(y):n(y)}function j(y){return y===62?(e.consume(y),I):n(y)}function I(y){return y===null||ye(y)?T(y):Ce(y)?(e.consume(y),I):n(y)}function T(y){return y===45&&i===2?(e.consume(y),V):y===60&&i===1?(e.consume(y),U):y===62&&i===4?(e.consume(y),oe):y===63&&i===3?(e.consume(y),S):y===93&&i===5?(e.consume(y),ne):ye(y)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(y0,B,P)(y)):y===null||ye(y)?(e.exit("htmlFlowData"),P(y)):(e.consume(y),T)}function P(y){return e.check(b0,A,B)(y)}function A(y){return e.enter("lineEnding"),e.consume(y),e.exit("lineEnding"),M}function M(y){return y===null||ye(y)?P(y):(e.enter("htmlFlowData"),T(y))}function V(y){return y===45?(e.consume(y),S):T(y)}function U(y){return y===47?(e.consume(y),a="",J):T(y)}function J(y){if(y===62){const q=a.toLowerCase();return gu.includes(q)?(e.consume(y),oe):T(y)}return pt(y)&&a.length<8?(e.consume(y),a+=String.fromCharCode(y),J):T(y)}function ne(y){return y===93?(e.consume(y),S):T(y)}function S(y){return y===62?(e.consume(y),oe):y===45&&i===2?(e.consume(y),S):T(y)}function oe(y){return y===null||ye(y)?(e.exit("htmlFlowData"),B(y)):(e.consume(y),oe)}function B(y){return e.exit("htmlFlow"),t(y)}}function k0(e,t,n){const r=this;return i;function i(a){return ye(a)?(e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),s):n(a)}function s(a){return r.parser.lazy[r.now().line]?n(a):t(a)}}function S0(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(vi,t,n)}}const _0={name:"htmlText",tokenize:j0};function j0(e,t,n){const r=this;let i,s,a;return o;function o(S){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(S),l}function l(S){return S===33?(e.consume(S),c):S===47?(e.consume(S),C):S===63?(e.consume(S),m):pt(S)?(e.consume(S),$):n(S)}function c(S){return S===45?(e.consume(S),f):S===91?(e.consume(S),s=0,g):pt(S)?(e.consume(S),N):n(S)}function f(S){return S===45?(e.consume(S),p):n(S)}function d(S){return S===null?n(S):S===45?(e.consume(S),h):ye(S)?(a=d,U(S)):(e.consume(S),d)}function h(S){return S===45?(e.consume(S),p):d(S)}function p(S){return S===62?V(S):S===45?h(S):d(S)}function g(S){const oe="CDATA[";return S===oe.charCodeAt(s++)?(e.consume(S),s===oe.length?w:g):n(S)}function w(S){return S===null?n(S):S===93?(e.consume(S),_):ye(S)?(a=w,U(S)):(e.consume(S),w)}function _(S){return S===93?(e.consume(S),b):w(S)}function b(S){return S===62?V(S):S===93?(e.consume(S),b):w(S)}function N(S){return S===null||S===62?V(S):ye(S)?(a=N,U(S)):(e.consume(S),N)}function m(S){return S===null?n(S):S===63?(e.consume(S),O):ye(S)?(a=m,U(S)):(e.consume(S),m)}function O(S){return S===62?V(S):m(S)}function C(S){return pt(S)?(e.consume(S),v):n(S)}function v(S){return S===45||ot(S)?(e.consume(S),v):k(S)}function k(S){return ye(S)?(a=k,U(S)):Ce(S)?(e.consume(S),k):V(S)}function $(S){return S===45||ot(S)?(e.consume(S),$):S===47||S===62||Fe(S)?H(S):n(S)}function H(S){return S===47?(e.consume(S),V):S===58||S===95||pt(S)?(e.consume(S),j):ye(S)?(a=H,U(S)):Ce(S)?(e.consume(S),H):V(S)}function j(S){return S===45||S===46||S===58||S===95||ot(S)?(e.consume(S),j):I(S)}function I(S){return S===61?(e.consume(S),T):ye(S)?(a=I,U(S)):Ce(S)?(e.consume(S),I):H(S)}function T(S){return S===null||S===60||S===61||S===62||S===96?n(S):S===34||S===39?(e.consume(S),i=S,P):ye(S)?(a=T,U(S)):Ce(S)?(e.consume(S),T):(e.consume(S),A)}function P(S){return S===i?(e.consume(S),i=void 0,M):S===null?n(S):ye(S)?(a=P,U(S)):(e.consume(S),P)}function A(S){return S===null||S===34||S===39||S===60||S===61||S===96?n(S):S===47||S===62||Fe(S)?H(S):(e.consume(S),A)}function M(S){return S===47||S===62||Fe(S)?H(S):n(S)}function V(S){return S===62?(e.consume(S),e.exit("htmlTextData"),e.exit("htmlText"),t):n(S)}function U(S){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),J}function J(S){return Ce(S)?ze(e,ne,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(S):ne(S)}function ne(S){return e.enter("htmlTextData"),a(S)}}const $o={name:"labelEnd",resolveAll:T0,resolveTo:I0,tokenize:A0},N0={tokenize:z0},E0={tokenize:O0},C0={tokenize:P0};function T0(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&&Tt(e,0,e.length,n),e}function I0(e,t){let n=e.length,r=0,i,s,a,o;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(a){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"&&(a=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},c={type:"label",start:{...e[s][1].start},end:{...e[a][1].end}},f={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[a-2][1].start}};return o=[["enter",l,t],["enter",c,t]],o=Ot(o,e.slice(s+1,s+r+3)),o=Ot(o,[["enter",f,t]]),o=Ot(o,Ps(t.parser.constructs.insideSpan.null,e.slice(s+r+4,a-3),t)),o=Ot(o,[["exit",f,t],e[a-2],e[a-1],["exit",c,t]]),o=Ot(o,e.slice(a+1)),o=Ot(o,[["exit",l,t]]),Tt(e,s,e.length,o),e}function A0(e,t,n){const r=this;let i=r.events.length,s,a;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 o;function o(h){return s?s._inactive?d(h):(a=r.parser.defined.includes(Zt(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(h),e.exit("labelMarker"),e.exit("labelEnd"),l):n(h)}function l(h){return h===40?e.attempt(N0,f,a?f:d)(h):h===91?e.attempt(E0,f,a?c:d)(h):a?f(h):d(h)}function c(h){return e.attempt(C0,f,d)(h)}function f(h){return t(h)}function d(h){return s._balanced=!0,n(h)}}function z0(e,t,n){return r;function r(d){return e.enter("resource"),e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),i}function i(d){return Fe(d)?Xr(e,s)(d):s(d)}function s(d){return d===41?f(d):Ep(e,a,o,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(d)}function a(d){return Fe(d)?Xr(e,l)(d):f(d)}function o(d){return n(d)}function l(d){return d===34||d===39||d===40?Tp(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(d):f(d)}function c(d){return Fe(d)?Xr(e,f)(d):f(d)}function f(d){return d===41?(e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),e.exit("resource"),t):n(d)}}function O0(e,t,n){const r=this;return i;function i(o){return Cp.call(r,e,s,a,"reference","referenceMarker","referenceString")(o)}function s(o){return r.parser.defined.includes(Zt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(o):n(o)}function a(o){return n(o)}}function P0(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 D0={name:"labelStartImage",resolveAll:$o.resolveAll,tokenize:R0};function R0(e,t,n){const r=this;return i;function i(o){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(o),e.exit("labelImageMarker"),s}function s(o){return o===91?(e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelImage"),a):n(o)}function a(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const M0={name:"labelStartLink",resolveAll:$o.resolveAll,tokenize:$0};function $0(e,t,n){const r=this;return i;function i(a){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelLink"),s}function s(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const sa={name:"lineEnding",tokenize:F0};function F0(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),ze(e,t,"linePrefix")}}const Zi={name:"thematicBreak",tokenize:L0};function L0(e,t,n){let r=0,i;return s;function s(c){return e.enter("thematicBreak"),a(c)}function a(c){return i=c,o(c)}function o(c){return c===i?(e.enter("thematicBreakSequence"),l(c)):r>=3&&(c===null||ye(c))?(e.exit("thematicBreak"),t(c)):n(c)}function l(c){return c===i?(e.consume(c),r++,l):(e.exit("thematicBreakSequence"),Ce(c)?ze(e,o,"whitespace")(c):o(c))}}const xt={continuation:{tokenize:U0},exit:H0,name:"list",tokenize:V0},B0={partial:!0,tokenize:W0},Z0={partial:!0,tokenize:J0};function V0(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,a=0;return o;function o(p){const g=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:Ja(p)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),p===42||p===45?e.check(Zi,n,c)(p):c(p);if(!r.interrupt||p===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(p)}return n(p)}function l(p){return Ja(p)&&++a<10?(e.consume(p),l):(!r.interrupt||a<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(e.exit("listItemValue"),c(p)):n(p)}function c(p){return e.enter("listItemMarker"),e.consume(p),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,e.check(vi,r.interrupt?n:f,e.attempt(B0,h,d))}function f(p){return r.containerState.initialBlankLine=!0,s++,h(p)}function d(p){return Ce(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 U0(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(vi,i,s);function i(o){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,ze(e,t,"listItemIndent",r.containerState.size+1)(o)}function s(o){return r.containerState.furtherBlankLines||!Ce(o)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,a(o)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(Z0,t,a)(o))}function a(o){return r.containerState._closeFlow=!0,r.interrupt=void 0,ze(e,e.attempt(xt,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o)}}function J0(e,t,n){const r=this;return ze(e,i,"listItemIndent",r.containerState.size+1);function i(s){const a=r.events[r.events.length-1];return a&&a[1].type==="listItemIndent"&&a[2].sliceSerialize(a[1],!0).length===r.containerState.size?t(s):n(s)}}function H0(e){e.exit(this.containerState.type)}function W0(e,t,n){const r=this;return ze(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const a=r.events[r.events.length-1];return!Ce(s)&&a&&a[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const xu={name:"setextUnderline",resolveTo:q0,tokenize:G0};function q0(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 a={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",a,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=a,e.push(["exit",a,t]),e}function G0(e,t,n){const r=this;let i;return s;function s(c){let f=r.events.length,d;for(;f--;)if(r.events[f][1].type!=="lineEnding"&&r.events[f][1].type!=="linePrefix"&&r.events[f][1].type!=="content"){d=r.events[f][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||d)?(e.enter("setextHeadingLine"),i=c,a(c)):n(c)}function a(c){return e.enter("setextHeadingLineSequence"),o(c)}function o(c){return c===i?(e.consume(c),o):(e.exit("setextHeadingLineSequence"),Ce(c)?ze(e,l,"lineSuffix")(c):l(c))}function l(c){return c===null||ye(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const Y0={tokenize:K0};function K0(e){const t=this,n=e.attempt(vi,r,e.attempt(this.parser.constructs.flowInitial,i,ze(e,e.attempt(this.parser.constructs.flow,i,e.attempt(n0,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 X0={resolveAll:Ap()},Q0=Ip("string"),ek=Ip("text");function Ip(e){return{resolveAll:Ap(e==="text"?tk:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,a,o);return a;function a(f){return c(f)?s(f):o(f)}function o(f){if(f===null){n.consume(f);return}return n.enter("data"),n.consume(f),l}function l(f){return c(f)?(n.exit("data"),s(f)):(n.consume(f),l)}function c(f){if(f===null)return!0;const d=i[f];let h=-1;if(d)for(;++h<d.length;){const p=d[h];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function Ap(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 tk(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,a=-1,o=0,l;for(;s--;){const c=i[s];if(typeof c=="string"){for(a=c.length;c.charCodeAt(a-1)===32;)o++,a--;if(a)break;a=-1}else if(c===-2)l=!0,o++;else if(c!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(o=0),o){const c={type:n===e.length||l||o<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?a:r.start._bufferIndex+a,_index:r.start._index+s,line:r.end.line,column:r.end.column-o,offset:r.end.offset-o},end:{...r.end}};r.end={...c.start},r.start.offset===r.end.offset?Object.assign(r,c):(e.splice(n,0,["enter",c,t],["exit",c,t]),n+=2)}n++}return e}const nk={42:xt,43:xt,45:xt,48:xt,49:xt,50:xt,51:xt,52:xt,53:xt,54:xt,55:xt,56:xt,57:xt,62:Sp},rk={91:o0},ik={[-2]:ia,[-1]:ia,32:ia},sk={35:p0,42:Zi,45:[xu,Zi],60:x0,61:xu,95:Zi,96:mu,126:mu},ak={38:jp,92:_p},ok={[-5]:sa,[-4]:sa,[-3]:sa,33:D0,38:jp,42:Ha,60:[Mw,_0],91:M0,92:[d0,_p],93:$o,95:Ha,96:Yw},lk={null:[Ha,X0]},uk={null:[42,95]},ck={null:[]},dk=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:uk,contentInitial:rk,disable:ck,document:nk,flow:sk,flowInitial:ik,insideSpan:lk,string:ak,text:ok},Symbol.toStringTag,{value:"Module"}));function fk(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 a=[],o=[];const l={attempt:k(C),check:k(v),consume:N,enter:m,exit:O,interrupt:k(v,{interrupt:!0})},c={code:null,containerState:{},defineSkip:w,events:[],now:g,parser:e,previous:null,sliceSerialize:h,sliceStream:p,write:d};let f=t.tokenize.call(c,l);return t.resolveAll&&s.push(t),c;function d(I){return a=Ot(a,I),_(),a[a.length-1]!==null?[]:($(t,0),c.events=Ps(s,c.events,c),c.events)}function h(I,T){return hk(p(I),T)}function p(I){return pk(a,I)}function g(){const{_bufferIndex:I,_index:T,line:P,column:A,offset:M}=r;return{_bufferIndex:I,_index:T,line:P,column:A,offset:M}}function w(I){i[I.line]=I.column,j()}function _(){let I;for(;r._index<a.length;){const T=a[r._index];if(typeof T=="string")for(I=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===I&&r._bufferIndex<T.length;)b(T.charCodeAt(r._bufferIndex));else b(T)}}function b(I){f=f(I)}function N(I){ye(I)?(r.line++,r.column=1,r.offset+=I===-3?2:1,j()):I!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===a[r._index].length&&(r._bufferIndex=-1,r._index++)),c.previous=I}function m(I,T){const P=T||{};return P.type=I,P.start=g(),c.events.push(["enter",P,c]),o.push(P),P}function O(I){const T=o.pop();return T.end=g(),c.events.push(["exit",T,c]),T}function C(I,T){$(I,T.from)}function v(I,T){T.restore()}function k(I,T){return P;function P(A,M,V){let U,J,ne,S;return Array.isArray(A)?B(A):"tokenize"in A?B([A]):oe(A);function oe(Y){return ie;function ie(D){const ue=D!==null&&Y[D],he=D!==null&&Y.null,ce=[...Array.isArray(ue)?ue:ue?[ue]:[],...Array.isArray(he)?he:he?[he]:[]];return B(ce)(D)}}function B(Y){return U=Y,J=0,Y.length===0?V:y(Y[J])}function y(Y){return ie;function ie(D){return S=H(),ne=Y,Y.partial||(c.currentConstruct=Y),Y.name&&c.parser.constructs.disable.null.includes(Y.name)?X():Y.tokenize.call(T?Object.assign(Object.create(c),T):c,l,q,X)(D)}}function q(Y){return I(ne,S),M}function X(Y){return S.restore(),++J<U.length?y(U[J]):V}}}function $(I,T){I.resolveAll&&!s.includes(I)&&s.push(I),I.resolve&&Tt(c.events,T,c.events.length-T,I.resolve(c.events.slice(T),c)),I.resolveTo&&(c.events=I.resolveTo(c.events,c))}function H(){const I=g(),T=c.previous,P=c.currentConstruct,A=c.events.length,M=Array.from(o);return{from:A,restore:V};function V(){r=I,c.previous=T,c.currentConstruct=P,c.events.length=A,o=M,j()}}function j(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function pk(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let a;if(n===i)a=[e[n].slice(r,s)];else{if(a=e.slice(n,i),r>-1){const o=a[0];typeof o=="string"?a[0]=o.slice(r):a.shift()}s>0&&a.push(e[i].slice(0,s))}return a}function hk(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let a;if(typeof s=="string")a=s;else switch(s){case-5:{a="\r";break}case-4:{a=`
11
11
  `;break}case-3:{a=`\r
12
12
  `;break}case-2:{a=t?" ":" ";break}case-1:{if(!t&&i)continue;a=" ";break}default:a=String.fromCharCode(s)}i=s===-2,r.push(a)}return r.join("")}function mk(e){const r={constructs:wp([dk,...(e||{}).extensions||[]]),content:i(Iw),defined:[],document:i(zw),flow:i(Y0),lazy:{},string:i(Q0),text:i(ek)};return r;function i(s){return a;function a(o){return fk(r,s,o)}}}function gk(e){for(;!Np(e););return e}const yu=/[\0\t\n\r]/g;function xk(){let e=1,t="",n=!0,r;return i;function i(s,a,o){const l=[];let c,f,d,h,p;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(a||void 0).decode(s)),d=0,t="",n&&(s.charCodeAt(0)===65279&&d++,n=void 0);d<s.length;){if(yu.lastIndex=d,c=yu.exec(s),h=c&&c.index!==void 0?c.index:s.length,p=s.charCodeAt(h),!c){t=s.slice(d);break}if(p===10&&d===h&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),d<h&&(l.push(s.slice(d,h)),e+=h-d),p){case 0:{l.push(65533),e++;break}case 9:{for(f=Math.ceil(e/4)*4,l.push(-2);e++<f;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}d=h+1}return o&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const yk=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function bk(e){return e.replace(yk,vk)}function vk(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return kp(n.slice(s?2:1),s?16:10)}return Mo(n)||e}const zp={}.hasOwnProperty;function wk(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),kk(n)(gk(mk(n).document().write(xk()(e,t,!0))))}function kk(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(R),autolinkProtocol:H,autolinkEmail:H,atxHeading:s(Re),blockQuote:s(he),characterEscape:H,characterReference:H,codeFenced:s(ce),codeFencedFenceInfo:a,codeFencedFenceMeta:a,codeIndented:s(ce,a),codeText:s(ee,a),codeTextData:H,data:H,codeFlowValue:H,definition:s(de),definitionDestinationString:a,definitionLabelString:a,definitionTitleString:a,emphasis:s(fe),hardBreakEscape:s(Oe),hardBreakTrailing:s(Oe),htmlFlow:s(We,a),htmlFlowData:H,htmlText:s(We,a),htmlTextData:H,image:s(E),label:a,link:s(R),listItem:s(se),listItemValue:h,listOrdered:s(Z,d),listUnordered:s(Z),paragraph:s(z),reference:y,referenceString:a,resourceDestinationString:a,resourceTitleString:a,setextHeading:s(Re),strong:s(K),thematicBreak:s(xe)},exit:{atxHeading:l(),atxHeadingSequence:C,autolink:l(),autolinkEmail:ue,autolinkProtocol:D,blockQuote:l(),characterEscapeValue:j,characterReferenceMarkerHexadecimal:X,characterReferenceMarkerNumeric:X,characterReferenceValue:Y,characterReference:ie,codeFenced:l(_),codeFencedFence:w,codeFencedFenceInfo:p,codeFencedFenceMeta:g,codeFlowValue:j,codeIndented:l(b),codeText:l(M),codeTextData:j,data:j,definition:l(),definitionDestinationString:O,definitionLabelString:N,definitionTitleString:m,emphasis:l(),hardBreakEscape:l(T),hardBreakTrailing:l(T),htmlFlow:l(P),htmlFlowData:j,htmlText:l(A),htmlTextData:j,image:l(U),label:ne,labelText:J,lineEnding:I,link:l(V),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:q,resourceDestinationString:S,resourceTitleString:oe,resource:B,setextHeading:l($),setextHeadingLineSequence:k,setextHeadingText:v,strong:l(),thematicBreak:l()}};Op(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(L){let Q={type:"root",children:[]};const me={stack:[Q],tokenStack:[],config:t,enter:o,exit:c,buffer:a,resume:f,data:n},ve=[];let F=-1;for(;++F<L.length;)if(L[F][1].type==="listOrdered"||L[F][1].type==="listUnordered")if(L[F][0]==="enter")ve.push(F);else{const ge=ve.pop();F=i(L,ge,F)}for(F=-1;++F<L.length;){const ge=t[L[F][0]];zp.call(ge,L[F][1].type)&&ge[L[F][1].type].call(Object.assign({sliceSerialize:L[F][2].sliceSerialize},me),L[F][1])}if(me.tokenStack.length>0){const ge=me.tokenStack[me.tokenStack.length-1];(ge[1]||bu).call(me,void 0,ge[0])}for(Q.position={start:dn(L.length>0?L[0][1].start:{line:1,column:1,offset:0}),end:dn(L.length>0?L[L.length-2][1].end:{line:1,column:1,offset:0})},F=-1;++F<t.transforms.length;)Q=t.transforms[F](Q)||Q;return Q}function i(L,Q,me){let ve=Q-1,F=-1,ge=!1,Te,Le,rt,tt;for(;++ve<=me;){const at=L[ve];switch(at[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{at[0]==="enter"?F++:F--,tt=void 0;break}case"lineEndingBlank":{at[0]==="enter"&&(Te&&!tt&&!F&&!rt&&(rt=ve),tt=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:tt=void 0}if(!F&&at[0]==="enter"&&at[1].type==="listItemPrefix"||F===-1&&at[0]==="exit"&&(at[1].type==="listUnordered"||at[1].type==="listOrdered")){if(Te){let un=ve;for(Le=void 0;un--;){const en=L[un];if(en[1].type==="lineEnding"||en[1].type==="lineEndingBlank"){if(en[0]==="exit")continue;Le&&(L[Le][1].type="lineEndingBlank",ge=!0),en[1].type="lineEnding",Le=un}else if(!(en[1].type==="linePrefix"||en[1].type==="blockQuotePrefix"||en[1].type==="blockQuotePrefixWhitespace"||en[1].type==="blockQuoteMarker"||en[1].type==="listItemIndent"))break}rt&&(!Le||rt<Le)&&(Te._spread=!0),Te.end=Object.assign({},Le?L[Le][1].start:at[1].end),L.splice(Le||ve,0,["exit",Te,at[2]]),ve++,me++}if(at[1].type==="listItemPrefix"){const un={type:"listItem",_spread:!1,start:Object.assign({},at[1].start),end:void 0};Te=un,L.splice(ve,0,["enter",un,at[2]]),ve++,me++,rt=void 0,tt=!0}}}return L[Q][1]._spread=ge,me}function s(L,Q){return me;function me(ve){o.call(this,L(ve),ve),Q&&Q.call(this,ve)}}function a(){this.stack.push({type:"fragment",children:[]})}function o(L,Q,me){this.stack[this.stack.length-1].children.push(L),this.stack.push(L),this.tokenStack.push([Q,me||void 0]),L.position={start:dn(Q.start),end:void 0}}function l(L){return Q;function Q(me){L&&L.call(this,me),c.call(this,me)}}function c(L,Q){const me=this.stack.pop(),ve=this.tokenStack.pop();if(ve)ve[0].type!==L.type&&(Q?Q.call(this,L,ve[0]):(ve[1]||bu).call(this,L,ve[0]));else throw new Error("Cannot close `"+L.type+"` ("+Kr({start:L.start,end:L.end})+"): it’s not open");me.position.end=dn(L.end)}function f(){return Ro(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function h(L){if(this.data.expectingFirstListItemValue){const Q=this.stack[this.stack.length-2];Q.start=Number.parseInt(this.sliceSerialize(L),10),this.data.expectingFirstListItemValue=void 0}}function p(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.lang=L}function g(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.meta=L}function w(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function _(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.value=L.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function b(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.value=L.replace(/(\r?\n|\r)$/g,"")}function N(L){const Q=this.resume(),me=this.stack[this.stack.length-1];me.label=Q,me.identifier=Zt(this.sliceSerialize(L)).toLowerCase()}function m(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.title=L}function O(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.url=L}function C(L){const Q=this.stack[this.stack.length-1];if(!Q.depth){const me=this.sliceSerialize(L).length;Q.depth=me}}function v(){this.data.setextHeadingSlurpLineEnding=!0}function k(L){const Q=this.stack[this.stack.length-1];Q.depth=this.sliceSerialize(L).codePointAt(0)===61?1:2}function $(){this.data.setextHeadingSlurpLineEnding=void 0}function H(L){const me=this.stack[this.stack.length-1].children;let ve=me[me.length-1];(!ve||ve.type!=="text")&&(ve=te(),ve.position={start:dn(L.start),end:void 0},me.push(ve)),this.stack.push(ve)}function j(L){const Q=this.stack.pop();Q.value+=this.sliceSerialize(L),Q.position.end=dn(L.end)}function I(L){const Q=this.stack[this.stack.length-1];if(this.data.atHardBreak){const me=Q.children[Q.children.length-1];me.position.end=dn(L.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(Q.type)&&(H.call(this,L),j.call(this,L))}function T(){this.data.atHardBreak=!0}function P(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.value=L}function A(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.value=L}function M(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.value=L}function V(){const L=this.stack[this.stack.length-1];if(this.data.inReference){const Q=this.data.referenceType||"shortcut";L.type+="Reference",L.referenceType=Q,delete L.url,delete L.title}else delete L.identifier,delete L.label;this.data.referenceType=void 0}function U(){const L=this.stack[this.stack.length-1];if(this.data.inReference){const Q=this.data.referenceType||"shortcut";L.type+="Reference",L.referenceType=Q,delete L.url,delete L.title}else delete L.identifier,delete L.label;this.data.referenceType=void 0}function J(L){const Q=this.sliceSerialize(L),me=this.stack[this.stack.length-2];me.label=bk(Q),me.identifier=Zt(Q).toLowerCase()}function ne(){const L=this.stack[this.stack.length-1],Q=this.resume(),me=this.stack[this.stack.length-1];if(this.data.inReference=!0,me.type==="link"){const ve=L.children;me.children=ve}else me.alt=Q}function S(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.url=L}function oe(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.title=L}function B(){this.data.inReference=void 0}function y(){this.data.referenceType="collapsed"}function q(L){const Q=this.resume(),me=this.stack[this.stack.length-1];me.label=Q,me.identifier=Zt(this.sliceSerialize(L)).toLowerCase(),this.data.referenceType="full"}function X(L){this.data.characterReferenceType=L.type}function Y(L){const Q=this.sliceSerialize(L),me=this.data.characterReferenceType;let ve;me?(ve=kp(Q,me==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):ve=Mo(Q);const F=this.stack[this.stack.length-1];F.value+=ve}function ie(L){const Q=this.stack.pop();Q.position.end=dn(L.end)}function D(L){j.call(this,L);const Q=this.stack[this.stack.length-1];Q.url=this.sliceSerialize(L)}function ue(L){j.call(this,L);const Q=this.stack[this.stack.length-1];Q.url="mailto:"+this.sliceSerialize(L)}function he(){return{type:"blockquote",children:[]}}function ce(){return{type:"code",lang:null,meta:null,value:""}}function ee(){return{type:"inlineCode",value:""}}function de(){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 We(){return{type:"html",value:""}}function E(){return{type:"image",title:null,url:"",alt:null}}function R(){return{type:"link",title:null,url:"",children:[]}}function Z(L){return{type:"list",ordered:L.type==="listOrdered",start:null,spread:L._spread,children:[]}}function se(L){return{type:"listItem",spread:L._spread,checked:null,children:[]}}function z(){return{type:"paragraph",children:[]}}function K(){return{type:"strong",children:[]}}function te(){return{type:"text",value:""}}function xe(){return{type:"thematicBreak"}}}function dn(e){return{line:e.line,column:e.column,offset:e.offset}}function Op(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Op(e,r):Sk(e,r)}}function Sk(e,t){let n;for(n in t)if(zp.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 bu(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Kr({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Kr({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Kr({start:t.start,end:t.end})+") is still open")}function _k(e){const t=this;t.parser=n;function n(r){return wk(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function jk(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 Nk(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
@@ -103,4 +103,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
103
103
  `;)t++;return!0}return!1}function c(J){if(f(J)){if(Ac(e[t]))for(;t<e.length&&zc(e[t]);)t++;return a(),!0}return!1}function f(J){o(!0);for(const ne of J){const S=t+ne.length;if(e.slice(t,S)===ne)return t=S,!0}return!1}function d(J){return e[t]===J?(n+=e[t],t++,!0):!1}function h(J){return e[t]===J?(t++,!0):!1}function p(){return h("\\")}function g(){return a(),e[t]==="."&&e[t+1]==="."&&e[t+2]==="."?(t+=3,a(),h(","),!0):!1}function w(){if(e[t]==="{"){n+="{",t++,a(),h(",")&&a();let J=!0;for(;t<e.length&&e[t]!=="}";){let ne;if(J?(ne=!0,J=!1):(ne=d(","),ne||(n=Mt(n,",")),a()),g(),!(N()||k(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=$r(n,","):M();break}a();const oe=d(":"),B=t>=e.length;oe||(Rc(e[t])||B?n=Mt(n,":"):V()),s()||(oe||B?n+="null":V())}return e[t]==="}"?(n+="}",t++):n=Mt(n,"}"),!0}return!1}function _(){if(e[t]==="["){n+="[",t++,a(),h(",")&&a();let J=!0;for(;t<e.length&&e[t]!=="]";)if(J?J=!1:d(",")||(n=Mt(n,",")),g(),!s()){n=$r(n,",");break}return e[t]==="]"?(n+="]",t++):n=Mt(n,"]"),!0}return!1}function b(){let J=!0,ne=!0;for(;ne;)J?J=!1:d(",")||(n=Mt(n,",")),ne=s();ne||(n=$r(n,",")),n=`[
104
104
  ${n}
105
105
  ]`}function N(){let J=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1,ne=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1,S=e[t]==="\\";if(S&&(t++,S=!0),Ji(e[t])){const oe=Mc(e[t])?Mc:$c(e[t])?$c:lo(e[t])?lo:qm,B=t,y=n.length;let q='"';for(t++;;){if(t>=e.length){const X=H(t-1);return!J&&Ri(e.charAt(X))?(t=B,n=n.substring(0,y),N(!0)):(q=Mt(q,'"'),n+=q,!0)}if(t===ne)return q=Mt(q,'"'),n+=q,!0;if(oe(e[t])){const X=t,Y=q.length;if(q+='"',t++,n+=q,a(!1),J||t>=e.length||Ri(e[t])||Ji(e[t])||Cn(e[t]))return m(),!0;const ie=H(X-1),D=e.charAt(ie);if(D===",")return t=B,n=n.substring(0,y),N(!1,ie);if(Ri(D))return t=B,n=n.substring(0,y),N(!0);n=n.substring(0,y),t=X+1,q=`${q.substring(0,Y)}\\${q.substring(Y)}`}else if(J&&Dc(e[t])){if(e[t-1]===":"&&Oc.test(e.substring(B+1,t+2)))for(;t<e.length&&Pc.test(e[t]);)q+=e[t],t++;return q=Mt(q,'"'),n+=q,m(),!0}else if(e[t]==="\\"){const X=e.charAt(t+1);if(lz[X]!==void 0)q+=e.slice(t,t+2),t+=2;else if(X==="u"){let ie=2;for(;ie<6&&QA(e[t+ie]);)ie++;ie===6?(q+=e.slice(t,t+6),t+=6):t+ie>=e.length?t=e.length:U()}else q+=X,t+=2}else{const X=e.charAt(t);X==='"'&&e[t-1]!=="\\"?(q+=`\\${X}`,t++):nz(X)?(q+=oz[X],t++):(ez(X)||T(X),q+=X,t++)}S&&p()}}return!1}function m(){let J=!1;for(a();e[t]==="+";){J=!0,t++,a(),n=$r(n,'"',!0);const ne=n.length;N()?n=sz(n,ne,1):n=Mt(n,'"')}return J}function O(){const J=t;if(e[t]==="-"){if(t++,j())return I(J),!0;if(!Cn(e[t]))return t=J,!1}for(;Cn(e[t]);)t++;if(e[t]==="."){if(t++,j())return I(J),!0;if(!Cn(e[t]))return t=J,!1;for(;Cn(e[t]);)t++}if(e[t]==="e"||e[t]==="E"){if(t++,(e[t]==="-"||e[t]==="+")&&t++,j())return I(J),!0;if(!Cn(e[t]))return t=J,!1;for(;Cn(e[t]);)t++}if(!j())return t=J,!1;if(t>J){const ne=e.slice(J,t),S=/^0\d/.test(ne);return n+=S?`"${ne}"`:ne,!0}return!1}function C(){return v("true","true")||v("false","false")||v("null","null")||v("True","true")||v("False","false")||v("None","null")}function v(J,ne){return e.slice(t,t+J.length)===J?(n+=ne,t+=J.length,!0):!1}function k(J){const ne=t;if(Ac(e[t])){for(;t<e.length&&zc(e[t]);)t++;let S=t;for(;Tn(e,S);)S++;if(e[S]==="(")return t=S+1,s(),e[t]===")"&&(t++,e[t]===";"&&t++),!0}for(;t<e.length&&!Dc(e[t])&&!Ji(e[t])&&(!J||e[t]!==":");)t++;if(e[t-1]===":"&&Oc.test(e.substring(ne,t+2)))for(;t<e.length&&Pc.test(e[t]);)t++;if(t>ne){for(;Tn(e,t-1)&&t>0;)t--;const S=e.slice(ne,t);return n+=S==="undefined"?"null":JSON.stringify(S),e[t]==='"'&&t++,!0}}function $(){if(e[t]==="/"){const J=t;for(t++;t<e.length&&(e[t]!=="/"||e[t-1]==="\\");)t++;return t++,n+=JSON.stringify(e.substring(J,t)),!0}}function H(J){let ne=J;for(;ne>0&&Tn(e,ne);)ne--;return ne}function j(){return t>=e.length||Ri(e[t])||Tn(e,t)}function I(J){n+=`${e.slice(J,t)}0`}function T(J){throw new Yn(`Invalid character ${JSON.stringify(J)}`,t)}function P(){throw new Yn(`Unexpected character ${JSON.stringify(e[t])}`,t)}function A(){throw new Yn("Unexpected end of json string",e.length)}function M(){throw new Yn("Object key expected",t)}function V(){throw new Yn("Colon expected",t)}function U(){const J=e.slice(t,t+6);throw new Yn(`Invalid unicode character "${J}"`,t)}}function uz(e,t){return e[t]==="*"&&e[t+1]==="/"}function cz({json:e,context:t,scope:n}){const[r,i]=x.useState(!1),[s,a]=x.useState(null),o=x.useMemo(()=>{try{return JSON.parse(e),e}catch{}try{return Fc(e)}catch{}const b=`{${e}}`;try{return JSON.parse(b),b}catch{}try{return Fc(b)}catch{return null}},[e]),l=x.useMemo(()=>Bm(o||e),[o,e]),c=Ne(b=>b.activeTab),f=Ne(b=>b.documents),d=Ne(b=>(b.acceptedApplyIds||[]).includes(l)),h=Ne(b=>b.setPendingDiff),p=Ne(b=>b.createDocument),g=Ne(b=>b.openDocument),w=x.useCallback(()=>{if(o){a(null);try{if(c){const b=f.find(v=>v.name===c),N=(b==null?void 0:b.text)||"";if(n==="templates")try{const v=JSON.parse(N),k=JSON.parse(o);if(Array.isArray(k.templates)){v.props||(v.props={}),v.props.templates=Lm(v.props.templates||[],k.templates);const $=JSON.stringify(v,null,2);h(c,N,$,l);return}}catch{}const m=t==null?void 0:t[0],{original:O,modified:C}=Zm(N,o,m);h(c,O,C,l)}else{const b=`ai-generated-${Date.now()}`;p(b,o),g(b)}}catch(b){a(b instanceof Error?b.message:"Merge failed")}}},[o,c,f,h,p,g,t,n,l]),_=x.useCallback(async()=>{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)},[e]);return u.jsxs("div",{className:"flex flex-col gap-1 px-3 py-2 border-t",children:[u.jsxs("div",{className:"flex gap-1.5",children:[u.jsx(Se,{variant:"secondary",size:"sm",onClick:w,disabled:d||!o,children:d?"Applied":o?"Apply to Editor":"Invalid JSON"}),u.jsx(Se,{variant:"ghost",size:"sm",onClick:_,children:r?u.jsx(an,{className:"h-3.5 w-3.5"}):u.jsx(ks,{className:"h-3.5 w-3.5"})})]}),s&&u.jsx("p",{className:"text-xs text-destructive m-0",children:s})]})}function dz({threads:e,activeThread:t,disabled:n,onSwitch:r,onCreate:i,onDelete:s,onRename:a}){const[o,l]=x.useState(null),[c,f]=x.useState(""),[d,h]=x.useState(null),p=x.useRef(null),g=(t==null?void 0:t.title)||"New Chat",w=g.length>24?g.slice(0,24)+"...":g;x.useEffect(()=>{o&&requestAnimationFrame(()=>{var k;return(k=p.current)==null?void 0:k.focus()})},[o]);const _=x.useCallback((k,$)=>{$.stopPropagation(),$.preventDefault(),l(k.id),f(k.title),h(null)},[]),b=x.useCallback(()=>{o&&c.trim()&&a(o,c.trim()),l(null),f("")},[o,c,a]),N=x.useCallback(()=>{l(null),f("")},[]),m=x.useCallback(k=>{k.stopPropagation(),k.key==="Enter"?(k.preventDefault(),b()):k.key==="Escape"&&(k.preventDefault(),N())},[b,N]),O=x.useCallback((k,$)=>{$.stopPropagation(),$.preventDefault(),h(k),l(null)},[]),C=x.useCallback(k=>{k.stopPropagation(),k.preventDefault(),d&&(s(d),h(null))},[d,s]),v=x.useCallback(k=>{k.stopPropagation(),k.preventDefault(),h(null)},[]);return u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsxs(Ns,{onOpenChange:k=>{k||(l(null),h(null))},children:[u.jsx(Es,{asChild:!0,disabled:n,children:u.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:[u.jsx("div",{className:"h-2 w-2 rounded-full bg-primary/70 shrink-0"}),u.jsx("span",{className:"truncate",children:w}),u.jsx(mi,{className:"h-3 w-3 shrink-0 opacity-60"})]})}),u.jsxs(yi,{align:"start",className:"w-64",children:[e.map(k=>{const $=o===k.id;return d===k.id?u.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-sm",children:[u.jsx("span",{className:"text-destructive text-xs flex-1 truncate",children:"Delete this thread?"}),u.jsx("button",{className:"shrink-0 text-destructive hover:text-destructive/80 transition-colors cursor-pointer",onClick:C,children:u.jsx(an,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:v,children:u.jsx(yn,{className:"h-3.5 w-3.5"})})]},k.id):$?u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1",onClick:j=>j.stopPropagation(),onPointerDown:j=>j.stopPropagation(),children:[u.jsx("input",{ref:p,type:"text",value:c,onChange:j=>f(j.target.value),onKeyDown:m,onBlur:b,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"}),u.jsx("button",{className:"shrink-0 text-primary hover:text-primary/80 transition-colors cursor-pointer",onMouseDown:j=>{j.preventDefault(),b()},children:u.jsx(an,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onMouseDown:j=>{j.preventDefault(),N()},children:u.jsx(yn,{className:"h-3.5 w-3.5"})})]},k.id):u.jsxs($t,{onSelect:()=>r(k.id),className:`group ${k.id===(t==null?void 0:t.id)?"bg-accent":""}`,children:[u.jsx("span",{className:"truncate flex-1",children:k.title.length>30?k.title.slice(0,30)+"...":k.title}),u.jsxs("div",{className:"ml-auto shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[u.jsx("button",{className:"text-muted-foreground hover:text-foreground transition-colors p-0.5 cursor-pointer",onClick:j=>_(k,j),children:u.jsx(rx,{className:"h-3 w-3"})}),e.length>1&&u.jsx("button",{className:"text-muted-foreground hover:text-destructive transition-colors p-0.5 cursor-pointer",onClick:j=>O(k.id,j),children:u.jsx(fo,{className:"h-3 w-3"})})]})]},k.id)}),u.jsx(mr,{}),u.jsxs($t,{onSelect:k=>{k.preventDefault();const $=i();$&&(l($),f(vo()),h(null))},children:[u.jsx(nn,{className:"h-3.5 w-3.5 mr-1.5"}),"New Chat"]})]})]}),u.jsx(Se,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",onClick:()=>i(),disabled:n,title:"New chat thread",children:u.jsx(nn,{className:"h-3.5 w-3.5"})})]})}const Gm=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),fz=Array.from(Gm).join(","),pz=20*1024*1024,Lc=10;function hz(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 Bc(e){return Array.from(e).filter(t=>Gm.has(t.type)&&t.size<=pz)}function Ym(e){return e.startsWith("image/")}function Zc(){var Q,me,ve;const e=Pe(F=>F.contextAttachments),t=Pe(F=>F.addContext),n=Pe(F=>F.removeContext),r=Pe(F=>F.scope),i=Pe(F=>F.setScope),s=Pe(F=>F.model),a=Pe(F=>F.setModel),o=Pe(F=>F.openChat),l=Pe(F=>F.closeChat),c=Pe(F=>F.threads),f=Pe(F=>F.activeThreadId),d=Pe(F=>F.createThread),h=Pe(F=>F.deleteThread),p=Pe(F=>F.switchThread),g=Pe(F=>F.updateThreadMessages),w=Pe(F=>F.updateThreadTitle),_=Pe(F=>F.deleteThreadsForDocument),b=Ne(F=>F.activeTab),N=Ne(F=>F.documents),{messages:m,sendMessage:O,status:C,error:v,setMessages:k,stop:$,getMessageContext:H,getMessageScope:j}=BA(),[I,T]=x.useState(""),[P,A]=x.useState([]),[M,V]=x.useState(!1),[U,J]=x.useState(!1),ne=x.useRef(null),S=x.useRef(null),oe=x.useRef(null),B=x.useCallback(async F=>{const ge=Bc(F);if(ge.length===0)return;const Te=await Promise.all(ge.map(hz));A(Le=>{const rt=[...Le,...Te];return rt.length>Lc?rt.slice(0,Lc):rt})},[]),y=x.useCallback(F=>{A(ge=>ge.filter((Te,Le)=>Le!==F))},[]),q=x.useCallback(F=>{var Te;const ge=(Te=F.clipboardData)==null?void 0:Te.files;if(ge&&ge.length>0){const Le=Bc(ge);Le.length>0&&(F.preventDefault(),B(Le))}},[B]),X=x.useCallback(F=>{var Te;F.preventDefault(),J(!1);const ge=(Te=F.dataTransfer)==null?void 0:Te.files;ge&&ge.length>0&&B(Array.from(ge))},[B]),Y=x.useCallback(F=>{F.preventDefault(),J(!0)},[]),ie=x.useCallback(()=>J(!1),[]),D=b?f[b]:void 0,ue=D?c[D]:void 0,he=x.useMemo(()=>b?Object.values(c).filter(F=>F.documentName===b).sort((F,ge)=>ge.updatedAt-F.updatedAt):[],[c,b]);x.useEffect(()=>{b&&he.length===0&&d(b)},[b,he.length,d]);const ce=x.useRef(c);ce.current=c,x.useEffect(()=>{const F=new Set(N.map(Te=>Te.name)),ge=new Set;for(const Te of Object.values(ce.current))!F.has(Te.documentName)&&Te.documentName!=="__migrated__"&&ge.add(Te.documentName);for(const Te of ge)_(Te)},[N,_]);const ee=x.useRef(null);x.useEffect(()=>{ee.current!==D&&(ee.current=D,k((ue==null?void 0:ue.messages)??[]))},[D,ue,k]),x.useEffect(()=>{var F;(F=ne.current)==null||F.scrollIntoView({behavior:"smooth"})},[m,C]),x.useEffect(()=>{const F=ge=>{var rt;const{documentName:Te,selection:Le}=ge.detail;t({...Le,documentName:Te}),o(),(rt=S.current)==null||rt.focus()};return window.addEventListener("monaco-selection-to-ai",F),()=>window.removeEventListener("monaco-selection-to-ai",F)},[t,o]);const de=C==="streaming",fe=C==="submitted"||de,Re=x.useCallback(F=>{F.preventDefault(),!(!I.trim()&&P.length===0||fe)&&(O(I,P.length>0?P:void 0),T(""),A([]))},[I,P,fe,O]),Oe=x.useCallback(F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),Re(F))},[Re]),We=x.useCallback(()=>{m.length!==0&&V(!0)},[m.length]),E=x.useCallback(()=>{V(!1),k([]),D&&(g(D,[]),w(D,vo()))},[k,D,g,w]),[R,Z]=x.useState(null),se=x.useCallback(F=>{Z(F)},[]),z=x.useCallback(()=>{var rt,tt;if(!R)return;const F=m.findIndex(at=>at.id===R);if(F===-1){Z(null);return}const ge=m[F],Te=new Set([F]);ge.role==="user"&&((rt=m[F+1])==null?void 0:rt.role)==="assistant"?Te.add(F+1):ge.role==="assistant"&&F>0&&((tt=m[F-1])==null?void 0:tt.role)==="user"&&Te.add(F-1);const Le=m.filter((at,un)=>!Te.has(un));k(Le),D&&g(D,Le),Z(null)},[R,m,k,D,g]),K=x.useCallback(F=>{if(!fe){if(he.length<=1){We();return}h(F)}},[fe,he.length,We,h]),te=x.useCallback(()=>{if(!(!b||fe))return d(b)},[b,fe,d]),xe=x.useCallback(F=>{fe||F===D||p(F)},[fe,D,p]),L=x.useCallback((F,ge)=>{w(F,ge)},[w]);return u.jsxs("div",{className:"flex flex-col h-full border-l bg-surface-chat",children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-surface-chat",children:[u.jsx(dz,{threads:he,activeThread:ue,disabled:fe,onSwitch:xe,onCreate:te,onDelete:K,onRename:L}),u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(Se,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:We,disabled:fe||m.length===0,children:"Clear"}),u.jsx(Se,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:l,title:"Close chat",children:u.jsx(yn,{className:"h-3.5 w-3.5"})})]})]}),u.jsx(ri,{className:"flex-1 min-h-0 [&_[data-radix-scroll-area-viewport]>div]:!block",children:u.jsxs("div",{className:"p-3 space-y-4 min-w-0",children:[m.length===0&&u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4",children:[u.jsx("div",{className:"rounded-xl bg-primary/10 p-3 mb-4",children:u.jsx(il,{className:"h-5 w-5 text-primary"})}),u.jsx("p",{className:"text-sm font-medium text-foreground/80 mb-1",children:"JSON Assistant"}),u.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."}),u.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-muted/50 px-2.5 py-1.5",children:[u.jsx(ii,{shortcut:"mod+k"}),u.jsx("span",{className:"text-xs text-muted-foreground",children:"to send a selection"})]})]}),m.map((F,ge)=>{let Te;if(F.role==="user"){const tt=H(F.id);tt&&tt.length>0&&(Te=tt)}else if(F.role==="assistant"){for(let tt=ge-1;tt>=0;tt--)if(m[tt].role==="user"){Te=H(m[tt].id);break}}const Le=de&&ge===m.length-1&&F.role==="assistant",rt=F.role==="user"?j(F.id):void 0;return u.jsx(mz,{msg:F,isStreaming:Le,context:Te,scope:rt,onDelete:fe?void 0:se},F.id)}),fe&&((Q=m[m.length-1])==null?void 0:Q.role)!=="assistant"&&u.jsx("div",{className:"flex justify-start",children:u.jsx("div",{className:"rounded-lg px-3 py-2 bg-muted/60 border border-border/40",children:u.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[u.jsx(Fr,{className:"h-3.5 w-3.5 animate-spin text-primary"}),u.jsx("span",{children:"Thinking..."})]})})}),v&&!fe&&u.jsx("div",{className:"flex justify-start",children:u.jsx("div",{className:"rounded-lg px-3 py-2 bg-destructive/10 border border-destructive/30 text-destructive text-sm max-w-[90%]",children:v.message||"Something went wrong"})}),u.jsx("div",{ref:ne})]})}),u.jsxs("div",{className:`border-t border-border/60 p-2.5 space-y-2 bg-surface-chat transition-colors ${U?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:X,onDragOver:Y,onDragLeave:ie,children:[e.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((F,ge)=>u.jsx(Um,{context:F,onRemove:()=>n(ge)},ge))}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx(yz,{model:s,setModel:a}),ht==="pptx"&&b&&u.jsx(vz,{scope:r,setScope:i,docSize:((ve=(me=N.find(F=>F.name===b))==null?void 0:me.text)==null?void 0:ve.length)??0})]}),P.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:P.map((F,ge)=>u.jsxs("div",{className:"relative group",children:[Ym(F.mediaType)?u.jsx("img",{src:F.url,alt:F.filename||"attachment",className:"h-14 w-14 rounded-md object-cover border border-border/60"}):u.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:[u.jsx(Ta,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsx("span",{className:"text-xs truncate text-muted-foreground",children:F.filename||"file"})]}),u.jsx("button",{type:"button",onClick:()=>y(ge),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:u.jsx(yn,{className:"h-3 w-3"})})]},ge))}),u.jsxs("form",{onSubmit:Re,className:"flex items-end gap-2",children:[u.jsx("input",{ref:oe,type:"file",accept:fz,multiple:!0,className:"hidden",onChange:F=>{F.target.files&&B(Array.from(F.target.files)),F.target.value=""}}),u.jsx(Se,{type:"button",variant:"ghost",size:"icon",className:"shrink-0 h-9 w-9 rounded-lg text-muted-foreground hover:text-foreground",onClick:()=>{var F;return(F=oe.current)==null?void 0:F.click()},title:"Attach file",children:u.jsx(Ta,{className:"h-4 w-4"})}),u.jsx("textarea",{ref:S,value:I,onChange:F=>{T(F.target.value);const ge=F.target;ge.style.height="auto",ge.style.height=`${Math.min(ge.scrollHeight,128)}px`},onKeyDown:Oe,onPaste:q,placeholder:e.length>0?"Describe how to edit the selection...":r==="slides"?"Add, edit, or remove slides...":r==="templates"?"Edit template layouts and placeholders...":"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?u.jsx(Se,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:$,title:"Stop generating",children:u.jsx(zd,{className:"h-4 w-4"})}):u.jsx(Se,{type:"submit",size:"icon",disabled:!I.trim()&&P.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:u.jsx(il,{className:"h-4 w-4"})})]})]}),u.jsx(Ct,{open:M,onOpenChange:V,children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Clear thread"}),u.jsx(on,{children:"This will delete all messages in this thread. This action cannot be undone."})]}),u.jsxs(bn,{children:[u.jsx(al,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Se,{variant:"destructive",size:"sm",onClick:E,children:"Clear"})]})]})}),u.jsx(Ct,{open:R!==null,onOpenChange:F=>{F||Z(null)},children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Vt,{children:[u.jsx(Ut,{children:"Delete message"}),u.jsx(on,{children:"This will delete the message and its paired response. This action cannot be undone."})]}),u.jsxs(bn,{children:[u.jsx(al,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Se,{variant:"destructive",size:"sm",onClick:z,children:"Delete"})]})]})})]})}const mz=x.memo(function({msg:t,isStreaming:n,context:r,scope:i,onDelete:s}){var l,c;const a=((l=t.parts)==null?void 0:l.filter(f=>f.type==="text").map(f=>f.text).join(""))||"",o=((c=t.parts)==null?void 0:c.filter(f=>f.type==="file"))||[];return u.jsx("div",{className:`group/msg flex ${t.role==="user"?"justify-end":"justify-start"}`,children:u.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"?u.jsxs("div",{children:[o.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:o.map((f,d)=>Ym(f.mediaType)?u.jsx("img",{src:f.url,alt:f.filename||"image",className:"h-20 max-w-[160px] rounded-sm object-cover"},d):u.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm bg-primary-foreground/20 px-2 py-1",children:[u.jsx(Ta,{className:"h-3 w-3 shrink-0"}),u.jsx("span",{className:"text-xs truncate max-w-[120px]",children:f.filename||"file"})]},d))}),r&&r.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:r.map((f,d)=>u.jsx(Um,{context:f,variant:"sent"},d))}),a&&u.jsx("div",{className:"whitespace-pre-wrap text-sm break-words",children:a}),i&&i!=="global"&&u.jsx("span",{className:"text-[10px] text-primary-foreground/60 mt-0.5 block text-right",children:i})]}):u.jsx(gz,{text:a,isStreaming:n,context:r,scope:i}),s&&!n&&u.jsx("div",{className:"opacity-0 transition-opacity group-hover/msg:opacity-100 focus-within:opacity-100 mt-1",children:u.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:u.jsx(fo,{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 gz({text:e,isStreaming:t,context:n,scope:r}){return t?u.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1",children:u.jsx("pre",{className:"whitespace-pre-wrap font-sans text-sm m-0 p-0 bg-transparent border-none",children:e})}):u.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:u.jsx(V1,{remarkPlugins:[nj],components:{pre:({children:i})=>u.jsx(u.Fragment,{children:i}),code:({className:i,children:s})=>{const a=i==null?void 0:i.startsWith("language-"),o=(i==null?void 0:i.replace("language-",""))||"",l=String(s).replace(/\n$/,"");if(!a)return u.jsx("code",{className:"rounded-sm bg-muted px-1 py-0.5 text-xs font-mono",children:s});const c=o==="json"||o==="jsonc";return u.jsxs("div",{className:"my-2 rounded-lg border bg-card",children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-muted/60 border-b text-xs text-muted-foreground",children:[u.jsx("span",{className:"font-mono",children:o||"code"}),!c&&u.jsx(wz,{text:l})]}),u.jsx("pre",{className:"p-3 text-xs font-mono overflow-x-auto max-h-80 overflow-y-auto m-0",children:u.jsx("code",{children:l})}),c&&u.jsx(cz,{json:l,context:n,scope:r})]})}},children:e})})}const xz=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function yz({model:e,setModel:t}){return u.jsxs(ti,{value:e,onValueChange:n=>t(n),children:[u.jsx(fr,{className:"h-6 w-auto gap-1 border-none bg-muted/40 px-2 py-0 text-[10px] shadow-none focus:ring-0",children:u.jsx(ni,{})}),u.jsx(pr,{children:xz.map(n=>u.jsx(Pn,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const Vc={global:"AI sees and edits the entire document",slides:"AI sees and edits only slides — templates stay unchanged",templates:"AI sees and edits only template layouts — slides stay unchanged"},bz=1e5;function vz({scope:e,setScope:t,docSize:n}){return u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Scope"}),u.jsx("div",{className:"flex items-center bg-muted/40 rounded-md p-0.5 gap-px",children:Object.keys(Vc).map(r=>u.jsxs(Ye,{children:[u.jsx(Ke,{asChild:!0,children:u.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})}),u.jsx(Xe,{side:"top",className:"text-xs max-w-[200px]",children:Vc[r]})]},r))})]}),e==="global"&&n>bz&&u.jsxs("div",{className:"text-[10px] text-warning flex items-center gap-1",children:[u.jsx(Dd,{className:"h-3 w-3 shrink-0"}),u.jsxs("span",{children:["Large doc — switch to"," ",u.jsx("button",{type:"button",onClick:()=>t("slides"),className:"underline cursor-pointer hover:text-warning/80",children:"slides"})," ","or"," ",u.jsx("button",{type:"button",onClick:()=>t("templates"),className:"underline cursor-pointer hover:text-warning/80",children:"templates"})]})]})]})}function wz({text:e}){const[t,n]=x.useState(!1),r=x.useCallback(async()=>{await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},[e]);return u.jsx("button",{onClick:r,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:t?"Copied!":"Copy"})}function kz({discoveryData:e}){const t=wf(),n=py(),r=Pe(j=>j.chatOpen),i=Pe(j=>j.toggleChat),[s,a]=x.useState(()=>{try{const j=localStorage.getItem("dev-env.sidebar-open");return n?!1:j?j==="true":!0}catch{return!n}}),[o,l]=x.useState(()=>{try{const j=localStorage.getItem("dev-env.preview-open");return j?j==="true":!0}catch{return!0}}),[c,f]=x.useState("editor"),[d,h]=x.useState(!1),p=150,[g,w]=x.useState(!s),[_,b]=x.useState(!1);x.useEffect(()=>{try{localStorage.setItem("dev-env.sidebar-open",String(s))}catch{}},[s]),x.useEffect(()=>{try{localStorage.setItem("dev-env.preview-open",String(o))}catch{}},[o]);const N=x.useRef(n);x.useEffect(()=>{n&&!N.current&&s&&(b(!0),a(!1),setTimeout(()=>{w(!0),b(!1)},p)),!n&&N.current&&!s&&(b(!0),a(!0),setTimeout(()=>{w(!1),b(!1)},p)),N.current=n},[n,s]);const m=x.useCallback(()=>{if(t){h(j=>!j);return}b(!0),a(j=>!j),setTimeout(()=>{w(j=>!j),b(!1)},p)},[t]),O=x.useCallback(()=>l(j=>!j),[]),C=x.useRef(i),v=x.useRef(m),k=x.useRef(O);x.useEffect(()=>{C.current=i}),x.useEffect(()=>{v.current=m}),x.useEffect(()=>{k.current=O}),x.useEffect(()=>{const j=I=>{(I.metaKey||I.ctrlKey)&&(I.code==="KeyB"&&!I.shiftKey&&(I.preventDefault(),v.current()),I.code==="KeyJ"&&I.shiftKey&&(I.preventDefault(),I.stopPropagation(),C.current()),I.code==="KeyP"&&I.shiftKey&&(I.preventDefault(),k.current()))};return window.addEventListener("keydown",j,!0),()=>window.removeEventListener("keydown",j,!0)},[]);const $=LA,H=[{key:"editor",icon:Ca,label:"Editor"},{key:"preview",icon:Rd,label:"Preview"},{key:"chat",icon:Md,label:"Chat"}];return t?u.jsx($,{children:u.jsxs("div",{className:"flex flex-col h-full w-full overflow-hidden",children:[u.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b bg-sidebar shrink-0",children:[u.jsxs(yf,{open:d,onOpenChange:h,children:[u.jsx(ly,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:u.jsx(Pd,{className:"h-4 w-4"})})}),u.jsx(So,{side:"left",className:"p-0 w-72",children:u.jsx(Tl,{discoveryData:e,onToggleSidebar:()=>h(!1),isCollapsed:!1})})]}),u.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:H.map(({key:j,icon:I,label:T})=>u.jsxs(Se,{variant:c===j?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>f(j),children:[u.jsx(I,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"hidden xs:inline",children:T})]},j))})]}),c!=="chat"&&u.jsx(Xl,{previewOpen:o,onTogglePreview:O}),u.jsxs("div",{className:"flex-1 min-h-0",children:[c==="editor"&&u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(Il,{})}),c==="preview"&&u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Al,{})}),c==="chat"&&u.jsx(Zc,{})]})]})}):u.jsx($,{children:u.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[u.jsx("div",{className:G("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:u.jsx(Tl,{discoveryData:e,onToggleSidebar:m,isCollapsed:g,isAnimating:_})}),u.jsxs("div",{className:"flex-1 min-w-0 flex flex-col h-full",children:[u.jsx(Xl,{previewOpen:o,onTogglePreview:O}),u.jsxs(Wb,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[u.jsx(Qs,{defaultSize:o?50:100,minSize:20,id:"editor",order:1,children:u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(Il,{})})}),o&&u.jsxs(u.Fragment,{children:[u.jsx(Bl,{withHandle:!0}),u.jsx(Qs,{defaultSize:50,minSize:20,id:"preview",order:2,children:u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Al,{})})})]}),r&&u.jsxs(u.Fragment,{children:[u.jsx(Bl,{withHandle:!0}),u.jsx(Qs,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:u.jsx(Zc,{})})]})]})]})]})})}function Sz(){const[e,t]=x.useState(null),[n,r]=x.useState(!0),[i,s]=x.useState(null),a=x.useCallback(async()=>{r(!0),s(null);try{const o=await fetch("/api/discovery/all");if(!o.ok)throw new Error(`Discovery failed: ${o.statusText}`);const l=await o.json();if(!l.success)throw new Error(l.error||"Discovery failed");t(l.data)}catch(o){console.error("Discovery error:",o),s(o instanceof Error?o.message:"Failed to fetch discovered items"),t({plugins:[],documents:[],themes:[]})}finally{r(!1)}},[]);return x.useEffect(()=>{a()},[a]),{data:e,loading:n,error:i,refetch:a}}let Mi=null;async function _z(){const e=await fetch("/api/discovery/load-plugins",{method:"POST"});if(!e.ok)throw new Error(`Failed to load plugins: ${e.statusText}`);const t=await e.json();if(!t.success)throw new Error(t.error||"Failed to load plugins");return t.data.loaded}function jz(){const[e,t]=x.useState(!1),[n,r]=x.useState(null),[i,s]=x.useState(0);return{loadPlugins:x.useCallback(async()=>{t(!0),r(null);try{Mi||(Mi=_z().finally(()=>{Mi=null}));const o=await Mi;return s(o),!0}catch(o){return console.error("Plugin loading error:",o),r(o instanceof Error?o.message:"Failed to load plugins"),!1}finally{t(!1)}},[]),loading:e,error:n,loadedCount:i}}function Nz(){const{data:e,loading:t,error:n}=Sz(),{loadPlugins:r}=jz(),i=Lt(s=>s.applyPluginsWithValidation);return x.useEffect(()=>{e&&e.plugins.length>0&&r().then(s=>{if(s){console.log("Plugins loaded successfully");const a=Lt.getState().selectedPlugins;a.size>0&&(console.log("Auto-applying persisted plugin selections:",Array.from(a)),i())}})},[e,r,i]),t?u.jsx("div",{className:"flex items-center justify-center h-screen",children:u.jsxs("div",{className:"text-center",children:[u.jsx("div",{className:"text-lg font-medium",children:"Discovering project resources..."}),u.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:"Searching for documents, themes, and plugins"})]})}):n?u.jsx("div",{className:"flex items-center justify-center h-screen",children:u.jsxs("div",{className:"text-center",children:[u.jsx("div",{className:"text-lg font-medium text-destructive",children:"Discovery failed"}),u.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:n}),u.jsx("div",{className:"text-xs text-muted-foreground mt-4",children:"The playground will work with limited functionality."})]})}):u.jsx(ax,{children:u.jsx(ox,{children:u.jsx(lx,{children:u.jsx(ux,{children:u.jsx(cx,{children:u.jsx(Jx,{children:u.jsx(Sf,{children:u.jsx("section",{className:"flex h-screen w-full flex-col",children:u.jsx("div",{className:"grow overflow-hidden",children:u.jsx(kz,{discoveryData:e})})})})})})})})})})}const Mz=Object.freeze(Object.defineProperty({__proto__:null,HomePage:Nz},Symbol.toStringTag,{value:"Module"}));export{Kt as B,Ct as D,Mz as H,Wr as L,av as P,Yb as Q,Yr as S,ur as T,sp as a,ti as b,fr as c,ni as d,pr as e,Pn as f,Rz as g,xf as h,kt as i,Vt as j,Ut as k,Xb as l,Zy as p,ev as u};
106
- //# sourceMappingURL=HomePage-fDrbL-5G.js.map
106
+ //# sourceMappingURL=HomePage-r7ryeW_v.js.map