@json-to-office/jto 1.0.0 → 1.2.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 (23) hide show
  1. package/dist/cli.js +4 -4
  2. package/dist/cli.js.map +1 -1
  3. package/dist/client/assets/{HomePage-D3vuZyJI.js → HomePage-jkIz_s7u.js} +4 -4
  4. package/dist/client/assets/{HomePage-D3vuZyJI.js.map → HomePage-jkIz_s7u.js.map} +1 -1
  5. package/dist/client/assets/{JsonEditorPage-Cqy_bBQ5.js → JsonEditorPage-DR8UoROz.js} +3 -3
  6. package/dist/client/assets/{JsonEditorPage-Cqy_bBQ5.js.map → JsonEditorPage-DR8UoROz.js.map} +1 -1
  7. package/dist/client/assets/{MonacoPluginProvider-BNFHf2Mg.js → MonacoPluginProvider-CE5NPGwN.js} +3 -3
  8. package/dist/client/assets/{MonacoPluginProvider-BNFHf2Mg.js.map → MonacoPluginProvider-CE5NPGwN.js.map} +1 -1
  9. package/dist/client/assets/{editor-CN0fauKm.js → editor-edmvhW9F.js} +2 -2
  10. package/dist/client/assets/{editor-CN0fauKm.js.map → editor-edmvhW9F.js.map} +1 -1
  11. package/dist/client/assets/{editor-monaco-json-HXjjUFz_.js → editor-monaco-json-CAlvfPc7.js} +2 -2
  12. package/dist/client/assets/{editor-monaco-json-HXjjUFz_.js.map → editor-monaco-json-CAlvfPc7.js.map} +1 -1
  13. package/dist/client/assets/{editor-refs-store-C7y0QHBG.js → editor-refs-store-DKOJcTAk.js} +2 -2
  14. package/dist/client/assets/{editor-refs-store-C7y0QHBG.js.map → editor-refs-store-DKOJcTAk.js.map} +1 -1
  15. package/dist/client/assets/index-DLlW4q4v.js +5 -0
  16. package/dist/client/assets/index-DLlW4q4v.js.map +1 -0
  17. package/dist/client/assets/{preview-BoIgsKxW.js → preview-zo-CHAU0.js} +2 -2
  18. package/dist/client/assets/{preview-BoIgsKxW.js.map → preview-zo-CHAU0.js.map} +1 -1
  19. package/dist/client/index.html +1 -1
  20. package/dist/client/templates/media/tech-report/fonts/OFL.txt +93 -0
  21. package/package.json +7 -7
  22. package/dist/client/assets/index-ClBlf8v3.js +0 -5
  23. package/dist/client/assets/index-ClBlf8v3.js.map +0 -1
