@json-to-office/jto 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/client/assets/{HomePage-DgVVosCp.js → HomePage-ClplX49_.js} +4 -4
- package/dist/client/assets/{HomePage-DgVVosCp.js.map → HomePage-ClplX49_.js.map} +1 -1
- package/dist/client/assets/{JsonEditorPage-13oxEHfY.js → JsonEditorPage-VBBzZ5AM.js} +3 -3
- package/dist/client/assets/{JsonEditorPage-13oxEHfY.js.map → JsonEditorPage-VBBzZ5AM.js.map} +1 -1
- package/dist/client/assets/{MonacoPluginProvider-DiUyU9px.js → MonacoPluginProvider-DhTtNIjM.js} +3 -3
- package/dist/client/assets/{MonacoPluginProvider-DiUyU9px.js.map → MonacoPluginProvider-DhTtNIjM.js.map} +1 -1
- package/dist/client/assets/{editor-ouhvdGgK.js → editor-B4VqQFbE.js} +2 -2
- package/dist/client/assets/{editor-ouhvdGgK.js.map → editor-B4VqQFbE.js.map} +1 -1
- package/dist/client/assets/{editor-monaco-json-CTrPZKuA.js → editor-monaco-json-BHxvOGIG.js} +2 -2
- package/dist/client/assets/{editor-monaco-json-CTrPZKuA.js.map → editor-monaco-json-BHxvOGIG.js.map} +1 -1
- package/dist/client/assets/{editor-refs-store-DNQzN0_z.js → editor-refs-store-bPpACPf6.js} +2 -2
- package/dist/client/assets/{editor-refs-store-DNQzN0_z.js.map → editor-refs-store-bPpACPf6.js.map} +1 -1
- package/dist/client/assets/{index-CRuLxurM.js → index-D6iX-U9c.js} +4 -4
- package/dist/client/assets/index-D6iX-U9c.js.map +1 -0
- package/dist/client/assets/{preview-D3QYaLPp.js → preview-DElYSCd1.js} +2 -2
- package/dist/client/assets/{preview-D3QYaLPp.js.map → preview-DElYSCd1.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +3 -3
- package/dist/client/assets/index-CRuLxurM.js.map +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-
|
|
2
|
-
var Um=Object.defineProperty;var Jm=(e,t,n)=>t in e?Um(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var el=(e,t,n)=>Jm(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as je,R as Fc,g as la}from"./react-vendor-CTFDOf2G.js";import{b as Lc,c as ua,d as Bc,e as xs,f as ys,D as bs,O as vs,g as Hm,V as Wm,h as Zc,I as qm,i as Gm,j as Vc,k as Ym,l as Uc,m as Km,n as Xm,G as Qm,S as Jc,o as Hc,L as Wc,p as qc,q as Gc,r as _r,s as eg,t as tg,u as ng,v as Yc,w as Kc,x as Xc,y as Qc,z as ed,B as td,E as nd,F as rd,H as id,J as rg,K as ig,M as sg,N as sd,Q as od,U as ad,W as ld,X as ud,Y as cd,Z as dd,_ as fd,$ as pd,a0 as hd,a1 as og,a2 as md,a3 as ag,a4 as lg,a5 as gd,a6 as ug,a7 as cg,a8 as dg,a9 as fg,aa as pg,ab as hg,ac as mg,ad as xd,ae as yd,af as bd}from"./radix-ui-Bq-7y_Sq.js";import{c as G,u as jr,S as sn,A as Ji,T as Si,C as gg,E as xg,F as ot,a as yg,b as bg,d as qe,e as Ge,f as Ye,g as vd,_ as wd,h as _i,i as vg,j as wg,k as kg,l as Ir,s as Zs,W as kd,m as $i}from"./index-CRuLxurM.js";import{X as xn,C as hi,a as yn,b as Sg,d as mi,G as Sd,F as _g,e as Pn,f as _d,P as jg,g as Ng,h as jd,E as Nd,B as _o,H as Eg,T as jo,L as tl,i as Cg,j as Tg,S as Ed,I as Ig,k as Ag,l as No,m as zg,n as Og,o as Pg,p as Dg,q as Rg,r as Mg,s as $g,t as Fg,u as ws,v as Lg,M as Bg,w as Cd,x as nn,y as Zg,z as Vg,A as Td,D as Ug,J as Jg,K as Hg,N as Wg,R as qg,O as Gg,Q as Id,U as Yg,V as Eo,W as ca,Y as Ad,Z as Kg,_ as zd,$ as Lr,a0 as Xg,a1 as Qg,a2 as ex,a3 as nl,a4 as Co}from"./ui-vendor-DyQLnWB8.js";import{B as _e,u as tx,d as rl}from"./editor-refs-store-DNQzN0_z.js";import{u as Ce,i as nx,a as To,b as rn,g as rx,c as Bt,T as Od,d as ji,S as ix,O as sx,e as ox,M as ax,D as lx}from"./MonacoPluginProvider-DiUyU9px.js";import{u as da,a as ux,d as cx,p as dx,b as fx,e as px}from"./state-vendor-ByFYl9bq.js";import{b as hx}from"./query-vendor-Df8-oete.js";const Ct=Lc,mx=Bc,il=ua,Pd=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("fixed inset-0 z-50 bg-black/50",e),...t}));Pd.displayName=vs.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(mx,{children:[u.jsx(Pd,{}),u.jsxs(xs,{ref:r,className:G("bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",e),...n,children:[t,u.jsxs(ua,{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(xn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));kt.displayName=xs.displayName;const Ut=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ut.displayName="DialogHeader";const bn=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});bn.displayName="DialogFooter";const Jt=x.forwardRef(({className:e,...t},n)=>u.jsx(ys,{ref:n,className:G("text-lg leading-none font-semibold tracking-tight",e),...t}));Jt.displayName=ys.displayName;const an=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));an.displayName=bs.displayName;const ei=Hm,gx=Qm,ti=Wm,hr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Zc,{ref:r,className:G("border-input ring-offset-background placeholder:text-muted-foreground focus:ring-ring flex min-h-9 w-full min-w-0 items-center justify-between gap-2 rounded-sm border bg-background px-3 py-2 text-sm shadow-xs focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:min-w-0 [&>span]:whitespace-normal [&>span]:break-words text-left cursor-pointer",e),...n,children:[t,u.jsx(qm,{asChild:!0,children:u.jsx(hi,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));hr.displayName=Zc.displayName;const Dd=x.forwardRef(({className:e,...t},n)=>u.jsx(Jc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Sg,{className:"h-4 w-4"})}));Dd.displayName=Jc.displayName;const Rd=x.forwardRef(({className:e,...t},n)=>u.jsx(Hc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(hi,{className:"h-4 w-4"})}));Rd.displayName=Hc.displayName;const mr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(Gm,{children:u.jsxs(Vc,{ref:i,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-lg border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Dd,{}),u.jsx(Ym,{className:G("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Rd,{})]})}));mr.displayName=Vc.displayName;const Md=x.forwardRef(({className:e,...t},n)=>u.jsx(Wc,{ref:n,className:G("px-2 py-1.5 text-sm font-semibold",e),...t}));Md.displayName=Wc.displayName;const Dn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Uc,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex w-full cursor-pointer items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Km,{children:u.jsx(yn,{className:"h-4 w-4"})})}),u.jsx(Xm,{children:t})]}));Dn.displayName=Uc.displayName;const xx=x.forwardRef(({className:e,...t},n)=>u.jsx(qc,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));xx.displayName=qc.displayName;const gr=x.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:G("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-sm border bg-background px-3 py-1 text-sm shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));gr.displayName="Input";const yx=mi("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),sr=x.forwardRef(({className:e,...t},n)=>u.jsx(Gc,{ref:n,className:G(yx(),e),...t}));sr.displayName=Gc.displayName;const bx=mi("inline-flex items-center rounded-md border px-2.5 py-1 text-xs font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Kt({className:e,variant:t,...n}){return u.jsx("div",{className:G(bx({variant:t}),e),...n})}const vx=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:o}=Ce(da(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),{toast:a}=jr(),l=x.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[c,d]=x.useState(""),[f,p]=x.useState(""),[h,g]=x.useState("playground"),[v,S]=x.useState(!1),[y,j]=x.useState(null),[m,A]=x.useState(null),[C,w]=x.useState(null),N=()=>{j(null),A(null),w(null)};x.useEffect(()=>{if(!e)return;j(null),A(null),w(null);const T=l.map(z=>z.name),I=T.includes(i)?i:T[0]??"";p(I),d(T.find(z=>z!==I)??"")},[e]);const J=async()=>{const T=l.find(z=>z.name===c),I=l.find(z=>z.name===f);if(!(!T||!I)){S(!0),j(null),A(null),w(null);try{const z=await fetch(Ji.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:T.text,newDefinition:I.text,options:{author:h||"playground"}})}),O=await z.json();if(!z.ok||!O.success){const R=Array.isArray(O.errors)?`: ${O.errors.slice(0,3).map(Y=>Y.message||String(Y)).join("; ")}`:"";throw new Error((O.error||`Diff failed (${z.status})`)+R)}A(O.data.summary),w(O.data.document)}catch(z){j(z instanceof Error?z.message:"Diff failed")}finally{S(!1)}}},D=()=>{if(!C)return;const T=new Set(n.map(O=>O.name));let I=`${f}-redline`,z=2;for(;T.has(I);)I=`${f}-redline-${z++}`;s(I,JSON.stringify(C,null,2)),o(I),a({title:`Redline created: ${I}`}),t(!1)},_=m?m.tracked.modified+m.tracked.inserted+m.tracked.deleted:0;return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"sm:max-w-[560px]",children:[u.jsxs(Ut,{children:[u.jsxs(Jt,{className:"flex items-center gap-2",children:[u.jsx(Sd,{className:"size-4"}),"Compare documents"]}),u.jsx(an,{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(sr,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(ei,{value:c,onValueChange:T=>{d(T),N()},children:[u.jsx(hr,{id:"diff-base",children:u.jsx(ti,{placeholder:"Select document"})}),u.jsx(mr,{children:l.map(T=>u.jsx(Dn,{value:T.name,children:T.name},T.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(ei,{value:f,onValueChange:T=>{p(T),N()},children:[u.jsx(hr,{id:"diff-revised",children:u.jsx(ti,{placeholder:"Select document"})}),u.jsx(mr,{children:l.map(T=>u.jsx(Dn,{value:T.name,children:T.name},T.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(gr,{id:"diff-author",value:h,onChange:T=>{g(T.target.value),N()},placeholder:"playground"})]}),y&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:y}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Kt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),_===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((T,I)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},I))]}),m.notes.map((T,I)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},I))]})]}),u.jsx(bn,{children:m&&_+m.untracked.length>0?u.jsxs(_e,{onClick:D,children:[u.jsx(_g,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(_e,{onClick:J,disabled:v||!c||!f||c===f,children:[v&&u.jsx(sn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var gi=e=>e.type==="checkbox",In=e=>e instanceof Date,pt=e=>e==null;const $d=e=>typeof e=="object";var et=e=>!pt(e)&&!Array.isArray(e)&&$d(e)&&!In(e),Fd=e=>et(e)&&e.target?gi(e.target)?e.target.checked:e.target.value:e,wx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Ld=(e,t)=>e.has(wx(t)),kx=e=>{const t=e.constructor&&e.constructor.prototype;return et(t)&&t.hasOwnProperty("isPrototypeOf")},fa=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function yt(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(fa&&(e instanceof Blob||r))&&(n||et(e)))if(t=n?[]:{},!n&&!kx(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=yt(e[i]));else return e;return t}var ks=e=>Array.isArray(e)?e.filter(Boolean):[],Qe=e=>e===void 0,le=(e,t,n)=>{if(!t||!et(e))return n;const r=ks(t.split(/[,[\].]+?/)).reduce((i,s)=>pt(i)?i:i[s],e);return Qe(r)||r===e?Qe(e[t])?n:e[t]:r},zt=e=>typeof e=="boolean",pa=e=>/^\w*$/.test(e),Bd=e=>ks(e.replace(/["|']|\]/g,"").split(/\.|\[/)),$e=(e,t,n)=>{let r=-1;const i=pa(t)?[t]:Bd(t),s=i.length,o=s-1;for(;++r<s;){const a=i[r];let l=n;if(r!==o){const c=e[a];l=et(c)||Array.isArray(c)?c:isNaN(+i[r+1])?{}:[]}if(a==="__proto__"||a==="constructor"||a==="prototype")return;e[a]=l,e=e[a]}return e};const Hi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Lt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},tn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Zd=je.createContext(null),Ss=()=>je.useContext(Zd),Sx=e=>{const{children:t,...n}=e;return je.createElement(Zd.Provider,{value:n},t)};var Vd=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const o=s;return t._proxyFormState[o]!==Lt.all&&(t._proxyFormState[o]=!r||Lt.all),n&&(n[o]=!0),e[o]}});return i},bt=e=>et(e)&&!Object.keys(e).length,Ud=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return bt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(o=>t[o]===(!r||Lt.all))},qr=e=>Array.isArray(e)?e:[e],Jd=(e,t,n)=>!e||!t||e===t||qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function ha(e){const t=je.useRef(e);t.current=e,je.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function _x(e){const t=Ss(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[o,a]=je.useState(n._formState),l=je.useRef(!0),c=je.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=je.useRef(i);return d.current=i,ha({disabled:r,next:f=>l.current&&Jd(d.current,f.name,s)&&Ud(f,c.current,n._updateFormState)&&a({...n._formState,...f}),subject:n._subjects.state}),je.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),je.useMemo(()=>Vd(o,n,c.current,!1),[o,n])}var Yt=e=>typeof e=="string",Hd=(e,t,n,r,i)=>Yt(e)?(r&&t.watch.add(e),le(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),le(n,s))):(r&&(t.watchAll=!0),n);function jx(e){const t=Ss(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:o}=e||{},a=je.useRef(r);a.current=r,ha({disabled:s,subject:n._subjects.values,next:d=>{Jd(a.current,d.name,o)&&c(yt(Hd(a.current,n._names,d.values||n._formValues,!1,i)))}});const[l,c]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),l}function Nx(e){const t=Ss(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,o=Ld(i._names.array,n),a=jx({control:i,name:n,defaultValue:le(i._formValues,n,le(i._defaultValues,n,e.defaultValue)),exact:!0}),l=_x({control:i,name:n,exact:!0}),c=je.useRef(i.register(n,{...e.rules,value:a,...zt(e.disabled)?{disabled:e.disabled}:{}})),d=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!le(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!le(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!le(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!le(l.validatingFields,n)},error:{enumerable:!0,get:()=>le(l.errors,n)}}),[l,n]),f=je.useMemo(()=>({name:n,value:a,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:Fd(p),name:n},type:Hi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:le(i._formValues,n),name:n},type:Hi.BLUR}),ref:p=>{const h=le(i._fields,n);h&&p&&(h._f.ref={focus:()=>p.focus(),select:()=>p.select(),setCustomValidity:g=>p.setCustomValidity(g),reportValidity:()=>p.reportValidity()})}}),[n,i._formValues,r,l.disabled,a,i._fields]);return je.useEffect(()=>{const p=i._options.shouldUnregister||s,h=(g,v)=>{const S=le(i._fields,g);S&&S._f&&(S._f.mount=v)};if(h(n,!0),p){const g=yt(le(i._options.defaultValues,n));$e(i._defaultValues,n,g),Qe(le(i._formValues,n))&&$e(i._formValues,n,g)}return!o&&i.register(n),()=>{(o?p&&!i._state.action:p)?i.unregister(n):h(n,!1)}},[n,i,o,s]),je.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),je.useMemo(()=>({field:f,formState:l,fieldState:d}),[f,l,d])}const Ex=e=>e.render(Nx(e));var Cx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},sl=e=>({isOnSubmit:!e||e===Lt.onSubmit,isOnBlur:e===Lt.onBlur,isOnChange:e===Lt.onChange,isOnAll:e===Lt.all,isOnTouch:e===Lt.onTouched}),ol=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Gr=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=le(e,i);if(s){const{_f:o,...a}=s;if(o){if(o.refs&&o.refs[0]&&t(o.refs[0],i)&&!r)return!0;if(o.ref&&t(o.ref,o.name)&&!r)return!0;if(Gr(a,t))break}else if(et(a)&&Gr(a,t))break}}};var Tx=(e,t,n)=>{const r=qr(le(e,n));return $e(r,"root",t[n]),$e(e,n,r),e},ma=e=>e.type==="file",Gt=e=>typeof e=="function",Wi=e=>{if(!fa)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Fi=e=>Yt(e),ga=e=>e.type==="radio",qi=e=>e instanceof RegExp;const al={value:!1,isValid:!1},ll={value:!0,isValid:!0};var Wd=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Qe(e[0].attributes.value)?Qe(e[0].value)||e[0].value===""?ll:{value:e[0].value,isValid:!0}:ll:al}return al};const ul={isValid:!1,value:null};var qd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,ul):ul;function cl(e,t,n="validate"){if(Fi(e)||Array.isArray(e)&&e.every(Fi)||zt(e)&&!e)return{type:n,message:Fi(e)?e:"",ref:t}}var Bn=e=>et(e)&&!qi(e)?e:{value:e,message:""},dl=async(e,t,n,r,i,s)=>{const{ref:o,refs:a,required:l,maxLength:c,minLength:d,min:f,max:p,pattern:h,validate:g,name:v,valueAsNumber:S,mount:y}=e._f,j=le(n,v);if(!y||t.has(v))return{};const m=a?a[0]:o,A=I=>{i&&m.reportValidity&&(m.setCustomValidity(zt(I)?"":I||""),m.reportValidity())},C={},w=ga(o),N=gi(o),J=w||N,D=(S||ma(o))&&Qe(o.value)&&Qe(j)||Wi(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,_=Cx.bind(null,v,r,C),T=(I,z,O,R=tn.maxLength,Y=tn.minLength)=>{const H=I?z:O;C[v]={type:I?R:Y,message:H,ref:o,..._(I?R:Y,H)}};if(s?!Array.isArray(j)||!j.length:l&&(!J&&(D||pt(j))||zt(j)&&!j||N&&!Wd(a).isValid||w&&!qd(a).isValid)){const{value:I,message:z}=Fi(l)?{value:!!l,message:l}:Bn(l);if(I&&(C[v]={type:tn.required,message:z,ref:m,..._(tn.required,z)},!r))return A(z),C}if(!D&&(!pt(f)||!pt(p))){let I,z;const O=Bn(p),R=Bn(f);if(!pt(j)&&!isNaN(j)){const Y=o.valueAsNumber||j&&+j;pt(O.value)||(I=Y>O.value),pt(R.value)||(z=Y<R.value)}else{const Y=o.valueAsDate||new Date(j),H=k=>new Date(new Date().toDateString()+" "+k),$=o.type=="time",ee=o.type=="week";Yt(O.value)&&j&&(I=$?H(j)>H(O.value):ee?j>O.value:Y>new Date(O.value)),Yt(R.value)&&j&&(z=$?H(j)<H(R.value):ee?j<R.value:Y<new Date(R.value))}if((I||z)&&(T(!!I,O.message,R.message,tn.max,tn.min),!r))return A(C[v].message),C}if((c||d)&&!D&&(Yt(j)||s&&Array.isArray(j))){const I=Bn(c),z=Bn(d),O=!pt(I.value)&&j.length>+I.value,R=!pt(z.value)&&j.length<+z.value;if((O||R)&&(T(O,I.message,z.message),!r))return A(C[v].message),C}if(h&&!D&&Yt(j)){const{value:I,message:z}=Bn(h);if(qi(I)&&!j.match(I)&&(C[v]={type:tn.pattern,message:z,ref:o,..._(tn.pattern,z)},!r))return A(z),C}if(g){if(Gt(g)){const I=await g(j,n),z=cl(I,m);if(z&&(C[v]={...z,..._(tn.validate,z.message)},!r))return A(z.message),C}else if(et(g)){let I={};for(const z in g){if(!bt(I)&&!r)break;const O=cl(await g[z](j,n),m,z);O&&(I={...O,..._(z,O.message)},A(O.message),r&&(C[v]=I))}if(!bt(I)&&(C[v]={ref:m,...I},!r))return C}}return A(!0),C};function Ix(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Qe(e)?r++:e[t[r++]];return e}function Ax(e){for(const t in e)if(e.hasOwnProperty(t)&&!Qe(e[t]))return!1;return!0}function it(e,t){const n=Array.isArray(t)?t:pa(t)?[t]:Bd(t),r=n.length===1?e:Ix(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(et(r)&&bt(r)||Array.isArray(r)&&Ax(r))&&it(e,n.slice(0,-1)),e}var Vs=()=>{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=[]}}},Io=e=>pt(e)||!$d(e);function hn(e,t){if(Io(e)||Io(t))return e===t;if(In(e)&&In(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const s=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const o=t[i];if(In(s)&&In(o)||et(s)&&et(o)||Array.isArray(s)&&Array.isArray(o)?!hn(s,o):s!==o)return!1}}return!0}var Gd=e=>e.type==="select-multiple",zx=e=>ga(e)||gi(e),Us=e=>Wi(e)&&e.isConnected,Yd=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Gi(e,t={}){const n=Array.isArray(e);if(et(e)||n)for(const r in e)Array.isArray(e[r])||et(e[r])&&!Yd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Gi(e[r],t[r])):pt(e[r])||(t[r]=!0);return t}function Kd(e,t,n){const r=Array.isArray(e);if(et(e)||r)for(const i in e)Array.isArray(e[i])||et(e[i])&&!Yd(e[i])?Qe(t)||Io(n[i])?n[i]=Array.isArray(e[i])?Gi(e[i],[]):{...Gi(e[i])}:Kd(e[i],pt(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Ar=(e,t)=>Kd(e,t,Gi(t)),Xd=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Qe(e)?e:t?e===""?NaN:e&&+e:n&&Yt(e)?new Date(e):r?r(e):e;function Js(e){const t=e.ref;return ma(t)?t.files:ga(t)?qd(e.refs).value:Gd(t)?[...t.selectedOptions].map(({value:n})=>n):gi(t)?Wd(e.refs).value:Xd(Qe(t.value)?e.ref.value:t.value,e)}var Ox=(e,t,n,r)=>{const i={};for(const s of e){const o=le(t,s);o&&$e(i,s,o._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},zr=e=>Qe(e)?e:qi(e)?e.source:et(e)?qi(e.value)?e.value.source:e.value:e;const fl="AsyncFunction";var Px=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===fl||et(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===fl)),Dx=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function pl(e,t,n){const r=le(e,n);if(r||pa(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),o=le(t,s),a=le(e,s);if(o&&!Array.isArray(o)&&n!==s)return{name:n};if(a&&a.type)return{name:s,error:a};i.pop()}return{name:n}}var Rx=(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,Mx=(e,t)=>!ks(le(e,t)).length&&it(e,t);const $x={mode:Lt.onSubmit,reValidateMode:Lt.onChange,shouldFocusError:!0};function Fx(e={}){let t={...$x,...e},n={submitCount:0,isDirty:!1,isLoading:Gt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=et(t.defaultValues)||et(t.values)?yt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:yt(i),o={action:!1,mount:!1,watch:!1},a={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Vs(),array:Vs(),state:Vs()},p=sl(t.mode),h=sl(t.reValidateMode),g=t.criteriaMode===Lt.all,v=E=>M=>{clearTimeout(c),c=setTimeout(E,M)},S=async E=>{if(!t.disabled&&(d.isValid||E)){const M=t.resolver?bt((await J()).errors):await _(r,!0);M!==n.isValid&&f.state.next({isValid:M})}},y=(E,M)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((E||Array.from(a.mount)).forEach(F=>{F&&(M?$e(n.validatingFields,F,M):it(n.validatingFields,F))}),f.state.next({validatingFields:n.validatingFields,isValidating:!bt(n.validatingFields)}))},j=(E,M=[],F,ne,Q=!0,te=!0)=>{if(ne&&F&&!t.disabled){if(o.action=!0,te&&Array.isArray(le(r,E))){const de=F(le(r,E),ne.argA,ne.argB);Q&&$e(r,E,de)}if(te&&Array.isArray(le(n.errors,E))){const de=F(le(n.errors,E),ne.argA,ne.argB);Q&&$e(n.errors,E,de),Mx(n.errors,E)}if(d.touchedFields&&te&&Array.isArray(le(n.touchedFields,E))){const de=F(le(n.touchedFields,E),ne.argA,ne.argB);Q&&$e(n.touchedFields,E,de)}d.dirtyFields&&(n.dirtyFields=Ar(i,s)),f.state.next({name:E,isDirty:I(E,M),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else $e(s,E,M)},m=(E,M)=>{$e(n.errors,E,M),f.state.next({errors:n.errors})},A=E=>{n.errors=E,f.state.next({errors:n.errors,isValid:!1})},C=(E,M,F,ne)=>{const Q=le(r,E);if(Q){const te=le(s,E,Qe(F)?le(i,E):F);Qe(te)||ne&&ne.defaultChecked||M?$e(s,E,M?te:Js(Q._f)):R(E,te),o.mount&&S()}},w=(E,M,F,ne,Q)=>{let te=!1,de=!1;const ve={name:E};if(!t.disabled){const Z=!!(le(r,E)&&le(r,E)._f&&le(r,E)._f.disabled);if(!F||ne){d.isDirty&&(de=n.isDirty,n.isDirty=ve.isDirty=I(),te=de!==ve.isDirty);const K=Z||hn(le(i,E),M);de=!!(!Z&&le(n.dirtyFields,E)),K||Z?it(n.dirtyFields,E):$e(n.dirtyFields,E,!0),ve.dirtyFields=n.dirtyFields,te=te||d.dirtyFields&&de!==!K}if(F){const K=le(n.touchedFields,E);K||($e(n.touchedFields,E,F),ve.touchedFields=n.touchedFields,te=te||d.touchedFields&&K!==F)}te&&Q&&f.state.next(ve)}return te?ve:{}},N=(E,M,F,ne)=>{const Q=le(n.errors,E),te=d.isValid&&zt(M)&&n.isValid!==M;if(t.delayError&&F?(l=v(()=>m(E,F)),l(t.delayError)):(clearTimeout(c),l=null,F?$e(n.errors,E,F):it(n.errors,E)),(F?!hn(Q,F):Q)||!bt(ne)||te){const de={...ne,...te&&zt(M)?{isValid:M}:{},errors:n.errors,name:E};n={...n,...de},f.state.next(de)}},J=async E=>{y(E,!0);const M=await t.resolver(s,t.context,Ox(E||a.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return y(E),M},D=async E=>{const{errors:M}=await J(E);if(E)for(const F of E){const ne=le(M,F);ne?$e(n.errors,F,ne):it(n.errors,F)}else n.errors=M;return M},_=async(E,M,F={valid:!0})=>{for(const ne in E){const Q=E[ne];if(Q){const{_f:te,...de}=Q;if(te){const ve=a.array.has(te.name),Z=Q._f&&Px(Q._f);Z&&d.validatingFields&&y([ne],!0);const K=await dl(Q,a.disabled,s,g,t.shouldUseNativeValidation&&!M,ve);if(Z&&d.validatingFields&&y([ne]),K[te.name]&&(F.valid=!1,M))break;!M&&(le(K,te.name)?ve?Tx(n.errors,K,te.name):$e(n.errors,te.name,K[te.name]):it(n.errors,te.name))}!bt(de)&&await _(de,M,F)}}return F.valid},T=()=>{for(const E of a.unMount){const M=le(r,E);M&&(M._f.refs?M._f.refs.every(F=>!Us(F)):!Us(M._f.ref))&&re(E)}a.unMount=new Set},I=(E,M)=>!t.disabled&&(E&&M&&$e(s,E,M),!hn(oe(),i)),z=(E,M,F)=>Hd(E,a,{...o.mount?s:Qe(M)?i:Yt(E)?{[E]:M}:M},F,M),O=E=>ks(le(o.mount?s:i,E,t.shouldUnregister?le(i,E,[]):[])),R=(E,M,F={})=>{const ne=le(r,E);let Q=M;if(ne){const te=ne._f;te&&(!te.disabled&&$e(s,E,Xd(M,te)),Q=Wi(te.ref)&&pt(M)?"":M,Gd(te.ref)?[...te.ref.options].forEach(de=>de.selected=Q.includes(de.value)):te.refs?gi(te.ref)?te.refs.length>1?te.refs.forEach(de=>(!de.defaultChecked||!de.disabled)&&(de.checked=Array.isArray(Q)?!!Q.find(ve=>ve===de.value):Q===de.value)):te.refs[0]&&(te.refs[0].checked=!!Q):te.refs.forEach(de=>de.checked=de.value===Q):ma(te.ref)?te.ref.value="":(te.ref.value=Q,te.ref.type||f.values.next({name:E,values:{...s}})))}(F.shouldDirty||F.shouldTouch)&&w(E,Q,F.shouldTouch,F.shouldDirty,!0),F.shouldValidate&&k(E)},Y=(E,M,F)=>{for(const ne in M){const Q=M[ne],te=`${E}.${ne}`,de=le(r,te);(a.array.has(E)||et(Q)||de&&!de._f)&&!In(Q)?Y(te,Q,F):R(te,Q,F)}},H=(E,M,F={})=>{const ne=le(r,E),Q=a.array.has(E),te=yt(M);$e(s,E,te),Q?(f.array.next({name:E,values:{...s}}),(d.isDirty||d.dirtyFields)&&F.shouldDirty&&f.state.next({name:E,dirtyFields:Ar(i,s),isDirty:I(E,te)})):ne&&!ne._f&&!pt(te)?Y(E,te,F):R(E,te,F),ol(E,a)&&f.state.next({...n}),f.values.next({name:o.mount?E:void 0,values:{...s}})},$=async E=>{o.mount=!0;const M=E.target;let F=M.name,ne=!0;const Q=le(r,F),te=()=>M.type?Js(Q._f):Fd(E),de=ve=>{ne=Number.isNaN(ve)||In(ve)&&isNaN(ve.getTime())||hn(ve,le(s,F,ve))};if(Q){let ve,Z;const K=te(),ge=E.type===Hi.BLUR||E.type===Hi.FOCUS_OUT,Ne=!Dx(Q._f)&&!t.resolver&&!le(n.errors,F)&&!Q._f.deps||Rx(ge,le(n.touchedFields,F),n.isSubmitted,h,p),L=ol(F,a,ge);$e(s,F,K),ge?(Q._f.onBlur&&Q._f.onBlur(E),l&&l(0)):Q._f.onChange&&Q._f.onChange(E);const xe=w(F,K,ge,!1),ze=!bt(xe)||L;if(!ge&&f.values.next({name:F,type:E.type,values:{...s}}),Ne)return d.isValid&&(t.mode==="onBlur"&&ge?S():ge||S()),ze&&f.state.next({name:F,...L?{}:xe});if(!ge&&L&&f.state.next({...n}),t.resolver){const{errors:Be}=await J([F]);if(de(K),ne){const rt=pl(n.errors,r,F),tt=pl(Be,r,rt.name||F);ve=tt.error,F=tt.name,Z=bt(Be)}}else y([F],!0),ve=(await dl(Q,a.disabled,s,g,t.shouldUseNativeValidation))[F],y([F]),de(K),ne&&(ve?Z=!1:d.isValid&&(Z=await _(r,!0)));ne&&(Q._f.deps&&k(Q._f.deps),N(F,Z,ve,xe))}},ee=(E,M)=>{if(le(n.errors,M)&&E.focus)return E.focus(),1},k=async(E,M={})=>{let F,ne;const Q=qr(E);if(t.resolver){const te=await D(Qe(E)?E:Q);F=bt(te),ne=E?!Q.some(de=>le(te,de)):F}else E?(ne=(await Promise.all(Q.map(async te=>{const de=le(r,te);return await _(de&&de._f?{[te]:de}:de)}))).every(Boolean),!(!ne&&!n.isValid)&&S()):ne=F=await _(r);return f.state.next({...!Yt(E)||d.isValid&&F!==n.isValid?{}:{name:E},...t.resolver||!E?{isValid:F}:{},errors:n.errors}),M.shouldFocus&&!ne&&Gr(r,ee,E?Q:a.mount),ne},oe=E=>{const M={...o.mount?s:i};return Qe(E)?M:Yt(E)?le(M,E):E.map(F=>le(M,F))},q=(E,M)=>({invalid:!!le((M||n).errors,E),isDirty:!!le((M||n).dirtyFields,E),error:le((M||n).errors,E),isValidating:!!le(n.validatingFields,E),isTouched:!!le((M||n).touchedFields,E)}),b=E=>{E&&qr(E).forEach(M=>it(n.errors,M)),f.state.next({errors:E?n.errors:{}})},B=(E,M,F)=>{const ne=(le(r,E,{_f:{}})._f||{}).ref,Q=le(n.errors,E)||{},{ref:te,message:de,type:ve,...Z}=Q;$e(n.errors,E,{...Z,...M,ref:ne}),f.state.next({name:E,errors:n.errors,isValid:!1}),F&&F.shouldFocus&&ne&&ne.focus&&ne.focus()},V=(E,M)=>Gt(E)?f.values.subscribe({next:F=>E(z(void 0,M),F)}):z(E,M,!0),re=(E,M={})=>{for(const F of E?qr(E):a.mount)a.mount.delete(F),a.array.delete(F),M.keepValue||(it(r,F),it(s,F)),!M.keepError&&it(n.errors,F),!M.keepDirty&&it(n.dirtyFields,F),!M.keepTouched&&it(n.touchedFields,F),!M.keepIsValidating&&it(n.validatingFields,F),!t.shouldUnregister&&!M.keepDefaultValue&&it(i,F);f.values.next({values:{...s}}),f.state.next({...n,...M.keepDirty?{isDirty:I()}:{}}),!M.keepIsValid&&S()},se=({disabled:E,name:M,field:F,fields:ne})=>{(zt(E)&&o.mount||E||a.disabled.has(M))&&(E?a.disabled.add(M):a.disabled.delete(M),w(M,Js(F?F._f:le(ne,M)._f),!1,!1,!0))},P=(E,M={})=>{let F=le(r,E);const ne=zt(M.disabled)||zt(t.disabled);return $e(r,E,{...F||{},_f:{...F&&F._f?F._f:{ref:{name:E}},name:E,mount:!0,...M}}),a.mount.add(E),F?se({field:F,disabled:zt(M.disabled)?M.disabled:t.disabled,name:E}):C(E,!0,M.value),{...ne?{disabled:M.disabled||t.disabled}:{},...t.progressive?{required:!!M.required,min:zr(M.min),max:zr(M.max),minLength:zr(M.minLength),maxLength:zr(M.maxLength),pattern:zr(M.pattern)}:{},name:E,onChange:$,onBlur:$,ref:Q=>{if(Q){P(E,M),F=le(r,E);const te=Qe(Q.value)&&Q.querySelectorAll&&Q.querySelectorAll("input,select,textarea")[0]||Q,de=zx(te),ve=F._f.refs||[];if(de?ve.find(Z=>Z===te):te===F._f.ref)return;$e(r,E,{_f:{...F._f,...de?{refs:[...ve.filter(Us),te,...Array.isArray(le(i,E))?[{}]:[]],ref:{type:te.type,name:E}}:{ref:te}}}),C(E,!1,void 0,te)}else F=le(r,E,{}),F._f&&(F._f.mount=!1),(t.shouldUnregister||M.shouldUnregister)&&!(Ld(a.array,E)&&o.action)&&a.unMount.add(E)}}},ue=()=>t.shouldFocusError&&Gr(r,ee,a.mount),he=E=>{zt(E)&&(f.state.next({disabled:E}),Gr(r,(M,F)=>{const ne=le(r,F);ne&&(M.disabled=ne._f.disabled||E,Array.isArray(ne._f.refs)&&ne._f.refs.forEach(Q=>{Q.disabled=ne._f.disabled||E}))},0,!1))},ce=(E,M)=>async F=>{let ne;F&&(F.preventDefault&&F.preventDefault(),F.persist&&F.persist());let Q=yt(s);if(a.disabled.size)for(const te of a.disabled)$e(Q,te,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:te,values:de}=await J();n.errors=te,Q=de}else await _(r);if(it(n.errors,"root"),bt(n.errors)){f.state.next({errors:{}});try{await E(Q,F)}catch(te){ne=te}}else M&&await M({...n.errors},F),ue(),setTimeout(ue);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bt(n.errors)&&!ne,submitCount:n.submitCount+1,errors:n.errors}),ne)throw ne},pe=(E,M={})=>{le(r,E)&&(Qe(M.defaultValue)?H(E,yt(le(i,E))):(H(E,M.defaultValue),$e(i,E,yt(M.defaultValue))),M.keepTouched||it(n.touchedFields,E),M.keepDirty||(it(n.dirtyFields,E),n.isDirty=M.defaultValue?I(E,yt(le(i,E))):I()),M.keepError||(it(n.errors,E),d.isValid&&S()),f.state.next({...n}))},me=(E,M={})=>{const F=E?yt(E):i,ne=yt(F),Q=bt(E),te=Q?i:ne;if(M.keepDefaultValues||(i=F),!M.keepValues){if(M.keepDirtyValues){const de=new Set([...a.mount,...Object.keys(Ar(i,s))]);for(const ve of Array.from(de))le(n.dirtyFields,ve)?$e(te,ve,le(s,ve)):H(ve,le(te,ve))}else{if(fa&&Qe(E))for(const de of a.mount){const ve=le(r,de);if(ve&&ve._f){const Z=Array.isArray(ve._f.refs)?ve._f.refs[0]:ve._f.ref;if(Wi(Z)){const K=Z.closest("form");if(K){K.reset();break}}}}r={}}s=t.shouldUnregister?M.keepDefaultValues?yt(i):{}:yt(te),f.array.next({values:{...te}}),f.values.next({values:{...te}})}a={mount:M.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!d.isValid||!!M.keepIsValid||!!M.keepDirtyValues,o.watch=!!t.shouldUnregister,f.state.next({submitCount:M.keepSubmitCount?n.submitCount:0,isDirty:Q?!1:M.keepDirty?n.isDirty:!!(M.keepDefaultValues&&!hn(E,i)),isSubmitted:M.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:Q?{}:M.keepDirtyValues?M.keepDefaultValues&&s?Ar(i,s):n.dirtyFields:M.keepDefaultValues&&E?Ar(i,E):M.keepDirty?n.dirtyFields:{},touchedFields:M.keepTouched?n.touchedFields:{},errors:M.keepErrors?n.errors:{},isSubmitSuccessful:M.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},U=(E,M)=>me(Gt(E)?E(s):E,M);return{control:{register:P,unregister:re,getFieldState:q,handleSubmit:ce,setError:B,_executeSchema:J,_getWatch:z,_getDirty:I,_updateValid:S,_removeUnmounted:T,_updateFieldArray:j,_updateDisabledField:se,_getFieldArray:O,_reset:me,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(E=>{U(E,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:E=>{n={...n,...E}},_disableForm:he,_subjects:f,_proxyFormState:d,_setErrors:A,get _fields(){return r},get _formValues(){return s},get _state(){return o},set _state(E){o=E},get _defaultValues(){return i},get _names(){return a},set _names(E){a=E},get _formState(){return n},set _formState(E){n=E},get _options(){return t},set _options(E){t={...t,...E}}},trigger:k,register:P,handleSubmit:ce,watch:V,setValue:H,getValues:oe,reset:U,resetField:pe,clearErrors:b,unregister:re,setError:B,setFocus:(E,M={})=>{const F=le(r,E),ne=F&&F._f;if(ne){const Q=ne.refs?ne.refs[0]:ne.ref;Q.focus&&(Q.focus(),M.shouldSelect&&Gt(Q.select)&&Q.select())}},getFieldState:q}}function Lx(e={}){const t=je.useRef(void 0),n=je.useRef(void 0),[r,i]=je.useState({isDirty:!1,isValidating:!1,isLoading:Gt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Gt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Fx(e),formState:r});const s=t.current.control;return s._options=e,ha({subject:s._subjects.state,next:o=>{Ud(o,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),je.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),je.useEffect(()=>{if(s._proxyFormState.isDirty){const o=s._getDirty();o!==r.isDirty&&s._subjects.state.next({isDirty:o})}},[s,r.isDirty]),je.useEffect(()=>{e.values&&!hn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(o=>({...o}))):s._resetDefaultValues()},[e.values,s]),je.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),je.useEffect(()=>{s._state.mount||(s._updateValid(),s._state.mount=!0),s._state.watch&&(s._state.watch=!1,s._subjects.state.next({...s._formState})),s._removeUnmounted()}),je.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=Vd(r,s),t.current}function Bx(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 Zx=Sx,Qd=x.createContext({}),hl=({...e})=>u.jsx(Qd.Provider,{value:{name:e.name},children:u.jsx(Ex,{...e})}),_s=()=>{const e=x.useContext(Qd),t=x.useContext(ef),{getFieldState:n,formState:r}=Ss(),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}},ef=x.createContext({}),Ao=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(ef.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:G("space-y-2",e),...t})})});Ao.displayName="FormItem";const zo=x.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=_s();return u.jsx(sr,{ref:n,className:G(r&&"text-destructive",e),htmlFor:i,...t})});zo.displayName="FormLabel";const Oo=x.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=_s();return u.jsx(_r,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Oo.displayName="FormControl";const tf=x.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=_s();return u.jsx("p",{ref:n,id:r,className:G("text-muted-foreground text-[0.8rem]",e),...t})});tf.displayName="FormDescription";const Po=x.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=_s(),o=i?String(i==null?void 0:i.message):t;return o?u.jsx("p",{ref:r,id:s,className:G("text-destructive text-[0.8rem] font-medium",e),...n,children:o}):null});Po.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 nf=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Vx=(e=nf())=>ux()(cx(dx((t,n)=>({...e,toggleChat:()=>t(r=>({chatOpen:!r.chatOpen})),openChat:()=>t({chatOpen:!0}),closeChat:()=>t({chatOpen:!1}),addContext:r=>t(i=>({contextAttachments:[...i.contextAttachments,r]})),removeContext:r=>t(i=>({contextAttachments:i.contextAttachments.filter((s,o)=>o!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),o={id:i,documentName:r,title:xa(),messages:[],createdAt:s,updatedAt:s};return t(a=>({threads:{...a.threads,[i]:o},activeThreadId:{...a.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const o=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),a=s.documentName,l={...i.activeThreadId};if(l[a]===r){const c=Object.values(o).filter(d=>d.documentName===a);c.length>0?(c.sort((d,f)=>f.updatedAt-d.updatedAt),l[a]=c[0].id):delete l[a]}t({threads:o,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(o=>({activeThreadId:{...o.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},o={...i.activeThreadId};for(const[a,l]of Object.entries(s))l.documentName===r&&delete s[a];return delete o[r],{threads:s,activeThreadId:o}})},renameThreadsForDocument:(r,i)=>{t(s=>{const o={...s.threads},a={...s.activeThreadId};for(const[l,c]of Object.entries(o))c.documentName===r&&(o[l]={...c,documentName:i});return r in a&&(a[i]=a[r],delete a[r]),{threads:o,activeThreadId:a}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:fx(()=>nx),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}}))),rf=x.createContext(void 0),Ux=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Vx(nf())),u.jsx(rf.Provider,{value:t.current,children:e})},Re=e=>{const t=x.useContext(rf);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return px(t,e)};function Jx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Hx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=Si.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=Si.Optional(Si.String({description:"Template selection"})));const s=Si.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:o=>{const a=[];if(!gg(s,o))for(const c of xg(s,o))a.push({path:c.path.replace(/^\//,""),message:c.message});const l=o;if(e!=="delete"&&l.name){const c=l.name.trim();c?(l.name=c,t(c)||a.push({path:"name",message:"Document with this name already exists"})):a.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)||a.push({path:"template",message:"You must select a valid template"})),{success:a.length===0,data:a.length===0?l:void 0,errors:a}}}}function Wx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const qx=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"}}),Zn="__empty__";function Gx({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:o}){const[a,l]=x.useState(!1),[c,d]=x.useState(null),[f,p]=x.useState("idle"),{toast:h}=jr(),g=qx(o),{documents:v,openTabs:S,createDocument:y,renameDocument:j,deleteDocument:m,openDocument:A,closeDocument:C}=Ce(oe=>oe),{updateTheme:w,removeTheme:N}=To(oe=>oe),J=Re(oe=>oe.renameThreadsForDocument),D=Re(oe=>oe.deleteThreadsForDocument),_=x.useMemo(()=>o?s||[]:i||[],[o,i,s]),T=x.useMemo(()=>{const oe={current:[],downstream:[]};return _.forEach(q=>{oe[q.location]&&oe[q.location].push(q)}),oe},[_]),I=x.useMemo(()=>_.map(oe=>({name:oe.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[_]),z=x.useMemo(()=>Hx(e,oe=>Jx(oe,v,r),I),[e,v,r,I]),O=z.schema,R=x.useMemo(()=>{const oe=new Map;return _.forEach(q=>oe.set(q.path,q)),oe},[_]),Y=Zn,H=Lx({resolver:Bx(z.validate),defaultValues:Wx(e,void 0,r)}),[$,ee]=x.useState(Y);x.useEffect(()=>{if($&&$!==Zn&&e==="create"){const oe=R.get($);if(oe){d(null),p("loading");let q=!1;return fetch(`/api/discovery/${o?"themes":"documents"}/${encodeURIComponent(oe.name)}/content`).then(b=>{if(!b.ok)throw new Error(`Failed to fetch content: ${b.statusText}`);return b.text()}).then(b=>{if(q)return;const B=JSON.parse(b);d(JSON.stringify(B,null,2)),p("idle")}).catch(b=>{q||(console.error("Failed to copy template:",b),d(null),p("error"))}),()=>{q=!0}}}p("idle")},[$,e,R,o]),x.useEffect(()=>{t&&(H.reset(),d(null),p("idle"),ee(Y))},[H,t]);const k=H.handleSubmit(async({name:oe,template:q})=>{l(!0);try{if(await new Promise(b=>setTimeout(b,200)),e==="create"){const b=$?R.get($):_.find(pe=>pe.name===q);let B,V=oe;if(!!$&&$!==Zn&&c===null){h({title:f==="loading"?"Template still loading":`Could not copy ${(b==null?void 0:b.name)??"the selected template"}`,description:f==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(o){const pe=V.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),me=ot==="docx"?yg(pe):{name:pe,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};B=c||JSON.stringify(me,null,2);const U=`.${ot}.theme.json`;V.endsWith(U)||(V=V.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),V+=U)}else{const pe=b;B=c||JSON.stringify(ot==="docx"?{name:"docx",props:{theme:(pe==null?void 0:pe.theme)||"default",metadata:{title:(pe==null?void 0:pe.title)||V.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(pe==null?void 0:pe.title)||V.replace(/\.(json|js)$/i,""),theme:(pe==null?void 0:pe.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 me=ot==="docx"?".docx.json":".pptx.json";!V.endsWith(me)&&!V.endsWith(".json")&&(V+=me)}const se=V.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),P=se?se[0]:"",ue=V.slice(0,V.length-P.length);let he=V,ce=1;for(;v.some(pe=>pe.name===he);)ce++,he=`${ue} (${ce})${P}`;V=he,y(V,B),A(V),o&&w(V,B)}else if(e==="update"){const b=r,B=oe,V=S.includes(b);V&&C(b),j(b,B),J(b,B),V&&A(B)}else if(e==="delete"){const b=r;C(b),m(b),D(b),o&&N(b)}n()}finally{l(!1)}});return u.jsx(Zx,{...H,children:u.jsxs("form",{onSubmit:k,children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:g[e].title}),u.jsx(an,{children:g[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[O.properties&&"name"in O.properties&&u.jsx(hl,{control:H.control,name:"name",render:({field:oe})=>u.jsxs(Ao,{children:[u.jsx(zo,{children:"Name"}),u.jsx(Oo,{children:u.jsx(gr,{placeholder:"Enter a name or select a template below",autoComplete:"off",...oe})}),u.jsx(Po,{})]})}),e==="create"&&u.jsx(hl,{control:H.control,name:"template",render:({field:oe})=>u.jsxs(Ao,{children:[u.jsx(zo,{children:o?"Base Theme":"Base Document"}),u.jsxs(ei,{onValueChange:q=>{if(q===Zn)oe.onChange(void 0),H.setValue("name",""),ee(Zn),d(null);else{const b=R.get(q);b&&(oe.onChange(b.name),H.setValue("name",b.name),ee(q))}},defaultValue:Y,children:[u.jsx(Oo,{children:u.jsx(hr,{children:u.jsx(ti,{placeholder:`Select a discovered ${o?"theme":"document"}`})})}),u.jsxs(mr,{className:"max-h-[300px]",children:[u.jsxs(Dn,{value:Zn,children:["Empty ",o?"theme":"document"]}),Object.entries(T).map(([q,b])=>b.length===0?null:u.jsxs(gx,{children:[u.jsx(Md,{children:q==="current"?"📁 Current Directory":"📦 Project"}),b.map(B=>{let V;return B.title&&B.title!==B.name?V=B.title:B.description&&(V=B.description.length>40?B.description.substring(0,40)+"...":B.description),u.jsx(Dn,{value:B.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:B.name}),V&&u.jsx("span",{className:"text-muted-foreground text-xs",children:V})]})},B.path)})]},q))]})]}),u.jsxs(tf,{children:["Start empty or select a discovered"," ",o?"theme":"document"," as a starting point"]}),u.jsx(Po,{})]})})]}),u.jsx(bn,{children:u.jsx(_e,{type:"submit",variant:g[e].buttonVariant,disabled:a,children:a?u.jsxs(u.Fragment,{children:[u.jsx(sn,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):g[e].button})})]})})}const Yi=je.memo(Gx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function ya({text:e,query:t}){if(!t)return u.jsx(u.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?u.jsx(u.Fragment,{children:e}):u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Do({children:e,count:t,actions:n,className:r}){return u.jsxs("div",{className:G("flex h-6 shrink-0 items-center gap-1.5 px-1 select-none",r),children:[u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] text-sidebar-foreground/70 uppercase",children:e}),t!==void 0&&u.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t}),n&&u.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:n})]})}const $t=je.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:G("flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm","text-sidebar-foreground/55 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","disabled:pointer-events-none disabled:opacity-40","[&>svg]:size-3.5",e),...t}));$t.displayName="RailIconButton";function ml({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:G("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function gl({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:G("flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(e,{className:"size-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:t})]}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const Yx=eg,Kx=tg,Xx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(Qc,{ref:i,className:G("focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none",t&&"pl-8",e),...r,children:[n,u.jsx(Pn,{className:"ml-auto h-4 w-4"})]}));Xx.displayName=Qc.displayName;const Qx=x.forwardRef(({className:e,...t},n)=>u.jsx(ed,{ref:n,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));Qx.displayName=ed.displayName;const sf=x.forwardRef(({className:e,...t},n)=>u.jsx(ng,{children:u.jsx(Yc,{ref:n,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md",e),...t})}));sf.displayName=Yc.displayName;const of=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Xc,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));of.displayName=Xc.displayName;const ey=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(td,{ref:i,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(nd,{children:u.jsx(yn,{className:"h-4 w-4"})})}),t]}));ey.displayName=td.displayName;const ty=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(rd,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(nd,{children:u.jsx(_d,{className:"h-4 w-4 fill-current"})})}),t]}));ty.displayName=rd.displayName;const ny=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(id,{ref:r,className:G("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ny.displayName=id.displayName;const af=x.forwardRef(({className:e,...t},n)=>u.jsx(Kc,{ref:n,className:G("bg-border -mx-1 my-1 h-px",e),...t}));af.displayName=Kc.displayName;const lf=({className:e,...t})=>u.jsx("span",{className:G("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});lf.displayName="ContextMenuShortcut";const js=rg,Ns=ig,ry=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(ud,{ref:i,className:G("focus:bg-accent data-[state=open]:bg-accent flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none select-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",e),...r,children:[n,u.jsx(Pn,{className:"ml-auto"})]}));ry.displayName=ud.displayName;const iy=x.forwardRef(({className:e,...t},n)=>u.jsx(cd,{ref:n,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));iy.displayName=cd.displayName;const xi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(sg,{children:u.jsx(sd,{ref:r,sideOffset:t,className:G("bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));xi.displayName=sd.displayName;const Ft=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(od,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",e),...n}));Ft.displayName=od.displayName;const sy=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(dd,{ref:i,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(fd,{children:u.jsx(yn,{className:"h-4 w-4"})})}),t]}));sy.displayName=dd.displayName;const oy=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pd,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(fd,{children:u.jsx(_d,{className:"h-2 w-2 fill-current"})})}),t]}));oy.displayName=pd.displayName;const uf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ld,{ref:r,className:G("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));uf.displayName=ld.displayName;const xr=x.forwardRef(({className:e,...t},n)=>u.jsx(ad,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));xr.displayName=ad.displayName;const cf=({className:e,...t})=>u.jsx("span",{className:G("ml-auto text-xs tracking-widest opacity-60",e),...t});cf.displayName="DropdownMenuShortcut";const df=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(hd,{ref:i,decorative:n,orientation:t,className:G("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));df.displayName=hd.displayName;const ff=Lc,ay=og,ly=Bc,pf=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{className:G("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t,ref:n}));pf.displayName=vs.displayName;const uy=mi("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"}}),ba=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(ly,{children:[u.jsx(pf,{}),u.jsxs(xs,{ref:i,className:G(uy({side:e}),t),...r,children:[u.jsxs(ua,{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(xn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));ba.displayName=xs.displayName;const cy=x.forwardRef(({className:e,...t},n)=>u.jsx(ys,{ref:n,className:G("text-foreground text-lg font-semibold",e),...t}));cy.displayName=ys.displayName;const dy=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));dy.displayName=bs.displayName;function Yr({className:e,...t}){return u.jsx("div",{className:G("bg-primary/10 animate-pulse rounded-md",e),...t})}const Hs=768,Ws=1200;function hf(e){return typeof window<"u"?window.innerWidth<e:!1}function mf(){const[e,t]=x.useState(()=>hf(Hs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Hs-1}px)`),r=()=>{t(window.innerWidth<Hs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function fy(){const[e,t]=x.useState(()=>hf(Ws));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ws-1}px)`),r=()=>{t(window.innerWidth<Ws)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const py="sidebar_state",hy=60*60*24*7,my="16rem",gy="18rem",xy="3rem",yy="b",gf=x.createContext(null);function Es(){const e=x.useContext(gf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const xf=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...o},a)=>{const l=mf(),[c,d]=x.useState(!1),[f,p]=x.useState(e),h=t??f,g=x.useCallback(j=>{const m=typeof j=="function"?j(h):j;n?n(m):p(m),document.cookie=`${py}=${m}; path=/; max-age=${hy}`},[n,h]),v=x.useCallback(()=>l?d(j=>!j):g(j=>!j),[l,g,d]);x.useEffect(()=>{const j=A=>{var N;const C=A;if(!C)return!1;const w=(N=C.tagName)==null?void 0:N.toLowerCase();return w==="input"||w==="textarea"||w==="select"||C.isContentEditable?!0:!!(C.closest&&C.closest(".monaco-editor"))},m=A=>{const C=A.metaKey||A.ctrlKey,w=A.key.toLowerCase();if(C&&w===yy){A.preventDefault(),v();return}C&&w==="s"&&!j(A.target)&&(A.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const S=h?"expanded":"collapsed",y=x.useMemo(()=>({state:S,open:h,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:d,toggleSidebar:v}),[S,h,g,l,c,d,v]);return u.jsx(gf.Provider,{value:y,children:u.jsx(bg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":my,"--sidebar-width-icon":xy,...i},className:G("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:a,...o,children:s})})})});xf.displayName="SidebarProvider";const yf=x.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},o)=>{const{isMobile:a,state:l,openMobile:c,setOpenMobile:d}=Es();return n==="none"?u.jsx("div",{className:G("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:o,...s,children:i}):a?u.jsx(ff,{open:c,onOpenChange:d,...s,children:u.jsx(ba,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":gy},side:e,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):u.jsxs("div",{ref:o,className:"group peer text-sidebar-foreground hidden md:block","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":t,"data-side":e,children:[u.jsx("div",{className:G("relative h-svh w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),u.jsx("div",{className:G("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",e==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...s,children:u.jsx("div",{"data-sidebar":"sidebar",className:"bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow",children:i})})]})});yf.displayName="Sidebar";const by=x.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=Es();return u.jsxs(_e,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:G("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(jg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});by.displayName="SidebarTrigger";const vy=x.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=Es();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:G("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:hover:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",e),...t})});vy.displayName="SidebarRail";const wy=x.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:G("bg-background relative flex min-h-svh flex-1 flex-col","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2",e),...t}));wy.displayName="SidebarInset";const ky=x.forwardRef(({className:e,...t},n)=>u.jsx(gr,{ref:n,"data-sidebar":"input",className:G("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));ky.displayName="SidebarInput";const Ro=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:G("flex flex-col gap-2 p-2",e),...t}));Ro.displayName="SidebarHeader";const bf=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:G("flex flex-col gap-2 p-2",e),...t}));bf.displayName="SidebarFooter";const Sy=x.forwardRef(({className:e,...t},n)=>u.jsx(df,{ref:n,"data-sidebar":"separator",className:G("bg-sidebar-border mx-2 w-auto",e),...t}));Sy.displayName="SidebarSeparator";const Mo=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:G("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Mo.displayName="SidebarContent";const _y=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:G("relative flex w-full min-w-0 flex-col p-2",e),...t}));_y.displayName="SidebarGroup";const jy=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?_r:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:G("text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium transition-[margin,opa] duration-200 ease-linear outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",e),...n})});jy.displayName="SidebarGroupLabel";const Ny=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?_r:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:G("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",e),...n})});Ny.displayName="SidebarGroupAction";const Ey=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:G("w-full text-sm",e),...t}));Ey.displayName="SidebarGroupContent";const Br=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:G("flex w-full min-w-0 flex-col gap-1",e),...t}));Br.displayName="SidebarMenu";const vf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:G("group/menu-item relative",e),...t}));vf.displayName="SidebarMenuItem";const Cy=mi("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"}}),wf=x.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...o},a)=>{const l=e?_r:"button",{isMobile:c,state:d}=Es(),f=u.jsx(l,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:G(Cy({variant:n,size:r}),s),...o});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:f}),u.jsx(Ye,{side:"right",align:"center",hidden:d!=="collapsed"||c,...i})]})):f});wf.displayName="SidebarMenuButton";const kf=x.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?_r:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:G("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",e),...r})});kf.displayName="SidebarMenuAction";const Ty=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:G("text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",e),...t}));Ty.displayName="SidebarMenuBadge";const Iy=x.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=x.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:G("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Yr,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Yr,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Iy.displayName="SidebarMenuSkeleton";const Ay=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:G("border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",e),...t}));Ay.displayName="SidebarMenuSub";const zy=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));zy.displayName="SidebarMenuSubItem";const Oy=x.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const o=e?_r:"a";return u.jsx(o,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:G("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...i})});Oy.displayName="SidebarMenuSubButton";function Li(e,t){const n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.style.display="none",r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}const Py=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Dy({document:e,compact:t=!1,query:n=""}){const r=x.useRef(null),[i,s]=x.useState(!1),[o,a]=x.useState(!1),[l,c]=x.useState(!1),[d,f]=x.useState(!1),p=Ce(q=>q.openDocument),h=Ce(q=>q.documentTypes),g=Ce(q=>q.activeTab),v=rn(q=>q.name),S=rn(q=>q.text),y=rn(q=>q.isGenerating),m=(h[e.name]||"application/json+report")==="application/json+theme",A=g===e.name,[C,w]=x.useState(v),[N,J]=x.useState(S),D=100,_=0;x.useEffect(()=>{const q=setTimeout(()=>{v&&S?(w(v),J(S)):y||(w(""),J(""))},y?D:_);return()=>clearTimeout(q)},[v,S,y]);const T=C===e.name,I=q=>{var B;const b=new Set;try{const V=JSON.parse(q);(B=V.props)!=null&&B.theme&&b.add(V.props.theme),V.children&&Array.isArray(V.children)&&V.children.forEach(re=>{var se;re.name==="docx"&&((se=re.props)!=null&&se.theme)&&b.add(re.props.theme)})}catch{}return b},z=x.useMemo(()=>{if(!m||!N)return!1;try{const q=JSON.parse(e.text),b=rx(q);if(b)return I(N).has(b)}catch{}return!1},[m,N,e.text]),O=x.useCallback(()=>{c(!1)},[]),R=x.useCallback(()=>{f(!1)},[]),Y=A?null:T?"preview":z?"in-use":null,H=A?"Editing":T?"In preview":z?"Used by preview":null,$=x.useMemo(()=>[{key:"open",label:"Open",shortcut:Py?"⌘⏎":"⌃⏎",run:()=>p(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Li(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>f(!0)}],[e.name,e.text,e.type,p]),ee=m?Ng:jd,k=i||o,oe=u.jsxs(wf,{size:"sm",ref:r,"aria-label":H?`${e.name} — ${H}`:e.name,className:G("relative h-7 rounded-sm text-[13px] font-normal","text-sidebar-foreground/85 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground",t?"size-7 justify-center px-0":"gap-2 pr-7 pl-2",k&&"bg-sidebar-accent/60 text-sidebar-foreground",A&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:H?`${e.name} — ${H}`:e.name,onClick:()=>{p(e.name)},onKeyDown:q=>{var b;(q.ctrlKey||q.metaKey)&&q.key==="Enter"?(p(e.name),q.preventDefault()):q.key==="Enter"?(c(!0),q.preventDefault()):q.key==="Backspace"||q.key==="Delete"?(f(!0),q.preventDefault()):q.key==="Escape"&&((b=r.current)==null||b.blur(),q.preventDefault())},children:[A&&u.jsx("span",{"aria-hidden":!0,className:G("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(ee,{className:G("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",A&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(ya,{text:e.name,query:n})}),t&&Y&&u.jsx(ml,{tone:Y,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(vf,{children:[u.jsxs(Yx,{onOpenChange:s,children:[u.jsx(Kx,{className:"block",children:t?u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:oe}),u.jsx(Ye,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:H??(m?"Theme":"Document")})]})})]}):oe}),u.jsx(sf,{className:"w-44",children:$.map(q=>u.jsxs(je.Fragment,{children:[q.separatorBefore&&u.jsx(af,{}),u.jsxs(of,{onClick:q.run,className:G(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(lf,{children:q.shortcut})]})]},q.key))})]}),!t&&u.jsxs(u.Fragment,{children:[Y&&u.jsx(ml,{tone:Y,className:G("pointer-events-none absolute top-1/2 right-2.5 -translate-y-1/2 transition-opacity","group-hover/menu-item:opacity-0 group-focus-within/menu-item:opacity-0",o&&"opacity-0")}),u.jsxs(js,{onOpenChange:a,children:[u.jsx(Ns,{asChild:!0,children:u.jsx(kf,{showOnHover:!0,"aria-label":`Actions for ${e.name}`,className:"top-1 size-5 rounded-sm text-sidebar-foreground/55 hover:text-sidebar-foreground [&>svg]:size-3.5",children:u.jsx(Nd,{})})}),u.jsx(xi,{side:"right",align:"start",className:"w-44",children:$.map(q=>u.jsxs(je.Fragment,{children:[q.separatorBefore&&u.jsx(xr,{}),u.jsxs(Ft,{onClick:q.run,className:G(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(cf,{children:q.shortcut})]})]},q.key))})]})]}),u.jsx(Ct,{open:l,onOpenChange:c,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var b;q.preventDefault(),(b=r.current)==null||b.focus()},children:u.jsx(Yi,{mode:"update",shouldReset:!l,postSubmit:O,selectedName:e.name})})}),u.jsx(Ct,{open:d,onOpenChange:f,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var b;q.preventDefault(),(b=r.current)==null||b.focus()},children:u.jsx(Yi,{mode:"delete",shouldReset:!d,postSubmit:R,selectedName:e.name})})})]})}const Ni=je.memo(Dy);function Ry(e,t=!1){const n=e.length;let r=0,i="",s=0,o=16,a=0,l=0,c=0,d=0,f=0;function p(m,A){let C=0,w=0;for(;C<m;){let N=e.charCodeAt(r);if(N>=48&&N<=57)w=w*16+N-48;else if(N>=65&&N<=70)w=w*16+N-65+10;else if(N>=97&&N<=102)w=w*16+N-97+10;else break;r++,C++}return C<m&&(w=-1),w}function h(m){r=m,i="",s=0,o=16,f=0}function g(){let m=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Vn(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Vn(e.charCodeAt(r)))for(r++;r<e.length&&Vn(e.charCodeAt(r));)r++;else return f=3,e.substring(m,r);let A=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Vn(e.charCodeAt(r))){for(r++;r<e.length&&Vn(e.charCodeAt(r));)r++;A=r}else f=3;return e.substring(m,A)}function v(){let m="",A=r;for(;;){if(r>=n){m+=e.substring(A,r),f=2;break}const C=e.charCodeAt(r);if(C===34){m+=e.substring(A,r),r++;break}if(C===92){if(m+=e.substring(A,r),r++,r>=n){f=2;break}switch(e.charCodeAt(r++)){case 34:m+='"';break;case 92:m+="\\";break;case 47:m+="/";break;case 98:m+="\b";break;case 102:m+="\f";break;case 110:m+=`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-B4VqQFbE.js","assets/react-vendor-CTFDOf2G.js","assets/editor-monaco-json-BHxvOGIG.js","assets/index-D6iX-U9c.js","assets/query-vendor-Df8-oete.js","assets/radix-ui-Bq-7y_Sq.js","assets/ui-vendor-DyQLnWB8.js","assets/monaco-editor-BcgxPCqT.js","assets/state-vendor-ByFYl9bq.js","assets/index-CnUTzeor.css","assets/editor-refs-store-bPpACPf6.js","assets/MonacoPluginProvider-DhTtNIjM.js","assets/preview-DElYSCd1.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Um=Object.defineProperty;var Jm=(e,t,n)=>t in e?Um(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var el=(e,t,n)=>Jm(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as je,R as Fc,g as la}from"./react-vendor-CTFDOf2G.js";import{b as Lc,c as ua,d as Bc,e as xs,f as ys,D as bs,O as vs,g as Hm,V as Wm,h as Zc,I as qm,i as Gm,j as Vc,k as Ym,l as Uc,m as Km,n as Xm,G as Qm,S as Jc,o as Hc,L as Wc,p as qc,q as Gc,r as _r,s as eg,t as tg,u as ng,v as Yc,w as Kc,x as Xc,y as Qc,z as ed,B as td,E as nd,F as rd,H as id,J as rg,K as ig,M as sg,N as sd,Q as od,U as ad,W as ld,X as ud,Y as cd,Z as dd,_ as fd,$ as pd,a0 as hd,a1 as og,a2 as md,a3 as ag,a4 as lg,a5 as gd,a6 as ug,a7 as cg,a8 as dg,a9 as fg,aa as pg,ab as hg,ac as mg,ad as xd,ae as yd,af as bd}from"./radix-ui-Bq-7y_Sq.js";import{c as G,u as jr,S as sn,A as Ji,T as Si,C as gg,E as xg,F as ot,a as yg,b as bg,d as qe,e as Ge,f as Ye,g as vd,_ as wd,h as _i,i as vg,j as wg,k as kg,l as Ir,s as Zs,W as kd,m as $i}from"./index-D6iX-U9c.js";import{X as xn,C as hi,a as yn,b as Sg,d as mi,G as Sd,F as _g,e as Pn,f as _d,P as jg,g as Ng,h as jd,E as Nd,B as _o,H as Eg,T as jo,L as tl,i as Cg,j as Tg,S as Ed,I as Ig,k as Ag,l as No,m as zg,n as Og,o as Pg,p as Dg,q as Rg,r as Mg,s as $g,t as Fg,u as ws,v as Lg,M as Bg,w as Cd,x as nn,y as Zg,z as Vg,A as Td,D as Ug,J as Jg,K as Hg,N as Wg,R as qg,O as Gg,Q as Id,U as Yg,V as Eo,W as ca,Y as Ad,Z as Kg,_ as zd,$ as Lr,a0 as Xg,a1 as Qg,a2 as ex,a3 as nl,a4 as Co}from"./ui-vendor-DyQLnWB8.js";import{B as _e,u as tx,d as rl}from"./editor-refs-store-bPpACPf6.js";import{u as Ce,i as nx,a as To,b as rn,g as rx,c as Bt,T as Od,d as ji,S as ix,O as sx,e as ox,M as ax,D as lx}from"./MonacoPluginProvider-DhTtNIjM.js";import{u as da,a as ux,d as cx,p as dx,b as fx,e as px}from"./state-vendor-ByFYl9bq.js";import{b as hx}from"./query-vendor-Df8-oete.js";const Ct=Lc,mx=Bc,il=ua,Pd=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{ref:n,className:G("fixed inset-0 z-50 bg-black/50",e),...t}));Pd.displayName=vs.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(mx,{children:[u.jsx(Pd,{}),u.jsxs(xs,{ref:r,className:G("bg-background fixed top-[50%] left-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border p-6 shadow-lg sm:rounded-lg",e),...n,children:[t,u.jsxs(ua,{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(xn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));kt.displayName=xs.displayName;const Ut=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ut.displayName="DialogHeader";const bn=({className:e,...t})=>u.jsx("div",{className:G("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});bn.displayName="DialogFooter";const Jt=x.forwardRef(({className:e,...t},n)=>u.jsx(ys,{ref:n,className:G("text-lg leading-none font-semibold tracking-tight",e),...t}));Jt.displayName=ys.displayName;const an=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));an.displayName=bs.displayName;const ei=Hm,gx=Qm,ti=Wm,hr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Zc,{ref:r,className:G("border-input ring-offset-background placeholder:text-muted-foreground focus:ring-ring flex min-h-9 w-full min-w-0 items-center justify-between gap-2 rounded-sm border bg-background px-3 py-2 text-sm shadow-xs focus:ring-1 focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 [&>span]:min-w-0 [&>span]:whitespace-normal [&>span]:break-words text-left cursor-pointer",e),...n,children:[t,u.jsx(qm,{asChild:!0,children:u.jsx(hi,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));hr.displayName=Zc.displayName;const Dd=x.forwardRef(({className:e,...t},n)=>u.jsx(Jc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(Sg,{className:"h-4 w-4"})}));Dd.displayName=Jc.displayName;const Rd=x.forwardRef(({className:e,...t},n)=>u.jsx(Hc,{ref:n,className:G("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(hi,{className:"h-4 w-4"})}));Rd.displayName=Hc.displayName;const mr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(Gm,{children:u.jsxs(Vc,{ref:i,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-lg border shadow-md",n==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:n,...r,children:[u.jsx(Dd,{}),u.jsx(Ym,{className:G("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Rd,{})]})}));mr.displayName=Vc.displayName;const Md=x.forwardRef(({className:e,...t},n)=>u.jsx(Wc,{ref:n,className:G("px-2 py-1.5 text-sm font-semibold",e),...t}));Md.displayName=Wc.displayName;const Dn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Uc,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex w-full cursor-pointer items-center rounded-sm py-1.5 pr-8 pl-2 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(Km,{children:u.jsx(yn,{className:"h-4 w-4"})})}),u.jsx(Xm,{children:t})]}));Dn.displayName=Uc.displayName;const xx=x.forwardRef(({className:e,...t},n)=>u.jsx(qc,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));xx.displayName=qc.displayName;const gr=x.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:G("border-input file:text-foreground placeholder:text-muted-foreground focus-visible:ring-ring flex h-9 w-full rounded-sm border bg-background px-3 py-1 text-sm shadow-xs transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",e),ref:r,...n}));gr.displayName="Input";const yx=mi("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),sr=x.forwardRef(({className:e,...t},n)=>u.jsx(Gc,{ref:n,className:G(yx(),e),...t}));sr.displayName=Gc.displayName;const bx=mi("inline-flex items-center rounded-md border px-2.5 py-1 text-xs font-medium transition-colors focus:outline-none",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground",secondary:"border-transparent bg-secondary text-secondary-foreground",destructive:"border-transparent bg-destructive text-destructive-foreground",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Kt({className:e,variant:t,...n}){return u.jsx("div",{className:G(bx({variant:t}),e),...n})}const vx=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:o}=Ce(da(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),{toast:a}=jr(),l=x.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[c,d]=x.useState(""),[f,p]=x.useState(""),[h,g]=x.useState("playground"),[v,S]=x.useState(!1),[y,j]=x.useState(null),[m,A]=x.useState(null),[C,w]=x.useState(null),N=()=>{j(null),A(null),w(null)};x.useEffect(()=>{if(!e)return;j(null),A(null),w(null);const T=l.map(z=>z.name),I=T.includes(i)?i:T[0]??"";p(I),d(T.find(z=>z!==I)??"")},[e]);const J=async()=>{const T=l.find(z=>z.name===c),I=l.find(z=>z.name===f);if(!(!T||!I)){S(!0),j(null),A(null),w(null);try{const z=await fetch(Ji.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:T.text,newDefinition:I.text,options:{author:h||"playground"}})}),O=await z.json();if(!z.ok||!O.success){const R=Array.isArray(O.errors)?`: ${O.errors.slice(0,3).map(Y=>Y.message||String(Y)).join("; ")}`:"";throw new Error((O.error||`Diff failed (${z.status})`)+R)}A(O.data.summary),w(O.data.document)}catch(z){j(z instanceof Error?z.message:"Diff failed")}finally{S(!1)}}},D=()=>{if(!C)return;const T=new Set(n.map(O=>O.name));let I=`${f}-redline`,z=2;for(;T.has(I);)I=`${f}-redline-${z++}`;s(I,JSON.stringify(C,null,2)),o(I),a({title:`Redline created: ${I}`}),t(!1)},_=m?m.tracked.modified+m.tracked.inserted+m.tracked.deleted:0;return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"sm:max-w-[560px]",children:[u.jsxs(Ut,{children:[u.jsxs(Jt,{className:"flex items-center gap-2",children:[u.jsx(Sd,{className:"size-4"}),"Compare documents"]}),u.jsx(an,{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(sr,{htmlFor:"diff-base",children:"Base (old)"}),u.jsxs(ei,{value:c,onValueChange:T=>{d(T),N()},children:[u.jsx(hr,{id:"diff-base",children:u.jsx(ti,{placeholder:"Select document"})}),u.jsx(mr,{children:l.map(T=>u.jsx(Dn,{value:T.name,children:T.name},T.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(ei,{value:f,onValueChange:T=>{p(T),N()},children:[u.jsx(hr,{id:"diff-revised",children:u.jsx(ti,{placeholder:"Select document"})}),u.jsx(mr,{children:l.map(T=>u.jsx(Dn,{value:T.name,children:T.name},T.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(gr,{id:"diff-author",value:h,onChange:T=>{g(T.target.value),N()},placeholder:"playground"})]}),y&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:y}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Kt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),_===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((T,I)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},I))]}),m.notes.map((T,I)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},I))]})]}),u.jsx(bn,{children:m&&_+m.untracked.length>0?u.jsxs(_e,{onClick:D,children:[u.jsx(_g,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(_e,{onClick:J,disabled:v||!c||!f||c===f,children:[v&&u.jsx(sn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var gi=e=>e.type==="checkbox",In=e=>e instanceof Date,pt=e=>e==null;const $d=e=>typeof e=="object";var et=e=>!pt(e)&&!Array.isArray(e)&&$d(e)&&!In(e),Fd=e=>et(e)&&e.target?gi(e.target)?e.target.checked:e.target.value:e,wx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Ld=(e,t)=>e.has(wx(t)),kx=e=>{const t=e.constructor&&e.constructor.prototype;return et(t)&&t.hasOwnProperty("isPrototypeOf")},fa=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function yt(e){let t;const n=Array.isArray(e),r=typeof FileList<"u"?e instanceof FileList:!1;if(e instanceof Date)t=new Date(e);else if(e instanceof Set)t=new Set(e);else if(!(fa&&(e instanceof Blob||r))&&(n||et(e)))if(t=n?[]:{},!n&&!kx(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=yt(e[i]));else return e;return t}var ks=e=>Array.isArray(e)?e.filter(Boolean):[],Qe=e=>e===void 0,le=(e,t,n)=>{if(!t||!et(e))return n;const r=ks(t.split(/[,[\].]+?/)).reduce((i,s)=>pt(i)?i:i[s],e);return Qe(r)||r===e?Qe(e[t])?n:e[t]:r},zt=e=>typeof e=="boolean",pa=e=>/^\w*$/.test(e),Bd=e=>ks(e.replace(/["|']|\]/g,"").split(/\.|\[/)),$e=(e,t,n)=>{let r=-1;const i=pa(t)?[t]:Bd(t),s=i.length,o=s-1;for(;++r<s;){const a=i[r];let l=n;if(r!==o){const c=e[a];l=et(c)||Array.isArray(c)?c:isNaN(+i[r+1])?{}:[]}if(a==="__proto__"||a==="constructor"||a==="prototype")return;e[a]=l,e=e[a]}return e};const Hi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Lt={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},tn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Zd=je.createContext(null),Ss=()=>je.useContext(Zd),Sx=e=>{const{children:t,...n}=e;return je.createElement(Zd.Provider,{value:n},t)};var Vd=(e,t,n,r=!0)=>{const i={defaultValues:t._defaultValues};for(const s in e)Object.defineProperty(i,s,{get:()=>{const o=s;return t._proxyFormState[o]!==Lt.all&&(t._proxyFormState[o]=!r||Lt.all),n&&(n[o]=!0),e[o]}});return i},bt=e=>et(e)&&!Object.keys(e).length,Ud=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return bt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(o=>t[o]===(!r||Lt.all))},qr=e=>Array.isArray(e)?e:[e],Jd=(e,t,n)=>!e||!t||e===t||qr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function ha(e){const t=je.useRef(e);t.current=e,je.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function _x(e){const t=Ss(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[o,a]=je.useState(n._formState),l=je.useRef(!0),c=je.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=je.useRef(i);return d.current=i,ha({disabled:r,next:f=>l.current&&Jd(d.current,f.name,s)&&Ud(f,c.current,n._updateFormState)&&a({...n._formState,...f}),subject:n._subjects.state}),je.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),je.useMemo(()=>Vd(o,n,c.current,!1),[o,n])}var Yt=e=>typeof e=="string",Hd=(e,t,n,r,i)=>Yt(e)?(r&&t.watch.add(e),le(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),le(n,s))):(r&&(t.watchAll=!0),n);function jx(e){const t=Ss(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:o}=e||{},a=je.useRef(r);a.current=r,ha({disabled:s,subject:n._subjects.values,next:d=>{Jd(a.current,d.name,o)&&c(yt(Hd(a.current,n._names,d.values||n._formValues,!1,i)))}});const[l,c]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),l}function Nx(e){const t=Ss(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,o=Ld(i._names.array,n),a=jx({control:i,name:n,defaultValue:le(i._formValues,n,le(i._defaultValues,n,e.defaultValue)),exact:!0}),l=_x({control:i,name:n,exact:!0}),c=je.useRef(i.register(n,{...e.rules,value:a,...zt(e.disabled)?{disabled:e.disabled}:{}})),d=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!le(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!le(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!le(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!le(l.validatingFields,n)},error:{enumerable:!0,get:()=>le(l.errors,n)}}),[l,n]),f=je.useMemo(()=>({name:n,value:a,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:Fd(p),name:n},type:Hi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:le(i._formValues,n),name:n},type:Hi.BLUR}),ref:p=>{const h=le(i._fields,n);h&&p&&(h._f.ref={focus:()=>p.focus(),select:()=>p.select(),setCustomValidity:g=>p.setCustomValidity(g),reportValidity:()=>p.reportValidity()})}}),[n,i._formValues,r,l.disabled,a,i._fields]);return je.useEffect(()=>{const p=i._options.shouldUnregister||s,h=(g,v)=>{const S=le(i._fields,g);S&&S._f&&(S._f.mount=v)};if(h(n,!0),p){const g=yt(le(i._options.defaultValues,n));$e(i._defaultValues,n,g),Qe(le(i._formValues,n))&&$e(i._formValues,n,g)}return!o&&i.register(n),()=>{(o?p&&!i._state.action:p)?i.unregister(n):h(n,!1)}},[n,i,o,s]),je.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),je.useMemo(()=>({field:f,formState:l,fieldState:d}),[f,l,d])}const Ex=e=>e.render(Nx(e));var Cx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},sl=e=>({isOnSubmit:!e||e===Lt.onSubmit,isOnBlur:e===Lt.onBlur,isOnChange:e===Lt.onChange,isOnAll:e===Lt.all,isOnTouch:e===Lt.onTouched}),ol=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Gr=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=le(e,i);if(s){const{_f:o,...a}=s;if(o){if(o.refs&&o.refs[0]&&t(o.refs[0],i)&&!r)return!0;if(o.ref&&t(o.ref,o.name)&&!r)return!0;if(Gr(a,t))break}else if(et(a)&&Gr(a,t))break}}};var Tx=(e,t,n)=>{const r=qr(le(e,n));return $e(r,"root",t[n]),$e(e,n,r),e},ma=e=>e.type==="file",Gt=e=>typeof e=="function",Wi=e=>{if(!fa)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Fi=e=>Yt(e),ga=e=>e.type==="radio",qi=e=>e instanceof RegExp;const al={value:!1,isValid:!1},ll={value:!0,isValid:!0};var Wd=e=>{if(Array.isArray(e)){if(e.length>1){const t=e.filter(n=>n&&n.checked&&!n.disabled).map(n=>n.value);return{value:t,isValid:!!t.length}}return e[0].checked&&!e[0].disabled?e[0].attributes&&!Qe(e[0].attributes.value)?Qe(e[0].value)||e[0].value===""?ll:{value:e[0].value,isValid:!0}:ll:al}return al};const ul={isValid:!1,value:null};var qd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,ul):ul;function cl(e,t,n="validate"){if(Fi(e)||Array.isArray(e)&&e.every(Fi)||zt(e)&&!e)return{type:n,message:Fi(e)?e:"",ref:t}}var Bn=e=>et(e)&&!qi(e)?e:{value:e,message:""},dl=async(e,t,n,r,i,s)=>{const{ref:o,refs:a,required:l,maxLength:c,minLength:d,min:f,max:p,pattern:h,validate:g,name:v,valueAsNumber:S,mount:y}=e._f,j=le(n,v);if(!y||t.has(v))return{};const m=a?a[0]:o,A=I=>{i&&m.reportValidity&&(m.setCustomValidity(zt(I)?"":I||""),m.reportValidity())},C={},w=ga(o),N=gi(o),J=w||N,D=(S||ma(o))&&Qe(o.value)&&Qe(j)||Wi(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,_=Cx.bind(null,v,r,C),T=(I,z,O,R=tn.maxLength,Y=tn.minLength)=>{const H=I?z:O;C[v]={type:I?R:Y,message:H,ref:o,..._(I?R:Y,H)}};if(s?!Array.isArray(j)||!j.length:l&&(!J&&(D||pt(j))||zt(j)&&!j||N&&!Wd(a).isValid||w&&!qd(a).isValid)){const{value:I,message:z}=Fi(l)?{value:!!l,message:l}:Bn(l);if(I&&(C[v]={type:tn.required,message:z,ref:m,..._(tn.required,z)},!r))return A(z),C}if(!D&&(!pt(f)||!pt(p))){let I,z;const O=Bn(p),R=Bn(f);if(!pt(j)&&!isNaN(j)){const Y=o.valueAsNumber||j&&+j;pt(O.value)||(I=Y>O.value),pt(R.value)||(z=Y<R.value)}else{const Y=o.valueAsDate||new Date(j),H=k=>new Date(new Date().toDateString()+" "+k),$=o.type=="time",ee=o.type=="week";Yt(O.value)&&j&&(I=$?H(j)>H(O.value):ee?j>O.value:Y>new Date(O.value)),Yt(R.value)&&j&&(z=$?H(j)<H(R.value):ee?j<R.value:Y<new Date(R.value))}if((I||z)&&(T(!!I,O.message,R.message,tn.max,tn.min),!r))return A(C[v].message),C}if((c||d)&&!D&&(Yt(j)||s&&Array.isArray(j))){const I=Bn(c),z=Bn(d),O=!pt(I.value)&&j.length>+I.value,R=!pt(z.value)&&j.length<+z.value;if((O||R)&&(T(O,I.message,z.message),!r))return A(C[v].message),C}if(h&&!D&&Yt(j)){const{value:I,message:z}=Bn(h);if(qi(I)&&!j.match(I)&&(C[v]={type:tn.pattern,message:z,ref:o,..._(tn.pattern,z)},!r))return A(z),C}if(g){if(Gt(g)){const I=await g(j,n),z=cl(I,m);if(z&&(C[v]={...z,..._(tn.validate,z.message)},!r))return A(z.message),C}else if(et(g)){let I={};for(const z in g){if(!bt(I)&&!r)break;const O=cl(await g[z](j,n),m,z);O&&(I={...O,..._(z,O.message)},A(O.message),r&&(C[v]=I))}if(!bt(I)&&(C[v]={ref:m,...I},!r))return C}}return A(!0),C};function Ix(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=Qe(e)?r++:e[t[r++]];return e}function Ax(e){for(const t in e)if(e.hasOwnProperty(t)&&!Qe(e[t]))return!1;return!0}function it(e,t){const n=Array.isArray(t)?t:pa(t)?[t]:Bd(t),r=n.length===1?e:Ix(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(et(r)&&bt(r)||Array.isArray(r)&&Ax(r))&&it(e,n.slice(0,-1)),e}var Vs=()=>{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=[]}}},Io=e=>pt(e)||!$d(e);function hn(e,t){if(Io(e)||Io(t))return e===t;if(In(e)&&In(t))return e.getTime()===t.getTime();const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n){const s=e[i];if(!r.includes(i))return!1;if(i!=="ref"){const o=t[i];if(In(s)&&In(o)||et(s)&&et(o)||Array.isArray(s)&&Array.isArray(o)?!hn(s,o):s!==o)return!1}}return!0}var Gd=e=>e.type==="select-multiple",zx=e=>ga(e)||gi(e),Us=e=>Wi(e)&&e.isConnected,Yd=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Gi(e,t={}){const n=Array.isArray(e);if(et(e)||n)for(const r in e)Array.isArray(e[r])||et(e[r])&&!Yd(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Gi(e[r],t[r])):pt(e[r])||(t[r]=!0);return t}function Kd(e,t,n){const r=Array.isArray(e);if(et(e)||r)for(const i in e)Array.isArray(e[i])||et(e[i])&&!Yd(e[i])?Qe(t)||Io(n[i])?n[i]=Array.isArray(e[i])?Gi(e[i],[]):{...Gi(e[i])}:Kd(e[i],pt(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Ar=(e,t)=>Kd(e,t,Gi(t)),Xd=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>Qe(e)?e:t?e===""?NaN:e&&+e:n&&Yt(e)?new Date(e):r?r(e):e;function Js(e){const t=e.ref;return ma(t)?t.files:ga(t)?qd(e.refs).value:Gd(t)?[...t.selectedOptions].map(({value:n})=>n):gi(t)?Wd(e.refs).value:Xd(Qe(t.value)?e.ref.value:t.value,e)}var Ox=(e,t,n,r)=>{const i={};for(const s of e){const o=le(t,s);o&&$e(i,s,o._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},zr=e=>Qe(e)?e:qi(e)?e.source:et(e)?qi(e.value)?e.value.source:e.value:e;const fl="AsyncFunction";var Px=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===fl||et(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===fl)),Dx=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function pl(e,t,n){const r=le(e,n);if(r||pa(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),o=le(t,s),a=le(e,s);if(o&&!Array.isArray(o)&&n!==s)return{name:n};if(a&&a.type)return{name:s,error:a};i.pop()}return{name:n}}var Rx=(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,Mx=(e,t)=>!ks(le(e,t)).length&&it(e,t);const $x={mode:Lt.onSubmit,reValidateMode:Lt.onChange,shouldFocusError:!0};function Fx(e={}){let t={...$x,...e},n={submitCount:0,isDirty:!1,isLoading:Gt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=et(t.defaultValues)||et(t.values)?yt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:yt(i),o={action:!1,mount:!1,watch:!1},a={mount:new Set,disabled:new Set,unMount:new Set,array:new Set,watch:new Set},l,c=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:Vs(),array:Vs(),state:Vs()},p=sl(t.mode),h=sl(t.reValidateMode),g=t.criteriaMode===Lt.all,v=E=>M=>{clearTimeout(c),c=setTimeout(E,M)},S=async E=>{if(!t.disabled&&(d.isValid||E)){const M=t.resolver?bt((await J()).errors):await _(r,!0);M!==n.isValid&&f.state.next({isValid:M})}},y=(E,M)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((E||Array.from(a.mount)).forEach(F=>{F&&(M?$e(n.validatingFields,F,M):it(n.validatingFields,F))}),f.state.next({validatingFields:n.validatingFields,isValidating:!bt(n.validatingFields)}))},j=(E,M=[],F,ne,Q=!0,te=!0)=>{if(ne&&F&&!t.disabled){if(o.action=!0,te&&Array.isArray(le(r,E))){const de=F(le(r,E),ne.argA,ne.argB);Q&&$e(r,E,de)}if(te&&Array.isArray(le(n.errors,E))){const de=F(le(n.errors,E),ne.argA,ne.argB);Q&&$e(n.errors,E,de),Mx(n.errors,E)}if(d.touchedFields&&te&&Array.isArray(le(n.touchedFields,E))){const de=F(le(n.touchedFields,E),ne.argA,ne.argB);Q&&$e(n.touchedFields,E,de)}d.dirtyFields&&(n.dirtyFields=Ar(i,s)),f.state.next({name:E,isDirty:I(E,M),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else $e(s,E,M)},m=(E,M)=>{$e(n.errors,E,M),f.state.next({errors:n.errors})},A=E=>{n.errors=E,f.state.next({errors:n.errors,isValid:!1})},C=(E,M,F,ne)=>{const Q=le(r,E);if(Q){const te=le(s,E,Qe(F)?le(i,E):F);Qe(te)||ne&&ne.defaultChecked||M?$e(s,E,M?te:Js(Q._f)):R(E,te),o.mount&&S()}},w=(E,M,F,ne,Q)=>{let te=!1,de=!1;const ve={name:E};if(!t.disabled){const Z=!!(le(r,E)&&le(r,E)._f&&le(r,E)._f.disabled);if(!F||ne){d.isDirty&&(de=n.isDirty,n.isDirty=ve.isDirty=I(),te=de!==ve.isDirty);const K=Z||hn(le(i,E),M);de=!!(!Z&&le(n.dirtyFields,E)),K||Z?it(n.dirtyFields,E):$e(n.dirtyFields,E,!0),ve.dirtyFields=n.dirtyFields,te=te||d.dirtyFields&&de!==!K}if(F){const K=le(n.touchedFields,E);K||($e(n.touchedFields,E,F),ve.touchedFields=n.touchedFields,te=te||d.touchedFields&&K!==F)}te&&Q&&f.state.next(ve)}return te?ve:{}},N=(E,M,F,ne)=>{const Q=le(n.errors,E),te=d.isValid&&zt(M)&&n.isValid!==M;if(t.delayError&&F?(l=v(()=>m(E,F)),l(t.delayError)):(clearTimeout(c),l=null,F?$e(n.errors,E,F):it(n.errors,E)),(F?!hn(Q,F):Q)||!bt(ne)||te){const de={...ne,...te&&zt(M)?{isValid:M}:{},errors:n.errors,name:E};n={...n,...de},f.state.next(de)}},J=async E=>{y(E,!0);const M=await t.resolver(s,t.context,Ox(E||a.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return y(E),M},D=async E=>{const{errors:M}=await J(E);if(E)for(const F of E){const ne=le(M,F);ne?$e(n.errors,F,ne):it(n.errors,F)}else n.errors=M;return M},_=async(E,M,F={valid:!0})=>{for(const ne in E){const Q=E[ne];if(Q){const{_f:te,...de}=Q;if(te){const ve=a.array.has(te.name),Z=Q._f&&Px(Q._f);Z&&d.validatingFields&&y([ne],!0);const K=await dl(Q,a.disabled,s,g,t.shouldUseNativeValidation&&!M,ve);if(Z&&d.validatingFields&&y([ne]),K[te.name]&&(F.valid=!1,M))break;!M&&(le(K,te.name)?ve?Tx(n.errors,K,te.name):$e(n.errors,te.name,K[te.name]):it(n.errors,te.name))}!bt(de)&&await _(de,M,F)}}return F.valid},T=()=>{for(const E of a.unMount){const M=le(r,E);M&&(M._f.refs?M._f.refs.every(F=>!Us(F)):!Us(M._f.ref))&&re(E)}a.unMount=new Set},I=(E,M)=>!t.disabled&&(E&&M&&$e(s,E,M),!hn(oe(),i)),z=(E,M,F)=>Hd(E,a,{...o.mount?s:Qe(M)?i:Yt(E)?{[E]:M}:M},F,M),O=E=>ks(le(o.mount?s:i,E,t.shouldUnregister?le(i,E,[]):[])),R=(E,M,F={})=>{const ne=le(r,E);let Q=M;if(ne){const te=ne._f;te&&(!te.disabled&&$e(s,E,Xd(M,te)),Q=Wi(te.ref)&&pt(M)?"":M,Gd(te.ref)?[...te.ref.options].forEach(de=>de.selected=Q.includes(de.value)):te.refs?gi(te.ref)?te.refs.length>1?te.refs.forEach(de=>(!de.defaultChecked||!de.disabled)&&(de.checked=Array.isArray(Q)?!!Q.find(ve=>ve===de.value):Q===de.value)):te.refs[0]&&(te.refs[0].checked=!!Q):te.refs.forEach(de=>de.checked=de.value===Q):ma(te.ref)?te.ref.value="":(te.ref.value=Q,te.ref.type||f.values.next({name:E,values:{...s}})))}(F.shouldDirty||F.shouldTouch)&&w(E,Q,F.shouldTouch,F.shouldDirty,!0),F.shouldValidate&&k(E)},Y=(E,M,F)=>{for(const ne in M){const Q=M[ne],te=`${E}.${ne}`,de=le(r,te);(a.array.has(E)||et(Q)||de&&!de._f)&&!In(Q)?Y(te,Q,F):R(te,Q,F)}},H=(E,M,F={})=>{const ne=le(r,E),Q=a.array.has(E),te=yt(M);$e(s,E,te),Q?(f.array.next({name:E,values:{...s}}),(d.isDirty||d.dirtyFields)&&F.shouldDirty&&f.state.next({name:E,dirtyFields:Ar(i,s),isDirty:I(E,te)})):ne&&!ne._f&&!pt(te)?Y(E,te,F):R(E,te,F),ol(E,a)&&f.state.next({...n}),f.values.next({name:o.mount?E:void 0,values:{...s}})},$=async E=>{o.mount=!0;const M=E.target;let F=M.name,ne=!0;const Q=le(r,F),te=()=>M.type?Js(Q._f):Fd(E),de=ve=>{ne=Number.isNaN(ve)||In(ve)&&isNaN(ve.getTime())||hn(ve,le(s,F,ve))};if(Q){let ve,Z;const K=te(),ge=E.type===Hi.BLUR||E.type===Hi.FOCUS_OUT,Ne=!Dx(Q._f)&&!t.resolver&&!le(n.errors,F)&&!Q._f.deps||Rx(ge,le(n.touchedFields,F),n.isSubmitted,h,p),L=ol(F,a,ge);$e(s,F,K),ge?(Q._f.onBlur&&Q._f.onBlur(E),l&&l(0)):Q._f.onChange&&Q._f.onChange(E);const xe=w(F,K,ge,!1),ze=!bt(xe)||L;if(!ge&&f.values.next({name:F,type:E.type,values:{...s}}),Ne)return d.isValid&&(t.mode==="onBlur"&&ge?S():ge||S()),ze&&f.state.next({name:F,...L?{}:xe});if(!ge&&L&&f.state.next({...n}),t.resolver){const{errors:Be}=await J([F]);if(de(K),ne){const rt=pl(n.errors,r,F),tt=pl(Be,r,rt.name||F);ve=tt.error,F=tt.name,Z=bt(Be)}}else y([F],!0),ve=(await dl(Q,a.disabled,s,g,t.shouldUseNativeValidation))[F],y([F]),de(K),ne&&(ve?Z=!1:d.isValid&&(Z=await _(r,!0)));ne&&(Q._f.deps&&k(Q._f.deps),N(F,Z,ve,xe))}},ee=(E,M)=>{if(le(n.errors,M)&&E.focus)return E.focus(),1},k=async(E,M={})=>{let F,ne;const Q=qr(E);if(t.resolver){const te=await D(Qe(E)?E:Q);F=bt(te),ne=E?!Q.some(de=>le(te,de)):F}else E?(ne=(await Promise.all(Q.map(async te=>{const de=le(r,te);return await _(de&&de._f?{[te]:de}:de)}))).every(Boolean),!(!ne&&!n.isValid)&&S()):ne=F=await _(r);return f.state.next({...!Yt(E)||d.isValid&&F!==n.isValid?{}:{name:E},...t.resolver||!E?{isValid:F}:{},errors:n.errors}),M.shouldFocus&&!ne&&Gr(r,ee,E?Q:a.mount),ne},oe=E=>{const M={...o.mount?s:i};return Qe(E)?M:Yt(E)?le(M,E):E.map(F=>le(M,F))},q=(E,M)=>({invalid:!!le((M||n).errors,E),isDirty:!!le((M||n).dirtyFields,E),error:le((M||n).errors,E),isValidating:!!le(n.validatingFields,E),isTouched:!!le((M||n).touchedFields,E)}),b=E=>{E&&qr(E).forEach(M=>it(n.errors,M)),f.state.next({errors:E?n.errors:{}})},B=(E,M,F)=>{const ne=(le(r,E,{_f:{}})._f||{}).ref,Q=le(n.errors,E)||{},{ref:te,message:de,type:ve,...Z}=Q;$e(n.errors,E,{...Z,...M,ref:ne}),f.state.next({name:E,errors:n.errors,isValid:!1}),F&&F.shouldFocus&&ne&&ne.focus&&ne.focus()},V=(E,M)=>Gt(E)?f.values.subscribe({next:F=>E(z(void 0,M),F)}):z(E,M,!0),re=(E,M={})=>{for(const F of E?qr(E):a.mount)a.mount.delete(F),a.array.delete(F),M.keepValue||(it(r,F),it(s,F)),!M.keepError&&it(n.errors,F),!M.keepDirty&&it(n.dirtyFields,F),!M.keepTouched&&it(n.touchedFields,F),!M.keepIsValidating&&it(n.validatingFields,F),!t.shouldUnregister&&!M.keepDefaultValue&&it(i,F);f.values.next({values:{...s}}),f.state.next({...n,...M.keepDirty?{isDirty:I()}:{}}),!M.keepIsValid&&S()},se=({disabled:E,name:M,field:F,fields:ne})=>{(zt(E)&&o.mount||E||a.disabled.has(M))&&(E?a.disabled.add(M):a.disabled.delete(M),w(M,Js(F?F._f:le(ne,M)._f),!1,!1,!0))},P=(E,M={})=>{let F=le(r,E);const ne=zt(M.disabled)||zt(t.disabled);return $e(r,E,{...F||{},_f:{...F&&F._f?F._f:{ref:{name:E}},name:E,mount:!0,...M}}),a.mount.add(E),F?se({field:F,disabled:zt(M.disabled)?M.disabled:t.disabled,name:E}):C(E,!0,M.value),{...ne?{disabled:M.disabled||t.disabled}:{},...t.progressive?{required:!!M.required,min:zr(M.min),max:zr(M.max),minLength:zr(M.minLength),maxLength:zr(M.maxLength),pattern:zr(M.pattern)}:{},name:E,onChange:$,onBlur:$,ref:Q=>{if(Q){P(E,M),F=le(r,E);const te=Qe(Q.value)&&Q.querySelectorAll&&Q.querySelectorAll("input,select,textarea")[0]||Q,de=zx(te),ve=F._f.refs||[];if(de?ve.find(Z=>Z===te):te===F._f.ref)return;$e(r,E,{_f:{...F._f,...de?{refs:[...ve.filter(Us),te,...Array.isArray(le(i,E))?[{}]:[]],ref:{type:te.type,name:E}}:{ref:te}}}),C(E,!1,void 0,te)}else F=le(r,E,{}),F._f&&(F._f.mount=!1),(t.shouldUnregister||M.shouldUnregister)&&!(Ld(a.array,E)&&o.action)&&a.unMount.add(E)}}},ue=()=>t.shouldFocusError&&Gr(r,ee,a.mount),he=E=>{zt(E)&&(f.state.next({disabled:E}),Gr(r,(M,F)=>{const ne=le(r,F);ne&&(M.disabled=ne._f.disabled||E,Array.isArray(ne._f.refs)&&ne._f.refs.forEach(Q=>{Q.disabled=ne._f.disabled||E}))},0,!1))},ce=(E,M)=>async F=>{let ne;F&&(F.preventDefault&&F.preventDefault(),F.persist&&F.persist());let Q=yt(s);if(a.disabled.size)for(const te of a.disabled)$e(Q,te,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:te,values:de}=await J();n.errors=te,Q=de}else await _(r);if(it(n.errors,"root"),bt(n.errors)){f.state.next({errors:{}});try{await E(Q,F)}catch(te){ne=te}}else M&&await M({...n.errors},F),ue(),setTimeout(ue);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:bt(n.errors)&&!ne,submitCount:n.submitCount+1,errors:n.errors}),ne)throw ne},pe=(E,M={})=>{le(r,E)&&(Qe(M.defaultValue)?H(E,yt(le(i,E))):(H(E,M.defaultValue),$e(i,E,yt(M.defaultValue))),M.keepTouched||it(n.touchedFields,E),M.keepDirty||(it(n.dirtyFields,E),n.isDirty=M.defaultValue?I(E,yt(le(i,E))):I()),M.keepError||(it(n.errors,E),d.isValid&&S()),f.state.next({...n}))},me=(E,M={})=>{const F=E?yt(E):i,ne=yt(F),Q=bt(E),te=Q?i:ne;if(M.keepDefaultValues||(i=F),!M.keepValues){if(M.keepDirtyValues){const de=new Set([...a.mount,...Object.keys(Ar(i,s))]);for(const ve of Array.from(de))le(n.dirtyFields,ve)?$e(te,ve,le(s,ve)):H(ve,le(te,ve))}else{if(fa&&Qe(E))for(const de of a.mount){const ve=le(r,de);if(ve&&ve._f){const Z=Array.isArray(ve._f.refs)?ve._f.refs[0]:ve._f.ref;if(Wi(Z)){const K=Z.closest("form");if(K){K.reset();break}}}}r={}}s=t.shouldUnregister?M.keepDefaultValues?yt(i):{}:yt(te),f.array.next({values:{...te}}),f.values.next({values:{...te}})}a={mount:M.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!d.isValid||!!M.keepIsValid||!!M.keepDirtyValues,o.watch=!!t.shouldUnregister,f.state.next({submitCount:M.keepSubmitCount?n.submitCount:0,isDirty:Q?!1:M.keepDirty?n.isDirty:!!(M.keepDefaultValues&&!hn(E,i)),isSubmitted:M.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:Q?{}:M.keepDirtyValues?M.keepDefaultValues&&s?Ar(i,s):n.dirtyFields:M.keepDefaultValues&&E?Ar(i,E):M.keepDirty?n.dirtyFields:{},touchedFields:M.keepTouched?n.touchedFields:{},errors:M.keepErrors?n.errors:{},isSubmitSuccessful:M.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},U=(E,M)=>me(Gt(E)?E(s):E,M);return{control:{register:P,unregister:re,getFieldState:q,handleSubmit:ce,setError:B,_executeSchema:J,_getWatch:z,_getDirty:I,_updateValid:S,_removeUnmounted:T,_updateFieldArray:j,_updateDisabledField:se,_getFieldArray:O,_reset:me,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(E=>{U(E,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:E=>{n={...n,...E}},_disableForm:he,_subjects:f,_proxyFormState:d,_setErrors:A,get _fields(){return r},get _formValues(){return s},get _state(){return o},set _state(E){o=E},get _defaultValues(){return i},get _names(){return a},set _names(E){a=E},get _formState(){return n},set _formState(E){n=E},get _options(){return t},set _options(E){t={...t,...E}}},trigger:k,register:P,handleSubmit:ce,watch:V,setValue:H,getValues:oe,reset:U,resetField:pe,clearErrors:b,unregister:re,setError:B,setFocus:(E,M={})=>{const F=le(r,E),ne=F&&F._f;if(ne){const Q=ne.refs?ne.refs[0]:ne.ref;Q.focus&&(Q.focus(),M.shouldSelect&&Gt(Q.select)&&Q.select())}},getFieldState:q}}function Lx(e={}){const t=je.useRef(void 0),n=je.useRef(void 0),[r,i]=je.useState({isDirty:!1,isValidating:!1,isLoading:Gt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Gt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Fx(e),formState:r});const s=t.current.control;return s._options=e,ha({subject:s._subjects.state,next:o=>{Ud(o,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),je.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),je.useEffect(()=>{if(s._proxyFormState.isDirty){const o=s._getDirty();o!==r.isDirty&&s._subjects.state.next({isDirty:o})}},[s,r.isDirty]),je.useEffect(()=>{e.values&&!hn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(o=>({...o}))):s._resetDefaultValues()},[e.values,s]),je.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),je.useEffect(()=>{s._state.mount||(s._updateValid(),s._state.mount=!0),s._state.watch&&(s._state.watch=!1,s._subjects.state.next({...s._formState})),s._removeUnmounted()}),je.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=Vd(r,s),t.current}function Bx(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 Zx=Sx,Qd=x.createContext({}),hl=({...e})=>u.jsx(Qd.Provider,{value:{name:e.name},children:u.jsx(Ex,{...e})}),_s=()=>{const e=x.useContext(Qd),t=x.useContext(ef),{getFieldState:n,formState:r}=Ss(),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}},ef=x.createContext({}),Ao=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(ef.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:G("space-y-2",e),...t})})});Ao.displayName="FormItem";const zo=x.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=_s();return u.jsx(sr,{ref:n,className:G(r&&"text-destructive",e),htmlFor:i,...t})});zo.displayName="FormLabel";const Oo=x.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=_s();return u.jsx(_r,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Oo.displayName="FormControl";const tf=x.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=_s();return u.jsx("p",{ref:n,id:r,className:G("text-muted-foreground text-[0.8rem]",e),...t})});tf.displayName="FormDescription";const Po=x.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=_s(),o=i?String(i==null?void 0:i.message):t;return o?u.jsx("p",{ref:r,id:s,className:G("text-destructive text-[0.8rem] font-medium",e),...n,children:o}):null});Po.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 nf=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Vx=(e=nf())=>ux()(cx(dx((t,n)=>({...e,toggleChat:()=>t(r=>({chatOpen:!r.chatOpen})),openChat:()=>t({chatOpen:!0}),closeChat:()=>t({chatOpen:!1}),addContext:r=>t(i=>({contextAttachments:[...i.contextAttachments,r]})),removeContext:r=>t(i=>({contextAttachments:i.contextAttachments.filter((s,o)=>o!==r)})),clearContext:()=>t({contextAttachments:[]}),setScope:r=>t({scope:r}),setModel:r=>t({model:r}),createThread:r=>{const i=crypto.randomUUID(),s=Date.now(),o={id:i,documentName:r,title:xa(),messages:[],createdAt:s,updatedAt:s};return t(a=>({threads:{...a.threads,[i]:o},activeThreadId:{...a.activeThreadId,[r]:i}})),i},deleteThread:r=>{const i=n(),s=i.threads[r];if(!s)return;const o=Object.fromEntries(Object.entries(i.threads).filter(([c])=>c!==r)),a=s.documentName,l={...i.activeThreadId};if(l[a]===r){const c=Object.values(o).filter(d=>d.documentName===a);c.length>0?(c.sort((d,f)=>f.updatedAt-d.updatedAt),l[a]=c[0].id):delete l[a]}t({threads:o,activeThreadId:l})},switchThread:r=>{const s=n().threads[r];s&&t(o=>({activeThreadId:{...o.activeThreadId,[s.documentName]:r}}))},updateThreadMessages:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,messages:i,updatedAt:Date.now()}}}:s})},updateThreadTitle:(r,i)=>{t(s=>{const o=s.threads[r];return o?{threads:{...s.threads,[r]:{...o,title:i}}}:s})},deleteThreadsForDocument:r=>{t(i=>{const s={...i.threads},o={...i.activeThreadId};for(const[a,l]of Object.entries(s))l.documentName===r&&delete s[a];return delete o[r],{threads:s,activeThreadId:o}})},renameThreadsForDocument:(r,i)=>{t(s=>{const o={...s.threads},a={...s.activeThreadId};for(const[l,c]of Object.entries(o))c.documentName===r&&(o[l]={...c,documentName:i});return r in a&&(a[i]=a[r],delete a[r]),{threads:o,activeThreadId:a}})},clearChat:()=>{t(r=>({contextAttachments:[]}))}}),{name:"chat-storage",version:1,storage:fx(()=>nx),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}}))),rf=x.createContext(void 0),Ux=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Vx(nf())),u.jsx(rf.Provider,{value:t.current,children:e})},Re=e=>{const t=x.useContext(rf);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return px(t,e)};function Jx(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Hx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=Si.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=Si.Optional(Si.String({description:"Template selection"})));const s=Si.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:o=>{const a=[];if(!gg(s,o))for(const c of xg(s,o))a.push({path:c.path.replace(/^\//,""),message:c.message});const l=o;if(e!=="delete"&&l.name){const c=l.name.trim();c?(l.name=c,t(c)||a.push({path:"name",message:"Document with this name already exists"})):a.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)||a.push({path:"template",message:"You must select a valid template"})),{success:a.length===0,data:a.length===0?l:void 0,errors:a}}}}function Wx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const qx=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"}}),Zn="__empty__";function Gx({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,isTheme:o}){const[a,l]=x.useState(!1),[c,d]=x.useState(null),[f,p]=x.useState("idle"),{toast:h}=jr(),g=qx(o),{documents:v,openTabs:S,createDocument:y,renameDocument:j,deleteDocument:m,openDocument:A,closeDocument:C}=Ce(oe=>oe),{updateTheme:w,removeTheme:N}=To(oe=>oe),J=Re(oe=>oe.renameThreadsForDocument),D=Re(oe=>oe.deleteThreadsForDocument),_=x.useMemo(()=>o?s||[]:i||[],[o,i,s]),T=x.useMemo(()=>{const oe={current:[],downstream:[]};return _.forEach(q=>{oe[q.location]&&oe[q.location].push(q)}),oe},[_]),I=x.useMemo(()=>_.map(oe=>({name:oe.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[_]),z=x.useMemo(()=>Hx(e,oe=>Jx(oe,v,r),I),[e,v,r,I]),O=z.schema,R=x.useMemo(()=>{const oe=new Map;return _.forEach(q=>oe.set(q.path,q)),oe},[_]),Y=Zn,H=Lx({resolver:Bx(z.validate),defaultValues:Wx(e,void 0,r)}),[$,ee]=x.useState(Y);x.useEffect(()=>{if($&&$!==Zn&&e==="create"){const oe=R.get($);if(oe){d(null),p("loading");let q=!1;return fetch(`/api/discovery/${o?"themes":"documents"}/${encodeURIComponent(oe.name)}/content`).then(b=>{if(!b.ok)throw new Error(`Failed to fetch content: ${b.statusText}`);return b.text()}).then(b=>{if(q)return;const B=JSON.parse(b);d(JSON.stringify(B,null,2)),p("idle")}).catch(b=>{q||(console.error("Failed to copy template:",b),d(null),p("error"))}),()=>{q=!0}}}p("idle")},[$,e,R,o]),x.useEffect(()=>{t&&(H.reset(),d(null),p("idle"),ee(Y))},[H,t]);const k=H.handleSubmit(async({name:oe,template:q})=>{l(!0);try{if(await new Promise(b=>setTimeout(b,200)),e==="create"){const b=$?R.get($):_.find(pe=>pe.name===q);let B,V=oe;if(!!$&&$!==Zn&&c===null){h({title:f==="loading"?"Template still loading":`Could not copy ${(b==null?void 0:b.name)??"the selected template"}`,description:f==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(o){const pe=V.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),me=ot==="docx"?yg(pe):{name:pe,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};B=c||JSON.stringify(me,null,2);const U=`.${ot}.theme.json`;V.endsWith(U)||(V=V.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),V+=U)}else{const pe=b;B=c||JSON.stringify(ot==="docx"?{name:"docx",props:{theme:(pe==null?void 0:pe.theme)||"default",metadata:{title:(pe==null?void 0:pe.title)||V.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(pe==null?void 0:pe.title)||V.replace(/\.(json|js)$/i,""),theme:(pe==null?void 0:pe.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 me=ot==="docx"?".docx.json":".pptx.json";!V.endsWith(me)&&!V.endsWith(".json")&&(V+=me)}const se=V.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),P=se?se[0]:"",ue=V.slice(0,V.length-P.length);let he=V,ce=1;for(;v.some(pe=>pe.name===he);)ce++,he=`${ue} (${ce})${P}`;V=he,y(V,B),A(V),o&&w(V,B)}else if(e==="update"){const b=r,B=oe,V=S.includes(b);V&&C(b),j(b,B),J(b,B),V&&A(B)}else if(e==="delete"){const b=r;C(b),m(b),D(b),o&&N(b)}n()}finally{l(!1)}});return u.jsx(Zx,{...H,children:u.jsxs("form",{onSubmit:k,children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:g[e].title}),u.jsx(an,{children:g[e].description})]}),u.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[O.properties&&"name"in O.properties&&u.jsx(hl,{control:H.control,name:"name",render:({field:oe})=>u.jsxs(Ao,{children:[u.jsx(zo,{children:"Name"}),u.jsx(Oo,{children:u.jsx(gr,{placeholder:"Enter a name or select a template below",autoComplete:"off",...oe})}),u.jsx(Po,{})]})}),e==="create"&&u.jsx(hl,{control:H.control,name:"template",render:({field:oe})=>u.jsxs(Ao,{children:[u.jsx(zo,{children:o?"Base Theme":"Base Document"}),u.jsxs(ei,{onValueChange:q=>{if(q===Zn)oe.onChange(void 0),H.setValue("name",""),ee(Zn),d(null);else{const b=R.get(q);b&&(oe.onChange(b.name),H.setValue("name",b.name),ee(q))}},defaultValue:Y,children:[u.jsx(Oo,{children:u.jsx(hr,{children:u.jsx(ti,{placeholder:`Select a discovered ${o?"theme":"document"}`})})}),u.jsxs(mr,{className:"max-h-[300px]",children:[u.jsxs(Dn,{value:Zn,children:["Empty ",o?"theme":"document"]}),Object.entries(T).map(([q,b])=>b.length===0?null:u.jsxs(gx,{children:[u.jsx(Md,{children:q==="current"?"📁 Current Directory":"📦 Project"}),b.map(B=>{let V;return B.title&&B.title!==B.name?V=B.title:B.description&&(V=B.description.length>40?B.description.substring(0,40)+"...":B.description),u.jsx(Dn,{value:B.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:B.name}),V&&u.jsx("span",{className:"text-muted-foreground text-xs",children:V})]})},B.path)})]},q))]})]}),u.jsxs(tf,{children:["Start empty or select a discovered"," ",o?"theme":"document"," as a starting point"]}),u.jsx(Po,{})]})})]}),u.jsx(bn,{children:u.jsx(_e,{type:"submit",variant:g[e].buttonVariant,disabled:a,children:a?u.jsxs(u.Fragment,{children:[u.jsx(sn,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):g[e].button})})]})})}const Yi=je.memo(Gx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function ya({text:e,query:t}){if(!t)return u.jsx(u.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?u.jsx(u.Fragment,{children:e}):u.jsxs(u.Fragment,{children:[e.slice(0,n),u.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Do({children:e,count:t,actions:n,className:r}){return u.jsxs("div",{className:G("flex h-6 shrink-0 items-center gap-1.5 px-1 select-none",r),children:[u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] text-sidebar-foreground/70 uppercase",children:e}),t!==void 0&&u.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t}),n&&u.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:n})]})}const $t=je.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:G("flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-sm","text-sidebar-foreground/55 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","disabled:pointer-events-none disabled:opacity-40","[&>svg]:size-3.5",e),...t}));$t.displayName="RailIconButton";function ml({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:G("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function gl({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:G("flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(e,{className:"size-3.5 shrink-0"}),u.jsx("span",{className:"truncate",children:t})]}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const Yx=eg,Kx=tg,Xx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(Qc,{ref:i,className:G("focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none",t&&"pl-8",e),...r,children:[n,u.jsx(Pn,{className:"ml-auto h-4 w-4"})]}));Xx.displayName=Qc.displayName;const Qx=x.forwardRef(({className:e,...t},n)=>u.jsx(ed,{ref:n,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));Qx.displayName=ed.displayName;const sf=x.forwardRef(({className:e,...t},n)=>u.jsx(ng,{children:u.jsx(Yc,{ref:n,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md",e),...t})}));sf.displayName=Yc.displayName;const of=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Xc,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm px-2 py-1.5 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));of.displayName=Xc.displayName;const ey=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(td,{ref:i,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(nd,{children:u.jsx(yn,{className:"h-4 w-4"})})}),t]}));ey.displayName=td.displayName;const ty=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(rd,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(nd,{children:u.jsx(_d,{className:"h-4 w-4 fill-current"})})}),t]}));ty.displayName=rd.displayName;const ny=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(id,{ref:r,className:G("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));ny.displayName=id.displayName;const af=x.forwardRef(({className:e,...t},n)=>u.jsx(Kc,{ref:n,className:G("bg-border -mx-1 my-1 h-px",e),...t}));af.displayName=Kc.displayName;const lf=({className:e,...t})=>u.jsx("span",{className:G("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});lf.displayName="ContextMenuShortcut";const js=rg,Ns=ig,ry=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(ud,{ref:i,className:G("focus:bg-accent data-[state=open]:bg-accent flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none select-none [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t&&"pl-8",e),...r,children:[n,u.jsx(Pn,{className:"ml-auto"})]}));ry.displayName=ud.displayName;const iy=x.forwardRef(({className:e,...t},n)=>u.jsx(cd,{ref:n,className:G("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));iy.displayName=cd.displayName;const xi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(sg,{children:u.jsx(sd,{ref:r,sideOffset:t,className:G("bg-popover text-popover-foreground z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...n})}));xi.displayName=sd.displayName;const Ft=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(od,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",e),...n}));Ft.displayName=od.displayName;const sy=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(dd,{ref:i,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(fd,{children:u.jsx(yn,{className:"h-4 w-4"})})}),t]}));sy.displayName=dd.displayName;const oy=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(pd,{ref:r,className:G("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center rounded-sm py-1.5 pr-2 pl-8 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[u.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:u.jsx(fd,{children:u.jsx(_d,{className:"h-2 w-2 fill-current"})})}),t]}));oy.displayName=pd.displayName;const uf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ld,{ref:r,className:G("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));uf.displayName=ld.displayName;const xr=x.forwardRef(({className:e,...t},n)=>u.jsx(ad,{ref:n,className:G("bg-muted -mx-1 my-1 h-px",e),...t}));xr.displayName=ad.displayName;const cf=({className:e,...t})=>u.jsx("span",{className:G("ml-auto text-xs tracking-widest opacity-60",e),...t});cf.displayName="DropdownMenuShortcut";const df=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(hd,{ref:i,decorative:n,orientation:t,className:G("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));df.displayName=hd.displayName;const ff=Lc,ay=og,ly=Bc,pf=x.forwardRef(({className:e,...t},n)=>u.jsx(vs,{className:G("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t,ref:n}));pf.displayName=vs.displayName;const uy=mi("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"}}),ba=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(ly,{children:[u.jsx(pf,{}),u.jsxs(xs,{ref:i,className:G(uy({side:e}),t),...r,children:[u.jsxs(ua,{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(xn,{className:"h-4 w-4"}),u.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));ba.displayName=xs.displayName;const cy=x.forwardRef(({className:e,...t},n)=>u.jsx(ys,{ref:n,className:G("text-foreground text-lg font-semibold",e),...t}));cy.displayName=ys.displayName;const dy=x.forwardRef(({className:e,...t},n)=>u.jsx(bs,{ref:n,className:G("text-muted-foreground text-sm",e),...t}));dy.displayName=bs.displayName;function Yr({className:e,...t}){return u.jsx("div",{className:G("bg-primary/10 animate-pulse rounded-md",e),...t})}const Hs=768,Ws=1200;function hf(e){return typeof window<"u"?window.innerWidth<e:!1}function mf(){const[e,t]=x.useState(()=>hf(Hs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Hs-1}px)`),r=()=>{t(window.innerWidth<Hs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function fy(){const[e,t]=x.useState(()=>hf(Ws));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Ws-1}px)`),r=()=>{t(window.innerWidth<Ws)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const py="sidebar_state",hy=60*60*24*7,my="16rem",gy="18rem",xy="3rem",yy="b",gf=x.createContext(null);function Es(){const e=x.useContext(gf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const xf=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...o},a)=>{const l=mf(),[c,d]=x.useState(!1),[f,p]=x.useState(e),h=t??f,g=x.useCallback(j=>{const m=typeof j=="function"?j(h):j;n?n(m):p(m),document.cookie=`${py}=${m}; path=/; max-age=${hy}`},[n,h]),v=x.useCallback(()=>l?d(j=>!j):g(j=>!j),[l,g,d]);x.useEffect(()=>{const j=A=>{var N;const C=A;if(!C)return!1;const w=(N=C.tagName)==null?void 0:N.toLowerCase();return w==="input"||w==="textarea"||w==="select"||C.isContentEditable?!0:!!(C.closest&&C.closest(".monaco-editor"))},m=A=>{const C=A.metaKey||A.ctrlKey,w=A.key.toLowerCase();if(C&&w===yy){A.preventDefault(),v();return}C&&w==="s"&&!j(A.target)&&(A.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const S=h?"expanded":"collapsed",y=x.useMemo(()=>({state:S,open:h,setOpen:g,isMobile:l,openMobile:c,setOpenMobile:d,toggleSidebar:v}),[S,h,g,l,c,d,v]);return u.jsx(gf.Provider,{value:y,children:u.jsx(bg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":my,"--sidebar-width-icon":xy,...i},className:G("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:a,...o,children:s})})})});xf.displayName="SidebarProvider";const yf=x.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},o)=>{const{isMobile:a,state:l,openMobile:c,setOpenMobile:d}=Es();return n==="none"?u.jsx("div",{className:G("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:o,...s,children:i}):a?u.jsx(ff,{open:c,onOpenChange:d,...s,children:u.jsx(ba,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":gy},side:e,children:u.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):u.jsxs("div",{ref:o,className:"group peer text-sidebar-foreground hidden md:block","data-state":l,"data-collapsible":l==="collapsed"?n:"","data-variant":t,"data-side":e,children:[u.jsx("div",{className:G("relative h-svh w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180",t==="floating"||t==="inset"?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),u.jsx("div",{className:G("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex",e==="left"?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",t==="floating"||t==="inset"?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",r),...s,children:u.jsx("div",{"data-sidebar":"sidebar",className:"bg-sidebar group-data-[variant=floating]:border-sidebar-border flex h-full w-full flex-col group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:shadow",children:i})})]})});yf.displayName="Sidebar";const by=x.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=Es();return u.jsxs(_e,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:G("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(jg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});by.displayName="SidebarTrigger";const vy=x.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=Es();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:G("hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:hover:bg-sidebar group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",e),...t})});vy.displayName="SidebarRail";const wy=x.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:G("bg-background relative flex min-h-svh flex-1 flex-col","peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2",e),...t}));wy.displayName="SidebarInset";const ky=x.forwardRef(({className:e,...t},n)=>u.jsx(gr,{ref:n,"data-sidebar":"input",className:G("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));ky.displayName="SidebarInput";const Ro=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:G("flex flex-col gap-2 p-2",e),...t}));Ro.displayName="SidebarHeader";const bf=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:G("flex flex-col gap-2 p-2",e),...t}));bf.displayName="SidebarFooter";const Sy=x.forwardRef(({className:e,...t},n)=>u.jsx(df,{ref:n,"data-sidebar":"separator",className:G("bg-sidebar-border mx-2 w-auto",e),...t}));Sy.displayName="SidebarSeparator";const Mo=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:G("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Mo.displayName="SidebarContent";const _y=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:G("relative flex w-full min-w-0 flex-col p-2",e),...t}));_y.displayName="SidebarGroup";const jy=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?_r:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:G("text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium transition-[margin,opa] duration-200 ease-linear outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",e),...n})});jy.displayName="SidebarGroupLabel";const Ny=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?_r:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:G("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",e),...n})});Ny.displayName="SidebarGroupAction";const Ey=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:G("w-full text-sm",e),...t}));Ey.displayName="SidebarGroupContent";const Br=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:G("flex w-full min-w-0 flex-col gap-1",e),...t}));Br.displayName="SidebarMenu";const vf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:G("group/menu-item relative",e),...t}));vf.displayName="SidebarMenuItem";const Cy=mi("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"}}),wf=x.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...o},a)=>{const l=e?_r:"button",{isMobile:c,state:d}=Es(),f=u.jsx(l,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:G(Cy({variant:n,size:r}),s),...o});return i?(typeof i=="string"&&(i={children:i}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:f}),u.jsx(Ye,{side:"right",align:"center",hidden:d!=="collapsed"||c,...i})]})):f});wf.displayName="SidebarMenuButton";const kf=x.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?_r:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:G("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground peer-hover/menu-button:text-sidebar-accent-foreground absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 transition-transform outline-none focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"peer-data-[active=true]/menu-button:text-sidebar-accent-foreground group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 md:opacity-0",e),...r})});kf.displayName="SidebarMenuAction";const Ty=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:G("text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",e),...t}));Ty.displayName="SidebarMenuBadge";const Iy=x.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=x.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return u.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:G("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Yr,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Yr,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Iy.displayName="SidebarMenuSkeleton";const Ay=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:G("border-sidebar-border mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",e),...t}));Ay.displayName="SidebarMenuSub";const zy=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));zy.displayName="SidebarMenuSubItem";const Oy=x.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const o=e?_r:"a";return u.jsx(o,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:G("text-sidebar-foreground ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground active:bg-sidebar-accent active:text-sidebar-accent-foreground [&>svg]:text-sidebar-accent-foreground flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 outline-none focus-visible:ring-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 cursor-pointer","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground",t==="sm"&&"text-xs",t==="md"&&"text-sm","group-data-[collapsible=icon]:hidden",r),...i})});Oy.displayName="SidebarMenuSubButton";function Li(e,t){const n=URL.createObjectURL(t),r=document.createElement("a");r.href=n,r.style.display="none",r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}const Py=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Dy({document:e,compact:t=!1,query:n=""}){const r=x.useRef(null),[i,s]=x.useState(!1),[o,a]=x.useState(!1),[l,c]=x.useState(!1),[d,f]=x.useState(!1),p=Ce(q=>q.openDocument),h=Ce(q=>q.documentTypes),g=Ce(q=>q.activeTab),v=rn(q=>q.name),S=rn(q=>q.text),y=rn(q=>q.isGenerating),m=(h[e.name]||"application/json+report")==="application/json+theme",A=g===e.name,[C,w]=x.useState(v),[N,J]=x.useState(S),D=100,_=0;x.useEffect(()=>{const q=setTimeout(()=>{v&&S?(w(v),J(S)):y||(w(""),J(""))},y?D:_);return()=>clearTimeout(q)},[v,S,y]);const T=C===e.name,I=q=>{var B;const b=new Set;try{const V=JSON.parse(q);(B=V.props)!=null&&B.theme&&b.add(V.props.theme),V.children&&Array.isArray(V.children)&&V.children.forEach(re=>{var se;re.name==="docx"&&((se=re.props)!=null&&se.theme)&&b.add(re.props.theme)})}catch{}return b},z=x.useMemo(()=>{if(!m||!N)return!1;try{const q=JSON.parse(e.text),b=rx(q);if(b)return I(N).has(b)}catch{}return!1},[m,N,e.text]),O=x.useCallback(()=>{c(!1)},[]),R=x.useCallback(()=>{f(!1)},[]),Y=A?null:T?"preview":z?"in-use":null,H=A?"Editing":T?"In preview":z?"Used by preview":null,$=x.useMemo(()=>[{key:"open",label:"Open",shortcut:Py?"⌘⏎":"⌃⏎",run:()=>p(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Li(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>c(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>f(!0)}],[e.name,e.text,e.type,p]),ee=m?Ng:jd,k=i||o,oe=u.jsxs(wf,{size:"sm",ref:r,"aria-label":H?`${e.name} — ${H}`:e.name,className:G("relative h-7 rounded-sm text-[13px] font-normal","text-sidebar-foreground/85 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground",t?"size-7 justify-center px-0":"gap-2 pr-7 pl-2",k&&"bg-sidebar-accent/60 text-sidebar-foreground",A&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:H?`${e.name} — ${H}`:e.name,onClick:()=>{p(e.name)},onKeyDown:q=>{var b;(q.ctrlKey||q.metaKey)&&q.key==="Enter"?(p(e.name),q.preventDefault()):q.key==="Enter"?(c(!0),q.preventDefault()):q.key==="Backspace"||q.key==="Delete"?(f(!0),q.preventDefault()):q.key==="Escape"&&((b=r.current)==null||b.blur(),q.preventDefault())},children:[A&&u.jsx("span",{"aria-hidden":!0,className:G("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(ee,{className:G("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",A&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(ya,{text:e.name,query:n})}),t&&Y&&u.jsx(ml,{tone:Y,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(vf,{children:[u.jsxs(Yx,{onOpenChange:s,children:[u.jsx(Kx,{className:"block",children:t?u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:oe}),u.jsx(Ye,{side:"right",children:u.jsxs("div",{className:"text-xs",children:[u.jsx("div",{children:e.name}),u.jsx("div",{className:"opacity-70",children:H??(m?"Theme":"Document")})]})})]}):oe}),u.jsx(sf,{className:"w-44",children:$.map(q=>u.jsxs(je.Fragment,{children:[q.separatorBefore&&u.jsx(af,{}),u.jsxs(of,{onClick:q.run,className:G(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(lf,{children:q.shortcut})]})]},q.key))})]}),!t&&u.jsxs(u.Fragment,{children:[Y&&u.jsx(ml,{tone:Y,className:G("pointer-events-none absolute top-1/2 right-2.5 -translate-y-1/2 transition-opacity","group-hover/menu-item:opacity-0 group-focus-within/menu-item:opacity-0",o&&"opacity-0")}),u.jsxs(js,{onOpenChange:a,children:[u.jsx(Ns,{asChild:!0,children:u.jsx(kf,{showOnHover:!0,"aria-label":`Actions for ${e.name}`,className:"top-1 size-5 rounded-sm text-sidebar-foreground/55 hover:text-sidebar-foreground [&>svg]:size-3.5",children:u.jsx(Nd,{})})}),u.jsx(xi,{side:"right",align:"start",className:"w-44",children:$.map(q=>u.jsxs(je.Fragment,{children:[q.separatorBefore&&u.jsx(xr,{}),u.jsxs(Ft,{onClick:q.run,className:G(q.danger&&"text-destructive focus:text-destructive"),children:[q.label,q.shortcut&&u.jsx(cf,{children:q.shortcut})]})]},q.key))})]})]}),u.jsx(Ct,{open:l,onOpenChange:c,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var b;q.preventDefault(),(b=r.current)==null||b.focus()},children:u.jsx(Yi,{mode:"update",shouldReset:!l,postSubmit:O,selectedName:e.name})})}),u.jsx(Ct,{open:d,onOpenChange:f,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:q=>{var b;q.preventDefault(),(b=r.current)==null||b.focus()},children:u.jsx(Yi,{mode:"delete",shouldReset:!d,postSubmit:R,selectedName:e.name})})})]})}const Ni=je.memo(Dy);function Ry(e,t=!1){const n=e.length;let r=0,i="",s=0,o=16,a=0,l=0,c=0,d=0,f=0;function p(m,A){let C=0,w=0;for(;C<m;){let N=e.charCodeAt(r);if(N>=48&&N<=57)w=w*16+N-48;else if(N>=65&&N<=70)w=w*16+N-65+10;else if(N>=97&&N<=102)w=w*16+N-97+10;else break;r++,C++}return C<m&&(w=-1),w}function h(m){r=m,i="",s=0,o=16,f=0}function g(){let m=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&Vn(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Vn(e.charCodeAt(r)))for(r++;r<e.length&&Vn(e.charCodeAt(r));)r++;else return f=3,e.substring(m,r);let A=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Vn(e.charCodeAt(r))){for(r++;r<e.length&&Vn(e.charCodeAt(r));)r++;A=r}else f=3;return e.substring(m,A)}function v(){let m="",A=r;for(;;){if(r>=n){m+=e.substring(A,r),f=2;break}const C=e.charCodeAt(r);if(C===34){m+=e.substring(A,r),r++;break}if(C===92){if(m+=e.substring(A,r),r++,r>=n){f=2;break}switch(e.charCodeAt(r++)){case 34:m+='"';break;case 92:m+="\\";break;case 47:m+="/";break;case 98:m+="\b";break;case 102:m+="\f";break;case 110:m+=`
|
|
3
3
|
`;break;case 114:m+="\r";break;case 116:m+=" ";break;case 117:const N=p(4);N>=0?m+=String.fromCharCode(N):f=4;break;default:f=5}A=r;continue}if(C>=0&&C<=31)if(Or(C)){m+=e.substring(A,r),f=2;break}else f=6;r++}return m}function S(){if(i="",f=0,s=r,l=a,d=c,r>=n)return s=n,o=17;let m=e.charCodeAt(r);if(qs(m)){do r++,i+=String.fromCharCode(m),m=e.charCodeAt(r);while(qs(m));return o=15}if(Or(m))return r++,i+=String.fromCharCode(m),m===13&&e.charCodeAt(r)===10&&(r++,i+=`
|
|
4
4
|
`),a++,c=r,o=14;switch(m){case 123:return r++,o=1;case 125:return r++,o=2;case 91:return r++,o=3;case 93:return r++,o=4;case 58:return r++,o=6;case 44:return r++,o=5;case 34:return r++,i=v(),o=10;case 47:const A=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!Or(e.charCodeAt(r));)r++;return i=e.substring(A,r),o=12}if(e.charCodeAt(r+1)===42){r+=2;const C=n-1;let w=!1;for(;r<C;){const N=e.charCodeAt(r);if(N===42&&e.charCodeAt(r+1)===47){r+=2,w=!0;break}r++,Or(N)&&(N===13&&e.charCodeAt(r)===10&&r++,a++,c=r)}return w||(r++,f=1),i=e.substring(A,r),o=13}return i+=String.fromCharCode(m),r++,o=16;case 45:if(i+=String.fromCharCode(m),r++,r===n||!Vn(e.charCodeAt(r)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=g(),o=11;default:for(;r<n&&y(m);)r++,m=e.charCodeAt(r);if(s!==r){switch(i=e.substring(s,r),i){case"true":return o=8;case"false":return o=9;case"null":return o=7}return o=16}return i+=String.fromCharCode(m),r++,o=16}}function y(m){if(qs(m)||Or(m))return!1;switch(m){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function j(){let m;do m=S();while(m>=12&&m<=15);return m}return{setPosition:h,getPosition:()=>r,scan:t?j:S,getToken:()=>o,getTokenValue:()=>i,getTokenOffset:()=>s,getTokenLength:()=>r-s,getTokenStartLine:()=>l,getTokenStartCharacter:()=>s-d,getTokenError:()=>f}}function qs(e){return e===32||e===9}function Or(e){return e===10||e===13}function Vn(e){return e>=48&&e<=57}var xl;(function(e){e[e.lineFeed=10]="lineFeed",e[e.carriageReturn=13]="carriageReturn",e[e.space=32]="space",e[e._0=48]="_0",e[e._1=49]="_1",e[e._2=50]="_2",e[e._3=51]="_3",e[e._4=52]="_4",e[e._5=53]="_5",e[e._6=54]="_6",e[e._7=55]="_7",e[e._8=56]="_8",e[e._9=57]="_9",e[e.a=97]="a",e[e.b=98]="b",e[e.c=99]="c",e[e.d=100]="d",e[e.e=101]="e",e[e.f=102]="f",e[e.g=103]="g",e[e.h=104]="h",e[e.i=105]="i",e[e.j=106]="j",e[e.k=107]="k",e[e.l=108]="l",e[e.m=109]="m",e[e.n=110]="n",e[e.o=111]="o",e[e.p=112]="p",e[e.q=113]="q",e[e.r=114]="r",e[e.s=115]="s",e[e.t=116]="t",e[e.u=117]="u",e[e.v=118]="v",e[e.w=119]="w",e[e.x=120]="x",e[e.y=121]="y",e[e.z=122]="z",e[e.A=65]="A",e[e.B=66]="B",e[e.C=67]="C",e[e.D=68]="D",e[e.E=69]="E",e[e.F=70]="F",e[e.G=71]="G",e[e.H=72]="H",e[e.I=73]="I",e[e.J=74]="J",e[e.K=75]="K",e[e.L=76]="L",e[e.M=77]="M",e[e.N=78]="N",e[e.O=79]="O",e[e.P=80]="P",e[e.Q=81]="Q",e[e.R=82]="R",e[e.S=83]="S",e[e.T=84]="T",e[e.U=85]="U",e[e.V=86]="V",e[e.W=87]="W",e[e.X=88]="X",e[e.Y=89]="Y",e[e.Z=90]="Z",e[e.asterisk=42]="asterisk",e[e.backslash=92]="backslash",e[e.closeBrace=125]="closeBrace",e[e.closeBracket=93]="closeBracket",e[e.colon=58]="colon",e[e.comma=44]="comma",e[e.dot=46]="dot",e[e.doubleQuote=34]="doubleQuote",e[e.minus=45]="minus",e[e.openBrace=123]="openBrace",e[e.openBracket=91]="openBracket",e[e.plus=43]="plus",e[e.slash=47]="slash",e[e.formFeed=12]="formFeed",e[e.tab=9]="tab"})(xl||(xl={}));new Array(20).fill(0).map((e,t)=>" ".repeat(t));const Un=200;new Array(Un).fill(0).map((e,t)=>`
|
|
5
5
|
`+" ".repeat(t)),new Array(Un).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(Un).fill(0).map((e,t)=>`\r
|
|
6
6
|
`+" ".repeat(t)),new Array(Un).fill(0).map((e,t)=>`
|
|
7
7
|
`+" ".repeat(t)),new Array(Un).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(Un).fill(0).map((e,t)=>`\r
|
|
8
8
|
`+" ".repeat(t));var Ki;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Ki||(Ki={}));function My(e,t=[],n=Ki.DEFAULT){let r={type:"array",offset:-1,length:-1,children:[],parent:void 0};function i(l){r.type==="property"&&(r.length=l-r.offset,r=r.parent)}function s(l){return r.children.push(l),l}$y(e,{onObjectBegin:l=>{r=s({type:"object",offset:l,length:-1,parent:r,children:[]})},onObjectProperty:(l,c,d)=>{r=s({type:"property",offset:c,length:-1,parent:r,children:[]}),r.children.push({type:"string",value:l,offset:c,length:d,parent:r})},onObjectEnd:(l,c)=>{i(l+c),r.length=l+c-r.offset,r=r.parent,i(l+c)},onArrayBegin:(l,c)=>{r=s({type:"array",offset:l,length:-1,parent:r,children:[]})},onArrayEnd:(l,c)=>{r.length=l+c-r.offset,r=r.parent,i(l+c)},onLiteralValue:(l,c,d)=>{s({type:Fy(l),offset:c,length:d,parent:r,value:l}),i(c+d)},onSeparator:(l,c,d)=>{r.type==="property"&&(l===":"?r.colonOffset=c:l===","&&i(c))},onError:(l,c,d)=>{t.push({error:l,offset:c,length:d})}},n);const a=r.children[0];return a&&delete a.parent,a}function $y(e,t,n=Ki.DEFAULT){const r=Ry(e,!1),i=[];let s=0;function o(O){return O?()=>s===0&&O(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function a(O){return O?R=>s===0&&O(R,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function l(O){return O?R=>s===0&&O(R,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function c(O){return O?()=>{s>0?s++:O(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(s=1)}:()=>!0}function d(O){return O?()=>{s>0&&s--,s===0&&O(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}const f=c(t.onObjectBegin),p=l(t.onObjectProperty),h=d(t.onObjectEnd),g=c(t.onArrayBegin),v=d(t.onArrayEnd),S=l(t.onLiteralValue),y=a(t.onSeparator),j=o(t.onComment),m=a(t.onError),A=n&&n.disallowComments,C=n&&n.allowTrailingComma;function w(){for(;;){const O=r.scan();switch(r.getTokenError()){case 4:N(14);break;case 5:N(15);break;case 3:N(13);break;case 1:A||N(11);break;case 2:N(12);break;case 6:N(16);break}switch(O){case 12:case 13:A?N(10):j();break;case 16:N(1);break;case 15:case 14:break;default:return O}}}function N(O,R=[],Y=[]){if(m(O),R.length+Y.length>0){let H=r.getToken();for(;H!==17;){if(R.indexOf(H)!==-1){w();break}else if(Y.indexOf(H)!==-1)break;H=w()}}}function J(O){const R=r.getTokenValue();return O?S(R):(p(R),i.push(R)),w(),!0}function D(){switch(r.getToken()){case 11:const O=r.getTokenValue();let R=Number(O);isNaN(R)&&(N(2),R=0),S(R);break;case 7:S(null);break;case 8:S(!0);break;case 9:S(!1);break;default:return!1}return w(),!0}function _(){return r.getToken()!==10?(N(3,[],[2,5]),!1):(J(!1),r.getToken()===6?(y(":"),w(),z()||N(4,[],[2,5])):N(5,[],[2,5]),i.pop(),!0)}function T(){f(),w();let O=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(O||N(4,[],[]),y(","),w(),r.getToken()===2&&C)break}else O&&N(6,[],[]);_()||N(4,[],[2,5]),O=!0}return h(),r.getToken()!==2?N(7,[2],[]):w(),!0}function I(){g(),w();let O=!0,R=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(R||N(4,[],[]),y(","),w(),r.getToken()===4&&C)break}else R&&N(6,[],[]);O?(i.push(0),O=!1):i[i.length-1]++,z()||N(4,[],[4,5]),R=!0}return v(),O||i.pop(),r.getToken()!==4?N(8,[4],[]):w(),!0}function z(){switch(r.getToken()){case 3:return I();case 1:return T();case 10:return J(!0);default:return D()}}return w(),r.getToken()===17?n.allowEmptyContent?!0:(N(4,[],[]),!1):z()?(r.getToken()!==17&&N(9,[],[]),!0):(N(4,[],[]),!1)}function Fy(e){switch(typeof e){case"boolean":return"boolean";case"number":return"number";case"string":return"string";case"object":{if(e){if(Array.isArray(e))return"array"}else return"null";return"object"}default:return"null"}}var yl;(function(e){e[e.None=0]="None",e[e.UnexpectedEndOfComment=1]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=2]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=3]="UnexpectedEndOfNumber",e[e.InvalidUnicode=4]="InvalidUnicode",e[e.InvalidEscapeCharacter=5]="InvalidEscapeCharacter",e[e.InvalidCharacter=6]="InvalidCharacter"})(yl||(yl={}));var bl;(function(e){e[e.OpenBraceToken=1]="OpenBraceToken",e[e.CloseBraceToken=2]="CloseBraceToken",e[e.OpenBracketToken=3]="OpenBracketToken",e[e.CloseBracketToken=4]="CloseBracketToken",e[e.CommaToken=5]="CommaToken",e[e.ColonToken=6]="ColonToken",e[e.NullKeyword=7]="NullKeyword",e[e.TrueKeyword=8]="TrueKeyword",e[e.FalseKeyword=9]="FalseKeyword",e[e.StringLiteral=10]="StringLiteral",e[e.NumericLiteral=11]="NumericLiteral",e[e.LineCommentTrivia=12]="LineCommentTrivia",e[e.BlockCommentTrivia=13]="BlockCommentTrivia",e[e.LineBreakTrivia=14]="LineBreakTrivia",e[e.Trivia=15]="Trivia",e[e.Unknown=16]="Unknown",e[e.EOF=17]="EOF"})(bl||(bl={}));const Ly=My;var vl;(function(e){e[e.InvalidSymbol=1]="InvalidSymbol",e[e.InvalidNumberFormat=2]="InvalidNumberFormat",e[e.PropertyNameExpected=3]="PropertyNameExpected",e[e.ValueExpected=4]="ValueExpected",e[e.ColonExpected=5]="ColonExpected",e[e.CommaExpected=6]="CommaExpected",e[e.CloseBraceExpected=7]="CloseBraceExpected",e[e.CloseBracketExpected=8]="CloseBracketExpected",e[e.EndOfFileExpected=9]="EndOfFileExpected",e[e.InvalidCommentToken=10]="InvalidCommentToken",e[e.UnexpectedEndOfComment=11]="UnexpectedEndOfComment",e[e.UnexpectedEndOfString=12]="UnexpectedEndOfString",e[e.UnexpectedEndOfNumber=13]="UnexpectedEndOfNumber",e[e.InvalidUnicode=14]="InvalidUnicode",e[e.InvalidEscapeCharacter=15]="InvalidEscapeCharacter",e[e.InvalidCharacter=16]="InvalidCharacter"})(vl||(vl={}));const By=60,Zy=/§jtoc:\d+§/g;function Oe(e,t){if(!(!e||e.type!=="object"||!e.children))for(const n of e.children){if(n.type!=="property"||!n.children)continue;const[r,i]=n.children;if((r==null?void 0:r.value)===t)return i}}function st(e){return(e==null?void 0:e.type)==="string"&&typeof e.value=="string"?e.value:void 0}function $o(e){return(e==null?void 0:e.type)==="number"&&typeof e.value=="number"?e.value:void 0}function Et(e){return(e==null?void 0:e.type)==="array"&&e.children?e.children:[]}function vt(e,t=By,n=!1){const r=e.replace(Zy,"…"),i=n?r.replace(/\s*\n\s*/g," ").trim():r.split(`
|
|
9
|
-
`)[0].trim();return i.length>t?`${i.slice(0,t-1)}…`:i}function Vy(e){const t=Et(Oe(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>Et(Oe(i,"cells")).length))}×${t.length}`;const n=Et(Oe(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?Et(r).length:Et(Oe(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Uy(e){const t=st(Oe(e,"alt"));if(t)return vt(t);const n=st(Oe(e,"src"));if(n){if(n.startsWith("data:")){const i=n.slice(5).split(/[;,]/)[0];return i?`image (${i.split("/").pop()})`:"image"}const r=n.split(/[?#]/)[0].split("/").pop();if(r)return vt(r,40)}return"image"}function Jy(e,t){var r;const n=st(Oe(t,"text"));switch(e){case"heading":{const i=$o(Oe(t,"level"))??1;return{label:n?vt(n):"heading",detail:`H${i}`}}case"text":return{label:n?vt(n):"text",detail:st(Oe(t,"style"))};case"paragraph":return{label:n?vt(n):"paragraph"};case"chart":case"highcharts":{const i=st(Oe(t,"title"))??st(Oe(Oe(t,"options"),"title"));return{label:i?vt(i):e,detail:st(Oe(t,"type"))}}case"table":return{label:"table",detail:Vy(t)};case"image":return{label:Uy(t)};case"shape":return{label:st(Oe(t,"type"))??"shape"};case"list":{const i=Et(Oe(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=st(Oe(Oe(t,"meta"),"title"))??st(Oe(t,"title"));return{label:i?vt(i):"section"}}case"statistic":{const i=st(Oe(t,"value"))??((r=$o(Oe(t,"value")))==null?void 0:r.toString()),s=st(Oe(t,"label"));return{label:vt(s??i??"statistic"),detail:i}}default:return{label:n?vt(n):e}}}function yr(e){if(e.type!=="object")return null;const t=st(Oe(e,"name"));return t?{name:t,props:Oe(e,"props"),childrenArr:Oe(e,"children")}:null}function Hy(e){let t;for(const n of Et(e)){const r=yr(n);if(!r)continue;const i=st(Oe(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return vt(i,48);r.name==="paragraph"&&t===void 0&&(t=vt(i,48))}}return t}function Xi(e,t,n){let{label:r,detail:i}=Jy(t.name,t.props);return r===t.name&&t.childrenArr&&(r=Hy(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:Sf(t.childrenArr),reorder:n}}function Sf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of Et(e)){const i=yr(r);i&&n.push(Xi(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Wy(e){const t=Oe(e,"props"),n=st(Oe(Oe(t,"meta"),"title"));if(n)return vt(n,48,!0);let r;const i=(a,l)=>{l&&(!r||a<r.rank)&&(r={rank:a,text:l})},s=Oe(t,"placeholders");if((s==null?void 0:s.type)==="object"&&s.children)for(const a of s.children){if(a.type!=="property"||!a.children)continue;const[l,c]=a.children,d=typeof(l==null?void 0:l.value)=="string"?l.value:"",f=c?yr(c):null,p=f?st(Oe(f.props,"text")):void 0;i(d==="title"?0:d==="subtitle"||d.startsWith("heading")?1:2,p)}const o=(a,l)=>{const c=yr(a);if(c){if(c.name==="text"||c.name==="heading"){const d=st(Oe(c.props,"text"));if(d){const f=st(Oe(c.props,"style"))??"";i(f==="title"?0:f.startsWith("heading")?1:2,d)}}if(l<1)for(const d of Et(c.childrenArr))o(d,l+1)}};for(const a of Et(Oe(e,"children")))o(a,0);return r?vt(r.text,48,!0):void 0}function qy(e){const t=Oe(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of Et(t)){const o=yr(s);if(!o)continue;const a={groupId:n,sliceStart:s.offset,sliceEnd:s.offset+s.length};o.name==="slide"?(i+=1,r.push({id:"",kind:"slide",label:Wy(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:Sf(o.childrenArr),reorder:a})):r.push(Xi(s,o,a))}return r}function Gy(e){const t=Oe(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const o of Et(t)){const a=yr(o);if(!a)continue;const l={groupId:n,sliceStart:o.offset,sliceEnd:o.offset+o.length},c=()=>i.length?i[i.length-1].node.children:r;if(a.name==="heading"){const d=$o(Oe(a.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=Xi(o,a,l);c().push(f),i.push({level:d,node:f})}else c().push(Xi(o,a,l))}const s=o=>{o.children.forEach(s);const a=o.children[o.children.length-1];o.kind==="heading"&&a&&(o.end=Math.max(o.end,a.end),o.reorder&&a.reorder&&(o.reorder.sliceEnd=Math.max(o.reorder.sliceEnd,a.reorder.sliceEnd)))};return r.forEach(s),r}function wl(e){switch(e.type){case"string":return vt(String(e.value??""),24);case"number":case"boolean":return String(e.value);case"array":return`${Et(e).length} items`;case"object":return;default:return}}function Yy(e){if(e.type!=="object"||!e.children)return[];const t=[];for(const n of e.children){if(n.type!=="property"||!n.children)continue;const[r,i]=n.children,s=typeof(r==null?void 0:r.value)=="string"?r.value:void 0;if(!s||s==="$schema"||!i)continue;const o=[];if(i.type==="object"&&i.children)for(const a of i.children){if(a.type!=="property"||!a.children)continue;const[l,c]=a.children,d=typeof(l==null?void 0:l.value)=="string"?l.value:void 0;!d||!c||o.push({id:"",kind:"key",label:d,detail:wl(c),start:a.offset,end:a.offset+a.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:o.length===0?wl(i):void 0,start:n.offset,end:n.offset+n.length,children:o})}return t}function kl(e,t,n){if(!e.trim())return[];const r=Ly(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Yy(r):t==="pptx"?qy(r):Gy(r);return _f(i,""),i}function _f(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,_f(n.children,n.id)})}function jf(e,t){const n=[];let r=e;for(;;){const i=r.find(s=>t>=s.start&&t<s.end);if(!i)return n;n.push(i.id),r=i.children}}function Ky(e,t){const n=new Set;for(const r of t)for(const i of jf(e,r))n.add(i);return n}function Xy(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(d=>d.reorder);if(i.some(d=>!d))return null;const s=i[0].groupId;if(i.some(d=>d.groupId!==s))return null;for(let d=1;d<i.length;d++)if(i[d].sliceStart<i[d-1].sliceEnd)return null;const o=i.map(d=>e.slice(d.sliceStart,d.sliceEnd)),a=[];for(let d=1;d<i.length;d++){const f=e.slice(i[d-1].sliceEnd,i[d].sliceStart);if((f.match(/,/g)??[]).length!==1)return null;a.push(f)}const l=o.map((d,f)=>f);l.splice(r,0,l.splice(n,1)[0]);let c="";return l.forEach((d,f)=>{c+=o[d],f<a.length&&(c+=a[f])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:c}}const Qy={slide:Pg,heading:Og,text:jo,paragraph:zg,chart:No,highcharts:No,table:Ag,image:Ig,shape:Ed,list:Tg,toc:Cg,section:tl,columns:tl,"text-box":jo,statistic:Eg,key:_o};function eb(e,t){let n=e,r=null;for(const i of t.split(".")){if(r=n[Number(i)]??null,!r)return null;n=r.children}return r}function tb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function nb(){const{activeTab:e,documentTypes:t}=Ce(da(D=>({activeTab:D.activeTab,documentTypes:D.documentTypes}))),n=Ce(D=>{var _;return D.activeTab?(_=D.documents.find(T=>T.name===D.activeTab))==null?void 0:_.text:void 0}),r=tx(D=>e?D.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,o]=x.useState(()=>{try{const D=localStorage.getItem("dev-env.outline-open");return D?D==="true":!0}catch{return!0}});x.useEffect(()=>{try{localStorage.setItem("dev-env.outline-open",String(s))}catch{}},[s]);const[a,l]=x.useState([]),[c,d]=x.useState(null),[f,p]=x.useState(()=>new Set),[h,g]=x.useState(()=>new Set),[v,S]=x.useState(null),y=x.useRef(a);y.current=a;const j=x.useRef(null),m=x.useRef(null),A=x.useCallback(()=>{var T;if(!e){l([]);return}const D=((T=r==null?void 0:r.editor.getModel())==null?void 0:T.getValue())??n??"",_=kl(D,ot,i);if(l(_),m.current!==e){m.current=e;const I=new Set;if(i==="document"&&ot==="docx")for(const z of _)z.kind==="heading"&&I.add(z.id);g(I),d(null)}},[e,r,n,i]);x.useEffect(()=>{A();const D=r==null?void 0:r.editor.getModel();if(!D)return;const _=rl(A,300),T=D.onDidChangeContent(()=>_());return()=>{_.cancel(),T.dispose()}},[A,r]),x.useEffect(()=>{if(!r)return;const{editor:D}=r,_=rl(()=>{const I=D.getModel(),z=D.getPosition();if(!I||!z)return;const O=I.getOffsetAt(z),R=jf(y.current,O);if(R.length===0){d(null);return}d(R[R.length-1]);const Y=R.slice(0,-1);Y.length&&g(H=>{if(Y.every(ee=>H.has(ee)))return H;const $=new Set(H);for(const ee of Y)$.add(ee);return $})},150),T=D.onDidChangeCursorPosition(()=>_());return()=>{_.cancel(),T.dispose()}},[r]),x.useEffect(()=>{if(!c||!j.current)return;const D=j.current.querySelector(`[data-oid="${CSS.escape(c)}"]`);D==null||D.scrollIntoView({block:"nearest"})},[c]),x.useEffect(()=>{if(!r){p(new Set);return}const{editor:D,monaco:_}=r,T=()=>{const z=D.getModel();if(!z)return;const O=_.editor.getModelMarkers({resource:z.uri}).filter(R=>R.severity===_.MarkerSeverity.Error).map(R=>z.getOffsetAt({lineNumber:R.startLineNumber,column:R.startColumn}));p(Ky(y.current,O))};T();const I=_.editor.onDidChangeMarkers(z=>{const O=D.getModel();O&&z.some(R=>R.toString()===O.uri.toString())&&T()});return()=>I.dispose()},[r,a]);const C=x.useCallback(D=>{g(_=>{const T=new Set(_);return T.has(D)?T.delete(D):T.add(D),T})},[]),w=x.useCallback(D=>{if(d(D.id),!r)return;const{editor:_,monaco:T}=r,I=_.getModel();if(!I)return;const z=I.getPositionAt(D.start),O=I.getPositionAt(D.end),R=new T.Range(z.lineNumber,z.column,O.lineNumber,O.column);_.revealRangeNearTopIfOutsideViewport(R,T.editor.ScrollType.Smooth),_.setPosition(z),_.focus();const Y=_.deltaDecorations([],[{range:R,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>_.deltaDecorations(Y,[]),700)},[r]),N=x.useCallback(D=>{var b;if(!r||!D.overId)return;const{editor:_,monaco:T,collapse:I}=r,z=_.getModel();if(!z)return;const O=z.getValue(),R=kl(O,ot,i),Y=D.parentId?((b=eb(R,D.parentId))==null?void 0:b.children)??[]:R,H=Y.findIndex(B=>B.id===D.dragId),$=Y.findIndex(B=>B.id===D.overId);if(H===-1||$===-1)return;let ee=$+(D.overHalf==="after"?1:0);H<ee&&(ee-=1);const k=Xy(O,Y,H,ee);if(!k)return;const oe=z.getPositionAt(k.start),q=z.getPositionAt(k.end);_.executeEdits("outline-reorder",[{range:new T.Range(oe.lineNumber,oe.column,q.lineNumber,q.column),text:k.text}]),I==null||I.resyncDecorations()},[r,i]),J=x.useMemo(()=>{const D=[],_=(T,I,z)=>{var Y,H;const O=(H=(Y=T[0])==null?void 0:Y.reorder)==null?void 0:H.groupId,R=T.length>1&&O!==void 0&&T.every($=>{var ee;return((ee=$.reorder)==null?void 0:ee.groupId)===O});T.forEach($=>{const ee=Qy[$.kind]??Dg,k=$.children.length>0,oe=h.has($.id),q=c===$.id,b=(v==null?void 0:v.overId)===$.id;D.push(u.jsxs("div",{"data-oid":$.id,role:"treeitem","aria-selected":q,"aria-expanded":k?oe:void 0,tabIndex:0,draggable:R,onClick:()=>w($),onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),w($)),B.key==="ArrowRight"&&k&&!oe&&C($.id),B.key==="ArrowLeft"&&k&&oe&&C($.id)},onDragStart:B=>{B.dataTransfer.setData("text/plain",$.id),B.dataTransfer.effectAllowed="move",S({dragId:$.id,parentId:z,overId:null,overHalf:"before"})},onDragOver:B=>{if(!v||v.dragId===$.id||tb(v.dragId)!==z)return;B.preventDefault(),B.dataTransfer.dropEffect="move";const V=B.currentTarget.getBoundingClientRect(),re=B.clientY<V.top+V.height/2?"before":"after";(v.overId!==$.id||v.overHalf!==re)&&S({...v,overId:$.id,overHalf:re})},onDrop:B=>{B.preventDefault(),v&&N({...v,overId:$.id,overHalf:v.overHalf}),S(null)},onDragEnd:()=>S(null),className:G("group flex h-6 w-full cursor-pointer items-center gap-1 rounded-sm pr-1","text-[12px] text-sidebar-foreground/80 transition-colors select-none","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none",q&&"bg-sidebar-accent font-medium text-sidebar-foreground",b&&(v==null?void 0:v.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",b&&(v==null?void 0:v.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+I*12},children:[k?u.jsx("span",{role:"button","aria-label":oe?"Collapse":"Expand",onClick:B=>{B.stopPropagation(),C($.id)},className:"flex size-3.5 shrink-0 items-center justify-center rounded-xs text-sidebar-foreground/55 hover:text-sidebar-foreground",children:u.jsx(Pn,{className:G("size-3 transition-transform",oe&&"rotate-90")})}):u.jsx("span",{className:"size-3.5 shrink-0"}),$.kind==="slide"&&u.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:$.detail}),u.jsx(ee,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:$.label}),$.kind!=="slide"&&$.detail&&u.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:$.detail}),f.has($.id)&&u.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},$.id)),k&&oe&&_($.children,I+1,$.id)})};return _(a,0,""),D},[a,h,c,f,v,w,C,N]);return e?u.jsxs("section",{className:"mt-3 shrink-0",children:[u.jsx(Do,{count:a.length||void 0,actions:u.jsx($t,{"aria-label":s?"Collapse outline":"Expand outline","aria-expanded":s,onClick:()=>o(D=>!D),children:u.jsx(Pn,{className:G("transition-transform",s&&"rotate-90")})}),children:"Outline"}),s&&(a.length>0?u.jsx("div",{ref:j,role:"tree","aria-label":"Document outline",className:"max-h-[45vh] overflow-y-auto",children:J}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/60",children:"No structure to show yet."}))]}):null}const rb=x.memo(nb);async function ib(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const ni=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(md,{ref:r,className:G("relative overflow-hidden",e),...n,children:[u.jsx(ag,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Nf,{}),u.jsx(lg,{})]}));ni.displayName=md.displayName;const Nf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(gd,{ref:r,orientation:t,className:G("flex touch-none transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(ug,{className:"bg-border relative flex-1 rounded-full"})}));Nf.displayName=gd.displayName;function va({className:e,...t}){return u.jsx(cg,{"data-slot":"switch",className:G("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-switch-off focus-visible:ring-ring inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent transition-colors outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:u.jsx(dg,{"data-slot":"switch-thumb",className:G("bg-background pointer-events-none block size-4 rounded-full shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const sb=mi("relative w-full rounded-sm border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-card text-foreground",destructive:"border-transparent bg-destructive-bg text-destructive-bg-foreground [&>svg]:text-destructive-bg-foreground",warning:"border-transparent bg-warning-bg text-warning-bg-foreground [&>svg]:text-warning-bg-foreground",success:"border-transparent bg-success-bg text-success-bg-foreground [&>svg]:text-success-bg-foreground",info:"border-transparent bg-data-blue-bg text-data-blue-bg-foreground [&>svg]:text-data-blue-bg-foreground"}},defaultVariants:{variant:"default"}}),or=x.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:G(sb({variant:t}),e),...n}));or.displayName="Alert";const ob=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:G("mb-1 font-medium leading-none tracking-tight",e),...t}));ob.displayName="AlertTitle";const ar=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:G("text-sm [&_p]:leading-relaxed",e),...t}));ar.displayName="AlertDescription";const Qi=x.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=x.useState(n<2),o=t!==null&&typeof t=="object",a=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?u.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-warning",children:['"',t,'"']}):u.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,d=o?Object.keys(t).length:0;return u.jsxs("div",{className:G("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[o&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(hi,{className:"h-3 w-3"}):u.jsx(Pn,{className:"h-3 w-3"})}),!o&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),o?u.jsxs("span",{className:"text-muted-foreground",children:[a?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[d," ",a?"items":"properties"]}),!i&&(a?"]":"}")]}):c(),!o&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),o&&i&&u.jsxs("div",{className:"ml-4",children:[a?t.map((f,p)=>u.jsx(Qi,{keyName:String(p),value:f,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([f,p],h,g)=>u.jsx(Qi,{keyName:f,value:p,depth:n+1,isLast:h===g.length-1},f)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[a?"]":"}",!r&&","]})})]})]})});Qi.displayName="JsonNode";const es=x.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:G("space-y-4",r),children:[u.jsx(Yr,{className:"h-8 w-64"}),u.jsx(Yr,{className:"h-4 w-full"}),u.jsx(Yr,{className:"h-64 w-full"})]}):n?u.jsx(or,{variant:"destructive",className:r,children:u.jsx(ar,{children:n})}):e?u.jsx(ni,{className:G("h-full w-full rounded-md border bg-muted/10 p-4",r),children:u.jsx("div",{className:"font-mono text-xs",children:u.jsx(Qi,{value:e})})}):u.jsx(or,{className:r,children:u.jsx(ar,{children:"No schema available"})}));es.displayName="SchemaViewer";function ab({plugins:e,initialFocusedPlugin:t}){var m,A;const n=Bt(C=>C.togglePlugin),r=Bt(C=>C.isPluginSelected),i=Bt(C=>C.selectedPlugins),s=Bt(C=>C.isApplyingPlugins),[o,a]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState("properties");x.useEffect(()=>{if(t){const C=e.find(w=>w.name===t);if(C){a(C);return}}e.length>0&&!o&&a(e[0])},[t,e]);const p=x.useMemo(()=>{const C={current:[],downstream:[],upstream:[]};return e.forEach(w=>{C[w.location]&&C[w.location].push(w)}),C},[e]),h=async(C,w)=>{o&&(await ib(o.name,C.props),c(w),setTimeout(()=>c(null),2e3))},g=C=>{switch(C){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return C}},v=C=>{switch(C){case"current":return u.jsx(Bg,{className:"size-3"});case"downstream":return u.jsx(Lg,{className:"size-3"});case"upstream":return u.jsx(jd,{className:"size-3"});default:return null}},S=((m=o==null?void 0:o.schema)==null?void 0:m.properties)&&Object.keys(o.schema.properties).length>0,y=(A=o==null?void 0:o.schema)==null?void 0:A.jsonSchema,j=(o==null?void 0:o.examples)&&o.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(Rg,{className:"size-5 text-warning"}),"Plugins",u.jsxs(Kt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(an,{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(ni,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(p).map(([C,w])=>w.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[v(C),g(C)]}),u.jsx("div",{className:"space-y-0.5",children:w.map(N=>{const J=r(N.name),D=(o==null?void 0:o.name)===N.name;return u.jsxs("button",{onClick:()=>a(N),className:G("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",D?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:G("size-1.5 rounded-full flex-none transition-colors",J?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:N.name})]},N.name)})})]},C))})})}),o?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:o.name}),o.version&&u.jsxs(Kt,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",o.version]})]}),o.description&&u.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:o.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(o.name)?"On":"Off"}),u.jsx(va,{checked:r(o.name),onCheckedChange:()=>n(o),disabled:s,"aria-label":`Toggle ${o.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[v(o.location),u.jsx("span",{children:g(o.location)}),u.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),u.jsx("span",{className:"font-mono truncate",children:o.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:()=>f("properties"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(_o,{className:"size-3.5"}),"Properties"]})}),y&&u.jsx("button",{onClick:()=>f("schema"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Mg,{className:"size-3.5"}),"Schema"]})}),j&&u.jsx("button",{onClick:()=>f("examples"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx($g,{className:"size-3.5"}),"Examples",u.jsx(Kt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:o.examples.length})]})})]}),u.jsx(ni,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[d==="properties"&&S&&u.jsx("div",{className:"space-y-1",children:Object.entries(o.schema.properties).map(([C,w])=>u.jsx(lb,{name:C,prop:w},C))}),d==="schema"&&y&&u.jsx(es,{schema:o.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&j&&o.examples.map((C,w)=>u.jsxs("div",{className:G(w>0&&"mt-4 pt-4 border-t"),children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[C.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:C.title}),!C.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),u.jsx(_e,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>h(C,w),children:l===w?u.jsxs(u.Fragment,{children:[u.jsx(Fg,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(ws,{className:"size-3 mr-1"}),"Copy"]})})]}),C.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:C.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(C.props,null,2)})]},w)),!S&&!y&&!j&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(_o,{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 lb({name:e,prop:t}){var o;const[n,r]=x.useState(!1),i=t.description||t.enum||t.default!==void 0||t.items||t.properties,s=t.type||(t.enum?"enum":t.oneOf?"oneOf":"—");return u.jsxs("div",{className:"rounded-md border",children:[u.jsxs("button",{onClick:()=>i&&r(!n),className:G("w-full text-left flex items-center gap-2 px-3 py-2 text-sm",i&&"cursor-pointer hover:bg-muted/50"),children:[i?n?u.jsx(hi,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(Pn,{className:"size-3 text-muted-foreground flex-none"}):u.jsx("span",{className:"size-3 flex-none"}),u.jsx("span",{className:"font-mono font-medium text-xs",children:e}),u.jsx(Kt,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&u.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),u.jsx("span",{className:"flex-1"}),t.default!==void 0&&u.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&u.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&u.jsx("p",{children:t.description}),t.enum&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((a,l)=>u.jsxs("span",{children:[l>0&&", ",u.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(a)})]},l))]}),((o=t.items)==null?void 0:o.type)&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const ub=fg,cb=pg,db=hg,fb={current:"Current directory",downstream:"Project"};function Gs({id:e,label:t,count:n,open:r,onToggle:i,children:s}){return u.jsxs(ub,{open:r,children:[u.jsxs(cb,{onClick:()=>i(e),className:G("flex h-7 w-full cursor-pointer items-center gap-1.5 rounded-sm px-1","text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(Pn,{className:G("size-3 shrink-0 transition-transform duration-150 ease-out",r&&"rotate-90")}),u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:t}),u.jsx("span",{className:"ml-auto text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:n})]}),u.jsx(db,{children:u.jsx("div",{className:"border-sidebar-border/70 mt-0.5 ml-[13px] border-l pl-1",children:s})})]})}function Sl({location:e}){return u.jsx("div",{className:"px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:fb[e]??e})}function _l({name:e,subtitle:t,added:n,query:r,onSelect:i}){return u.jsxs("button",{type:"button",onClick:i,title:t?`${e} — ${t}`:e,"aria-label":n?`Open ${e}`:`Add ${e} to workspace`,className:G("group/row flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","text-sidebar-foreground/70"),children:[u.jsx("span",{className:"truncate",children:u.jsx(ya,{text:e,query:r})}),n?u.jsx("span",{className:"ml-auto shrink-0 text-[10px] tracking-[0.06em] text-sidebar-foreground/65 uppercase",children:"Open"}):u.jsx(nn,{"aria-hidden":!0,className:"ml-auto size-3.5 shrink-0 text-sidebar-foreground/45 opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100"})]})}function pb({documents:e,themes:t,plugins:n,openNames:r,query:i,expandedGroups:s,onToggleGroup:o,onQuickAdd:a,onShowPluginDetails:l,isPluginSelected:c,onTogglePlugin:d,isApplyingPlugins:f,selectedPluginCount:p}){const h=y=>i?!0:s.has(y),g=x.useMemo(()=>jl(e),[e]),v=x.useMemo(()=>jl(t),[t]);return e.length>0||t.length>0||n.length>0?u.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.length>0&&u.jsx(Gs,{id:"library-documents",label:"Project documents",count:e.length,open:h("library-documents"),onToggle:o,children:g.map(([y,j])=>u.jsxs(je.Fragment,{children:[g.length>1&&u.jsx(Sl,{location:y}),j.map(m=>u.jsx(_l,{name:m.name,subtitle:m.title,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!1)},m.path||m.name))]},y))}),t.length>0&&u.jsx(Gs,{id:"library-themes",label:"Project themes",count:t.length,open:h("library-themes"),onToggle:o,children:v.map(([y,j])=>u.jsxs(je.Fragment,{children:[v.length>1&&u.jsx(Sl,{location:y}),j.map(m=>u.jsx(_l,{name:m.name,subtitle:m.description,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!0)},m.path||m.name))]},y))}),n.length>0&&u.jsx(Gs,{id:"library-plugins",label:"Plugins",count:`${p}/${n.length}`,open:h("library-plugins"),onToggle:o,children:n.map(y=>{const j=c(y.name),m=`plugin-switch-${y.filePath||y.name}`;return u.jsxs("div",{title:y.description?`${y.name} — ${y.description}`:y.name,className:G("group/row flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2","transition-colors hover:bg-sidebar-accent/60"),children:[u.jsx("label",{htmlFor:m,className:G("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",j?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(ya,{text:y.name,query:i})})}),u.jsx($t,{"aria-label":`Details for ${y.name}`,onClick:A=>{A.stopPropagation(),l(y.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(Cd,{})}),u.jsx(va,{id:m,checked:j,onCheckedChange:()=>d(y),disabled:f,className:"shrink-0","aria-label":`Toggle ${y.name} plugin`})]},y.filePath||y.name)})})]}):null}function jl(e){const t=["current","downstream"],n=new Map;return e.forEach(r=>{const i=n.get(r.location);i?i.push(r):n.set(r.location,[r])}),[...n.entries()].sort(([r],[i])=>t.indexOf(r)-t.indexOf(i))}function Ef({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:G("pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground","[[data-slot=tooltip-content]_&]:bg-primary-foreground/20 [[data-slot=tooltip-content]_&]:text-primary-foreground",t),children:e})}function hb({children:e,className:t}){return u.jsx("span",{className:G("inline-flex items-center gap-0.5",t),children:e})}const Ei=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function ri({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return Ei?"⌘":"Ctrl";case"shift":return Ei?"⇧":"Shift";case"alt":return Ei?"⌥":"Alt";case"ctrl":return Ei?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(hb,{className:t,children:r.map((i,s)=>u.jsx(Ef,{children:i},s))})}function mb({className:e}={}){const{theme:t,setTheme:n}=vd(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=x.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(_e,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Zg,{className:"hidden dark:block"}),u.jsx(Vg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ye,{children:u.jsx("p",{children:"Toggle theme"})})]})}function gb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:o,openDocument:a}=Ce(da(U=>({documents:U.documents,documentTypes:U.documentTypes,createDocument:U.createDocument,openDocument:U.openDocument}))),l=To(U=>U.updateTheme),c=To(U=>U.removeTheme),d=x.useContext(Od),[f,p]=x.useState(!1),[h,g]=x.useState(!1),[v,S]=x.useState(!1),[y,j]=x.useState(null),m=Bt(U=>U.togglePlugin),A=Bt(U=>U.isPluginSelected),C=Bt(U=>U.selectedPlugins),w=Bt(U=>U.isApplyingPlugins),[N,J]=x.useState(!1),[D,_]=x.useState(new Set(["library-documents"])),[T,I]=x.useState(""),z=x.useRef(null),{toast:O}=jr(),R=i.filter(U=>s[U.name]!=="application/json+theme"),Y=i.filter(U=>s[U.name]==="application/json+theme"),H=x.useCallback(()=>{p(!1)},[]),$=x.useCallback(()=>{g(!1)},[]),ee=x.useRef(new Map);x.useEffect(()=>{const U=ee.current,Te=new Map;Y.forEach(X=>{Te.set(X.name,X.text),U.get(X.name)!==X.text&&l(X.name,X.text)}),U.forEach((X,we)=>{Te.has(we)||c(we)}),ee.current=Te},[Y,l,c]);const k=x.useRef(!1);x.useEffect(()=>{if(k.current||!d)return;k.current=!0;const U=new Set(Y.map(X=>X.name));Object.keys(d.getState().customThemes).forEach(X=>{U.has(X)||c(X)})},[Y,c,d]);const oe=x.useCallback(U=>{_(Te=>{const X=new Set(Te);return X.has(U)?X.delete(U):X.add(U),X})},[]),{resolvedTheme:q}=vd(),b=q==="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",B=x.useCallback(async(U,Te)=>{if(i.some(X=>X.name===U)){a(U);return}try{const X=await fetch(`/api/discovery/${Te?"themes":"documents"}/${encodeURIComponent(U)}/content`);if(!X.ok)throw new Error(X.statusText);const we=await X.text(),E=JSON.parse(we);o(U,JSON.stringify(E,null,2)),a(U),O({title:`Added ${Te?"theme":"document"}: ${U}`})}catch{O({title:"Failed to load",description:`Could not load ${U}`,variant:"destructive"})}},[i,o,a,O]);x.useEffect(()=>{if(n)return;const U=Te=>{var E,M,F,ne,Q;if(Te.key!=="/"||Te.metaKey||Te.ctrlKey||Te.altKey)return;const X=Te.target,we=(E=X==null?void 0:X.tagName)==null?void 0:E.toLowerCase();we==="input"||we==="textarea"||we==="select"||X!=null&&X.isContentEditable||(M=X==null?void 0:X.closest)!=null&&M.call(X,".monaco-editor")||(F=z.current)!=null&&F.closest('[aria-hidden="true"], [inert]')||(Te.preventDefault(),(ne=z.current)==null||ne.focus(),(Q=z.current)==null||Q.select())};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[n]);const V=T.trim(),re=x.useMemo(()=>new Set(i.map(U=>U.name)),[i]),se=x.useMemo(()=>R.filter(U=>cn(U.name,V)),[R,V]),P=x.useMemo(()=>Y.filter(U=>cn(U.name,V)),[Y,V]),ue=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(U=>cn(U.name,V)||cn(U.title??"",V)),[e,V]),he=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(U=>cn(U.name,V)||cn(U.description??"",V)),[e,V]),ce=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(U=>cn(U.name,V)||cn(U.description??"",V)),[e,V]),pe=V.length>0&&se.length===0&&P.length===0&&ue.length===0&&he.length===0&&ce.length===0,me=G("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(yf,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Ro,{className:G("gap-0 p-1.5",me),children:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Td,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(ri,{shortcut:"mod+b"})]})]})}),u.jsxs(Mo,{className:G("gap-2 px-1 py-1",me),children:[u.jsxs(Br,{className:"items-center gap-0.5",children:[R.map(U=>u.jsx(Ni,{document:U,compact:!0},U.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"right",children:"New document"})]})]}),u.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),u.jsxs(Br,{className:"items-center gap-0.5",children:[Y.map(U=>u.jsx(Ni,{document:U,compact:!0},U.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{className:"size-7","aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(Ro,{className:G("gap-0 p-2",me),children:[u.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[u.jsx("a",{href:"/","aria-label":"JSON to Office home",className:"focus-visible:ring-sidebar-ring flex items-center rounded-sm pl-1 focus-visible:ring-1 focus-visible:outline-none",children:u.jsx("img",{src:b,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(Ug,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(ri,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(Jg,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),u.jsx("input",{ref:z,type:"text",value:T,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:U=>I(U.target.value),onKeyDown:U=>{U.key==="Escape"&&(U.preventDefault(),I(""),U.currentTarget.blur())},className:G("border-sidebar-border/70 bg-sidebar-accent/40 h-7 w-full rounded-sm border","pr-7 pl-7 text-[13px] text-sidebar-foreground transition-colors","placeholder:text-sidebar-foreground/60","focus-visible:border-sidebar-ring focus-visible:bg-sidebar-accent/60","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none")}),V?u.jsx($t,{"aria-label":"Clear filter",onClick:()=>{var U;I(""),(U=z.current)==null||U.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(xn,{})}):u.jsx(Ef,{className:"absolute top-1/2 right-1.5 h-4 min-w-4 -translate-y-1/2 bg-transparent px-0 text-[10px] text-sidebar-foreground/65",children:"/"})]})]}),u.jsx(Mo,{className:G("gap-0 px-2 pb-2",me),children:pe?u.jsxs("div",{className:"px-1 py-6 text-center",children:[u.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",V,"”"]}),u.jsx("button",{type:"button",onClick:()=>{var U;I(""),(U=z.current)==null||U.focus()},className:"text-sidebar-foreground/70 hover:text-sidebar-foreground focus-visible:ring-sidebar-ring mt-1 cursor-pointer rounded-sm text-[12px] underline-offset-2 hover:underline focus-visible:ring-1 focus-visible:outline-none",children:"Clear filter"})]}):u.jsxs(u.Fragment,{children:[(se.length>0||!V)&&u.jsxs("section",{children:[u.jsx(Do,{count:(V?se.length:R.length)||void 0,actions:u.jsxs(u.Fragment,{children:[ot==="docx"&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"Compare documents",disabled:R.length<2,onClick:()=>J(!0),children:u.jsx(Sd,{})})}),u.jsx(Ye,{side:"bottom",children:R.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),u.jsx(Br,{className:"gap-0.5",children:se.length>0?se.map(U=>u.jsx(Ni,{document:U,query:V},U.name)):u.jsx(gl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]}),(P.length>0||!V)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Do,{count:(V?P.length:Y.length)||void 0,actions:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"bottom",children:"New theme"})]}),children:"Themes"}),u.jsx(Br,{className:"gap-0.5",children:P.length>0?P.map(U=>u.jsx(Ni,{document:U,query:V},U.name)):u.jsx(gl,{icon:nn,label:"New theme",onClick:()=>g(!0)})})]}),!V&&u.jsx(rb,{}),(ue.length>0||he.length>0||ce.length>0)&&u.jsx("div",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:u.jsx(pb,{documents:ue,themes:he,plugins:ce,openNames:re,query:V,expandedGroups:D,onToggleGroup:oe,onQuickAdd:B,onShowPluginDetails:U=>{j(U),S(!0)},isPluginSelected:A,onTogglePlugin:m,isApplyingPlugins:w,selectedPluginCount:C.size})})]})})]}),u.jsx(bf,{className:G("border-sidebar-border/70 gap-0 border-t p-1.5",me),children:u.jsx("div",{className:G("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(mb,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),u.jsx(Ct,{open:f,onOpenChange:p,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Yi,{mode:"create",shouldReset:!f,postSubmit:H,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(Ct,{open:h,onOpenChange:g,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Yi,{mode:"create",shouldReset:!h,postSubmit:$,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(Ct,{open:v,onOpenChange:U=>{S(U),U||j(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(ab,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:y})})}),u.jsx(vx,{open:N,onOpenChange:J})]})}const Nl=x.memo(gb),xb=x.lazy(()=>wd(()=>import("./editor-ouhvdGgK.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function El(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(sn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(xb,{})})}const yb=x.lazy(()=>wd(()=>import("./preview-D3QYaLPp.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function Cl(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(sn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(yb,{})})}const{createElement:br,createContext:bb,forwardRef:Cf,useCallback:gt,useContext:Tf,useEffect:zn,useImperativeHandle:If,useLayoutEffect:vb,useMemo:wb,useRef:wt,useState:lr}=Fc,Tl=Fc[`useId${Math.random()}`.slice(0,5)],kb=vb,Cs=bb(null);Cs.displayName="PanelGroupContext";const On=kb,Sb=typeof Tl=="function"?Tl:()=>null;let _b=0;function wa(e=null){const t=Sb(),n=wt(e||t||null);return n.current===null&&(n.current=""+_b++),e??n.current}function Af({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:o,maxSize:a,minSize:l,onCollapse:c,onExpand:d,onResize:f,order:p,style:h,tagName:g="div",...v}){const S=Tf(Cs);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:j,getPanelSize:m,getPanelStyle:A,groupId:C,isPanelCollapsed:w,reevaluatePanelConstraints:N,registerPanel:J,resizePanel:D,unregisterPanel:_}=S,T=wa(o),I=wt({callbacks:{onCollapse:c,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:a,minSize:l},id:T,idIsFromProps:o!==void 0,order:p});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:O,constraints:R}=I.current,Y={...R};I.current.id=T,I.current.idIsFromProps=o!==void 0,I.current.order=p,O.onCollapse=c,O.onExpand=d,O.onResize=f,R.collapsedSize=n,R.collapsible=r,R.defaultSize=i,R.maxSize=a,R.minSize=l,(Y.collapsedSize!==R.collapsedSize||Y.collapsible!==R.collapsible||Y.maxSize!==R.maxSize||Y.minSize!==R.minSize)&&N(I.current,Y)}),On(()=>{const O=I.current;return J(O),()=>{_(O)}},[p,T,J,_]),If(s,()=>({collapse:()=>{y(I.current)},expand:O=>{j(I.current,O)},getId(){return T},getSize(){return m(I.current)},isCollapsed(){return w(I.current)},isExpanded(){return!w(I.current)},resize:O=>{D(I.current,O)}}),[y,j,m,w,T,D]);const z=A(I.current,i);return br(g,{...v,children:e,className:t,id:o,style:{...z,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":C,"data-panel-id":T,"data-panel-size":parseFloat(""+z.flexGrow).toFixed(1)})}const zf=Cf((e,t)=>br(Af,{...e,forwardedRef:t}));Af.displayName="Panel";zf.displayName="forwardRef(Panel)";let Fo=null,An=null;function jb(e,t){if(t){const n=(t&Mf)!==0,r=(t&$f)!==0,i=(t&Ff)!==0,s=(t&Lf)!==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 Nb(){An!==null&&(document.head.removeChild(An),Fo=null,An=null)}function Ys(e,t){const n=jb(e,t);Fo!==n&&(Fo=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Of(e){return e.type==="keydown"}function Pf(e){return e.type.startsWith("pointer")}function Df(e){return e.type.startsWith("mouse")}function Ts(e){if(Pf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Df(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function Eb(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Cb(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 Tb(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:zl(e),b:zl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ee(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Al(Il(n.a)),b:Al(Il(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const l=s[a];if(l===o.a)return 1;if(l===o.b)return-1}}return Math.sign(i.a-i.b)}const Ib=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Ab(e){var t;const n=getComputedStyle((t=Rf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function zb(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Ab(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"||Ib.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Il(e){let t=e.length;for(;t--;){const n=e[t];if(Ee(n,"Missing node"),zb(n))return n}return null}function Al(e){return e&&Number(getComputedStyle(e).zIndex)||0}function zl(e){const t=[];for(;e;)t.push(e),e=Rf(e);return t}function Rf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Mf=1,$f=2,Ff=4,Lf=8,Ob=Eb()==="coarse";let Zt=[],ur=!1,mn=new Map,Is=new Map;const ii=new Set;function Pb(e,t,n,r,i){var s;const{ownerDocument:o}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=mn.get(o))!==null&&s!==void 0?s:0;return mn.set(o,l+1),ii.add(a),ts(),function(){var d;Is.delete(e),ii.delete(a);const f=(d=mn.get(o))!==null&&d!==void 0?d:1;if(mn.set(o,f-1),ts(),f===1&&mn.delete(o),Zt.includes(a)){const p=Zt.indexOf(a);p>=0&&Zt.splice(p,1),Sa(),i("up",!0,null)}}}function Ol(e){const{target:t}=e,{x:n,y:r}=Ts(e);ur=!0,ka({target:t,x:n,y:r}),ts(),Zt.length>0&&(ns("down",e),e.preventDefault(),e.stopPropagation())}function Pr(e){const{x:t,y:n}=Ts(e);if(ur&&e.buttons===0&&(ur=!1,ns("up",e)),!ur){const{target:r}=e;ka({target:r,x:t,y:n})}ns("move",e),Sa(),Zt.length>0&&e.preventDefault()}function Jn(e){const{target:t}=e,{x:n,y:r}=Ts(e);Is.clear(),ur=!1,Zt.length>0&&e.preventDefault(),ns("up",e),ka({target:t,x:n,y:r}),Sa(),ts()}function ka({target:e,x:t,y:n}){Zt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),ii.forEach(i=>{const{element:s,hitAreaMargins:o}=i,a=s.getBoundingClientRect(),{bottom:l,left:c,right:d,top:f}=a,p=Ob?o.coarse:o.fine;if(t>=c-p&&t<=d+p&&n>=f-p&&n<=l+p){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&Tb(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(Cb(g.getBoundingClientRect(),a)){v=!0;break}g=g.parentElement}if(v)return}Zt.push(i)}})}function Ks(e,t){Is.set(e,t)}function Sa(){let e=!1,t=!1;Zt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;Is.forEach(r=>{n|=r}),e&&t?Ys("intersection",n):e?Ys("horizontal",n):t?Ys("vertical",n):Nb()}function ts(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Jn),n.removeEventListener("pointerdown",Ol),n.removeEventListener("pointerleave",Pr),n.removeEventListener("pointermove",Pr)}),window.removeEventListener("pointerup",Jn),window.removeEventListener("pointercancel",Jn),ii.size>0&&(ur?(Zt.length>0&&mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Jn),n.addEventListener("pointerleave",Pr),n.addEventListener("pointermove",Pr))}),window.addEventListener("pointerup",Jn),window.addEventListener("pointercancel",Jn)):mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Ol,{capture:!0}),n.addEventListener("pointermove",Pr))}))}function ns(e,t){ii.forEach(n=>{const{setResizeHandlerState:r}=n,i=Zt.includes(n);r(e,i,t)})}function Db(){const[e,t]=lr(0);return gt(()=>t(n=>n+1),[])}function Ee(e,t){if(!e)throw console.error(t),Error(t)}const _a=10;function Rn(e,t,n=_a){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function on(e,t,n=_a){return Rn(e,t,n)===0}function Nt(e,t,n){return Rn(e,t,n)===0}function Rb(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],s=t[r];if(!Nt(i,s,n))return!1}return!0}function nr({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ee(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:o=100,minSize:a=0}=r;if(Rn(n,a)<0)if(s){const l=(i+a)/2;Rn(n,l)<0?n=i:n=a}else n=a;return n=Math.min(o,n),n=parseFloat(n.toFixed(_a)),n}function Zr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Nt(e,0))return t;const o=[...t],[a,l]=r;Ee(a!=null,"Invalid first pivot index"),Ee(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const f=e<0?l:a,p=n[f];Ee(p,`Panel constraints not found for index ${f}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[f];if(Ee(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,h)){const y=v-S;Rn(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const f=e<0?a:l,p=n[f];Ee(p,`No panel constraints found for index ${f}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[f];if(Ee(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,v)){const y=S-h;Rn(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const f=e<0?1:-1;let p=e<0?l:a,h=0;for(;;){const v=t[p];Ee(v!=null,`Previous layout not found for panel index ${p}`);const y=nr({panelConstraints:n,panelIndex:p,size:100})-v;if(h+=y,p+=f,p<0||p>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-g:g}{let p=e<0?a:l;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),g=t[p];Ee(g!=null,`Previous layout not found for panel index ${p}`);const v=g-h,S=nr({panelConstraints:n,panelIndex:p,size:v});if(!Nt(g,S)&&(c+=g-S,o[p]=S,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(Rb(i,o))return i;{const f=e<0?l:a,p=t[f];Ee(p!=null,`Previous layout not found for panel index ${f}`);const h=p+c,g=nr({panelConstraints:n,panelIndex:f,size:h});if(o[f]=g,!Nt(g,h)){let v=h-g,y=e<0?l:a;for(;y>=0&&y<n.length;){const j=o[y];Ee(j!=null,`Previous layout not found for panel index ${y}`);const m=j+v,A=nr({panelConstraints:n,panelIndex:y,size:m});if(Nt(j,A)||(v-=A-j,o[y]=A),Nt(v,0))break;e>0?y--:y++}}}const d=o.reduce((f,p)=>p+f,0);return Nt(d,100)?o:i}function Mb({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,o=0;const a=n[0];Ee(a!=null,"No pivot index found"),t.forEach((f,p)=>{const{constraints:h}=f,{maxSize:g=100,minSize:v=0}=h;p===a?(r=v,i=g):(s+=v,o+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-o),d=e[a];return{valueMax:l,valueMin:c,valueNow:d}}function si(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function Bf(e,t,n=document){const i=si(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Zf(e,t,n){const r=Bf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Vf(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 As(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function $b(e,t,n,r=document){var i,s,o,a;const l=As(t,r),c=si(e,r),d=l?c.indexOf(l):-1,f=(i=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,p=(o=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&o!==void 0?o:null;return[f,p]}function Fb({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:o}){wt({didWarnAboutMissingResizeHandle:!1}),On(()=>{if(!s)return;const a=si(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:d,valueNow:f}=Mb({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=a[l];if(p!=null){const h=i[l];Ee(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(d)),p.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),zn(()=>{if(!s)return;const a=t.current;Ee(a,"Eager values not found");const{panelDataArray:l}=a,c=Vf(n,s);Ee(c!=null,`No group found for id "${n}"`);const d=si(n,s);Ee(d,`No resize handles found for group id "${n}"`);const f=d.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");Ee(h,"Resize handle element has no handle id attribute");const[g,v]=$b(n,h,l,s);if(g==null||v==null)return()=>{};const S=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const j=l.findIndex(m=>m.id===g);if(j>=0){const m=l[j];Ee(m,`No panel data found for index ${j}`);const A=r[j],{collapsedSize:C=0,collapsible:w,minSize:N=0}=m.constraints;if(A!=null&&w){const J=Zr({delta:Nt(A,C)?N-C:C-A,initialLayout:r,panelConstraints:l.map(D=>D.constraints),pivotIndices:Zf(n,h,s),prevLayout:r,trigger:"keyboard"});r!==J&&o(J)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{f.forEach(p=>p())}},[s,e,t,n,r,i,o])}function Pl(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 Uf(e,t){const n=e==="horizontal",{x:r,y:i}=Ts(t);return n?r:i}function Lb(e,t,n,r,i){const s=n==="horizontal",o=As(t,i);Ee(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute("data-panel-group-id");Ee(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=Uf(n,e),d=Vf(a,i);Ee(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),p=s?f.width:f.height;return(c-l)/p*100}function Bb(e,t,n,r,i,s){if(Of(e)){const o=n==="horizontal";let a=0;e.shiftKey?a=100:i!=null?a=i:a=10;let l=0;switch(e.key){case"ArrowDown":l=o?0:a;break;case"ArrowLeft":l=o?-a:0;break;case"ArrowRight":l=o?a:0;break;case"ArrowUp":l=o?0:-a;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:Lb(e,t,n,r,s)}function Zb({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,i=100;for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;a!=null&&(r++,t[s]=a,i-=a)}for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;if(a!=null)continue;const l=e.length-r,c=i/l;r++,t[s]=c,i-=c}return t}function Hn(e,t,n){t.forEach((r,i)=>{const s=e[i];Ee(s,`Panel data not found for index ${i}`);const{callbacks:o,constraints:a,id:l}=s,{collapsedSize:c=0,collapsible:d}=a,f=n[l];if(f==null||r!==f){n[l]=r;const{onCollapse:p,onExpand:h,onResize:g}=o;g&&g(r,f),d&&(p||h)&&(h&&(f==null||on(f,c))&&!on(r,c)&&h(),p&&(f==null||!on(f,c))&&on(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 Vb({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const o=n[i];let a;return o==null?a=e!=null?e.toPrecision(s):"1":r.length===1?a="1":a=o.toPrecision(s),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function Ub(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Dl(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 Jf(e){return`react-resizable-panels:${e}`}function Hf(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 Wf(e,t){try{const n=Jf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Jb(e,t,n){var r,i;const s=(r=Wf(e,n))!==null&&r!==void 0?r:{},o=Hf(t);return(i=s[o])!==null&&i!==void 0?i:null}function Hb(e,t,n,r,i){var s;const o=Jf(e),a=Hf(t),l=(s=Wf(e,i))!==null&&s!==void 0?s:{};l[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(o,JSON.stringify(l))}catch(c){console.error(c)}}function Rl({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,o)=>s+o,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Nt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=100/r*o;n[s]=a}let i=0;for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=nr({panelConstraints:t,panelIndex:s,size:o});o!=a&&(i+=o-a,n[s]=a)}if(!Nt(i,0))for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=o+i,l=nr({panelConstraints:t,panelIndex:s,size:a});if(o!==l&&(i-=l-o,n[s]=l,Nt(i,0)))break}return n}const Wb=100,Vr={getItem:e=>(Dl(Vr),Vr.getItem(e)),setItem:(e,t)=>{Dl(Vr),Vr.setItem(e,t)}},Ml={};function qf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:o=null,keyboardResizeBy:a=null,storage:l=Vr,style:c,tagName:d="div",...f}){const p=wa(s),h=wt(null),[g,v]=lr(null),[S,y]=lr([]),j=Db(),m=wt({}),A=wt(new Map),C=wt(0),w=wt({autoSaveId:e,direction:r,dragState:g,id:p,keyboardResizeBy:a,onLayout:o,storage:l}),N=wt({layout:S,panelDataArray:[],panelDataArrayChanged:!1});wt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),If(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:b}=N.current;return b},setLayout:b=>{const{onLayout:B}=w.current,{layout:V,panelDataArray:re}=N.current,se=Rl({layout:b,panelConstraints:re.map(P=>P.constraints)});Pl(V,se)||(y(se),N.current.layout=se,B&&B(se),Hn(re,se,m.current))}}),[]),On(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=g,w.current.id=p,w.current.onLayout=o,w.current.storage=l}),Fb({committedValuesRef:w,eagerValuesRef:N,groupId:p,layout:S,panelDataArray:N.current.panelDataArray,setLayout:y,panelGroupElement:h.current}),zn(()=>{const{panelDataArray:b}=N.current;if(e){if(S.length===0||S.length!==b.length)return;let B=Ml[e];B==null&&(B=Ub(Hb,Wb),Ml[e]=B);const V=[...b],re=new Map(A.current);B(e,V,re,S,l)}},[e,S,l]),zn(()=>{});const J=gt(b=>{const{onLayout:B}=w.current,{layout:V,panelDataArray:re}=N.current;if(b.constraints.collapsible){const se=re.map(ce=>ce.constraints),{collapsedSize:P=0,panelSize:ue,pivotIndices:he}=jn(re,b,V);if(Ee(ue!=null,`Panel size not found for panel "${b.id}"`),!on(ue,P)){A.current.set(b.id,ue);const pe=Xn(re,b)===re.length-1?ue-P:P-ue,me=Zr({delta:pe,initialLayout:V,panelConstraints:se,pivotIndices:he,prevLayout:V,trigger:"imperative-api"});Ci(V,me)||(y(me),N.current.layout=me,B&&B(me),Hn(re,me,m.current))}}},[]),D=gt((b,B)=>{const{onLayout:V}=w.current,{layout:re,panelDataArray:se}=N.current;if(b.constraints.collapsible){const P=se.map(U=>U.constraints),{collapsedSize:ue=0,panelSize:he=0,minSize:ce=0,pivotIndices:pe}=jn(se,b,re),me=B??ce;if(on(he,ue)){const U=A.current.get(b.id),Te=U!=null&&U>=me?U:me,we=Xn(se,b)===se.length-1?he-Te:Te-he,E=Zr({delta:we,initialLayout:re,panelConstraints:P,pivotIndices:pe,prevLayout:re,trigger:"imperative-api"});Ci(re,E)||(y(E),N.current.layout=E,V&&V(E),Hn(se,E,m.current))}}},[]),_=gt(b=>{const{layout:B,panelDataArray:V}=N.current,{panelSize:re}=jn(V,b,B);return Ee(re!=null,`Panel size not found for panel "${b.id}"`),re},[]),T=gt((b,B)=>{const{panelDataArray:V}=N.current,re=Xn(V,b);return Vb({defaultSize:B,dragState:g,layout:S,panelData:V,panelIndex:re})},[g,S]),I=gt(b=>{const{layout:B,panelDataArray:V}=N.current,{collapsedSize:re=0,collapsible:se,panelSize:P}=jn(V,b,B);return Ee(P!=null,`Panel size not found for panel "${b.id}"`),se===!0&&on(P,re)},[]),z=gt(b=>{const{layout:B,panelDataArray:V}=N.current,{collapsedSize:re=0,collapsible:se,panelSize:P}=jn(V,b,B);return Ee(P!=null,`Panel size not found for panel "${b.id}"`),!se||Rn(P,re)>0},[]),O=gt(b=>{const{panelDataArray:B}=N.current;B.push(b),B.sort((V,re)=>{const se=V.order,P=re.order;return se==null&&P==null?0:se==null?-1:P==null?1:se-P}),N.current.panelDataArrayChanged=!0,j()},[j]);On(()=>{if(N.current.panelDataArrayChanged){N.current.panelDataArrayChanged=!1;const{autoSaveId:b,onLayout:B,storage:V}=w.current,{layout:re,panelDataArray:se}=N.current;let P=null;if(b){const he=Jb(b,se,V);he&&(A.current=new Map(Object.entries(he.expandToSizes)),P=he.layout)}P==null&&(P=Zb({panelDataArray:se}));const ue=Rl({layout:P,panelConstraints:se.map(he=>he.constraints)});Pl(re,ue)||(y(ue),N.current.layout=ue,B&&B(ue),Hn(se,ue,m.current))}}),On(()=>{const b=N.current;return()=>{b.layout=[]}},[]);const R=gt(b=>{let B=!1;const V=h.current;return V&&window.getComputedStyle(V,null).getPropertyValue("direction")==="rtl"&&(B=!0),function(se){se.preventDefault();const P=h.current;if(!P)return()=>null;const{direction:ue,dragState:he,id:ce,keyboardResizeBy:pe,onLayout:me}=w.current,{layout:U,panelDataArray:Te}=N.current,{initialLayout:X}=he??{},we=Zf(ce,b,P);let E=Bb(se,b,ue,he,pe,P);const M=ue==="horizontal";M&&B&&(E=-E);const F=Te.map(te=>te.constraints),ne=Zr({delta:E,initialLayout:X??U,panelConstraints:F,pivotIndices:we,prevLayout:U,trigger:Of(se)?"keyboard":"mouse-or-touch"}),Q=!Ci(U,ne);(Pf(se)||Df(se))&&C.current!=E&&(C.current=E,!Q&&E!==0?M?Ks(b,E<0?Mf:$f):Ks(b,E<0?Ff:Lf):Ks(b,0)),Q&&(y(ne),N.current.layout=ne,me&&me(ne),Hn(Te,ne,m.current))}},[]),Y=gt((b,B)=>{const{onLayout:V}=w.current,{layout:re,panelDataArray:se}=N.current,P=se.map(U=>U.constraints),{panelSize:ue,pivotIndices:he}=jn(se,b,re);Ee(ue!=null,`Panel size not found for panel "${b.id}"`);const pe=Xn(se,b)===se.length-1?ue-B:B-ue,me=Zr({delta:pe,initialLayout:re,panelConstraints:P,pivotIndices:he,prevLayout:re,trigger:"imperative-api"});Ci(re,me)||(y(me),N.current.layout=me,V&&V(me),Hn(se,me,m.current))},[]),H=gt((b,B)=>{const{layout:V,panelDataArray:re}=N.current,{collapsedSize:se=0,collapsible:P}=B,{collapsedSize:ue=0,collapsible:he,maxSize:ce=100,minSize:pe=0}=b.constraints,{panelSize:me}=jn(re,b,V);me!=null&&(P&&he&&on(me,se)?on(se,ue)||Y(b,ue):me<pe?Y(b,pe):me>ce&&Y(b,ce))},[Y]),$=gt((b,B)=>{const{direction:V}=w.current,{layout:re}=N.current;if(!h.current)return;const se=As(b,h.current);Ee(se,`Drag handle element not found for id "${b}"`);const P=Uf(V,B);v({dragHandleId:b,dragHandleRect:se.getBoundingClientRect(),initialCursorPosition:P,initialLayout:re})},[]),ee=gt(()=>{v(null)},[]),k=gt(b=>{const{panelDataArray:B}=N.current,V=Xn(B,b);V>=0&&(B.splice(V,1),delete m.current[b.id],N.current.panelDataArrayChanged=!0,j())},[j]),oe=wb(()=>({collapsePanel:J,direction:r,dragState:g,expandPanel:D,getPanelSize:_,getPanelStyle:T,groupId:p,isPanelCollapsed:I,isPanelExpanded:z,reevaluatePanelConstraints:H,registerPanel:O,registerResizeHandle:R,resizePanel:Y,startDragging:$,stopDragging:ee,unregisterPanel:k,panelGroupElement:h.current}),[J,g,r,D,_,T,p,I,z,H,O,R,Y,$,ee,k]),q={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return br(Cs.Provider,{value:oe},br(d,{...f,children:t,className:n,id:s,ref:h,style:{...q,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const Gf=Cf((e,t)=>br(qf,{...e,forwardedRef:t}));qf.displayName="PanelGroup";Gf.displayName="forwardRef(PanelGroup)";function Xn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function jn(e,t,n){const r=Xn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],o=n[r];return{...t.constraints,panelSize:o,pivotIndices:s}}function qb({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){zn(()=>{if(e||n==null||r==null)return;const i=As(t,r);if(i==null)return;const s=o=>{if(!o.defaultPrevented)switch(o.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{o.preventDefault(),n(o);break}case"F6":{o.preventDefault();const a=i.getAttribute("data-panel-group-id");Ee(a,`No group element found for id "${a}"`);const l=si(a,r),c=Bf(a,t,r);Ee(c!==null,`No resize element found for id "${t}"`);const d=o.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[d].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function Yf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:o,onFocus:a,style:l={},tabIndex:c=0,tagName:d="div",...f}){var p,h;const g=wt(null),v=wt({onDragging:o});zn(()=>{v.current.onDragging=o});const S=Tf(Cs);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:y,groupId:j,registerResizeHandle:m,startDragging:A,stopDragging:C,panelGroupElement:w}=S,N=wa(i),[J,D]=lr("inactive"),[_,T]=lr(!1),[I,z]=lr(null),O=wt({state:J});On(()=>{O.current.state=J}),zn(()=>{if(n)z(null);else{const $=m(N);z(()=>$)}},[n,N,m]);const R=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,Y=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return zn(()=>{if(n||I==null)return;const $=g.current;return Ee($,"Element ref not attached"),Pb(N,$,y,{coarse:R,fine:Y},(k,oe,q)=>{if(oe)switch(k){case"down":{D("drag"),Ee(q,'Expected event to be defined for "down" action'),A(N,q);const{onDragging:b}=v.current;b&&b(!0);break}case"move":{const{state:b}=O.current;b!=="drag"&&D("hover"),Ee(q,'Expected event to be defined for "move" action'),I(q);break}case"up":{D("hover"),C();const{onDragging:b}=v.current;b&&b(!1);break}}else D("inactive")})},[R,y,n,Y,m,N,I,A,C]),qb({disabled:n,handleId:N,resizeHandler:I,panelGroupElement:w}),br(d,{...f,children:e,className:t,id:i,onBlur:()=>{T(!1),s==null||s()},onFocus:()=>{T(!0),a==null||a()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":y,"data-panel-group-id":j,"data-resize-handle":"","data-resize-handle-active":J==="drag"?"pointer":_?"keyboard":void 0,"data-resize-handle-state":J,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":N})}Yf.displayName="PanelResizeHandle";const Gb=({className:e,...t})=>u.jsx(Gf,{className:G("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Xs=zf,$l=({withHandle:e,className:t,...n})=>u.jsx(Yf,{className:G("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-none data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&u.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:u.jsx(Hg,{className:"h-2.5 w-2.5"})})}),Kf=x.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:G("flex min-h-[80px] w-full rounded-sm border border-input bg-background px-3 py-2 text-sm shadow-xs","placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Kf.displayName="Textarea";class Yb{constructor(t){el(this,"client");this.client=hx.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 Kb=new Yb;function Xb(){const e=x.useRef(null),t=x.useCallback(async(r,i,s,o,a)=>{e.current&&e.current.abort();const l=new AbortController;e.current=l;try{o==null||o("parsing","Validating JSON structure...");let c;try{c=JSON.parse(i)}catch(w){throw new Error(`Invalid JSON: ${w instanceof Error?w.message:"Unknown parse error"}`)}o==null||o("building",`Building ${_i.toLowerCase()} structure...`);const d={jsonDefinition:c,options:{...a,sourceName:r}};d.customThemes=s??{},o==null||o("rendering",`Generating ${ot.toUpperCase()} content...`);const f={"Content-Type":"application/json"};a!=null&&a.bypassCache&&(f["X-Bypass-Cache"]="true");const p=await fetch(Ji.generate,{method:"POST",headers:f,body:JSON.stringify(d),signal:l.signal}),h=await p.json();if(!p.ok||!h.success){const w=h.error||h.message||`API request failed with status: ${p.status}`;throw new Error(w)}const{data:g,cache:v,warnings:S}=h,y=v.status==="HIT"?"HIT":v.status==="MISS"?"MISS":"UNKNOWN",j=y==="HIT"?`Served from cache (Hit rate: ${v.hitRate})`:`Generated fresh ${_i.toLowerCase()}`;o==null||o("finalizing",j);const m=globalThis.atob(g.document),A=new Uint8Array(m.length);for(let w=0;w<m.length;w++)A[w]=m.charCodeAt(w);const C=new Blob([A],{type:g.contentType});if(C.size===0)throw new Error(`Received empty ${_i.toLowerCase()} from API`);return{name:r,text:i,blob:C,filename:g.filename,fileId:g.fileId,cacheStatus:y,cacheHitRate:v.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${_i} generation was cancelled`):c}finally{e.current===l&&(e.current=null)}},[]),n=x.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:t,generateDocument:t,cancelGeneration:n}}function Qb(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const o of i){let a=o.message;if(o.context&&Object.keys(o.context).length>0){const l=Object.entries(o.context).map(([c,d])=>`${c}: ${JSON.stringify(d)}`).join(", ");a+=` (${l})`}s.push(a)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function ev({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=je.useState("custom");je.useEffect(()=>{e&&s("custom")},[e]);const o=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),a=[{value:"custom",title:"Keep custom fonts",desc:"Recipients with the font installed see the authored typeface. Others get a generic fallback."},{value:"substitute",title:"Convert to safe fonts",desc:"Rewrite non-safe families to Calibri / Georgia / Consolas so every recipient sees the same glyphs."}];return u.jsx(Ct,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(kt,{className:"max-w-md",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Non-safe fonts in this document"}),u.jsxs(an,{children:[o," ",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:a.map(l=>{const c=i===l.value;return u.jsxs("button",{type:"button",onClick:()=>s(l.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${c?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${c?"border-primary":"border-muted-foreground/50"}`,children:c&&u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),u.jsx("span",{className:"text-sm font-medium",children:l.title})]}),u.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:l.desc})]},l.value)})}),u.jsxs(bn,{children:[u.jsx(_e,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(_e,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const Fl=ot==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],Qs={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function tv({name:e,blob:t,displayReloadButton:n,iframeRef:r,autoReload:i,onToggleAutoReload:s,onManualRender:o,isGenerating:a,isRendering:l,onShowCacheMetrics:c,onShowSchemas:d,onShowFonts:f,documentText:p,editorDocumentText:h,warnings:g,renderingLibrary:v,setRenderingLibrary:S,onToggleChat:y,chatOpen:j,onTogglePreview:m,previewOpen:A}){const C=v!=="docxjs",[w,N]=x.useState(!1),[J,D]=x.useState(!1),[_,T]=x.useState(!1),[I,z]=x.useState(!1),[O,R]=x.useState(!1),[Y,H]=x.useState(!1),[$,ee]=x.useState(null),{toast:k}=jr(),{generateDocument:oe}=Xb(),q=x.useContext(Od),b=x.useCallback(()=>{const X={},{customThemes:we}=q.getState();return Object.values(we).forEach(E=>{E.valid&&E.parsed&&(X[E.name]=E.parsed)}),X},[q]),B=je.useMemo(()=>{if(!p)return[];try{const X=JSON.parse(p);return[...(ot==="pptx"?vg:wg)(X)].filter(E=>!kg(E))}catch{return[]}},[p]),[V,re]=x.useState(!1),se=x.useCallback(async()=>{if(t){N(!0);try{await new Promise(X=>setTimeout(X,100)),Li(`${e}${Ir}`,t)}finally{setTimeout(()=>N(!1),500)}}},[t,e]),P=x.useCallback(async()=>{if(t){if(B.length===0){await se();return}re(!0)}},[t,B.length,se]),ue=x.useCallback(async X=>{var we;if(p){N(!0);try{const E=await oe(e,p,b(),void 0,{bypassCache:!0,fonts:{mode:X}});if(E.blob.size===0)k({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Li(`${e}${Ir}`,E.blob);const M=(we=E.warnings)==null?void 0:we.find(F=>{var ne,Q;return((ne=F.context)==null?void 0:ne.code)==="FONT_MODE_SUBSTITUTED"||((Q=F.context)==null?void 0:Q.code)==="FONT_MODE_CUSTOM"});M&&k({title:X==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:M.message})}}catch(E){k({title:"Export failed",description:E instanceof Error?E.message:String(E),variant:"destructive"})}finally{setTimeout(()=>N(!1),500)}}},[p,e,oe,k,b]),he=x.useCallback(async()=>{if(!(!g||g.length===0)){D(!0);try{const X=Qb(g);if(!X){k({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const we=await oe("warnings",JSON.stringify(X,null,2),{});we&&typeof we=="object"&&"blob"in we&&we.blob&&(Li(`${e}-warnings${Ir}`,we.blob),k({title:"Warnings downloaded",description:`Downloaded warnings document with ${g.length} warning(s).`}))}catch(X){console.error("Failed to generate warnings document:",X),k({title:"Download failed",description:X instanceof Error?X.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>D(!1),500)}}},[g,e,oe,k]),ce=x.useCallback(async()=>{const X=r==null?void 0:r.current;if(X!=null&&X.src){T(!0);try{await new Promise(E=>{let M=null,F=!1;const ne=()=>{M&&(clearTimeout(M),M=null),X.removeEventListener("load",te),X.removeEventListener("error",de)},Q=()=>{F||(F=!0,ne(),E())},te=()=>Q(),de=()=>Q();X.addEventListener("load",te),X.addEventListener("error",de),M=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),Q()},5e3);const ve=X.src,Z=ve.includes("?")?"&":"?",K=Date.now();X.src=`${ve}${Z}_reload=${K}`})}catch(we){console.error("Iframe reload failed:",we)}finally{T(!1)}}},[r]),pe=x.useCallback(async()=>{z(!0);try{await Kb.delete(`/${ot}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),k({title:"Cache Cleared",description:"All caches (document and component) have been successfully cleared.",variant:"default"})}catch(X){console.error("Failed to clear cache:",X),k({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{z(!1)}},[k]),me=h??p,U=x.useCallback(()=>{var E,M;if(!me){k({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(me)}catch{k({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}H(!0);const X=(async()=>{const F=await fetch(`/api/${ot}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:me,customThemes:b(),options:{sourceName:e}})});if(!F.ok){let Q=`Request failed with status ${F.status}`;try{const te=await F.json(),de=te.error??te.message;typeof de=="string"&&de&&(Q=de)}catch{}throw new Error(Q)}const ne=await F.json();return JSON.stringify(ne.data,null,2)})();let we;typeof ClipboardItem<"u"&&((E=navigator.clipboard)!=null&&E.write)?we=navigator.clipboard.write([new ClipboardItem({"text/plain":X.then(F=>new Blob([F],{type:"text/plain"}))})]):(M=navigator.clipboard)!=null&&M.writeText?we=X.then(F=>navigator.clipboard.writeText(F)):we=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await we,k({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(F){let ne=null;try{ne=await X}catch(Q){console.error("Error fetching standard components:",Q),k({title:"Failed to get standard components",description:Q instanceof Error?Q.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",F),ee(ne)}finally{H(!1)}})()},[me,e,b,k]),Te=x.useCallback(async()=>{if($!=null)try{await navigator.clipboard.writeText($),k({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),ee(null)}catch{k({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[$,k]);return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"bg-sidebar border-b flex flex-row flex-nowrap items-center justify-between gap-x-2 px-3 py-1.5",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[u.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),u.jsxs(qe,{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-sm hover:bg-muted/60 shrink-0",children:u.jsx(Cd,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Ye,{className:"max-w-sm",children:u.jsxs("p",{className:"text-sm",children:["Preview uses"," ",ot==="docx"?"docx-preview":"LibreOffice PDF conversion",". Download the ",Ir," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[(!i||C)&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(_e,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:o,"aria-label":"Render preview",disabled:a||l||A===!1,children:[l?u.jsx(sn,{size:"sm"}):u.jsx(Wg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Ye,{children:u.jsx("p",{children:A===!1?"Open preview to run":l?"Rendering preview...":"Render preview"})})]}),ot==="docx"&&u.jsxs(qe,{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(sr,{className:"text-xs text-muted-foreground hidden sm:inline",children:"Auto"}),u.jsx(va,{checked:i,onCheckedChange:s,disabled:C})]})}),u.jsx(Ye,{children:u.jsx("p",{children:C?"Auto-reload is not available for Office, Docs, and LibreOffice renderers":`${i?"Disable":"Enable"} automatic preview reload on content changes`})})]}),n&&i&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:ce,disabled:_||a||l,children:_?u.jsx(sn,{size:"sm"}):u.jsx(qg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsx("p",{children:_?"Reloading...":"Reload"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(_e,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||w||a,onClick:P,children:[w?u.jsx(sn,{size:"sm"}):u.jsx(Gg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Ye,{children:u.jsxs("p",{children:["Download ",Ir]})})]}),g&&g.length>0&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:J||a,onClick:he,children:J?u.jsx(sn,{size:"sm"}):u.jsx(Id,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("p",{children:["Download warnings (",g.length,")"]})})]}),v&&S&&u.jsxs(ei,{value:v,onValueChange:S,children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(hr,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(ti,{placeholder:"Renderer"})})}),u.jsx(Ye,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(mr,{className:"text-sidebar-foreground",children:Fl.map(X=>u.jsxs(Dn,{value:X,children:[u.jsxs(qe,{children:[u.jsx(Ge,{tabIndex:-1,children:Qs[X][0]}),u.jsx(Ye,{children:Qs[X][1]})]})," ",X]},X))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(js,{children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ns,{asChild:!0,children:u.jsx(_e,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Nd,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ye,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(xi,{align:"end",className:"w-52",children:[d&&u.jsxs(Ft,{onClick:d,children:[u.jsx(Yg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),f&&u.jsxs(Ft,{onClick:f,children:[u.jsx(jo,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Ft,{onClick:c,children:[u.jsx(No,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),me?u.jsxs(Ft,{onClick:U,disabled:Y,children:[u.jsx(Eo,{className:"h-4 w-4 mr-2"}),Y?"Copying...":"Copy standard components"]}):u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs(Ft,{disabled:!0,children:[u.jsx(Eo,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),u.jsx(Ye,{side:"left",children:u.jsx("p",{children:"No document selected — open or select a document first"})})]}),u.jsx(xr,{}),u.jsxs(Ft,{onClick:()=>R(!0),disabled:I,className:"text-destructive focus:text-destructive",children:[u.jsx(ca,{className:"h-4 w-4 mr-2"}),I?"Clearing...":"Clear all caches"]}),v&&S&&u.jsxs(u.Fragment,{children:[u.jsx(xr,{className:"lg:hidden"}),Fl.map(X=>u.jsxs(Ft,{className:"lg:hidden",onClick:()=>S(X),children:[u.jsx("span",{className:"mr-2",children:v===X?"●":"○"}),Qs[X][0]," ",X]},X))]})]})]}),m&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:A?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:m,children:A?u.jsx(Ad,{className:"h-3.5 w-3.5"}):u.jsx(Kg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[A?"Hide":"Show"," Preview"," ",u.jsx(ri,{shortcut:"mod+shift+p"})]})})]}),y&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:j?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:y,children:u.jsx(zd,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[j?"Close":"Open"," AI Chat"," ",u.jsx(ri,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(ev,{open:V,onClose:()=>re(!1),nonSafeFonts:B,onChoose:ue}),u.jsx(Ct,{open:$!=null,onOpenChange:X=>{X||ee(null)},children:u.jsxs(kt,{className:"max-w-lg",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Standard components"}),u.jsx(an,{children:"The browser blocked the automatic clipboard write. Copy the JSON from here instead."})]}),u.jsx(Kf,{readOnly:!0,value:$??"",className:"h-64 font-mono text-xs",onFocus:X=>X.currentTarget.select()}),u.jsxs(bn,{children:[u.jsx(_e,{variant:"outline",size:"sm",onClick:()=>ee(null),children:"Close"}),u.jsx(_e,{size:"sm",onClick:Te,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:O,onOpenChange:R,children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Clear all caches?"}),u.jsx(an,{children:"This will clear the document, component, and rasterized-visual caches. Next generation will be uncached."})]}),u.jsxs(bn,{children:[u.jsx(_e,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),u.jsx(_e,{variant:"destructive",size:"sm",disabled:I,onClick:async()=>{await pe(),R(!1)},children:I?u.jsx(sn,{size:"sm"}):"Clear"})]})]})})]})}const nv=je.memo(tv),Xf=mg,ja=x.forwardRef(({className:e,...t},n)=>u.jsx(xd,{ref:n,className:G("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));ja.displayName=xd.displayName;const cr=x.forwardRef(({className:e,...t},n)=>u.jsx(yd,{ref:n,className:G("ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex cursor-pointer items-center justify-center rounded-sm px-3 py-1 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",e),...t}));cr.displayName=yd.displayName;const dr=x.forwardRef(({className:e,...t},n)=>u.jsx(bd,{ref:n,className:G("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));dr.displayName=bd.displayName;async function rv(e){if(navigator.clipboard&&navigator.clipboard.writeText)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="2em",t.style.height="2em",t.style.padding="0",t.style.border="none",t.style.outline="none",t.style.boxShadow="none",t.style.background="transparent",document.body.appendChild(t),t.focus(),t.select();const n=document.execCommand("copy");return document.body.removeChild(t),n}catch(t){return console.error("Failed to copy text to clipboard:",t),!1}}function iv(e){try{const t=typeof e=="string"?JSON.parse(e):e;return JSON.stringify(t,null,2)}catch(t){return console.error("Failed to format schema:",t),typeof e=="string"?e:JSON.stringify(e)}}async function sv(e){const t=iv(e);return rv(t)}const ov=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=x.useState(n),[s,o]=x.useState(null),[a,l]=x.useState(null),[c,d]=x.useState(!1),[f,p]=x.useState(!1),[h,g]=x.useState(null),[v,S]=x.useState(null),[y,j]=x.useState(!1),{toast:m}=jr(),A=Bt(z=>z.selectedPlugins),C=Array.from(A);x.useEffect(()=>{n&&i(n)},[n]);const w=x.useCallback(async()=>{d(!0),g(null);try{const z=await Zs.fetchDocumentSchema(C);o(z)}catch(z){const O=z instanceof Error?z.message:"Failed to load document schema";g(O),m({variant:"destructive",title:"Error loading schema",description:O})}finally{d(!1)}},[C,m]),N=x.useCallback(async()=>{if(!a){p(!0),S(null);try{const z=await Zs.fetchThemeSchema();l(z)}catch(z){const O=z instanceof Error?z.message:"Failed to load theme schema";S(O),m({variant:"destructive",title:"Error loading schema",description:O})}finally{p(!1)}}},[a,m]),[J,D]=x.useState([]);x.useEffect(()=>{e||(o(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const z=C.length!==J.length||C.some((O,R)=>O!==J[R]);r==="document"?(!s||z)&&(z&&(Zs.clearPluginSchemaCache(),D([...C])),c||w()):r==="theme"&&!a&&!f&&N()},[r,e,s,a,c,f,C,J,w,N]);const _=C.length,T=r==="document"?s:a,I=async()=>{if(T)try{await sv(T)&&(j(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>j(!1),2e3))}catch(z){console.error("Copy failed:",z)}};return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:"Schema Viewer"})}),u.jsxs(Xf,{value:r,onValueChange:z=>i(z),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ja,{children:[u.jsxs(cr,{value:"document",className:"flex items-center gap-1",children:["Document",_>0&&u.jsxs(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",_]})]}),u.jsx(cr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(_e,{variant:"ghost",size:"icon",onClick:I,disabled:y||!T,"aria-label":"Copy schema",children:y?u.jsx(yn,{className:"h-4 w-4"}):u.jsx(ws,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(dr,{value:"document",className:"h-full",children:u.jsx(es,{schema:s,loading:c,error:h||void 0})}),u.jsx(dr,{value:"theme",className:"h-full",children:u.jsx(es,{schema:a,loading:f,error:v||void 0})})]})]})]})})};function Qf(e,t,n){if(t.length===0)return n;const r=Ll(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const o=t[s],a=t[s+1],l=i[o],c=Ll(l,a);i[o]=c,i=c}return i[t[t.length-1]]=n,r}function Ll(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Bl=2*1024*1024,Zl=12*1024*1024;function av(e){if(e.length<4)return"unknown";const[t,n,r,i]=e;return t===0&&n===1&&r===0&&i===0||t===116&&n===114&&r===117&&i===101||t===116&&n===116&&r===99&&i===102?"ttf":t===79&&n===84&&r===84&&i===79?"otf":t===119&&n===79&&r===70&&i===70?"woff":t===119&&n===79&&r===70&&i===50?"woff2":"unknown"}function lv(e){let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function rs(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.round(e/1024)} KB`}function uv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>Bl)return{ok:!1,message:`"${e}" is ${rs(t.length)}. The limit is ${rs(Bl)} per font, because the bytes travel inside the document JSON.`};const n=av(t);return n==="woff"||n==="woff2"?{ok:!1,message:`"${e}" is a ${n.toUpperCase()} file. Upload the TTF or OTF instead — the preview renderer cannot register web font formats.`}:n!=="ttf"&&n!=="otf"?{ok:!1,message:`"${e}" does not look like a TTF or OTF font file.`}:{ok:!0,format:n,base64:lv(t)}}const cv=new Set(["italic","oblique"]);function dv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[o,a]of Object.entries(kd))r.set(a.toLowerCase(),Number(o));let i=400,s=!1;for(;n.length>1;){const o=n[n.length-1].toLowerCase();if(cv.has(o)){s=!0,n.pop();continue}const a=r.get(o);if(a!==void 0){i=a,n.pop();continue}break}return{family:n.join(" ")||t,weight:i,italic:s}}function fv(e,t){const n=Array.isArray(e)?[...e]:[],r=n.findIndex(i=>{var s;return((s=i==null?void 0:i.family)==null?void 0:s.toLowerCase())===t.family.toLowerCase()});return r>=0?n[r]=t:n.push(t),n}function pv(e){return e.kind==="safe"||e.kind==="google"?null:{weight:"weight"in e&&e.weight?e.weight:400,italic:"italic"in e?!!e.italic:!1}}function hv(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(a=>{const l=pv(a);return l?!n.some(c=>c.weight===l.weight&&c.italic===l.italic):!0}),s=n.map(a=>({kind:"data",data:a.data,weight:a.weight,italic:a.italic})),o=r??(e==null?void 0:e.category);return{id:(e==null?void 0:e.id)??t,family:t,...o?{category:o}:{},sources:[...i,...s]}}function mv(e,t){let n=Array.isArray(e)?[...e]:[];for(const r of t){const i=r.sources.filter(o=>o.kind==="data").map(o=>({data:o.data,weight:o.weight??400,italic:o.italic??!1}));if(i.length===0)continue;const s=n.find(o=>{var a;return((a=o==null?void 0:o.family)==null?void 0:a.toLowerCase())===r.family.toLowerCase()});n=fv(n,hv(s,r.family,i,r.category))}return n}function gv(e,t){const n=(e.sources??[]).filter(r=>r.format==="ttf"||r.format==="otf").map(r=>({kind:"data",data:r.data,weight:r.weight,italic:r.italic}));return n.length===0?null:{id:e.family,family:e.family,...t?{category:t}:{},sources:n}}function xv(e){const t=new TextEncoder().encode(e).length;return t<=Zl?null:`Adding this font would push the document to ${rs(t)}, past the ${rs(Zl)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const Vl=new Set,yv=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function bv(e){const t=e.startsWith("data:")?e.slice(e.indexOf(",")+1):e,n=atob(t),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r}async function vv(e,t,n,r){const i=yv(e,n,r);if(!Vl.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=bv(t),o=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await o.load(),document.fonts.add(o),Vl.add(i)}catch{}}const wv={safe:[],google:[]};function Ul(e,t){var d;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((d=r==null?void 0:r.dataset.weights)==null?void 0:d.split(",").map(Number).filter(f=>!Number.isNaN(f)))??[]),o=new Set([...s,...i]);if(r&&o.size===s.size)return;const a=[...o].sort((f,p)=>f-p).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${a}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...o].sort((f,p)=>f-p).join(",")}function kv(){const e=Ce(i=>i.activeTab),t=Ce(i=>i.documents),n=Ce(i=>i.documentTypes),r=Ce(i=>i.saveDocument);return x.useCallback(i=>{if(!e)return{ok:!1,error:"No active file"};if(n[e]!=="application/json+theme")return{ok:!1,error:"Fonts are registered on themes, not documents. Open a .theme.json file and try again."};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active theme not found"};let o;try{o=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active theme is not valid JSON: ${l.message}`}}const a=i(o);return r(e,JSON.stringify(a,null,2)),{ok:!0,name:e}},[e,t,n,r])}function Sv(){const e=Ce(r=>r.activeTab),t=Ce(r=>r.documents),n=Ce(r=>r.saveDocument);return x.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active document not found"};let o;try{o=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active document is not valid JSON: ${l.message}`}}const a=Qf(o,r,i);return n(e,JSON.stringify(a,null,2)),{ok:!0,name:e}},[e,t,n])}function _v(){const e=Ce(i=>i.activeTab),t=Ce(i=>i.documents),n=Ce(i=>i.documentTypes),r=Ce(i=>i.saveDocument);return x.useCallback(i=>{var f;if(i.length===0)return{ok:!0,name:e};if(!e)return{ok:!1,error:"No active file"};if(n[e]==="application/json+theme")return{ok:!1,error:"Custom fonts are registered on the document, not the theme. Open the .docx.json / .pptx.json tab and try again."};const s=t.find(p=>p.name===e);if(!s)return{ok:!1,error:"Active document not found"};let o;try{o=JSON.parse(s.text)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const a=mv((f=o==null?void 0:o.props)==null?void 0:f.fontRegistry,i),l=Qf(o,["props","fontRegistry"],a),c=JSON.stringify(l,null,2),d=xv(c);return d?{ok:!1,error:d}:(r(e,c),{ok:!0,name:e})},[e,t,n,r])}function jv(e,t,n){(!e.fonts||typeof e.fonts!="object")&&(e.fonts={});const r=e.fonts[t];r&&typeof r=="object"?e.fonts[t]={...r,family:n}:e.fonts[t]=n}function Jl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Nv=({open:e,onOpenChange:t})=>{const n=$i(P=>P.open),r=$i(P=>P.contextual),i=$i(P=>P.close),s=e??n,o=r,a=x.useCallback(P=>{t&&t(P),P||i()},[t,i]),[l,c]=x.useState(wv),[d,f]=x.useState(!1),[p,h]=x.useState(""),[g,v]=x.useState("safe"),[S,y]=x.useState(null),[j,m]=x.useState(null),[A,C]=x.useState(!1),[w,N]=x.useState(!1),[J,D]=x.useState(""),[_,T]=x.useState([]),I=x.useRef(null),{toast:z}=jr(),O=kv(),R=Sv(),Y=_v(),H=Ce(P=>P.activeTab),$=Ce(P=>P.documentTypes),ee=H&&$[H]==="application/json+theme",k=!!o||ee;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(f(!0),fetch(Ji.fonts.catalog).then(P=>P.json()).then(P=>c(P)).catch(P=>{z({variant:"destructive",title:"Font catalog unavailable",description:P.message})}).finally(()=>f(!1))))},[s,l,z]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const P of l.google)Ul(P.family,P.weights)},[g,l]);const oe=x.useMemo(()=>l.safe.filter(P=>P.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),q=x.useMemo(()=>l.google.filter(P=>P.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),b=x.useCallback(async P=>{try{await navigator.clipboard.writeText(P),m(P),setTimeout(()=>m(null),1500)}catch{z({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[z]),B=x.useCallback(async(P,ue,he)=>{y(P);try{const ce=O(pe=>(jv(pe,he,P),pe));if(!ce.ok){z({variant:"destructive",title:"Could not insert font",description:ce.error});return}z({title:"Font inserted",description:`${P} set as ${he} font in "${ce.name}".`})}finally{y(null)}},[O,z]),V=x.useCallback(async P=>{if(o){y(P);try{const ue=R(o.jsonPath,P);if(!ue.ok){z({variant:"destructive",title:"Could not insert font",description:ue.error});return}z({title:"Font inserted",description:`${P} set at ${Jl(o.jsonPath)}.`}),a(!1)}finally{y(null)}}},[o,R,z,a]),re=x.useCallback(async P=>{if(!(!P||P.length===0)){C(!0);try{const ue=[];for(const ce of Array.from(P)){const pe=new Uint8Array(await ce.arrayBuffer()),me=uv(ce.name,pe);if(!me.ok){z({variant:"destructive",title:"Font rejected",description:me.message});continue}ue.push({identity:dv(ce.name),base64:me.base64})}if(ue.length===0)return;const he=Y(ue.map(({identity:ce,base64:pe})=>({id:ce.family,family:ce.family,sources:[{kind:"data",data:pe,weight:ce.weight,italic:ce.italic}]})));if(!he.ok){z({variant:"destructive",title:"Could not register font",description:he.error});return}for(const{identity:ce,base64:pe}of ue)vv(ce.family,pe,ce.weight,ce.italic),z({title:`Added ${ce.family}`,description:`Registered at weight ${ce.weight}${ce.italic?" italic":""} in props.fontRegistry. Reference it as "${ce.family}".`})}catch(ue){z({variant:"destructive",title:"Upload failed",description:ue.message})}finally{C(!1),I.current&&(I.current.value="")}}},[Y,z]),se=x.useCallback(async()=>{var ue,he;const P=J.trim();if(P){N(!0),T([]);try{const ce=await fetch(Ji.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:P,weights:[400,700],italics:!1})});if(ce.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!ce.ok){const X=await ce.json().catch(()=>({}));throw new Error(X.error??`Materialize failed (${ce.status})`)}const pe=await ce.json();T(pe.warnings??[]);const me=(ue=l.google.find(X=>X.family.toLowerCase()===pe.family.toLowerCase()))==null?void 0:ue.category,U=gv(pe,me);if(!U){z({variant:"destructive",title:"Nothing to embed",description:((he=pe.warnings)==null?void 0:he.join(" · "))||`Google Fonts has no family named "${P}".`});return}const Te=Y([U]);if(!Te.ok){z({variant:"destructive",title:"Could not register font",description:Te.error});return}Ul(pe.family,[400,700]),z({title:`Added ${pe.family}`,description:`Embedded ${U.sources.length} weight(s) in props.fontRegistry.`})}catch(ce){z({variant:"destructive",title:"Google Fonts fetch failed",description:ce.message})}finally{N(!1)}}},[J,l.google,Y,z]);return u.jsx(Ct,{open:s,onOpenChange:a,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:o?`Font for ${Jl(o.jsonPath)}`:"Fonts"})}),!o&&!ee&&g!=="custom"&&u.jsx(or,{children:u.jsxs(ar,{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(Xf,{value:g,onValueChange:P=>v(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ja,{children:[u.jsxs(cr,{value:"safe",children:["Safe",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(cr,{value:"google",children:["Google",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]}),u.jsx(cr,{value:"custom",children:"Custom"})]}),u.jsx(gr,{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(dr,{value:"safe",className:"m-0",children:d&&oe.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Lr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:oe.map(P=>u.jsx(Hl,{family:P,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${P}", sans-serif`},onCopy:()=>b(P),copied:j===P,contextual:!!o,onUseThis:()=>V(P),onInsertHeading:()=>B(P,"safe","heading"),onInsertBody:()=>B(P,"safe","body"),applying:S===P,disabled:!k},P))})}),u.jsx(dr,{value:"google",className:"m-0",children:d&&q.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Lr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:q.map(P=>u.jsx(Hl,{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:j===P.family,contextual:!!o,onUseThis:()=>V(P.family),onInsertHeading:()=>B(P.family,"google","heading"),onInsertBody:()=>B(P.family,"google","body"),applying:S===P.family,disabled:!k,extraAction:u.jsx(Cv,{family:P.family,weights:P.weights,hasItalic:P.hasItalic})},P.family))})}),u.jsx(dr,{value:"custom",className:"m-0 flex flex-col gap-6",children:ee?u.jsx(or,{children:u.jsxs(ar,{children:["Custom fonts are stored on the document (",u.jsx("code",{children:"props.fontRegistry"}),"), because the bytes travel with the JSON. Open a document tab to add one."]})}):u.jsxs(u.Fragment,{children:[u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Upload a font file"}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["TTF or OTF, up to 2 MB each. The font is embedded in the document as base64, so it survives export and re-import — and renders in the preview. The family and weight are guessed from the filename (e.g."," ",u.jsx("code",{children:"Geist-SemiBold.ttf"}),")."]}),u.jsxs("div",{onDragOver:P=>P.preventDefault(),onDrop:P=>{P.preventDefault(),re(P.dataTransfer.files)},className:"rounded-md border border-dashed p-6 text-center",children:[u.jsx("input",{ref:I,type:"file",accept:".ttf,.otf,font/ttf,font/otf",multiple:!0,className:"hidden",onChange:P=>void re(P.target.files)}),u.jsxs(_e,{variant:"secondary",disabled:A,onClick:()=>{var P;return(P=I.current)==null?void 0:P.click()},children:[A?u.jsx(Lr,{className:"animate-spin mr-2 h-4 w-4"}):u.jsx(Xg,{className:"mr-2 h-4 w-4"}),"Choose font files"]}),u.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"or drop them here"})]})]}),u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Embed any Google font"}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not limited to the ",l.google.length," curated families — type any Google Fonts family name and its regular and bold weights are fetched and embedded."]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(gr,{placeholder:"e.g. Geist",value:J,onChange:P=>D(P.target.value),onKeyDown:P=>{P.key==="Enter"&&se()}}),u.jsxs(_e,{onClick:()=>void se(),disabled:w||J.trim()==="",children:[w&&u.jsx(Lr,{className:"animate-spin mr-2 h-4 w-4"}),"Embed"]})]}),_.length>0&&u.jsx(or,{children:u.jsx(ar,{className:"text-xs",children:_.join(" · ")})})]})]})})]})]})]})})},Ev="The quick brown fox jumps over the lazy dog",Cv=({family:e,weights:t,hasItalic:n})=>{const r=x.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(js,{children:[u.jsx(Ns,{asChild:!0,children:u.jsx(_e,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(xi,{align:"end",className:"min-w-[260px]",children:[u.jsxs(uf,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(xr,{}),r.map(i=>{const s=kd[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)})]})]})},Hl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:o,onInsertHeading:a,onInsertBody:l,applying:c,disabled:d,extraAction:f})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:Ev}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(_e,{size:"sm",onClick:o,disabled:c||d,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(_e,{size:"sm",variant:"secondary",onClick:a,disabled:c||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(_e,{size:"sm",variant:"secondary",onClick:l,disabled:c||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,u.jsx(_e,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(yn,{className:"h-4 w-4"}):u.jsx(ws,{className:"h-4 w-4"})})]})]});function Wl({previewOpen:e,onTogglePreview:t}){const n=rn(D=>D.name||""),r=rn(D=>D.blob),i=rn(D=>D.isGenerating),s=rn(D=>D.text),o=rn(D=>D.warnings),a=rn(D=>D.isRendering),l=ji(D=>D.autoReload),c=ji(D=>D.renderingLibrary),d=ji(D=>D.setSettings),f=ji(D=>D.useGlobalPreviewHeader??!0),p=Ce(D=>D.activeTab),h=Ce(D=>D.documentTypes),g=p&&h[p]==="application/json+theme"?"theme":"document",v=Ce(D=>{var _;return D.activeTab&&D.documentTypes[D.activeTab]!=="application/json+theme"?(_=D.documents.find(T=>T.name===D.activeTab))==null?void 0:_.text:void 0}),S=Re(D=>D.chatOpen),y=Re(D=>D.toggleChat),[j,m]=je.useState(!1),A=$i(D=>D.openFor);if(!f)return null;const C=x.useCallback(()=>d({saveDocumentDebounceWait:2e3,autoReload:!l}),[l,d]),w=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),N=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),J=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(nv,{name:J,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:C,onManualRender:w,isGenerating:i,isRendering:!!a,onShowCacheMetrics:N,onShowSchemas:()=>m(!0),onShowFonts:()=>A(),documentText:s,editorDocumentText:v,warnings:o,renderingLibrary:c,setRenderingLibrary:D=>d({renderingLibrary:D}),onToggleChat:y,chatOpen:S,onTogglePreview:t,previewOpen:e}),u.jsx(ov,{open:j,onOpenChange:m,defaultTab:g==="theme"?"theme":"document"}),u.jsx(Nv,{})]})}function Tv(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Iv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Av=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,zv={};function ql(e,t){return(zv.jsx?Av:Iv).test(e)}const Ov=/[ \t\n\f\r]/g;function Pv(e){return typeof e=="object"?e.type==="text"?Gl(e.value):!1:Gl(e)}function Gl(e){return e.replace(Ov,"")===""}class yi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}yi.prototype.normal={};yi.prototype.property={};yi.prototype.space=void 0;function ep(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new yi(n,r,t)}function Lo(e){return e.toLowerCase()}class St{constructor(t,n){this.attribute=n,this.property=t}}St.prototype.attribute="";St.prototype.booleanish=!1;St.prototype.boolean=!1;St.prototype.commaOrSpaceSeparated=!1;St.prototype.commaSeparated=!1;St.prototype.defined=!1;St.prototype.mustUseProperty=!1;St.prototype.number=!1;St.prototype.overloadedBoolean=!1;St.prototype.property="";St.prototype.spaceSeparated=!1;St.prototype.space=void 0;let Dv=0;const Se=Fn(),nt=Fn(),Bo=Fn(),ie=Fn(),Ze=Fn(),fr=Fn(),jt=Fn();function Fn(){return 2**++Dv}const Zo=Object.freeze(Object.defineProperty({__proto__:null,boolean:Se,booleanish:nt,commaOrSpaceSeparated:jt,commaSeparated:fr,number:ie,overloadedBoolean:Bo,spaceSeparated:Ze},Symbol.toStringTag,{value:"Module"})),eo=Object.keys(Zo);class Na extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),Yl(this,"space",i),typeof r=="number")for(;++s<eo.length;){const o=eo[s];Yl(this,eo[s],(r&Zo[o])===Zo[o])}}}Na.prototype.defined=!0;function Yl(e,t,n){n&&(e[t]=n)}function Nr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Na(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Lo(r)]=r,n[Lo(s.attribute)]=r}return new yi(t,n,e.space)}const tp=Nr({properties:{ariaActiveDescendant:null,ariaAtomic:nt,ariaAutoComplete:null,ariaBusy:nt,ariaChecked:nt,ariaColCount:ie,ariaColIndex:ie,ariaColSpan:ie,ariaControls:Ze,ariaCurrent:null,ariaDescribedBy:Ze,ariaDetails:null,ariaDisabled:nt,ariaDropEffect:Ze,ariaErrorMessage:null,ariaExpanded:nt,ariaFlowTo:Ze,ariaGrabbed:nt,ariaHasPopup:null,ariaHidden:nt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Ze,ariaLevel:ie,ariaLive:null,ariaModal:nt,ariaMultiLine:nt,ariaMultiSelectable:nt,ariaOrientation:null,ariaOwns:Ze,ariaPlaceholder:null,ariaPosInSet:ie,ariaPressed:nt,ariaReadOnly:nt,ariaRelevant:null,ariaRequired:nt,ariaRoleDescription:Ze,ariaRowCount:ie,ariaRowIndex:ie,ariaRowSpan:ie,ariaSelected:nt,ariaSetSize:ie,ariaSort:null,ariaValueMax:ie,ariaValueMin:ie,ariaValueNow:ie,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function np(e,t){return t in e?e[t]:t}function rp(e,t){return np(e,t.toLowerCase())}const Rv=Nr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:fr,acceptCharset:Ze,accessKey:Ze,action:null,allow:null,allowFullScreen:Se,allowPaymentRequest:Se,allowUserMedia:Se,alt:null,as:null,async:Se,autoCapitalize:null,autoComplete:Ze,autoFocus:Se,autoPlay:Se,blocking:Ze,capture:null,charSet:null,checked:Se,cite:null,className:Ze,cols:ie,colSpan:null,content:null,contentEditable:nt,controls:Se,controlsList:Ze,coords:ie|fr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Se,defer:Se,dir:null,dirName:null,disabled:Se,download:Bo,draggable:nt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Se,formTarget:null,headers:Ze,height:ie,hidden:Bo,high:ie,href:null,hrefLang:null,htmlFor:Ze,httpEquiv:Ze,id:null,imageSizes:null,imageSrcSet:null,inert:Se,inputMode:null,integrity:null,is:null,isMap:Se,itemId:null,itemProp:Ze,itemRef:Ze,itemScope:Se,itemType:Ze,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Se,low:ie,manifest:null,max:null,maxLength:ie,media:null,method:null,min:null,minLength:ie,multiple:Se,muted:Se,name:null,nonce:null,noModule:Se,noValidate:Se,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:Se,optimum:ie,pattern:null,ping:Ze,placeholder:null,playsInline:Se,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Se,referrerPolicy:null,rel:Ze,required:Se,reversed:Se,rows:ie,rowSpan:ie,sandbox:Ze,scope:null,scoped:Se,seamless:Se,selected:Se,shadowRootClonable:Se,shadowRootDelegatesFocus:Se,shadowRootMode:null,shape:null,size:ie,sizes:null,slot:null,span:ie,spellCheck:nt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:ie,step:null,style:null,tabIndex:ie,target:null,title:null,translate:null,type:null,typeMustMatch:Se,useMap:null,value:nt,width:ie,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ze,axis:null,background:null,bgColor:null,border:ie,borderColor:null,bottomMargin:ie,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Se,declare:Se,event:null,face:null,frame:null,frameBorder:null,hSpace:ie,leftMargin:ie,link:null,longDesc:null,lowSrc:null,marginHeight:ie,marginWidth:ie,noResize:Se,noHref:Se,noShade:Se,noWrap:Se,object:null,profile:null,prompt:null,rev:null,rightMargin:ie,rules:null,scheme:null,scrolling:nt,standby:null,summary:null,text:null,topMargin:ie,valueType:null,version:null,vAlign:null,vLink:null,vSpace:ie,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Se,disableRemotePlayback:Se,prefix:null,property:null,results:ie,security:null,unselectable:null},space:"html",transform:rp}),Mv=Nr({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:jt,accentHeight:ie,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:ie,amplitude:ie,arabicForm:null,ascent:ie,attributeName:null,attributeType:null,azimuth:ie,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:ie,by:null,calcMode:null,capHeight:ie,className:Ze,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:ie,diffuseConstant:ie,direction:null,display:null,dur:null,divisor:ie,dominantBaseline:null,download:Se,dx:null,dy:null,edgeMode:null,editable:null,elevation:ie,enableBackground:null,end:null,event:null,exponent:ie,externalResourcesRequired:null,fill:null,fillOpacity:ie,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:fr,g2:fr,glyphName:fr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:ie,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:ie,horizOriginX:ie,horizOriginY:ie,id:null,ideographic:ie,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:ie,k:ie,k1:ie,k2:ie,k3:ie,k4:ie,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:ie,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:ie,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:ie,overlineThickness:ie,paintOrder:null,panose1:null,path:null,pathLength:ie,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ze,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:ie,pointsAtY:ie,pointsAtZ:ie,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:jt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:jt,rev:jt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:jt,requiredFeatures:jt,requiredFonts:jt,requiredFormats:jt,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:ie,specularExponent:ie,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:ie,strikethroughThickness:ie,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:ie,strokeOpacity:ie,strokeWidth:null,style:null,surfaceScale:ie,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:ie,tableValues:null,target:null,targetX:ie,targetY:ie,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:jt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:ie,underlineThickness:ie,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:ie,values:null,vAlphabetic:ie,vMathematical:ie,vectorEffect:null,vHanging:ie,vIdeographic:ie,version:null,vertAdvY:ie,vertOriginX:ie,vertOriginY:ie,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:ie,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:np}),ip=Nr({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),sp=Nr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:rp}),op=Nr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),$v={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},Fv=/[A-Z]/g,Kl=/-[a-z]/g,Lv=/^data[-\w.:]+$/i;function Bv(e,t){const n=Lo(t);let r=t,i=St;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Lv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Kl,Vv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Kl.test(s)){let o=s.replace(Fv,Zv);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=Na}return new i(r,t)}function Zv(e){return"-"+e.toLowerCase()}function Vv(e){return e.charAt(1).toUpperCase()}const Uv=ep([tp,Rv,ip,sp,op],"html"),Ea=ep([tp,Mv,ip,sp,op],"svg");function Jv(e){return e.join(" ").trim()}var Wn={},to,Xl;function Hv(){if(Xl)return to;Xl=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,l=`
|
|
9
|
+
`)[0].trim();return i.length>t?`${i.slice(0,t-1)}…`:i}function Vy(e){const t=Et(Oe(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>Et(Oe(i,"cells")).length))}×${t.length}`;const n=Et(Oe(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?Et(r).length:Et(Oe(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Uy(e){const t=st(Oe(e,"alt"));if(t)return vt(t);const n=st(Oe(e,"src"));if(n){if(n.startsWith("data:")){const i=n.slice(5).split(/[;,]/)[0];return i?`image (${i.split("/").pop()})`:"image"}const r=n.split(/[?#]/)[0].split("/").pop();if(r)return vt(r,40)}return"image"}function Jy(e,t){var r;const n=st(Oe(t,"text"));switch(e){case"heading":{const i=$o(Oe(t,"level"))??1;return{label:n?vt(n):"heading",detail:`H${i}`}}case"text":return{label:n?vt(n):"text",detail:st(Oe(t,"style"))};case"paragraph":return{label:n?vt(n):"paragraph"};case"chart":case"highcharts":{const i=st(Oe(t,"title"))??st(Oe(Oe(t,"options"),"title"));return{label:i?vt(i):e,detail:st(Oe(t,"type"))}}case"table":return{label:"table",detail:Vy(t)};case"image":return{label:Uy(t)};case"shape":return{label:st(Oe(t,"type"))??"shape"};case"list":{const i=Et(Oe(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=st(Oe(Oe(t,"meta"),"title"))??st(Oe(t,"title"));return{label:i?vt(i):"section"}}case"statistic":{const i=st(Oe(t,"value"))??((r=$o(Oe(t,"value")))==null?void 0:r.toString()),s=st(Oe(t,"label"));return{label:vt(s??i??"statistic"),detail:i}}default:return{label:n?vt(n):e}}}function yr(e){if(e.type!=="object")return null;const t=st(Oe(e,"name"));return t?{name:t,props:Oe(e,"props"),childrenArr:Oe(e,"children")}:null}function Hy(e){let t;for(const n of Et(e)){const r=yr(n);if(!r)continue;const i=st(Oe(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return vt(i,48);r.name==="paragraph"&&t===void 0&&(t=vt(i,48))}}return t}function Xi(e,t,n){let{label:r,detail:i}=Jy(t.name,t.props);return r===t.name&&t.childrenArr&&(r=Hy(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:Sf(t.childrenArr),reorder:n}}function Sf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of Et(e)){const i=yr(r);i&&n.push(Xi(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Wy(e){const t=Oe(e,"props"),n=st(Oe(Oe(t,"meta"),"title"));if(n)return vt(n,48,!0);let r;const i=(a,l)=>{l&&(!r||a<r.rank)&&(r={rank:a,text:l})},s=Oe(t,"placeholders");if((s==null?void 0:s.type)==="object"&&s.children)for(const a of s.children){if(a.type!=="property"||!a.children)continue;const[l,c]=a.children,d=typeof(l==null?void 0:l.value)=="string"?l.value:"",f=c?yr(c):null,p=f?st(Oe(f.props,"text")):void 0;i(d==="title"?0:d==="subtitle"||d.startsWith("heading")?1:2,p)}const o=(a,l)=>{const c=yr(a);if(c){if(c.name==="text"||c.name==="heading"){const d=st(Oe(c.props,"text"));if(d){const f=st(Oe(c.props,"style"))??"";i(f==="title"?0:f.startsWith("heading")?1:2,d)}}if(l<1)for(const d of Et(c.childrenArr))o(d,l+1)}};for(const a of Et(Oe(e,"children")))o(a,0);return r?vt(r.text,48,!0):void 0}function qy(e){const t=Oe(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of Et(t)){const o=yr(s);if(!o)continue;const a={groupId:n,sliceStart:s.offset,sliceEnd:s.offset+s.length};o.name==="slide"?(i+=1,r.push({id:"",kind:"slide",label:Wy(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:Sf(o.childrenArr),reorder:a})):r.push(Xi(s,o,a))}return r}function Gy(e){const t=Oe(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const o of Et(t)){const a=yr(o);if(!a)continue;const l={groupId:n,sliceStart:o.offset,sliceEnd:o.offset+o.length},c=()=>i.length?i[i.length-1].node.children:r;if(a.name==="heading"){const d=$o(Oe(a.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=Xi(o,a,l);c().push(f),i.push({level:d,node:f})}else c().push(Xi(o,a,l))}const s=o=>{o.children.forEach(s);const a=o.children[o.children.length-1];o.kind==="heading"&&a&&(o.end=Math.max(o.end,a.end),o.reorder&&a.reorder&&(o.reorder.sliceEnd=Math.max(o.reorder.sliceEnd,a.reorder.sliceEnd)))};return r.forEach(s),r}function wl(e){switch(e.type){case"string":return vt(String(e.value??""),24);case"number":case"boolean":return String(e.value);case"array":return`${Et(e).length} items`;case"object":return;default:return}}function Yy(e){if(e.type!=="object"||!e.children)return[];const t=[];for(const n of e.children){if(n.type!=="property"||!n.children)continue;const[r,i]=n.children,s=typeof(r==null?void 0:r.value)=="string"?r.value:void 0;if(!s||s==="$schema"||!i)continue;const o=[];if(i.type==="object"&&i.children)for(const a of i.children){if(a.type!=="property"||!a.children)continue;const[l,c]=a.children,d=typeof(l==null?void 0:l.value)=="string"?l.value:void 0;!d||!c||o.push({id:"",kind:"key",label:d,detail:wl(c),start:a.offset,end:a.offset+a.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:o.length===0?wl(i):void 0,start:n.offset,end:n.offset+n.length,children:o})}return t}function kl(e,t,n){if(!e.trim())return[];const r=Ly(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Yy(r):t==="pptx"?qy(r):Gy(r);return _f(i,""),i}function _f(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,_f(n.children,n.id)})}function jf(e,t){const n=[];let r=e;for(;;){const i=r.find(s=>t>=s.start&&t<s.end);if(!i)return n;n.push(i.id),r=i.children}}function Ky(e,t){const n=new Set;for(const r of t)for(const i of jf(e,r))n.add(i);return n}function Xy(e,t,n,r){if(n===r||n<0||r<0||n>=t.length||r>=t.length)return null;const i=t.map(d=>d.reorder);if(i.some(d=>!d))return null;const s=i[0].groupId;if(i.some(d=>d.groupId!==s))return null;for(let d=1;d<i.length;d++)if(i[d].sliceStart<i[d-1].sliceEnd)return null;const o=i.map(d=>e.slice(d.sliceStart,d.sliceEnd)),a=[];for(let d=1;d<i.length;d++){const f=e.slice(i[d-1].sliceEnd,i[d].sliceStart);if((f.match(/,/g)??[]).length!==1)return null;a.push(f)}const l=o.map((d,f)=>f);l.splice(r,0,l.splice(n,1)[0]);let c="";return l.forEach((d,f)=>{c+=o[d],f<a.length&&(c+=a[f])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:c}}const Qy={slide:Pg,heading:Og,text:jo,paragraph:zg,chart:No,highcharts:No,table:Ag,image:Ig,shape:Ed,list:Tg,toc:Cg,section:tl,columns:tl,"text-box":jo,statistic:Eg,key:_o};function eb(e,t){let n=e,r=null;for(const i of t.split(".")){if(r=n[Number(i)]??null,!r)return null;n=r.children}return r}function tb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function nb(){const{activeTab:e,documentTypes:t}=Ce(da(D=>({activeTab:D.activeTab,documentTypes:D.documentTypes}))),n=Ce(D=>{var _;return D.activeTab?(_=D.documents.find(T=>T.name===D.activeTab))==null?void 0:_.text:void 0}),r=tx(D=>e?D.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,o]=x.useState(()=>{try{const D=localStorage.getItem("dev-env.outline-open");return D?D==="true":!0}catch{return!0}});x.useEffect(()=>{try{localStorage.setItem("dev-env.outline-open",String(s))}catch{}},[s]);const[a,l]=x.useState([]),[c,d]=x.useState(null),[f,p]=x.useState(()=>new Set),[h,g]=x.useState(()=>new Set),[v,S]=x.useState(null),y=x.useRef(a);y.current=a;const j=x.useRef(null),m=x.useRef(null),A=x.useCallback(()=>{var T;if(!e){l([]);return}const D=((T=r==null?void 0:r.editor.getModel())==null?void 0:T.getValue())??n??"",_=kl(D,ot,i);if(l(_),m.current!==e){m.current=e;const I=new Set;if(i==="document"&&ot==="docx")for(const z of _)z.kind==="heading"&&I.add(z.id);g(I),d(null)}},[e,r,n,i]);x.useEffect(()=>{A();const D=r==null?void 0:r.editor.getModel();if(!D)return;const _=rl(A,300),T=D.onDidChangeContent(()=>_());return()=>{_.cancel(),T.dispose()}},[A,r]),x.useEffect(()=>{if(!r)return;const{editor:D}=r,_=rl(()=>{const I=D.getModel(),z=D.getPosition();if(!I||!z)return;const O=I.getOffsetAt(z),R=jf(y.current,O);if(R.length===0){d(null);return}d(R[R.length-1]);const Y=R.slice(0,-1);Y.length&&g(H=>{if(Y.every(ee=>H.has(ee)))return H;const $=new Set(H);for(const ee of Y)$.add(ee);return $})},150),T=D.onDidChangeCursorPosition(()=>_());return()=>{_.cancel(),T.dispose()}},[r]),x.useEffect(()=>{if(!c||!j.current)return;const D=j.current.querySelector(`[data-oid="${CSS.escape(c)}"]`);D==null||D.scrollIntoView({block:"nearest"})},[c]),x.useEffect(()=>{if(!r){p(new Set);return}const{editor:D,monaco:_}=r,T=()=>{const z=D.getModel();if(!z)return;const O=_.editor.getModelMarkers({resource:z.uri}).filter(R=>R.severity===_.MarkerSeverity.Error).map(R=>z.getOffsetAt({lineNumber:R.startLineNumber,column:R.startColumn}));p(Ky(y.current,O))};T();const I=_.editor.onDidChangeMarkers(z=>{const O=D.getModel();O&&z.some(R=>R.toString()===O.uri.toString())&&T()});return()=>I.dispose()},[r,a]);const C=x.useCallback(D=>{g(_=>{const T=new Set(_);return T.has(D)?T.delete(D):T.add(D),T})},[]),w=x.useCallback(D=>{if(d(D.id),!r)return;const{editor:_,monaco:T}=r,I=_.getModel();if(!I)return;const z=I.getPositionAt(D.start),O=I.getPositionAt(D.end),R=new T.Range(z.lineNumber,z.column,O.lineNumber,O.column);_.revealRangeNearTopIfOutsideViewport(R,T.editor.ScrollType.Smooth),_.setPosition(z),_.focus();const Y=_.deltaDecorations([],[{range:R,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>_.deltaDecorations(Y,[]),700)},[r]),N=x.useCallback(D=>{var b;if(!r||!D.overId)return;const{editor:_,monaco:T,collapse:I}=r,z=_.getModel();if(!z)return;const O=z.getValue(),R=kl(O,ot,i),Y=D.parentId?((b=eb(R,D.parentId))==null?void 0:b.children)??[]:R,H=Y.findIndex(B=>B.id===D.dragId),$=Y.findIndex(B=>B.id===D.overId);if(H===-1||$===-1)return;let ee=$+(D.overHalf==="after"?1:0);H<ee&&(ee-=1);const k=Xy(O,Y,H,ee);if(!k)return;const oe=z.getPositionAt(k.start),q=z.getPositionAt(k.end);_.executeEdits("outline-reorder",[{range:new T.Range(oe.lineNumber,oe.column,q.lineNumber,q.column),text:k.text}]),I==null||I.resyncDecorations()},[r,i]),J=x.useMemo(()=>{const D=[],_=(T,I,z)=>{var Y,H;const O=(H=(Y=T[0])==null?void 0:Y.reorder)==null?void 0:H.groupId,R=T.length>1&&O!==void 0&&T.every($=>{var ee;return((ee=$.reorder)==null?void 0:ee.groupId)===O});T.forEach($=>{const ee=Qy[$.kind]??Dg,k=$.children.length>0,oe=h.has($.id),q=c===$.id,b=(v==null?void 0:v.overId)===$.id;D.push(u.jsxs("div",{"data-oid":$.id,role:"treeitem","aria-selected":q,"aria-expanded":k?oe:void 0,tabIndex:0,draggable:R,onClick:()=>w($),onKeyDown:B=>{(B.key==="Enter"||B.key===" ")&&(B.preventDefault(),w($)),B.key==="ArrowRight"&&k&&!oe&&C($.id),B.key==="ArrowLeft"&&k&&oe&&C($.id)},onDragStart:B=>{B.dataTransfer.setData("text/plain",$.id),B.dataTransfer.effectAllowed="move",S({dragId:$.id,parentId:z,overId:null,overHalf:"before"})},onDragOver:B=>{if(!v||v.dragId===$.id||tb(v.dragId)!==z)return;B.preventDefault(),B.dataTransfer.dropEffect="move";const V=B.currentTarget.getBoundingClientRect(),re=B.clientY<V.top+V.height/2?"before":"after";(v.overId!==$.id||v.overHalf!==re)&&S({...v,overId:$.id,overHalf:re})},onDrop:B=>{B.preventDefault(),v&&N({...v,overId:$.id,overHalf:v.overHalf}),S(null)},onDragEnd:()=>S(null),className:G("group flex h-6 w-full cursor-pointer items-center gap-1 rounded-sm pr-1","text-[12px] text-sidebar-foreground/80 transition-colors select-none","hover:bg-sidebar-accent hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none",q&&"bg-sidebar-accent font-medium text-sidebar-foreground",b&&(v==null?void 0:v.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",b&&(v==null?void 0:v.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+I*12},children:[k?u.jsx("span",{role:"button","aria-label":oe?"Collapse":"Expand",onClick:B=>{B.stopPropagation(),C($.id)},className:"flex size-3.5 shrink-0 items-center justify-center rounded-xs text-sidebar-foreground/55 hover:text-sidebar-foreground",children:u.jsx(Pn,{className:G("size-3 transition-transform",oe&&"rotate-90")})}):u.jsx("span",{className:"size-3.5 shrink-0"}),$.kind==="slide"&&u.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:$.detail}),u.jsx(ee,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),u.jsx("span",{className:"min-w-0 flex-1 truncate",children:$.label}),$.kind!=="slide"&&$.detail&&u.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:$.detail}),f.has($.id)&&u.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},$.id)),k&&oe&&_($.children,I+1,$.id)})};return _(a,0,""),D},[a,h,c,f,v,w,C,N]);return e?u.jsxs("section",{className:"mt-3 shrink-0",children:[u.jsx(Do,{count:a.length||void 0,actions:u.jsx($t,{"aria-label":s?"Collapse outline":"Expand outline","aria-expanded":s,onClick:()=>o(D=>!D),children:u.jsx(Pn,{className:G("transition-transform",s&&"rotate-90")})}),children:"Outline"}),s&&(a.length>0?u.jsx("div",{ref:j,role:"tree","aria-label":"Document outline",className:"max-h-[45vh] overflow-y-auto",children:J}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/60",children:"No structure to show yet."}))]}):null}const rb=x.memo(nb);async function ib(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const ni=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(md,{ref:r,className:G("relative overflow-hidden",e),...n,children:[u.jsx(ag,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(Nf,{}),u.jsx(lg,{})]}));ni.displayName=md.displayName;const Nf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(gd,{ref:r,orientation:t,className:G("flex touch-none transition-colors select-none",t==="vertical"&&"h-full w-2.5 border-l border-l-transparent p-[1px]",t==="horizontal"&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",e),...n,children:u.jsx(ug,{className:"bg-border relative flex-1 rounded-full"})}));Nf.displayName=gd.displayName;function va({className:e,...t}){return u.jsx(cg,{"data-slot":"switch",className:G("peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-switch-off focus-visible:ring-ring inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent transition-colors outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",e),...t,children:u.jsx(dg,{"data-slot":"switch-thumb",className:G("bg-background pointer-events-none block size-4 rounded-full shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0")})})}const sb=mi("relative w-full rounded-sm border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",{variants:{variant:{default:"bg-card text-foreground",destructive:"border-transparent bg-destructive-bg text-destructive-bg-foreground [&>svg]:text-destructive-bg-foreground",warning:"border-transparent bg-warning-bg text-warning-bg-foreground [&>svg]:text-warning-bg-foreground",success:"border-transparent bg-success-bg text-success-bg-foreground [&>svg]:text-success-bg-foreground",info:"border-transparent bg-data-blue-bg text-data-blue-bg-foreground [&>svg]:text-data-blue-bg-foreground"}},defaultVariants:{variant:"default"}}),or=x.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:G(sb({variant:t}),e),...n}));or.displayName="Alert";const ob=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:G("mb-1 font-medium leading-none tracking-tight",e),...t}));ob.displayName="AlertTitle";const ar=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:G("text-sm [&_p]:leading-relaxed",e),...t}));ar.displayName="AlertDescription";const Qi=x.memo(({keyName:e,value:t,depth:n=0,isLast:r=!1})=>{const[i,s]=x.useState(n<2),o=t!==null&&typeof t=="object",a=Array.isArray(t),l=()=>s(!i),c=()=>t===null?u.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?u.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?u.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?u.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?u.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?u.jsxs("span",{className:"text-warning",children:['"',t,'"']}):u.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,d=o?Object.keys(t).length:0;return u.jsxs("div",{className:G("text-sm",n>0&&"ml-4"),children:[u.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[o&&u.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?u.jsx(hi,{className:"h-3 w-3"}):u.jsx(Pn,{className:"h-3 w-3"})}),!o&&u.jsx("span",{className:"w-4"}),e&&u.jsxs(u.Fragment,{children:[u.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),u.jsx("span",{className:"mx-1",children:":"})]}),o?u.jsxs("span",{className:"text-muted-foreground",children:[a?"[":"{",!i&&u.jsxs("span",{className:"mx-1 text-xs",children:[d," ",a?"items":"properties"]}),!i&&(a?"]":"}")]}):c(),!o&&!r&&u.jsx("span",{className:"text-muted-foreground",children:","})]}),o&&i&&u.jsxs("div",{className:"ml-4",children:[a?t.map((f,p)=>u.jsx(Qi,{keyName:String(p),value:f,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([f,p],h,g)=>u.jsx(Qi,{keyName:f,value:p,depth:n+1,isLast:h===g.length-1},f)),u.jsx("div",{className:"ml-4",children:u.jsxs("span",{className:"text-muted-foreground",children:[a?"]":"}",!r&&","]})})]})]})});Qi.displayName="JsonNode";const es=x.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:G("space-y-4",r),children:[u.jsx(Yr,{className:"h-8 w-64"}),u.jsx(Yr,{className:"h-4 w-full"}),u.jsx(Yr,{className:"h-64 w-full"})]}):n?u.jsx(or,{variant:"destructive",className:r,children:u.jsx(ar,{children:n})}):e?u.jsx(ni,{className:G("h-full w-full rounded-md border bg-muted/10 p-4",r),children:u.jsx("div",{className:"font-mono text-xs",children:u.jsx(Qi,{value:e})})}):u.jsx(or,{className:r,children:u.jsx(ar,{children:"No schema available"})}));es.displayName="SchemaViewer";function ab({plugins:e,initialFocusedPlugin:t}){var m,A;const n=Bt(C=>C.togglePlugin),r=Bt(C=>C.isPluginSelected),i=Bt(C=>C.selectedPlugins),s=Bt(C=>C.isApplyingPlugins),[o,a]=x.useState(null),[l,c]=x.useState(null),[d,f]=x.useState("properties");x.useEffect(()=>{if(t){const C=e.find(w=>w.name===t);if(C){a(C);return}}e.length>0&&!o&&a(e[0])},[t,e]);const p=x.useMemo(()=>{const C={current:[],downstream:[],upstream:[]};return e.forEach(w=>{C[w.location]&&C[w.location].push(w)}),C},[e]),h=async(C,w)=>{o&&(await ib(o.name,C.props),c(w),setTimeout(()=>c(null),2e3))},g=C=>{switch(C){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return C}},v=C=>{switch(C){case"current":return u.jsx(Bg,{className:"size-3"});case"downstream":return u.jsx(Lg,{className:"size-3"});case"upstream":return u.jsx(jd,{className:"size-3"});default:return null}},S=((m=o==null?void 0:o.schema)==null?void 0:m.properties)&&Object.keys(o.schema.properties).length>0,y=(A=o==null?void 0:o.schema)==null?void 0:A.jsonSchema,j=(o==null?void 0:o.examples)&&o.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(Rg,{className:"size-5 text-warning"}),"Plugins",u.jsxs(Kt,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),u.jsxs(an,{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(ni,{className:"h-full",children:u.jsx("div",{className:"p-2 space-y-3",children:Object.entries(p).map(([C,w])=>w.length===0?null:u.jsxs("div",{children:[u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[v(C),g(C)]}),u.jsx("div",{className:"space-y-0.5",children:w.map(N=>{const J=r(N.name),D=(o==null?void 0:o.name)===N.name;return u.jsxs("button",{onClick:()=>a(N),className:G("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",D?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:G("size-1.5 rounded-full flex-none transition-colors",J?"bg-warning":"bg-muted-foreground/30")}),u.jsx("span",{className:"text-sm font-medium truncate flex-1",children:N.name})]},N.name)})})]},C))})})}),o?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:o.name}),o.version&&u.jsxs(Kt,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",o.version]})]}),o.description&&u.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:o.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(o.name)?"On":"Off"}),u.jsx(va,{checked:r(o.name),onCheckedChange:()=>n(o),disabled:s,"aria-label":`Toggle ${o.name}`})]})]}),u.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[v(o.location),u.jsx("span",{children:g(o.location)}),u.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),u.jsx("span",{className:"font-mono truncate",children:o.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:()=>f("properties"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="properties"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(_o,{className:"size-3.5"}),"Properties"]})}),y&&u.jsx("button",{onClick:()=>f("schema"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="schema"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx(Mg,{className:"size-3.5"}),"Schema"]})}),j&&u.jsx("button",{onClick:()=>f("examples"),className:G("px-3 py-1.5 text-sm font-medium rounded-t-md border-b-2 transition-colors cursor-pointer",d==="examples"?"border-primary text-foreground":"border-transparent text-muted-foreground hover:text-foreground"),children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[u.jsx($g,{className:"size-3.5"}),"Examples",u.jsx(Kt,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:o.examples.length})]})})]}),u.jsx(ni,{className:"flex-1",children:u.jsxs("div",{className:"p-5",children:[d==="properties"&&S&&u.jsx("div",{className:"space-y-1",children:Object.entries(o.schema.properties).map(([C,w])=>u.jsx(lb,{name:C,prop:w},C))}),d==="schema"&&y&&u.jsx(es,{schema:o.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&j&&o.examples.map((C,w)=>u.jsxs("div",{className:G(w>0&&"mt-4 pt-4 border-t"),children:[u.jsxs("div",{className:"flex items-center justify-between mb-2",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[C.title&&u.jsx("span",{className:"font-medium text-sm truncate",children:C.title}),!C.title&&u.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",w+1]})]}),u.jsx(_e,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>h(C,w),children:l===w?u.jsxs(u.Fragment,{children:[u.jsx(Fg,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(ws,{className:"size-3 mr-1"}),"Copy"]})})]}),C.description&&u.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:C.description}),u.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(C.props,null,2)})]},w)),!S&&!y&&!j&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(_o,{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 lb({name:e,prop:t}){var o;const[n,r]=x.useState(!1),i=t.description||t.enum||t.default!==void 0||t.items||t.properties,s=t.type||(t.enum?"enum":t.oneOf?"oneOf":"—");return u.jsxs("div",{className:"rounded-md border",children:[u.jsxs("button",{onClick:()=>i&&r(!n),className:G("w-full text-left flex items-center gap-2 px-3 py-2 text-sm",i&&"cursor-pointer hover:bg-muted/50"),children:[i?n?u.jsx(hi,{className:"size-3 text-muted-foreground flex-none"}):u.jsx(Pn,{className:"size-3 text-muted-foreground flex-none"}):u.jsx("span",{className:"size-3 flex-none"}),u.jsx("span",{className:"font-mono font-medium text-xs",children:e}),u.jsx(Kt,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&u.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),u.jsx("span",{className:"flex-1"}),t.default!==void 0&&u.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&u.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&u.jsx("p",{children:t.description}),t.enum&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((a,l)=>u.jsxs("span",{children:[l>0&&", ",u.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(a)})]},l))]}),((o=t.items)==null?void 0:o.type)&&u.jsxs("p",{children:[u.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const ub=fg,cb=pg,db=hg,fb={current:"Current directory",downstream:"Project"};function Gs({id:e,label:t,count:n,open:r,onToggle:i,children:s}){return u.jsxs(ub,{open:r,children:[u.jsxs(cb,{onClick:()=>i(e),className:G("flex h-7 w-full cursor-pointer items-center gap-1.5 rounded-sm px-1","text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[u.jsx(Pn,{className:G("size-3 shrink-0 transition-transform duration-150 ease-out",r&&"rotate-90")}),u.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:t}),u.jsx("span",{className:"ml-auto text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:n})]}),u.jsx(db,{children:u.jsx("div",{className:"border-sidebar-border/70 mt-0.5 ml-[13px] border-l pl-1",children:s})})]})}function Sl({location:e}){return u.jsx("div",{className:"px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:fb[e]??e})}function _l({name:e,subtitle:t,added:n,query:r,onSelect:i}){return u.jsxs("button",{type:"button",onClick:i,title:t?`${e} — ${t}`:e,"aria-label":n?`Open ${e}`:`Add ${e} to workspace`,className:G("group/row flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm px-2","text-[13px] transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none","text-sidebar-foreground/70"),children:[u.jsx("span",{className:"truncate",children:u.jsx(ya,{text:e,query:r})}),n?u.jsx("span",{className:"ml-auto shrink-0 text-[10px] tracking-[0.06em] text-sidebar-foreground/65 uppercase",children:"Open"}):u.jsx(nn,{"aria-hidden":!0,className:"ml-auto size-3.5 shrink-0 text-sidebar-foreground/45 opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100"})]})}function pb({documents:e,themes:t,plugins:n,openNames:r,query:i,expandedGroups:s,onToggleGroup:o,onQuickAdd:a,onShowPluginDetails:l,isPluginSelected:c,onTogglePlugin:d,isApplyingPlugins:f,selectedPluginCount:p}){const h=y=>i?!0:s.has(y),g=x.useMemo(()=>jl(e),[e]),v=x.useMemo(()=>jl(t),[t]);return e.length>0||t.length>0||n.length>0?u.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.length>0&&u.jsx(Gs,{id:"library-documents",label:"Project documents",count:e.length,open:h("library-documents"),onToggle:o,children:g.map(([y,j])=>u.jsxs(je.Fragment,{children:[g.length>1&&u.jsx(Sl,{location:y}),j.map(m=>u.jsx(_l,{name:m.name,subtitle:m.title,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!1)},m.path||m.name))]},y))}),t.length>0&&u.jsx(Gs,{id:"library-themes",label:"Project themes",count:t.length,open:h("library-themes"),onToggle:o,children:v.map(([y,j])=>u.jsxs(je.Fragment,{children:[v.length>1&&u.jsx(Sl,{location:y}),j.map(m=>u.jsx(_l,{name:m.name,subtitle:m.description,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!0)},m.path||m.name))]},y))}),n.length>0&&u.jsx(Gs,{id:"library-plugins",label:"Plugins",count:`${p}/${n.length}`,open:h("library-plugins"),onToggle:o,children:n.map(y=>{const j=c(y.name),m=`plugin-switch-${y.filePath||y.name}`;return u.jsxs("div",{title:y.description?`${y.name} — ${y.description}`:y.name,className:G("group/row flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2","transition-colors hover:bg-sidebar-accent/60"),children:[u.jsx("label",{htmlFor:m,className:G("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]",j?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:u.jsx("span",{className:"truncate",children:u.jsx(ya,{text:y.name,query:i})})}),u.jsx($t,{"aria-label":`Details for ${y.name}`,onClick:A=>{A.stopPropagation(),l(y.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(Cd,{})}),u.jsx(va,{id:m,checked:j,onCheckedChange:()=>d(y),disabled:f,className:"shrink-0","aria-label":`Toggle ${y.name} plugin`})]},y.filePath||y.name)})})]}):null}function jl(e){const t=["current","downstream"],n=new Map;return e.forEach(r=>{const i=n.get(r.location);i?i.push(r):n.set(r.location,[r])}),[...n.entries()].sort(([r],[i])=>t.indexOf(r)-t.indexOf(i))}function Ef({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:G("pointer-events-none inline-flex h-5 w-fit min-w-5 select-none items-center justify-center gap-1 rounded-sm bg-muted px-1 font-sans text-xs font-medium text-muted-foreground","[[data-slot=tooltip-content]_&]:bg-primary-foreground/20 [[data-slot=tooltip-content]_&]:text-primary-foreground",t),children:e})}function hb({children:e,className:t}){return u.jsx("span",{className:G("inline-flex items-center gap-0.5",t),children:e})}const Ei=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function ri({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return Ei?"⌘":"Ctrl";case"shift":return Ei?"⇧":"Shift";case"alt":return Ei?"⌥":"Alt";case"ctrl":return Ei?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(hb,{className:t,children:r.map((i,s)=>u.jsx(Ef,{children:i},s))})}function mb({className:e}={}){const{theme:t,setTheme:n}=vd(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=x.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(_e,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Zg,{className:"hidden dark:block"}),u.jsx(Vg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ye,{children:u.jsx("p",{children:"Toggle theme"})})]})}function gb({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:o,openDocument:a}=Ce(da(U=>({documents:U.documents,documentTypes:U.documentTypes,createDocument:U.createDocument,openDocument:U.openDocument}))),l=To(U=>U.updateTheme),c=To(U=>U.removeTheme),d=x.useContext(Od),[f,p]=x.useState(!1),[h,g]=x.useState(!1),[v,S]=x.useState(!1),[y,j]=x.useState(null),m=Bt(U=>U.togglePlugin),A=Bt(U=>U.isPluginSelected),C=Bt(U=>U.selectedPlugins),w=Bt(U=>U.isApplyingPlugins),[N,J]=x.useState(!1),[D,_]=x.useState(new Set(["library-documents"])),[T,I]=x.useState(""),z=x.useRef(null),{toast:O}=jr(),R=i.filter(U=>s[U.name]!=="application/json+theme"),Y=i.filter(U=>s[U.name]==="application/json+theme"),H=x.useCallback(()=>{p(!1)},[]),$=x.useCallback(()=>{g(!1)},[]),ee=x.useRef(new Map);x.useEffect(()=>{const U=ee.current,Te=new Map;Y.forEach(X=>{Te.set(X.name,X.text),U.get(X.name)!==X.text&&l(X.name,X.text)}),U.forEach((X,we)=>{Te.has(we)||c(we)}),ee.current=Te},[Y,l,c]);const k=x.useRef(!1);x.useEffect(()=>{if(k.current||!d)return;k.current=!0;const U=new Set(Y.map(X=>X.name));Object.keys(d.getState().customThemes).forEach(X=>{U.has(X)||c(X)})},[Y,c,d]);const oe=x.useCallback(U=>{_(Te=>{const X=new Set(Te);return X.has(U)?X.delete(U):X.add(U),X})},[]),{resolvedTheme:q}=vd(),b=q==="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",B=x.useCallback(async(U,Te)=>{if(i.some(X=>X.name===U)){a(U);return}try{const X=await fetch(`/api/discovery/${Te?"themes":"documents"}/${encodeURIComponent(U)}/content`);if(!X.ok)throw new Error(X.statusText);const we=await X.text(),E=JSON.parse(we);o(U,JSON.stringify(E,null,2)),a(U),O({title:`Added ${Te?"theme":"document"}: ${U}`})}catch{O({title:"Failed to load",description:`Could not load ${U}`,variant:"destructive"})}},[i,o,a,O]);x.useEffect(()=>{if(n)return;const U=Te=>{var E,M,F,ne,Q;if(Te.key!=="/"||Te.metaKey||Te.ctrlKey||Te.altKey)return;const X=Te.target,we=(E=X==null?void 0:X.tagName)==null?void 0:E.toLowerCase();we==="input"||we==="textarea"||we==="select"||X!=null&&X.isContentEditable||(M=X==null?void 0:X.closest)!=null&&M.call(X,".monaco-editor")||(F=z.current)!=null&&F.closest('[aria-hidden="true"], [inert]')||(Te.preventDefault(),(ne=z.current)==null||ne.focus(),(Q=z.current)==null||Q.select())};return window.addEventListener("keydown",U),()=>window.removeEventListener("keydown",U)},[n]);const V=T.trim(),re=x.useMemo(()=>new Set(i.map(U=>U.name)),[i]),se=x.useMemo(()=>R.filter(U=>cn(U.name,V)),[R,V]),P=x.useMemo(()=>Y.filter(U=>cn(U.name,V)),[Y,V]),ue=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(U=>cn(U.name,V)||cn(U.title??"",V)),[e,V]),he=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(U=>cn(U.name,V)||cn(U.description??"",V)),[e,V]),ce=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(U=>cn(U.name,V)||cn(U.description??"",V)),[e,V]),pe=V.length>0&&se.length===0&&P.length===0&&ue.length===0&&he.length===0&&ce.length===0,me=G("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(yf,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Ro,{className:G("gap-0 p-1.5",me),children:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:u.jsx(Td,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(ri,{shortcut:"mod+b"})]})]})}),u.jsxs(Mo,{className:G("gap-2 px-1 py-1",me),children:[u.jsxs(Br,{className:"items-center gap-0.5",children:[R.map(U=>u.jsx(Ni,{document:U,compact:!0},U.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"right",children:"New document"})]})]}),u.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),u.jsxs(Br,{className:"items-center gap-0.5",children:[Y.map(U=>u.jsx(Ni,{document:U,compact:!0},U.name)),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{className:"size-7","aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"right",children:"New theme"})]})]})]})]}):u.jsxs(u.Fragment,{children:[u.jsxs(Ro,{className:G("gap-0 p-2",me),children:[u.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[u.jsx("a",{href:"/","aria-label":"JSON to Office home",className:"focus-visible:ring-sidebar-ring flex items-center rounded-sm pl-1 focus-visible:ring-1 focus-visible:outline-none",children:u.jsx("img",{src:b,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:u.jsx(Ug,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(ri,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(Jg,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),u.jsx("input",{ref:z,type:"text",value:T,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:U=>I(U.target.value),onKeyDown:U=>{U.key==="Escape"&&(U.preventDefault(),I(""),U.currentTarget.blur())},className:G("border-sidebar-border/70 bg-sidebar-accent/40 h-7 w-full rounded-sm border","pr-7 pl-7 text-[13px] text-sidebar-foreground transition-colors","placeholder:text-sidebar-foreground/60","focus-visible:border-sidebar-ring focus-visible:bg-sidebar-accent/60","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none")}),V?u.jsx($t,{"aria-label":"Clear filter",onClick:()=>{var U;I(""),(U=z.current)==null||U.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(xn,{})}):u.jsx(Ef,{className:"absolute top-1/2 right-1.5 h-4 min-w-4 -translate-y-1/2 bg-transparent px-0 text-[10px] text-sidebar-foreground/65",children:"/"})]})]}),u.jsx(Mo,{className:G("gap-0 px-2 pb-2",me),children:pe?u.jsxs("div",{className:"px-1 py-6 text-center",children:[u.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",V,"”"]}),u.jsx("button",{type:"button",onClick:()=>{var U;I(""),(U=z.current)==null||U.focus()},className:"text-sidebar-foreground/70 hover:text-sidebar-foreground focus-visible:ring-sidebar-ring mt-1 cursor-pointer rounded-sm text-[12px] underline-offset-2 hover:underline focus-visible:ring-1 focus-visible:outline-none",children:"Clear filter"})]}):u.jsxs(u.Fragment,{children:[(se.length>0||!V)&&u.jsxs("section",{children:[u.jsx(Do,{count:(V?se.length:R.length)||void 0,actions:u.jsxs(u.Fragment,{children:[ot==="docx"&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"Compare documents",disabled:R.length<2,onClick:()=>J(!0),children:u.jsx(Sd,{})})}),u.jsx(Ye,{side:"bottom",children:R.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"New document",onClick:()=>p(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),u.jsx(Br,{className:"gap-0.5",children:se.length>0?se.map(U=>u.jsx(Ni,{document:U,query:V},U.name)):u.jsx(gl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]}),(P.length>0||!V)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Do,{count:(V?P.length:Y.length)||void 0,actions:u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx($t,{"aria-label":"New theme",onClick:()=>g(!0),children:u.jsx(nn,{})})}),u.jsx(Ye,{side:"bottom",children:"New theme"})]}),children:"Themes"}),u.jsx(Br,{className:"gap-0.5",children:P.length>0?P.map(U=>u.jsx(Ni,{document:U,query:V},U.name)):u.jsx(gl,{icon:nn,label:"New theme",onClick:()=>g(!0)})})]}),!V&&u.jsx(rb,{}),(ue.length>0||he.length>0||ce.length>0)&&u.jsx("div",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:u.jsx(pb,{documents:ue,themes:he,plugins:ce,openNames:re,query:V,expandedGroups:D,onToggleGroup:oe,onQuickAdd:B,onShowPluginDetails:U=>{j(U),S(!0)},isPluginSelected:A,onTogglePlugin:m,isApplyingPlugins:w,selectedPluginCount:C.size})})]})})]}),u.jsx(bf,{className:G("border-sidebar-border/70 gap-0 border-t p-1.5",me),children:u.jsx("div",{className:G("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(mb,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),u.jsx(Ct,{open:f,onOpenChange:p,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Yi,{mode:"create",shouldReset:!f,postSubmit:H,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),u.jsx(Ct,{open:h,onOpenChange:g,children:u.jsx(kt,{className:"sm:max-w-[525px]",children:u.jsx(Yi,{mode:"create",shouldReset:!h,postSubmit:$,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(Ct,{open:v,onOpenChange:U=>{S(U),U||j(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(ab,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:y})})}),u.jsx(vx,{open:N,onOpenChange:J})]})}const Nl=x.memo(gb),xb=x.lazy(()=>wd(()=>import("./editor-B4VqQFbE.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function El(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(sn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:u.jsx(xb,{})})}const yb=x.lazy(()=>wd(()=>import("./preview-DElYSCd1.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function Cl(){return u.jsx(x.Suspense,{fallback:u.jsx("div",{className:"flex items-center justify-center h-full",children:u.jsxs("div",{className:"text-center",children:[u.jsx(sn,{className:"w-8 h-8 mx-auto mb-2"}),u.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:u.jsx(yb,{})})}const{createElement:br,createContext:bb,forwardRef:Cf,useCallback:gt,useContext:Tf,useEffect:zn,useImperativeHandle:If,useLayoutEffect:vb,useMemo:wb,useRef:wt,useState:lr}=Fc,Tl=Fc[`useId${Math.random()}`.slice(0,5)],kb=vb,Cs=bb(null);Cs.displayName="PanelGroupContext";const On=kb,Sb=typeof Tl=="function"?Tl:()=>null;let _b=0;function wa(e=null){const t=Sb(),n=wt(e||t||null);return n.current===null&&(n.current=""+_b++),e??n.current}function Af({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:o,maxSize:a,minSize:l,onCollapse:c,onExpand:d,onResize:f,order:p,style:h,tagName:g="div",...v}){const S=Tf(Cs);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:j,getPanelSize:m,getPanelStyle:A,groupId:C,isPanelCollapsed:w,reevaluatePanelConstraints:N,registerPanel:J,resizePanel:D,unregisterPanel:_}=S,T=wa(o),I=wt({callbacks:{onCollapse:c,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:a,minSize:l},id:T,idIsFromProps:o!==void 0,order:p});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:O,constraints:R}=I.current,Y={...R};I.current.id=T,I.current.idIsFromProps=o!==void 0,I.current.order=p,O.onCollapse=c,O.onExpand=d,O.onResize=f,R.collapsedSize=n,R.collapsible=r,R.defaultSize=i,R.maxSize=a,R.minSize=l,(Y.collapsedSize!==R.collapsedSize||Y.collapsible!==R.collapsible||Y.maxSize!==R.maxSize||Y.minSize!==R.minSize)&&N(I.current,Y)}),On(()=>{const O=I.current;return J(O),()=>{_(O)}},[p,T,J,_]),If(s,()=>({collapse:()=>{y(I.current)},expand:O=>{j(I.current,O)},getId(){return T},getSize(){return m(I.current)},isCollapsed(){return w(I.current)},isExpanded(){return!w(I.current)},resize:O=>{D(I.current,O)}}),[y,j,m,w,T,D]);const z=A(I.current,i);return br(g,{...v,children:e,className:t,id:o,style:{...z,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":C,"data-panel-id":T,"data-panel-size":parseFloat(""+z.flexGrow).toFixed(1)})}const zf=Cf((e,t)=>br(Af,{...e,forwardedRef:t}));Af.displayName="Panel";zf.displayName="forwardRef(Panel)";let Fo=null,An=null;function jb(e,t){if(t){const n=(t&Mf)!==0,r=(t&$f)!==0,i=(t&Ff)!==0,s=(t&Lf)!==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 Nb(){An!==null&&(document.head.removeChild(An),Fo=null,An=null)}function Ys(e,t){const n=jb(e,t);Fo!==n&&(Fo=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Of(e){return e.type==="keydown"}function Pf(e){return e.type.startsWith("pointer")}function Df(e){return e.type.startsWith("mouse")}function Ts(e){if(Pf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(Df(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function Eb(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function Cb(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 Tb(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:zl(e),b:zl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ee(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Al(Il(n.a)),b:Al(Il(n.b))};if(i.a===i.b){const s=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=s.length;for(;a--;){const l=s[a];if(l===o.a)return 1;if(l===o.b)return-1}}return Math.sign(i.a-i.b)}const Ib=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function Ab(e){var t;const n=getComputedStyle((t=Rf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function zb(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||Ab(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"||Ib.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Il(e){let t=e.length;for(;t--;){const n=e[t];if(Ee(n,"Missing node"),zb(n))return n}return null}function Al(e){return e&&Number(getComputedStyle(e).zIndex)||0}function zl(e){const t=[];for(;e;)t.push(e),e=Rf(e);return t}function Rf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Mf=1,$f=2,Ff=4,Lf=8,Ob=Eb()==="coarse";let Zt=[],ur=!1,mn=new Map,Is=new Map;const ii=new Set;function Pb(e,t,n,r,i){var s;const{ownerDocument:o}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=mn.get(o))!==null&&s!==void 0?s:0;return mn.set(o,l+1),ii.add(a),ts(),function(){var d;Is.delete(e),ii.delete(a);const f=(d=mn.get(o))!==null&&d!==void 0?d:1;if(mn.set(o,f-1),ts(),f===1&&mn.delete(o),Zt.includes(a)){const p=Zt.indexOf(a);p>=0&&Zt.splice(p,1),Sa(),i("up",!0,null)}}}function Ol(e){const{target:t}=e,{x:n,y:r}=Ts(e);ur=!0,ka({target:t,x:n,y:r}),ts(),Zt.length>0&&(ns("down",e),e.preventDefault(),e.stopPropagation())}function Pr(e){const{x:t,y:n}=Ts(e);if(ur&&e.buttons===0&&(ur=!1,ns("up",e)),!ur){const{target:r}=e;ka({target:r,x:t,y:n})}ns("move",e),Sa(),Zt.length>0&&e.preventDefault()}function Jn(e){const{target:t}=e,{x:n,y:r}=Ts(e);Is.clear(),ur=!1,Zt.length>0&&e.preventDefault(),ns("up",e),ka({target:t,x:n,y:r}),Sa(),ts()}function ka({target:e,x:t,y:n}){Zt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),ii.forEach(i=>{const{element:s,hitAreaMargins:o}=i,a=s.getBoundingClientRect(),{bottom:l,left:c,right:d,top:f}=a,p=Ob?o.coarse:o.fine;if(t>=c-p&&t<=d+p&&n>=f-p&&n<=l+p){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&Tb(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(Cb(g.getBoundingClientRect(),a)){v=!0;break}g=g.parentElement}if(v)return}Zt.push(i)}})}function Ks(e,t){Is.set(e,t)}function Sa(){let e=!1,t=!1;Zt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;Is.forEach(r=>{n|=r}),e&&t?Ys("intersection",n):e?Ys("horizontal",n):t?Ys("vertical",n):Nb()}function ts(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Jn),n.removeEventListener("pointerdown",Ol),n.removeEventListener("pointerleave",Pr),n.removeEventListener("pointermove",Pr)}),window.removeEventListener("pointerup",Jn),window.removeEventListener("pointercancel",Jn),ii.size>0&&(ur?(Zt.length>0&&mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Jn),n.addEventListener("pointerleave",Pr),n.addEventListener("pointermove",Pr))}),window.addEventListener("pointerup",Jn),window.addEventListener("pointercancel",Jn)):mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Ol,{capture:!0}),n.addEventListener("pointermove",Pr))}))}function ns(e,t){ii.forEach(n=>{const{setResizeHandlerState:r}=n,i=Zt.includes(n);r(e,i,t)})}function Db(){const[e,t]=lr(0);return gt(()=>t(n=>n+1),[])}function Ee(e,t){if(!e)throw console.error(t),Error(t)}const _a=10;function Rn(e,t,n=_a){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function on(e,t,n=_a){return Rn(e,t,n)===0}function Nt(e,t,n){return Rn(e,t,n)===0}function Rb(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const i=e[r],s=t[r];if(!Nt(i,s,n))return!1}return!0}function nr({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ee(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:o=100,minSize:a=0}=r;if(Rn(n,a)<0)if(s){const l=(i+a)/2;Rn(n,l)<0?n=i:n=a}else n=a;return n=Math.min(o,n),n=parseFloat(n.toFixed(_a)),n}function Zr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Nt(e,0))return t;const o=[...t],[a,l]=r;Ee(a!=null,"Invalid first pivot index"),Ee(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const f=e<0?l:a,p=n[f];Ee(p,`Panel constraints not found for index ${f}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[f];if(Ee(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,h)){const y=v-S;Rn(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const f=e<0?a:l,p=n[f];Ee(p,`No panel constraints found for index ${f}`);const{collapsedSize:h=0,collapsible:g,minSize:v=0}=p;if(g){const S=t[f];if(Ee(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,v)){const y=S-h;Rn(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const f=e<0?1:-1;let p=e<0?l:a,h=0;for(;;){const v=t[p];Ee(v!=null,`Previous layout not found for panel index ${p}`);const y=nr({panelConstraints:n,panelIndex:p,size:100})-v;if(h+=y,p+=f,p<0||p>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(h));e=e<0?0-g:g}{let p=e<0?a:l;for(;p>=0&&p<n.length;){const h=Math.abs(e)-Math.abs(c),g=t[p];Ee(g!=null,`Previous layout not found for panel index ${p}`);const v=g-h,S=nr({panelConstraints:n,panelIndex:p,size:v});if(!Nt(g,S)&&(c+=g-S,o[p]=S,c.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?p--:p++}}if(Rb(i,o))return i;{const f=e<0?l:a,p=t[f];Ee(p!=null,`Previous layout not found for panel index ${f}`);const h=p+c,g=nr({panelConstraints:n,panelIndex:f,size:h});if(o[f]=g,!Nt(g,h)){let v=h-g,y=e<0?l:a;for(;y>=0&&y<n.length;){const j=o[y];Ee(j!=null,`Previous layout not found for panel index ${y}`);const m=j+v,A=nr({panelConstraints:n,panelIndex:y,size:m});if(Nt(j,A)||(v-=A-j,o[y]=A),Nt(v,0))break;e>0?y--:y++}}}const d=o.reduce((f,p)=>p+f,0);return Nt(d,100)?o:i}function Mb({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,o=0;const a=n[0];Ee(a!=null,"No pivot index found"),t.forEach((f,p)=>{const{constraints:h}=f,{maxSize:g=100,minSize:v=0}=h;p===a?(r=v,i=g):(s+=v,o+=g)});const l=Math.min(i,100-s),c=Math.max(r,100-o),d=e[a];return{valueMax:l,valueMin:c,valueNow:d}}function si(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function Bf(e,t,n=document){const i=si(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Zf(e,t,n){const r=Bf(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Vf(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 As(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function $b(e,t,n,r=document){var i,s,o,a;const l=As(t,r),c=si(e,r),d=l?c.indexOf(l):-1,f=(i=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,p=(o=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&o!==void 0?o:null;return[f,p]}function Fb({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:o}){wt({didWarnAboutMissingResizeHandle:!1}),On(()=>{if(!s)return;const a=si(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:d,valueNow:f}=Mb({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=a[l];if(p!=null){const h=i[l];Ee(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(d)),p.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),zn(()=>{if(!s)return;const a=t.current;Ee(a,"Eager values not found");const{panelDataArray:l}=a,c=Vf(n,s);Ee(c!=null,`No group found for id "${n}"`);const d=si(n,s);Ee(d,`No resize handles found for group id "${n}"`);const f=d.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");Ee(h,"Resize handle element has no handle id attribute");const[g,v]=$b(n,h,l,s);if(g==null||v==null)return()=>{};const S=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const j=l.findIndex(m=>m.id===g);if(j>=0){const m=l[j];Ee(m,`No panel data found for index ${j}`);const A=r[j],{collapsedSize:C=0,collapsible:w,minSize:N=0}=m.constraints;if(A!=null&&w){const J=Zr({delta:Nt(A,C)?N-C:C-A,initialLayout:r,panelConstraints:l.map(D=>D.constraints),pivotIndices:Zf(n,h,s),prevLayout:r,trigger:"keyboard"});r!==J&&o(J)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{f.forEach(p=>p())}},[s,e,t,n,r,i,o])}function Pl(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 Uf(e,t){const n=e==="horizontal",{x:r,y:i}=Ts(t);return n?r:i}function Lb(e,t,n,r,i){const s=n==="horizontal",o=As(t,i);Ee(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute("data-panel-group-id");Ee(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=Uf(n,e),d=Vf(a,i);Ee(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),p=s?f.width:f.height;return(c-l)/p*100}function Bb(e,t,n,r,i,s){if(Of(e)){const o=n==="horizontal";let a=0;e.shiftKey?a=100:i!=null?a=i:a=10;let l=0;switch(e.key){case"ArrowDown":l=o?0:a;break;case"ArrowLeft":l=o?-a:0;break;case"ArrowRight":l=o?a:0;break;case"ArrowUp":l=o?0:-a;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:Lb(e,t,n,r,s)}function Zb({panelDataArray:e}){const t=Array(e.length),n=e.map(s=>s.constraints);let r=0,i=100;for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;a!=null&&(r++,t[s]=a,i-=a)}for(let s=0;s<e.length;s++){const o=n[s];Ee(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;if(a!=null)continue;const l=e.length-r,c=i/l;r++,t[s]=c,i-=c}return t}function Hn(e,t,n){t.forEach((r,i)=>{const s=e[i];Ee(s,`Panel data not found for index ${i}`);const{callbacks:o,constraints:a,id:l}=s,{collapsedSize:c=0,collapsible:d}=a,f=n[l];if(f==null||r!==f){n[l]=r;const{onCollapse:p,onExpand:h,onResize:g}=o;g&&g(r,f),d&&(p||h)&&(h&&(f==null||on(f,c))&&!on(r,c)&&h(),p&&(f==null||!on(f,c))&&on(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 Vb({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:i,precision:s=3}){const o=n[i];let a;return o==null?a=e!=null?e.toPrecision(s):"1":r.length===1?a="1":a=o.toPrecision(s),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function Ub(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Dl(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 Jf(e){return`react-resizable-panels:${e}`}function Hf(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 Wf(e,t){try{const n=Jf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Jb(e,t,n){var r,i;const s=(r=Wf(e,n))!==null&&r!==void 0?r:{},o=Hf(t);return(i=s[o])!==null&&i!==void 0?i:null}function Hb(e,t,n,r,i){var s;const o=Jf(e),a=Hf(t),l=(s=Wf(e,i))!==null&&s!==void 0?s:{};l[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(o,JSON.stringify(l))}catch(c){console.error(c)}}function Rl({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((s,o)=>s+o,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(s=>`${s}%`).join(", ")}`);if(!Nt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=100/r*o;n[s]=a}let i=0;for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=nr({panelConstraints:t,panelIndex:s,size:o});o!=a&&(i+=o-a,n[s]=a)}if(!Nt(i,0))for(let s=0;s<t.length;s++){const o=n[s];Ee(o!=null,`No layout data found for index ${s}`);const a=o+i,l=nr({panelConstraints:t,panelIndex:s,size:a});if(o!==l&&(i-=l-o,n[s]=l,Nt(i,0)))break}return n}const Wb=100,Vr={getItem:e=>(Dl(Vr),Vr.getItem(e)),setItem:(e,t)=>{Dl(Vr),Vr.setItem(e,t)}},Ml={};function qf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:o=null,keyboardResizeBy:a=null,storage:l=Vr,style:c,tagName:d="div",...f}){const p=wa(s),h=wt(null),[g,v]=lr(null),[S,y]=lr([]),j=Db(),m=wt({}),A=wt(new Map),C=wt(0),w=wt({autoSaveId:e,direction:r,dragState:g,id:p,keyboardResizeBy:a,onLayout:o,storage:l}),N=wt({layout:S,panelDataArray:[],panelDataArrayChanged:!1});wt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),If(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:b}=N.current;return b},setLayout:b=>{const{onLayout:B}=w.current,{layout:V,panelDataArray:re}=N.current,se=Rl({layout:b,panelConstraints:re.map(P=>P.constraints)});Pl(V,se)||(y(se),N.current.layout=se,B&&B(se),Hn(re,se,m.current))}}),[]),On(()=>{w.current.autoSaveId=e,w.current.direction=r,w.current.dragState=g,w.current.id=p,w.current.onLayout=o,w.current.storage=l}),Fb({committedValuesRef:w,eagerValuesRef:N,groupId:p,layout:S,panelDataArray:N.current.panelDataArray,setLayout:y,panelGroupElement:h.current}),zn(()=>{const{panelDataArray:b}=N.current;if(e){if(S.length===0||S.length!==b.length)return;let B=Ml[e];B==null&&(B=Ub(Hb,Wb),Ml[e]=B);const V=[...b],re=new Map(A.current);B(e,V,re,S,l)}},[e,S,l]),zn(()=>{});const J=gt(b=>{const{onLayout:B}=w.current,{layout:V,panelDataArray:re}=N.current;if(b.constraints.collapsible){const se=re.map(ce=>ce.constraints),{collapsedSize:P=0,panelSize:ue,pivotIndices:he}=jn(re,b,V);if(Ee(ue!=null,`Panel size not found for panel "${b.id}"`),!on(ue,P)){A.current.set(b.id,ue);const pe=Xn(re,b)===re.length-1?ue-P:P-ue,me=Zr({delta:pe,initialLayout:V,panelConstraints:se,pivotIndices:he,prevLayout:V,trigger:"imperative-api"});Ci(V,me)||(y(me),N.current.layout=me,B&&B(me),Hn(re,me,m.current))}}},[]),D=gt((b,B)=>{const{onLayout:V}=w.current,{layout:re,panelDataArray:se}=N.current;if(b.constraints.collapsible){const P=se.map(U=>U.constraints),{collapsedSize:ue=0,panelSize:he=0,minSize:ce=0,pivotIndices:pe}=jn(se,b,re),me=B??ce;if(on(he,ue)){const U=A.current.get(b.id),Te=U!=null&&U>=me?U:me,we=Xn(se,b)===se.length-1?he-Te:Te-he,E=Zr({delta:we,initialLayout:re,panelConstraints:P,pivotIndices:pe,prevLayout:re,trigger:"imperative-api"});Ci(re,E)||(y(E),N.current.layout=E,V&&V(E),Hn(se,E,m.current))}}},[]),_=gt(b=>{const{layout:B,panelDataArray:V}=N.current,{panelSize:re}=jn(V,b,B);return Ee(re!=null,`Panel size not found for panel "${b.id}"`),re},[]),T=gt((b,B)=>{const{panelDataArray:V}=N.current,re=Xn(V,b);return Vb({defaultSize:B,dragState:g,layout:S,panelData:V,panelIndex:re})},[g,S]),I=gt(b=>{const{layout:B,panelDataArray:V}=N.current,{collapsedSize:re=0,collapsible:se,panelSize:P}=jn(V,b,B);return Ee(P!=null,`Panel size not found for panel "${b.id}"`),se===!0&&on(P,re)},[]),z=gt(b=>{const{layout:B,panelDataArray:V}=N.current,{collapsedSize:re=0,collapsible:se,panelSize:P}=jn(V,b,B);return Ee(P!=null,`Panel size not found for panel "${b.id}"`),!se||Rn(P,re)>0},[]),O=gt(b=>{const{panelDataArray:B}=N.current;B.push(b),B.sort((V,re)=>{const se=V.order,P=re.order;return se==null&&P==null?0:se==null?-1:P==null?1:se-P}),N.current.panelDataArrayChanged=!0,j()},[j]);On(()=>{if(N.current.panelDataArrayChanged){N.current.panelDataArrayChanged=!1;const{autoSaveId:b,onLayout:B,storage:V}=w.current,{layout:re,panelDataArray:se}=N.current;let P=null;if(b){const he=Jb(b,se,V);he&&(A.current=new Map(Object.entries(he.expandToSizes)),P=he.layout)}P==null&&(P=Zb({panelDataArray:se}));const ue=Rl({layout:P,panelConstraints:se.map(he=>he.constraints)});Pl(re,ue)||(y(ue),N.current.layout=ue,B&&B(ue),Hn(se,ue,m.current))}}),On(()=>{const b=N.current;return()=>{b.layout=[]}},[]);const R=gt(b=>{let B=!1;const V=h.current;return V&&window.getComputedStyle(V,null).getPropertyValue("direction")==="rtl"&&(B=!0),function(se){se.preventDefault();const P=h.current;if(!P)return()=>null;const{direction:ue,dragState:he,id:ce,keyboardResizeBy:pe,onLayout:me}=w.current,{layout:U,panelDataArray:Te}=N.current,{initialLayout:X}=he??{},we=Zf(ce,b,P);let E=Bb(se,b,ue,he,pe,P);const M=ue==="horizontal";M&&B&&(E=-E);const F=Te.map(te=>te.constraints),ne=Zr({delta:E,initialLayout:X??U,panelConstraints:F,pivotIndices:we,prevLayout:U,trigger:Of(se)?"keyboard":"mouse-or-touch"}),Q=!Ci(U,ne);(Pf(se)||Df(se))&&C.current!=E&&(C.current=E,!Q&&E!==0?M?Ks(b,E<0?Mf:$f):Ks(b,E<0?Ff:Lf):Ks(b,0)),Q&&(y(ne),N.current.layout=ne,me&&me(ne),Hn(Te,ne,m.current))}},[]),Y=gt((b,B)=>{const{onLayout:V}=w.current,{layout:re,panelDataArray:se}=N.current,P=se.map(U=>U.constraints),{panelSize:ue,pivotIndices:he}=jn(se,b,re);Ee(ue!=null,`Panel size not found for panel "${b.id}"`);const pe=Xn(se,b)===se.length-1?ue-B:B-ue,me=Zr({delta:pe,initialLayout:re,panelConstraints:P,pivotIndices:he,prevLayout:re,trigger:"imperative-api"});Ci(re,me)||(y(me),N.current.layout=me,V&&V(me),Hn(se,me,m.current))},[]),H=gt((b,B)=>{const{layout:V,panelDataArray:re}=N.current,{collapsedSize:se=0,collapsible:P}=B,{collapsedSize:ue=0,collapsible:he,maxSize:ce=100,minSize:pe=0}=b.constraints,{panelSize:me}=jn(re,b,V);me!=null&&(P&&he&&on(me,se)?on(se,ue)||Y(b,ue):me<pe?Y(b,pe):me>ce&&Y(b,ce))},[Y]),$=gt((b,B)=>{const{direction:V}=w.current,{layout:re}=N.current;if(!h.current)return;const se=As(b,h.current);Ee(se,`Drag handle element not found for id "${b}"`);const P=Uf(V,B);v({dragHandleId:b,dragHandleRect:se.getBoundingClientRect(),initialCursorPosition:P,initialLayout:re})},[]),ee=gt(()=>{v(null)},[]),k=gt(b=>{const{panelDataArray:B}=N.current,V=Xn(B,b);V>=0&&(B.splice(V,1),delete m.current[b.id],N.current.panelDataArrayChanged=!0,j())},[j]),oe=wb(()=>({collapsePanel:J,direction:r,dragState:g,expandPanel:D,getPanelSize:_,getPanelStyle:T,groupId:p,isPanelCollapsed:I,isPanelExpanded:z,reevaluatePanelConstraints:H,registerPanel:O,registerResizeHandle:R,resizePanel:Y,startDragging:$,stopDragging:ee,unregisterPanel:k,panelGroupElement:h.current}),[J,g,r,D,_,T,p,I,z,H,O,R,Y,$,ee,k]),q={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return br(Cs.Provider,{value:oe},br(d,{...f,children:t,className:n,id:s,ref:h,style:{...q,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const Gf=Cf((e,t)=>br(qf,{...e,forwardedRef:t}));qf.displayName="PanelGroup";Gf.displayName="forwardRef(PanelGroup)";function Xn(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function jn(e,t,n){const r=Xn(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],o=n[r];return{...t.constraints,panelSize:o,pivotIndices:s}}function qb({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){zn(()=>{if(e||n==null||r==null)return;const i=As(t,r);if(i==null)return;const s=o=>{if(!o.defaultPrevented)switch(o.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{o.preventDefault(),n(o);break}case"F6":{o.preventDefault();const a=i.getAttribute("data-panel-group-id");Ee(a,`No group element found for id "${a}"`);const l=si(a,r),c=Bf(a,t,r);Ee(c!==null,`No resize element found for id "${t}"`);const d=o.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[d].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function Yf({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:o,onFocus:a,style:l={},tabIndex:c=0,tagName:d="div",...f}){var p,h;const g=wt(null),v=wt({onDragging:o});zn(()=>{v.current.onDragging=o});const S=Tf(Cs);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:y,groupId:j,registerResizeHandle:m,startDragging:A,stopDragging:C,panelGroupElement:w}=S,N=wa(i),[J,D]=lr("inactive"),[_,T]=lr(!1),[I,z]=lr(null),O=wt({state:J});On(()=>{O.current.state=J}),zn(()=>{if(n)z(null);else{const $=m(N);z(()=>$)}},[n,N,m]);const R=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,Y=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return zn(()=>{if(n||I==null)return;const $=g.current;return Ee($,"Element ref not attached"),Pb(N,$,y,{coarse:R,fine:Y},(k,oe,q)=>{if(oe)switch(k){case"down":{D("drag"),Ee(q,'Expected event to be defined for "down" action'),A(N,q);const{onDragging:b}=v.current;b&&b(!0);break}case"move":{const{state:b}=O.current;b!=="drag"&&D("hover"),Ee(q,'Expected event to be defined for "move" action'),I(q);break}case"up":{D("hover"),C();const{onDragging:b}=v.current;b&&b(!1);break}}else D("inactive")})},[R,y,n,Y,m,N,I,A,C]),qb({disabled:n,handleId:N,resizeHandler:I,panelGroupElement:w}),br(d,{...f,children:e,className:t,id:i,onBlur:()=>{T(!1),s==null||s()},onFocus:()=>{T(!0),a==null||a()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":y,"data-panel-group-id":j,"data-resize-handle":"","data-resize-handle-active":J==="drag"?"pointer":_?"keyboard":void 0,"data-resize-handle-state":J,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":N})}Yf.displayName="PanelResizeHandle";const Gb=({className:e,...t})=>u.jsx(Gf,{className:G("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Xs=zf,$l=({withHandle:e,className:t,...n})=>u.jsx(Yf,{className:G("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-none data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",t),...n,children:e&&u.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:u.jsx(Hg,{className:"h-2.5 w-2.5"})})}),Kf=x.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:G("flex min-h-[80px] w-full rounded-sm border border-input bg-background px-3 py-2 text-sm shadow-xs","placeholder:text-muted-foreground","focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring","disabled:cursor-not-allowed disabled:opacity-50",e),ref:n,...t}));Kf.displayName="Textarea";class Yb{constructor(t){el(this,"client");this.client=hx.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 Kb=new Yb;function Xb(){const e=x.useRef(null),t=x.useCallback(async(r,i,s,o,a)=>{e.current&&e.current.abort();const l=new AbortController;e.current=l;try{o==null||o("parsing","Validating JSON structure...");let c;try{c=JSON.parse(i)}catch(w){throw new Error(`Invalid JSON: ${w instanceof Error?w.message:"Unknown parse error"}`)}o==null||o("building",`Building ${_i.toLowerCase()} structure...`);const d={jsonDefinition:c,options:{...a,sourceName:r}};d.customThemes=s??{},o==null||o("rendering",`Generating ${ot.toUpperCase()} content...`);const f={"Content-Type":"application/json"};a!=null&&a.bypassCache&&(f["X-Bypass-Cache"]="true");const p=await fetch(Ji.generate,{method:"POST",headers:f,body:JSON.stringify(d),signal:l.signal}),h=await p.json();if(!p.ok||!h.success){const w=h.error||h.message||`API request failed with status: ${p.status}`;throw new Error(w)}const{data:g,cache:v,warnings:S}=h,y=v.status==="HIT"?"HIT":v.status==="MISS"?"MISS":"UNKNOWN",j=y==="HIT"?`Served from cache (Hit rate: ${v.hitRate})`:`Generated fresh ${_i.toLowerCase()}`;o==null||o("finalizing",j);const m=globalThis.atob(g.document),A=new Uint8Array(m.length);for(let w=0;w<m.length;w++)A[w]=m.charCodeAt(w);const C=new Blob([A],{type:g.contentType});if(C.size===0)throw new Error(`Received empty ${_i.toLowerCase()} from API`);return{name:r,text:i,blob:C,filename:g.filename,fileId:g.fileId,cacheStatus:y,cacheHitRate:v.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${_i} generation was cancelled`):c}finally{e.current===l&&(e.current=null)}},[]),n=x.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:t,generateDocument:t,cancelGeneration:n}}function Qb(e){if(!e||e.length===0)return null;const t=[{name:"heading",props:{level:1,text:"Document Generation Warnings"}},{name:"paragraph",props:{text:`${e.length} warning(s) were generated during document processing.`,spacing:{after:240}}}],n=new Map;for(const r of e){const i=n.get(r.component)||[];i.push(r),n.set(r.component,i)}for(const[r,i]of n.entries()){t.push({name:"heading",props:{level:2,text:`Component: ${r}`}});const s=[];for(const o of i){let a=o.message;if(o.context&&Object.keys(o.context).length>0){const l=Object.entries(o.context).map(([c,d])=>`${c}: ${JSON.stringify(d)}`).join(", ");a+=` (${l})`}s.push(a)}t.push({name:"list",props:{items:s,spacing:{after:120}}})}return{name:"docx",props:{metadata:{title:"Generation Warnings"},theme:"minimal"},children:t}}function ev({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=je.useState("custom");je.useEffect(()=>{e&&s("custom")},[e]);const o=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),a=[{value:"custom",title:"Keep custom fonts",desc:"Recipients with the font installed see the authored typeface. Others get a generic fallback."},{value:"substitute",title:"Convert to safe fonts",desc:"Rewrite non-safe families to Calibri / Georgia / Consolas so every recipient sees the same glyphs."}];return u.jsx(Ct,{open:e,onOpenChange:l=>!l&&t(),children:u.jsxs(kt,{className:"max-w-md",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Non-safe fonts in this document"}),u.jsxs(an,{children:[o," ",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:a.map(l=>{const c=i===l.value;return u.jsxs("button",{type:"button",onClick:()=>s(l.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${c?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${c?"border-primary":"border-muted-foreground/50"}`,children:c&&u.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),u.jsx("span",{className:"text-sm font-medium",children:l.title})]}),u.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:l.desc})]},l.value)})}),u.jsxs(bn,{children:[u.jsx(_e,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(_e,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const Fl=ot==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],Qs={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function tv({name:e,blob:t,displayReloadButton:n,iframeRef:r,autoReload:i,onToggleAutoReload:s,onManualRender:o,isGenerating:a,isRendering:l,onShowCacheMetrics:c,onShowSchemas:d,onShowFonts:f,documentText:p,editorDocumentText:h,warnings:g,renderingLibrary:v,setRenderingLibrary:S,onToggleChat:y,chatOpen:j,onTogglePreview:m,previewOpen:A}){const C=v!=="docxjs",[w,N]=x.useState(!1),[J,D]=x.useState(!1),[_,T]=x.useState(!1),[I,z]=x.useState(!1),[O,R]=x.useState(!1),[Y,H]=x.useState(!1),[$,ee]=x.useState(null),{toast:k}=jr(),{generateDocument:oe}=Xb(),q=x.useContext(Od),b=x.useCallback(()=>{const X={},{customThemes:we}=q.getState();return Object.values(we).forEach(E=>{E.valid&&E.parsed&&(X[E.name]=E.parsed)}),X},[q]),B=je.useMemo(()=>{if(!p)return[];try{const X=JSON.parse(p);return[...(ot==="pptx"?vg:wg)(X)].filter(E=>!kg(E))}catch{return[]}},[p]),[V,re]=x.useState(!1),se=x.useCallback(async()=>{if(t){N(!0);try{await new Promise(X=>setTimeout(X,100)),Li(`${e}${Ir}`,t)}finally{setTimeout(()=>N(!1),500)}}},[t,e]),P=x.useCallback(async()=>{if(t){if(B.length===0){await se();return}re(!0)}},[t,B.length,se]),ue=x.useCallback(async X=>{var we;if(p){N(!0);try{const E=await oe(e,p,b(),void 0,{bypassCache:!0,fonts:{mode:X}});if(E.blob.size===0)k({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Li(`${e}${Ir}`,E.blob);const M=(we=E.warnings)==null?void 0:we.find(F=>{var ne,Q;return((ne=F.context)==null?void 0:ne.code)==="FONT_MODE_SUBSTITUTED"||((Q=F.context)==null?void 0:Q.code)==="FONT_MODE_CUSTOM"});M&&k({title:X==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:M.message})}}catch(E){k({title:"Export failed",description:E instanceof Error?E.message:String(E),variant:"destructive"})}finally{setTimeout(()=>N(!1),500)}}},[p,e,oe,k,b]),he=x.useCallback(async()=>{if(!(!g||g.length===0)){D(!0);try{const X=Qb(g);if(!X){k({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const we=await oe("warnings",JSON.stringify(X,null,2),{});we&&typeof we=="object"&&"blob"in we&&we.blob&&(Li(`${e}-warnings${Ir}`,we.blob),k({title:"Warnings downloaded",description:`Downloaded warnings document with ${g.length} warning(s).`}))}catch(X){console.error("Failed to generate warnings document:",X),k({title:"Download failed",description:X instanceof Error?X.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>D(!1),500)}}},[g,e,oe,k]),ce=x.useCallback(async()=>{const X=r==null?void 0:r.current;if(X!=null&&X.src){T(!0);try{await new Promise(E=>{let M=null,F=!1;const ne=()=>{M&&(clearTimeout(M),M=null),X.removeEventListener("load",te),X.removeEventListener("error",de)},Q=()=>{F||(F=!0,ne(),E())},te=()=>Q(),de=()=>Q();X.addEventListener("load",te),X.addEventListener("error",de),M=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),Q()},5e3);const ve=X.src,Z=ve.includes("?")?"&":"?",K=Date.now();X.src=`${ve}${Z}_reload=${K}`})}catch(we){console.error("Iframe reload failed:",we)}finally{T(!1)}}},[r]),pe=x.useCallback(async()=>{z(!0);try{await Kb.delete(`/${ot}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),k({title:"Cache Cleared",description:"All caches (document and component) have been successfully cleared.",variant:"default"})}catch(X){console.error("Failed to clear cache:",X),k({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{z(!1)}},[k]),me=h??p,U=x.useCallback(()=>{var E,M;if(!me){k({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(me)}catch{k({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}H(!0);const X=(async()=>{const F=await fetch(`/api/${ot}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:me,customThemes:b(),options:{sourceName:e}})});if(!F.ok){let Q=`Request failed with status ${F.status}`;try{const te=await F.json(),de=te.error??te.message;typeof de=="string"&&de&&(Q=de)}catch{}throw new Error(Q)}const ne=await F.json();return JSON.stringify(ne.data,null,2)})();let we;typeof ClipboardItem<"u"&&((E=navigator.clipboard)!=null&&E.write)?we=navigator.clipboard.write([new ClipboardItem({"text/plain":X.then(F=>new Blob([F],{type:"text/plain"}))})]):(M=navigator.clipboard)!=null&&M.writeText?we=X.then(F=>navigator.clipboard.writeText(F)):we=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await we,k({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(F){let ne=null;try{ne=await X}catch(Q){console.error("Error fetching standard components:",Q),k({title:"Failed to get standard components",description:Q instanceof Error?Q.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",F),ee(ne)}finally{H(!1)}})()},[me,e,b,k]),Te=x.useCallback(async()=>{if($!=null)try{await navigator.clipboard.writeText($),k({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),ee(null)}catch{k({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[$,k]);return u.jsxs(u.Fragment,{children:[u.jsxs("div",{className:"bg-sidebar border-b flex flex-row flex-nowrap items-center justify-between gap-x-2 px-3 py-1.5",children:[u.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[u.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),u.jsxs(qe,{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-sm hover:bg-muted/60 shrink-0",children:u.jsx(Cd,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),u.jsx(Ye,{className:"max-w-sm",children:u.jsxs("p",{className:"text-sm",children:["Preview uses"," ",ot==="docx"?"docx-preview":"LibreOffice PDF conversion",". Download the ",Ir," to verify fidelity."]})})]})]}),u.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[(!i||C)&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(_e,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:o,"aria-label":"Render preview",disabled:a||l||A===!1,children:[l?u.jsx(sn,{size:"sm"}):u.jsx(Wg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),u.jsx(Ye,{children:u.jsx("p",{children:A===!1?"Open preview to run":l?"Rendering preview...":"Render preview"})})]}),ot==="docx"&&u.jsxs(qe,{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(sr,{className:"text-xs text-muted-foreground hidden sm:inline",children:"Auto"}),u.jsx(va,{checked:i,onCheckedChange:s,disabled:C})]})}),u.jsx(Ye,{children:u.jsx("p",{children:C?"Auto-reload is not available for Office, Docs, and LibreOffice renderers":`${i?"Disable":"Enable"} automatic preview reload on content changes`})})]}),n&&i&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:ce,disabled:_||a||l,children:_?u.jsx(sn,{size:"sm"}):u.jsx(qg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsx("p",{children:_?"Reloading...":"Reload"})})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsxs(_e,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||w||a,onClick:P,children:[w?u.jsx(sn,{size:"sm"}):u.jsx(Gg,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),u.jsx(Ye,{children:u.jsxs("p",{children:["Download ",Ir]})})]}),g&&g.length>0&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:J||a,onClick:he,children:J?u.jsx(sn,{size:"sm"}):u.jsx(Id,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("p",{children:["Download warnings (",g.length,")"]})})]}),v&&S&&u.jsxs(ei,{value:v,onValueChange:S,children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(hr,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(ti,{placeholder:"Renderer"})})}),u.jsx(Ye,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(mr,{className:"text-sidebar-foreground",children:Fl.map(X=>u.jsxs(Dn,{value:X,children:[u.jsxs(qe,{children:[u.jsx(Ge,{tabIndex:-1,children:Qs[X][0]}),u.jsx(Ye,{children:Qs[X][1]})]})," ",X]},X))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(js,{children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ns,{asChild:!0,children:u.jsx(_e,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(Nd,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ye,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(xi,{align:"end",className:"w-52",children:[d&&u.jsxs(Ft,{onClick:d,children:[u.jsx(Yg,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),f&&u.jsxs(Ft,{onClick:f,children:[u.jsx(jo,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Ft,{onClick:c,children:[u.jsx(No,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),me?u.jsxs(Ft,{onClick:U,disabled:Y,children:[u.jsx(Eo,{className:"h-4 w-4 mr-2"}),Y?"Copying...":"Copy standard components"]}):u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs(Ft,{disabled:!0,children:[u.jsx(Eo,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),u.jsx(Ye,{side:"left",children:u.jsx("p",{children:"No document selected — open or select a document first"})})]}),u.jsx(xr,{}),u.jsxs(Ft,{onClick:()=>R(!0),disabled:I,className:"text-destructive focus:text-destructive",children:[u.jsx(ca,{className:"h-4 w-4 mr-2"}),I?"Clearing...":"Clear all caches"]}),v&&S&&u.jsxs(u.Fragment,{children:[u.jsx(xr,{className:"lg:hidden"}),Fl.map(X=>u.jsxs(Ft,{className:"lg:hidden",onClick:()=>S(X),children:[u.jsx("span",{className:"mr-2",children:v===X?"●":"○"}),Qs[X][0]," ",X]},X))]})]})]}),m&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:A?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:m,children:A?u.jsx(Ad,{className:"h-3.5 w-3.5"}):u.jsx(Kg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[A?"Hide":"Show"," Preview"," ",u.jsx(ri,{shortcut:"mod+shift+p"})]})})]}),y&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(_e,{variant:j?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:y,children:u.jsx(zd,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[j?"Close":"Open"," AI Chat"," ",u.jsx(ri,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(ev,{open:V,onClose:()=>re(!1),nonSafeFonts:B,onChoose:ue}),u.jsx(Ct,{open:$!=null,onOpenChange:X=>{X||ee(null)},children:u.jsxs(kt,{className:"max-w-lg",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Standard components"}),u.jsx(an,{children:"The browser blocked the automatic clipboard write. Copy the JSON from here instead."})]}),u.jsx(Kf,{readOnly:!0,value:$??"",className:"h-64 font-mono text-xs",onFocus:X=>X.currentTarget.select()}),u.jsxs(bn,{children:[u.jsx(_e,{variant:"outline",size:"sm",onClick:()=>ee(null),children:"Close"}),u.jsx(_e,{size:"sm",onClick:Te,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:O,onOpenChange:R,children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Clear all caches?"}),u.jsx(an,{children:"This will clear the document, component, and rasterized-visual caches. Next generation will be uncached."})]}),u.jsxs(bn,{children:[u.jsx(_e,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),u.jsx(_e,{variant:"destructive",size:"sm",disabled:I,onClick:async()=>{await pe(),R(!1)},children:I?u.jsx(sn,{size:"sm"}):"Clear"})]})]})})]})}const nv=je.memo(tv),Xf=mg,ja=x.forwardRef(({className:e,...t},n)=>u.jsx(xd,{ref:n,className:G("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));ja.displayName=xd.displayName;const cr=x.forwardRef(({className:e,...t},n)=>u.jsx(yd,{ref:n,className:G("ring-offset-background focus-visible:ring-ring data-[state=active]:bg-background data-[state=active]:text-foreground inline-flex cursor-pointer items-center justify-center rounded-sm px-3 py-1 text-sm font-medium whitespace-nowrap transition-all focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:pointer-events-none disabled:opacity-50",e),...t}));cr.displayName=yd.displayName;const dr=x.forwardRef(({className:e,...t},n)=>u.jsx(bd,{ref:n,className:G("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));dr.displayName=bd.displayName;async function rv(e){if(navigator.clipboard&&navigator.clipboard.writeText)try{return await navigator.clipboard.writeText(e),!0}catch(t){console.warn("Clipboard API failed, falling back to legacy method:",t)}try{const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.width="2em",t.style.height="2em",t.style.padding="0",t.style.border="none",t.style.outline="none",t.style.boxShadow="none",t.style.background="transparent",document.body.appendChild(t),t.focus(),t.select();const n=document.execCommand("copy");return document.body.removeChild(t),n}catch(t){return console.error("Failed to copy text to clipboard:",t),!1}}function iv(e){try{const t=typeof e=="string"?JSON.parse(e):e;return JSON.stringify(t,null,2)}catch(t){return console.error("Failed to format schema:",t),typeof e=="string"?e:JSON.stringify(e)}}async function sv(e){const t=iv(e);return rv(t)}const ov=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=x.useState(n),[s,o]=x.useState(null),[a,l]=x.useState(null),[c,d]=x.useState(!1),[f,p]=x.useState(!1),[h,g]=x.useState(null),[v,S]=x.useState(null),[y,j]=x.useState(!1),{toast:m}=jr(),A=Bt(z=>z.selectedPlugins),C=Array.from(A);x.useEffect(()=>{n&&i(n)},[n]);const w=x.useCallback(async()=>{d(!0),g(null);try{const z=await Zs.fetchDocumentSchema(C);o(z)}catch(z){const O=z instanceof Error?z.message:"Failed to load document schema";g(O),m({variant:"destructive",title:"Error loading schema",description:O})}finally{d(!1)}},[C,m]),N=x.useCallback(async()=>{if(!a){p(!0),S(null);try{const z=await Zs.fetchThemeSchema();l(z)}catch(z){const O=z instanceof Error?z.message:"Failed to load theme schema";S(O),m({variant:"destructive",title:"Error loading schema",description:O})}finally{p(!1)}}},[a,m]),[J,D]=x.useState([]);x.useEffect(()=>{e||(o(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const z=C.length!==J.length||C.some((O,R)=>O!==J[R]);r==="document"?(!s||z)&&(z&&(Zs.clearPluginSchemaCache(),D([...C])),c||w()):r==="theme"&&!a&&!f&&N()},[r,e,s,a,c,f,C,J,w,N]);const _=C.length,T=r==="document"?s:a,I=async()=>{if(T)try{await sv(T)&&(j(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>j(!1),2e3))}catch(z){console.error("Copy failed:",z)}};return u.jsx(Ct,{open:e,onOpenChange:t,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:"Schema Viewer"})}),u.jsxs(Xf,{value:r,onValueChange:z=>i(z),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ja,{children:[u.jsxs(cr,{value:"document",className:"flex items-center gap-1",children:["Document",_>0&&u.jsxs(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",_]})]}),u.jsx(cr,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(_e,{variant:"ghost",size:"icon",onClick:I,disabled:y||!T,"aria-label":"Copy schema",children:y?u.jsx(yn,{className:"h-4 w-4"}):u.jsx(ws,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(dr,{value:"document",className:"h-full",children:u.jsx(es,{schema:s,loading:c,error:h||void 0})}),u.jsx(dr,{value:"theme",className:"h-full",children:u.jsx(es,{schema:a,loading:f,error:v||void 0})})]})]})]})})};function Qf(e,t,n){if(t.length===0)return n;const r=Ll(e,t[0]);let i=r;for(let s=0;s<t.length-1;s++){const o=t[s],a=t[s+1],l=i[o],c=Ll(l,a);i[o]=c,i=c}return i[t[t.length-1]]=n,r}function Ll(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const Bl=2*1024*1024,Zl=12*1024*1024;function av(e){if(e.length<4)return"unknown";const[t,n,r,i]=e;return t===0&&n===1&&r===0&&i===0||t===116&&n===114&&r===117&&i===101||t===116&&n===116&&r===99&&i===102?"ttf":t===79&&n===84&&r===84&&i===79?"otf":t===119&&n===79&&r===70&&i===70?"woff":t===119&&n===79&&r===70&&i===50?"woff2":"unknown"}function lv(e){let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function rs(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.round(e/1024)} KB`}function uv(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>Bl)return{ok:!1,message:`"${e}" is ${rs(t.length)}. The limit is ${rs(Bl)} per font, because the bytes travel inside the document JSON.`};const n=av(t);return n==="woff"||n==="woff2"?{ok:!1,message:`"${e}" is a ${n.toUpperCase()} file. Upload the TTF or OTF instead — the preview renderer cannot register web font formats.`}:n!=="ttf"&&n!=="otf"?{ok:!1,message:`"${e}" does not look like a TTF or OTF font file.`}:{ok:!0,format:n,base64:lv(t)}}const cv=new Set(["italic","oblique"]);function dv(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[o,a]of Object.entries(kd))r.set(a.toLowerCase(),Number(o));let i=400,s=!1;for(;n.length>1;){const o=n[n.length-1].toLowerCase();if(cv.has(o)){s=!0,n.pop();continue}const a=r.get(o);if(a!==void 0){i=a,n.pop();continue}break}return{family:n.join(" ")||t,weight:i,italic:s}}function fv(e,t){const n=Array.isArray(e)?[...e]:[],r=n.findIndex(i=>{var s;return((s=i==null?void 0:i.family)==null?void 0:s.toLowerCase())===t.family.toLowerCase()});return r>=0?n[r]=t:n.push(t),n}function pv(e){return e.kind==="safe"||e.kind==="google"?null:{weight:"weight"in e&&e.weight?e.weight:400,italic:"italic"in e?!!e.italic:!1}}function hv(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(a=>{const l=pv(a);return l?!n.some(c=>c.weight===l.weight&&c.italic===l.italic):!0}),s=n.map(a=>({kind:"data",data:a.data,weight:a.weight,italic:a.italic})),o=r??(e==null?void 0:e.category);return{id:(e==null?void 0:e.id)??t,family:t,...o?{category:o}:{},sources:[...i,...s]}}function mv(e,t){let n=Array.isArray(e)?[...e]:[];for(const r of t){const i=r.sources.filter(o=>o.kind==="data").map(o=>({data:o.data,weight:o.weight??400,italic:o.italic??!1}));if(i.length===0)continue;const s=n.find(o=>{var a;return((a=o==null?void 0:o.family)==null?void 0:a.toLowerCase())===r.family.toLowerCase()});n=fv(n,hv(s,r.family,i,r.category))}return n}function gv(e,t){const n=(e.sources??[]).filter(r=>r.format==="ttf"||r.format==="otf").map(r=>({kind:"data",data:r.data,weight:r.weight,italic:r.italic}));return n.length===0?null:{id:e.family,family:e.family,...t?{category:t}:{},sources:n}}function xv(e){const t=new TextEncoder().encode(e).length;return t<=Zl?null:`Adding this font would push the document to ${rs(t)}, past the ${rs(Zl)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const Vl=new Set,yv=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function bv(e){const t=e.startsWith("data:")?e.slice(e.indexOf(",")+1):e,n=atob(t),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r}async function vv(e,t,n,r){const i=yv(e,n,r);if(!Vl.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=bv(t),o=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await o.load(),document.fonts.add(o),Vl.add(i)}catch{}}const wv={safe:[],google:[]};function Ul(e,t){var d;const n=`gf-${e.replace(/\s+/g,"-")}`,r=document.getElementById(n),i=new Set(t&&t.length>0?t:[400,700]),s=new Set(((d=r==null?void 0:r.dataset.weights)==null?void 0:d.split(",").map(Number).filter(f=>!Number.isNaN(f)))??[]),o=new Set([...s,...i]);if(r&&o.size===s.size)return;const a=[...o].sort((f,p)=>f-p).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${a}&display=swap`,c=r??document.createElement("link");r||(c.id=n,c.rel="stylesheet",document.head.appendChild(c)),c.href=l,c.dataset.weights=[...o].sort((f,p)=>f-p).join(",")}function kv(){const e=Ce(i=>i.activeTab),t=Ce(i=>i.documents),n=Ce(i=>i.documentTypes),r=Ce(i=>i.saveDocument);return x.useCallback(i=>{if(!e)return{ok:!1,error:"No active file"};if(n[e]!=="application/json+theme")return{ok:!1,error:"Fonts are registered on themes, not documents. Open a .theme.json file and try again."};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active theme not found"};let o;try{o=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active theme is not valid JSON: ${l.message}`}}const a=i(o);return r(e,JSON.stringify(a,null,2)),{ok:!0,name:e}},[e,t,n,r])}function Sv(){const e=Ce(r=>r.activeTab),t=Ce(r=>r.documents),n=Ce(r=>r.saveDocument);return x.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(l=>l.name===e);if(!s)return{ok:!1,error:"Active document not found"};let o;try{o=JSON.parse(s.text)}catch(l){return{ok:!1,error:`Active document is not valid JSON: ${l.message}`}}const a=Qf(o,r,i);return n(e,JSON.stringify(a,null,2)),{ok:!0,name:e}},[e,t,n])}function _v(){const e=Ce(i=>i.activeTab),t=Ce(i=>i.documents),n=Ce(i=>i.documentTypes),r=Ce(i=>i.saveDocument);return x.useCallback(i=>{var f;if(i.length===0)return{ok:!0,name:e};if(!e)return{ok:!1,error:"No active file"};if(n[e]==="application/json+theme")return{ok:!1,error:"Custom fonts are registered on the document, not the theme. Open the .docx.json / .pptx.json tab and try again."};const s=t.find(p=>p.name===e);if(!s)return{ok:!1,error:"Active document not found"};let o;try{o=JSON.parse(s.text)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const a=mv((f=o==null?void 0:o.props)==null?void 0:f.fontRegistry,i),l=Qf(o,["props","fontRegistry"],a),c=JSON.stringify(l,null,2),d=xv(c);return d?{ok:!1,error:d}:(r(e,c),{ok:!0,name:e})},[e,t,n,r])}function jv(e,t,n){(!e.fonts||typeof e.fonts!="object")&&(e.fonts={});const r=e.fonts[t];r&&typeof r=="object"?e.fonts[t]={...r,family:n}:e.fonts[t]=n}function Jl(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Nv=({open:e,onOpenChange:t})=>{const n=$i(P=>P.open),r=$i(P=>P.contextual),i=$i(P=>P.close),s=e??n,o=r,a=x.useCallback(P=>{t&&t(P),P||i()},[t,i]),[l,c]=x.useState(wv),[d,f]=x.useState(!1),[p,h]=x.useState(""),[g,v]=x.useState("safe"),[S,y]=x.useState(null),[j,m]=x.useState(null),[A,C]=x.useState(!1),[w,N]=x.useState(!1),[J,D]=x.useState(""),[_,T]=x.useState([]),I=x.useRef(null),{toast:z}=jr(),O=kv(),R=Sv(),Y=_v(),H=Ce(P=>P.activeTab),$=Ce(P=>P.documentTypes),ee=H&&$[H]==="application/json+theme",k=!!o||ee;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(f(!0),fetch(Ji.fonts.catalog).then(P=>P.json()).then(P=>c(P)).catch(P=>{z({variant:"destructive",title:"Font catalog unavailable",description:P.message})}).finally(()=>f(!1))))},[s,l,z]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const P of l.google)Ul(P.family,P.weights)},[g,l]);const oe=x.useMemo(()=>l.safe.filter(P=>P.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),q=x.useMemo(()=>l.google.filter(P=>P.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),b=x.useCallback(async P=>{try{await navigator.clipboard.writeText(P),m(P),setTimeout(()=>m(null),1500)}catch{z({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[z]),B=x.useCallback(async(P,ue,he)=>{y(P);try{const ce=O(pe=>(jv(pe,he,P),pe));if(!ce.ok){z({variant:"destructive",title:"Could not insert font",description:ce.error});return}z({title:"Font inserted",description:`${P} set as ${he} font in "${ce.name}".`})}finally{y(null)}},[O,z]),V=x.useCallback(async P=>{if(o){y(P);try{const ue=R(o.jsonPath,P);if(!ue.ok){z({variant:"destructive",title:"Could not insert font",description:ue.error});return}z({title:"Font inserted",description:`${P} set at ${Jl(o.jsonPath)}.`}),a(!1)}finally{y(null)}}},[o,R,z,a]),re=x.useCallback(async P=>{if(!(!P||P.length===0)){C(!0);try{const ue=[];for(const ce of Array.from(P)){const pe=new Uint8Array(await ce.arrayBuffer()),me=uv(ce.name,pe);if(!me.ok){z({variant:"destructive",title:"Font rejected",description:me.message});continue}ue.push({identity:dv(ce.name),base64:me.base64})}if(ue.length===0)return;const he=Y(ue.map(({identity:ce,base64:pe})=>({id:ce.family,family:ce.family,sources:[{kind:"data",data:pe,weight:ce.weight,italic:ce.italic}]})));if(!he.ok){z({variant:"destructive",title:"Could not register font",description:he.error});return}for(const{identity:ce,base64:pe}of ue)vv(ce.family,pe,ce.weight,ce.italic),z({title:`Added ${ce.family}`,description:`Registered at weight ${ce.weight}${ce.italic?" italic":""} in props.fontRegistry. Reference it as "${ce.family}".`})}catch(ue){z({variant:"destructive",title:"Upload failed",description:ue.message})}finally{C(!1),I.current&&(I.current.value="")}}},[Y,z]),se=x.useCallback(async()=>{var ue,he;const P=J.trim();if(P){N(!0),T([]);try{const ce=await fetch(Ji.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:P,weights:[400,700],italics:!1})});if(ce.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!ce.ok){const X=await ce.json().catch(()=>({}));throw new Error(X.error??`Materialize failed (${ce.status})`)}const pe=await ce.json();T(pe.warnings??[]);const me=(ue=l.google.find(X=>X.family.toLowerCase()===pe.family.toLowerCase()))==null?void 0:ue.category,U=gv(pe,me);if(!U){z({variant:"destructive",title:"Nothing to embed",description:((he=pe.warnings)==null?void 0:he.join(" · "))||`Google Fonts has no family named "${P}".`});return}const Te=Y([U]);if(!Te.ok){z({variant:"destructive",title:"Could not register font",description:Te.error});return}Ul(pe.family,[400,700]),z({title:`Added ${pe.family}`,description:`Embedded ${U.sources.length} weight(s) in props.fontRegistry.`})}catch(ce){z({variant:"destructive",title:"Google Fonts fetch failed",description:ce.message})}finally{N(!1)}}},[J,l.google,Y,z]);return u.jsx(Ct,{open:s,onOpenChange:a,children:u.jsxs(kt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[u.jsx(Ut,{children:u.jsx(Jt,{children:o?`Font for ${Jl(o.jsonPath)}`:"Fonts"})}),!o&&!ee&&g!=="custom"&&u.jsx(or,{children:u.jsxs(ar,{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(Xf,{value:g,onValueChange:P=>v(P),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(ja,{children:[u.jsxs(cr,{value:"safe",children:["Safe",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(cr,{value:"google",children:["Google",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]}),u.jsx(cr,{value:"custom",children:"Custom"})]}),u.jsx(gr,{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(dr,{value:"safe",className:"m-0",children:d&&oe.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Lr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:oe.map(P=>u.jsx(Hl,{family:P,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${P}", sans-serif`},onCopy:()=>b(P),copied:j===P,contextual:!!o,onUseThis:()=>V(P),onInsertHeading:()=>B(P,"safe","heading"),onInsertBody:()=>B(P,"safe","body"),applying:S===P,disabled:!k},P))})}),u.jsx(dr,{value:"google",className:"m-0",children:d&&q.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(Lr,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:q.map(P=>u.jsx(Hl,{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:j===P.family,contextual:!!o,onUseThis:()=>V(P.family),onInsertHeading:()=>B(P.family,"google","heading"),onInsertBody:()=>B(P.family,"google","body"),applying:S===P.family,disabled:!k,extraAction:u.jsx(Cv,{family:P.family,weights:P.weights,hasItalic:P.hasItalic})},P.family))})}),u.jsx(dr,{value:"custom",className:"m-0 flex flex-col gap-6",children:ee?u.jsx(or,{children:u.jsxs(ar,{children:["Custom fonts are stored on the document (",u.jsx("code",{children:"props.fontRegistry"}),"), because the bytes travel with the JSON. Open a document tab to add one."]})}):u.jsxs(u.Fragment,{children:[u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Upload a font file"}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["TTF or OTF, up to 2 MB each. The font is embedded in the document as base64, so it survives export and re-import — and renders in the preview. The family and weight are guessed from the filename (e.g."," ",u.jsx("code",{children:"Geist-SemiBold.ttf"}),")."]}),u.jsxs("div",{onDragOver:P=>P.preventDefault(),onDrop:P=>{P.preventDefault(),re(P.dataTransfer.files)},className:"rounded-md border border-dashed p-6 text-center",children:[u.jsx("input",{ref:I,type:"file",accept:".ttf,.otf,font/ttf,font/otf",multiple:!0,className:"hidden",onChange:P=>void re(P.target.files)}),u.jsxs(_e,{variant:"secondary",disabled:A,onClick:()=>{var P;return(P=I.current)==null?void 0:P.click()},children:[A?u.jsx(Lr,{className:"animate-spin mr-2 h-4 w-4"}):u.jsx(Xg,{className:"mr-2 h-4 w-4"}),"Choose font files"]}),u.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"or drop them here"})]})]}),u.jsxs("section",{className:"flex flex-col gap-2",children:[u.jsx("h3",{className:"text-sm font-medium",children:"Embed any Google font"}),u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not limited to the ",l.google.length," curated families — type any Google Fonts family name and its regular and bold weights are fetched and embedded."]}),u.jsxs("div",{className:"flex gap-2",children:[u.jsx(gr,{placeholder:"e.g. Geist",value:J,onChange:P=>D(P.target.value),onKeyDown:P=>{P.key==="Enter"&&se()}}),u.jsxs(_e,{onClick:()=>void se(),disabled:w||J.trim()==="",children:[w&&u.jsx(Lr,{className:"animate-spin mr-2 h-4 w-4"}),"Embed"]})]}),_.length>0&&u.jsx(or,{children:u.jsx(ar,{className:"text-xs",children:_.join(" · ")})})]})]})})]})]})]})})},Ev="The quick brown fox jumps over the lazy dog",Cv=({family:e,weights:t,hasItalic:n})=>{const r=x.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(js,{children:[u.jsx(Ns,{asChild:!0,children:u.jsx(_e,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(xi,{align:"end",className:"min-w-[260px]",children:[u.jsxs(uf,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(xr,{}),r.map(i=>{const s=kd[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)})]})]})},Hl=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:o,onInsertHeading:a,onInsertBody:l,applying:c,disabled:d,extraAction:f})=>u.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[u.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[u.jsx("div",{className:"font-medium truncate",children:e}),u.jsx("div",{className:"text-muted-foreground",children:t})]}),u.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:Ev}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(_e,{size:"sm",onClick:o,disabled:c||d,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):u.jsxs(u.Fragment,{children:[u.jsx(_e,{size:"sm",variant:"secondary",onClick:a,disabled:c||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(_e,{size:"sm",variant:"secondary",onClick:l,disabled:c||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,u.jsx(_e,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(yn,{className:"h-4 w-4"}):u.jsx(ws,{className:"h-4 w-4"})})]})]});function Wl({previewOpen:e,onTogglePreview:t}){const n=rn(D=>D.name||""),r=rn(D=>D.blob),i=rn(D=>D.isGenerating),s=rn(D=>D.text),o=rn(D=>D.warnings),a=rn(D=>D.isRendering),l=ji(D=>D.autoReload),c=ji(D=>D.renderingLibrary),d=ji(D=>D.setSettings),f=ji(D=>D.useGlobalPreviewHeader??!0),p=Ce(D=>D.activeTab),h=Ce(D=>D.documentTypes),g=p&&h[p]==="application/json+theme"?"theme":"document",v=Ce(D=>{var _;return D.activeTab&&D.documentTypes[D.activeTab]!=="application/json+theme"?(_=D.documents.find(T=>T.name===D.activeTab))==null?void 0:_.text:void 0}),S=Re(D=>D.chatOpen),y=Re(D=>D.toggleChat),[j,m]=je.useState(!1),A=$i(D=>D.openFor);if(!f)return null;const C=x.useCallback(()=>d({saveDocumentDebounceWait:2e3,autoReload:!l}),[l,d]),w=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),N=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),J=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(nv,{name:J,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:C,onManualRender:w,isGenerating:i,isRendering:!!a,onShowCacheMetrics:N,onShowSchemas:()=>m(!0),onShowFonts:()=>A(),documentText:s,editorDocumentText:v,warnings:o,renderingLibrary:c,setRenderingLibrary:D=>d({renderingLibrary:D}),onToggleChat:y,chatOpen:S,onTogglePreview:t,previewOpen:e}),u.jsx(ov,{open:j,onOpenChange:m,defaultTab:g==="theme"?"theme":"document"}),u.jsx(Nv,{})]})}function Tv(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Iv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Av=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,zv={};function ql(e,t){return(zv.jsx?Av:Iv).test(e)}const Ov=/[ \t\n\f\r]/g;function Pv(e){return typeof e=="object"?e.type==="text"?Gl(e.value):!1:Gl(e)}function Gl(e){return e.replace(Ov,"")===""}class yi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}yi.prototype.normal={};yi.prototype.property={};yi.prototype.space=void 0;function ep(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new yi(n,r,t)}function Lo(e){return e.toLowerCase()}class St{constructor(t,n){this.attribute=n,this.property=t}}St.prototype.attribute="";St.prototype.booleanish=!1;St.prototype.boolean=!1;St.prototype.commaOrSpaceSeparated=!1;St.prototype.commaSeparated=!1;St.prototype.defined=!1;St.prototype.mustUseProperty=!1;St.prototype.number=!1;St.prototype.overloadedBoolean=!1;St.prototype.property="";St.prototype.spaceSeparated=!1;St.prototype.space=void 0;let Dv=0;const Se=Fn(),nt=Fn(),Bo=Fn(),ie=Fn(),Ze=Fn(),fr=Fn(),jt=Fn();function Fn(){return 2**++Dv}const Zo=Object.freeze(Object.defineProperty({__proto__:null,boolean:Se,booleanish:nt,commaOrSpaceSeparated:jt,commaSeparated:fr,number:ie,overloadedBoolean:Bo,spaceSeparated:Ze},Symbol.toStringTag,{value:"Module"})),eo=Object.keys(Zo);class Na extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),Yl(this,"space",i),typeof r=="number")for(;++s<eo.length;){const o=eo[s];Yl(this,eo[s],(r&Zo[o])===Zo[o])}}}Na.prototype.defined=!0;function Yl(e,t,n){n&&(e[t]=n)}function Nr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Na(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Lo(r)]=r,n[Lo(s.attribute)]=r}return new yi(t,n,e.space)}const tp=Nr({properties:{ariaActiveDescendant:null,ariaAtomic:nt,ariaAutoComplete:null,ariaBusy:nt,ariaChecked:nt,ariaColCount:ie,ariaColIndex:ie,ariaColSpan:ie,ariaControls:Ze,ariaCurrent:null,ariaDescribedBy:Ze,ariaDetails:null,ariaDisabled:nt,ariaDropEffect:Ze,ariaErrorMessage:null,ariaExpanded:nt,ariaFlowTo:Ze,ariaGrabbed:nt,ariaHasPopup:null,ariaHidden:nt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Ze,ariaLevel:ie,ariaLive:null,ariaModal:nt,ariaMultiLine:nt,ariaMultiSelectable:nt,ariaOrientation:null,ariaOwns:Ze,ariaPlaceholder:null,ariaPosInSet:ie,ariaPressed:nt,ariaReadOnly:nt,ariaRelevant:null,ariaRequired:nt,ariaRoleDescription:Ze,ariaRowCount:ie,ariaRowIndex:ie,ariaRowSpan:ie,ariaSelected:nt,ariaSetSize:ie,ariaSort:null,ariaValueMax:ie,ariaValueMin:ie,ariaValueNow:ie,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function np(e,t){return t in e?e[t]:t}function rp(e,t){return np(e,t.toLowerCase())}const Rv=Nr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:fr,acceptCharset:Ze,accessKey:Ze,action:null,allow:null,allowFullScreen:Se,allowPaymentRequest:Se,allowUserMedia:Se,alt:null,as:null,async:Se,autoCapitalize:null,autoComplete:Ze,autoFocus:Se,autoPlay:Se,blocking:Ze,capture:null,charSet:null,checked:Se,cite:null,className:Ze,cols:ie,colSpan:null,content:null,contentEditable:nt,controls:Se,controlsList:Ze,coords:ie|fr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Se,defer:Se,dir:null,dirName:null,disabled:Se,download:Bo,draggable:nt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Se,formTarget:null,headers:Ze,height:ie,hidden:Bo,high:ie,href:null,hrefLang:null,htmlFor:Ze,httpEquiv:Ze,id:null,imageSizes:null,imageSrcSet:null,inert:Se,inputMode:null,integrity:null,is:null,isMap:Se,itemId:null,itemProp:Ze,itemRef:Ze,itemScope:Se,itemType:Ze,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Se,low:ie,manifest:null,max:null,maxLength:ie,media:null,method:null,min:null,minLength:ie,multiple:Se,muted:Se,name:null,nonce:null,noModule:Se,noValidate:Se,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:Se,optimum:ie,pattern:null,ping:Ze,placeholder:null,playsInline:Se,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Se,referrerPolicy:null,rel:Ze,required:Se,reversed:Se,rows:ie,rowSpan:ie,sandbox:Ze,scope:null,scoped:Se,seamless:Se,selected:Se,shadowRootClonable:Se,shadowRootDelegatesFocus:Se,shadowRootMode:null,shape:null,size:ie,sizes:null,slot:null,span:ie,spellCheck:nt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:ie,step:null,style:null,tabIndex:ie,target:null,title:null,translate:null,type:null,typeMustMatch:Se,useMap:null,value:nt,width:ie,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ze,axis:null,background:null,bgColor:null,border:ie,borderColor:null,bottomMargin:ie,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Se,declare:Se,event:null,face:null,frame:null,frameBorder:null,hSpace:ie,leftMargin:ie,link:null,longDesc:null,lowSrc:null,marginHeight:ie,marginWidth:ie,noResize:Se,noHref:Se,noShade:Se,noWrap:Se,object:null,profile:null,prompt:null,rev:null,rightMargin:ie,rules:null,scheme:null,scrolling:nt,standby:null,summary:null,text:null,topMargin:ie,valueType:null,version:null,vAlign:null,vLink:null,vSpace:ie,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Se,disableRemotePlayback:Se,prefix:null,property:null,results:ie,security:null,unselectable:null},space:"html",transform:rp}),Mv=Nr({attributes:{accentHeight:"accent-height",alignmentBaseline:"alignment-baseline",arabicForm:"arabic-form",baselineShift:"baseline-shift",capHeight:"cap-height",className:"class",clipPath:"clip-path",clipRule:"clip-rule",colorInterpolation:"color-interpolation",colorInterpolationFilters:"color-interpolation-filters",colorProfile:"color-profile",colorRendering:"color-rendering",crossOrigin:"crossorigin",dataType:"datatype",dominantBaseline:"dominant-baseline",enableBackground:"enable-background",fillOpacity:"fill-opacity",fillRule:"fill-rule",floodColor:"flood-color",floodOpacity:"flood-opacity",fontFamily:"font-family",fontSize:"font-size",fontSizeAdjust:"font-size-adjust",fontStretch:"font-stretch",fontStyle:"font-style",fontVariant:"font-variant",fontWeight:"font-weight",glyphName:"glyph-name",glyphOrientationHorizontal:"glyph-orientation-horizontal",glyphOrientationVertical:"glyph-orientation-vertical",hrefLang:"hreflang",horizAdvX:"horiz-adv-x",horizOriginX:"horiz-origin-x",horizOriginY:"horiz-origin-y",imageRendering:"image-rendering",letterSpacing:"letter-spacing",lightingColor:"lighting-color",markerEnd:"marker-end",markerMid:"marker-mid",markerStart:"marker-start",navDown:"nav-down",navDownLeft:"nav-down-left",navDownRight:"nav-down-right",navLeft:"nav-left",navNext:"nav-next",navPrev:"nav-prev",navRight:"nav-right",navUp:"nav-up",navUpLeft:"nav-up-left",navUpRight:"nav-up-right",onAbort:"onabort",onActivate:"onactivate",onAfterPrint:"onafterprint",onBeforePrint:"onbeforeprint",onBegin:"onbegin",onCancel:"oncancel",onCanPlay:"oncanplay",onCanPlayThrough:"oncanplaythrough",onChange:"onchange",onClick:"onclick",onClose:"onclose",onCopy:"oncopy",onCueChange:"oncuechange",onCut:"oncut",onDblClick:"ondblclick",onDrag:"ondrag",onDragEnd:"ondragend",onDragEnter:"ondragenter",onDragExit:"ondragexit",onDragLeave:"ondragleave",onDragOver:"ondragover",onDragStart:"ondragstart",onDrop:"ondrop",onDurationChange:"ondurationchange",onEmptied:"onemptied",onEnd:"onend",onEnded:"onended",onError:"onerror",onFocus:"onfocus",onFocusIn:"onfocusin",onFocusOut:"onfocusout",onHashChange:"onhashchange",onInput:"oninput",onInvalid:"oninvalid",onKeyDown:"onkeydown",onKeyPress:"onkeypress",onKeyUp:"onkeyup",onLoad:"onload",onLoadedData:"onloadeddata",onLoadedMetadata:"onloadedmetadata",onLoadStart:"onloadstart",onMessage:"onmessage",onMouseDown:"onmousedown",onMouseEnter:"onmouseenter",onMouseLeave:"onmouseleave",onMouseMove:"onmousemove",onMouseOut:"onmouseout",onMouseOver:"onmouseover",onMouseUp:"onmouseup",onMouseWheel:"onmousewheel",onOffline:"onoffline",onOnline:"ononline",onPageHide:"onpagehide",onPageShow:"onpageshow",onPaste:"onpaste",onPause:"onpause",onPlay:"onplay",onPlaying:"onplaying",onPopState:"onpopstate",onProgress:"onprogress",onRateChange:"onratechange",onRepeat:"onrepeat",onReset:"onreset",onResize:"onresize",onScroll:"onscroll",onSeeked:"onseeked",onSeeking:"onseeking",onSelect:"onselect",onShow:"onshow",onStalled:"onstalled",onStorage:"onstorage",onSubmit:"onsubmit",onSuspend:"onsuspend",onTimeUpdate:"ontimeupdate",onToggle:"ontoggle",onUnload:"onunload",onVolumeChange:"onvolumechange",onWaiting:"onwaiting",onZoom:"onzoom",overlinePosition:"overline-position",overlineThickness:"overline-thickness",paintOrder:"paint-order",panose1:"panose-1",pointerEvents:"pointer-events",referrerPolicy:"referrerpolicy",renderingIntent:"rendering-intent",shapeRendering:"shape-rendering",stopColor:"stop-color",stopOpacity:"stop-opacity",strikethroughPosition:"strikethrough-position",strikethroughThickness:"strikethrough-thickness",strokeDashArray:"stroke-dasharray",strokeDashOffset:"stroke-dashoffset",strokeLineCap:"stroke-linecap",strokeLineJoin:"stroke-linejoin",strokeMiterLimit:"stroke-miterlimit",strokeOpacity:"stroke-opacity",strokeWidth:"stroke-width",tabIndex:"tabindex",textAnchor:"text-anchor",textDecoration:"text-decoration",textRendering:"text-rendering",transformOrigin:"transform-origin",typeOf:"typeof",underlinePosition:"underline-position",underlineThickness:"underline-thickness",unicodeBidi:"unicode-bidi",unicodeRange:"unicode-range",unitsPerEm:"units-per-em",vAlphabetic:"v-alphabetic",vHanging:"v-hanging",vIdeographic:"v-ideographic",vMathematical:"v-mathematical",vectorEffect:"vector-effect",vertAdvY:"vert-adv-y",vertOriginX:"vert-origin-x",vertOriginY:"vert-origin-y",wordSpacing:"word-spacing",writingMode:"writing-mode",xHeight:"x-height",playbackOrder:"playbackorder",timelineBegin:"timelinebegin"},properties:{about:jt,accentHeight:ie,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:ie,amplitude:ie,arabicForm:null,ascent:ie,attributeName:null,attributeType:null,azimuth:ie,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:ie,by:null,calcMode:null,capHeight:ie,className:Ze,clip:null,clipPath:null,clipPathUnits:null,clipRule:null,color:null,colorInterpolation:null,colorInterpolationFilters:null,colorProfile:null,colorRendering:null,content:null,contentScriptType:null,contentStyleType:null,crossOrigin:null,cursor:null,cx:null,cy:null,d:null,dataType:null,defaultAction:null,descent:ie,diffuseConstant:ie,direction:null,display:null,dur:null,divisor:ie,dominantBaseline:null,download:Se,dx:null,dy:null,edgeMode:null,editable:null,elevation:ie,enableBackground:null,end:null,event:null,exponent:ie,externalResourcesRequired:null,fill:null,fillOpacity:ie,fillRule:null,filter:null,filterRes:null,filterUnits:null,floodColor:null,floodOpacity:null,focusable:null,focusHighlight:null,fontFamily:null,fontSize:null,fontSizeAdjust:null,fontStretch:null,fontStyle:null,fontVariant:null,fontWeight:null,format:null,fr:null,from:null,fx:null,fy:null,g1:fr,g2:fr,glyphName:fr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:ie,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:ie,horizOriginX:ie,horizOriginY:ie,id:null,ideographic:ie,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:ie,k:ie,k1:ie,k2:ie,k3:ie,k4:ie,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:ie,local:null,markerEnd:null,markerMid:null,markerStart:null,markerHeight:null,markerUnits:null,markerWidth:null,mask:null,maskContentUnits:null,maskUnits:null,mathematical:null,max:null,media:null,mediaCharacterEncoding:null,mediaContentEncodings:null,mediaSize:ie,mediaTime:null,method:null,min:null,mode:null,name:null,navDown:null,navDownLeft:null,navDownRight:null,navLeft:null,navNext:null,navPrev:null,navRight:null,navUp:null,navUpLeft:null,navUpRight:null,numOctaves:null,observer:null,offset:null,onAbort:null,onActivate:null,onAfterPrint:null,onBeforePrint:null,onBegin:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnd:null,onEnded:null,onError:null,onFocus:null,onFocusIn:null,onFocusOut:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadStart:null,onMessage:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onMouseWheel:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRepeat:null,onReset:null,onResize:null,onScroll:null,onSeeked:null,onSeeking:null,onSelect:null,onShow:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnload:null,onVolumeChange:null,onWaiting:null,onZoom:null,opacity:null,operator:null,order:null,orient:null,orientation:null,origin:null,overflow:null,overlay:null,overlinePosition:ie,overlineThickness:ie,paintOrder:null,panose1:null,path:null,pathLength:ie,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ze,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:ie,pointsAtY:ie,pointsAtZ:ie,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:jt,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:jt,rev:jt,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:jt,requiredFeatures:jt,requiredFonts:jt,requiredFormats:jt,resource:null,restart:null,result:null,rotate:null,rx:null,ry:null,scale:null,seed:null,shapeRendering:null,side:null,slope:null,snapshotTime:null,specularConstant:ie,specularExponent:ie,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:ie,strikethroughThickness:ie,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:ie,strokeOpacity:ie,strokeWidth:null,style:null,surfaceScale:ie,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:ie,tableValues:null,target:null,targetX:ie,targetY:ie,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:jt,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:ie,underlineThickness:ie,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:ie,values:null,vAlphabetic:ie,vMathematical:ie,vectorEffect:null,vHanging:ie,vIdeographic:ie,version:null,vertAdvY:ie,vertOriginX:ie,vertOriginY:ie,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:ie,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:np}),ip=Nr({properties:{xLinkActuate:null,xLinkArcRole:null,xLinkHref:null,xLinkRole:null,xLinkShow:null,xLinkTitle:null,xLinkType:null},space:"xlink",transform(e,t){return"xlink:"+t.slice(5).toLowerCase()}}),sp=Nr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:rp}),op=Nr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),$v={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"},Fv=/[A-Z]/g,Kl=/-[a-z]/g,Lv=/^data[-\w.:]+$/i;function Bv(e,t){const n=Lo(t);let r=t,i=St;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Lv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Kl,Vv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Kl.test(s)){let o=s.replace(Fv,Zv);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=Na}return new i(r,t)}function Zv(e){return"-"+e.toLowerCase()}function Vv(e){return e.charAt(1).toUpperCase()}const Uv=ep([tp,Rv,ip,sp,op],"html"),Ea=ep([tp,Mv,ip,sp,op],"svg");function Jv(e){return e.join(" ").trim()}var Wn={},to,Xl;function Hv(){if(Xl)return to;Xl=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,l=`
|
|
10
10
|
`,c="/",d="*",f="",p="comment",h="declaration";function g(S,y){if(typeof S!="string")throw new TypeError("First argument must be a string");if(!S)return[];y=y||{};var j=1,m=1;function A(O){var R=O.match(t);R&&(j+=R.length);var Y=O.lastIndexOf(l);m=~Y?O.length-Y:m+O.length}function C(){var O={line:j,column:m};return function(R){return R.position=new w(O),D(),R}}function w(O){this.start=O,this.end={line:j,column:m},this.source=y.source}w.prototype.content=S;function N(O){var R=new Error(y.source+":"+j+":"+m+": "+O);if(R.reason=O,R.filename=y.source,R.line=j,R.column=m,R.source=S,!y.silent)throw R}function J(O){var R=O.exec(S);if(R){var Y=R[0];return A(Y),S=S.slice(Y.length),R}}function D(){J(n)}function _(O){var R;for(O=O||[];R=T();)R!==!1&&O.push(R);return O}function T(){var O=C();if(!(c!=S.charAt(0)||d!=S.charAt(1))){for(var R=2;f!=S.charAt(R)&&(d!=S.charAt(R)||c!=S.charAt(R+1));)++R;if(R+=2,f===S.charAt(R-1))return N("End of comment missing");var Y=S.slice(2,R-2);return m+=2,A(Y),S=S.slice(R),m+=2,O({type:p,comment:Y})}}function I(){var O=C(),R=J(r);if(R){if(T(),!J(i))return N("property missing ':'");var Y=J(s),H=O({type:h,property:v(R[0].replace(e,f)),value:Y?v(Y[0].replace(e,f)):f});return J(o),H}}function z(){var O=[];_(O);for(var R;R=I();)R!==!1&&(O.push(R),_(O));return O}return D(),z()}function v(S){return S?S.replace(a,f):f}return to=g,to}var Ql;function Wv(){if(Ql)return Wn;Ql=1;var e=Wn&&Wn.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Wn,"__esModule",{value:!0}),Wn.default=n;const t=e(Hv());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const o=(0,t.default)(r),a=typeof i=="function";return o.forEach(l=>{if(l.type!=="declaration")return;const{property:c,value:d}=l;a?i(c,d,l):d&&(s=s||{},s[c]=d)}),s}return Wn}var Dr={},eu;function qv(){if(eu)return Dr;eu=1,Object.defineProperty(Dr,"__esModule",{value:!0}),Dr.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)},o=function(c,d){return d.toUpperCase()},a=function(c,d){return"".concat(d,"-")},l=function(c,d){return d===void 0&&(d={}),s(c)?c:(c=c.toLowerCase(),d.reactCompat?c=c.replace(i,a):c=c.replace(r,a),c.replace(t,o))};return Dr.camelCase=l,Dr}var Rr,tu;function Gv(){if(tu)return Rr;tu=1;var e=Rr&&Rr.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Wv()),n=qv();function r(i,s){var o={};return!i||typeof i!="string"||(0,t.default)(i,function(a,l){a&&l&&(o[(0,n.camelCase)(a,s)]=l)}),o}return r.default=r,Rr=r,Rr}var Yv=Gv();const Kv=la(Yv),ap=lp("end"),Ca=lp("start");function lp(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function Xv(e){const t=Ca(e),n=ap(e);if(t&&n)return{start:t,end:n}}function Kr(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?nu(e.position):"start"in e||"end"in e?nu(e):"line"in e||"column"in e?Vo(e):""}function Vo(e){return ru(e&&e.line)+":"+ru(e&&e.column)}function nu(e){return Vo(e&&e.start)+"-"+Vo(e&&e.end)}function ru(e){return e&&typeof e=="number"?e:1}class ut extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},o=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(o=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const 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 a=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=Kr(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=o&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}ut.prototype.file="";ut.prototype.name="";ut.prototype.reason="";ut.prototype.message="";ut.prototype.stack="";ut.prototype.column=void 0;ut.prototype.line=void 0;ut.prototype.ancestors=void 0;ut.prototype.cause=void 0;ut.prototype.fatal=void 0;ut.prototype.place=void 0;ut.prototype.ruleId=void 0;ut.prototype.source=void 0;const Ta={}.hasOwnProperty,Qv=new Map,ew=/[A-Z]/g,tw=new Set(["table","tbody","thead","tfoot","tr"]),nw=new Set(["td","th"]),up="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function rw(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=dw(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=cw(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?Ea:Uv,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=cp(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function cp(e,t,n){if(t.type==="element")return iw(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return sw(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return aw(e,t,n);if(t.type==="mdxjsEsm")return ow(e,t);if(t.type==="root")return lw(e,t,n);if(t.type==="text")return uw(e,t)}function iw(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=Ea,e.schema=i),e.ancestors.push(t);const s=fp(e,t.tagName,!1),o=fw(e,t);let a=Aa(e,t);return tw.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!Pv(l):!0})),dp(e,o,s,t),Ia(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function sw(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}oi(e,t.position)}function ow(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);oi(e,t.position)}function aw(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=Ea,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:fp(e,t.name,!0),o=pw(e,t),a=Aa(e,t);return dp(e,o,s,t),Ia(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function lw(e,t,n){const r={};return Ia(r,Aa(e,t)),e.create(t,e.Fragment,r,n)}function uw(e,t){return t.value}function dp(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Ia(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function cw(e,t,n){return r;function r(i,s,o,a){const c=Array.isArray(o.children)?n:t;return a?c(s,o,a):c(s,o)}}function dw(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),l=Ca(r);return t(i,s,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function fw(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&Ta.call(t.properties,i)){const s=hw(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&nw.has(t.tagName)?r=a:n[o]=a}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function pw(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const o=s.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else oi(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,s=e.evaluater.evaluateExpression(a.expression)}else oi(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function Aa(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:Qv;for(;++r<t.children.length;){const s=t.children[r];let o;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;o=l+"-"+c,i.set(l,c+1)}}const a=cp(e,s,o);a!==void 0&&n.push(a)}return n}function hw(e,t,n){const r=Bv(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Tv(n):Jv(n)),r.property==="style"){let i=typeof n=="object"?n:mw(e,String(n));return e.stylePropertyNameCase==="css"&&(i=gw(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?$v[r.property]||r.property:r.attribute,n]}}function mw(e,t){try{return Kv(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new ut("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=up+"#cannot-parse-style-attribute",i}}function fp(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,o;for(;++s<i.length;){const a=ql(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(s&&a.type==="Literal"),optional:!1}:a}r=o}else r=ql(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return Ta.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);oi(e)}function oi(e,t){const n=new ut("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=up+"#cannot-handle-mdx-estrees-without-createevaluater",n}function gw(e){const t={};let n;for(n in e)Ta.call(e,n)&&(t[xw(n)]=e[n]);return t}function xw(e){let t=e.replace(ew,yw);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function yw(e){return"-"+e.toLowerCase()}const no={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},bw={};function za(e,t){const n=bw,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return pp(e,r,i)}function pp(e,t,n){if(vw(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return iu(e.children,t,n)}return Array.isArray(e)?iu(e,t,n):""}function iu(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=pp(e[i],t,n);return r.join("")}function vw(e){return!!(e&&typeof e=="object")}const su=document.createElement("i");function Oa(e){const t="&"+e+";";su.innerHTML=t;const n=su.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function Tt(e,t,n,r){const i=e.length;let s=0,o;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);s<r.length;)o=r.slice(s,s+1e4),o.unshift(t,0),e.splice(...o),s+=1e4,t+=1e4}function Ot(e,t){return e.length>0?(Tt(e,e.length,0,t),e):t}const ou={}.hasOwnProperty;function hp(e){const t={};let n=-1;for(;++n<e.length;)ww(t,e[n]);return t}function ww(e,t){let n;for(n in t){const i=(ou.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){ou.call(i,o)||(i[o]=[]);const a=s[o];kw(i[o],Array.isArray(a)?a:a?[a]:[])}}}function kw(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);Tt(e,0,0,r)}function mp(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 Vt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const ht=kn(/[A-Za-z]/),lt=kn(/[\dA-Za-z]/),Sw=kn(/[#-'*+\--9=?A-Z^-~]/);function is(e){return e!==null&&(e<32||e===127)}const Uo=kn(/\d/),_w=kn(/[\dA-Fa-f]/),jw=kn(/[!-/:-@[-`{-~]/);function ye(e){return e!==null&&e<-2}function Le(e){return e!==null&&(e<0||e===32)}function Ae(e){return e===-2||e===-1||e===32}const zs=kn(new RegExp("\\p{P}|\\p{S}","u")),Mn=kn(/\s/);function kn(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Er(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let o="";if(s===37&<(e.charCodeAt(n+1))&<(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(o=String.fromCharCode(s));else if(s>55295&&s<57344){const a=e.charCodeAt(n+1);s<56320&&a>56319&&a<57344?(o=String.fromCharCode(s,a),i=1):o="�"}else o=String.fromCharCode(s);o&&(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,o=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function De(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return o;function o(l){return Ae(l)?(e.enter(n),a(l)):t(l)}function a(l){return Ae(l)&&s++<i?(e.consume(l),a):(e.exit(n),t(l))}}const Nw={tokenize:Ew};function Ew(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),De(e,t,"linePrefix")}function i(a){return e.enter("paragraph"),s(a)}function s(a){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,o(a)}function o(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return ye(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const Cw={tokenize:Tw},au={tokenize:Iw};function Tw(e){const t=this,n=[];let r=0,i,s,o;return a;function a(m){if(r<n.length){const A=n[r];return t.containerState=A[1],e.attempt(A[0].continuation,l,c)(m)}return c(m)}function l(m){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&j();const A=t.events.length;let C=A,w;for(;C--;)if(t.events[C][0]==="exit"&&t.events[C][1].type==="chunkFlow"){w=t.events[C][1].end;break}y(r);let N=A;for(;N<t.events.length;)t.events[N][1].end={...w},N++;return Tt(t.events,C+1,0,t.events.slice(A)),t.events.length=N,c(m)}return a(m)}function c(m){if(r===n.length){if(!i)return p(m);if(i.currentConstruct&&i.currentConstruct.concrete)return g(m);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(au,d,f)(m)}function d(m){return i&&j(),y(r),p(m)}function f(m){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,g(m)}function p(m){return t.containerState={},e.attempt(au,h,g)(m)}function h(m){return r++,n.push([t.currentConstruct,t.containerState]),p(m)}function g(m){if(m===null){i&&j(),y(0),e.consume(m);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),v(m)}function v(m){if(m===null){S(e.exit("chunkFlow"),!0),y(0),e.consume(m);return}return ye(m)?(e.consume(m),S(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(m),v)}function S(m,A){const C=t.sliceStream(m);if(A&&C.push(null),m.previous=s,s&&(s.next=m),s=m,i.defineSkip(m.start),i.write(C),t.parser.lazy[m.start.line]){let w=i.events.length;for(;w--;)if(i.events[w][1].start.offset<o&&(!i.events[w][1].end||i.events[w][1].end.offset>o))return;const N=t.events.length;let J=N,D,_;for(;J--;)if(t.events[J][0]==="exit"&&t.events[J][1].type==="chunkFlow"){if(D){_=t.events[J][1].end;break}D=!0}for(y(r),w=N;w<t.events.length;)t.events[w][1].end={..._},w++;Tt(t.events,J+1,0,t.events.slice(N)),t.events.length=w}}function y(m){let A=n.length;for(;A-- >m;){const C=n[A];t.containerState=C[1],C[0].exit.call(t,e)}n.length=m}function j(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Iw(e,t,n){return De(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function vr(e){if(e===null||Le(e)||Mn(e))return 1;if(zs(e))return 2}function Os(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 Jo={name:"attention",resolveAll:Aw,tokenize:zw};function Aw(e,t){let n=-1,r,i,s,o,a,l,c,d;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},p={...e[n][1].start};lu(f,-l),lu(p,l),o={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...e[r][1].end}},a={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:{...o.start},end:{...a.end}},e[r][1].end={...o.start},e[n][1].start={...a.end},c=[],e[r][1].end.offset-e[r][1].start.offset&&(c=Ot(c,[["enter",e[r][1],t],["exit",e[r][1],t]])),c=Ot(c,[["enter",i,t],["enter",o,t],["exit",o,t],["enter",s,t]]),c=Ot(c,Os(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),c=Ot(c,[["exit",s,t],["enter",a,t],["exit",a,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(d=2,c=Ot(c,[["enter",e[n][1],t],["exit",e[n][1],t]])):d=0,Tt(e,r-1,n-r+3,c),n=r+c.length-d-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function zw(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=vr(r);let s;return o;function o(l){return s=l,e.enter("attentionSequence"),a(l)}function a(l){if(l===s)return e.consume(l),a;const c=e.exit("attentionSequence"),d=vr(l),f=!d||d===2&&i||n.includes(l),p=!i||i===2&&d||n.includes(r);return c._open=!!(s===42?f:f&&(i||!p)),c._close=!!(s===42?p:p&&(d||!f)),t(l)}}function lu(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Ow={name:"autolink",tokenize:Pw};function Pw(e,t,n){let r=0;return i;function i(h){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(h),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(h){return ht(h)?(e.consume(h),o):h===64?n(h):c(h)}function o(h){return h===43||h===45||h===46||lt(h)?(r=1,a(h)):c(h)}function a(h){return h===58?(e.consume(h),r=0,l):(h===43||h===45||h===46||lt(h))&&r++<32?(e.consume(h),a):(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||is(h)?n(h):(e.consume(h),l)}function c(h){return h===64?(e.consume(h),d):Sw(h)?(e.consume(h),c):n(h)}function d(h){return lt(h)?f(h):n(h)}function f(h){return h===46?(e.consume(h),r=0,d):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||lt(h))&&r++<63){const g=h===45?p:f;return e.consume(h),g}return n(h)}}const bi={partial:!0,tokenize:Dw};function Dw(e,t,n){return r;function r(s){return Ae(s)?De(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||ye(s)?t(s):n(s)}}const gp={continuation:{tokenize:Mw},exit:$w,name:"blockQuote",tokenize:Rw};function Rw(e,t,n){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),s}return n(o)}function s(o){return Ae(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function Mw(e,t,n){const r=this;return i;function i(o){return Ae(o)?De(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(gp,t,n)(o)}}function $w(e){e.exit("blockQuote")}const xp={name:"characterEscape",tokenize:Fw};function Fw(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return jw(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const yp={name:"characterReference",tokenize:Lw};function Lw(e,t,n){const r=this;let i=0,s,o;return a;function a(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),l}function l(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),c):(e.enter("characterReferenceValue"),s=31,o=lt,d(f))}function c(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,o=_w,d):(e.enter("characterReferenceValue"),s=7,o=Uo,d(f))}function d(f){if(f===59&&i){const p=e.exit("characterReferenceValue");return o===lt&&!Oa(r.sliceSerialize(p))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return o(f)&&i++<s?(e.consume(f),d):n(f)}}const uu={partial:!0,tokenize:Zw},cu={concrete:!0,name:"codeFenced",tokenize:Bw};function Bw(e,t,n){const r=this,i={partial:!0,tokenize:C};let s=0,o=0,a;return l;function l(w){return c(w)}function c(w){const N=r.events[r.events.length-1];return s=N&&N[1].type==="linePrefix"?N[2].sliceSerialize(N[1],!0).length:0,a=w,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),d(w)}function d(w){return w===a?(o++,e.consume(w),d):o<3?n(w):(e.exit("codeFencedFenceSequence"),Ae(w)?De(e,f,"whitespace")(w):f(w))}function f(w){return w===null||ye(w)?(e.exit("codeFencedFence"),r.interrupt?t(w):e.check(uu,v,A)(w)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(w))}function p(w){return w===null||ye(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(w)):Ae(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),De(e,h,"whitespace")(w)):w===96&&w===a?n(w):(e.consume(w),p)}function h(w){return w===null||ye(w)?f(w):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(w))}function g(w){return w===null||ye(w)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(w)):w===96&&w===a?n(w):(e.consume(w),g)}function v(w){return e.attempt(i,A,S)(w)}function S(w){return e.enter("lineEnding"),e.consume(w),e.exit("lineEnding"),y}function y(w){return s>0&&Ae(w)?De(e,j,"linePrefix",s+1)(w):j(w)}function j(w){return w===null||ye(w)?e.check(uu,v,A)(w):(e.enter("codeFlowValue"),m(w))}function m(w){return w===null||ye(w)?(e.exit("codeFlowValue"),j(w)):(e.consume(w),m)}function A(w){return e.exit("codeFenced"),t(w)}function C(w,N,J){let D=0;return _;function _(R){return w.enter("lineEnding"),w.consume(R),w.exit("lineEnding"),T}function T(R){return w.enter("codeFencedFence"),Ae(R)?De(w,I,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(R):I(R)}function I(R){return R===a?(w.enter("codeFencedFenceSequence"),z(R)):J(R)}function z(R){return R===a?(D++,w.consume(R),z):D>=o?(w.exit("codeFencedFenceSequence"),Ae(R)?De(w,O,"whitespace")(R):O(R)):J(R)}function O(R){return R===null||ye(R)?(w.exit("codeFencedFence"),N(R)):J(R)}}}function Zw(e,t,n){const r=this;return i;function i(o){return o===null?n(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}const ro={name:"codeIndented",tokenize:Uw},Vw={partial:!0,tokenize:Jw};function Uw(e,t,n){const r=this;return i;function i(c){return e.enter("codeIndented"),De(e,s,"linePrefix",5)(c)}function s(c){const d=r.events[r.events.length-1];return d&&d[1].type==="linePrefix"&&d[2].sliceSerialize(d[1],!0).length>=4?o(c):n(c)}function o(c){return c===null?l(c):ye(c)?e.attempt(Vw,o,l)(c):(e.enter("codeFlowValue"),a(c))}function a(c){return c===null||ye(c)?(e.exit("codeFlowValue"),o(c)):(e.consume(c),a)}function l(c){return e.exit("codeIndented"),t(c)}}function Jw(e,t,n){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):ye(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):De(e,s,"linePrefix",5)(o)}function s(o){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):ye(o)?i(o):n(o)}}const Hw={name:"codeText",previous:qw,resolve:Ww,tokenize:Gw};function Ww(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function qw(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Gw(e,t,n){let r=0,i,s;return o;function o(f){return e.enter("codeText"),e.enter("codeTextSequence"),a(f)}function a(f){return f===96?(e.consume(f),r++,a):(e.exit("codeTextSequence"),l(f))}function l(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),l):f===96?(s=e.enter("codeTextSequence"),i=0,d(f)):ye(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),l):(e.enter("codeTextData"),c(f))}function c(f){return f===null||f===32||f===96||ye(f)?(e.exit("codeTextData"),l(f)):(e.consume(f),c)}function d(f){return f===96?(e.consume(f),i++,d):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(s.type="codeTextData",c(f))}}class Yw{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Mr(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),Mr(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Mr(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);Mr(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Mr(this.left,n.reverse())}}}function Mr(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 bp(e){const t={};let n=-1,r,i,s,o,a,l,c;const d=new Yw(e);for(;++n<d.length;){for(;n in t;)n=t[n];if(r=d.get(n),n&&r[1].type==="chunkFlow"&&d.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,Kw(d,n)),n=t[n],c=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(o=d.get(s),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(i&&(d.get(i)[1].type="lineEndingBlank"),o[1].type="lineEnding",i=s);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;i&&(r[1].end={...d.get(i)[1].start},a=d.slice(i,n),a.unshift(r),d.splice(i,n-i+1,a))}}return Tt(e,0,Number.POSITIVE_INFINITY,d.slice(0)),!c}function Kw(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));const a=o.events,l=[],c={};let d,f,p=-1,h=n,g=0,v=0;const S=[v];for(;h;){for(;e.get(++i)[1]!==h;);s.push(i),h._tokenizer||(d=r.sliceStream(h),h.next||d.push(null),f&&o.defineSkip(h.start),h._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(d),h._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),f=h,h=h.next}for(h=n;++p<a.length;)a[p][0]==="exit"&&a[p-1][0]==="enter"&&a[p][1].type===a[p-1][1].type&&a[p][1].start.line!==a[p][1].end.line&&(v=p+1,S.push(v),h._tokenizer=void 0,h.previous=void 0,h=h.next);for(o.events=[],h?(h._tokenizer=void 0,h.previous=void 0):S.pop(),p=S.length;p--;){const y=a.slice(S[p],S[p+1]),j=s.pop();l.push([j,j+y.length-1]),e.splice(j,2,y)}for(l.reverse(),p=-1;++p<l.length;)c[g+l[p][0]]=g+l[p][1],g+=l[p][1]-l[p][0]-1;return c}const Xw={resolve:e0,tokenize:t0},Qw={partial:!0,tokenize:n0};function e0(e){return bp(e),e}function t0(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?s(a):ye(a)?e.check(Qw,o,s)(a):(e.consume(a),i)}function s(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function o(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function n0(e,t,n){const r=this;return i;function i(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),De(e,s,"linePrefix")}function s(o){if(o===null||ye(o))return n(o);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):e.interrupt(r.parser.constructs.flow,n,t)(o)}}function vp(e,t,n,r,i,s,o,a,l){const c=l||Number.POSITIVE_INFINITY;let d=0;return f;function f(y){return y===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(y),e.exit(s),p):y===null||y===32||y===41||is(y)?n(y):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),v(y))}function p(y){return y===62?(e.enter(s),e.consume(y),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),h(y))}function h(y){return y===62?(e.exit("chunkString"),e.exit(a),p(y)):y===null||y===60||ye(y)?n(y):(e.consume(y),y===92?g:h)}function g(y){return y===60||y===62||y===92?(e.consume(y),h):h(y)}function v(y){return!d&&(y===null||y===41||Le(y))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(y)):d<c&&y===40?(e.consume(y),d++,v):y===41?(e.consume(y),d--,v):y===null||y===32||y===40||is(y)?n(y):(e.consume(y),y===92?S:v)}function S(y){return y===40||y===41||y===92?(e.consume(y),v):v(y)}}function wp(e,t,n,r,i,s){const o=this;let a=0,l;return c;function c(h){return e.enter(r),e.enter(i),e.consume(h),e.exit(i),e.enter(s),d}function d(h){return a>999||h===null||h===91||h===93&&!l||h===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(h):h===93?(e.exit(s),e.enter(i),e.consume(h),e.exit(i),e.exit(r),t):ye(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),d):(e.enter("chunkString",{contentType:"string"}),f(h))}function f(h){return h===null||h===91||h===93||ye(h)||a++>999?(e.exit("chunkString"),d(h)):(e.consume(h),l||(l=!Ae(h)),h===92?p:f)}function p(h){return h===91||h===92||h===93?(e.consume(h),a++,f):f(h)}}function kp(e,t,n,r,i,s){let o;return a;function a(p){return p===34||p===39||p===40?(e.enter(r),e.enter(i),e.consume(p),e.exit(i),o=p===40?41:p,l):n(p)}function l(p){return p===o?(e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):(e.enter(s),c(p))}function c(p){return p===o?(e.exit(s),l(o)):p===null?n(p):ye(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),De(e,c,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),d(p))}function d(p){return p===o||p===null||ye(p)?(e.exit("chunkString"),c(p)):(e.consume(p),p===92?f:d)}function f(p){return p===o||p===92?(e.consume(p),d):d(p)}}function Xr(e,t){let n;return r;function r(i){return ye(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):Ae(i)?De(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const r0={name:"definition",tokenize:s0},i0={partial:!0,tokenize:o0};function s0(e,t,n){const r=this;let i;return s;function s(h){return e.enter("definition"),o(h)}function o(h){return wp.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(h)}function a(h){return i=Vt(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 Le(h)?Xr(e,c)(h):c(h)}function c(h){return vp(e,d,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function d(h){return e.attempt(i0,f,f)(h)}function f(h){return Ae(h)?De(e,p,"whitespace")(h):p(h)}function p(h){return h===null||ye(h)?(e.exit("definition"),r.parser.defined.push(i),t(h)):n(h)}}function o0(e,t,n){return r;function r(a){return Le(a)?Xr(e,i)(a):n(a)}function i(a){return kp(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return Ae(a)?De(e,o,"whitespace")(a):o(a)}function o(a){return a===null||ye(a)?t(a):n(a)}}const a0={name:"hardBreakEscape",tokenize:l0};function l0(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return ye(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const u0={name:"headingAtx",resolve:c0,tokenize:d0};function c0(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},Tt(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function d0(e,t,n){let r=0;return i;function i(d){return e.enter("atxHeading"),s(d)}function s(d){return e.enter("atxHeadingSequence"),o(d)}function o(d){return d===35&&r++<6?(e.consume(d),o):d===null||Le(d)?(e.exit("atxHeadingSequence"),a(d)):n(d)}function a(d){return d===35?(e.enter("atxHeadingSequence"),l(d)):d===null||ye(d)?(e.exit("atxHeading"),t(d)):Ae(d)?De(e,a,"whitespace")(d):(e.enter("atxHeadingText"),c(d))}function l(d){return d===35?(e.consume(d),l):(e.exit("atxHeadingSequence"),a(d))}function c(d){return d===null||d===35||Le(d)?(e.exit("atxHeadingText"),a(d)):(e.consume(d),c)}}const f0=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],du=["pre","script","style","textarea"],p0={concrete:!0,name:"htmlFlow",resolveTo:g0,tokenize:x0},h0={partial:!0,tokenize:b0},m0={partial:!0,tokenize:y0};function g0(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function x0(e,t,n){const r=this;let i,s,o,a,l;return c;function c(b){return d(b)}function d(b){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(b),f}function f(b){return b===33?(e.consume(b),p):b===47?(e.consume(b),s=!0,v):b===63?(e.consume(b),i=3,r.interrupt?t:k):ht(b)?(e.consume(b),o=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,a=0,g):ht(b)?(e.consume(b),i=4,r.interrupt?t:k):n(b)}function h(b){return b===45?(e.consume(b),r.interrupt?t:k):n(b)}function g(b){const B="CDATA[";return b===B.charCodeAt(a++)?(e.consume(b),a===B.length?r.interrupt?t:I:g):n(b)}function v(b){return ht(b)?(e.consume(b),o=String.fromCharCode(b),S):n(b)}function S(b){if(b===null||b===47||b===62||Le(b)){const B=b===47,V=o.toLowerCase();return!B&&!s&&du.includes(V)?(i=1,r.interrupt?t(b):I(b)):f0.includes(o.toLowerCase())?(i=6,B?(e.consume(b),y):r.interrupt?t(b):I(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):s?j(b):m(b))}return b===45||lt(b)?(e.consume(b),o+=String.fromCharCode(b),S):n(b)}function y(b){return b===62?(e.consume(b),r.interrupt?t:I):n(b)}function j(b){return Ae(b)?(e.consume(b),j):_(b)}function m(b){return b===47?(e.consume(b),_):b===58||b===95||ht(b)?(e.consume(b),A):Ae(b)?(e.consume(b),m):_(b)}function A(b){return b===45||b===46||b===58||b===95||lt(b)?(e.consume(b),A):C(b)}function C(b){return b===61?(e.consume(b),w):Ae(b)?(e.consume(b),C):m(b)}function w(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(e.consume(b),l=b,N):Ae(b)?(e.consume(b),w):J(b)}function N(b){return b===l?(e.consume(b),l=null,D):b===null||ye(b)?n(b):(e.consume(b),N)}function J(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||Le(b)?C(b):(e.consume(b),J)}function D(b){return b===47||b===62||Ae(b)?m(b):n(b)}function _(b){return b===62?(e.consume(b),T):n(b)}function T(b){return b===null||ye(b)?I(b):Ae(b)?(e.consume(b),T):n(b)}function I(b){return b===45&&i===2?(e.consume(b),Y):b===60&&i===1?(e.consume(b),H):b===62&&i===4?(e.consume(b),oe):b===63&&i===3?(e.consume(b),k):b===93&&i===5?(e.consume(b),ee):ye(b)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(h0,q,z)(b)):b===null||ye(b)?(e.exit("htmlFlowData"),z(b)):(e.consume(b),I)}function z(b){return e.check(m0,O,q)(b)}function O(b){return e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),R}function R(b){return b===null||ye(b)?z(b):(e.enter("htmlFlowData"),I(b))}function Y(b){return b===45?(e.consume(b),k):I(b)}function H(b){return b===47?(e.consume(b),o="",$):I(b)}function $(b){if(b===62){const B=o.toLowerCase();return du.includes(B)?(e.consume(b),oe):I(b)}return ht(b)&&o.length<8?(e.consume(b),o+=String.fromCharCode(b),$):I(b)}function ee(b){return b===93?(e.consume(b),k):I(b)}function k(b){return b===62?(e.consume(b),oe):b===45&&i===2?(e.consume(b),k):I(b)}function oe(b){return b===null||ye(b)?(e.exit("htmlFlowData"),q(b)):(e.consume(b),oe)}function q(b){return e.exit("htmlFlow"),t(b)}}function y0(e,t,n){const r=this;return i;function i(o){return ye(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s):n(o)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}function b0(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(bi,t,n)}}const v0={name:"htmlText",tokenize:w0};function w0(e,t,n){const r=this;let i,s,o;return a;function a(k){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(k),l}function l(k){return k===33?(e.consume(k),c):k===47?(e.consume(k),C):k===63?(e.consume(k),m):ht(k)?(e.consume(k),J):n(k)}function c(k){return k===45?(e.consume(k),d):k===91?(e.consume(k),s=0,g):ht(k)?(e.consume(k),j):n(k)}function d(k){return k===45?(e.consume(k),h):n(k)}function f(k){return k===null?n(k):k===45?(e.consume(k),p):ye(k)?(o=f,H(k)):(e.consume(k),f)}function p(k){return k===45?(e.consume(k),h):f(k)}function h(k){return k===62?Y(k):k===45?p(k):f(k)}function g(k){const oe="CDATA[";return k===oe.charCodeAt(s++)?(e.consume(k),s===oe.length?v:g):n(k)}function v(k){return k===null?n(k):k===93?(e.consume(k),S):ye(k)?(o=v,H(k)):(e.consume(k),v)}function S(k){return k===93?(e.consume(k),y):v(k)}function y(k){return k===62?Y(k):k===93?(e.consume(k),y):v(k)}function j(k){return k===null||k===62?Y(k):ye(k)?(o=j,H(k)):(e.consume(k),j)}function m(k){return k===null?n(k):k===63?(e.consume(k),A):ye(k)?(o=m,H(k)):(e.consume(k),m)}function A(k){return k===62?Y(k):m(k)}function C(k){return ht(k)?(e.consume(k),w):n(k)}function w(k){return k===45||lt(k)?(e.consume(k),w):N(k)}function N(k){return ye(k)?(o=N,H(k)):Ae(k)?(e.consume(k),N):Y(k)}function J(k){return k===45||lt(k)?(e.consume(k),J):k===47||k===62||Le(k)?D(k):n(k)}function D(k){return k===47?(e.consume(k),Y):k===58||k===95||ht(k)?(e.consume(k),_):ye(k)?(o=D,H(k)):Ae(k)?(e.consume(k),D):Y(k)}function _(k){return k===45||k===46||k===58||k===95||lt(k)?(e.consume(k),_):T(k)}function T(k){return k===61?(e.consume(k),I):ye(k)?(o=T,H(k)):Ae(k)?(e.consume(k),T):D(k)}function I(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(e.consume(k),i=k,z):ye(k)?(o=I,H(k)):Ae(k)?(e.consume(k),I):(e.consume(k),O)}function z(k){return k===i?(e.consume(k),i=void 0,R):k===null?n(k):ye(k)?(o=z,H(k)):(e.consume(k),z)}function O(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||Le(k)?D(k):(e.consume(k),O)}function R(k){return k===47||k===62||Le(k)?D(k):n(k)}function Y(k){return k===62?(e.consume(k),e.exit("htmlTextData"),e.exit("htmlText"),t):n(k)}function H(k){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),$}function $(k){return Ae(k)?De(e,ee,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):ee(k)}function ee(k){return e.enter("htmlTextData"),o(k)}}const Pa={name:"labelEnd",resolveAll:j0,resolveTo:N0,tokenize:E0},k0={tokenize:C0},S0={tokenize:T0},_0={tokenize:I0};function j0(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&Tt(e,0,e.length,n),e}function N0(e,t){let n=e.length,r=0,i,s,o,a;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(o){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(o=n);const 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[o][1].end}},d={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[o-2][1].start}};return a=[["enter",l,t],["enter",c,t]],a=Ot(a,e.slice(s+1,s+r+3)),a=Ot(a,[["enter",d,t]]),a=Ot(a,Os(t.parser.constructs.insideSpan.null,e.slice(s+r+4,o-3),t)),a=Ot(a,[["exit",d,t],e[o-2],e[o-1],["exit",c,t]]),a=Ot(a,e.slice(o+1)),a=Ot(a,[["exit",l,t]]),Tt(e,s,e.length,a),e}function E0(e,t,n){const r=this;let i=r.events.length,s,o;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return a;function a(p){return s?s._inactive?f(p):(o=r.parser.defined.includes(Vt(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(k0,d,o?d:f)(p):p===91?e.attempt(S0,d,o?c:f)(p):o?d(p):f(p)}function c(p){return e.attempt(_0,d,f)(p)}function d(p){return t(p)}function f(p){return s._balanced=!0,n(p)}}function C0(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),i}function i(f){return Le(f)?Xr(e,s)(f):s(f)}function s(f){return f===41?d(f):vp(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function o(f){return Le(f)?Xr(e,l)(f):d(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?kp(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):d(f)}function c(f){return Le(f)?Xr(e,d)(f):d(f)}function d(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function T0(e,t,n){const r=this;return i;function i(a){return wp.call(r,e,s,o,"reference","referenceMarker","referenceString")(a)}function s(a){return r.parser.defined.includes(Vt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function I0(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const A0={name:"labelStartImage",resolveAll:Pa.resolveAll,tokenize:z0};function z0(e,t,n){const r=this;return i;function i(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),s}function s(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),o):n(a)}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const O0={name:"labelStartLink",resolveAll:Pa.resolveAll,tokenize:P0};function P0(e,t,n){const r=this;return i;function i(o){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelLink"),s}function s(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const io={name:"lineEnding",tokenize:D0};function D0(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),De(e,t,"linePrefix")}}const Bi={name:"thematicBreak",tokenize:R0};function R0(e,t,n){let r=0,i;return s;function s(c){return e.enter("thematicBreak"),o(c)}function o(c){return i=c,a(c)}function a(c){return c===i?(e.enter("thematicBreakSequence"),l(c)):r>=3&&(c===null||ye(c))?(e.exit("thematicBreak"),t(c)):n(c)}function l(c){return c===i?(e.consume(c),r++,l):(e.exit("thematicBreakSequence"),Ae(c)?De(e,a,"whitespace")(c):a(c))}}const xt={continuation:{tokenize:L0},exit:Z0,name:"list",tokenize:F0},M0={partial:!0,tokenize:V0},$0={partial:!0,tokenize:B0};function F0(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,o=0;return a;function a(h){const g=r.containerState.type||(h===42||h===43||h===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||h===r.containerState.marker:Uo(h)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),h===42||h===45?e.check(Bi,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 Uo(h)&&++o<10?(e.consume(h),l):(!r.interrupt||o<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(bi,r.interrupt?n:d,e.attempt(M0,p,f))}function d(h){return r.containerState.initialBlankLine=!0,s++,p(h)}function f(h){return Ae(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 L0(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(bi,i,s);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,De(e,t,"listItemIndent",r.containerState.size+1)(a)}function s(a){return r.containerState.furtherBlankLines||!Ae(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt($0,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,De(e,e.attempt(xt,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function B0(e,t,n){const r=this;return De(e,i,"listItemIndent",r.containerState.size+1);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="listItemIndent"&&o[2].sliceSerialize(o[1],!0).length===r.containerState.size?t(s):n(s)}}function Z0(e){e.exit(this.containerState.type)}function V0(e,t,n){const r=this;return De(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const o=r.events[r.events.length-1];return!Ae(s)&&o&&o[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const fu={name:"setextUnderline",resolveTo:U0,tokenize:J0};function U0(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const o={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",o,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=o,e.push(["exit",o,t]),e}function J0(e,t,n){const r=this;let i;return s;function s(c){let d=r.events.length,f;for(;d--;)if(r.events[d][1].type!=="lineEnding"&&r.events[d][1].type!=="linePrefix"&&r.events[d][1].type!=="content"){f=r.events[d][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),i=c,o(c)):n(c)}function o(c){return e.enter("setextHeadingLineSequence"),a(c)}function a(c){return c===i?(e.consume(c),a):(e.exit("setextHeadingLineSequence"),Ae(c)?De(e,l,"lineSuffix")(c):l(c))}function l(c){return c===null||ye(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const H0={tokenize:W0};function W0(e){const t=this,n=e.attempt(bi,r,e.attempt(this.parser.constructs.flowInitial,i,De(e,e.attempt(this.parser.constructs.flow,i,e.attempt(Xw,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const q0={resolveAll:_p()},G0=Sp("string"),Y0=Sp("text");function Sp(e){return{resolveAll:_p(e==="text"?K0:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,o,a);return o;function o(d){return c(d)?s(d):a(d)}function a(d){if(d===null){n.consume(d);return}return n.enter("data"),n.consume(d),l}function l(d){return c(d)?(n.exit("data"),s(d)):(n.consume(d),l)}function c(d){if(d===null)return!0;const f=i[d];let p=-1;if(f)for(;++p<f.length;){const h=f[p];if(!h.previous||h.previous.call(r,r.previous))return!0}return!1}}}function _p(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function K0(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,o=-1,a=0,l;for(;s--;){const c=i[s];if(typeof c=="string"){for(o=c.length;c.charCodeAt(o-1)===32;)a++,o--;if(o)break;o=-1}else if(c===-2)l=!0,a++;else if(c!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const c={type:n===e.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?o:r.start._bufferIndex+o,_index:r.start._index+s,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...c.start},r.start.offset===r.end.offset?Object.assign(r,c):(e.splice(n,0,["enter",c,t],["exit",c,t]),n+=2)}n++}return e}const X0={42:xt,43:xt,45:xt,48:xt,49:xt,50:xt,51:xt,52:xt,53:xt,54:xt,55:xt,56:xt,57:xt,62:gp},Q0={91:r0},ek={[-2]:ro,[-1]:ro,32:ro},tk={35:u0,42:Bi,45:[fu,Bi],60:p0,61:fu,95:Bi,96:cu,126:cu},nk={38:yp,92:xp},rk={[-5]:io,[-4]:io,[-3]:io,33:A0,38:yp,42:Jo,60:[Ow,v0],91:O0,92:[a0,xp],93:Pa,95:Jo,96:Hw},ik={null:[Jo,q0]},sk={null:[42,95]},ok={null:[]},ak=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:sk,contentInitial:Q0,disable:ok,document:X0,flow:tk,flowInitial:ek,insideSpan:ik,string:nk,text:rk},Symbol.toStringTag,{value:"Module"}));function lk(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let o=[],a=[];const l={attempt:N(C),check:N(w),consume:j,enter:m,exit:A,interrupt:N(w,{interrupt:!0})},c={code:null,containerState:{},defineSkip:v,events:[],now:g,parser:e,previous:null,sliceSerialize:p,sliceStream:h,write:f};let d=t.tokenize.call(c,l);return t.resolveAll&&s.push(t),c;function f(T){return o=Ot(o,T),S(),o[o.length-1]!==null?[]:(J(t,0),c.events=Os(s,c.events,c),c.events)}function p(T,I){return ck(h(T),I)}function h(T){return uk(o,T)}function g(){const{_bufferIndex:T,_index:I,line:z,column:O,offset:R}=r;return{_bufferIndex:T,_index:I,line:z,column:O,offset:R}}function v(T){i[T.line]=T.column,_()}function S(){let T;for(;r._index<o.length;){const I=o[r._index];if(typeof I=="string")for(T=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===T&&r._bufferIndex<I.length;)y(I.charCodeAt(r._bufferIndex));else y(I)}}function y(T){d=d(T)}function j(T){ye(T)?(r.line++,r.column=1,r.offset+=T===-3?2:1,_()):T!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),c.previous=T}function m(T,I){const z=I||{};return z.type=T,z.start=g(),c.events.push(["enter",z,c]),a.push(z),z}function A(T){const I=a.pop();return I.end=g(),c.events.push(["exit",I,c]),I}function C(T,I){J(T,I.from)}function w(T,I){I.restore()}function N(T,I){return z;function z(O,R,Y){let H,$,ee,k;return Array.isArray(O)?q(O):"tokenize"in O?q([O]):oe(O);function oe(re){return se;function se(P){const ue=P!==null&&re[P],he=P!==null&&re.null,ce=[...Array.isArray(ue)?ue:ue?[ue]:[],...Array.isArray(he)?he:he?[he]:[]];return q(ce)(P)}}function q(re){return H=re,$=0,re.length===0?Y:b(re[$])}function b(re){return se;function se(P){return k=D(),ee=re,re.partial||(c.currentConstruct=re),re.name&&c.parser.constructs.disable.null.includes(re.name)?V():re.tokenize.call(I?Object.assign(Object.create(c),I):c,l,B,V)(P)}}function B(re){return T(ee,k),R}function V(re){return k.restore(),++$<H.length?b(H[$]):Y}}}function J(T,I){T.resolveAll&&!s.includes(T)&&s.push(T),T.resolve&&Tt(c.events,I,c.events.length-I,T.resolve(c.events.slice(I),c)),T.resolveTo&&(c.events=T.resolveTo(c.events,c))}function D(){const T=g(),I=c.previous,z=c.currentConstruct,O=c.events.length,R=Array.from(a);return{from:O,restore:Y};function Y(){r=T,c.previous=I,c.currentConstruct=z,c.events.length=O,a=R,_()}}function _(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function uk(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let o;if(n===i)o=[e[n].slice(r,s)];else{if(o=e.slice(n,i),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}s>0&&o.push(e[i].slice(0,s))}return o}function ck(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let o;if(typeof s=="string")o=s;else switch(s){case-5:{o="\r";break}case-4:{o=`
|
|
11
11
|
`;break}case-3:{o=`\r
|
|
12
12
|
`;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&i)continue;o=" ";break}default:o=String.fromCharCode(s)}i=s===-2,r.push(o)}return r.join("")}function dk(e){const r={constructs:hp([ak,...(e||{}).extensions||[]]),content:i(Nw),defined:[],document:i(Cw),flow:i(H0),lazy:{},string:i(G0),text:i(Y0)};return r;function i(s){return o;function o(a){return lk(r,s,a)}}}function fk(e){for(;!bp(e););return e}const pu=/[\0\t\n\r]/g;function pk(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const l=[];let c,d,f,p,h;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(o||void 0).decode(s)),f=0,t="",n&&(s.charCodeAt(0)===65279&&f++,n=void 0);f<s.length;){if(pu.lastIndex=f,c=pu.exec(s),p=c&&c.index!==void 0?c.index:s.length,h=s.charCodeAt(p),!c){t=s.slice(f);break}if(h===10&&f===p&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<p&&(l.push(s.slice(f,p)),e+=p-f),h){case 0:{l.push(65533),e++;break}case 9:{for(d=Math.ceil(e/4)*4,l.push(-2);e++<d;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}f=p+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const hk=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function mk(e){return e.replace(hk,gk)}function gk(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return mp(n.slice(s?2:1),s?16:10)}return Oa(n)||e}const jp={}.hasOwnProperty;function xk(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),yk(n)(fk(dk(n).document().write(pk()(e,t,!0))))}function yk(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(M),autolinkProtocol:D,autolinkEmail:D,atxHeading:s(Te),blockQuote:s(he),characterEscape:D,characterReference:D,codeFenced:s(ce),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(ce,o),codeText:s(pe,o),codeTextData:D,data:D,codeFlowValue:D,definition:s(me),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(U),hardBreakEscape:s(X),hardBreakTrailing:s(X),htmlFlow:s(we,o),htmlFlowData:D,htmlText:s(we,o),htmlTextData:D,image:s(E),label:o,link:s(M),listItem:s(ne),listItemValue:p,listOrdered:s(F,f),listUnordered:s(F),paragraph:s(Q),reference:b,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Te),strong:s(te),thematicBreak:s(ve)},exit:{atxHeading:l(),atxHeadingSequence:C,autolink:l(),autolinkEmail:ue,autolinkProtocol:P,blockQuote:l(),characterEscapeValue:_,characterReferenceMarkerHexadecimal:V,characterReferenceMarkerNumeric:V,characterReferenceValue:re,characterReference:se,codeFenced:l(S),codeFencedFence:v,codeFencedFenceInfo:h,codeFencedFenceMeta:g,codeFlowValue:_,codeIndented:l(y),codeText:l(R),codeTextData:_,data:_,definition:l(),definitionDestinationString:A,definitionLabelString:j,definitionTitleString:m,emphasis:l(),hardBreakEscape:l(I),hardBreakTrailing:l(I),htmlFlow:l(z),htmlFlowData:_,htmlText:l(O),htmlTextData:_,image:l(H),label:ee,labelText:$,lineEnding:T,link:l(Y),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:B,resourceDestinationString:k,resourceTitleString:oe,resource:q,setextHeading:l(J),setextHeadingLineSequence:N,setextHeadingText:w,strong:l(),thematicBreak:l()}};Np(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(Z){let K={type:"root",children:[]};const ge={stack:[K],tokenStack:[],config:t,enter:a,exit:c,buffer:o,resume:d,data:n},Ne=[];let L=-1;for(;++L<Z.length;)if(Z[L][1].type==="listOrdered"||Z[L][1].type==="listUnordered")if(Z[L][0]==="enter")Ne.push(L);else{const xe=Ne.pop();L=i(Z,xe,L)}for(L=-1;++L<Z.length;){const xe=t[Z[L][0]];jp.call(xe,Z[L][1].type)&&xe[Z[L][1].type].call(Object.assign({sliceSerialize:Z[L][2].sliceSerialize},ge),Z[L][1])}if(ge.tokenStack.length>0){const xe=ge.tokenStack[ge.tokenStack.length-1];(xe[1]||hu).call(ge,void 0,xe[0])}for(K.position={start:dn(Z.length>0?Z[0][1].start:{line:1,column:1,offset:0}),end:dn(Z.length>0?Z[Z.length-2][1].end:{line:1,column:1,offset:0})},L=-1;++L<t.transforms.length;)K=t.transforms[L](K)||K;return K}function i(Z,K,ge){let Ne=K-1,L=-1,xe=!1,ze,Be,rt,tt;for(;++Ne<=ge;){const at=Z[Ne];switch(at[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{at[0]==="enter"?L++:L--,tt=void 0;break}case"lineEndingBlank":{at[0]==="enter"&&(ze&&!tt&&!L&&!rt&&(rt=Ne),tt=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:tt=void 0}if(!L&&at[0]==="enter"&&at[1].type==="listItemPrefix"||L===-1&&at[0]==="exit"&&(at[1].type==="listUnordered"||at[1].type==="listOrdered")){if(ze){let un=Ne;for(Be=void 0;un--;){const en=Z[un];if(en[1].type==="lineEnding"||en[1].type==="lineEndingBlank"){if(en[0]==="exit")continue;Be&&(Z[Be][1].type="lineEndingBlank",xe=!0),en[1].type="lineEnding",Be=un}else if(!(en[1].type==="linePrefix"||en[1].type==="blockQuotePrefix"||en[1].type==="blockQuotePrefixWhitespace"||en[1].type==="blockQuoteMarker"||en[1].type==="listItemIndent"))break}rt&&(!Be||rt<Be)&&(ze._spread=!0),ze.end=Object.assign({},Be?Z[Be][1].start:at[1].end),Z.splice(Be||Ne,0,["exit",ze,at[2]]),Ne++,ge++}if(at[1].type==="listItemPrefix"){const un={type:"listItem",_spread:!1,start:Object.assign({},at[1].start),end:void 0};ze=un,Z.splice(Ne,0,["enter",un,at[2]]),Ne++,ge++,rt=void 0,tt=!0}}}return Z[K][1]._spread=xe,ge}function s(Z,K){return ge;function ge(Ne){a.call(this,Z(Ne),Ne),K&&K.call(this,Ne)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(Z,K,ge){this.stack[this.stack.length-1].children.push(Z),this.stack.push(Z),this.tokenStack.push([K,ge||void 0]),Z.position={start:dn(K.start),end:void 0}}function l(Z){return K;function K(ge){Z&&Z.call(this,ge),c.call(this,ge)}}function c(Z,K){const ge=this.stack.pop(),Ne=this.tokenStack.pop();if(Ne)Ne[0].type!==Z.type&&(K?K.call(this,Z,Ne[0]):(Ne[1]||hu).call(this,Z,Ne[0]));else throw new Error("Cannot close `"+Z.type+"` ("+Kr({start:Z.start,end:Z.end})+"): it’s not open");ge.position.end=dn(Z.end)}function d(){return za(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function p(Z){if(this.data.expectingFirstListItemValue){const K=this.stack[this.stack.length-2];K.start=Number.parseInt(this.sliceSerialize(Z),10),this.data.expectingFirstListItemValue=void 0}}function h(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.lang=Z}function g(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.meta=Z}function v(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function S(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.value=Z.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function y(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.value=Z.replace(/(\r?\n|\r)$/g,"")}function j(Z){const K=this.resume(),ge=this.stack[this.stack.length-1];ge.label=K,ge.identifier=Vt(this.sliceSerialize(Z)).toLowerCase()}function m(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.title=Z}function A(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.url=Z}function C(Z){const K=this.stack[this.stack.length-1];if(!K.depth){const ge=this.sliceSerialize(Z).length;K.depth=ge}}function w(){this.data.setextHeadingSlurpLineEnding=!0}function N(Z){const K=this.stack[this.stack.length-1];K.depth=this.sliceSerialize(Z).codePointAt(0)===61?1:2}function J(){this.data.setextHeadingSlurpLineEnding=void 0}function D(Z){const ge=this.stack[this.stack.length-1].children;let Ne=ge[ge.length-1];(!Ne||Ne.type!=="text")&&(Ne=de(),Ne.position={start:dn(Z.start),end:void 0},ge.push(Ne)),this.stack.push(Ne)}function _(Z){const K=this.stack.pop();K.value+=this.sliceSerialize(Z),K.position.end=dn(Z.end)}function T(Z){const K=this.stack[this.stack.length-1];if(this.data.atHardBreak){const ge=K.children[K.children.length-1];ge.position.end=dn(Z.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(K.type)&&(D.call(this,Z),_.call(this,Z))}function I(){this.data.atHardBreak=!0}function z(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.value=Z}function O(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.value=Z}function R(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.value=Z}function Y(){const Z=this.stack[this.stack.length-1];if(this.data.inReference){const K=this.data.referenceType||"shortcut";Z.type+="Reference",Z.referenceType=K,delete Z.url,delete Z.title}else delete Z.identifier,delete Z.label;this.data.referenceType=void 0}function H(){const Z=this.stack[this.stack.length-1];if(this.data.inReference){const K=this.data.referenceType||"shortcut";Z.type+="Reference",Z.referenceType=K,delete Z.url,delete Z.title}else delete Z.identifier,delete Z.label;this.data.referenceType=void 0}function $(Z){const K=this.sliceSerialize(Z),ge=this.stack[this.stack.length-2];ge.label=mk(K),ge.identifier=Vt(K).toLowerCase()}function ee(){const Z=this.stack[this.stack.length-1],K=this.resume(),ge=this.stack[this.stack.length-1];if(this.data.inReference=!0,ge.type==="link"){const Ne=Z.children;ge.children=Ne}else ge.alt=K}function k(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.url=Z}function oe(){const Z=this.resume(),K=this.stack[this.stack.length-1];K.title=Z}function q(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function B(Z){const K=this.resume(),ge=this.stack[this.stack.length-1];ge.label=K,ge.identifier=Vt(this.sliceSerialize(Z)).toLowerCase(),this.data.referenceType="full"}function V(Z){this.data.characterReferenceType=Z.type}function re(Z){const K=this.sliceSerialize(Z),ge=this.data.characterReferenceType;let Ne;ge?(Ne=mp(K,ge==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):Ne=Oa(K);const L=this.stack[this.stack.length-1];L.value+=Ne}function se(Z){const K=this.stack.pop();K.position.end=dn(Z.end)}function P(Z){_.call(this,Z);const K=this.stack[this.stack.length-1];K.url=this.sliceSerialize(Z)}function ue(Z){_.call(this,Z);const K=this.stack[this.stack.length-1];K.url="mailto:"+this.sliceSerialize(Z)}function he(){return{type:"blockquote",children:[]}}function ce(){return{type:"code",lang:null,meta:null,value:""}}function pe(){return{type:"inlineCode",value:""}}function me(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function U(){return{type:"emphasis",children:[]}}function Te(){return{type:"heading",depth:0,children:[]}}function X(){return{type:"break"}}function we(){return{type:"html",value:""}}function E(){return{type:"image",title:null,url:"",alt:null}}function M(){return{type:"link",title:null,url:"",children:[]}}function F(Z){return{type:"list",ordered:Z.type==="listOrdered",start:null,spread:Z._spread,children:[]}}function ne(Z){return{type:"listItem",spread:Z._spread,checked:null,children:[]}}function Q(){return{type:"paragraph",children:[]}}function te(){return{type:"strong",children:[]}}function de(){return{type:"text",value:""}}function ve(){return{type:"thematicBreak"}}}function dn(e){return{line:e.line,column:e.column,offset:e.offset}}function Np(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Np(e,r):bk(e,r)}}function bk(e,t){let n;for(n in t)if(jp.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 hu(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Kr({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Kr({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Kr({start:t.start,end:t.end})+") is still open")}function vk(e){const t=this;t.parser=n;function n(r){return xk(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function wk(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function kk(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
|
|
@@ -103,4 +103,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
103
103
|
`;)t++;return!0}return!1}function c($){if(d($)){if(Nc(e[t]))for(;t<e.length&&Ec(e[t]);)t++;return o(),!0}return!1}function d($){a(!0);for(const ee of $){const k=t+ee.length;if(e.slice(t,k)===ee)return t=k,!0}return!1}function f($){return e[t]===$?(n+=e[t],t++,!0):!1}function p($){return e[t]===$?(t++,!0):!1}function h(){return p("\\")}function g(){return o(),e[t]==="."&&e[t+1]==="."&&e[t+2]==="."?(t+=3,o(),p(","),!0):!1}function v(){if(e[t]==="{"){n+="{",t++,o(),p(",")&&o();let $=!0;for(;t<e.length&&e[t]!=="}";){let ee;if($?(ee=!0,$=!1):(ee=f(","),ee||(n=Mt(n,",")),o()),g(),!(j()||N(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=Fr(n,","):R();break}o();const oe=f(":"),q=t>=e.length;oe||(Ac(e[t])||q?n=Mt(n,":"):Y()),s()||(oe||q?n+="null":Y())}return e[t]==="}"?(n+="}",t++):n=Mt(n,"}"),!0}return!1}function S(){if(e[t]==="["){n+="[",t++,o(),p(",")&&o();let $=!0;for(;t<e.length&&e[t]!=="]";)if($?$=!1:f(",")||(n=Mt(n,",")),g(),!s()){n=Fr(n,",");break}return e[t]==="]"?(n+="]",t++):n=Mt(n,"]"),!0}return!1}function y(){let $=!0,ee=!0;for(;ee;)$?$=!1:f(",")||(n=Mt(n,",")),ee=s();ee||(n=Fr(n,",")),n=`[
|
|
104
104
|
${n}
|
|
105
105
|
]`}function j(){let $=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1,ee=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1,k=e[t]==="\\";if(k&&(t++,k=!0),Ui(e[t])){const oe=zc(e[t])?zc:Oc(e[t])?Oc:aa(e[t])?aa:Bm,q=t,b=n.length;let B='"';for(t++;;){if(t>=e.length){const V=D(t-1);return!$&&Ri(e.charAt(V))?(t=q,n=n.substring(0,b),j(!0)):(B=Mt(B,'"'),n+=B,!0)}if(t===ee)return B=Mt(B,'"'),n+=B,!0;if(oe(e[t])){const V=t,re=B.length;if(B+='"',t++,n+=B,o(!1),$||t>=e.length||Ri(e[t])||Ui(e[t])||Cn(e[t]))return m(),!0;const se=D(V-1),P=e.charAt(se);if(P===",")return t=q,n=n.substring(0,b),j(!1,se);if(Ri(P))return t=q,n=n.substring(0,b),j(!0);n=n.substring(0,b),t=V+1,B=`${B.substring(0,re)}\\${B.substring(re)}`}else if($&&Ic(e[t])){if(e[t-1]===":"&&Cc.test(e.substring(q+1,t+2)))for(;t<e.length&&Tc.test(e[t]);)B+=e[t],t++;return B=Mt(B,'"'),n+=B,m(),!0}else if(e[t]==="\\"){const V=e.charAt(t+1);if(iz[V]!==void 0)B+=e.slice(t,t+2),t+=2;else if(V==="u"){let se=2;for(;se<6&&GA(e[t+se]);)se++;se===6?(B+=e.slice(t,t+6),t+=6):t+se>=e.length?t=e.length:H()}else B+=V,t+=2}else{const V=e.charAt(t);V==='"'&&e[t-1]!=="\\"?(B+=`\\${V}`,t++):XA(V)?(B+=rz[V],t++):(YA(V)||I(V),B+=V,t++)}k&&h()}}return!1}function m(){let $=!1;for(o();e[t]==="+";){$=!0,t++,o(),n=Fr(n,'"',!0);const ee=n.length;j()?n=tz(n,ee,1):n=Mt(n,'"')}return $}function A(){const $=t;if(e[t]==="-"){if(t++,_())return T($),!0;if(!Cn(e[t]))return t=$,!1}for(;Cn(e[t]);)t++;if(e[t]==="."){if(t++,_())return T($),!0;if(!Cn(e[t]))return t=$,!1;for(;Cn(e[t]);)t++}if(e[t]==="e"||e[t]==="E"){if(t++,(e[t]==="-"||e[t]==="+")&&t++,_())return T($),!0;if(!Cn(e[t]))return t=$,!1;for(;Cn(e[t]);)t++}if(!_())return t=$,!1;if(t>$){const ee=e.slice($,t),k=/^0\d/.test(ee);return n+=k?`"${ee}"`:ee,!0}return!1}function C(){return w("true","true")||w("false","false")||w("null","null")||w("True","true")||w("False","false")||w("None","null")}function w($,ee){return e.slice(t,t+$.length)===$?(n+=ee,t+=$.length,!0):!1}function N($){const ee=t;if(Nc(e[t])){for(;t<e.length&&Ec(e[t]);)t++;let k=t;for(;Tn(e,k);)k++;if(e[k]==="(")return t=k+1,s(),e[t]===")"&&(t++,e[t]===";"&&t++),!0}for(;t<e.length&&!Ic(e[t])&&!Ui(e[t])&&(!$||e[t]!==":");)t++;if(e[t-1]===":"&&Cc.test(e.substring(ee,t+2)))for(;t<e.length&&Tc.test(e[t]);)t++;if(t>ee){for(;Tn(e,t-1)&&t>0;)t--;const k=e.slice(ee,t);return n+=k==="undefined"?"null":JSON.stringify(k),e[t]==='"'&&t++,!0}}function J(){if(e[t]==="/"){const $=t;for(t++;t<e.length&&(e[t]!=="/"||e[t-1]==="\\");)t++;return t++,n+=JSON.stringify(e.substring($,t)),!0}}function D($){let ee=$;for(;ee>0&&Tn(e,ee);)ee--;return ee}function _(){return t>=e.length||Ri(e[t])||Tn(e,t)}function T($){n+=`${e.slice($,t)}0`}function I($){throw new Kn(`Invalid character ${JSON.stringify($)}`,t)}function z(){throw new Kn(`Unexpected character ${JSON.stringify(e[t])}`,t)}function O(){throw new Kn("Unexpected end of json string",e.length)}function R(){throw new Kn("Object key expected",t)}function Y(){throw new Kn("Colon expected",t)}function H(){const $=e.slice(t,t+6);throw new Kn(`Invalid unicode character "${$}"`,t)}}function sz(e,t){return e[t]==="*"&&e[t+1]==="/"}function oz({json:e,context:t,scope:n}){const[r,i]=x.useState(!1),[s,o]=x.useState(null),a=x.useMemo(()=>{try{return JSON.parse(e),e}catch{}try{return Pc(e)}catch{}const y=`{${e}}`;try{return JSON.parse(y),y}catch{}try{return Pc(y)}catch{return null}},[e]),l=x.useMemo(()=>Pm(a||e),[a,e]),c=Ce(y=>y.activeTab),d=Ce(y=>y.documents),f=Ce(y=>(y.acceptedApplyIds||[]).includes(l)),p=Ce(y=>y.setPendingDiff),h=Ce(y=>y.createDocument),g=Ce(y=>y.openDocument),v=x.useCallback(()=>{if(a){o(null);try{if(c){const y=d.find(w=>w.name===c),j=(y==null?void 0:y.text)||"";if(n==="templates")try{const w=JSON.parse(j),N=JSON.parse(a);if(Array.isArray(N.templates)){w.props||(w.props={}),w.props.templates=Om(w.props.templates||[],N.templates);const J=JSON.stringify(w,null,2);p(c,j,J,l);return}}catch{}const m=t==null?void 0:t[0],{original:A,modified:C}=Dm(j,a,m);p(c,A,C,l)}else{const y=`ai-generated-${Date.now()}`;h(y,a),g(y)}}catch(y){o(y instanceof Error?y.message:"Merge failed")}}},[a,c,d,p,h,g,t,n,l]),S=x.useCallback(async()=>{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)},[e]);return u.jsxs("div",{className:"flex flex-col gap-1 px-3 py-2 border-t",children:[u.jsxs("div",{className:"flex gap-1.5",children:[u.jsx(_e,{variant:"secondary",size:"sm",onClick:v,disabled:f||!a,children:f?"Applied":a?"Apply to Editor":"Invalid JSON"}),u.jsx(_e,{variant:"ghost",size:"sm",onClick:S,children:r?u.jsx(yn,{className:"h-3.5 w-3.5"}):u.jsx(ws,{className:"h-3.5 w-3.5"})})]}),s&&u.jsx("p",{className:"text-xs text-destructive m-0",children:s})]})}function az({threads:e,activeThread:t,disabled:n,onSwitch:r,onCreate:i,onDelete:s,onRename:o}){const[a,l]=x.useState(null),[c,d]=x.useState(""),[f,p]=x.useState(null),h=x.useRef(null),g=(t==null?void 0:t.title)||"New Chat",v=g.length>24?g.slice(0,24)+"...":g;x.useEffect(()=>{a&&requestAnimationFrame(()=>{var N;return(N=h.current)==null?void 0:N.focus()})},[a]);const S=x.useCallback((N,J)=>{J.stopPropagation(),J.preventDefault(),l(N.id),d(N.title),p(null)},[]),y=x.useCallback(()=>{a&&c.trim()&&o(a,c.trim()),l(null),d("")},[a,c,o]),j=x.useCallback(()=>{l(null),d("")},[]),m=x.useCallback(N=>{N.stopPropagation(),N.key==="Enter"?(N.preventDefault(),y()):N.key==="Escape"&&(N.preventDefault(),j())},[y,j]),A=x.useCallback((N,J)=>{J.stopPropagation(),J.preventDefault(),p(N),l(null)},[]),C=x.useCallback(N=>{N.stopPropagation(),N.preventDefault(),f&&(s(f),p(null))},[f,s]),w=x.useCallback(N=>{N.stopPropagation(),N.preventDefault(),p(null)},[]);return u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsxs(js,{onOpenChange:N=>{N||(l(null),p(null))},children:[u.jsx(Ns,{asChild:!0,disabled:n,children:u.jsxs("button",{className:"flex items-center gap-1 text-sm font-semibold tracking-tight hover:text-foreground/80 transition-colors max-w-[180px] cursor-pointer",children:[u.jsx("div",{className:"h-2 w-2 rounded-full bg-primary/70 shrink-0"}),u.jsx("span",{className:"truncate",children:v}),u.jsx(hi,{className:"h-3 w-3 shrink-0 opacity-60"})]})}),u.jsxs(xi,{align:"start",className:"w-64",children:[e.map(N=>{const J=a===N.id;return f===N.id?u.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-sm",children:[u.jsx("span",{className:"text-destructive text-xs flex-1 truncate",children:"Delete this thread?"}),u.jsx("button",{className:"shrink-0 text-destructive hover:text-destructive/80 transition-colors cursor-pointer",onClick:C,children:u.jsx(yn,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:w,children:u.jsx(xn,{className:"h-3.5 w-3.5"})})]},N.id):J?u.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1",onClick:_=>_.stopPropagation(),onPointerDown:_=>_.stopPropagation(),children:[u.jsx("input",{ref:h,type:"text",value:c,onChange:_=>d(_.target.value),onKeyDown:m,onBlur:y,className:"flex-1 min-w-0 text-sm rounded-sm border border-border bg-background px-1.5 py-0.5 outline-none focus:ring-1 focus:ring-primary/40"}),u.jsx("button",{className:"shrink-0 text-primary hover:text-primary/80 transition-colors cursor-pointer",onMouseDown:_=>{_.preventDefault(),y()},children:u.jsx(yn,{className:"h-3.5 w-3.5"})}),u.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onMouseDown:_=>{_.preventDefault(),j()},children:u.jsx(xn,{className:"h-3.5 w-3.5"})})]},N.id):u.jsxs(Ft,{onSelect:()=>r(N.id),className:`group ${N.id===(t==null?void 0:t.id)?"bg-accent":""}`,children:[u.jsx("span",{className:"truncate flex-1",children:N.title.length>30?N.title.slice(0,30)+"...":N.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:_=>S(N,_),children:u.jsx(ex,{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:_=>A(N.id,_),children:u.jsx(ca,{className:"h-3 w-3"})})]})]},N.id)}),u.jsx(xr,{}),u.jsxs(Ft,{onSelect:N=>{N.preventDefault();const J=i();J&&(l(J),d(xa()),p(null))},children:[u.jsx(nn,{className:"h-3.5 w-3.5 mr-1.5"}),"New Chat"]})]})]}),u.jsx(_e,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",onClick:()=>i(),disabled:n,title:"New chat thread",children:u.jsx(nn,{className:"h-3.5 w-3.5"})})]})}const Zm=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),lz=Array.from(Zm).join(","),uz=20*1024*1024,Dc=10;function cz(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t({type:"file",mediaType:e.type,filename:e.name,url:r.result}),r.onerror=n,r.readAsDataURL(e)})}function Rc(e){return Array.from(e).filter(t=>Zm.has(t.type)&&t.size<=uz)}function Vm(e){return e.startsWith("image/")}function Mc(){var K,ge,Ne;const e=Re(L=>L.contextAttachments),t=Re(L=>L.addContext),n=Re(L=>L.removeContext),r=Re(L=>L.scope),i=Re(L=>L.setScope),s=Re(L=>L.model),o=Re(L=>L.setModel),a=Re(L=>L.openChat),l=Re(L=>L.closeChat),c=Re(L=>L.threads),d=Re(L=>L.activeThreadId),f=Re(L=>L.createThread),p=Re(L=>L.deleteThread),h=Re(L=>L.switchThread),g=Re(L=>L.updateThreadMessages),v=Re(L=>L.updateThreadTitle),S=Re(L=>L.deleteThreadsForDocument),y=Ce(L=>L.activeTab),j=Ce(L=>L.documents),{messages:m,sendMessage:A,status:C,error:w,setMessages:N,stop:J,getMessageContext:D,getMessageScope:_}=MA(),[T,I]=x.useState(""),[z,O]=x.useState([]),[R,Y]=x.useState(!1),[H,$]=x.useState(!1),ee=x.useRef(null),k=x.useRef(null),oe=x.useRef(null),q=x.useCallback(async L=>{const xe=Rc(L);if(xe.length===0)return;const ze=await Promise.all(xe.map(cz));O(Be=>{const rt=[...Be,...ze];return rt.length>Dc?rt.slice(0,Dc):rt})},[]),b=x.useCallback(L=>{O(xe=>xe.filter((ze,Be)=>Be!==L))},[]),B=x.useCallback(L=>{var ze;const xe=(ze=L.clipboardData)==null?void 0:ze.files;if(xe&&xe.length>0){const Be=Rc(xe);Be.length>0&&(L.preventDefault(),q(Be))}},[q]),V=x.useCallback(L=>{var ze;L.preventDefault(),$(!1);const xe=(ze=L.dataTransfer)==null?void 0:ze.files;xe&&xe.length>0&&q(Array.from(xe))},[q]),re=x.useCallback(L=>{L.preventDefault(),$(!0)},[]),se=x.useCallback(()=>$(!1),[]),P=y?d[y]:void 0,ue=P?c[P]:void 0,he=x.useMemo(()=>y?Object.values(c).filter(L=>L.documentName===y).sort((L,xe)=>xe.updatedAt-L.updatedAt):[],[c,y]);x.useEffect(()=>{y&&he.length===0&&f(y)},[y,he.length,f]);const ce=x.useRef(c);ce.current=c,x.useEffect(()=>{const L=new Set(j.map(ze=>ze.name)),xe=new Set;for(const ze of Object.values(ce.current))!L.has(ze.documentName)&&ze.documentName!=="__migrated__"&&xe.add(ze.documentName);for(const ze of xe)S(ze)},[j,S]);const pe=x.useRef(null);x.useEffect(()=>{pe.current!==P&&(pe.current=P,N((ue==null?void 0:ue.messages)??[]))},[P,ue,N]),x.useEffect(()=>{var L;(L=ee.current)==null||L.scrollIntoView({behavior:"smooth"})},[m,C]),x.useEffect(()=>{const L=xe=>{var rt;const{documentName:ze,selection:Be}=xe.detail;t({...Be,documentName:ze}),a(),(rt=k.current)==null||rt.focus()};return window.addEventListener("monaco-selection-to-ai",L),()=>window.removeEventListener("monaco-selection-to-ai",L)},[t,a]);const me=C==="streaming",U=C==="submitted"||me,Te=x.useCallback(L=>{L.preventDefault(),!(!T.trim()&&z.length===0||U)&&(A(T,z.length>0?z:void 0),I(""),O([]))},[T,z,U,A]),X=x.useCallback(L=>{L.key==="Enter"&&!L.shiftKey&&(L.preventDefault(),Te(L))},[Te]),we=x.useCallback(()=>{m.length!==0&&Y(!0)},[m.length]),E=x.useCallback(()=>{Y(!1),N([]),P&&(g(P,[]),v(P,xa()))},[N,P,g,v]),[M,F]=x.useState(null),ne=x.useCallback(L=>{F(L)},[]),Q=x.useCallback(()=>{var rt,tt;if(!M)return;const L=m.findIndex(at=>at.id===M);if(L===-1){F(null);return}const xe=m[L],ze=new Set([L]);xe.role==="user"&&((rt=m[L+1])==null?void 0:rt.role)==="assistant"?ze.add(L+1):xe.role==="assistant"&&L>0&&((tt=m[L-1])==null?void 0:tt.role)==="user"&&ze.add(L-1);const Be=m.filter((at,un)=>!ze.has(un));N(Be),P&&g(P,Be),F(null)},[M,m,N,P,g]),te=x.useCallback(L=>{if(!U){if(he.length<=1){we();return}p(L)}},[U,he.length,we,p]),de=x.useCallback(()=>{if(!(!y||U))return f(y)},[y,U,f]),ve=x.useCallback(L=>{U||L===P||h(L)},[U,P,h]),Z=x.useCallback((L,xe)=>{v(L,xe)},[v]);return u.jsxs("div",{className:"flex flex-col h-full border-l bg-surface-chat",children:[u.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-surface-chat",children:[u.jsx(az,{threads:he,activeThread:ue,disabled:U,onSwitch:ve,onCreate:de,onDelete:te,onRename:Z}),u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(_e,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:we,disabled:U||m.length===0,children:"Clear"}),u.jsx(_e,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:l,title:"Close chat",children:u.jsx(xn,{className:"h-3.5 w-3.5"})})]})]}),u.jsx(ni,{className:"flex-1 min-h-0 [&_[data-radix-scroll-area-viewport]>div]:!block",children:u.jsxs("div",{className:"p-3 space-y-4 min-w-0",children:[m.length===0&&u.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4",children:[u.jsx("div",{className:"rounded-xl bg-primary/10 p-3 mb-4",children:u.jsx(nl,{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(ri,{shortcut:"mod+k"}),u.jsx("span",{className:"text-xs text-muted-foreground",children:"to send a selection"})]})]}),m.map((L,xe)=>{let ze;if(L.role==="user"){const tt=D(L.id);tt&&tt.length>0&&(ze=tt)}else if(L.role==="assistant"){for(let tt=xe-1;tt>=0;tt--)if(m[tt].role==="user"){ze=D(m[tt].id);break}}const Be=me&&xe===m.length-1&&L.role==="assistant",rt=L.role==="user"?_(L.id):void 0;return u.jsx(dz,{msg:L,isStreaming:Be,context:ze,scope:rt,onDelete:U?void 0:ne},L.id)}),U&&((K=m[m.length-1])==null?void 0:K.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(Lr,{className:"h-3.5 w-3.5 animate-spin text-primary"}),u.jsx("span",{children:"Thinking..."})]})})}),w&&!U&&u.jsx("div",{className:"flex justify-start",children:u.jsx("div",{className:"rounded-lg px-3 py-2 bg-destructive/10 border border-destructive/30 text-destructive text-sm max-w-[90%]",children:w.message||"Something went wrong"})}),u.jsx("div",{ref:ee})]})}),u.jsxs("div",{className:`border-t border-border/60 p-2.5 space-y-2 bg-surface-chat transition-colors ${H?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:V,onDragOver:re,onDragLeave:se,children:[e.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((L,xe)=>u.jsx(Mm,{context:L,onRemove:()=>n(xe)},xe))}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx(hz,{model:s,setModel:o}),ot==="pptx"&&y&&u.jsx(gz,{scope:r,setScope:i,docSize:((Ne=(ge=j.find(L=>L.name===y))==null?void 0:ge.text)==null?void 0:Ne.length)??0})]}),z.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:z.map((L,xe)=>u.jsxs("div",{className:"relative group",children:[Vm(L.mediaType)?u.jsx("img",{src:L.url,alt:L.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(Co,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsx("span",{className:"text-xs truncate text-muted-foreground",children:L.filename||"file"})]}),u.jsx("button",{type:"button",onClick:()=>b(xe),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(xn,{className:"h-3 w-3"})})]},xe))}),u.jsxs("form",{onSubmit:Te,className:"flex items-end gap-2",children:[u.jsx("input",{ref:oe,type:"file",accept:lz,multiple:!0,className:"hidden",onChange:L=>{L.target.files&&q(Array.from(L.target.files)),L.target.value=""}}),u.jsx(_e,{type:"button",variant:"ghost",size:"icon",className:"shrink-0 h-9 w-9 rounded-lg text-muted-foreground hover:text-foreground",onClick:()=>{var L;return(L=oe.current)==null?void 0:L.click()},title:"Attach file",children:u.jsx(Co,{className:"h-4 w-4"})}),u.jsx("textarea",{ref:k,value:T,onChange:L=>{I(L.target.value);const xe=L.target;xe.style.height="auto",xe.style.height=`${Math.min(xe.scrollHeight,128)}px`},onKeyDown:X,onPaste:B,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}),U?u.jsx(_e,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:J,title:"Stop generating",children:u.jsx(Ed,{className:"h-4 w-4"})}):u.jsx(_e,{type:"submit",size:"icon",disabled:!T.trim()&&z.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:u.jsx(nl,{className:"h-4 w-4"})})]})]}),u.jsx(Ct,{open:R,onOpenChange:Y,children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Clear thread"}),u.jsx(an,{children:"This will delete all messages in this thread. This action cannot be undone."})]}),u.jsxs(bn,{children:[u.jsx(il,{asChild:!0,children:u.jsx(_e,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(_e,{variant:"destructive",size:"sm",onClick:E,children:"Clear"})]})]})}),u.jsx(Ct,{open:M!==null,onOpenChange:L=>{L||F(null)},children:u.jsxs(kt,{className:"max-w-sm",children:[u.jsxs(Ut,{children:[u.jsx(Jt,{children:"Delete message"}),u.jsx(an,{children:"This will delete the message and its paired response. This action cannot be undone."})]}),u.jsxs(bn,{children:[u.jsx(il,{asChild:!0,children:u.jsx(_e,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(_e,{variant:"destructive",size:"sm",onClick:Q,children:"Delete"})]})]})})]})}const dz=x.memo(function({msg:t,isStreaming:n,context:r,scope:i,onDelete:s}){var l,c;const o=((l=t.parts)==null?void 0:l.filter(d=>d.type==="text").map(d=>d.text).join(""))||"",a=((c=t.parts)==null?void 0:c.filter(d=>d.type==="file"))||[];return u.jsx("div",{className:`group/msg flex ${t.role==="user"?"justify-end":"justify-start"}`,children:u.jsxs("div",{className:`rounded-lg px-3 py-2 max-w-[90%] overflow-hidden min-w-0 ${t.role==="user"?"bg-primary text-primary-foreground":"bg-muted/60 border border-border/40"}`,children:[t.role==="user"?u.jsxs("div",{children:[a.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:a.map((d,f)=>Vm(d.mediaType)?u.jsx("img",{src:d.url,alt:d.filename||"image",className:"h-20 max-w-[160px] rounded-sm object-cover"},f):u.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm bg-primary-foreground/20 px-2 py-1",children:[u.jsx(Co,{className:"h-3 w-3 shrink-0"}),u.jsx("span",{className:"text-xs truncate max-w-[120px]",children:d.filename||"file"})]},f))}),r&&r.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:r.map((d,f)=>u.jsx(Mm,{context:d,variant:"sent"},f))}),o&&u.jsx("div",{className:"whitespace-pre-wrap text-sm break-words",children:o}),i&&i!=="global"&&u.jsx("span",{className:"text-[10px] text-primary-foreground/60 mt-0.5 block text-right",children:i})]}):u.jsx(fz,{text:o,isStreaming:n,context:r,scope:i}),s&&!n&&u.jsx("div",{className:"opacity-0 transition-opacity group-hover/msg:opacity-100 focus-within:opacity-100 mt-1",children:u.jsx("button",{type:"button","aria-label":"Delete message",onClick:()=>s(t.id),className:`p-0.5 rounded-sm cursor-pointer focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring ${t.role==="user"?"text-primary-foreground/50 hover:text-primary-foreground/80":"text-muted-foreground hover:text-destructive"}`,children:u.jsx(ca,{className:"h-3 w-3"})})})]})})},(e,t)=>e.msg.id===t.msg.id&&e.msg===t.msg&&e.isStreaming===t.isStreaming&&e.scope===t.scope&&e.onDelete===t.onDelete&&e.context===t.context);function fz({text:e,isStreaming:t,context:n,scope:r}){return t?u.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1",children:u.jsx("pre",{className:"whitespace-pre-wrap font-sans text-sm m-0 p-0 bg-transparent border-none",children:e})}):u.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1 [&_ul]:my-1 [&_ol]:my-1 [&_li]:my-0.5 [&_h1]:text-base [&_h2]:text-sm [&_h3]:text-sm [&_h1]:my-2 [&_h2]:my-1.5 [&_h3]:my-1",children:u.jsx(F1,{remarkPlugins:[X_],components:{pre:({children:i})=>u.jsx(u.Fragment,{children:i}),code:({className:i,children:s})=>{const o=i==null?void 0:i.startsWith("language-"),a=(i==null?void 0:i.replace("language-",""))||"",l=String(s).replace(/\n$/,"");if(!o)return u.jsx("code",{className:"rounded-sm bg-muted px-1 py-0.5 text-xs font-mono",children:s});const c=a==="json"||a==="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:a||"code"}),!c&&u.jsx(xz,{text:l})]}),u.jsx("pre",{className:"p-3 text-xs font-mono overflow-x-auto max-h-80 overflow-y-auto m-0",children:u.jsx("code",{children:l})}),c&&u.jsx(oz,{json:l,context:n,scope:r})]})}},children:e})})}const pz=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function hz({model:e,setModel:t}){return u.jsxs(ei,{value:e,onValueChange:n=>t(n),children:[u.jsx(hr,{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(ti,{})}),u.jsx(mr,{children:pz.map(n=>u.jsx(Dn,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const $c={global:"AI sees and edits the entire document",slides:"AI sees and edits only slides — templates stay unchanged",templates:"AI sees and edits only template layouts — slides stay unchanged"},mz=1e5;function gz({scope:e,setScope:t,docSize:n}){return u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs("div",{className:"flex items-center gap-1.5",children:[u.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Scope"}),u.jsx("div",{className:"flex items-center bg-muted/40 rounded-md p-0.5 gap-px",children:Object.keys($c).map(r=>u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("button",{type:"button",onClick:()=>t(r),className:`px-2 py-0.5 rounded-sm text-[10px] cursor-pointer transition-colors ${e===r?"bg-background text-foreground font-medium shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:r})}),u.jsx(Ye,{side:"top",className:"text-xs max-w-[200px]",children:$c[r]})]},r))})]}),e==="global"&&n>mz&&u.jsxs("div",{className:"text-[10px] text-warning flex items-center gap-1",children:[u.jsx(Id,{className:"h-3 w-3 shrink-0"}),u.jsxs("span",{children:["Large doc — switch to"," ",u.jsx("button",{type:"button",onClick:()=>t("slides"),className:"underline cursor-pointer hover:text-warning/80",children:"slides"})," ","or"," ",u.jsx("button",{type:"button",onClick:()=>t("templates"),className:"underline cursor-pointer hover:text-warning/80",children:"templates"})]})]})]})}function xz({text:e}){const[t,n]=x.useState(!1),r=x.useCallback(async()=>{await navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},[e]);return u.jsx("button",{onClick:r,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:t?"Copied!":"Copy"})}function yz({discoveryData:e}){const t=mf(),n=fy(),r=Re(_=>_.chatOpen),i=Re(_=>_.toggleChat),[s,o]=x.useState(()=>{try{const _=localStorage.getItem("dev-env.sidebar-open");return n?!1:_?_==="true":!0}catch{return!n}}),[a,l]=x.useState(()=>{try{const _=localStorage.getItem("dev-env.preview-open");return _?_==="true":!0}catch{return!0}}),[c,d]=x.useState("editor"),[f,p]=x.useState(!1),h=150,[g,v]=x.useState(!s),[S,y]=x.useState(!1);x.useEffect(()=>{try{localStorage.setItem("dev-env.sidebar-open",String(s))}catch{}},[s]),x.useEffect(()=>{try{localStorage.setItem("dev-env.preview-open",String(a))}catch{}},[a]);const j=x.useRef(n);x.useEffect(()=>{n&&!j.current&&s&&(y(!0),o(!1),setTimeout(()=>{v(!0),y(!1)},h)),!n&&j.current&&!s&&(y(!0),o(!0),setTimeout(()=>{v(!1),y(!1)},h)),j.current=n},[n,s]);const m=x.useCallback(()=>{if(t){p(_=>!_);return}y(!0),o(_=>!_),setTimeout(()=>{v(_=>!_),y(!1)},h)},[t]),A=x.useCallback(()=>l(_=>!_),[]),C=x.useRef(i),w=x.useRef(m),N=x.useRef(A);x.useEffect(()=>{C.current=i}),x.useEffect(()=>{w.current=m}),x.useEffect(()=>{N.current=A}),x.useEffect(()=>{const _=T=>{(T.metaKey||T.ctrlKey)&&(T.code==="KeyB"&&!T.shiftKey&&(T.preventDefault(),w.current()),T.code==="KeyJ"&&T.shiftKey&&(T.preventDefault(),T.stopPropagation(),C.current()),T.code==="KeyP"&&T.shiftKey&&(T.preventDefault(),N.current()))};return window.addEventListener("keydown",_,!0),()=>window.removeEventListener("keydown",_,!0)},[]);const J=RA,D=[{key:"editor",icon:Eo,label:"Editor"},{key:"preview",icon:Ad,label:"Preview"},{key:"chat",icon:zd,label:"Chat"}];return t?u.jsx(J,{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(ff,{open:f,onOpenChange:p,children:[u.jsx(ay,{asChild:!0,children:u.jsx(_e,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:u.jsx(Td,{className:"h-4 w-4"})})}),u.jsx(ba,{side:"left",className:"p-0 w-72",children:u.jsx(Nl,{discoveryData:e,onToggleSidebar:()=>p(!1),isCollapsed:!1})})]}),u.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:D.map(({key:_,icon:T,label:I})=>u.jsxs(_e,{variant:c===_?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>d(_),children:[u.jsx(T,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"hidden xs:inline",children:I})]},_))})]}),c!=="chat"&&u.jsx(Wl,{previewOpen:a,onTogglePreview:A}),u.jsxs("div",{className:"flex-1 min-h-0",children:[c==="editor"&&u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(El,{})}),c==="preview"&&u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Cl,{})}),c==="chat"&&u.jsx(Mc,{})]})]})}):u.jsx(J,{children:u.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[u.jsx("div",{className:G("shrink-0 overflow-hidden border-r bg-sidebar","transition-[width] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]",s?"w-64":"w-12"),children:u.jsx(Nl,{discoveryData:e,onToggleSidebar:m,isCollapsed:g,isAnimating:S})}),u.jsxs("div",{className:"flex-1 min-w-0 flex flex-col h-full",children:[u.jsx(Wl,{previewOpen:a,onTogglePreview:A}),u.jsxs(Gb,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[u.jsx(Xs,{defaultSize:a?50:100,minSize:20,id:"editor",order:1,children:u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(El,{})})}),a&&u.jsxs(u.Fragment,{children:[u.jsx($l,{withHandle:!0}),u.jsx(Xs,{defaultSize:50,minSize:20,id:"preview",order:2,children:u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Cl,{})})})]}),r&&u.jsxs(u.Fragment,{children:[u.jsx($l,{withHandle:!0}),u.jsx(Xs,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:u.jsx(Mc,{})})]})]})]})]})})}function bz(){const[e,t]=x.useState(null),[n,r]=x.useState(!0),[i,s]=x.useState(null),o=x.useCallback(async()=>{r(!0),s(null);try{const a=await fetch("/api/discovery/all");if(!a.ok)throw new Error(`Discovery failed: ${a.statusText}`);const l=await a.json();if(!l.success)throw new Error(l.error||"Discovery failed");t(l.data)}catch(a){console.error("Discovery error:",a),s(a instanceof Error?a.message:"Failed to fetch discovered items"),t({plugins:[],documents:[],themes:[]})}finally{r(!1)}},[]);return x.useEffect(()=>{o()},[o]),{data:e,loading:n,error:i,refetch:o}}let Mi=null;async function vz(){const e=await fetch("/api/discovery/load-plugins",{method:"POST"});if(!e.ok)throw new Error(`Failed to load plugins: ${e.statusText}`);const t=await e.json();if(!t.success)throw new Error(t.error||"Failed to load plugins");return t.data.loaded}function wz(){const[e,t]=x.useState(!1),[n,r]=x.useState(null),[i,s]=x.useState(0);return{loadPlugins:x.useCallback(async()=>{t(!0),r(null);try{Mi||(Mi=vz().finally(()=>{Mi=null}));const a=await Mi;return s(a),!0}catch(a){return console.error("Plugin loading error:",a),r(a instanceof Error?a.message:"Failed to load plugins"),!1}finally{t(!1)}},[]),loading:e,error:n,loadedCount:i}}function kz(){const{data:e,loading:t,error:n}=bz(),{loadPlugins:r}=wz(),i=Bt(s=>s.applyPluginsWithValidation);return x.useEffect(()=>{e&&e.plugins.length>0&&r().then(s=>{if(s){console.log("Plugins loaded successfully");const o=Bt.getState().selectedPlugins;o.size>0&&(console.log("Auto-applying persisted plugin selections:",Array.from(o)),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(ix,{children:u.jsx(sx,{children:u.jsx(ox,{children:u.jsx(ax,{children:u.jsx(lx,{children:u.jsx(Ux,{children:u.jsx(xf,{children:u.jsx("section",{className:"flex h-screen w-full flex-col",children:u.jsx("div",{className:"grow overflow-hidden",children:u.jsx(yz,{discoveryData:e})})})})})})})})})})}const zz=Object.freeze(Object.defineProperty({__proto__:null,HomePage:kz},Symbol.toStringTag,{value:"Module"}));export{Kt as B,Ct as D,zz as H,nv as P,Yr as S,dr as T,Xf as a,df as b,kt as c,Ut as d,Jt as e,Xb as u};
|
|
106
|
-
//# sourceMappingURL=HomePage-
|
|
106
|
+
//# sourceMappingURL=HomePage-ClplX49_.js.map
|