@json-to-office/jto 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +130 -37
- package/dist/cli.js.map +1 -1
- package/dist/client/assets/{HomePage-BTmw2QAf.js → HomePage-Czwc5NK6.js} +3 -3
- package/dist/client/assets/{HomePage-BTmw2QAf.js.map → HomePage-Czwc5NK6.js.map} +1 -1
- package/dist/client/assets/{JsonEditorPage-CRONWw-J.js → JsonEditorPage-CwOeiOy6.js} +3 -3
- package/dist/client/assets/{JsonEditorPage-CRONWw-J.js.map → JsonEditorPage-CwOeiOy6.js.map} +1 -1
- package/dist/client/assets/{MonacoPluginProvider-DhOIgTne.js → MonacoPluginProvider-DQcmmuko.js} +3 -3
- package/dist/client/assets/{MonacoPluginProvider-DhOIgTne.js.map → MonacoPluginProvider-DQcmmuko.js.map} +1 -1
- package/dist/client/assets/{button-ebCBEwlw.js → button-DfjYrtU-.js} +2 -2
- package/dist/client/assets/{button-ebCBEwlw.js.map → button-DfjYrtU-.js.map} +1 -1
- package/dist/client/assets/{editor-CB9BVJGn.js → editor-BPfMyucg.js} +2 -2
- package/dist/client/assets/{editor-CB9BVJGn.js.map → editor-BPfMyucg.js.map} +1 -1
- package/dist/client/assets/{editor-monaco-json-DaGk8WIJ.js → editor-monaco-json-cWylTaeJ.js} +2 -2
- package/dist/client/assets/{editor-monaco-json-DaGk8WIJ.js.map → editor-monaco-json-cWylTaeJ.js.map} +1 -1
- package/dist/client/assets/index-Dd4Xxzh5.js +5 -0
- package/dist/client/assets/index-Dd4Xxzh5.js.map +1 -0
- package/dist/client/assets/{preview-B4bcm38l.js → preview-Cdpjm_5u.js} +2 -2
- package/dist/client/assets/{preview-B4bcm38l.js.map → preview-Cdpjm_5u.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/render-server.d.ts +2 -0
- package/dist/render-server.js +255 -0
- package/dist/render-server.js.map +1 -0
- package/package.json +9 -9
- package/dist/client/assets/index-Cy63RxyT.js +0 -5
- package/dist/client/assets/index-Cy63RxyT.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-
|
|
2
|
-
var cm=Object.defineProperty;var dm=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Mo=(e,t,n)=>dm(e,typeof t!="symbol"?t+"":t,n);import{r as y,j as u,c as Ee,R as cc,g as Ua}from"./react-vendor-CTFDOf2G.js";import{b as dc,c as Ja,d as fc,e as pc,f as ts,g as ns,D as rs,O as is,h as fm,V as pm,i as hc,I as hm,j as mm,k as mc,l as gm,m as gc,n as xm,o as ym,G as bm,S as xc,p as yc,L as bc,q as vc,r as wc,s as or,t as vm,u as wm,v as km,w as kc,x as Sc,y as _c,z as jc,A as Nc,B as Cc,E as Ec,F as Ic,H as zc,J as Tc,K as Ac,M as Sm,N as _m,Q as Pc,U as jm,W as Nm,X as Cm,Y as Em,Z as Im,_ as zm,$ as Tm,a0 as Am,a1 as Pm,a2 as Oc,a3 as Dc,a4 as Rc,a5 as Mc,a6 as $c,a7 as Fc,a8 as Lc,a9 as Zc,aa as Bc,ab as Om,ac as Vc,ad as Uc,ae as Jc}from"./radix-ui-BQBCrmlJ.js";import{c as H,u as Xr,S as Yt,A as Hc,T as oi,C as Dm,E as Rm,F as yt,a as Mm,b as We,d as Ge,e as Ke,f as qc,s as Ns,_ as Wc,g as li,h as $m,i as Fm,j as Lm,k as fr,l as vi,W as Zm}from"./index-Cy63RxyT.js";import{X as Nn,C as on,a as un,b as Bm,d as Qr,G as Gc,F as Vm,e as ss,f as Kc,P as Um,g as $o,h as la,i as Yc,S as Xc,B as Fo,j as Jm,k as Hm,l as qm,m as as,n as Wm,M as Gm,o as Km,p as Ym,q as Qc,r as Xm,s as Lo,t as zi,u as Qm,I as ed,v as eg,w as tg,R as ng,x as rg,T as td,E as ig,y as sg,z as ag,A as og,D as nd,H as Ha,J as rd,K as lg,L as id,N as ua,O as ug,Q as cg,U as Zo,V as ca,W as dg}from"./ui-vendor-HKNXoiLD.js";import{B as we}from"./button-ebCBEwlw.js";import{u as Ae,i as fg,a as da,b as vn,g as fa,c as Dt,T as sd,d as ui,S as pg,O as hg,e as mg,M as gg,D as xg}from"./MonacoPluginProvider-DhOIgTne.js";import{u as ad,a as yg,d as bg,p as vg,b as wg,e as kg}from"./state-vendor-ByFYl9bq.js";import{b as Sg}from"./query-vendor-Df8-oete.js";const It=dc,Bo=fc,_g=pc,Vo=Ja,od=y.forwardRef(({className:e,...t},n)=>u.jsx(is,{ref:n,className:H("fixed inset-0 z-50 bg-black/80",e),...t}));od.displayName=is.displayName;const St=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_g,{children:[u.jsx(od,{}),u.jsxs(ts,{ref:r,className:H("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(Ja,{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(Nn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));St.displayName=ts.displayName;const Ut=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ut.displayName="DialogHeader";const Cn=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});Cn.displayName="DialogFooter";const Jt=y.forwardRef(({className:e,...t},n)=>u.jsx(ns,{ref:n,className:H("text-lg leading-none font-semibold tracking-tight",e),...t}));Jt.displayName=ns.displayName;const cn=y.forwardRef(({className:e,...t},n)=>u.jsx(rs,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));cn.displayName=rs.displayName;const Rr=fm,jg=bm,Mr=pm,er=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hc,{ref:r,className:H("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-md border bg-transparent px-3 py-2 text-sm shadow-sm 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(hm,{asChild:!0,children:u.jsx(on,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));er.displayName=hc.displayName;const ld=y.forwardRef(({className:e,...t},n)=>u.jsx(xc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Bm,{className:"h-4 w-4"})}));ld.displayName=xc.displayName;const ud=y.forwardRef(({className:e,...t},n)=>u.jsx(yc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(on,{className:"h-4 w-4"})}));ud.displayName=yc.displayName;const tr=y.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(mm,{children:u.jsxs(mc,{ref:i,className:H("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-md 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(ld,{}),u.jsx(gm,{className:H("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(ud,{})]})}));tr.displayName=mc.displayName;const cd=y.forwardRef(({className:e,...t},n)=>u.jsx(bc,{ref:n,className:H("px-2 py-1.5 text-sm font-semibold",e),...t}));cd.displayName=bc.displayName;const En=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gc,{ref:r,className:H("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(xm,{children:u.jsx(un,{className:"h-4 w-4"})})}),u.jsx(ym,{children:t})]}));En.displayName=gc.displayName;const Ng=y.forwardRef(({className:e,...t},n)=>u.jsx(vc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));Ng.displayName=vc.displayName;const ei=y.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:H("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-md border bg-transparent px-3 py-1 text-base shadow-sm 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 md:text-sm",e),ref:r,...n}));ei.displayName="Input";const Cg=Qr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Gn=y.forwardRef(({className:e,...t},n)=>u.jsx(wc,{ref:n,className:H(Cg(),e),...t}));Gn.displayName=wc.displayName;const Eg=Qr("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Vt({className:e,variant:t,...n}){return u.jsx("div",{className:H(Eg({variant:t}),e),...n})}const Ig=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Ae(ad(I=>({documents:I.documents,documentTypes:I.documentTypes,activeTab:I.activeTab,createDocument:I.createDocument,openDocument:I.openDocument}))),{toast:o}=Xr(),l=y.useMemo(()=>n.filter(I=>r[I.name]!=="application/json+theme"),[n,r]),[c,f]=y.useState(""),[d,p]=y.useState(""),[h,m]=y.useState("playground"),[w,S]=y.useState(!1),[x,_]=y.useState(null),[g,z]=y.useState(null),[E,k]=y.useState(null),C=()=>{_(null),z(null),k(null)};y.useEffect(()=>{if(!e)return;_(null),z(null),k(null);const I=l.map(B=>B.name),A=I.includes(i)?i:I[0]??"";p(A),f(I.find(B=>B!==A)??"")},[e]);const $=async()=>{const I=l.find(B=>B.name===c),A=l.find(B=>B.name===d);if(!(!I||!A)){S(!0),_(null),z(null),k(null);try{const B=await fetch(Hc.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:I.text,newDefinition:A.text,options:{author:h||"playground"}})}),D=await B.json();if(!B.ok||!D.success){const T=Array.isArray(D.errors)?`: ${D.errors.slice(0,3).map(P=>P.message||String(P)).join("; ")}`:"";throw new Error((D.error||`Diff failed (${B.status})`)+T)}z(D.data.summary),k(D.data.document)}catch(B){_(B instanceof Error?B.message:"Diff failed")}finally{S(!1)}}},K=()=>{if(!E)return;const I=new Set(n.map(D=>D.name));let A=`${d}-redline`,B=2;for(;I.has(A);)A=`${d}-redline-${B++}`;s(A,JSON.stringify(E,null,2)),a(A),o({title:`Redline created: ${A}`}),t(!1)},N=g?g.tracked.modified+g.tracked.inserted+g.tracked.deleted:0;return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"sm:max-w-[560px]",children:[u.jsxs(Ut,{children:[u.jsxs(Jt,{className:"flex items-center gap-2",children:[u.jsx(Gc,{className:"size-4"}),"Compare documents"]}),u.jsx(cn,{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(Gn,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(Rr,{value:c,onValueChange:I=>{f(I),C()},children:[u.jsx(er,{id:"diff-base",children:u.jsx(Mr,{placeholder:"Select document"})}),u.jsx(tr,{children:l.map(I=>u.jsx(En,{value:I.name,children:I.name},I.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Gn,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(Rr,{value:d,onValueChange:I=>{p(I),C()},children:[u.jsx(er,{id:"diff-revised",children:u.jsx(Mr,{placeholder:"Select document"})}),u.jsx(tr,{children:l.map(I=>u.jsx(En,{value:I.name,children:I.name},I.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Gn,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(ei,{id:"diff-author",value:h,onChange:I=>{m(I.target.value),C()},placeholder:"playground"})]}),x&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:x}),g&&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(Vt,{variant:"secondary",children:[g.tracked.inserted," inserted"]}),u.jsxs(Vt,{variant:"secondary",children:[g.tracked.deleted," deleted"]}),u.jsxs(Vt,{variant:"secondary",children:[g.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[g.unchangedBlocks," blocks unchanged"]})]}),N===0&&g.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),g.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-amber-600 dark:text-amber-500",children:[g.untracked.length," change(s) not expressible as tracked changes:"]}),g.untracked.map((I,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[I.path," [",I.component,"] ",I.detail]},A))]}),g.notes.map((I,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",I]},A))]})]}),u.jsx(Cn,{children:g&&N+g.untracked.length>0?u.jsxs(we,{onClick:K,children:[u.jsx(Vm,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(we,{onClick:$,disabled:w||!c||!d||c===d,children:[w&&u.jsx(Yt,{className:"size-4 mr-1"}),"Compare"]})})]})})};var ti=e=>e.type==="checkbox",kn=e=>e instanceof Date,ct=e=>e==null;const dd=e=>typeof e=="object";var Xe=e=>!ct(e)&&!Array.isArray(e)&&dd(e)&&!kn(e),fd=e=>Xe(e)&&e.target?ti(e.target)?e.target.checked:e.target.value:e,zg=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,pd=(e,t)=>e.has(zg(t)),Tg=e=>{const t=e.constructor&&e.constructor.prototype;return Xe(t)&&t.hasOwnProperty("isPrototypeOf")},qa=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mt(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(!(qa&&(e instanceof Blob||r))&&(n||Xe(e)))if(t=n?[]:{},!n&&!Tg(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=mt(e[i]));else return e;return t}var os=e=>Array.isArray(e)?e.filter(Boolean):[],Ye=e=>e===void 0,ae=(e,t,n)=>{if(!t||!Xe(e))return n;const r=os(t.split(/[,[\].]+?/)).reduce((i,s)=>ct(i)?i:i[s],e);return Ye(r)||r===e?Ye(e[t])?n:e[t]:r},Ct=e=>typeof e=="boolean",Wa=e=>/^\w*$/.test(e),hd=e=>os(e.replace(/["|']|\]/g,"").split(/\.|\[/)),De=(e,t,n)=>{let r=-1;const i=Wa(t)?[t]:hd(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=Xe(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 Ti={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ot={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Gt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},md=Ee.createContext(null),ls=()=>Ee.useContext(md),Ag=e=>{const{children:t,...n}=e;return Ee.createElement(md.Provider,{value:n},t)};var gd=(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]!==Ot.all&&(t._proxyFormState[a]=!r||Ot.all),n&&(n[a]=!0),e[a]}});return i},gt=e=>Xe(e)&&!Object.keys(e).length,xd=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return gt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(a=>t[a]===(!r||Ot.all))},zr=e=>Array.isArray(e)?e:[e],yd=(e,t,n)=>!e||!t||e===t||zr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function Ga(e){const t=Ee.useRef(e);t.current=e,Ee.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function Pg(e){const t=ls(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[a,o]=Ee.useState(n._formState),l=Ee.useRef(!0),c=Ee.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),f=Ee.useRef(i);return f.current=i,Ga({disabled:r,next:d=>l.current&&yd(f.current,d.name,s)&&xd(d,c.current,n._updateFormState)&&o({...n._formState,...d}),subject:n._subjects.state}),Ee.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),Ee.useMemo(()=>gd(a,n,c.current,!1),[a,n])}var Bt=e=>typeof e=="string",bd=(e,t,n,r,i)=>Bt(e)?(r&&t.watch.add(e),ae(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),ae(n,s))):(r&&(t.watchAll=!0),n);function Og(e){const t=ls(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=Ee.useRef(r);o.current=r,Ga({disabled:s,subject:n._subjects.values,next:f=>{yd(o.current,f.name,a)&&c(mt(bd(o.current,n._names,f.values||n._formValues,!1,i)))}});const[l,c]=Ee.useState(n._getWatch(r,i));return Ee.useEffect(()=>n._removeUnmounted()),l}function Dg(e){const t=ls(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=pd(i._names.array,n),o=Og({control:i,name:n,defaultValue:ae(i._formValues,n,ae(i._defaultValues,n,e.defaultValue)),exact:!0}),l=Pg({control:i,name:n,exact:!0}),c=Ee.useRef(i.register(n,{...e.rules,value:o,...Ct(e.disabled)?{disabled:e.disabled}:{}})),f=Ee.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ae(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!ae(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ae(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ae(l.validatingFields,n)},error:{enumerable:!0,get:()=>ae(l.errors,n)}}),[l,n]),d=Ee.useMemo(()=>({name:n,value:o,...Ct(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:fd(p),name:n},type:Ti.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:ae(i._formValues,n),name:n},type:Ti.BLUR}),ref:p=>{const h=ae(i._fields,n);h&&p&&(h._f.ref={focus:()=>p.focus(),select:()=>p.select(),setCustomValidity:m=>p.setCustomValidity(m),reportValidity:()=>p.reportValidity()})}}),[n,i._formValues,r,l.disabled,o,i._fields]);return Ee.useEffect(()=>{const p=i._options.shouldUnregister||s,h=(m,w)=>{const S=ae(i._fields,m);S&&S._f&&(S._f.mount=w)};if(h(n,!0),p){const m=mt(ae(i._options.defaultValues,n));De(i._defaultValues,n,m),Ye(ae(i._formValues,n))&&De(i._formValues,n,m)}return!a&&i.register(n),()=>{(a?p&&!i._state.action:p)?i.unregister(n):h(n,!1)}},[n,i,a,s]),Ee.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),Ee.useMemo(()=>({field:d,formState:l,fieldState:f}),[d,l,f])}const Rg=e=>e.render(Dg(e));var Mg=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},Uo=e=>({isOnSubmit:!e||e===Ot.onSubmit,isOnBlur:e===Ot.onBlur,isOnChange:e===Ot.onChange,isOnAll:e===Ot.all,isOnTouch:e===Ot.onTouched}),Jo=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Tr=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=ae(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(Tr(o,t))break}else if(Xe(o)&&Tr(o,t))break}}};var $g=(e,t,n)=>{const r=zr(ae(e,n));return De(r,"root",t[n]),De(e,n,r),e},Ka=e=>e.type==="file",Zt=e=>typeof e=="function",Ai=e=>{if(!qa)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},wi=e=>Bt(e),Ya=e=>e.type==="radio",Pi=e=>e instanceof RegExp;const Ho={value:!1,isValid:!1},qo={value:!0,isValid:!0};var vd=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&&!Ye(e[0].attributes.value)?Ye(e[0].value)||e[0].value===""?qo:{value:e[0].value,isValid:!0}:qo:Ho}return Ho};const Wo={isValid:!1,value:null};var wd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Wo):Wo;function Go(e,t,n="validate"){if(wi(e)||Array.isArray(e)&&e.every(wi)||Ct(e)&&!e)return{type:n,message:wi(e)?e:"",ref:t}}var On=e=>Xe(e)&&!Pi(e)?e:{value:e,message:""},Ko=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:f,min:d,max:p,pattern:h,validate:m,name:w,valueAsNumber:S,mount:x}=e._f,_=ae(n,w);if(!x||t.has(w))return{};const g=o?o[0]:a,z=A=>{i&&g.reportValidity&&(g.setCustomValidity(Ct(A)?"":A||""),g.reportValidity())},E={},k=Ya(a),C=ti(a),$=k||C,K=(S||Ka(a))&&Ye(a.value)&&Ye(_)||Ai(a)&&a.value===""||_===""||Array.isArray(_)&&!_.length,N=Mg.bind(null,w,r,E),I=(A,B,D,T=Gt.maxLength,P=Gt.minLength)=>{const J=A?B:D;E[w]={type:A?T:P,message:J,ref:a,...N(A?T:P,J)}};if(s?!Array.isArray(_)||!_.length:l&&(!$&&(K||ct(_))||Ct(_)&&!_||C&&!vd(o).isValid||k&&!wd(o).isValid)){const{value:A,message:B}=wi(l)?{value:!!l,message:l}:On(l);if(A&&(E[w]={type:Gt.required,message:B,ref:g,...N(Gt.required,B)},!r))return z(B),E}if(!K&&(!ct(d)||!ct(p))){let A,B;const D=On(p),T=On(d);if(!ct(_)&&!isNaN(_)){const P=a.valueAsNumber||_&&+_;ct(D.value)||(A=P>D.value),ct(T.value)||(B=P<T.value)}else{const P=a.valueAsDate||new Date(_),J=v=>new Date(new Date().toDateString()+" "+v),R=a.type=="time",q=a.type=="week";Bt(D.value)&&_&&(A=R?J(_)>J(D.value):q?_>D.value:P>new Date(D.value)),Bt(T.value)&&_&&(B=R?J(_)<J(T.value):q?_<T.value:P<new Date(T.value))}if((A||B)&&(I(!!A,D.message,T.message,Gt.max,Gt.min),!r))return z(E[w].message),E}if((c||f)&&!K&&(Bt(_)||s&&Array.isArray(_))){const A=On(c),B=On(f),D=!ct(A.value)&&_.length>+A.value,T=!ct(B.value)&&_.length<+B.value;if((D||T)&&(I(D,A.message,B.message),!r))return z(E[w].message),E}if(h&&!K&&Bt(_)){const{value:A,message:B}=On(h);if(Pi(A)&&!_.match(A)&&(E[w]={type:Gt.pattern,message:B,ref:a,...N(Gt.pattern,B)},!r))return z(B),E}if(m){if(Zt(m)){const A=await m(_,n),B=Go(A,g);if(B&&(E[w]={...B,...N(Gt.validate,B.message)},!r))return z(B.message),E}else if(Xe(m)){let A={};for(const B in m){if(!gt(A)&&!r)break;const D=Go(await m[B](_,n),g,B);D&&(A={...D,...N(B,D.message)},z(D.message),r&&(E[w]=A))}if(!gt(A)&&(E[w]={ref:g,...A},!r))return E}}return z(!0),E};function Fg(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Ye(e)?r++:e[t[r++]];return e}function Lg(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ye(e[t]))return!1;return!0}function rt(e,t){const n=Array.isArray(t)?t:Wa(t)?[t]:hd(t),r=n.length===1?e:Fg(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(Xe(r)&>(r)||Array.isArray(r)&&Lg(r))&&rt(e,n.slice(0,-1)),e}var Cs=()=>{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=[]}}},pa=e=>ct(e)||!dd(e);function sn(e,t){if(pa(e)||pa(t))return e===t;if(kn(e)&&kn(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(kn(s)&&kn(a)||Xe(s)&&Xe(a)||Array.isArray(s)&&Array.isArray(a)?!sn(s,a):s!==a)return!1}}return!0}var kd=e=>e.type==="select-multiple",Zg=e=>Ya(e)||ti(e),Es=e=>Ai(e)&&e.isConnected,Sd=e=>{for(const t in e)if(Zt(e[t]))return!0;return!1};function Oi(e,t={}){const n=Array.isArray(e);if(Xe(e)||n)for(const r in e)Array.isArray(e[r])||Xe(e[r])&&!Sd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Oi(e[r],t[r])):ct(e[r])||(t[r]=!0);return t}function _d(e,t,n){const r=Array.isArray(e);if(Xe(e)||r)for(const i in e)Array.isArray(e[i])||Xe(e[i])&&!Sd(e[i])?Ye(t)||pa(n[i])?n[i]=Array.isArray(e[i])?Oi(e[i],[]):{...Oi(e[i])}:_d(e[i],ct(t)?{}:t[i],n[i]):n[i]=!sn(e[i],t[i]);return n}var pr=(e,t)=>_d(e,t,Oi(t)),jd=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ye(e)?e:t?e===""?NaN:e&&+e:n&&Bt(e)?new Date(e):r?r(e):e;function Is(e){const t=e.ref;return Ka(t)?t.files:Ya(t)?wd(e.refs).value:kd(t)?[...t.selectedOptions].map(({value:n})=>n):ti(t)?vd(e.refs).value:jd(Ye(t.value)?e.ref.value:t.value,e)}var Bg=(e,t,n,r)=>{const i={};for(const s of e){const a=ae(t,s);a&&De(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},hr=e=>Ye(e)?e:Pi(e)?e.source:Xe(e)?Pi(e.value)?e.value.source:e.value:e;const Yo="AsyncFunction";var Vg=e=>!!e&&!!e.validate&&!!(Zt(e.validate)&&e.validate.constructor.name===Yo||Xe(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Yo)),Ug=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Xo(e,t,n){const r=ae(e,n);if(r||Wa(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=ae(t,s),o=ae(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 Jg=(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,Hg=(e,t)=>!os(ae(e,t)).length&&rt(e,t);const qg={mode:Ot.onSubmit,reValidateMode:Ot.onChange,shouldFocusError:!0};function Wg(e={}){let t={...qg,...e},n={submitCount:0,isDirty:!1,isLoading:Zt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=Xe(t.defaultValues)||Xe(t.values)?mt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:mt(i),a={action:!1,mount:!1,watch:!1},o={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const f={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={values:Cs(),array:Cs(),state:Cs()},p=Uo(t.mode),h=Uo(t.reValidateMode),m=t.criteriaMode===Ot.all,w=j=>O=>{clearTimeout(c),c=setTimeout(j,O)},S=async j=>{if(!t.disabled&&(f.isValid||j)){const O=t.resolver?gt((await $()).errors):await N(r,!0);O!==n.isValid&&d.state.next({isValid:O})}},x=(j,O)=>{!t.disabled&&(f.isValidating||f.validatingFields)&&((j||Array.from(o.mount)).forEach(Z=>{Z&&(O?De(n.validatingFields,Z,O):rt(n.validatingFields,Z))}),d.state.next({validatingFields:n.validatingFields,isValidating:!gt(n.validatingFields)}))},_=(j,O=[],Z,re,ee=!0,Q=!0)=>{if(re&&Z&&!t.disabled){if(a.action=!0,Q&&Array.isArray(ae(r,j))){const pe=Z(ae(r,j),re.argA,re.argB);ee&&De(r,j,pe)}if(Q&&Array.isArray(ae(n.errors,j))){const pe=Z(ae(n.errors,j),re.argA,re.argB);ee&&De(n.errors,j,pe),Hg(n.errors,j)}if(f.touchedFields&&Q&&Array.isArray(ae(n.touchedFields,j))){const pe=Z(ae(n.touchedFields,j),re.argA,re.argB);ee&&De(n.touchedFields,j,pe)}f.dirtyFields&&(n.dirtyFields=pr(i,s)),d.state.next({name:j,isDirty:A(j,O),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else De(s,j,O)},g=(j,O)=>{De(n.errors,j,O),d.state.next({errors:n.errors})},z=j=>{n.errors=j,d.state.next({errors:n.errors,isValid:!1})},E=(j,O,Z,re)=>{const ee=ae(r,j);if(ee){const Q=ae(s,j,Ye(Z)?ae(i,j):Z);Ye(Q)||re&&re.defaultChecked||O?De(s,j,O?Q:Is(ee._f)):T(j,Q),a.mount&&S()}},k=(j,O,Z,re,ee)=>{let Q=!1,pe=!1;const ve={name:j};if(!t.disabled){const L=!!(ae(r,j)&&ae(r,j)._f&&ae(r,j)._f.disabled);if(!Z||re){f.isDirty&&(pe=n.isDirty,n.isDirty=ve.isDirty=A(),Q=pe!==ve.isDirty);const G=L||sn(ae(i,j),O);pe=!!(!L&&ae(n.dirtyFields,j)),G||L?rt(n.dirtyFields,j):De(n.dirtyFields,j,!0),ve.dirtyFields=n.dirtyFields,Q=Q||f.dirtyFields&&pe!==!G}if(Z){const G=ae(n.touchedFields,j);G||(De(n.touchedFields,j,Z),ve.touchedFields=n.touchedFields,Q=Q||f.touchedFields&&G!==Z)}Q&&ee&&d.state.next(ve)}return Q?ve:{}},C=(j,O,Z,re)=>{const ee=ae(n.errors,j),Q=f.isValid&&Ct(O)&&n.isValid!==O;if(t.delayError&&Z?(l=w(()=>g(j,Z)),l(t.delayError)):(clearTimeout(c),l=null,Z?De(n.errors,j,Z):rt(n.errors,j)),(Z?!sn(ee,Z):ee)||!gt(re)||Q){const pe={...re,...Q&&Ct(O)?{isValid:O}:{},errors:n.errors,name:j};n={...n,...pe},d.state.next(pe)}},$=async j=>{x(j,!0);const O=await t.resolver(s,t.context,Bg(j||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return x(j),O},K=async j=>{const{errors:O}=await $(j);if(j)for(const Z of j){const re=ae(O,Z);re?De(n.errors,Z,re):rt(n.errors,Z)}else n.errors=O;return O},N=async(j,O,Z={valid:!0})=>{for(const re in j){const ee=j[re];if(ee){const{_f:Q,...pe}=ee;if(Q){const ve=o.array.has(Q.name),L=ee._f&&Vg(ee._f);L&&f.validatingFields&&x([re],!0);const G=await Ko(ee,o.disabled,s,m,t.shouldUseNativeValidation&&!O,ve);if(L&&f.validatingFields&&x([re]),G[Q.name]&&(Z.valid=!1,O))break;!O&&(ae(G,Q.name)?ve?$g(n.errors,G,Q.name):De(n.errors,Q.name,G[Q.name]):rt(n.errors,Q.name))}!gt(pe)&&await N(pe,O,Z)}}return Z.valid},I=()=>{for(const j of o.unMount){const O=ae(r,j);O&&(O._f.refs?O._f.refs.every(Z=>!Es(Z)):!Es(O._f.ref))&&ne(j)}o.unMount=new Set},A=(j,O)=>!t.disabled&&(j&&O&&De(s,j,O),!sn(fe(),i)),B=(j,O,Z)=>bd(j,o,{...a.mount?s:Ye(O)?i:Bt(j)?{[j]:O}:O},Z,O),D=j=>os(ae(a.mount?s:i,j,t.shouldUnregister?ae(i,j,[]):[])),T=(j,O,Z={})=>{const re=ae(r,j);let ee=O;if(re){const Q=re._f;Q&&(!Q.disabled&&De(s,j,jd(O,Q)),ee=Ai(Q.ref)&&ct(O)?"":O,kd(Q.ref)?[...Q.ref.options].forEach(pe=>pe.selected=ee.includes(pe.value)):Q.refs?ti(Q.ref)?Q.refs.length>1?Q.refs.forEach(pe=>(!pe.defaultChecked||!pe.disabled)&&(pe.checked=Array.isArray(ee)?!!ee.find(ve=>ve===pe.value):ee===pe.value)):Q.refs[0]&&(Q.refs[0].checked=!!ee):Q.refs.forEach(pe=>pe.checked=pe.value===ee):Ka(Q.ref)?Q.ref.value="":(Q.ref.value=ee,Q.ref.type||d.values.next({name:j,values:{...s}})))}(Z.shouldDirty||Z.shouldTouch)&&k(j,ee,Z.shouldTouch,Z.shouldDirty,!0),Z.shouldValidate&&v(j)},P=(j,O,Z)=>{for(const re in O){const ee=O[re],Q=`${j}.${re}`,pe=ae(r,Q);(o.array.has(j)||Xe(ee)||pe&&!pe._f)&&!kn(ee)?P(Q,ee,Z):T(Q,ee,Z)}},J=(j,O,Z={})=>{const re=ae(r,j),ee=o.array.has(j),Q=mt(O);De(s,j,Q),ee?(d.array.next({name:j,values:{...s}}),(f.isDirty||f.dirtyFields)&&Z.shouldDirty&&d.state.next({name:j,dirtyFields:pr(i,s),isDirty:A(j,Q)})):re&&!re._f&&!ct(Q)?P(j,Q,Z):T(j,Q,Z),Jo(j,o)&&d.state.next({...n}),d.values.next({name:a.mount?j:void 0,values:{...s}})},R=async j=>{a.mount=!0;const O=j.target;let Z=O.name,re=!0;const ee=ae(r,Z),Q=()=>O.type?Is(ee._f):fd(j),pe=ve=>{re=Number.isNaN(ve)||kn(ve)&&isNaN(ve.getTime())||sn(ve,ae(s,Z,ve))};if(ee){let ve,L;const G=Q(),he=j.type===Ti.BLUR||j.type===Ti.FOCUS_OUT,Se=!Ug(ee._f)&&!t.resolver&&!ae(n.errors,Z)&&!ee._f.deps||Jg(he,ae(n.touchedFields,Z),n.isSubmitted,h,p),M=Jo(Z,o,he);De(s,Z,G),he?(ee._f.onBlur&&ee._f.onBlur(j),l&&l(0)):ee._f.onChange&&ee._f.onChange(j);const me=k(Z,G,he,!1),Ce=!gt(me)||M;if(!he&&d.values.next({name:Z,type:j.type,values:{...s}}),Se)return f.isValid&&(t.mode==="onBlur"&&he?S():he||S()),Ce&&d.state.next({name:Z,...M?{}:me});if(!he&&M&&d.state.next({...n}),t.resolver){const{errors:$e}=await $([Z]);if(pe(G),re){const nt=Xo(n.errors,r,Z),et=Xo($e,r,nt.name||Z);ve=et.error,Z=et.name,L=gt($e)}}else x([Z],!0),ve=(await Ko(ee,o.disabled,s,m,t.shouldUseNativeValidation))[Z],x([Z]),pe(G),re&&(ve?L=!1:f.isValid&&(L=await N(r,!0)));re&&(ee._f.deps&&v(ee._f.deps),C(Z,L,ve,me))}},q=(j,O)=>{if(ae(n.errors,O)&&j.focus)return j.focus(),1},v=async(j,O={})=>{let Z,re;const ee=zr(j);if(t.resolver){const Q=await K(Ye(j)?j:ee);Z=gt(Q),re=j?!ee.some(pe=>ae(Q,pe)):Z}else j?(re=(await Promise.all(ee.map(async Q=>{const pe=ae(r,Q);return await N(pe&&pe._f?{[Q]:pe}:pe)}))).every(Boolean),!(!re&&!n.isValid)&&S()):re=Z=await N(r);return d.state.next({...!Bt(j)||f.isValid&&Z!==n.isValid?{}:{name:j},...t.resolver||!j?{isValid:Z}:{},errors:n.errors}),O.shouldFocus&&!re&&Tr(r,q,j?ee:o.mount),re},fe=j=>{const O={...a.mount?s:i};return Ye(j)?O:Bt(j)?ae(O,j):j.map(Z=>ae(O,Z))},ue=(j,O)=>({invalid:!!ae((O||n).errors,j),isDirty:!!ae((O||n).dirtyFields,j),error:ae((O||n).errors,j),isValidating:!!ae(n.validatingFields,j),isTouched:!!ae((O||n).touchedFields,j)}),b=j=>{j&&zr(j).forEach(O=>rt(n.errors,O)),d.state.next({errors:j?n.errors:{}})},Y=(j,O,Z)=>{const re=(ae(r,j,{_f:{}})._f||{}).ref,ee=ae(n.errors,j)||{},{ref:Q,message:pe,type:ve,...L}=ee;De(n.errors,j,{...L,...O,ref:re}),d.state.next({name:j,errors:n.errors,isValid:!1}),Z&&Z.shouldFocus&&re&&re.focus&&re.focus()},oe=(j,O)=>Zt(j)?d.values.subscribe({next:Z=>j(B(void 0,O),Z)}):B(j,O,!0),ne=(j,O={})=>{for(const Z of j?zr(j):o.mount)o.mount.delete(Z),o.array.delete(Z),O.keepValue||(rt(r,Z),rt(s,Z)),!O.keepError&&rt(n.errors,Z),!O.keepDirty&&rt(n.dirtyFields,Z),!O.keepTouched&&rt(n.touchedFields,Z),!O.keepIsValidating&&rt(n.validatingFields,Z),!t.shouldUnregister&&!O.keepDefaultValue&&rt(i,Z);d.values.next({values:{...s}}),d.state.next({...n,...O.keepDirty?{isDirty:A()}:{}}),!O.keepIsValid&&S()},ie=({disabled:j,name:O,field:Z,fields:re})=>{(Ct(j)&&a.mount||j||o.disabled.has(O))&&(j?o.disabled.add(O):o.disabled.delete(O),k(O,Is(Z?Z._f:ae(re,O)._f),!1,!1,!0))},W=(j,O={})=>{let Z=ae(r,j);const re=Ct(O.disabled)||Ct(t.disabled);return De(r,j,{...Z||{},_f:{...Z&&Z._f?Z._f:{ref:{name:j}},name:j,mount:!0,...O}}),o.mount.add(j),Z?ie({field:Z,disabled:Ct(O.disabled)?O.disabled:t.disabled,name:j}):E(j,!0,O.value),{...re?{disabled:O.disabled||t.disabled}:{},...t.progressive?{required:!!O.required,min:hr(O.min),max:hr(O.max),minLength:hr(O.minLength),maxLength:hr(O.maxLength),pattern:hr(O.pattern)}:{},name:j,onChange:R,onBlur:R,ref:ee=>{if(ee){W(j,O),Z=ae(r,j);const Q=Ye(ee.value)&&ee.querySelectorAll&&ee.querySelectorAll("input,select,textarea")[0]||ee,pe=Zg(Q),ve=Z._f.refs||[];if(pe?ve.find(L=>L===Q):Q===Z._f.ref)return;De(r,j,{_f:{...Z._f,...pe?{refs:[...ve.filter(Es),Q,...Array.isArray(ae(i,j))?[{}]:[]],ref:{type:Q.type,name:j}}:{ref:Q}}}),E(j,!1,void 0,Q)}else Z=ae(r,j,{}),Z._f&&(Z._f.mount=!1),(t.shouldUnregister||O.shouldUnregister)&&!(pd(o.array,j)&&a.action)&&o.unMount.add(j)}}},F=()=>t.shouldFocusError&&Tr(r,q,o.mount),te=j=>{Ct(j)&&(d.state.next({disabled:j}),Tr(r,(O,Z)=>{const re=ae(r,Z);re&&(O.disabled=re._f.disabled||j,Array.isArray(re._f.refs)&&re._f.refs.forEach(ee=>{ee.disabled=re._f.disabled||j}))},0,!1))},V=(j,O)=>async Z=>{let re;Z&&(Z.preventDefault&&Z.preventDefault(),Z.persist&&Z.persist());let ee=mt(s);if(o.disabled.size)for(const Q of o.disabled)De(ee,Q,void 0);if(d.state.next({isSubmitting:!0}),t.resolver){const{errors:Q,values:pe}=await $();n.errors=Q,ee=pe}else await N(r);if(rt(n.errors,"root"),gt(n.errors)){d.state.next({errors:{}});try{await j(ee,Z)}catch(Q){re=Q}}else O&&await O({...n.errors},Z),F(),setTimeout(F);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:gt(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},de=(j,O={})=>{ae(r,j)&&(Ye(O.defaultValue)?J(j,mt(ae(i,j))):(J(j,O.defaultValue),De(i,j,mt(O.defaultValue))),O.keepTouched||rt(n.touchedFields,j),O.keepDirty||(rt(n.dirtyFields,j),n.isDirty=O.defaultValue?A(j,mt(ae(i,j))):A()),O.keepError||(rt(n.errors,j),f.isValid&&S()),d.state.next({...n}))},le=(j,O={})=>{const Z=j?mt(j):i,re=mt(Z),ee=gt(j),Q=ee?i:re;if(O.keepDefaultValues||(i=Z),!O.keepValues){if(O.keepDirtyValues){const pe=new Set([...o.mount,...Object.keys(pr(i,s))]);for(const ve of Array.from(pe))ae(n.dirtyFields,ve)?De(Q,ve,ae(s,ve)):J(ve,ae(Q,ve))}else{if(qa&&Ye(j))for(const pe of o.mount){const ve=ae(r,pe);if(ve&&ve._f){const L=Array.isArray(ve._f.refs)?ve._f.refs[0]:ve._f.ref;if(Ai(L)){const G=L.closest("form");if(G){G.reset();break}}}}r={}}s=t.shouldUnregister?O.keepDefaultValues?mt(i):{}:mt(Q),d.array.next({values:{...Q}}),d.values.next({values:{...Q}})}o={mount:O.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!f.isValid||!!O.keepIsValid||!!O.keepDirtyValues,a.watch=!!t.shouldUnregister,d.state.next({submitCount:O.keepSubmitCount?n.submitCount:0,isDirty:ee?!1:O.keepDirty?n.isDirty:!!(O.keepDefaultValues&&!sn(j,i)),isSubmitted:O.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ee?{}:O.keepDirtyValues?O.keepDefaultValues&&s?pr(i,s):n.dirtyFields:O.keepDefaultValues&&j?pr(i,j):O.keepDirty?n.dirtyFields:{},touchedFields:O.keepTouched?n.touchedFields:{},errors:O.keepErrors?n.errors:{},isSubmitSuccessful:O.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},ye=(j,O)=>le(Zt(j)?j(s):j,O);return{control:{register:W,unregister:ne,getFieldState:ue,handleSubmit:V,setError:Y,_executeSchema:$,_getWatch:B,_getDirty:A,_updateValid:S,_removeUnmounted:I,_updateFieldArray:_,_updateDisabledField:ie,_getFieldArray:D,_reset:le,_resetDefaultValues:()=>Zt(t.defaultValues)&&t.defaultValues().then(j=>{ye(j,t.resetOptions),d.state.next({isLoading:!1})}),_updateFormState:j=>{n={...n,...j}},_disableForm:te,_subjects:d,_proxyFormState:f,_setErrors:z,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(j){a=j},get _defaultValues(){return i},get _names(){return o},set _names(j){o=j},get _formState(){return n},set _formState(j){n=j},get _options(){return t},set _options(j){t={...t,...j}}},trigger:v,register:W,handleSubmit:V,watch:oe,setValue:J,getValues:fe,reset:ye,resetField:de,clearErrors:b,unregister:ne,setError:Y,setFocus:(j,O={})=>{const Z=ae(r,j),re=Z&&Z._f;if(re){const ee=re.refs?re.refs[0]:re.ref;ee.focus&&(ee.focus(),O.shouldSelect&&Zt(ee.select)&&ee.select())}},getFieldState:ue}}function Gg(e={}){const t=Ee.useRef(void 0),n=Ee.useRef(void 0),[r,i]=Ee.useState({isDirty:!1,isValidating:!1,isLoading:Zt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Zt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Wg(e),formState:r});const s=t.current.control;return s._options=e,Ga({subject:s._subjects.state,next:a=>{xd(a,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),Ee.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),Ee.useEffect(()=>{if(s._proxyFormState.isDirty){const a=s._getDirty();a!==r.isDirty&&s._subjects.state.next({isDirty:a})}},[s,r.isDirty]),Ee.useEffect(()=>{e.values&&!sn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(a=>({...a}))):s._resetDefaultValues()},[e.values,s]),Ee.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),Ee.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()}),Ee.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=gd(r,s),t.current}function Kg(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 Yg=Ag,Nd=y.createContext({}),Qo=({...e})=>u.jsx(Nd.Provider,{value:{name:e.name},children:u.jsx(Rg,{...e})}),us=()=>{const e=y.useContext(Nd),t=y.useContext(Cd),{getFieldState:n,formState:r}=ls(),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}},Cd=y.createContext({}),ha=y.forwardRef(({className:e,...t},n)=>{const r=y.useId();return u.jsx(Cd.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:H("space-y-2",e),...t})})});ha.displayName="FormItem";const ma=y.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=us();return u.jsx(Gn,{ref:n,className:H(r&&"text-destructive",e),htmlFor:i,...t})});ma.displayName="FormLabel";const ga=y.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=us();return u.jsx(or,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});ga.displayName="FormControl";const Ed=y.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=us();return u.jsx("p",{ref:n,id:r,className:H("text-muted-foreground text-[0.8rem]",e),...t})});Ed.displayName="FormDescription";const xa=y.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=us(),a=i?String(i==null?void 0:i.message):t;return a?u.jsx("p",{ref:r,id:s,className:H("text-destructive text-[0.8rem] font-medium",e),...n,children:a}):null});xa.displayName="FormMessage";function Xa(){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 Id=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Xg=(e=Id())=>yg()(bg(vg((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:Xa(),messages:[],createdAt:s,updatedAt:s};return t(o=>({threads:{...o.threads,[i]:a},activeThreadId:{...o.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const a=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),o=s.documentName,l={...i.activeThreadId};if(l[o]===r){const c=Object.values(a).filter(f=>f.documentName===o);c.length>0?(c.sort((f,d)=>d.updatedAt-f.updatedAt),l[o]=c[0].id):delete l[o]}t({threads:a,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(a=>({activeThreadId:{...a.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},a={...i.activeThreadId};for(const[o,l]of Object.entries(s))l.documentName===r&&delete s[o];return delete a[r],{threads:s,activeThreadId:a}})},renameThreadsForDocument:(r,i)=>{t(s=>{const a={...s.threads},o={...s.activeThreadId};for(const[l,c]of Object.entries(a))c.documentName===r&&(a[l]={...c,documentName:i});return r in o&&(o[i]=o[r],delete o[r]),{threads:a,activeThreadId:o}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:wg(()=>fg),partialize:t=>({threads:t.threads,activeThreadId:t.activeThreadId,scope:t.scope,model:t.model}),migrate:(t,n)=>{if(n===0&&t){const r=t.chatMessages;if(Array.isArray(r)&&r.length>0){const i=crypto.randomUUID(),s=Date.now();return{threads:{[i]:{id:i,documentName:"__migrated__",title:"Migrated Chat",messages:r,createdAt:s,updatedAt:s}},activeThreadId:{__migrated__:i}}}return{threads:{},activeThreadId:{}}}return t}}))),zd=y.createContext(void 0),Qg=({children:e})=>{const t=y.useRef(null);return t.current||(t.current=Xg(Id())),u.jsx(zd.Provider,{value:t.current,children:e})},Te=e=>{const t=y.useContext(zd);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return kg(t,e)};function ex(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function tx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=oi.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),i.push("name")),e==="create"&&(r.template=oi.Optional(oi.String({description:"Template selection"})));const s=oi.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:a=>{const o=[];if(!Dm(s,a))for(const c of Rm(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 nx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const rx=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"}}),mr="__empty__";function ix({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=y.useState(!1),[c,f]=y.useState(null),d=rx(a),{documents:p,openTabs:h,createDocument:m,renameDocument:w,deleteDocument:S,openDocument:x,closeDocument:_}=Ae(R=>R),{updateTheme:g,removeTheme:z}=da(R=>R),E=Te(R=>R.renameThreadsForDocument),k=Te(R=>R.deleteThreadsForDocument),C=y.useMemo(()=>a?s||[]:i||[],[a,i,s]),$=y.useMemo(()=>{const R={current:[],downstream:[]};return C.forEach(q=>{R[q.location]&&R[q.location].push(q)}),R},[C]),K=y.useMemo(()=>C.map(R=>({name:R.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[C]),N=y.useMemo(()=>tx(e,R=>ex(R,p,r),K),[e,p,r,K]),I=N.schema,A=y.useMemo(()=>{const R=new Map;return C.forEach(q=>R.set(q.path,q)),R},[C]),B=mr,D=Gg({resolver:Kg(N.validate),defaultValues:nx(e,void 0,r)}),[T,P]=y.useState(B);y.useEffect(()=>{if(T&&T!==mr&&e==="create"){const R=A.get(T);R&&fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(R.name)}/content`).then(q=>{if(!q.ok)throw new Error(`Failed to fetch content: ${q.statusText}`);return q.text()}).then(q=>{try{const v=JSON.parse(q);f(JSON.stringify(v,null,2))}catch(v){console.error("Invalid JSON content received:",v),f(null)}}).catch(q=>{console.error("Failed to fetch content:",q),f(null)})}},[T,e,A,a]),y.useEffect(()=>{t&&(D.reset(),f(null),P(B))},[D,t]);const J=D.handleSubmit(async({name:R,template:q})=>{l(!0);try{if(await new Promise(v=>setTimeout(v,200)),e==="create"){const v=T?A.get(T):C.find(W=>W.name===q);let fe,ue=R;if(a){const W=ue.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-");fe=c||JSON.stringify(yt==="docx"?{name:W,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:{family:"Calibri",size:28},body:{family:"Calibri",size:11}},page:{size:"A4"}}:{name:W,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}},null,2);const te=`.${yt}.theme.json`;ue.endsWith(te)||(ue=ue.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),ue+=te)}else{const W=v;fe=c||JSON.stringify(yt==="docx"?{name:"docx",props:{theme:(W==null?void 0:W.theme)||"default",metadata:{title:(W==null?void 0:W.title)||ue.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(W==null?void 0:W.title)||ue.replace(/\.(json|js)$/i,""),theme:(W==null?void 0:W.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 F=yt==="docx"?".docx.json":".pptx.json";!ue.endsWith(F)&&!ue.endsWith(".json")&&(ue+=F)}const b=ue.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),Y=b?b[0]:"",oe=ue.slice(0,ue.length-Y.length);let ne=ue,ie=1;for(;p.some(W=>W.name===ne);)ie++,ne=`${oe} (${ie})${Y}`;ue=ne,m(ue,fe),x(ue),a&&g(ue,fe)}else if(e==="update"){const v=r,fe=R,ue=h.includes(v);ue&&_(v),w(v,fe),E(v,fe),ue&&x(fe)}else if(e==="delete"){const v=r;_(v),S(v),k(v),a&&z(v)}n()}finally{l(!1)}});return u.jsx(Yg,{...D,children:u.jsxs("form",{onSubmit:J,children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:d[e].title}),u.jsx(cn,{children:d[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[I.properties&&"name"in I.properties&&u.jsx(Qo,{control:D.control,name:"name",render:({field:R})=>u.jsxs(ha,{children:[u.jsx(ma,{children:"Name"}),u.jsx(ga,{children:u.jsx(ei,{placeholder:"Enter a name or select a template below",autoComplete:"off",...R})}),u.jsx(xa,{})]})}),e==="create"&&u.jsx(Qo,{control:D.control,name:"template",render:({field:R})=>u.jsxs(ha,{children:[u.jsx(ma,{children:a?"Base Theme":"Base Document"}),u.jsxs(Rr,{onValueChange:q=>{if(q===mr)R.onChange(void 0),D.setValue("name",""),P(mr),f(null);else{const v=A.get(q);v&&(R.onChange(v.name),D.setValue("name",v.name),P(q))}},defaultValue:B,children:[u.jsx(ga,{children:u.jsx(er,{children:u.jsx(Mr,{placeholder:`Select a discovered ${a?"theme":"document"}`})})}),u.jsxs(tr,{className:"max-h-[300px]",children:[u.jsxs(En,{value:mr,children:["Empty ",a?"theme":"document"]}),Object.entries($).map(([q,v])=>v.length===0?null:u.jsxs(jg,{children:[u.jsx(cd,{children:q==="current"?"📁 Current Directory":"📦 Project"}),v.map(fe=>{let ue;return fe.title&&fe.title!==fe.name?ue=fe.title:fe.description&&(ue=fe.description.length>40?fe.description.substring(0,40)+"...":fe.description),u.jsx(En,{value:fe.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:fe.name}),ue&&u.jsx("span",{className:"text-muted-foreground text-xs",children:ue})]})},fe.path)})]},q))]})]}),u.jsxs(Ed,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(xa,{})]})})]}),u.jsx(Cn,{children:u.jsx(we,{type:"submit",variant:d[e].buttonVariant,disabled:o,children:o?u.jsxs(u.Fragment,{children:[u.jsx(Yt,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):d[e].button})})]})})}const Di=Ee.memo(ix),sx=vm,ax=wm,ox=y.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(jc,{ref:i,className:H("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(ss,{className:"ml-auto h-4 w-4"})]}));ox.displayName=jc.displayName;const lx=y.forwardRef(({className:e,...t},n)=>u.jsx(Nc,{ref:n,className:H("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-md border p-1 shadow-lg",e),...t}));lx.displayName=Nc.displayName;const Td=y.forwardRef(({className:e,...t},n)=>u.jsx(km,{children:u.jsx(kc,{ref:n,className:H("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-md border p-1 shadow-md",e),...t})}));Td.displayName=kc.displayName;const kr=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Sc,{ref:r,className:H("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}));kr.displayName=Sc.displayName;const ux=y.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Cc,{ref:i,className:H("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(Ec,{children:u.jsx(un,{className:"h-4 w-4"})})}),t]}));ux.displayName=Cc.displayName;const cx=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ic,{ref:r,className:H("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(Ec,{children:u.jsx(Kc,{className:"h-4 w-4 fill-current"})})}),t]}));cx.displayName=Ic.displayName;const dx=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(zc,{ref:r,className:H("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));dx.displayName=zc.displayName;const ya=y.forwardRef(({className:e,...t},n)=>u.jsx(_c,{ref:n,className:H("bg-border -mx-1 my-1 h-px",e),...t}));ya.displayName=_c.displayName;const ki=({className:e,...t})=>u.jsx("span",{className:H("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});ki.displayName="ContextMenuShortcut";const Ad=y.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(Tc,{ref:i,decorative:n,orientation:t,className:H("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ad.displayName=Tc.displayName;const Pd=dc,fx=fc,px=pc,Od=y.forwardRef(({className:e,...t},n)=>u.jsx(is,{className:H("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/80",e),...t,ref:n}));Od.displayName=is.displayName;const hx=Qr("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"}}),Qa=y.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(px,{children:[u.jsx(Od,{}),u.jsxs(ts,{ref:i,className:H(hx({side:e}),t),...r,children:[u.jsxs(Ja,{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(Nn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));Qa.displayName=ts.displayName;const mx=y.forwardRef(({className:e,...t},n)=>u.jsx(ns,{ref:n,className:H("text-foreground text-lg font-semibold",e),...t}));mx.displayName=ns.displayName;const gx=y.forwardRef(({className:e,...t},n)=>u.jsx(rs,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));gx.displayName=rs.displayName;function Ar({className:e,...t}){return u.jsx("div",{className:H("bg-primary/10 animate-pulse rounded-md",e),...t})}const zs=768,Ts=1200;function Dd(e){return typeof window<"u"?window.innerWidth<e:!1}function Rd(){const[e,t]=y.useState(()=>Dd(zs));return y.useEffect(()=>{const n=window.matchMedia(`(max-width: ${zs-1}px)`),r=()=>{t(window.innerWidth<zs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function xx(){const[e,t]=y.useState(()=>Dd(Ts));return y.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ts-1}px)`),r=()=>{t(window.innerWidth<Ts)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const yx="sidebar_state",bx=60*60*24*7,vx="16rem",wx="18rem",kx="3rem",Sx="b",Md=y.createContext(null);function cs(){const e=y.useContext(Md);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const $d=y.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=Rd(),[c,f]=y.useState(!1),[d,p]=y.useState(e),h=t??d,m=y.useCallback(_=>{const g=typeof _=="function"?_(h):_;n?n(g):p(g),document.cookie=`${yx}=${g}; path=/; max-age=${bx}`},[n,h]),w=y.useCallback(()=>l?f(_=>!_):m(_=>!_),[l,m,f]);y.useEffect(()=>{const _=z=>{var C;const E=z;if(!E)return!1;const k=(C=E.tagName)==null?void 0:C.toLowerCase();return k==="input"||k==="textarea"||k==="select"||E.isContentEditable?!0:!!(E.closest&&E.closest(".monaco-editor"))},g=z=>{const E=z.metaKey||z.ctrlKey,k=z.key.toLowerCase();if(E&&k===Sx){z.preventDefault(),w();return}E&&k==="s"&&!_(z.target)&&(z.preventDefault(),w())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[w]);const S=h?"expanded":"collapsed",x=y.useMemo(()=>({state:S,open:h,setOpen:m,isMobile:l,openMobile:c,setOpenMobile:f,toggleSidebar:w}),[S,h,m,l,c,f,w]);return u.jsx(Md.Provider,{value:x,children:u.jsx(Mm,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":vx,"--sidebar-width-icon":kx,...i},className:H("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});$d.displayName="SidebarProvider";const Fd=y.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},a)=>{const{isMobile:o,state:l,openMobile:c,setOpenMobile:f}=cs();return n==="none"?u.jsx("div",{className:H("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:a,...s,children:i}):o?u.jsx(Pd,{open:c,onOpenChange:f,...s,children:u.jsx(Qa,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":wx},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:H("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:H("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})})]})});Fd.displayName="Sidebar";const _x=y.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=cs();return u.jsxs(we,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:H("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(Um,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});_x.displayName="SidebarTrigger";const jx=y.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:H("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})});jx.displayName="SidebarRail";const Nx=y.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:H("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}));Nx.displayName="SidebarInset";const Cx=y.forwardRef(({className:e,...t},n)=>u.jsx(ei,{ref:n,"data-sidebar":"input",className:H("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));Cx.displayName="SidebarInput";const Ld=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:H("flex flex-col gap-2 p-2",e),...t}));Ld.displayName="SidebarHeader";const Zd=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:H("flex flex-col gap-2 p-2",e),...t}));Zd.displayName="SidebarFooter";const Bd=y.forwardRef(({className:e,...t},n)=>u.jsx(Ad,{ref:n,"data-sidebar":"separator",className:H("bg-sidebar-border mx-2 w-auto",e),...t}));Bd.displayName="SidebarSeparator";const Vd=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:H("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Vd.displayName="SidebarContent";const Si=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:H("relative flex w-full min-w-0 flex-col p-2",e),...t}));Si.displayName="SidebarGroup";const _i=y.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?or:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:H("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})});_i.displayName="SidebarGroupLabel";const Ex=y.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?or:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:H("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})});Ex.displayName="SidebarGroupAction";const Sr=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:H("w-full text-sm",e),...t}));Sr.displayName="SidebarGroupContent";const ba=y.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:H("flex w-full min-w-0 flex-col gap-1",e),...t}));ba.displayName="SidebarMenu";const Ud=y.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:H("group/menu-item relative",e),...t}));Ud.displayName="SidebarMenuItem";const Ix=Qr("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"}}),Jd=y.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...a},o)=>{const l=e?or:"button",{isMobile:c,state:f}=cs(),d=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:H(Ix({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:d}),u.jsx(Ke,{side:"right",align:"center",hidden:f!=="collapsed"||c,...i})]})):d});Jd.displayName="SidebarMenuButton";const zx=y.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?or:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:H("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})});zx.displayName="SidebarMenuAction";const Tx=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:H("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}));Tx.displayName="SidebarMenuBadge";const Ax=y.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=y.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:H("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Ar,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Ar,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Ax.displayName="SidebarMenuSkeleton";const Px=y.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:H("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}));Px.displayName="SidebarMenuSub";const Ox=y.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Ox.displayName="SidebarMenuSubItem";const Dx=y.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const a=e?or:"a";return u.jsx(a,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:H("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})});Dx.displayName="SidebarMenuSubButton";function ji(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 Rx=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Mx({document:e,indicator:t,compact:n=!1}){const r=y.useRef(null),[i,s]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState(!1),{openDocument:f,documentTypes:d,activeTab:p}=Ae(T=>T),{name:h,text:m,isGenerating:w}=vn(T=>T),x=(d[e.name]||"application/json+report")==="application/json+theme",_=p===e.name,[g,z]=y.useState(h),[E,k]=y.useState(m),C=100,$=0;y.useEffect(()=>{const T=setTimeout(()=>{h&&m?(z(h),k(m)):w||(z(""),k(""))},w?C:$);return()=>clearTimeout(T)},[h,m,w]);const K=g===e.name,N=T=>{var J;const P=new Set;try{const R=JSON.parse(T);(J=R.props)!=null&&J.theme&&P.add(R.props.theme),R.children&&Array.isArray(R.children)&&R.children.forEach(q=>{var v;q.name==="docx"&&((v=q.props)!=null&&v.theme)&&P.add(q.props.theme)})}catch{}return P},I=y.useMemo(()=>{if(!x||!E)return!1;try{const T=JSON.parse(e.text),P=fa(T);if(P)return N(E).has(P)}catch{}return!1},[x,E,e.text,e.name,g]),A=y.useCallback(()=>{o(!1)},[]),B=y.useCallback(()=>{c(!1)},[]),D=u.jsxs(Jd,{variant:"default",size:"default",ref:r,className:H("text-sidebar-foreground focus:bg-accent focus:text-accent-foreground w-full",n?"justify-center px-1":"justify-start gap-2",i&&"bg-accent text-accent-foreground",_&&(n?"bg-green-50 text-green-700 dark:bg-green-900/20 dark:text-green-300":"bg-green-50 border-l-2 border-green-500 text-green-700 dark:bg-green-900/20 dark:border-green-400 dark:text-green-300"),K&&!_&&(n?"bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-300":"bg-blue-50 border-l-2 border-blue-500 text-blue-700 dark:bg-blue-900/20 dark:border-blue-400 dark:text-blue-300"),I&&!_&&!K&&(n?"bg-purple-50 text-purple-700 dark:bg-purple-900/20 dark:text-purple-300":"bg-purple-50 border-l-2 border-purple-500 text-purple-700 dark:bg-purple-900/20 dark:border-purple-400 dark:text-purple-300")),title:e.name,onClick:()=>{f(e.name)},onKeyDown:T=>{var P;(T.ctrlKey||T.metaKey)&&T.key==="Enter"?(f(e.name),T.preventDefault()):T.key==="Enter"?(o(!0),T.preventDefault()):T.key==="Backspace"||T.key==="Delete"?(c(!0),T.preventDefault()):T.key==="Escape"&&((P=r.current)==null||P.blur(),T.preventDefault())},children:[_?u.jsx($o,{className:H("size-4","text-green-600 dark:text-green-400")}):K?u.jsx($o,{className:H("size-4","text-blue-600 dark:text-blue-400")}):x?u.jsx(la,{className:"size-4 text-purple-600 dark:text-purple-400"}):u.jsx(Yc,{className:"size-4 text-blue-600 dark:text-blue-400"}),!n&&u.jsx("span",{className:H("truncate flex-1",x&&!_&&!K&&!I&&"text-purple-700 dark:text-purple-300",(_||K||I)&&"font-medium"),children:e.name})]});return u.jsxs(Ud,{children:[u.jsxs(sx,{onOpenChange:s,children:[u.jsx(ax,{children:n?u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:D}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[e.name,x?u.jsx("div",{className:"opacity-70",children:"Theme"}):u.jsx("div",{className:"opacity-70",children:"Document"})]})})]}):D}),u.jsxs(Td,{children:[u.jsxs(kr,{onClick:()=>f(e.name),children:["Open",u.jsx(ki,{children:Rx?"⌘⏎":"⌃⏎"})]}),u.jsx(ya,{}),u.jsx(kr,{disabled:!e,onClick:()=>{e&&ji(e.name,new Blob([e.text],{type:e.type}))},children:"Download..."}),u.jsx(ya,{}),u.jsxs(kr,{onClick:()=>o(!0),children:["Rename...",u.jsx(ki,{children:"⏎"})]}),u.jsxs(kr,{onClick:()=>c(!0),children:["Delete",u.jsx(ki,{children:"⌫"})]})]})]}),u.jsx(It,{open:a,onOpenChange:o,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:T=>{var P;T.preventDefault(),(P=r.current)==null||P.focus()},children:u.jsx(Di,{mode:"update",shouldReset:!a,postSubmit:A,selectedName:e.name})})}),u.jsx(It,{open:l,onOpenChange:c,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:T=>{var P;T.preventDefault(),(P=r.current)==null||P.focus()},children:u.jsx(Di,{mode:"delete",shouldReset:!l,postSubmit:B,selectedName:e.name})})})]})}const el=Ee.memo(Mx);async function $x(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const $r=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ac,{ref:r,className:H("relative overflow-hidden",e),...n,children:[u.jsx(Sm,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Hd,{}),u.jsx(_m,{})]}));$r.displayName=Ac.displayName;const Hd=y.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pc,{ref:r,orientation:t,className:H("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(jm,{className:"bg-border relative flex-1 rounded-full"})}));Hd.displayName=Pc.displayName;function eo({className:e,...t}){return u.jsx(Nm,{"data-slot":"switch",className:H("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:u.jsx(Cm,{"data-slot":"switch-thumb",className:H("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const Fx=Qr("relative w-full rounded-lg 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-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Ri=y.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:H(Fx({variant:t}),e),...n}));Ri.displayName="Alert";const Lx=y.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:H("mb-1 font-medium leading-none tracking-tight",e),...t}));Lx.displayName="AlertTitle";const Mi=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:H("text-sm [&_p]:leading-relaxed",e),...t}));Mi.displayName="AlertDescription";const $i=y.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=y.useState(n<2),a=t!==null&&typeof t=="object",o=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-orange-500",children:"null"}):t===void 0?u.jsx("span",{className:"text-gray-500",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-blue-500",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-green-500",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-purple-500",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-cyan-500",children:['"',t,'"']}):u.jsxs("span",{className:"text-amber-600",children:['"',t,'"']}):null,f=a?Object.keys(t).length:0;return u.jsxs("div",{className:H("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded px-1 py-0.5",children:[a&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(on,{className:"h-3 w-3"}):u.jsx(ss,{className:"h-3 w-3"})}),!a&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-blue-600 dark:text-blue-400",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),a?u.jsxs("span",{className:"text-muted-foreground",children:[o?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[f," ",o?"items":"properties"]}),!i&&(o?"]":"}")]}):c(),!a&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),a&&i&&u.jsxs("div",{className:"ml-4",children:[o?t.map((d,p)=>u.jsx($i,{keyName:String(p),value:d,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([d,p],h,m)=>u.jsx($i,{keyName:d,value:p,depth:n+1,isLast:h===m.length-1},d)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[o?"]":"}",!r&&","]})})]})]})});$i.displayName="JsonNode";const Fi=y.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:H("space-y-4",r),children:[u.jsx(Ar,{className:"h-8 w-64"}),u.jsx(Ar,{className:"h-4 w-full"}),u.jsx(Ar,{className:"h-64 w-full"})]}):n?u.jsx(Ri,{variant:"destructive",className:r,children:u.jsx(Mi,{children:n})}):e?u.jsx($r,{className:H("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($i,{value:e})})}):u.jsx(Ri,{className:r,children:u.jsx(Mi,{children:"No schema available"})}));Fi.displayName="SchemaViewer";function Zx({plugins:e,initialFocusedPlugin:t}){var g,z;const n=Dt(E=>E.togglePlugin),r=Dt(E=>E.isPluginSelected),i=Dt(E=>E.selectedPlugins),s=Dt(E=>E.isApplyingPlugins),[a,o]=y.useState(null),[l,c]=y.useState(null),[f,d]=y.useState("properties");y.useEffect(()=>{if(t){const E=e.find(k=>k.name===t);if(E){o(E);return}}e.length>0&&!a&&o(e[0])},[t,e]);const p=y.useMemo(()=>{const E={current:[],downstream:[],upstream:[]};return e.forEach(k=>{E[k.location]&&E[k.location].push(k)}),E},[e]),h=async(E,k)=>{a&&(await $x(a.name,E.props),c(k),setTimeout(()=>c(null),2e3))},m=E=>{switch(E){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return E}},w=E=>{switch(E){case"current":return u.jsx(Gm,{className:"size-3"});case"downstream":return u.jsx(Wm,{className:"size-3"});case"upstream":return u.jsx(Yc,{className:"size-3"});default:return null}},S=((g=a==null?void 0:a.schema)==null?void 0:g.properties)&&Object.keys(a.schema.properties).length>0,x=(z=a==null?void 0:a.schema)==null?void 0:z.jsonSchema,_=(a==null?void 0:a.examples)&&a.examples.length>0;return u.jsxs(u.Fragment,{children:[u.jsxs(Ut,{children:[u.jsxs(Jt,{className:"flex items-center gap-2",children:[u.jsx(Xc,{className:"size-5 text-amber-600 dark:text-amber-400"}),"Plugins",u.jsxs(Vt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(cn,{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($r,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(p).map(([E,k])=>k.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[w(E),m(E)]}),u.jsx("div",{className:"space-y-0.5",children:k.map(C=>{const $=r(C.name),K=(a==null?void 0:a.name)===C.name;return u.jsxs("button",{onClick:()=>o(C),className:H("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",K?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:H("size-1.5 rounded-full flex-none transition-colors",$?"bg-amber-500 dark:bg-amber-400":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:C.name})]},C.name)})})]},E))})})}),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(Vt,{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(eo,{checked:r(a.name),onCheckedChange:()=>n(a),disabled:s,"aria-label":`Toggle ${a.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[w(a.location),u.jsx("span",{children:m(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:[S&&u.jsx("button",{onClick:()=>d("properties"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Fo,{className:"size-3.5"}),"Properties"]})}),x&&u.jsx("button",{onClick:()=>d("schema"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Jm,{className:"size-3.5"}),"Schema"]})}),_&&u.jsx("button",{onClick:()=>d("examples"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Hm,{className:"size-3.5"}),"Examples",u.jsx(Vt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:a.examples.length})]})})]}),u.jsx($r,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[f==="properties"&&S&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([E,k])=>u.jsx(Bx,{name:E,prop:k},E))}),f==="schema"&&x&&u.jsx(Fi,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),f==="examples"&&_&&a.examples.map((E,k)=>u.jsxs("div",{className:H(k>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:[E.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:E.title}),!E.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",k+1]})]}),u.jsx(we,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>h(E,k),children:l===k?u.jsxs(u.Fragment,{children:[u.jsx(qm,{className:"size-3 mr-1 text-green-600"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(as,{className:"size-3 mr-1"}),"Copy"]})})]}),E.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:E.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(E.props,null,2)})]},k)),!S&&!x&&!_&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(Fo,{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 Bx({name:e,prop:t}){var a;const[n,r]=y.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:H("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(on,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(ss,{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(Vt,{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-red-500 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",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 As=Em,Ps=Im,Os=zm,to=Tm,no=Am,Vx=y.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs($c,{ref:i,className:H("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(ss,{className:"ml-auto"})]}));Vx.displayName=$c.displayName;const Ux=y.forwardRef(({className:e,...t},n)=>u.jsx(Fc,{ref:n,className:H("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-md border p-1 shadow-lg",e),...t}));Ux.displayName=Fc.displayName;const ds=y.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Pm,{children:u.jsx(Oc,{ref:r,sideOffset:t,className:H("bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-md 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})}));ds.displayName=Oc.displayName;const Kt=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Dc,{ref:r,className:H("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}));Kt.displayName=Dc.displayName;const Jx=y.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Lc,{ref:i,className:H("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(Zc,{children:u.jsx(un,{className:"h-4 w-4"})})}),t]}));Jx.displayName=Lc.displayName;const Hx=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Bc,{ref:r,className:H("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(Zc,{children:u.jsx(Kc,{className:"h-2 w-2 fill-current"})})}),t]}));Hx.displayName=Bc.displayName;const qd=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Mc,{ref:r,className:H("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));qd.displayName=Mc.displayName;const Fr=y.forwardRef(({className:e,...t},n)=>u.jsx(Rc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));Fr.displayName=Rc.displayName;function qx(){const{theme:e,setTheme:t}=qc(),n=e==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e,r=y.useCallback(()=>{t(n==="dark"?"light":"dark")},[n,t]);return u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(we,{variant:"ghost",size:"icon",onClick:r,children:[u.jsx(Km,{className:"hidden dark:block"}),u.jsx(Ym,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:"Toggle theme"})})]})}const Wd=Om,ro=y.forwardRef(({className:e,...t},n)=>u.jsx(Vc,{ref:n,className:H("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-lg p-1",e),...t}));ro.displayName=Vc.displayName;const Lr=y.forwardRef(({className:e,...t},n)=>u.jsx(Uc,{ref:n,className:H("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-md 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 data-[state=active]:shadow",e),...t}));Lr.displayName=Uc.displayName;const Zr=y.forwardRef(({className:e,...t},n)=>u.jsx(Jc,{ref:n,className:H("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));Zr.displayName=Jc.displayName;async function Wx(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 Gx(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 Kx(e){const t=Gx(e);return Wx(t)}const Gd=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=y.useState(n),[s,a]=y.useState(null),[o,l]=y.useState(null),[c,f]=y.useState(!1),[d,p]=y.useState(!1),[h,m]=y.useState(null),[w,S]=y.useState(null),[x,_]=y.useState(!1),{toast:g}=Xr(),z=Dt(B=>B.selectedPlugins),E=Array.from(z);y.useEffect(()=>{n&&i(n)},[n]);const k=y.useCallback(async()=>{f(!0),m(null);try{const B=await Ns.fetchDocumentSchema(E);a(B)}catch(B){const D=B instanceof Error?B.message:"Failed to load document schema";m(D),g({variant:"destructive",title:"Error loading schema",description:D})}finally{f(!1)}},[E,g]),C=y.useCallback(async()=>{if(!o){p(!0),S(null);try{const B=await Ns.fetchThemeSchema();l(B)}catch(B){const D=B instanceof Error?B.message:"Failed to load theme schema";S(D),g({variant:"destructive",title:"Error loading schema",description:D})}finally{p(!1)}}},[o,g]),[$,K]=y.useState([]);y.useEffect(()=>{e||(a(null),m(null))},[e]),y.useEffect(()=>{if(!e)return;const B=E.length!==$.length||E.some((D,T)=>D!==$[T]);r==="document"?(!s||B)&&(B&&(Ns.clearPluginSchemaCache(),K([...E])),c||k()):r==="theme"&&!o&&!d&&C()},[r,e,s,o,c,d,E,$,k,C]);const N=E.length,I=r==="document"?s:o,A=async()=>{if(I)try{await Kx(I)&&(_(!0),g({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>_(!1),2e3))}catch(B){console.error("Copy failed:",B)}};return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:"Schema Viewer"})}),u.jsxs(Wd,{value:r,onValueChange:B=>i(B),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Lr,{value:"document",className:"flex items-center gap-1",children:["Document",N>0&&u.jsxs(Vt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",N]})]}),u.jsx(Lr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(we,{variant:"ghost",size:"icon",onClick:A,disabled:x||!I,"aria-label":"Copy schema",children:x?u.jsx(un,{className:"h-4 w-4"}):u.jsx(as,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(Zr,{value:"document",className:"h-full",children:u.jsx(Fi,{schema:s,loading:c,error:h||void 0})}),u.jsx(Zr,{value:"theme",className:"h-full",children:u.jsx(Fi,{schema:o,loading:d,error:w||void 0})})]})]})]})})};function Yx({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o}=Ae(ad(F=>({documents:F.documents,documentTypes:F.documentTypes,createDocument:F.createDocument,openDocument:F.openDocument}))),l=da(F=>F.updateTheme),c=da(F=>F.removeTheme),f=y.useContext(sd),[d,p]=y.useState(!1),[h,m]=y.useState(!1),[w,S]=y.useState(!1),[x,_]=y.useState(null),g=Dt(F=>F.togglePlugin),z=Dt(F=>F.isPluginSelected),E=Dt(F=>F.selectedPlugins),k=Dt(F=>F.isApplyingPlugins),[C,$]=y.useState(!1),[K,N]=y.useState(!1),[I,A]=y.useState(new Set(["current-docs","current-themes"])),{toast:B}=Xr(),D=i.filter(F=>s[F.name]!=="application/json+theme"),T=i.filter(F=>s[F.name]==="application/json+theme"),P=y.useMemo(()=>{if(!e)return{current:[],downstream:[]};const F={current:[],downstream:[]};return e.documents.forEach(te=>{F[te.location]&&F[te.location].push(te)}),F},[e]),J=y.useMemo(()=>{if(!e)return{current:[],downstream:[]};const F={current:[],downstream:[]};return e.themes.forEach(te=>{F[te.location]&&F[te.location].push(te)}),F},[e]),R=y.useMemo(()=>{const F=new Set;return D.forEach(te=>{try{const V=JSON.parse(te.text);V.children&&Array.isArray(V.children)&&V.children.forEach(de=>{var le;de.name==="docx"&&((le=de.props)!=null&&le.theme)&&F.add(de.props.theme)})}catch{}}),F},[D]),q=y.useCallback(()=>{p(!1)},[]),v=y.useCallback(()=>{m(!1)},[]),fe=y.useRef(new Map);y.useEffect(()=>{const F=fe.current,te=new Map;T.forEach(V=>{te.set(V.name,V.text),F.get(V.name)!==V.text&&l(V.name,V.text)}),F.forEach((V,de)=>{te.has(de)||c(de)}),fe.current=te},[T,l,c]);const ue=y.useRef(!1);y.useEffect(()=>{if(ue.current||!f)return;ue.current=!0;const F=new Set(T.map(V=>V.name));Object.keys(f.getState().customThemes).forEach(V=>{F.has(V)||c(V)})},[T,c,f]);const b=F=>{A(te=>{const V=new Set(te);return V.has(F)?V.delete(F):V.add(F),V})},Y=Ae(F=>F.activeTab),oe=Y&&s[Y]==="application/json+theme"?"theme":"document",{resolvedTheme:ne}=qc(),ie=ne==="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",W=y.useCallback(async(F,te)=>{if(i.some(V=>V.name===F)){o(F);return}try{const V=await fetch(`/api/discovery/${te?"themes":"documents"}/${encodeURIComponent(F)}/content`);if(!V.ok)throw new Error(V.statusText);const de=await V.text(),le=JSON.parse(de);a(F,JSON.stringify(le,null,2)),o(F),B({title:`Added ${te?"theme":"document"}: ${F}`})}catch{B({title:"Failed to load",description:`Could not load ${F}`,variant:"destructive"})}},[i,a,o,B]);return u.jsxs(u.Fragment,{children:[u.jsxs(Fd,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[u.jsx(Ld,{children:u.jsx("div",{className:H("flex items-center transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100",n?"justify-center":"justify-between"),children:n?u.jsx(we,{variant:"ghost",size:"icon","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Qc,{className:"h-4 w-4"})}):u.jsxs(u.Fragment,{children:[u.jsx("a",{href:"/",className:"flex items-center pl-2",children:u.jsx("img",{src:ie,alt:"WiseAir logo",className:"h-5 w-auto max-w-[120px] shrink-0"})}),u.jsx("div",{className:"flex items-center gap-1",children:u.jsx(we,{variant:"ghost",size:"icon","aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(Xm,{className:"h-4 w-4"})})})]})})}),u.jsxs(Vd,{className:H("h-full transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100"),children:[u.jsxs(Si,{children:[u.jsxs(_i,{className:H("flex items-center",n?"justify-center":"justify-between"),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[!n&&u.jsx(Lo,{className:"size-3"}),!n&&u.jsx("span",{children:"Active Documents"})]}),u.jsxs("div",{className:"flex items-center gap-0.5",children:[yt==="docx"&&!n&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{className:"h-6 w-6 p-0 flex-shrink-0",variant:"ghost",size:"icon","aria-label":"Compare documents",disabled:D.length<2,onClick:()=>N(!0),children:u.jsx(Gc,{className:"size-4"})})}),u.jsx(Ke,{side:"bottom",children:u.jsx("span",{className:"text-xs",children:D.length<2?"Compare needs two documents":"Compare documents (redline)"})})]}),u.jsxs(It,{open:d,onOpenChange:p,children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Bo,{asChild:!0,children:u.jsx(we,{className:H("p-0 flex-shrink-0",n?"mx-auto h-8 w-8 rounded border border-dashed border-sidebar-foreground/20 hover:border-sidebar-foreground/40":"h-6 w-6"),variant:"ghost",size:"icon",children:u.jsx(zi,{className:n?"size-3.5":"size-4"})})})}),u.jsx(Ke,{side:n?"right":"bottom",children:u.jsx("span",{className:"text-xs",children:"New Document"})})]}),u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Di,{mode:"create",shouldReset:!d,postSubmit:q,discoveredDocuments:(e==null?void 0:e.documents)||[]})})]})]})]}),n?u.jsx(Sr,{children:u.jsx("div",{className:"flex flex-col items-center gap-0.5 px-0.5",children:D.map(F=>{const te=Y===F.name;return u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("button",{onClick:()=>o(F.name),"aria-label":F.name,className:H("relative w-8 h-8 rounded flex items-center justify-center text-[11px] font-bold transition-colors cursor-pointer",te?"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[te&&u.jsx("span",{className:"absolute left-0 top-1 bottom-1 w-0.5 rounded-full bg-green-500 dark:bg-green-400"}),F.name.replace(/\.[^.]+$/,"").slice(0,2).toUpperCase()]})}),u.jsx(Ke,{side:"right",children:u.jsx("span",{className:"text-xs",children:F.name})})]},F.name)})})}):u.jsx(Sr,{children:u.jsx(ba,{children:D.length>0?D.map((F,te)=>u.jsx(el,{document:F,compact:n},`doc-${te}`)):u.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No active documents. Click + to create one."})})})]}),u.jsx(Bd,{}),u.jsxs(Si,{children:[u.jsxs(_i,{className:H("flex items-center",n?"justify-center":"justify-between"),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[!n&&u.jsx(la,{className:"size-3 text-purple-600 dark:text-purple-400"}),!n&&u.jsx("span",{children:"Active Themes"})]}),u.jsxs(It,{open:h,onOpenChange:m,children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Bo,{asChild:!0,children:u.jsx(we,{className:H("p-0 flex-shrink-0",n?"mx-auto h-8 w-8 rounded border border-dashed border-sidebar-foreground/20 hover:border-sidebar-foreground/40":"h-6 w-6"),variant:"ghost",size:"icon",children:u.jsx(zi,{className:n?"size-3.5":"size-4"})})})}),u.jsx(Ke,{side:n?"right":"bottom",children:u.jsx("span",{className:"text-xs",children:"New Theme"})})]}),u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Di,{mode:"create",shouldReset:!h,postSubmit:v,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})]})]}),n?u.jsx(Sr,{children:u.jsx("div",{className:"flex flex-col items-center gap-0.5 px-0.5",children:T.map(F=>{const te=Y===F.name;let V=null;try{const le=JSON.parse(F.text);V=fa(le)}catch{}const de=V?R.has(V):!1;return u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("button",{onClick:()=>o(F.name),"aria-label":F.name,className:H("relative w-8 h-8 rounded flex items-center justify-center text-[11px] font-bold transition-colors cursor-pointer",te?"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300":de?"bg-purple-50 text-purple-600 dark:bg-purple-900/20 dark:text-purple-400":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[te&&u.jsx("span",{className:"absolute left-0 top-1 bottom-1 w-0.5 rounded-full bg-purple-500 dark:bg-purple-400"}),(V||F.name).charAt(0).toUpperCase()]})}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[F.name,de&&u.jsx("div",{className:"opacity-70",children:"In use"})]})})]},F.name)})})}):u.jsx(Sr,{children:u.jsx(ba,{children:T.length>0?T.map((F,te)=>{let V=null;try{const le=JSON.parse(F.text);V=fa(le)}catch{}const de=V?R.has(V):!1;return u.jsx(el,{document:F,compact:n,indicator:de?"in-use":void 0},`theme-${te}`)}):u.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No active themes."," ",e&&e.themes.length>0?"Click + to add one.":"No themes discovered in project."]})})})]}),!n&&e&&(e.documents.length>0||e.themes.length>0)&&u.jsxs(Si,{className:"mt-2 border-t pt-4",children:[u.jsxs(_i,{className:"flex items-center mb-2 gap-2",children:[u.jsx(Qm,{className:"size-3"}),u.jsx("span",{children:"Discovered Resources"})]}),u.jsxs(u.Fragment,{children:[Object.entries(P).map(([F,te])=>{if(te.length===0)return null;const V=`${F}-docs`,de=I.has(V);return u.jsxs(As,{open:de,children:[u.jsxs(Ps,{className:"flex items-center gap-1 px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer w-full",onClick:()=>b(V),children:[u.jsx(on,{className:H("size-3 transition-transform",!de&&"-rotate-90")}),u.jsx(Lo,{className:"size-3"}),F==="current"?"Current Directory":"Project"," ","Documents (",te.length,")"]}),u.jsx(Os,{children:u.jsx("div",{className:"pl-4 space-y-0.5",children:te.map((le,ye)=>{const Oe=i.some(qe=>qe.name===le.name);return u.jsxs("button",{onClick:()=>W(le.name,!1),className:H("w-full text-left py-1 px-2 rounded text-sm transition-colors","border-l-2 border-blue-400/60 dark:border-blue-500/40","hover:bg-accent hover:text-accent-foreground",Oe&&"opacity-50"),children:[u.jsx("div",{className:"font-medium truncate",children:le.name}),le.title&&u.jsx("div",{className:"text-xs text-muted-foreground truncate",children:le.title})]},ye)})})})]},V)}),Object.entries(J).map(([F,te])=>{if(te.length===0)return null;const V=`${F}-themes`,de=I.has(V);return u.jsxs(As,{open:de,children:[u.jsxs(Ps,{className:"flex items-center gap-1 px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer w-full",onClick:()=>b(V),children:[u.jsx(on,{className:H("size-3 transition-transform",!de&&"-rotate-90")}),u.jsx(la,{className:"size-3"}),F==="current"?"Current Directory":"Project"," ","Themes (",te.length,")"]}),u.jsx(Os,{children:u.jsx("div",{className:"pl-4 space-y-0.5",children:te.map((le,ye)=>{const Oe=i.some(qe=>qe.name===le.name);return u.jsxs("button",{onClick:()=>W(le.name,!0),className:H("w-full text-left py-1 px-2 rounded text-sm transition-colors","border-l-2 border-purple-400/60 dark:border-purple-500/40","hover:bg-accent hover:text-accent-foreground",Oe&&"opacity-50"),children:[u.jsx("div",{className:"font-medium truncate",children:le.name}),le.description&&u.jsx("div",{className:"text-xs text-muted-foreground truncate",children:le.description})]},ye)})})})]},V)}),e&&e.plugins.length>0&&u.jsxs(As,{open:I.has("plugins"),children:[u.jsxs(Ps,{className:"flex items-center gap-1 px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer w-full",onClick:()=>b("plugins"),children:[u.jsx(on,{className:H("size-3 transition-transform",!I.has("plugins")&&"-rotate-90")}),u.jsx(Xc,{className:"size-3 text-amber-600 dark:text-amber-400"}),"Plugins (",E.size,"/",e.plugins.length,")"]}),u.jsx(Os,{children:u.jsx("div",{className:"pl-4 space-y-0.5",children:e.plugins.map((F,te)=>{const V=z(F.name);return u.jsxs("div",{className:H("py-1 px-2 text-sm border-l-2 flex items-center gap-2 group transition-colors",V?"border-amber-500 dark:border-amber-400 text-foreground":"border-amber-400/30 dark:border-amber-500/20 text-muted-foreground"),children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"font-medium truncate",children:F.name}),F.description&&u.jsx("div",{className:"text-xs opacity-70 truncate",children:F.description})]}),u.jsx("button",{className:"flex-none size-5 flex items-center justify-center rounded-sm opacity-0 group-hover:opacity-100 hover:bg-accent transition-all cursor-pointer",title:`View details for ${F.name}`,onClick:de=>{de.stopPropagation(),_(F.name),S(!0)},children:u.jsx(ed,{className:"size-3 text-muted-foreground"})}),u.jsx(eo,{checked:V,onCheckedChange:()=>g(F),disabled:k,className:"flex-none scale-[0.8]","aria-label":`Toggle ${F.name} plugin`})]},te)})})})]})]})]})]}),u.jsx(Zd,{children:u.jsx("div",{className:H("flex w-full items-center transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100",n?"justify-center":"justify-end pr-2"),children:u.jsx(qx,{})})}),u.jsx(It,{open:w,onOpenChange:F=>{S(F),F||_(null)},children:u.jsx(St,{className:"sm:max-w-5xl max-h-[85vh] overflow-hidden",children:u.jsx(Zx,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:x})})})]}),u.jsx(Gd,{open:C,onOpenChange:$,defaultTab:oe==="theme"?"theme":"document"}),u.jsx(Ig,{open:K,onOpenChange:N})]})}const tl=y.memo(Yx),Xx=y.lazy(()=>Wc(()=>import("./editor-CB9BVJGn.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function nl(){return u.jsx(y.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(Yt,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(Xx,{})})}const Qx=y.lazy(()=>Wc(()=>import("./preview-B4bcm38l.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function rl(){return u.jsx(y.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(Yt,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(Qx,{})})}const{createElement:nr,createContext:ey,forwardRef:Kd,useCallback:pt,useContext:Yd,useEffect:_n,useImperativeHandle:Xd,useLayoutEffect:ty,useMemo:ny,useRef:xt,useState:Kn}=cc,il=cc[`useId${Math.random()}`.slice(0,5)],ry=ty,fs=ey(null);fs.displayName="PanelGroupContext";const jn=ry,iy=typeof il=="function"?il:()=>null;let sy=0;function io(e=null){const t=iy(),n=xt(e||t||null);return n.current===null&&(n.current=""+sy++),e??n.current}function Qd({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:f,onResize:d,order:p,style:h,tagName:m="div",...w}){const S=Yd(fs);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:x,expandPanel:_,getPanelSize:g,getPanelStyle:z,groupId:E,isPanelCollapsed:k,reevaluatePanelConstraints:C,registerPanel:$,resizePanel:K,unregisterPanel:N}=S,I=io(a),A=xt({callbacks:{onCollapse:c,onExpand:f,onResize:d},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:I,idIsFromProps:a!==void 0,order:p});xt({didLogMissingDefaultSizeWarning:!1}),jn(()=>{const{callbacks:D,constraints:T}=A.current,P={...T};A.current.id=I,A.current.idIsFromProps=a!==void 0,A.current.order=p,D.onCollapse=c,D.onExpand=f,D.onResize=d,T.collapsedSize=n,T.collapsible=r,T.defaultSize=i,T.maxSize=o,T.minSize=l,(P.collapsedSize!==T.collapsedSize||P.collapsible!==T.collapsible||P.maxSize!==T.maxSize||P.minSize!==T.minSize)&&C(A.current,P)}),jn(()=>{const D=A.current;return $(D),()=>{N(D)}},[p,I,$,N]),Xd(s,()=>({collapse:()=>{x(A.current)},expand:D=>{_(A.current,D)},getId(){return I},getSize(){return g(A.current)},isCollapsed(){return k(A.current)},isExpanded(){return!k(A.current)},resize:D=>{K(A.current,D)}}),[x,_,g,k,I,K]);const B=z(A.current,i);return nr(m,{...w,children:e,className:t,id:a,style:{...B,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":E,"data-panel-id":I,"data-panel-size":parseFloat(""+B.flexGrow).toFixed(1)})}const ef=Kd((e,t)=>nr(Qd,{...e,forwardedRef:t}));Qd.displayName="Panel";ef.displayName="forwardRef(Panel)";let va=null,Sn=null;function ay(e,t){if(t){const n=(t&af)!==0,r=(t&of)!==0,i=(t&lf)!==0,s=(t&uf)!==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 oy(){Sn!==null&&(document.head.removeChild(Sn),va=null,Sn=null)}function Ds(e,t){const n=ay(e,t);va!==n&&(va=n,Sn===null&&(Sn=document.createElement("style"),document.head.appendChild(Sn)),Sn.innerHTML=`*{cursor: ${n}!important;}`)}function tf(e){return e.type==="keydown"}function nf(e){return e.type.startsWith("pointer")}function rf(e){return e.type.startsWith("mouse")}function ps(e){if(nf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(rf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function ly(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function uy(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 cy(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:ol(e),b:ol(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:al(sl(n.a)),b:al(sl(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 dy=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function fy(e){var t;const n=getComputedStyle((t=sf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function py(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||fy(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"||dy.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function sl(e){let t=e.length;for(;t--;){const n=e[t];if(_e(n,"Missing node"),py(n))return n}return null}function al(e){return e&&Number(getComputedStyle(e).zIndex)||0}function ol(e){const t=[];for(;e;)t.push(e),e=sf(e);return t}function sf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const af=1,of=2,lf=4,uf=8,hy=ly()==="coarse";let Rt=[],Yn=!1,an=new Map,hs=new Map;const Br=new Set;function my(e,t,n,r,i){var s;const{ownerDocument:a}=t,o={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=an.get(a))!==null&&s!==void 0?s:0;return an.set(a,l+1),Br.add(o),Li(),function(){var f;hs.delete(e),Br.delete(o);const d=(f=an.get(a))!==null&&f!==void 0?f:1;if(an.set(a,d-1),Li(),d===1&&an.delete(a),Rt.includes(o)){const p=Rt.indexOf(o);p>=0&&Rt.splice(p,1),ao(),i("up",!0,null)}}}function ll(e){const{target:t}=e,{x:n,y:r}=ps(e);Yn=!0,so({target:t,x:n,y:r}),Li(),Rt.length>0&&(Zi("down",e),e.preventDefault(),e.stopPropagation())}function gr(e){const{x:t,y:n}=ps(e);if(Yn&&e.buttons===0&&(Yn=!1,Zi("up",e)),!Yn){const{target:r}=e;so({target:r,x:t,y:n})}Zi("move",e),ao(),Rt.length>0&&e.preventDefault()}function Dn(e){const{target:t}=e,{x:n,y:r}=ps(e);hs.clear(),Yn=!1,Rt.length>0&&e.preventDefault(),Zi("up",e),so({target:t,x:n,y:r}),ao(),Li()}function so({target:e,x:t,y:n}){Rt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Br.forEach(i=>{const{element:s,hitAreaMargins:a}=i,o=s.getBoundingClientRect(),{bottom:l,left:c,right:f,top:d}=o,p=hy?a.coarse:a.fine;if(t>=c-p&&t<=f+p&&n>=d-p&&n<=l+p){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&cy(r,s)>0){let m=r,w=!1;for(;m&&!m.contains(s);){if(uy(m.getBoundingClientRect(),o)){w=!0;break}m=m.parentElement}if(w)return}Rt.push(i)}})}function Rs(e,t){hs.set(e,t)}function ao(){let e=!1,t=!1;Rt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;hs.forEach(r=>{n|=r}),e&&t?Ds("intersection",n):e?Ds("horizontal",n):t?Ds("vertical",n):oy()}function Li(){an.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Dn),n.removeEventListener("pointerdown",ll),n.removeEventListener("pointerleave",gr),n.removeEventListener("pointermove",gr)}),window.removeEventListener("pointerup",Dn),window.removeEventListener("pointercancel",Dn),Br.size>0&&(Yn?(Rt.length>0&&an.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Dn),n.addEventListener("pointerleave",gr),n.addEventListener("pointermove",gr))}),window.addEventListener("pointerup",Dn),window.addEventListener("pointercancel",Dn)):an.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",ll,{capture:!0}),n.addEventListener("pointermove",gr))}))}function Zi(e,t){Br.forEach(n=>{const{setResizeHandlerState:r}=n,i=Rt.includes(n);r(e,i,t)})}function gy(){const[e,t]=Kn(0);return pt(()=>t(n=>n+1),[])}function _e(e,t){if(!e)throw console.error(t),Error(t)}const oo=10;function In(e,t,n=oo){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function Xt(e,t,n=oo){return In(e,t,n)===0}function kt(e,t,n){return In(e,t,n)===0}function xy(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(!kt(i,s,n))return!1}return!0}function Hn({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(In(n,o)<0)if(s){const l=(i+o)/2;In(n,l)<0?n=i:n=o}else n=o;return n=Math.min(a,n),n=parseFloat(n.toFixed(oo)),n}function _r({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(kt(e,0))return t;const a=[...t],[o,l]=r;_e(o!=null,"Invalid first pivot index"),_e(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?l:o,p=n[d];_e(p,`Panel constraints not found for index ${d}`);const{collapsedSize:h=0,collapsible:m,minSize:w=0}=p;if(m){const S=t[d];if(_e(S!=null,`Previous layout not found for panel index ${d}`),kt(S,h)){const x=w-S;In(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}{const d=e<0?o:l,p=n[d];_e(p,`No panel constraints found for index ${d}`);const{collapsedSize:h=0,collapsible:m,minSize:w=0}=p;if(m){const S=t[d];if(_e(S!=null,`Previous layout not found for panel index ${d}`),kt(S,w)){const x=S-h;In(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}}{const d=e<0?1:-1;let p=e<0?l:o,h=0;for(;;){const w=t[p];_e(w!=null,`Previous layout not found for panel index ${p}`);const x=Hn({panelConstraints:n,panelIndex:p,size:100})-w;if(h+=x,p+=d,p<0||p>=n.length)break}const m=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-m:m}{let p=e<0?o:l;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),m=t[p];_e(m!=null,`Previous layout not found for panel index ${p}`);const w=m-h,S=Hn({panelConstraints:n,panelIndex:p,size:w});if(!kt(m,S)&&(c+=m-S,a[p]=S,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(xy(i,a))return i;{const d=e<0?l:o,p=t[d];_e(p!=null,`Previous layout not found for panel index ${d}`);const h=p+c,m=Hn({panelConstraints:n,panelIndex:d,size:h});if(a[d]=m,!kt(m,h)){let w=h-m,x=e<0?l:o;for(;x>=0&&x<n.length;){const _=a[x];_e(_!=null,`Previous layout not found for panel index ${x}`);const g=_+w,z=Hn({panelConstraints:n,panelIndex:x,size:g});if(kt(_,z)||(w-=z-_,a[x]=z),kt(w,0))break;e>0?x--:x++}}}const f=a.reduce((d,p)=>p+d,0);return kt(f,100)?a:i}function yy({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,a=0;const o=n[0];_e(o!=null,"No pivot index found"),t.forEach((d,p)=>{const{constraints:h}=d,{maxSize:m=100,minSize:w=0}=h;p===o?(r=w,i=m):(s+=w,a+=m)});const l=Math.min(i,100-s),c=Math.max(r,100-a),f=e[o];return{valueMax:l,valueMin:c,valueNow:f}}function Vr(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function cf(e,t,n=document){const i=Vr(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function df(e,t,n){const r=cf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function ff(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 ms(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function by(e,t,n,r=document){var i,s,a,o;const l=ms(t,r),c=Vr(e,r),f=l?c.indexOf(l):-1,d=(i=(s=n[f])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,p=(a=(o=n[f+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[d,p]}function vy({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:a}){xt({didWarnAboutMissingResizeHandle:!1}),jn(()=>{if(!s)return;const o=Vr(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:f,valueNow:d}=yy({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=o[l];if(p!=null){const h=i[l];_e(h,`No panel data found for index "${l}"`),p.setAttribute("aria-controls",h.id),p.setAttribute("aria-valuemax",""+Math.round(c)),p.setAttribute("aria-valuemin",""+Math.round(f)),p.setAttribute("aria-valuenow",d!=null?""+Math.round(d):"")}}return()=>{o.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),_n(()=>{if(!s)return;const o=t.current;_e(o,"Eager values not found");const{panelDataArray:l}=o,c=ff(n,s);_e(c!=null,`No group found for id "${n}"`);const f=Vr(n,s);_e(f,`No resize handles found for group id "${n}"`);const d=f.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");_e(h,"Resize handle element has no handle id attribute");const[m,w]=by(n,h,l,s);if(m==null||w==null)return()=>{};const S=x=>{if(!x.defaultPrevented)switch(x.key){case"Enter":{x.preventDefault();const _=l.findIndex(g=>g.id===m);if(_>=0){const g=l[_];_e(g,`No panel data found for index ${_}`);const z=r[_],{collapsedSize:E=0,collapsible:k,minSize:C=0}=g.constraints;if(z!=null&&k){const $=_r({delta:kt(z,E)?C-E:E-z,initialLayout:r,panelConstraints:l.map(K=>K.constraints),pivotIndices:df(n,h,s),prevLayout:r,trigger:"keyboard"});r!==$&&a($)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{d.forEach(p=>p())}},[s,e,t,n,r,i,a])}function ul(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 pf(e,t){const n=e==="horizontal",{x:r,y:i}=ps(t);return n?r:i}function wy(e,t,n,r,i){const s=n==="horizontal",a=ms(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=pf(n,e),f=ff(o,i);_e(f,`No group element found for id "${o}"`);const d=f.getBoundingClientRect(),p=s?d.width:d.height;return(c-l)/p*100}function ky(e,t,n,r,i,s){if(tf(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:wy(e,t,n,r,s)}function Sy({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 Rn(e,t,n){t.forEach((r,i)=>{const s=e[i];_e(s,`Panel data not found for index ${i}`);const{callbacks:a,constraints:o,id:l}=s,{collapsedSize:c=0,collapsible:f}=o,d=n[l];if(d==null||r!==d){n[l]=r;const{onCollapse:p,onExpand:h,onResize:m}=a;m&&m(r,d),f&&(p||h)&&(h&&(d==null||Xt(d,c))&&!Xt(r,c)&&h(),p&&(d==null||!Xt(d,c))&&Xt(r,c)&&p())}})}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 _y({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 jy(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function cl(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 hf(e){return`react-resizable-panels:${e}`}function mf(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 gf(e,t){try{const n=hf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Ny(e,t,n){var r,i;const s=(r=gf(e,n))!==null&&r!==void 0?r:{},a=mf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Cy(e,t,n,r,i){var s;const a=hf(e),o=mf(t),l=(s=gf(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 dl({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(!kt(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=Hn({panelConstraints:t,panelIndex:s,size:a});a!=o&&(i+=a-o,n[s]=o)}if(!kt(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=Hn({panelConstraints:t,panelIndex:s,size:o});if(a!==l&&(i-=l-a,n[s]=l,kt(i,0)))break}return n}const Ey=100,jr={getItem:e=>(cl(jr),jr.getItem(e)),setItem:(e,t)=>{cl(jr),jr.setItem(e,t)}},fl={};function xf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:a=null,keyboardResizeBy:o=null,storage:l=jr,style:c,tagName:f="div",...d}){const p=io(s),h=xt(null),[m,w]=Kn(null),[S,x]=Kn([]),_=gy(),g=xt({}),z=xt(new Map),E=xt(0),k=xt({autoSaveId:e,direction:r,dragState:m,id:p,keyboardResizeBy:o,onLayout:a,storage:l}),C=xt({layout:S,panelDataArray:[],panelDataArrayChanged:!1});xt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),Xd(i,()=>({getId:()=>k.current.id,getLayout:()=>{const{layout:b}=C.current;return b},setLayout:b=>{const{onLayout:Y}=k.current,{layout:oe,panelDataArray:ne}=C.current,ie=dl({layout:b,panelConstraints:ne.map(W=>W.constraints)});ul(oe,ie)||(x(ie),C.current.layout=ie,Y&&Y(ie),Rn(ne,ie,g.current))}}),[]),jn(()=>{k.current.autoSaveId=e,k.current.direction=r,k.current.dragState=m,k.current.id=p,k.current.onLayout=a,k.current.storage=l}),vy({committedValuesRef:k,eagerValuesRef:C,groupId:p,layout:S,panelDataArray:C.current.panelDataArray,setLayout:x,panelGroupElement:h.current}),_n(()=>{const{panelDataArray:b}=C.current;if(e){if(S.length===0||S.length!==b.length)return;let Y=fl[e];Y==null&&(Y=jy(Cy,Ey),fl[e]=Y);const oe=[...b],ne=new Map(z.current);Y(e,oe,ne,S,l)}},[e,S,l]),_n(()=>{});const $=pt(b=>{const{onLayout:Y}=k.current,{layout:oe,panelDataArray:ne}=C.current;if(b.constraints.collapsible){const ie=ne.map(V=>V.constraints),{collapsedSize:W=0,panelSize:F,pivotIndices:te}=gn(ne,b,oe);if(_e(F!=null,`Panel size not found for panel "${b.id}"`),!Xt(F,W)){z.current.set(b.id,F);const de=Bn(ne,b)===ne.length-1?F-W:W-F,le=_r({delta:de,initialLayout:oe,panelConstraints:ie,pivotIndices:te,prevLayout:oe,trigger:"imperative-api"});ci(oe,le)||(x(le),C.current.layout=le,Y&&Y(le),Rn(ne,le,g.current))}}},[]),K=pt((b,Y)=>{const{onLayout:oe}=k.current,{layout:ne,panelDataArray:ie}=C.current;if(b.constraints.collapsible){const W=ie.map(ye=>ye.constraints),{collapsedSize:F=0,panelSize:te=0,minSize:V=0,pivotIndices:de}=gn(ie,b,ne),le=Y??V;if(Xt(te,F)){const ye=z.current.get(b.id),Oe=ye!=null&&ye>=le?ye:le,Qe=Bn(ie,b)===ie.length-1?te-Oe:Oe-te,j=_r({delta:Qe,initialLayout:ne,panelConstraints:W,pivotIndices:de,prevLayout:ne,trigger:"imperative-api"});ci(ne,j)||(x(j),C.current.layout=j,oe&&oe(j),Rn(ie,j,g.current))}}},[]),N=pt(b=>{const{layout:Y,panelDataArray:oe}=C.current,{panelSize:ne}=gn(oe,b,Y);return _e(ne!=null,`Panel size not found for panel "${b.id}"`),ne},[]),I=pt((b,Y)=>{const{panelDataArray:oe}=C.current,ne=Bn(oe,b);return _y({defaultSize:Y,dragState:m,layout:S,panelData:oe,panelIndex:ne})},[m,S]),A=pt(b=>{const{layout:Y,panelDataArray:oe}=C.current,{collapsedSize:ne=0,collapsible:ie,panelSize:W}=gn(oe,b,Y);return _e(W!=null,`Panel size not found for panel "${b.id}"`),ie===!0&&Xt(W,ne)},[]),B=pt(b=>{const{layout:Y,panelDataArray:oe}=C.current,{collapsedSize:ne=0,collapsible:ie,panelSize:W}=gn(oe,b,Y);return _e(W!=null,`Panel size not found for panel "${b.id}"`),!ie||In(W,ne)>0},[]),D=pt(b=>{const{panelDataArray:Y}=C.current;Y.push(b),Y.sort((oe,ne)=>{const ie=oe.order,W=ne.order;return ie==null&&W==null?0:ie==null?-1:W==null?1:ie-W}),C.current.panelDataArrayChanged=!0,_()},[_]);jn(()=>{if(C.current.panelDataArrayChanged){C.current.panelDataArrayChanged=!1;const{autoSaveId:b,onLayout:Y,storage:oe}=k.current,{layout:ne,panelDataArray:ie}=C.current;let W=null;if(b){const te=Ny(b,ie,oe);te&&(z.current=new Map(Object.entries(te.expandToSizes)),W=te.layout)}W==null&&(W=Sy({panelDataArray:ie}));const F=dl({layout:W,panelConstraints:ie.map(te=>te.constraints)});ul(ne,F)||(x(F),C.current.layout=F,Y&&Y(F),Rn(ie,F,g.current))}}),jn(()=>{const b=C.current;return()=>{b.layout=[]}},[]);const T=pt(b=>{let Y=!1;const oe=h.current;return oe&&window.getComputedStyle(oe,null).getPropertyValue("direction")==="rtl"&&(Y=!0),function(ie){ie.preventDefault();const W=h.current;if(!W)return()=>null;const{direction:F,dragState:te,id:V,keyboardResizeBy:de,onLayout:le}=k.current,{layout:ye,panelDataArray:Oe}=C.current,{initialLayout:qe}=te??{},Qe=df(V,b,W);let j=ky(ie,b,F,te,de,W);const O=F==="horizontal";O&&Y&&(j=-j);const Z=Oe.map(Q=>Q.constraints),re=_r({delta:j,initialLayout:qe??ye,panelConstraints:Z,pivotIndices:Qe,prevLayout:ye,trigger:tf(ie)?"keyboard":"mouse-or-touch"}),ee=!ci(ye,re);(nf(ie)||rf(ie))&&E.current!=j&&(E.current=j,!ee&&j!==0?O?Rs(b,j<0?af:of):Rs(b,j<0?lf:uf):Rs(b,0)),ee&&(x(re),C.current.layout=re,le&&le(re),Rn(Oe,re,g.current))}},[]),P=pt((b,Y)=>{const{onLayout:oe}=k.current,{layout:ne,panelDataArray:ie}=C.current,W=ie.map(ye=>ye.constraints),{panelSize:F,pivotIndices:te}=gn(ie,b,ne);_e(F!=null,`Panel size not found for panel "${b.id}"`);const de=Bn(ie,b)===ie.length-1?F-Y:Y-F,le=_r({delta:de,initialLayout:ne,panelConstraints:W,pivotIndices:te,prevLayout:ne,trigger:"imperative-api"});ci(ne,le)||(x(le),C.current.layout=le,oe&&oe(le),Rn(ie,le,g.current))},[]),J=pt((b,Y)=>{const{layout:oe,panelDataArray:ne}=C.current,{collapsedSize:ie=0,collapsible:W}=Y,{collapsedSize:F=0,collapsible:te,maxSize:V=100,minSize:de=0}=b.constraints,{panelSize:le}=gn(ne,b,oe);le!=null&&(W&&te&&Xt(le,ie)?Xt(ie,F)||P(b,F):le<de?P(b,de):le>V&&P(b,V))},[P]),R=pt((b,Y)=>{const{direction:oe}=k.current,{layout:ne}=C.current;if(!h.current)return;const ie=ms(b,h.current);_e(ie,`Drag handle element not found for id "${b}"`);const W=pf(oe,Y);w({dragHandleId:b,dragHandleRect:ie.getBoundingClientRect(),initialCursorPosition:W,initialLayout:ne})},[]),q=pt(()=>{w(null)},[]),v=pt(b=>{const{panelDataArray:Y}=C.current,oe=Bn(Y,b);oe>=0&&(Y.splice(oe,1),delete g.current[b.id],C.current.panelDataArrayChanged=!0,_())},[_]),fe=ny(()=>({collapsePanel:$,direction:r,dragState:m,expandPanel:K,getPanelSize:N,getPanelStyle:I,groupId:p,isPanelCollapsed:A,isPanelExpanded:B,reevaluatePanelConstraints:J,registerPanel:D,registerResizeHandle:T,resizePanel:P,startDragging:R,stopDragging:q,unregisterPanel:v,panelGroupElement:h.current}),[$,m,r,K,N,I,p,A,B,J,D,T,P,R,q,v]),ue={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return nr(fs.Provider,{value:fe},nr(f,{...d,children:t,className:n,id:s,ref:h,style:{...ue,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const yf=Kd((e,t)=>nr(xf,{...e,forwardedRef:t}));xf.displayName="PanelGroup";yf.displayName="forwardRef(PanelGroup)";function Bn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function gn(e,t,n){const r=Bn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],a=n[r];return{...t.constraints,panelSize:a,pivotIndices:s}}function Iy({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){_n(()=>{if(e||n==null||r==null)return;const i=ms(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=Vr(o,r),c=cf(o,t,r);_e(c!==null,`No resize element found for id "${t}"`);const f=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[f].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function bf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:f="div",...d}){var p,h;const m=xt(null),w=xt({onDragging:a});_n(()=>{w.current.onDragging=a});const S=Yd(fs);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:x,groupId:_,registerResizeHandle:g,startDragging:z,stopDragging:E,panelGroupElement:k}=S,C=io(i),[$,K]=Kn("inactive"),[N,I]=Kn(!1),[A,B]=Kn(null),D=xt({state:$});jn(()=>{D.current.state=$}),_n(()=>{if(n)B(null);else{const R=g(C);B(()=>R)}},[n,C,g]);const T=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,P=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return _n(()=>{if(n||A==null)return;const R=m.current;return _e(R,"Element ref not attached"),my(C,R,x,{coarse:T,fine:P},(v,fe,ue)=>{if(fe)switch(v){case"down":{K("drag"),_e(ue,'Expected event to be defined for "down" action'),z(C,ue);const{onDragging:b}=w.current;b&&b(!0);break}case"move":{const{state:b}=D.current;b!=="drag"&&K("hover"),_e(ue,'Expected event to be defined for "move" action'),A(ue);break}case"up":{K("hover"),E();const{onDragging:b}=w.current;b&&b(!1);break}}else K("inactive")})},[T,x,n,P,g,C,A,z,E]),Iy({disabled:n,handleId:C,resizeHandler:A,panelGroupElement:k}),nr(f,{...d,children:e,className:t,id:i,onBlur:()=>{I(!1),s==null||s()},onFocus:()=>{I(!0),o==null||o()},ref:m,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":x,"data-panel-group-id":_,"data-resize-handle":"","data-resize-handle-active":$==="drag"?"pointer":N?"keyboard":void 0,"data-resize-handle-state":$,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":C})}bf.displayName="PanelResizeHandle";const zy=({className:e,...t})=>u.jsx(yf,{className:H("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Ms=ef,pl=({withHandle:e,className:t,...n})=>u.jsx(bf,{className:H("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(eg,{className:"h-2.5 w-2.5"})})});function Ty({children:e,className:t}){return u.jsx("kbd",{className:H("inline-flex items-center justify-center min-w-[1.25rem] h-5 px-1 rounded border border-border bg-background text-[11px] font-mono font-medium text-muted-foreground shadow-[0_1px_0_0] shadow-border/50 leading-none select-none",t),children:e})}function Ay({children:e,className:t}){return u.jsx("span",{className:H("inline-flex items-center gap-0.5",t),children:e})}const di=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function wa({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return di?"⌘":"Ctrl";case"shift":return di?"⇧":"Shift";case"alt":return di?"⌥":"Alt";case"ctrl":return di?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(Ay,{className:t,children:r.map((i,s)=>u.jsx(Ty,{children:i},s))})}class Py{constructor(t){Mo(this,"client");this.client=Sg.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 Oy=new Py;function Dy(){const e=y.useRef(null),t=y.useCallback(async(r,i,s,a,o)=>{e.current&&e.current.abort();const l=new AbortController;e.current=l;try{a==null||a("parsing","Validating JSON structure...");let c;try{c=JSON.parse(i)}catch(k){throw new Error(`Invalid JSON: ${k instanceof Error?k.message:"Unknown parse error"}`)}a==null||a("building",`Building ${li.toLowerCase()} structure...`);const f={jsonDefinition:c,options:o||{}};f.customThemes=s??{},a==null||a("rendering",`Generating ${yt.toUpperCase()} content...`);const d={"Content-Type":"application/json"};o!=null&&o.bypassCache&&(d["X-Bypass-Cache"]="true");const p=await fetch(Hc.generate,{method:"POST",headers:d,body:JSON.stringify(f),signal:l.signal}),h=await p.json();if(!p.ok||!h.success){const k=h.error||h.message||`API request failed with status: ${p.status}`;throw new Error(k)}const{data:m,cache:w,warnings:S}=h,x=w.status==="HIT"?"HIT":w.status==="MISS"?"MISS":"UNKNOWN",_=x==="HIT"?`Served from cache (Hit rate: ${w.hitRate})`:`Generated fresh ${li.toLowerCase()}`;a==null||a("finalizing",_);const g=globalThis.atob(m.document),z=new Uint8Array(g.length);for(let k=0;k<g.length;k++)z[k]=g.charCodeAt(k);const E=new Blob([z],{type:m.contentType});if(E.size===0)throw new Error(`Received empty ${li.toLowerCase()} from API`);return{name:r,text:i,blob:E,filename:m.filename,fileId:m.fileId,cacheStatus:x,cacheHitRate:w.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${li} generation was cancelled`):c}finally{e.current===l&&(e.current=null)}},[]),n=y.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:t,generateDocument:t,cancelGeneration:n}}function Ry(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const a of i){let o=a.message;if(a.context&&Object.keys(a.context).length>0){const l=Object.entries(a.context).map(([c,f])=>`${c}: ${JSON.stringify(f)}`).join(", ");o+=` (${l})`}s.push(o)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function My({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=Ee.useState("custom");Ee.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(It,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(St,{className:"max-w-md",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Non-safe fonts in this document"}),u.jsxs(cn,{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(Cn,{children:[u.jsx(we,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(we,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const hl=yt==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],$s={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function $y({name:e,blob:t,displayReloadButton:n,iframeRef:r,autoReload:i,onToggleAutoReload:s,onManualRender:a,isGenerating:o,isRendering:l,onShowCacheMetrics:c,onShowSchemas:f,onShowFonts:d,documentText:p,warnings:h,renderingLibrary:m,setRenderingLibrary:w,onToggleChat:S,chatOpen:x,onTogglePreview:_,previewOpen:g}){const z=m!=="docxjs",[E,k]=y.useState(!1),[C,$]=y.useState(!1),[K,N]=y.useState(!1),[I,A]=y.useState(!1),[B,D]=y.useState(!1),[T,P]=y.useState(!1),{toast:J}=Xr(),{generateDocument:R}=Dy(),q=y.useContext(sd),v=y.useCallback(()=>{const V={},{customThemes:de}=q.getState();return Object.values(de).forEach(le=>{le.valid&&le.parsed&&(V[le.name]=le.parsed)}),V},[q]),fe=Ee.useMemo(()=>{if(!p)return[];try{const V=JSON.parse(p);return[...(yt==="pptx"?$m:Fm)(V)].filter(le=>!Lm(le))}catch{return[]}},[p]),[ue,b]=y.useState(!1),Y=y.useCallback(async()=>{if(t){k(!0);try{await new Promise(V=>setTimeout(V,100)),ji(`${e}${fr}`,t)}finally{setTimeout(()=>k(!1),500)}}},[t,e]),oe=y.useCallback(async()=>{if(t){if(fe.length===0){await Y();return}b(!0)}},[t,fe.length,Y]),ne=y.useCallback(async V=>{var de;if(p){k(!0);try{const le=await R(e,p,v(),void 0,{bypassCache:!0,fonts:{mode:V}});if(le.blob.size===0)J({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{ji(`${e}${fr}`,le.blob);const ye=(de=le.warnings)==null?void 0:de.find(Oe=>{var qe,Qe;return((qe=Oe.context)==null?void 0:qe.code)==="FONT_MODE_SUBSTITUTED"||((Qe=Oe.context)==null?void 0:Qe.code)==="FONT_MODE_CUSTOM"});ye&&J({title:V==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:ye.message})}}catch(le){J({title:"Export failed",description:le instanceof Error?le.message:String(le),variant:"destructive"})}finally{setTimeout(()=>k(!1),500)}}},[p,e,R,J,v]),ie=y.useCallback(async()=>{if(!(!h||h.length===0)){$(!0);try{const V=Ry(h);if(!V){J({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const de=await R("warnings",JSON.stringify(V,null,2),{});de&&typeof de=="object"&&"blob"in de&&de.blob&&(ji(`${e}-warnings${fr}`,de.blob),J({title:"Warnings downloaded",description:`Downloaded warnings document with ${h.length} warning(s).`}))}catch(V){console.error("Failed to generate warnings document:",V),J({title:"Download failed",description:V instanceof Error?V.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>$(!1),500)}}},[h,e,R,J]),W=y.useCallback(async()=>{const V=r==null?void 0:r.current;if(V!=null&&V.src){N(!0);try{await new Promise(le=>{let ye=null,Oe=!1;const qe=()=>{ye&&(clearTimeout(ye),ye=null),V.removeEventListener("load",j),V.removeEventListener("error",O)},Qe=()=>{Oe||(Oe=!0,qe(),le())},j=()=>Qe(),O=()=>Qe();V.addEventListener("load",j),V.addEventListener("error",O),ye=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),Qe()},5e3);const Z=V.src,re=Z.includes("?")?"&":"?",ee=Date.now();V.src=`${Z}${re}_reload=${ee}`})}catch(de){console.error("Iframe reload failed:",de)}finally{N(!1)}}},[r]),F=y.useCallback(async()=>{A(!0);try{await Oy.delete(`/${yt}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),J({title:"Cache Cleared",description:"All caches (document and component) have been successfully cleared.",variant:"default"})}catch(V){console.error("Failed to clear cache:",V),J({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{A(!1)}},[J]),te=y.useCallback(async()=>{if(!p){J({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}P(!0);try{const V=await fetch(`/api/${yt}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:p})});if(!V.ok){let ye=`Request failed with status ${V.status}`;try{const Oe=await V.json();Oe.message&&(ye=Oe.message)}catch{}J({title:"Failed to get standard components",description:ye,variant:"destructive"});return}const de=await V.json(),le=JSON.stringify(de.data,null,2);await navigator.clipboard.writeText(le),J({title:"Copied to clipboard",description:"Standard modules JSON has been copied"})}catch(V){console.error("Error copying standard components:",V),J({title:"Error",description:V instanceof Error?V.message:"Failed to copy standard components",variant:"destructive"})}finally{P(!1)}},[p,J]);return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"bg-sidebar 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(We,{children:[u.jsx(Ge,{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 hover:bg-muted/60 shrink-0",children:u.jsx(ed,{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 uses"," ",yt==="docx"?"docx-preview":"LibreOffice PDF conversion",". Download the ",fr," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[(!i||z)&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(we,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:a,"aria-label":"Render preview",disabled:o||l||g===!1,children:[l?u.jsx(Yt,{size:"sm"}):u.jsx(tg,{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":l?"Rendering preview...":"Render preview"})})]}),yt==="docx"&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("div",{className:"flex items-center gap-1.5 cursor-help ml-2 mr-1",children:[u.jsx(Gn,{className:"text-xs text-muted-foreground hidden sm:inline",children:"Auto"}),u.jsx(eo,{checked:i,onCheckedChange:s,disabled:z})]})}),u.jsx(Ke,{children:u.jsx("p",{children:z?"Auto-reload is not available for Office, Docs, and LibreOffice renderers":`${i?"Disable":"Enable"} automatic preview reload on content changes`})})]}),n&&i&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:W,disabled:K||o||l,children:K?u.jsx(Yt,{size:"sm"}):u.jsx(ng,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsx("p",{children:K?"Reloading...":"Reload"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(we,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||E||o,onClick:oe,children:[E?u.jsx(Yt,{size:"sm"}):u.jsx(rg,{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 ",fr]})})]}),h&&h.length>0&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:"outline",size:"icon",className:"h-7 w-7 bg-amber-50 dark:bg-amber-950 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-800 hover:bg-amber-100 dark:hover:bg-amber-900",disabled:C||o,onClick:ie,children:C?u.jsx(Yt,{size:"sm"}):u.jsx(td,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download warnings (",h.length,")"]})})]}),m&&w&&u.jsxs(Rr,{value:m,onValueChange:w,children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(er,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(Mr,{placeholder:"Renderer"})})}),u.jsx(Ke,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(tr,{className:"text-sidebar-foreground",children:hl.map(V=>u.jsxs(En,{value:V,children:[u.jsxs(We,{children:[u.jsx(Ge,{tabIndex:-1,children:$s[V][0]}),u.jsx(Ke,{children:$s[V][1]})]})," ",V]},V))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(to,{children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(no,{asChild:!0,children:u.jsx(we,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(ig,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ke,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(ds,{align:"end",className:"w-52",children:[f&&u.jsxs(Kt,{onClick:f,children:[u.jsx(sg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),d&&u.jsxs(Kt,{onClick:d,children:[u.jsx(ag,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Kt,{onClick:c,children:[u.jsx(og,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),u.jsxs(Kt,{onClick:te,disabled:!p||T,children:[u.jsx(nd,{className:"h-4 w-4 mr-2"}),T?"Copying...":"Copy standard components"]}),u.jsx(Fr,{}),u.jsxs(Kt,{onClick:()=>D(!0),disabled:I,className:"text-destructive focus:text-destructive",children:[u.jsx(Ha,{className:"h-4 w-4 mr-2"}),I?"Clearing...":"Clear all caches"]}),m&&w&&u.jsxs(u.Fragment,{children:[u.jsx(Fr,{className:"lg:hidden"}),hl.map(V=>u.jsxs(Kt,{className:"lg:hidden",onClick:()=>w(V),children:[u.jsx("span",{className:"mr-2",children:m===V?"●":"○"}),$s[V][0]," ",V]},V))]})]})]}),_&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:g?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:_,children:g?u.jsx(rd,{className:"h-3.5 w-3.5"}):u.jsx(lg,{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(wa,{shortcut:"mod+shift+p"})]})})]}),S&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:x?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:S,children:u.jsx(id,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[x?"Close":"Open"," AI Chat"," ",u.jsx(wa,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(My,{open:ue,onClose:()=>b(!1),nonSafeFonts:fe,onChoose:ne}),u.jsx(It,{open:B,onOpenChange:D,children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Clear all caches?"}),u.jsx(cn,{children:"This will clear document and component caches. Next generation will be uncached."})]}),u.jsxs(Cn,{children:[u.jsx(we,{variant:"outline",size:"sm",onClick:()=>D(!1),children:"Cancel"}),u.jsx(we,{variant:"destructive",size:"sm",disabled:I,onClick:async()=>{await F(),D(!1)},children:I?u.jsx(Yt,{size:"sm"}):"Clear"})]})]})})]})}const Fy=Ee.memo($y);function Ly(e,t,n){if(t.length===0)return n;const r=ml(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=ml(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function ml(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Zy={safe:[],google:[]};function By(e,t){var f;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((f=r==null?void 0:r.dataset.weights)==null?void 0:f.split(",").map(Number).filter(d=>!Number.isNaN(d)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((d,p)=>d-p).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${o}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...a].sort((d,p)=>d-p).join(",")}function Vy(){const e=Ae(i=>i.activeTab),t=Ae(i=>i.documents),n=Ae(i=>i.documentTypes),r=Ae(i=>i.saveDocument);return y.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 Uy(){const e=Ae(r=>r.activeTab),t=Ae(r=>r.documents),n=Ae(r=>r.saveDocument);return y.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=Ly(a,r,i);return n(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n])}function Jy(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 gl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Hy=({open:e,onOpenChange:t})=>{const n=vi(P=>P.open),r=vi(P=>P.contextual),i=vi(P=>P.close),s=e??n,a=r,o=y.useCallback(P=>{t&&t(P),P||i()},[t,i]),[l,c]=y.useState(Zy),[f,d]=y.useState(!1),[p,h]=y.useState(""),[m,w]=y.useState("safe"),[S,x]=y.useState(null),[_,g]=y.useState(null),{toast:z}=Xr(),E=Vy(),k=Uy(),C=Ae(P=>P.activeTab),$=Ae(P=>P.documentTypes),K=C&&$[C]==="application/json+theme",N=!!a||K;y.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(d(!0),fetch("/api/fonts/catalog").then(P=>P.json()).then(P=>c(P)).catch(P=>{z({variant:"destructive",title:"Font catalog unavailable",description:P.message})}).finally(()=>d(!1))))},[s,l,z]),y.useEffect(()=>{if(!(m!=="google"||l.google.length===0))for(const P of l.google)By(P.family,P.weights)},[m,l]);const I=y.useMemo(()=>l.safe.filter(P=>P.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),A=y.useMemo(()=>l.google.filter(P=>P.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),B=y.useCallback(async P=>{try{await navigator.clipboard.writeText(P),g(P),setTimeout(()=>g(null),1500)}catch{z({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[z]),D=y.useCallback(async(P,J,R)=>{x(P);try{const q=E(v=>(Jy(v,R,P),v));if(!q.ok){z({variant:"destructive",title:"Could not insert font",description:q.error});return}z({title:"Font inserted",description:`${P} set as ${R} font in "${q.name}".`})}finally{x(null)}},[E,z]),T=y.useCallback(async P=>{if(a){x(P);try{const J=k(a.jsonPath,P);if(!J.ok){z({variant:"destructive",title:"Could not insert font",description:J.error});return}z({title:"Font inserted",description:`${P} set at ${gl(a.jsonPath)}.`}),o(!1)}finally{x(null)}}},[a,k,z,o]);return u.jsx(It,{open:s,onOpenChange:o,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:a?`Font for ${gl(a.jsonPath)}`:"Fonts"})}),!a&&!K&&u.jsx(Ri,{children:u.jsxs(Mi,{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(Wd,{value:m,onValueChange:P=>w(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Lr,{value:"safe",children:["Safe",u.jsx(Vt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(Lr,{value:"google",children:["Google",u.jsx(Vt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]})]}),u.jsx(ei,{type:"search",placeholder:"Search fonts...",value:p,onChange:P=>h(P.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(Zr,{value:"safe",className:"m-0",children:f&&I.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(ua,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:I.map(P=>u.jsx(xl,{family:P,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${P}", sans-serif`},onCopy:()=>B(P),copied:_===P,contextual:!!a,onUseThis:()=>T(P),onInsertHeading:()=>D(P,"safe","heading"),onInsertBody:()=>D(P,"safe","body"),applying:S===P,disabled:!N},P))})}),u.jsx(Zr,{value:"google",className:"m-0",children:f&&A.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(ua,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:A.map(P=>u.jsx(xl,{family:P.family,meta:u.jsxs("span",{className:"text-xs",children:[P.category," · ",P.weights.length," weights"]}),previewStyle:{fontFamily:`"${P.family}", sans-serif`},onCopy:()=>B(P.family),copied:_===P.family,contextual:!!a,onUseThis:()=>T(P.family),onInsertHeading:()=>D(P.family,"google","heading"),onInsertBody:()=>D(P.family,"google","body"),applying:S===P.family,disabled:!N,extraAction:u.jsx(Wy,{family:P.family,weights:P.weights,hasItalic:P.hasItalic})},P.family))})})]})]})]})})},qy="The quick brown fox jumps over the lazy dog",Wy=({family:e,weights:t,hasItalic:n})=>{const r=y.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(to,{children:[u.jsx(no,{asChild:!0,children:u.jsx(we,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(ds,{align:"end",className:"min-w-[260px]",children:[u.jsxs(qd,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(Fr,{}),r.map(i=>{const s=Zm[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)})]})]})},xl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:f,extraAction:d})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:qy}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(we,{size:"sm",onClick:a,disabled:c||f,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(we,{size:"sm",variant:"secondary",onClick:o,disabled:c||f,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(we,{size:"sm",variant:"secondary",onClick:l,disabled:c||f,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),d,u.jsx(we,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(un,{className:"h-4 w-4"}):u.jsx(as,{className:"h-4 w-4"})})]})]});function yl({previewOpen:e,onTogglePreview:t}){const n=vn($=>$.name||""),r=vn($=>$.blob),i=vn($=>$.isGenerating),s=vn($=>$.text),a=vn($=>$.warnings),o=vn($=>$.isRendering),l=ui($=>$.autoReload),c=ui($=>$.renderingLibrary),f=ui($=>$.setSettings),d=ui($=>$.useGlobalPreviewHeader??!0),p=Ae($=>$.activeTab),h=Ae($=>$.documentTypes),m=p&&h[p]==="application/json+theme"?"theme":"document",w=Te($=>$.chatOpen),S=Te($=>$.toggleChat),[x,_]=Ee.useState(!1),g=vi($=>$.openFor);if(!d)return null;const z=y.useCallback(()=>f({saveDocumentDebounceWait:2e3,autoReload:!l}),[l,f]),E=y.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),k=y.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),C=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(Fy,{name:C,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:z,onManualRender:E,isGenerating:i,isRendering:!!o,onShowCacheMetrics:k,onShowSchemas:()=>_(!0),onShowFonts:()=>g(),documentText:s,warnings:a,renderingLibrary:c,setRenderingLibrary:$=>f({renderingLibrary:$}),onToggleChat:S,chatOpen:w,onTogglePreview:t,previewOpen:e}),u.jsx(Gd,{open:x,onOpenChange:_,defaultTab:m==="theme"?"theme":"document"}),u.jsx(Hy,{})]})}function Gy(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Ky=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Yy=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Xy={};function bl(e,t){return(Xy.jsx?Yy:Ky).test(e)}const Qy=/[ \t\n\f\r]/g;function eb(e){return typeof e=="object"?e.type==="text"?vl(e.value):!1:vl(e)}function vl(e){return e.replace(Qy,"")===""}class ni{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}ni.prototype.normal={};ni.prototype.property={};ni.prototype.space=void 0;function vf(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new ni(n,r,t)}function ka(e){return e.toLowerCase()}class bt{constructor(t,n){this.attribute=n,this.property=t}}bt.prototype.attribute="";bt.prototype.booleanish=!1;bt.prototype.boolean=!1;bt.prototype.commaOrSpaceSeparated=!1;bt.prototype.commaSeparated=!1;bt.prototype.defined=!1;bt.prototype.mustUseProperty=!1;bt.prototype.number=!1;bt.prototype.overloadedBoolean=!1;bt.prototype.property="";bt.prototype.spaceSeparated=!1;bt.prototype.space=void 0;let tb=0;const ke=An(),tt=An(),Sa=An(),X=An(),Fe=An(),Xn=An(),wt=An();function An(){return 2**++tb}const _a=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:tt,commaOrSpaceSeparated:wt,commaSeparated:Xn,number:X,overloadedBoolean:Sa,spaceSeparated:Fe},Symbol.toStringTag,{value:"Module"})),Fs=Object.keys(_a);class lo extends bt{constructor(t,n,r,i){let s=-1;if(super(t,n),wl(this,"space",i),typeof r=="number")for(;++s<Fs.length;){const a=Fs[s];wl(this,Fs[s],(r&_a[a])===_a[a])}}}lo.prototype.defined=!0;function wl(e,t,n){n&&(e[t]=n)}function lr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new lo(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[ka(r)]=r,n[ka(s.attribute)]=r}return new ni(t,n,e.space)}const wf=lr({properties:{ariaActiveDescendant:null,ariaAtomic:tt,ariaAutoComplete:null,ariaBusy:tt,ariaChecked:tt,ariaColCount:X,ariaColIndex:X,ariaColSpan:X,ariaControls:Fe,ariaCurrent:null,ariaDescribedBy:Fe,ariaDetails:null,ariaDisabled:tt,ariaDropEffect:Fe,ariaErrorMessage:null,ariaExpanded:tt,ariaFlowTo:Fe,ariaGrabbed:tt,ariaHasPopup:null,ariaHidden:tt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Fe,ariaLevel:X,ariaLive:null,ariaModal:tt,ariaMultiLine:tt,ariaMultiSelectable:tt,ariaOrientation:null,ariaOwns:Fe,ariaPlaceholder:null,ariaPosInSet:X,ariaPressed:tt,ariaReadOnly:tt,ariaRelevant:null,ariaRequired:tt,ariaRoleDescription:Fe,ariaRowCount:X,ariaRowIndex:X,ariaRowSpan:X,ariaSelected:tt,ariaSetSize:X,ariaSort:null,ariaValueMax:X,ariaValueMin:X,ariaValueNow:X,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function kf(e,t){return t in e?e[t]:t}function Sf(e,t){return kf(e,t.toLowerCase())}const nb=lr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:Xn,acceptCharset:Fe,accessKey:Fe,action:null,allow:null,allowFullScreen:ke,allowPaymentRequest:ke,allowUserMedia:ke,alt:null,as:null,async:ke,autoCapitalize:null,autoComplete:Fe,autoFocus:ke,autoPlay:ke,blocking:Fe,capture:null,charSet:null,checked:ke,cite:null,className:Fe,cols:X,colSpan:null,content:null,contentEditable:tt,controls:ke,controlsList:Fe,coords:X|Xn,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Sa,draggable:tt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Fe,height:X,hidden:Sa,high:X,href:null,hrefLang:null,htmlFor:Fe,httpEquiv:Fe,id:null,imageSizes:null,imageSrcSet:null,inert:ke,inputMode:null,integrity:null,is:null,isMap:ke,itemId:null,itemProp:Fe,itemRef:Fe,itemScope:ke,itemType:Fe,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:ke,low:X,manifest:null,max:null,maxLength:X,media:null,method:null,min:null,minLength:X,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:X,pattern:null,ping:Fe,placeholder:null,playsInline:ke,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:ke,referrerPolicy:null,rel:Fe,required:ke,reversed:ke,rows:X,rowSpan:X,sandbox:Fe,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:X,sizes:null,slot:null,span:X,spellCheck:tt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:X,step:null,style:null,tabIndex:X,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:tt,width:X,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Fe,axis:null,background:null,bgColor:null,border:X,borderColor:null,bottomMargin:X,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:X,leftMargin:X,link:null,longDesc:null,lowSrc:null,marginHeight:X,marginWidth:X,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:X,rules:null,scheme:null,scrolling:tt,standby:null,summary:null,text:null,topMargin:X,valueType:null,version:null,vAlign:null,vLink:null,vSpace:X,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:X,security:null,unselectable:null},space:"html",transform:Sf}),rb=lr({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:wt,accentHeight:X,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:X,amplitude:X,arabicForm:null,ascent:X,attributeName:null,attributeType:null,azimuth:X,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:X,by:null,calcMode:null,capHeight:X,className:Fe,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:X,diffuseConstant:X,direction:null,display:null,dur:null,divisor:X,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:X,enableBackground:null,end:null,event:null,exponent:X,externalResourcesRequired:null,fill:null,fillOpacity:X,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:Xn,g2:Xn,glyphName:Xn,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:X,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:X,horizOriginX:X,horizOriginY:X,id:null,ideographic:X,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:X,k:X,k1:X,k2:X,k3:X,k4:X,kernelMatrix:wt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:X,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:X,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:X,overlineThickness:X,paintOrder:null,panose1:null,path:null,pathLength:X,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Fe,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:X,pointsAtY:X,pointsAtZ:X,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:wt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:wt,rev:wt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:wt,requiredFeatures:wt,requiredFonts:wt,requiredFormats:wt,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:X,specularExponent:X,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:X,strikethroughThickness:X,string:null,stroke:null,strokeDashArray:wt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:X,strokeOpacity:X,strokeWidth:null,style:null,surfaceScale:X,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:wt,tabIndex:X,tableValues:null,target:null,targetX:X,targetY:X,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:wt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:X,underlineThickness:X,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:X,values:null,vAlphabetic:X,vMathematical:X,vectorEffect:null,vHanging:X,vIdeographic:X,version:null,vertAdvY:X,vertOriginX:X,vertOriginY:X,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:X,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:kf}),_f=lr({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()}}),jf=lr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:Sf}),Nf=lr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),ib={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"},sb=/[A-Z]/g,kl=/-[a-z]/g,ab=/^data[-\w.:]+$/i;function ob(e,t){const n=ka(t);let r=t,i=bt;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&ab.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(kl,ub);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!kl.test(s)){let a=s.replace(sb,lb);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=lo}return new i(r,t)}function lb(e){return"-"+e.toLowerCase()}function ub(e){return e.charAt(1).toUpperCase()}const cb=vf([wf,nb,_f,jf,Nf],"html"),uo=vf([wf,rb,_f,jf,Nf],"svg");function db(e){return e.join(" ").trim()}var Mn={},Ls,Sl;function fb(){if(Sl)return Ls;Sl=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=`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-BPfMyucg.js","assets/react-vendor-CTFDOf2G.js","assets/editor-monaco-json-cWylTaeJ.js","assets/index-Dd4Xxzh5.js","assets/query-vendor-Df8-oete.js","assets/radix-ui-BQBCrmlJ.js","assets/ui-vendor-HKNXoiLD.js","assets/monaco-editor-BcgxPCqT.js","assets/state-vendor-ByFYl9bq.js","assets/index-DiQf3mCW.css","assets/MonacoPluginProvider-DQcmmuko.js","assets/button-DfjYrtU-.js","assets/preview-Cdpjm_5u.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var cm=Object.defineProperty;var dm=(e,t,n)=>t in e?cm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Mo=(e,t,n)=>dm(e,typeof t!="symbol"?t+"":t,n);import{r as y,j as u,c as Ee,R as cc,g as Ua}from"./react-vendor-CTFDOf2G.js";import{b as dc,c as Ja,d as fc,e as pc,f as ts,g as ns,D as rs,O as is,h as fm,V as pm,i as hc,I as hm,j as mm,k as mc,l as gm,m as gc,n as xm,o as ym,G as bm,S as xc,p as yc,L as bc,q as vc,r as wc,s as or,t as vm,u as wm,v as km,w as kc,x as Sc,y as _c,z as jc,A as Nc,B as Cc,E as Ec,F as Ic,H as zc,J as Tc,K as Ac,M as Sm,N as _m,Q as Pc,U as jm,W as Nm,X as Cm,Y as Em,Z as Im,_ as zm,$ as Tm,a0 as Am,a1 as Pm,a2 as Oc,a3 as Dc,a4 as Rc,a5 as Mc,a6 as $c,a7 as Fc,a8 as Lc,a9 as Zc,aa as Bc,ab as Om,ac as Vc,ad as Uc,ae as Jc}from"./radix-ui-BQBCrmlJ.js";import{c as H,u as Xr,S as Yt,A as Hc,T as oi,C as Dm,E as Rm,F as yt,a as Mm,b as We,d as Ge,e as Ke,f as qc,s as Ns,_ as Wc,g as li,h as $m,i as Fm,j as Lm,k as fr,l as vi,W as Zm}from"./index-Dd4Xxzh5.js";import{X as Nn,C as on,a as un,b as Bm,d as Qr,G as Gc,F as Vm,e as ss,f as Kc,P as Um,g as $o,h as la,i as Yc,S as Xc,B as Fo,j as Jm,k as Hm,l as qm,m as as,n as Wm,M as Gm,o as Km,p as Ym,q as Qc,r as Xm,s as Lo,t as zi,u as Qm,I as ed,v as eg,w as tg,R as ng,x as rg,T as td,E as ig,y as sg,z as ag,A as og,D as nd,H as Ha,J as rd,K as lg,L as id,N as ua,O as ug,Q as cg,U as Zo,V as ca,W as dg}from"./ui-vendor-HKNXoiLD.js";import{B as we}from"./button-DfjYrtU-.js";import{u as Ae,i as fg,a as da,b as vn,g as fa,c as Dt,T as sd,d as ui,S as pg,O as hg,e as mg,M as gg,D as xg}from"./MonacoPluginProvider-DQcmmuko.js";import{u as ad,a as yg,d as bg,p as vg,b as wg,e as kg}from"./state-vendor-ByFYl9bq.js";import{b as Sg}from"./query-vendor-Df8-oete.js";const It=dc,Bo=fc,_g=pc,Vo=Ja,od=y.forwardRef(({className:e,...t},n)=>u.jsx(is,{ref:n,className:H("fixed inset-0 z-50 bg-black/80",e),...t}));od.displayName=is.displayName;const St=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(_g,{children:[u.jsx(od,{}),u.jsxs(ts,{ref:r,className:H("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(Ja,{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(Nn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));St.displayName=ts.displayName;const Ut=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ut.displayName="DialogHeader";const Cn=({className:e,...t})=>u.jsx("div",{className:H("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});Cn.displayName="DialogFooter";const Jt=y.forwardRef(({className:e,...t},n)=>u.jsx(ns,{ref:n,className:H("text-lg leading-none font-semibold tracking-tight",e),...t}));Jt.displayName=ns.displayName;const cn=y.forwardRef(({className:e,...t},n)=>u.jsx(rs,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));cn.displayName=rs.displayName;const Rr=fm,jg=bm,Mr=pm,er=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(hc,{ref:r,className:H("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-md border bg-transparent px-3 py-2 text-sm shadow-sm 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(hm,{asChild:!0,children:u.jsx(on,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));er.displayName=hc.displayName;const ld=y.forwardRef(({className:e,...t},n)=>u.jsx(xc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Bm,{className:"h-4 w-4"})}));ld.displayName=xc.displayName;const ud=y.forwardRef(({className:e,...t},n)=>u.jsx(yc,{ref:n,className:H("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(on,{className:"h-4 w-4"})}));ud.displayName=yc.displayName;const tr=y.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(mm,{children:u.jsxs(mc,{ref:i,className:H("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-md 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(ld,{}),u.jsx(gm,{className:H("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(ud,{})]})}));tr.displayName=mc.displayName;const cd=y.forwardRef(({className:e,...t},n)=>u.jsx(bc,{ref:n,className:H("px-2 py-1.5 text-sm font-semibold",e),...t}));cd.displayName=bc.displayName;const En=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(gc,{ref:r,className:H("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(xm,{children:u.jsx(un,{className:"h-4 w-4"})})}),u.jsx(ym,{children:t})]}));En.displayName=gc.displayName;const Ng=y.forwardRef(({className:e,...t},n)=>u.jsx(vc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));Ng.displayName=vc.displayName;const ei=y.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:H("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-md border bg-transparent px-3 py-1 text-base shadow-sm 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 md:text-sm",e),ref:r,...n}));ei.displayName="Input";const Cg=Qr("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Gn=y.forwardRef(({className:e,...t},n)=>u.jsx(wc,{ref:n,className:H(Cg(),e),...t}));Gn.displayName=wc.displayName;const Eg=Qr("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Vt({className:e,variant:t,...n}){return u.jsx("div",{className:H(Eg({variant:t}),e),...n})}const Ig=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:a}=Ae(ad(I=>({documents:I.documents,documentTypes:I.documentTypes,activeTab:I.activeTab,createDocument:I.createDocument,openDocument:I.openDocument}))),{toast:o}=Xr(),l=y.useMemo(()=>n.filter(I=>r[I.name]!=="application/json+theme"),[n,r]),[c,f]=y.useState(""),[d,p]=y.useState(""),[h,m]=y.useState("playground"),[w,S]=y.useState(!1),[x,_]=y.useState(null),[g,z]=y.useState(null),[E,k]=y.useState(null),C=()=>{_(null),z(null),k(null)};y.useEffect(()=>{if(!e)return;_(null),z(null),k(null);const I=l.map(B=>B.name),A=I.includes(i)?i:I[0]??"";p(A),f(I.find(B=>B!==A)??"")},[e]);const $=async()=>{const I=l.find(B=>B.name===c),A=l.find(B=>B.name===d);if(!(!I||!A)){S(!0),_(null),z(null),k(null);try{const B=await fetch(Hc.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:I.text,newDefinition:A.text,options:{author:h||"playground"}})}),D=await B.json();if(!B.ok||!D.success){const T=Array.isArray(D.errors)?`: ${D.errors.slice(0,3).map(P=>P.message||String(P)).join("; ")}`:"";throw new Error((D.error||`Diff failed (${B.status})`)+T)}z(D.data.summary),k(D.data.document)}catch(B){_(B instanceof Error?B.message:"Diff failed")}finally{S(!1)}}},K=()=>{if(!E)return;const I=new Set(n.map(D=>D.name));let A=`${d}-redline`,B=2;for(;I.has(A);)A=`${d}-redline-${B++}`;s(A,JSON.stringify(E,null,2)),a(A),o({title:`Redline created: ${A}`}),t(!1)},N=g?g.tracked.modified+g.tracked.inserted+g.tracked.deleted:0;return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"sm:max-w-[560px]",children:[u.jsxs(Ut,{children:[u.jsxs(Jt,{className:"flex items-center gap-2",children:[u.jsx(Gc,{className:"size-4"}),"Compare documents"]}),u.jsx(cn,{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(Gn,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(Rr,{value:c,onValueChange:I=>{f(I),C()},children:[u.jsx(er,{id:"diff-base",children:u.jsx(Mr,{placeholder:"Select document"})}),u.jsx(tr,{children:l.map(I=>u.jsx(En,{value:I.name,children:I.name},I.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Gn,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(Rr,{value:d,onValueChange:I=>{p(I),C()},children:[u.jsx(er,{id:"diff-revised",children:u.jsx(Mr,{placeholder:"Select document"})}),u.jsx(tr,{children:l.map(I=>u.jsx(En,{value:I.name,children:I.name},I.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(Gn,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(ei,{id:"diff-author",value:h,onChange:I=>{m(I.target.value),C()},placeholder:"playground"})]}),x&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:x}),g&&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(Vt,{variant:"secondary",children:[g.tracked.inserted," inserted"]}),u.jsxs(Vt,{variant:"secondary",children:[g.tracked.deleted," deleted"]}),u.jsxs(Vt,{variant:"secondary",children:[g.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[g.unchangedBlocks," blocks unchanged"]})]}),N===0&&g.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),g.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-amber-600 dark:text-amber-500",children:[g.untracked.length," change(s) not expressible as tracked changes:"]}),g.untracked.map((I,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[I.path," [",I.component,"] ",I.detail]},A))]}),g.notes.map((I,A)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",I]},A))]})]}),u.jsx(Cn,{children:g&&N+g.untracked.length>0?u.jsxs(we,{onClick:K,children:[u.jsx(Vm,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(we,{onClick:$,disabled:w||!c||!d||c===d,children:[w&&u.jsx(Yt,{className:"size-4 mr-1"}),"Compare"]})})]})})};var ti=e=>e.type==="checkbox",kn=e=>e instanceof Date,ct=e=>e==null;const dd=e=>typeof e=="object";var Xe=e=>!ct(e)&&!Array.isArray(e)&&dd(e)&&!kn(e),fd=e=>Xe(e)&&e.target?ti(e.target)?e.target.checked:e.target.value:e,zg=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,pd=(e,t)=>e.has(zg(t)),Tg=e=>{const t=e.constructor&&e.constructor.prototype;return Xe(t)&&t.hasOwnProperty("isPrototypeOf")},qa=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function mt(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(!(qa&&(e instanceof Blob||r))&&(n||Xe(e)))if(t=n?[]:{},!n&&!Tg(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=mt(e[i]));else return e;return t}var os=e=>Array.isArray(e)?e.filter(Boolean):[],Ye=e=>e===void 0,ae=(e,t,n)=>{if(!t||!Xe(e))return n;const r=os(t.split(/[,[\].]+?/)).reduce((i,s)=>ct(i)?i:i[s],e);return Ye(r)||r===e?Ye(e[t])?n:e[t]:r},Ct=e=>typeof e=="boolean",Wa=e=>/^\w*$/.test(e),hd=e=>os(e.replace(/["|']|\]/g,"").split(/\.|\[/)),De=(e,t,n)=>{let r=-1;const i=Wa(t)?[t]:hd(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=Xe(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 Ti={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ot={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},Gt={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},md=Ee.createContext(null),ls=()=>Ee.useContext(md),Ag=e=>{const{children:t,...n}=e;return Ee.createElement(md.Provider,{value:n},t)};var gd=(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]!==Ot.all&&(t._proxyFormState[a]=!r||Ot.all),n&&(n[a]=!0),e[a]}});return i},gt=e=>Xe(e)&&!Object.keys(e).length,xd=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return gt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(a=>t[a]===(!r||Ot.all))},zr=e=>Array.isArray(e)?e:[e],yd=(e,t,n)=>!e||!t||e===t||zr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function Ga(e){const t=Ee.useRef(e);t.current=e,Ee.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function Pg(e){const t=ls(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[a,o]=Ee.useState(n._formState),l=Ee.useRef(!0),c=Ee.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),f=Ee.useRef(i);return f.current=i,Ga({disabled:r,next:d=>l.current&&yd(f.current,d.name,s)&&xd(d,c.current,n._updateFormState)&&o({...n._formState,...d}),subject:n._subjects.state}),Ee.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),Ee.useMemo(()=>gd(a,n,c.current,!1),[a,n])}var Bt=e=>typeof e=="string",bd=(e,t,n,r,i)=>Bt(e)?(r&&t.watch.add(e),ae(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),ae(n,s))):(r&&(t.watchAll=!0),n);function Og(e){const t=ls(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:a}=e||{},o=Ee.useRef(r);o.current=r,Ga({disabled:s,subject:n._subjects.values,next:f=>{yd(o.current,f.name,a)&&c(mt(bd(o.current,n._names,f.values||n._formValues,!1,i)))}});const[l,c]=Ee.useState(n._getWatch(r,i));return Ee.useEffect(()=>n._removeUnmounted()),l}function Dg(e){const t=ls(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,a=pd(i._names.array,n),o=Og({control:i,name:n,defaultValue:ae(i._formValues,n,ae(i._defaultValues,n,e.defaultValue)),exact:!0}),l=Pg({control:i,name:n,exact:!0}),c=Ee.useRef(i.register(n,{...e.rules,value:o,...Ct(e.disabled)?{disabled:e.disabled}:{}})),f=Ee.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ae(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!ae(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ae(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ae(l.validatingFields,n)},error:{enumerable:!0,get:()=>ae(l.errors,n)}}),[l,n]),d=Ee.useMemo(()=>({name:n,value:o,...Ct(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:fd(p),name:n},type:Ti.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:ae(i._formValues,n),name:n},type:Ti.BLUR}),ref:p=>{const h=ae(i._fields,n);h&&p&&(h._f.ref={focus:()=>p.focus(),select:()=>p.select(),setCustomValidity:m=>p.setCustomValidity(m),reportValidity:()=>p.reportValidity()})}}),[n,i._formValues,r,l.disabled,o,i._fields]);return Ee.useEffect(()=>{const p=i._options.shouldUnregister||s,h=(m,w)=>{const S=ae(i._fields,m);S&&S._f&&(S._f.mount=w)};if(h(n,!0),p){const m=mt(ae(i._options.defaultValues,n));De(i._defaultValues,n,m),Ye(ae(i._formValues,n))&&De(i._formValues,n,m)}return!a&&i.register(n),()=>{(a?p&&!i._state.action:p)?i.unregister(n):h(n,!1)}},[n,i,a,s]),Ee.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),Ee.useMemo(()=>({field:d,formState:l,fieldState:f}),[d,l,f])}const Rg=e=>e.render(Dg(e));var Mg=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},Uo=e=>({isOnSubmit:!e||e===Ot.onSubmit,isOnBlur:e===Ot.onBlur,isOnChange:e===Ot.onChange,isOnAll:e===Ot.all,isOnTouch:e===Ot.onTouched}),Jo=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Tr=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=ae(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(Tr(o,t))break}else if(Xe(o)&&Tr(o,t))break}}};var $g=(e,t,n)=>{const r=zr(ae(e,n));return De(r,"root",t[n]),De(e,n,r),e},Ka=e=>e.type==="file",Zt=e=>typeof e=="function",Ai=e=>{if(!qa)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},wi=e=>Bt(e),Ya=e=>e.type==="radio",Pi=e=>e instanceof RegExp;const Ho={value:!1,isValid:!1},qo={value:!0,isValid:!0};var vd=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&&!Ye(e[0].attributes.value)?Ye(e[0].value)||e[0].value===""?qo:{value:e[0].value,isValid:!0}:qo:Ho}return Ho};const Wo={isValid:!1,value:null};var wd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Wo):Wo;function Go(e,t,n="validate"){if(wi(e)||Array.isArray(e)&&e.every(wi)||Ct(e)&&!e)return{type:n,message:wi(e)?e:"",ref:t}}var On=e=>Xe(e)&&!Pi(e)?e:{value:e,message:""},Ko=async(e,t,n,r,i,s)=>{const{ref:a,refs:o,required:l,maxLength:c,minLength:f,min:d,max:p,pattern:h,validate:m,name:w,valueAsNumber:S,mount:x}=e._f,_=ae(n,w);if(!x||t.has(w))return{};const g=o?o[0]:a,z=A=>{i&&g.reportValidity&&(g.setCustomValidity(Ct(A)?"":A||""),g.reportValidity())},E={},k=Ya(a),C=ti(a),$=k||C,K=(S||Ka(a))&&Ye(a.value)&&Ye(_)||Ai(a)&&a.value===""||_===""||Array.isArray(_)&&!_.length,N=Mg.bind(null,w,r,E),I=(A,B,D,T=Gt.maxLength,P=Gt.minLength)=>{const J=A?B:D;E[w]={type:A?T:P,message:J,ref:a,...N(A?T:P,J)}};if(s?!Array.isArray(_)||!_.length:l&&(!$&&(K||ct(_))||Ct(_)&&!_||C&&!vd(o).isValid||k&&!wd(o).isValid)){const{value:A,message:B}=wi(l)?{value:!!l,message:l}:On(l);if(A&&(E[w]={type:Gt.required,message:B,ref:g,...N(Gt.required,B)},!r))return z(B),E}if(!K&&(!ct(d)||!ct(p))){let A,B;const D=On(p),T=On(d);if(!ct(_)&&!isNaN(_)){const P=a.valueAsNumber||_&&+_;ct(D.value)||(A=P>D.value),ct(T.value)||(B=P<T.value)}else{const P=a.valueAsDate||new Date(_),J=v=>new Date(new Date().toDateString()+" "+v),R=a.type=="time",q=a.type=="week";Bt(D.value)&&_&&(A=R?J(_)>J(D.value):q?_>D.value:P>new Date(D.value)),Bt(T.value)&&_&&(B=R?J(_)<J(T.value):q?_<T.value:P<new Date(T.value))}if((A||B)&&(I(!!A,D.message,T.message,Gt.max,Gt.min),!r))return z(E[w].message),E}if((c||f)&&!K&&(Bt(_)||s&&Array.isArray(_))){const A=On(c),B=On(f),D=!ct(A.value)&&_.length>+A.value,T=!ct(B.value)&&_.length<+B.value;if((D||T)&&(I(D,A.message,B.message),!r))return z(E[w].message),E}if(h&&!K&&Bt(_)){const{value:A,message:B}=On(h);if(Pi(A)&&!_.match(A)&&(E[w]={type:Gt.pattern,message:B,ref:a,...N(Gt.pattern,B)},!r))return z(B),E}if(m){if(Zt(m)){const A=await m(_,n),B=Go(A,g);if(B&&(E[w]={...B,...N(Gt.validate,B.message)},!r))return z(B.message),E}else if(Xe(m)){let A={};for(const B in m){if(!gt(A)&&!r)break;const D=Go(await m[B](_,n),g,B);D&&(A={...D,...N(B,D.message)},z(D.message),r&&(E[w]=A))}if(!gt(A)&&(E[w]={ref:g,...A},!r))return E}}return z(!0),E};function Fg(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Ye(e)?r++:e[t[r++]];return e}function Lg(e){for(const t in e)if(e.hasOwnProperty(t)&&!Ye(e[t]))return!1;return!0}function rt(e,t){const n=Array.isArray(t)?t:Wa(t)?[t]:hd(t),r=n.length===1?e:Fg(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(Xe(r)&>(r)||Array.isArray(r)&&Lg(r))&&rt(e,n.slice(0,-1)),e}var Cs=()=>{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=[]}}},pa=e=>ct(e)||!dd(e);function sn(e,t){if(pa(e)||pa(t))return e===t;if(kn(e)&&kn(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(kn(s)&&kn(a)||Xe(s)&&Xe(a)||Array.isArray(s)&&Array.isArray(a)?!sn(s,a):s!==a)return!1}}return!0}var kd=e=>e.type==="select-multiple",Zg=e=>Ya(e)||ti(e),Es=e=>Ai(e)&&e.isConnected,Sd=e=>{for(const t in e)if(Zt(e[t]))return!0;return!1};function Oi(e,t={}){const n=Array.isArray(e);if(Xe(e)||n)for(const r in e)Array.isArray(e[r])||Xe(e[r])&&!Sd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Oi(e[r],t[r])):ct(e[r])||(t[r]=!0);return t}function _d(e,t,n){const r=Array.isArray(e);if(Xe(e)||r)for(const i in e)Array.isArray(e[i])||Xe(e[i])&&!Sd(e[i])?Ye(t)||pa(n[i])?n[i]=Array.isArray(e[i])?Oi(e[i],[]):{...Oi(e[i])}:_d(e[i],ct(t)?{}:t[i],n[i]):n[i]=!sn(e[i],t[i]);return n}var pr=(e,t)=>_d(e,t,Oi(t)),jd=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Ye(e)?e:t?e===""?NaN:e&&+e:n&&Bt(e)?new Date(e):r?r(e):e;function Is(e){const t=e.ref;return Ka(t)?t.files:Ya(t)?wd(e.refs).value:kd(t)?[...t.selectedOptions].map(({value:n})=>n):ti(t)?vd(e.refs).value:jd(Ye(t.value)?e.ref.value:t.value,e)}var Bg=(e,t,n,r)=>{const i={};for(const s of e){const a=ae(t,s);a&&De(i,s,a._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},hr=e=>Ye(e)?e:Pi(e)?e.source:Xe(e)?Pi(e.value)?e.value.source:e.value:e;const Yo="AsyncFunction";var Vg=e=>!!e&&!!e.validate&&!!(Zt(e.validate)&&e.validate.constructor.name===Yo||Xe(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Yo)),Ug=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Xo(e,t,n){const r=ae(e,n);if(r||Wa(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),a=ae(t,s),o=ae(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 Jg=(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,Hg=(e,t)=>!os(ae(e,t)).length&&rt(e,t);const qg={mode:Ot.onSubmit,reValidateMode:Ot.onChange,shouldFocusError:!0};function Wg(e={}){let t={...qg,...e},n={submitCount:0,isDirty:!1,isLoading:Zt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=Xe(t.defaultValues)||Xe(t.values)?mt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:mt(i),a={action:!1,mount:!1,watch:!1},o={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const f={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},d={values:Cs(),array:Cs(),state:Cs()},p=Uo(t.mode),h=Uo(t.reValidateMode),m=t.criteriaMode===Ot.all,w=j=>O=>{clearTimeout(c),c=setTimeout(j,O)},S=async j=>{if(!t.disabled&&(f.isValid||j)){const O=t.resolver?gt((await $()).errors):await N(r,!0);O!==n.isValid&&d.state.next({isValid:O})}},x=(j,O)=>{!t.disabled&&(f.isValidating||f.validatingFields)&&((j||Array.from(o.mount)).forEach(Z=>{Z&&(O?De(n.validatingFields,Z,O):rt(n.validatingFields,Z))}),d.state.next({validatingFields:n.validatingFields,isValidating:!gt(n.validatingFields)}))},_=(j,O=[],Z,re,ee=!0,Q=!0)=>{if(re&&Z&&!t.disabled){if(a.action=!0,Q&&Array.isArray(ae(r,j))){const pe=Z(ae(r,j),re.argA,re.argB);ee&&De(r,j,pe)}if(Q&&Array.isArray(ae(n.errors,j))){const pe=Z(ae(n.errors,j),re.argA,re.argB);ee&&De(n.errors,j,pe),Hg(n.errors,j)}if(f.touchedFields&&Q&&Array.isArray(ae(n.touchedFields,j))){const pe=Z(ae(n.touchedFields,j),re.argA,re.argB);ee&&De(n.touchedFields,j,pe)}f.dirtyFields&&(n.dirtyFields=pr(i,s)),d.state.next({name:j,isDirty:A(j,O),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else De(s,j,O)},g=(j,O)=>{De(n.errors,j,O),d.state.next({errors:n.errors})},z=j=>{n.errors=j,d.state.next({errors:n.errors,isValid:!1})},E=(j,O,Z,re)=>{const ee=ae(r,j);if(ee){const Q=ae(s,j,Ye(Z)?ae(i,j):Z);Ye(Q)||re&&re.defaultChecked||O?De(s,j,O?Q:Is(ee._f)):T(j,Q),a.mount&&S()}},k=(j,O,Z,re,ee)=>{let Q=!1,pe=!1;const ve={name:j};if(!t.disabled){const L=!!(ae(r,j)&&ae(r,j)._f&&ae(r,j)._f.disabled);if(!Z||re){f.isDirty&&(pe=n.isDirty,n.isDirty=ve.isDirty=A(),Q=pe!==ve.isDirty);const G=L||sn(ae(i,j),O);pe=!!(!L&&ae(n.dirtyFields,j)),G||L?rt(n.dirtyFields,j):De(n.dirtyFields,j,!0),ve.dirtyFields=n.dirtyFields,Q=Q||f.dirtyFields&&pe!==!G}if(Z){const G=ae(n.touchedFields,j);G||(De(n.touchedFields,j,Z),ve.touchedFields=n.touchedFields,Q=Q||f.touchedFields&&G!==Z)}Q&&ee&&d.state.next(ve)}return Q?ve:{}},C=(j,O,Z,re)=>{const ee=ae(n.errors,j),Q=f.isValid&&Ct(O)&&n.isValid!==O;if(t.delayError&&Z?(l=w(()=>g(j,Z)),l(t.delayError)):(clearTimeout(c),l=null,Z?De(n.errors,j,Z):rt(n.errors,j)),(Z?!sn(ee,Z):ee)||!gt(re)||Q){const pe={...re,...Q&&Ct(O)?{isValid:O}:{},errors:n.errors,name:j};n={...n,...pe},d.state.next(pe)}},$=async j=>{x(j,!0);const O=await t.resolver(s,t.context,Bg(j||o.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return x(j),O},K=async j=>{const{errors:O}=await $(j);if(j)for(const Z of j){const re=ae(O,Z);re?De(n.errors,Z,re):rt(n.errors,Z)}else n.errors=O;return O},N=async(j,O,Z={valid:!0})=>{for(const re in j){const ee=j[re];if(ee){const{_f:Q,...pe}=ee;if(Q){const ve=o.array.has(Q.name),L=ee._f&&Vg(ee._f);L&&f.validatingFields&&x([re],!0);const G=await Ko(ee,o.disabled,s,m,t.shouldUseNativeValidation&&!O,ve);if(L&&f.validatingFields&&x([re]),G[Q.name]&&(Z.valid=!1,O))break;!O&&(ae(G,Q.name)?ve?$g(n.errors,G,Q.name):De(n.errors,Q.name,G[Q.name]):rt(n.errors,Q.name))}!gt(pe)&&await N(pe,O,Z)}}return Z.valid},I=()=>{for(const j of o.unMount){const O=ae(r,j);O&&(O._f.refs?O._f.refs.every(Z=>!Es(Z)):!Es(O._f.ref))&&ne(j)}o.unMount=new Set},A=(j,O)=>!t.disabled&&(j&&O&&De(s,j,O),!sn(fe(),i)),B=(j,O,Z)=>bd(j,o,{...a.mount?s:Ye(O)?i:Bt(j)?{[j]:O}:O},Z,O),D=j=>os(ae(a.mount?s:i,j,t.shouldUnregister?ae(i,j,[]):[])),T=(j,O,Z={})=>{const re=ae(r,j);let ee=O;if(re){const Q=re._f;Q&&(!Q.disabled&&De(s,j,jd(O,Q)),ee=Ai(Q.ref)&&ct(O)?"":O,kd(Q.ref)?[...Q.ref.options].forEach(pe=>pe.selected=ee.includes(pe.value)):Q.refs?ti(Q.ref)?Q.refs.length>1?Q.refs.forEach(pe=>(!pe.defaultChecked||!pe.disabled)&&(pe.checked=Array.isArray(ee)?!!ee.find(ve=>ve===pe.value):ee===pe.value)):Q.refs[0]&&(Q.refs[0].checked=!!ee):Q.refs.forEach(pe=>pe.checked=pe.value===ee):Ka(Q.ref)?Q.ref.value="":(Q.ref.value=ee,Q.ref.type||d.values.next({name:j,values:{...s}})))}(Z.shouldDirty||Z.shouldTouch)&&k(j,ee,Z.shouldTouch,Z.shouldDirty,!0),Z.shouldValidate&&v(j)},P=(j,O,Z)=>{for(const re in O){const ee=O[re],Q=`${j}.${re}`,pe=ae(r,Q);(o.array.has(j)||Xe(ee)||pe&&!pe._f)&&!kn(ee)?P(Q,ee,Z):T(Q,ee,Z)}},J=(j,O,Z={})=>{const re=ae(r,j),ee=o.array.has(j),Q=mt(O);De(s,j,Q),ee?(d.array.next({name:j,values:{...s}}),(f.isDirty||f.dirtyFields)&&Z.shouldDirty&&d.state.next({name:j,dirtyFields:pr(i,s),isDirty:A(j,Q)})):re&&!re._f&&!ct(Q)?P(j,Q,Z):T(j,Q,Z),Jo(j,o)&&d.state.next({...n}),d.values.next({name:a.mount?j:void 0,values:{...s}})},R=async j=>{a.mount=!0;const O=j.target;let Z=O.name,re=!0;const ee=ae(r,Z),Q=()=>O.type?Is(ee._f):fd(j),pe=ve=>{re=Number.isNaN(ve)||kn(ve)&&isNaN(ve.getTime())||sn(ve,ae(s,Z,ve))};if(ee){let ve,L;const G=Q(),he=j.type===Ti.BLUR||j.type===Ti.FOCUS_OUT,Se=!Ug(ee._f)&&!t.resolver&&!ae(n.errors,Z)&&!ee._f.deps||Jg(he,ae(n.touchedFields,Z),n.isSubmitted,h,p),M=Jo(Z,o,he);De(s,Z,G),he?(ee._f.onBlur&&ee._f.onBlur(j),l&&l(0)):ee._f.onChange&&ee._f.onChange(j);const me=k(Z,G,he,!1),Ce=!gt(me)||M;if(!he&&d.values.next({name:Z,type:j.type,values:{...s}}),Se)return f.isValid&&(t.mode==="onBlur"&&he?S():he||S()),Ce&&d.state.next({name:Z,...M?{}:me});if(!he&&M&&d.state.next({...n}),t.resolver){const{errors:$e}=await $([Z]);if(pe(G),re){const nt=Xo(n.errors,r,Z),et=Xo($e,r,nt.name||Z);ve=et.error,Z=et.name,L=gt($e)}}else x([Z],!0),ve=(await Ko(ee,o.disabled,s,m,t.shouldUseNativeValidation))[Z],x([Z]),pe(G),re&&(ve?L=!1:f.isValid&&(L=await N(r,!0)));re&&(ee._f.deps&&v(ee._f.deps),C(Z,L,ve,me))}},q=(j,O)=>{if(ae(n.errors,O)&&j.focus)return j.focus(),1},v=async(j,O={})=>{let Z,re;const ee=zr(j);if(t.resolver){const Q=await K(Ye(j)?j:ee);Z=gt(Q),re=j?!ee.some(pe=>ae(Q,pe)):Z}else j?(re=(await Promise.all(ee.map(async Q=>{const pe=ae(r,Q);return await N(pe&&pe._f?{[Q]:pe}:pe)}))).every(Boolean),!(!re&&!n.isValid)&&S()):re=Z=await N(r);return d.state.next({...!Bt(j)||f.isValid&&Z!==n.isValid?{}:{name:j},...t.resolver||!j?{isValid:Z}:{},errors:n.errors}),O.shouldFocus&&!re&&Tr(r,q,j?ee:o.mount),re},fe=j=>{const O={...a.mount?s:i};return Ye(j)?O:Bt(j)?ae(O,j):j.map(Z=>ae(O,Z))},ue=(j,O)=>({invalid:!!ae((O||n).errors,j),isDirty:!!ae((O||n).dirtyFields,j),error:ae((O||n).errors,j),isValidating:!!ae(n.validatingFields,j),isTouched:!!ae((O||n).touchedFields,j)}),b=j=>{j&&zr(j).forEach(O=>rt(n.errors,O)),d.state.next({errors:j?n.errors:{}})},Y=(j,O,Z)=>{const re=(ae(r,j,{_f:{}})._f||{}).ref,ee=ae(n.errors,j)||{},{ref:Q,message:pe,type:ve,...L}=ee;De(n.errors,j,{...L,...O,ref:re}),d.state.next({name:j,errors:n.errors,isValid:!1}),Z&&Z.shouldFocus&&re&&re.focus&&re.focus()},oe=(j,O)=>Zt(j)?d.values.subscribe({next:Z=>j(B(void 0,O),Z)}):B(j,O,!0),ne=(j,O={})=>{for(const Z of j?zr(j):o.mount)o.mount.delete(Z),o.array.delete(Z),O.keepValue||(rt(r,Z),rt(s,Z)),!O.keepError&&rt(n.errors,Z),!O.keepDirty&&rt(n.dirtyFields,Z),!O.keepTouched&&rt(n.touchedFields,Z),!O.keepIsValidating&&rt(n.validatingFields,Z),!t.shouldUnregister&&!O.keepDefaultValue&&rt(i,Z);d.values.next({values:{...s}}),d.state.next({...n,...O.keepDirty?{isDirty:A()}:{}}),!O.keepIsValid&&S()},ie=({disabled:j,name:O,field:Z,fields:re})=>{(Ct(j)&&a.mount||j||o.disabled.has(O))&&(j?o.disabled.add(O):o.disabled.delete(O),k(O,Is(Z?Z._f:ae(re,O)._f),!1,!1,!0))},W=(j,O={})=>{let Z=ae(r,j);const re=Ct(O.disabled)||Ct(t.disabled);return De(r,j,{...Z||{},_f:{...Z&&Z._f?Z._f:{ref:{name:j}},name:j,mount:!0,...O}}),o.mount.add(j),Z?ie({field:Z,disabled:Ct(O.disabled)?O.disabled:t.disabled,name:j}):E(j,!0,O.value),{...re?{disabled:O.disabled||t.disabled}:{},...t.progressive?{required:!!O.required,min:hr(O.min),max:hr(O.max),minLength:hr(O.minLength),maxLength:hr(O.maxLength),pattern:hr(O.pattern)}:{},name:j,onChange:R,onBlur:R,ref:ee=>{if(ee){W(j,O),Z=ae(r,j);const Q=Ye(ee.value)&&ee.querySelectorAll&&ee.querySelectorAll("input,select,textarea")[0]||ee,pe=Zg(Q),ve=Z._f.refs||[];if(pe?ve.find(L=>L===Q):Q===Z._f.ref)return;De(r,j,{_f:{...Z._f,...pe?{refs:[...ve.filter(Es),Q,...Array.isArray(ae(i,j))?[{}]:[]],ref:{type:Q.type,name:j}}:{ref:Q}}}),E(j,!1,void 0,Q)}else Z=ae(r,j,{}),Z._f&&(Z._f.mount=!1),(t.shouldUnregister||O.shouldUnregister)&&!(pd(o.array,j)&&a.action)&&o.unMount.add(j)}}},F=()=>t.shouldFocusError&&Tr(r,q,o.mount),te=j=>{Ct(j)&&(d.state.next({disabled:j}),Tr(r,(O,Z)=>{const re=ae(r,Z);re&&(O.disabled=re._f.disabled||j,Array.isArray(re._f.refs)&&re._f.refs.forEach(ee=>{ee.disabled=re._f.disabled||j}))},0,!1))},V=(j,O)=>async Z=>{let re;Z&&(Z.preventDefault&&Z.preventDefault(),Z.persist&&Z.persist());let ee=mt(s);if(o.disabled.size)for(const Q of o.disabled)De(ee,Q,void 0);if(d.state.next({isSubmitting:!0}),t.resolver){const{errors:Q,values:pe}=await $();n.errors=Q,ee=pe}else await N(r);if(rt(n.errors,"root"),gt(n.errors)){d.state.next({errors:{}});try{await j(ee,Z)}catch(Q){re=Q}}else O&&await O({...n.errors},Z),F(),setTimeout(F);if(d.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:gt(n.errors)&&!re,submitCount:n.submitCount+1,errors:n.errors}),re)throw re},de=(j,O={})=>{ae(r,j)&&(Ye(O.defaultValue)?J(j,mt(ae(i,j))):(J(j,O.defaultValue),De(i,j,mt(O.defaultValue))),O.keepTouched||rt(n.touchedFields,j),O.keepDirty||(rt(n.dirtyFields,j),n.isDirty=O.defaultValue?A(j,mt(ae(i,j))):A()),O.keepError||(rt(n.errors,j),f.isValid&&S()),d.state.next({...n}))},le=(j,O={})=>{const Z=j?mt(j):i,re=mt(Z),ee=gt(j),Q=ee?i:re;if(O.keepDefaultValues||(i=Z),!O.keepValues){if(O.keepDirtyValues){const pe=new Set([...o.mount,...Object.keys(pr(i,s))]);for(const ve of Array.from(pe))ae(n.dirtyFields,ve)?De(Q,ve,ae(s,ve)):J(ve,ae(Q,ve))}else{if(qa&&Ye(j))for(const pe of o.mount){const ve=ae(r,pe);if(ve&&ve._f){const L=Array.isArray(ve._f.refs)?ve._f.refs[0]:ve._f.ref;if(Ai(L)){const G=L.closest("form");if(G){G.reset();break}}}}r={}}s=t.shouldUnregister?O.keepDefaultValues?mt(i):{}:mt(Q),d.array.next({values:{...Q}}),d.values.next({values:{...Q}})}o={mount:O.keepDirtyValues?o.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},a.mount=!f.isValid||!!O.keepIsValid||!!O.keepDirtyValues,a.watch=!!t.shouldUnregister,d.state.next({submitCount:O.keepSubmitCount?n.submitCount:0,isDirty:ee?!1:O.keepDirty?n.isDirty:!!(O.keepDefaultValues&&!sn(j,i)),isSubmitted:O.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ee?{}:O.keepDirtyValues?O.keepDefaultValues&&s?pr(i,s):n.dirtyFields:O.keepDefaultValues&&j?pr(i,j):O.keepDirty?n.dirtyFields:{},touchedFields:O.keepTouched?n.touchedFields:{},errors:O.keepErrors?n.errors:{},isSubmitSuccessful:O.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},ye=(j,O)=>le(Zt(j)?j(s):j,O);return{control:{register:W,unregister:ne,getFieldState:ue,handleSubmit:V,setError:Y,_executeSchema:$,_getWatch:B,_getDirty:A,_updateValid:S,_removeUnmounted:I,_updateFieldArray:_,_updateDisabledField:ie,_getFieldArray:D,_reset:le,_resetDefaultValues:()=>Zt(t.defaultValues)&&t.defaultValues().then(j=>{ye(j,t.resetOptions),d.state.next({isLoading:!1})}),_updateFormState:j=>{n={...n,...j}},_disableForm:te,_subjects:d,_proxyFormState:f,_setErrors:z,get _fields(){return r},get _formValues(){return s},get _state(){return a},set _state(j){a=j},get _defaultValues(){return i},get _names(){return o},set _names(j){o=j},get _formState(){return n},set _formState(j){n=j},get _options(){return t},set _options(j){t={...t,...j}}},trigger:v,register:W,handleSubmit:V,watch:oe,setValue:J,getValues:fe,reset:ye,resetField:de,clearErrors:b,unregister:ne,setError:Y,setFocus:(j,O={})=>{const Z=ae(r,j),re=Z&&Z._f;if(re){const ee=re.refs?re.refs[0]:re.ref;ee.focus&&(ee.focus(),O.shouldSelect&&Zt(ee.select)&&ee.select())}},getFieldState:ue}}function Gg(e={}){const t=Ee.useRef(void 0),n=Ee.useRef(void 0),[r,i]=Ee.useState({isDirty:!1,isValidating:!1,isLoading:Zt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Zt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Wg(e),formState:r});const s=t.current.control;return s._options=e,Ga({subject:s._subjects.state,next:a=>{xd(a,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),Ee.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),Ee.useEffect(()=>{if(s._proxyFormState.isDirty){const a=s._getDirty();a!==r.isDirty&&s._subjects.state.next({isDirty:a})}},[s,r.isDirty]),Ee.useEffect(()=>{e.values&&!sn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(a=>({...a}))):s._resetDefaultValues()},[e.values,s]),Ee.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),Ee.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()}),Ee.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=gd(r,s),t.current}function Kg(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 Yg=Ag,Nd=y.createContext({}),Qo=({...e})=>u.jsx(Nd.Provider,{value:{name:e.name},children:u.jsx(Rg,{...e})}),us=()=>{const e=y.useContext(Nd),t=y.useContext(Cd),{getFieldState:n,formState:r}=ls(),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}},Cd=y.createContext({}),ha=y.forwardRef(({className:e,...t},n)=>{const r=y.useId();return u.jsx(Cd.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:H("space-y-2",e),...t})})});ha.displayName="FormItem";const ma=y.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=us();return u.jsx(Gn,{ref:n,className:H(r&&"text-destructive",e),htmlFor:i,...t})});ma.displayName="FormLabel";const ga=y.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=us();return u.jsx(or,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});ga.displayName="FormControl";const Ed=y.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=us();return u.jsx("p",{ref:n,id:r,className:H("text-muted-foreground text-[0.8rem]",e),...t})});Ed.displayName="FormDescription";const xa=y.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=us(),a=i?String(i==null?void 0:i.message):t;return a?u.jsx("p",{ref:r,id:s,className:H("text-destructive text-[0.8rem] font-medium",e),...n,children:a}):null});xa.displayName="FormMessage";function Xa(){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 Id=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Xg=(e=Id())=>yg()(bg(vg((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:Xa(),messages:[],createdAt:s,updatedAt:s};return t(o=>({threads:{...o.threads,[i]:a},activeThreadId:{...o.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const a=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),o=s.documentName,l={...i.activeThreadId};if(l[o]===r){const c=Object.values(a).filter(f=>f.documentName===o);c.length>0?(c.sort((f,d)=>d.updatedAt-f.updatedAt),l[o]=c[0].id):delete l[o]}t({threads:a,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(a=>({activeThreadId:{...a.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const a=s.threads[r];return a?{threads:{...s.threads,[r]:{...a,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},a={...i.activeThreadId};for(const[o,l]of Object.entries(s))l.documentName===r&&delete s[o];return delete a[r],{threads:s,activeThreadId:a}})},renameThreadsForDocument:(r,i)=>{t(s=>{const a={...s.threads},o={...s.activeThreadId};for(const[l,c]of Object.entries(a))c.documentName===r&&(a[l]={...c,documentName:i});return r in o&&(o[i]=o[r],delete o[r]),{threads:a,activeThreadId:o}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:wg(()=>fg),partialize:t=>({threads:t.threads,activeThreadId:t.activeThreadId,scope:t.scope,model:t.model}),migrate:(t,n)=>{if(n===0&&t){const r=t.chatMessages;if(Array.isArray(r)&&r.length>0){const i=crypto.randomUUID(),s=Date.now();return{threads:{[i]:{id:i,documentName:"__migrated__",title:"Migrated Chat",messages:r,createdAt:s,updatedAt:s}},activeThreadId:{__migrated__:i}}}return{threads:{},activeThreadId:{}}}return t}}))),zd=y.createContext(void 0),Qg=({children:e})=>{const t=y.useRef(null);return t.current||(t.current=Xg(Id())),u.jsx(zd.Provider,{value:t.current,children:e})},Te=e=>{const t=y.useContext(zd);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return kg(t,e)};function ex(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function tx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=oi.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),i.push("name")),e==="create"&&(r.template=oi.Optional(oi.String({description:"Template selection"})));const s=oi.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:a=>{const o=[];if(!Dm(s,a))for(const c of Rm(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 nx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const rx=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"}}),mr="__empty__";function ix({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:a}){const[o,l]=y.useState(!1),[c,f]=y.useState(null),d=rx(a),{documents:p,openTabs:h,createDocument:m,renameDocument:w,deleteDocument:S,openDocument:x,closeDocument:_}=Ae(R=>R),{updateTheme:g,removeTheme:z}=da(R=>R),E=Te(R=>R.renameThreadsForDocument),k=Te(R=>R.deleteThreadsForDocument),C=y.useMemo(()=>a?s||[]:i||[],[a,i,s]),$=y.useMemo(()=>{const R={current:[],downstream:[]};return C.forEach(q=>{R[q.location]&&R[q.location].push(q)}),R},[C]),K=y.useMemo(()=>C.map(R=>({name:R.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[C]),N=y.useMemo(()=>tx(e,R=>ex(R,p,r),K),[e,p,r,K]),I=N.schema,A=y.useMemo(()=>{const R=new Map;return C.forEach(q=>R.set(q.path,q)),R},[C]),B=mr,D=Gg({resolver:Kg(N.validate),defaultValues:nx(e,void 0,r)}),[T,P]=y.useState(B);y.useEffect(()=>{if(T&&T!==mr&&e==="create"){const R=A.get(T);R&&fetch(`/api/discovery/${a?"themes":"documents"}/${encodeURIComponent(R.name)}/content`).then(q=>{if(!q.ok)throw new Error(`Failed to fetch content: ${q.statusText}`);return q.text()}).then(q=>{try{const v=JSON.parse(q);f(JSON.stringify(v,null,2))}catch(v){console.error("Invalid JSON content received:",v),f(null)}}).catch(q=>{console.error("Failed to fetch content:",q),f(null)})}},[T,e,A,a]),y.useEffect(()=>{t&&(D.reset(),f(null),P(B))},[D,t]);const J=D.handleSubmit(async({name:R,template:q})=>{l(!0);try{if(await new Promise(v=>setTimeout(v,200)),e==="create"){const v=T?A.get(T):C.find(W=>W.name===q);let fe,ue=R;if(a){const W=ue.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-");fe=c||JSON.stringify(yt==="docx"?{name:W,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:{family:"Calibri",size:28},body:{family:"Calibri",size:11}},page:{size:"A4"}}:{name:W,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}},null,2);const te=`.${yt}.theme.json`;ue.endsWith(te)||(ue=ue.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),ue+=te)}else{const W=v;fe=c||JSON.stringify(yt==="docx"?{name:"docx",props:{theme:(W==null?void 0:W.theme)||"default",metadata:{title:(W==null?void 0:W.title)||ue.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(W==null?void 0:W.title)||ue.replace(/\.(json|js)$/i,""),theme:(W==null?void 0:W.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 F=yt==="docx"?".docx.json":".pptx.json";!ue.endsWith(F)&&!ue.endsWith(".json")&&(ue+=F)}const b=ue.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),Y=b?b[0]:"",oe=ue.slice(0,ue.length-Y.length);let ne=ue,ie=1;for(;p.some(W=>W.name===ne);)ie++,ne=`${oe} (${ie})${Y}`;ue=ne,m(ue,fe),x(ue),a&&g(ue,fe)}else if(e==="update"){const v=r,fe=R,ue=h.includes(v);ue&&_(v),w(v,fe),E(v,fe),ue&&x(fe)}else if(e==="delete"){const v=r;_(v),S(v),k(v),a&&z(v)}n()}finally{l(!1)}});return u.jsx(Yg,{...D,children:u.jsxs("form",{onSubmit:J,children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:d[e].title}),u.jsx(cn,{children:d[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[I.properties&&"name"in I.properties&&u.jsx(Qo,{control:D.control,name:"name",render:({field:R})=>u.jsxs(ha,{children:[u.jsx(ma,{children:"Name"}),u.jsx(ga,{children:u.jsx(ei,{placeholder:"Enter a name or select a template below",autoComplete:"off",...R})}),u.jsx(xa,{})]})}),e==="create"&&u.jsx(Qo,{control:D.control,name:"template",render:({field:R})=>u.jsxs(ha,{children:[u.jsx(ma,{children:a?"Base Theme":"Base Document"}),u.jsxs(Rr,{onValueChange:q=>{if(q===mr)R.onChange(void 0),D.setValue("name",""),P(mr),f(null);else{const v=A.get(q);v&&(R.onChange(v.name),D.setValue("name",v.name),P(q))}},defaultValue:B,children:[u.jsx(ga,{children:u.jsx(er,{children:u.jsx(Mr,{placeholder:`Select a discovered ${a?"theme":"document"}`})})}),u.jsxs(tr,{className:"max-h-[300px]",children:[u.jsxs(En,{value:mr,children:["Empty ",a?"theme":"document"]}),Object.entries($).map(([q,v])=>v.length===0?null:u.jsxs(jg,{children:[u.jsx(cd,{children:q==="current"?"📁 Current Directory":"📦 Project"}),v.map(fe=>{let ue;return fe.title&&fe.title!==fe.name?ue=fe.title:fe.description&&(ue=fe.description.length>40?fe.description.substring(0,40)+"...":fe.description),u.jsx(En,{value:fe.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:fe.name}),ue&&u.jsx("span",{className:"text-muted-foreground text-xs",children:ue})]})},fe.path)})]},q))]})]}),u.jsxs(Ed,{children:["Start empty or select a discovered"," ",a?"theme":"document"," as a starting point"]}),u.jsx(xa,{})]})})]}),u.jsx(Cn,{children:u.jsx(we,{type:"submit",variant:d[e].buttonVariant,disabled:o,children:o?u.jsxs(u.Fragment,{children:[u.jsx(Yt,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):d[e].button})})]})})}const Di=Ee.memo(ix),sx=vm,ax=wm,ox=y.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(jc,{ref:i,className:H("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(ss,{className:"ml-auto h-4 w-4"})]}));ox.displayName=jc.displayName;const lx=y.forwardRef(({className:e,...t},n)=>u.jsx(Nc,{ref:n,className:H("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-md border p-1 shadow-lg",e),...t}));lx.displayName=Nc.displayName;const Td=y.forwardRef(({className:e,...t},n)=>u.jsx(km,{children:u.jsx(kc,{ref:n,className:H("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-md border p-1 shadow-md",e),...t})}));Td.displayName=kc.displayName;const kr=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Sc,{ref:r,className:H("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}));kr.displayName=Sc.displayName;const ux=y.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Cc,{ref:i,className:H("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(Ec,{children:u.jsx(un,{className:"h-4 w-4"})})}),t]}));ux.displayName=Cc.displayName;const cx=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ic,{ref:r,className:H("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(Ec,{children:u.jsx(Kc,{className:"h-4 w-4 fill-current"})})}),t]}));cx.displayName=Ic.displayName;const dx=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(zc,{ref:r,className:H("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));dx.displayName=zc.displayName;const ya=y.forwardRef(({className:e,...t},n)=>u.jsx(_c,{ref:n,className:H("bg-border -mx-1 my-1 h-px",e),...t}));ya.displayName=_c.displayName;const ki=({className:e,...t})=>u.jsx("span",{className:H("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});ki.displayName="ContextMenuShortcut";const Ad=y.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(Tc,{ref:i,decorative:n,orientation:t,className:H("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Ad.displayName=Tc.displayName;const Pd=dc,fx=fc,px=pc,Od=y.forwardRef(({className:e,...t},n)=>u.jsx(is,{className:H("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/80",e),...t,ref:n}));Od.displayName=is.displayName;const hx=Qr("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"}}),Qa=y.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(px,{children:[u.jsx(Od,{}),u.jsxs(ts,{ref:i,className:H(hx({side:e}),t),...r,children:[u.jsxs(Ja,{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(Nn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));Qa.displayName=ts.displayName;const mx=y.forwardRef(({className:e,...t},n)=>u.jsx(ns,{ref:n,className:H("text-foreground text-lg font-semibold",e),...t}));mx.displayName=ns.displayName;const gx=y.forwardRef(({className:e,...t},n)=>u.jsx(rs,{ref:n,className:H("text-muted-foreground text-sm",e),...t}));gx.displayName=rs.displayName;function Ar({className:e,...t}){return u.jsx("div",{className:H("bg-primary/10 animate-pulse rounded-md",e),...t})}const zs=768,Ts=1200;function Dd(e){return typeof window<"u"?window.innerWidth<e:!1}function Rd(){const[e,t]=y.useState(()=>Dd(zs));return y.useEffect(()=>{const n=window.matchMedia(`(max-width: ${zs-1}px)`),r=()=>{t(window.innerWidth<zs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function xx(){const[e,t]=y.useState(()=>Dd(Ts));return y.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ts-1}px)`),r=()=>{t(window.innerWidth<Ts)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const yx="sidebar_state",bx=60*60*24*7,vx="16rem",wx="18rem",kx="3rem",Sx="b",Md=y.createContext(null);function cs(){const e=y.useContext(Md);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const $d=y.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...a},o)=>{const l=Rd(),[c,f]=y.useState(!1),[d,p]=y.useState(e),h=t??d,m=y.useCallback(_=>{const g=typeof _=="function"?_(h):_;n?n(g):p(g),document.cookie=`${yx}=${g}; path=/; max-age=${bx}`},[n,h]),w=y.useCallback(()=>l?f(_=>!_):m(_=>!_),[l,m,f]);y.useEffect(()=>{const _=z=>{var C;const E=z;if(!E)return!1;const k=(C=E.tagName)==null?void 0:C.toLowerCase();return k==="input"||k==="textarea"||k==="select"||E.isContentEditable?!0:!!(E.closest&&E.closest(".monaco-editor"))},g=z=>{const E=z.metaKey||z.ctrlKey,k=z.key.toLowerCase();if(E&&k===Sx){z.preventDefault(),w();return}E&&k==="s"&&!_(z.target)&&(z.preventDefault(),w())};return window.addEventListener("keydown",g),()=>window.removeEventListener("keydown",g)},[w]);const S=h?"expanded":"collapsed",x=y.useMemo(()=>({state:S,open:h,setOpen:m,isMobile:l,openMobile:c,setOpenMobile:f,toggleSidebar:w}),[S,h,m,l,c,f,w]);return u.jsx(Md.Provider,{value:x,children:u.jsx(Mm,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":vx,"--sidebar-width-icon":kx,...i},className:H("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:o,...a,children:s})})})});$d.displayName="SidebarProvider";const Fd=y.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},a)=>{const{isMobile:o,state:l,openMobile:c,setOpenMobile:f}=cs();return n==="none"?u.jsx("div",{className:H("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:a,...s,children:i}):o?u.jsx(Pd,{open:c,onOpenChange:f,...s,children:u.jsx(Qa,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":wx},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:H("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:H("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})})]})});Fd.displayName="Sidebar";const _x=y.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=cs();return u.jsxs(we,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:H("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(Um,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});_x.displayName="SidebarTrigger";const jx=y.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:H("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})});jx.displayName="SidebarRail";const Nx=y.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:H("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}));Nx.displayName="SidebarInset";const Cx=y.forwardRef(({className:e,...t},n)=>u.jsx(ei,{ref:n,"data-sidebar":"input",className:H("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));Cx.displayName="SidebarInput";const Ld=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:H("flex flex-col gap-2 p-2",e),...t}));Ld.displayName="SidebarHeader";const Zd=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:H("flex flex-col gap-2 p-2",e),...t}));Zd.displayName="SidebarFooter";const Bd=y.forwardRef(({className:e,...t},n)=>u.jsx(Ad,{ref:n,"data-sidebar":"separator",className:H("bg-sidebar-border mx-2 w-auto",e),...t}));Bd.displayName="SidebarSeparator";const Vd=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:H("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Vd.displayName="SidebarContent";const Si=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:H("relative flex w-full min-w-0 flex-col p-2",e),...t}));Si.displayName="SidebarGroup";const _i=y.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?or:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:H("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})});_i.displayName="SidebarGroupLabel";const Ex=y.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?or:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:H("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})});Ex.displayName="SidebarGroupAction";const Sr=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:H("w-full text-sm",e),...t}));Sr.displayName="SidebarGroupContent";const ba=y.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:H("flex w-full min-w-0 flex-col gap-1",e),...t}));ba.displayName="SidebarMenu";const Ud=y.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:H("group/menu-item relative",e),...t}));Ud.displayName="SidebarMenuItem";const Ix=Qr("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"}}),Jd=y.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...a},o)=>{const l=e?or:"button",{isMobile:c,state:f}=cs(),d=u.jsx(l,{ref:o,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:H(Ix({variant:n,size:r}),s),...a});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:d}),u.jsx(Ke,{side:"right",align:"center",hidden:f!=="collapsed"||c,...i})]})):d});Jd.displayName="SidebarMenuButton";const zx=y.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?or:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:H("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})});zx.displayName="SidebarMenuAction";const Tx=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:H("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}));Tx.displayName="SidebarMenuBadge";const Ax=y.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=y.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:H("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Ar,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Ar,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Ax.displayName="SidebarMenuSkeleton";const Px=y.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:H("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}));Px.displayName="SidebarMenuSub";const Ox=y.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));Ox.displayName="SidebarMenuSubItem";const Dx=y.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const a=e?or:"a";return u.jsx(a,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:H("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})});Dx.displayName="SidebarMenuSubButton";function ji(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 Rx=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Mx({document:e,indicator:t,compact:n=!1}){const r=y.useRef(null),[i,s]=y.useState(!1),[a,o]=y.useState(!1),[l,c]=y.useState(!1),{openDocument:f,documentTypes:d,activeTab:p}=Ae(T=>T),{name:h,text:m,isGenerating:w}=vn(T=>T),x=(d[e.name]||"application/json+report")==="application/json+theme",_=p===e.name,[g,z]=y.useState(h),[E,k]=y.useState(m),C=100,$=0;y.useEffect(()=>{const T=setTimeout(()=>{h&&m?(z(h),k(m)):w||(z(""),k(""))},w?C:$);return()=>clearTimeout(T)},[h,m,w]);const K=g===e.name,N=T=>{var J;const P=new Set;try{const R=JSON.parse(T);(J=R.props)!=null&&J.theme&&P.add(R.props.theme),R.children&&Array.isArray(R.children)&&R.children.forEach(q=>{var v;q.name==="docx"&&((v=q.props)!=null&&v.theme)&&P.add(q.props.theme)})}catch{}return P},I=y.useMemo(()=>{if(!x||!E)return!1;try{const T=JSON.parse(e.text),P=fa(T);if(P)return N(E).has(P)}catch{}return!1},[x,E,e.text,e.name,g]),A=y.useCallback(()=>{o(!1)},[]),B=y.useCallback(()=>{c(!1)},[]),D=u.jsxs(Jd,{variant:"default",size:"default",ref:r,className:H("text-sidebar-foreground focus:bg-accent focus:text-accent-foreground w-full",n?"justify-center px-1":"justify-start gap-2",i&&"bg-accent text-accent-foreground",_&&(n?"bg-green-50 text-green-700 dark:bg-green-900/20 dark:text-green-300":"bg-green-50 border-l-2 border-green-500 text-green-700 dark:bg-green-900/20 dark:border-green-400 dark:text-green-300"),K&&!_&&(n?"bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-300":"bg-blue-50 border-l-2 border-blue-500 text-blue-700 dark:bg-blue-900/20 dark:border-blue-400 dark:text-blue-300"),I&&!_&&!K&&(n?"bg-purple-50 text-purple-700 dark:bg-purple-900/20 dark:text-purple-300":"bg-purple-50 border-l-2 border-purple-500 text-purple-700 dark:bg-purple-900/20 dark:border-purple-400 dark:text-purple-300")),title:e.name,onClick:()=>{f(e.name)},onKeyDown:T=>{var P;(T.ctrlKey||T.metaKey)&&T.key==="Enter"?(f(e.name),T.preventDefault()):T.key==="Enter"?(o(!0),T.preventDefault()):T.key==="Backspace"||T.key==="Delete"?(c(!0),T.preventDefault()):T.key==="Escape"&&((P=r.current)==null||P.blur(),T.preventDefault())},children:[_?u.jsx($o,{className:H("size-4","text-green-600 dark:text-green-400")}):K?u.jsx($o,{className:H("size-4","text-blue-600 dark:text-blue-400")}):x?u.jsx(la,{className:"size-4 text-purple-600 dark:text-purple-400"}):u.jsx(Yc,{className:"size-4 text-blue-600 dark:text-blue-400"}),!n&&u.jsx("span",{className:H("truncate flex-1",x&&!_&&!K&&!I&&"text-purple-700 dark:text-purple-300",(_||K||I)&&"font-medium"),children:e.name})]});return u.jsxs(Ud,{children:[u.jsxs(sx,{onOpenChange:s,children:[u.jsx(ax,{children:n?u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:D}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[e.name,x?u.jsx("div",{className:"opacity-70",children:"Theme"}):u.jsx("div",{className:"opacity-70",children:"Document"})]})})]}):D}),u.jsxs(Td,{children:[u.jsxs(kr,{onClick:()=>f(e.name),children:["Open",u.jsx(ki,{children:Rx?"⌘⏎":"⌃⏎"})]}),u.jsx(ya,{}),u.jsx(kr,{disabled:!e,onClick:()=>{e&&ji(e.name,new Blob([e.text],{type:e.type}))},children:"Download..."}),u.jsx(ya,{}),u.jsxs(kr,{onClick:()=>o(!0),children:["Rename...",u.jsx(ki,{children:"⏎"})]}),u.jsxs(kr,{onClick:()=>c(!0),children:["Delete",u.jsx(ki,{children:"⌫"})]})]})]}),u.jsx(It,{open:a,onOpenChange:o,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:T=>{var P;T.preventDefault(),(P=r.current)==null||P.focus()},children:u.jsx(Di,{mode:"update",shouldReset:!a,postSubmit:A,selectedName:e.name})})}),u.jsx(It,{open:l,onOpenChange:c,children:u.jsx(St,{className:"sm:max-w-[425px]",onCloseAutoFocus:T=>{var P;T.preventDefault(),(P=r.current)==null||P.focus()},children:u.jsx(Di,{mode:"delete",shouldReset:!l,postSubmit:B,selectedName:e.name})})})]})}const el=Ee.memo(Mx);async function $x(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const $r=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Ac,{ref:r,className:H("relative overflow-hidden",e),...n,children:[u.jsx(Sm,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Hd,{}),u.jsx(_m,{})]}));$r.displayName=Ac.displayName;const Hd=y.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(Pc,{ref:r,orientation:t,className:H("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(jm,{className:"bg-border relative flex-1 rounded-full"})}));Hd.displayName=Pc.displayName;function eo({className:e,...t}){return u.jsx(Nm,{"data-slot":"switch",className:H("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:u.jsx(Cm,{"data-slot":"switch-thumb",className:H("bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const Fx=Qr("relative w-full rounded-lg 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-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),Ri=y.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:H(Fx({variant:t}),e),...n}));Ri.displayName="Alert";const Lx=y.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:H("mb-1 font-medium leading-none tracking-tight",e),...t}));Lx.displayName="AlertTitle";const Mi=y.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:H("text-sm [&_p]:leading-relaxed",e),...t}));Mi.displayName="AlertDescription";const $i=y.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=y.useState(n<2),a=t!==null&&typeof t=="object",o=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-orange-500",children:"null"}):t===void 0?u.jsx("span",{className:"text-gray-500",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-blue-500",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-green-500",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-purple-500",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-cyan-500",children:['"',t,'"']}):u.jsxs("span",{className:"text-amber-600",children:['"',t,'"']}):null,f=a?Object.keys(t).length:0;return u.jsxs("div",{className:H("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded px-1 py-0.5",children:[a&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(on,{className:"h-3 w-3"}):u.jsx(ss,{className:"h-3 w-3"})}),!a&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-blue-600 dark:text-blue-400",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),a?u.jsxs("span",{className:"text-muted-foreground",children:[o?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[f," ",o?"items":"properties"]}),!i&&(o?"]":"}")]}):c(),!a&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),a&&i&&u.jsxs("div",{className:"ml-4",children:[o?t.map((d,p)=>u.jsx($i,{keyName:String(p),value:d,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([d,p],h,m)=>u.jsx($i,{keyName:d,value:p,depth:n+1,isLast:h===m.length-1},d)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[o?"]":"}",!r&&","]})})]})]})});$i.displayName="JsonNode";const Fi=y.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:H("space-y-4",r),children:[u.jsx(Ar,{className:"h-8 w-64"}),u.jsx(Ar,{className:"h-4 w-full"}),u.jsx(Ar,{className:"h-64 w-full"})]}):n?u.jsx(Ri,{variant:"destructive",className:r,children:u.jsx(Mi,{children:n})}):e?u.jsx($r,{className:H("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($i,{value:e})})}):u.jsx(Ri,{className:r,children:u.jsx(Mi,{children:"No schema available"})}));Fi.displayName="SchemaViewer";function Zx({plugins:e,initialFocusedPlugin:t}){var g,z;const n=Dt(E=>E.togglePlugin),r=Dt(E=>E.isPluginSelected),i=Dt(E=>E.selectedPlugins),s=Dt(E=>E.isApplyingPlugins),[a,o]=y.useState(null),[l,c]=y.useState(null),[f,d]=y.useState("properties");y.useEffect(()=>{if(t){const E=e.find(k=>k.name===t);if(E){o(E);return}}e.length>0&&!a&&o(e[0])},[t,e]);const p=y.useMemo(()=>{const E={current:[],downstream:[],upstream:[]};return e.forEach(k=>{E[k.location]&&E[k.location].push(k)}),E},[e]),h=async(E,k)=>{a&&(await $x(a.name,E.props),c(k),setTimeout(()=>c(null),2e3))},m=E=>{switch(E){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return E}},w=E=>{switch(E){case"current":return u.jsx(Gm,{className:"size-3"});case"downstream":return u.jsx(Wm,{className:"size-3"});case"upstream":return u.jsx(Yc,{className:"size-3"});default:return null}},S=((g=a==null?void 0:a.schema)==null?void 0:g.properties)&&Object.keys(a.schema.properties).length>0,x=(z=a==null?void 0:a.schema)==null?void 0:z.jsonSchema,_=(a==null?void 0:a.examples)&&a.examples.length>0;return u.jsxs(u.Fragment,{children:[u.jsxs(Ut,{children:[u.jsxs(Jt,{className:"flex items-center gap-2",children:[u.jsx(Xc,{className:"size-5 text-amber-600 dark:text-amber-400"}),"Plugins",u.jsxs(Vt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(cn,{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($r,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(p).map(([E,k])=>k.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[w(E),m(E)]}),u.jsx("div",{className:"space-y-0.5",children:k.map(C=>{const $=r(C.name),K=(a==null?void 0:a.name)===C.name;return u.jsxs("button",{onClick:()=>o(C),className:H("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",K?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:H("size-1.5 rounded-full flex-none transition-colors",$?"bg-amber-500 dark:bg-amber-400":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:C.name})]},C.name)})})]},E))})})}),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(Vt,{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(eo,{checked:r(a.name),onCheckedChange:()=>n(a),disabled:s,"aria-label":`Toggle ${a.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[w(a.location),u.jsx("span",{children:m(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:[S&&u.jsx("button",{onClick:()=>d("properties"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Fo,{className:"size-3.5"}),"Properties"]})}),x&&u.jsx("button",{onClick:()=>d("schema"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Jm,{className:"size-3.5"}),"Schema"]})}),_&&u.jsx("button",{onClick:()=>d("examples"),className:H("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",f==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Hm,{className:"size-3.5"}),"Examples",u.jsx(Vt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:a.examples.length})]})})]}),u.jsx($r,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[f==="properties"&&S&&u.jsx("div",{className:"space-y-1",children:Object.entries(a.schema.properties).map(([E,k])=>u.jsx(Bx,{name:E,prop:k},E))}),f==="schema"&&x&&u.jsx(Fi,{schema:a.schema.jsonSchema,loading:!1,className:"h-[420px]"}),f==="examples"&&_&&a.examples.map((E,k)=>u.jsxs("div",{className:H(k>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:[E.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:E.title}),!E.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",k+1]})]}),u.jsx(we,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>h(E,k),children:l===k?u.jsxs(u.Fragment,{children:[u.jsx(qm,{className:"size-3 mr-1 text-green-600"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(as,{className:"size-3 mr-1"}),"Copy"]})})]}),E.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:E.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(E.props,null,2)})]},k)),!S&&!x&&!_&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(Fo,{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 Bx({name:e,prop:t}){var a;const[n,r]=y.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:H("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(on,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(ss,{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(Vt,{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-red-500 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",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 As=Em,Ps=Im,Os=zm,to=Tm,no=Am,Vx=y.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs($c,{ref:i,className:H("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(ss,{className:"ml-auto"})]}));Vx.displayName=$c.displayName;const Ux=y.forwardRef(({className:e,...t},n)=>u.jsx(Fc,{ref:n,className:H("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-md border p-1 shadow-lg",e),...t}));Ux.displayName=Fc.displayName;const ds=y.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Pm,{children:u.jsx(Oc,{ref:r,sideOffset:t,className:H("bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-md 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})}));ds.displayName=Oc.displayName;const Kt=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Dc,{ref:r,className:H("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}));Kt.displayName=Dc.displayName;const Jx=y.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Lc,{ref:i,className:H("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(Zc,{children:u.jsx(un,{className:"h-4 w-4"})})}),t]}));Jx.displayName=Lc.displayName;const Hx=y.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Bc,{ref:r,className:H("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(Zc,{children:u.jsx(Kc,{className:"h-2 w-2 fill-current"})})}),t]}));Hx.displayName=Bc.displayName;const qd=y.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Mc,{ref:r,className:H("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));qd.displayName=Mc.displayName;const Fr=y.forwardRef(({className:e,...t},n)=>u.jsx(Rc,{ref:n,className:H("bg-muted -mx-1 my-1 h-px",e),...t}));Fr.displayName=Rc.displayName;function qx(){const{theme:e,setTheme:t}=qc(),n=e==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e,r=y.useCallback(()=>{t(n==="dark"?"light":"dark")},[n,t]);return u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(we,{variant:"ghost",size:"icon",onClick:r,children:[u.jsx(Km,{className:"hidden dark:block"}),u.jsx(Ym,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ke,{children:u.jsx("p",{children:"Toggle theme"})})]})}const Wd=Om,ro=y.forwardRef(({className:e,...t},n)=>u.jsx(Vc,{ref:n,className:H("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-lg p-1",e),...t}));ro.displayName=Vc.displayName;const Lr=y.forwardRef(({className:e,...t},n)=>u.jsx(Uc,{ref:n,className:H("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-md 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 data-[state=active]:shadow",e),...t}));Lr.displayName=Uc.displayName;const Zr=y.forwardRef(({className:e,...t},n)=>u.jsx(Jc,{ref:n,className:H("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));Zr.displayName=Jc.displayName;async function Wx(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 Gx(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 Kx(e){const t=Gx(e);return Wx(t)}const Gd=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=y.useState(n),[s,a]=y.useState(null),[o,l]=y.useState(null),[c,f]=y.useState(!1),[d,p]=y.useState(!1),[h,m]=y.useState(null),[w,S]=y.useState(null),[x,_]=y.useState(!1),{toast:g}=Xr(),z=Dt(B=>B.selectedPlugins),E=Array.from(z);y.useEffect(()=>{n&&i(n)},[n]);const k=y.useCallback(async()=>{f(!0),m(null);try{const B=await Ns.fetchDocumentSchema(E);a(B)}catch(B){const D=B instanceof Error?B.message:"Failed to load document schema";m(D),g({variant:"destructive",title:"Error loading schema",description:D})}finally{f(!1)}},[E,g]),C=y.useCallback(async()=>{if(!o){p(!0),S(null);try{const B=await Ns.fetchThemeSchema();l(B)}catch(B){const D=B instanceof Error?B.message:"Failed to load theme schema";S(D),g({variant:"destructive",title:"Error loading schema",description:D})}finally{p(!1)}}},[o,g]),[$,K]=y.useState([]);y.useEffect(()=>{e||(a(null),m(null))},[e]),y.useEffect(()=>{if(!e)return;const B=E.length!==$.length||E.some((D,T)=>D!==$[T]);r==="document"?(!s||B)&&(B&&(Ns.clearPluginSchemaCache(),K([...E])),c||k()):r==="theme"&&!o&&!d&&C()},[r,e,s,o,c,d,E,$,k,C]);const N=E.length,I=r==="document"?s:o,A=async()=>{if(I)try{await Kx(I)&&(_(!0),g({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>_(!1),2e3))}catch(B){console.error("Copy failed:",B)}};return u.jsx(It,{open:e,onOpenChange:t,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:"Schema Viewer"})}),u.jsxs(Wd,{value:r,onValueChange:B=>i(B),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Lr,{value:"document",className:"flex items-center gap-1",children:["Document",N>0&&u.jsxs(Vt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",N]})]}),u.jsx(Lr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(we,{variant:"ghost",size:"icon",onClick:A,disabled:x||!I,"aria-label":"Copy schema",children:x?u.jsx(un,{className:"h-4 w-4"}):u.jsx(as,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(Zr,{value:"document",className:"h-full",children:u.jsx(Fi,{schema:s,loading:c,error:h||void 0})}),u.jsx(Zr,{value:"theme",className:"h-full",children:u.jsx(Fi,{schema:o,loading:d,error:w||void 0})})]})]})]})})};function Yx({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:a,openDocument:o}=Ae(ad(F=>({documents:F.documents,documentTypes:F.documentTypes,createDocument:F.createDocument,openDocument:F.openDocument}))),l=da(F=>F.updateTheme),c=da(F=>F.removeTheme),f=y.useContext(sd),[d,p]=y.useState(!1),[h,m]=y.useState(!1),[w,S]=y.useState(!1),[x,_]=y.useState(null),g=Dt(F=>F.togglePlugin),z=Dt(F=>F.isPluginSelected),E=Dt(F=>F.selectedPlugins),k=Dt(F=>F.isApplyingPlugins),[C,$]=y.useState(!1),[K,N]=y.useState(!1),[I,A]=y.useState(new Set(["current-docs","current-themes"])),{toast:B}=Xr(),D=i.filter(F=>s[F.name]!=="application/json+theme"),T=i.filter(F=>s[F.name]==="application/json+theme"),P=y.useMemo(()=>{if(!e)return{current:[],downstream:[]};const F={current:[],downstream:[]};return e.documents.forEach(te=>{F[te.location]&&F[te.location].push(te)}),F},[e]),J=y.useMemo(()=>{if(!e)return{current:[],downstream:[]};const F={current:[],downstream:[]};return e.themes.forEach(te=>{F[te.location]&&F[te.location].push(te)}),F},[e]),R=y.useMemo(()=>{const F=new Set;return D.forEach(te=>{try{const V=JSON.parse(te.text);V.children&&Array.isArray(V.children)&&V.children.forEach(de=>{var le;de.name==="docx"&&((le=de.props)!=null&&le.theme)&&F.add(de.props.theme)})}catch{}}),F},[D]),q=y.useCallback(()=>{p(!1)},[]),v=y.useCallback(()=>{m(!1)},[]),fe=y.useRef(new Map);y.useEffect(()=>{const F=fe.current,te=new Map;T.forEach(V=>{te.set(V.name,V.text),F.get(V.name)!==V.text&&l(V.name,V.text)}),F.forEach((V,de)=>{te.has(de)||c(de)}),fe.current=te},[T,l,c]);const ue=y.useRef(!1);y.useEffect(()=>{if(ue.current||!f)return;ue.current=!0;const F=new Set(T.map(V=>V.name));Object.keys(f.getState().customThemes).forEach(V=>{F.has(V)||c(V)})},[T,c,f]);const b=F=>{A(te=>{const V=new Set(te);return V.has(F)?V.delete(F):V.add(F),V})},Y=Ae(F=>F.activeTab),oe=Y&&s[Y]==="application/json+theme"?"theme":"document",{resolvedTheme:ne}=qc(),ie=ne==="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",W=y.useCallback(async(F,te)=>{if(i.some(V=>V.name===F)){o(F);return}try{const V=await fetch(`/api/discovery/${te?"themes":"documents"}/${encodeURIComponent(F)}/content`);if(!V.ok)throw new Error(V.statusText);const de=await V.text(),le=JSON.parse(de);a(F,JSON.stringify(le,null,2)),o(F),B({title:`Added ${te?"theme":"document"}: ${F}`})}catch{B({title:"Failed to load",description:`Could not load ${F}`,variant:"destructive"})}},[i,a,o,B]);return u.jsxs(u.Fragment,{children:[u.jsxs(Fd,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[u.jsx(Ld,{children:u.jsx("div",{className:H("flex items-center transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100",n?"justify-center":"justify-between"),children:n?u.jsx(we,{variant:"ghost",size:"icon","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Qc,{className:"h-4 w-4"})}):u.jsxs(u.Fragment,{children:[u.jsx("a",{href:"/",className:"flex items-center pl-2",children:u.jsx("img",{src:ie,alt:"WiseAir logo",className:"h-5 w-auto max-w-[120px] shrink-0"})}),u.jsx("div",{className:"flex items-center gap-1",children:u.jsx(we,{variant:"ghost",size:"icon","aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(Xm,{className:"h-4 w-4"})})})]})})}),u.jsxs(Vd,{className:H("h-full transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100"),children:[u.jsxs(Si,{children:[u.jsxs(_i,{className:H("flex items-center",n?"justify-center":"justify-between"),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[!n&&u.jsx(Lo,{className:"size-3"}),!n&&u.jsx("span",{children:"Active Documents"})]}),u.jsxs("div",{className:"flex items-center gap-0.5",children:[yt==="docx"&&!n&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{className:"h-6 w-6 p-0 flex-shrink-0",variant:"ghost",size:"icon","aria-label":"Compare documents",disabled:D.length<2,onClick:()=>N(!0),children:u.jsx(Gc,{className:"size-4"})})}),u.jsx(Ke,{side:"bottom",children:u.jsx("span",{className:"text-xs",children:D.length<2?"Compare needs two documents":"Compare documents (redline)"})})]}),u.jsxs(It,{open:d,onOpenChange:p,children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Bo,{asChild:!0,children:u.jsx(we,{className:H("p-0 flex-shrink-0",n?"mx-auto h-8 w-8 rounded border border-dashed border-sidebar-foreground/20 hover:border-sidebar-foreground/40":"h-6 w-6"),variant:"ghost",size:"icon",children:u.jsx(zi,{className:n?"size-3.5":"size-4"})})})}),u.jsx(Ke,{side:n?"right":"bottom",children:u.jsx("span",{className:"text-xs",children:"New Document"})})]}),u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Di,{mode:"create",shouldReset:!d,postSubmit:q,discoveredDocuments:(e==null?void 0:e.documents)||[]})})]})]})]}),n?u.jsx(Sr,{children:u.jsx("div",{className:"flex flex-col items-center gap-0.5 px-0.5",children:D.map(F=>{const te=Y===F.name;return u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("button",{onClick:()=>o(F.name),"aria-label":F.name,className:H("relative w-8 h-8 rounded flex items-center justify-center text-[11px] font-bold transition-colors cursor-pointer",te?"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[te&&u.jsx("span",{className:"absolute left-0 top-1 bottom-1 w-0.5 rounded-full bg-green-500 dark:bg-green-400"}),F.name.replace(/\.[^.]+$/,"").slice(0,2).toUpperCase()]})}),u.jsx(Ke,{side:"right",children:u.jsx("span",{className:"text-xs",children:F.name})})]},F.name)})})}):u.jsx(Sr,{children:u.jsx(ba,{children:D.length>0?D.map((F,te)=>u.jsx(el,{document:F,compact:n},`doc-${te}`)):u.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"No active documents. Click + to create one."})})})]}),u.jsx(Bd,{}),u.jsxs(Si,{children:[u.jsxs(_i,{className:H("flex items-center",n?"justify-center":"justify-between"),children:[u.jsxs("div",{className:"flex items-center gap-2",children:[!n&&u.jsx(la,{className:"size-3 text-purple-600 dark:text-purple-400"}),!n&&u.jsx("span",{children:"Active Themes"})]}),u.jsxs(It,{open:h,onOpenChange:m,children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Bo,{asChild:!0,children:u.jsx(we,{className:H("p-0 flex-shrink-0",n?"mx-auto h-8 w-8 rounded border border-dashed border-sidebar-foreground/20 hover:border-sidebar-foreground/40":"h-6 w-6"),variant:"ghost",size:"icon",children:u.jsx(zi,{className:n?"size-3.5":"size-4"})})})}),u.jsx(Ke,{side:n?"right":"bottom",children:u.jsx("span",{className:"text-xs",children:"New Theme"})})]}),u.jsx(St,{className:"sm:max-w-[525px]",children:u.jsx(Di,{mode:"create",shouldReset:!h,postSubmit:v,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})]})]}),n?u.jsx(Sr,{children:u.jsx("div",{className:"flex flex-col items-center gap-0.5 px-0.5",children:T.map(F=>{const te=Y===F.name;let V=null;try{const le=JSON.parse(F.text);V=fa(le)}catch{}const de=V?R.has(V):!1;return u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("button",{onClick:()=>o(F.name),"aria-label":F.name,className:H("relative w-8 h-8 rounded flex items-center justify-center text-[11px] font-bold transition-colors cursor-pointer",te?"bg-purple-100 text-purple-700 dark:bg-purple-900/40 dark:text-purple-300":de?"bg-purple-50 text-purple-600 dark:bg-purple-900/20 dark:text-purple-400":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[te&&u.jsx("span",{className:"absolute left-0 top-1 bottom-1 w-0.5 rounded-full bg-purple-500 dark:bg-purple-400"}),(V||F.name).charAt(0).toUpperCase()]})}),u.jsx(Ke,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[F.name,de&&u.jsx("div",{className:"opacity-70",children:"In use"})]})})]},F.name)})})}):u.jsx(Sr,{children:u.jsx(ba,{children:T.length>0?T.map((F,te)=>{let V=null;try{const le=JSON.parse(F.text);V=fa(le)}catch{}const de=V?R.has(V):!1;return u.jsx(el,{document:F,compact:n,indicator:de?"in-use":void 0},`theme-${te}`)}):u.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:["No active themes."," ",e&&e.themes.length>0?"Click + to add one.":"No themes discovered in project."]})})})]}),!n&&e&&(e.documents.length>0||e.themes.length>0)&&u.jsxs(Si,{className:"mt-2 border-t pt-4",children:[u.jsxs(_i,{className:"flex items-center mb-2 gap-2",children:[u.jsx(Qm,{className:"size-3"}),u.jsx("span",{children:"Discovered Resources"})]}),u.jsxs(u.Fragment,{children:[Object.entries(P).map(([F,te])=>{if(te.length===0)return null;const V=`${F}-docs`,de=I.has(V);return u.jsxs(As,{open:de,children:[u.jsxs(Ps,{className:"flex items-center gap-1 px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer w-full",onClick:()=>b(V),children:[u.jsx(on,{className:H("size-3 transition-transform",!de&&"-rotate-90")}),u.jsx(Lo,{className:"size-3"}),F==="current"?"Current Directory":"Project"," ","Documents (",te.length,")"]}),u.jsx(Os,{children:u.jsx("div",{className:"pl-4 space-y-0.5",children:te.map((le,ye)=>{const Oe=i.some(qe=>qe.name===le.name);return u.jsxs("button",{onClick:()=>W(le.name,!1),className:H("w-full text-left py-1 px-2 rounded text-sm transition-colors","border-l-2 border-blue-400/60 dark:border-blue-500/40","hover:bg-accent hover:text-accent-foreground",Oe&&"opacity-50"),children:[u.jsx("div",{className:"font-medium truncate",children:le.name}),le.title&&u.jsx("div",{className:"text-xs text-muted-foreground truncate",children:le.title})]},ye)})})})]},V)}),Object.entries(J).map(([F,te])=>{if(te.length===0)return null;const V=`${F}-themes`,de=I.has(V);return u.jsxs(As,{open:de,children:[u.jsxs(Ps,{className:"flex items-center gap-1 px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer w-full",onClick:()=>b(V),children:[u.jsx(on,{className:H("size-3 transition-transform",!de&&"-rotate-90")}),u.jsx(la,{className:"size-3"}),F==="current"?"Current Directory":"Project"," ","Themes (",te.length,")"]}),u.jsx(Os,{children:u.jsx("div",{className:"pl-4 space-y-0.5",children:te.map((le,ye)=>{const Oe=i.some(qe=>qe.name===le.name);return u.jsxs("button",{onClick:()=>W(le.name,!0),className:H("w-full text-left py-1 px-2 rounded text-sm transition-colors","border-l-2 border-purple-400/60 dark:border-purple-500/40","hover:bg-accent hover:text-accent-foreground",Oe&&"opacity-50"),children:[u.jsx("div",{className:"font-medium truncate",children:le.name}),le.description&&u.jsx("div",{className:"text-xs text-muted-foreground truncate",children:le.description})]},ye)})})})]},V)}),e&&e.plugins.length>0&&u.jsxs(As,{open:I.has("plugins"),children:[u.jsxs(Ps,{className:"flex items-center gap-1 px-3 py-1 text-xs font-medium text-muted-foreground hover:text-foreground transition-colors cursor-pointer w-full",onClick:()=>b("plugins"),children:[u.jsx(on,{className:H("size-3 transition-transform",!I.has("plugins")&&"-rotate-90")}),u.jsx(Xc,{className:"size-3 text-amber-600 dark:text-amber-400"}),"Plugins (",E.size,"/",e.plugins.length,")"]}),u.jsx(Os,{children:u.jsx("div",{className:"pl-4 space-y-0.5",children:e.plugins.map((F,te)=>{const V=z(F.name);return u.jsxs("div",{className:H("py-1 px-2 text-sm border-l-2 flex items-center gap-2 group transition-colors",V?"border-amber-500 dark:border-amber-400 text-foreground":"border-amber-400/30 dark:border-amber-500/20 text-muted-foreground"),children:[u.jsxs("div",{className:"flex-1 min-w-0",children:[u.jsx("div",{className:"font-medium truncate",children:F.name}),F.description&&u.jsx("div",{className:"text-xs opacity-70 truncate",children:F.description})]}),u.jsx("button",{className:"flex-none size-5 flex items-center justify-center rounded-sm opacity-0 group-hover:opacity-100 hover:bg-accent transition-all cursor-pointer",title:`View details for ${F.name}`,onClick:de=>{de.stopPropagation(),_(F.name),S(!0)},children:u.jsx(ed,{className:"size-3 text-muted-foreground"})}),u.jsx(eo,{checked:V,onCheckedChange:()=>g(F),disabled:k,className:"flex-none scale-[0.8]","aria-label":`Toggle ${F.name} plugin`})]},te)})})})]})]})]})]}),u.jsx(Zd,{children:u.jsx("div",{className:H("flex w-full items-center transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100",n?"justify-center":"justify-end pr-2"),children:u.jsx(qx,{})})}),u.jsx(It,{open:w,onOpenChange:F=>{S(F),F||_(null)},children:u.jsx(St,{className:"sm:max-w-5xl max-h-[85vh] overflow-hidden",children:u.jsx(Zx,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:x})})})]}),u.jsx(Gd,{open:C,onOpenChange:$,defaultTab:oe==="theme"?"theme":"document"}),u.jsx(Ig,{open:K,onOpenChange:N})]})}const tl=y.memo(Yx),Xx=y.lazy(()=>Wc(()=>import("./editor-BPfMyucg.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function nl(){return u.jsx(y.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(Yt,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(Xx,{})})}const Qx=y.lazy(()=>Wc(()=>import("./preview-Cdpjm_5u.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function rl(){return u.jsx(y.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(Yt,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(Qx,{})})}const{createElement:nr,createContext:ey,forwardRef:Kd,useCallback:pt,useContext:Yd,useEffect:_n,useImperativeHandle:Xd,useLayoutEffect:ty,useMemo:ny,useRef:xt,useState:Kn}=cc,il=cc[`useId${Math.random()}`.slice(0,5)],ry=ty,fs=ey(null);fs.displayName="PanelGroupContext";const jn=ry,iy=typeof il=="function"?il:()=>null;let sy=0;function io(e=null){const t=iy(),n=xt(e||t||null);return n.current===null&&(n.current=""+sy++),e??n.current}function Qd({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:a,maxSize:o,minSize:l,onCollapse:c,onExpand:f,onResize:d,order:p,style:h,tagName:m="div",...w}){const S=Yd(fs);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:x,expandPanel:_,getPanelSize:g,getPanelStyle:z,groupId:E,isPanelCollapsed:k,reevaluatePanelConstraints:C,registerPanel:$,resizePanel:K,unregisterPanel:N}=S,I=io(a),A=xt({callbacks:{onCollapse:c,onExpand:f,onResize:d},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:o,minSize:l},id:I,idIsFromProps:a!==void 0,order:p});xt({didLogMissingDefaultSizeWarning:!1}),jn(()=>{const{callbacks:D,constraints:T}=A.current,P={...T};A.current.id=I,A.current.idIsFromProps=a!==void 0,A.current.order=p,D.onCollapse=c,D.onExpand=f,D.onResize=d,T.collapsedSize=n,T.collapsible=r,T.defaultSize=i,T.maxSize=o,T.minSize=l,(P.collapsedSize!==T.collapsedSize||P.collapsible!==T.collapsible||P.maxSize!==T.maxSize||P.minSize!==T.minSize)&&C(A.current,P)}),jn(()=>{const D=A.current;return $(D),()=>{N(D)}},[p,I,$,N]),Xd(s,()=>({collapse:()=>{x(A.current)},expand:D=>{_(A.current,D)},getId(){return I},getSize(){return g(A.current)},isCollapsed(){return k(A.current)},isExpanded(){return!k(A.current)},resize:D=>{K(A.current,D)}}),[x,_,g,k,I,K]);const B=z(A.current,i);return nr(m,{...w,children:e,className:t,id:a,style:{...B,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":E,"data-panel-id":I,"data-panel-size":parseFloat(""+B.flexGrow).toFixed(1)})}const ef=Kd((e,t)=>nr(Qd,{...e,forwardedRef:t}));Qd.displayName="Panel";ef.displayName="forwardRef(Panel)";let va=null,Sn=null;function ay(e,t){if(t){const n=(t&af)!==0,r=(t&of)!==0,i=(t&lf)!==0,s=(t&uf)!==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 oy(){Sn!==null&&(document.head.removeChild(Sn),va=null,Sn=null)}function Ds(e,t){const n=ay(e,t);va!==n&&(va=n,Sn===null&&(Sn=document.createElement("style"),document.head.appendChild(Sn)),Sn.innerHTML=`*{cursor: ${n}!important;}`)}function tf(e){return e.type==="keydown"}function nf(e){return e.type.startsWith("pointer")}function rf(e){return e.type.startsWith("mouse")}function ps(e){if(nf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(rf(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function ly(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function uy(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 cy(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:ol(e),b:ol(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:al(sl(n.a)),b:al(sl(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 dy=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function fy(e){var t;const n=getComputedStyle((t=sf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function py(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||fy(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"||dy.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function sl(e){let t=e.length;for(;t--;){const n=e[t];if(_e(n,"Missing node"),py(n))return n}return null}function al(e){return e&&Number(getComputedStyle(e).zIndex)||0}function ol(e){const t=[];for(;e;)t.push(e),e=sf(e);return t}function sf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const af=1,of=2,lf=4,uf=8,hy=ly()==="coarse";let Rt=[],Yn=!1,an=new Map,hs=new Map;const Br=new Set;function my(e,t,n,r,i){var s;const{ownerDocument:a}=t,o={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=an.get(a))!==null&&s!==void 0?s:0;return an.set(a,l+1),Br.add(o),Li(),function(){var f;hs.delete(e),Br.delete(o);const d=(f=an.get(a))!==null&&f!==void 0?f:1;if(an.set(a,d-1),Li(),d===1&&an.delete(a),Rt.includes(o)){const p=Rt.indexOf(o);p>=0&&Rt.splice(p,1),ao(),i("up",!0,null)}}}function ll(e){const{target:t}=e,{x:n,y:r}=ps(e);Yn=!0,so({target:t,x:n,y:r}),Li(),Rt.length>0&&(Zi("down",e),e.preventDefault(),e.stopPropagation())}function gr(e){const{x:t,y:n}=ps(e);if(Yn&&e.buttons===0&&(Yn=!1,Zi("up",e)),!Yn){const{target:r}=e;so({target:r,x:t,y:n})}Zi("move",e),ao(),Rt.length>0&&e.preventDefault()}function Dn(e){const{target:t}=e,{x:n,y:r}=ps(e);hs.clear(),Yn=!1,Rt.length>0&&e.preventDefault(),Zi("up",e),so({target:t,x:n,y:r}),ao(),Li()}function so({target:e,x:t,y:n}){Rt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Br.forEach(i=>{const{element:s,hitAreaMargins:a}=i,o=s.getBoundingClientRect(),{bottom:l,left:c,right:f,top:d}=o,p=hy?a.coarse:a.fine;if(t>=c-p&&t<=f+p&&n>=d-p&&n<=l+p){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&cy(r,s)>0){let m=r,w=!1;for(;m&&!m.contains(s);){if(uy(m.getBoundingClientRect(),o)){w=!0;break}m=m.parentElement}if(w)return}Rt.push(i)}})}function Rs(e,t){hs.set(e,t)}function ao(){let e=!1,t=!1;Rt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;hs.forEach(r=>{n|=r}),e&&t?Ds("intersection",n):e?Ds("horizontal",n):t?Ds("vertical",n):oy()}function Li(){an.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Dn),n.removeEventListener("pointerdown",ll),n.removeEventListener("pointerleave",gr),n.removeEventListener("pointermove",gr)}),window.removeEventListener("pointerup",Dn),window.removeEventListener("pointercancel",Dn),Br.size>0&&(Yn?(Rt.length>0&&an.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Dn),n.addEventListener("pointerleave",gr),n.addEventListener("pointermove",gr))}),window.addEventListener("pointerup",Dn),window.addEventListener("pointercancel",Dn)):an.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",ll,{capture:!0}),n.addEventListener("pointermove",gr))}))}function Zi(e,t){Br.forEach(n=>{const{setResizeHandlerState:r}=n,i=Rt.includes(n);r(e,i,t)})}function gy(){const[e,t]=Kn(0);return pt(()=>t(n=>n+1),[])}function _e(e,t){if(!e)throw console.error(t),Error(t)}const oo=10;function In(e,t,n=oo){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function Xt(e,t,n=oo){return In(e,t,n)===0}function kt(e,t,n){return In(e,t,n)===0}function xy(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(!kt(i,s,n))return!1}return!0}function Hn({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(In(n,o)<0)if(s){const l=(i+o)/2;In(n,l)<0?n=i:n=o}else n=o;return n=Math.min(a,n),n=parseFloat(n.toFixed(oo)),n}function _r({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(kt(e,0))return t;const a=[...t],[o,l]=r;_e(o!=null,"Invalid first pivot index"),_e(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const d=e<0?l:o,p=n[d];_e(p,`Panel constraints not found for index ${d}`);const{collapsedSize:h=0,collapsible:m,minSize:w=0}=p;if(m){const S=t[d];if(_e(S!=null,`Previous layout not found for panel index ${d}`),kt(S,h)){const x=w-S;In(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}{const d=e<0?o:l,p=n[d];_e(p,`No panel constraints found for index ${d}`);const{collapsedSize:h=0,collapsible:m,minSize:w=0}=p;if(m){const S=t[d];if(_e(S!=null,`Previous layout not found for panel index ${d}`),kt(S,w)){const x=S-h;In(x,Math.abs(e))>0&&(e=e<0?0-x:x)}}}}{const d=e<0?1:-1;let p=e<0?l:o,h=0;for(;;){const w=t[p];_e(w!=null,`Previous layout not found for panel index ${p}`);const x=Hn({panelConstraints:n,panelIndex:p,size:100})-w;if(h+=x,p+=d,p<0||p>=n.length)break}const m=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-m:m}{let p=e<0?o:l;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),m=t[p];_e(m!=null,`Previous layout not found for panel index ${p}`);const w=m-h,S=Hn({panelConstraints:n,panelIndex:p,size:w});if(!kt(m,S)&&(c+=m-S,a[p]=S,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(xy(i,a))return i;{const d=e<0?l:o,p=t[d];_e(p!=null,`Previous layout not found for panel index ${d}`);const h=p+c,m=Hn({panelConstraints:n,panelIndex:d,size:h});if(a[d]=m,!kt(m,h)){let w=h-m,x=e<0?l:o;for(;x>=0&&x<n.length;){const _=a[x];_e(_!=null,`Previous layout not found for panel index ${x}`);const g=_+w,z=Hn({panelConstraints:n,panelIndex:x,size:g});if(kt(_,z)||(w-=z-_,a[x]=z),kt(w,0))break;e>0?x--:x++}}}const f=a.reduce((d,p)=>p+d,0);return kt(f,100)?a:i}function yy({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,a=0;const o=n[0];_e(o!=null,"No pivot index found"),t.forEach((d,p)=>{const{constraints:h}=d,{maxSize:m=100,minSize:w=0}=h;p===o?(r=w,i=m):(s+=w,a+=m)});const l=Math.min(i,100-s),c=Math.max(r,100-a),f=e[o];return{valueMax:l,valueMin:c,valueNow:f}}function Vr(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function cf(e,t,n=document){const i=Vr(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function df(e,t,n){const r=cf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function ff(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 ms(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function by(e,t,n,r=document){var i,s,a,o;const l=ms(t,r),c=Vr(e,r),f=l?c.indexOf(l):-1,d=(i=(s=n[f])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,p=(a=(o=n[f+1])===null||o===void 0?void 0:o.id)!==null&&a!==void 0?a:null;return[d,p]}function vy({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:a}){xt({didWarnAboutMissingResizeHandle:!1}),jn(()=>{if(!s)return;const o=Vr(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:f,valueNow:d}=yy({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=o[l];if(p!=null){const h=i[l];_e(h,`No panel data found for index "${l}"`),p.setAttribute("aria-controls",h.id),p.setAttribute("aria-valuemax",""+Math.round(c)),p.setAttribute("aria-valuemin",""+Math.round(f)),p.setAttribute("aria-valuenow",d!=null?""+Math.round(d):"")}}return()=>{o.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),_n(()=>{if(!s)return;const o=t.current;_e(o,"Eager values not found");const{panelDataArray:l}=o,c=ff(n,s);_e(c!=null,`No group found for id "${n}"`);const f=Vr(n,s);_e(f,`No resize handles found for group id "${n}"`);const d=f.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");_e(h,"Resize handle element has no handle id attribute");const[m,w]=by(n,h,l,s);if(m==null||w==null)return()=>{};const S=x=>{if(!x.defaultPrevented)switch(x.key){case"Enter":{x.preventDefault();const _=l.findIndex(g=>g.id===m);if(_>=0){const g=l[_];_e(g,`No panel data found for index ${_}`);const z=r[_],{collapsedSize:E=0,collapsible:k,minSize:C=0}=g.constraints;if(z!=null&&k){const $=_r({delta:kt(z,E)?C-E:E-z,initialLayout:r,panelConstraints:l.map(K=>K.constraints),pivotIndices:df(n,h,s),prevLayout:r,trigger:"keyboard"});r!==$&&a($)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{d.forEach(p=>p())}},[s,e,t,n,r,i,a])}function ul(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 pf(e,t){const n=e==="horizontal",{x:r,y:i}=ps(t);return n?r:i}function wy(e,t,n,r,i){const s=n==="horizontal",a=ms(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=pf(n,e),f=ff(o,i);_e(f,`No group element found for id "${o}"`);const d=f.getBoundingClientRect(),p=s?d.width:d.height;return(c-l)/p*100}function ky(e,t,n,r,i,s){if(tf(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:wy(e,t,n,r,s)}function Sy({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 Rn(e,t,n){t.forEach((r,i)=>{const s=e[i];_e(s,`Panel data not found for index ${i}`);const{callbacks:a,constraints:o,id:l}=s,{collapsedSize:c=0,collapsible:f}=o,d=n[l];if(d==null||r!==d){n[l]=r;const{onCollapse:p,onExpand:h,onResize:m}=a;m&&m(r,d),f&&(p||h)&&(h&&(d==null||Xt(d,c))&&!Xt(r,c)&&h(),p&&(d==null||!Xt(d,c))&&Xt(r,c)&&p())}})}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 _y({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 jy(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function cl(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 hf(e){return`react-resizable-panels:${e}`}function mf(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 gf(e,t){try{const n=hf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Ny(e,t,n){var r,i;const s=(r=gf(e,n))!==null&&r!==void 0?r:{},a=mf(t);return(i=s[a])!==null&&i!==void 0?i:null}function Cy(e,t,n,r,i){var s;const a=hf(e),o=mf(t),l=(s=gf(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 dl({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(!kt(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=Hn({panelConstraints:t,panelIndex:s,size:a});a!=o&&(i+=a-o,n[s]=o)}if(!kt(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=Hn({panelConstraints:t,panelIndex:s,size:o});if(a!==l&&(i-=l-a,n[s]=l,kt(i,0)))break}return n}const Ey=100,jr={getItem:e=>(cl(jr),jr.getItem(e)),setItem:(e,t)=>{cl(jr),jr.setItem(e,t)}},fl={};function xf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:a=null,keyboardResizeBy:o=null,storage:l=jr,style:c,tagName:f="div",...d}){const p=io(s),h=xt(null),[m,w]=Kn(null),[S,x]=Kn([]),_=gy(),g=xt({}),z=xt(new Map),E=xt(0),k=xt({autoSaveId:e,direction:r,dragState:m,id:p,keyboardResizeBy:o,onLayout:a,storage:l}),C=xt({layout:S,panelDataArray:[],panelDataArrayChanged:!1});xt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),Xd(i,()=>({getId:()=>k.current.id,getLayout:()=>{const{layout:b}=C.current;return b},setLayout:b=>{const{onLayout:Y}=k.current,{layout:oe,panelDataArray:ne}=C.current,ie=dl({layout:b,panelConstraints:ne.map(W=>W.constraints)});ul(oe,ie)||(x(ie),C.current.layout=ie,Y&&Y(ie),Rn(ne,ie,g.current))}}),[]),jn(()=>{k.current.autoSaveId=e,k.current.direction=r,k.current.dragState=m,k.current.id=p,k.current.onLayout=a,k.current.storage=l}),vy({committedValuesRef:k,eagerValuesRef:C,groupId:p,layout:S,panelDataArray:C.current.panelDataArray,setLayout:x,panelGroupElement:h.current}),_n(()=>{const{panelDataArray:b}=C.current;if(e){if(S.length===0||S.length!==b.length)return;let Y=fl[e];Y==null&&(Y=jy(Cy,Ey),fl[e]=Y);const oe=[...b],ne=new Map(z.current);Y(e,oe,ne,S,l)}},[e,S,l]),_n(()=>{});const $=pt(b=>{const{onLayout:Y}=k.current,{layout:oe,panelDataArray:ne}=C.current;if(b.constraints.collapsible){const ie=ne.map(V=>V.constraints),{collapsedSize:W=0,panelSize:F,pivotIndices:te}=gn(ne,b,oe);if(_e(F!=null,`Panel size not found for panel "${b.id}"`),!Xt(F,W)){z.current.set(b.id,F);const de=Bn(ne,b)===ne.length-1?F-W:W-F,le=_r({delta:de,initialLayout:oe,panelConstraints:ie,pivotIndices:te,prevLayout:oe,trigger:"imperative-api"});ci(oe,le)||(x(le),C.current.layout=le,Y&&Y(le),Rn(ne,le,g.current))}}},[]),K=pt((b,Y)=>{const{onLayout:oe}=k.current,{layout:ne,panelDataArray:ie}=C.current;if(b.constraints.collapsible){const W=ie.map(ye=>ye.constraints),{collapsedSize:F=0,panelSize:te=0,minSize:V=0,pivotIndices:de}=gn(ie,b,ne),le=Y??V;if(Xt(te,F)){const ye=z.current.get(b.id),Oe=ye!=null&&ye>=le?ye:le,Qe=Bn(ie,b)===ie.length-1?te-Oe:Oe-te,j=_r({delta:Qe,initialLayout:ne,panelConstraints:W,pivotIndices:de,prevLayout:ne,trigger:"imperative-api"});ci(ne,j)||(x(j),C.current.layout=j,oe&&oe(j),Rn(ie,j,g.current))}}},[]),N=pt(b=>{const{layout:Y,panelDataArray:oe}=C.current,{panelSize:ne}=gn(oe,b,Y);return _e(ne!=null,`Panel size not found for panel "${b.id}"`),ne},[]),I=pt((b,Y)=>{const{panelDataArray:oe}=C.current,ne=Bn(oe,b);return _y({defaultSize:Y,dragState:m,layout:S,panelData:oe,panelIndex:ne})},[m,S]),A=pt(b=>{const{layout:Y,panelDataArray:oe}=C.current,{collapsedSize:ne=0,collapsible:ie,panelSize:W}=gn(oe,b,Y);return _e(W!=null,`Panel size not found for panel "${b.id}"`),ie===!0&&Xt(W,ne)},[]),B=pt(b=>{const{layout:Y,panelDataArray:oe}=C.current,{collapsedSize:ne=0,collapsible:ie,panelSize:W}=gn(oe,b,Y);return _e(W!=null,`Panel size not found for panel "${b.id}"`),!ie||In(W,ne)>0},[]),D=pt(b=>{const{panelDataArray:Y}=C.current;Y.push(b),Y.sort((oe,ne)=>{const ie=oe.order,W=ne.order;return ie==null&&W==null?0:ie==null?-1:W==null?1:ie-W}),C.current.panelDataArrayChanged=!0,_()},[_]);jn(()=>{if(C.current.panelDataArrayChanged){C.current.panelDataArrayChanged=!1;const{autoSaveId:b,onLayout:Y,storage:oe}=k.current,{layout:ne,panelDataArray:ie}=C.current;let W=null;if(b){const te=Ny(b,ie,oe);te&&(z.current=new Map(Object.entries(te.expandToSizes)),W=te.layout)}W==null&&(W=Sy({panelDataArray:ie}));const F=dl({layout:W,panelConstraints:ie.map(te=>te.constraints)});ul(ne,F)||(x(F),C.current.layout=F,Y&&Y(F),Rn(ie,F,g.current))}}),jn(()=>{const b=C.current;return()=>{b.layout=[]}},[]);const T=pt(b=>{let Y=!1;const oe=h.current;return oe&&window.getComputedStyle(oe,null).getPropertyValue("direction")==="rtl"&&(Y=!0),function(ie){ie.preventDefault();const W=h.current;if(!W)return()=>null;const{direction:F,dragState:te,id:V,keyboardResizeBy:de,onLayout:le}=k.current,{layout:ye,panelDataArray:Oe}=C.current,{initialLayout:qe}=te??{},Qe=df(V,b,W);let j=ky(ie,b,F,te,de,W);const O=F==="horizontal";O&&Y&&(j=-j);const Z=Oe.map(Q=>Q.constraints),re=_r({delta:j,initialLayout:qe??ye,panelConstraints:Z,pivotIndices:Qe,prevLayout:ye,trigger:tf(ie)?"keyboard":"mouse-or-touch"}),ee=!ci(ye,re);(nf(ie)||rf(ie))&&E.current!=j&&(E.current=j,!ee&&j!==0?O?Rs(b,j<0?af:of):Rs(b,j<0?lf:uf):Rs(b,0)),ee&&(x(re),C.current.layout=re,le&&le(re),Rn(Oe,re,g.current))}},[]),P=pt((b,Y)=>{const{onLayout:oe}=k.current,{layout:ne,panelDataArray:ie}=C.current,W=ie.map(ye=>ye.constraints),{panelSize:F,pivotIndices:te}=gn(ie,b,ne);_e(F!=null,`Panel size not found for panel "${b.id}"`);const de=Bn(ie,b)===ie.length-1?F-Y:Y-F,le=_r({delta:de,initialLayout:ne,panelConstraints:W,pivotIndices:te,prevLayout:ne,trigger:"imperative-api"});ci(ne,le)||(x(le),C.current.layout=le,oe&&oe(le),Rn(ie,le,g.current))},[]),J=pt((b,Y)=>{const{layout:oe,panelDataArray:ne}=C.current,{collapsedSize:ie=0,collapsible:W}=Y,{collapsedSize:F=0,collapsible:te,maxSize:V=100,minSize:de=0}=b.constraints,{panelSize:le}=gn(ne,b,oe);le!=null&&(W&&te&&Xt(le,ie)?Xt(ie,F)||P(b,F):le<de?P(b,de):le>V&&P(b,V))},[P]),R=pt((b,Y)=>{const{direction:oe}=k.current,{layout:ne}=C.current;if(!h.current)return;const ie=ms(b,h.current);_e(ie,`Drag handle element not found for id "${b}"`);const W=pf(oe,Y);w({dragHandleId:b,dragHandleRect:ie.getBoundingClientRect(),initialCursorPosition:W,initialLayout:ne})},[]),q=pt(()=>{w(null)},[]),v=pt(b=>{const{panelDataArray:Y}=C.current,oe=Bn(Y,b);oe>=0&&(Y.splice(oe,1),delete g.current[b.id],C.current.panelDataArrayChanged=!0,_())},[_]),fe=ny(()=>({collapsePanel:$,direction:r,dragState:m,expandPanel:K,getPanelSize:N,getPanelStyle:I,groupId:p,isPanelCollapsed:A,isPanelExpanded:B,reevaluatePanelConstraints:J,registerPanel:D,registerResizeHandle:T,resizePanel:P,startDragging:R,stopDragging:q,unregisterPanel:v,panelGroupElement:h.current}),[$,m,r,K,N,I,p,A,B,J,D,T,P,R,q,v]),ue={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return nr(fs.Provider,{value:fe},nr(f,{...d,children:t,className:n,id:s,ref:h,style:{...ue,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const yf=Kd((e,t)=>nr(xf,{...e,forwardedRef:t}));xf.displayName="PanelGroup";yf.displayName="forwardRef(PanelGroup)";function Bn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function gn(e,t,n){const r=Bn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],a=n[r];return{...t.constraints,panelSize:a,pivotIndices:s}}function Iy({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){_n(()=>{if(e||n==null||r==null)return;const i=ms(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=Vr(o,r),c=cf(o,t,r);_e(c!==null,`No resize element found for id "${t}"`);const f=a.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[f].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function bf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:a,onFocus:o,style:l={},tabIndex:c=0,tagName:f="div",...d}){var p,h;const m=xt(null),w=xt({onDragging:a});_n(()=>{w.current.onDragging=a});const S=Yd(fs);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:x,groupId:_,registerResizeHandle:g,startDragging:z,stopDragging:E,panelGroupElement:k}=S,C=io(i),[$,K]=Kn("inactive"),[N,I]=Kn(!1),[A,B]=Kn(null),D=xt({state:$});jn(()=>{D.current.state=$}),_n(()=>{if(n)B(null);else{const R=g(C);B(()=>R)}},[n,C,g]);const T=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,P=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return _n(()=>{if(n||A==null)return;const R=m.current;return _e(R,"Element ref not attached"),my(C,R,x,{coarse:T,fine:P},(v,fe,ue)=>{if(fe)switch(v){case"down":{K("drag"),_e(ue,'Expected event to be defined for "down" action'),z(C,ue);const{onDragging:b}=w.current;b&&b(!0);break}case"move":{const{state:b}=D.current;b!=="drag"&&K("hover"),_e(ue,'Expected event to be defined for "move" action'),A(ue);break}case"up":{K("hover"),E();const{onDragging:b}=w.current;b&&b(!1);break}}else K("inactive")})},[T,x,n,P,g,C,A,z,E]),Iy({disabled:n,handleId:C,resizeHandler:A,panelGroupElement:k}),nr(f,{...d,children:e,className:t,id:i,onBlur:()=>{I(!1),s==null||s()},onFocus:()=>{I(!0),o==null||o()},ref:m,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":x,"data-panel-group-id":_,"data-resize-handle":"","data-resize-handle-active":$==="drag"?"pointer":N?"keyboard":void 0,"data-resize-handle-state":$,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":C})}bf.displayName="PanelResizeHandle";const zy=({className:e,...t})=>u.jsx(yf,{className:H("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Ms=ef,pl=({withHandle:e,className:t,...n})=>u.jsx(bf,{className:H("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(eg,{className:"h-2.5 w-2.5"})})});function Ty({children:e,className:t}){return u.jsx("kbd",{className:H("inline-flex items-center justify-center min-w-[1.25rem] h-5 px-1 rounded border border-border bg-background text-[11px] font-mono font-medium text-muted-foreground shadow-[0_1px_0_0] shadow-border/50 leading-none select-none",t),children:e})}function Ay({children:e,className:t}){return u.jsx("span",{className:H("inline-flex items-center gap-0.5",t),children:e})}const di=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function wa({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return di?"⌘":"Ctrl";case"shift":return di?"⇧":"Shift";case"alt":return di?"⌥":"Alt";case"ctrl":return di?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(Ay,{className:t,children:r.map((i,s)=>u.jsx(Ty,{children:i},s))})}class Py{constructor(t){Mo(this,"client");this.client=Sg.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 Oy=new Py;function Dy(){const e=y.useRef(null),t=y.useCallback(async(r,i,s,a,o)=>{e.current&&e.current.abort();const l=new AbortController;e.current=l;try{a==null||a("parsing","Validating JSON structure...");let c;try{c=JSON.parse(i)}catch(k){throw new Error(`Invalid JSON: ${k instanceof Error?k.message:"Unknown parse error"}`)}a==null||a("building",`Building ${li.toLowerCase()} structure...`);const f={jsonDefinition:c,options:o||{}};f.customThemes=s??{},a==null||a("rendering",`Generating ${yt.toUpperCase()} content...`);const d={"Content-Type":"application/json"};o!=null&&o.bypassCache&&(d["X-Bypass-Cache"]="true");const p=await fetch(Hc.generate,{method:"POST",headers:d,body:JSON.stringify(f),signal:l.signal}),h=await p.json();if(!p.ok||!h.success){const k=h.error||h.message||`API request failed with status: ${p.status}`;throw new Error(k)}const{data:m,cache:w,warnings:S}=h,x=w.status==="HIT"?"HIT":w.status==="MISS"?"MISS":"UNKNOWN",_=x==="HIT"?`Served from cache (Hit rate: ${w.hitRate})`:`Generated fresh ${li.toLowerCase()}`;a==null||a("finalizing",_);const g=globalThis.atob(m.document),z=new Uint8Array(g.length);for(let k=0;k<g.length;k++)z[k]=g.charCodeAt(k);const E=new Blob([z],{type:m.contentType});if(E.size===0)throw new Error(`Received empty ${li.toLowerCase()} from API`);return{name:r,text:i,blob:E,filename:m.filename,fileId:m.fileId,cacheStatus:x,cacheHitRate:w.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${li} generation was cancelled`):c}finally{e.current===l&&(e.current=null)}},[]),n=y.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:t,generateDocument:t,cancelGeneration:n}}function Ry(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const a of i){let o=a.message;if(a.context&&Object.keys(a.context).length>0){const l=Object.entries(a.context).map(([c,f])=>`${c}: ${JSON.stringify(f)}`).join(", ");o+=` (${l})`}s.push(o)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function My({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=Ee.useState("custom");Ee.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(It,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(St,{className:"max-w-md",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Non-safe fonts in this document"}),u.jsxs(cn,{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(Cn,{children:[u.jsx(we,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(we,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const hl=yt==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],$s={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function $y({name:e,blob:t,displayReloadButton:n,iframeRef:r,autoReload:i,onToggleAutoReload:s,onManualRender:a,isGenerating:o,isRendering:l,onShowCacheMetrics:c,onShowSchemas:f,onShowFonts:d,documentText:p,warnings:h,renderingLibrary:m,setRenderingLibrary:w,onToggleChat:S,chatOpen:x,onTogglePreview:_,previewOpen:g}){const z=m!=="docxjs",[E,k]=y.useState(!1),[C,$]=y.useState(!1),[K,N]=y.useState(!1),[I,A]=y.useState(!1),[B,D]=y.useState(!1),[T,P]=y.useState(!1),{toast:J}=Xr(),{generateDocument:R}=Dy(),q=y.useContext(sd),v=y.useCallback(()=>{const V={},{customThemes:de}=q.getState();return Object.values(de).forEach(le=>{le.valid&&le.parsed&&(V[le.name]=le.parsed)}),V},[q]),fe=Ee.useMemo(()=>{if(!p)return[];try{const V=JSON.parse(p);return[...(yt==="pptx"?$m:Fm)(V)].filter(le=>!Lm(le))}catch{return[]}},[p]),[ue,b]=y.useState(!1),Y=y.useCallback(async()=>{if(t){k(!0);try{await new Promise(V=>setTimeout(V,100)),ji(`${e}${fr}`,t)}finally{setTimeout(()=>k(!1),500)}}},[t,e]),oe=y.useCallback(async()=>{if(t){if(fe.length===0){await Y();return}b(!0)}},[t,fe.length,Y]),ne=y.useCallback(async V=>{var de;if(p){k(!0);try{const le=await R(e,p,v(),void 0,{bypassCache:!0,fonts:{mode:V}});if(le.blob.size===0)J({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{ji(`${e}${fr}`,le.blob);const ye=(de=le.warnings)==null?void 0:de.find(Oe=>{var qe,Qe;return((qe=Oe.context)==null?void 0:qe.code)==="FONT_MODE_SUBSTITUTED"||((Qe=Oe.context)==null?void 0:Qe.code)==="FONT_MODE_CUSTOM"});ye&&J({title:V==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:ye.message})}}catch(le){J({title:"Export failed",description:le instanceof Error?le.message:String(le),variant:"destructive"})}finally{setTimeout(()=>k(!1),500)}}},[p,e,R,J,v]),ie=y.useCallback(async()=>{if(!(!h||h.length===0)){$(!0);try{const V=Ry(h);if(!V){J({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const de=await R("warnings",JSON.stringify(V,null,2),{});de&&typeof de=="object"&&"blob"in de&&de.blob&&(ji(`${e}-warnings${fr}`,de.blob),J({title:"Warnings downloaded",description:`Downloaded warnings document with ${h.length} warning(s).`}))}catch(V){console.error("Failed to generate warnings document:",V),J({title:"Download failed",description:V instanceof Error?V.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>$(!1),500)}}},[h,e,R,J]),W=y.useCallback(async()=>{const V=r==null?void 0:r.current;if(V!=null&&V.src){N(!0);try{await new Promise(le=>{let ye=null,Oe=!1;const qe=()=>{ye&&(clearTimeout(ye),ye=null),V.removeEventListener("load",j),V.removeEventListener("error",O)},Qe=()=>{Oe||(Oe=!0,qe(),le())},j=()=>Qe(),O=()=>Qe();V.addEventListener("load",j),V.addEventListener("error",O),ye=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),Qe()},5e3);const Z=V.src,re=Z.includes("?")?"&":"?",ee=Date.now();V.src=`${Z}${re}_reload=${ee}`})}catch(de){console.error("Iframe reload failed:",de)}finally{N(!1)}}},[r]),F=y.useCallback(async()=>{A(!0);try{await Oy.delete(`/${yt}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),J({title:"Cache Cleared",description:"All caches (document and component) have been successfully cleared.",variant:"default"})}catch(V){console.error("Failed to clear cache:",V),J({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{A(!1)}},[J]),te=y.useCallback(async()=>{if(!p){J({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}P(!0);try{const V=await fetch(`/api/${yt}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:p})});if(!V.ok){let ye=`Request failed with status ${V.status}`;try{const Oe=await V.json();Oe.message&&(ye=Oe.message)}catch{}J({title:"Failed to get standard components",description:ye,variant:"destructive"});return}const de=await V.json(),le=JSON.stringify(de.data,null,2);await navigator.clipboard.writeText(le),J({title:"Copied to clipboard",description:"Standard modules JSON has been copied"})}catch(V){console.error("Error copying standard components:",V),J({title:"Error",description:V instanceof Error?V.message:"Failed to copy standard components",variant:"destructive"})}finally{P(!1)}},[p,J]);return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"bg-sidebar 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(We,{children:[u.jsx(Ge,{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 hover:bg-muted/60 shrink-0",children:u.jsx(ed,{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 uses"," ",yt==="docx"?"docx-preview":"LibreOffice PDF conversion",". Download the ",fr," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[(!i||z)&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(we,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:a,"aria-label":"Render preview",disabled:o||l||g===!1,children:[l?u.jsx(Yt,{size:"sm"}):u.jsx(tg,{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":l?"Rendering preview...":"Render preview"})})]}),yt==="docx"&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs("div",{className:"flex items-center gap-1.5 cursor-help ml-2 mr-1",children:[u.jsx(Gn,{className:"text-xs text-muted-foreground hidden sm:inline",children:"Auto"}),u.jsx(eo,{checked:i,onCheckedChange:s,disabled:z})]})}),u.jsx(Ke,{children:u.jsx("p",{children:z?"Auto-reload is not available for Office, Docs, and LibreOffice renderers":`${i?"Disable":"Enable"} automatic preview reload on content changes`})})]}),n&&i&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:W,disabled:K||o||l,children:K?u.jsx(Yt,{size:"sm"}):u.jsx(ng,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsx("p",{children:K?"Reloading...":"Reload"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(we,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||E||o,onClick:oe,children:[E?u.jsx(Yt,{size:"sm"}):u.jsx(rg,{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 ",fr]})})]}),h&&h.length>0&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:"outline",size:"icon",className:"h-7 w-7 bg-amber-50 dark:bg-amber-950 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-800 hover:bg-amber-100 dark:hover:bg-amber-900",disabled:C||o,onClick:ie,children:C?u.jsx(Yt,{size:"sm"}):u.jsx(td,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("p",{children:["Download warnings (",h.length,")"]})})]}),m&&w&&u.jsxs(Rr,{value:m,onValueChange:w,children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(er,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(Mr,{placeholder:"Renderer"})})}),u.jsx(Ke,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(tr,{className:"text-sidebar-foreground",children:hl.map(V=>u.jsxs(En,{value:V,children:[u.jsxs(We,{children:[u.jsx(Ge,{tabIndex:-1,children:$s[V][0]}),u.jsx(Ke,{children:$s[V][1]})]})," ",V]},V))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(to,{children:[u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(no,{asChild:!0,children:u.jsx(we,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(ig,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ke,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(ds,{align:"end",className:"w-52",children:[f&&u.jsxs(Kt,{onClick:f,children:[u.jsx(sg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),d&&u.jsxs(Kt,{onClick:d,children:[u.jsx(ag,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Kt,{onClick:c,children:[u.jsx(og,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),u.jsxs(Kt,{onClick:te,disabled:!p||T,children:[u.jsx(nd,{className:"h-4 w-4 mr-2"}),T?"Copying...":"Copy standard components"]}),u.jsx(Fr,{}),u.jsxs(Kt,{onClick:()=>D(!0),disabled:I,className:"text-destructive focus:text-destructive",children:[u.jsx(Ha,{className:"h-4 w-4 mr-2"}),I?"Clearing...":"Clear all caches"]}),m&&w&&u.jsxs(u.Fragment,{children:[u.jsx(Fr,{className:"lg:hidden"}),hl.map(V=>u.jsxs(Kt,{className:"lg:hidden",onClick:()=>w(V),children:[u.jsx("span",{className:"mr-2",children:m===V?"●":"○"}),$s[V][0]," ",V]},V))]})]})]}),_&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:g?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:_,children:g?u.jsx(rd,{className:"h-3.5 w-3.5"}):u.jsx(lg,{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(wa,{shortcut:"mod+shift+p"})]})})]}),S&&u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(we,{variant:x?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:S,children:u.jsx(id,{className:"h-3.5 w-3.5"})})}),u.jsx(Ke,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[x?"Close":"Open"," AI Chat"," ",u.jsx(wa,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(My,{open:ue,onClose:()=>b(!1),nonSafeFonts:fe,onChoose:ne}),u.jsx(It,{open:B,onOpenChange:D,children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Clear all caches?"}),u.jsx(cn,{children:"This will clear document and component caches. Next generation will be uncached."})]}),u.jsxs(Cn,{children:[u.jsx(we,{variant:"outline",size:"sm",onClick:()=>D(!1),children:"Cancel"}),u.jsx(we,{variant:"destructive",size:"sm",disabled:I,onClick:async()=>{await F(),D(!1)},children:I?u.jsx(Yt,{size:"sm"}):"Clear"})]})]})})]})}const Fy=Ee.memo($y);function Ly(e,t,n){if(t.length===0)return n;const r=ml(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=ml(l,o);i[a]=c,i=c}return i[t[t.length-1]]=n,r}function ml(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Zy={safe:[],google:[]};function By(e,t){var f;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((f=r==null?void 0:r.dataset.weights)==null?void 0:f.split(",").map(Number).filter(d=>!Number.isNaN(d)))??[]),a=new Set([...s,...i]);if(r&&a.size===s.size)return;const o=[...a].sort((d,p)=>d-p).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${o}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...a].sort((d,p)=>d-p).join(",")}function Vy(){const e=Ae(i=>i.activeTab),t=Ae(i=>i.documents),n=Ae(i=>i.documentTypes),r=Ae(i=>i.saveDocument);return y.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 Uy(){const e=Ae(r=>r.activeTab),t=Ae(r=>r.documents),n=Ae(r=>r.saveDocument);return y.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=Ly(a,r,i);return n(e,JSON.stringify(o,null,2)),{ok:!0,name:e}},[e,t,n])}function Jy(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 gl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Hy=({open:e,onOpenChange:t})=>{const n=vi(P=>P.open),r=vi(P=>P.contextual),i=vi(P=>P.close),s=e??n,a=r,o=y.useCallback(P=>{t&&t(P),P||i()},[t,i]),[l,c]=y.useState(Zy),[f,d]=y.useState(!1),[p,h]=y.useState(""),[m,w]=y.useState("safe"),[S,x]=y.useState(null),[_,g]=y.useState(null),{toast:z}=Xr(),E=Vy(),k=Uy(),C=Ae(P=>P.activeTab),$=Ae(P=>P.documentTypes),K=C&&$[C]==="application/json+theme",N=!!a||K;y.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(d(!0),fetch("/api/fonts/catalog").then(P=>P.json()).then(P=>c(P)).catch(P=>{z({variant:"destructive",title:"Font catalog unavailable",description:P.message})}).finally(()=>d(!1))))},[s,l,z]),y.useEffect(()=>{if(!(m!=="google"||l.google.length===0))for(const P of l.google)By(P.family,P.weights)},[m,l]);const I=y.useMemo(()=>l.safe.filter(P=>P.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),A=y.useMemo(()=>l.google.filter(P=>P.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),B=y.useCallback(async P=>{try{await navigator.clipboard.writeText(P),g(P),setTimeout(()=>g(null),1500)}catch{z({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[z]),D=y.useCallback(async(P,J,R)=>{x(P);try{const q=E(v=>(Jy(v,R,P),v));if(!q.ok){z({variant:"destructive",title:"Could not insert font",description:q.error});return}z({title:"Font inserted",description:`${P} set as ${R} font in "${q.name}".`})}finally{x(null)}},[E,z]),T=y.useCallback(async P=>{if(a){x(P);try{const J=k(a.jsonPath,P);if(!J.ok){z({variant:"destructive",title:"Could not insert font",description:J.error});return}z({title:"Font inserted",description:`${P} set at ${gl(a.jsonPath)}.`}),o(!1)}finally{x(null)}}},[a,k,z,o]);return u.jsx(It,{open:s,onOpenChange:o,children:u.jsxs(St,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:a?`Font for ${gl(a.jsonPath)}`:"Fonts"})}),!a&&!K&&u.jsx(Ri,{children:u.jsxs(Mi,{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(Wd,{value:m,onValueChange:P=>w(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ro,{children:[u.jsxs(Lr,{value:"safe",children:["Safe",u.jsx(Vt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(Lr,{value:"google",children:["Google",u.jsx(Vt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]})]}),u.jsx(ei,{type:"search",placeholder:"Search fonts...",value:p,onChange:P=>h(P.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(Zr,{value:"safe",className:"m-0",children:f&&I.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(ua,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:I.map(P=>u.jsx(xl,{family:P,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${P}", sans-serif`},onCopy:()=>B(P),copied:_===P,contextual:!!a,onUseThis:()=>T(P),onInsertHeading:()=>D(P,"safe","heading"),onInsertBody:()=>D(P,"safe","body"),applying:S===P,disabled:!N},P))})}),u.jsx(Zr,{value:"google",className:"m-0",children:f&&A.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(ua,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:A.map(P=>u.jsx(xl,{family:P.family,meta:u.jsxs("span",{className:"text-xs",children:[P.category," · ",P.weights.length," weights"]}),previewStyle:{fontFamily:`"${P.family}", sans-serif`},onCopy:()=>B(P.family),copied:_===P.family,contextual:!!a,onUseThis:()=>T(P.family),onInsertHeading:()=>D(P.family,"google","heading"),onInsertBody:()=>D(P.family,"google","body"),applying:S===P.family,disabled:!N,extraAction:u.jsx(Wy,{family:P.family,weights:P.weights,hasItalic:P.hasItalic})},P.family))})})]})]})]})})},qy="The quick brown fox jumps over the lazy dog",Wy=({family:e,weights:t,hasItalic:n})=>{const r=y.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(to,{children:[u.jsx(no,{asChild:!0,children:u.jsx(we,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(ds,{align:"end",className:"min-w-[260px]",children:[u.jsxs(qd,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(Fr,{}),r.map(i=>{const s=Zm[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)})]})]})},xl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:a,onInsertHeading:o,onInsertBody:l,applying:c,disabled:f,extraAction:d})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:qy}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(we,{size:"sm",onClick:a,disabled:c||f,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(we,{size:"sm",variant:"secondary",onClick:o,disabled:c||f,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(we,{size:"sm",variant:"secondary",onClick:l,disabled:c||f,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),d,u.jsx(we,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(un,{className:"h-4 w-4"}):u.jsx(as,{className:"h-4 w-4"})})]})]});function yl({previewOpen:e,onTogglePreview:t}){const n=vn($=>$.name||""),r=vn($=>$.blob),i=vn($=>$.isGenerating),s=vn($=>$.text),a=vn($=>$.warnings),o=vn($=>$.isRendering),l=ui($=>$.autoReload),c=ui($=>$.renderingLibrary),f=ui($=>$.setSettings),d=ui($=>$.useGlobalPreviewHeader??!0),p=Ae($=>$.activeTab),h=Ae($=>$.documentTypes),m=p&&h[p]==="application/json+theme"?"theme":"document",w=Te($=>$.chatOpen),S=Te($=>$.toggleChat),[x,_]=Ee.useState(!1),g=vi($=>$.openFor);if(!d)return null;const z=y.useCallback(()=>f({saveDocumentDebounceWait:2e3,autoReload:!l}),[l,f]),E=y.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),k=y.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),C=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(Fy,{name:C,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:z,onManualRender:E,isGenerating:i,isRendering:!!o,onShowCacheMetrics:k,onShowSchemas:()=>_(!0),onShowFonts:()=>g(),documentText:s,warnings:a,renderingLibrary:c,setRenderingLibrary:$=>f({renderingLibrary:$}),onToggleChat:S,chatOpen:w,onTogglePreview:t,previewOpen:e}),u.jsx(Gd,{open:x,onOpenChange:_,defaultTab:m==="theme"?"theme":"document"}),u.jsx(Hy,{})]})}function Gy(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Ky=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Yy=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Xy={};function bl(e,t){return(Xy.jsx?Yy:Ky).test(e)}const Qy=/[ \t\n\f\r]/g;function eb(e){return typeof e=="object"?e.type==="text"?vl(e.value):!1:vl(e)}function vl(e){return e.replace(Qy,"")===""}class ni{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}ni.prototype.normal={};ni.prototype.property={};ni.prototype.space=void 0;function vf(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new ni(n,r,t)}function ka(e){return e.toLowerCase()}class bt{constructor(t,n){this.attribute=n,this.property=t}}bt.prototype.attribute="";bt.prototype.booleanish=!1;bt.prototype.boolean=!1;bt.prototype.commaOrSpaceSeparated=!1;bt.prototype.commaSeparated=!1;bt.prototype.defined=!1;bt.prototype.mustUseProperty=!1;bt.prototype.number=!1;bt.prototype.overloadedBoolean=!1;bt.prototype.property="";bt.prototype.spaceSeparated=!1;bt.prototype.space=void 0;let tb=0;const ke=An(),tt=An(),Sa=An(),X=An(),Fe=An(),Xn=An(),wt=An();function An(){return 2**++tb}const _a=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:tt,commaOrSpaceSeparated:wt,commaSeparated:Xn,number:X,overloadedBoolean:Sa,spaceSeparated:Fe},Symbol.toStringTag,{value:"Module"})),Fs=Object.keys(_a);class lo extends bt{constructor(t,n,r,i){let s=-1;if(super(t,n),wl(this,"space",i),typeof r=="number")for(;++s<Fs.length;){const a=Fs[s];wl(this,Fs[s],(r&_a[a])===_a[a])}}}lo.prototype.defined=!0;function wl(e,t,n){n&&(e[t]=n)}function lr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new lo(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[ka(r)]=r,n[ka(s.attribute)]=r}return new ni(t,n,e.space)}const wf=lr({properties:{ariaActiveDescendant:null,ariaAtomic:tt,ariaAutoComplete:null,ariaBusy:tt,ariaChecked:tt,ariaColCount:X,ariaColIndex:X,ariaColSpan:X,ariaControls:Fe,ariaCurrent:null,ariaDescribedBy:Fe,ariaDetails:null,ariaDisabled:tt,ariaDropEffect:Fe,ariaErrorMessage:null,ariaExpanded:tt,ariaFlowTo:Fe,ariaGrabbed:tt,ariaHasPopup:null,ariaHidden:tt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Fe,ariaLevel:X,ariaLive:null,ariaModal:tt,ariaMultiLine:tt,ariaMultiSelectable:tt,ariaOrientation:null,ariaOwns:Fe,ariaPlaceholder:null,ariaPosInSet:X,ariaPressed:tt,ariaReadOnly:tt,ariaRelevant:null,ariaRequired:tt,ariaRoleDescription:Fe,ariaRowCount:X,ariaRowIndex:X,ariaRowSpan:X,ariaSelected:tt,ariaSetSize:X,ariaSort:null,ariaValueMax:X,ariaValueMin:X,ariaValueNow:X,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function kf(e,t){return t in e?e[t]:t}function Sf(e,t){return kf(e,t.toLowerCase())}const nb=lr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:Xn,acceptCharset:Fe,accessKey:Fe,action:null,allow:null,allowFullScreen:ke,allowPaymentRequest:ke,allowUserMedia:ke,alt:null,as:null,async:ke,autoCapitalize:null,autoComplete:Fe,autoFocus:ke,autoPlay:ke,blocking:Fe,capture:null,charSet:null,checked:ke,cite:null,className:Fe,cols:X,colSpan:null,content:null,contentEditable:tt,controls:ke,controlsList:Fe,coords:X|Xn,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Sa,draggable:tt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Fe,height:X,hidden:Sa,high:X,href:null,hrefLang:null,htmlFor:Fe,httpEquiv:Fe,id:null,imageSizes:null,imageSrcSet:null,inert:ke,inputMode:null,integrity:null,is:null,isMap:ke,itemId:null,itemProp:Fe,itemRef:Fe,itemScope:ke,itemType:Fe,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:ke,low:X,manifest:null,max:null,maxLength:X,media:null,method:null,min:null,minLength:X,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:X,pattern:null,ping:Fe,placeholder:null,playsInline:ke,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:ke,referrerPolicy:null,rel:Fe,required:ke,reversed:ke,rows:X,rowSpan:X,sandbox:Fe,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:X,sizes:null,slot:null,span:X,spellCheck:tt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:X,step:null,style:null,tabIndex:X,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:tt,width:X,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Fe,axis:null,background:null,bgColor:null,border:X,borderColor:null,bottomMargin:X,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:X,leftMargin:X,link:null,longDesc:null,lowSrc:null,marginHeight:X,marginWidth:X,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:X,rules:null,scheme:null,scrolling:tt,standby:null,summary:null,text:null,topMargin:X,valueType:null,version:null,vAlign:null,vLink:null,vSpace:X,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:X,security:null,unselectable:null},space:"html",transform:Sf}),rb=lr({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:wt,accentHeight:X,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:X,amplitude:X,arabicForm:null,ascent:X,attributeName:null,attributeType:null,azimuth:X,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:X,by:null,calcMode:null,capHeight:X,className:Fe,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:X,diffuseConstant:X,direction:null,display:null,dur:null,divisor:X,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:X,enableBackground:null,end:null,event:null,exponent:X,externalResourcesRequired:null,fill:null,fillOpacity:X,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:Xn,g2:Xn,glyphName:Xn,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:X,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:X,horizOriginX:X,horizOriginY:X,id:null,ideographic:X,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:X,k:X,k1:X,k2:X,k3:X,k4:X,kernelMatrix:wt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:X,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:X,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:X,overlineThickness:X,paintOrder:null,panose1:null,path:null,pathLength:X,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Fe,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:X,pointsAtY:X,pointsAtZ:X,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:wt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:wt,rev:wt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:wt,requiredFeatures:wt,requiredFonts:wt,requiredFormats:wt,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:X,specularExponent:X,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:X,strikethroughThickness:X,string:null,stroke:null,strokeDashArray:wt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:X,strokeOpacity:X,strokeWidth:null,style:null,surfaceScale:X,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:wt,tabIndex:X,tableValues:null,target:null,targetX:X,targetY:X,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:wt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:X,underlineThickness:X,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:X,values:null,vAlphabetic:X,vMathematical:X,vectorEffect:null,vHanging:X,vIdeographic:X,version:null,vertAdvY:X,vertOriginX:X,vertOriginY:X,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:X,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:kf}),_f=lr({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()}}),jf=lr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:Sf}),Nf=lr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),ib={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"},sb=/[A-Z]/g,kl=/-[a-z]/g,ab=/^data[-\w.:]+$/i;function ob(e,t){const n=ka(t);let r=t,i=bt;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&ab.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(kl,ub);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!kl.test(s)){let a=s.replace(sb,lb);a.charAt(0)!=="-"&&(a="-"+a),t="data"+a}}i=lo}return new i(r,t)}function lb(e){return"-"+e.toLowerCase()}function ub(e){return e.charAt(1).toUpperCase()}const cb=vf([wf,nb,_f,jf,Nf],"html"),uo=vf([wf,rb,_f,jf,Nf],"svg");function db(e){return e.join(" ").trim()}var Mn={},Ls,Sl;function fb(){if(Sl)return Ls;Sl=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=`
|
|
3
3
|
`,c="/",f="*",d="",p="comment",h="declaration";function m(S,x){if(typeof S!="string")throw new TypeError("First argument must be a string");if(!S)return[];x=x||{};var _=1,g=1;function z(D){var T=D.match(t);T&&(_+=T.length);var P=D.lastIndexOf(l);g=~P?D.length-P:g+D.length}function E(){var D={line:_,column:g};return function(T){return T.position=new k(D),K(),T}}function k(D){this.start=D,this.end={line:_,column:g},this.source=x.source}k.prototype.content=S;function C(D){var T=new Error(x.source+":"+_+":"+g+": "+D);if(T.reason=D,T.filename=x.source,T.line=_,T.column=g,T.source=S,!x.silent)throw T}function $(D){var T=D.exec(S);if(T){var P=T[0];return z(P),S=S.slice(P.length),T}}function K(){$(n)}function N(D){var T;for(D=D||[];T=I();)T!==!1&&D.push(T);return D}function I(){var D=E();if(!(c!=S.charAt(0)||f!=S.charAt(1))){for(var T=2;d!=S.charAt(T)&&(f!=S.charAt(T)||c!=S.charAt(T+1));)++T;if(T+=2,d===S.charAt(T-1))return C("End of comment missing");var P=S.slice(2,T-2);return g+=2,z(P),S=S.slice(T),g+=2,D({type:p,comment:P})}}function A(){var D=E(),T=$(r);if(T){if(I(),!$(i))return C("property missing ':'");var P=$(s),J=D({type:h,property:w(T[0].replace(e,d)),value:P?w(P[0].replace(e,d)):d});return $(a),J}}function B(){var D=[];N(D);for(var T;T=A();)T!==!1&&(D.push(T),N(D));return D}return K(),B()}function w(S){return S?S.replace(o,d):d}return Ls=m,Ls}var _l;function pb(){if(_l)return Mn;_l=1;var e=Mn&&Mn.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Mn,"__esModule",{value:!0}),Mn.default=n;const t=e(fb());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const a=(0,t.default)(r),o=typeof i=="function";return a.forEach(l=>{if(l.type!=="declaration")return;const{property:c,value:f}=l;o?i(c,f,l):f&&(s=s||{},s[c]=f)}),s}return Mn}var xr={},jl;function hb(){if(jl)return xr;jl=1,Object.defineProperty(xr,"__esModule",{value:!0}),xr.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(c){return!c||n.test(c)||e.test(c)},a=function(c,f){return f.toUpperCase()},o=function(c,f){return"".concat(f,"-")},l=function(c,f){return f===void 0&&(f={}),s(c)?c:(c=c.toLowerCase(),f.reactCompat?c=c.replace(i,o):c=c.replace(r,o),c.replace(t,a))};return xr.camelCase=l,xr}var yr,Nl;function mb(){if(Nl)return yr;Nl=1;var e=yr&&yr.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(pb()),n=hb();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,yr=r,yr}var gb=mb();const xb=Ua(gb),Cf=Ef("end"),co=Ef("start");function Ef(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 yb(e){const t=co(e),n=Cf(e);if(t&&n)return{start:t,end:n}}function Pr(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Cl(e.position):"start"in e||"end"in e?Cl(e):"line"in e||"column"in e?ja(e):""}function ja(e){return El(e&&e.line)+":"+El(e&&e.column)}function Cl(e){return ja(e&&e.start)+"-"+ja(e&&e.end)}function El(e){return e&&typeof e=="number"?e:1}class at 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=Pr(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}}at.prototype.file="";at.prototype.name="";at.prototype.reason="";at.prototype.message="";at.prototype.stack="";at.prototype.column=void 0;at.prototype.line=void 0;at.prototype.ancestors=void 0;at.prototype.cause=void 0;at.prototype.fatal=void 0;at.prototype.place=void 0;at.prototype.ruleId=void 0;at.prototype.source=void 0;const fo={}.hasOwnProperty,bb=new Map,vb=/[A-Z]/g,wb=new Set(["table","tbody","thead","tfoot","tr"]),kb=new Set(["td","th"]),If="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function Sb(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=Tb(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=zb(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"?uo:cb,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=zf(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function zf(e,t,n){if(t.type==="element")return _b(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return jb(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return Cb(e,t,n);if(t.type==="mdxjsEsm")return Nb(e,t);if(t.type==="root")return Eb(e,t,n);if(t.type==="text")return Ib(e,t)}function _b(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=uo,e.schema=i),e.ancestors.push(t);const s=Af(e,t.tagName,!1),a=Ab(e,t);let o=ho(e,t);return wb.has(t.tagName)&&(o=o.filter(function(l){return typeof l=="string"?!eb(l):!0})),Tf(e,a,s,t),po(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function jb(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)}Ur(e,t.position)}function Nb(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Ur(e,t.position)}function Cb(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=uo,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:Af(e,t.name,!0),a=Pb(e,t),o=ho(e,t);return Tf(e,a,s,t),po(a,o),e.ancestors.pop(),e.schema=r,e.create(t,s,a,n)}function Eb(e,t,n){const r={};return po(r,ho(e,t)),e.create(t,e.Fragment,r,n)}function Ib(e,t){return t.value}function Tf(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function po(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function zb(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 Tb(e,t){return n;function n(r,i,s,a){const o=Array.isArray(s.children),l=co(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 Ab(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&fo.call(t.properties,i)){const s=Ob(e,i,t.properties[i]);if(s){const[a,o]=s;e.tableCellAlignToStyle&&a==="align"&&typeof o=="string"&&kb.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 Pb(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 Ur(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 Ur(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function ho(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:bb;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=zf(e,s,a);o!==void 0&&n.push(o)}return n}function Ob(e,t,n){const r=ob(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Gy(n):db(n)),r.property==="style"){let i=typeof n=="object"?n:Db(e,String(n));return e.stylePropertyNameCase==="css"&&(i=Rb(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?ib[r.property]||r.property:r.attribute,n]}}function Db(e,t){try{return xb(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new at("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=If+"#cannot-parse-style-attribute",i}}function Af(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=bl(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=bl(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return fo.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);Ur(e)}function Ur(e,t){const n=new at("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=If+"#cannot-handle-mdx-estrees-without-createevaluater",n}function Rb(e){const t={};let n;for(n in e)fo.call(e,n)&&(t[Mb(n)]=e[n]);return t}function Mb(e){let t=e.replace(vb,$b);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function $b(e){return"-"+e.toLowerCase()}const Zs={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"]},Fb={};function mo(e,t){const n=Fb,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Pf(e,r,i)}function Pf(e,t,n){if(Lb(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 Il(e.children,t,n)}return Array.isArray(e)?Il(e,t,n):""}function Il(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=Pf(e[i],t,n);return r.join("")}function Lb(e){return!!(e&&typeof e=="object")}const zl=document.createElement("i");function go(e){const t="&"+e+";";zl.innerHTML=t;const n=zl.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function _t(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 Et(e,t){return e.length>0?(_t(e,e.length,0,t),e):t}const Tl={}.hasOwnProperty;function Of(e){const t={};let n=-1;for(;++n<e.length;)Zb(t,e[n]);return t}function Zb(e,t){let n;for(n in t){const i=(Tl.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let a;if(s)for(a in s){Tl.call(i,a)||(i[a]=[]);const o=s[a];Bb(i[a],Array.isArray(o)?o:o?[o]:[])}}}function Bb(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);_t(e,0,0,r)}function Df(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 Mt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const dt=pn(/[A-Za-z]/),st=pn(/[\dA-Za-z]/),Vb=pn(/[#-'*+\--9=?A-Z^-~]/);function Bi(e){return e!==null&&(e<32||e===127)}const Na=pn(/\d/),Ub=pn(/[\dA-Fa-f]/),Jb=pn(/[!-/:-@[-`{-~]/);function ge(e){return e!==null&&e<-2}function Me(e){return e!==null&&(e<0||e===32)}function Ne(e){return e===-2||e===-1||e===32}const gs=pn(new RegExp("\\p{P}|\\p{S}","u")),zn=pn(/\s/);function pn(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function ur(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let a="";if(s===37&&st(e.charCodeAt(n+1))&&st(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 Ne(l)?(e.enter(n),o(l)):t(l)}function o(l){return Ne(l)&&s++<i?(e.consume(l),o):(e.exit(n),t(l))}}const Hb={tokenize:qb};function qb(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 ge(o)?(e.consume(o),e.exit("chunkText"),s):(e.consume(o),a)}}const Wb={tokenize:Gb},Al={tokenize:Kb};function Gb(e){const t=this,n=[];let r=0,i,s,a;return o;function o(g){if(r<n.length){const z=n[r];return t.containerState=z[1],e.attempt(z[0].continuation,l,c)(g)}return c(g)}function l(g){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&_();const z=t.events.length;let E=z,k;for(;E--;)if(t.events[E][0]==="exit"&&t.events[E][1].type==="chunkFlow"){k=t.events[E][1].end;break}x(r);let C=z;for(;C<t.events.length;)t.events[C][1].end={...k},C++;return _t(t.events,E+1,0,t.events.slice(z)),t.events.length=C,c(g)}return o(g)}function c(g){if(r===n.length){if(!i)return p(g);if(i.currentConstruct&&i.currentConstruct.concrete)return m(g);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Al,f,d)(g)}function f(g){return i&&_(),x(r),p(g)}function d(g){return t.parser.lazy[t.now().line]=r!==n.length,a=t.now().offset,m(g)}function p(g){return t.containerState={},e.attempt(Al,h,m)(g)}function h(g){return r++,n.push([t.currentConstruct,t.containerState]),p(g)}function m(g){if(g===null){i&&_(),x(0),e.consume(g);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),w(g)}function w(g){if(g===null){S(e.exit("chunkFlow"),!0),x(0),e.consume(g);return}return ge(g)?(e.consume(g),S(e.exit("chunkFlow")),r=0,t.interrupt=void 0,o):(e.consume(g),w)}function S(g,z){const E=t.sliceStream(g);if(z&&E.push(null),g.previous=s,s&&(s.next=g),s=g,i.defineSkip(g.start),i.write(E),t.parser.lazy[g.start.line]){let k=i.events.length;for(;k--;)if(i.events[k][1].start.offset<a&&(!i.events[k][1].end||i.events[k][1].end.offset>a))return;const C=t.events.length;let $=C,K,N;for(;$--;)if(t.events[$][0]==="exit"&&t.events[$][1].type==="chunkFlow"){if(K){N=t.events[$][1].end;break}K=!0}for(x(r),k=C;k<t.events.length;)t.events[k][1].end={...N},k++;_t(t.events,$+1,0,t.events.slice(C)),t.events.length=k}}function x(g){let z=n.length;for(;z-- >g;){const E=n[z];t.containerState=E[1],E[0].exit.call(t,e)}n.length=g}function _(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Kb(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 rr(e){if(e===null||Me(e)||zn(e))return 1;if(gs(e))return 2}function xs(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 Ca={name:"attention",resolveAll:Yb,tokenize:Xb};function Yb(e,t){let n=-1,r,i,s,a,o,l,c,f;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const d={...e[r][1].end},p={...e[n][1].start};Pl(d,-l),Pl(p,l),a={type:l>1?"strongSequence":"emphasisSequence",start:d,end:{...e[r][1].end}},o={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:p},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=Et(c,[["enter",e[r][1],t],["exit",e[r][1],t]])),c=Et(c,[["enter",i,t],["enter",a,t],["exit",a,t],["enter",s,t]]),c=Et(c,xs(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),c=Et(c,[["exit",s,t],["enter",o,t],["exit",o,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(f=2,c=Et(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):f=0,_t(e,r-1,n-r+3,c),n=r+c.length-f-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function Xb(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=rr(r);let s;return a;function a(l){return s=l,e.enter("attentionSequence"),o(l)}function o(l){if(l===s)return e.consume(l),o;const c=e.exit("attentionSequence"),f=rr(l),d=!f||f===2&&i||n.includes(l),p=!i||i===2&&f||n.includes(r);return c._open=!!(s===42?d:d&&(i||!p)),c._close=!!(s===42?p:p&&(f||!d)),t(l)}}function Pl(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Qb={name:"autolink",tokenize:ev};function ev(e,t,n){let r=0;return i;function i(h){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(h){return dt(h)?(e.consume(h),a):h===64?n(h):c(h)}function a(h){return h===43||h===45||h===46||st(h)?(r=1,o(h)):c(h)}function o(h){return h===58?(e.consume(h),r=0,l):(h===43||h===45||h===46||st(h))&&r++<32?(e.consume(h),o):(r=0,c(h))}function l(h){return h===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.exit("autolink"),t):h===null||h===32||h===60||Bi(h)?n(h):(e.consume(h),l)}function c(h){return h===64?(e.consume(h),f):Vb(h)?(e.consume(h),c):n(h)}function f(h){return st(h)?d(h):n(h)}function d(h){return h===46?(e.consume(h),r=0,f):h===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.exit("autolink"),t):p(h)}function p(h){if((h===45||st(h))&&r++<63){const m=h===45?p:d;return e.consume(h),m}return n(h)}}const ri={partial:!0,tokenize:tv};function tv(e,t,n){return r;function r(s){return Ne(s)?ze(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||ge(s)?t(s):n(s)}}const Rf={continuation:{tokenize:rv},exit:iv,name:"blockQuote",tokenize:nv};function nv(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 Ne(a)?(e.enter("blockQuotePrefixWhitespace"),e.consume(a),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(a))}}function rv(e,t,n){const r=this;return i;function i(a){return Ne(a)?ze(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a):s(a)}function s(a){return e.attempt(Rf,t,n)(a)}}function iv(e){e.exit("blockQuote")}const Mf={name:"characterEscape",tokenize:sv};function sv(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 Jb(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const $f={name:"characterReference",tokenize:av};function av(e,t,n){const r=this;let i=0,s,a;return o;function o(d){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),l}function l(d){return d===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(d),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),s=31,a=st,f(d))}function c(d){return d===88||d===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(d),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,a=Ub,f):(e.enter("characterReferenceValue"),s=7,a=Na,f(d))}function f(d){if(d===59&&i){const p=e.exit("characterReferenceValue");return a===st&&!go(r.sliceSerialize(p))?n(d):(e.enter("characterReferenceMarker"),e.consume(d),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return a(d)&&i++<s?(e.consume(d),f):n(d)}}const Ol={partial:!0,tokenize:lv},Dl={concrete:!0,name:"codeFenced",tokenize:ov};function ov(e,t,n){const r=this,i={partial:!0,tokenize:E};let s=0,a=0,o;return l;function l(k){return c(k)}function c(k){const C=r.events[r.events.length-1];return s=C&&C[1].type==="linePrefix"?C[2].sliceSerialize(C[1],!0).length:0,o=k,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),f(k)}function f(k){return k===o?(a++,e.consume(k),f):a<3?n(k):(e.exit("codeFencedFenceSequence"),Ne(k)?ze(e,d,"whitespace")(k):d(k))}function d(k){return k===null||ge(k)?(e.exit("codeFencedFence"),r.interrupt?t(k):e.check(Ol,w,z)(k)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(k))}function p(k){return k===null||ge(k)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),d(k)):Ne(k)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),ze(e,h,"whitespace")(k)):k===96&&k===o?n(k):(e.consume(k),p)}function h(k){return k===null||ge(k)?d(k):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),m(k))}function m(k){return k===null||ge(k)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),d(k)):k===96&&k===o?n(k):(e.consume(k),m)}function w(k){return e.attempt(i,z,S)(k)}function S(k){return e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),x}function x(k){return s>0&&Ne(k)?ze(e,_,"linePrefix",s+1)(k):_(k)}function _(k){return k===null||ge(k)?e.check(Ol,w,z)(k):(e.enter("codeFlowValue"),g(k))}function g(k){return k===null||ge(k)?(e.exit("codeFlowValue"),_(k)):(e.consume(k),g)}function z(k){return e.exit("codeFenced"),t(k)}function E(k,C,$){let K=0;return N;function N(T){return k.enter("lineEnding"),k.consume(T),k.exit("lineEnding"),I}function I(T){return k.enter("codeFencedFence"),Ne(T)?ze(k,A,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(T):A(T)}function A(T){return T===o?(k.enter("codeFencedFenceSequence"),B(T)):$(T)}function B(T){return T===o?(K++,k.consume(T),B):K>=a?(k.exit("codeFencedFenceSequence"),Ne(T)?ze(k,D,"whitespace")(T):D(T)):$(T)}function D(T){return T===null||ge(T)?(k.exit("codeFencedFence"),C(T)):$(T)}}}function lv(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 Bs={name:"codeIndented",tokenize:cv},uv={partial:!0,tokenize:dv};function cv(e,t,n){const r=this;return i;function i(c){return e.enter("codeIndented"),ze(e,s,"linePrefix",5)(c)}function s(c){const f=r.events[r.events.length-1];return f&&f[1].type==="linePrefix"&&f[2].sliceSerialize(f[1],!0).length>=4?a(c):n(c)}function a(c){return c===null?l(c):ge(c)?e.attempt(uv,a,l)(c):(e.enter("codeFlowValue"),o(c))}function o(c){return c===null||ge(c)?(e.exit("codeFlowValue"),a(c)):(e.consume(c),o)}function l(c){return e.exit("codeIndented"),t(c)}}function dv(e,t,n){const r=this;return i;function i(a){return r.parser.lazy[r.now().line]?n(a):ge(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):ge(a)?i(a):n(a)}}const fv={name:"codeText",previous:hv,resolve:pv,tokenize:mv};function pv(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 hv(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function mv(e,t,n){let r=0,i,s;return a;function a(d){return e.enter("codeText"),e.enter("codeTextSequence"),o(d)}function o(d){return d===96?(e.consume(d),r++,o):(e.exit("codeTextSequence"),l(d))}function l(d){return d===null?n(d):d===32?(e.enter("space"),e.consume(d),e.exit("space"),l):d===96?(s=e.enter("codeTextSequence"),i=0,f(d)):ge(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),l):(e.enter("codeTextData"),c(d))}function c(d){return d===null||d===32||d===96||ge(d)?(e.exit("codeTextData"),l(d)):(e.consume(d),c)}function f(d){return d===96?(e.consume(d),i++,f):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(d)):(s.type="codeTextData",c(d))}}class gv{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&&br(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),br(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),br(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);br(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);br(this.left,n.reverse())}}}function br(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 Ff(e){const t={};let n=-1,r,i,s,a,o,l,c;const f=new gv(e);for(;++n<f.length;){for(;n in t;)n=t[n];if(r=f.get(n),n&&r[1].type==="chunkFlow"&&f.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,xv(f,n)),n=t[n],c=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(a=f.get(s),a[1].type==="lineEnding"||a[1].type==="lineEndingBlank")a[0]==="enter"&&(i&&(f.get(i)[1].type="lineEndingBlank"),a[1].type="lineEnding",i=s);else if(!(a[1].type==="linePrefix"||a[1].type==="listItemIndent"))break;i&&(r[1].end={...f.get(i)[1].start},o=f.slice(i,n),o.unshift(r),f.splice(i,n-i+1,o))}}return _t(e,0,Number.POSITIVE_INFINITY,f.slice(0)),!c}function xv(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let a=n._tokenizer;a||(a=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(a._contentTypeTextTrailing=!0));const o=a.events,l=[],c={};let f,d,p=-1,h=n,m=0,w=0;const S=[w];for(;h;){for(;e.get(++i)[1]!==h;);s.push(i),h._tokenizer||(f=r.sliceStream(h),h.next||f.push(null),d&&a.defineSkip(h.start),h._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=!0),a.write(f),h._isInFirstContentOfListItem&&(a._gfmTasklistFirstContentOfListItem=void 0)),d=h,h=h.next}for(h=n;++p<o.length;)o[p][0]==="exit"&&o[p-1][0]==="enter"&&o[p][1].type===o[p-1][1].type&&o[p][1].start.line!==o[p][1].end.line&&(w=p+1,S.push(w),h._tokenizer=void 0,h.previous=void 0,h=h.next);for(a.events=[],h?(h._tokenizer=void 0,h.previous=void 0):S.pop(),p=S.length;p--;){const x=o.slice(S[p],S[p+1]),_=s.pop();l.push([_,_+x.length-1]),e.splice(_,2,x)}for(l.reverse(),p=-1;++p<l.length;)c[m+l[p][0]]=m+l[p][1],m+=l[p][1]-l[p][0]-1;return c}const yv={resolve:vv,tokenize:wv},bv={partial:!0,tokenize:kv};function vv(e){return Ff(e),e}function wv(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):ge(o)?e.check(bv,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 kv(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||ge(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 Lf(e,t,n,r,i,s,a,o,l){const c=l||Number.POSITIVE_INFINITY;let f=0;return d;function d(x){return x===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(x),e.exit(s),p):x===null||x===32||x===41||Bi(x)?n(x):(e.enter(r),e.enter(a),e.enter(o),e.enter("chunkString",{contentType:"string"}),w(x))}function p(x){return x===62?(e.enter(s),e.consume(x),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(o),e.enter("chunkString",{contentType:"string"}),h(x))}function h(x){return x===62?(e.exit("chunkString"),e.exit(o),p(x)):x===null||x===60||ge(x)?n(x):(e.consume(x),x===92?m:h)}function m(x){return x===60||x===62||x===92?(e.consume(x),h):h(x)}function w(x){return!f&&(x===null||x===41||Me(x))?(e.exit("chunkString"),e.exit(o),e.exit(a),e.exit(r),t(x)):f<c&&x===40?(e.consume(x),f++,w):x===41?(e.consume(x),f--,w):x===null||x===32||x===40||Bi(x)?n(x):(e.consume(x),x===92?S:w)}function S(x){return x===40||x===41||x===92?(e.consume(x),w):w(x)}}function Zf(e,t,n,r,i,s){const a=this;let o=0,l;return c;function c(h){return e.enter(r),e.enter(i),e.consume(h),e.exit(i),e.enter(s),f}function f(h){return o>999||h===null||h===91||h===93&&!l||h===94&&!o&&"_hiddenFootnoteSupport"in a.parser.constructs?n(h):h===93?(e.exit(s),e.enter(i),e.consume(h),e.exit(i),e.exit(r),t):ge(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),f):(e.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===null||h===91||h===93||ge(h)||o++>999?(e.exit("chunkString"),f(h)):(e.consume(h),l||(l=!Ne(h)),h===92?p:d)}function p(h){return h===91||h===92||h===93?(e.consume(h),o++,d):d(h)}}function Bf(e,t,n,r,i,s){let a;return o;function o(p){return p===34||p===39||p===40?(e.enter(r),e.enter(i),e.consume(p),e.exit(i),a=p===40?41:p,l):n(p)}function l(p){return p===a?(e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):(e.enter(s),c(p))}function c(p){return p===a?(e.exit(s),l(a)):p===null?n(p):ge(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),ze(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===a||p===null||ge(p)?(e.exit("chunkString"),c(p)):(e.consume(p),p===92?d:f)}function d(p){return p===a||p===92?(e.consume(p),f):f(p)}}function Or(e,t){let n;return r;function r(i){return ge(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):Ne(i)?ze(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const Sv={name:"definition",tokenize:jv},_v={partial:!0,tokenize:Nv};function jv(e,t,n){const r=this;let i;return s;function s(h){return e.enter("definition"),a(h)}function a(h){return Zf.call(r,e,o,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function o(h){return i=Mt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),h===58?(e.enter("definitionMarker"),e.consume(h),e.exit("definitionMarker"),l):n(h)}function l(h){return Me(h)?Or(e,c)(h):c(h)}function c(h){return Lf(e,f,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function f(h){return e.attempt(_v,d,d)(h)}function d(h){return Ne(h)?ze(e,p,"whitespace")(h):p(h)}function p(h){return h===null||ge(h)?(e.exit("definition"),r.parser.defined.push(i),t(h)):n(h)}}function Nv(e,t,n){return r;function r(o){return Me(o)?Or(e,i)(o):n(o)}function i(o){return Bf(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(o)}function s(o){return Ne(o)?ze(e,a,"whitespace")(o):a(o)}function a(o){return o===null||ge(o)?t(o):n(o)}}const Cv={name:"hardBreakEscape",tokenize:Ev};function Ev(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return ge(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const Iv={name:"headingAtx",resolve:zv,tokenize:Tv};function zv(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"},_t(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function Tv(e,t,n){let r=0;return i;function i(f){return e.enter("atxHeading"),s(f)}function s(f){return e.enter("atxHeadingSequence"),a(f)}function a(f){return f===35&&r++<6?(e.consume(f),a):f===null||Me(f)?(e.exit("atxHeadingSequence"),o(f)):n(f)}function o(f){return f===35?(e.enter("atxHeadingSequence"),l(f)):f===null||ge(f)?(e.exit("atxHeading"),t(f)):Ne(f)?ze(e,o,"whitespace")(f):(e.enter("atxHeadingText"),c(f))}function l(f){return f===35?(e.consume(f),l):(e.exit("atxHeadingSequence"),o(f))}function c(f){return f===null||f===35||Me(f)?(e.exit("atxHeadingText"),o(f)):(e.consume(f),c)}}const Av=["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"],Rl=["pre","script","style","textarea"],Pv={concrete:!0,name:"htmlFlow",resolveTo:Rv,tokenize:Mv},Ov={partial:!0,tokenize:Fv},Dv={partial:!0,tokenize:$v};function Rv(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 Mv(e,t,n){const r=this;let i,s,a,o,l;return c;function c(b){return f(b)}function f(b){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(b),d}function d(b){return b===33?(e.consume(b),p):b===47?(e.consume(b),s=!0,w):b===63?(e.consume(b),i=3,r.interrupt?t:v):dt(b)?(e.consume(b),a=String.fromCharCode(b),S):n(b)}function p(b){return b===45?(e.consume(b),i=2,h):b===91?(e.consume(b),i=5,o=0,m):dt(b)?(e.consume(b),i=4,r.interrupt?t:v):n(b)}function h(b){return b===45?(e.consume(b),r.interrupt?t:v):n(b)}function m(b){const Y="CDATA[";return b===Y.charCodeAt(o++)?(e.consume(b),o===Y.length?r.interrupt?t:A:m):n(b)}function w(b){return dt(b)?(e.consume(b),a=String.fromCharCode(b),S):n(b)}function S(b){if(b===null||b===47||b===62||Me(b)){const Y=b===47,oe=a.toLowerCase();return!Y&&!s&&Rl.includes(oe)?(i=1,r.interrupt?t(b):A(b)):Av.includes(a.toLowerCase())?(i=6,Y?(e.consume(b),x):r.interrupt?t(b):A(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):s?_(b):g(b))}return b===45||st(b)?(e.consume(b),a+=String.fromCharCode(b),S):n(b)}function x(b){return b===62?(e.consume(b),r.interrupt?t:A):n(b)}function _(b){return Ne(b)?(e.consume(b),_):N(b)}function g(b){return b===47?(e.consume(b),N):b===58||b===95||dt(b)?(e.consume(b),z):Ne(b)?(e.consume(b),g):N(b)}function z(b){return b===45||b===46||b===58||b===95||st(b)?(e.consume(b),z):E(b)}function E(b){return b===61?(e.consume(b),k):Ne(b)?(e.consume(b),E):g(b)}function k(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(e.consume(b),l=b,C):Ne(b)?(e.consume(b),k):$(b)}function C(b){return b===l?(e.consume(b),l=null,K):b===null||ge(b)?n(b):(e.consume(b),C)}function $(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||Me(b)?E(b):(e.consume(b),$)}function K(b){return b===47||b===62||Ne(b)?g(b):n(b)}function N(b){return b===62?(e.consume(b),I):n(b)}function I(b){return b===null||ge(b)?A(b):Ne(b)?(e.consume(b),I):n(b)}function A(b){return b===45&&i===2?(e.consume(b),P):b===60&&i===1?(e.consume(b),J):b===62&&i===4?(e.consume(b),fe):b===63&&i===3?(e.consume(b),v):b===93&&i===5?(e.consume(b),q):ge(b)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(Ov,ue,B)(b)):b===null||ge(b)?(e.exit("htmlFlowData"),B(b)):(e.consume(b),A)}function B(b){return e.check(Dv,D,ue)(b)}function D(b){return e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),T}function T(b){return b===null||ge(b)?B(b):(e.enter("htmlFlowData"),A(b))}function P(b){return b===45?(e.consume(b),v):A(b)}function J(b){return b===47?(e.consume(b),a="",R):A(b)}function R(b){if(b===62){const Y=a.toLowerCase();return Rl.includes(Y)?(e.consume(b),fe):A(b)}return dt(b)&&a.length<8?(e.consume(b),a+=String.fromCharCode(b),R):A(b)}function q(b){return b===93?(e.consume(b),v):A(b)}function v(b){return b===62?(e.consume(b),fe):b===45&&i===2?(e.consume(b),v):A(b)}function fe(b){return b===null||ge(b)?(e.exit("htmlFlowData"),ue(b)):(e.consume(b),fe)}function ue(b){return e.exit("htmlFlow"),t(b)}}function $v(e,t,n){const r=this;return i;function i(a){return ge(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 Fv(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(ri,t,n)}}const Lv={name:"htmlText",tokenize:Zv};function Zv(e,t,n){const r=this;let i,s,a;return o;function o(v){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(v),l}function l(v){return v===33?(e.consume(v),c):v===47?(e.consume(v),E):v===63?(e.consume(v),g):dt(v)?(e.consume(v),$):n(v)}function c(v){return v===45?(e.consume(v),f):v===91?(e.consume(v),s=0,m):dt(v)?(e.consume(v),_):n(v)}function f(v){return v===45?(e.consume(v),h):n(v)}function d(v){return v===null?n(v):v===45?(e.consume(v),p):ge(v)?(a=d,J(v)):(e.consume(v),d)}function p(v){return v===45?(e.consume(v),h):d(v)}function h(v){return v===62?P(v):v===45?p(v):d(v)}function m(v){const fe="CDATA[";return v===fe.charCodeAt(s++)?(e.consume(v),s===fe.length?w:m):n(v)}function w(v){return v===null?n(v):v===93?(e.consume(v),S):ge(v)?(a=w,J(v)):(e.consume(v),w)}function S(v){return v===93?(e.consume(v),x):w(v)}function x(v){return v===62?P(v):v===93?(e.consume(v),x):w(v)}function _(v){return v===null||v===62?P(v):ge(v)?(a=_,J(v)):(e.consume(v),_)}function g(v){return v===null?n(v):v===63?(e.consume(v),z):ge(v)?(a=g,J(v)):(e.consume(v),g)}function z(v){return v===62?P(v):g(v)}function E(v){return dt(v)?(e.consume(v),k):n(v)}function k(v){return v===45||st(v)?(e.consume(v),k):C(v)}function C(v){return ge(v)?(a=C,J(v)):Ne(v)?(e.consume(v),C):P(v)}function $(v){return v===45||st(v)?(e.consume(v),$):v===47||v===62||Me(v)?K(v):n(v)}function K(v){return v===47?(e.consume(v),P):v===58||v===95||dt(v)?(e.consume(v),N):ge(v)?(a=K,J(v)):Ne(v)?(e.consume(v),K):P(v)}function N(v){return v===45||v===46||v===58||v===95||st(v)?(e.consume(v),N):I(v)}function I(v){return v===61?(e.consume(v),A):ge(v)?(a=I,J(v)):Ne(v)?(e.consume(v),I):K(v)}function A(v){return v===null||v===60||v===61||v===62||v===96?n(v):v===34||v===39?(e.consume(v),i=v,B):ge(v)?(a=A,J(v)):Ne(v)?(e.consume(v),A):(e.consume(v),D)}function B(v){return v===i?(e.consume(v),i=void 0,T):v===null?n(v):ge(v)?(a=B,J(v)):(e.consume(v),B)}function D(v){return v===null||v===34||v===39||v===60||v===61||v===96?n(v):v===47||v===62||Me(v)?K(v):(e.consume(v),D)}function T(v){return v===47||v===62||Me(v)?K(v):n(v)}function P(v){return v===62?(e.consume(v),e.exit("htmlTextData"),e.exit("htmlText"),t):n(v)}function J(v){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(v),e.exit("lineEnding"),R}function R(v){return Ne(v)?ze(e,q,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(v):q(v)}function q(v){return e.enter("htmlTextData"),a(v)}}const xo={name:"labelEnd",resolveAll:Jv,resolveTo:Hv,tokenize:qv},Bv={tokenize:Wv},Vv={tokenize:Gv},Uv={tokenize:Kv};function Jv(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&&_t(e,0,e.length,n),e}function Hv(e,t){let n=e.length,r=0,i,s,a,o;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(a){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(a=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},c={type:"label",start:{...e[s][1].start},end:{...e[a][1].end}},f={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[a-2][1].start}};return o=[["enter",l,t],["enter",c,t]],o=Et(o,e.slice(s+1,s+r+3)),o=Et(o,[["enter",f,t]]),o=Et(o,xs(t.parser.constructs.insideSpan.null,e.slice(s+r+4,a-3),t)),o=Et(o,[["exit",f,t],e[a-2],e[a-1],["exit",c,t]]),o=Et(o,e.slice(a+1)),o=Et(o,[["exit",l,t]]),_t(e,s,e.length,o),e}function qv(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(p){return s?s._inactive?d(p):(a=r.parser.defined.includes(Mt(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(p),e.exit("labelMarker"),e.exit("labelEnd"),l):n(p)}function l(p){return p===40?e.attempt(Bv,f,a?f:d)(p):p===91?e.attempt(Vv,f,a?c:d)(p):a?f(p):d(p)}function c(p){return e.attempt(Uv,f,d)(p)}function f(p){return t(p)}function d(p){return s._balanced=!0,n(p)}}function Wv(e,t,n){return r;function r(d){return e.enter("resource"),e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),i}function i(d){return Me(d)?Or(e,s)(d):s(d)}function s(d){return d===41?f(d):Lf(e,a,o,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(d)}function a(d){return Me(d)?Or(e,l)(d):f(d)}function o(d){return n(d)}function l(d){return d===34||d===39||d===40?Bf(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(d):f(d)}function c(d){return Me(d)?Or(e,f)(d):f(d)}function f(d){return d===41?(e.enter("resourceMarker"),e.consume(d),e.exit("resourceMarker"),e.exit("resource"),t):n(d)}}function Gv(e,t,n){const r=this;return i;function i(o){return Zf.call(r,e,s,a,"reference","referenceMarker","referenceString")(o)}function s(o){return r.parser.defined.includes(Mt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(o):n(o)}function a(o){return n(o)}}function Kv(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 Yv={name:"labelStartImage",resolveAll:xo.resolveAll,tokenize:Xv};function Xv(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 Qv={name:"labelStartLink",resolveAll:xo.resolveAll,tokenize:ew};function ew(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 Vs={name:"lineEnding",tokenize:tw};function tw(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),ze(e,t,"linePrefix")}}const Ni={name:"thematicBreak",tokenize:nw};function nw(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||ge(c))?(e.exit("thematicBreak"),t(c)):n(c)}function l(c){return c===i?(e.consume(c),r++,l):(e.exit("thematicBreakSequence"),Ne(c)?ze(e,o,"whitespace")(c):o(c))}}const ht={continuation:{tokenize:aw},exit:lw,name:"list",tokenize:sw},rw={partial:!0,tokenize:uw},iw={partial:!0,tokenize:ow};function sw(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(h){const m=r.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(m==="listUnordered"?!r.containerState.marker||h===r.containerState.marker:Na(h)){if(r.containerState.type||(r.containerState.type=m,e.enter(m,{_container:!0})),m==="listUnordered")return e.enter("listItemPrefix"),h===42||h===45?e.check(Ni,n,c)(h):c(h);if(!r.interrupt||h===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(h)}return n(h)}function l(h){return Na(h)&&++a<10?(e.consume(h),l):(!r.interrupt||a<2)&&(r.containerState.marker?h===r.containerState.marker:h===41||h===46)?(e.exit("listItemValue"),c(h)):n(h)}function c(h){return e.enter("listItemMarker"),e.consume(h),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||h,e.check(ri,r.interrupt?n:f,e.attempt(rw,p,d))}function f(h){return r.containerState.initialBlankLine=!0,s++,p(h)}function d(h){return Ne(h)?(e.enter("listItemPrefixWhitespace"),e.consume(h),e.exit("listItemPrefixWhitespace"),p):n(h)}function p(h){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(h)}}function aw(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(ri,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||!Ne(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(iw,t,a)(o))}function a(o){return r.containerState._closeFlow=!0,r.interrupt=void 0,ze(e,e.attempt(ht,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o)}}function ow(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 lw(e){e.exit(this.containerState.type)}function uw(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!Ne(s)&&a&&a[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const Ml={name:"setextUnderline",resolveTo:cw,tokenize:dw};function cw(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 dw(e,t,n){const r=this;let i;return s;function s(c){let f=r.events.length,d;for(;f--;)if(r.events[f][1].type!=="lineEnding"&&r.events[f][1].type!=="linePrefix"&&r.events[f][1].type!=="content"){d=r.events[f][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||d)?(e.enter("setextHeadingLine"),i=c,a(c)):n(c)}function a(c){return e.enter("setextHeadingLineSequence"),o(c)}function o(c){return c===i?(e.consume(c),o):(e.exit("setextHeadingLineSequence"),Ne(c)?ze(e,l,"lineSuffix")(c):l(c))}function l(c){return c===null||ge(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const fw={tokenize:pw};function pw(e){const t=this,n=e.attempt(ri,r,e.attempt(this.parser.constructs.flowInitial,i,ze(e,e.attempt(this.parser.constructs.flow,i,e.attempt(yv,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 hw={resolveAll:Uf()},mw=Vf("string"),gw=Vf("text");function Vf(e){return{resolveAll:Uf(e==="text"?xw:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,a,o);return a;function a(f){return c(f)?s(f):o(f)}function o(f){if(f===null){n.consume(f);return}return n.enter("data"),n.consume(f),l}function l(f){return c(f)?(n.exit("data"),s(f)):(n.consume(f),l)}function c(f){if(f===null)return!0;const d=i[f];let p=-1;if(d)for(;++p<d.length;){const h=d[p];if(!h.previous||h.previous.call(r,r.previous))return!0}return!1}}}function Uf(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 xw(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 yw={42:ht,43:ht,45:ht,48:ht,49:ht,50:ht,51:ht,52:ht,53:ht,54:ht,55:ht,56:ht,57:ht,62:Rf},bw={91:Sv},vw={[-2]:Bs,[-1]:Bs,32:Bs},ww={35:Iv,42:Ni,45:[Ml,Ni],60:Pv,61:Ml,95:Ni,96:Dl,126:Dl},kw={38:$f,92:Mf},Sw={[-5]:Vs,[-4]:Vs,[-3]:Vs,33:Yv,38:$f,42:Ca,60:[Qb,Lv],91:Qv,92:[Cv,Mf],93:xo,95:Ca,96:fv},_w={null:[Ca,hw]},jw={null:[42,95]},Nw={null:[]},Cw=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:jw,contentInitial:bw,disable:Nw,document:yw,flow:ww,flowInitial:vw,insideSpan:_w,string:kw,text:Sw},Symbol.toStringTag,{value:"Module"}));function Ew(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:C(E),check:C(k),consume:_,enter:g,exit:z,interrupt:C(k,{interrupt:!0})},c={code:null,containerState:{},defineSkip:w,events:[],now:m,parser:e,previous:null,sliceSerialize:p,sliceStream:h,write:d};let f=t.tokenize.call(c,l);return t.resolveAll&&s.push(t),c;function d(I){return a=Et(a,I),S(),a[a.length-1]!==null?[]:($(t,0),c.events=xs(s,c.events,c),c.events)}function p(I,A){return zw(h(I),A)}function h(I){return Iw(a,I)}function m(){const{_bufferIndex:I,_index:A,line:B,column:D,offset:T}=r;return{_bufferIndex:I,_index:A,line:B,column:D,offset:T}}function w(I){i[I.line]=I.column,N()}function S(){let I;for(;r._index<a.length;){const A=a[r._index];if(typeof A=="string")for(I=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===I&&r._bufferIndex<A.length;)x(A.charCodeAt(r._bufferIndex));else x(A)}}function x(I){f=f(I)}function _(I){ge(I)?(r.line++,r.column=1,r.offset+=I===-3?2:1,N()):I!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===a[r._index].length&&(r._bufferIndex=-1,r._index++)),c.previous=I}function g(I,A){const B=A||{};return B.type=I,B.start=m(),c.events.push(["enter",B,c]),o.push(B),B}function z(I){const A=o.pop();return A.end=m(),c.events.push(["exit",A,c]),A}function E(I,A){$(I,A.from)}function k(I,A){A.restore()}function C(I,A){return B;function B(D,T,P){let J,R,q,v;return Array.isArray(D)?ue(D):"tokenize"in D?ue([D]):fe(D);function fe(ne){return ie;function ie(W){const F=W!==null&&ne[W],te=W!==null&&ne.null,V=[...Array.isArray(F)?F:F?[F]:[],...Array.isArray(te)?te:te?[te]:[]];return ue(V)(W)}}function ue(ne){return J=ne,R=0,ne.length===0?P:b(ne[R])}function b(ne){return ie;function ie(W){return v=K(),q=ne,ne.partial||(c.currentConstruct=ne),ne.name&&c.parser.constructs.disable.null.includes(ne.name)?oe():ne.tokenize.call(A?Object.assign(Object.create(c),A):c,l,Y,oe)(W)}}function Y(ne){return I(q,v),T}function oe(ne){return v.restore(),++R<J.length?b(J[R]):P}}}function $(I,A){I.resolveAll&&!s.includes(I)&&s.push(I),I.resolve&&_t(c.events,A,c.events.length-A,I.resolve(c.events.slice(A),c)),I.resolveTo&&(c.events=I.resolveTo(c.events,c))}function K(){const I=m(),A=c.previous,B=c.currentConstruct,D=c.events.length,T=Array.from(o);return{from:D,restore:P};function P(){r=I,c.previous=A,c.currentConstruct=B,c.events.length=D,o=T,N()}}function N(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function Iw(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 zw(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=`
|
|
4
4
|
`;break}case-3:{a=`\r
|
|
5
5
|
`;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 Tw(e){const r={constructs:Of([Cw,...(e||{}).extensions||[]]),content:i(Hb),defined:[],document:i(Wb),flow:i(fw),lazy:{},string:i(mw),text:i(gw)};return r;function i(s){return a;function a(o){return Ew(r,s,o)}}}function Aw(e){for(;!Ff(e););return e}const $l=/[\0\t\n\r]/g;function Pw(){let e=1,t="",n=!0,r;return i;function i(s,a,o){const l=[];let c,f,d,p,h;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(a||void 0).decode(s)),d=0,t="",n&&(s.charCodeAt(0)===65279&&d++,n=void 0);d<s.length;){if($l.lastIndex=d,c=$l.exec(s),p=c&&c.index!==void 0?c.index:s.length,h=s.charCodeAt(p),!c){t=s.slice(d);break}if(h===10&&d===p&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),d<p&&(l.push(s.slice(d,p)),e+=p-d),h){case 0:{l.push(65533),e++;break}case 9:{for(f=Math.ceil(e/4)*4,l.push(-2);e++<f;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}d=p+1}return o&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const Ow=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function Dw(e){return e.replace(Ow,Rw)}function Rw(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Df(n.slice(s?2:1),s?16:10)}return go(n)||e}const Jf={}.hasOwnProperty;function Mw(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),$w(n)(Aw(Tw(n).document().write(Pw()(e,t,!0))))}function $w(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(O),autolinkProtocol:K,autolinkEmail:K,atxHeading:s(Oe),blockQuote:s(te),characterEscape:K,characterReference:K,codeFenced:s(V),codeFencedFenceInfo:a,codeFencedFenceMeta:a,codeIndented:s(V,a),codeText:s(de,a),codeTextData:K,data:K,codeFlowValue:K,definition:s(le),definitionDestinationString:a,definitionLabelString:a,definitionTitleString:a,emphasis:s(ye),hardBreakEscape:s(qe),hardBreakTrailing:s(qe),htmlFlow:s(Qe,a),htmlFlowData:K,htmlText:s(Qe,a),htmlTextData:K,image:s(j),label:a,link:s(O),listItem:s(re),listItemValue:p,listOrdered:s(Z,d),listUnordered:s(Z),paragraph:s(ee),reference:b,referenceString:a,resourceDestinationString:a,resourceTitleString:a,setextHeading:s(Oe),strong:s(Q),thematicBreak:s(ve)},exit:{atxHeading:l(),atxHeadingSequence:E,autolink:l(),autolinkEmail:F,autolinkProtocol:W,blockQuote:l(),characterEscapeValue:N,characterReferenceMarkerHexadecimal:oe,characterReferenceMarkerNumeric:oe,characterReferenceValue:ne,characterReference:ie,codeFenced:l(S),codeFencedFence:w,codeFencedFenceInfo:h,codeFencedFenceMeta:m,codeFlowValue:N,codeIndented:l(x),codeText:l(T),codeTextData:N,data:N,definition:l(),definitionDestinationString:z,definitionLabelString:_,definitionTitleString:g,emphasis:l(),hardBreakEscape:l(A),hardBreakTrailing:l(A),htmlFlow:l(B),htmlFlowData:N,htmlText:l(D),htmlTextData:N,image:l(J),label:q,labelText:R,lineEnding:I,link:l(P),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:Y,resourceDestinationString:v,resourceTitleString:fe,resource:ue,setextHeading:l($),setextHeadingLineSequence:C,setextHeadingText:k,strong:l(),thematicBreak:l()}};Hf(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(L){let G={type:"root",children:[]};const he={stack:[G],tokenStack:[],config:t,enter:o,exit:c,buffer:a,resume:f,data:n},Se=[];let M=-1;for(;++M<L.length;)if(L[M][1].type==="listOrdered"||L[M][1].type==="listUnordered")if(L[M][0]==="enter")Se.push(M);else{const me=Se.pop();M=i(L,me,M)}for(M=-1;++M<L.length;){const me=t[L[M][0]];Jf.call(me,L[M][1].type)&&me[L[M][1].type].call(Object.assign({sliceSerialize:L[M][2].sliceSerialize},he),L[M][1])}if(he.tokenStack.length>0){const me=he.tokenStack[he.tokenStack.length-1];(me[1]||Fl).call(he,void 0,me[0])}for(G.position={start:tn(L.length>0?L[0][1].start:{line:1,column:1,offset:0}),end:tn(L.length>0?L[L.length-2][1].end:{line:1,column:1,offset:0})},M=-1;++M<t.transforms.length;)G=t.transforms[M](G)||G;return G}function i(L,G,he){let Se=G-1,M=-1,me=!1,Ce,$e,nt,et;for(;++Se<=he;){const it=L[Se];switch(it[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{it[0]==="enter"?M++:M--,et=void 0;break}case"lineEndingBlank":{it[0]==="enter"&&(Ce&&!et&&!M&&!nt&&(nt=Se),et=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:et=void 0}if(!M&&it[0]==="enter"&&it[1].type==="listItemPrefix"||M===-1&&it[0]==="exit"&&(it[1].type==="listUnordered"||it[1].type==="listOrdered")){if(Ce){let en=Se;for($e=void 0;en--;){const Wt=L[en];if(Wt[1].type==="lineEnding"||Wt[1].type==="lineEndingBlank"){if(Wt[0]==="exit")continue;$e&&(L[$e][1].type="lineEndingBlank",me=!0),Wt[1].type="lineEnding",$e=en}else if(!(Wt[1].type==="linePrefix"||Wt[1].type==="blockQuotePrefix"||Wt[1].type==="blockQuotePrefixWhitespace"||Wt[1].type==="blockQuoteMarker"||Wt[1].type==="listItemIndent"))break}nt&&(!$e||nt<$e)&&(Ce._spread=!0),Ce.end=Object.assign({},$e?L[$e][1].start:it[1].end),L.splice($e||Se,0,["exit",Ce,it[2]]),Se++,he++}if(it[1].type==="listItemPrefix"){const en={type:"listItem",_spread:!1,start:Object.assign({},it[1].start),end:void 0};Ce=en,L.splice(Se,0,["enter",en,it[2]]),Se++,he++,nt=void 0,et=!0}}}return L[G][1]._spread=me,he}function s(L,G){return he;function he(Se){o.call(this,L(Se),Se),G&&G.call(this,Se)}}function a(){this.stack.push({type:"fragment",children:[]})}function o(L,G,he){this.stack[this.stack.length-1].children.push(L),this.stack.push(L),this.tokenStack.push([G,he||void 0]),L.position={start:tn(G.start),end:void 0}}function l(L){return G;function G(he){L&&L.call(this,he),c.call(this,he)}}function c(L,G){const he=this.stack.pop(),Se=this.tokenStack.pop();if(Se)Se[0].type!==L.type&&(G?G.call(this,L,Se[0]):(Se[1]||Fl).call(this,L,Se[0]));else throw new Error("Cannot close `"+L.type+"` ("+Pr({start:L.start,end:L.end})+"): it’s not open");he.position.end=tn(L.end)}function f(){return mo(this.stack.pop())}function d(){this.data.expectingFirstListItemValue=!0}function p(L){if(this.data.expectingFirstListItemValue){const G=this.stack[this.stack.length-2];G.start=Number.parseInt(this.sliceSerialize(L),10),this.data.expectingFirstListItemValue=void 0}}function h(){const L=this.resume(),G=this.stack[this.stack.length-1];G.lang=L}function m(){const L=this.resume(),G=this.stack[this.stack.length-1];G.meta=L}function w(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function S(){const L=this.resume(),G=this.stack[this.stack.length-1];G.value=L.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function x(){const L=this.resume(),G=this.stack[this.stack.length-1];G.value=L.replace(/(\r?\n|\r)$/g,"")}function _(L){const G=this.resume(),he=this.stack[this.stack.length-1];he.label=G,he.identifier=Mt(this.sliceSerialize(L)).toLowerCase()}function g(){const L=this.resume(),G=this.stack[this.stack.length-1];G.title=L}function z(){const L=this.resume(),G=this.stack[this.stack.length-1];G.url=L}function E(L){const G=this.stack[this.stack.length-1];if(!G.depth){const he=this.sliceSerialize(L).length;G.depth=he}}function k(){this.data.setextHeadingSlurpLineEnding=!0}function C(L){const G=this.stack[this.stack.length-1];G.depth=this.sliceSerialize(L).codePointAt(0)===61?1:2}function $(){this.data.setextHeadingSlurpLineEnding=void 0}function K(L){const he=this.stack[this.stack.length-1].children;let Se=he[he.length-1];(!Se||Se.type!=="text")&&(Se=pe(),Se.position={start:tn(L.start),end:void 0},he.push(Se)),this.stack.push(Se)}function N(L){const G=this.stack.pop();G.value+=this.sliceSerialize(L),G.position.end=tn(L.end)}function I(L){const G=this.stack[this.stack.length-1];if(this.data.atHardBreak){const he=G.children[G.children.length-1];he.position.end=tn(L.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(G.type)&&(K.call(this,L),N.call(this,L))}function A(){this.data.atHardBreak=!0}function B(){const L=this.resume(),G=this.stack[this.stack.length-1];G.value=L}function D(){const L=this.resume(),G=this.stack[this.stack.length-1];G.value=L}function T(){const L=this.resume(),G=this.stack[this.stack.length-1];G.value=L}function P(){const L=this.stack[this.stack.length-1];if(this.data.inReference){const G=this.data.referenceType||"shortcut";L.type+="Reference",L.referenceType=G,delete L.url,delete L.title}else delete L.identifier,delete L.label;this.data.referenceType=void 0}function J(){const L=this.stack[this.stack.length-1];if(this.data.inReference){const G=this.data.referenceType||"shortcut";L.type+="Reference",L.referenceType=G,delete L.url,delete L.title}else delete L.identifier,delete L.label;this.data.referenceType=void 0}function R(L){const G=this.sliceSerialize(L),he=this.stack[this.stack.length-2];he.label=Dw(G),he.identifier=Mt(G).toLowerCase()}function q(){const L=this.stack[this.stack.length-1],G=this.resume(),he=this.stack[this.stack.length-1];if(this.data.inReference=!0,he.type==="link"){const Se=L.children;he.children=Se}else he.alt=G}function v(){const L=this.resume(),G=this.stack[this.stack.length-1];G.url=L}function fe(){const L=this.resume(),G=this.stack[this.stack.length-1];G.title=L}function ue(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function Y(L){const G=this.resume(),he=this.stack[this.stack.length-1];he.label=G,he.identifier=Mt(this.sliceSerialize(L)).toLowerCase(),this.data.referenceType="full"}function oe(L){this.data.characterReferenceType=L.type}function ne(L){const G=this.sliceSerialize(L),he=this.data.characterReferenceType;let Se;he?(Se=Df(G,he==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):Se=go(G);const M=this.stack[this.stack.length-1];M.value+=Se}function ie(L){const G=this.stack.pop();G.position.end=tn(L.end)}function W(L){N.call(this,L);const G=this.stack[this.stack.length-1];G.url=this.sliceSerialize(L)}function F(L){N.call(this,L);const G=this.stack[this.stack.length-1];G.url="mailto:"+this.sliceSerialize(L)}function te(){return{type:"blockquote",children:[]}}function V(){return{type:"code",lang:null,meta:null,value:""}}function de(){return{type:"inlineCode",value:""}}function le(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function ye(){return{type:"emphasis",children:[]}}function Oe(){return{type:"heading",depth:0,children:[]}}function qe(){return{type:"break"}}function Qe(){return{type:"html",value:""}}function j(){return{type:"image",title:null,url:"",alt:null}}function O(){return{type:"link",title:null,url:"",children:[]}}function Z(L){return{type:"list",ordered:L.type==="listOrdered",start:null,spread:L._spread,children:[]}}function re(L){return{type:"listItem",spread:L._spread,checked:null,children:[]}}function ee(){return{type:"paragraph",children:[]}}function Q(){return{type:"strong",children:[]}}function pe(){return{type:"text",value:""}}function ve(){return{type:"thematicBreak"}}}function tn(e){return{line:e.line,column:e.column,offset:e.offset}}function Hf(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Hf(e,r):Fw(e,r)}}function Fw(e,t){let n;for(n in t)if(Jf.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 Fl(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Pr({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Pr({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Pr({start:t.start,end:t.end})+") is still open")}function Lw(e){const t=this;t.parser=n;function n(r){return Mw(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function Zw(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 Bw(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
|
|
@@ -96,4 +96,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
96
96
|
`;)t++;return!0}return!1}function c(R){if(f(R)){if(Yu(e[t]))for(;t<e.length&&Xu(e[t]);)t++;return a(),!0}return!1}function f(R){o(!0);for(const q of R){const v=t+q.length;if(e.slice(t,v)===q)return t=v,!0}return!1}function d(R){return e[t]===R?(n+=e[t],t++,!0):!1}function p(R){return e[t]===R?(t++,!0):!1}function h(){return p("\\")}function m(){return a(),e[t]==="."&&e[t+1]==="."&&e[t+2]==="."?(t+=3,a(),p(","),!0):!1}function w(){if(e[t]==="{"){n+="{",t++,a(),p(",")&&a();let R=!0;for(;t<e.length&&e[t]!=="}";){let q;if(R?(q=!0,R=!1):(q=d(","),q||(n=Pt(n,",")),a()),m(),!(_()||C(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=wr(n,","):T();break}a();const fe=d(":"),ue=t>=e.length;fe||(nc(e[t])||ue?n=Pt(n,":"):P()),s()||(fe||ue?n+="null":P())}return e[t]==="}"?(n+="}",t++):n=Pt(n,"}"),!0}return!1}function S(){if(e[t]==="["){n+="[",t++,a(),p(",")&&a();let R=!0;for(;t<e.length&&e[t]!=="]";)if(R?R=!1:d(",")||(n=Pt(n,",")),m(),!s()){n=wr(n,",");break}return e[t]==="]"?(n+="]",t++):n=Pt(n,"]"),!0}return!1}function x(){let R=!0,q=!0;for(;q;)R?R=!1:d(",")||(n=Pt(n,",")),q=s();q||(n=wr(n,",")),n=`[
|
|
97
97
|
${n}
|
|
98
98
|
]`}function _(){let R=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1,q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1,v=e[t]==="\\";if(v&&(t++,v=!0),Ii(e[t])){const fe=rc(e[t])?rc:ic(e[t])?ic:Va(e[t])?Va:om,ue=t,b=n.length;let Y='"';for(t++;;){if(t>=e.length){const oe=K(t-1);return!R&&bi(e.charAt(oe))?(t=ue,n=n.substring(0,b),_(!0)):(Y=Pt(Y,'"'),n+=Y,!0)}if(t===q)return Y=Pt(Y,'"'),n+=Y,!0;if(fe(e[t])){const oe=t,ne=Y.length;if(Y+='"',t++,n+=Y,a(!1),R||t>=e.length||bi(e[t])||Ii(e[t])||bn(e[t]))return g(),!0;const ie=K(oe-1),W=e.charAt(ie);if(W===",")return t=ue,n=n.substring(0,b),_(!1,ie);if(bi(W))return t=ue,n=n.substring(0,b),_(!0);n=n.substring(0,b),t=oe+1,Y=`${Y.substring(0,ne)}\\${Y.substring(ne)}`}else if(R&&tc(e[t])){if(e[t-1]===":"&&Qu.test(e.substring(ue+1,t+2)))for(;t<e.length&&ec.test(e[t]);)Y+=e[t],t++;return Y=Pt(Y,'"'),n+=Y,g(),!0}else if(e[t]==="\\"){const oe=e.charAt(t+1);if(_z[oe]!==void 0)Y+=e.slice(t,t+2),t+=2;else if(oe==="u"){let ie=2;for(;ie<6&&mz(e[t+ie]);)ie++;ie===6?(Y+=e.slice(t,t+6),t+=6):t+ie>=e.length?t=e.length:J()}else Y+=oe,t+=2}else{const oe=e.charAt(t);oe==='"'&&e[t-1]!=="\\"?(Y+=`\\${oe}`,t++):yz(oe)?(Y+=Sz[oe],t++):(gz(oe)||A(oe),Y+=oe,t++)}v&&h()}}return!1}function g(){let R=!1;for(a();e[t]==="+";){R=!0,t++,a(),n=wr(n,'"',!0);const q=n.length;_()?n=wz(n,q,1):n=Pt(n,'"')}return R}function z(){const R=t;if(e[t]==="-"){if(t++,N())return I(R),!0;if(!bn(e[t]))return t=R,!1}for(;bn(e[t]);)t++;if(e[t]==="."){if(t++,N())return I(R),!0;if(!bn(e[t]))return t=R,!1;for(;bn(e[t]);)t++}if(e[t]==="e"||e[t]==="E"){if(t++,(e[t]==="-"||e[t]==="+")&&t++,N())return I(R),!0;if(!bn(e[t]))return t=R,!1;for(;bn(e[t]);)t++}if(!N())return t=R,!1;if(t>R){const q=e.slice(R,t),v=/^0\d/.test(q);return n+=v?`"${q}"`:q,!0}return!1}function E(){return k("true","true")||k("false","false")||k("null","null")||k("True","true")||k("False","false")||k("None","null")}function k(R,q){return e.slice(t,t+R.length)===R?(n+=q,t+=R.length,!0):!1}function C(R){const q=t;if(Yu(e[t])){for(;t<e.length&&Xu(e[t]);)t++;let v=t;for(;wn(e,v);)v++;if(e[v]==="(")return t=v+1,s(),e[t]===")"&&(t++,e[t]===";"&&t++),!0}for(;t<e.length&&!tc(e[t])&&!Ii(e[t])&&(!R||e[t]!==":");)t++;if(e[t-1]===":"&&Qu.test(e.substring(q,t+2)))for(;t<e.length&&ec.test(e[t]);)t++;if(t>q){for(;wn(e,t-1)&&t>0;)t--;const v=e.slice(q,t);return n+=v==="undefined"?"null":JSON.stringify(v),e[t]==='"'&&t++,!0}}function $(){if(e[t]==="/"){const R=t;for(t++;t<e.length&&(e[t]!=="/"||e[t-1]==="\\");)t++;return t++,n+=JSON.stringify(e.substring(R,t)),!0}}function K(R){let q=R;for(;q>0&&wn(e,q);)q--;return q}function N(){return t>=e.length||bi(e[t])||wn(e,t)}function I(R){n+=`${e.slice(R,t)}0`}function A(R){throw new Zn(`Invalid character ${JSON.stringify(R)}`,t)}function B(){throw new Zn(`Unexpected character ${JSON.stringify(e[t])}`,t)}function D(){throw new Zn("Unexpected end of json string",e.length)}function T(){throw new Zn("Object key expected",t)}function P(){throw new Zn("Colon expected",t)}function J(){const R=e.slice(t,t+6);throw new Zn(`Invalid unicode character "${R}"`,t)}}function jz(e,t){return e[t]==="*"&&e[t+1]==="/"}function Nz({json:e,context:t,scope:n}){const[r,i]=y.useState(!1),[s,a]=y.useState(null),o=y.useMemo(()=>{try{return JSON.parse(e),e}catch{}try{return sc(e)}catch{}const x=`{${e}}`;try{return JSON.parse(x),x}catch{}try{return sc(x)}catch{return null}},[e]),l=y.useMemo(()=>em(o||e),[o,e]),c=Ae(x=>x.activeTab),f=Ae(x=>x.documents),d=Ae(x=>(x.acceptedApplyIds||[]).includes(l)),p=Ae(x=>x.setPendingDiff),h=Ae(x=>x.createDocument),m=Ae(x=>x.openDocument),w=y.useCallback(()=>{if(o){a(null);try{if(c){const x=f.find(k=>k.name===c),_=(x==null?void 0:x.text)||"";if(n==="templates")try{const k=JSON.parse(_),C=JSON.parse(o);if(Array.isArray(C.templates)){k.props||(k.props={}),k.props.templates=Qh(k.props.templates||[],C.templates);const $=JSON.stringify(k,null,2);p(c,_,$,l);return}}catch{}const g=t==null?void 0:t[0],{original:z,modified:E}=tm(_,o,g);p(c,z,E,l)}else{const x=`ai-generated-${Date.now()}`;h(x,o),m(x)}}catch(x){a(x instanceof Error?x.message:"Merge failed")}}},[o,c,f,p,h,m,t,n,l]),S=y.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(we,{variant:"secondary",size:"sm",onClick:w,disabled:d||!o,children:d?"Applied":o?"Apply to Editor":"Invalid JSON"}),u.jsx(we,{variant:"ghost",size:"sm",onClick:S,children:r?u.jsx(un,{className:"h-3.5 w-3.5"}):u.jsx(as,{className:"h-3.5 w-3.5"})})]}),s&&u.jsx("p",{className:"text-xs text-destructive m-0",children:s})]})}function Cz({threads:e,activeThread:t,disabled:n,onSwitch:r,onCreate:i,onDelete:s,onRename:a}){const[o,l]=y.useState(null),[c,f]=y.useState(""),[d,p]=y.useState(null),h=y.useRef(null),m=(t==null?void 0:t.title)||"New Chat",w=m.length>24?m.slice(0,24)+"...":m;y.useEffect(()=>{o&&requestAnimationFrame(()=>{var C;return(C=h.current)==null?void 0:C.focus()})},[o]);const S=y.useCallback((C,$)=>{$.stopPropagation(),$.preventDefault(),l(C.id),f(C.title),p(null)},[]),x=y.useCallback(()=>{o&&c.trim()&&a(o,c.trim()),l(null),f("")},[o,c,a]),_=y.useCallback(()=>{l(null),f("")},[]),g=y.useCallback(C=>{C.stopPropagation(),C.key==="Enter"?(C.preventDefault(),x()):C.key==="Escape"&&(C.preventDefault(),_())},[x,_]),z=y.useCallback((C,$)=>{$.stopPropagation(),$.preventDefault(),p(C),l(null)},[]),E=y.useCallback(C=>{C.stopPropagation(),C.preventDefault(),d&&(s(d),p(null))},[d,s]),k=y.useCallback(C=>{C.stopPropagation(),C.preventDefault(),p(null)},[]);return u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsxs(to,{onOpenChange:C=>{C||(l(null),p(null))},children:[u.jsx(no,{asChild:!0,disabled:n,children:u.jsxs("button",{className:"flex items-center gap-1 text-sm font-semibold tracking-tight hover:text-foreground/80 transition-colors max-w-[180px] cursor-pointer",children:[u.jsx("div",{className:"h-2 w-2 rounded-full bg-primary/70 shrink-0"}),u.jsx("span",{className:"truncate",children:w}),u.jsx(on,{className:"h-3 w-3 shrink-0 opacity-60"})]})}),u.jsxs(ds,{align:"start",className:"w-64",children:[e.map(C=>{const $=o===C.id;return d===C.id?u.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-sm",children:[u.jsx("span",{className:"text-red-400 text-xs flex-1 truncate",children:"Delete this thread?"}),u.jsx("button",{className:"shrink-0 text-red-400 hover:text-red-300 transition-colors cursor-pointer",onClick:E,children:u.jsx(un,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:k,children:u.jsx(Nn,{className:"h-3.5 w-3.5"})})]},C.id):$?u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1",onClick:N=>N.stopPropagation(),onPointerDown:N=>N.stopPropagation(),children:[u.jsx("input",{ref:h,type:"text",value:c,onChange:N=>f(N.target.value),onKeyDown:g,onBlur:x,className:"flex-1 min-w-0 text-sm rounded 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:N=>{N.preventDefault(),x()},children:u.jsx(un,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onMouseDown:N=>{N.preventDefault(),_()},children:u.jsx(Nn,{className:"h-3.5 w-3.5"})})]},C.id):u.jsxs(Kt,{onSelect:()=>r(C.id),className:`group ${C.id===(t==null?void 0:t.id)?"bg-accent":""}`,children:[u.jsx("span",{className:"truncate flex-1",children:C.title.length>30?C.title.slice(0,30)+"...":C.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:N=>S(C,N),children:u.jsx(cg,{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:N=>z(C.id,N),children:u.jsx(Ha,{className:"h-3 w-3"})})]})]},C.id)}),u.jsx(Fr,{}),u.jsxs(Kt,{onSelect:C=>{C.preventDefault();const $=i();$&&(l($),f(Xa()),p(null))},children:[u.jsx(zi,{className:"h-3.5 w-3.5 mr-1.5"}),"New Chat"]})]})]}),u.jsx(we,{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(zi,{className:"h-3.5 w-3.5"})})]})}const lm=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),Ez=Array.from(lm).join(","),Iz=20*1024*1024,ac=10;function zz(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 oc(e){return Array.from(e).filter(t=>lm.has(t.type)&&t.size<=Iz)}function um(e){return e.startsWith("image/")}function lc(){var G,he,Se;const e=Te(M=>M.contextAttachments),t=Te(M=>M.addContext),n=Te(M=>M.removeContext),r=Te(M=>M.scope),i=Te(M=>M.setScope),s=Te(M=>M.model),a=Te(M=>M.setModel),o=Te(M=>M.openChat),l=Te(M=>M.closeChat),c=Te(M=>M.threads),f=Te(M=>M.activeThreadId),d=Te(M=>M.createThread),p=Te(M=>M.deleteThread),h=Te(M=>M.switchThread),m=Te(M=>M.updateThreadMessages),w=Te(M=>M.updateThreadTitle),S=Te(M=>M.deleteThreadsForDocument),x=Ae(M=>M.activeTab),_=Ae(M=>M.documents),{messages:g,sendMessage:z,status:E,error:k,setMessages:C,stop:$,getMessageContext:K,getMessageScope:N}=rz(),[I,A]=y.useState(""),[B,D]=y.useState([]),[T,P]=y.useState(!1),[J,R]=y.useState(!1),q=y.useRef(null),v=y.useRef(null),fe=y.useRef(null),ue=y.useCallback(async M=>{const me=oc(M);if(me.length===0)return;const Ce=await Promise.all(me.map(zz));D($e=>{const nt=[...$e,...Ce];return nt.length>ac?nt.slice(0,ac):nt})},[]),b=y.useCallback(M=>{D(me=>me.filter((Ce,$e)=>$e!==M))},[]),Y=y.useCallback(M=>{var Ce;const me=(Ce=M.clipboardData)==null?void 0:Ce.files;if(me&&me.length>0){const $e=oc(me);$e.length>0&&(M.preventDefault(),ue($e))}},[ue]),oe=y.useCallback(M=>{var Ce;M.preventDefault(),R(!1);const me=(Ce=M.dataTransfer)==null?void 0:Ce.files;me&&me.length>0&&ue(Array.from(me))},[ue]),ne=y.useCallback(M=>{M.preventDefault(),R(!0)},[]),ie=y.useCallback(()=>R(!1),[]),W=x?f[x]:void 0,F=W?c[W]:void 0,te=y.useMemo(()=>x?Object.values(c).filter(M=>M.documentName===x).sort((M,me)=>me.updatedAt-M.updatedAt):[],[c,x]);y.useEffect(()=>{x&&te.length===0&&d(x)},[x,te.length,d]);const V=y.useRef(c);V.current=c,y.useEffect(()=>{const M=new Set(_.map(Ce=>Ce.name)),me=new Set;for(const Ce of Object.values(V.current))!M.has(Ce.documentName)&&Ce.documentName!=="__migrated__"&&me.add(Ce.documentName);for(const Ce of me)S(Ce)},[_,S]);const de=y.useRef(null);y.useEffect(()=>{de.current!==W&&(de.current=W,C((F==null?void 0:F.messages)??[]))},[W,F,C]),y.useEffect(()=>{var M;(M=q.current)==null||M.scrollIntoView({behavior:"smooth"})},[g,E]),y.useEffect(()=>{const M=me=>{var nt;const{documentName:Ce,selection:$e}=me.detail;t({...$e,documentName:Ce}),o(),(nt=v.current)==null||nt.focus()};return window.addEventListener("monaco-selection-to-ai",M),()=>window.removeEventListener("monaco-selection-to-ai",M)},[t,o]);const le=E==="streaming",ye=E==="submitted"||le,Oe=y.useCallback(M=>{M.preventDefault(),!(!I.trim()&&B.length===0||ye)&&(z(I,B.length>0?B:void 0),A(""),D([]))},[I,B,ye,z]),qe=y.useCallback(M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),Oe(M))},[Oe]),Qe=y.useCallback(()=>{g.length!==0&&P(!0)},[g.length]),j=y.useCallback(()=>{P(!1),C([]),W&&(m(W,[]),w(W,Xa()))},[C,W,m,w]),[O,Z]=y.useState(null),re=y.useCallback(M=>{Z(M)},[]),ee=y.useCallback(()=>{var nt,et;if(!O)return;const M=g.findIndex(it=>it.id===O);if(M===-1){Z(null);return}const me=g[M],Ce=new Set([M]);me.role==="user"&&((nt=g[M+1])==null?void 0:nt.role)==="assistant"?Ce.add(M+1):me.role==="assistant"&&M>0&&((et=g[M-1])==null?void 0:et.role)==="user"&&Ce.add(M-1);const $e=g.filter((it,en)=>!Ce.has(en));C($e),W&&m(W,$e),Z(null)},[O,g,C,W,m]),Q=y.useCallback(M=>{if(!ye){if(te.length<=1){Qe();return}p(M)}},[ye,te.length,Qe,p]),pe=y.useCallback(()=>{if(!(!x||ye))return d(x)},[x,ye,d]),ve=y.useCallback(M=>{ye||M===W||h(M)},[ye,W,h]),L=y.useCallback((M,me)=>{w(M,me)},[w]);return u.jsxs("div",{className:"flex flex-col h-full border-l bg-surface-chat",children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-surface-chat",children:[u.jsx(Cz,{threads:te,activeThread:F,disabled:ye,onSwitch:ve,onCreate:pe,onDelete:Q,onRename:L}),u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(we,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:Qe,disabled:ye||g.length===0,children:"Clear"}),u.jsx(we,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:l,title:"Close chat",children:u.jsx(Nn,{className:"h-3.5 w-3.5"})})]})]}),u.jsx($r,{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:[g.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(Zo,{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(wa,{shortcut:"mod+k"}),u.jsx("span",{className:"text-xs text-muted-foreground",children:"to send a selection"})]})]}),g.map((M,me)=>{let Ce;if(M.role==="user"){const et=K(M.id);et&&et.length>0&&(Ce=et)}else if(M.role==="assistant"){for(let et=me-1;et>=0;et--)if(g[et].role==="user"){Ce=K(g[et].id);break}}const $e=le&&me===g.length-1&&M.role==="assistant",nt=M.role==="user"?N(M.id):void 0;return u.jsx(Tz,{msg:M,isStreaming:$e,context:Ce,scope:nt,onDelete:ye?void 0:re},M.id)}),ye&&((G=g[g.length-1])==null?void 0:G.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(ua,{className:"h-3.5 w-3.5 animate-spin text-primary"}),u.jsx("span",{children:"Thinking..."})]})})}),k&&!ye&&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:k.message||"Something went wrong"})}),u.jsx("div",{ref:q})]})}),u.jsxs("div",{className:`border-t border-border/60 p-2.5 space-y-2 bg-surface-chat transition-colors ${J?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:oe,onDragOver:ne,onDragLeave:ie,children:[e.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((M,me)=>u.jsx(rm,{context:M,onRemove:()=>n(me)},me))}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx(Oz,{model:s,setModel:a}),yt==="pptx"&&x&&u.jsx(Rz,{scope:r,setScope:i,docSize:((Se=(he=_.find(M=>M.name===x))==null?void 0:he.text)==null?void 0:Se.length)??0})]}),B.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:B.map((M,me)=>u.jsxs("div",{className:"relative group",children:[um(M.mediaType)?u.jsx("img",{src:M.url,alt:M.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:M.filename||"file"})]}),u.jsx("button",{type:"button",onClick:()=>b(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(Nn,{className:"h-3 w-3"})})]},me))}),u.jsxs("form",{onSubmit:Oe,className:"flex items-end gap-2",children:[u.jsx("input",{ref:fe,type:"file",accept:Ez,multiple:!0,className:"hidden",onChange:M=>{M.target.files&&ue(Array.from(M.target.files)),M.target.value=""}}),u.jsx(we,{type:"button",variant:"ghost",size:"icon",className:"shrink-0 h-9 w-9 rounded-lg text-muted-foreground hover:text-foreground",onClick:()=>{var M;return(M=fe.current)==null?void 0:M.click()},title:"Attach file",children:u.jsx(ca,{className:"h-4 w-4"})}),u.jsx("textarea",{ref:v,value:I,onChange:M=>{A(M.target.value);const me=M.target;me.style.height="auto",me.style.height=`${Math.min(me.scrollHeight,128)}px`},onKeyDown:qe,onPaste:Y,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}),ye?u.jsx(we,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:$,title:"Stop generating",children:u.jsx(dg,{className:"h-4 w-4"})}):u.jsx(we,{type:"submit",size:"icon",disabled:!I.trim()&&B.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:u.jsx(Zo,{className:"h-4 w-4"})})]})]}),u.jsx(It,{open:T,onOpenChange:P,children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Clear thread"}),u.jsx(cn,{children:"This will delete all messages in this thread. This action cannot be undone."})]}),u.jsxs(Cn,{children:[u.jsx(Vo,{asChild:!0,children:u.jsx(we,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(we,{variant:"destructive",size:"sm",onClick:j,children:"Clear"})]})]})}),u.jsx(It,{open:O!==null,onOpenChange:M=>{M||Z(null)},children:u.jsxs(St,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Delete message"}),u.jsx(cn,{children:"This will delete the message and its paired response. This action cannot be undone."})]}),u.jsxs(Cn,{children:[u.jsx(Vo,{asChild:!0,children:u.jsx(we,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(we,{variant:"destructive",size:"sm",onClick:ee,children:"Delete"})]})]})})]})}const Tz=y.memo(function({msg:t,isStreaming:n,context:r,scope:i,onDelete:s}){var l,c;const a=((l=t.parts)==null?void 0:l.filter(f=>f.type==="text").map(f=>f.text).join(""))||"",o=((c=t.parts)==null?void 0:c.filter(f=>f.type==="file"))||[];return u.jsx("div",{className:`group/msg flex ${t.role==="user"?"justify-end":"justify-start"}`,children:u.jsxs("div",{className:`rounded-lg px-3 py-2 max-w-[90%] overflow-hidden min-w-0 ${t.role==="user"?"bg-primary text-primary-foreground":"bg-muted/60 border border-border/40"}`,children:[t.role==="user"?u.jsxs("div",{children:[o.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:o.map((f,d)=>um(f.mediaType)?u.jsx("img",{src:f.url,alt:f.filename||"image",className:"h-20 max-w-[160px] rounded object-cover"},d):u.jsxs("div",{className:"flex items-center gap-1.5 rounded 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:f.filename||"file"})]},d))}),r&&r.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:r.map((f,d)=>u.jsx(rm,{context:f,variant:"sent"},d))}),a&&u.jsx("div",{className:"whitespace-pre-wrap text-sm break-words",children:a}),i&&i!=="global"&&u.jsx("span",{className:"text-[10px] text-primary-foreground/60 mt-0.5 block text-right",children:i})]}):u.jsx(Az,{text:a,isStreaming:n,context:r,scope:i}),s&&!n&&u.jsx("div",{className:"opacity-0 group-hover/msg:opacity-100 transition-opacity mt-1",children:u.jsx("button",{type:"button",onClick:()=>s(t.id),className:`p-0.5 rounded cursor-pointer ${t.role==="user"?"text-primary-foreground/50 hover:text-primary-foreground/80":"text-muted-foreground hover:text-destructive"}`,children:u.jsx(Ha,{className:"h-3 w-3"})})})]})})},(e,t)=>e.msg.id===t.msg.id&&e.isStreaming===t.isStreaming&&e.scope===t.scope&&e.onDelete===t.onDelete&&e.context===t.context);function Az({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(sk,{remarkPlugins:[y1],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 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(Mz,{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(Nz,{json:l,context:n,scope:r})]})}},children:e})})}const Pz=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function Oz({model:e,setModel:t}){return u.jsxs(Rr,{value:e,onValueChange:n=>t(n),children:[u.jsx(er,{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(Mr,{})}),u.jsx(tr,{children:Pz.map(n=>u.jsx(En,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const uc={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"},Dz=1e5;function Rz({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(uc).map(r=>u.jsxs(We,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("button",{type:"button",onClick:()=>t(r),className:`px-2 py-0.5 rounded 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:uc[r]})]},r))})]}),e==="global"&&n>Dz&&u.jsxs("div",{className:"text-[10px] text-amber-500 flex items-center gap-1",children:[u.jsx(td,{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-amber-400",children:"slides"})," ","or"," ",u.jsx("button",{type:"button",onClick:()=>t("templates"),className:"underline cursor-pointer hover:text-amber-400",children:"templates"})]})]})]})}function Mz({text:e}){const[t,n]=y.useState(!1),r=y.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 $z({discoveryData:e}){const t=Rd(),n=xx(),r=Te(N=>N.chatOpen),i=Te(N=>N.toggleChat),[s,a]=y.useState(()=>{try{const N=localStorage.getItem("dev-env.sidebar-open");return n?!1:N?N==="true":!0}catch{return!n}}),[o,l]=y.useState(()=>{try{const N=localStorage.getItem("dev-env.preview-open");return N?N==="true":!0}catch{return!0}}),[c,f]=y.useState("editor"),[d,p]=y.useState(!1),h=150,[m,w]=y.useState(!s),[S,x]=y.useState(!1);y.useEffect(()=>{try{localStorage.setItem("dev-env.sidebar-open",String(s))}catch{}},[s]),y.useEffect(()=>{try{localStorage.setItem("dev-env.preview-open",String(o))}catch{}},[o]);const _=y.useRef(n);y.useEffect(()=>{n&&!_.current&&s&&(x(!0),a(!1),setTimeout(()=>{w(!0),x(!1)},h)),!n&&_.current&&!s&&(x(!0),a(!0),setTimeout(()=>{w(!1),x(!1)},h)),_.current=n},[n,s]);const g=y.useCallback(()=>{if(t){p(N=>!N);return}x(!0),a(N=>!N),setTimeout(()=>{w(N=>!N),x(!1)},h)},[t]),z=y.useCallback(()=>l(N=>!N),[]),E=y.useRef(i),k=y.useRef(g),C=y.useRef(z);y.useEffect(()=>{E.current=i}),y.useEffect(()=>{k.current=g}),y.useEffect(()=>{C.current=z}),y.useEffect(()=>{const N=I=>{(I.metaKey||I.ctrlKey)&&(I.code==="KeyB"&&!I.shiftKey&&(I.preventDefault(),k.current()),I.code==="KeyJ"&&I.shiftKey&&(I.preventDefault(),I.stopPropagation(),E.current()),I.code==="KeyP"&&I.shiftKey&&(I.preventDefault(),C.current()))};return window.addEventListener("keydown",N,!0),()=>window.removeEventListener("keydown",N,!0)},[]);const $=nz,K=[{key:"editor",icon:nd,label:"Editor"},{key:"preview",icon:rd,label:"Preview"},{key:"chat",icon:id,label:"Chat"}];return t?u.jsx($,{children:u.jsxs("div",{className:"flex flex-col h-full w-full overflow-hidden",children:[u.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b bg-sidebar shrink-0",children:[u.jsxs(Pd,{open:d,onOpenChange:p,children:[u.jsx(fx,{asChild:!0,children:u.jsx(we,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:u.jsx(Qc,{className:"h-4 w-4"})})}),u.jsx(Qa,{side:"left",className:"p-0 w-72",children:u.jsx(tl,{discoveryData:e,onToggleSidebar:()=>p(!1),isCollapsed:!1})})]}),u.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:K.map(({key:N,icon:I,label:A})=>u.jsxs(we,{variant:c===N?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>f(N),children:[u.jsx(I,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"hidden xs:inline",children:A})]},N))})]}),c!=="chat"&&u.jsx(yl,{previewOpen:o,onTogglePreview:z}),u.jsxs("div",{className:"flex-1 min-h-0",children:[c==="editor"&&u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(nl,{})}),c==="preview"&&u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(rl,{})}),c==="chat"&&u.jsx(lc,{})]})]})}):u.jsx($,{children:u.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[u.jsx("div",{className:H("shrink-0 overflow-hidden border-r bg-sidebar","transition-[width] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]",s?"w-64":"w-12"),children:u.jsx(tl,{discoveryData:e,onToggleSidebar:g,isCollapsed:m,isAnimating:S})}),u.jsxs("div",{className:"flex-1 min-w-0 flex flex-col h-full",children:[u.jsx(yl,{previewOpen:o,onTogglePreview:z}),u.jsxs(zy,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[u.jsx(Ms,{defaultSize:o?50:100,minSize:20,id:"editor",order:1,children:u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(nl,{})})}),o&&u.jsxs(u.Fragment,{children:[u.jsx(pl,{withHandle:!0}),u.jsx(Ms,{defaultSize:50,minSize:20,id:"preview",order:2,children:u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(rl,{})})})]}),r&&u.jsxs(u.Fragment,{children:[u.jsx(pl,{withHandle:!0}),u.jsx(Ms,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:u.jsx(lc,{})})]})]})]})]})})}function Fz(){const[e,t]=y.useState(null),[n,r]=y.useState(!0),[i,s]=y.useState(null),a=y.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 y.useEffect(()=>{a()},[a]),{data:e,loading:n,error:i,refetch:a}}function Lz(){const[e,t]=y.useState(!1),[n,r]=y.useState(null),[i,s]=y.useState(0);return{loadPlugins:y.useCallback(async()=>{t(!0),r(null);try{const o=await fetch("/api/discovery/load-plugins",{method:"POST"});if(!o.ok)throw new Error(`Failed to load plugins: ${o.statusText}`);const l=await o.json();if(!l.success)throw new Error(l.error||"Failed to load plugins");return s(l.data.loaded),!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 Zz(){const{data:e,loading:t,error:n}=Fz(),{loadPlugins:r}=Lz(),i=Dt(s=>s.applyPluginsWithValidation);return y.useEffect(()=>{e&&e.plugins.length>0&&r().then(s=>{if(s){console.log("Plugins loaded successfully");const a=Dt.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(pg,{children:u.jsx(hg,{children:u.jsx(mg,{children:u.jsx(gg,{children:u.jsx(xg,{children:u.jsx(Qg,{children:u.jsx($d,{children:u.jsx("section",{className:"flex h-screen w-full flex-col",children:u.jsx("div",{className:"grow overflow-hidden",children:u.jsx($z,{discoveryData:e})})})})})})})})})})}const Yz=Object.freeze(Object.defineProperty({__proto__:null,HomePage:Zz},Symbol.toStringTag,{value:"Module"}));export{Vt as B,It as D,Yz as H,Fy as P,Ar as S,Zr as T,Wd as a,Ad as b,St as c,Ut as d,Jt as e,Dy as u};
|
|
99
|
-
//# sourceMappingURL=HomePage-
|
|
99
|
+
//# sourceMappingURL=HomePage-Czwc5NK6.js.map
|