@@ -1,12 +1,12 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-CN0fauKm.js","assets/react-vendor-BmQ2Ko_D.js","assets/editor-monaco-json-HXjjUFz_.js","assets/index-ClBlf8v3.js","assets/query-vendor--rhYD8mC.js","assets/radix-ui-DFNP5I4e.js","assets/ui-vendor-DpjQWJgX.js","assets/monaco-editor-DJsdM0WK.js","assets/state-vendor-Cq67_JbF.js","assets/index-CNvLzaJ7.css","assets/editor-refs-store-C7y0QHBG.js","assets/MonacoPluginProvider-BNFHf2Mg.js","assets/preview-BoIgsKxW.js"])))=>i.map(i=>d[i]);
2
- var Wm=Object.defineProperty;var qm=(e,t,n)=>t in e?Wm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var nl=(e,t,n)=>qm(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as je,R as Zc,g as lo}from"./react-vendor-BmQ2Ko_D.js";import{b as Vc,c as uo,d as Uc,e as ys,f as bs,D as vs,O as ws,g as Gm,V as Ym,G as Km,h as Jc,I as Xm,i as Qm,j as Hc,k as eg,l as Wc,m as tg,n as ng,L as qc,S as Gc,o as Yc,p as Kc,q as Xc,r as kr,s as rg,t as ig,u as sg,v as Qc,w as ed,x as td,y as nd,z as rd,B as id,E as sd,F as ad,H as od,J as ag,K as og,M as lg,N as ld,Q as ud,U as cd,W as dd,X as fd,Y as pd,Z as hd,_ as md,$ as gd,a0 as xd,a1 as ug,a2 as yd,a3 as cg,a4 as dg,a5 as bd,a6 as fg,a7 as pg,a8 as hg,a9 as mg,aa as vd,ab as wd,ac as kd}from"./radix-ui-DFNP5I4e.js";import{c as G,u as Sr,S as gn,A as ei,T as _i,C as gg,E as xg,F as ht,a as yg,b as bg,d as Ge,e as Ye,f as Ke,g as Sd,_ as _d,h as ji,i as vg,j as wg,k as kg,l as Tr,s as Vs,W as jd,m as $i}from"./index-ClBlf8v3.js";import{X as yn,C as mi,a as an,b as Sg,d as gi,G as Nd,F as _g,e as _r,f as Ed,P as jg,g as Ng,h as Cd,E as Td,B as Sa,H as Eg,T as _a,L as ja,i as Cg,j as Tg,S as Id,I as Ig,k as Ag,l as Na,m as zg,n as Og,o as Pg,p as Dg,q as Rg,r as Mg,s as $g,t as Fg,u as ks,v as Lg,M as Bg,w as nn,x as Ad,y as Zg,z as Vg,A as zd,D as Ug,J as Jg,K as Hg,N as Wg,O as qg,Q as Od,R as Gg,U as Ea,V as co,W as Pd,Y as Yg,Z as Dd,_ as Fr,$ as Kg,a0 as Xg,a1 as Qg,a2 as rl,a3 as Ca}from"./ui-vendor-DpjQWJgX.js";import{B as Se,u as ex,d as il}from"./editor-refs-store-C7y0QHBG.js";import{u as Ne,i as tx,a as Ta,b as rn,g as nx,c as Lt,T as Rd,d as Hi,S as rx,O as ix,e as sx,M as ax,D as ox}from"./MonacoPluginProvider-BNFHf2Mg.js";import{u as fo,a as lx,d as ux,p as cx,b as dx,e as fx}from"./state-vendor-Cq67_JbF.js";import{b as px}from"./query-vendor--rhYD8mC.js";const Ct=Vc,hx=Uc,sl=uo,Md=x.forwardRef(({className:e,...t},n)=>u.jsx(ws,{ref:n,className:G("fixed inset-0 z-50 bg-black/50",e),...t}));Md.displayName=ws.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hx,{children:[u.jsx(Md,{}),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(uo,{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=Gm,$d=Km,ni=Ym,fr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Jc,{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(Xm,{asChild:!0,children:u.jsx(mi,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));fr.displayName=Jc.displayName;const Fd=x.forwardRef(({className:e,...t},n)=>u.jsx(Gc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Sg,{className:"h-4 w-4"})}));Fd.displayName=Gc.displayName;const Ld=x.forwardRef(({className:e,...t},n)=>u.jsx(Yc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(mi,{className:"h-4 w-4"})}));Ld.displayName=Yc.displayName;const pr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(Qm,{children:u.jsxs(Hc,{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(Fd,{}),u.jsx(eg,{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(Ld,{})]})}));pr.displayName=Hc.displayName;const po=x.forwardRef(({className:e,...t},n)=>u.jsx(qc,{ref:n,className:G("px-2 py-1.5 text-sm font-semibold",e),...t}));po.displayName=qc.displayName;const Pn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Wc,{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(tg,{children:u.jsx(an,{className:"h-4 w-4"})})}),u.jsx(ng,{children:t})]}));Pn.displayName=Wc.displayName;const mx=x.forwardRef(({className:e,...t},n)=>u.jsx(Kc,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));mx.displayName=Kc.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 gx=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(Xc,{ref:n,className:G(gx(),e),...t}));Wr.displayName=Xc.displayName;const xx=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(xx({variant:t}),e),...n})}const yx=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Ne(fo(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),{toast:o}=Sr(),l=x.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[c,d]=x.useState(""),[f,h]=x.useState(""),[p,g]=x.useState("playground"),[v,_]=x.useState(!1),[b,E]=x.useState(null),[m,O]=x.useState(null),[N,w]=x.useState(null),k=()=>{E(null),O(null),w(null)};x.useEffect(()=>{if(!e)return;E(null),O(null),w(null);const T=l.map(P=>P.name),z=T.includes(i)?i:T[0]??"";h(z),d(T.find(P=>P!==z)??"")},[e]);const R=async()=>{const T=l.find(P=>P.name===c),z=l.find(P=>P.name===f);if(!(!T||!z)){_(!0),E(null),O(null),w(null);try{const P=await fetch(ei.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:T.text,newDefinition:z.text,options:{author:p||"playground"}})}),I=await P.json();if(!P.ok||!I.success){const M=Array.isArray(I.errors)?`: ${I.errors.slice(0,3).map(J=>J.message||String(J)).join("; ")}`:"";throw new Error((I.error||`Diff failed (${P.status})`)+M)}O(I.data.summary),w(I.data.document)}catch(P){E(P instanceof Error?P.message:"Diff failed")}finally{_(!1)}}},q=()=>{if(!N)return;const T=new Set(n.map(I=>I.name));let z=`${f}-redline`,P=2;for(;T.has(z);)z=`${f}-redline-${P++}`;s(z,JSON.stringify(N,null,2)),a(z),o({title:`Redline created: ${z}`}),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(Nd,{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:T=>{d(T),k()},children:[u.jsx(fr,{id:"diff-base",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(T=>u.jsx(Pn,{value:T.name,children:T.name},T.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(ti,{value:f,onValueChange:T=>{h(T),k()},children:[u.jsx(fr,{id:"diff-revised",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(T=>u.jsx(Pn,{value:T.name,children:T.name},T.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:T=>{g(T.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((T,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},z))]}),m.notes.map((T,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},z))]})]}),u.jsx(bn,{children:m&&j+m.untracked.length>0?u.jsxs(Se,{onClick:q,children:[u.jsx(_g,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Se,{onClick:R,disabled:v||!c||!f||c===f,children:[v&&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 Bd=e=>typeof e=="object";var Qe=e=>!ft(e)&&!Array.isArray(e)&&Bd(e)&&!In(e),Zd=e=>Qe(e)&&e.target?xi(e.target)?e.target.checked:e.target.value:e,bx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Vd=(e,t)=>e.has(bx(t)),vx=e=>{const t=e.constructor&&e.constructor.prototype;return Qe(t)&&t.hasOwnProperty("isPrototypeOf")},ho=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(!(ho&&(e instanceof Blob||r))&&(n||Qe(e)))if(t=n?[]:{},!n&&!vx(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):[],Xe=e=>e===void 0,ce=(e,t,n)=>{if(!t||!Qe(e))return n;const r=Ss(t.split(/[,[\].]+?/)).reduce((i,s)=>ft(i)?i:i[s],e);return Xe(r)||r===e?Xe(e[t])?n:e[t]:r},zt=e=>typeof e=="boolean",mo=e=>/^\w*$/.test(e),Ud=e=>Ss(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Me=(e,t,n)=>{let r=-1;const i=mo(t)?[t]:Ud(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=Qe(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"},Jd=je.createContext(null),_s=()=>je.useContext(Jd),wx=e=>{const{children:t,...n}=e;return je.createElement(Jd.Provider,{value:n},t)};var Hd=(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=>Qe(e)&&!Object.keys(e).length,Wd=(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],qd=(e,t,n)=>!e||!t||e===t||qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function go(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 kx(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}),d=je.useRef(i);return d.current=i,go({disabled:r,next:f=>l.current&&qd(d.current,f.name,s)&&Wd(f,c.current,n._updateFormState)&&o({...n._formState,...f}),subject:n._subjects.state}),je.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),je.useMemo(()=>Hd(a,n,c.current,!1),[a,n])}var Yt=e=>typeof e=="string",Gd=(e,t,n,r,i)=>Yt(e)?(r&&t.watch.add(e),ce(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),ce(n,s))):(r&&(t.watchAll=!0),n);function Sx(e){const t=_s(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=je.useRef(r);o.current=r,go({disabled:s,subject:n._subjects.values,next:d=>{qd(o.current,d.name,a)&&c(yt(Gd(o.current,n._names,d.values||n._formValues,!1,i)))}});const[l,c]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),l}function _x(e){const t=_s(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=Vd(i._names.array,n),o=Sx({control:i,name:n,defaultValue:ce(i._formValues,n,ce(i._defaultValues,n,e.defaultValue)),exact:!0}),l=kx({control:i,name:n,exact:!0}),c=je.useRef(i.register(n,{...e.rules,value:o,...zt(e.disabled)?{disabled:e.disabled}:{}})),d=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ce(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!ce(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ce(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ce(l.validatingFields,n)},error:{enumerable:!0,get:()=>ce(l.errors,n)}}),[l,n]),f=je.useMemo(()=>({name:n,value:o,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:h=>c.current.onChange({target:{value:Zd(h),name:n},type:Wi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:ce(i._formValues,n),name:n},type:Wi.BLUR}),ref:h=>{const p=ce(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,v)=>{const _=ce(i._fields,g);_&&_._f&&(_._f.mount=v)};if(p(n,!0),h){const g=yt(ce(i._options.defaultValues,n));Me(i._defaultValues,n,g),Xe(ce(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:f,formState:l,fieldState:d}),[f,l,d])}const jx=e=>e.render(_x(e));var Nx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},al=e=>({isOnSubmit:!e||e===Ft.onSubmit,isOnBlur:e===Ft.onBlur,isOnChange:e===Ft.onChange,isOnAll:e===Ft.all,isOnTouch:e===Ft.onTouched}),ol=(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=ce(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(Qe(o)&&Gr(o,t))break}}};var Ex=(e,t,n)=>{const r=qr(ce(e,n));return Me(r,"root",t[n]),Me(e,n,r),e},xo=e=>e.type==="file",Gt=e=>typeof e=="function",qi=e=>{if(!ho)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Fi=e=>Yt(e),yo=e=>e.type==="radio",Gi=e=>e instanceof RegExp;const ll={value:!1,isValid:!1},ul={value:!0,isValid:!0};var Yd=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&&!Xe(e[0].attributes.value)?Xe(e[0].value)||e[0].value===""?ul:{value:e[0].value,isValid:!0}:ul:ll}return ll};const cl={isValid:!1,value:null};var Kd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,cl):cl;function dl(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=>Qe(e)&&!Gi(e)?e:{value:e,message:""},fl=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:d,min:f,max:h,pattern:p,validate:g,name:v,valueAsNumber:_,mount:b}=e._f,E=ce(n,v);if(!b||t.has(v))return{};const m=o?o[0]:a,O=z=>{i&&m.reportValidity&&(m.setCustomValidity(zt(z)?"":z||""),m.reportValidity())},N={},w=yo(a),k=xi(a),R=w||k,q=(_||xo(a))&&Xe(a.value)&&Xe(E)||qi(a)&&a.value===""||E===""||Array.isArray(E)&&!E.length,j=Nx.bind(null,v,r,N),T=(z,P,I,M=tn.maxLength,J=tn.minLength)=>{const Z=z?P:I;N[v]={type:z?M:J,message:Z,ref:a,...j(z?M:J,Z)}};if(s?!Array.isArray(E)||!E.length:l&&(!R&&(q||ft(E))||zt(E)&&!E||k&&!Yd(o).isValid||w&&!Kd(o).isValid)){const{value:z,message:P}=Fi(l)?{value:!!l,message:l}:Ln(l);if(z&&(N[v]={type:tn.required,message:P,ref:m,...j(tn.required,P)},!r))return O(P),N}if(!q&&(!ft(f)||!ft(h))){let z,P;const I=Ln(h),M=Ln(f);if(!ft(E)&&!isNaN(E)){const J=a.valueAsNumber||E&&+E;ft(I.value)||(z=J>I.value),ft(M.value)||(P=J<M.value)}else{const J=a.valueAsDate||new Date(E),Z=S=>new Date(new Date().toDateString()+" "+S),V=a.type=="time",ne=a.type=="week";Yt(I.value)&&E&&(z=V?Z(E)>Z(I.value):ne?E>I.value:J>new Date(I.value)),Yt(M.value)&&E&&(P=V?Z(E)<Z(M.value):ne?E<M.value:J<new Date(M.value))}if((z||P)&&(T(!!z,I.message,M.message,tn.max,tn.min),!r))return O(N[v].message),N}if((c||d)&&!q&&(Yt(E)||s&&Array.isArray(E))){const z=Ln(c),P=Ln(d),I=!ft(z.value)&&E.length>+z.value,M=!ft(P.value)&&E.length<+P.value;if((I||M)&&(T(I,z.message,P.message),!r))return O(N[v].message),N}if(p&&!q&&Yt(E)){const{value:z,message:P}=Ln(p);if(Gi(z)&&!E.match(z)&&(N[v]={type:tn.pattern,message:P,ref:a,...j(tn.pattern,P)},!r))return O(P),N}if(g){if(Gt(g)){const z=await g(E,n),P=dl(z,m);if(P&&(N[v]={...P,...j(tn.validate,P.message)},!r))return O(P.message),N}else if(Qe(g)){let z={};for(const P in g){if(!bt(z)&&!r)break;const I=dl(await g[P](E,n),m,P);I&&(z={...I,...j(P,I.message)},O(I.message),r&&(N[v]=z))}if(!bt(z)&&(N[v]={ref:m,...z},!r))return N}}return O(!0),N};function Cx(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Xe(e)?r++:e[t[r++]];return e}function Tx(e){for(const t in e)if(e.hasOwnProperty(t)&&!Xe(e[t]))return!1;return!0}function it(e,t){const n=Array.isArray(t)?t:mo(t)?[t]:Ud(t),r=n.length===1?e:Cx(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(Qe(r)&&bt(r)||Array.isArray(r)&&Tx(r))&&it(e,n.slice(0,-1)),e}var Us=()=>{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=[]}}},Ia=e=>ft(e)||!Bd(e);function hn(e,t){if(Ia(e)||Ia(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)||Qe(s)&&Qe(a)||Array.isArray(s)&&Array.isArray(a)?!hn(s,a):s!==a)return!1}}return!0}var Xd=e=>e.type==="select-multiple",Ix=e=>yo(e)||xi(e),Js=e=>qi(e)&&e.isConnected,Qd=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Yi(e,t={}){const n=Array.isArray(e);if(Qe(e)||n)for(const r in e)Array.isArray(e[r])||Qe(e[r])&&!Qd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Yi(e[r],t[r])):ft(e[r])||(t[r]=!0);return t}function ef(e,t,n){const r=Array.isArray(e);if(Qe(e)||r)for(const i in e)Array.isArray(e[i])||Qe(e[i])&&!Qd(e[i])?Xe(t)||Ia(n[i])?n[i]=Array.isArray(e[i])?Yi(e[i],[]):{...Yi(e[i])}:ef(e[i],ft(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Ir=(e,t)=>ef(e,t,Yi(t)),tf=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Xe(e)?e:t?e===""?NaN:e&&+e:n&&Yt(e)?new Date(e):r?r(e):e;function Hs(e){const t=e.ref;return xo(t)?t.files:yo(t)?Kd(e.refs).value:Xd(t)?[...t.selectedOptions].map(({value:n})=>n):xi(t)?Yd(e.refs).value:tf(Xe(t.value)?e.ref.value:t.value,e)}var Ax=(e,t,n,r)=>{const i={};for(const s of e){const a=ce(t,s);a&&Me(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Ar=e=>Xe(e)?e:Gi(e)?e.source:Qe(e)?Gi(e.value)?e.value.source:e.value:e;const pl="AsyncFunction";var zx=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===pl||Qe(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===pl)),Ox=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function hl(e,t,n){const r=ce(e,n);if(r||mo(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=ce(t,s),o=ce(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 Px=(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,Dx=(e,t)=>!Ss(ce(e,t)).length&&it(e,t);const Rx={mode:Ft.onSubmit,reValidateMode:Ft.onChange,shouldFocusError:!0};function Mx(e={}){let t={...Rx,...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=Qe(t.defaultValues)||Qe(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 d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Us(),array:Us(),state:Us()},h=al(t.mode),p=al(t.reValidateMode),g=t.criteriaMode===Ft.all,v=C=>$=>{clearTimeout(c),c=setTimeout(C,$)},_=async C=>{if(!t.disabled&&(d.isValid||C)){const $=t.resolver?bt((await R()).errors):await j(r,!0);$!==n.isValid&&f.state.next({isValid:$})}},b=(C,$)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((C||Array.from(o.mount)).forEach(U=>{U&&($?Me(n.validatingFields,U,$):it(n.validatingFields,U))}),f.state.next({validatingFields:n.validatingFields,isValidating:!bt(n.validatingFields)}))},E=(C,$=[],U,se,A=!0,K=!0)=>{if(se&&U&&!t.disabled){if(a.action=!0,K&&Array.isArray(ce(r,C))){const ee=U(ce(r,C),se.argA,se.argB);A&&Me(r,C,ee)}if(K&&Array.isArray(ce(n.errors,C))){const ee=U(ce(n.errors,C),se.argA,se.argB);A&&Me(n.errors,C,ee),Dx(n.errors,C)}if(d.touchedFields&&K&&Array.isArray(ce(n.touchedFields,C))){const ee=U(ce(n.touchedFields,C),se.argA,se.argB);A&&Me(n.touchedFields,C,ee)}d.dirtyFields&&(n.dirtyFields=Ir(i,s)),f.state.next({name:C,isDirty:z(C,$),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Me(s,C,$)},m=(C,$)=>{Me(n.errors,C,$),f.state.next({errors:n.errors})},O=C=>{n.errors=C,f.state.next({errors:n.errors,isValid:!1})},N=(C,$,U,se)=>{const A=ce(r,C);if(A){const K=ce(s,C,Xe(U)?ce(i,C):U);Xe(K)||se&&se.defaultChecked||$?Me(s,C,$?K:Hs(A._f)):M(C,K),a.mount&&_()}},w=(C,$,U,se,A)=>{let K=!1,ee=!1;const xe={name:C};if(!t.disabled){const L=!!(ce(r,C)&&ce(r,C)._f&&ce(r,C)._f.disabled);if(!U||se){d.isDirty&&(ee=n.isDirty,n.isDirty=xe.isDirty=z(),K=ee!==xe.isDirty);const Q=L||hn(ce(i,C),$);ee=!!(!L&&ce(n.dirtyFields,C)),Q||L?it(n.dirtyFields,C):Me(n.dirtyFields,C,!0),xe.dirtyFields=n.dirtyFields,K=K||d.dirtyFields&&ee!==!Q}if(U){const Q=ce(n.touchedFields,C);Q||(Me(n.touchedFields,C,U),xe.touchedFields=n.touchedFields,K=K||d.touchedFields&&Q!==U)}K&&A&&f.state.next(xe)}return K?xe:{}},k=(C,$,U,se)=>{const A=ce(n.errors,C),K=d.isValid&&zt($)&&n.isValid!==$;if(t.delayError&&U?(l=v(()=>m(C,U)),l(t.delayError)):(clearTimeout(c),l=null,U?Me(n.errors,C,U):it(n.errors,C)),(U?!hn(A,U):A)||!bt(se)||K){const ee={...se,...K&&zt($)?{isValid:$}:{},errors:n.errors,name:C};n={...n,...ee},f.state.next(ee)}},R=async C=>{b(C,!0);const $=await t.resolver(s,t.context,Ax(C||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(C),$},q=async C=>{const{errors:$}=await R(C);if(C)for(const U of C){const se=ce($,U);se?Me(n.errors,U,se):it(n.errors,U)}else n.errors=$;return $},j=async(C,$,U={valid:!0})=>{for(const se in C){const A=C[se];if(A){const{_f:K,...ee}=A;if(K){const xe=o.array.has(K.name),L=A._f&&zx(A._f);L&&d.validatingFields&&b([se],!0);const Q=await fl(A,o.disabled,s,g,t.shouldUseNativeValidation&&!$,xe);if(L&&d.validatingFields&&b([se]),Q[K.name]&&(U.valid=!1,$))break;!$&&(ce(Q,K.name)?xe?Ex(n.errors,Q,K.name):Me(n.errors,K.name,Q[K.name]):it(n.errors,K.name))}!bt(ee)&&await j(ee,$,U)}}return U.valid},T=()=>{for(const C of o.unMount){const $=ce(r,C);$&&($._f.refs?$._f.refs.every(U=>!Js(U)):!Js($._f.ref))&&Y(C)}o.unMount=new Set},z=(C,$)=>!t.disabled&&(C&&$&&Me(s,C,$),!hn(le(),i)),P=(C,$,U)=>Gd(C,o,{...a.mount?s:Xe($)?i:Yt(C)?{[C]:$}:$},U,$),I=C=>Ss(ce(a.mount?s:i,C,t.shouldUnregister?ce(i,C,[]):[])),M=(C,$,U={})=>{const se=ce(r,C);let A=$;if(se){const K=se._f;K&&(!K.disabled&&Me(s,C,tf($,K)),A=qi(K.ref)&&ft($)?"":$,Xd(K.ref)?[...K.ref.options].forEach(ee=>ee.selected=A.includes(ee.value)):K.refs?xi(K.ref)?K.refs.length>1?K.refs.forEach(ee=>(!ee.defaultChecked||!ee.disabled)&&(ee.checked=Array.isArray(A)?!!A.find(xe=>xe===ee.value):A===ee.value)):K.refs[0]&&(K.refs[0].checked=!!A):K.refs.forEach(ee=>ee.checked=ee.value===A):xo(K.ref)?K.ref.value="":(K.ref.value=A,K.ref.type||f.values.next({name:C,values:{...s}})))}(U.shouldDirty||U.shouldTouch)&&w(C,A,U.shouldTouch,U.shouldDirty,!0),U.shouldValidate&&S(C)},J=(C,$,U)=>{for(const se in $){const A=$[se],K=`${C}.${se}`,ee=ce(r,K);(o.array.has(C)||Qe(A)||ee&&!ee._f)&&!In(A)?J(K,A,U):M(K,A,U)}},Z=(C,$,U={})=>{const se=ce(r,C),A=o.array.has(C),K=yt($);Me(s,C,K),A?(f.array.next({name:C,values:{...s}}),(d.isDirty||d.dirtyFields)&&U.shouldDirty&&f.state.next({name:C,dirtyFields:Ir(i,s),isDirty:z(C,K)})):se&&!se._f&&!ft(K)?J(C,K,U):M(C,K,U),ol(C,o)&&f.state.next({...n}),f.values.next({name:a.mount?C:void 0,values:{...s}})},V=async C=>{a.mount=!0;const $=C.target;let U=$.name,se=!0;const A=ce(r,U),K=()=>$.type?Hs(A._f):Zd(C),ee=xe=>{se=Number.isNaN(xe)||In(xe)&&isNaN(xe.getTime())||hn(xe,ce(s,U,xe))};if(A){let xe,L;const Q=K(),he=C.type===Wi.BLUR||C.type===Wi.FOCUS_OUT,ve=!Ox(A._f)&&!t.resolver&&!ce(n.errors,U)&&!A._f.deps||Px(he,ce(n.touchedFields,U),n.isSubmitted,p,h),F=ol(U,o,he);Me(s,U,Q),he?(A._f.onBlur&&A._f.onBlur(C),l&&l(0)):A._f.onChange&&A._f.onChange(C);const me=w(U,Q,he,!1),Te=!bt(me)||F;if(!he&&f.values.next({name:U,type:C.type,values:{...s}}),ve)return d.isValid&&(t.mode==="onBlur"&&he?_():he||_()),Te&&f.state.next({name:U,...F?{}:me});if(!he&&F&&f.state.next({...n}),t.resolver){const{errors:Le}=await R([U]);if(ee(Q),se){const rt=hl(n.errors,r,U),et=hl(Le,r,rt.name||U);xe=et.error,U=et.name,L=bt(Le)}}else b([U],!0),xe=(await fl(A,o.disabled,s,g,t.shouldUseNativeValidation))[U],b([U]),ee(Q),se&&(xe?L=!1:d.isValid&&(L=await j(r,!0)));se&&(A._f.deps&&S(A._f.deps),k(U,L,xe,me))}},ne=(C,$)=>{if(ce(n.errors,$)&&C.focus)return C.focus(),1},S=async(C,$={})=>{let U,se;const A=qr(C);if(t.resolver){const K=await q(Xe(C)?C:A);U=bt(K),se=C?!A.some(ee=>ce(K,ee)):U}else C?(se=(await Promise.all(A.map(async K=>{const ee=ce(r,K);return await j(ee&&ee._f?{[K]:ee}:ee)}))).every(Boolean),!(!se&&!n.isValid)&&_()):se=U=await j(r);return f.state.next({...!Yt(C)||d.isValid&&U!==n.isValid?{}:{name:C},...t.resolver||!C?{isValid:U}:{},errors:n.errors}),$.shouldFocus&&!se&&Gr(r,ne,C?A:o.mount),se},le=C=>{const $={...a.mount?s:i};return Xe(C)?$:Yt(C)?ce($,C):C.map(U=>ce($,U))},B=(C,$)=>({invalid:!!ce(($||n).errors,C),isDirty:!!ce(($||n).dirtyFields,C),error:ce(($||n).errors,C),isValidating:!!ce(n.validatingFields,C),isTouched:!!ce(($||n).touchedFields,C)}),y=C=>{C&&qr(C).forEach($=>it(n.errors,$)),f.state.next({errors:C?n.errors:{}})},W=(C,$,U)=>{const se=(ce(r,C,{_f:{}})._f||{}).ref,A=ce(n.errors,C)||{},{ref:K,message:ee,type:xe,...L}=A;Me(n.errors,C,{...L,...$,ref:se}),f.state.next({name:C,errors:n.errors,isValid:!1}),U&&U.shouldFocus&&se&&se.focus&&se.focus()},X=(C,$)=>Gt(C)?f.values.subscribe({next:U=>C(P(void 0,$),U)}):P(C,$,!0),Y=(C,$={})=>{for(const U of C?qr(C):o.mount)o.mount.delete(U),o.array.delete(U),$.keepValue||(it(r,U),it(s,U)),!$.keepError&&it(n.errors,U),!$.keepDirty&&it(n.dirtyFields,U),!$.keepTouched&&it(n.touchedFields,U),!$.keepIsValidating&&it(n.validatingFields,U),!t.shouldUnregister&&!$.keepDefaultValue&&it(i,U);f.values.next({values:{...s}}),f.state.next({...n,...$.keepDirty?{isDirty:z()}:{}}),!$.keepIsValid&&_()},re=({disabled:C,name:$,field:U,fields:se})=>{(zt(C)&&a.mount||C||o.disabled.has($))&&(C?o.disabled.add($):o.disabled.delete($),w($,Hs(U?U._f:ce(se,$)._f),!1,!1,!0))},D=(C,$={})=>{let U=ce(r,C);const se=zt($.disabled)||zt(t.disabled);return Me(r,C,{...U||{},_f:{...U&&U._f?U._f:{ref:{name:C}},name:C,mount:!0,...$}}),o.mount.add(C),U?re({field:U,disabled:zt($.disabled)?$.disabled:t.disabled,name:C}):N(C,!0,$.value),{...se?{disabled:$.disabled||t.disabled}:{},...t.progressive?{required:!!$.required,min:Ar($.min),max:Ar($.max),minLength:Ar($.minLength),maxLength:Ar($.maxLength),pattern:Ar($.pattern)}:{},name:C,onChange:V,onBlur:V,ref:A=>{if(A){D(C,$),U=ce(r,C);const K=Xe(A.value)&&A.querySelectorAll&&A.querySelectorAll("input,select,textarea")[0]||A,ee=Ix(K),xe=U._f.refs||[];if(ee?xe.find(L=>L===K):K===U._f.ref)return;Me(r,C,{_f:{...U._f,...ee?{refs:[...xe.filter(Js),K,...Array.isArray(ce(i,C))?[{}]:[]],ref:{type:K.type,name:C}}:{ref:K}}}),N(C,!1,void 0,K)}else U=ce(r,C,{}),U._f&&(U._f.mount=!1),(t.shouldUnregister||$.shouldUnregister)&&!(Vd(o.array,C)&&a.action)&&o.unMount.add(C)}}},de=()=>t.shouldFocusError&&Gr(r,ne,o.mount),te=C=>{zt(C)&&(f.state.next({disabled:C}),Gr(r,($,U)=>{const se=ce(r,U);se&&($.disabled=se._f.disabled||C,Array.isArray(se._f.refs)&&se._f.refs.forEach(A=>{A.disabled=se._f.disabled||C}))},0,!1))},ae=(C,$)=>async U=>{let se;U&&(U.preventDefault&&U.preventDefault(),U.persist&&U.persist());let A=yt(s);if(o.disabled.size)for(const K of o.disabled)Me(A,K,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:K,values:ee}=await R();n.errors=K,A=ee}else await j(r);if(it(n.errors,"root"),bt(n.errors)){f.state.next({errors:{}});try{await C(A,U)}catch(K){se=K}}else $&&await $({...n.errors},U),de(),setTimeout(de);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bt(n.errors)&&!se,submitCount:n.submitCount+1,errors:n.errors}),se)throw se},ue=(C,$={})=>{ce(r,C)&&(Xe($.defaultValue)?Z(C,yt(ce(i,C))):(Z(C,$.defaultValue),Me(i,C,yt($.defaultValue))),$.keepTouched||it(n.touchedFields,C),$.keepDirty||(it(n.dirtyFields,C),n.isDirty=$.defaultValue?z(C,yt(ce(i,C))):z()),$.keepError||(it(n.errors,C),d.isValid&&_()),f.state.next({...n}))},ge=(C,$={})=>{const U=C?yt(C):i,se=yt(U),A=bt(C),K=A?i:se;if($.keepDefaultValues||(i=U),!$.keepValues){if($.keepDirtyValues){const ee=new Set([...o.mount,...Object.keys(Ir(i,s))]);for(const xe of Array.from(ee))ce(n.dirtyFields,xe)?Me(K,xe,ce(s,xe)):Z(xe,ce(K,xe))}else{if(ho&&Xe(C))for(const ee of o.mount){const xe=ce(r,ee);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?$.keepDefaultValues?yt(i):{}:yt(K),f.array.next({values:{...K}}),f.values.next({values:{...K}})}o={mount:$.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!d.isValid||!!$.keepIsValid||!!$.keepDirtyValues,a.watch=!!t.shouldUnregister,f.state.next({submitCount:$.keepSubmitCount?n.submitCount:0,isDirty:A?!1:$.keepDirty?n.isDirty:!!($.keepDefaultValues&&!hn(C,i)),isSubmitted:$.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:A?{}:$.keepDirtyValues?$.keepDefaultValues&&s?Ir(i,s):n.dirtyFields:$.keepDefaultValues&&C?Ir(i,C):$.keepDirty?n.dirtyFields:{},touchedFields:$.keepTouched?n.touchedFields:{},errors:$.keepErrors?n.errors:{},isSubmitSuccessful:$.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},pe=(C,$)=>ge(Gt(C)?C(s):C,$);return{control:{register:D,unregister:Y,getFieldState:B,handleSubmit:ae,setError:W,_executeSchema:R,_getWatch:P,_getDirty:z,_updateValid:_,_removeUnmounted:T,_updateFieldArray:E,_updateDisabledField:re,_getFieldArray:I,_reset:ge,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(C=>{pe(C,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:C=>{n={...n,...C}},_disableForm:te,_subjects:f,_proxyFormState:d,_setErrors:O,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(C){a=C},get _defaultValues(){return i},get _names(){return o},set _names(C){o=C},get _formState(){return n},set _formState(C){n=C},get _options(){return t},set _options(C){t={...t,...C}}},trigger:S,register:D,handleSubmit:ae,watch:X,setValue:Z,getValues:le,reset:pe,resetField:ue,clearErrors:y,unregister:Y,setError:W,setFocus:(C,$={})=>{const U=ce(r,C),se=U&&U._f;if(se){const A=se.refs?se.refs[0]:se.ref;A.focus&&(A.focus(),$.shouldSelect&&Gt(A.select)&&A.select())}},getFieldState:B}}function $x(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={...Mx(e),formState:r});const s=t.current.control;return s._options=e,go({subject:s._subjects.state,next:a=>{Wd(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=Hd(r,s),t.current}function Fx(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 Lx=wx,nf=x.createContext({}),ml=({...e})=>u.jsx(nf.Provider,{value:{name:e.name},children:u.jsx(jx,{...e})}),js=()=>{const e=x.useContext(nf),t=x.useContext(rf),{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}},rf=x.createContext({}),Aa=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(rf.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:G("space-y-2",e),...t})})});Aa.displayName="FormItem";const za=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})});za.displayName="FormLabel";const Oa=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})});Oa.displayName="FormControl";const sf=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})});sf.displayName="FormDescription";const Pa=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});Pa.displayName="FormMessage";function bo(){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 af=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Bx=(e=af())=>lx()(ux(cx((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:bo(),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(d=>d.documentName===o);c.length>0?(c.sort((d,f)=>f.updatedAt-d.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:dx(()=>tx),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}}))),of=x.createContext(void 0),Zx=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Bx(af())),u.jsx(of.Provider,{value:t.current,children:e})},Oe=e=>{const t=x.useContext(of);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return fx(t,e)};function Vx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Ux(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(!gg(s,a))for(const c of xg(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 Jx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Hx=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 Wx({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=x.useState(!1),[c,d]=x.useState(null),[f,h]=x.useState("idle"),{toast:p}=Sr(),g=Hx(a),{documents:v,openTabs:_,createDocument:b,renameDocument:E,deleteDocument:m,openDocument:O,closeDocument:N}=Ne(le=>le),{updateTheme:w,removeTheme:k}=Ta(le=>le),R=Oe(le=>le.renameThreadsForDocument),q=Oe(le=>le.deleteThreadsForDocument),j=x.useMemo(()=>a?s||[]:i||[],[a,i,s]),T=x.useMemo(()=>{const le={current:[],downstream:[]};return j.forEach(B=>{le[B.location]&&le[B.location].push(B)}),le},[j]),z=x.useMemo(()=>j.map(le=>({name:le.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[j]),P=x.useMemo(()=>Ux(e,le=>Vx(le,v,r),z),[e,v,r,z]),I=P.schema,M=x.useMemo(()=>{const le=new Map;return j.forEach(B=>le.set(B.path,B)),le},[j]),J=Bn,Z=$x({resolver:Fx(P.validate),defaultValues:Jx(e,void 0,r)}),[V,ne]=x.useState(J);x.useEffect(()=>{if(V&&V!==Bn&&e==="create"){const le=M.get(V);if(le){d(null),h("loading");let B=!1;return fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(le.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 W=JSON.parse(y);d(JSON.stringify(W,null,2)),h("idle")}).catch(y=>{B||(console.error("Failed to copy template:",y),d(null),h("error"))}),()=>{B=!0}}}h("idle")},[V,e,M,a]),x.useEffect(()=>{t&&(Z.reset(),d(null),h("idle"),ne(J))},[Z,t]);const S=Z.handleSubmit(async({name:le,template:B})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=V?M.get(V):j.find(ue=>ue.name===B);let W,X=le;if(!!V&&V!==Bn&&c===null){p({title:f==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:f==="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 ue=X.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),ge=ht==="docx"?yg(ue):{name:ue,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};W=c||JSON.stringify(ge,null,2);const pe=`.${ht}.theme.json`;X.endsWith(pe)||(X=X.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),X+=pe)}else{const ue=y;W=c||JSON.stringify(ht==="docx"?{name:"docx",props:{theme:(ue==null?void 0:ue.theme)||"default",metadata:{title:(ue==null?void 0:ue.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:(ue==null?void 0:ue.title)||X.replace(/\.(json|js)$/i,""),theme:(ue==null?void 0:ue.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 ge=ht==="docx"?".docx.json":".pptx.json";!X.endsWith(ge)&&!X.endsWith(".json")&&(X+=ge)}const re=X.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),D=re?re[0]:"",de=X.slice(0,X.length-D.length);let te=X,ae=1;for(;v.some(ue=>ue.name===te);)ae++,te=`${de} (${ae})${D}`;X=te,b(X,W),O(X),a&&w(X,W)}else if(e==="update"){const y=r,W=le,X=_.includes(y);X&&N(y),E(y,W),R(y,W),X&&O(W)}else if(e==="delete"){const y=r;N(y),m(y),q(y),a&&k(y)}n()}finally{l(!1)}});return u.jsx(Lx,{...Z,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:[I.properties&&"name"in I.properties&&u.jsx(ml,{control:Z.control,name:"name",render:({field:le})=>u.jsxs(Aa,{children:[u.jsx(za,{children:"Name"}),u.jsx(Oa,{children:u.jsx(hr,{placeholder:"Enter a name or select a template below",autoComplete:"off",...le})}),u.jsx(Pa,{})]})}),e==="create"&&u.jsx(ml,{control:Z.control,name:"template",render:({field:le})=>u.jsxs(Aa,{children:[u.jsx(za,{children:a?"Base Theme":"Base Document"}),u.jsxs(ti,{onValueChange:B=>{if(B===Bn)le.onChange(void 0),Z.setValue("name",""),ne(Bn),d(null);else{const y=M.get(B);y&&(le.onChange(y.name),Z.setValue("name",y.name),ne(B))}},defaultValue:J,children:[u.jsx(Oa,{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(T).map(([B,y])=>y.length===0?null:u.jsxs($d,{children:[u.jsx(po,{children:B==="current"?"📁 Current Directory":"📦 Project"}),y.map(W=>{let X;return W.title&&W.title!==W.name?X=W.title:W.description&&(X=W.description.length>40?W.description.substring(0,40)+"...":W.description),u.jsx(Pn,{value:W.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:W.name}),X&&u.jsx("span",{className:"text-muted-foreground text-xs",children:X})]})},W.path)})]},B))]})]}),u.jsxs(sf,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(Pa,{})]})})]}),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(Wx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function vo({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 Da({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 gl({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 xl({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 qx=rg,Gx=ig,Yx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(nd,{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"})]}));Yx.displayName=nd.displayName;const Kx=x.forwardRef(({className:e,...t},n)=>u.jsx(rd,{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}));Kx.displayName=rd.displayName;const lf=x.forwardRef(({className:e,...t},n)=>u.jsx(sg,{children:u.jsx(Qc,{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})}));lf.displayName=Qc.displayName;const uf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(td,{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}));uf.displayName=td.displayName;const Xx=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(id,{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(sd,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));Xx.displayName=id.displayName;const Qx=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ad,{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(sd,{children:u.jsx(Ed,{className:"h-4 w-4 fill-current"})})}),t]}));Qx.displayName=ad.displayName;const ey=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(od,{ref:r,className:G("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ey.displayName=od.displayName;const cf=x.forwardRef(({className:e,...t},n)=>u.jsx(ed,{ref:n,className:G("bg-border -mx-1 my-1 h-px",e),...t}));cf.displayName=ed.displayName;const df=({className:e,...t})=>u.jsx("span",{className:G("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});df.displayName="ContextMenuShortcut";const Ns=ag,Es=og,ty=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(fd,{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"})]}));ty.displayName=fd.displayName;const ny=x.forwardRef(({className:e,...t},n)=>u.jsx(pd,{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}));ny.displayName=pd.displayName;const yi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(lg,{children:u.jsx(ld,{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=ld.displayName;const $t=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{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=ud.displayName;const ry=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(hd,{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(md,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));ry.displayName=hd.displayName;const iy=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gd,{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(md,{children:u.jsx(Ed,{className:"h-2 w-2 fill-current"})})}),t]}));iy.displayName=gd.displayName;const wo=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:G("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));wo.displayName=dd.displayName;const mr=x.forwardRef(({className:e,...t},n)=>u.jsx(cd,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));mr.displayName=cd.displayName;const ff=({className:e,...t})=>u.jsx("span",{className:G("ml-auto text-xs tracking-widest opacity-60",e),...t});ff.displayName="DropdownMenuShortcut";const pf=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(xd,{ref:i,decorative:n,orientation:t,className:G("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));pf.displayName=xd.displayName;const hf=Vc,sy=ug,ay=Uc,mf=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}));mf.displayName=ws.displayName;const oy=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"}}),ko=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(ay,{children:[u.jsx(mf,{}),u.jsxs(ys,{ref:i,className:G(oy({side:e}),t),...r,children:[u.jsxs(uo,{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]})]}));ko.displayName=ys.displayName;const ly=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-foreground text-lg font-semibold",e),...t}));ly.displayName=bs.displayName;const uy=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));uy.displayName=vs.displayName;function Yr({className:e,...t}){return u.jsx("div",{className:G("bg-primary/10 animate-pulse rounded-md",e),...t})}const Ws=768,qs=1200;function gf(e){return typeof window<"u"?window.innerWidth<e:!1}function xf(){const[e,t]=x.useState(()=>gf(Ws));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ws-1}px)`),r=()=>{t(window.innerWidth<Ws)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function cy(){const[e,t]=x.useState(()=>gf(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}const dy="sidebar_state",fy=60*60*24*7,py="16rem",hy="18rem",my="3rem",gy="b",yf=x.createContext(null);function Cs(){const e=x.useContext(yf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const bf=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=xf(),[c,d]=x.useState(!1),[f,h]=x.useState(e),p=t??f,g=x.useCallback(E=>{const m=typeof E=="function"?E(p):E;n?n(m):h(m),document.cookie=`${dy}=${m}; path=/; max-age=${fy}`},[n,p]),v=x.useCallback(()=>l?d(E=>!E):g(E=>!E),[l,g,d]);x.useEffect(()=>{const E=O=>{var k;const N=O;if(!N)return!1;const w=(k=N.tagName)==null?void 0:k.toLowerCase();return w==="input"||w==="textarea"||w==="select"||N.isContentEditable?!0:!!(N.closest&&N.closest(".monaco-editor"))},m=O=>{const N=O.metaKey||O.ctrlKey,w=O.key.toLowerCase();if(N&&w===gy){O.preventDefault(),v();return}N&&w==="s"&&!E(O.target)&&(O.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const _=p?"expanded":"collapsed",b=x.useMemo(()=>({state:_,open:p,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:d,toggleSidebar:v}),[_,p,g,l,c,d,v]);return u.jsx(yf.Provider,{value:b,children:u.jsx(bg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":py,"--sidebar-width-icon":my,...i},className:G("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});bf.displayName="SidebarProvider";const vf=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:d}=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(hf,{open:c,onOpenChange:d,...s,children:u.jsx(ko,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":hy},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})})]})});vf.displayName="Sidebar";const xy=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(jg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});xy.displayName="SidebarTrigger";const yy=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})});yy.displayName="SidebarRail";const by=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}));by.displayName="SidebarInset";const vy=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}));vy.displayName="SidebarInput";const Ra=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}));Ra.displayName="SidebarHeader";const wf=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}));wf.displayName="SidebarFooter";const wy=x.forwardRef(({className:e,...t},n)=>u.jsx(pf,{ref:n,"data-sidebar":"separator",className:G("bg-sidebar-border mx-2 w-auto",e),...t}));wy.displayName="SidebarSeparator";const Ma=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}));Ma.displayName="SidebarContent";const ky=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}));ky.displayName="SidebarGroup";const Sy=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})});Sy.displayName="SidebarGroupLabel";const _y=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})});_y.displayName="SidebarGroupAction";const jy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:G("w-full text-sm",e),...t}));jy.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 kf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:G("group/menu-item relative",e),...t}));kf.displayName="SidebarMenuItem";const Ny=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"}}),Sf=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:d}=Cs(),f=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:G(Ny({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:f}),u.jsx(Ke,{side:"right",align:"center",hidden:d!=="collapsed"||c,...i})]})):f});Sf.displayName="SidebarMenuButton";const _f=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})});_f.displayName="SidebarMenuAction";const Ey=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}));Ey.displayName="SidebarMenuBadge";const Cy=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}})]})});Cy.displayName="SidebarMenuSkeleton";const Ty=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}));Ty.displayName="SidebarMenuSub";const Iy=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Iy.displayName="SidebarMenuSubItem";const Ay=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})});Ay.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 zy=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Oy({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),[d,f]=x.useState(!1),h=Ne(B=>B.openDocument),p=Ne(B=>B.documentTypes),g=Ne(B=>B.activeTab),v=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,[N,w]=x.useState(v),[k,R]=x.useState(_),q=100,j=0;x.useEffect(()=>{const B=setTimeout(()=>{v&&_?(w(v),R(_)):b||(w(""),R(""))},b?q:j);return()=>clearTimeout(B)},[v,_,b]);const T=N===e.name,z=B=>{var W;const y=new Set;try{const X=JSON.parse(B);(W=X.props)!=null&&W.theme&&y.add(X.props.theme),X.children&&Array.isArray(X.children)&&X.children.forEach(Y=>{var re;Y.name==="docx"&&((re=Y.props)!=null&&re.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=nx(B);if(y)return z(k).has(y)}catch{}return!1},[m,k,e.text]),I=x.useCallback(()=>{c(!1)},[]),M=x.useCallback(()=>{f(!1)},[]),J=O?null:T?"preview":P?"in-use":null,Z=O?"Editing":T?"In preview":P?"Used by preview":null,V=x.useMemo(()=>[{key:"open",label:"Open",shortcut:zy?"⌘⏎":"⌃⏎",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:()=>f(!0)}],[e.name,e.text,e.type,h]),ne=m?Ng:Cd,S=i||a,le=u.jsxs(Sf,{size:"sm",ref:r,"aria-label":Z?`${e.name} — ${Z}`: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:Z?`${e.name} — ${Z}`: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"?(f(!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(vo,{text:e.name,query:n})}),t&&J&&u.jsx(gl,{tone:J,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(kf,{children:[u.jsxs(qx,{onOpenChange:s,children:[u.jsx(Gx,{className:"block",children:t?u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:le}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:Z??(m?"Theme":"Document")})]})})]}):le}),u.jsx(lf,{className:"w-44",children:V.map(B=>u.jsxs(je.Fragment,{children:[B.separatorBefore&&u.jsx(cf,{}),u.jsxs(uf,{onClick:B.run,className:G(B.danger&&"text-destructive focus:text-destructive"),children:[B.label,B.shortcut&&u.jsx(df,{children:B.shortcut})]})]},B.key))})]}),!t&&u.jsxs(u.Fragment,{children:[J&&u.jsx(gl,{tone:J,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(_f,{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(Td,{})})}),u.jsx(yi,{side:"right",align:"start",className:"w-44",children:V.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(ff,{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:I,selectedName:e.name})})}),u.jsx(Ct,{open:d,onOpenChange:f,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:!d,postSubmit:M,selectedName:e.name})})})]})}const Ni=je.memo(Oy);function Py(e,t=!1){const n=e.length;let r=0,i="",s=0,a=16,o=0,l=0,c=0,d=0,f=0;function h(m,O){let N=0,w=0;for(;N<m;){let k=e.charCodeAt(r);if(k>=48&&k<=57)w=w*16+k-48;else if(k>=65&&k<=70)w=w*16+k-65+10;else if(k>=97&&k<=102)w=w*16+k-97+10;else break;r++,N++}return N<m&&(w=-1),w}function p(m){r=m,i="",s=0,a=16,f=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 f=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 f=3;return e.substring(m,O)}function v(){let m="",O=r;for(;;){if(r>=n){m+=e.substring(O,r),f=2;break}const N=e.charCodeAt(r);if(N===34){m+=e.substring(O,r),r++;break}if(N===92){if(m+=e.substring(O,r),r++,r>=n){f=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-edmvhW9F.js","assets/react-vendor-BmQ2Ko_D.js","assets/editor-monaco-json-CAlvfPc7.js","assets/index-DLlW4q4v.js","assets/query-vendor--rhYD8mC.js","assets/radix-ui-DFNP5I4e.js","assets/ui-vendor-DpjQWJgX.js","assets/monaco-editor-DJsdM0WK.js","assets/state-vendor-Cq67_JbF.js","assets/index-CNvLzaJ7.css","assets/editor-refs-store-DKOJcTAk.js","assets/MonacoPluginProvider-CE5NPGwN.js","assets/preview-zo-CHAU0.js"])))=>i.map(i=>d[i]);
2
+ var Wm=Object.defineProperty;var qm=(e,t,n)=>t in e?Wm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var nl=(e,t,n)=>qm(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as je,R as Zc,g as lo}from"./react-vendor-BmQ2Ko_D.js";import{b as Vc,c as uo,d as Uc,e as ys,f as bs,D as vs,O as ws,g as Gm,V as Ym,G as Km,h as Jc,I as Xm,i as Qm,j as Hc,k as eg,l as Wc,m as tg,n as ng,L as qc,S as Gc,o as Yc,p as Kc,q as Xc,r as kr,s as rg,t as ig,u as sg,v as Qc,w as ed,x as td,y as nd,z as rd,B as id,E as sd,F as ad,H as od,J as ag,K as og,M as lg,N as ld,Q as ud,U as cd,W as dd,X as fd,Y as pd,Z as hd,_ as md,$ as gd,a0 as xd,a1 as ug,a2 as yd,a3 as cg,a4 as dg,a5 as bd,a6 as fg,a7 as pg,a8 as hg,a9 as mg,aa as vd,ab as wd,ac as kd}from"./radix-ui-DFNP5I4e.js";import{c as G,u as Sr,S as gn,A as ei,T as _i,C as gg,E as xg,F as ht,a as yg,b as bg,d as Ge,e as Ye,f as Ke,g as Sd,_ as _d,h as ji,i as vg,j as wg,k as kg,l as Tr,s as Vs,W as jd,m as $i}from"./index-DLlW4q4v.js";import{X as yn,C as mi,a as an,b as Sg,d as gi,G as Nd,F as _g,e as _r,f as Ed,P as jg,g as Ng,h as Cd,E as Td,B as Sa,H as Eg,T as _a,L as ja,i as Cg,j as Tg,S as Id,I as Ig,k as Ag,l as Na,m as zg,n as Og,o as Pg,p as Dg,q as Rg,r as Mg,s as $g,t as Fg,u as ks,v as Lg,M as Bg,w as nn,x as Ad,y as Zg,z as Vg,A as zd,D as Ug,J as Jg,K as Hg,N as Wg,O as qg,Q as Od,R as Gg,U as Ea,V as co,W as Pd,Y as Yg,Z as Dd,_ as Fr,$ as Kg,a0 as Xg,a1 as Qg,a2 as rl,a3 as Ca}from"./ui-vendor-DpjQWJgX.js";import{B as Se,u as ex,d as il}from"./editor-refs-store-DKOJcTAk.js";import{u as Ne,i as tx,a as Ta,b as rn,g as nx,c as Lt,T as Rd,d as Hi,S as rx,O as ix,e as sx,M as ax,D as ox}from"./MonacoPluginProvider-CE5NPGwN.js";import{u as fo,a as lx,d as ux,p as cx,b as dx,e as fx}from"./state-vendor-Cq67_JbF.js";import{b as px}from"./query-vendor--rhYD8mC.js";const Ct=Vc,hx=Uc,sl=uo,Md=x.forwardRef(({className:e,...t},n)=>u.jsx(ws,{ref:n,className:G("fixed inset-0 z-50 bg-black/50",e),...t}));Md.displayName=ws.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hx,{children:[u.jsx(Md,{}),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(uo,{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=Gm,$d=Km,ni=Ym,fr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Jc,{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(Xm,{asChild:!0,children:u.jsx(mi,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));fr.displayName=Jc.displayName;const Fd=x.forwardRef(({className:e,...t},n)=>u.jsx(Gc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Sg,{className:"h-4 w-4"})}));Fd.displayName=Gc.displayName;const Ld=x.forwardRef(({className:e,...t},n)=>u.jsx(Yc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(mi,{className:"h-4 w-4"})}));Ld.displayName=Yc.displayName;const pr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(Qm,{children:u.jsxs(Hc,{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(Fd,{}),u.jsx(eg,{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(Ld,{})]})}));pr.displayName=Hc.displayName;const po=x.forwardRef(({className:e,...t},n)=>u.jsx(qc,{ref:n,className:G("px-2 py-1.5 text-sm font-semibold",e),...t}));po.displayName=qc.displayName;const Pn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Wc,{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(tg,{children:u.jsx(an,{className:"h-4 w-4"})})}),u.jsx(ng,{children:t})]}));Pn.displayName=Wc.displayName;const mx=x.forwardRef(({className:e,...t},n)=>u.jsx(Kc,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));mx.displayName=Kc.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 gx=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(Xc,{ref:n,className:G(gx(),e),...t}));Wr.displayName=Xc.displayName;const xx=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(xx({variant:t}),e),...n})}const yx=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Ne(fo(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),{toast:o}=Sr(),l=x.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[c,d]=x.useState(""),[f,h]=x.useState(""),[p,g]=x.useState("playground"),[v,_]=x.useState(!1),[b,E]=x.useState(null),[m,O]=x.useState(null),[N,w]=x.useState(null),k=()=>{E(null),O(null),w(null)};x.useEffect(()=>{if(!e)return;E(null),O(null),w(null);const T=l.map(P=>P.name),z=T.includes(i)?i:T[0]??"";h(z),d(T.find(P=>P!==z)??"")},[e]);const R=async()=>{const T=l.find(P=>P.name===c),z=l.find(P=>P.name===f);if(!(!T||!z)){_(!0),E(null),O(null),w(null);try{const P=await fetch(ei.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:T.text,newDefinition:z.text,options:{author:p||"playground"}})}),I=await P.json();if(!P.ok||!I.success){const M=Array.isArray(I.errors)?`: ${I.errors.slice(0,3).map(J=>J.message||String(J)).join("; ")}`:"";throw new Error((I.error||`Diff failed (${P.status})`)+M)}O(I.data.summary),w(I.data.document)}catch(P){E(P instanceof Error?P.message:"Diff failed")}finally{_(!1)}}},q=()=>{if(!N)return;const T=new Set(n.map(I=>I.name));let z=`${f}-redline`,P=2;for(;T.has(z);)z=`${f}-redline-${P++}`;s(z,JSON.stringify(N,null,2)),a(z),o({title:`Redline created: ${z}`}),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(Nd,{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:T=>{d(T),k()},children:[u.jsx(fr,{id:"diff-base",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(T=>u.jsx(Pn,{value:T.name,children:T.name},T.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Wr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(ti,{value:f,onValueChange:T=>{h(T),k()},children:[u.jsx(fr,{id:"diff-revised",children:u.jsx(ni,{placeholder:"Select document"})}),u.jsx(pr,{children:l.map(T=>u.jsx(Pn,{value:T.name,children:T.name},T.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:T=>{g(T.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((T,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},z))]}),m.notes.map((T,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},z))]})]}),u.jsx(bn,{children:m&&j+m.untracked.length>0?u.jsxs(Se,{onClick:q,children:[u.jsx(_g,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Se,{onClick:R,disabled:v||!c||!f||c===f,children:[v&&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 Bd=e=>typeof e=="object";var Qe=e=>!ft(e)&&!Array.isArray(e)&&Bd(e)&&!In(e),Zd=e=>Qe(e)&&e.target?xi(e.target)?e.target.checked:e.target.value:e,bx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Vd=(e,t)=>e.has(bx(t)),vx=e=>{const t=e.constructor&&e.constructor.prototype;return Qe(t)&&t.hasOwnProperty("isPrototypeOf")},ho=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(!(ho&&(e instanceof Blob||r))&&(n||Qe(e)))if(t=n?[]:{},!n&&!vx(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):[],Xe=e=>e===void 0,ce=(e,t,n)=>{if(!t||!Qe(e))return n;const r=Ss(t.split(/[,[\].]+?/)).reduce((i,s)=>ft(i)?i:i[s],e);return Xe(r)||r===e?Xe(e[t])?n:e[t]:r},zt=e=>typeof e=="boolean",mo=e=>/^\w*$/.test(e),Ud=e=>Ss(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Me=(e,t,n)=>{let r=-1;const i=mo(t)?[t]:Ud(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=Qe(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"},Jd=je.createContext(null),_s=()=>je.useContext(Jd),wx=e=>{const{children:t,...n}=e;return je.createElement(Jd.Provider,{value:n},t)};var Hd=(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=>Qe(e)&&!Object.keys(e).length,Wd=(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],qd=(e,t,n)=>!e||!t||e===t||qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function go(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 kx(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}),d=je.useRef(i);return d.current=i,go({disabled:r,next:f=>l.current&&qd(d.current,f.name,s)&&Wd(f,c.current,n._updateFormState)&&o({...n._formState,...f}),subject:n._subjects.state}),je.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),je.useMemo(()=>Hd(a,n,c.current,!1),[a,n])}var Yt=e=>typeof e=="string",Gd=(e,t,n,r,i)=>Yt(e)?(r&&t.watch.add(e),ce(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),ce(n,s))):(r&&(t.watchAll=!0),n);function Sx(e){const t=_s(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=je.useRef(r);o.current=r,go({disabled:s,subject:n._subjects.values,next:d=>{qd(o.current,d.name,a)&&c(yt(Gd(o.current,n._names,d.values||n._formValues,!1,i)))}});const[l,c]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),l}function _x(e){const t=_s(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=Vd(i._names.array,n),o=Sx({control:i,name:n,defaultValue:ce(i._formValues,n,ce(i._defaultValues,n,e.defaultValue)),exact:!0}),l=kx({control:i,name:n,exact:!0}),c=je.useRef(i.register(n,{...e.rules,value:o,...zt(e.disabled)?{disabled:e.disabled}:{}})),d=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ce(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!ce(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ce(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ce(l.validatingFields,n)},error:{enumerable:!0,get:()=>ce(l.errors,n)}}),[l,n]),f=je.useMemo(()=>({name:n,value:o,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:h=>c.current.onChange({target:{value:Zd(h),name:n},type:Wi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:ce(i._formValues,n),name:n},type:Wi.BLUR}),ref:h=>{const p=ce(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,v)=>{const _=ce(i._fields,g);_&&_._f&&(_._f.mount=v)};if(p(n,!0),h){const g=yt(ce(i._options.defaultValues,n));Me(i._defaultValues,n,g),Xe(ce(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:f,formState:l,fieldState:d}),[f,l,d])}const jx=e=>e.render(_x(e));var Nx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},al=e=>({isOnSubmit:!e||e===Ft.onSubmit,isOnBlur:e===Ft.onBlur,isOnChange:e===Ft.onChange,isOnAll:e===Ft.all,isOnTouch:e===Ft.onTouched}),ol=(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=ce(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(Qe(o)&&Gr(o,t))break}}};var Ex=(e,t,n)=>{const r=qr(ce(e,n));return Me(r,"root",t[n]),Me(e,n,r),e},xo=e=>e.type==="file",Gt=e=>typeof e=="function",qi=e=>{if(!ho)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Fi=e=>Yt(e),yo=e=>e.type==="radio",Gi=e=>e instanceof RegExp;const ll={value:!1,isValid:!1},ul={value:!0,isValid:!0};var Yd=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&&!Xe(e[0].attributes.value)?Xe(e[0].value)||e[0].value===""?ul:{value:e[0].value,isValid:!0}:ul:ll}return ll};const cl={isValid:!1,value:null};var Kd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,cl):cl;function dl(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=>Qe(e)&&!Gi(e)?e:{value:e,message:""},fl=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:d,min:f,max:h,pattern:p,validate:g,name:v,valueAsNumber:_,mount:b}=e._f,E=ce(n,v);if(!b||t.has(v))return{};const m=o?o[0]:a,O=z=>{i&&m.reportValidity&&(m.setCustomValidity(zt(z)?"":z||""),m.reportValidity())},N={},w=yo(a),k=xi(a),R=w||k,q=(_||xo(a))&&Xe(a.value)&&Xe(E)||qi(a)&&a.value===""||E===""||Array.isArray(E)&&!E.length,j=Nx.bind(null,v,r,N),T=(z,P,I,M=tn.maxLength,J=tn.minLength)=>{const Z=z?P:I;N[v]={type:z?M:J,message:Z,ref:a,...j(z?M:J,Z)}};if(s?!Array.isArray(E)||!E.length:l&&(!R&&(q||ft(E))||zt(E)&&!E||k&&!Yd(o).isValid||w&&!Kd(o).isValid)){const{value:z,message:P}=Fi(l)?{value:!!l,message:l}:Ln(l);if(z&&(N[v]={type:tn.required,message:P,ref:m,...j(tn.required,P)},!r))return O(P),N}if(!q&&(!ft(f)||!ft(h))){let z,P;const I=Ln(h),M=Ln(f);if(!ft(E)&&!isNaN(E)){const J=a.valueAsNumber||E&&+E;ft(I.value)||(z=J>I.value),ft(M.value)||(P=J<M.value)}else{const J=a.valueAsDate||new Date(E),Z=S=>new Date(new Date().toDateString()+" "+S),V=a.type=="time",ne=a.type=="week";Yt(I.value)&&E&&(z=V?Z(E)>Z(I.value):ne?E>I.value:J>new Date(I.value)),Yt(M.value)&&E&&(P=V?Z(E)<Z(M.value):ne?E<M.value:J<new Date(M.value))}if((z||P)&&(T(!!z,I.message,M.message,tn.max,tn.min),!r))return O(N[v].message),N}if((c||d)&&!q&&(Yt(E)||s&&Array.isArray(E))){const z=Ln(c),P=Ln(d),I=!ft(z.value)&&E.length>+z.value,M=!ft(P.value)&&E.length<+P.value;if((I||M)&&(T(I,z.message,P.message),!r))return O(N[v].message),N}if(p&&!q&&Yt(E)){const{value:z,message:P}=Ln(p);if(Gi(z)&&!E.match(z)&&(N[v]={type:tn.pattern,message:P,ref:a,...j(tn.pattern,P)},!r))return O(P),N}if(g){if(Gt(g)){const z=await g(E,n),P=dl(z,m);if(P&&(N[v]={...P,...j(tn.validate,P.message)},!r))return O(P.message),N}else if(Qe(g)){let z={};for(const P in g){if(!bt(z)&&!r)break;const I=dl(await g[P](E,n),m,P);I&&(z={...I,...j(P,I.message)},O(I.message),r&&(N[v]=z))}if(!bt(z)&&(N[v]={ref:m,...z},!r))return N}}return O(!0),N};function Cx(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Xe(e)?r++:e[t[r++]];return e}function Tx(e){for(const t in e)if(e.hasOwnProperty(t)&&!Xe(e[t]))return!1;return!0}function it(e,t){const n=Array.isArray(t)?t:mo(t)?[t]:Ud(t),r=n.length===1?e:Cx(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(Qe(r)&&bt(r)||Array.isArray(r)&&Tx(r))&&it(e,n.slice(0,-1)),e}var Us=()=>{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=[]}}},Ia=e=>ft(e)||!Bd(e);function hn(e,t){if(Ia(e)||Ia(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)||Qe(s)&&Qe(a)||Array.isArray(s)&&Array.isArray(a)?!hn(s,a):s!==a)return!1}}return!0}var Xd=e=>e.type==="select-multiple",Ix=e=>yo(e)||xi(e),Js=e=>qi(e)&&e.isConnected,Qd=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Yi(e,t={}){const n=Array.isArray(e);if(Qe(e)||n)for(const r in e)Array.isArray(e[r])||Qe(e[r])&&!Qd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Yi(e[r],t[r])):ft(e[r])||(t[r]=!0);return t}function ef(e,t,n){const r=Array.isArray(e);if(Qe(e)||r)for(const i in e)Array.isArray(e[i])||Qe(e[i])&&!Qd(e[i])?Xe(t)||Ia(n[i])?n[i]=Array.isArray(e[i])?Yi(e[i],[]):{...Yi(e[i])}:ef(e[i],ft(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Ir=(e,t)=>ef(e,t,Yi(t)),tf=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Xe(e)?e:t?e===""?NaN:e&&+e:n&&Yt(e)?new Date(e):r?r(e):e;function Hs(e){const t=e.ref;return xo(t)?t.files:yo(t)?Kd(e.refs).value:Xd(t)?[...t.selectedOptions].map(({value:n})=>n):xi(t)?Yd(e.refs).value:tf(Xe(t.value)?e.ref.value:t.value,e)}var Ax=(e,t,n,r)=>{const i={};for(const s of e){const a=ce(t,s);a&&Me(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Ar=e=>Xe(e)?e:Gi(e)?e.source:Qe(e)?Gi(e.value)?e.value.source:e.value:e;const pl="AsyncFunction";var zx=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===pl||Qe(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===pl)),Ox=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function hl(e,t,n){const r=ce(e,n);if(r||mo(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=ce(t,s),o=ce(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 Px=(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,Dx=(e,t)=>!Ss(ce(e,t)).length&&it(e,t);const Rx={mode:Ft.onSubmit,reValidateMode:Ft.onChange,shouldFocusError:!0};function Mx(e={}){let t={...Rx,...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=Qe(t.defaultValues)||Qe(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 d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Us(),array:Us(),state:Us()},h=al(t.mode),p=al(t.reValidateMode),g=t.criteriaMode===Ft.all,v=C=>$=>{clearTimeout(c),c=setTimeout(C,$)},_=async C=>{if(!t.disabled&&(d.isValid||C)){const $=t.resolver?bt((await R()).errors):await j(r,!0);$!==n.isValid&&f.state.next({isValid:$})}},b=(C,$)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((C||Array.from(o.mount)).forEach(U=>{U&&($?Me(n.validatingFields,U,$):it(n.validatingFields,U))}),f.state.next({validatingFields:n.validatingFields,isValidating:!bt(n.validatingFields)}))},E=(C,$=[],U,se,A=!0,K=!0)=>{if(se&&U&&!t.disabled){if(a.action=!0,K&&Array.isArray(ce(r,C))){const ee=U(ce(r,C),se.argA,se.argB);A&&Me(r,C,ee)}if(K&&Array.isArray(ce(n.errors,C))){const ee=U(ce(n.errors,C),se.argA,se.argB);A&&Me(n.errors,C,ee),Dx(n.errors,C)}if(d.touchedFields&&K&&Array.isArray(ce(n.touchedFields,C))){const ee=U(ce(n.touchedFields,C),se.argA,se.argB);A&&Me(n.touchedFields,C,ee)}d.dirtyFields&&(n.dirtyFields=Ir(i,s)),f.state.next({name:C,isDirty:z(C,$),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Me(s,C,$)},m=(C,$)=>{Me(n.errors,C,$),f.state.next({errors:n.errors})},O=C=>{n.errors=C,f.state.next({errors:n.errors,isValid:!1})},N=(C,$,U,se)=>{const A=ce(r,C);if(A){const K=ce(s,C,Xe(U)?ce(i,C):U);Xe(K)||se&&se.defaultChecked||$?Me(s,C,$?K:Hs(A._f)):M(C,K),a.mount&&_()}},w=(C,$,U,se,A)=>{let K=!1,ee=!1;const xe={name:C};if(!t.disabled){const L=!!(ce(r,C)&&ce(r,C)._f&&ce(r,C)._f.disabled);if(!U||se){d.isDirty&&(ee=n.isDirty,n.isDirty=xe.isDirty=z(),K=ee!==xe.isDirty);const Q=L||hn(ce(i,C),$);ee=!!(!L&&ce(n.dirtyFields,C)),Q||L?it(n.dirtyFields,C):Me(n.dirtyFields,C,!0),xe.dirtyFields=n.dirtyFields,K=K||d.dirtyFields&&ee!==!Q}if(U){const Q=ce(n.touchedFields,C);Q||(Me(n.touchedFields,C,U),xe.touchedFields=n.touchedFields,K=K||d.touchedFields&&Q!==U)}K&&A&&f.state.next(xe)}return K?xe:{}},k=(C,$,U,se)=>{const A=ce(n.errors,C),K=d.isValid&&zt($)&&n.isValid!==$;if(t.delayError&&U?(l=v(()=>m(C,U)),l(t.delayError)):(clearTimeout(c),l=null,U?Me(n.errors,C,U):it(n.errors,C)),(U?!hn(A,U):A)||!bt(se)||K){const ee={...se,...K&&zt($)?{isValid:$}:{},errors:n.errors,name:C};n={...n,...ee},f.state.next(ee)}},R=async C=>{b(C,!0);const $=await t.resolver(s,t.context,Ax(C||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(C),$},q=async C=>{const{errors:$}=await R(C);if(C)for(const U of C){const se=ce($,U);se?Me(n.errors,U,se):it(n.errors,U)}else n.errors=$;return $},j=async(C,$,U={valid:!0})=>{for(const se in C){const A=C[se];if(A){const{_f:K,...ee}=A;if(K){const xe=o.array.has(K.name),L=A._f&&zx(A._f);L&&d.validatingFields&&b([se],!0);const Q=await fl(A,o.disabled,s,g,t.shouldUseNativeValidation&&!$,xe);if(L&&d.validatingFields&&b([se]),Q[K.name]&&(U.valid=!1,$))break;!$&&(ce(Q,K.name)?xe?Ex(n.errors,Q,K.name):Me(n.errors,K.name,Q[K.name]):it(n.errors,K.name))}!bt(ee)&&await j(ee,$,U)}}return U.valid},T=()=>{for(const C of o.unMount){const $=ce(r,C);$&&($._f.refs?$._f.refs.every(U=>!Js(U)):!Js($._f.ref))&&Y(C)}o.unMount=new Set},z=(C,$)=>!t.disabled&&(C&&$&&Me(s,C,$),!hn(le(),i)),P=(C,$,U)=>Gd(C,o,{...a.mount?s:Xe($)?i:Yt(C)?{[C]:$}:$},U,$),I=C=>Ss(ce(a.mount?s:i,C,t.shouldUnregister?ce(i,C,[]):[])),M=(C,$,U={})=>{const se=ce(r,C);let A=$;if(se){const K=se._f;K&&(!K.disabled&&Me(s,C,tf($,K)),A=qi(K.ref)&&ft($)?"":$,Xd(K.ref)?[...K.ref.options].forEach(ee=>ee.selected=A.includes(ee.value)):K.refs?xi(K.ref)?K.refs.length>1?K.refs.forEach(ee=>(!ee.defaultChecked||!ee.disabled)&&(ee.checked=Array.isArray(A)?!!A.find(xe=>xe===ee.value):A===ee.value)):K.refs[0]&&(K.refs[0].checked=!!A):K.refs.forEach(ee=>ee.checked=ee.value===A):xo(K.ref)?K.ref.value="":(K.ref.value=A,K.ref.type||f.values.next({name:C,values:{...s}})))}(U.shouldDirty||U.shouldTouch)&&w(C,A,U.shouldTouch,U.shouldDirty,!0),U.shouldValidate&&S(C)},J=(C,$,U)=>{for(const se in $){const A=$[se],K=`${C}.${se}`,ee=ce(r,K);(o.array.has(C)||Qe(A)||ee&&!ee._f)&&!In(A)?J(K,A,U):M(K,A,U)}},Z=(C,$,U={})=>{const se=ce(r,C),A=o.array.has(C),K=yt($);Me(s,C,K),A?(f.array.next({name:C,values:{...s}}),(d.isDirty||d.dirtyFields)&&U.shouldDirty&&f.state.next({name:C,dirtyFields:Ir(i,s),isDirty:z(C,K)})):se&&!se._f&&!ft(K)?J(C,K,U):M(C,K,U),ol(C,o)&&f.state.next({...n}),f.values.next({name:a.mount?C:void 0,values:{...s}})},V=async C=>{a.mount=!0;const $=C.target;let U=$.name,se=!0;const A=ce(r,U),K=()=>$.type?Hs(A._f):Zd(C),ee=xe=>{se=Number.isNaN(xe)||In(xe)&&isNaN(xe.getTime())||hn(xe,ce(s,U,xe))};if(A){let xe,L;const Q=K(),he=C.type===Wi.BLUR||C.type===Wi.FOCUS_OUT,ve=!Ox(A._f)&&!t.resolver&&!ce(n.errors,U)&&!A._f.deps||Px(he,ce(n.touchedFields,U),n.isSubmitted,p,h),F=ol(U,o,he);Me(s,U,Q),he?(A._f.onBlur&&A._f.onBlur(C),l&&l(0)):A._f.onChange&&A._f.onChange(C);const me=w(U,Q,he,!1),Te=!bt(me)||F;if(!he&&f.values.next({name:U,type:C.type,values:{...s}}),ve)return d.isValid&&(t.mode==="onBlur"&&he?_():he||_()),Te&&f.state.next({name:U,...F?{}:me});if(!he&&F&&f.state.next({...n}),t.resolver){const{errors:Le}=await R([U]);if(ee(Q),se){const rt=hl(n.errors,r,U),et=hl(Le,r,rt.name||U);xe=et.error,U=et.name,L=bt(Le)}}else b([U],!0),xe=(await fl(A,o.disabled,s,g,t.shouldUseNativeValidation))[U],b([U]),ee(Q),se&&(xe?L=!1:d.isValid&&(L=await j(r,!0)));se&&(A._f.deps&&S(A._f.deps),k(U,L,xe,me))}},ne=(C,$)=>{if(ce(n.errors,$)&&C.focus)return C.focus(),1},S=async(C,$={})=>{let U,se;const A=qr(C);if(t.resolver){const K=await q(Xe(C)?C:A);U=bt(K),se=C?!A.some(ee=>ce(K,ee)):U}else C?(se=(await Promise.all(A.map(async K=>{const ee=ce(r,K);return await j(ee&&ee._f?{[K]:ee}:ee)}))).every(Boolean),!(!se&&!n.isValid)&&_()):se=U=await j(r);return f.state.next({...!Yt(C)||d.isValid&&U!==n.isValid?{}:{name:C},...t.resolver||!C?{isValid:U}:{},errors:n.errors}),$.shouldFocus&&!se&&Gr(r,ne,C?A:o.mount),se},le=C=>{const $={...a.mount?s:i};return Xe(C)?$:Yt(C)?ce($,C):C.map(U=>ce($,U))},B=(C,$)=>({invalid:!!ce(($||n).errors,C),isDirty:!!ce(($||n).dirtyFields,C),error:ce(($||n).errors,C),isValidating:!!ce(n.validatingFields,C),isTouched:!!ce(($||n).touchedFields,C)}),y=C=>{C&&qr(C).forEach($=>it(n.errors,$)),f.state.next({errors:C?n.errors:{}})},W=(C,$,U)=>{const se=(ce(r,C,{_f:{}})._f||{}).ref,A=ce(n.errors,C)||{},{ref:K,message:ee,type:xe,...L}=A;Me(n.errors,C,{...L,...$,ref:se}),f.state.next({name:C,errors:n.errors,isValid:!1}),U&&U.shouldFocus&&se&&se.focus&&se.focus()},X=(C,$)=>Gt(C)?f.values.subscribe({next:U=>C(P(void 0,$),U)}):P(C,$,!0),Y=(C,$={})=>{for(const U of C?qr(C):o.mount)o.mount.delete(U),o.array.delete(U),$.keepValue||(it(r,U),it(s,U)),!$.keepError&&it(n.errors,U),!$.keepDirty&&it(n.dirtyFields,U),!$.keepTouched&&it(n.touchedFields,U),!$.keepIsValidating&&it(n.validatingFields,U),!t.shouldUnregister&&!$.keepDefaultValue&&it(i,U);f.values.next({values:{...s}}),f.state.next({...n,...$.keepDirty?{isDirty:z()}:{}}),!$.keepIsValid&&_()},re=({disabled:C,name:$,field:U,fields:se})=>{(zt(C)&&a.mount||C||o.disabled.has($))&&(C?o.disabled.add($):o.disabled.delete($),w($,Hs(U?U._f:ce(se,$)._f),!1,!1,!0))},D=(C,$={})=>{let U=ce(r,C);const se=zt($.disabled)||zt(t.disabled);return Me(r,C,{...U||{},_f:{...U&&U._f?U._f:{ref:{name:C}},name:C,mount:!0,...$}}),o.mount.add(C),U?re({field:U,disabled:zt($.disabled)?$.disabled:t.disabled,name:C}):N(C,!0,$.value),{...se?{disabled:$.disabled||t.disabled}:{},...t.progressive?{required:!!$.required,min:Ar($.min),max:Ar($.max),minLength:Ar($.minLength),maxLength:Ar($.maxLength),pattern:Ar($.pattern)}:{},name:C,onChange:V,onBlur:V,ref:A=>{if(A){D(C,$),U=ce(r,C);const K=Xe(A.value)&&A.querySelectorAll&&A.querySelectorAll("input,select,textarea")[0]||A,ee=Ix(K),xe=U._f.refs||[];if(ee?xe.find(L=>L===K):K===U._f.ref)return;Me(r,C,{_f:{...U._f,...ee?{refs:[...xe.filter(Js),K,...Array.isArray(ce(i,C))?[{}]:[]],ref:{type:K.type,name:C}}:{ref:K}}}),N(C,!1,void 0,K)}else U=ce(r,C,{}),U._f&&(U._f.mount=!1),(t.shouldUnregister||$.shouldUnregister)&&!(Vd(o.array,C)&&a.action)&&o.unMount.add(C)}}},de=()=>t.shouldFocusError&&Gr(r,ne,o.mount),te=C=>{zt(C)&&(f.state.next({disabled:C}),Gr(r,($,U)=>{const se=ce(r,U);se&&($.disabled=se._f.disabled||C,Array.isArray(se._f.refs)&&se._f.refs.forEach(A=>{A.disabled=se._f.disabled||C}))},0,!1))},ae=(C,$)=>async U=>{let se;U&&(U.preventDefault&&U.preventDefault(),U.persist&&U.persist());let A=yt(s);if(o.disabled.size)for(const K of o.disabled)Me(A,K,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:K,values:ee}=await R();n.errors=K,A=ee}else await j(r);if(it(n.errors,"root"),bt(n.errors)){f.state.next({errors:{}});try{await C(A,U)}catch(K){se=K}}else $&&await $({...n.errors},U),de(),setTimeout(de);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bt(n.errors)&&!se,submitCount:n.submitCount+1,errors:n.errors}),se)throw se},ue=(C,$={})=>{ce(r,C)&&(Xe($.defaultValue)?Z(C,yt(ce(i,C))):(Z(C,$.defaultValue),Me(i,C,yt($.defaultValue))),$.keepTouched||it(n.touchedFields,C),$.keepDirty||(it(n.dirtyFields,C),n.isDirty=$.defaultValue?z(C,yt(ce(i,C))):z()),$.keepError||(it(n.errors,C),d.isValid&&_()),f.state.next({...n}))},ge=(C,$={})=>{const U=C?yt(C):i,se=yt(U),A=bt(C),K=A?i:se;if($.keepDefaultValues||(i=U),!$.keepValues){if($.keepDirtyValues){const ee=new Set([...o.mount,...Object.keys(Ir(i,s))]);for(const xe of Array.from(ee))ce(n.dirtyFields,xe)?Me(K,xe,ce(s,xe)):Z(xe,ce(K,xe))}else{if(ho&&Xe(C))for(const ee of o.mount){const xe=ce(r,ee);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?$.keepDefaultValues?yt(i):{}:yt(K),f.array.next({values:{...K}}),f.values.next({values:{...K}})}o={mount:$.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!d.isValid||!!$.keepIsValid||!!$.keepDirtyValues,a.watch=!!t.shouldUnregister,f.state.next({submitCount:$.keepSubmitCount?n.submitCount:0,isDirty:A?!1:$.keepDirty?n.isDirty:!!($.keepDefaultValues&&!hn(C,i)),isSubmitted:$.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:A?{}:$.keepDirtyValues?$.keepDefaultValues&&s?Ir(i,s):n.dirtyFields:$.keepDefaultValues&&C?Ir(i,C):$.keepDirty?n.dirtyFields:{},touchedFields:$.keepTouched?n.touchedFields:{},errors:$.keepErrors?n.errors:{},isSubmitSuccessful:$.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},pe=(C,$)=>ge(Gt(C)?C(s):C,$);return{control:{register:D,unregister:Y,getFieldState:B,handleSubmit:ae,setError:W,_executeSchema:R,_getWatch:P,_getDirty:z,_updateValid:_,_removeUnmounted:T,_updateFieldArray:E,_updateDisabledField:re,_getFieldArray:I,_reset:ge,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(C=>{pe(C,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:C=>{n={...n,...C}},_disableForm:te,_subjects:f,_proxyFormState:d,_setErrors:O,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(C){a=C},get _defaultValues(){return i},get _names(){return o},set _names(C){o=C},get _formState(){return n},set _formState(C){n=C},get _options(){return t},set _options(C){t={...t,...C}}},trigger:S,register:D,handleSubmit:ae,watch:X,setValue:Z,getValues:le,reset:pe,resetField:ue,clearErrors:y,unregister:Y,setError:W,setFocus:(C,$={})=>{const U=ce(r,C),se=U&&U._f;if(se){const A=se.refs?se.refs[0]:se.ref;A.focus&&(A.focus(),$.shouldSelect&&Gt(A.select)&&A.select())}},getFieldState:B}}function $x(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={...Mx(e),formState:r});const s=t.current.control;return s._options=e,go({subject:s._subjects.state,next:a=>{Wd(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=Hd(r,s),t.current}function Fx(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 Lx=wx,nf=x.createContext({}),ml=({...e})=>u.jsx(nf.Provider,{value:{name:e.name},children:u.jsx(jx,{...e})}),js=()=>{const e=x.useContext(nf),t=x.useContext(rf),{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}},rf=x.createContext({}),Aa=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(rf.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:G("space-y-2",e),...t})})});Aa.displayName="FormItem";const za=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})});za.displayName="FormLabel";const Oa=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})});Oa.displayName="FormControl";const sf=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})});sf.displayName="FormDescription";const Pa=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});Pa.displayName="FormMessage";function bo(){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 af=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Bx=(e=af())=>lx()(ux(cx((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:bo(),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(d=>d.documentName===o);c.length>0?(c.sort((d,f)=>f.updatedAt-d.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:dx(()=>tx),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}}))),of=x.createContext(void 0),Zx=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Bx(af())),u.jsx(of.Provider,{value:t.current,children:e})},Oe=e=>{const t=x.useContext(of);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return fx(t,e)};function Vx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Ux(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(!gg(s,a))for(const c of xg(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 Jx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Hx=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 Wx({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=x.useState(!1),[c,d]=x.useState(null),[f,h]=x.useState("idle"),{toast:p}=Sr(),g=Hx(a),{documents:v,openTabs:_,createDocument:b,renameDocument:E,deleteDocument:m,openDocument:O,closeDocument:N}=Ne(le=>le),{updateTheme:w,removeTheme:k}=Ta(le=>le),R=Oe(le=>le.renameThreadsForDocument),q=Oe(le=>le.deleteThreadsForDocument),j=x.useMemo(()=>a?s||[]:i||[],[a,i,s]),T=x.useMemo(()=>{const le={current:[],downstream:[]};return j.forEach(B=>{le[B.location]&&le[B.location].push(B)}),le},[j]),z=x.useMemo(()=>j.map(le=>({name:le.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[j]),P=x.useMemo(()=>Ux(e,le=>Vx(le,v,r),z),[e,v,r,z]),I=P.schema,M=x.useMemo(()=>{const le=new Map;return j.forEach(B=>le.set(B.path,B)),le},[j]),J=Bn,Z=$x({resolver:Fx(P.validate),defaultValues:Jx(e,void 0,r)}),[V,ne]=x.useState(J);x.useEffect(()=>{if(V&&V!==Bn&&e==="create"){const le=M.get(V);if(le){d(null),h("loading");let B=!1;return fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(le.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 W=JSON.parse(y);d(JSON.stringify(W,null,2)),h("idle")}).catch(y=>{B||(console.error("Failed to copy template:",y),d(null),h("error"))}),()=>{B=!0}}}h("idle")},[V,e,M,a]),x.useEffect(()=>{t&&(Z.reset(),d(null),h("idle"),ne(J))},[Z,t]);const S=Z.handleSubmit(async({name:le,template:B})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=V?M.get(V):j.find(ue=>ue.name===B);let W,X=le;if(!!V&&V!==Bn&&c===null){p({title:f==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:f==="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 ue=X.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),ge=ht==="docx"?yg(ue):{name:ue,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};W=c||JSON.stringify(ge,null,2);const pe=`.${ht}.theme.json`;X.endsWith(pe)||(X=X.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),X+=pe)}else{const ue=y;W=c||JSON.stringify(ht==="docx"?{name:"docx",props:{theme:(ue==null?void 0:ue.theme)||"default",metadata:{title:(ue==null?void 0:ue.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:(ue==null?void 0:ue.title)||X.replace(/\.(json|js)$/i,""),theme:(ue==null?void 0:ue.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 ge=ht==="docx"?".docx.json":".pptx.json";!X.endsWith(ge)&&!X.endsWith(".json")&&(X+=ge)}const re=X.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),D=re?re[0]:"",de=X.slice(0,X.length-D.length);let te=X,ae=1;for(;v.some(ue=>ue.name===te);)ae++,te=`${de} (${ae})${D}`;X=te,b(X,W),O(X),a&&w(X,W)}else if(e==="update"){const y=r,W=le,X=_.includes(y);X&&N(y),E(y,W),R(y,W),X&&O(W)}else if(e==="delete"){const y=r;N(y),m(y),q(y),a&&k(y)}n()}finally{l(!1)}});return u.jsx(Lx,{...Z,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:[I.properties&&"name"in I.properties&&u.jsx(ml,{control:Z.control,name:"name",render:({field:le})=>u.jsxs(Aa,{children:[u.jsx(za,{children:"Name"}),u.jsx(Oa,{children:u.jsx(hr,{placeholder:"Enter a name or select a template below",autoComplete:"off",...le})}),u.jsx(Pa,{})]})}),e==="create"&&u.jsx(ml,{control:Z.control,name:"template",render:({field:le})=>u.jsxs(Aa,{children:[u.jsx(za,{children:a?"Base Theme":"Base Document"}),u.jsxs(ti,{onValueChange:B=>{if(B===Bn)le.onChange(void 0),Z.setValue("name",""),ne(Bn),d(null);else{const y=M.get(B);y&&(le.onChange(y.name),Z.setValue("name",y.name),ne(B))}},defaultValue:J,children:[u.jsx(Oa,{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(T).map(([B,y])=>y.length===0?null:u.jsxs($d,{children:[u.jsx(po,{children:B==="current"?"📁 Current Directory":"📦 Project"}),y.map(W=>{let X;return W.title&&W.title!==W.name?X=W.title:W.description&&(X=W.description.length>40?W.description.substring(0,40)+"...":W.description),u.jsx(Pn,{value:W.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:W.name}),X&&u.jsx("span",{className:"text-muted-foreground text-xs",children:X})]})},W.path)})]},B))]})]}),u.jsxs(sf,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(Pa,{})]})})]}),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(Wx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function vo({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 Da({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 gl({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 xl({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 qx=rg,Gx=ig,Yx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(nd,{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"})]}));Yx.displayName=nd.displayName;const Kx=x.forwardRef(({className:e,...t},n)=>u.jsx(rd,{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}));Kx.displayName=rd.displayName;const lf=x.forwardRef(({className:e,...t},n)=>u.jsx(sg,{children:u.jsx(Qc,{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})}));lf.displayName=Qc.displayName;const uf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(td,{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}));uf.displayName=td.displayName;const Xx=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(id,{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(sd,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));Xx.displayName=id.displayName;const Qx=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ad,{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(sd,{children:u.jsx(Ed,{className:"h-4 w-4 fill-current"})})}),t]}));Qx.displayName=ad.displayName;const ey=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(od,{ref:r,className:G("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ey.displayName=od.displayName;const cf=x.forwardRef(({className:e,...t},n)=>u.jsx(ed,{ref:n,className:G("bg-border -mx-1 my-1 h-px",e),...t}));cf.displayName=ed.displayName;const df=({className:e,...t})=>u.jsx("span",{className:G("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});df.displayName="ContextMenuShortcut";const Ns=ag,Es=og,ty=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(fd,{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"})]}));ty.displayName=fd.displayName;const ny=x.forwardRef(({className:e,...t},n)=>u.jsx(pd,{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}));ny.displayName=pd.displayName;const yi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(lg,{children:u.jsx(ld,{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=ld.displayName;const $t=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ud,{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=ud.displayName;const ry=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(hd,{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(md,{children:u.jsx(an,{className:"h-4 w-4"})})}),t]}));ry.displayName=hd.displayName;const iy=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gd,{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(md,{children:u.jsx(Ed,{className:"h-2 w-2 fill-current"})})}),t]}));iy.displayName=gd.displayName;const wo=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(dd,{ref:r,className:G("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));wo.displayName=dd.displayName;const mr=x.forwardRef(({className:e,...t},n)=>u.jsx(cd,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));mr.displayName=cd.displayName;const ff=({className:e,...t})=>u.jsx("span",{className:G("ml-auto text-xs tracking-widest opacity-60",e),...t});ff.displayName="DropdownMenuShortcut";const pf=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(xd,{ref:i,decorative:n,orientation:t,className:G("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));pf.displayName=xd.displayName;const hf=Vc,sy=ug,ay=Uc,mf=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}));mf.displayName=ws.displayName;const oy=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"}}),ko=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(ay,{children:[u.jsx(mf,{}),u.jsxs(ys,{ref:i,className:G(oy({side:e}),t),...r,children:[u.jsxs(uo,{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]})]}));ko.displayName=ys.displayName;const ly=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-foreground text-lg font-semibold",e),...t}));ly.displayName=bs.displayName;const uy=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));uy.displayName=vs.displayName;function Yr({className:e,...t}){return u.jsx("div",{className:G("bg-primary/10 animate-pulse rounded-md",e),...t})}const Ws=768,qs=1200;function gf(e){return typeof window<"u"?window.innerWidth<e:!1}function xf(){const[e,t]=x.useState(()=>gf(Ws));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ws-1}px)`),r=()=>{t(window.innerWidth<Ws)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function cy(){const[e,t]=x.useState(()=>gf(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}const dy="sidebar_state",fy=60*60*24*7,py="16rem",hy="18rem",my="3rem",gy="b",yf=x.createContext(null);function Cs(){const e=x.useContext(yf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const bf=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=xf(),[c,d]=x.useState(!1),[f,h]=x.useState(e),p=t??f,g=x.useCallback(E=>{const m=typeof E=="function"?E(p):E;n?n(m):h(m),document.cookie=`${dy}=${m}; path=/; max-age=${fy}`},[n,p]),v=x.useCallback(()=>l?d(E=>!E):g(E=>!E),[l,g,d]);x.useEffect(()=>{const E=O=>{var k;const N=O;if(!N)return!1;const w=(k=N.tagName)==null?void 0:k.toLowerCase();return w==="input"||w==="textarea"||w==="select"||N.isContentEditable?!0:!!(N.closest&&N.closest(".monaco-editor"))},m=O=>{const N=O.metaKey||O.ctrlKey,w=O.key.toLowerCase();if(N&&w===gy){O.preventDefault(),v();return}N&&w==="s"&&!E(O.target)&&(O.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const _=p?"expanded":"collapsed",b=x.useMemo(()=>({state:_,open:p,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:d,toggleSidebar:v}),[_,p,g,l,c,d,v]);return u.jsx(yf.Provider,{value:b,children:u.jsx(bg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":py,"--sidebar-width-icon":my,...i},className:G("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});bf.displayName="SidebarProvider";const vf=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:d}=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(hf,{open:c,onOpenChange:d,...s,children:u.jsx(ko,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":hy},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})})]})});vf.displayName="Sidebar";const xy=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(jg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});xy.displayName="SidebarTrigger";const yy=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})});yy.displayName="SidebarRail";const by=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}));by.displayName="SidebarInset";const vy=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}));vy.displayName="SidebarInput";const Ra=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}));Ra.displayName="SidebarHeader";const wf=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}));wf.displayName="SidebarFooter";const wy=x.forwardRef(({className:e,...t},n)=>u.jsx(pf,{ref:n,"data-sidebar":"separator",className:G("bg-sidebar-border mx-2 w-auto",e),...t}));wy.displayName="SidebarSeparator";const Ma=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}));Ma.displayName="SidebarContent";const ky=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}));ky.displayName="SidebarGroup";const Sy=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})});Sy.displayName="SidebarGroupLabel";const _y=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})});_y.displayName="SidebarGroupAction";const jy=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:G("w-full text-sm",e),...t}));jy.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 kf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:G("group/menu-item relative",e),...t}));kf.displayName="SidebarMenuItem";const Ny=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"}}),Sf=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:d}=Cs(),f=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:G(Ny({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:f}),u.jsx(Ke,{side:"right",align:"center",hidden:d!=="collapsed"||c,...i})]})):f});Sf.displayName="SidebarMenuButton";const _f=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})});_f.displayName="SidebarMenuAction";const Ey=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}));Ey.displayName="SidebarMenuBadge";const Cy=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}})]})});Cy.displayName="SidebarMenuSkeleton";const Ty=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}));Ty.displayName="SidebarMenuSub";const Iy=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Iy.displayName="SidebarMenuSubItem";const Ay=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})});Ay.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 zy=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Oy({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),[d,f]=x.useState(!1),h=Ne(B=>B.openDocument),p=Ne(B=>B.documentTypes),g=Ne(B=>B.activeTab),v=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,[N,w]=x.useState(v),[k,R]=x.useState(_),q=100,j=0;x.useEffect(()=>{const B=setTimeout(()=>{v&&_?(w(v),R(_)):b||(w(""),R(""))},b?q:j);return()=>clearTimeout(B)},[v,_,b]);const T=N===e.name,z=B=>{var W;const y=new Set;try{const X=JSON.parse(B);(W=X.props)!=null&&W.theme&&y.add(X.props.theme),X.children&&Array.isArray(X.children)&&X.children.forEach(Y=>{var re;Y.name==="docx"&&((re=Y.props)!=null&&re.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=nx(B);if(y)return z(k).has(y)}catch{}return!1},[m,k,e.text]),I=x.useCallback(()=>{c(!1)},[]),M=x.useCallback(()=>{f(!1)},[]),J=O?null:T?"preview":P?"in-use":null,Z=O?"Editing":T?"In preview":P?"Used by preview":null,V=x.useMemo(()=>[{key:"open",label:"Open",shortcut:zy?"⌘⏎":"⌃⏎",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:()=>f(!0)}],[e.name,e.text,e.type,h]),ne=m?Ng:Cd,S=i||a,le=u.jsxs(Sf,{size:"sm",ref:r,"aria-label":Z?`${e.name} — ${Z}`: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:Z?`${e.name} — ${Z}`: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"?(f(!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(vo,{text:e.name,query:n})}),t&&J&&u.jsx(gl,{tone:J,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(kf,{children:[u.jsxs(qx,{onOpenChange:s,children:[u.jsx(Gx,{className:"block",children:t?u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:le}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:Z??(m?"Theme":"Document")})]})})]}):le}),u.jsx(lf,{className:"w-44",children:V.map(B=>u.jsxs(je.Fragment,{children:[B.separatorBefore&&u.jsx(cf,{}),u.jsxs(uf,{onClick:B.run,className:G(B.danger&&"text-destructive focus:text-destructive"),children:[B.label,B.shortcut&&u.jsx(df,{children:B.shortcut})]})]},B.key))})]}),!t&&u.jsxs(u.Fragment,{children:[J&&u.jsx(gl,{tone:J,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(_f,{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(Td,{})})}),u.jsx(yi,{side:"right",align:"start",className:"w-44",children:V.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(ff,{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:I,selectedName:e.name})})}),u.jsx(Ct,{open:d,onOpenChange:f,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:!d,postSubmit:M,selectedName:e.name})})})]})}const Ni=je.memo(Oy);function Py(e,t=!1){const n=e.length;let r=0,i="",s=0,a=16,o=0,l=0,c=0,d=0,f=0;function h(m,O){let N=0,w=0;for(;N<m;){let k=e.charCodeAt(r);if(k>=48&&k<=57)w=w*16+k-48;else if(k>=65&&k<=70)w=w*16+k-65+10;else if(k>=97&&k<=102)w=w*16+k-97+10;else break;r++,N++}return N<m&&(w=-1),w}function p(m){r=m,i="",s=0,a=16,f=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 f=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 f=3;return e.substring(m,O)}function v(){let m="",O=r;for(;;){if(r>=n){m+=e.substring(O,r),f=2;break}const N=e.charCodeAt(r);if(N===34){m+=e.substring(O,r),r++;break}if(N===92){if(m+=e.substring(O,r),r++,r>=n){f=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):f=4;break;default:f=5}O=r;continue}if(N>=0&&N<=31)if(zr(N)){m+=e.substring(O,r),f=2;break}else f=6;r++}return m}function _(){if(i="",f=0,s=r,l=o,d=c,r>=n)return s=n,a=17;let m=e.charCodeAt(r);if(Gs(m)){do r++,i+=String.fromCharCode(m),m=e.charCodeAt(r);while(Gs(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=v(),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 N=n-1;let w=!1;for(;r<N;){const k=e.charCodeAt(r);if(k===42&&e.charCodeAt(r+1)===47){r+=2,w=!0;break}r++,zr(k)&&(k===13&&e.charCodeAt(r)===10&&r++,o++,c=r)}return w||(r++,f=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(Gs(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 E(){let m;do m=_();while(m>=12&&m<=15);return m}return{setPosition:p,getPosition:()=>r,scan:t?E:_,getToken:()=>a,getTokenValue:()=>i,getTokenOffset:()=>s,getTokenLength:()=>r-s,getTokenStartLine:()=>l,getTokenStartCharacter:()=>s-d,getTokenError:()=>f}}function Gs(e){return e===32||e===9}function zr(e){return e===10||e===13}function Zn(e){return e>=48&&e<=57}var yl;(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"})(yl||(yl={}));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 Dy(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}Ry(e,{onObjectBegin:l=>{r=s({type:"object",offset:l,length:-1,parent:r,children:[]})},onObjectProperty:(l,c,d)=>{r=s({type:"property",offset:c,length:-1,parent:r,children:[]}),r.children.push({type:"string",value:l,offset:c,length:d,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,d)=>{s({type:My(l),offset:c,length:d,parent:r,value:l}),i(c+d)},onSeparator:(l,c,d)=>{r.type==="property"&&(l===":"?r.colonOffset=c:l===","&&i(c))},onError:(l,c,d)=>{t.push({error:l,offset:c,length:d})}},n);const o=r.children[0];return o&&delete o.parent,o}function Ry(e,t,n=Xi.DEFAULT){const r=Py(e,!1),i=[];let s=0;function a(I){return I?()=>s===0&&I(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function o(I){return I?M=>s===0&&I(M,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function l(I){return I?M=>s===0&&I(M,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function c(I){return I?()=>{s>0?s++:I(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(s=1)}:()=>!0}function d(I){return I?()=>{s>0&&s--,s===0&&I(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}const f=c(t.onObjectBegin),h=l(t.onObjectProperty),p=d(t.onObjectEnd),g=c(t.onArrayBegin),v=d(t.onArrayEnd),_=l(t.onLiteralValue),b=o(t.onSeparator),E=a(t.onComment),m=o(t.onError),O=n&&n.disallowComments,N=n&&n.allowTrailingComma;function w(){for(;;){const I=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(I){case 12:case 13:O?k(10):E();break;case 16:k(1);break;case 15:case 14:break;default:return I}}}function k(I,M=[],J=[]){if(m(I),M.length+J.length>0){let Z=r.getToken();for(;Z!==17;){if(M.indexOf(Z)!==-1){w();break}else if(J.indexOf(Z)!==-1)break;Z=w()}}}function R(I){const M=r.getTokenValue();return I?_(M):(h(M),i.push(M)),w(),!0}function q(){switch(r.getToken()){case 11:const I=r.getTokenValue();let M=Number(I);isNaN(M)&&(k(2),M=0),_(M);break;case 7:_(null);break;case 8:_(!0);break;case 9:_(!1);break;default:return!1}return w(),!0}function j(){return r.getToken()!==10?(k(3,[],[2,5]),!1):(R(!1),r.getToken()===6?(b(":"),w(),P()||k(4,[],[2,5])):k(5,[],[2,5]),i.pop(),!0)}function T(){f(),w();let I=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(I||k(4,[],[]),b(","),w(),r.getToken()===2&&N)break}else I&&k(6,[],[]);j()||k(4,[],[2,5]),I=!0}return p(),r.getToken()!==2?k(7,[2],[]):w(),!0}function z(){g(),w();let I=!0,M=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(M||k(4,[],[]),b(","),w(),r.getToken()===4&&N)break}else M&&k(6,[],[]);I?(i.push(0),I=!1):i[i.length-1]++,P()||k(4,[],[4,5]),M=!0}return v(),I||i.pop(),r.getToken()!==4?k(8,[4],[]):w(),!0}function P(){switch(r.getToken()){case 3:return z();case 1:return T();case 10:return R(!0);default:return q()}}return w(),r.getToken()===17?n.allowEmptyContent?!0:(k(4,[],[]),!1):P()?(r.getToken()!==17&&k(9,[],[]),!0):(k(4,[],[]),!1)}function My(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 bl;(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"})(bl||(bl={}));var vl;(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"})(vl||(vl={}));const $y=Dy;var wl;(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"})(wl||(wl={}));const Fy=60,Ly=/§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 $a(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=Fy,n=!1){const r=e.replace(Ly,"…"),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 By(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 Zy(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 Vy(e,t){var r;const n=st(Ie(t,"text"));switch(e){case"heading":{const i=$a(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:By(t)};case"image":return{label:Zy(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=$a(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 Uy(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}=Vy(t.name,t.props);return r===t.name&&t.childrenArr&&(r=Uy(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:jf(t.childrenArr),reorder:n}}function jf(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 Jy(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,d=typeof(l==null?void 0:l.value)=="string"?l.value:"",f=c?gr(c):null,h=f?st(Ie(f.props,"text")):void 0;i(d==="title"?0:d==="subtitle"||d.startsWith("heading")?1:2,h)}const a=(o,l)=>{const c=gr(o);if(c){if(c.name==="text"||c.name==="heading"){const d=st(Ie(c.props,"text"));if(d){const f=st(Ie(c.props,"style"))??"";i(f==="title"?0:f.startsWith("heading")?1:2,d)}}if(l<1)for(const d of Et(c.childrenArr))a(d,l+1)}};for(const o of Et(Ie(e,"children")))a(o,0);return r?vt(r.text,48,!0):void 0}function Hy(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:Jy(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:jf(a.childrenArr),reorder:o})):r.push(Qi(s,a,o))}return r}function Wy(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 d=$a(Ie(o.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=Qi(a,o,l);c().push(f),i.push({level:d,node:f})}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 kl(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 qy(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,d=typeof(l==null?void 0:l.value)=="string"?l.value:void 0;!d||!c||a.push({id:"",kind:"key",label:d,detail:kl(c),start:o.offset,end:o.offset+o.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:a.length===0?kl(i):void 0,start:n.offset,end:n.offset+n.length,children:a})}return t}function Sl(e,t,n){if(!e.trim())return[];const r=$y(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?qy(r):t==="pptx"?Hy(r):Wy(r);return Nf(i,""),i}function Nf(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,Nf(n.children,n.id)})}function Ef(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 Gy(e,t){const n=new Set;for(const r of t)for(const i of Ef(e,r))n.add(i);return n}function Yy(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(d=>d.reorder);if(i.some(d=>!d))return null;const s=i[0].groupId;if(i.some(d=>d.groupId!==s))return null;for(let d=1;d<i.length;d++)if(i[d].sliceStart<i[d-1].sliceEnd)return null;const a=i.map(d=>e.slice(d.sliceStart,d.sliceEnd)),o=[];for(let d=1;d<i.length;d++){const f=e.slice(i[d-1].sliceEnd,i[d].sliceStart);if((f.match(/,/g)??[]).length!==1)return null;o.push(f)}const l=a.map((d,f)=>f);l.splice(r,0,l.splice(n,1)[0]);let c="";return l.forEach((d,f)=>{c+=a[d],f<o.length&&(c+=o[f])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:c}}const Ky={slide:Pg,heading:Og,text:_a,paragraph:zg,chart:Na,highcharts:Na,table:Ag,image:Ig,shape:Id,list:Tg,toc:Cg,section:ja,columns:ja,"text-box":_a,statistic:Eg,key:Sa};function Xy(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 Qy(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function eb(){const{activeTab:e,documentTypes:t}=Ne(fo(k=>({activeTab:k.activeTab,documentTypes:k.documentTypes}))),n=Ne(k=>{var R;return k.activeTab?(R=k.documents.find(q=>q.name===k.activeTab))==null?void 0:R.text:void 0}),r=ex(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,d]=x.useState(()=>new Set),[f,h]=x.useState(()=>new Set),[p,g]=x.useState(null),v=x.useRef(s);v.current=s;const _=x.useRef(null),b=x.useRef(null),E=x.useCallback(()=>{var q;if(!e){a([]);return}const k=((q=r==null?void 0:r.editor.getModel())==null?void 0:q.getValue())??n??"",R=Sl(k,ht,i);if(a(R),b.current!==e){b.current=e;const j=new Set;if(i==="document"&&ht==="docx")for(const T of R)T.kind==="heading"&&j.add(T.id);h(j),l(null)}},[e,r,n,i]);x.useEffect(()=>{E();const k=r==null?void 0:r.editor.getModel();if(!k)return;const R=il(E,300),q=k.onDidChangeContent(()=>R());return()=>{R.cancel(),q.dispose()}},[E,r]),x.useEffect(()=>{if(!r)return;const{editor:k}=r,R=il(()=>{const j=k.getModel(),T=k.getPosition();if(!j||!T)return;const z=j.getOffsetAt(T),P=Ef(v.current,z);if(P.length===0){l(null);return}l(P[P.length-1]);const I=P.slice(0,-1);I.length&&h(M=>{if(I.every(Z=>M.has(Z)))return M;const J=new Set(M);for(const Z of I)J.add(Z);return J})},150),q=k.onDidChangeCursorPosition(()=>R());return()=>{R.cancel(),q.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){d(new Set);return}const{editor:k,monaco:R}=r,q=()=>{const T=k.getModel();if(!T)return;const z=R.editor.getModelMarkers({resource:T.uri}).filter(P=>P.severity===R.MarkerSeverity.Error).map(P=>T.getOffsetAt({lineNumber:P.startLineNumber,column:P.startColumn}));d(Gy(v.current,z))};q();const j=R.editor.onDidChangeMarkers(T=>{const z=k.getModel();z&&T.some(P=>P.toString()===z.uri.toString())&&q()});return()=>j.dispose()},[r,s]);const m=x.useCallback(k=>{h(R=>{const q=new Set(R);return q.has(k)?q.delete(k):q.add(k),q})},[]),O=x.useCallback(k=>{if(l(k.id),!r)return;const{editor:R,monaco:q}=r,j=R.getModel();if(!j)return;const T=j.getPositionAt(k.start),z=j.getPositionAt(k.end),P=new q.Range(T.lineNumber,T.column,z.lineNumber,z.column);R.revealRangeNearTopIfOutsideViewport(P,q.editor.ScrollType.Smooth),R.setPosition(T),R.focus();const I=R.deltaDecorations([],[{range:P,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>R.deltaDecorations(I,[]),700)},[r]),N=x.useCallback(k=>{var le;if(!r||!k.overId)return;const{editor:R,monaco:q,collapse:j}=r,T=R.getModel();if(!T)return;const z=T.getValue(),P=Sl(z,ht,i),I=k.parentId?((le=Xy(P,k.parentId))==null?void 0:le.children)??[]:P,M=I.findIndex(B=>B.id===k.dragId),J=I.findIndex(B=>B.id===k.overId);if(M===-1||J===-1)return;let Z=J+(k.overHalf==="after"?1:0);M<Z&&(Z-=1);const V=Yy(z,I,M,Z);if(!V)return;const ne=T.getPositionAt(V.start),S=T.getPositionAt(V.end);R.executeEdits("outline-reorder",[{range:new q.Range(ne.lineNumber,ne.column,S.lineNumber,S.column),text:V.text}]),j==null||j.resyncDecorations()},[r,i]),w=x.useMemo(()=>{const k=[],R=(q,j,T)=>{var I,M;const z=(M=(I=q[0])==null?void 0:I.reorder)==null?void 0:M.groupId,P=q.length>1&&z!==void 0&&q.every(J=>{var Z;return((Z=J.reorder)==null?void 0:Z.groupId)===z});q.forEach(J=>{const Z=Ky[J.kind]??Dg,V=J.children.length>0,ne=f.has(J.id),S=o===J.id,le=(p==null?void 0:p.overId)===J.id;k.push(u.jsxs("div",{"data-oid":J.id,role:"treeitem","aria-selected":S,"aria-expanded":V?ne:void 0,tabIndex:0,draggable:P,onClick:()=>O(J),onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),O(J)),B.key==="ArrowRight"&&V&&!ne&&m(J.id),B.key==="ArrowLeft"&&V&&ne&&m(J.id)},onDragStart:B=>{B.dataTransfer.setData("text/plain",J.id),B.dataTransfer.effectAllowed="move",g({dragId:J.id,parentId:T,overId:null,overHalf:"before"})},onDragOver:B=>{if(!p||p.dragId===J.id||Qy(p.dragId)!==T)return;B.preventDefault(),B.dataTransfer.dropEffect="move";const y=B.currentTarget.getBoundingClientRect(),W=B.clientY<y.top+y.height/2?"before":"after";(p.overId!==J.id||p.overHalf!==W)&&g({...p,overId:J.id,overHalf:W})},onDrop:B=>{B.preventDefault(),p&&N({...p,overId:J.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",le&&(p==null?void 0:p.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",le&&(p==null?void 0:p.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+j*12},children:[V?u.jsx("span",{role:"button","aria-label":ne?"Collapse":"Expand",onClick:B=>{B.stopPropagation(),m(J.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"}),J.kind==="slide"&&u.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:J.detail}),u.jsx(Z,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:J.label}),J.kind!=="slide"&&J.detail&&u.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:J.detail}),c.has(J.id)&&u.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},J.id)),V&&ne&&R(J.children,j+1,J.id)})};return R(s,0,""),k},[s,f,o,c,p,O,m,N]);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:w})})}const _l=x.memo(eb);async function tb(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(yd,{ref:r,className:G("relative overflow-hidden",e),...n,children:[u.jsx(cg,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Cf,{}),u.jsx(dg,{})]}));ri.displayName=yd.displayName;const Cf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(bd,{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(fg,{className:"bg-border relative flex-1 rounded-full"})}));Cf.displayName=bd.displayName;function Tf({className:e,...t}){return u.jsx(pg,{"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(hg,{"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 nb=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(nb({variant:t}),e),...n}));ir.displayName="Alert";const rb=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:G("mb-1 font-medium leading-none tracking-tight",e),...t}));rb.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,d=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:[d," ",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((f,h)=>u.jsx(es,{keyName:String(h),value:f,depth:n+1,isLast:h===t.length-1},h)):Object.entries(t).map(([f,h],p,g)=>u.jsx(es,{keyName:f,value:h,depth:n+1,isLast:p===g.length-1},f)),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 ib({plugins:e,initialFocusedPlugin:t}){var m,O;const n=Lt(N=>N.togglePlugin),r=Lt(N=>N.isPluginSelected),i=Lt(N=>N.selectedPlugins),s=Lt(N=>N.isApplyingPlugins),[a,o]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState("properties");x.useEffect(()=>{if(t){const N=e.find(w=>w.name===t);if(N){o(N);return}}e.length>0&&!a&&o(e[0])},[t,e]);const h=x.useMemo(()=>{const N={current:[],downstream:[],upstream:[]};return e.forEach(w=>{N[w.location]&&N[w.location].push(w)}),N},[e]),p=async(N,w)=>{a&&(await tb(a.name,N.props),c(w),setTimeout(()=>c(null),2e3))},g=N=>{switch(N){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return N}},v=N=>{switch(N){case"current":return u.jsx(Bg,{className:"size-3"});case"downstream":return u.jsx(Lg,{className:"size-3"});case"upstream":return u.jsx(Cd,{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,E=(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(Rg,{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(([N,w])=>w.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:[v(N),g(N)]}),u.jsx("div",{className:"space-y-0.5",children:w.map(k=>{const R=r(k.name),q=(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",q?"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",R?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:k.name})]},k.name)})})]},N))})})}),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(Tf,{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:[v(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:()=>f("properties"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Sa,{className:"size-3.5"}),"Properties"]})}),b&&u.jsx("button",{onClick:()=>f("schema"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Mg,{className:"size-3.5"}),"Schema"]})}),E&&u.jsx("button",{onClick:()=>f("examples"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx($g,{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:[d==="properties"&&_&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([N,w])=>u.jsx(sb,{name:N,prop:w},N))}),d==="schema"&&b&&u.jsx(ts,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&E&&a.examples.map((N,w)=>u.jsxs("div",{className:G(w>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:[N.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:N.title}),!N.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),u.jsx(Se,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>p(N,w),children:l===w?u.jsxs(u.Fragment,{children:[u.jsx(Fg,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(ks,{className:"size-3 mr-1"}),"Copy"]})})]}),N.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:N.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(N.props,null,2)})]},w)),!_&&!b&&!E&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(Sa,{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 sb({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 ab={current:"Current directory",downstream:"Project"};function jl({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:ab[e]??e})}function Nl({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(vo,{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 ob({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(Da,{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 d=s(c.name),f=`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:f,className:G("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",d?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(vo,{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(Ad,{})}),u.jsx(Tf,{id:f,checked:d,onCheckedChange:()=>a(c),disabled:o,className:"shrink-0","aria-label":`Toggle ${c.name} plugin`})]},c.filePath||c.name)})})]})}function El(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 If({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 lb({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(lb,{className:t,children:r.map((i,s)=>u.jsx(If,{children:i},s))})}function ub({className:e}={}){const{theme:t,setTheme:n}=Sd(),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(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsxs(Se,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Zg,{className:"hidden dark:block"}),u.jsx(Vg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:"Toggle theme"})})]})}function cb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o,activeTab:l}=Ne(fo(A=>({documents:A.documents,documentTypes:A.documentTypes,createDocument:A.createDocument,openDocument:A.openDocument,activeTab:A.activeTab}))),c=Ta(A=>A.updateTheme),d=Ta(A=>A.removeTheme),f=x.useContext(Rd),[h,p]=x.useState(!1),[g,v]=x.useState(!1),[_,b]=x.useState(!1),[E,m]=x.useState(null),O=Lt(A=>A.togglePlugin),N=Lt(A=>A.isPluginSelected),w=Lt(A=>A.selectedPlugins),k=Lt(A=>A.isApplyingPlugins),[R,q]=x.useState(!1),[j,T]=x.useState(new Set(["documents","themes"])),[z,P]=x.useState(""),I=x.useRef(null),{toast:M}=Sr(),J=i.filter(A=>s[A.name]!=="application/json+theme"),Z=i.filter(A=>s[A.name]==="application/json+theme"),V=x.useCallback(()=>{p(!1)},[]),ne=x.useCallback(()=>{v(!1)},[]),S=x.useRef(new Map);x.useEffect(()=>{const A=S.current,K=new Map;Z.forEach(ee=>{K.set(ee.name,ee.text),A.get(ee.name)!==ee.text&&c(ee.name,ee.text)}),A.forEach((ee,xe)=>{K.has(xe)||d(xe)}),S.current=K},[Z,c,d]);const le=x.useRef(!1);x.useEffect(()=>{if(le.current||!f)return;le.current=!0;const A=new Set(Z.map(ee=>ee.name));Object.keys(f.getState().customThemes).forEach(ee=>{A.has(ee)||d(ee)})},[Z,d,f]);const B=x.useCallback(A=>{T(K=>{const ee=new Set(K);return ee.has(A)?ee.delete(A):ee.add(A),ee})},[]),{resolvedTheme:y}=Sd(),W=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(A,K)=>{if(i.some(ee=>ee.name===A)){o(A);return}try{const ee=await fetch(`/api/discovery/${K?"themes":"documents"}/${encodeURIComponent(A)}/content`);if(!ee.ok)throw new Error(ee.statusText);const xe=await ee.text(),L=JSON.parse(xe);a(A,JSON.stringify(L,null,2)),o(A),M({title:`Added ${K?"theme":"document"}: ${A}`})}catch{M({title:"Failed to load",description:`Could not load ${A}`,variant:"destructive"})}},[i,a,o,M]);x.useEffect(()=>{if(n)return;const A=K=>{var L,Q,he,ve,F;if(K.key!=="/"||K.metaKey||K.ctrlKey||K.altKey)return;const ee=K.target,xe=(L=ee==null?void 0:ee.tagName)==null?void 0:L.toLowerCase();xe==="input"||xe==="textarea"||xe==="select"||ee!=null&&ee.isContentEditable||(Q=ee==null?void 0:ee.closest)!=null&&Q.call(ee,".monaco-editor")||(he=I.current)!=null&&he.closest('[aria-hidden="true"], [inert]')||(K.preventDefault(),(ve=I.current)==null||ve.focus(),(F=I.current)==null||F.select())};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[n]);const Y=z.trim(),re=x.useMemo(()=>new Set(i.map(A=>A.name)),[i]),D=x.useMemo(()=>J.filter(A=>cn(A.name,Y)),[J,Y]),de=x.useMemo(()=>Z.filter(A=>cn(A.name,Y)),[Z,Y]),te=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(A=>!re.has(A.name)&&(cn(A.name,Y)||cn(A.title??"",Y))),[e,Y,re]),ae=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(A=>!re.has(A.name)&&(cn(A.name,Y)||cn(A.description??"",Y))),[e,Y,re]),ue=El(te),ge=El(ae),pe=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(A=>cn(A.name,Y)||cn(A.description??"",Y)),[e,Y]),Pe=A=>Y.length>0||j.has(A),De=Pe("documents"),nt=Pe("themes"),C=D.length+te.length,$=de.length+ae.length,U=Y.length>0&&D.length===0&&de.length===0&&te.length===0&&ae.length===0&&pe.length===0,se=G("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(vf,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Ra,{className:G("gap-0 p-1.5",se),children:u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(zd,{})})}),u.jsxs(Ke,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(ii,{shortcut:"mod+b"})]})]})}),u.jsxs(Ma,{className:G("gap-2 px-1 py-1",se),children:[u.jsxs(Lr,{className:"items-center gap-0.5",children:[J.map(A=>u.jsx(Ni,{document:A,compact:!0},A.name)),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{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:[Z.map(A=>u.jsx(Ni,{document:A,compact:!0},A.name)),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New theme",onClick:()=>v(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(Ra,{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:W,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(Ug,{})})}),u.jsxs(Ke,{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(Jg,{"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:I,type:"text",value:z,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:A=>P(A.target.value),onKeyDown:A=>{A.key==="Escape"&&(A.preventDefault(),P(""),A.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 A;P(""),(A=I.current)==null||A.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(yn,{})}):u.jsx(If,{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(Ma,{className:G("gap-0 px-2 pb-2",se),children:U?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 A;P(""),(A=I.current)==null||A.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:[(C>0||!Y)&&u.jsxs("section",{children:[u.jsx(Da,{open:De,onToggle:()=>B("documents"),count:C||void 0,actions:u.jsxs(u.Fragment,{children:[ht==="docx"&&u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Compare documents",disabled:J.length<2,onClick:()=>q(!0),children:u.jsx(Nd,{})})}),u.jsx(Ke,{side:"bottom",children:J.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),De&&u.jsxs(Lr,{className:"gap-0.5",children:[D.map(A=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:A,query:Y}),!Y&&l===A.name&&u.jsx(_l,{})]},A.name)),ue.map(([A,K])=>u.jsxs(x.Fragment,{children:[ue.length>1&&u.jsx(jl,{location:A}),K.map(ee=>u.jsx(Nl,{name:ee.name,subtitle:ee.title,query:Y,onSelect:()=>X(ee.name,!1)},ee.path||ee.name))]},A)),C===0&&u.jsx("li",{className:"list-none",children:u.jsx(xl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]})]}),($>0||!Y)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Da,{open:nt,onToggle:()=>B("themes"),count:$||void 0,actions:u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New theme",onClick:()=>v(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{side:"bottom",children:"New theme"})]}),children:"Themes"}),nt&&u.jsxs(Lr,{className:"gap-0.5",children:[de.map(A=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:A,query:Y}),!Y&&l===A.name&&u.jsx(_l,{})]},A.name)),ge.map(([A,K])=>u.jsxs(x.Fragment,{children:[ge.length>1&&u.jsx(jl,{location:A}),K.map(ee=>u.jsx(Nl,{name:ee.name,subtitle:ee.description,query:Y,onSelect:()=>X(ee.name,!0)},ee.path||ee.name))]},A)),$===0&&u.jsx("li",{className:"list-none",children:u.jsx(xl,{icon:nn,label:"New theme",onClick:()=>v(!0)})})]})]}),u.jsx(ob,{plugins:pe,query:Y,open:Pe("plugins"),onToggleSection:()=>B("plugins"),onShowPluginDetails:A=>{m(A),b(!0)},isPluginSelected:N,onTogglePlugin:O,isApplyingPlugins:k,selectedPluginCount:w.size})]})})]}),u.jsx(wf,{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(ub,{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:V,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(Ct,{open:g,onOpenChange:v,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:A=>{b(A),A||m(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(ib,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:E})})}),u.jsx(yx,{open:R,onOpenChange:q})]})}const Cl=x.memo(cb),db=x.lazy(()=>_d(()=>import("./editor-CN0fauKm.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function Tl(){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(db,{})})}const fb=x.lazy(()=>_d(()=>import("./preview-BoIgsKxW.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));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 preview..."})]})}),children:u.jsx(fb,{})})}const{createElement:xr,createContext:pb,forwardRef:Af,useCallback:gt,useContext:zf,useEffect:zn,useImperativeHandle:Of,useLayoutEffect:hb,useMemo:mb,useRef:wt,useState:ar}=Zc,Al=Zc[`useId${Math.random()}`.slice(0,5)],gb=hb,Ts=pb(null);Ts.displayName="PanelGroupContext";const On=gb,xb=typeof Al=="function"?Al:()=>null;let yb=0;function So(e=null){const t=xb(),n=wt(e||t||null);return n.current===null&&(n.current=""+yb++),e??n.current}function Pf({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:d,onResize:f,order:h,style:p,tagName:g="div",...v}){const _=zf(Ts);if(_===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:E,getPanelSize:m,getPanelStyle:O,groupId:N,isPanelCollapsed:w,reevaluatePanelConstraints:k,registerPanel:R,resizePanel:q,unregisterPanel:j}=_,T=So(a),z=wt({callbacks:{onCollapse:c,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:T,idIsFromProps:a!==void 0,order:h});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:I,constraints:M}=z.current,J={...M};z.current.id=T,z.current.idIsFromProps=a!==void 0,z.current.order=h,I.onCollapse=c,I.onExpand=d,I.onResize=f,M.collapsedSize=n,M.collapsible=r,M.defaultSize=i,M.maxSize=o,M.minSize=l,(J.collapsedSize!==M.collapsedSize||J.collapsible!==M.collapsible||J.maxSize!==M.maxSize||J.minSize!==M.minSize)&&k(z.current,J)}),On(()=>{const I=z.current;return R(I),()=>{j(I)}},[h,T,R,j]),Of(s,()=>({collapse:()=>{b(z.current)},expand:I=>{E(z.current,I)},getId(){return T},getSize(){return m(z.current)},isCollapsed(){return w(z.current)},isExpanded(){return!w(z.current)},resize:I=>{q(z.current,I)}}),[b,E,m,w,T,q]);const P=O(z.current,i);return xr(g,{...v,children:e,className:t,id:a,style:{...P,...p},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":N,"data-panel-id":T,"data-panel-size":parseFloat(""+P.flexGrow).toFixed(1)})}const Df=Af((e,t)=>xr(Pf,{...e,forwardedRef:t}));Pf.displayName="Panel";Df.displayName="forwardRef(Panel)";let Fa=null,An=null;function bb(e,t){if(t){const n=(t&Lf)!==0,r=(t&Bf)!==0,i=(t&Zf)!==0,s=(t&Vf)!==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 vb(){An!==null&&(document.head.removeChild(An),Fa=null,An=null)}function Ys(e,t){const n=bb(e,t);Fa!==n&&(Fa=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Rf(e){return e.type==="keydown"}function Mf(e){return e.type.startsWith("pointer")}function $f(e){return e.type.startsWith("mouse")}function Is(e){if(Mf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if($f(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function wb(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function kb(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 Sb(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Pl(e),b:Pl(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:Ol(zl(n.a)),b:Ol(zl(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 _b=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function jb(e){var t;const n=getComputedStyle((t=Ff(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function Nb(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||jb(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"||_b.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function zl(e){let t=e.length;for(;t--;){const n=e[t];if(_e(n,"Missing node"),Nb(n))return n}return null}function Ol(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Pl(e){const t=[];for(;e;)t.push(e),e=Ff(e);return t}function Ff(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Lf=1,Bf=2,Zf=4,Vf=8,Eb=wb()==="coarse";let Bt=[],or=!1,mn=new Map,As=new Map;const si=new Set;function Cb(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 d;As.delete(e),si.delete(o);const f=(d=mn.get(a))!==null&&d!==void 0?d:1;if(mn.set(a,f-1),ns(),f===1&&mn.delete(a),Bt.includes(o)){const h=Bt.indexOf(o);h>=0&&Bt.splice(h,1),jo(),i("up",!0,null)}}}function Dl(e){const{target:t}=e,{x:n,y:r}=Is(e);or=!0,_o({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;_o({target:r,x:t,y:n})}rs("move",e),jo(),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),_o({target:t,x:n,y:r}),jo(),ns()}function _o({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:d,top:f}=o,h=Eb?a.coarse:a.fine;if(t>=c-h&&t<=d+h&&n>=f-h&&n<=l+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&Sb(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(kb(g.getBoundingClientRect(),o)){v=!0;break}g=g.parentElement}if(v)return}Bt.push(i)}})}function Ks(e,t){As.set(e,t)}function jo(){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?Ys("intersection",n):e?Ys("horizontal",n):t?Ys("vertical",n):vb()}function ns(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Un),n.removeEventListener("pointerdown",Dl),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",Dl,{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 Tb(){const[e,t]=ar(0);return gt(()=>t(n=>n+1),[])}function _e(e,t){if(!e)throw console.error(t),Error(t)}const No=10;function Dn(e,t,n=No){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function sn(e,t,n=No){return Dn(e,t,n)===0}function Nt(e,t,n){return Dn(e,t,n)===0}function Ib(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(No)),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 f=e<0?l:o,h=n[f];_e(h,`Panel constraints not found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:v=0}=h;if(g){const _=t[f];if(_e(_!=null,`Previous layout not found for panel index ${f}`),Nt(_,p)){const b=v-_;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const f=e<0?o:l,h=n[f];_e(h,`No panel constraints found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:v=0}=h;if(g){const _=t[f];if(_e(_!=null,`Previous layout not found for panel index ${f}`),Nt(_,v)){const b=_-p;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const f=e<0?1:-1;let h=e<0?l:o,p=0;for(;;){const v=t[h];_e(v!=null,`Previous layout not found for panel index ${h}`);const b=tr({panelConstraints:n,panelIndex:h,size:100})-v;if(p+=b,h+=f,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 v=g-p,_=tr({panelConstraints:n,panelIndex:h,size:v});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(Ib(i,a))return i;{const f=e<0?l:o,h=t[f];_e(h!=null,`Previous layout not found for panel index ${f}`);const p=h+c,g=tr({panelConstraints:n,panelIndex:f,size:p});if(a[f]=g,!Nt(g,p)){let v=p-g,b=e<0?l:o;for(;b>=0&&b<n.length;){const E=a[b];_e(E!=null,`Previous layout not found for panel index ${b}`);const m=E+v,O=tr({panelConstraints:n,panelIndex:b,size:m});if(Nt(E,O)||(v-=O-E,a[b]=O),Nt(v,0))break;e>0?b--:b++}}}const d=a.reduce((f,h)=>h+f,0);return Nt(d,100)?a:i}function Ab({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((f,h)=>{const{constraints:p}=f,{maxSize:g=100,minSize:v=0}=p;h===o?(r=v,i=g):(s+=v,a+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-a),d=e[o];return{valueMax:l,valueMin:c,valueNow:d}}function ai(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function Uf(e,t,n=document){const i=ai(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Jf(e,t,n){const r=Uf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Hf(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 zb(e,t,n,r=document){var i,s,a,o;const l=zs(t,r),c=ai(e,r),d=l?c.indexOf(l):-1,f=(i=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,h=(a=(o=n[d+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[f,h]}function Ob({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:d,valueNow:f}=Ab({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(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}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=Hf(n,s);_e(c!=null,`No group found for id "${n}"`);const d=ai(n,s);_e(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const p=h.getAttribute("data-panel-resize-handle-id");_e(p,"Resize handle element has no handle id attribute");const[g,v]=zb(n,p,l,s);if(g==null||v==null)return()=>{};const _=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const E=l.findIndex(m=>m.id===g);if(E>=0){const m=l[E];_e(m,`No panel data found for index ${E}`);const O=r[E],{collapsedSize:N=0,collapsible:w,minSize:k=0}=m.constraints;if(O!=null&&w){const R=Br({delta:Nt(O,N)?k-N:N-O,initialLayout:r,panelConstraints:l.map(q=>q.constraints),pivotIndices:Jf(n,p,s),prevLayout:r,trigger:"keyboard"});r!==R&&a(R)}}break}}};return h.addEventListener("keydown",_),()=>{h.removeEventListener("keydown",_)}});return()=>{f.forEach(h=>h())}},[s,e,t,n,r,i,a])}function Rl(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 Wf(e,t){const n=e==="horizontal",{x:r,y:i}=Is(t);return n?r:i}function Pb(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=Wf(n,e),d=Hf(o,i);_e(d,`No group element found for id "${o}"`);const f=d.getBoundingClientRect(),h=s?f.width:f.height;return(c-l)/h*100}function Db(e,t,n,r,i,s){if(Rf(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:Pb(e,t,n,r,s)}function Rb({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:d}=o,f=n[l];if(f==null||r!==f){n[l]=r;const{onCollapse:h,onExpand:p,onResize:g}=a;g&&g(r,f),d&&(h||p)&&(p&&(f==null||sn(f,c))&&!sn(r,c)&&p(),h&&(f==null||!sn(f,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 Mb({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 $b(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Ml(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 qf(e){return`react-resizable-panels:${e}`}function Gf(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 Yf(e,t){try{const n=qf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Fb(e,t,n){var r,i;const s=(r=Yf(e,n))!==null&&r!==void 0?r:{},a=Gf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Lb(e,t,n,r,i){var s;const a=qf(e),o=Gf(t),l=(s=Yf(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 $l({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 Bb=100,Zr={getItem:e=>(Ml(Zr),Zr.getItem(e)),setItem:(e,t)=>{Ml(Zr),Zr.setItem(e,t)}},Fl={};function Kf({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:d="div",...f}){const h=So(s),p=wt(null),[g,v]=ar(null),[_,b]=ar([]),E=Tb(),m=wt({}),O=wt(new Map),N=wt(0),w=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:[]}),Of(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:y}=k.current;return y},setLayout:y=>{const{onLayout:W}=w.current,{layout:X,panelDataArray:Y}=k.current,re=$l({layout:y,panelConstraints:Y.map(D=>D.constraints)});Rl(X,re)||(b(re),k.current.layout=re,W&&W(re),Jn(Y,re,m.current))}}),[]),On(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=g,w.current.id=h,w.current.onLayout=a,w.current.storage=l}),Ob({committedValuesRef:w,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 W=Fl[e];W==null&&(W=$b(Lb,Bb),Fl[e]=W);const X=[...y],Y=new Map(O.current);W(e,X,Y,_,l)}},[e,_,l]),zn(()=>{});const R=gt(y=>{const{onLayout:W}=w.current,{layout:X,panelDataArray:Y}=k.current;if(y.constraints.collapsible){const re=Y.map(ae=>ae.constraints),{collapsedSize:D=0,panelSize:de,pivotIndices:te}=jn(Y,y,X);if(_e(de!=null,`Panel size not found for panel "${y.id}"`),!sn(de,D)){O.current.set(y.id,de);const ue=Kn(Y,y)===Y.length-1?de-D:D-de,ge=Br({delta:ue,initialLayout:X,panelConstraints:re,pivotIndices:te,prevLayout:X,trigger:"imperative-api"});Ci(X,ge)||(b(ge),k.current.layout=ge,W&&W(ge),Jn(Y,ge,m.current))}}},[]),q=gt((y,W)=>{const{onLayout:X}=w.current,{layout:Y,panelDataArray:re}=k.current;if(y.constraints.collapsible){const D=re.map(pe=>pe.constraints),{collapsedSize:de=0,panelSize:te=0,minSize:ae=0,pivotIndices:ue}=jn(re,y,Y),ge=W??ae;if(sn(te,de)){const pe=O.current.get(y.id),Pe=pe!=null&&pe>=ge?pe:ge,nt=Kn(re,y)===re.length-1?te-Pe:Pe-te,C=Br({delta:nt,initialLayout:Y,panelConstraints:D,pivotIndices:ue,prevLayout:Y,trigger:"imperative-api"});Ci(Y,C)||(b(C),k.current.layout=C,X&&X(C),Jn(re,C,m.current))}}},[]),j=gt(y=>{const{layout:W,panelDataArray:X}=k.current,{panelSize:Y}=jn(X,y,W);return _e(Y!=null,`Panel size not found for panel "${y.id}"`),Y},[]),T=gt((y,W)=>{const{panelDataArray:X}=k.current,Y=Kn(X,y);return Mb({defaultSize:W,dragState:g,layout:_,panelData:X,panelIndex:Y})},[g,_]),z=gt(y=>{const{layout:W,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:re,panelSize:D}=jn(X,y,W);return _e(D!=null,`Panel size not found for panel "${y.id}"`),re===!0&&sn(D,Y)},[]),P=gt(y=>{const{layout:W,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:re,panelSize:D}=jn(X,y,W);return _e(D!=null,`Panel size not found for panel "${y.id}"`),!re||Dn(D,Y)>0},[]),I=gt(y=>{const{panelDataArray:W}=k.current;W.push(y),W.sort((X,Y)=>{const re=X.order,D=Y.order;return re==null&&D==null?0:re==null?-1:D==null?1:re-D}),k.current.panelDataArrayChanged=!0,E()},[E]);On(()=>{if(k.current.panelDataArrayChanged){k.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:W,storage:X}=w.current,{layout:Y,panelDataArray:re}=k.current;let D=null;if(y){const te=Fb(y,re,X);te&&(O.current=new Map(Object.entries(te.expandToSizes)),D=te.layout)}D==null&&(D=Rb({panelDataArray:re}));const de=$l({layout:D,panelConstraints:re.map(te=>te.constraints)});Rl(Y,de)||(b(de),k.current.layout=de,W&&W(de),Jn(re,de,m.current))}}),On(()=>{const y=k.current;return()=>{y.layout=[]}},[]);const M=gt(y=>{let W=!1;const X=p.current;return X&&window.getComputedStyle(X,null).getPropertyValue("direction")==="rtl"&&(W=!0),function(re){re.preventDefault();const D=p.current;if(!D)return()=>null;const{direction:de,dragState:te,id:ae,keyboardResizeBy:ue,onLayout:ge}=w.current,{layout:pe,panelDataArray:Pe}=k.current,{initialLayout:De}=te??{},nt=Jf(ae,y,D);let C=Db(re,y,de,te,ue,D);const $=de==="horizontal";$&&W&&(C=-C);const U=Pe.map(K=>K.constraints),se=Br({delta:C,initialLayout:De??pe,panelConstraints:U,pivotIndices:nt,prevLayout:pe,trigger:Rf(re)?"keyboard":"mouse-or-touch"}),A=!Ci(pe,se);(Mf(re)||$f(re))&&N.current!=C&&(N.current=C,!A&&C!==0?$?Ks(y,C<0?Lf:Bf):Ks(y,C<0?Zf:Vf):Ks(y,0)),A&&(b(se),k.current.layout=se,ge&&ge(se),Jn(Pe,se,m.current))}},[]),J=gt((y,W)=>{const{onLayout:X}=w.current,{layout:Y,panelDataArray:re}=k.current,D=re.map(pe=>pe.constraints),{panelSize:de,pivotIndices:te}=jn(re,y,Y);_e(de!=null,`Panel size not found for panel "${y.id}"`);const ue=Kn(re,y)===re.length-1?de-W:W-de,ge=Br({delta:ue,initialLayout:Y,panelConstraints:D,pivotIndices:te,prevLayout:Y,trigger:"imperative-api"});Ci(Y,ge)||(b(ge),k.current.layout=ge,X&&X(ge),Jn(re,ge,m.current))},[]),Z=gt((y,W)=>{const{layout:X,panelDataArray:Y}=k.current,{collapsedSize:re=0,collapsible:D}=W,{collapsedSize:de=0,collapsible:te,maxSize:ae=100,minSize:ue=0}=y.constraints,{panelSize:ge}=jn(Y,y,X);ge!=null&&(D&&te&&sn(ge,re)?sn(re,de)||J(y,de):ge<ue?J(y,ue):ge>ae&&J(y,ae))},[J]),V=gt((y,W)=>{const{direction:X}=w.current,{layout:Y}=k.current;if(!p.current)return;const re=zs(y,p.current);_e(re,`Drag handle element not found for id "${y}"`);const D=Wf(X,W);v({dragHandleId:y,dragHandleRect:re.getBoundingClientRect(),initialCursorPosition:D,initialLayout:Y})},[]),ne=gt(()=>{v(null)},[]),S=gt(y=>{const{panelDataArray:W}=k.current,X=Kn(W,y);X>=0&&(W.splice(X,1),delete m.current[y.id],k.current.panelDataArrayChanged=!0,E())},[E]),le=mb(()=>({collapsePanel:R,direction:r,dragState:g,expandPanel:q,getPanelSize:j,getPanelStyle:T,groupId:h,isPanelCollapsed:z,isPanelExpanded:P,reevaluatePanelConstraints:Z,registerPanel:I,registerResizeHandle:M,resizePanel:J,startDragging:V,stopDragging:ne,unregisterPanel:S,panelGroupElement:p.current}),[R,g,r,q,j,T,h,z,P,Z,I,M,J,V,ne,S]),B={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return xr(Ts.Provider,{value:le},xr(d,{...f,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 Xf=Af((e,t)=>xr(Kf,{...e,forwardedRef:t}));Kf.displayName="PanelGroup";Xf.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 Zb({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=Uf(o,t,r);_e(c!==null,`No resize element found for id "${t}"`);const d=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[d].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function Qf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:d="div",...f}){var h,p;const g=wt(null),v=wt({onDragging:a});zn(()=>{v.current.onDragging=a});const _=zf(Ts);if(_===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:b,groupId:E,registerResizeHandle:m,startDragging:O,stopDragging:N,panelGroupElement:w}=_,k=So(i),[R,q]=ar("inactive"),[j,T]=ar(!1),[z,P]=ar(null),I=wt({state:R});On(()=>{I.current.state=R}),zn(()=>{if(n)P(null);else{const V=m(k);P(()=>V)}},[n,k,m]);const M=(h=r==null?void 0:r.coarse)!==null&&h!==void 0?h:15,J=(p=r==null?void 0:r.fine)!==null&&p!==void 0?p:5;return zn(()=>{if(n||z==null)return;const V=g.current;return _e(V,"Element ref not attached"),Cb(k,V,b,{coarse:M,fine:J},(S,le,B)=>{if(le)switch(S){case"down":{q("drag"),_e(B,'Expected event to be defined for "down" action'),O(k,B);const{onDragging:y}=v.current;y&&y(!0);break}case"move":{const{state:y}=I.current;y!=="drag"&&q("hover"),_e(B,'Expected event to be defined for "move" action'),z(B);break}case"up":{q("hover"),N();const{onDragging:y}=v.current;y&&y(!1);break}}else q("inactive")})},[M,b,n,J,m,k,z,O,N]),Zb({disabled:n,handleId:k,resizeHandler:z,panelGroupElement:w}),xr(d,{...f,children:e,className:t,id:i,onBlur:()=>{T(!1),s==null||s()},onFocus:()=>{T(!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":E,"data-resize-handle":"","data-resize-handle-active":R==="drag"?"pointer":j?"keyboard":void 0,"data-resize-handle-state":R,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":k})}Qf.displayName="PanelResizeHandle";const Vb=({className:e,...t})=>u.jsx(Xf,{className:G("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Xs=Df,Ll=({withHandle:e,className:t,...n})=>u.jsx(Qf,{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(Hg,{className:"h-2.5 w-2.5"})})}),ep=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}));ep.displayName="Textarea";class Ub{constructor(t){nl(this,"client");this.client=px.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 Jb=new Ub;function Hb(e,t){return e??t}function Wb(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(Wb(e.headers.get("content-type")))try{return await e.json()}catch{return}}function Gb(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 Yb(){const e=x.useRef(null),t=Hi(i=>i.generationBackend),n=x.useCallback(async(i,s,a,o,l)=>{e.current&&e.current.abort();const c=new AbortController;e.current=c;const d=Hb(l==null?void 0:l.renderer,t);try{o==null||o("parsing","Validating JSON structure...");let f;try{f=JSON.parse(s)}catch(R){throw new Error(`Invalid JSON: ${R instanceof Error?R.message:"Unknown parse error"}`)}o==null||o("building",`Building ${ji.toLowerCase()} structure...`);const h={jsonDefinition:f,options:{...l,sourceName:i,...d?{renderer:d}:{}}};h.customThemes=a??{},o==null||o("rendering",`Generating ${ht.toUpperCase()} content...`);const p={"Content-Type":"application/json"};l!=null&&l.bypassCache&&(p["X-Bypass-Cache"]="true");const g=await fetch(ei.generate,{method:"POST",headers:p,body:JSON.stringify(h),signal:c.signal}),v=await qb(g);if(!g.ok||!(v!=null&&v.success))throw new Error(Gb(g,v));const{data:_,cache:b,warnings:E}=v,m=b.status==="HIT"?"HIT":b.status==="MISS"?"MISS":"UNKNOWN",O=m==="HIT"?`Served from cache (Hit rate: ${b.hitRate})`:`Generated fresh ${ji.toLowerCase()}`;o==null||o("finalizing",O);const N=globalThis.atob(_.document),w=new Uint8Array(N.length);for(let R=0;R<N.length;R++)w[R]=N.charCodeAt(R);const k=new Blob([w],{type:_.contentType});if(k.size===0)throw new Error(`Received empty ${ji.toLowerCase()} from API`);return{name:i,text:s,blob:k,...d?{renderer:d}:{},filename:_.filename,fileId:_.fileId,cacheStatus:m,cacheHitRate:b.hitRate,warnings:E}}catch(f){throw f instanceof Error&&f.name==="AbortError"?new Error(`${ji} generation was cancelled`):f}finally{e.current===c&&(e.current=null)}},[t]),r=x.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:n,generateDocument:n,cancelGeneration:r}}const Bi={ids:[],default:null};let Bl;function Kb(){return Bl??(Bl=(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}})()),Bl}function Xb(){const[e,t]=x.useState(Bi);return x.useEffect(()=>{let n=!1;return Kb().then(r=>{n||t(r)}),()=>{n=!0}},[]),e}function Qb(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,d])=>`${c}: ${JSON.stringify(d)}`).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 ev({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 Qs(){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 Zl(){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 tv({name:e,blob:t,onManualRender:n,isGenerating:r,isRendering:i,onShowCacheMetrics:s,onShowSchemas:a,onShowFonts:o,documentText:l,editorDocumentText:c,warnings:d,onToggleChat:f,chatOpen:h,onTogglePreview:p,previewOpen:g}){const[v,_]=x.useState(!1),[b,E]=x.useState(!1),[m,O]=x.useState(!1),[N,w]=x.useState(!1),[k,R]=x.useState(!1),[q,j]=x.useState(null),{toast:T}=Sr(),{generateDocument:z}=Yb(),P=x.useContext(Rd),I=Xb(),M=Hi(te=>te.generationBackend),J=Hi(te=>te.setSettings),Z=M??I.default??void 0,V=x.useCallback(()=>{const te={},{customThemes:ae}=P.getState();return Object.values(ae).forEach(ue=>{ue.valid&&ue.parsed&&(te[ue.name]=ue.parsed)}),te},[P]),ne=je.useMemo(()=>{if(!l)return[];try{const te=JSON.parse(l);return[...(ht==="pptx"?vg:wg)(te)].filter(ue=>!kg(ue))}catch{return[]}},[l]),[S,le]=x.useState(!1),B=x.useCallback(async()=>{if(t){_(!0);try{await new Promise(te=>setTimeout(te,100)),Li(`${e}${Tr}`,t)}finally{setTimeout(()=>_(!1),500)}}},[t,e]),y=x.useCallback(async()=>{if(t){if(ne.length===0){await B();return}le(!0)}},[t,ne.length,B]),W=x.useCallback(async te=>{var ae;if(l){_(!0);try{const ue=await z(e,l,V(),void 0,{bypassCache:!0,fonts:{mode:te}});if(ue.blob.size===0)T({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Li(`${e}${Tr}`,ue.blob);const ge=(ae=ue.warnings)==null?void 0:ae.find(pe=>{var Pe,De;return((Pe=pe.context)==null?void 0:Pe.code)==="FONT_MODE_SUBSTITUTED"||((De=pe.context)==null?void 0:De.code)==="FONT_MODE_CUSTOM"});ge&&T({title:te==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:ge.message})}}catch(ue){T({title:"Export failed",description:ue instanceof Error?ue.message:String(ue),variant:"destructive"})}finally{setTimeout(()=>_(!1),500)}}},[l,e,z,T,V]),X=x.useCallback(async()=>{if(!(!d||d.length===0)){E(!0);try{const te=Qb(d);if(!te){T({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const ae=await z("warnings",JSON.stringify(te,null,2),{});ae&&typeof ae=="object"&&"blob"in ae&&ae.blob&&(Li(`${e}-warnings${Tr}`,ae.blob),T({title:"Warnings downloaded",description:`Downloaded warnings document with ${d.length} warning(s).`}))}catch(te){console.error("Failed to generate warnings document:",te),T({title:"Download failed",description:te instanceof Error?te.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>E(!1),500)}}},[d,e,z,T]),Y=x.useCallback(async()=>{O(!0);try{await Jb.delete(`/${ht}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),T({title:"Cache Cleared",description:"All active caches have been successfully cleared.",variant:"default"})}catch(te){console.error("Failed to clear cache:",te),T({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{O(!1)}},[T]),re=c??l,D=x.useCallback(()=>{var ue,ge;if(!re){T({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(re)}catch{T({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}R(!0);const te=(async()=>{const pe=await fetch(`/api/${ht}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:re,customThemes:V(),options:{sourceName:e}})});if(!pe.ok){let De=`Request failed with status ${pe.status}`;try{const nt=await pe.json(),C=nt.error??nt.message;typeof C=="string"&&C&&(De=C)}catch{}throw new Error(De)}const Pe=await pe.json();return JSON.stringify(Pe.data,null,2)})();let ae;typeof ClipboardItem<"u"&&((ue=navigator.clipboard)!=null&&ue.write)?ae=navigator.clipboard.write([new ClipboardItem({"text/plain":te.then(pe=>new Blob([pe],{type:"text/plain"}))})]):(ge=navigator.clipboard)!=null&&ge.writeText?ae=te.then(pe=>navigator.clipboard.writeText(pe)):ae=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await ae,T({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(pe){let Pe=null;try{Pe=await te}catch(De){console.error("Error fetching standard components:",De),T({title:"Failed to get standard components",description:De instanceof Error?De.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",pe),j(Pe)}finally{R(!1)}})()},[re,e,V,T]),de=x.useCallback(async()=>{if(q!=null)try{await navigator.clipboard.writeText(q),T({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),j(null)}catch{T({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[q,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(Ge,{children:[u.jsx(Ye,{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(Ad,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Ke,{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(Ge,{children:[u.jsx(Ye,{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||g===!1,children:[i?u.jsx(gn,{size:"sm"}):u.jsx(Wg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:g===!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(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsxs(Se,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||v||r,onClick:y,children:[v?u.jsx(gn,{size:"sm"}):u.jsx(qg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download ",Tr]})})]}),d&&d.length>0&&u.jsxs(Ge,{children:[u.jsx(Ye,{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:b||r,onClick:X,children:b?u.jsx(gn,{size:"sm"}):u.jsx(Od,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download warnings (",d.length,")"]})})]}),I.ids.length>1&&u.jsxs(ti,{value:Z,onValueChange:te=>J({generationBackend:te}),children:[u.jsxs(Ge,{children:[u.jsx(Ye,{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(ja,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),u.jsxs(ni,{placeholder:"Renderer",children:[u.jsx("span",{className:"font-medium",children:Z}),Z!==I.default&&u.jsx(Qs,{})]})]})}),u.jsx(Ke,{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($d,{children:[u.jsx(po,{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),I.ids.map(te=>u.jsx(Pn,{value:te,className:"text-xs",children:u.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap",children:[u.jsx("span",{className:"font-medium",children:te}),te===I.default?u.jsx(Zl,{}):u.jsx(Qs,{})]})},te))]})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(Ns,{children:[u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Es,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Td,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ke,{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(Gg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),o&&u.jsxs($t,{onClick:o,children:[u.jsx(_a,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),s&&u.jsxs($t,{onClick:s,children:[u.jsx(Na,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),re?u.jsxs($t,{onClick:D,disabled:k,children:[u.jsx(Ea,{className:"h-4 w-4 mr-2"}),k?"Copying...":"Copy standard components"]}):u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs($t,{disabled:!0,children:[u.jsx(Ea,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),u.jsx(Ke,{side:"left",children:u.jsx("p",{children:"No document selected — open or select a document first"})})]}),u.jsx(mr,{}),u.jsxs($t,{onClick:()=>w(!0),disabled:m,className:"text-destructive focus:text-destructive",children:[u.jsx(co,{className:"h-4 w-4 mr-2"}),m?"Clearing...":"Clear all caches"]}),I.ids.length>1&&u.jsxs(u.Fragment,{children:[u.jsx(mr,{className:"lg:hidden"}),u.jsx(wo,{className:"lg:hidden px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),I.ids.map(te=>u.jsxs($t,{className:"lg:hidden gap-1.5",onClick:()=>J({generationBackend:te}),children:[u.jsx(an,{className:`h-3.5 w-3.5 shrink-0 ${Z===te?"opacity-100":"opacity-0"}`}),u.jsx("span",{className:"font-medium",children:te}),te===I.default?u.jsx(Zl,{}):u.jsx(Qs,{})]},te))]})]})]}),p&&u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Se,{variant:g?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:p,children:g?u.jsx(Pd,{className:"h-3.5 w-3.5"}):u.jsx(Yg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[g?"Hide":"Show"," Preview"," ",u.jsx(ii,{shortcut:"mod+shift+p"})]})})]}),f&&u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Se,{variant:h?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:f,children:u.jsx(Dd,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[h?"Close":"Open"," AI Chat"," ",u.jsx(ii,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(ev,{open:S,onClose:()=>le(!1),nonSafeFonts:ne,onChoose:W}),u.jsx(Ct,{open:q!=null,onOpenChange:te=>{te||j(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(ep,{readOnly:!0,value:q??"",className:"h-64 font-mono text-xs",onFocus:te=>te.currentTarget.select()}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:()=>j(null),children:"Close"}),u.jsx(Se,{size:"sm",onClick:de,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:N,onOpenChange:w,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:()=>w(!1),children:"Cancel"}),u.jsx(Se,{variant:"destructive",size:"sm",disabled:m,onClick:async()=>{await Y(),w(!1)},children:m?u.jsx(gn,{size:"sm"}):"Clear"})]})]})})]})}const nv=je.memo(tv),tp=mg,Eo=x.forwardRef(({className:e,...t},n)=>u.jsx(vd,{ref:n,className:G("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Eo.displayName=vd.displayName;const lr=x.forwardRef(({className:e,...t},n)=>u.jsx(wd,{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=wd.displayName;const ur=x.forwardRef(({className:e,...t},n)=>u.jsx(kd,{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=kd.displayName;async function rv(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 iv(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 sv(e){const t=iv(e);return rv(t)}const av=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=x.useState(n),[s,a]=x.useState(null),[o,l]=x.useState(null),[c,d]=x.useState(!1),[f,h]=x.useState(!1),[p,g]=x.useState(null),[v,_]=x.useState(null),[b,E]=x.useState(!1),{toast:m}=Sr(),O=Lt(P=>P.selectedPlugins),N=Array.from(O);x.useEffect(()=>{n&&i(n)},[n]);const w=x.useCallback(async()=>{d(!0),g(null);try{const P=await Vs.fetchDocumentSchema(N);a(P)}catch(P){const I=P instanceof Error?P.message:"Failed to load document schema";g(I),m({variant:"destructive",title:"Error loading schema",description:I})}finally{d(!1)}},[N,m]),k=x.useCallback(async()=>{if(!o){h(!0),_(null);try{const P=await Vs.fetchThemeSchema();l(P)}catch(P){const I=P instanceof Error?P.message:"Failed to load theme schema";_(I),m({variant:"destructive",title:"Error loading schema",description:I})}finally{h(!1)}}},[o,m]),[R,q]=x.useState([]);x.useEffect(()=>{e||(a(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const P=N.length!==R.length||N.some((I,M)=>I!==R[M]);r==="document"?(!s||P)&&(P&&(Vs.clearPluginSchemaCache(),q([...N])),c||w()):r==="theme"&&!o&&!f&&k()},[r,e,s,o,c,f,N,R,w,k]);const j=N.length,T=r==="document"?s:o,z=async()=>{if(T)try{await sv(T)&&(E(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>E(!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(tp,{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(Eo,{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:z,disabled:b||!T,"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:f,error:v||void 0})})]})]})]})})};function np(e,t,n){if(t.length===0)return n;const r=Vl(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=Vl(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function Vl(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Ul=2*1024*1024,Jl=12*1024*1024;function ov(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 lv(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 uv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>Ul)return{ok:!1,message:`"${e}" is ${is(t.length)}. The limit is ${is(Ul)} per font, because the bytes travel inside the document JSON.`};const n=ov(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:lv(t)}}const cv=new Set(["italic","oblique"]);function dv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[a,o]of Object.entries(jd))r.set(o.toLowerCase(),Number(a));let i=400,s=!1;for(;n.length>1;){const a=n[n.length-1].toLowerCase();if(cv.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 fv(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 pv(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 hv(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(o=>{const l=pv(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 mv(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=fv(n,hv(s,r.family,i,r.category))}return n}function gv(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 xv(e){const t=new TextEncoder().encode(e).length;return t<=Jl?null:`Adding this font would push the document to ${is(t)}, past the ${is(Jl)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const Hl=new Set,yv=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function bv(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 vv(e,t,n,r){const i=yv(e,n,r);if(!Hl.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=bv(t),a=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await a.load(),document.fonts.add(a),Hl.add(i)}catch{}}const wv={safe:[],google:[]};function Wl(e,t){var d;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((d=r==null?void 0:r.dataset.weights)==null?void 0:d.split(",").map(Number).filter(f=>!Number.isNaN(f)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((f,h)=>f-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((f,h)=>f-h).join(",")}function kv(){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(l=>l.name===e);if(!s)return{ok:!1,error:"Active theme not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active theme is not valid JSON: ${l.message}`}}const o=i(a);return r(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n,r])}function Sv(){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(l=>l.name===e);if(!s)return{ok:!1,error:"Active document not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active document is not valid JSON: ${l.message}`}}const o=np(a,r,i);return n(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n])}function _v(){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 f;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(h=>h.name===e);if(!s)return{ok:!1,error:"Active document not found"};let a;try{a=JSON.parse(s.text)}catch(h){return{ok:!1,error:`Active document is not valid JSON: ${h.message}`}}const o=mv((f=a==null?void 0:a.props)==null?void 0:f.fontRegistry,i),l=np(a,["props","fontRegistry"],o),c=JSON.stringify(l,null,2),d=xv(c);return d?{ok:!1,error:d}:(r(e,c),{ok:!0,name:e})},[e,t,n,r])}function jv(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 ql(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Nv=({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(wv),[d,f]=x.useState(!1),[h,p]=x.useState(""),[g,v]=x.useState("safe"),[_,b]=x.useState(null),[E,m]=x.useState(null),[O,N]=x.useState(!1),[w,k]=x.useState(!1),[R,q]=x.useState(""),[j,T]=x.useState([]),z=x.useRef(null),{toast:P}=Sr(),I=kv(),M=Sv(),J=_v(),Z=Ne(D=>D.activeTab),V=Ne(D=>D.documentTypes),ne=Z&&V[Z]==="application/json+theme",S=!!a||ne;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(f(!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(()=>f(!1))))},[s,l,P]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const D of l.google)Wl(D.family,D.weights)},[g,l]);const le=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]),W=x.useCallback(async(D,de,te)=>{b(D);try{const ae=I(ue=>(jv(ue,te,D),ue));if(!ae.ok){P({variant:"destructive",title:"Could not insert font",description:ae.error});return}P({title:"Font inserted",description:`${D} set as ${te} font in "${ae.name}".`})}finally{b(null)}},[I,P]),X=x.useCallback(async D=>{if(a){b(D);try{const de=M(a.jsonPath,D);if(!de.ok){P({variant:"destructive",title:"Could not insert font",description:de.error});return}P({title:"Font inserted",description:`${D} set at ${ql(a.jsonPath)}.`}),o(!1)}finally{b(null)}}},[a,M,P,o]),Y=x.useCallback(async D=>{if(!(!D||D.length===0)){N(!0);try{const de=[];for(const ae of Array.from(D)){const ue=new Uint8Array(await ae.arrayBuffer()),ge=uv(ae.name,ue);if(!ge.ok){P({variant:"destructive",title:"Font rejected",description:ge.message});continue}de.push({identity:dv(ae.name),base64:ge.base64})}if(de.length===0)return;const te=J(de.map(({identity:ae,base64:ue})=>({id:ae.family,family:ae.family,sources:[{kind:"data",data:ue,weight:ae.weight,italic:ae.italic}]})));if(!te.ok){P({variant:"destructive",title:"Could not register font",description:te.error});return}for(const{identity:ae,base64:ue}of de)vv(ae.family,ue,ae.weight,ae.italic),P({title:`Added ${ae.family}`,description:`Registered at weight ${ae.weight}${ae.italic?" italic":""} in props.fontRegistry. Reference it as "${ae.family}".`})}catch(de){P({variant:"destructive",title:"Upload failed",description:de.message})}finally{N(!1),z.current&&(z.current.value="")}}},[J,P]),re=x.useCallback(async()=>{var de,te;const D=R.trim();if(D){k(!0),T([]);try{const ae=await fetch(ei.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:D,weights:[400,700],italics:!1})});if(ae.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!ae.ok){const De=await ae.json().catch(()=>({}));throw new Error(De.error??`Materialize failed (${ae.status})`)}const ue=await ae.json();T(ue.warnings??[]);const ge=(de=l.google.find(De=>De.family.toLowerCase()===ue.family.toLowerCase()))==null?void 0:de.category,pe=gv(ue,ge);if(!pe){P({variant:"destructive",title:"Nothing to embed",description:((te=ue.warnings)==null?void 0:te.join(" · "))||`Google Fonts has no family named "${D}".`});return}const Pe=J([pe]);if(!Pe.ok){P({variant:"destructive",title:"Could not register font",description:Pe.error});return}Wl(ue.family,[400,700]),P({title:`Added ${ue.family}`,description:`Embedded ${pe.sources.length} weight(s) in props.fontRegistry.`})}catch(ae){P({variant:"destructive",title:"Google Fonts fetch failed",description:ae.message})}finally{k(!1)}}},[R,l.google,J,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 ${ql(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(tp,{value:g,onValueChange:D=>v(D),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Eo,{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:d&&le.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:le.map(D=>u.jsx(Gl,{family:D,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${D}", sans-serif`},onCopy:()=>y(D),copied:E===D,contextual:!!a,onUseThis:()=>X(D),onInsertHeading:()=>W(D,"safe","heading"),onInsertBody:()=>W(D,"safe","body"),applying:_===D,disabled:!S},D))})}),u.jsx(ur,{value:"google",className:"m-0",children:d&&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(Gl,{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:E===D.family,contextual:!!a,onUseThis:()=>X(D.family),onInsertHeading:()=>W(D.family,"google","heading"),onInsertBody:()=>W(D.family,"google","body"),applying:_===D.family,disabled:!S,extraAction:u.jsx(Cv,{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:z,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=z.current)==null?void 0:D.click()},children:[O?u.jsx(Fr,{className:"animate-spin mr-2 h-4 w-4"}):u.jsx(Kg,{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:R,onChange:D=>q(D.target.value),onKeyDown:D=>{D.key==="Enter"&&re()}}),u.jsxs(Se,{onClick:()=>void re(),disabled:w||R.trim()==="",children:[w&&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(" · ")})})]})]})})]})]})]})})},Ev="The quick brown fox jumps over the lazy dog",Cv=({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(wo,{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=jd[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)})]})]})},Gl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:d,extraAction:f})=>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:Ev}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Se,{size:"sm",onClick:a,disabled:c||d,"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||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Se,{size:"sm",variant:"secondary",onClick:l,disabled:c||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,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 Yl({previewOpen:e,onTogglePreview:t}){const n=rn(N=>N.name||""),r=rn(N=>N.blob),i=rn(N=>N.isGenerating),s=rn(N=>N.text),a=rn(N=>N.warnings),o=rn(N=>N.isRendering),l=Hi(N=>N.useGlobalPreviewHeader??!0),c=Ne(N=>N.activeTab),d=Ne(N=>N.documentTypes),f=c&&d[c]==="application/json+theme"?"theme":"document",h=Ne(N=>{var w;return N.activeTab&&N.documentTypes[N.activeTab]!=="application/json+theme"?(w=N.documents.find(k=>k.name===N.activeTab))==null?void 0:w.text:void 0}),p=Oe(N=>N.chatOpen),g=Oe(N=>N.toggleChat),[v,_]=je.useState(!1),b=$i(N=>N.openFor);if(!l)return null;const E=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),m=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),O=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(nv,{name:O,blob:r,onManualRender:E,isGenerating:i,isRendering:!!o,onShowCacheMetrics:m,onShowSchemas:()=>_(!0),onShowFonts:()=>b(),documentText:s,editorDocumentText:h,warnings:a,onToggleChat:g,chatOpen:p,onTogglePreview:t,previewOpen:e}),u.jsx(av,{open:v,onOpenChange:_,defaultTab:f==="theme"?"theme":"document"}),u.jsx(Nv,{})]})}function Tv(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Iv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Av=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,zv={};function Kl(e,t){return(zv.jsx?Av:Iv).test(e)}const Ov=/[ \t\n\f\r]/g;function Pv(e){return typeof e=="object"?e.type==="text"?Xl(e.value):!1:Xl(e)}function Xl(e){return e.replace(Ov,"")===""}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 rp(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 La(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 Dv=0;const ke=$n(),tt=$n(),Ba=$n(),ie=$n(),Be=$n(),cr=$n(),jt=$n();function $n(){return 2**++Dv}const Za=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:tt,commaOrSpaceSeparated:jt,commaSeparated:cr,number:ie,overloadedBoolean:Ba,spaceSeparated:Be},Symbol.toStringTag,{value:"Module"})),ea=Object.keys(Za);class Co extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),Ql(this,"space",i),typeof r=="number")for(;++s<ea.length;){const a=ea[s];Ql(this,ea[s],(r&Za[a])===Za[a])}}}Co.prototype.defined=!0;function Ql(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 Co(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[La(r)]=r,n[La(s.attribute)]=r}return new bi(t,n,e.space)}const ip=jr({properties:{ariaActiveDescendant:null,ariaAtomic:tt,ariaAutoComplete:null,ariaBusy:tt,ariaChecked:tt,ariaColCount:ie,ariaColIndex:ie,ariaColSpan:ie,ariaControls:Be,ariaCurrent:null,ariaDescribedBy:Be,ariaDetails:null,ariaDisabled:tt,ariaDropEffect:Be,ariaErrorMessage:null,ariaExpanded:tt,ariaFlowTo:Be,ariaGrabbed:tt,ariaHasPopup:null,ariaHidden:tt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Be,ariaLevel:ie,ariaLive:null,ariaModal:tt,ariaMultiLine:tt,ariaMultiSelectable:tt,ariaOrientation:null,ariaOwns:Be,ariaPlaceholder:null,ariaPosInSet:ie,ariaPressed:tt,ariaReadOnly:tt,ariaRelevant:null,ariaRequired:tt,ariaRoleDescription:Be,ariaRowCount:ie,ariaRowIndex:ie,ariaRowSpan:ie,ariaSelected:tt,ariaSetSize:ie,ariaSort:null,ariaValueMax:ie,ariaValueMin:ie,ariaValueNow:ie,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function sp(e,t){return t in e?e[t]:t}function ap(e,t){return sp(e,t.toLowerCase())}const Rv=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:ie,colSpan:null,content:null,contentEditable:tt,controls:ke,controlsList:Be,coords:ie|cr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Ba,draggable:tt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Be,height:ie,hidden:Ba,high:ie,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:ie,manifest:null,max:null,maxLength:ie,media:null,method:null,min:null,minLength:ie,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:ie,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:ie,rowSpan:ie,sandbox:Be,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:ie,sizes:null,slot:null,span:ie,spellCheck:tt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:ie,step:null,style:null,tabIndex:ie,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:tt,width:ie,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Be,axis:null,background:null,bgColor:null,border:ie,borderColor:null,bottomMargin:ie,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:ie,leftMargin:ie,link:null,longDesc:null,lowSrc:null,marginHeight:ie,marginWidth:ie,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:ie,rules:null,scheme:null,scrolling:tt,standby:null,summary:null,text:null,topMargin:ie,valueType:null,version:null,vAlign:null,vLink:null,vSpace:ie,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:ie,security:null,unselectable:null},space:"html",transform:ap}),Mv=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:ie,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:ie,amplitude:ie,arabicForm:null,ascent:ie,attributeName:null,attributeType:null,azimuth:ie,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:ie,by:null,calcMode:null,capHeight:ie,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:ie,diffuseConstant:ie,direction:null,display:null,dur:null,divisor:ie,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:ie,enableBackground:null,end:null,event:null,exponent:ie,externalResourcesRequired:null,fill:null,fillOpacity:ie,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:ie,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:ie,horizOriginX:ie,horizOriginY:ie,id:null,ideographic:ie,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:ie,k:ie,k1:ie,k2:ie,k3:ie,k4:ie,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:ie,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:ie,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:ie,overlineThickness:ie,paintOrder:null,panose1:null,path:null,pathLength:ie,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Be,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:ie,pointsAtY:ie,pointsAtZ:ie,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:ie,specularExponent:ie,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:ie,strikethroughThickness:ie,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:ie,strokeOpacity:ie,strokeWidth:null,style:null,surfaceScale:ie,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:ie,tableValues:null,target:null,targetX:ie,targetY:ie,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:ie,underlineThickness:ie,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:ie,values:null,vAlphabetic:ie,vMathematical:ie,vectorEffect:null,vHanging:ie,vIdeographic:ie,version:null,vertAdvY:ie,vertOriginX:ie,vertOriginY:ie,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:ie,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:sp}),op=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()}}),lp=jr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:ap}),up=jr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),$v={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"},Fv=/[A-Z]/g,eu=/-[a-z]/g,Lv=/^data[-\w.:]+$/i;function Bv(e,t){const n=La(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"&&Lv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(eu,Vv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!eu.test(s)){let a=s.replace(Fv,Zv);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=Co}return new i(r,t)}function Zv(e){return"-"+e.toLowerCase()}function Vv(e){return e.charAt(1).toUpperCase()}const Uv=rp([ip,Rv,op,lp,up],"html"),To=rp([ip,Mv,op,lp,up],"svg");function Jv(e){return e.join(" ").trim()}var Hn={},ta,tu;function Hv(){if(tu)return ta;tu=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 By(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 Zy(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 Vy(e,t){var r;const n=st(Ie(t,"text"));switch(e){case"heading":{const i=$a(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:By(t)};case"image":return{label:Zy(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=$a(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 Uy(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}=Vy(t.name,t.props);return r===t.name&&t.childrenArr&&(r=Uy(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:jf(t.childrenArr),reorder:n}}function jf(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 Jy(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,d=typeof(l==null?void 0:l.value)=="string"?l.value:"",f=c?gr(c):null,h=f?st(Ie(f.props,"text")):void 0;i(d==="title"?0:d==="subtitle"||d.startsWith("heading")?1:2,h)}const a=(o,l)=>{const c=gr(o);if(c){if(c.name==="text"||c.name==="heading"){const d=st(Ie(c.props,"text"));if(d){const f=st(Ie(c.props,"style"))??"";i(f==="title"?0:f.startsWith("heading")?1:2,d)}}if(l<1)for(const d of Et(c.childrenArr))a(d,l+1)}};for(const o of Et(Ie(e,"children")))a(o,0);return r?vt(r.text,48,!0):void 0}function Hy(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:Jy(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:jf(a.childrenArr),reorder:o})):r.push(Qi(s,a,o))}return r}function Wy(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 d=$a(Ie(o.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=Qi(a,o,l);c().push(f),i.push({level:d,node:f})}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 kl(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 qy(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,d=typeof(l==null?void 0:l.value)=="string"?l.value:void 0;!d||!c||a.push({id:"",kind:"key",label:d,detail:kl(c),start:o.offset,end:o.offset+o.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:a.length===0?kl(i):void 0,start:n.offset,end:n.offset+n.length,children:a})}return t}function Sl(e,t,n){if(!e.trim())return[];const r=$y(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?qy(r):t==="pptx"?Hy(r):Wy(r);return Nf(i,""),i}function Nf(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,Nf(n.children,n.id)})}function Ef(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 Gy(e,t){const n=new Set;for(const r of t)for(const i of Ef(e,r))n.add(i);return n}function Yy(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(d=>d.reorder);if(i.some(d=>!d))return null;const s=i[0].groupId;if(i.some(d=>d.groupId!==s))return null;for(let d=1;d<i.length;d++)if(i[d].sliceStart<i[d-1].sliceEnd)return null;const a=i.map(d=>e.slice(d.sliceStart,d.sliceEnd)),o=[];for(let d=1;d<i.length;d++){const f=e.slice(i[d-1].sliceEnd,i[d].sliceStart);if((f.match(/,/g)??[]).length!==1)return null;o.push(f)}const l=a.map((d,f)=>f);l.splice(r,0,l.splice(n,1)[0]);let c="";return l.forEach((d,f)=>{c+=a[d],f<o.length&&(c+=o[f])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:c}}const Ky={slide:Pg,heading:Og,text:_a,paragraph:zg,chart:Na,highcharts:Na,table:Ag,image:Ig,shape:Id,list:Tg,toc:Cg,section:ja,columns:ja,"text-box":_a,statistic:Eg,key:Sa};function Xy(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 Qy(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function eb(){const{activeTab:e,documentTypes:t}=Ne(fo(k=>({activeTab:k.activeTab,documentTypes:k.documentTypes}))),n=Ne(k=>{var R;return k.activeTab?(R=k.documents.find(q=>q.name===k.activeTab))==null?void 0:R.text:void 0}),r=ex(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,d]=x.useState(()=>new Set),[f,h]=x.useState(()=>new Set),[p,g]=x.useState(null),v=x.useRef(s);v.current=s;const _=x.useRef(null),b=x.useRef(null),E=x.useCallback(()=>{var q;if(!e){a([]);return}const k=((q=r==null?void 0:r.editor.getModel())==null?void 0:q.getValue())??n??"",R=Sl(k,ht,i);if(a(R),b.current!==e){b.current=e;const j=new Set;if(i==="document"&&ht==="docx")for(const T of R)T.kind==="heading"&&j.add(T.id);h(j),l(null)}},[e,r,n,i]);x.useEffect(()=>{E();const k=r==null?void 0:r.editor.getModel();if(!k)return;const R=il(E,300),q=k.onDidChangeContent(()=>R());return()=>{R.cancel(),q.dispose()}},[E,r]),x.useEffect(()=>{if(!r)return;const{editor:k}=r,R=il(()=>{const j=k.getModel(),T=k.getPosition();if(!j||!T)return;const z=j.getOffsetAt(T),P=Ef(v.current,z);if(P.length===0){l(null);return}l(P[P.length-1]);const I=P.slice(0,-1);I.length&&h(M=>{if(I.every(Z=>M.has(Z)))return M;const J=new Set(M);for(const Z of I)J.add(Z);return J})},150),q=k.onDidChangeCursorPosition(()=>R());return()=>{R.cancel(),q.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){d(new Set);return}const{editor:k,monaco:R}=r,q=()=>{const T=k.getModel();if(!T)return;const z=R.editor.getModelMarkers({resource:T.uri}).filter(P=>P.severity===R.MarkerSeverity.Error).map(P=>T.getOffsetAt({lineNumber:P.startLineNumber,column:P.startColumn}));d(Gy(v.current,z))};q();const j=R.editor.onDidChangeMarkers(T=>{const z=k.getModel();z&&T.some(P=>P.toString()===z.uri.toString())&&q()});return()=>j.dispose()},[r,s]);const m=x.useCallback(k=>{h(R=>{const q=new Set(R);return q.has(k)?q.delete(k):q.add(k),q})},[]),O=x.useCallback(k=>{if(l(k.id),!r)return;const{editor:R,monaco:q}=r,j=R.getModel();if(!j)return;const T=j.getPositionAt(k.start),z=j.getPositionAt(k.end),P=new q.Range(T.lineNumber,T.column,z.lineNumber,z.column);R.revealRangeNearTopIfOutsideViewport(P,q.editor.ScrollType.Smooth),R.setPosition(T),R.focus();const I=R.deltaDecorations([],[{range:P,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>R.deltaDecorations(I,[]),700)},[r]),N=x.useCallback(k=>{var le;if(!r||!k.overId)return;const{editor:R,monaco:q,collapse:j}=r,T=R.getModel();if(!T)return;const z=T.getValue(),P=Sl(z,ht,i),I=k.parentId?((le=Xy(P,k.parentId))==null?void 0:le.children)??[]:P,M=I.findIndex(B=>B.id===k.dragId),J=I.findIndex(B=>B.id===k.overId);if(M===-1||J===-1)return;let Z=J+(k.overHalf==="after"?1:0);M<Z&&(Z-=1);const V=Yy(z,I,M,Z);if(!V)return;const ne=T.getPositionAt(V.start),S=T.getPositionAt(V.end);R.executeEdits("outline-reorder",[{range:new q.Range(ne.lineNumber,ne.column,S.lineNumber,S.column),text:V.text}]),j==null||j.resyncDecorations()},[r,i]),w=x.useMemo(()=>{const k=[],R=(q,j,T)=>{var I,M;const z=(M=(I=q[0])==null?void 0:I.reorder)==null?void 0:M.groupId,P=q.length>1&&z!==void 0&&q.every(J=>{var Z;return((Z=J.reorder)==null?void 0:Z.groupId)===z});q.forEach(J=>{const Z=Ky[J.kind]??Dg,V=J.children.length>0,ne=f.has(J.id),S=o===J.id,le=(p==null?void 0:p.overId)===J.id;k.push(u.jsxs("div",{"data-oid":J.id,role:"treeitem","aria-selected":S,"aria-expanded":V?ne:void 0,tabIndex:0,draggable:P,onClick:()=>O(J),onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),O(J)),B.key==="ArrowRight"&&V&&!ne&&m(J.id),B.key==="ArrowLeft"&&V&&ne&&m(J.id)},onDragStart:B=>{B.dataTransfer.setData("text/plain",J.id),B.dataTransfer.effectAllowed="move",g({dragId:J.id,parentId:T,overId:null,overHalf:"before"})},onDragOver:B=>{if(!p||p.dragId===J.id||Qy(p.dragId)!==T)return;B.preventDefault(),B.dataTransfer.dropEffect="move";const y=B.currentTarget.getBoundingClientRect(),W=B.clientY<y.top+y.height/2?"before":"after";(p.overId!==J.id||p.overHalf!==W)&&g({...p,overId:J.id,overHalf:W})},onDrop:B=>{B.preventDefault(),p&&N({...p,overId:J.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",le&&(p==null?void 0:p.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",le&&(p==null?void 0:p.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+j*12},children:[V?u.jsx("span",{role:"button","aria-label":ne?"Collapse":"Expand",onClick:B=>{B.stopPropagation(),m(J.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"}),J.kind==="slide"&&u.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:J.detail}),u.jsx(Z,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:J.label}),J.kind!=="slide"&&J.detail&&u.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:J.detail}),c.has(J.id)&&u.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},J.id)),V&&ne&&R(J.children,j+1,J.id)})};return R(s,0,""),k},[s,f,o,c,p,O,m,N]);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:w})})}const _l=x.memo(eb);async function tb(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(yd,{ref:r,className:G("relative overflow-hidden",e),...n,children:[u.jsx(cg,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Cf,{}),u.jsx(dg,{})]}));ri.displayName=yd.displayName;const Cf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(bd,{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(fg,{className:"bg-border relative flex-1 rounded-full"})}));Cf.displayName=bd.displayName;function Tf({className:e,...t}){return u.jsx(pg,{"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(hg,{"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 nb=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(nb({variant:t}),e),...n}));ir.displayName="Alert";const rb=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:G("mb-1 font-medium leading-none tracking-tight",e),...t}));rb.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,d=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:[d," ",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((f,h)=>u.jsx(es,{keyName:String(h),value:f,depth:n+1,isLast:h===t.length-1},h)):Object.entries(t).map(([f,h],p,g)=>u.jsx(es,{keyName:f,value:h,depth:n+1,isLast:p===g.length-1},f)),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 ib({plugins:e,initialFocusedPlugin:t}){var m,O;const n=Lt(N=>N.togglePlugin),r=Lt(N=>N.isPluginSelected),i=Lt(N=>N.selectedPlugins),s=Lt(N=>N.isApplyingPlugins),[a,o]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState("properties");x.useEffect(()=>{if(t){const N=e.find(w=>w.name===t);if(N){o(N);return}}e.length>0&&!a&&o(e[0])},[t,e]);const h=x.useMemo(()=>{const N={current:[],downstream:[],upstream:[]};return e.forEach(w=>{N[w.location]&&N[w.location].push(w)}),N},[e]),p=async(N,w)=>{a&&(await tb(a.name,N.props),c(w),setTimeout(()=>c(null),2e3))},g=N=>{switch(N){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return N}},v=N=>{switch(N){case"current":return u.jsx(Bg,{className:"size-3"});case"downstream":return u.jsx(Lg,{className:"size-3"});case"upstream":return u.jsx(Cd,{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,E=(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(Rg,{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(([N,w])=>w.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:[v(N),g(N)]}),u.jsx("div",{className:"space-y-0.5",children:w.map(k=>{const R=r(k.name),q=(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",q?"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",R?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:k.name})]},k.name)})})]},N))})})}),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(Tf,{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:[v(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:()=>f("properties"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Sa,{className:"size-3.5"}),"Properties"]})}),b&&u.jsx("button",{onClick:()=>f("schema"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Mg,{className:"size-3.5"}),"Schema"]})}),E&&u.jsx("button",{onClick:()=>f("examples"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx($g,{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:[d==="properties"&&_&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([N,w])=>u.jsx(sb,{name:N,prop:w},N))}),d==="schema"&&b&&u.jsx(ts,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&E&&a.examples.map((N,w)=>u.jsxs("div",{className:G(w>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:[N.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:N.title}),!N.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),u.jsx(Se,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>p(N,w),children:l===w?u.jsxs(u.Fragment,{children:[u.jsx(Fg,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(ks,{className:"size-3 mr-1"}),"Copy"]})})]}),N.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:N.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(N.props,null,2)})]},w)),!_&&!b&&!E&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(Sa,{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 sb({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 ab={current:"Current directory",downstream:"Project"};function jl({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:ab[e]??e})}function Nl({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(vo,{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 ob({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(Da,{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 d=s(c.name),f=`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:f,className:G("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",d?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(vo,{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(Ad,{})}),u.jsx(Tf,{id:f,checked:d,onCheckedChange:()=>a(c),disabled:o,className:"shrink-0","aria-label":`Toggle ${c.name} plugin`})]},c.filePath||c.name)})})]})}function El(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 If({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 lb({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(lb,{className:t,children:r.map((i,s)=>u.jsx(If,{children:i},s))})}function ub({className:e}={}){const{theme:t,setTheme:n}=Sd(),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(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsxs(Se,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Zg,{className:"hidden dark:block"}),u.jsx(Vg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:"Toggle theme"})})]})}function cb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o,activeTab:l}=Ne(fo(A=>({documents:A.documents,documentTypes:A.documentTypes,createDocument:A.createDocument,openDocument:A.openDocument,activeTab:A.activeTab}))),c=Ta(A=>A.updateTheme),d=Ta(A=>A.removeTheme),f=x.useContext(Rd),[h,p]=x.useState(!1),[g,v]=x.useState(!1),[_,b]=x.useState(!1),[E,m]=x.useState(null),O=Lt(A=>A.togglePlugin),N=Lt(A=>A.isPluginSelected),w=Lt(A=>A.selectedPlugins),k=Lt(A=>A.isApplyingPlugins),[R,q]=x.useState(!1),[j,T]=x.useState(new Set(["documents","themes"])),[z,P]=x.useState(""),I=x.useRef(null),{toast:M}=Sr(),J=i.filter(A=>s[A.name]!=="application/json+theme"),Z=i.filter(A=>s[A.name]==="application/json+theme"),V=x.useCallback(()=>{p(!1)},[]),ne=x.useCallback(()=>{v(!1)},[]),S=x.useRef(new Map);x.useEffect(()=>{const A=S.current,K=new Map;Z.forEach(ee=>{K.set(ee.name,ee.text),A.get(ee.name)!==ee.text&&c(ee.name,ee.text)}),A.forEach((ee,xe)=>{K.has(xe)||d(xe)}),S.current=K},[Z,c,d]);const le=x.useRef(!1);x.useEffect(()=>{if(le.current||!f)return;le.current=!0;const A=new Set(Z.map(ee=>ee.name));Object.keys(f.getState().customThemes).forEach(ee=>{A.has(ee)||d(ee)})},[Z,d,f]);const B=x.useCallback(A=>{T(K=>{const ee=new Set(K);return ee.has(A)?ee.delete(A):ee.add(A),ee})},[]),{resolvedTheme:y}=Sd(),W=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(A,K)=>{if(i.some(ee=>ee.name===A)){o(A);return}try{const ee=await fetch(`/api/discovery/${K?"themes":"documents"}/${encodeURIComponent(A)}/content`);if(!ee.ok)throw new Error(ee.statusText);const xe=await ee.text(),L=JSON.parse(xe);a(A,JSON.stringify(L,null,2)),o(A),M({title:`Added ${K?"theme":"document"}: ${A}`})}catch{M({title:"Failed to load",description:`Could not load ${A}`,variant:"destructive"})}},[i,a,o,M]);x.useEffect(()=>{if(n)return;const A=K=>{var L,Q,he,ve,F;if(K.key!=="/"||K.metaKey||K.ctrlKey||K.altKey)return;const ee=K.target,xe=(L=ee==null?void 0:ee.tagName)==null?void 0:L.toLowerCase();xe==="input"||xe==="textarea"||xe==="select"||ee!=null&&ee.isContentEditable||(Q=ee==null?void 0:ee.closest)!=null&&Q.call(ee,".monaco-editor")||(he=I.current)!=null&&he.closest('[aria-hidden="true"], [inert]')||(K.preventDefault(),(ve=I.current)==null||ve.focus(),(F=I.current)==null||F.select())};return window.addEventListener("keydown",A),()=>window.removeEventListener("keydown",A)},[n]);const Y=z.trim(),re=x.useMemo(()=>new Set(i.map(A=>A.name)),[i]),D=x.useMemo(()=>J.filter(A=>cn(A.name,Y)),[J,Y]),de=x.useMemo(()=>Z.filter(A=>cn(A.name,Y)),[Z,Y]),te=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(A=>!re.has(A.name)&&(cn(A.name,Y)||cn(A.title??"",Y))),[e,Y,re]),ae=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(A=>!re.has(A.name)&&(cn(A.name,Y)||cn(A.description??"",Y))),[e,Y,re]),ue=El(te),ge=El(ae),pe=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(A=>cn(A.name,Y)||cn(A.description??"",Y)),[e,Y]),Pe=A=>Y.length>0||j.has(A),De=Pe("documents"),nt=Pe("themes"),C=D.length+te.length,$=de.length+ae.length,U=Y.length>0&&D.length===0&&de.length===0&&te.length===0&&ae.length===0&&pe.length===0,se=G("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(vf,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Ra,{className:G("gap-0 p-1.5",se),children:u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(zd,{})})}),u.jsxs(Ke,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(ii,{shortcut:"mod+b"})]})]})}),u.jsxs(Ma,{className:G("gap-2 px-1 py-1",se),children:[u.jsxs(Lr,{className:"items-center gap-0.5",children:[J.map(A=>u.jsx(Ni,{document:A,compact:!0},A.name)),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{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:[Z.map(A=>u.jsx(Ni,{document:A,compact:!0},A.name)),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{className:"size-7","aria-label":"New theme",onClick:()=>v(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(Ra,{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:W,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(Ug,{})})}),u.jsxs(Ke,{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(Jg,{"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:I,type:"text",value:z,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:A=>P(A.target.value),onKeyDown:A=>{A.key==="Escape"&&(A.preventDefault(),P(""),A.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 A;P(""),(A=I.current)==null||A.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(yn,{})}):u.jsx(If,{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(Ma,{className:G("gap-0 px-2 pb-2",se),children:U?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 A;P(""),(A=I.current)==null||A.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:[(C>0||!Y)&&u.jsxs("section",{children:[u.jsx(Da,{open:De,onToggle:()=>B("documents"),count:C||void 0,actions:u.jsxs(u.Fragment,{children:[ht==="docx"&&u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"Compare documents",disabled:J.length<2,onClick:()=>q(!0),children:u.jsx(Nd,{})})}),u.jsx(Ke,{side:"bottom",children:J.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),De&&u.jsxs(Lr,{className:"gap-0.5",children:[D.map(A=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:A,query:Y}),!Y&&l===A.name&&u.jsx(_l,{})]},A.name)),ue.map(([A,K])=>u.jsxs(x.Fragment,{children:[ue.length>1&&u.jsx(jl,{location:A}),K.map(ee=>u.jsx(Nl,{name:ee.name,subtitle:ee.title,query:Y,onSelect:()=>X(ee.name,!1)},ee.path||ee.name))]},A)),C===0&&u.jsx("li",{className:"list-none",children:u.jsx(xl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]})]}),($>0||!Y)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Da,{open:nt,onToggle:()=>B("themes"),count:$||void 0,actions:u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Ht,{"aria-label":"New theme",onClick:()=>v(!0),children:u.jsx(nn,{})})}),u.jsx(Ke,{side:"bottom",children:"New theme"})]}),children:"Themes"}),nt&&u.jsxs(Lr,{className:"gap-0.5",children:[de.map(A=>u.jsxs(x.Fragment,{children:[u.jsx(Ni,{document:A,query:Y}),!Y&&l===A.name&&u.jsx(_l,{})]},A.name)),ge.map(([A,K])=>u.jsxs(x.Fragment,{children:[ge.length>1&&u.jsx(jl,{location:A}),K.map(ee=>u.jsx(Nl,{name:ee.name,subtitle:ee.description,query:Y,onSelect:()=>X(ee.name,!0)},ee.path||ee.name))]},A)),$===0&&u.jsx("li",{className:"list-none",children:u.jsx(xl,{icon:nn,label:"New theme",onClick:()=>v(!0)})})]})]}),u.jsx(ob,{plugins:pe,query:Y,open:Pe("plugins"),onToggleSection:()=>B("plugins"),onShowPluginDetails:A=>{m(A),b(!0)},isPluginSelected:N,onTogglePlugin:O,isApplyingPlugins:k,selectedPluginCount:w.size})]})})]}),u.jsx(wf,{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(ub,{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:V,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(Ct,{open:g,onOpenChange:v,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:A=>{b(A),A||m(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(ib,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:E})})}),u.jsx(yx,{open:R,onOpenChange:q})]})}const Cl=x.memo(cb),db=x.lazy(()=>_d(()=>import("./editor-edmvhW9F.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function Tl(){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(db,{})})}const fb=x.lazy(()=>_d(()=>import("./preview-zo-CHAU0.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));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 preview..."})]})}),children:u.jsx(fb,{})})}const{createElement:xr,createContext:pb,forwardRef:Af,useCallback:gt,useContext:zf,useEffect:zn,useImperativeHandle:Of,useLayoutEffect:hb,useMemo:mb,useRef:wt,useState:ar}=Zc,Al=Zc[`useId${Math.random()}`.slice(0,5)],gb=hb,Ts=pb(null);Ts.displayName="PanelGroupContext";const On=gb,xb=typeof Al=="function"?Al:()=>null;let yb=0;function So(e=null){const t=xb(),n=wt(e||t||null);return n.current===null&&(n.current=""+yb++),e??n.current}function Pf({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:d,onResize:f,order:h,style:p,tagName:g="div",...v}){const _=zf(Ts);if(_===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:E,getPanelSize:m,getPanelStyle:O,groupId:N,isPanelCollapsed:w,reevaluatePanelConstraints:k,registerPanel:R,resizePanel:q,unregisterPanel:j}=_,T=So(a),z=wt({callbacks:{onCollapse:c,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:T,idIsFromProps:a!==void 0,order:h});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:I,constraints:M}=z.current,J={...M};z.current.id=T,z.current.idIsFromProps=a!==void 0,z.current.order=h,I.onCollapse=c,I.onExpand=d,I.onResize=f,M.collapsedSize=n,M.collapsible=r,M.defaultSize=i,M.maxSize=o,M.minSize=l,(J.collapsedSize!==M.collapsedSize||J.collapsible!==M.collapsible||J.maxSize!==M.maxSize||J.minSize!==M.minSize)&&k(z.current,J)}),On(()=>{const I=z.current;return R(I),()=>{j(I)}},[h,T,R,j]),Of(s,()=>({collapse:()=>{b(z.current)},expand:I=>{E(z.current,I)},getId(){return T},getSize(){return m(z.current)},isCollapsed(){return w(z.current)},isExpanded(){return!w(z.current)},resize:I=>{q(z.current,I)}}),[b,E,m,w,T,q]);const P=O(z.current,i);return xr(g,{...v,children:e,className:t,id:a,style:{...P,...p},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":N,"data-panel-id":T,"data-panel-size":parseFloat(""+P.flexGrow).toFixed(1)})}const Df=Af((e,t)=>xr(Pf,{...e,forwardedRef:t}));Pf.displayName="Panel";Df.displayName="forwardRef(Panel)";let Fa=null,An=null;function bb(e,t){if(t){const n=(t&Lf)!==0,r=(t&Bf)!==0,i=(t&Zf)!==0,s=(t&Vf)!==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 vb(){An!==null&&(document.head.removeChild(An),Fa=null,An=null)}function Ys(e,t){const n=bb(e,t);Fa!==n&&(Fa=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Rf(e){return e.type==="keydown"}function Mf(e){return e.type.startsWith("pointer")}function $f(e){return e.type.startsWith("mouse")}function Is(e){if(Mf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if($f(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function wb(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function kb(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 Sb(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Pl(e),b:Pl(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:Ol(zl(n.a)),b:Ol(zl(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 _b=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function jb(e){var t;const n=getComputedStyle((t=Ff(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function Nb(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||jb(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"||_b.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function zl(e){let t=e.length;for(;t--;){const n=e[t];if(_e(n,"Missing node"),Nb(n))return n}return null}function Ol(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Pl(e){const t=[];for(;e;)t.push(e),e=Ff(e);return t}function Ff(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Lf=1,Bf=2,Zf=4,Vf=8,Eb=wb()==="coarse";let Bt=[],or=!1,mn=new Map,As=new Map;const si=new Set;function Cb(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 d;As.delete(e),si.delete(o);const f=(d=mn.get(a))!==null&&d!==void 0?d:1;if(mn.set(a,f-1),ns(),f===1&&mn.delete(a),Bt.includes(o)){const h=Bt.indexOf(o);h>=0&&Bt.splice(h,1),jo(),i("up",!0,null)}}}function Dl(e){const{target:t}=e,{x:n,y:r}=Is(e);or=!0,_o({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;_o({target:r,x:t,y:n})}rs("move",e),jo(),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),_o({target:t,x:n,y:r}),jo(),ns()}function _o({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:d,top:f}=o,h=Eb?a.coarse:a.fine;if(t>=c-h&&t<=d+h&&n>=f-h&&n<=l+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&Sb(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(kb(g.getBoundingClientRect(),o)){v=!0;break}g=g.parentElement}if(v)return}Bt.push(i)}})}function Ks(e,t){As.set(e,t)}function jo(){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?Ys("intersection",n):e?Ys("horizontal",n):t?Ys("vertical",n):vb()}function ns(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Un),n.removeEventListener("pointerdown",Dl),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",Dl,{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 Tb(){const[e,t]=ar(0);return gt(()=>t(n=>n+1),[])}function _e(e,t){if(!e)throw console.error(t),Error(t)}const No=10;function Dn(e,t,n=No){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function sn(e,t,n=No){return Dn(e,t,n)===0}function Nt(e,t,n){return Dn(e,t,n)===0}function Ib(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(No)),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 f=e<0?l:o,h=n[f];_e(h,`Panel constraints not found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:v=0}=h;if(g){const _=t[f];if(_e(_!=null,`Previous layout not found for panel index ${f}`),Nt(_,p)){const b=v-_;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const f=e<0?o:l,h=n[f];_e(h,`No panel constraints found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:v=0}=h;if(g){const _=t[f];if(_e(_!=null,`Previous layout not found for panel index ${f}`),Nt(_,v)){const b=_-p;Dn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const f=e<0?1:-1;let h=e<0?l:o,p=0;for(;;){const v=t[h];_e(v!=null,`Previous layout not found for panel index ${h}`);const b=tr({panelConstraints:n,panelIndex:h,size:100})-v;if(p+=b,h+=f,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 v=g-p,_=tr({panelConstraints:n,panelIndex:h,size:v});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(Ib(i,a))return i;{const f=e<0?l:o,h=t[f];_e(h!=null,`Previous layout not found for panel index ${f}`);const p=h+c,g=tr({panelConstraints:n,panelIndex:f,size:p});if(a[f]=g,!Nt(g,p)){let v=p-g,b=e<0?l:o;for(;b>=0&&b<n.length;){const E=a[b];_e(E!=null,`Previous layout not found for panel index ${b}`);const m=E+v,O=tr({panelConstraints:n,panelIndex:b,size:m});if(Nt(E,O)||(v-=O-E,a[b]=O),Nt(v,0))break;e>0?b--:b++}}}const d=a.reduce((f,h)=>h+f,0);return Nt(d,100)?a:i}function Ab({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((f,h)=>{const{constraints:p}=f,{maxSize:g=100,minSize:v=0}=p;h===o?(r=v,i=g):(s+=v,a+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-a),d=e[o];return{valueMax:l,valueMin:c,valueNow:d}}function ai(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function Uf(e,t,n=document){const i=ai(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Jf(e,t,n){const r=Uf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Hf(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 zb(e,t,n,r=document){var i,s,a,o;const l=zs(t,r),c=ai(e,r),d=l?c.indexOf(l):-1,f=(i=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,h=(a=(o=n[d+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[f,h]}function Ob({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:d,valueNow:f}=Ab({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(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}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=Hf(n,s);_e(c!=null,`No group found for id "${n}"`);const d=ai(n,s);_e(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const p=h.getAttribute("data-panel-resize-handle-id");_e(p,"Resize handle element has no handle id attribute");const[g,v]=zb(n,p,l,s);if(g==null||v==null)return()=>{};const _=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const E=l.findIndex(m=>m.id===g);if(E>=0){const m=l[E];_e(m,`No panel data found for index ${E}`);const O=r[E],{collapsedSize:N=0,collapsible:w,minSize:k=0}=m.constraints;if(O!=null&&w){const R=Br({delta:Nt(O,N)?k-N:N-O,initialLayout:r,panelConstraints:l.map(q=>q.constraints),pivotIndices:Jf(n,p,s),prevLayout:r,trigger:"keyboard"});r!==R&&a(R)}}break}}};return h.addEventListener("keydown",_),()=>{h.removeEventListener("keydown",_)}});return()=>{f.forEach(h=>h())}},[s,e,t,n,r,i,a])}function Rl(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 Wf(e,t){const n=e==="horizontal",{x:r,y:i}=Is(t);return n?r:i}function Pb(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=Wf(n,e),d=Hf(o,i);_e(d,`No group element found for id "${o}"`);const f=d.getBoundingClientRect(),h=s?f.width:f.height;return(c-l)/h*100}function Db(e,t,n,r,i,s){if(Rf(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:Pb(e,t,n,r,s)}function Rb({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:d}=o,f=n[l];if(f==null||r!==f){n[l]=r;const{onCollapse:h,onExpand:p,onResize:g}=a;g&&g(r,f),d&&(h||p)&&(p&&(f==null||sn(f,c))&&!sn(r,c)&&p(),h&&(f==null||!sn(f,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 Mb({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 $b(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Ml(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 qf(e){return`react-resizable-panels:${e}`}function Gf(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 Yf(e,t){try{const n=qf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Fb(e,t,n){var r,i;const s=(r=Yf(e,n))!==null&&r!==void 0?r:{},a=Gf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Lb(e,t,n,r,i){var s;const a=qf(e),o=Gf(t),l=(s=Yf(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 $l({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 Bb=100,Zr={getItem:e=>(Ml(Zr),Zr.getItem(e)),setItem:(e,t)=>{Ml(Zr),Zr.setItem(e,t)}},Fl={};function Kf({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:d="div",...f}){const h=So(s),p=wt(null),[g,v]=ar(null),[_,b]=ar([]),E=Tb(),m=wt({}),O=wt(new Map),N=wt(0),w=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:[]}),Of(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:y}=k.current;return y},setLayout:y=>{const{onLayout:W}=w.current,{layout:X,panelDataArray:Y}=k.current,re=$l({layout:y,panelConstraints:Y.map(D=>D.constraints)});Rl(X,re)||(b(re),k.current.layout=re,W&&W(re),Jn(Y,re,m.current))}}),[]),On(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=g,w.current.id=h,w.current.onLayout=a,w.current.storage=l}),Ob({committedValuesRef:w,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 W=Fl[e];W==null&&(W=$b(Lb,Bb),Fl[e]=W);const X=[...y],Y=new Map(O.current);W(e,X,Y,_,l)}},[e,_,l]),zn(()=>{});const R=gt(y=>{const{onLayout:W}=w.current,{layout:X,panelDataArray:Y}=k.current;if(y.constraints.collapsible){const re=Y.map(ae=>ae.constraints),{collapsedSize:D=0,panelSize:de,pivotIndices:te}=jn(Y,y,X);if(_e(de!=null,`Panel size not found for panel "${y.id}"`),!sn(de,D)){O.current.set(y.id,de);const ue=Kn(Y,y)===Y.length-1?de-D:D-de,ge=Br({delta:ue,initialLayout:X,panelConstraints:re,pivotIndices:te,prevLayout:X,trigger:"imperative-api"});Ci(X,ge)||(b(ge),k.current.layout=ge,W&&W(ge),Jn(Y,ge,m.current))}}},[]),q=gt((y,W)=>{const{onLayout:X}=w.current,{layout:Y,panelDataArray:re}=k.current;if(y.constraints.collapsible){const D=re.map(pe=>pe.constraints),{collapsedSize:de=0,panelSize:te=0,minSize:ae=0,pivotIndices:ue}=jn(re,y,Y),ge=W??ae;if(sn(te,de)){const pe=O.current.get(y.id),Pe=pe!=null&&pe>=ge?pe:ge,nt=Kn(re,y)===re.length-1?te-Pe:Pe-te,C=Br({delta:nt,initialLayout:Y,panelConstraints:D,pivotIndices:ue,prevLayout:Y,trigger:"imperative-api"});Ci(Y,C)||(b(C),k.current.layout=C,X&&X(C),Jn(re,C,m.current))}}},[]),j=gt(y=>{const{layout:W,panelDataArray:X}=k.current,{panelSize:Y}=jn(X,y,W);return _e(Y!=null,`Panel size not found for panel "${y.id}"`),Y},[]),T=gt((y,W)=>{const{panelDataArray:X}=k.current,Y=Kn(X,y);return Mb({defaultSize:W,dragState:g,layout:_,panelData:X,panelIndex:Y})},[g,_]),z=gt(y=>{const{layout:W,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:re,panelSize:D}=jn(X,y,W);return _e(D!=null,`Panel size not found for panel "${y.id}"`),re===!0&&sn(D,Y)},[]),P=gt(y=>{const{layout:W,panelDataArray:X}=k.current,{collapsedSize:Y=0,collapsible:re,panelSize:D}=jn(X,y,W);return _e(D!=null,`Panel size not found for panel "${y.id}"`),!re||Dn(D,Y)>0},[]),I=gt(y=>{const{panelDataArray:W}=k.current;W.push(y),W.sort((X,Y)=>{const re=X.order,D=Y.order;return re==null&&D==null?0:re==null?-1:D==null?1:re-D}),k.current.panelDataArrayChanged=!0,E()},[E]);On(()=>{if(k.current.panelDataArrayChanged){k.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:W,storage:X}=w.current,{layout:Y,panelDataArray:re}=k.current;let D=null;if(y){const te=Fb(y,re,X);te&&(O.current=new Map(Object.entries(te.expandToSizes)),D=te.layout)}D==null&&(D=Rb({panelDataArray:re}));const de=$l({layout:D,panelConstraints:re.map(te=>te.constraints)});Rl(Y,de)||(b(de),k.current.layout=de,W&&W(de),Jn(re,de,m.current))}}),On(()=>{const y=k.current;return()=>{y.layout=[]}},[]);const M=gt(y=>{let W=!1;const X=p.current;return X&&window.getComputedStyle(X,null).getPropertyValue("direction")==="rtl"&&(W=!0),function(re){re.preventDefault();const D=p.current;if(!D)return()=>null;const{direction:de,dragState:te,id:ae,keyboardResizeBy:ue,onLayout:ge}=w.current,{layout:pe,panelDataArray:Pe}=k.current,{initialLayout:De}=te??{},nt=Jf(ae,y,D);let C=Db(re,y,de,te,ue,D);const $=de==="horizontal";$&&W&&(C=-C);const U=Pe.map(K=>K.constraints),se=Br({delta:C,initialLayout:De??pe,panelConstraints:U,pivotIndices:nt,prevLayout:pe,trigger:Rf(re)?"keyboard":"mouse-or-touch"}),A=!Ci(pe,se);(Mf(re)||$f(re))&&N.current!=C&&(N.current=C,!A&&C!==0?$?Ks(y,C<0?Lf:Bf):Ks(y,C<0?Zf:Vf):Ks(y,0)),A&&(b(se),k.current.layout=se,ge&&ge(se),Jn(Pe,se,m.current))}},[]),J=gt((y,W)=>{const{onLayout:X}=w.current,{layout:Y,panelDataArray:re}=k.current,D=re.map(pe=>pe.constraints),{panelSize:de,pivotIndices:te}=jn(re,y,Y);_e(de!=null,`Panel size not found for panel "${y.id}"`);const ue=Kn(re,y)===re.length-1?de-W:W-de,ge=Br({delta:ue,initialLayout:Y,panelConstraints:D,pivotIndices:te,prevLayout:Y,trigger:"imperative-api"});Ci(Y,ge)||(b(ge),k.current.layout=ge,X&&X(ge),Jn(re,ge,m.current))},[]),Z=gt((y,W)=>{const{layout:X,panelDataArray:Y}=k.current,{collapsedSize:re=0,collapsible:D}=W,{collapsedSize:de=0,collapsible:te,maxSize:ae=100,minSize:ue=0}=y.constraints,{panelSize:ge}=jn(Y,y,X);ge!=null&&(D&&te&&sn(ge,re)?sn(re,de)||J(y,de):ge<ue?J(y,ue):ge>ae&&J(y,ae))},[J]),V=gt((y,W)=>{const{direction:X}=w.current,{layout:Y}=k.current;if(!p.current)return;const re=zs(y,p.current);_e(re,`Drag handle element not found for id "${y}"`);const D=Wf(X,W);v({dragHandleId:y,dragHandleRect:re.getBoundingClientRect(),initialCursorPosition:D,initialLayout:Y})},[]),ne=gt(()=>{v(null)},[]),S=gt(y=>{const{panelDataArray:W}=k.current,X=Kn(W,y);X>=0&&(W.splice(X,1),delete m.current[y.id],k.current.panelDataArrayChanged=!0,E())},[E]),le=mb(()=>({collapsePanel:R,direction:r,dragState:g,expandPanel:q,getPanelSize:j,getPanelStyle:T,groupId:h,isPanelCollapsed:z,isPanelExpanded:P,reevaluatePanelConstraints:Z,registerPanel:I,registerResizeHandle:M,resizePanel:J,startDragging:V,stopDragging:ne,unregisterPanel:S,panelGroupElement:p.current}),[R,g,r,q,j,T,h,z,P,Z,I,M,J,V,ne,S]),B={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return xr(Ts.Provider,{value:le},xr(d,{...f,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 Xf=Af((e,t)=>xr(Kf,{...e,forwardedRef:t}));Kf.displayName="PanelGroup";Xf.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 Zb({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=Uf(o,t,r);_e(c!==null,`No resize element found for id "${t}"`);const d=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[d].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function Qf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:d="div",...f}){var h,p;const g=wt(null),v=wt({onDragging:a});zn(()=>{v.current.onDragging=a});const _=zf(Ts);if(_===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:b,groupId:E,registerResizeHandle:m,startDragging:O,stopDragging:N,panelGroupElement:w}=_,k=So(i),[R,q]=ar("inactive"),[j,T]=ar(!1),[z,P]=ar(null),I=wt({state:R});On(()=>{I.current.state=R}),zn(()=>{if(n)P(null);else{const V=m(k);P(()=>V)}},[n,k,m]);const M=(h=r==null?void 0:r.coarse)!==null&&h!==void 0?h:15,J=(p=r==null?void 0:r.fine)!==null&&p!==void 0?p:5;return zn(()=>{if(n||z==null)return;const V=g.current;return _e(V,"Element ref not attached"),Cb(k,V,b,{coarse:M,fine:J},(S,le,B)=>{if(le)switch(S){case"down":{q("drag"),_e(B,'Expected event to be defined for "down" action'),O(k,B);const{onDragging:y}=v.current;y&&y(!0);break}case"move":{const{state:y}=I.current;y!=="drag"&&q("hover"),_e(B,'Expected event to be defined for "move" action'),z(B);break}case"up":{q("hover"),N();const{onDragging:y}=v.current;y&&y(!1);break}}else q("inactive")})},[M,b,n,J,m,k,z,O,N]),Zb({disabled:n,handleId:k,resizeHandler:z,panelGroupElement:w}),xr(d,{...f,children:e,className:t,id:i,onBlur:()=>{T(!1),s==null||s()},onFocus:()=>{T(!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":E,"data-resize-handle":"","data-resize-handle-active":R==="drag"?"pointer":j?"keyboard":void 0,"data-resize-handle-state":R,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":k})}Qf.displayName="PanelResizeHandle";const Vb=({className:e,...t})=>u.jsx(Xf,{className:G("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Xs=Df,Ll=({withHandle:e,className:t,...n})=>u.jsx(Qf,{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(Hg,{className:"h-2.5 w-2.5"})})}),ep=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}));ep.displayName="Textarea";class Ub{constructor(t){nl(this,"client");this.client=px.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 Jb=new Ub;function Hb(e,t){return e??t}function Wb(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(Wb(e.headers.get("content-type")))try{return await e.json()}catch{return}}function Gb(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 Yb(){const e=x.useRef(null),t=Hi(i=>i.generationBackend),n=x.useCallback(async(i,s,a,o,l)=>{e.current&&e.current.abort();const c=new AbortController;e.current=c;const d=Hb(l==null?void 0:l.renderer,t);try{o==null||o("parsing","Validating JSON structure...");let f;try{f=JSON.parse(s)}catch(R){throw new Error(`Invalid JSON: ${R instanceof Error?R.message:"Unknown parse error"}`)}o==null||o("building",`Building ${ji.toLowerCase()} structure...`);const h={jsonDefinition:f,options:{...l,sourceName:i,...d?{renderer:d}:{}}};h.customThemes=a??{},o==null||o("rendering",`Generating ${ht.toUpperCase()} content...`);const p={"Content-Type":"application/json"};l!=null&&l.bypassCache&&(p["X-Bypass-Cache"]="true");const g=await fetch(ei.generate,{method:"POST",headers:p,body:JSON.stringify(h),signal:c.signal}),v=await qb(g);if(!g.ok||!(v!=null&&v.success))throw new Error(Gb(g,v));const{data:_,cache:b,warnings:E}=v,m=b.status==="HIT"?"HIT":b.status==="MISS"?"MISS":"UNKNOWN",O=m==="HIT"?`Served from cache (Hit rate: ${b.hitRate})`:`Generated fresh ${ji.toLowerCase()}`;o==null||o("finalizing",O);const N=globalThis.atob(_.document),w=new Uint8Array(N.length);for(let R=0;R<N.length;R++)w[R]=N.charCodeAt(R);const k=new Blob([w],{type:_.contentType});if(k.size===0)throw new Error(`Received empty ${ji.toLowerCase()} from API`);return{name:i,text:s,blob:k,...d?{renderer:d}:{},filename:_.filename,fileId:_.fileId,cacheStatus:m,cacheHitRate:b.hitRate,warnings:E}}catch(f){throw f instanceof Error&&f.name==="AbortError"?new Error(`${ji} generation was cancelled`):f}finally{e.current===c&&(e.current=null)}},[t]),r=x.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:n,generateDocument:n,cancelGeneration:r}}const Bi={ids:[],default:null};let Bl;function Kb(){return Bl??(Bl=(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}})()),Bl}function Xb(){const[e,t]=x.useState(Bi);return x.useEffect(()=>{let n=!1;return Kb().then(r=>{n||t(r)}),()=>{n=!0}},[]),e}function Qb(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,d])=>`${c}: ${JSON.stringify(d)}`).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 ev({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 Qs(){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 Zl(){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 tv({name:e,blob:t,onManualRender:n,isGenerating:r,isRendering:i,onShowCacheMetrics:s,onShowSchemas:a,onShowFonts:o,documentText:l,editorDocumentText:c,warnings:d,onToggleChat:f,chatOpen:h,onTogglePreview:p,previewOpen:g}){const[v,_]=x.useState(!1),[b,E]=x.useState(!1),[m,O]=x.useState(!1),[N,w]=x.useState(!1),[k,R]=x.useState(!1),[q,j]=x.useState(null),{toast:T}=Sr(),{generateDocument:z}=Yb(),P=x.useContext(Rd),I=Xb(),M=Hi(te=>te.generationBackend),J=Hi(te=>te.setSettings),Z=M??I.default??void 0,V=x.useCallback(()=>{const te={},{customThemes:ae}=P.getState();return Object.values(ae).forEach(ue=>{ue.valid&&ue.parsed&&(te[ue.name]=ue.parsed)}),te},[P]),ne=je.useMemo(()=>{if(!l)return[];try{const te=JSON.parse(l);return[...(ht==="pptx"?vg:wg)(te)].filter(ue=>!kg(ue))}catch{return[]}},[l]),[S,le]=x.useState(!1),B=x.useCallback(async()=>{if(t){_(!0);try{await new Promise(te=>setTimeout(te,100)),Li(`${e}${Tr}`,t)}finally{setTimeout(()=>_(!1),500)}}},[t,e]),y=x.useCallback(async()=>{if(t){if(ne.length===0){await B();return}le(!0)}},[t,ne.length,B]),W=x.useCallback(async te=>{var ae;if(l){_(!0);try{const ue=await z(e,l,V(),void 0,{bypassCache:!0,fonts:{mode:te}});if(ue.blob.size===0)T({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Li(`${e}${Tr}`,ue.blob);const ge=(ae=ue.warnings)==null?void 0:ae.find(pe=>{var Pe,De;return((Pe=pe.context)==null?void 0:Pe.code)==="FONT_MODE_SUBSTITUTED"||((De=pe.context)==null?void 0:De.code)==="FONT_MODE_CUSTOM"});ge&&T({title:te==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:ge.message})}}catch(ue){T({title:"Export failed",description:ue instanceof Error?ue.message:String(ue),variant:"destructive"})}finally{setTimeout(()=>_(!1),500)}}},[l,e,z,T,V]),X=x.useCallback(async()=>{if(!(!d||d.length===0)){E(!0);try{const te=Qb(d);if(!te){T({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const ae=await z("warnings",JSON.stringify(te,null,2),{});ae&&typeof ae=="object"&&"blob"in ae&&ae.blob&&(Li(`${e}-warnings${Tr}`,ae.blob),T({title:"Warnings downloaded",description:`Downloaded warnings document with ${d.length} warning(s).`}))}catch(te){console.error("Failed to generate warnings document:",te),T({title:"Download failed",description:te instanceof Error?te.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>E(!1),500)}}},[d,e,z,T]),Y=x.useCallback(async()=>{O(!0);try{await Jb.delete(`/${ht}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),T({title:"Cache Cleared",description:"All active caches have been successfully cleared.",variant:"default"})}catch(te){console.error("Failed to clear cache:",te),T({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{O(!1)}},[T]),re=c??l,D=x.useCallback(()=>{var ue,ge;if(!re){T({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(re)}catch{T({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}R(!0);const te=(async()=>{const pe=await fetch(`/api/${ht}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:re,customThemes:V(),options:{sourceName:e}})});if(!pe.ok){let De=`Request failed with status ${pe.status}`;try{const nt=await pe.json(),C=nt.error??nt.message;typeof C=="string"&&C&&(De=C)}catch{}throw new Error(De)}const Pe=await pe.json();return JSON.stringify(Pe.data,null,2)})();let ae;typeof ClipboardItem<"u"&&((ue=navigator.clipboard)!=null&&ue.write)?ae=navigator.clipboard.write([new ClipboardItem({"text/plain":te.then(pe=>new Blob([pe],{type:"text/plain"}))})]):(ge=navigator.clipboard)!=null&&ge.writeText?ae=te.then(pe=>navigator.clipboard.writeText(pe)):ae=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await ae,T({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(pe){let Pe=null;try{Pe=await te}catch(De){console.error("Error fetching standard components:",De),T({title:"Failed to get standard components",description:De instanceof Error?De.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",pe),j(Pe)}finally{R(!1)}})()},[re,e,V,T]),de=x.useCallback(async()=>{if(q!=null)try{await navigator.clipboard.writeText(q),T({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),j(null)}catch{T({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[q,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(Ge,{children:[u.jsx(Ye,{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(Ad,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Ke,{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(Ge,{children:[u.jsx(Ye,{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||g===!1,children:[i?u.jsx(gn,{size:"sm"}):u.jsx(Wg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:g===!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(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsxs(Se,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||v||r,onClick:y,children:[v?u.jsx(gn,{size:"sm"}):u.jsx(qg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download ",Tr]})})]}),d&&d.length>0&&u.jsxs(Ge,{children:[u.jsx(Ye,{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:b||r,onClick:X,children:b?u.jsx(gn,{size:"sm"}):u.jsx(Od,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download warnings (",d.length,")"]})})]}),I.ids.length>1&&u.jsxs(ti,{value:Z,onValueChange:te=>J({generationBackend:te}),children:[u.jsxs(Ge,{children:[u.jsx(Ye,{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(ja,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),u.jsxs(ni,{placeholder:"Renderer",children:[u.jsx("span",{className:"font-medium",children:Z}),Z!==I.default&&u.jsx(Qs,{})]})]})}),u.jsx(Ke,{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($d,{children:[u.jsx(po,{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),I.ids.map(te=>u.jsx(Pn,{value:te,className:"text-xs",children:u.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap",children:[u.jsx("span",{className:"font-medium",children:te}),te===I.default?u.jsx(Zl,{}):u.jsx(Qs,{})]})},te))]})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(Ns,{children:[u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Es,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Td,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ke,{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(Gg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),o&&u.jsxs($t,{onClick:o,children:[u.jsx(_a,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),s&&u.jsxs($t,{onClick:s,children:[u.jsx(Na,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),re?u.jsxs($t,{onClick:D,disabled:k,children:[u.jsx(Ea,{className:"h-4 w-4 mr-2"}),k?"Copying...":"Copy standard components"]}):u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs($t,{disabled:!0,children:[u.jsx(Ea,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),u.jsx(Ke,{side:"left",children:u.jsx("p",{children:"No document selected — open or select a document first"})})]}),u.jsx(mr,{}),u.jsxs($t,{onClick:()=>w(!0),disabled:m,className:"text-destructive focus:text-destructive",children:[u.jsx(co,{className:"h-4 w-4 mr-2"}),m?"Clearing...":"Clear all caches"]}),I.ids.length>1&&u.jsxs(u.Fragment,{children:[u.jsx(mr,{className:"lg:hidden"}),u.jsx(wo,{className:"lg:hidden px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),I.ids.map(te=>u.jsxs($t,{className:"lg:hidden gap-1.5",onClick:()=>J({generationBackend:te}),children:[u.jsx(an,{className:`h-3.5 w-3.5 shrink-0 ${Z===te?"opacity-100":"opacity-0"}`}),u.jsx("span",{className:"font-medium",children:te}),te===I.default?u.jsx(Zl,{}):u.jsx(Qs,{})]},te))]})]})]}),p&&u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Se,{variant:g?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:p,children:g?u.jsx(Pd,{className:"h-3.5 w-3.5"}):u.jsx(Yg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[g?"Hide":"Show"," Preview"," ",u.jsx(ii,{shortcut:"mod+shift+p"})]})})]}),f&&u.jsxs(Ge,{children:[u.jsx(Ye,{asChild:!0,children:u.jsx(Se,{variant:h?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:f,children:u.jsx(Dd,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[h?"Close":"Open"," AI Chat"," ",u.jsx(ii,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(ev,{open:S,onClose:()=>le(!1),nonSafeFonts:ne,onChoose:W}),u.jsx(Ct,{open:q!=null,onOpenChange:te=>{te||j(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(ep,{readOnly:!0,value:q??"",className:"h-64 font-mono text-xs",onFocus:te=>te.currentTarget.select()}),u.jsxs(bn,{children:[u.jsx(Se,{variant:"outline",size:"sm",onClick:()=>j(null),children:"Close"}),u.jsx(Se,{size:"sm",onClick:de,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:N,onOpenChange:w,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:()=>w(!1),children:"Cancel"}),u.jsx(Se,{variant:"destructive",size:"sm",disabled:m,onClick:async()=>{await Y(),w(!1)},children:m?u.jsx(gn,{size:"sm"}):"Clear"})]})]})})]})}const nv=je.memo(tv),tp=mg,Eo=x.forwardRef(({className:e,...t},n)=>u.jsx(vd,{ref:n,className:G("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Eo.displayName=vd.displayName;const lr=x.forwardRef(({className:e,...t},n)=>u.jsx(wd,{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=wd.displayName;const ur=x.forwardRef(({className:e,...t},n)=>u.jsx(kd,{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=kd.displayName;async function rv(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 iv(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 sv(e){const t=iv(e);return rv(t)}const av=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=x.useState(n),[s,a]=x.useState(null),[o,l]=x.useState(null),[c,d]=x.useState(!1),[f,h]=x.useState(!1),[p,g]=x.useState(null),[v,_]=x.useState(null),[b,E]=x.useState(!1),{toast:m}=Sr(),O=Lt(P=>P.selectedPlugins),N=Array.from(O);x.useEffect(()=>{n&&i(n)},[n]);const w=x.useCallback(async()=>{d(!0),g(null);try{const P=await Vs.fetchDocumentSchema(N);a(P)}catch(P){const I=P instanceof Error?P.message:"Failed to load document schema";g(I),m({variant:"destructive",title:"Error loading schema",description:I})}finally{d(!1)}},[N,m]),k=x.useCallback(async()=>{if(!o){h(!0),_(null);try{const P=await Vs.fetchThemeSchema();l(P)}catch(P){const I=P instanceof Error?P.message:"Failed to load theme schema";_(I),m({variant:"destructive",title:"Error loading schema",description:I})}finally{h(!1)}}},[o,m]),[R,q]=x.useState([]);x.useEffect(()=>{e||(a(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const P=N.length!==R.length||N.some((I,M)=>I!==R[M]);r==="document"?(!s||P)&&(P&&(Vs.clearPluginSchemaCache(),q([...N])),c||w()):r==="theme"&&!o&&!f&&k()},[r,e,s,o,c,f,N,R,w,k]);const j=N.length,T=r==="document"?s:o,z=async()=>{if(T)try{await sv(T)&&(E(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>E(!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(tp,{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(Eo,{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:z,disabled:b||!T,"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:f,error:v||void 0})})]})]})]})})};function np(e,t,n){if(t.length===0)return n;const r=Vl(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=Vl(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function Vl(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Ul=2*1024*1024,Jl=12*1024*1024;function ov(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 lv(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 uv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>Ul)return{ok:!1,message:`"${e}" is ${is(t.length)}. The limit is ${is(Ul)} per font, because the bytes travel inside the document JSON.`};const n=ov(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:lv(t)}}const cv=new Set(["italic","oblique"]);function dv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[a,o]of Object.entries(jd))r.set(o.toLowerCase(),Number(a));let i=400,s=!1;for(;n.length>1;){const a=n[n.length-1].toLowerCase();if(cv.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 fv(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 pv(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 hv(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(o=>{const l=pv(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 mv(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=fv(n,hv(s,r.family,i,r.category))}return n}function gv(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 xv(e){const t=new TextEncoder().encode(e).length;return t<=Jl?null:`Adding this font would push the document to ${is(t)}, past the ${is(Jl)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const Hl=new Set,yv=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function bv(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 vv(e,t,n,r){const i=yv(e,n,r);if(!Hl.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=bv(t),a=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await a.load(),document.fonts.add(a),Hl.add(i)}catch{}}const wv={safe:[],google:[]};function Wl(e,t){var d;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((d=r==null?void 0:r.dataset.weights)==null?void 0:d.split(",").map(Number).filter(f=>!Number.isNaN(f)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((f,h)=>f-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((f,h)=>f-h).join(",")}function kv(){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(l=>l.name===e);if(!s)return{ok:!1,error:"Active theme not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active theme is not valid JSON: ${l.message}`}}const o=i(a);return r(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n,r])}function Sv(){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(l=>l.name===e);if(!s)return{ok:!1,error:"Active document not found"};let a;try{a=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active document is not valid JSON: ${l.message}`}}const o=np(a,r,i);return n(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n])}function _v(){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 f;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(h=>h.name===e);if(!s)return{ok:!1,error:"Active document not found"};let a;try{a=JSON.parse(s.text)}catch(h){return{ok:!1,error:`Active document is not valid JSON: ${h.message}`}}const o=mv((f=a==null?void 0:a.props)==null?void 0:f.fontRegistry,i),l=np(a,["props","fontRegistry"],o),c=JSON.stringify(l,null,2),d=xv(c);return d?{ok:!1,error:d}:(r(e,c),{ok:!0,name:e})},[e,t,n,r])}function jv(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 ql(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Nv=({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(wv),[d,f]=x.useState(!1),[h,p]=x.useState(""),[g,v]=x.useState("safe"),[_,b]=x.useState(null),[E,m]=x.useState(null),[O,N]=x.useState(!1),[w,k]=x.useState(!1),[R,q]=x.useState(""),[j,T]=x.useState([]),z=x.useRef(null),{toast:P}=Sr(),I=kv(),M=Sv(),J=_v(),Z=Ne(D=>D.activeTab),V=Ne(D=>D.documentTypes),ne=Z&&V[Z]==="application/json+theme",S=!!a||ne;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(f(!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(()=>f(!1))))},[s,l,P]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const D of l.google)Wl(D.family,D.weights)},[g,l]);const le=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]),W=x.useCallback(async(D,de,te)=>{b(D);try{const ae=I(ue=>(jv(ue,te,D),ue));if(!ae.ok){P({variant:"destructive",title:"Could not insert font",description:ae.error});return}P({title:"Font inserted",description:`${D} set as ${te} font in "${ae.name}".`})}finally{b(null)}},[I,P]),X=x.useCallback(async D=>{if(a){b(D);try{const de=M(a.jsonPath,D);if(!de.ok){P({variant:"destructive",title:"Could not insert font",description:de.error});return}P({title:"Font inserted",description:`${D} set at ${ql(a.jsonPath)}.`}),o(!1)}finally{b(null)}}},[a,M,P,o]),Y=x.useCallback(async D=>{if(!(!D||D.length===0)){N(!0);try{const de=[];for(const ae of Array.from(D)){const ue=new Uint8Array(await ae.arrayBuffer()),ge=uv(ae.name,ue);if(!ge.ok){P({variant:"destructive",title:"Font rejected",description:ge.message});continue}de.push({identity:dv(ae.name),base64:ge.base64})}if(de.length===0)return;const te=J(de.map(({identity:ae,base64:ue})=>({id:ae.family,family:ae.family,sources:[{kind:"data",data:ue,weight:ae.weight,italic:ae.italic}]})));if(!te.ok){P({variant:"destructive",title:"Could not register font",description:te.error});return}for(const{identity:ae,base64:ue}of de)vv(ae.family,ue,ae.weight,ae.italic),P({title:`Added ${ae.family}`,description:`Registered at weight ${ae.weight}${ae.italic?" italic":""} in props.fontRegistry. Reference it as "${ae.family}".`})}catch(de){P({variant:"destructive",title:"Upload failed",description:de.message})}finally{N(!1),z.current&&(z.current.value="")}}},[J,P]),re=x.useCallback(async()=>{var de,te;const D=R.trim();if(D){k(!0),T([]);try{const ae=await fetch(ei.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:D,weights:[400,700],italics:!1})});if(ae.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!ae.ok){const De=await ae.json().catch(()=>({}));throw new Error(De.error??`Materialize failed (${ae.status})`)}const ue=await ae.json();T(ue.warnings??[]);const ge=(de=l.google.find(De=>De.family.toLowerCase()===ue.family.toLowerCase()))==null?void 0:de.category,pe=gv(ue,ge);if(!pe){P({variant:"destructive",title:"Nothing to embed",description:((te=ue.warnings)==null?void 0:te.join(" · "))||`Google Fonts has no family named "${D}".`});return}const Pe=J([pe]);if(!Pe.ok){P({variant:"destructive",title:"Could not register font",description:Pe.error});return}Wl(ue.family,[400,700]),P({title:`Added ${ue.family}`,description:`Embedded ${pe.sources.length} weight(s) in props.fontRegistry.`})}catch(ae){P({variant:"destructive",title:"Google Fonts fetch failed",description:ae.message})}finally{k(!1)}}},[R,l.google,J,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 ${ql(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(tp,{value:g,onValueChange:D=>v(D),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Eo,{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:d&&le.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:le.map(D=>u.jsx(Gl,{family:D,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${D}", sans-serif`},onCopy:()=>y(D),copied:E===D,contextual:!!a,onUseThis:()=>X(D),onInsertHeading:()=>W(D,"safe","heading"),onInsertBody:()=>W(D,"safe","body"),applying:_===D,disabled:!S},D))})}),u.jsx(ur,{value:"google",className:"m-0",children:d&&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(Gl,{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:E===D.family,contextual:!!a,onUseThis:()=>X(D.family),onInsertHeading:()=>W(D.family,"google","heading"),onInsertBody:()=>W(D.family,"google","body"),applying:_===D.family,disabled:!S,extraAction:u.jsx(Cv,{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:z,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=z.current)==null?void 0:D.click()},children:[O?u.jsx(Fr,{className:"animate-spin mr-2 h-4 w-4"}):u.jsx(Kg,{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:R,onChange:D=>q(D.target.value),onKeyDown:D=>{D.key==="Enter"&&re()}}),u.jsxs(Se,{onClick:()=>void re(),disabled:w||R.trim()==="",children:[w&&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(" · ")})})]})]})})]})]})]})})},Ev="The quick brown fox jumps over the lazy dog",Cv=({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(wo,{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=jd[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)})]})]})},Gl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:d,extraAction:f})=>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:Ev}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Se,{size:"sm",onClick:a,disabled:c||d,"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||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Se,{size:"sm",variant:"secondary",onClick:l,disabled:c||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,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 Yl({previewOpen:e,onTogglePreview:t}){const n=rn(N=>N.name||""),r=rn(N=>N.blob),i=rn(N=>N.isGenerating),s=rn(N=>N.text),a=rn(N=>N.warnings),o=rn(N=>N.isRendering),l=Hi(N=>N.useGlobalPreviewHeader??!0),c=Ne(N=>N.activeTab),d=Ne(N=>N.documentTypes),f=c&&d[c]==="application/json+theme"?"theme":"document",h=Ne(N=>{var w;return N.activeTab&&N.documentTypes[N.activeTab]!=="application/json+theme"?(w=N.documents.find(k=>k.name===N.activeTab))==null?void 0:w.text:void 0}),p=Oe(N=>N.chatOpen),g=Oe(N=>N.toggleChat),[v,_]=je.useState(!1),b=$i(N=>N.openFor);if(!l)return null;const E=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),m=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),O=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(nv,{name:O,blob:r,onManualRender:E,isGenerating:i,isRendering:!!o,onShowCacheMetrics:m,onShowSchemas:()=>_(!0),onShowFonts:()=>b(),documentText:s,editorDocumentText:h,warnings:a,onToggleChat:g,chatOpen:p,onTogglePreview:t,previewOpen:e}),u.jsx(av,{open:v,onOpenChange:_,defaultTab:f==="theme"?"theme":"document"}),u.jsx(Nv,{})]})}function Tv(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Iv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Av=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,zv={};function Kl(e,t){return(zv.jsx?Av:Iv).test(e)}const Ov=/[ \t\n\f\r]/g;function Pv(e){return typeof e=="object"?e.type==="text"?Xl(e.value):!1:Xl(e)}function Xl(e){return e.replace(Ov,"")===""}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 rp(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 La(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 Dv=0;const ke=$n(),tt=$n(),Ba=$n(),ie=$n(),Be=$n(),cr=$n(),jt=$n();function $n(){return 2**++Dv}const Za=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:tt,commaOrSpaceSeparated:jt,commaSeparated:cr,number:ie,overloadedBoolean:Ba,spaceSeparated:Be},Symbol.toStringTag,{value:"Module"})),ea=Object.keys(Za);class Co extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),Ql(this,"space",i),typeof r=="number")for(;++s<ea.length;){const a=ea[s];Ql(this,ea[s],(r&Za[a])===Za[a])}}}Co.prototype.defined=!0;function Ql(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 Co(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[La(r)]=r,n[La(s.attribute)]=r}return new bi(t,n,e.space)}const ip=jr({properties:{ariaActiveDescendant:null,ariaAtomic:tt,ariaAutoComplete:null,ariaBusy:tt,ariaChecked:tt,ariaColCount:ie,ariaColIndex:ie,ariaColSpan:ie,ariaControls:Be,ariaCurrent:null,ariaDescribedBy:Be,ariaDetails:null,ariaDisabled:tt,ariaDropEffect:Be,ariaErrorMessage:null,ariaExpanded:tt,ariaFlowTo:Be,ariaGrabbed:tt,ariaHasPopup:null,ariaHidden:tt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Be,ariaLevel:ie,ariaLive:null,ariaModal:tt,ariaMultiLine:tt,ariaMultiSelectable:tt,ariaOrientation:null,ariaOwns:Be,ariaPlaceholder:null,ariaPosInSet:ie,ariaPressed:tt,ariaReadOnly:tt,ariaRelevant:null,ariaRequired:tt,ariaRoleDescription:Be,ariaRowCount:ie,ariaRowIndex:ie,ariaRowSpan:ie,ariaSelected:tt,ariaSetSize:ie,ariaSort:null,ariaValueMax:ie,ariaValueMin:ie,ariaValueNow:ie,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function sp(e,t){return t in e?e[t]:t}function ap(e,t){return sp(e,t.toLowerCase())}const Rv=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:ie,colSpan:null,content:null,contentEditable:tt,controls:ke,controlsList:Be,coords:ie|cr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Ba,draggable:tt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Be,height:ie,hidden:Ba,high:ie,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:ie,manifest:null,max:null,maxLength:ie,media:null,method:null,min:null,minLength:ie,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:ie,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:ie,rowSpan:ie,sandbox:Be,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:ie,sizes:null,slot:null,span:ie,spellCheck:tt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:ie,step:null,style:null,tabIndex:ie,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:tt,width:ie,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Be,axis:null,background:null,bgColor:null,border:ie,borderColor:null,bottomMargin:ie,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:ie,leftMargin:ie,link:null,longDesc:null,lowSrc:null,marginHeight:ie,marginWidth:ie,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:ie,rules:null,scheme:null,scrolling:tt,standby:null,summary:null,text:null,topMargin:ie,valueType:null,version:null,vAlign:null,vLink:null,vSpace:ie,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:ie,security:null,unselectable:null},space:"html",transform:ap}),Mv=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:ie,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:ie,amplitude:ie,arabicForm:null,ascent:ie,attributeName:null,attributeType:null,azimuth:ie,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:ie,by:null,calcMode:null,capHeight:ie,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:ie,diffuseConstant:ie,direction:null,display:null,dur:null,divisor:ie,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:ie,enableBackground:null,end:null,event:null,exponent:ie,externalResourcesRequired:null,fill:null,fillOpacity:ie,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:ie,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:ie,horizOriginX:ie,horizOriginY:ie,id:null,ideographic:ie,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:ie,k:ie,k1:ie,k2:ie,k3:ie,k4:ie,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:ie,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:ie,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:ie,overlineThickness:ie,paintOrder:null,panose1:null,path:null,pathLength:ie,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Be,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:ie,pointsAtY:ie,pointsAtZ:ie,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:ie,specularExponent:ie,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:ie,strikethroughThickness:ie,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:ie,strokeOpacity:ie,strokeWidth:null,style:null,surfaceScale:ie,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:ie,tableValues:null,target:null,targetX:ie,targetY:ie,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:ie,underlineThickness:ie,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:ie,values:null,vAlphabetic:ie,vMathematical:ie,vectorEffect:null,vHanging:ie,vIdeographic:ie,version:null,vertAdvY:ie,vertOriginX:ie,vertOriginY:ie,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:ie,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:sp}),op=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()}}),lp=jr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:ap}),up=jr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),$v={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"},Fv=/[A-Z]/g,eu=/-[a-z]/g,Lv=/^data[-\w.:]+$/i;function Bv(e,t){const n=La(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"&&Lv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(eu,Vv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!eu.test(s)){let a=s.replace(Fv,Zv);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=Co}return new i(r,t)}function Zv(e){return"-"+e.toLowerCase()}function Vv(e){return e.charAt(1).toUpperCase()}const Uv=rp([ip,Rv,op,lp,up],"html"),To=rp([ip,Mv,op,lp,up],"svg");function Jv(e){return e.join(" ").trim()}var Hn={},ta,tu;function Hv(){if(tu)return ta;tu=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="/",d="*",f="",h="comment",p="declaration";function g(_,b){if(typeof _!="string")throw new TypeError("First argument must be a string");if(!_)return[];b=b||{};var E=1,m=1;function O(I){var M=I.match(t);M&&(E+=M.length);var J=I.lastIndexOf(l);m=~J?I.length-J:m+I.length}function N(){var I={line:E,column:m};return function(M){return M.position=new w(I),q(),M}}function w(I){this.start=I,this.end={line:E,column:m},this.source=b.source}w.prototype.content=_;function k(I){var M=new Error(b.source+":"+E+":"+m+": "+I);if(M.reason=I,M.filename=b.source,M.line=E,M.column=m,M.source=_,!b.silent)throw M}function R(I){var M=I.exec(_);if(M){var J=M[0];return O(J),_=_.slice(J.length),M}}function q(){R(n)}function j(I){var M;for(I=I||[];M=T();)M!==!1&&I.push(M);return I}function T(){var I=N();if(!(c!=_.charAt(0)||d!=_.charAt(1))){for(var M=2;f!=_.charAt(M)&&(d!=_.charAt(M)||c!=_.charAt(M+1));)++M;if(M+=2,f===_.charAt(M-1))return k("End of comment missing");var J=_.slice(2,M-2);return m+=2,O(J),_=_.slice(M),m+=2,I({type:h,comment:J})}}function z(){var I=N(),M=R(r);if(M){if(T(),!R(i))return k("property missing ':'");var J=R(s),Z=I({type:p,property:v(M[0].replace(e,f)),value:J?v(J[0].replace(e,f)):f});return R(a),Z}}function P(){var I=[];j(I);for(var M;M=z();)M!==!1&&(I.push(M),j(I));return I}return q(),P()}function v(_){return _?_.replace(o,f):f}return ta=g,ta}var nu;function Wv(){if(nu)return Hn;nu=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(Hv());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:d}=l;o?i(c,d,l):d&&(s=s||{},s[c]=d)}),s}return Hn}var Pr={},ru;function qv(){if(ru)return Pr;ru=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,d){return d.toUpperCase()},o=function(c,d){return"".concat(d,"-")},l=function(c,d){return d===void 0&&(d={}),s(c)?c:(c=c.toLowerCase(),d.reactCompat?c=c.replace(i,o):c=c.replace(r,o),c.replace(t,a))};return Pr.camelCase=l,Pr}var Dr,iu;function Gv(){if(iu)return Dr;iu=1;var e=Dr&&Dr.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Wv()),n=qv();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 Yv=Gv();const Kv=lo(Yv),cp=dp("end"),Io=dp("start");function dp(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 Xv(e){const t=Io(e),n=cp(e);if(t&&n)return{start:t,end:n}}function Kr(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?su(e.position):"start"in e||"end"in e?su(e):"line"in e||"column"in e?Va(e):""}function Va(e){return au(e&&e.line)+":"+au(e&&e.column)}function su(e){return Va(e&&e.start)+"-"+Va(e&&e.end)}function au(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 Ao={}.hasOwnProperty,Qv=new Map,ew=/[A-Z]/g,tw=new Set(["table","tbody","thead","tfoot","tr"]),nw=new Set(["td","th"]),fp="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function rw(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=dw(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=cw(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"?To:Uv,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=pp(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function pp(e,t,n){if(t.type==="element")return iw(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return sw(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return ow(e,t,n);if(t.type==="mdxjsEsm")return aw(e,t);if(t.type==="root")return lw(e,t,n);if(t.type==="text")return uw(e,t)}function iw(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=To,e.schema=i),e.ancestors.push(t);const s=mp(e,t.tagName,!1),a=fw(e,t);let o=Oo(e,t);return tw.has(t.tagName)&&(o=o.filter(function(l){return typeof l=="string"?!Pv(l):!0})),hp(e,a,s,t),zo(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function sw(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 aw(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);oi(e,t.position)}function ow(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=To,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:mp(e,t.name,!0),a=pw(e,t),o=Oo(e,t);return hp(e,a,s,t),zo(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function lw(e,t,n){const r={};return zo(r,Oo(e,t)),e.create(t,e.Fragment,r,n)}function uw(e,t){return t.value}function hp(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function zo(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function cw(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 dw(e,t){return n;function n(r,i,s,a){const o=Array.isArray(s.children),l=Io(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 fw(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&Ao.call(t.properties,i)){const s=hw(e,i,t.properties[i]);if(s){const[a,o]=s;e.tableCellAlignToStyle&&a==="align"&&typeof o=="string"&&nw.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 pw(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 Oo(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:Qv;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=pp(e,s,a);o!==void 0&&n.push(o)}return n}function hw(e,t,n){const r=Bv(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Tv(n):Jv(n)),r.property==="style"){let i=typeof n=="object"?n:mw(e,String(n));return e.stylePropertyNameCase==="css"&&(i=gw(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?$v[r.property]||r.property:r.attribute,n]}}function mw(e,t){try{return Kv(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=fp+"#cannot-parse-style-attribute",i}}function mp(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=Kl(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=Kl(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return Ao.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=fp+"#cannot-handle-mdx-estrees-without-createevaluater",n}function gw(e){const t={};let n;for(n in e)Ao.call(e,n)&&(t[xw(n)]=e[n]);return t}function xw(e){let t=e.replace(ew,yw);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function yw(e){return"-"+e.toLowerCase()}const na={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"]},bw={};function Po(e,t){const n=bw,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return gp(e,r,i)}function gp(e,t,n){if(vw(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 ou(e.children,t,n)}return Array.isArray(e)?ou(e,t,n):""}function ou(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=gp(e[i],t,n);return r.join("")}function vw(e){return!!(e&&typeof e=="object")}const lu=document.createElement("i");function Do(e){const t="&"+e+";";lu.innerHTML=t;const n=lu.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 uu={}.hasOwnProperty;function xp(e){const t={};let n=-1;for(;++n<e.length;)ww(t,e[n]);return t}function ww(e,t){let n;for(n in t){const i=(uu.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let a;if(s)for(a in s){uu.call(i,a)||(i[a]=[]);const o=s[a];kw(i[a],Array.isArray(o)?o:o?[o]:[])}}}function kw(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 yp(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]/),Sw=kn(/[#-'*+\--9=?A-Z^-~]/);function ss(e){return e!==null&&(e<32||e===127)}const Ua=kn(/\d/),_w=kn(/[\dA-Fa-f]/),jw=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 Nw={tokenize:Ew};function Ew(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 Cw={tokenize:Tw},cu={tokenize:Iw};function Tw(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&&E();const O=t.events.length;let N=O,w;for(;N--;)if(t.events[N][0]==="exit"&&t.events[N][1].type==="chunkFlow"){w=t.events[N][1].end;break}b(r);let k=O;for(;k<t.events.length;)t.events[k][1].end={...w},k++;return Tt(t.events,N+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(cu,d,f)(m)}function d(m){return i&&E(),b(r),h(m)}function f(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(cu,p,g)(m)}function p(m){return r++,n.push([t.currentConstruct,t.containerState]),h(m)}function g(m){if(m===null){i&&E(),b(0),e.consume(m);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),v(m)}function v(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),v)}function _(m,O){const N=t.sliceStream(m);if(O&&N.push(null),m.previous=s,s&&(s.next=m),s=m,i.defineSkip(m.start),i.write(N),t.parser.lazy[m.start.line]){let w=i.events.length;for(;w--;)if(i.events[w][1].start.offset<a&&(!i.events[w][1].end||i.events[w][1].end.offset>a))return;const k=t.events.length;let R=k,q,j;for(;R--;)if(t.events[R][0]==="exit"&&t.events[R][1].type==="chunkFlow"){if(q){j=t.events[R][1].end;break}q=!0}for(b(r),w=k;w<t.events.length;)t.events[w][1].end={...j},w++;Tt(t.events,R+1,0,t.events.slice(k)),t.events.length=w}}function b(m){let O=n.length;for(;O-- >m;){const N=n[O];t.containerState=N[1],N[0].exit.call(t,e)}n.length=m}function E(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Iw(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 Ja={name:"attention",resolveAll:Aw,tokenize:zw};function Aw(e,t){let n=-1,r,i,s,a,o,l,c,d;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;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 f={...e[r][1].end},h={...e[n][1].start};du(f,-l),du(h,l),a={type:l>1?"strongSequence":"emphasisSequence",start:f,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?(d=2,c=Ot(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):d=0,Tt(e,r-1,n-r+3,c),n=r+c.length-d-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function zw(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"),d=yr(l),f=!d||d===2&&i||n.includes(l),h=!i||i===2&&d||n.includes(r);return c._open=!!(s===42?f:f&&(i||!h)),c._close=!!(s===42?h:h&&(d||!f)),t(l)}}function du(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Ow={name:"autolink",tokenize:Pw};function Pw(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),d):Sw(p)?(e.consume(p),c):n(p)}function d(p){return ot(p)?f(p):n(p)}function f(p){return p===46?(e.consume(p),r=0,d):p===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):h(p)}function h(p){if((p===45||ot(p))&&r++<63){const g=p===45?h:f;return e.consume(p),g}return n(p)}}const vi={partial:!0,tokenize:Dw};function Dw(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 bp={continuation:{tokenize:Mw},exit:$w,name:"blockQuote",tokenize:Rw};function Rw(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 Mw(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(bp,t,n)(a)}}function $w(e){e.exit("blockQuote")}const vp={name:"characterEscape",tokenize:Fw};function Fw(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 jw(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const wp={name:"characterReference",tokenize:Lw};function Lw(e,t,n){const r=this;let i=0,s,a;return o;function o(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),l}function l(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),s=31,a=ot,d(f))}function c(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,a=_w,d):(e.enter("characterReferenceValue"),s=7,a=Ua,d(f))}function d(f){if(f===59&&i){const h=e.exit("characterReferenceValue");return a===ot&&!Do(r.sliceSerialize(h))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return a(f)&&i++<s?(e.consume(f),d):n(f)}}const fu={partial:!0,tokenize:Zw},pu={concrete:!0,name:"codeFenced",tokenize:Bw};function Bw(e,t,n){const r=this,i={partial:!0,tokenize:N};let s=0,a=0,o;return l;function l(w){return c(w)}function c(w){const k=r.events[r.events.length-1];return s=k&&k[1].type==="linePrefix"?k[2].sliceSerialize(k[1],!0).length:0,o=w,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),d(w)}function d(w){return w===o?(a++,e.consume(w),d):a<3?n(w):(e.exit("codeFencedFenceSequence"),Ce(w)?ze(e,f,"whitespace")(w):f(w))}function f(w){return w===null||ye(w)?(e.exit("codeFencedFence"),r.interrupt?t(w):e.check(fu,v,O)(w)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),h(w))}function h(w){return w===null||ye(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(w)):Ce(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),ze(e,p,"whitespace")(w)):w===96&&w===o?n(w):(e.consume(w),h)}function p(w){return w===null||ye(w)?f(w):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(w))}function g(w){return w===null||ye(w)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(w)):w===96&&w===o?n(w):(e.consume(w),g)}function v(w){return e.attempt(i,O,_)(w)}function _(w){return e.enter("lineEnding"),e.consume(w),e.exit("lineEnding"),b}function b(w){return s>0&&Ce(w)?ze(e,E,"linePrefix",s+1)(w):E(w)}function E(w){return w===null||ye(w)?e.check(fu,v,O)(w):(e.enter("codeFlowValue"),m(w))}function m(w){return w===null||ye(w)?(e.exit("codeFlowValue"),E(w)):(e.consume(w),m)}function O(w){return e.exit("codeFenced"),t(w)}function N(w,k,R){let q=0;return j;function j(M){return w.enter("lineEnding"),w.consume(M),w.exit("lineEnding"),T}function T(M){return w.enter("codeFencedFence"),Ce(M)?ze(w,z,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(M):z(M)}function z(M){return M===o?(w.enter("codeFencedFenceSequence"),P(M)):R(M)}function P(M){return M===o?(q++,w.consume(M),P):q>=a?(w.exit("codeFencedFenceSequence"),Ce(M)?ze(w,I,"whitespace")(M):I(M)):R(M)}function I(M){return M===null||ye(M)?(w.exit("codeFencedFence"),k(M)):R(M)}}}function Zw(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 ra={name:"codeIndented",tokenize:Uw},Vw={partial:!0,tokenize:Jw};function Uw(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 d=r.events[r.events.length-1];return d&&d[1].type==="linePrefix"&&d[2].sliceSerialize(d[1],!0).length>=4?a(c):n(c)}function a(c){return c===null?l(c):ye(c)?e.attempt(Vw,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 Jw(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 Hw={name:"codeText",previous:qw,resolve:Ww,tokenize:Gw};function Ww(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 qw(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Gw(e,t,n){let r=0,i,s;return a;function a(f){return e.enter("codeText"),e.enter("codeTextSequence"),o(f)}function o(f){return f===96?(e.consume(f),r++,o):(e.exit("codeTextSequence"),l(f))}function l(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),l):f===96?(s=e.enter("codeTextSequence"),i=0,d(f)):ye(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),l):(e.enter("codeTextData"),c(f))}function c(f){return f===null||f===32||f===96||ye(f)?(e.exit("codeTextData"),l(f)):(e.consume(f),c)}function d(f){return f===96?(e.consume(f),i++,d):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(s.type="codeTextData",c(f))}}class Yw{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 kp(e){const t={};let n=-1,r,i,s,a,o,l,c;const d=new Yw(e);for(;++n<d.length;){for(;n in t;)n=t[n];if(r=d.get(n),n&&r[1].type==="chunkFlow"&&d.get(n-1)[1].type==="listItemPrefix"&&(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,Kw(d,n)),n=t[n],c=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(a=d.get(s),a[1].type==="lineEnding"||a[1].type==="lineEndingBlank")a[0]==="enter"&&(i&&(d.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={...d.get(i)[1].start},o=d.slice(i,n),o.unshift(r),d.splice(i,n-i+1,o))}}return Tt(e,0,Number.POSITIVE_INFINITY,d.slice(0)),!c}function Kw(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 d,f,h=-1,p=n,g=0,v=0;const _=[v];for(;p;){for(;e.get(++i)[1]!==p;);s.push(i),p._tokenizer||(d=r.sliceStream(p),p.next||d.push(null),f&&a.defineSkip(p.start),p._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=!0),a.write(d),p._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=void 0)),f=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&&(v=h+1,_.push(v),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]),E=s.pop();l.push([E,E+b.length-1]),e.splice(E,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 Xw={resolve:e0,tokenize:t0},Qw={partial:!0,tokenize:n0};function e0(e){return kp(e),e}function t0(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(Qw,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 n0(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 Sp(e,t,n,r,i,s,a,o,l){const c=l||Number.POSITIVE_INFINITY;let d=0;return f;function f(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"}),v(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 v(b){return!d&&(b===null||b===41||Fe(b))?(e.exit("chunkString"),e.exit(o),e.exit(a),e.exit(r),t(b)):d<c&&b===40?(e.consume(b),d++,v):b===41?(e.consume(b),d--,v):b===null||b===32||b===40||ss(b)?n(b):(e.consume(b),b===92?_:v)}function _(b){return b===40||b===41||b===92?(e.consume(b),v):v(b)}}function _p(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),d}function d(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"),d):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||ye(p)||o++>999?(e.exit("chunkString"),d(p)):(e.consume(p),l||(l=!Ce(p)),p===92?h:f)}function h(p){return p===91||p===92||p===93?(e.consume(p),o++,f):f(p)}}function jp(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"}),d(h))}function d(h){return h===a||h===null||ye(h)?(e.exit("chunkString"),c(h)):(e.consume(h),h===92?f:d)}function f(h){return h===a||h===92?(e.consume(h),d):d(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 r0={name:"definition",tokenize:s0},i0={partial:!0,tokenize:a0};function s0(e,t,n){const r=this;let i;return s;function s(p){return e.enter("definition"),a(p)}function a(p){return _p.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 Sp(e,d,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function d(p){return e.attempt(i0,f,f)(p)}function f(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 a0(e,t,n){return r;function r(o){return Fe(o)?Xr(e,i)(o):n(o)}function i(o){return jp(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 o0={name:"hardBreakEscape",tokenize:l0};function l0(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 u0={name:"headingAtx",resolve:c0,tokenize:d0};function c0(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 d0(e,t,n){let r=0;return i;function i(d){return e.enter("atxHeading"),s(d)}function s(d){return e.enter("atxHeadingSequence"),a(d)}function a(d){return d===35&&r++<6?(e.consume(d),a):d===null||Fe(d)?(e.exit("atxHeadingSequence"),o(d)):n(d)}function o(d){return d===35?(e.enter("atxHeadingSequence"),l(d)):d===null||ye(d)?(e.exit("atxHeading"),t(d)):Ce(d)?ze(e,o,"whitespace")(d):(e.enter("atxHeadingText"),c(d))}function l(d){return d===35?(e.consume(d),l):(e.exit("atxHeadingSequence"),o(d))}function c(d){return d===null||d===35||Fe(d)?(e.exit("atxHeadingText"),o(d)):(e.consume(d),c)}}const f0=["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"],hu=["pre","script","style","textarea"],p0={concrete:!0,name:"htmlFlow",resolveTo:g0,tokenize:x0},h0={partial:!0,tokenize:b0},m0={partial:!0,tokenize:y0};function g0(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 x0(e,t,n){const r=this;let i,s,a,o,l;return c;function c(y){return d(y)}function d(y){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(y),f}function f(y){return y===33?(e.consume(y),h):y===47?(e.consume(y),s=!0,v):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 W="CDATA[";return y===W.charCodeAt(o++)?(e.consume(y),o===W.length?r.interrupt?t:z:g):n(y)}function v(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 W=y===47,X=a.toLowerCase();return!W&&!s&&hu.includes(X)?(i=1,r.interrupt?t(y):z(y)):f0.includes(a.toLowerCase())?(i=6,W?(e.consume(y),b):r.interrupt?t(y):z(y)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(y):s?E(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:z):n(y)}function E(y){return Ce(y)?(e.consume(y),E):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):N(y)}function N(y){return y===61?(e.consume(y),w):Ce(y)?(e.consume(y),N):m(y)}function w(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),w):R(y)}function k(y){return y===l?(e.consume(y),l=null,q):y===null||ye(y)?n(y):(e.consume(y),k)}function R(y){return y===null||y===34||y===39||y===47||y===60||y===61||y===62||y===96||Fe(y)?N(y):(e.consume(y),R)}function q(y){return y===47||y===62||Ce(y)?m(y):n(y)}function j(y){return y===62?(e.consume(y),T):n(y)}function T(y){return y===null||ye(y)?z(y):Ce(y)?(e.consume(y),T):n(y)}function z(y){return y===45&&i===2?(e.consume(y),J):y===60&&i===1?(e.consume(y),Z):y===62&&i===4?(e.consume(y),le):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(h0,B,P)(y)):y===null||ye(y)?(e.exit("htmlFlowData"),P(y)):(e.consume(y),z)}function P(y){return e.check(m0,I,B)(y)}function I(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"),z(y))}function J(y){return y===45?(e.consume(y),S):z(y)}function Z(y){return y===47?(e.consume(y),a="",V):z(y)}function V(y){if(y===62){const W=a.toLowerCase();return hu.includes(W)?(e.consume(y),le):z(y)}return pt(y)&&a.length<8?(e.consume(y),a+=String.fromCharCode(y),V):z(y)}function ne(y){return y===93?(e.consume(y),S):z(y)}function S(y){return y===62?(e.consume(y),le):y===45&&i===2?(e.consume(y),S):z(y)}function le(y){return y===null||ye(y)?(e.exit("htmlFlowData"),B(y)):(e.consume(y),le)}function B(y){return e.exit("htmlFlow"),t(y)}}function y0(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 b0(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(vi,t,n)}}const v0={name:"htmlText",tokenize:w0};function w0(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),N):S===63?(e.consume(S),m):pt(S)?(e.consume(S),R):n(S)}function c(S){return S===45?(e.consume(S),d):S===91?(e.consume(S),s=0,g):pt(S)?(e.consume(S),E):n(S)}function d(S){return S===45?(e.consume(S),p):n(S)}function f(S){return S===null?n(S):S===45?(e.consume(S),h):ye(S)?(a=f,Z(S)):(e.consume(S),f)}function h(S){return S===45?(e.consume(S),p):f(S)}function p(S){return S===62?J(S):S===45?h(S):f(S)}function g(S){const le="CDATA[";return S===le.charCodeAt(s++)?(e.consume(S),s===le.length?v:g):n(S)}function v(S){return S===null?n(S):S===93?(e.consume(S),_):ye(S)?(a=v,Z(S)):(e.consume(S),v)}function _(S){return S===93?(e.consume(S),b):v(S)}function b(S){return S===62?J(S):S===93?(e.consume(S),b):v(S)}function E(S){return S===null||S===62?J(S):ye(S)?(a=E,Z(S)):(e.consume(S),E)}function m(S){return S===null?n(S):S===63?(e.consume(S),O):ye(S)?(a=m,Z(S)):(e.consume(S),m)}function O(S){return S===62?J(S):m(S)}function N(S){return pt(S)?(e.consume(S),w):n(S)}function w(S){return S===45||ot(S)?(e.consume(S),w):k(S)}function k(S){return ye(S)?(a=k,Z(S)):Ce(S)?(e.consume(S),k):J(S)}function R(S){return S===45||ot(S)?(e.consume(S),R):S===47||S===62||Fe(S)?q(S):n(S)}function q(S){return S===47?(e.consume(S),J):S===58||S===95||pt(S)?(e.consume(S),j):ye(S)?(a=q,Z(S)):Ce(S)?(e.consume(S),q):J(S)}function j(S){return S===45||S===46||S===58||S===95||ot(S)?(e.consume(S),j):T(S)}function T(S){return S===61?(e.consume(S),z):ye(S)?(a=T,Z(S)):Ce(S)?(e.consume(S),T):q(S)}function z(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=z,Z(S)):Ce(S)?(e.consume(S),z):(e.consume(S),I)}function P(S){return S===i?(e.consume(S),i=void 0,M):S===null?n(S):ye(S)?(a=P,Z(S)):(e.consume(S),P)}function I(S){return S===null||S===34||S===39||S===60||S===61||S===96?n(S):S===47||S===62||Fe(S)?q(S):(e.consume(S),I)}function M(S){return S===47||S===62||Fe(S)?q(S):n(S)}function J(S){return S===62?(e.consume(S),e.exit("htmlTextData"),e.exit("htmlText"),t):n(S)}function Z(S){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(S),e.exit("lineEnding"),V}function V(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 Ro={name:"labelEnd",resolveAll:j0,resolveTo:N0,tokenize:E0},k0={tokenize:C0},S0={tokenize:T0},_0={tokenize:I0};function j0(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 N0(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}},d={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",d,t]]),o=Ot(o,Ps(t.parser.constructs.insideSpan.null,e.slice(s+r+4,a-3),t)),o=Ot(o,[["exit",d,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 E0(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?f(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(k0,d,a?d:f)(h):h===91?e.attempt(S0,d,a?c:f)(h):a?d(h):f(h)}function c(h){return e.attempt(_0,d,f)(h)}function d(h){return t(h)}function f(h){return s._balanced=!0,n(h)}}function C0(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),i}function i(f){return Fe(f)?Xr(e,s)(f):s(f)}function s(f){return f===41?d(f):Sp(e,a,o,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function a(f){return Fe(f)?Xr(e,l)(f):d(f)}function o(f){return n(f)}function l(f){return f===34||f===39||f===40?jp(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):d(f)}function c(f){return Fe(f)?Xr(e,d)(f):d(f)}function d(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function T0(e,t,n){const r=this;return i;function i(o){return _p.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 I0(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 A0={name:"labelStartImage",resolveAll:Ro.resolveAll,tokenize:z0};function z0(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 O0={name:"labelStartLink",resolveAll:Ro.resolveAll,tokenize:P0};function P0(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 ia={name:"lineEnding",tokenize:D0};function D0(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:R0};function R0(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:L0},exit:Z0,name:"list",tokenize:F0},M0={partial:!0,tokenize:V0},$0={partial:!0,tokenize:B0};function F0(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:Ua(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 Ua(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:d,e.attempt(M0,h,f))}function d(p){return r.containerState.initialBlankLine=!0,s++,h(p)}function f(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 L0(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($0,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 B0(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 Z0(e){e.exit(this.containerState.type)}function V0(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 mu={name:"setextUnderline",resolveTo:U0,tokenize:J0};function U0(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 J0(e,t,n){const r=this;let i;return s;function s(c){let d=r.events.length,f;for(;d--;)if(r.events[d][1].type!=="lineEnding"&&r.events[d][1].type!=="linePrefix"&&r.events[d][1].type!=="content"){f=r.events[d][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),i=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 H0={tokenize:W0};function W0(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(Xw,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 q0={resolveAll:Ep()},G0=Np("string"),Y0=Np("text");function Np(e){return{resolveAll:Ep(e==="text"?K0: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(d){return c(d)?s(d):o(d)}function o(d){if(d===null){n.consume(d);return}return n.enter("data"),n.consume(d),l}function l(d){return c(d)?(n.exit("data"),s(d)):(n.consume(d),l)}function c(d){if(d===null)return!0;const f=i[d];let h=-1;if(f)for(;++h<f.length;){const p=f[h];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function Ep(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 K0(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 X0={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:bp},Q0={91:r0},ek={[-2]:ra,[-1]:ra,32:ra},tk={35:u0,42:Zi,45:[mu,Zi],60:p0,61:mu,95:Zi,96:pu,126:pu},nk={38:wp,92:vp},rk={[-5]:ia,[-4]:ia,[-3]:ia,33:A0,38:wp,42:Ja,60:[Ow,v0],91:O0,92:[o0,vp],93:Ro,95:Ja,96:Hw},ik={null:[Ja,q0]},sk={null:[42,95]},ak={null:[]},ok=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:sk,contentInitial:Q0,disable:ak,document:X0,flow:tk,flowInitial:ek,insideSpan:ik,string:nk,text:rk},Symbol.toStringTag,{value:"Module"}));function lk(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(N),check:k(w),consume:E,enter:m,exit:O,interrupt:k(w,{interrupt:!0})},c={code:null,containerState:{},defineSkip:v,events:[],now:g,parser:e,previous:null,sliceSerialize:h,sliceStream:p,write:f};let d=t.tokenize.call(c,l);return t.resolveAll&&s.push(t),c;function f(T){return a=Ot(a,T),_(),a[a.length-1]!==null?[]:(R(t,0),c.events=Ps(s,c.events,c),c.events)}function h(T,z){return ck(p(T),z)}function p(T){return uk(a,T)}function g(){const{_bufferIndex:T,_index:z,line:P,column:I,offset:M}=r;return{_bufferIndex:T,_index:z,line:P,column:I,offset:M}}function v(T){i[T.line]=T.column,j()}function _(){let T;for(;r._index<a.length;){const z=a[r._index];if(typeof z=="string")for(T=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===T&&r._bufferIndex<z.length;)b(z.charCodeAt(r._bufferIndex));else b(z)}}function b(T){d=d(T)}function E(T){ye(T)?(r.line++,r.column=1,r.offset+=T===-3?2:1,j()):T!==-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=T}function m(T,z){const P=z||{};return P.type=T,P.start=g(),c.events.push(["enter",P,c]),o.push(P),P}function O(T){const z=o.pop();return z.end=g(),c.events.push(["exit",z,c]),z}function N(T,z){R(T,z.from)}function w(T,z){z.restore()}function k(T,z){return P;function P(I,M,J){let Z,V,ne,S;return Array.isArray(I)?B(I):"tokenize"in I?B([I]):le(I);function le(Y){return re;function re(D){const de=D!==null&&Y[D],te=D!==null&&Y.null,ae=[...Array.isArray(de)?de:de?[de]:[],...Array.isArray(te)?te:te?[te]:[]];return B(ae)(D)}}function B(Y){return Z=Y,V=0,Y.length===0?J:y(Y[V])}function y(Y){return re;function re(D){return S=q(),ne=Y,Y.partial||(c.currentConstruct=Y),Y.name&&c.parser.constructs.disable.null.includes(Y.name)?X():Y.tokenize.call(z?Object.assign(Object.create(c),z):c,l,W,X)(D)}}function W(Y){return T(ne,S),M}function X(Y){return S.restore(),++V<Z.length?y(Z[V]):J}}}function R(T,z){T.resolveAll&&!s.includes(T)&&s.push(T),T.resolve&&Tt(c.events,z,c.events.length-z,T.resolve(c.events.slice(z),c)),T.resolveTo&&(c.events=T.resolveTo(c.events,c))}function q(){const T=g(),z=c.previous,P=c.currentConstruct,I=c.events.length,M=Array.from(o);return{from:I,restore:J};function J(){r=T,c.previous=z,c.currentConstruct=P,c.events.length=I,o=M,j()}}function j(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function uk(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 ck(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 dk(e){const r={constructs:xp([ok,...(e||{}).extensions||[]]),content:i(Nw),defined:[],document:i(Cw),flow:i(H0),lazy:{},string:i(G0),text:i(Y0)};return r;function i(s){return a;function a(o){return lk(r,s,o)}}}function fk(e){for(;!kp(e););return e}const gu=/[\0\t\n\r]/g;function pk(){let e=1,t="",n=!0,r;return i;function i(s,a,o){const l=[];let c,d,f,h,p;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(a||void 0).decode(s)),f=0,t="",n&&(s.charCodeAt(0)===65279&&f++,n=void 0);f<s.length;){if(gu.lastIndex=f,c=gu.exec(s),h=c&&c.index!==void 0?c.index:s.length,p=s.charCodeAt(h),!c){t=s.slice(f);break}if(p===10&&f===h&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<h&&(l.push(s.slice(f,h)),e+=h-f),p){case 0:{l.push(65533),e++;break}case 9:{for(d=Math.ceil(e/4)*4,l.push(-2);e++<d;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}f=h+1}return o&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const hk=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function mk(e){return e.replace(hk,gk)}function gk(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return yp(n.slice(s?2:1),s?16:10)}return Do(n)||e}const Cp={}.hasOwnProperty;function xk(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),yk(n)(fk(dk(n).document().write(pk()(e,t,!0))))}function yk(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s($),autolinkProtocol:q,autolinkEmail:q,atxHeading:s(Pe),blockQuote:s(te),characterEscape:q,characterReference:q,codeFenced:s(ae),codeFencedFenceInfo:a,codeFencedFenceMeta:a,codeIndented:s(ae,a),codeText:s(ue,a),codeTextData:q,data:q,codeFlowValue:q,definition:s(ge),definitionDestinationString:a,definitionLabelString:a,definitionTitleString:a,emphasis:s(pe),hardBreakEscape:s(De),hardBreakTrailing:s(De),htmlFlow:s(nt,a),htmlFlowData:q,htmlText:s(nt,a),htmlTextData:q,image:s(C),label:a,link:s($),listItem:s(se),listItemValue:h,listOrdered:s(U,f),listUnordered:s(U),paragraph:s(A),reference:y,referenceString:a,resourceDestinationString:a,resourceTitleString:a,setextHeading:s(Pe),strong:s(K),thematicBreak:s(xe)},exit:{atxHeading:l(),atxHeadingSequence:N,autolink:l(),autolinkEmail:de,autolinkProtocol:D,blockQuote:l(),characterEscapeValue:j,characterReferenceMarkerHexadecimal:X,characterReferenceMarkerNumeric:X,characterReferenceValue:Y,characterReference:re,codeFenced:l(_),codeFencedFence:v,codeFencedFenceInfo:p,codeFencedFenceMeta:g,codeFlowValue:j,codeIndented:l(b),codeText:l(M),codeTextData:j,data:j,definition:l(),definitionDestinationString:O,definitionLabelString:E,definitionTitleString:m,emphasis:l(),hardBreakEscape:l(z),hardBreakTrailing:l(z),htmlFlow:l(P),htmlFlowData:j,htmlText:l(I),htmlTextData:j,image:l(Z),label:ne,labelText:V,lineEnding:T,link:l(J),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:W,resourceDestinationString:S,resourceTitleString:le,resource:B,setextHeading:l(R),setextHeadingLineSequence:k,setextHeadingText:w,strong:l(),thematicBreak:l()}};Tp(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(L){let Q={type:"root",children:[]};const he={stack:[Q],tokenStack:[],config:t,enter:o,exit:c,buffer:a,resume:d,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 me=ve.pop();F=i(L,me,F)}for(F=-1;++F<L.length;){const me=t[L[F][0]];Cp.call(me,L[F][1].type)&&me[L[F][1].type].call(Object.assign({sliceSerialize:L[F][2].sliceSerialize},he),L[F][1])}if(he.tokenStack.length>0){const me=he.tokenStack[he.tokenStack.length-1];(me[1]||xu).call(he,void 0,me[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,he){let ve=Q-1,F=-1,me=!1,Te,Le,rt,et;for(;++ve<=he;){const at=L[ve];switch(at[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{at[0]==="enter"?F++:F--,et=void 0;break}case"lineEndingBlank":{at[0]==="enter"&&(Te&&!et&&!F&&!rt&&(rt=ve),et=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:et=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",me=!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++,he++}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++,he++,rt=void 0,et=!0}}}return L[Q][1]._spread=me,he}function s(L,Q){return he;function he(ve){o.call(this,L(ve),ve),Q&&Q.call(this,ve)}}function a(){this.stack.push({type:"fragment",children:[]})}function o(L,Q,he){this.stack[this.stack.length-1].children.push(L),this.stack.push(L),this.tokenStack.push([Q,he||void 0]),L.position={start:dn(Q.start),end:void 0}}function l(L){return Q;function Q(he){L&&L.call(this,he),c.call(this,he)}}function c(L,Q){const he=this.stack.pop(),ve=this.tokenStack.pop();if(ve)ve[0].type!==L.type&&(Q?Q.call(this,L,ve[0]):(ve[1]||xu).call(this,L,ve[0]));else throw new Error("Cannot close `"+L.type+"` ("+Kr({start:L.start,end:L.end})+"): it’s not open");he.position.end=dn(L.end)}function d(){return Po(this.stack.pop())}function f(){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 v(){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 E(L){const Q=this.resume(),he=this.stack[this.stack.length-1];he.label=Q,he.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 N(L){const Q=this.stack[this.stack.length-1];if(!Q.depth){const he=this.sliceSerialize(L).length;Q.depth=he}}function w(){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 R(){this.data.setextHeadingSlurpLineEnding=void 0}function q(L){const he=this.stack[this.stack.length-1].children;let ve=he[he.length-1];(!ve||ve.type!=="text")&&(ve=ee(),ve.position={start:dn(L.start),end:void 0},he.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 T(L){const Q=this.stack[this.stack.length-1];if(this.data.atHardBreak){const he=Q.children[Q.children.length-1];he.position.end=dn(L.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(Q.type)&&(q.call(this,L),j.call(this,L))}function z(){this.data.atHardBreak=!0}function P(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.value=L}function I(){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 J(){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 Z(){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 V(L){const Q=this.sliceSerialize(L),he=this.stack[this.stack.length-2];he.label=mk(Q),he.identifier=Zt(Q).toLowerCase()}function ne(){const L=this.stack[this.stack.length-1],Q=this.resume(),he=this.stack[this.stack.length-1];if(this.data.inReference=!0,he.type==="link"){const ve=L.children;he.children=ve}else he.alt=Q}function S(){const L=this.resume(),Q=this.stack[this.stack.length-1];Q.url=L}function le(){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 W(L){const Q=this.resume(),he=this.stack[this.stack.length-1];he.label=Q,he.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),he=this.data.characterReferenceType;let ve;he?(ve=yp(Q,he==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):ve=Do(Q);const F=this.stack[this.stack.length-1];F.value+=ve}function re(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 de(L){j.call(this,L);const Q=this.stack[this.stack.length-1];Q.url="mailto:"+this.sliceSerialize(L)}function te(){return{type:"blockquote",children:[]}}function ae(){return{type:"code",lang:null,meta:null,value:""}}function ue(){return{type:"inlineCode",value:""}}function ge(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function pe(){return{type:"emphasis",children:[]}}function Pe(){return{type:"heading",depth:0,children:[]}}function De(){return{type:"break"}}function nt(){return{type:"html",value:""}}function C(){return{type:"image",title:null,url:"",alt:null}}function $(){return{type:"link",title:null,url:"",children:[]}}function U(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 A(){return{type:"paragraph",children:[]}}function K(){return{type:"strong",children:[]}}function ee(){return{type:"text",value:""}}function xe(){return{type:"thematicBreak"}}}function dn(e){return{line:e.line,column:e.column,offset:e.offset}}function Tp(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Tp(e,r):bk(e,r)}}function bk(e,t){let n;for(n in t)if(Cp.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 xu(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 vk(e){const t=this;t.parser=n;function n(r){return xk(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function wk(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 kk(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(V){if(d(V)){if(Tc(e[t]))for(;t<e.length&&Ic(e[t]);)t++;return a(),!0}return!1}function d(V){o(!0);for(const ne of V){const S=t+ne.length;if(e.slice(t,S)===ne)return t=S,!0}return!1}function f(V){return e[t]===V?(n+=e[t],t++,!0):!1}function h(V){return e[t]===V?(t++,!0):!1}function p(){return h("\\")}function g(){return a(),e[t]==="."&&e[t+1]==="."&&e[t+2]==="."?(t+=3,a(),h(","),!0):!1}function v(){if(e[t]==="{"){n+="{",t++,a(),h(",")&&a();let V=!0;for(;t<e.length&&e[t]!=="}";){let ne;if(V?(ne=!0,V=!1):(ne=f(","),ne||(n=Mt(n,",")),a()),g(),!(E()||k(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=$r(n,","):M();break}a();const le=f(":"),B=t>=e.length;le||(Pc(e[t])||B?n=Mt(n,":"):J()),s()||(le||B?n+="null":J())}return e[t]==="}"?(n+="}",t++):n=Mt(n,"}"),!0}return!1}function _(){if(e[t]==="["){n+="[",t++,a(),h(",")&&a();let V=!0;for(;t<e.length&&e[t]!=="]";)if(V?V=!1:f(",")||(n=Mt(n,",")),g(),!s()){n=$r(n,",");break}return e[t]==="]"?(n+="]",t++):n=Mt(n,"]"),!0}return!1}function b(){let V=!0,ne=!0;for(;ne;)V?V=!1:f(",")||(n=Mt(n,",")),ne=s();ne||(n=$r(n,",")),n=`[
104
104
  ${n}
105
105
  ]`}function E(){let V=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 le=Dc(e[t])?Dc:Rc(e[t])?Rc:oo(e[t])?oo:Um,B=t,y=n.length;let W='"';for(t++;;){if(t>=e.length){const X=q(t-1);return!V&&Ri(e.charAt(X))?(t=B,n=n.substring(0,y),E(!0)):(W=Mt(W,'"'),n+=W,!0)}if(t===ne)return W=Mt(W,'"'),n+=W,!0;if(le(e[t])){const X=t,Y=W.length;if(W+='"',t++,n+=W,a(!1),V||t>=e.length||Ri(e[t])||Ji(e[t])||Cn(e[t]))return m(),!0;const re=q(X-1),D=e.charAt(re);if(D===",")return t=B,n=n.substring(0,y),E(!1,re);if(Ri(D))return t=B,n=n.substring(0,y),E(!0);n=n.substring(0,y),t=X+1,W=`${W.substring(0,Y)}\\${W.substring(Y)}`}else if(V&&Oc(e[t])){if(e[t-1]===":"&&Ac.test(e.substring(B+1,t+2)))for(;t<e.length&&zc.test(e[t]);)W+=e[t],t++;return W=Mt(W,'"'),n+=W,m(),!0}else if(e[t]==="\\"){const X=e.charAt(t+1);if(iz[X]!==void 0)W+=e.slice(t,t+2),t+=2;else if(X==="u"){let re=2;for(;re<6&&GA(e[t+re]);)re++;re===6?(W+=e.slice(t,t+6),t+=6):t+re>=e.length?t=e.length:Z()}else W+=X,t+=2}else{const X=e.charAt(t);X==='"'&&e[t-1]!=="\\"?(W+=`\\${X}`,t++):XA(X)?(W+=rz[X],t++):(YA(X)||z(X),W+=X,t++)}S&&p()}}return!1}function m(){let V=!1;for(a();e[t]==="+";){V=!0,t++,a(),n=$r(n,'"',!0);const ne=n.length;E()?n=tz(n,ne,1):n=Mt(n,'"')}return V}function O(){const V=t;if(e[t]==="-"){if(t++,j())return T(V),!0;if(!Cn(e[t]))return t=V,!1}for(;Cn(e[t]);)t++;if(e[t]==="."){if(t++,j())return T(V),!0;if(!Cn(e[t]))return t=V,!1;for(;Cn(e[t]);)t++}if(e[t]==="e"||e[t]==="E"){if(t++,(e[t]==="-"||e[t]==="+")&&t++,j())return T(V),!0;if(!Cn(e[t]))return t=V,!1;for(;Cn(e[t]);)t++}if(!j())return t=V,!1;if(t>V){const ne=e.slice(V,t),S=/^0\d/.test(ne);return n+=S?`"${ne}"`:ne,!0}return!1}function N(){return w("true","true")||w("false","false")||w("null","null")||w("True","true")||w("False","false")||w("None","null")}function w(V,ne){return e.slice(t,t+V.length)===V?(n+=ne,t+=V.length,!0):!1}function k(V){const ne=t;if(Tc(e[t])){for(;t<e.length&&Ic(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&&!Oc(e[t])&&!Ji(e[t])&&(!V||e[t]!==":");)t++;if(e[t-1]===":"&&Ac.test(e.substring(ne,t+2)))for(;t<e.length&&zc.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 R(){if(e[t]==="/"){const V=t;for(t++;t<e.length&&(e[t]!=="/"||e[t-1]==="\\");)t++;return t++,n+=JSON.stringify(e.substring(V,t)),!0}}function q(V){let ne=V;for(;ne>0&&Tn(e,ne);)ne--;return ne}function j(){return t>=e.length||Ri(e[t])||Tn(e,t)}function T(V){n+=`${e.slice(V,t)}0`}function z(V){throw new Yn(`Invalid character ${JSON.stringify(V)}`,t)}function P(){throw new Yn(`Unexpected character ${JSON.stringify(e[t])}`,t)}function I(){throw new Yn("Unexpected end of json string",e.length)}function M(){throw new Yn("Object key expected",t)}function J(){throw new Yn("Colon expected",t)}function Z(){const V=e.slice(t,t+6);throw new Yn(`Invalid unicode character "${V}"`,t)}}function sz(e,t){return e[t]==="*"&&e[t+1]==="/"}function az({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 Mc(e)}catch{}const b=`{${e}}`;try{return JSON.parse(b),b}catch{}try{return Mc(b)}catch{return null}},[e]),l=x.useMemo(()=>Mm(o||e),[o,e]),c=Ne(b=>b.activeTab),d=Ne(b=>b.documents),f=Ne(b=>(b.acceptedApplyIds||[]).includes(l)),h=Ne(b=>b.setPendingDiff),p=Ne(b=>b.createDocument),g=Ne(b=>b.openDocument),v=x.useCallback(()=>{if(o){a(null);try{if(c){const b=d.find(w=>w.name===c),E=(b==null?void 0:b.text)||"";if(n==="templates")try{const w=JSON.parse(E),k=JSON.parse(o);if(Array.isArray(k.templates)){w.props||(w.props={}),w.props.templates=Rm(w.props.templates||[],k.templates);const R=JSON.stringify(w,null,2);h(c,E,R,l);return}}catch{}const m=t==null?void 0:t[0],{original:O,modified:N}=$m(E,o,m);h(c,O,N,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,d,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:v,disabled:f||!o,children:f?"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 oz({threads:e,activeThread:t,disabled:n,onSwitch:r,onCreate:i,onDelete:s,onRename:a}){const[o,l]=x.useState(null),[c,d]=x.useState(""),[f,h]=x.useState(null),p=x.useRef(null),g=(t==null?void 0:t.title)||"New Chat",v=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,R)=>{R.stopPropagation(),R.preventDefault(),l(k.id),d(k.title),h(null)},[]),b=x.useCallback(()=>{o&&c.trim()&&a(o,c.trim()),l(null),d("")},[o,c,a]),E=x.useCallback(()=>{l(null),d("")},[]),m=x.useCallback(k=>{k.stopPropagation(),k.key==="Enter"?(k.preventDefault(),b()):k.key==="Escape"&&(k.preventDefault(),E())},[b,E]),O=x.useCallback((k,R)=>{R.stopPropagation(),R.preventDefault(),h(k),l(null)},[]),N=x.useCallback(k=>{k.stopPropagation(),k.preventDefault(),f&&(s(f),h(null))},[f,s]),w=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:v}),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 R=o===k.id;return f===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:N,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:w,children:u.jsx(yn,{className:"h-3.5 w-3.5"})})]},k.id):R?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=>d(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(),E()},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(Qg,{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(co,{className:"h-3 w-3"})})]})]},k.id)}),u.jsx(mr,{}),u.jsxs($t,{onSelect:k=>{k.preventDefault();const R=i();R&&(l(R),d(bo()),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 Jm=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),lz=Array.from(Jm).join(","),uz=20*1024*1024,$c=10;function cz(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 Fc(e){return Array.from(e).filter(t=>Jm.has(t.type)&&t.size<=uz)}function Hm(e){return e.startsWith("image/")}function Lc(){var Q,he,ve;const e=Oe(F=>F.contextAttachments),t=Oe(F=>F.addContext),n=Oe(F=>F.removeContext),r=Oe(F=>F.scope),i=Oe(F=>F.setScope),s=Oe(F=>F.model),a=Oe(F=>F.setModel),o=Oe(F=>F.openChat),l=Oe(F=>F.closeChat),c=Oe(F=>F.threads),d=Oe(F=>F.activeThreadId),f=Oe(F=>F.createThread),h=Oe(F=>F.deleteThread),p=Oe(F=>F.switchThread),g=Oe(F=>F.updateThreadMessages),v=Oe(F=>F.updateThreadTitle),_=Oe(F=>F.deleteThreadsForDocument),b=Ne(F=>F.activeTab),E=Ne(F=>F.documents),{messages:m,sendMessage:O,status:N,error:w,setMessages:k,stop:R,getMessageContext:q,getMessageScope:j}=MA(),[T,z]=x.useState(""),[P,I]=x.useState([]),[M,J]=x.useState(!1),[Z,V]=x.useState(!1),ne=x.useRef(null),S=x.useRef(null),le=x.useRef(null),B=x.useCallback(async F=>{const me=Fc(F);if(me.length===0)return;const Te=await Promise.all(me.map(cz));I(Le=>{const rt=[...Le,...Te];return rt.length>$c?rt.slice(0,$c):rt})},[]),y=x.useCallback(F=>{I(me=>me.filter((Te,Le)=>Le!==F))},[]),W=x.useCallback(F=>{var Te;const me=(Te=F.clipboardData)==null?void 0:Te.files;if(me&&me.length>0){const Le=Fc(me);Le.length>0&&(F.preventDefault(),B(Le))}},[B]),X=x.useCallback(F=>{var Te;F.preventDefault(),V(!1);const me=(Te=F.dataTransfer)==null?void 0:Te.files;me&&me.length>0&&B(Array.from(me))},[B]),Y=x.useCallback(F=>{F.preventDefault(),V(!0)},[]),re=x.useCallback(()=>V(!1),[]),D=b?d[b]:void 0,de=D?c[D]:void 0,te=x.useMemo(()=>b?Object.values(c).filter(F=>F.documentName===b).sort((F,me)=>me.updatedAt-F.updatedAt):[],[c,b]);x.useEffect(()=>{b&&te.length===0&&f(b)},[b,te.length,f]);const ae=x.useRef(c);ae.current=c,x.useEffect(()=>{const F=new Set(E.map(Te=>Te.name)),me=new Set;for(const Te of Object.values(ae.current))!F.has(Te.documentName)&&Te.documentName!=="__migrated__"&&me.add(Te.documentName);for(const Te of me)_(Te)},[E,_]);const ue=x.useRef(null);x.useEffect(()=>{ue.current!==D&&(ue.current=D,k((de==null?void 0:de.messages)??[]))},[D,de,k]),x.useEffect(()=>{var F;(F=ne.current)==null||F.scrollIntoView({behavior:"smooth"})},[m,N]),x.useEffect(()=>{const F=me=>{var rt;const{documentName:Te,selection:Le}=me.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 ge=N==="streaming",pe=N==="submitted"||ge,Pe=x.useCallback(F=>{F.preventDefault(),!(!T.trim()&&P.length===0||pe)&&(O(T,P.length>0?P:void 0),z(""),I([]))},[T,P,pe,O]),De=x.useCallback(F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),Pe(F))},[Pe]),nt=x.useCallback(()=>{m.length!==0&&J(!0)},[m.length]),C=x.useCallback(()=>{J(!1),k([]),D&&(g(D,[]),v(D,bo()))},[k,D,g,v]),[$,U]=x.useState(null),se=x.useCallback(F=>{U(F)},[]),A=x.useCallback(()=>{var rt,et;if(!$)return;const F=m.findIndex(at=>at.id===$);if(F===-1){U(null);return}const me=m[F],Te=new Set([F]);me.role==="user"&&((rt=m[F+1])==null?void 0:rt.role)==="assistant"?Te.add(F+1):me.role==="assistant"&&F>0&&((et=m[F-1])==null?void 0:et.role)==="user"&&Te.add(F-1);const Le=m.filter((at,un)=>!Te.has(un));k(Le),D&&g(D,Le),U(null)},[$,m,k,D,g]),K=x.useCallback(F=>{if(!pe){if(te.length<=1){nt();return}h(F)}},[pe,te.length,nt,h]),ee=x.useCallback(()=>{if(!(!b||pe))return f(b)},[b,pe,f]),xe=x.useCallback(F=>{pe||F===D||p(F)},[pe,D,p]),L=x.useCallback((F,me)=>{v(F,me)},[v]);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(oz,{threads:te,activeThread:de,disabled:pe,onSwitch:xe,onCreate:ee,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:nt,disabled:pe||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(rl,{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,me)=>{let Te;if(F.role==="user"){const et=q(F.id);et&&et.length>0&&(Te=et)}else if(F.role==="assistant"){for(let et=me-1;et>=0;et--)if(m[et].role==="user"){Te=q(m[et].id);break}}const Le=ge&&me===m.length-1&&F.role==="assistant",rt=F.role==="user"?j(F.id):void 0;return u.jsx(dz,{msg:F,isStreaming:Le,context:Te,scope:rt,onDelete:pe?void 0:se},F.id)}),pe&&((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..."})]})})}),w&&!pe&&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:w.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 ${Z?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:X,onDragOver:Y,onDragLeave:re,children:[e.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((F,me)=>u.jsx(Lm,{context:F,onRemove:()=>n(me)},me))}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx(hz,{model:s,setModel:a}),ht==="pptx"&&b&&u.jsx(gz,{scope:r,setScope:i,docSize:((ve=(he=E.find(F=>F.name===b))==null?void 0:he.text)==null?void 0:ve.length)??0})]}),P.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:P.map((F,me)=>u.jsxs("div",{className:"relative group",children:[Hm(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(Ca,{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(me),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"})})]},me))}),u.jsxs("form",{onSubmit:Pe,className:"flex items-end gap-2",children:[u.jsx("input",{ref:le,type:"file",accept:lz,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=le.current)==null?void 0:F.click()},title:"Attach file",children:u.jsx(Ca,{className:"h-4 w-4"})}),u.jsx("textarea",{ref:S,value:T,onChange:F=>{z(F.target.value);const me=F.target;me.style.height="auto",me.style.height=`${Math.min(me.scrollHeight,128)}px`},onKeyDown:De,onPaste:W,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}),pe?u.jsx(Se,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:R,title:"Stop generating",children:u.jsx(Id,{className:"h-4 w-4"})}):u.jsx(Se,{type:"submit",size:"icon",disabled:!T.trim()&&P.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:u.jsx(rl,{className:"h-4 w-4"})})]})]}),u.jsx(Ct,{open:M,onOpenChange:J,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(sl,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Se,{variant:"destructive",size:"sm",onClick:C,children:"Clear"})]})]})}),u.jsx(Ct,{open:$!==null,onOpenChange:F=>{F||U(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(sl,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Se,{variant:"destructive",size:"sm",onClick:A,children:"Delete"})]})]})})]})}const dz=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(d=>d.type==="text").map(d=>d.text).join(""))||"",o=((c=t.parts)==null?void 0:c.filter(d=>d.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((d,f)=>Hm(d.mediaType)?u.jsx("img",{src:d.url,alt:d.filename||"image",className:"h-20 max-w-[160px] rounded-sm object-cover"},f):u.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm bg-primary-foreground/20 px-2 py-1",children:[u.jsx(Ca,{className:"h-3 w-3 shrink-0"}),u.jsx("span",{className:"text-xs truncate max-w-[120px]",children:d.filename||"file"})]},f))}),r&&r.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:r.map((d,f)=>u.jsx(Lm,{context:d,variant:"sent"},f))}),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(fz,{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(co,{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 fz({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(F1,{remarkPlugins:[X_],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(xz,{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(az,{json:l,context:n,scope:r})]})}},children:e})})}const pz=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function hz({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:pz.map(n=>u.jsx(Pn,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const Bc={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"},mz=1e5;function gz({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(Bc).map(r=>u.jsxs(Ge,{children:[u.jsx(Ye,{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(Ke,{side:"top",className:"text-xs max-w-[200px]",children:Bc[r]})]},r))})]}),e==="global"&&n>mz&&u.jsxs("div",{className:"text-[10px] text-warning flex items-center gap-1",children:[u.jsx(Od,{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 xz({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 yz({discoveryData:e}){const t=xf(),n=cy(),r=Oe(j=>j.chatOpen),i=Oe(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,d]=x.useState("editor"),[f,h]=x.useState(!1),p=150,[g,v]=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 E=x.useRef(n);x.useEffect(()=>{n&&!E.current&&s&&(b(!0),a(!1),setTimeout(()=>{v(!0),b(!1)},p)),!n&&E.current&&!s&&(b(!0),a(!0),setTimeout(()=>{v(!1),b(!1)},p)),E.current=n},[n,s]);const m=x.useCallback(()=>{if(t){h(j=>!j);return}b(!0),a(j=>!j),setTimeout(()=>{v(j=>!j),b(!1)},p)},[t]),O=x.useCallback(()=>l(j=>!j),[]),N=x.useRef(i),w=x.useRef(m),k=x.useRef(O);x.useEffect(()=>{N.current=i}),x.useEffect(()=>{w.current=m}),x.useEffect(()=>{k.current=O}),x.useEffect(()=>{const j=T=>{(T.metaKey||T.ctrlKey)&&(T.code==="KeyB"&&!T.shiftKey&&(T.preventDefault(),w.current()),T.code==="KeyJ"&&T.shiftKey&&(T.preventDefault(),T.stopPropagation(),N.current()),T.code==="KeyP"&&T.shiftKey&&(T.preventDefault(),k.current()))};return window.addEventListener("keydown",j,!0),()=>window.removeEventListener("keydown",j,!0)},[]);const R=RA,q=[{key:"editor",icon:Ea,label:"Editor"},{key:"preview",icon:Pd,label:"Preview"},{key:"chat",icon:Dd,label:"Chat"}];return t?u.jsx(R,{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(hf,{open:f,onOpenChange:h,children:[u.jsx(sy,{asChild:!0,children:u.jsx(Se,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:u.jsx(zd,{className:"h-4 w-4"})})}),u.jsx(ko,{side:"left",className:"p-0 w-72",children:u.jsx(Cl,{discoveryData:e,onToggleSidebar:()=>h(!1),isCollapsed:!1})})]}),u.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:q.map(({key:j,icon:T,label:z})=>u.jsxs(Se,{variant:c===j?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>d(j),children:[u.jsx(T,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"hidden xs:inline",children:z})]},j))})]}),c!=="chat"&&u.jsx(Yl,{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(Tl,{})}),c==="preview"&&u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Il,{})}),c==="chat"&&u.jsx(Lc,{})]})]})}):u.jsx(R,{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(Cl,{discoveryData:e,onToggleSidebar:m,isCollapsed:g,isAnimating:_})}),u.jsxs("div",{className:"flex-1 min-w-0 flex flex-col h-full",children:[u.jsx(Yl,{previewOpen:o,onTogglePreview:O}),u.jsxs(Vb,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[u.jsx(Xs,{defaultSize:o?50:100,minSize:20,id:"editor",order:1,children:u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(Tl,{})})}),o&&u.jsxs(u.Fragment,{children:[u.jsx(Ll,{withHandle:!0}),u.jsx(Xs,{defaultSize:50,minSize:20,id:"preview",order:2,children:u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Il,{})})})]}),r&&u.jsxs(u.Fragment,{children:[u.jsx(Ll,{withHandle:!0}),u.jsx(Xs,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:u.jsx(Lc,{})})]})]})]})]})})}function bz(){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 vz(){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 wz(){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=vz().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 kz(){const{data:e,loading:t,error:n}=bz(),{loadPlugins:r}=wz(),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(rx,{children:u.jsx(ix,{children:u.jsx(sx,{children:u.jsx(ax,{children:u.jsx(ox,{children:u.jsx(Zx,{children:u.jsx(bf,{children:u.jsx("section",{className:"flex h-screen w-full flex-col",children:u.jsx("div",{className:"grow overflow-hidden",children:u.jsx(yz,{discoveryData:e})})})})})})})})})})}const zz=Object.freeze(Object.defineProperty({__proto__:null,HomePage:kz},Symbol.toStringTag,{value:"Module"}));export{Kt as B,Ct as D,zz as H,nv as P,Yr as S,ur as T,tp as a,pf as b,kt as c,Vt as d,Ut as e,Yb as u};
106
- //# sourceMappingURL=HomePage-D3vuZyJI.js.map
106
+ //# sourceMappingURL=HomePage-jkIz_s7u.js.map