@json-to-office/jto 0.33.2 → 0.34.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-Cq6woGMG.js → HomePage-B6EwpLeU.js} +4 -4
- package/dist/client/assets/{HomePage-Cq6woGMG.js.map → HomePage-B6EwpLeU.js.map} +1 -1
- package/dist/client/assets/{JsonEditorPage-GZV7oJD2.js → JsonEditorPage-BOyS9roy.js} +3 -3
- package/dist/client/assets/{JsonEditorPage-GZV7oJD2.js.map → JsonEditorPage-BOyS9roy.js.map} +1 -1
- package/dist/client/assets/{MonacoPluginProvider-btNzJ41o.js → MonacoPluginProvider-DS8Ov7V6.js} +3 -3
- package/dist/client/assets/{MonacoPluginProvider-btNzJ41o.js.map → MonacoPluginProvider-DS8Ov7V6.js.map} +1 -1
- package/dist/client/assets/{editor-monaco-json-rhvIaBDI.js → editor-monaco-json-5MnjNhYy.js} +2 -2
- package/dist/client/assets/{editor-monaco-json-rhvIaBDI.js.map → editor-monaco-json-5MnjNhYy.js.map} +1 -1
- package/dist/client/assets/{editor-refs-store-DeJZ8FB9.js → editor-refs-store-DLWwmGGm.js} +2 -2
- package/dist/client/assets/{editor-refs-store-DeJZ8FB9.js.map → editor-refs-store-DLWwmGGm.js.map} +1 -1
- package/dist/client/assets/{editor-Cugq4RzH.js → editor-sQA3rPOP.js} +2 -2
- package/dist/client/assets/{editor-Cugq4RzH.js.map → editor-sQA3rPOP.js.map} +1 -1
- package/dist/client/assets/index-CkyZoRBe.js +5 -0
- package/dist/client/assets/index-CkyZoRBe.js.map +1 -0
- package/dist/client/assets/{preview-B_B09gpA.js → preview-CisNYRaE.js} +2 -2
- package/dist/client/assets/{preview-B_B09gpA.js.map → preview-CisNYRaE.js.map} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +4 -4
- package/dist/client/assets/index-C9uVroFQ.js +0 -5
- package/dist/client/assets/index-C9uVroFQ.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 Mm=Object.defineProperty;var $m=(e,t,n)=>t in e?Mm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Xa=(e,t,n)=>$m(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as Se,R as Oc,g as oa}from"./react-vendor-CTFDOf2G.js";import{b as Pc,c as aa,d as Dc,e as hs,f as ms,D as gs,O as xs,g as Lm,V as Fm,h as Rc,I as Bm,i as Zm,j as Mc,k as Vm,l as $c,m as Um,n as Jm,G as Hm,S as Lc,o as Fc,L as Bc,p as Zc,q as Vc,r as yr,s as Wm,t as qm,u as Gm,v as Uc,w as Jc,x as Hc,y as Wc,z as qc,B as Gc,E as Yc,F as Kc,H as Xc,J as Ym,K as Km,M as Xm,N as Qc,Q as ed,U as td,W as nd,X as rd,Y as id,Z as sd,_ as od,$ as ad,a0 as ld,a1 as Qm,a2 as ud,a3 as eg,a4 as tg,a5 as cd,a6 as ng,a7 as rg,a8 as ig,a9 as sg,aa as og,ab as ag,ac as lg,ad as dd,ae as fd,af as pd}from"./radix-ui-Bq-7y_Sq.js";import{c as q,u as vr,S as sn,A as hd,T as vi,C as ug,E as cg,F as ot,a as dg,b as fg,d as qe,e as Ge,f as Ye,g as md,_ as gd,h as wi,i as pg,j as hg,k as mg,l as jr,s as Ls,m as Di,W as gg}from"./index-C9uVroFQ.js";import{X as xn,C as ci,a as bn,b as xg,d as di,G as xd,F as bg,e as Pn,f as bd,P as yg,g as vg,h as yd,E as vd,B as wo,H as wg,T as ko,L as Qa,i as kg,j as Sg,S as wd,I as _g,k as jg,l as So,m as Ng,n as Eg,o as Cg,p as Ig,q as Tg,r as Ag,s as zg,t as Og,u as bs,v as Pg,M as Dg,w as kd,x as nn,y as Rg,z as Mg,A as Sd,D as $g,J as Lg,K as Fg,N as Bg,R as Zg,O as Vg,Q as _d,U as Ug,V as _o,W as la,Y as jd,Z as Jg,_ as Nd,$ as jo,a0 as Hg,a1 as Wg,a2 as el,a3 as No}from"./ui-vendor-Cs3OXpi7.js";import{B as Ne,u as qg,d as tl}from"./editor-refs-store-DeJZ8FB9.js";import{u as Pe,i as Gg,a as Eo,b as rn,g as Yg,c as Bt,T as Ed,d as ki,S as Kg,O as Xg,e as Qg,M as ex,D as tx}from"./MonacoPluginProvider-btNzJ41o.js";import{u as ua,a as nx,d as rx,p as ix,b as sx,e as ox}from"./state-vendor-ByFYl9bq.js";import{b as ax}from"./query-vendor-Df8-oete.js";const Ct=Pc,lx=Dc,nl=aa,Cd=x.forwardRef(({className:e,...t},n)=>u.jsx(xs,{ref:n,className:q("fixed inset-0 z-50 bg-black/50",e),...t}));Cd.displayName=xs.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(lx,{children:[u.jsx(Cd,{}),u.jsxs(hs,{ref:r,className:q("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(aa,{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=hs.displayName;const Ut=({className:e,...t})=>u.jsx("div",{className:q("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ut.displayName="DialogHeader";const yn=({className:e,...t})=>u.jsx("div",{className:q("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});yn.displayName="DialogFooter";const Jt=x.forwardRef(({className:e,...t},n)=>u.jsx(ms,{ref:n,className:q("text-lg leading-none font-semibold tracking-tight",e),...t}));Jt.displayName=ms.displayName;const an=x.forwardRef(({className:e,...t},n)=>u.jsx(gs,{ref:n,className:q("text-muted-foreground text-sm",e),...t}));an.displayName=gs.displayName;const qr=Lm,ux=Hm,Gr=Fm,cr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Rc,{ref:r,className:q("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(Bm,{asChild:!0,children:u.jsx(ci,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));cr.displayName=Rc.displayName;const Id=x.forwardRef(({className:e,...t},n)=>u.jsx(Lc,{ref:n,className:q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(xg,{className:"h-4 w-4"})}));Id.displayName=Lc.displayName;const Td=x.forwardRef(({className:e,...t},n)=>u.jsx(Fc,{ref:n,className:q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ci,{className:"h-4 w-4"})}));Td.displayName=Fc.displayName;const dr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(Zm,{children:u.jsxs(Mc,{ref:i,className:q("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(Id,{}),u.jsx(Vm,{className:q("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Td,{})]})}));dr.displayName=Mc.displayName;const Ad=x.forwardRef(({className:e,...t},n)=>u.jsx(Bc,{ref:n,className:q("px-2 py-1.5 text-sm font-semibold",e),...t}));Ad.displayName=Bc.displayName;const Dn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs($c,{ref:r,className:q("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(Um,{children:u.jsx(bn,{className:"h-4 w-4"})})}),u.jsx(Jm,{children:t})]}));Dn.displayName=$c.displayName;const cx=x.forwardRef(({className:e,...t},n)=>u.jsx(Zc,{ref:n,className:q("bg-muted -mx-1 my-1 h-px",e),...t}));cx.displayName=Zc.displayName;const fi=x.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:q("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}));fi.displayName="Input";const dx=di("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),sr=x.forwardRef(({className:e,...t},n)=>u.jsx(Vc,{ref:n,className:q(dx(),e),...t}));sr.displayName=Vc.displayName;const fx=di("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:q(fx({variant:t}),e),...n})}const px=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:o}=Pe(ua(I=>({documents:I.documents,documentTypes:I.documentTypes,activeTab:I.activeTab,createDocument:I.createDocument,openDocument:I.openDocument}))),{toast:a}=vr(),l=x.useMemo(()=>n.filter(I=>r[I.name]!=="application/json+theme"),[n,r]),[c,d]=x.useState(""),[f,p]=x.useState(""),[h,g]=x.useState("playground"),[v,S]=x.useState(!1),[b,j]=x.useState(null),[m,T]=x.useState(null),[C,w]=x.useState(null),N=()=>{j(null),T(null),w(null)};x.useEffect(()=>{if(!e)return;j(null),T(null),w(null);const I=l.map(M=>M.name),z=I.includes(i)?i:I[0]??"";p(z),d(I.find(M=>M!==z)??"")},[e]);const H=async()=>{const I=l.find(M=>M.name===c),z=l.find(M=>M.name===f);if(!(!I||!z)){S(!0),j(null),T(null),w(null);try{const M=await fetch(hd.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:I.text,newDefinition:z.text,options:{author:h||"playground"}})}),A=await M.json();if(!M.ok||!A.success){const P=Array.isArray(A.errors)?`: ${A.errors.slice(0,3).map(D=>D.message||String(D)).join("; ")}`:"";throw new Error((A.error||`Diff failed (${M.status})`)+P)}T(A.data.summary),w(A.data.document)}catch(M){j(M instanceof Error?M.message:"Diff failed")}finally{S(!1)}}},O=()=>{if(!C)return;const I=new Set(n.map(A=>A.name));let z=`${f}-redline`,M=2;for(;I.has(z);)z=`${f}-redline-${M++}`;s(z,JSON.stringify(C,null,2)),o(z),a({title:`Redline created: ${z}`}),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(xd,{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(qr,{value:c,onValueChange:I=>{d(I),N()},children:[u.jsx(cr,{id:"diff-base",children:u.jsx(Gr,{placeholder:"Select document"})}),u.jsx(dr,{children:l.map(I=>u.jsx(Dn,{value:I.name,children:I.name},I.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(qr,{value:f,onValueChange:I=>{p(I),N()},children:[u.jsx(cr,{id:"diff-revised",children:u.jsx(Gr,{placeholder:"Select document"})}),u.jsx(dr,{children:l.map(I=>u.jsx(Dn,{value:I.name,children:I.name},I.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(fi,{id:"diff-author",value:h,onChange:I=>{g(I.target.value),N()},placeholder:"playground"})]}),b&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:b}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Kt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),_===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((I,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[I.path," [",I.component,"] ",I.detail]},z))]}),m.notes.map((I,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",I]},z))]})]}),u.jsx(yn,{children:m&&_+m.untracked.length>0?u.jsxs(Ne,{onClick:O,children:[u.jsx(bg,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Ne,{onClick:H,disabled:v||!c||!f||c===f,children:[v&&u.jsx(sn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var pi=e=>e.type==="checkbox",Tn=e=>e instanceof Date,pt=e=>e==null;const zd=e=>typeof e=="object";var et=e=>!pt(e)&&!Array.isArray(e)&&zd(e)&&!Tn(e),Od=e=>et(e)&&e.target?pi(e.target)?e.target.checked:e.target.value:e,hx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Pd=(e,t)=>e.has(hx(t)),mx=e=>{const t=e.constructor&&e.constructor.prototype;return et(t)&&t.hasOwnProperty("isPrototypeOf")},ca=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function bt(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(!(ca&&(e instanceof Blob||r))&&(n||et(e)))if(t=n?[]:{},!n&&!mx(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=bt(e[i]));else return e;return t}var ys=e=>Array.isArray(e)?e.filter(Boolean):[],Qe=e=>e===void 0,le=(e,t,n)=>{if(!t||!et(e))return n;const r=ys(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",da=e=>/^\w*$/.test(e),Dd=e=>ys(e.replace(/["|']|\]/g,"").split(/\.|\[/)),$e=(e,t,n)=>{let r=-1;const i=da(t)?[t]:Dd(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 Zi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ft={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},tn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Rd=Se.createContext(null),vs=()=>Se.useContext(Rd),gx=e=>{const{children:t,...n}=e;return Se.createElement(Rd.Provider,{value:n},t)};var Md=(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]!==Ft.all&&(t._proxyFormState[o]=!r||Ft.all),n&&(n[o]=!0),e[o]}});return i},yt=e=>et(e)&&!Object.keys(e).length,$d=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return yt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(o=>t[o]===(!r||Ft.all))},Zr=e=>Array.isArray(e)?e:[e],Ld=(e,t,n)=>!e||!t||e===t||Zr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function fa(e){const t=Se.useRef(e);t.current=e,Se.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function xx(e){const t=vs(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[o,a]=Se.useState(n._formState),l=Se.useRef(!0),c=Se.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=Se.useRef(i);return d.current=i,fa({disabled:r,next:f=>l.current&&Ld(d.current,f.name,s)&&$d(f,c.current,n._updateFormState)&&a({...n._formState,...f}),subject:n._subjects.state}),Se.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),Se.useMemo(()=>Md(o,n,c.current,!1),[o,n])}var Yt=e=>typeof e=="string",Fd=(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 bx(e){const t=vs(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:o}=e||{},a=Se.useRef(r);a.current=r,fa({disabled:s,subject:n._subjects.values,next:d=>{Ld(a.current,d.name,o)&&c(bt(Fd(a.current,n._names,d.values||n._formValues,!1,i)))}});const[l,c]=Se.useState(n._getWatch(r,i));return Se.useEffect(()=>n._removeUnmounted()),l}function yx(e){const t=vs(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,o=Pd(i._names.array,n),a=bx({control:i,name:n,defaultValue:le(i._formValues,n,le(i._defaultValues,n,e.defaultValue)),exact:!0}),l=xx({control:i,name:n,exact:!0}),c=Se.useRef(i.register(n,{...e.rules,value:a,...zt(e.disabled)?{disabled:e.disabled}:{}})),d=Se.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=Se.useMemo(()=>({name:n,value:a,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:Od(p),name:n},type:Zi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:le(i._formValues,n),name:n},type:Zi.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 Se.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=bt(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]),Se.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),Se.useMemo(()=>({field:f,formState:l,fieldState:d}),[f,l,d])}const vx=e=>e.render(yx(e));var wx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},rl=e=>({isOnSubmit:!e||e===Ft.onSubmit,isOnBlur:e===Ft.onBlur,isOnChange:e===Ft.onChange,isOnAll:e===Ft.all,isOnTouch:e===Ft.onTouched}),il=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Vr=(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(Vr(a,t))break}else if(et(a)&&Vr(a,t))break}}};var kx=(e,t,n)=>{const r=Zr(le(e,n));return $e(r,"root",t[n]),$e(e,n,r),e},pa=e=>e.type==="file",Gt=e=>typeof e=="function",Vi=e=>{if(!ca)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Ri=e=>Yt(e),ha=e=>e.type==="radio",Ui=e=>e instanceof RegExp;const sl={value:!1,isValid:!1},ol={value:!0,isValid:!0};var Bd=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===""?ol:{value:e[0].value,isValid:!0}:ol:sl}return sl};const al={isValid:!1,value:null};var Zd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,al):al;function ll(e,t,n="validate"){if(Ri(e)||Array.isArray(e)&&e.every(Ri)||zt(e)&&!e)return{type:n,message:Ri(e)?e:"",ref:t}}var Bn=e=>et(e)&&!Ui(e)?e:{value:e,message:""},ul=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:b}=e._f,j=le(n,v);if(!b||t.has(v))return{};const m=a?a[0]:o,T=z=>{i&&m.reportValidity&&(m.setCustomValidity(zt(z)?"":z||""),m.reportValidity())},C={},w=ha(o),N=pi(o),H=w||N,O=(S||pa(o))&&Qe(o.value)&&Qe(j)||Vi(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,_=wx.bind(null,v,r,C),I=(z,M,A,P=tn.maxLength,D=tn.minLength)=>{const U=z?M:A;C[v]={type:z?P:D,message:U,ref:o,..._(z?P:D,U)}};if(s?!Array.isArray(j)||!j.length:l&&(!H&&(O||pt(j))||zt(j)&&!j||N&&!Bd(a).isValid||w&&!Zd(a).isValid)){const{value:z,message:M}=Ri(l)?{value:!!l,message:l}:Bn(l);if(z&&(C[v]={type:tn.required,message:M,ref:m,..._(tn.required,M)},!r))return T(M),C}if(!O&&(!pt(f)||!pt(p))){let z,M;const A=Bn(p),P=Bn(f);if(!pt(j)&&!isNaN(j)){const D=o.valueAsNumber||j&&+j;pt(A.value)||(z=D>A.value),pt(P.value)||(M=D<P.value)}else{const D=o.valueAsDate||new Date(j),U=k=>new Date(new Date().toDateString()+" "+k),$=o.type=="time",X=o.type=="week";Yt(A.value)&&j&&(z=$?U(j)>U(A.value):X?j>A.value:D>new Date(A.value)),Yt(P.value)&&j&&(M=$?U(j)<U(P.value):X?j<P.value:D<new Date(P.value))}if((z||M)&&(I(!!z,A.message,P.message,tn.max,tn.min),!r))return T(C[v].message),C}if((c||d)&&!O&&(Yt(j)||s&&Array.isArray(j))){const z=Bn(c),M=Bn(d),A=!pt(z.value)&&j.length>+z.value,P=!pt(M.value)&&j.length<+M.value;if((A||P)&&(I(A,z.message,M.message),!r))return T(C[v].message),C}if(h&&!O&&Yt(j)){const{value:z,message:M}=Bn(h);if(Ui(z)&&!j.match(z)&&(C[v]={type:tn.pattern,message:M,ref:o,..._(tn.pattern,M)},!r))return T(M),C}if(g){if(Gt(g)){const z=await g(j,n),M=ll(z,m);if(M&&(C[v]={...M,..._(tn.validate,M.message)},!r))return T(M.message),C}else if(et(g)){let z={};for(const M in g){if(!yt(z)&&!r)break;const A=ll(await g[M](j,n),m,M);A&&(z={...A,..._(M,A.message)},T(A.message),r&&(C[v]=z))}if(!yt(z)&&(C[v]={ref:m,...z},!r))return C}}return T(!0),C};function Sx(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 _x(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:da(t)?[t]:Dd(t),r=n.length===1?e:Sx(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(et(r)&&yt(r)||Array.isArray(r)&&_x(r))&&it(e,n.slice(0,-1)),e}var Fs=()=>{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=[]}}},Co=e=>pt(e)||!zd(e);function hn(e,t){if(Co(e)||Co(t))return e===t;if(Tn(e)&&Tn(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(Tn(s)&&Tn(o)||et(s)&&et(o)||Array.isArray(s)&&Array.isArray(o)?!hn(s,o):s!==o)return!1}}return!0}var Vd=e=>e.type==="select-multiple",jx=e=>ha(e)||pi(e),Bs=e=>Vi(e)&&e.isConnected,Ud=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Ji(e,t={}){const n=Array.isArray(e);if(et(e)||n)for(const r in e)Array.isArray(e[r])||et(e[r])&&!Ud(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Ji(e[r],t[r])):pt(e[r])||(t[r]=!0);return t}function Jd(e,t,n){const r=Array.isArray(e);if(et(e)||r)for(const i in e)Array.isArray(e[i])||et(e[i])&&!Ud(e[i])?Qe(t)||Co(n[i])?n[i]=Array.isArray(e[i])?Ji(e[i],[]):{...Ji(e[i])}:Jd(e[i],pt(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Nr=(e,t)=>Jd(e,t,Ji(t)),Hd=(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 Zs(e){const t=e.ref;return pa(t)?t.files:ha(t)?Zd(e.refs).value:Vd(t)?[...t.selectedOptions].map(({value:n})=>n):pi(t)?Bd(e.refs).value:Hd(Qe(t.value)?e.ref.value:t.value,e)}var Nx=(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}},Er=e=>Qe(e)?e:Ui(e)?e.source:et(e)?Ui(e.value)?e.value.source:e.value:e;const cl="AsyncFunction";var Ex=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===cl||et(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===cl)),Cx=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function dl(e,t,n){const r=le(e,n);if(r||da(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 Ix=(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,Tx=(e,t)=>!ys(le(e,t)).length&&it(e,t);const Ax={mode:Ft.onSubmit,reValidateMode:Ft.onChange,shouldFocusError:!0};function zx(e={}){let t={...Ax,...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)?bt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:bt(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:Fs(),array:Fs(),state:Fs()},p=rl(t.mode),h=rl(t.reValidateMode),g=t.criteriaMode===Ft.all,v=E=>R=>{clearTimeout(c),c=setTimeout(E,R)},S=async E=>{if(!t.disabled&&(d.isValid||E)){const R=t.resolver?yt((await H()).errors):await _(r,!0);R!==n.isValid&&f.state.next({isValid:R})}},b=(E,R)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((E||Array.from(a.mount)).forEach(L=>{L&&(R?$e(n.validatingFields,L,R):it(n.validatingFields,L))}),f.state.next({validatingFields:n.validatingFields,isValidating:!yt(n.validatingFields)}))},j=(E,R=[],L,te,K=!0,ee=!0)=>{if(te&&L&&!t.disabled){if(o.action=!0,ee&&Array.isArray(le(r,E))){const ue=L(le(r,E),te.argA,te.argB);K&&$e(r,E,ue)}if(ee&&Array.isArray(le(n.errors,E))){const ue=L(le(n.errors,E),te.argA,te.argB);K&&$e(n.errors,E,ue),Tx(n.errors,E)}if(d.touchedFields&&ee&&Array.isArray(le(n.touchedFields,E))){const ue=L(le(n.touchedFields,E),te.argA,te.argB);K&&$e(n.touchedFields,E,ue)}d.dirtyFields&&(n.dirtyFields=Nr(i,s)),f.state.next({name:E,isDirty:z(E,R),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else $e(s,E,R)},m=(E,R)=>{$e(n.errors,E,R),f.state.next({errors:n.errors})},T=E=>{n.errors=E,f.state.next({errors:n.errors,isValid:!1})},C=(E,R,L,te)=>{const K=le(r,E);if(K){const ee=le(s,E,Qe(L)?le(i,E):L);Qe(ee)||te&&te.defaultChecked||R?$e(s,E,R?ee:Zs(K._f)):P(E,ee),o.mount&&S()}},w=(E,R,L,te,K)=>{let ee=!1,ue=!1;const be={name:E};if(!t.disabled){const B=!!(le(r,E)&&le(r,E)._f&&le(r,E)._f.disabled);if(!L||te){d.isDirty&&(ue=n.isDirty,n.isDirty=be.isDirty=z(),ee=ue!==be.isDirty);const Y=B||hn(le(i,E),R);ue=!!(!B&&le(n.dirtyFields,E)),Y||B?it(n.dirtyFields,E):$e(n.dirtyFields,E,!0),be.dirtyFields=n.dirtyFields,ee=ee||d.dirtyFields&&ue!==!Y}if(L){const Y=le(n.touchedFields,E);Y||($e(n.touchedFields,E,L),be.touchedFields=n.touchedFields,ee=ee||d.touchedFields&&Y!==L)}ee&&K&&f.state.next(be)}return ee?be:{}},N=(E,R,L,te)=>{const K=le(n.errors,E),ee=d.isValid&&zt(R)&&n.isValid!==R;if(t.delayError&&L?(l=v(()=>m(E,L)),l(t.delayError)):(clearTimeout(c),l=null,L?$e(n.errors,E,L):it(n.errors,E)),(L?!hn(K,L):K)||!yt(te)||ee){const ue={...te,...ee&&zt(R)?{isValid:R}:{},errors:n.errors,name:E};n={...n,...ue},f.state.next(ue)}},H=async E=>{b(E,!0);const R=await t.resolver(s,t.context,Nx(E||a.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(E),R},O=async E=>{const{errors:R}=await H(E);if(E)for(const L of E){const te=le(R,L);te?$e(n.errors,L,te):it(n.errors,L)}else n.errors=R;return R},_=async(E,R,L={valid:!0})=>{for(const te in E){const K=E[te];if(K){const{_f:ee,...ue}=K;if(ee){const be=a.array.has(ee.name),B=K._f&&Ex(K._f);B&&d.validatingFields&&b([te],!0);const Y=await ul(K,a.disabled,s,g,t.shouldUseNativeValidation&&!R,be);if(B&&d.validatingFields&&b([te]),Y[ee.name]&&(L.valid=!1,R))break;!R&&(le(Y,ee.name)?be?kx(n.errors,Y,ee.name):$e(n.errors,ee.name,Y[ee.name]):it(n.errors,ee.name))}!yt(ue)&&await _(ue,R,L)}}return L.valid},I=()=>{for(const E of a.unMount){const R=le(r,E);R&&(R._f.refs?R._f.refs.every(L=>!Bs(L)):!Bs(R._f.ref))&&ie(E)}a.unMount=new Set},z=(E,R)=>!t.disabled&&(E&&R&&$e(s,E,R),!hn(oe(),i)),M=(E,R,L)=>Fd(E,a,{...o.mount?s:Qe(R)?i:Yt(E)?{[E]:R}:R},L,R),A=E=>ys(le(o.mount?s:i,E,t.shouldUnregister?le(i,E,[]):[])),P=(E,R,L={})=>{const te=le(r,E);let K=R;if(te){const ee=te._f;ee&&(!ee.disabled&&$e(s,E,Hd(R,ee)),K=Vi(ee.ref)&&pt(R)?"":R,Vd(ee.ref)?[...ee.ref.options].forEach(ue=>ue.selected=K.includes(ue.value)):ee.refs?pi(ee.ref)?ee.refs.length>1?ee.refs.forEach(ue=>(!ue.defaultChecked||!ue.disabled)&&(ue.checked=Array.isArray(K)?!!K.find(be=>be===ue.value):K===ue.value)):ee.refs[0]&&(ee.refs[0].checked=!!K):ee.refs.forEach(ue=>ue.checked=ue.value===K):pa(ee.ref)?ee.ref.value="":(ee.ref.value=K,ee.ref.type||f.values.next({name:E,values:{...s}})))}(L.shouldDirty||L.shouldTouch)&&w(E,K,L.shouldTouch,L.shouldDirty,!0),L.shouldValidate&&k(E)},D=(E,R,L)=>{for(const te in R){const K=R[te],ee=`${E}.${te}`,ue=le(r,ee);(a.array.has(E)||et(K)||ue&&!ue._f)&&!Tn(K)?D(ee,K,L):P(ee,K,L)}},U=(E,R,L={})=>{const te=le(r,E),K=a.array.has(E),ee=bt(R);$e(s,E,ee),K?(f.array.next({name:E,values:{...s}}),(d.isDirty||d.dirtyFields)&&L.shouldDirty&&f.state.next({name:E,dirtyFields:Nr(i,s),isDirty:z(E,ee)})):te&&!te._f&&!pt(ee)?D(E,ee,L):P(E,ee,L),il(E,a)&&f.state.next({...n}),f.values.next({name:o.mount?E:void 0,values:{...s}})},$=async E=>{o.mount=!0;const R=E.target;let L=R.name,te=!0;const K=le(r,L),ee=()=>R.type?Zs(K._f):Od(E),ue=be=>{te=Number.isNaN(be)||Tn(be)&&isNaN(be.getTime())||hn(be,le(s,L,be))};if(K){let be,B;const Y=ee(),fe=E.type===Zi.BLUR||E.type===Zi.FOCUS_OUT,_e=!Cx(K._f)&&!t.resolver&&!le(n.errors,L)&&!K._f.deps||Ix(fe,le(n.touchedFields,L),n.isSubmitted,h,p),F=il(L,a,fe);$e(s,L,Y),fe?(K._f.onBlur&&K._f.onBlur(E),l&&l(0)):K._f.onChange&&K._f.onChange(E);const pe=w(L,Y,fe,!1),Te=!yt(pe)||F;if(!fe&&f.values.next({name:L,type:E.type,values:{...s}}),_e)return d.isValid&&(t.mode==="onBlur"&&fe?S():fe||S()),Te&&f.state.next({name:L,...F?{}:pe});if(!fe&&F&&f.state.next({...n}),t.resolver){const{errors:Be}=await H([L]);if(ue(Y),te){const rt=dl(n.errors,r,L),tt=dl(Be,r,rt.name||L);be=tt.error,L=tt.name,B=yt(Be)}}else b([L],!0),be=(await ul(K,a.disabled,s,g,t.shouldUseNativeValidation))[L],b([L]),ue(Y),te&&(be?B=!1:d.isValid&&(B=await _(r,!0)));te&&(K._f.deps&&k(K._f.deps),N(L,B,be,pe))}},X=(E,R)=>{if(le(n.errors,R)&&E.focus)return E.focus(),1},k=async(E,R={})=>{let L,te;const K=Zr(E);if(t.resolver){const ee=await O(Qe(E)?E:K);L=yt(ee),te=E?!K.some(ue=>le(ee,ue)):L}else E?(te=(await Promise.all(K.map(async ee=>{const ue=le(r,ee);return await _(ue&&ue._f?{[ee]:ue}:ue)}))).every(Boolean),!(!te&&!n.isValid)&&S()):te=L=await _(r);return f.state.next({...!Yt(E)||d.isValid&&L!==n.isValid?{}:{name:E},...t.resolver||!E?{isValid:L}:{},errors:n.errors}),R.shouldFocus&&!te&&Vr(r,X,E?K:a.mount),te},oe=E=>{const R={...o.mount?s:i};return Qe(E)?R:Yt(E)?le(R,E):E.map(L=>le(R,L))},G=(E,R)=>({invalid:!!le((R||n).errors,E),isDirty:!!le((R||n).dirtyFields,E),error:le((R||n).errors,E),isValidating:!!le(n.validatingFields,E),isTouched:!!le((R||n).touchedFields,E)}),y=E=>{E&&Zr(E).forEach(R=>it(n.errors,R)),f.state.next({errors:E?n.errors:{}})},Z=(E,R,L)=>{const te=(le(r,E,{_f:{}})._f||{}).ref,K=le(n.errors,E)||{},{ref:ee,message:ue,type:be,...B}=K;$e(n.errors,E,{...B,...R,ref:te}),f.state.next({name:E,errors:n.errors,isValid:!1}),L&&L.shouldFocus&&te&&te.focus&&te.focus()},V=(E,R)=>Gt(E)?f.values.subscribe({next:L=>E(M(void 0,R),L)}):M(E,R,!0),ie=(E,R={})=>{for(const L of E?Zr(E):a.mount)a.mount.delete(L),a.array.delete(L),R.keepValue||(it(r,L),it(s,L)),!R.keepError&&it(n.errors,L),!R.keepDirty&&it(n.dirtyFields,L),!R.keepTouched&&it(n.touchedFields,L),!R.keepIsValidating&&it(n.validatingFields,L),!t.shouldUnregister&&!R.keepDefaultValue&&it(i,L);f.values.next({values:{...s}}),f.state.next({...n,...R.keepDirty?{isDirty:z()}:{}}),!R.keepIsValid&&S()},se=({disabled:E,name:R,field:L,fields:te})=>{(zt(E)&&o.mount||E||a.disabled.has(R))&&(E?a.disabled.add(R):a.disabled.delete(R),w(R,Zs(L?L._f:le(te,R)._f),!1,!1,!0))},re=(E,R={})=>{let L=le(r,E);const te=zt(R.disabled)||zt(t.disabled);return $e(r,E,{...L||{},_f:{...L&&L._f?L._f:{ref:{name:E}},name:E,mount:!0,...R}}),a.mount.add(E),L?se({field:L,disabled:zt(R.disabled)?R.disabled:t.disabled,name:E}):C(E,!0,R.value),{...te?{disabled:R.disabled||t.disabled}:{},...t.progressive?{required:!!R.required,min:Er(R.min),max:Er(R.max),minLength:Er(R.minLength),maxLength:Er(R.maxLength),pattern:Er(R.pattern)}:{},name:E,onChange:$,onBlur:$,ref:K=>{if(K){re(E,R),L=le(r,E);const ee=Qe(K.value)&&K.querySelectorAll&&K.querySelectorAll("input,select,textarea")[0]||K,ue=jx(ee),be=L._f.refs||[];if(ue?be.find(B=>B===ee):ee===L._f.ref)return;$e(r,E,{_f:{...L._f,...ue?{refs:[...be.filter(Bs),ee,...Array.isArray(le(i,E))?[{}]:[]],ref:{type:ee.type,name:E}}:{ref:ee}}}),C(E,!1,void 0,ee)}else L=le(r,E,{}),L._f&&(L._f.mount=!1),(t.shouldUnregister||R.shouldUnregister)&&!(Pd(a.array,E)&&o.action)&&a.unMount.add(E)}}},de=()=>t.shouldFocusError&&Vr(r,X,a.mount),ge=E=>{zt(E)&&(f.state.next({disabled:E}),Vr(r,(R,L)=>{const te=le(r,L);te&&(R.disabled=te._f.disabled||E,Array.isArray(te._f.refs)&&te._f.refs.forEach(K=>{K.disabled=te._f.disabled||E}))},0,!1))},Ee=(E,R)=>async L=>{let te;L&&(L.preventDefault&&L.preventDefault(),L.persist&&L.persist());let K=bt(s);if(a.disabled.size)for(const ee of a.disabled)$e(K,ee,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:ee,values:ue}=await H();n.errors=ee,K=ue}else await _(r);if(it(n.errors,"root"),yt(n.errors)){f.state.next({errors:{}});try{await E(K,L)}catch(ee){te=ee}}else R&&await R({...n.errors},L),de(),setTimeout(de);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:yt(n.errors)&&!te,submitCount:n.submitCount+1,errors:n.errors}),te)throw te},ye=(E,R={})=>{le(r,E)&&(Qe(R.defaultValue)?U(E,bt(le(i,E))):(U(E,R.defaultValue),$e(i,E,bt(R.defaultValue))),R.keepTouched||it(n.touchedFields,E),R.keepDirty||(it(n.dirtyFields,E),n.isDirty=R.defaultValue?z(E,bt(le(i,E))):z()),R.keepError||(it(n.errors,E),d.isValid&&S()),f.state.next({...n}))},xe=(E,R={})=>{const L=E?bt(E):i,te=bt(L),K=yt(E),ee=K?i:te;if(R.keepDefaultValues||(i=L),!R.keepValues){if(R.keepDirtyValues){const ue=new Set([...a.mount,...Object.keys(Nr(i,s))]);for(const be of Array.from(ue))le(n.dirtyFields,be)?$e(ee,be,le(s,be)):U(be,le(ee,be))}else{if(ca&&Qe(E))for(const ue of a.mount){const be=le(r,ue);if(be&&be._f){const B=Array.isArray(be._f.refs)?be._f.refs[0]:be._f.ref;if(Vi(B)){const Y=B.closest("form");if(Y){Y.reset();break}}}}r={}}s=t.shouldUnregister?R.keepDefaultValues?bt(i):{}:bt(ee),f.array.next({values:{...ee}}),f.values.next({values:{...ee}})}a={mount:R.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!d.isValid||!!R.keepIsValid||!!R.keepDirtyValues,o.watch=!!t.shouldUnregister,f.state.next({submitCount:R.keepSubmitCount?n.submitCount:0,isDirty:K?!1:R.keepDirty?n.isDirty:!!(R.keepDefaultValues&&!hn(E,i)),isSubmitted:R.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:K?{}:R.keepDirtyValues?R.keepDefaultValues&&s?Nr(i,s):n.dirtyFields:R.keepDefaultValues&&E?Nr(i,E):R.keepDirty?n.dirtyFields:{},touchedFields:R.keepTouched?n.touchedFields:{},errors:R.keepErrors?n.errors:{},isSubmitSuccessful:R.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},W=(E,R)=>xe(Gt(E)?E(s):E,R);return{control:{register:re,unregister:ie,getFieldState:G,handleSubmit:Ee,setError:Z,_executeSchema:H,_getWatch:M,_getDirty:z,_updateValid:S,_removeUnmounted:I,_updateFieldArray:j,_updateDisabledField:se,_getFieldArray:A,_reset:xe,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(E=>{W(E,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:E=>{n={...n,...E}},_disableForm:ge,_subjects:f,_proxyFormState:d,_setErrors:T,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:re,handleSubmit:Ee,watch:V,setValue:U,getValues:oe,reset:W,resetField:ye,clearErrors:y,unregister:ie,setError:Z,setFocus:(E,R={})=>{const L=le(r,E),te=L&&L._f;if(te){const K=te.refs?te.refs[0]:te.ref;K.focus&&(K.focus(),R.shouldSelect&&Gt(K.select)&&K.select())}},getFieldState:G}}function Ox(e={}){const t=Se.useRef(void 0),n=Se.useRef(void 0),[r,i]=Se.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={...zx(e),formState:r});const s=t.current.control;return s._options=e,fa({subject:s._subjects.state,next:o=>{$d(o,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),Se.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),Se.useEffect(()=>{if(s._proxyFormState.isDirty){const o=s._getDirty();o!==r.isDirty&&s._subjects.state.next({isDirty:o})}},[s,r.isDirty]),Se.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]),Se.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),Se.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()}),Se.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=Md(r,s),t.current}function Px(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 Dx=gx,Wd=x.createContext({}),fl=({...e})=>u.jsx(Wd.Provider,{value:{name:e.name},children:u.jsx(vx,{...e})}),ws=()=>{const e=x.useContext(Wd),t=x.useContext(qd),{getFieldState:n,formState:r}=vs(),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}},qd=x.createContext({}),Io=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(qd.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:q("space-y-2",e),...t})})});Io.displayName="FormItem";const To=x.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=ws();return u.jsx(sr,{ref:n,className:q(r&&"text-destructive",e),htmlFor:i,...t})});To.displayName="FormLabel";const Ao=x.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=ws();return u.jsx(yr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Ao.displayName="FormControl";const Gd=x.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=ws();return u.jsx("p",{ref:n,id:r,className:q("text-muted-foreground text-[0.8rem]",e),...t})});Gd.displayName="FormDescription";const zo=x.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=ws(),o=i?String(i==null?void 0:i.message):t;return o?u.jsx("p",{ref:r,id:s,className:q("text-destructive text-[0.8rem] font-medium",e),...n,children:o}):null});zo.displayName="FormMessage";function ma(){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 Yd=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Rx=(e=Yd())=>nx()(rx(ix((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:ma(),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:sx(()=>Gg),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}}))),Kd=x.createContext(void 0),Mx=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Rx(Yd())),u.jsx(Kd.Provider,{value:t.current,children:e})},Re=e=>{const t=x.useContext(Kd);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return ox(t,e)};function $x(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Lx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=vi.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=vi.Optional(vi.String({description:"Template selection"})));const s=vi.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:o=>{const a=[];if(!ug(s,o))for(const c of cg(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 Fx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Bx=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 Zx({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}=vr(),g=Bx(o),{documents:v,openTabs:S,createDocument:b,renameDocument:j,deleteDocument:m,openDocument:T,closeDocument:C}=Pe(oe=>oe),{updateTheme:w,removeTheme:N}=Eo(oe=>oe),H=Re(oe=>oe.renameThreadsForDocument),O=Re(oe=>oe.deleteThreadsForDocument),_=x.useMemo(()=>o?s||[]:i||[],[o,i,s]),I=x.useMemo(()=>{const oe={current:[],downstream:[]};return _.forEach(G=>{oe[G.location]&&oe[G.location].push(G)}),oe},[_]),z=x.useMemo(()=>_.map(oe=>({name:oe.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[_]),M=x.useMemo(()=>Lx(e,oe=>$x(oe,v,r),z),[e,v,r,z]),A=M.schema,P=x.useMemo(()=>{const oe=new Map;return _.forEach(G=>oe.set(G.path,G)),oe},[_]),D=Zn,U=Ox({resolver:Px(M.validate),defaultValues:Fx(e,void 0,r)}),[$,X]=x.useState(D);x.useEffect(()=>{if($&&$!==Zn&&e==="create"){const oe=P.get($);if(oe){d(null),p("loading");let G=!1;return fetch(`/api/discovery/${o?"themes":"documents"}/${encodeURIComponent(oe.name)}/content`).then(y=>{if(!y.ok)throw new Error(`Failed to fetch content: ${y.statusText}`);return y.text()}).then(y=>{if(G)return;const Z=JSON.parse(y);d(JSON.stringify(Z,null,2)),p("idle")}).catch(y=>{G||(console.error("Failed to copy template:",y),d(null),p("error"))}),()=>{G=!0}}}p("idle")},[$,e,P,o]),x.useEffect(()=>{t&&(U.reset(),d(null),p("idle"),X(D))},[U,t]);const k=U.handleSubmit(async({name:oe,template:G})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=$?P.get($):_.find(ye=>ye.name===G);let Z,V=oe;if(!!$&&$!==Zn&&c===null){h({title:f==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:f==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(o){const ye=V.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),xe=ot==="docx"?dg(ye):{name:ye,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};Z=c||JSON.stringify(xe,null,2);const W=`.${ot}.theme.json`;V.endsWith(W)||(V=V.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),V+=W)}else{const ye=y;Z=c||JSON.stringify(ot==="docx"?{name:"docx",props:{theme:(ye==null?void 0:ye.theme)||"default",metadata:{title:(ye==null?void 0:ye.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:(ye==null?void 0:ye.title)||V.replace(/\.(json|js)$/i,""),theme:(ye==null?void 0:ye.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 xe=ot==="docx"?".docx.json":".pptx.json";!V.endsWith(xe)&&!V.endsWith(".json")&&(V+=xe)}const se=V.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),re=se?se[0]:"",de=V.slice(0,V.length-re.length);let ge=V,Ee=1;for(;v.some(ye=>ye.name===ge);)Ee++,ge=`${de} (${Ee})${re}`;V=ge,b(V,Z),T(V),o&&w(V,Z)}else if(e==="update"){const y=r,Z=oe,V=S.includes(y);V&&C(y),j(y,Z),H(y,Z),V&&T(Z)}else if(e==="delete"){const y=r;C(y),m(y),O(y),o&&N(y)}n()}finally{l(!1)}});return u.jsx(Dx,{...U,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:[A.properties&&"name"in A.properties&&u.jsx(fl,{control:U.control,name:"name",render:({field:oe})=>u.jsxs(Io,{children:[u.jsx(To,{children:"Name"}),u.jsx(Ao,{children:u.jsx(fi,{placeholder:"Enter a name or select a template below",autoComplete:"off",...oe})}),u.jsx(zo,{})]})}),e==="create"&&u.jsx(fl,{control:U.control,name:"template",render:({field:oe})=>u.jsxs(Io,{children:[u.jsx(To,{children:o?"Base Theme":"Base Document"}),u.jsxs(qr,{onValueChange:G=>{if(G===Zn)oe.onChange(void 0),U.setValue("name",""),X(Zn),d(null);else{const y=P.get(G);y&&(oe.onChange(y.name),U.setValue("name",y.name),X(G))}},defaultValue:D,children:[u.jsx(Ao,{children:u.jsx(cr,{children:u.jsx(Gr,{placeholder:`Select a discovered ${o?"theme":"document"}`})})}),u.jsxs(dr,{className:"max-h-[300px]",children:[u.jsxs(Dn,{value:Zn,children:["Empty ",o?"theme":"document"]}),Object.entries(I).map(([G,y])=>y.length===0?null:u.jsxs(ux,{children:[u.jsx(Ad,{children:G==="current"?"📁 Current Directory":"📦 Project"}),y.map(Z=>{let V;return Z.title&&Z.title!==Z.name?V=Z.title:Z.description&&(V=Z.description.length>40?Z.description.substring(0,40)+"...":Z.description),u.jsx(Dn,{value:Z.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:Z.name}),V&&u.jsx("span",{className:"text-muted-foreground text-xs",children:V})]})},Z.path)})]},G))]})]}),u.jsxs(Gd,{children:["Start empty or select a discovered"," ",o?"theme":"document"," as a starting point"]}),u.jsx(zo,{})]})})]}),u.jsx(yn,{children:u.jsx(Ne,{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 Hi=Se.memo(Zx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function ga({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 Oo({children:e,count:t,actions:n,className:r}){return u.jsxs("div",{className:q("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=Se.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:q("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 pl({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:q("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function hl({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:q("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 Vx=Wm,Ux=qm,Jx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(Wc,{ref:i,className:q("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"})]}));Jx.displayName=Wc.displayName;const Hx=x.forwardRef(({className:e,...t},n)=>u.jsx(qc,{ref:n,className:q("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}));Hx.displayName=qc.displayName;const Xd=x.forwardRef(({className:e,...t},n)=>u.jsx(Gm,{children:u.jsx(Uc,{ref:n,className:q("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})}));Xd.displayName=Uc.displayName;const Qd=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Hc,{ref:r,className:q("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}));Qd.displayName=Hc.displayName;const Wx=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Gc,{ref:i,className:q("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(Yc,{children:u.jsx(bn,{className:"h-4 w-4"})})}),t]}));Wx.displayName=Gc.displayName;const qx=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Kc,{ref:r,className:q("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(Yc,{children:u.jsx(bd,{className:"h-4 w-4 fill-current"})})}),t]}));qx.displayName=Kc.displayName;const Gx=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Xc,{ref:r,className:q("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Gx.displayName=Xc.displayName;const ef=x.forwardRef(({className:e,...t},n)=>u.jsx(Jc,{ref:n,className:q("bg-border -mx-1 my-1 h-px",e),...t}));ef.displayName=Jc.displayName;const tf=({className:e,...t})=>u.jsx("span",{className:q("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});tf.displayName="ContextMenuShortcut";const ks=Ym,Ss=Km,Yx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(rd,{ref:i,className:q("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"})]}));Yx.displayName=rd.displayName;const Kx=x.forwardRef(({className:e,...t},n)=>u.jsx(id,{ref:n,className:q("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));Kx.displayName=id.displayName;const hi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Xm,{children:u.jsx(Qc,{ref:r,sideOffset:t,className:q("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})}));hi.displayName=Qc.displayName;const Lt=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ed,{ref:r,className:q("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}));Lt.displayName=ed.displayName;const Xx=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(sd,{ref:i,className:q("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(od,{children:u.jsx(bn,{className:"h-4 w-4"})})}),t]}));Xx.displayName=sd.displayName;const Qx=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ad,{ref:r,className:q("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(od,{children:u.jsx(bd,{className:"h-2 w-2 fill-current"})})}),t]}));Qx.displayName=ad.displayName;const nf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(nd,{ref:r,className:q("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));nf.displayName=nd.displayName;const fr=x.forwardRef(({className:e,...t},n)=>u.jsx(td,{ref:n,className:q("bg-muted -mx-1 my-1 h-px",e),...t}));fr.displayName=td.displayName;const rf=({className:e,...t})=>u.jsx("span",{className:q("ml-auto text-xs tracking-widest opacity-60",e),...t});rf.displayName="DropdownMenuShortcut";const sf=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(ld,{ref:i,decorative:n,orientation:t,className:q("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));sf.displayName=ld.displayName;const of=Pc,eb=Qm,tb=Dc,af=x.forwardRef(({className:e,...t},n)=>u.jsx(xs,{className:q("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t,ref:n}));af.displayName=xs.displayName;const nb=di("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"}}),xa=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(tb,{children:[u.jsx(af,{}),u.jsxs(hs,{ref:i,className:q(nb({side:e}),t),...r,children:[u.jsxs(aa,{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]})]}));xa.displayName=hs.displayName;const rb=x.forwardRef(({className:e,...t},n)=>u.jsx(ms,{ref:n,className:q("text-foreground text-lg font-semibold",e),...t}));rb.displayName=ms.displayName;const ib=x.forwardRef(({className:e,...t},n)=>u.jsx(gs,{ref:n,className:q("text-muted-foreground text-sm",e),...t}));ib.displayName=gs.displayName;function Ur({className:e,...t}){return u.jsx("div",{className:q("bg-primary/10 animate-pulse rounded-md",e),...t})}const Vs=768,Us=1200;function lf(e){return typeof window<"u"?window.innerWidth<e:!1}function uf(){const[e,t]=x.useState(()=>lf(Vs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Vs-1}px)`),r=()=>{t(window.innerWidth<Vs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function sb(){const[e,t]=x.useState(()=>lf(Us));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Us-1}px)`),r=()=>{t(window.innerWidth<Us)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const ob="sidebar_state",ab=60*60*24*7,lb="16rem",ub="18rem",cb="3rem",db="b",cf=x.createContext(null);function _s(){const e=x.useContext(cf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const df=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...o},a)=>{const l=uf(),[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=`${ob}=${m}; path=/; max-age=${ab}`},[n,h]),v=x.useCallback(()=>l?d(j=>!j):g(j=>!j),[l,g,d]);x.useEffect(()=>{const j=T=>{var N;const C=T;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=T=>{const C=T.metaKey||T.ctrlKey,w=T.key.toLowerCase();if(C&&w===db){T.preventDefault(),v();return}C&&w==="s"&&!j(T.target)&&(T.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const S=h?"expanded":"collapsed",b=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(cf.Provider,{value:b,children:u.jsx(fg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":lb,"--sidebar-width-icon":cb,...i},className:q("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:a,...o,children:s})})})});df.displayName="SidebarProvider";const ff=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}=_s();return n==="none"?u.jsx("div",{className:q("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:o,...s,children:i}):a?u.jsx(of,{open:c,onOpenChange:d,...s,children:u.jsx(xa,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":ub},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:q("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:q("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})})]})});ff.displayName="Sidebar";const fb=x.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=_s();return u.jsxs(Ne,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:q("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(yg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});fb.displayName="SidebarTrigger";const pb=x.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=_s();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:q("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})});pb.displayName="SidebarRail";const hb=x.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:q("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}));hb.displayName="SidebarInset";const mb=x.forwardRef(({className:e,...t},n)=>u.jsx(fi,{ref:n,"data-sidebar":"input",className:q("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));mb.displayName="SidebarInput";const Po=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:q("flex flex-col gap-2 p-2",e),...t}));Po.displayName="SidebarHeader";const pf=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:q("flex flex-col gap-2 p-2",e),...t}));pf.displayName="SidebarFooter";const gb=x.forwardRef(({className:e,...t},n)=>u.jsx(sf,{ref:n,"data-sidebar":"separator",className:q("bg-sidebar-border mx-2 w-auto",e),...t}));gb.displayName="SidebarSeparator";const Do=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:q("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Do.displayName="SidebarContent";const xb=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:q("relative flex w-full min-w-0 flex-col p-2",e),...t}));xb.displayName="SidebarGroup";const bb=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?yr:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:q("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})});bb.displayName="SidebarGroupLabel";const yb=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?yr:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:q("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})});yb.displayName="SidebarGroupAction";const vb=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:q("w-full text-sm",e),...t}));vb.displayName="SidebarGroupContent";const Dr=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:q("flex w-full min-w-0 flex-col gap-1",e),...t}));Dr.displayName="SidebarMenu";const hf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:q("group/menu-item relative",e),...t}));hf.displayName="SidebarMenuItem";const wb=di("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"}}),mf=x.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...o},a)=>{const l=e?yr:"button",{isMobile:c,state:d}=_s(),f=u.jsx(l,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:q(wb({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});mf.displayName="SidebarMenuButton";const gf=x.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?yr:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:q("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})});gf.displayName="SidebarMenuAction";const kb=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:q("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}));kb.displayName="SidebarMenuBadge";const Sb=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:q("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Ur,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Ur,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Sb.displayName="SidebarMenuSkeleton";const _b=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:q("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}));_b.displayName="SidebarMenuSub";const jb=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));jb.displayName="SidebarMenuSubItem";const Nb=x.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const o=e?yr:"a";return u.jsx(o,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:q("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})});Nb.displayName="SidebarMenuSubButton";function Mi(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 Eb=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Cb({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=Pe(G=>G.openDocument),h=Pe(G=>G.documentTypes),g=Pe(G=>G.activeTab),v=rn(G=>G.name),S=rn(G=>G.text),b=rn(G=>G.isGenerating),m=(h[e.name]||"application/json+report")==="application/json+theme",T=g===e.name,[C,w]=x.useState(v),[N,H]=x.useState(S),O=100,_=0;x.useEffect(()=>{const G=setTimeout(()=>{v&&S?(w(v),H(S)):b||(w(""),H(""))},b?O:_);return()=>clearTimeout(G)},[v,S,b]);const I=C===e.name,z=G=>{var Z;const y=new Set;try{const V=JSON.parse(G);(Z=V.props)!=null&&Z.theme&&y.add(V.props.theme),V.children&&Array.isArray(V.children)&&V.children.forEach(ie=>{var se;ie.name==="docx"&&((se=ie.props)!=null&&se.theme)&&y.add(ie.props.theme)})}catch{}return y},M=x.useMemo(()=>{if(!m||!N)return!1;try{const G=JSON.parse(e.text),y=Yg(G);if(y)return z(N).has(y)}catch{}return!1},[m,N,e.text]),A=x.useCallback(()=>{c(!1)},[]),P=x.useCallback(()=>{f(!1)},[]),D=T?null:I?"preview":M?"in-use":null,U=T?"Editing":I?"In preview":M?"Used by preview":null,$=x.useMemo(()=>[{key:"open",label:"Open",shortcut:Eb?"⌘⏎":"⌃⏎",run:()=>p(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Mi(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]),X=m?vg:yd,k=i||o,oe=u.jsxs(mf,{size:"sm",ref:r,"aria-label":U?`${e.name} — ${U}`:e.name,className:q("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",T&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:U?`${e.name} — ${U}`:e.name,onClick:()=>{p(e.name)},onKeyDown:G=>{var y;(G.ctrlKey||G.metaKey)&&G.key==="Enter"?(p(e.name),G.preventDefault()):G.key==="Enter"?(c(!0),G.preventDefault()):G.key==="Backspace"||G.key==="Delete"?(f(!0),G.preventDefault()):G.key==="Escape"&&((y=r.current)==null||y.blur(),G.preventDefault())},children:[T&&u.jsx("span",{"aria-hidden":!0,className:q("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(X,{className:q("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",T&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(ga,{text:e.name,query:n})}),t&&D&&u.jsx(pl,{tone:D,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(hf,{children:[u.jsxs(Vx,{onOpenChange:s,children:[u.jsx(Ux,{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:U??(m?"Theme":"Document")})]})})]}):oe}),u.jsx(Xd,{className:"w-44",children:$.map(G=>u.jsxs(Se.Fragment,{children:[G.separatorBefore&&u.jsx(ef,{}),u.jsxs(Qd,{onClick:G.run,className:q(G.danger&&"text-destructive focus:text-destructive"),children:[G.label,G.shortcut&&u.jsx(tf,{children:G.shortcut})]})]},G.key))})]}),!t&&u.jsxs(u.Fragment,{children:[D&&u.jsx(pl,{tone:D,className:q("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(ks,{onOpenChange:a,children:[u.jsx(Ss,{asChild:!0,children:u.jsx(gf,{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(vd,{})})}),u.jsx(hi,{side:"right",align:"start",className:"w-44",children:$.map(G=>u.jsxs(Se.Fragment,{children:[G.separatorBefore&&u.jsx(fr,{}),u.jsxs(Lt,{onClick:G.run,className:q(G.danger&&"text-destructive focus:text-destructive"),children:[G.label,G.shortcut&&u.jsx(rf,{children:G.shortcut})]})]},G.key))})]})]}),u.jsx(Ct,{open:l,onOpenChange:c,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:G=>{var y;G.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Hi,{mode:"update",shouldReset:!l,postSubmit:A,selectedName:e.name})})}),u.jsx(Ct,{open:d,onOpenChange:f,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:G=>{var y;G.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Hi,{mode:"delete",shouldReset:!d,postSubmit:P,selectedName:e.name})})})]})}const Si=Se.memo(Cb);function Ib(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,T){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 T=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++;T=r}else f=3;return e.substring(m,T)}function v(){let m="",T=r;for(;;){if(r>=n){m+=e.substring(T,r),f=2;break}const C=e.charCodeAt(r);if(C===34){m+=e.substring(T,r),r++;break}if(C===92){if(m+=e.substring(T,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-sQA3rPOP.js","assets/react-vendor-CTFDOf2G.js","assets/editor-monaco-json-5MnjNhYy.js","assets/index-CkyZoRBe.js","assets/query-vendor-Df8-oete.js","assets/radix-ui-Bq-7y_Sq.js","assets/ui-vendor-Cs3OXpi7.js","assets/monaco-editor-BcgxPCqT.js","assets/state-vendor-ByFYl9bq.js","assets/index-C9ply7vX.css","assets/editor-refs-store-DLWwmGGm.js","assets/MonacoPluginProvider-DS8Ov7V6.js","assets/preview-CisNYRaE.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Mm=Object.defineProperty;var $m=(e,t,n)=>t in e?Mm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Xa=(e,t,n)=>$m(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as u,c as Se,R as Oc,g as oa}from"./react-vendor-CTFDOf2G.js";import{b as Pc,c as aa,d as Dc,e as hs,f as ms,D as gs,O as xs,g as Lm,V as Fm,h as Rc,I as Bm,i as Zm,j as Mc,k as Vm,l as $c,m as Um,n as Jm,G as Hm,S as Lc,o as Fc,L as Bc,p as Zc,q as Vc,r as yr,s as Wm,t as qm,u as Gm,v as Uc,w as Jc,x as Hc,y as Wc,z as qc,B as Gc,E as Yc,F as Kc,H as Xc,J as Ym,K as Km,M as Xm,N as Qc,Q as ed,U as td,W as nd,X as rd,Y as id,Z as sd,_ as od,$ as ad,a0 as ld,a1 as Qm,a2 as ud,a3 as eg,a4 as tg,a5 as cd,a6 as ng,a7 as rg,a8 as ig,a9 as sg,aa as og,ab as ag,ac as lg,ad as dd,ae as fd,af as pd}from"./radix-ui-Bq-7y_Sq.js";import{c as q,u as vr,S as sn,A as hd,T as vi,C as ug,E as cg,F as ot,a as dg,b as fg,d as qe,e as Ge,f as Ye,g as md,_ as gd,h as wi,i as pg,j as hg,k as mg,l as jr,s as Ls,m as Di,W as gg}from"./index-CkyZoRBe.js";import{X as xn,C as ci,a as bn,b as xg,d as di,G as xd,F as bg,e as Pn,f as bd,P as yg,g as vg,h as yd,E as vd,B as wo,H as wg,T as ko,L as Qa,i as kg,j as Sg,S as wd,I as _g,k as jg,l as So,m as Ng,n as Eg,o as Cg,p as Ig,q as Tg,r as Ag,s as zg,t as Og,u as bs,v as Pg,M as Dg,w as kd,x as nn,y as Rg,z as Mg,A as Sd,D as $g,J as Lg,K as Fg,N as Bg,R as Zg,O as Vg,Q as _d,U as Ug,V as _o,W as la,Y as jd,Z as Jg,_ as Nd,$ as jo,a0 as Hg,a1 as Wg,a2 as el,a3 as No}from"./ui-vendor-Cs3OXpi7.js";import{B as Ne,u as qg,d as tl}from"./editor-refs-store-DLWwmGGm.js";import{u as Pe,i as Gg,a as Eo,b as rn,g as Yg,c as Bt,T as Ed,d as ki,S as Kg,O as Xg,e as Qg,M as ex,D as tx}from"./MonacoPluginProvider-DS8Ov7V6.js";import{u as ua,a as nx,d as rx,p as ix,b as sx,e as ox}from"./state-vendor-ByFYl9bq.js";import{b as ax}from"./query-vendor-Df8-oete.js";const Ct=Pc,lx=Dc,nl=aa,Cd=x.forwardRef(({className:e,...t},n)=>u.jsx(xs,{ref:n,className:q("fixed inset-0 z-50 bg-black/50",e),...t}));Cd.displayName=xs.displayName;const kt=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(lx,{children:[u.jsx(Cd,{}),u.jsxs(hs,{ref:r,className:q("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(aa,{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=hs.displayName;const Ut=({className:e,...t})=>u.jsx("div",{className:q("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});Ut.displayName="DialogHeader";const yn=({className:e,...t})=>u.jsx("div",{className:q("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});yn.displayName="DialogFooter";const Jt=x.forwardRef(({className:e,...t},n)=>u.jsx(ms,{ref:n,className:q("text-lg leading-none font-semibold tracking-tight",e),...t}));Jt.displayName=ms.displayName;const an=x.forwardRef(({className:e,...t},n)=>u.jsx(gs,{ref:n,className:q("text-muted-foreground text-sm",e),...t}));an.displayName=gs.displayName;const qr=Lm,ux=Hm,Gr=Fm,cr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Rc,{ref:r,className:q("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(Bm,{asChild:!0,children:u.jsx(ci,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));cr.displayName=Rc.displayName;const Id=x.forwardRef(({className:e,...t},n)=>u.jsx(Lc,{ref:n,className:q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(xg,{className:"h-4 w-4"})}));Id.displayName=Lc.displayName;const Td=x.forwardRef(({className:e,...t},n)=>u.jsx(Fc,{ref:n,className:q("flex cursor-default items-center justify-center py-1",e),...t,children:u.jsx(ci,{className:"h-4 w-4"})}));Td.displayName=Fc.displayName;const dr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>u.jsx(Zm,{children:u.jsxs(Mc,{ref:i,className:q("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(Id,{}),u.jsx(Vm,{className:q("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),u.jsx(Td,{})]})}));dr.displayName=Mc.displayName;const Ad=x.forwardRef(({className:e,...t},n)=>u.jsx(Bc,{ref:n,className:q("px-2 py-1.5 text-sm font-semibold",e),...t}));Ad.displayName=Bc.displayName;const Dn=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs($c,{ref:r,className:q("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(Um,{children:u.jsx(bn,{className:"h-4 w-4"})})}),u.jsx(Jm,{children:t})]}));Dn.displayName=$c.displayName;const cx=x.forwardRef(({className:e,...t},n)=>u.jsx(Zc,{ref:n,className:q("bg-muted -mx-1 my-1 h-px",e),...t}));cx.displayName=Zc.displayName;const fi=x.forwardRef(({className:e,type:t,...n},r)=>u.jsx("input",{type:t,className:q("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}));fi.displayName="Input";const dx=di("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),sr=x.forwardRef(({className:e,...t},n)=>u.jsx(Vc,{ref:n,className:q(dx(),e),...t}));sr.displayName=Vc.displayName;const fx=di("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:q(fx({variant:t}),e),...n})}const px=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:o}=Pe(ua(I=>({documents:I.documents,documentTypes:I.documentTypes,activeTab:I.activeTab,createDocument:I.createDocument,openDocument:I.openDocument}))),{toast:a}=vr(),l=x.useMemo(()=>n.filter(I=>r[I.name]!=="application/json+theme"),[n,r]),[c,d]=x.useState(""),[f,p]=x.useState(""),[h,g]=x.useState("playground"),[v,S]=x.useState(!1),[b,j]=x.useState(null),[m,T]=x.useState(null),[C,w]=x.useState(null),N=()=>{j(null),T(null),w(null)};x.useEffect(()=>{if(!e)return;j(null),T(null),w(null);const I=l.map(M=>M.name),z=I.includes(i)?i:I[0]??"";p(z),d(I.find(M=>M!==z)??"")},[e]);const H=async()=>{const I=l.find(M=>M.name===c),z=l.find(M=>M.name===f);if(!(!I||!z)){S(!0),j(null),T(null),w(null);try{const M=await fetch(hd.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:I.text,newDefinition:z.text,options:{author:h||"playground"}})}),A=await M.json();if(!M.ok||!A.success){const P=Array.isArray(A.errors)?`: ${A.errors.slice(0,3).map(D=>D.message||String(D)).join("; ")}`:"";throw new Error((A.error||`Diff failed (${M.status})`)+P)}T(A.data.summary),w(A.data.document)}catch(M){j(M instanceof Error?M.message:"Diff failed")}finally{S(!1)}}},O=()=>{if(!C)return;const I=new Set(n.map(A=>A.name));let z=`${f}-redline`,M=2;for(;I.has(z);)z=`${f}-redline-${M++}`;s(z,JSON.stringify(C,null,2)),o(z),a({title:`Redline created: ${z}`}),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(xd,{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(qr,{value:c,onValueChange:I=>{d(I),N()},children:[u.jsx(cr,{id:"diff-base",children:u.jsx(Gr,{placeholder:"Select document"})}),u.jsx(dr,{children:l.map(I=>u.jsx(Dn,{value:I.name,children:I.name},I.name))})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-revised",children:"Revised (new)"}),u.jsxs(qr,{value:f,onValueChange:I=>{p(I),N()},children:[u.jsx(cr,{id:"diff-revised",children:u.jsx(Gr,{placeholder:"Select document"})}),u.jsx(dr,{children:l.map(I=>u.jsx(Dn,{value:I.name,children:I.name},I.name))})]})]})]}),u.jsxs("div",{className:"grid gap-1.5",children:[u.jsx(sr,{htmlFor:"diff-author",children:"Revision author"}),u.jsx(fi,{id:"diff-author",value:h,onChange:I=>{g(I.target.value),N()},placeholder:"playground"})]}),b&&u.jsx("p",{className:"text-sm text-destructive",role:"alert",children:b}),m&&u.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[u.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u.jsxs(Kt,{variant:"secondary",children:[m.tracked.inserted," inserted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.deleted," deleted"]}),u.jsxs(Kt,{variant:"secondary",children:[m.tracked.modified," modified"]}),u.jsxs("span",{className:"text-muted-foreground text-xs",children:[m.unchangedBlocks," blocks unchanged"]})]}),_===0&&m.untracked.length===0&&u.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),m.untracked.length>0&&u.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[u.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[m.untracked.length," change(s) not expressible as tracked changes:"]}),m.untracked.map((I,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:[I.path," [",I.component,"] ",I.detail]},z))]}),m.notes.map((I,z)=>u.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",I]},z))]})]}),u.jsx(yn,{children:m&&_+m.untracked.length>0?u.jsxs(Ne,{onClick:O,children:[u.jsx(bg,{className:"size-4 mr-1"}),"Open redline"]}):u.jsxs(Ne,{onClick:H,disabled:v||!c||!f||c===f,children:[v&&u.jsx(sn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var pi=e=>e.type==="checkbox",Tn=e=>e instanceof Date,pt=e=>e==null;const zd=e=>typeof e=="object";var et=e=>!pt(e)&&!Array.isArray(e)&&zd(e)&&!Tn(e),Od=e=>et(e)&&e.target?pi(e.target)?e.target.checked:e.target.value:e,hx=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,Pd=(e,t)=>e.has(hx(t)),mx=e=>{const t=e.constructor&&e.constructor.prototype;return et(t)&&t.hasOwnProperty("isPrototypeOf")},ca=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function bt(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(!(ca&&(e instanceof Blob||r))&&(n||et(e)))if(t=n?[]:{},!n&&!mx(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=bt(e[i]));else return e;return t}var ys=e=>Array.isArray(e)?e.filter(Boolean):[],Qe=e=>e===void 0,le=(e,t,n)=>{if(!t||!et(e))return n;const r=ys(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",da=e=>/^\w*$/.test(e),Dd=e=>ys(e.replace(/["|']|\]/g,"").split(/\.|\[/)),$e=(e,t,n)=>{let r=-1;const i=da(t)?[t]:Dd(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 Zi={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ft={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},tn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},Rd=Se.createContext(null),vs=()=>Se.useContext(Rd),gx=e=>{const{children:t,...n}=e;return Se.createElement(Rd.Provider,{value:n},t)};var Md=(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]!==Ft.all&&(t._proxyFormState[o]=!r||Ft.all),n&&(n[o]=!0),e[o]}});return i},yt=e=>et(e)&&!Object.keys(e).length,$d=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return yt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(o=>t[o]===(!r||Ft.all))},Zr=e=>Array.isArray(e)?e:[e],Ld=(e,t,n)=>!e||!t||e===t||Zr(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function fa(e){const t=Se.useRef(e);t.current=e,Se.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function xx(e){const t=vs(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[o,a]=Se.useState(n._formState),l=Se.useRef(!0),c=Se.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=Se.useRef(i);return d.current=i,fa({disabled:r,next:f=>l.current&&Ld(d.current,f.name,s)&&$d(f,c.current,n._updateFormState)&&a({...n._formState,...f}),subject:n._subjects.state}),Se.useEffect(()=>(l.current=!0,c.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),Se.useMemo(()=>Md(o,n,c.current,!1),[o,n])}var Yt=e=>typeof e=="string",Fd=(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 bx(e){const t=vs(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:o}=e||{},a=Se.useRef(r);a.current=r,fa({disabled:s,subject:n._subjects.values,next:d=>{Ld(a.current,d.name,o)&&c(bt(Fd(a.current,n._names,d.values||n._formValues,!1,i)))}});const[l,c]=Se.useState(n._getWatch(r,i));return Se.useEffect(()=>n._removeUnmounted()),l}function yx(e){const t=vs(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,o=Pd(i._names.array,n),a=bx({control:i,name:n,defaultValue:le(i._formValues,n,le(i._defaultValues,n,e.defaultValue)),exact:!0}),l=xx({control:i,name:n,exact:!0}),c=Se.useRef(i.register(n,{...e.rules,value:a,...zt(e.disabled)?{disabled:e.disabled}:{}})),d=Se.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=Se.useMemo(()=>({name:n,value:a,...zt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:p=>c.current.onChange({target:{value:Od(p),name:n},type:Zi.CHANGE}),onBlur:()=>c.current.onBlur({target:{value:le(i._formValues,n),name:n},type:Zi.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 Se.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=bt(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]),Se.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),Se.useMemo(()=>({field:f,formState:l,fieldState:d}),[f,l,d])}const vx=e=>e.render(yx(e));var wx=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},rl=e=>({isOnSubmit:!e||e===Ft.onSubmit,isOnBlur:e===Ft.onBlur,isOnChange:e===Ft.onChange,isOnAll:e===Ft.all,isOnTouch:e===Ft.onTouched}),il=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const Vr=(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(Vr(a,t))break}else if(et(a)&&Vr(a,t))break}}};var kx=(e,t,n)=>{const r=Zr(le(e,n));return $e(r,"root",t[n]),$e(e,n,r),e},pa=e=>e.type==="file",Gt=e=>typeof e=="function",Vi=e=>{if(!ca)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Ri=e=>Yt(e),ha=e=>e.type==="radio",Ui=e=>e instanceof RegExp;const sl={value:!1,isValid:!1},ol={value:!0,isValid:!0};var Bd=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===""?ol:{value:e[0].value,isValid:!0}:ol:sl}return sl};const al={isValid:!1,value:null};var Zd=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,al):al;function ll(e,t,n="validate"){if(Ri(e)||Array.isArray(e)&&e.every(Ri)||zt(e)&&!e)return{type:n,message:Ri(e)?e:"",ref:t}}var Bn=e=>et(e)&&!Ui(e)?e:{value:e,message:""},ul=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:b}=e._f,j=le(n,v);if(!b||t.has(v))return{};const m=a?a[0]:o,T=z=>{i&&m.reportValidity&&(m.setCustomValidity(zt(z)?"":z||""),m.reportValidity())},C={},w=ha(o),N=pi(o),H=w||N,O=(S||pa(o))&&Qe(o.value)&&Qe(j)||Vi(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,_=wx.bind(null,v,r,C),I=(z,M,A,P=tn.maxLength,D=tn.minLength)=>{const U=z?M:A;C[v]={type:z?P:D,message:U,ref:o,..._(z?P:D,U)}};if(s?!Array.isArray(j)||!j.length:l&&(!H&&(O||pt(j))||zt(j)&&!j||N&&!Bd(a).isValid||w&&!Zd(a).isValid)){const{value:z,message:M}=Ri(l)?{value:!!l,message:l}:Bn(l);if(z&&(C[v]={type:tn.required,message:M,ref:m,..._(tn.required,M)},!r))return T(M),C}if(!O&&(!pt(f)||!pt(p))){let z,M;const A=Bn(p),P=Bn(f);if(!pt(j)&&!isNaN(j)){const D=o.valueAsNumber||j&&+j;pt(A.value)||(z=D>A.value),pt(P.value)||(M=D<P.value)}else{const D=o.valueAsDate||new Date(j),U=k=>new Date(new Date().toDateString()+" "+k),$=o.type=="time",X=o.type=="week";Yt(A.value)&&j&&(z=$?U(j)>U(A.value):X?j>A.value:D>new Date(A.value)),Yt(P.value)&&j&&(M=$?U(j)<U(P.value):X?j<P.value:D<new Date(P.value))}if((z||M)&&(I(!!z,A.message,P.message,tn.max,tn.min),!r))return T(C[v].message),C}if((c||d)&&!O&&(Yt(j)||s&&Array.isArray(j))){const z=Bn(c),M=Bn(d),A=!pt(z.value)&&j.length>+z.value,P=!pt(M.value)&&j.length<+M.value;if((A||P)&&(I(A,z.message,M.message),!r))return T(C[v].message),C}if(h&&!O&&Yt(j)){const{value:z,message:M}=Bn(h);if(Ui(z)&&!j.match(z)&&(C[v]={type:tn.pattern,message:M,ref:o,..._(tn.pattern,M)},!r))return T(M),C}if(g){if(Gt(g)){const z=await g(j,n),M=ll(z,m);if(M&&(C[v]={...M,..._(tn.validate,M.message)},!r))return T(M.message),C}else if(et(g)){let z={};for(const M in g){if(!yt(z)&&!r)break;const A=ll(await g[M](j,n),m,M);A&&(z={...A,..._(M,A.message)},T(A.message),r&&(C[v]=z))}if(!yt(z)&&(C[v]={ref:m,...z},!r))return C}}return T(!0),C};function Sx(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 _x(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:da(t)?[t]:Dd(t),r=n.length===1?e:Sx(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(et(r)&&yt(r)||Array.isArray(r)&&_x(r))&&it(e,n.slice(0,-1)),e}var Fs=()=>{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=[]}}},Co=e=>pt(e)||!zd(e);function hn(e,t){if(Co(e)||Co(t))return e===t;if(Tn(e)&&Tn(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(Tn(s)&&Tn(o)||et(s)&&et(o)||Array.isArray(s)&&Array.isArray(o)?!hn(s,o):s!==o)return!1}}return!0}var Vd=e=>e.type==="select-multiple",jx=e=>ha(e)||pi(e),Bs=e=>Vi(e)&&e.isConnected,Ud=e=>{for(const t in e)if(Gt(e[t]))return!0;return!1};function Ji(e,t={}){const n=Array.isArray(e);if(et(e)||n)for(const r in e)Array.isArray(e[r])||et(e[r])&&!Ud(e[r])?(t[r]=Array.isArray(e[r])?[]:{},Ji(e[r],t[r])):pt(e[r])||(t[r]=!0);return t}function Jd(e,t,n){const r=Array.isArray(e);if(et(e)||r)for(const i in e)Array.isArray(e[i])||et(e[i])&&!Ud(e[i])?Qe(t)||Co(n[i])?n[i]=Array.isArray(e[i])?Ji(e[i],[]):{...Ji(e[i])}:Jd(e[i],pt(t)?{}:t[i],n[i]):n[i]=!hn(e[i],t[i]);return n}var Nr=(e,t)=>Jd(e,t,Ji(t)),Hd=(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 Zs(e){const t=e.ref;return pa(t)?t.files:ha(t)?Zd(e.refs).value:Vd(t)?[...t.selectedOptions].map(({value:n})=>n):pi(t)?Bd(e.refs).value:Hd(Qe(t.value)?e.ref.value:t.value,e)}var Nx=(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}},Er=e=>Qe(e)?e:Ui(e)?e.source:et(e)?Ui(e.value)?e.value.source:e.value:e;const cl="AsyncFunction";var Ex=e=>!!e&&!!e.validate&&!!(Gt(e.validate)&&e.validate.constructor.name===cl||et(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===cl)),Cx=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function dl(e,t,n){const r=le(e,n);if(r||da(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 Ix=(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,Tx=(e,t)=>!ys(le(e,t)).length&&it(e,t);const Ax={mode:Ft.onSubmit,reValidateMode:Ft.onChange,shouldFocusError:!0};function zx(e={}){let t={...Ax,...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)?bt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:bt(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:Fs(),array:Fs(),state:Fs()},p=rl(t.mode),h=rl(t.reValidateMode),g=t.criteriaMode===Ft.all,v=E=>R=>{clearTimeout(c),c=setTimeout(E,R)},S=async E=>{if(!t.disabled&&(d.isValid||E)){const R=t.resolver?yt((await H()).errors):await _(r,!0);R!==n.isValid&&f.state.next({isValid:R})}},b=(E,R)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((E||Array.from(a.mount)).forEach(L=>{L&&(R?$e(n.validatingFields,L,R):it(n.validatingFields,L))}),f.state.next({validatingFields:n.validatingFields,isValidating:!yt(n.validatingFields)}))},j=(E,R=[],L,te,K=!0,ee=!0)=>{if(te&&L&&!t.disabled){if(o.action=!0,ee&&Array.isArray(le(r,E))){const ue=L(le(r,E),te.argA,te.argB);K&&$e(r,E,ue)}if(ee&&Array.isArray(le(n.errors,E))){const ue=L(le(n.errors,E),te.argA,te.argB);K&&$e(n.errors,E,ue),Tx(n.errors,E)}if(d.touchedFields&&ee&&Array.isArray(le(n.touchedFields,E))){const ue=L(le(n.touchedFields,E),te.argA,te.argB);K&&$e(n.touchedFields,E,ue)}d.dirtyFields&&(n.dirtyFields=Nr(i,s)),f.state.next({name:E,isDirty:z(E,R),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else $e(s,E,R)},m=(E,R)=>{$e(n.errors,E,R),f.state.next({errors:n.errors})},T=E=>{n.errors=E,f.state.next({errors:n.errors,isValid:!1})},C=(E,R,L,te)=>{const K=le(r,E);if(K){const ee=le(s,E,Qe(L)?le(i,E):L);Qe(ee)||te&&te.defaultChecked||R?$e(s,E,R?ee:Zs(K._f)):P(E,ee),o.mount&&S()}},w=(E,R,L,te,K)=>{let ee=!1,ue=!1;const be={name:E};if(!t.disabled){const B=!!(le(r,E)&&le(r,E)._f&&le(r,E)._f.disabled);if(!L||te){d.isDirty&&(ue=n.isDirty,n.isDirty=be.isDirty=z(),ee=ue!==be.isDirty);const Y=B||hn(le(i,E),R);ue=!!(!B&&le(n.dirtyFields,E)),Y||B?it(n.dirtyFields,E):$e(n.dirtyFields,E,!0),be.dirtyFields=n.dirtyFields,ee=ee||d.dirtyFields&&ue!==!Y}if(L){const Y=le(n.touchedFields,E);Y||($e(n.touchedFields,E,L),be.touchedFields=n.touchedFields,ee=ee||d.touchedFields&&Y!==L)}ee&&K&&f.state.next(be)}return ee?be:{}},N=(E,R,L,te)=>{const K=le(n.errors,E),ee=d.isValid&&zt(R)&&n.isValid!==R;if(t.delayError&&L?(l=v(()=>m(E,L)),l(t.delayError)):(clearTimeout(c),l=null,L?$e(n.errors,E,L):it(n.errors,E)),(L?!hn(K,L):K)||!yt(te)||ee){const ue={...te,...ee&&zt(R)?{isValid:R}:{},errors:n.errors,name:E};n={...n,...ue},f.state.next(ue)}},H=async E=>{b(E,!0);const R=await t.resolver(s,t.context,Nx(E||a.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return b(E),R},O=async E=>{const{errors:R}=await H(E);if(E)for(const L of E){const te=le(R,L);te?$e(n.errors,L,te):it(n.errors,L)}else n.errors=R;return R},_=async(E,R,L={valid:!0})=>{for(const te in E){const K=E[te];if(K){const{_f:ee,...ue}=K;if(ee){const be=a.array.has(ee.name),B=K._f&&Ex(K._f);B&&d.validatingFields&&b([te],!0);const Y=await ul(K,a.disabled,s,g,t.shouldUseNativeValidation&&!R,be);if(B&&d.validatingFields&&b([te]),Y[ee.name]&&(L.valid=!1,R))break;!R&&(le(Y,ee.name)?be?kx(n.errors,Y,ee.name):$e(n.errors,ee.name,Y[ee.name]):it(n.errors,ee.name))}!yt(ue)&&await _(ue,R,L)}}return L.valid},I=()=>{for(const E of a.unMount){const R=le(r,E);R&&(R._f.refs?R._f.refs.every(L=>!Bs(L)):!Bs(R._f.ref))&&ie(E)}a.unMount=new Set},z=(E,R)=>!t.disabled&&(E&&R&&$e(s,E,R),!hn(oe(),i)),M=(E,R,L)=>Fd(E,a,{...o.mount?s:Qe(R)?i:Yt(E)?{[E]:R}:R},L,R),A=E=>ys(le(o.mount?s:i,E,t.shouldUnregister?le(i,E,[]):[])),P=(E,R,L={})=>{const te=le(r,E);let K=R;if(te){const ee=te._f;ee&&(!ee.disabled&&$e(s,E,Hd(R,ee)),K=Vi(ee.ref)&&pt(R)?"":R,Vd(ee.ref)?[...ee.ref.options].forEach(ue=>ue.selected=K.includes(ue.value)):ee.refs?pi(ee.ref)?ee.refs.length>1?ee.refs.forEach(ue=>(!ue.defaultChecked||!ue.disabled)&&(ue.checked=Array.isArray(K)?!!K.find(be=>be===ue.value):K===ue.value)):ee.refs[0]&&(ee.refs[0].checked=!!K):ee.refs.forEach(ue=>ue.checked=ue.value===K):pa(ee.ref)?ee.ref.value="":(ee.ref.value=K,ee.ref.type||f.values.next({name:E,values:{...s}})))}(L.shouldDirty||L.shouldTouch)&&w(E,K,L.shouldTouch,L.shouldDirty,!0),L.shouldValidate&&k(E)},D=(E,R,L)=>{for(const te in R){const K=R[te],ee=`${E}.${te}`,ue=le(r,ee);(a.array.has(E)||et(K)||ue&&!ue._f)&&!Tn(K)?D(ee,K,L):P(ee,K,L)}},U=(E,R,L={})=>{const te=le(r,E),K=a.array.has(E),ee=bt(R);$e(s,E,ee),K?(f.array.next({name:E,values:{...s}}),(d.isDirty||d.dirtyFields)&&L.shouldDirty&&f.state.next({name:E,dirtyFields:Nr(i,s),isDirty:z(E,ee)})):te&&!te._f&&!pt(ee)?D(E,ee,L):P(E,ee,L),il(E,a)&&f.state.next({...n}),f.values.next({name:o.mount?E:void 0,values:{...s}})},$=async E=>{o.mount=!0;const R=E.target;let L=R.name,te=!0;const K=le(r,L),ee=()=>R.type?Zs(K._f):Od(E),ue=be=>{te=Number.isNaN(be)||Tn(be)&&isNaN(be.getTime())||hn(be,le(s,L,be))};if(K){let be,B;const Y=ee(),fe=E.type===Zi.BLUR||E.type===Zi.FOCUS_OUT,_e=!Cx(K._f)&&!t.resolver&&!le(n.errors,L)&&!K._f.deps||Ix(fe,le(n.touchedFields,L),n.isSubmitted,h,p),F=il(L,a,fe);$e(s,L,Y),fe?(K._f.onBlur&&K._f.onBlur(E),l&&l(0)):K._f.onChange&&K._f.onChange(E);const pe=w(L,Y,fe,!1),Te=!yt(pe)||F;if(!fe&&f.values.next({name:L,type:E.type,values:{...s}}),_e)return d.isValid&&(t.mode==="onBlur"&&fe?S():fe||S()),Te&&f.state.next({name:L,...F?{}:pe});if(!fe&&F&&f.state.next({...n}),t.resolver){const{errors:Be}=await H([L]);if(ue(Y),te){const rt=dl(n.errors,r,L),tt=dl(Be,r,rt.name||L);be=tt.error,L=tt.name,B=yt(Be)}}else b([L],!0),be=(await ul(K,a.disabled,s,g,t.shouldUseNativeValidation))[L],b([L]),ue(Y),te&&(be?B=!1:d.isValid&&(B=await _(r,!0)));te&&(K._f.deps&&k(K._f.deps),N(L,B,be,pe))}},X=(E,R)=>{if(le(n.errors,R)&&E.focus)return E.focus(),1},k=async(E,R={})=>{let L,te;const K=Zr(E);if(t.resolver){const ee=await O(Qe(E)?E:K);L=yt(ee),te=E?!K.some(ue=>le(ee,ue)):L}else E?(te=(await Promise.all(K.map(async ee=>{const ue=le(r,ee);return await _(ue&&ue._f?{[ee]:ue}:ue)}))).every(Boolean),!(!te&&!n.isValid)&&S()):te=L=await _(r);return f.state.next({...!Yt(E)||d.isValid&&L!==n.isValid?{}:{name:E},...t.resolver||!E?{isValid:L}:{},errors:n.errors}),R.shouldFocus&&!te&&Vr(r,X,E?K:a.mount),te},oe=E=>{const R={...o.mount?s:i};return Qe(E)?R:Yt(E)?le(R,E):E.map(L=>le(R,L))},G=(E,R)=>({invalid:!!le((R||n).errors,E),isDirty:!!le((R||n).dirtyFields,E),error:le((R||n).errors,E),isValidating:!!le(n.validatingFields,E),isTouched:!!le((R||n).touchedFields,E)}),y=E=>{E&&Zr(E).forEach(R=>it(n.errors,R)),f.state.next({errors:E?n.errors:{}})},Z=(E,R,L)=>{const te=(le(r,E,{_f:{}})._f||{}).ref,K=le(n.errors,E)||{},{ref:ee,message:ue,type:be,...B}=K;$e(n.errors,E,{...B,...R,ref:te}),f.state.next({name:E,errors:n.errors,isValid:!1}),L&&L.shouldFocus&&te&&te.focus&&te.focus()},V=(E,R)=>Gt(E)?f.values.subscribe({next:L=>E(M(void 0,R),L)}):M(E,R,!0),ie=(E,R={})=>{for(const L of E?Zr(E):a.mount)a.mount.delete(L),a.array.delete(L),R.keepValue||(it(r,L),it(s,L)),!R.keepError&&it(n.errors,L),!R.keepDirty&&it(n.dirtyFields,L),!R.keepTouched&&it(n.touchedFields,L),!R.keepIsValidating&&it(n.validatingFields,L),!t.shouldUnregister&&!R.keepDefaultValue&&it(i,L);f.values.next({values:{...s}}),f.state.next({...n,...R.keepDirty?{isDirty:z()}:{}}),!R.keepIsValid&&S()},se=({disabled:E,name:R,field:L,fields:te})=>{(zt(E)&&o.mount||E||a.disabled.has(R))&&(E?a.disabled.add(R):a.disabled.delete(R),w(R,Zs(L?L._f:le(te,R)._f),!1,!1,!0))},re=(E,R={})=>{let L=le(r,E);const te=zt(R.disabled)||zt(t.disabled);return $e(r,E,{...L||{},_f:{...L&&L._f?L._f:{ref:{name:E}},name:E,mount:!0,...R}}),a.mount.add(E),L?se({field:L,disabled:zt(R.disabled)?R.disabled:t.disabled,name:E}):C(E,!0,R.value),{...te?{disabled:R.disabled||t.disabled}:{},...t.progressive?{required:!!R.required,min:Er(R.min),max:Er(R.max),minLength:Er(R.minLength),maxLength:Er(R.maxLength),pattern:Er(R.pattern)}:{},name:E,onChange:$,onBlur:$,ref:K=>{if(K){re(E,R),L=le(r,E);const ee=Qe(K.value)&&K.querySelectorAll&&K.querySelectorAll("input,select,textarea")[0]||K,ue=jx(ee),be=L._f.refs||[];if(ue?be.find(B=>B===ee):ee===L._f.ref)return;$e(r,E,{_f:{...L._f,...ue?{refs:[...be.filter(Bs),ee,...Array.isArray(le(i,E))?[{}]:[]],ref:{type:ee.type,name:E}}:{ref:ee}}}),C(E,!1,void 0,ee)}else L=le(r,E,{}),L._f&&(L._f.mount=!1),(t.shouldUnregister||R.shouldUnregister)&&!(Pd(a.array,E)&&o.action)&&a.unMount.add(E)}}},de=()=>t.shouldFocusError&&Vr(r,X,a.mount),ge=E=>{zt(E)&&(f.state.next({disabled:E}),Vr(r,(R,L)=>{const te=le(r,L);te&&(R.disabled=te._f.disabled||E,Array.isArray(te._f.refs)&&te._f.refs.forEach(K=>{K.disabled=te._f.disabled||E}))},0,!1))},Ee=(E,R)=>async L=>{let te;L&&(L.preventDefault&&L.preventDefault(),L.persist&&L.persist());let K=bt(s);if(a.disabled.size)for(const ee of a.disabled)$e(K,ee,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:ee,values:ue}=await H();n.errors=ee,K=ue}else await _(r);if(it(n.errors,"root"),yt(n.errors)){f.state.next({errors:{}});try{await E(K,L)}catch(ee){te=ee}}else R&&await R({...n.errors},L),de(),setTimeout(de);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:yt(n.errors)&&!te,submitCount:n.submitCount+1,errors:n.errors}),te)throw te},ye=(E,R={})=>{le(r,E)&&(Qe(R.defaultValue)?U(E,bt(le(i,E))):(U(E,R.defaultValue),$e(i,E,bt(R.defaultValue))),R.keepTouched||it(n.touchedFields,E),R.keepDirty||(it(n.dirtyFields,E),n.isDirty=R.defaultValue?z(E,bt(le(i,E))):z()),R.keepError||(it(n.errors,E),d.isValid&&S()),f.state.next({...n}))},xe=(E,R={})=>{const L=E?bt(E):i,te=bt(L),K=yt(E),ee=K?i:te;if(R.keepDefaultValues||(i=L),!R.keepValues){if(R.keepDirtyValues){const ue=new Set([...a.mount,...Object.keys(Nr(i,s))]);for(const be of Array.from(ue))le(n.dirtyFields,be)?$e(ee,be,le(s,be)):U(be,le(ee,be))}else{if(ca&&Qe(E))for(const ue of a.mount){const be=le(r,ue);if(be&&be._f){const B=Array.isArray(be._f.refs)?be._f.refs[0]:be._f.ref;if(Vi(B)){const Y=B.closest("form");if(Y){Y.reset();break}}}}r={}}s=t.shouldUnregister?R.keepDefaultValues?bt(i):{}:bt(ee),f.array.next({values:{...ee}}),f.values.next({values:{...ee}})}a={mount:R.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!d.isValid||!!R.keepIsValid||!!R.keepDirtyValues,o.watch=!!t.shouldUnregister,f.state.next({submitCount:R.keepSubmitCount?n.submitCount:0,isDirty:K?!1:R.keepDirty?n.isDirty:!!(R.keepDefaultValues&&!hn(E,i)),isSubmitted:R.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:K?{}:R.keepDirtyValues?R.keepDefaultValues&&s?Nr(i,s):n.dirtyFields:R.keepDefaultValues&&E?Nr(i,E):R.keepDirty?n.dirtyFields:{},touchedFields:R.keepTouched?n.touchedFields:{},errors:R.keepErrors?n.errors:{},isSubmitSuccessful:R.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},W=(E,R)=>xe(Gt(E)?E(s):E,R);return{control:{register:re,unregister:ie,getFieldState:G,handleSubmit:Ee,setError:Z,_executeSchema:H,_getWatch:M,_getDirty:z,_updateValid:S,_removeUnmounted:I,_updateFieldArray:j,_updateDisabledField:se,_getFieldArray:A,_reset:xe,_resetDefaultValues:()=>Gt(t.defaultValues)&&t.defaultValues().then(E=>{W(E,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:E=>{n={...n,...E}},_disableForm:ge,_subjects:f,_proxyFormState:d,_setErrors:T,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:re,handleSubmit:Ee,watch:V,setValue:U,getValues:oe,reset:W,resetField:ye,clearErrors:y,unregister:ie,setError:Z,setFocus:(E,R={})=>{const L=le(r,E),te=L&&L._f;if(te){const K=te.refs?te.refs[0]:te.ref;K.focus&&(K.focus(),R.shouldSelect&&Gt(K.select)&&K.select())}},getFieldState:G}}function Ox(e={}){const t=Se.useRef(void 0),n=Se.useRef(void 0),[r,i]=Se.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={...zx(e),formState:r});const s=t.current.control;return s._options=e,fa({subject:s._subjects.state,next:o=>{$d(o,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),Se.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),Se.useEffect(()=>{if(s._proxyFormState.isDirty){const o=s._getDirty();o!==r.isDirty&&s._subjects.state.next({isDirty:o})}},[s,r.isDirty]),Se.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]),Se.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),Se.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()}),Se.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=Md(r,s),t.current}function Px(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 Dx=gx,Wd=x.createContext({}),fl=({...e})=>u.jsx(Wd.Provider,{value:{name:e.name},children:u.jsx(vx,{...e})}),ws=()=>{const e=x.useContext(Wd),t=x.useContext(qd),{getFieldState:n,formState:r}=vs(),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}},qd=x.createContext({}),Io=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return u.jsx(qd.Provider,{value:{id:r},children:u.jsx("div",{ref:n,className:q("space-y-2",e),...t})})});Io.displayName="FormItem";const To=x.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=ws();return u.jsx(sr,{ref:n,className:q(r&&"text-destructive",e),htmlFor:i,...t})});To.displayName="FormLabel";const Ao=x.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=ws();return u.jsx(yr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Ao.displayName="FormControl";const Gd=x.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=ws();return u.jsx("p",{ref:n,id:r,className:q("text-muted-foreground text-[0.8rem]",e),...t})});Gd.displayName="FormDescription";const zo=x.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=ws(),o=i?String(i==null?void 0:i.message):t;return o?u.jsx("p",{ref:r,id:s,className:q("text-destructive text-[0.8rem] font-medium",e),...n,children:o}):null});zo.displayName="FormMessage";function ma(){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 Yd=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Rx=(e=Yd())=>nx()(rx(ix((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:ma(),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:sx(()=>Gg),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}}))),Kd=x.createContext(void 0),Mx=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Rx(Yd())),u.jsx(Kd.Provider,{value:t.current,children:e})},Re=e=>{const t=x.useContext(Kd);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return ox(t,e)};function $x(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Lx(e,t,n){const r={},i=[];e!=="delete"&&(r.name=vi.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=vi.Optional(vi.String({description:"Template selection"})));const s=vi.Object(r,{additionalProperties:!1,required:i.length>0?i:void 0});return{schema:s,validate:o=>{const a=[];if(!ug(s,o))for(const c of cg(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 Fx(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Bx=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 Zx({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}=vr(),g=Bx(o),{documents:v,openTabs:S,createDocument:b,renameDocument:j,deleteDocument:m,openDocument:T,closeDocument:C}=Pe(oe=>oe),{updateTheme:w,removeTheme:N}=Eo(oe=>oe),H=Re(oe=>oe.renameThreadsForDocument),O=Re(oe=>oe.deleteThreadsForDocument),_=x.useMemo(()=>o?s||[]:i||[],[o,i,s]),I=x.useMemo(()=>{const oe={current:[],downstream:[]};return _.forEach(G=>{oe[G.location]&&oe[G.location].push(G)}),oe},[_]),z=x.useMemo(()=>_.map(oe=>({name:oe.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[_]),M=x.useMemo(()=>Lx(e,oe=>$x(oe,v,r),z),[e,v,r,z]),A=M.schema,P=x.useMemo(()=>{const oe=new Map;return _.forEach(G=>oe.set(G.path,G)),oe},[_]),D=Zn,U=Ox({resolver:Px(M.validate),defaultValues:Fx(e,void 0,r)}),[$,X]=x.useState(D);x.useEffect(()=>{if($&&$!==Zn&&e==="create"){const oe=P.get($);if(oe){d(null),p("loading");let G=!1;return fetch(`/api/discovery/${o?"themes":"documents"}/${encodeURIComponent(oe.name)}/content`).then(y=>{if(!y.ok)throw new Error(`Failed to fetch content: ${y.statusText}`);return y.text()}).then(y=>{if(G)return;const Z=JSON.parse(y);d(JSON.stringify(Z,null,2)),p("idle")}).catch(y=>{G||(console.error("Failed to copy template:",y),d(null),p("error"))}),()=>{G=!0}}}p("idle")},[$,e,P,o]),x.useEffect(()=>{t&&(U.reset(),d(null),p("idle"),X(D))},[U,t]);const k=U.handleSubmit(async({name:oe,template:G})=>{l(!0);try{if(await new Promise(y=>setTimeout(y,200)),e==="create"){const y=$?P.get($):_.find(ye=>ye.name===G);let Z,V=oe;if(!!$&&$!==Zn&&c===null){h({title:f==="loading"?"Template still loading":`Could not copy ${(y==null?void 0:y.name)??"the selected template"}`,description:f==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(o){const ye=V.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),xe=ot==="docx"?dg(ye):{name:ye,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};Z=c||JSON.stringify(xe,null,2);const W=`.${ot}.theme.json`;V.endsWith(W)||(V=V.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),V+=W)}else{const ye=y;Z=c||JSON.stringify(ot==="docx"?{name:"docx",props:{theme:(ye==null?void 0:ye.theme)||"default",metadata:{title:(ye==null?void 0:ye.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:(ye==null?void 0:ye.title)||V.replace(/\.(json|js)$/i,""),theme:(ye==null?void 0:ye.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 xe=ot==="docx"?".docx.json":".pptx.json";!V.endsWith(xe)&&!V.endsWith(".json")&&(V+=xe)}const se=V.match(/(\.(pptx|docx)(\.theme)?\.json|\.json)$/i),re=se?se[0]:"",de=V.slice(0,V.length-re.length);let ge=V,Ee=1;for(;v.some(ye=>ye.name===ge);)Ee++,ge=`${de} (${Ee})${re}`;V=ge,b(V,Z),T(V),o&&w(V,Z)}else if(e==="update"){const y=r,Z=oe,V=S.includes(y);V&&C(y),j(y,Z),H(y,Z),V&&T(Z)}else if(e==="delete"){const y=r;C(y),m(y),O(y),o&&N(y)}n()}finally{l(!1)}});return u.jsx(Dx,{...U,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:[A.properties&&"name"in A.properties&&u.jsx(fl,{control:U.control,name:"name",render:({field:oe})=>u.jsxs(Io,{children:[u.jsx(To,{children:"Name"}),u.jsx(Ao,{children:u.jsx(fi,{placeholder:"Enter a name or select a template below",autoComplete:"off",...oe})}),u.jsx(zo,{})]})}),e==="create"&&u.jsx(fl,{control:U.control,name:"template",render:({field:oe})=>u.jsxs(Io,{children:[u.jsx(To,{children:o?"Base Theme":"Base Document"}),u.jsxs(qr,{onValueChange:G=>{if(G===Zn)oe.onChange(void 0),U.setValue("name",""),X(Zn),d(null);else{const y=P.get(G);y&&(oe.onChange(y.name),U.setValue("name",y.name),X(G))}},defaultValue:D,children:[u.jsx(Ao,{children:u.jsx(cr,{children:u.jsx(Gr,{placeholder:`Select a discovered ${o?"theme":"document"}`})})}),u.jsxs(dr,{className:"max-h-[300px]",children:[u.jsxs(Dn,{value:Zn,children:["Empty ",o?"theme":"document"]}),Object.entries(I).map(([G,y])=>y.length===0?null:u.jsxs(ux,{children:[u.jsx(Ad,{children:G==="current"?"📁 Current Directory":"📦 Project"}),y.map(Z=>{let V;return Z.title&&Z.title!==Z.name?V=Z.title:Z.description&&(V=Z.description.length>40?Z.description.substring(0,40)+"...":Z.description),u.jsx(Dn,{value:Z.path,className:"pl-6",children:u.jsxs("span",{className:"flex flex-col",children:[u.jsx("span",{className:"font-medium",children:Z.name}),V&&u.jsx("span",{className:"text-muted-foreground text-xs",children:V})]})},Z.path)})]},G))]})]}),u.jsxs(Gd,{children:["Start empty or select a discovered"," ",o?"theme":"document"," as a starting point"]}),u.jsx(zo,{})]})})]}),u.jsx(yn,{children:u.jsx(Ne,{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 Hi=Se.memo(Zx);function cn(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function ga({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 Oo({children:e,count:t,actions:n,className:r}){return u.jsxs("div",{className:q("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=Se.forwardRef(({className:e,...t},n)=>u.jsx("button",{ref:n,type:"button",className:q("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 pl({tone:e,className:t}){return u.jsx("span",{"aria-hidden":!0,className:q("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function hl({icon:e,label:t,onClick:n,hint:r}){return n?u.jsxs("button",{type:"button",onClick:n,title:r,className:q("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 Vx=Wm,Ux=qm,Jx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(Wc,{ref:i,className:q("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"})]}));Jx.displayName=Wc.displayName;const Hx=x.forwardRef(({className:e,...t},n)=>u.jsx(qc,{ref:n,className:q("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}));Hx.displayName=qc.displayName;const Xd=x.forwardRef(({className:e,...t},n)=>u.jsx(Gm,{children:u.jsx(Uc,{ref:n,className:q("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})}));Xd.displayName=Uc.displayName;const Qd=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Hc,{ref:r,className:q("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}));Qd.displayName=Hc.displayName;const Wx=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(Gc,{ref:i,className:q("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(Yc,{children:u.jsx(bn,{className:"h-4 w-4"})})}),t]}));Wx.displayName=Gc.displayName;const qx=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(Kc,{ref:r,className:q("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(Yc,{children:u.jsx(bd,{className:"h-4 w-4 fill-current"})})}),t]}));qx.displayName=Kc.displayName;const Gx=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(Xc,{ref:r,className:q("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Gx.displayName=Xc.displayName;const ef=x.forwardRef(({className:e,...t},n)=>u.jsx(Jc,{ref:n,className:q("bg-border -mx-1 my-1 h-px",e),...t}));ef.displayName=Jc.displayName;const tf=({className:e,...t})=>u.jsx("span",{className:q("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});tf.displayName="ContextMenuShortcut";const ks=Ym,Ss=Km,Yx=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>u.jsxs(rd,{ref:i,className:q("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"})]}));Yx.displayName=rd.displayName;const Kx=x.forwardRef(({className:e,...t},n)=>u.jsx(id,{ref:n,className:q("bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] overflow-hidden rounded-lg border p-1 shadow-lg",e),...t}));Kx.displayName=id.displayName;const hi=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>u.jsx(Xm,{children:u.jsx(Qc,{ref:r,sideOffset:t,className:q("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})}));hi.displayName=Qc.displayName;const Lt=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(ed,{ref:r,className:q("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}));Lt.displayName=ed.displayName;const Xx=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>u.jsxs(sd,{ref:i,className:q("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(od,{children:u.jsx(bn,{className:"h-4 w-4"})})}),t]}));Xx.displayName=sd.displayName;const Qx=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ad,{ref:r,className:q("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(od,{children:u.jsx(bd,{className:"h-2 w-2 fill-current"})})}),t]}));Qx.displayName=ad.displayName;const nf=x.forwardRef(({className:e,inset:t,...n},r)=>u.jsx(nd,{ref:r,className:q("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));nf.displayName=nd.displayName;const fr=x.forwardRef(({className:e,...t},n)=>u.jsx(td,{ref:n,className:q("bg-muted -mx-1 my-1 h-px",e),...t}));fr.displayName=td.displayName;const rf=({className:e,...t})=>u.jsx("span",{className:q("ml-auto text-xs tracking-widest opacity-60",e),...t});rf.displayName="DropdownMenuShortcut";const sf=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>u.jsx(ld,{ref:i,decorative:n,orientation:t,className:q("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));sf.displayName=ld.displayName;const of=Pc,eb=Qm,tb=Dc,af=x.forwardRef(({className:e,...t},n)=>u.jsx(xs,{className:q("data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",e),...t,ref:n}));af.displayName=xs.displayName;const nb=di("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"}}),xa=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>u.jsxs(tb,{children:[u.jsx(af,{}),u.jsxs(hs,{ref:i,className:q(nb({side:e}),t),...r,children:[u.jsxs(aa,{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]})]}));xa.displayName=hs.displayName;const rb=x.forwardRef(({className:e,...t},n)=>u.jsx(ms,{ref:n,className:q("text-foreground text-lg font-semibold",e),...t}));rb.displayName=ms.displayName;const ib=x.forwardRef(({className:e,...t},n)=>u.jsx(gs,{ref:n,className:q("text-muted-foreground text-sm",e),...t}));ib.displayName=gs.displayName;function Ur({className:e,...t}){return u.jsx("div",{className:q("bg-primary/10 animate-pulse rounded-md",e),...t})}const Vs=768,Us=1200;function lf(e){return typeof window<"u"?window.innerWidth<e:!1}function uf(){const[e,t]=x.useState(()=>lf(Vs));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Vs-1}px)`),r=()=>{t(window.innerWidth<Vs)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function sb(){const[e,t]=x.useState(()=>lf(Us));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${Us-1}px)`),r=()=>{t(window.innerWidth<Us)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const ob="sidebar_state",ab=60*60*24*7,lb="16rem",ub="18rem",cb="3rem",db="b",cf=x.createContext(null);function _s(){const e=x.useContext(cf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const df=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...o},a)=>{const l=uf(),[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=`${ob}=${m}; path=/; max-age=${ab}`},[n,h]),v=x.useCallback(()=>l?d(j=>!j):g(j=>!j),[l,g,d]);x.useEffect(()=>{const j=T=>{var N;const C=T;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=T=>{const C=T.metaKey||T.ctrlKey,w=T.key.toLowerCase();if(C&&w===db){T.preventDefault(),v();return}C&&w==="s"&&!j(T.target)&&(T.preventDefault(),v())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[v]);const S=h?"expanded":"collapsed",b=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(cf.Provider,{value:b,children:u.jsx(fg,{delayDuration:0,children:u.jsx("div",{style:{"--sidebar-width":lb,"--sidebar-width-icon":cb,...i},className:q("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:a,...o,children:s})})})});df.displayName="SidebarProvider";const ff=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}=_s();return n==="none"?u.jsx("div",{className:q("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:o,...s,children:i}):a?u.jsx(of,{open:c,onOpenChange:d,...s,children:u.jsx(xa,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":ub},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:q("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:q("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})})]})});ff.displayName="Sidebar";const fb=x.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=_s();return u.jsxs(Ne,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:q("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[u.jsx(yg,{}),u.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});fb.displayName="SidebarTrigger";const pb=x.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=_s();return u.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:q("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})});pb.displayName="SidebarRail";const hb=x.forwardRef(({className:e,...t},n)=>u.jsx("main",{ref:n,className:q("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}));hb.displayName="SidebarInset";const mb=x.forwardRef(({className:e,...t},n)=>u.jsx(fi,{ref:n,"data-sidebar":"input",className:q("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));mb.displayName="SidebarInput";const Po=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"header",className:q("flex flex-col gap-2 p-2",e),...t}));Po.displayName="SidebarHeader";const pf=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"footer",className:q("flex flex-col gap-2 p-2",e),...t}));pf.displayName="SidebarFooter";const gb=x.forwardRef(({className:e,...t},n)=>u.jsx(sf,{ref:n,"data-sidebar":"separator",className:q("bg-sidebar-border mx-2 w-auto",e),...t}));gb.displayName="SidebarSeparator";const Do=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"content",className:q("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Do.displayName="SidebarContent";const xb=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group",className:q("relative flex w-full min-w-0 flex-col p-2",e),...t}));xb.displayName="SidebarGroup";const bb=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?yr:"div";return u.jsx(i,{ref:r,"data-sidebar":"group-label",className:q("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})});bb.displayName="SidebarGroupLabel";const yb=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?yr:"button";return u.jsx(i,{ref:r,"data-sidebar":"group-action",className:q("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})});yb.displayName="SidebarGroupAction";const vb=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"group-content",className:q("w-full text-sm",e),...t}));vb.displayName="SidebarGroupContent";const Dr=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu",className:q("flex w-full min-w-0 flex-col gap-1",e),...t}));Dr.displayName="SidebarMenu";const hf=x.forwardRef(({className:e,...t},n)=>u.jsx("li",{ref:n,"data-sidebar":"menu-item",className:q("group/menu-item relative",e),...t}));hf.displayName="SidebarMenuItem";const wb=di("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"}}),mf=x.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...o},a)=>{const l=e?yr:"button",{isMobile:c,state:d}=_s(),f=u.jsx(l,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:q(wb({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});mf.displayName="SidebarMenuButton";const gf=x.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?yr:"button";return u.jsx(s,{ref:i,"data-sidebar":"menu-action",className:q("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})});gf.displayName="SidebarMenuAction";const kb=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:q("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}));kb.displayName="SidebarMenuBadge";const Sb=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:q("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&u.jsx(Ur,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),u.jsx(Ur,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});Sb.displayName="SidebarMenuSkeleton";const _b=x.forwardRef(({className:e,...t},n)=>u.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:q("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}));_b.displayName="SidebarMenuSub";const jb=x.forwardRef(({...e},t)=>u.jsx("li",{ref:t,...e}));jb.displayName="SidebarMenuSubItem";const Nb=x.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const o=e?yr:"a";return u.jsx(o,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:q("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})});Nb.displayName="SidebarMenuSubButton";function Mi(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 Eb=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Cb({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=Pe(G=>G.openDocument),h=Pe(G=>G.documentTypes),g=Pe(G=>G.activeTab),v=rn(G=>G.name),S=rn(G=>G.text),b=rn(G=>G.isGenerating),m=(h[e.name]||"application/json+report")==="application/json+theme",T=g===e.name,[C,w]=x.useState(v),[N,H]=x.useState(S),O=100,_=0;x.useEffect(()=>{const G=setTimeout(()=>{v&&S?(w(v),H(S)):b||(w(""),H(""))},b?O:_);return()=>clearTimeout(G)},[v,S,b]);const I=C===e.name,z=G=>{var Z;const y=new Set;try{const V=JSON.parse(G);(Z=V.props)!=null&&Z.theme&&y.add(V.props.theme),V.children&&Array.isArray(V.children)&&V.children.forEach(ie=>{var se;ie.name==="docx"&&((se=ie.props)!=null&&se.theme)&&y.add(ie.props.theme)})}catch{}return y},M=x.useMemo(()=>{if(!m||!N)return!1;try{const G=JSON.parse(e.text),y=Yg(G);if(y)return z(N).has(y)}catch{}return!1},[m,N,e.text]),A=x.useCallback(()=>{c(!1)},[]),P=x.useCallback(()=>{f(!1)},[]),D=T?null:I?"preview":M?"in-use":null,U=T?"Editing":I?"In preview":M?"Used by preview":null,$=x.useMemo(()=>[{key:"open",label:"Open",shortcut:Eb?"⌘⏎":"⌃⏎",run:()=>p(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>Mi(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]),X=m?vg:yd,k=i||o,oe=u.jsxs(mf,{size:"sm",ref:r,"aria-label":U?`${e.name} — ${U}`:e.name,className:q("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",T&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:U?`${e.name} — ${U}`:e.name,onClick:()=>{p(e.name)},onKeyDown:G=>{var y;(G.ctrlKey||G.metaKey)&&G.key==="Enter"?(p(e.name),G.preventDefault()):G.key==="Enter"?(c(!0),G.preventDefault()):G.key==="Backspace"||G.key==="Delete"?(f(!0),G.preventDefault()):G.key==="Escape"&&((y=r.current)==null||y.blur(),G.preventDefault())},children:[T&&u.jsx("span",{"aria-hidden":!0,className:q("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),u.jsx(X,{className:q("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",T&&!m&&"text-sidebar-accent-foreground/70")}),!t&&u.jsx("span",{className:"flex-1 truncate",children:u.jsx(ga,{text:e.name,query:n})}),t&&D&&u.jsx(pl,{tone:D,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return u.jsxs(hf,{children:[u.jsxs(Vx,{onOpenChange:s,children:[u.jsx(Ux,{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:U??(m?"Theme":"Document")})]})})]}):oe}),u.jsx(Xd,{className:"w-44",children:$.map(G=>u.jsxs(Se.Fragment,{children:[G.separatorBefore&&u.jsx(ef,{}),u.jsxs(Qd,{onClick:G.run,className:q(G.danger&&"text-destructive focus:text-destructive"),children:[G.label,G.shortcut&&u.jsx(tf,{children:G.shortcut})]})]},G.key))})]}),!t&&u.jsxs(u.Fragment,{children:[D&&u.jsx(pl,{tone:D,className:q("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(ks,{onOpenChange:a,children:[u.jsx(Ss,{asChild:!0,children:u.jsx(gf,{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(vd,{})})}),u.jsx(hi,{side:"right",align:"start",className:"w-44",children:$.map(G=>u.jsxs(Se.Fragment,{children:[G.separatorBefore&&u.jsx(fr,{}),u.jsxs(Lt,{onClick:G.run,className:q(G.danger&&"text-destructive focus:text-destructive"),children:[G.label,G.shortcut&&u.jsx(rf,{children:G.shortcut})]})]},G.key))})]})]}),u.jsx(Ct,{open:l,onOpenChange:c,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:G=>{var y;G.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Hi,{mode:"update",shouldReset:!l,postSubmit:A,selectedName:e.name})})}),u.jsx(Ct,{open:d,onOpenChange:f,children:u.jsx(kt,{className:"sm:max-w-[425px]",onCloseAutoFocus:G=>{var y;G.preventDefault(),(y=r.current)==null||y.focus()},children:u.jsx(Hi,{mode:"delete",shouldReset:!d,postSubmit:P,selectedName:e.name})})})]})}const Si=Se.memo(Cb);function Ib(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,T){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 T=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++;T=r}else f=3;return e.substring(m,T)}function v(){let m="",T=r;for(;;){if(r>=n){m+=e.substring(T,r),f=2;break}const C=e.charCodeAt(r);if(C===34){m+=e.substring(T,r),r++;break}if(C===92){if(m+=e.substring(T,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}T=r;continue}if(C>=0&&C<=31)if(Cr(C)){m+=e.substring(T,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(Js(m)){do r++,i+=String.fromCharCode(m),m=e.charCodeAt(r);while(Js(m));return o=15}if(Cr(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 T=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!Cr(e.charCodeAt(r));)r++;return i=e.substring(T,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++,Cr(N)&&(N===13&&e.charCodeAt(r)===10&&r++,a++,c=r)}return w||(r++,f=1),i=e.substring(T,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&&b(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 b(m){if(Js(m)||Cr(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 Js(e){return e===32||e===9}function Cr(e){return e===10||e===13}function Vn(e){return e>=48&&e<=57}var ml;(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"})(ml||(ml={}));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 Wi;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Wi||(Wi={}));function Tb(e,t=[],n=Wi.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}Ab(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:zb(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 Ab(e,t,n=Wi.DEFAULT){const r=Ib(e,!1),i=[];let s=0;function o(A){return A?()=>s===0&&A(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function a(A){return A?P=>s===0&&A(P,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function l(A){return A?P=>s===0&&A(P,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function c(A){return A?()=>{s>0?s++:A(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(s=1)}:()=>!0}function d(A){return A?()=>{s>0&&s--,s===0&&A(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),b=a(t.onSeparator),j=o(t.onComment),m=a(t.onError),T=n&&n.disallowComments,C=n&&n.allowTrailingComma;function w(){for(;;){const A=r.scan();switch(r.getTokenError()){case 4:N(14);break;case 5:N(15);break;case 3:N(13);break;case 1:T||N(11);break;case 2:N(12);break;case 6:N(16);break}switch(A){case 12:case 13:T?N(10):j();break;case 16:N(1);break;case 15:case 14:break;default:return A}}}function N(A,P=[],D=[]){if(m(A),P.length+D.length>0){let U=r.getToken();for(;U!==17;){if(P.indexOf(U)!==-1){w();break}else if(D.indexOf(U)!==-1)break;U=w()}}}function H(A){const P=r.getTokenValue();return A?S(P):(p(P),i.push(P)),w(),!0}function O(){switch(r.getToken()){case 11:const A=r.getTokenValue();let P=Number(A);isNaN(P)&&(N(2),P=0),S(P);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):(H(!1),r.getToken()===6?(b(":"),w(),M()||N(4,[],[2,5])):N(5,[],[2,5]),i.pop(),!0)}function I(){f(),w();let A=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(A||N(4,[],[]),b(","),w(),r.getToken()===2&&C)break}else A&&N(6,[],[]);_()||N(4,[],[2,5]),A=!0}return h(),r.getToken()!==2?N(7,[2],[]):w(),!0}function z(){g(),w();let A=!0,P=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(P||N(4,[],[]),b(","),w(),r.getToken()===4&&C)break}else P&&N(6,[],[]);A?(i.push(0),A=!1):i[i.length-1]++,M()||N(4,[],[4,5]),P=!0}return v(),A||i.pop(),r.getToken()!==4?N(8,[4],[]):w(),!0}function M(){switch(r.getToken()){case 3:return z();case 1:return I();case 10:return H(!0);default:return O()}}return w(),r.getToken()===17?n.allowEmptyContent?!0:(N(4,[],[]),!1):M()?(r.getToken()!==17&&N(9,[],[]),!0):(N(4,[],[]),!1)}function zb(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 gl;(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"})(gl||(gl={}));var xl;(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"})(xl||(xl={}));const Ob=Tb;var bl;(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"})(bl||(bl={}));const Pb=60,Db=/§jtoc:\d+§/g;function Ae(e,t){if(!(!e||e.type!=="object"||!e.children))for(const n of e.children){if(n.type!=="property"||!n.children)continue;const[r,i]=n.children;if((r==null?void 0:r.value)===t)return i}}function st(e){return(e==null?void 0:e.type)==="string"&&typeof e.value=="string"?e.value:void 0}function Ro(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=Pb,n=!1){const r=e.replace(Db,"…"),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 Rb(e){const t=Et(Ae(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>Et(Ae(i,"cells")).length))}×${t.length}`;const n=Et(Ae(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?Et(r).length:Et(Ae(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Mb(e){const t=st(Ae(e,"alt"));if(t)return vt(t);const n=st(Ae(e,"src"));if(n){if(n.startsWith("data:")){const i=n.slice(5).split(/[;,]/)[0];return i?`image (${i.split("/").pop()})`:"image"}const r=n.split(/[?#]/)[0].split("/").pop();if(r)return vt(r,40)}return"image"}function $b(e,t){var r;const n=st(Ae(t,"text"));switch(e){case"heading":{const i=Ro(Ae(t,"level"))??1;return{label:n?vt(n):"heading",detail:`H${i}`}}case"text":return{label:n?vt(n):"text",detail:st(Ae(t,"style"))};case"paragraph":return{label:n?vt(n):"paragraph"};case"chart":case"highcharts":{const i=st(Ae(t,"title"))??st(Ae(Ae(t,"options"),"title"));return{label:i?vt(i):e,detail:st(Ae(t,"type"))}}case"table":return{label:"table",detail:Rb(t)};case"image":return{label:Mb(t)};case"shape":return{label:st(Ae(t,"type"))??"shape"};case"list":{const i=Et(Ae(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=st(Ae(Ae(t,"meta"),"title"))??st(Ae(t,"title"));return{label:i?vt(i):"section"}}case"statistic":{const i=st(Ae(t,"value"))??((r=Ro(Ae(t,"value")))==null?void 0:r.toString()),s=st(Ae(t,"label"));return{label:vt(s??i??"statistic"),detail:i}}default:return{label:n?vt(n):e}}}function pr(e){if(e.type!=="object")return null;const t=st(Ae(e,"name"));return t?{name:t,props:Ae(e,"props"),childrenArr:Ae(e,"children")}:null}function Lb(e){let t;for(const n of Et(e)){const r=pr(n);if(!r)continue;const i=st(Ae(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return vt(i,48);r.name==="paragraph"&&t===void 0&&(t=vt(i,48))}}return t}function qi(e,t,n){let{label:r,detail:i}=$b(t.name,t.props);return r===t.name&&t.childrenArr&&(r=Lb(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:xf(t.childrenArr),reorder:n}}function xf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of Et(e)){const i=pr(r);i&&n.push(qi(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Fb(e){const t=Ae(e,"props"),n=st(Ae(Ae(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=Ae(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?pr(c):null,p=f?st(Ae(f.props,"text")):void 0;i(d==="title"?0:d==="subtitle"||d.startsWith("heading")?1:2,p)}const o=(a,l)=>{const c=pr(a);if(c){if(c.name==="text"||c.name==="heading"){const d=st(Ae(c.props,"text"));if(d){const f=st(Ae(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(Ae(e,"children")))o(a,0);return r?vt(r.text,48,!0):void 0}function Bb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of Et(t)){const o=pr(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:Fb(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:xf(o.childrenArr),reorder:a})):r.push(qi(s,o,a))}return r}function Zb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const o of Et(t)){const a=pr(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=Ro(Ae(a.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=qi(o,a,l);c().push(f),i.push({level:d,node:f})}else c().push(qi(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 yl(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 Vb(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:yl(c),start:a.offset,end:a.offset+a.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:o.length===0?yl(i):void 0,start:n.offset,end:n.offset+n.length,children:o})}return t}function vl(e,t,n){if(!e.trim())return[];const r=Ob(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Vb(r):t==="pptx"?Bb(r):Zb(r);return bf(i,""),i}function bf(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,bf(n.children,n.id)})}function yf(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 Ub(e,t){const n=new Set;for(const r of t)for(const i of yf(e,r))n.add(i);return n}function Jb(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 Hb={slide:Cg,heading:Eg,text:ko,paragraph:Ng,chart:So,highcharts:So,table:jg,image:_g,shape:wd,list:Sg,toc:kg,section:Qa,columns:Qa,"text-box":ko,statistic:wg,key:wo};function Wb(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 qb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function Gb(){const{activeTab:e,documentTypes:t}=Pe(ua(O=>({activeTab:O.activeTab,documentTypes:O.documentTypes}))),n=Pe(O=>{var _;return O.activeTab?(_=O.documents.find(I=>I.name===O.activeTab))==null?void 0:_.text:void 0}),r=qg(O=>e?O.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,o]=x.useState(()=>{try{const O=localStorage.getItem("dev-env.outline-open");return O?O==="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),b=x.useRef(a);b.current=a;const j=x.useRef(null),m=x.useRef(null),T=x.useCallback(()=>{var I;if(!e){l([]);return}const O=((I=r==null?void 0:r.editor.getModel())==null?void 0:I.getValue())??n??"",_=vl(O,ot,i);if(l(_),m.current!==e){m.current=e;const z=new Set;if(i==="document"&&ot==="docx")for(const M of _)M.kind==="heading"&&z.add(M.id);g(z),d(null)}},[e,r,n,i]);x.useEffect(()=>{T();const O=r==null?void 0:r.editor.getModel();if(!O)return;const _=tl(T,300),I=O.onDidChangeContent(()=>_());return()=>{_.cancel(),I.dispose()}},[T,r]),x.useEffect(()=>{if(!r)return;const{editor:O}=r,_=tl(()=>{const z=O.getModel(),M=O.getPosition();if(!z||!M)return;const A=z.getOffsetAt(M),P=yf(b.current,A);if(P.length===0){d(null);return}d(P[P.length-1]);const D=P.slice(0,-1);D.length&&g(U=>{if(D.every(X=>U.has(X)))return U;const $=new Set(U);for(const X of D)$.add(X);return $})},150),I=O.onDidChangeCursorPosition(()=>_());return()=>{_.cancel(),I.dispose()}},[r]),x.useEffect(()=>{if(!c||!j.current)return;const O=j.current.querySelector(`[data-oid="${CSS.escape(c)}"]`);O==null||O.scrollIntoView({block:"nearest"})},[c]),x.useEffect(()=>{if(!r){p(new Set);return}const{editor:O,monaco:_}=r,I=()=>{const M=O.getModel();if(!M)return;const A=_.editor.getModelMarkers({resource:M.uri}).filter(P=>P.severity===_.MarkerSeverity.Error).map(P=>M.getOffsetAt({lineNumber:P.startLineNumber,column:P.startColumn}));p(Ub(b.current,A))};I();const z=_.editor.onDidChangeMarkers(M=>{const A=O.getModel();A&&M.some(P=>P.toString()===A.uri.toString())&&I()});return()=>z.dispose()},[r,a]);const C=x.useCallback(O=>{g(_=>{const I=new Set(_);return I.has(O)?I.delete(O):I.add(O),I})},[]),w=x.useCallback(O=>{if(d(O.id),!r)return;const{editor:_,monaco:I}=r,z=_.getModel();if(!z)return;const M=z.getPositionAt(O.start),A=z.getPositionAt(O.end),P=new I.Range(M.lineNumber,M.column,A.lineNumber,A.column);_.revealRangeNearTopIfOutsideViewport(P,I.editor.ScrollType.Smooth),_.setPosition(M),_.focus();const D=_.deltaDecorations([],[{range:P,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>_.deltaDecorations(D,[]),700)},[r]),N=x.useCallback(O=>{var y;if(!r||!O.overId)return;const{editor:_,monaco:I,collapse:z}=r,M=_.getModel();if(!M)return;const A=M.getValue(),P=vl(A,ot,i),D=O.parentId?((y=Wb(P,O.parentId))==null?void 0:y.children)??[]:P,U=D.findIndex(Z=>Z.id===O.dragId),$=D.findIndex(Z=>Z.id===O.overId);if(U===-1||$===-1)return;let X=$+(O.overHalf==="after"?1:0);U<X&&(X-=1);const k=Jb(A,D,U,X);if(!k)return;const oe=M.getPositionAt(k.start),G=M.getPositionAt(k.end);_.executeEdits("outline-reorder",[{range:new I.Range(oe.lineNumber,oe.column,G.lineNumber,G.column),text:k.text}]),z==null||z.resyncDecorations()},[r,i]),H=x.useMemo(()=>{const O=[],_=(I,z,M)=>{var D,U;const A=(U=(D=I[0])==null?void 0:D.reorder)==null?void 0:U.groupId,P=I.length>1&&A!==void 0&&I.every($=>{var X;return((X=$.reorder)==null?void 0:X.groupId)===A});I.forEach($=>{const X=Hb[$.kind]??Ig,k=$.children.length>0,oe=h.has($.id),G=c===$.id,y=(v==null?void 0:v.overId)===$.id;O.push(u.jsxs("div",{"data-oid":$.id,role:"treeitem","aria-selected":G,"aria-expanded":k?oe:void 0,tabIndex:0,draggable:P,onClick:()=>w($),onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),w($)),Z.key==="ArrowRight"&&k&&!oe&&C($.id),Z.key==="ArrowLeft"&&k&&oe&&C($.id)},onDragStart:Z=>{Z.dataTransfer.setData("text/plain",$.id),Z.dataTransfer.effectAllowed="move",S({dragId:$.id,parentId:M,overId:null,overHalf:"before"})},onDragOver:Z=>{if(!v||v.dragId===$.id||qb(v.dragId)!==M)return;Z.preventDefault(),Z.dataTransfer.dropEffect="move";const V=Z.currentTarget.getBoundingClientRect(),ie=Z.clientY<V.top+V.height/2?"before":"after";(v.overId!==$.id||v.overHalf!==ie)&&S({...v,overId:$.id,overHalf:ie})},onDrop:Z=>{Z.preventDefault(),v&&N({...v,overId:$.id,overHalf:v.overHalf}),S(null)},onDragEnd:()=>S(null),className:q("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",G&&"bg-sidebar-accent font-medium text-sidebar-foreground",y&&(v==null?void 0:v.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",y&&(v==null?void 0:v.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+z*12},children:[k?u.jsx("span",{role:"button","aria-label":oe?"Collapse":"Expand",onClick:Z=>{Z.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:q("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(X,{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,z+1,$.id)})};return _(a,0,""),O},[a,h,c,f,v,w,C,N]);return e?u.jsxs("section",{className:"mt-3 shrink-0",children:[u.jsx(Oo,{count:a.length||void 0,actions:u.jsx($t,{"aria-label":s?"Collapse outline":"Expand outline","aria-expanded":s,onClick:()=>o(O=>!O),children:u.jsx(Pn,{className:q("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:H}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/60",children:"No structure to show yet."}))]}):null}const Yb=x.memo(Gb);async function Kb(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const Yr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ud,{ref:r,className:q("relative overflow-hidden",e),...n,children:[u.jsx(eg,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(vf,{}),u.jsx(tg,{})]}));Yr.displayName=ud.displayName;const vf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(cd,{ref:r,orientation:t,className:q("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(ng,{className:"bg-border relative flex-1 rounded-full"})}));vf.displayName=cd.displayName;function ba({className:e,...t}){return u.jsx(rg,{"data-slot":"switch",className:q("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(ig,{"data-slot":"switch-thumb",className:q("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 Xb=di("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"}}),Gi=x.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:q(Xb({variant:t}),e),...n}));Gi.displayName="Alert";const Qb=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:q("mb-1 font-medium leading-none tracking-tight",e),...t}));Qb.displayName="AlertTitle";const Yi=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:q("text-sm [&_p]:leading-relaxed",e),...t}));Yi.displayName="AlertDescription";const Ki=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:q("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(ci,{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(Ki,{keyName:String(p),value:f,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([f,p],h,g)=>u.jsx(Ki,{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&&","]})})]})]})});Ki.displayName="JsonNode";const Xi=x.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:q("space-y-4",r),children:[u.jsx(Ur,{className:"h-8 w-64"}),u.jsx(Ur,{className:"h-4 w-full"}),u.jsx(Ur,{className:"h-64 w-full"})]}):n?u.jsx(Gi,{variant:"destructive",className:r,children:u.jsx(Yi,{children:n})}):e?u.jsx(Yr,{className:q("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(Ki,{value:e})})}):u.jsx(Gi,{className:r,children:u.jsx(Yi,{children:"No schema available"})}));Xi.displayName="SchemaViewer";function ey({plugins:e,initialFocusedPlugin:t}){var m,T;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 Kb(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(Dg,{className:"size-3"});case"downstream":return u.jsx(Pg,{className:"size-3"});case"upstream":return u.jsx(yd,{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,b=(T=o==null?void 0:o.schema)==null?void 0:T.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(Tg,{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(Yr,{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 H=r(N.name),O=(o==null?void 0:o.name)===N.name;return u.jsxs("button",{onClick:()=>a(N),className:q("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",O?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:q("size-1.5 rounded-full flex-none transition-colors",H?"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(ba,{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:q("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(wo,{className:"size-3.5"}),"Properties"]})}),b&&u.jsx("button",{onClick:()=>f("schema"),className:q("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(Ag,{className:"size-3.5"}),"Schema"]})}),j&&u.jsx("button",{onClick:()=>f("examples"),className:q("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(zg,{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(Yr,{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(ty,{name:C,prop:w},C))}),d==="schema"&&b&&u.jsx(Xi,{schema:o.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&j&&o.examples.map((C,w)=>u.jsxs("div",{className:q(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(Ne,{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(Og,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(bs,{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&&!b&&!j&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(wo,{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 ty({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:q("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(ci,{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 ny=sg,ry=og,iy=ag,sy={current:"Current directory",downstream:"Project"};function Hs({id:e,label:t,count:n,open:r,onToggle:i,children:s}){return u.jsxs(ny,{open:r,children:[u.jsxs(ry,{onClick:()=>i(e),className:q("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:q("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(iy,{children:u.jsx("div",{className:"border-sidebar-border/70 mt-0.5 ml-[13px] border-l pl-1",children:s})})]})}function wl({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:sy[e]??e})}function kl({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:q("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(ga,{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 oy({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=b=>i?!0:s.has(b),g=x.useMemo(()=>Sl(e),[e]),v=x.useMemo(()=>Sl(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(Hs,{id:"library-documents",label:"Project documents",count:e.length,open:h("library-documents"),onToggle:o,children:g.map(([b,j])=>u.jsxs(Se.Fragment,{children:[g.length>1&&u.jsx(wl,{location:b}),j.map(m=>u.jsx(kl,{name:m.name,subtitle:m.title,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!1)},m.path||m.name))]},b))}),t.length>0&&u.jsx(Hs,{id:"library-themes",label:"Project themes",count:t.length,open:h("library-themes"),onToggle:o,children:v.map(([b,j])=>u.jsxs(Se.Fragment,{children:[v.length>1&&u.jsx(wl,{location:b}),j.map(m=>u.jsx(kl,{name:m.name,subtitle:m.description,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!0)},m.path||m.name))]},b))}),n.length>0&&u.jsx(Hs,{id:"library-plugins",label:"Plugins",count:`${p}/${n.length}`,open:h("library-plugins"),onToggle:o,children:n.map(b=>{const j=c(b.name),m=`plugin-switch-${b.filePath||b.name}`;return u.jsxs("div",{title:b.description?`${b.name} — ${b.description}`:b.name,className:q("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:q("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(ga,{text:b.name,query:i})})}),u.jsx($t,{"aria-label":`Details for ${b.name}`,onClick:T=>{T.stopPropagation(),l(b.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(kd,{})}),u.jsx(ba,{id:m,checked:j,onCheckedChange:()=>d(b),disabled:f,className:"shrink-0","aria-label":`Toggle ${b.name} plugin`})]},b.filePath||b.name)})})]}):null}function Sl(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 wf({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:q("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 ay({children:e,className:t}){return u.jsx("span",{className:q("inline-flex items-center gap-0.5",t),children:e})}const _i=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function Kr({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return _i?"⌘":"Ctrl";case"shift":return _i?"⇧":"Shift";case"alt":return _i?"⌥":"Alt";case"ctrl":return _i?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(ay,{className:t,children:r.map((i,s)=>u.jsx(wf,{children:i},s))})}function ly({className:e}={}){const{theme:t,setTheme:n}=md(),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(Ne,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Rg,{className:"hidden dark:block"}),u.jsx(Mg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ye,{children:u.jsx("p",{children:"Toggle theme"})})]})}function uy({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:o,openDocument:a}=Pe(ua(W=>({documents:W.documents,documentTypes:W.documentTypes,createDocument:W.createDocument,openDocument:W.openDocument}))),l=Eo(W=>W.updateTheme),c=Eo(W=>W.removeTheme),d=x.useContext(Ed),[f,p]=x.useState(!1),[h,g]=x.useState(!1),[v,S]=x.useState(!1),[b,j]=x.useState(null),m=Bt(W=>W.togglePlugin),T=Bt(W=>W.isPluginSelected),C=Bt(W=>W.selectedPlugins),w=Bt(W=>W.isApplyingPlugins),[N,H]=x.useState(!1),[O,_]=x.useState(new Set(["library-documents"])),[I,z]=x.useState(""),M=x.useRef(null),{toast:A}=vr(),P=i.filter(W=>s[W.name]!=="application/json+theme"),D=i.filter(W=>s[W.name]==="application/json+theme"),U=x.useCallback(()=>{p(!1)},[]),$=x.useCallback(()=>{g(!1)},[]),X=x.useRef(new Map);x.useEffect(()=>{const W=X.current,Oe=new Map;D.forEach(Q=>{Oe.set(Q.name,Q.text),W.get(Q.name)!==Q.text&&l(Q.name,Q.text)}),W.forEach((Q,ve)=>{Oe.has(ve)||c(ve)}),X.current=Oe},[D,l,c]);const k=x.useRef(!1);x.useEffect(()=>{if(k.current||!d)return;k.current=!0;const W=new Set(D.map(Q=>Q.name));Object.keys(d.getState().customThemes).forEach(Q=>{W.has(Q)||c(Q)})},[D,c,d]);const oe=x.useCallback(W=>{_(Oe=>{const Q=new Set(Oe);return Q.has(W)?Q.delete(W):Q.add(W),Q})},[]),{resolvedTheme:G}=md(),y=G==="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",Z=x.useCallback(async(W,Oe)=>{if(i.some(Q=>Q.name===W)){a(W);return}try{const Q=await fetch(`/api/discovery/${Oe?"themes":"documents"}/${encodeURIComponent(W)}/content`);if(!Q.ok)throw new Error(Q.statusText);const ve=await Q.text(),E=JSON.parse(ve);o(W,JSON.stringify(E,null,2)),a(W),A({title:`Added ${Oe?"theme":"document"}: ${W}`})}catch{A({title:"Failed to load",description:`Could not load ${W}`,variant:"destructive"})}},[i,o,a,A]);x.useEffect(()=>{if(n)return;const W=Oe=>{var E,R,L,te,K;if(Oe.key!=="/"||Oe.metaKey||Oe.ctrlKey||Oe.altKey)return;const Q=Oe.target,ve=(E=Q==null?void 0:Q.tagName)==null?void 0:E.toLowerCase();ve==="input"||ve==="textarea"||ve==="select"||Q!=null&&Q.isContentEditable||(R=Q==null?void 0:Q.closest)!=null&&R.call(Q,".monaco-editor")||(L=M.current)!=null&&L.closest('[aria-hidden="true"], [inert]')||(Oe.preventDefault(),(te=M.current)==null||te.focus(),(K=M.current)==null||K.select())};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[n]);const V=I.trim(),ie=x.useMemo(()=>new Set(i.map(W=>W.name)),[i]),se=x.useMemo(()=>P.filter(W=>cn(W.name,V)),[P,V]),re=x.useMemo(()=>D.filter(W=>cn(W.name,V)),[D,V]),de=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(W=>cn(W.name,V)||cn(W.title??"",V)),[e,V]),ge=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(W=>cn(W.name,V)||cn(W.description??"",V)),[e,V]),Ee=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(W=>cn(W.name,V)||cn(W.description??"",V)),[e,V]),ye=V.length>0&&se.length===0&&re.length===0&&de.length===0&&ge.length===0&&Ee.length===0,xe=q("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(ff,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Po,{className:q("gap-0 p-1.5",xe),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(Sd,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(Kr,{shortcut:"mod+b"})]})]})}),u.jsxs(Do,{className:q("gap-2 px-1 py-1",xe),children:[u.jsxs(Dr,{className:"items-center gap-0.5",children:[P.map(W=>u.jsx(Si,{document:W,compact:!0},W.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(Dr,{className:"items-center gap-0.5",children:[D.map(W=>u.jsx(Si,{document:W,compact:!0},W.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(Po,{className:q("gap-0 p-2",xe),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:y,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($g,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(Kr,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(Lg,{"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:M,type:"text",value:I,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:W=>z(W.target.value),onKeyDown:W=>{W.key==="Escape"&&(W.preventDefault(),z(""),W.currentTarget.blur())},className:q("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 W;z(""),(W=M.current)==null||W.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(xn,{})}):u.jsx(wf,{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(Do,{className:q("gap-0 px-2 pb-2",xe),children:ye?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 W;z(""),(W=M.current)==null||W.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(Oo,{count:(V?se.length:P.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:P.length<2,onClick:()=>H(!0),children:u.jsx(xd,{})})}),u.jsx(Ye,{side:"bottom",children:P.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(Dr,{className:"gap-0.5",children:se.length>0?se.map(W=>u.jsx(Si,{document:W,query:V},W.name)):u.jsx(hl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]}),(re.length>0||!V)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Oo,{count:(V?re.length:D.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(Dr,{className:"gap-0.5",children:re.length>0?re.map(W=>u.jsx(Si,{document:W,query:V},W.name)):u.jsx(hl,{icon:nn,label:"New theme",onClick:()=>g(!0)})})]}),!V&&u.jsx(Yb,{}),(de.length>0||ge.length>0||Ee.length>0)&&u.jsx("div",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:u.jsx(oy,{documents:de,themes:ge,plugins:Ee,openNames:ie,query:V,expandedGroups:O,onToggleGroup:oe,onQuickAdd:Z,onShowPluginDetails:W=>{j(W),S(!0)},isPluginSelected:T,onTogglePlugin:m,isApplyingPlugins:w,selectedPluginCount:C.size})})]})})]}),u.jsx(pf,{className:q("border-sidebar-border/70 gap-0 border-t p-1.5",xe),children:u.jsx("div",{className:q("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(ly,{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(Hi,{mode:"create",shouldReset:!f,postSubmit:U,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(Hi,{mode:"create",shouldReset:!h,postSubmit:$,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(Ct,{open:v,onOpenChange:W=>{S(W),W||j(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(ey,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:b})})}),u.jsx(px,{open:N,onOpenChange:H})]})}const _l=x.memo(uy),cy=x.lazy(()=>gd(()=>import("./editor-Cugq4RzH.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function jl(){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(cy,{})})}const dy=x.lazy(()=>gd(()=>import("./preview-B_B09gpA.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function Nl(){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(dy,{})})}const{createElement:hr,createContext:fy,forwardRef:kf,useCallback:gt,useContext:Sf,useEffect:zn,useImperativeHandle:_f,useLayoutEffect:py,useMemo:hy,useRef:wt,useState:or}=Oc,El=Oc[`useId${Math.random()}`.slice(0,5)],my=py,js=fy(null);js.displayName="PanelGroupContext";const On=my,gy=typeof El=="function"?El:()=>null;let xy=0;function ya(e=null){const t=gy(),n=wt(e||t||null);return n.current===null&&(n.current=""+xy++),e??n.current}function jf({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=Sf(js);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:j,getPanelSize:m,getPanelStyle:T,groupId:C,isPanelCollapsed:w,reevaluatePanelConstraints:N,registerPanel:H,resizePanel:O,unregisterPanel:_}=S,I=ya(o),z=wt({callbacks:{onCollapse:c,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:a,minSize:l},id:I,idIsFromProps:o!==void 0,order:p});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:A,constraints:P}=z.current,D={...P};z.current.id=I,z.current.idIsFromProps=o!==void 0,z.current.order=p,A.onCollapse=c,A.onExpand=d,A.onResize=f,P.collapsedSize=n,P.collapsible=r,P.defaultSize=i,P.maxSize=a,P.minSize=l,(D.collapsedSize!==P.collapsedSize||D.collapsible!==P.collapsible||D.maxSize!==P.maxSize||D.minSize!==P.minSize)&&N(z.current,D)}),On(()=>{const A=z.current;return H(A),()=>{_(A)}},[p,I,H,_]),_f(s,()=>({collapse:()=>{b(z.current)},expand:A=>{j(z.current,A)},getId(){return I},getSize(){return m(z.current)},isCollapsed(){return w(z.current)},isExpanded(){return!w(z.current)},resize:A=>{O(z.current,A)}}),[b,j,m,w,I,O]);const M=T(z.current,i);return hr(g,{...v,children:e,className:t,id:o,style:{...M,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":C,"data-panel-id":I,"data-panel-size":parseFloat(""+M.flexGrow).toFixed(1)})}const Nf=kf((e,t)=>hr(jf,{...e,forwardedRef:t}));jf.displayName="Panel";Nf.displayName="forwardRef(Panel)";let Mo=null,An=null;function by(e,t){if(t){const n=(t&Af)!==0,r=(t&zf)!==0,i=(t&Of)!==0,s=(t&Pf)!==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 yy(){An!==null&&(document.head.removeChild(An),Mo=null,An=null)}function Ws(e,t){const n=by(e,t);Mo!==n&&(Mo=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Ef(e){return e.type==="keydown"}function Cf(e){return e.type.startsWith("pointer")}function If(e){return e.type.startsWith("mouse")}function Ns(e){if(Cf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(If(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function vy(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function wy(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 ky(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Tl(e),b:Tl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;je(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Il(Cl(n.a)),b:Il(Cl(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 Sy=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function _y(e){var t;const n=getComputedStyle((t=Tf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function jy(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||_y(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"||Sy.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Cl(e){let t=e.length;for(;t--;){const n=e[t];if(je(n,"Missing node"),jy(n))return n}return null}function Il(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Tl(e){const t=[];for(;e;)t.push(e),e=Tf(e);return t}function Tf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Af=1,zf=2,Of=4,Pf=8,Ny=vy()==="coarse";let Zt=[],ar=!1,mn=new Map,Es=new Map;const Xr=new Set;function Ey(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),Xr.add(a),Qi(),function(){var d;Es.delete(e),Xr.delete(a);const f=(d=mn.get(o))!==null&&d!==void 0?d:1;if(mn.set(o,f-1),Qi(),f===1&&mn.delete(o),Zt.includes(a)){const p=Zt.indexOf(a);p>=0&&Zt.splice(p,1),wa(),i("up",!0,null)}}}function Al(e){const{target:t}=e,{x:n,y:r}=Ns(e);ar=!0,va({target:t,x:n,y:r}),Qi(),Zt.length>0&&(es("down",e),e.preventDefault(),e.stopPropagation())}function Ir(e){const{x:t,y:n}=Ns(e);if(ar&&e.buttons===0&&(ar=!1,es("up",e)),!ar){const{target:r}=e;va({target:r,x:t,y:n})}es("move",e),wa(),Zt.length>0&&e.preventDefault()}function Jn(e){const{target:t}=e,{x:n,y:r}=Ns(e);Es.clear(),ar=!1,Zt.length>0&&e.preventDefault(),es("up",e),va({target:t,x:n,y:r}),wa(),Qi()}function va({target:e,x:t,y:n}){Zt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Xr.forEach(i=>{const{element:s,hitAreaMargins:o}=i,a=s.getBoundingClientRect(),{bottom:l,left:c,right:d,top:f}=a,p=Ny?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)&&ky(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(wy(g.getBoundingClientRect(),a)){v=!0;break}g=g.parentElement}if(v)return}Zt.push(i)}})}function qs(e,t){Es.set(e,t)}function wa(){let e=!1,t=!1;Zt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;Es.forEach(r=>{n|=r}),e&&t?Ws("intersection",n):e?Ws("horizontal",n):t?Ws("vertical",n):yy()}function Qi(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Jn),n.removeEventListener("pointerdown",Al),n.removeEventListener("pointerleave",Ir),n.removeEventListener("pointermove",Ir)}),window.removeEventListener("pointerup",Jn),window.removeEventListener("pointercancel",Jn),Xr.size>0&&(ar?(Zt.length>0&&mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Jn),n.addEventListener("pointerleave",Ir),n.addEventListener("pointermove",Ir))}),window.addEventListener("pointerup",Jn),window.addEventListener("pointercancel",Jn)):mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Al,{capture:!0}),n.addEventListener("pointermove",Ir))}))}function es(e,t){Xr.forEach(n=>{const{setResizeHandlerState:r}=n,i=Zt.includes(n);r(e,i,t)})}function Cy(){const[e,t]=or(0);return gt(()=>t(n=>n+1),[])}function je(e,t){if(!e)throw console.error(t),Error(t)}const ka=10;function Rn(e,t,n=ka){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function on(e,t,n=ka){return Rn(e,t,n)===0}function Nt(e,t,n){return Rn(e,t,n)===0}function Iy(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];je(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(ka)),n}function Rr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Nt(e,0))return t;const o=[...t],[a,l]=r;je(a!=null,"Invalid first pivot index"),je(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const f=e<0?l:a,p=n[f];je(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(je(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,h)){const b=v-S;Rn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const f=e<0?a:l,p=n[f];je(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(je(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,v)){const b=S-h;Rn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const f=e<0?1:-1;let p=e<0?l:a,h=0;for(;;){const v=t[p];je(v!=null,`Previous layout not found for panel index ${p}`);const b=nr({panelConstraints:n,panelIndex:p,size:100})-v;if(h+=b,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];je(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(Iy(i,o))return i;{const f=e<0?l:a,p=t[f];je(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,b=e<0?l:a;for(;b>=0&&b<n.length;){const j=o[b];je(j!=null,`Previous layout not found for panel index ${b}`);const m=j+v,T=nr({panelConstraints:n,panelIndex:b,size:m});if(Nt(j,T)||(v-=T-j,o[b]=T),Nt(v,0))break;e>0?b--:b++}}}const d=o.reduce((f,p)=>p+f,0);return Nt(d,100)?o:i}function Ty({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,o=0;const a=n[0];je(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 Qr(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function Df(e,t,n=document){const i=Qr(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Rf(e,t,n){const r=Df(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Mf(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 Cs(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function Ay(e,t,n,r=document){var i,s,o,a;const l=Cs(t,r),c=Qr(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 zy({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:o}){wt({didWarnAboutMissingResizeHandle:!1}),On(()=>{if(!s)return;const a=Qr(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:d,valueNow:f}=Ty({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=a[l];if(p!=null){const h=i[l];je(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;je(a,"Eager values not found");const{panelDataArray:l}=a,c=Mf(n,s);je(c!=null,`No group found for id "${n}"`);const d=Qr(n,s);je(d,`No resize handles found for group id "${n}"`);const f=d.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");je(h,"Resize handle element has no handle id attribute");const[g,v]=Ay(n,h,l,s);if(g==null||v==null)return()=>{};const S=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const j=l.findIndex(m=>m.id===g);if(j>=0){const m=l[j];je(m,`No panel data found for index ${j}`);const T=r[j],{collapsedSize:C=0,collapsible:w,minSize:N=0}=m.constraints;if(T!=null&&w){const H=Rr({delta:Nt(T,C)?N-C:C-T,initialLayout:r,panelConstraints:l.map(O=>O.constraints),pivotIndices:Rf(n,h,s),prevLayout:r,trigger:"keyboard"});r!==H&&o(H)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{f.forEach(p=>p())}},[s,e,t,n,r,i,o])}function zl(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 $f(e,t){const n=e==="horizontal",{x:r,y:i}=Ns(t);return n?r:i}function Oy(e,t,n,r,i){const s=n==="horizontal",o=Cs(t,i);je(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute("data-panel-group-id");je(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=$f(n,e),d=Mf(a,i);je(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),p=s?f.width:f.height;return(c-l)/p*100}function Py(e,t,n,r,i,s){if(Ef(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:Oy(e,t,n,r,s)}function Dy({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];je(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];je(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];je(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 ji(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 Ry({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 My(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Ol(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 Lf(e){return`react-resizable-panels:${e}`}function Ff(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 Bf(e,t){try{const n=Lf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function $y(e,t,n){var r,i;const s=(r=Bf(e,n))!==null&&r!==void 0?r:{},o=Ff(t);return(i=s[o])!==null&&i!==void 0?i:null}function Ly(e,t,n,r,i){var s;const o=Lf(e),a=Ff(t),l=(s=Bf(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 Pl({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];je(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];je(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];je(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 Fy=100,Mr={getItem:e=>(Ol(Mr),Mr.getItem(e)),setItem:(e,t)=>{Ol(Mr),Mr.setItem(e,t)}},Dl={};function Zf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:o=null,keyboardResizeBy:a=null,storage:l=Mr,style:c,tagName:d="div",...f}){const p=ya(s),h=wt(null),[g,v]=or(null),[S,b]=or([]),j=Cy(),m=wt({}),T=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:[]}),_f(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:y}=N.current;return y},setLayout:y=>{const{onLayout:Z}=w.current,{layout:V,panelDataArray:ie}=N.current,se=Pl({layout:y,panelConstraints:ie.map(re=>re.constraints)});zl(V,se)||(b(se),N.current.layout=se,Z&&Z(se),Hn(ie,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}),zy({committedValuesRef:w,eagerValuesRef:N,groupId:p,layout:S,panelDataArray:N.current.panelDataArray,setLayout:b,panelGroupElement:h.current}),zn(()=>{const{panelDataArray:y}=N.current;if(e){if(S.length===0||S.length!==y.length)return;let Z=Dl[e];Z==null&&(Z=My(Ly,Fy),Dl[e]=Z);const V=[...y],ie=new Map(T.current);Z(e,V,ie,S,l)}},[e,S,l]),zn(()=>{});const H=gt(y=>{const{onLayout:Z}=w.current,{layout:V,panelDataArray:ie}=N.current;if(y.constraints.collapsible){const se=ie.map(Ee=>Ee.constraints),{collapsedSize:re=0,panelSize:de,pivotIndices:ge}=jn(ie,y,V);if(je(de!=null,`Panel size not found for panel "${y.id}"`),!on(de,re)){T.current.set(y.id,de);const ye=Xn(ie,y)===ie.length-1?de-re:re-de,xe=Rr({delta:ye,initialLayout:V,panelConstraints:se,pivotIndices:ge,prevLayout:V,trigger:"imperative-api"});ji(V,xe)||(b(xe),N.current.layout=xe,Z&&Z(xe),Hn(ie,xe,m.current))}}},[]),O=gt((y,Z)=>{const{onLayout:V}=w.current,{layout:ie,panelDataArray:se}=N.current;if(y.constraints.collapsible){const re=se.map(W=>W.constraints),{collapsedSize:de=0,panelSize:ge=0,minSize:Ee=0,pivotIndices:ye}=jn(se,y,ie),xe=Z??Ee;if(on(ge,de)){const W=T.current.get(y.id),Oe=W!=null&&W>=xe?W:xe,ve=Xn(se,y)===se.length-1?ge-Oe:Oe-ge,E=Rr({delta:ve,initialLayout:ie,panelConstraints:re,pivotIndices:ye,prevLayout:ie,trigger:"imperative-api"});ji(ie,E)||(b(E),N.current.layout=E,V&&V(E),Hn(se,E,m.current))}}},[]),_=gt(y=>{const{layout:Z,panelDataArray:V}=N.current,{panelSize:ie}=jn(V,y,Z);return je(ie!=null,`Panel size not found for panel "${y.id}"`),ie},[]),I=gt((y,Z)=>{const{panelDataArray:V}=N.current,ie=Xn(V,y);return Ry({defaultSize:Z,dragState:g,layout:S,panelData:V,panelIndex:ie})},[g,S]),z=gt(y=>{const{layout:Z,panelDataArray:V}=N.current,{collapsedSize:ie=0,collapsible:se,panelSize:re}=jn(V,y,Z);return je(re!=null,`Panel size not found for panel "${y.id}"`),se===!0&&on(re,ie)},[]),M=gt(y=>{const{layout:Z,panelDataArray:V}=N.current,{collapsedSize:ie=0,collapsible:se,panelSize:re}=jn(V,y,Z);return je(re!=null,`Panel size not found for panel "${y.id}"`),!se||Rn(re,ie)>0},[]),A=gt(y=>{const{panelDataArray:Z}=N.current;Z.push(y),Z.sort((V,ie)=>{const se=V.order,re=ie.order;return se==null&&re==null?0:se==null?-1:re==null?1:se-re}),N.current.panelDataArrayChanged=!0,j()},[j]);On(()=>{if(N.current.panelDataArrayChanged){N.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:Z,storage:V}=w.current,{layout:ie,panelDataArray:se}=N.current;let re=null;if(y){const ge=$y(y,se,V);ge&&(T.current=new Map(Object.entries(ge.expandToSizes)),re=ge.layout)}re==null&&(re=Dy({panelDataArray:se}));const de=Pl({layout:re,panelConstraints:se.map(ge=>ge.constraints)});zl(ie,de)||(b(de),N.current.layout=de,Z&&Z(de),Hn(se,de,m.current))}}),On(()=>{const y=N.current;return()=>{y.layout=[]}},[]);const P=gt(y=>{let Z=!1;const V=h.current;return V&&window.getComputedStyle(V,null).getPropertyValue("direction")==="rtl"&&(Z=!0),function(se){se.preventDefault();const re=h.current;if(!re)return()=>null;const{direction:de,dragState:ge,id:Ee,keyboardResizeBy:ye,onLayout:xe}=w.current,{layout:W,panelDataArray:Oe}=N.current,{initialLayout:Q}=ge??{},ve=Rf(Ee,y,re);let E=Py(se,y,de,ge,ye,re);const R=de==="horizontal";R&&Z&&(E=-E);const L=Oe.map(ee=>ee.constraints),te=Rr({delta:E,initialLayout:Q??W,panelConstraints:L,pivotIndices:ve,prevLayout:W,trigger:Ef(se)?"keyboard":"mouse-or-touch"}),K=!ji(W,te);(Cf(se)||If(se))&&C.current!=E&&(C.current=E,!K&&E!==0?R?qs(y,E<0?Af:zf):qs(y,E<0?Of:Pf):qs(y,0)),K&&(b(te),N.current.layout=te,xe&&xe(te),Hn(Oe,te,m.current))}},[]),D=gt((y,Z)=>{const{onLayout:V}=w.current,{layout:ie,panelDataArray:se}=N.current,re=se.map(W=>W.constraints),{panelSize:de,pivotIndices:ge}=jn(se,y,ie);je(de!=null,`Panel size not found for panel "${y.id}"`);const ye=Xn(se,y)===se.length-1?de-Z:Z-de,xe=Rr({delta:ye,initialLayout:ie,panelConstraints:re,pivotIndices:ge,prevLayout:ie,trigger:"imperative-api"});ji(ie,xe)||(b(xe),N.current.layout=xe,V&&V(xe),Hn(se,xe,m.current))},[]),U=gt((y,Z)=>{const{layout:V,panelDataArray:ie}=N.current,{collapsedSize:se=0,collapsible:re}=Z,{collapsedSize:de=0,collapsible:ge,maxSize:Ee=100,minSize:ye=0}=y.constraints,{panelSize:xe}=jn(ie,y,V);xe!=null&&(re&&ge&&on(xe,se)?on(se,de)||D(y,de):xe<ye?D(y,ye):xe>Ee&&D(y,Ee))},[D]),$=gt((y,Z)=>{const{direction:V}=w.current,{layout:ie}=N.current;if(!h.current)return;const se=Cs(y,h.current);je(se,`Drag handle element not found for id "${y}"`);const re=$f(V,Z);v({dragHandleId:y,dragHandleRect:se.getBoundingClientRect(),initialCursorPosition:re,initialLayout:ie})},[]),X=gt(()=>{v(null)},[]),k=gt(y=>{const{panelDataArray:Z}=N.current,V=Xn(Z,y);V>=0&&(Z.splice(V,1),delete m.current[y.id],N.current.panelDataArrayChanged=!0,j())},[j]),oe=hy(()=>({collapsePanel:H,direction:r,dragState:g,expandPanel:O,getPanelSize:_,getPanelStyle:I,groupId:p,isPanelCollapsed:z,isPanelExpanded:M,reevaluatePanelConstraints:U,registerPanel:A,registerResizeHandle:P,resizePanel:D,startDragging:$,stopDragging:X,unregisterPanel:k,panelGroupElement:h.current}),[H,g,r,O,_,I,p,z,M,U,A,P,D,$,X,k]),G={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return hr(js.Provider,{value:oe},hr(d,{...f,children:t,className:n,id:s,ref:h,style:{...G,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const Vf=kf((e,t)=>hr(Zf,{...e,forwardedRef:t}));Zf.displayName="PanelGroup";Vf.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 By({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){zn(()=>{if(e||n==null||r==null)return;const i=Cs(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");je(a,`No group element found for id "${a}"`);const l=Qr(a,r),c=Df(a,t,r);je(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 Uf({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=Sf(js);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:b,groupId:j,registerResizeHandle:m,startDragging:T,stopDragging:C,panelGroupElement:w}=S,N=ya(i),[H,O]=or("inactive"),[_,I]=or(!1),[z,M]=or(null),A=wt({state:H});On(()=>{A.current.state=H}),zn(()=>{if(n)M(null);else{const $=m(N);M(()=>$)}},[n,N,m]);const P=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,D=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return zn(()=>{if(n||z==null)return;const $=g.current;return je($,"Element ref not attached"),Ey(N,$,b,{coarse:P,fine:D},(k,oe,G)=>{if(oe)switch(k){case"down":{O("drag"),je(G,'Expected event to be defined for "down" action'),T(N,G);const{onDragging:y}=v.current;y&&y(!0);break}case"move":{const{state:y}=A.current;y!=="drag"&&O("hover"),je(G,'Expected event to be defined for "move" action'),z(G);break}case"up":{O("hover"),C();const{onDragging:y}=v.current;y&&y(!1);break}}else O("inactive")})},[P,b,n,D,m,N,z,T,C]),By({disabled:n,handleId:N,resizeHandler:z,panelGroupElement:w}),hr(d,{...f,children:e,className:t,id:i,onBlur:()=>{I(!1),s==null||s()},onFocus:()=>{I(!0),a==null||a()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":b,"data-panel-group-id":j,"data-resize-handle":"","data-resize-handle-active":H==="drag"?"pointer":_?"keyboard":void 0,"data-resize-handle-state":H,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":N})}Uf.displayName="PanelResizeHandle";const Zy=({className:e,...t})=>u.jsx(Vf,{className:q("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Gs=Nf,Rl=({withHandle:e,className:t,...n})=>u.jsx(Uf,{className:q("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(Fg,{className:"h-2.5 w-2.5"})})}),Jf=x.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:q("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}));Jf.displayName="Textarea";class Vy{constructor(t){Xa(this,"client");this.client=ax.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 Uy=new Vy;function Jy(){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 ${wi.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(hd.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,b=v.status==="HIT"?"HIT":v.status==="MISS"?"MISS":"UNKNOWN",j=b==="HIT"?`Served from cache (Hit rate: ${v.hitRate})`:`Generated fresh ${wi.toLowerCase()}`;o==null||o("finalizing",j);const m=globalThis.atob(g.document),T=new Uint8Array(m.length);for(let w=0;w<m.length;w++)T[w]=m.charCodeAt(w);const C=new Blob([T],{type:g.contentType});if(C.size===0)throw new Error(`Received empty ${wi.toLowerCase()} from API`);return{name:r,text:i,blob:C,filename:g.filename,fileId:g.fileId,cacheStatus:b,cacheHitRate:v.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${wi} 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 Hy(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 Wy({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=Se.useState("custom");Se.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(yn,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(Ne,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const Ml=ot==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],Ys={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function qy({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:b,chatOpen:j,onTogglePreview:m,previewOpen:T}){const C=v!=="docxjs",[w,N]=x.useState(!1),[H,O]=x.useState(!1),[_,I]=x.useState(!1),[z,M]=x.useState(!1),[A,P]=x.useState(!1),[D,U]=x.useState(!1),[$,X]=x.useState(null),{toast:k}=vr(),{generateDocument:oe}=Jy(),G=x.useContext(Ed),y=x.useCallback(()=>{const Q={},{customThemes:ve}=G.getState();return Object.values(ve).forEach(E=>{E.valid&&E.parsed&&(Q[E.name]=E.parsed)}),Q},[G]),Z=Se.useMemo(()=>{if(!p)return[];try{const Q=JSON.parse(p);return[...(ot==="pptx"?pg:hg)(Q)].filter(E=>!mg(E))}catch{return[]}},[p]),[V,ie]=x.useState(!1),se=x.useCallback(async()=>{if(t){N(!0);try{await new Promise(Q=>setTimeout(Q,100)),Mi(`${e}${jr}`,t)}finally{setTimeout(()=>N(!1),500)}}},[t,e]),re=x.useCallback(async()=>{if(t){if(Z.length===0){await se();return}ie(!0)}},[t,Z.length,se]),de=x.useCallback(async Q=>{var ve;if(p){N(!0);try{const E=await oe(e,p,y(),void 0,{bypassCache:!0,fonts:{mode:Q}});if(E.blob.size===0)k({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Mi(`${e}${jr}`,E.blob);const R=(ve=E.warnings)==null?void 0:ve.find(L=>{var te,K;return((te=L.context)==null?void 0:te.code)==="FONT_MODE_SUBSTITUTED"||((K=L.context)==null?void 0:K.code)==="FONT_MODE_CUSTOM"});R&&k({title:Q==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:R.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,y]),ge=x.useCallback(async()=>{if(!(!g||g.length===0)){O(!0);try{const Q=Hy(g);if(!Q){k({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const ve=await oe("warnings",JSON.stringify(Q,null,2),{});ve&&typeof ve=="object"&&"blob"in ve&&ve.blob&&(Mi(`${e}-warnings${jr}`,ve.blob),k({title:"Warnings downloaded",description:`Downloaded warnings document with ${g.length} warning(s).`}))}catch(Q){console.error("Failed to generate warnings document:",Q),k({title:"Download failed",description:Q instanceof Error?Q.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>O(!1),500)}}},[g,e,oe,k]),Ee=x.useCallback(async()=>{const Q=r==null?void 0:r.current;if(Q!=null&&Q.src){I(!0);try{await new Promise(E=>{let R=null,L=!1;const te=()=>{R&&(clearTimeout(R),R=null),Q.removeEventListener("load",ee),Q.removeEventListener("error",ue)},K=()=>{L||(L=!0,te(),E())},ee=()=>K(),ue=()=>K();Q.addEventListener("load",ee),Q.addEventListener("error",ue),R=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),K()},5e3);const be=Q.src,B=be.includes("?")?"&":"?",Y=Date.now();Q.src=`${be}${B}_reload=${Y}`})}catch(ve){console.error("Iframe reload failed:",ve)}finally{I(!1)}}},[r]),ye=x.useCallback(async()=>{M(!0);try{await Uy.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(Q){console.error("Failed to clear cache:",Q),k({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{M(!1)}},[k]),xe=h??p,W=x.useCallback(()=>{var E,R;if(!xe){k({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(xe)}catch{k({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}U(!0);const Q=(async()=>{const L=await fetch(`/api/${ot}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:xe,customThemes:y(),options:{sourceName:e}})});if(!L.ok){let K=`Request failed with status ${L.status}`;try{const ee=await L.json(),ue=ee.error??ee.message;typeof ue=="string"&&ue&&(K=ue)}catch{}throw new Error(K)}const te=await L.json();return JSON.stringify(te.data,null,2)})();let ve;typeof ClipboardItem<"u"&&((E=navigator.clipboard)!=null&&E.write)?ve=navigator.clipboard.write([new ClipboardItem({"text/plain":Q.then(L=>new Blob([L],{type:"text/plain"}))})]):(R=navigator.clipboard)!=null&&R.writeText?ve=Q.then(L=>navigator.clipboard.writeText(L)):ve=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await ve,k({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(L){let te=null;try{te=await Q}catch(K){console.error("Error fetching standard components:",K),k({title:"Failed to get standard components",description:K instanceof Error?K.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",L),X(te)}finally{U(!1)}})()},[xe,e,y,k]),Oe=x.useCallback(async()=>{if($!=null)try{await navigator.clipboard.writeText($),k({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),X(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(kd,{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 ",jr," 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(Ne,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:o,"aria-label":"Render preview",disabled:a||l||T===!1,children:[l?u.jsx(sn,{size:"sm"}):u.jsx(Bg,{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:T===!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(ba,{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(Ne,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:Ee,disabled:_||a||l,children:_?u.jsx(sn,{size:"sm"}):u.jsx(Zg,{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(Ne,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||w||a,onClick:re,children:[w?u.jsx(sn,{size:"sm"}):u.jsx(Vg,{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 ",jr]})})]}),g&&g.length>0&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ne,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:H||a,onClick:ge,children:H?u.jsx(sn,{size:"sm"}):u.jsx(_d,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("p",{children:["Download warnings (",g.length,")"]})})]}),v&&S&&u.jsxs(qr,{value:v,onValueChange:S,children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(cr,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(Gr,{placeholder:"Renderer"})})}),u.jsx(Ye,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(dr,{className:"text-sidebar-foreground",children:Ml.map(Q=>u.jsxs(Dn,{value:Q,children:[u.jsxs(qe,{children:[u.jsx(Ge,{tabIndex:-1,children:Ys[Q][0]}),u.jsx(Ye,{children:Ys[Q][1]})]})," ",Q]},Q))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(ks,{children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ss,{asChild:!0,children:u.jsx(Ne,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(vd,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ye,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(hi,{align:"end",className:"w-52",children:[d&&u.jsxs(Lt,{onClick:d,children:[u.jsx(Ug,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),f&&u.jsxs(Lt,{onClick:f,children:[u.jsx(ko,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Lt,{onClick:c,children:[u.jsx(So,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),xe?u.jsxs(Lt,{onClick:W,disabled:D,children:[u.jsx(_o,{className:"h-4 w-4 mr-2"}),D?"Copying...":"Copy standard components"]}):u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs(Lt,{disabled:!0,children:[u.jsx(_o,{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(fr,{}),u.jsxs(Lt,{onClick:()=>P(!0),disabled:z,className:"text-destructive focus:text-destructive",children:[u.jsx(la,{className:"h-4 w-4 mr-2"}),z?"Clearing...":"Clear all caches"]}),v&&S&&u.jsxs(u.Fragment,{children:[u.jsx(fr,{className:"lg:hidden"}),Ml.map(Q=>u.jsxs(Lt,{className:"lg:hidden",onClick:()=>S(Q),children:[u.jsx("span",{className:"mr-2",children:v===Q?"●":"○"}),Ys[Q][0]," ",Q]},Q))]})]})]}),m&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ne,{variant:T?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:m,children:T?u.jsx(jd,{className:"h-3.5 w-3.5"}):u.jsx(Jg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[T?"Hide":"Show"," Preview"," ",u.jsx(Kr,{shortcut:"mod+shift+p"})]})})]}),b&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ne,{variant:j?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:b,children:u.jsx(Nd,{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(Kr,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(Wy,{open:V,onClose:()=>ie(!1),nonSafeFonts:Z,onChoose:de}),u.jsx(Ct,{open:$!=null,onOpenChange:Q=>{Q||X(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(Jf,{readOnly:!0,value:$??"",className:"h-64 font-mono text-xs",onFocus:Q=>Q.currentTarget.select()}),u.jsxs(yn,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>X(null),children:"Close"}),u.jsx(Ne,{size:"sm",onClick:Oe,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:A,onOpenChange:P,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(yn,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>P(!1),children:"Cancel"}),u.jsx(Ne,{variant:"destructive",size:"sm",disabled:z,onClick:async()=>{await ye(),P(!1)},children:z?u.jsx(sn,{size:"sm"}):"Clear"})]})]})})]})}const Gy=Se.memo(qy),Hf=lg,Sa=x.forwardRef(({className:e,...t},n)=>u.jsx(dd,{ref:n,className:q("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Sa.displayName=dd.displayName;const ei=x.forwardRef(({className:e,...t},n)=>u.jsx(fd,{ref:n,className:q("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}));ei.displayName=fd.displayName;const ti=x.forwardRef(({className:e,...t},n)=>u.jsx(pd,{ref:n,className:q("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));ti.displayName=pd.displayName;async function Yy(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 Ky(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 Xy(e){const t=Ky(e);return Yy(t)}const Qy=({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),[b,j]=x.useState(!1),{toast:m}=vr(),T=Bt(M=>M.selectedPlugins),C=Array.from(T);x.useEffect(()=>{n&&i(n)},[n]);const w=x.useCallback(async()=>{d(!0),g(null);try{const M=await Ls.fetchDocumentSchema(C);o(M)}catch(M){const A=M instanceof Error?M.message:"Failed to load document schema";g(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{d(!1)}},[C,m]),N=x.useCallback(async()=>{if(!a){p(!0),S(null);try{const M=await Ls.fetchThemeSchema();l(M)}catch(M){const A=M instanceof Error?M.message:"Failed to load theme schema";S(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{p(!1)}}},[a,m]),[H,O]=x.useState([]);x.useEffect(()=>{e||(o(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const M=C.length!==H.length||C.some((A,P)=>A!==H[P]);r==="document"?(!s||M)&&(M&&(Ls.clearPluginSchemaCache(),O([...C])),c||w()):r==="theme"&&!a&&!f&&N()},[r,e,s,a,c,f,C,H,w,N]);const _=C.length,I=r==="document"?s:a,z=async()=>{if(I)try{await Xy(I)&&(j(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>j(!1),2e3))}catch(M){console.error("Copy failed:",M)}};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(Hf,{value:r,onValueChange:M=>i(M),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Sa,{children:[u.jsxs(ei,{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(ei,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(Ne,{variant:"ghost",size:"icon",onClick:z,disabled:b||!I,"aria-label":"Copy schema",children:b?u.jsx(bn,{className:"h-4 w-4"}):u.jsx(bs,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(ti,{value:"document",className:"h-full",children:u.jsx(Xi,{schema:s,loading:c,error:h||void 0})}),u.jsx(ti,{value:"theme",className:"h-full",children:u.jsx(Xi,{schema:a,loading:f,error:v||void 0})})]})]})]})})};function ev(e,t,n){if(t.length===0)return n;const r=$l(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=$l(l,a);i[o]=c,i=c}return i[t[t.length-1]]=n,r}function $l(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const tv={safe:[],google:[]};function nv(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 rv(){const e=Pe(i=>i.activeTab),t=Pe(i=>i.documents),n=Pe(i=>i.documentTypes),r=Pe(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 iv(){const e=Pe(r=>r.activeTab),t=Pe(r=>r.documents),n=Pe(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=ev(o,r,i);return n(e,JSON.stringify(a,null,2)),{ok:!0,name:e}},[e,t,n])}function sv(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 Ll(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const ov=({open:e,onOpenChange:t})=>{const n=Di(D=>D.open),r=Di(D=>D.contextual),i=Di(D=>D.close),s=e??n,o=r,a=x.useCallback(D=>{t&&t(D),D||i()},[t,i]),[l,c]=x.useState(tv),[d,f]=x.useState(!1),[p,h]=x.useState(""),[g,v]=x.useState("safe"),[S,b]=x.useState(null),[j,m]=x.useState(null),{toast:T}=vr(),C=rv(),w=iv(),N=Pe(D=>D.activeTab),H=Pe(D=>D.documentTypes),O=N&&H[N]==="application/json+theme",_=!!o||O;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(f(!0),fetch("/api/fonts/catalog").then(D=>D.json()).then(D=>c(D)).catch(D=>{T({variant:"destructive",title:"Font catalog unavailable",description:D.message})}).finally(()=>f(!1))))},[s,l,T]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const D of l.google)nv(D.family,D.weights)},[g,l]);const I=x.useMemo(()=>l.safe.filter(D=>D.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),z=x.useMemo(()=>l.google.filter(D=>D.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),M=x.useCallback(async D=>{try{await navigator.clipboard.writeText(D),m(D),setTimeout(()=>m(null),1500)}catch{T({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[T]),A=x.useCallback(async(D,U,$)=>{b(D);try{const X=C(k=>(sv(k,$,D),k));if(!X.ok){T({variant:"destructive",title:"Could not insert font",description:X.error});return}T({title:"Font inserted",description:`${D} set as ${$} font in "${X.name}".`})}finally{b(null)}},[C,T]),P=x.useCallback(async D=>{if(o){b(D);try{const U=w(o.jsonPath,D);if(!U.ok){T({variant:"destructive",title:"Could not insert font",description:U.error});return}T({title:"Font inserted",description:`${D} set at ${Ll(o.jsonPath)}.`}),a(!1)}finally{b(null)}}},[o,w,T,a]);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 ${Ll(o.jsonPath)}`:"Fonts"})}),!o&&!O&&u.jsx(Gi,{children:u.jsxs(Yi,{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(Hf,{value:g,onValueChange:D=>v(D),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Sa,{children:[u.jsxs(ei,{value:"safe",children:["Safe",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(ei,{value:"google",children:["Google",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]})]}),u.jsx(fi,{type:"search",placeholder:"Search fonts...",value:p,onChange:D=>h(D.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(ti,{value:"safe",className:"m-0",children:d&&I.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(jo,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:I.map(D=>u.jsx(Fl,{family:D,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${D}", sans-serif`},onCopy:()=>M(D),copied:j===D,contextual:!!o,onUseThis:()=>P(D),onInsertHeading:()=>A(D,"safe","heading"),onInsertBody:()=>A(D,"safe","body"),applying:S===D,disabled:!_},D))})}),u.jsx(ti,{value:"google",className:"m-0",children:d&&z.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(jo,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:z.map(D=>u.jsx(Fl,{family:D.family,meta:u.jsxs("span",{className:"text-xs",children:[D.category," · ",D.weights.length," weights"]}),previewStyle:{fontFamily:`"${D.family}", sans-serif`},onCopy:()=>M(D.family),copied:j===D.family,contextual:!!o,onUseThis:()=>P(D.family),onInsertHeading:()=>A(D.family,"google","heading"),onInsertBody:()=>A(D.family,"google","body"),applying:S===D.family,disabled:!_,extraAction:u.jsx(lv,{family:D.family,weights:D.weights,hasItalic:D.hasItalic})},D.family))})})]})]})]})})},av="The quick brown fox jumps over the lazy dog",lv=({family:e,weights:t,hasItalic:n})=>{const r=x.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(ks,{children:[u.jsx(Ss,{asChild:!0,children:u.jsx(Ne,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(hi,{align:"end",className:"min-w-[260px]",children:[u.jsxs(nf,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(fr,{}),r.map(i=>{const s=gg[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)})]})]})},Fl=({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:av}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Ne,{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(Ne,{size:"sm",variant:"secondary",onClick:a,disabled:c||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Ne,{size:"sm",variant:"secondary",onClick:l,disabled:c||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,u.jsx(Ne,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(bn,{className:"h-4 w-4"}):u.jsx(bs,{className:"h-4 w-4"})})]})]});function Bl({previewOpen:e,onTogglePreview:t}){const n=rn(O=>O.name||""),r=rn(O=>O.blob),i=rn(O=>O.isGenerating),s=rn(O=>O.text),o=rn(O=>O.warnings),a=rn(O=>O.isRendering),l=ki(O=>O.autoReload),c=ki(O=>O.renderingLibrary),d=ki(O=>O.setSettings),f=ki(O=>O.useGlobalPreviewHeader??!0),p=Pe(O=>O.activeTab),h=Pe(O=>O.documentTypes),g=p&&h[p]==="application/json+theme"?"theme":"document",v=Pe(O=>{var _;return O.activeTab&&O.documentTypes[O.activeTab]!=="application/json+theme"?(_=O.documents.find(I=>I.name===O.activeTab))==null?void 0:_.text:void 0}),S=Re(O=>O.chatOpen),b=Re(O=>O.toggleChat),[j,m]=Se.useState(!1),T=Di(O=>O.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"))},[]),H=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(Gy,{name:H,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:C,onManualRender:w,isGenerating:i,isRendering:!!a,onShowCacheMetrics:N,onShowSchemas:()=>m(!0),onShowFonts:()=>T(),documentText:s,editorDocumentText:v,warnings:o,renderingLibrary:c,setRenderingLibrary:O=>d({renderingLibrary:O}),onToggleChat:b,chatOpen:S,onTogglePreview:t,previewOpen:e}),u.jsx(Qy,{open:j,onOpenChange:m,defaultTab:g==="theme"?"theme":"document"}),u.jsx(ov,{})]})}function uv(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const cv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,dv=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,fv={};function Zl(e,t){return(fv.jsx?dv:cv).test(e)}const pv=/[ \t\n\f\r]/g;function hv(e){return typeof e=="object"?e.type==="text"?Vl(e.value):!1:Vl(e)}function Vl(e){return e.replace(pv,"")===""}class mi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}mi.prototype.normal={};mi.prototype.property={};mi.prototype.space=void 0;function Wf(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new mi(n,r,t)}function $o(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 mv=0;const ke=Ln(),nt=Ln(),Lo=Ln(),ne=Ln(),Ze=Ln(),lr=Ln(),jt=Ln();function Ln(){return 2**++mv}const Fo=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:nt,commaOrSpaceSeparated:jt,commaSeparated:lr,number:ne,overloadedBoolean:Lo,spaceSeparated:Ze},Symbol.toStringTag,{value:"Module"})),Ks=Object.keys(Fo);class _a extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),Ul(this,"space",i),typeof r=="number")for(;++s<Ks.length;){const o=Ks[s];Ul(this,Ks[s],(r&Fo[o])===Fo[o])}}}_a.prototype.defined=!0;function Ul(e,t,n){n&&(e[t]=n)}function wr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new _a(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[$o(r)]=r,n[$o(s.attribute)]=r}return new mi(t,n,e.space)}const qf=wr({properties:{ariaActiveDescendant:null,ariaAtomic:nt,ariaAutoComplete:null,ariaBusy:nt,ariaChecked:nt,ariaColCount:ne,ariaColIndex:ne,ariaColSpan:ne,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:ne,ariaLive:null,ariaModal:nt,ariaMultiLine:nt,ariaMultiSelectable:nt,ariaOrientation:null,ariaOwns:Ze,ariaPlaceholder:null,ariaPosInSet:ne,ariaPressed:nt,ariaReadOnly:nt,ariaRelevant:null,ariaRequired:nt,ariaRoleDescription:Ze,ariaRowCount:ne,ariaRowIndex:ne,ariaRowSpan:ne,ariaSelected:nt,ariaSetSize:ne,ariaSort:null,ariaValueMax:ne,ariaValueMin:ne,ariaValueNow:ne,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function Gf(e,t){return t in e?e[t]:t}function Yf(e,t){return Gf(e,t.toLowerCase())}const gv=wr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:lr,acceptCharset:Ze,accessKey:Ze,action:null,allow:null,allowFullScreen:ke,allowPaymentRequest:ke,allowUserMedia:ke,alt:null,as:null,async:ke,autoCapitalize:null,autoComplete:Ze,autoFocus:ke,autoPlay:ke,blocking:Ze,capture:null,charSet:null,checked:ke,cite:null,className:Ze,cols:ne,colSpan:null,content:null,contentEditable:nt,controls:ke,controlsList:Ze,coords:ne|lr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Lo,draggable:nt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Ze,height:ne,hidden:Lo,high:ne,href:null,hrefLang:null,htmlFor:Ze,httpEquiv:Ze,id:null,imageSizes:null,imageSrcSet:null,inert:ke,inputMode:null,integrity:null,is:null,isMap:ke,itemId:null,itemProp:Ze,itemRef:Ze,itemScope:ke,itemType:Ze,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:ke,low:ne,manifest:null,max:null,maxLength:ne,media:null,method:null,min:null,minLength:ne,multiple:ke,muted:ke,name:null,nonce:null,noModule:ke,noValidate:ke,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:ke,optimum:ne,pattern:null,ping:Ze,placeholder:null,playsInline:ke,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:ke,referrerPolicy:null,rel:Ze,required:ke,reversed:ke,rows:ne,rowSpan:ne,sandbox:Ze,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:ne,sizes:null,slot:null,span:ne,spellCheck:nt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:ne,step:null,style:null,tabIndex:ne,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:nt,width:ne,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ze,axis:null,background:null,bgColor:null,border:ne,borderColor:null,bottomMargin:ne,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:ke,declare:ke,event:null,face:null,frame:null,frameBorder:null,hSpace:ne,leftMargin:ne,link:null,longDesc:null,lowSrc:null,marginHeight:ne,marginWidth:ne,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:ne,rules:null,scheme:null,scrolling:nt,standby:null,summary:null,text:null,topMargin:ne,valueType:null,version:null,vAlign:null,vLink:null,vSpace:ne,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:ne,security:null,unselectable:null},space:"html",transform:Yf}),xv=wr({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:ne,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:ne,amplitude:ne,arabicForm:null,ascent:ne,attributeName:null,attributeType:null,azimuth:ne,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:ne,by:null,calcMode:null,capHeight:ne,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:ne,diffuseConstant:ne,direction:null,display:null,dur:null,divisor:ne,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:ne,enableBackground:null,end:null,event:null,exponent:ne,externalResourcesRequired:null,fill:null,fillOpacity:ne,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:lr,g2:lr,glyphName:lr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:ne,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:ne,horizOriginX:ne,horizOriginY:ne,id:null,ideographic:ne,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:ne,k:ne,k1:ne,k2:ne,k3:ne,k4:ne,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:ne,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:ne,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:ne,overlineThickness:ne,paintOrder:null,panose1:null,path:null,pathLength:ne,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ze,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:ne,pointsAtY:ne,pointsAtZ:ne,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:ne,specularExponent:ne,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:ne,strikethroughThickness:ne,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:ne,strokeOpacity:ne,strokeWidth:null,style:null,surfaceScale:ne,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:ne,tableValues:null,target:null,targetX:ne,targetY:ne,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:ne,underlineThickness:ne,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:ne,values:null,vAlphabetic:ne,vMathematical:ne,vectorEffect:null,vHanging:ne,vIdeographic:ne,version:null,vertAdvY:ne,vertOriginX:ne,vertOriginY:ne,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:ne,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:Gf}),Kf=wr({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()}}),Xf=wr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:Yf}),Qf=wr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),bv={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"},yv=/[A-Z]/g,Jl=/-[a-z]/g,vv=/^data[-\w.:]+$/i;function wv(e,t){const n=$o(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"&&vv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Jl,Sv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Jl.test(s)){let o=s.replace(yv,kv);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=_a}return new i(r,t)}function kv(e){return"-"+e.toLowerCase()}function Sv(e){return e.charAt(1).toUpperCase()}const _v=Wf([qf,gv,Kf,Xf,Qf],"html"),ja=Wf([qf,xv,Kf,Xf,Qf],"svg");function jv(e){return e.join(" ").trim()}var Wn={},Xs,Hl;function Nv(){if(Hl)return Xs;Hl=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 Rb(e){const t=Et(Ae(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>Et(Ae(i,"cells")).length))}×${t.length}`;const n=Et(Ae(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?Et(r).length:Et(Ae(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function Mb(e){const t=st(Ae(e,"alt"));if(t)return vt(t);const n=st(Ae(e,"src"));if(n){if(n.startsWith("data:")){const i=n.slice(5).split(/[;,]/)[0];return i?`image (${i.split("/").pop()})`:"image"}const r=n.split(/[?#]/)[0].split("/").pop();if(r)return vt(r,40)}return"image"}function $b(e,t){var r;const n=st(Ae(t,"text"));switch(e){case"heading":{const i=Ro(Ae(t,"level"))??1;return{label:n?vt(n):"heading",detail:`H${i}`}}case"text":return{label:n?vt(n):"text",detail:st(Ae(t,"style"))};case"paragraph":return{label:n?vt(n):"paragraph"};case"chart":case"highcharts":{const i=st(Ae(t,"title"))??st(Ae(Ae(t,"options"),"title"));return{label:i?vt(i):e,detail:st(Ae(t,"type"))}}case"table":return{label:"table",detail:Rb(t)};case"image":return{label:Mb(t)};case"shape":return{label:st(Ae(t,"type"))??"shape"};case"list":{const i=Et(Ae(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=st(Ae(Ae(t,"meta"),"title"))??st(Ae(t,"title"));return{label:i?vt(i):"section"}}case"statistic":{const i=st(Ae(t,"value"))??((r=Ro(Ae(t,"value")))==null?void 0:r.toString()),s=st(Ae(t,"label"));return{label:vt(s??i??"statistic"),detail:i}}default:return{label:n?vt(n):e}}}function pr(e){if(e.type!=="object")return null;const t=st(Ae(e,"name"));return t?{name:t,props:Ae(e,"props"),childrenArr:Ae(e,"children")}:null}function Lb(e){let t;for(const n of Et(e)){const r=pr(n);if(!r)continue;const i=st(Ae(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return vt(i,48);r.name==="paragraph"&&t===void 0&&(t=vt(i,48))}}return t}function qi(e,t,n){let{label:r,detail:i}=$b(t.name,t.props);return r===t.name&&t.childrenArr&&(r=Lb(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:xf(t.childrenArr),reorder:n}}function xf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of Et(e)){const i=pr(r);i&&n.push(qi(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Fb(e){const t=Ae(e,"props"),n=st(Ae(Ae(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=Ae(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?pr(c):null,p=f?st(Ae(f.props,"text")):void 0;i(d==="title"?0:d==="subtitle"||d.startsWith("heading")?1:2,p)}const o=(a,l)=>{const c=pr(a);if(c){if(c.name==="text"||c.name==="heading"){const d=st(Ae(c.props,"text"));if(d){const f=st(Ae(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(Ae(e,"children")))o(a,0);return r?vt(r.text,48,!0):void 0}function Bb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[];let i=0;for(const s of Et(t)){const o=pr(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:Fb(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:xf(o.childrenArr),reorder:a})):r.push(qi(s,o,a))}return r}function Zb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const o of Et(t)){const a=pr(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=Ro(Ae(a.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=qi(o,a,l);c().push(f),i.push({level:d,node:f})}else c().push(qi(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 yl(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 Vb(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:yl(c),start:a.offset,end:a.offset+a.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:o.length===0?yl(i):void 0,start:n.offset,end:n.offset+n.length,children:o})}return t}function vl(e,t,n){if(!e.trim())return[];const r=Ob(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Vb(r):t==="pptx"?Bb(r):Zb(r);return bf(i,""),i}function bf(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,bf(n.children,n.id)})}function yf(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 Ub(e,t){const n=new Set;for(const r of t)for(const i of yf(e,r))n.add(i);return n}function Jb(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 Hb={slide:Cg,heading:Eg,text:ko,paragraph:Ng,chart:So,highcharts:So,table:jg,image:_g,shape:wd,list:Sg,toc:kg,section:Qa,columns:Qa,"text-box":ko,statistic:wg,key:wo};function Wb(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 qb(e){const t=e.lastIndexOf(".");return t===-1?"":e.slice(0,t)}function Gb(){const{activeTab:e,documentTypes:t}=Pe(ua(O=>({activeTab:O.activeTab,documentTypes:O.documentTypes}))),n=Pe(O=>{var _;return O.activeTab?(_=O.documents.find(I=>I.name===O.activeTab))==null?void 0:_.text:void 0}),r=qg(O=>e?O.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,o]=x.useState(()=>{try{const O=localStorage.getItem("dev-env.outline-open");return O?O==="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),b=x.useRef(a);b.current=a;const j=x.useRef(null),m=x.useRef(null),T=x.useCallback(()=>{var I;if(!e){l([]);return}const O=((I=r==null?void 0:r.editor.getModel())==null?void 0:I.getValue())??n??"",_=vl(O,ot,i);if(l(_),m.current!==e){m.current=e;const z=new Set;if(i==="document"&&ot==="docx")for(const M of _)M.kind==="heading"&&z.add(M.id);g(z),d(null)}},[e,r,n,i]);x.useEffect(()=>{T();const O=r==null?void 0:r.editor.getModel();if(!O)return;const _=tl(T,300),I=O.onDidChangeContent(()=>_());return()=>{_.cancel(),I.dispose()}},[T,r]),x.useEffect(()=>{if(!r)return;const{editor:O}=r,_=tl(()=>{const z=O.getModel(),M=O.getPosition();if(!z||!M)return;const A=z.getOffsetAt(M),P=yf(b.current,A);if(P.length===0){d(null);return}d(P[P.length-1]);const D=P.slice(0,-1);D.length&&g(U=>{if(D.every(X=>U.has(X)))return U;const $=new Set(U);for(const X of D)$.add(X);return $})},150),I=O.onDidChangeCursorPosition(()=>_());return()=>{_.cancel(),I.dispose()}},[r]),x.useEffect(()=>{if(!c||!j.current)return;const O=j.current.querySelector(`[data-oid="${CSS.escape(c)}"]`);O==null||O.scrollIntoView({block:"nearest"})},[c]),x.useEffect(()=>{if(!r){p(new Set);return}const{editor:O,monaco:_}=r,I=()=>{const M=O.getModel();if(!M)return;const A=_.editor.getModelMarkers({resource:M.uri}).filter(P=>P.severity===_.MarkerSeverity.Error).map(P=>M.getOffsetAt({lineNumber:P.startLineNumber,column:P.startColumn}));p(Ub(b.current,A))};I();const z=_.editor.onDidChangeMarkers(M=>{const A=O.getModel();A&&M.some(P=>P.toString()===A.uri.toString())&&I()});return()=>z.dispose()},[r,a]);const C=x.useCallback(O=>{g(_=>{const I=new Set(_);return I.has(O)?I.delete(O):I.add(O),I})},[]),w=x.useCallback(O=>{if(d(O.id),!r)return;const{editor:_,monaco:I}=r,z=_.getModel();if(!z)return;const M=z.getPositionAt(O.start),A=z.getPositionAt(O.end),P=new I.Range(M.lineNumber,M.column,A.lineNumber,A.column);_.revealRangeNearTopIfOutsideViewport(P,I.editor.ScrollType.Smooth),_.setPosition(M),_.focus();const D=_.deltaDecorations([],[{range:P,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>_.deltaDecorations(D,[]),700)},[r]),N=x.useCallback(O=>{var y;if(!r||!O.overId)return;const{editor:_,monaco:I,collapse:z}=r,M=_.getModel();if(!M)return;const A=M.getValue(),P=vl(A,ot,i),D=O.parentId?((y=Wb(P,O.parentId))==null?void 0:y.children)??[]:P,U=D.findIndex(Z=>Z.id===O.dragId),$=D.findIndex(Z=>Z.id===O.overId);if(U===-1||$===-1)return;let X=$+(O.overHalf==="after"?1:0);U<X&&(X-=1);const k=Jb(A,D,U,X);if(!k)return;const oe=M.getPositionAt(k.start),G=M.getPositionAt(k.end);_.executeEdits("outline-reorder",[{range:new I.Range(oe.lineNumber,oe.column,G.lineNumber,G.column),text:k.text}]),z==null||z.resyncDecorations()},[r,i]),H=x.useMemo(()=>{const O=[],_=(I,z,M)=>{var D,U;const A=(U=(D=I[0])==null?void 0:D.reorder)==null?void 0:U.groupId,P=I.length>1&&A!==void 0&&I.every($=>{var X;return((X=$.reorder)==null?void 0:X.groupId)===A});I.forEach($=>{const X=Hb[$.kind]??Ig,k=$.children.length>0,oe=h.has($.id),G=c===$.id,y=(v==null?void 0:v.overId)===$.id;O.push(u.jsxs("div",{"data-oid":$.id,role:"treeitem","aria-selected":G,"aria-expanded":k?oe:void 0,tabIndex:0,draggable:P,onClick:()=>w($),onKeyDown:Z=>{(Z.key==="Enter"||Z.key===" ")&&(Z.preventDefault(),w($)),Z.key==="ArrowRight"&&k&&!oe&&C($.id),Z.key==="ArrowLeft"&&k&&oe&&C($.id)},onDragStart:Z=>{Z.dataTransfer.setData("text/plain",$.id),Z.dataTransfer.effectAllowed="move",S({dragId:$.id,parentId:M,overId:null,overHalf:"before"})},onDragOver:Z=>{if(!v||v.dragId===$.id||qb(v.dragId)!==M)return;Z.preventDefault(),Z.dataTransfer.dropEffect="move";const V=Z.currentTarget.getBoundingClientRect(),ie=Z.clientY<V.top+V.height/2?"before":"after";(v.overId!==$.id||v.overHalf!==ie)&&S({...v,overId:$.id,overHalf:ie})},onDrop:Z=>{Z.preventDefault(),v&&N({...v,overId:$.id,overHalf:v.overHalf}),S(null)},onDragEnd:()=>S(null),className:q("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",G&&"bg-sidebar-accent font-medium text-sidebar-foreground",y&&(v==null?void 0:v.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",y&&(v==null?void 0:v.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+z*12},children:[k?u.jsx("span",{role:"button","aria-label":oe?"Collapse":"Expand",onClick:Z=>{Z.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:q("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(X,{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,z+1,$.id)})};return _(a,0,""),O},[a,h,c,f,v,w,C,N]);return e?u.jsxs("section",{className:"mt-3 shrink-0",children:[u.jsx(Oo,{count:a.length||void 0,actions:u.jsx($t,{"aria-label":s?"Collapse outline":"Expand outline","aria-expanded":s,onClick:()=>o(O=>!O),children:u.jsx(Pn,{className:q("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:H}):u.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/60",children:"No structure to show yet."}))]}):null}const Yb=x.memo(Gb);async function Kb(e,t){const n=JSON.stringify({name:e,props:t,children:[]},null,2);await navigator.clipboard.writeText(n)}const Yr=x.forwardRef(({className:e,children:t,...n},r)=>u.jsxs(ud,{ref:r,className:q("relative overflow-hidden",e),...n,children:[u.jsx(eg,{className:"h-full w-full rounded-[inherit]",children:t}),u.jsx(vf,{}),u.jsx(tg,{})]}));Yr.displayName=ud.displayName;const vf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>u.jsx(cd,{ref:r,orientation:t,className:q("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(ng,{className:"bg-border relative flex-1 rounded-full"})}));vf.displayName=cd.displayName;function ba({className:e,...t}){return u.jsx(rg,{"data-slot":"switch",className:q("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(ig,{"data-slot":"switch-thumb",className:q("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 Xb=di("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"}}),Gi=x.forwardRef(({className:e,variant:t,...n},r)=>u.jsx("div",{ref:r,role:"alert",className:q(Xb({variant:t}),e),...n}));Gi.displayName="Alert";const Qb=x.forwardRef(({className:e,...t},n)=>u.jsx("h5",{ref:n,className:q("mb-1 font-medium leading-none tracking-tight",e),...t}));Qb.displayName="AlertTitle";const Yi=x.forwardRef(({className:e,...t},n)=>u.jsx("div",{ref:n,className:q("text-sm [&_p]:leading-relaxed",e),...t}));Yi.displayName="AlertDescription";const Ki=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:q("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(ci,{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(Ki,{keyName:String(p),value:f,depth:n+1,isLast:p===t.length-1},p)):Object.entries(t).map(([f,p],h,g)=>u.jsx(Ki,{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&&","]})})]})]})});Ki.displayName="JsonNode";const Xi=x.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?u.jsxs("div",{className:q("space-y-4",r),children:[u.jsx(Ur,{className:"h-8 w-64"}),u.jsx(Ur,{className:"h-4 w-full"}),u.jsx(Ur,{className:"h-64 w-full"})]}):n?u.jsx(Gi,{variant:"destructive",className:r,children:u.jsx(Yi,{children:n})}):e?u.jsx(Yr,{className:q("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(Ki,{value:e})})}):u.jsx(Gi,{className:r,children:u.jsx(Yi,{children:"No schema available"})}));Xi.displayName="SchemaViewer";function ey({plugins:e,initialFocusedPlugin:t}){var m,T;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 Kb(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(Dg,{className:"size-3"});case"downstream":return u.jsx(Pg,{className:"size-3"});case"upstream":return u.jsx(yd,{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,b=(T=o==null?void 0:o.schema)==null?void 0:T.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(Tg,{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(Yr,{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 H=r(N.name),O=(o==null?void 0:o.name)===N.name;return u.jsxs("button",{onClick:()=>a(N),className:q("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",O?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[u.jsx("div",{className:q("size-1.5 rounded-full flex-none transition-colors",H?"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(ba,{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:q("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(wo,{className:"size-3.5"}),"Properties"]})}),b&&u.jsx("button",{onClick:()=>f("schema"),className:q("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(Ag,{className:"size-3.5"}),"Schema"]})}),j&&u.jsx("button",{onClick:()=>f("examples"),className:q("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(zg,{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(Yr,{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(ty,{name:C,prop:w},C))}),d==="schema"&&b&&u.jsx(Xi,{schema:o.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&j&&o.examples.map((C,w)=>u.jsxs("div",{className:q(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(Ne,{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(Og,{className:"size-3 mr-1 text-success"}),"Copied"]}):u.jsxs(u.Fragment,{children:[u.jsx(bs,{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&&!b&&!j&&u.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[u.jsx(wo,{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 ty({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:q("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(ci,{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 ny=sg,ry=og,iy=ag,sy={current:"Current directory",downstream:"Project"};function Hs({id:e,label:t,count:n,open:r,onToggle:i,children:s}){return u.jsxs(ny,{open:r,children:[u.jsxs(ry,{onClick:()=>i(e),className:q("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:q("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(iy,{children:u.jsx("div",{className:"border-sidebar-border/70 mt-0.5 ml-[13px] border-l pl-1",children:s})})]})}function wl({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:sy[e]??e})}function kl({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:q("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(ga,{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 oy({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=b=>i?!0:s.has(b),g=x.useMemo(()=>Sl(e),[e]),v=x.useMemo(()=>Sl(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(Hs,{id:"library-documents",label:"Project documents",count:e.length,open:h("library-documents"),onToggle:o,children:g.map(([b,j])=>u.jsxs(Se.Fragment,{children:[g.length>1&&u.jsx(wl,{location:b}),j.map(m=>u.jsx(kl,{name:m.name,subtitle:m.title,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!1)},m.path||m.name))]},b))}),t.length>0&&u.jsx(Hs,{id:"library-themes",label:"Project themes",count:t.length,open:h("library-themes"),onToggle:o,children:v.map(([b,j])=>u.jsxs(Se.Fragment,{children:[v.length>1&&u.jsx(wl,{location:b}),j.map(m=>u.jsx(kl,{name:m.name,subtitle:m.description,added:r.has(m.name),query:i,onSelect:()=>a(m.name,!0)},m.path||m.name))]},b))}),n.length>0&&u.jsx(Hs,{id:"library-plugins",label:"Plugins",count:`${p}/${n.length}`,open:h("library-plugins"),onToggle:o,children:n.map(b=>{const j=c(b.name),m=`plugin-switch-${b.filePath||b.name}`;return u.jsxs("div",{title:b.description?`${b.name} — ${b.description}`:b.name,className:q("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:q("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(ga,{text:b.name,query:i})})}),u.jsx($t,{"aria-label":`Details for ${b.name}`,onClick:T=>{T.stopPropagation(),l(b.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:u.jsx(kd,{})}),u.jsx(ba,{id:m,checked:j,onCheckedChange:()=>d(b),disabled:f,className:"shrink-0","aria-label":`Toggle ${b.name} plugin`})]},b.filePath||b.name)})})]}):null}function Sl(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 wf({children:e,className:t}){return u.jsx("kbd",{"data-slot":"kbd",className:q("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 ay({children:e,className:t}){return u.jsx("span",{className:q("inline-flex items-center gap-0.5",t),children:e})}const _i=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function Kr({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return _i?"⌘":"Ctrl";case"shift":return _i?"⇧":"Shift";case"alt":return _i?"⌥":"Alt";case"ctrl":return _i?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return u.jsx(ay,{className:t,children:r.map((i,s)=>u.jsx(wf,{children:i},s))})}function ly({className:e}={}){const{theme:t,setTheme:n}=md(),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(Ne,{variant:"ghost",size:"icon",onClick:i,className:e,children:[u.jsx(Rg,{className:"hidden dark:block"}),u.jsx(Mg,{className:"block dark:hidden"}),u.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),u.jsx(Ye,{children:u.jsx("p",{children:"Toggle theme"})})]})}function uy({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:o,openDocument:a}=Pe(ua(W=>({documents:W.documents,documentTypes:W.documentTypes,createDocument:W.createDocument,openDocument:W.openDocument}))),l=Eo(W=>W.updateTheme),c=Eo(W=>W.removeTheme),d=x.useContext(Ed),[f,p]=x.useState(!1),[h,g]=x.useState(!1),[v,S]=x.useState(!1),[b,j]=x.useState(null),m=Bt(W=>W.togglePlugin),T=Bt(W=>W.isPluginSelected),C=Bt(W=>W.selectedPlugins),w=Bt(W=>W.isApplyingPlugins),[N,H]=x.useState(!1),[O,_]=x.useState(new Set(["library-documents"])),[I,z]=x.useState(""),M=x.useRef(null),{toast:A}=vr(),P=i.filter(W=>s[W.name]!=="application/json+theme"),D=i.filter(W=>s[W.name]==="application/json+theme"),U=x.useCallback(()=>{p(!1)},[]),$=x.useCallback(()=>{g(!1)},[]),X=x.useRef(new Map);x.useEffect(()=>{const W=X.current,Oe=new Map;D.forEach(Q=>{Oe.set(Q.name,Q.text),W.get(Q.name)!==Q.text&&l(Q.name,Q.text)}),W.forEach((Q,ve)=>{Oe.has(ve)||c(ve)}),X.current=Oe},[D,l,c]);const k=x.useRef(!1);x.useEffect(()=>{if(k.current||!d)return;k.current=!0;const W=new Set(D.map(Q=>Q.name));Object.keys(d.getState().customThemes).forEach(Q=>{W.has(Q)||c(Q)})},[D,c,d]);const oe=x.useCallback(W=>{_(Oe=>{const Q=new Set(Oe);return Q.has(W)?Q.delete(W):Q.add(W),Q})},[]),{resolvedTheme:G}=md(),y=G==="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",Z=x.useCallback(async(W,Oe)=>{if(i.some(Q=>Q.name===W)){a(W);return}try{const Q=await fetch(`/api/discovery/${Oe?"themes":"documents"}/${encodeURIComponent(W)}/content`);if(!Q.ok)throw new Error(Q.statusText);const ve=await Q.text(),E=JSON.parse(ve);o(W,JSON.stringify(E,null,2)),a(W),A({title:`Added ${Oe?"theme":"document"}: ${W}`})}catch{A({title:"Failed to load",description:`Could not load ${W}`,variant:"destructive"})}},[i,o,a,A]);x.useEffect(()=>{if(n)return;const W=Oe=>{var E,R,L,te,K;if(Oe.key!=="/"||Oe.metaKey||Oe.ctrlKey||Oe.altKey)return;const Q=Oe.target,ve=(E=Q==null?void 0:Q.tagName)==null?void 0:E.toLowerCase();ve==="input"||ve==="textarea"||ve==="select"||Q!=null&&Q.isContentEditable||(R=Q==null?void 0:Q.closest)!=null&&R.call(Q,".monaco-editor")||(L=M.current)!=null&&L.closest('[aria-hidden="true"], [inert]')||(Oe.preventDefault(),(te=M.current)==null||te.focus(),(K=M.current)==null||K.select())};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[n]);const V=I.trim(),ie=x.useMemo(()=>new Set(i.map(W=>W.name)),[i]),se=x.useMemo(()=>P.filter(W=>cn(W.name,V)),[P,V]),re=x.useMemo(()=>D.filter(W=>cn(W.name,V)),[D,V]),de=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter(W=>cn(W.name,V)||cn(W.title??"",V)),[e,V]),ge=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter(W=>cn(W.name,V)||cn(W.description??"",V)),[e,V]),Ee=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter(W=>cn(W.name,V)||cn(W.description??"",V)),[e,V]),ye=V.length>0&&se.length===0&&re.length===0&&de.length===0&&ge.length===0&&Ee.length===0,xe=q("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return u.jsxs(u.Fragment,{children:[u.jsxs(ff,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?u.jsxs(u.Fragment,{children:[u.jsx(Po,{className:q("gap-0 p-1.5",xe),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(Sd,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Expand sidebar"}),u.jsx(Kr,{shortcut:"mod+b"})]})]})}),u.jsxs(Do,{className:q("gap-2 px-1 py-1",xe),children:[u.jsxs(Dr,{className:"items-center gap-0.5",children:[P.map(W=>u.jsx(Si,{document:W,compact:!0},W.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(Dr,{className:"items-center gap-0.5",children:[D.map(W=>u.jsx(Si,{document:W,compact:!0},W.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(Po,{className:q("gap-0 p-2",xe),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:y,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($g,{})})}),u.jsxs(Ye,{side:"right",className:"flex items-center gap-2",children:[u.jsx("span",{children:"Collapse sidebar"}),u.jsx(Kr,{shortcut:"mod+b"})]})]})]}),u.jsxs("div",{className:"relative mt-2",children:[u.jsx(Lg,{"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:M,type:"text",value:I,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:W=>z(W.target.value),onKeyDown:W=>{W.key==="Escape"&&(W.preventDefault(),z(""),W.currentTarget.blur())},className:q("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 W;z(""),(W=M.current)==null||W.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:u.jsx(xn,{})}):u.jsx(wf,{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(Do,{className:q("gap-0 px-2 pb-2",xe),children:ye?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 W;z(""),(W=M.current)==null||W.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(Oo,{count:(V?se.length:P.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:P.length<2,onClick:()=>H(!0),children:u.jsx(xd,{})})}),u.jsx(Ye,{side:"bottom",children:P.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(Dr,{className:"gap-0.5",children:se.length>0?se.map(W=>u.jsx(Si,{document:W,query:V},W.name)):u.jsx(hl,{icon:nn,label:"New document",onClick:()=>p(!0)})})]}),(re.length>0||!V)&&u.jsxs("section",{className:"mt-3",children:[u.jsx(Oo,{count:(V?re.length:D.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(Dr,{className:"gap-0.5",children:re.length>0?re.map(W=>u.jsx(Si,{document:W,query:V},W.name)):u.jsx(hl,{icon:nn,label:"New theme",onClick:()=>g(!0)})})]}),!V&&u.jsx(Yb,{}),(de.length>0||ge.length>0||Ee.length>0)&&u.jsx("div",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:u.jsx(oy,{documents:de,themes:ge,plugins:Ee,openNames:ie,query:V,expandedGroups:O,onToggleGroup:oe,onQuickAdd:Z,onShowPluginDetails:W=>{j(W),S(!0)},isPluginSelected:T,onTogglePlugin:m,isApplyingPlugins:w,selectedPluginCount:C.size})})]})})]}),u.jsx(pf,{className:q("border-sidebar-border/70 gap-0 border-t p-1.5",xe),children:u.jsx("div",{className:q("flex items-center",n?"justify-center":"justify-start"),children:u.jsx(ly,{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(Hi,{mode:"create",shouldReset:!f,postSubmit:U,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(Hi,{mode:"create",shouldReset:!h,postSubmit:$,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),u.jsx(Ct,{open:v,onOpenChange:W=>{S(W),W||j(null)},children:u.jsx(kt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:u.jsx(ey,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:b})})}),u.jsx(px,{open:N,onOpenChange:H})]})}const _l=x.memo(uy),cy=x.lazy(()=>gd(()=>import("./editor-sQA3rPOP.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Editor})));function jl(){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(cy,{})})}const dy=x.lazy(()=>gd(()=>import("./preview-CisNYRaE.js"),__vite__mapDeps([12,1,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.Preview})));function Nl(){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(dy,{})})}const{createElement:hr,createContext:fy,forwardRef:kf,useCallback:gt,useContext:Sf,useEffect:zn,useImperativeHandle:_f,useLayoutEffect:py,useMemo:hy,useRef:wt,useState:or}=Oc,El=Oc[`useId${Math.random()}`.slice(0,5)],my=py,js=fy(null);js.displayName="PanelGroupContext";const On=my,gy=typeof El=="function"?El:()=>null;let xy=0;function ya(e=null){const t=gy(),n=wt(e||t||null);return n.current===null&&(n.current=""+xy++),e??n.current}function jf({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=Sf(js);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:b,expandPanel:j,getPanelSize:m,getPanelStyle:T,groupId:C,isPanelCollapsed:w,reevaluatePanelConstraints:N,registerPanel:H,resizePanel:O,unregisterPanel:_}=S,I=ya(o),z=wt({callbacks:{onCollapse:c,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:a,minSize:l},id:I,idIsFromProps:o!==void 0,order:p});wt({didLogMissingDefaultSizeWarning:!1}),On(()=>{const{callbacks:A,constraints:P}=z.current,D={...P};z.current.id=I,z.current.idIsFromProps=o!==void 0,z.current.order=p,A.onCollapse=c,A.onExpand=d,A.onResize=f,P.collapsedSize=n,P.collapsible=r,P.defaultSize=i,P.maxSize=a,P.minSize=l,(D.collapsedSize!==P.collapsedSize||D.collapsible!==P.collapsible||D.maxSize!==P.maxSize||D.minSize!==P.minSize)&&N(z.current,D)}),On(()=>{const A=z.current;return H(A),()=>{_(A)}},[p,I,H,_]),_f(s,()=>({collapse:()=>{b(z.current)},expand:A=>{j(z.current,A)},getId(){return I},getSize(){return m(z.current)},isCollapsed(){return w(z.current)},isExpanded(){return!w(z.current)},resize:A=>{O(z.current,A)}}),[b,j,m,w,I,O]);const M=T(z.current,i);return hr(g,{...v,children:e,className:t,id:o,style:{...M,...h},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":C,"data-panel-id":I,"data-panel-size":parseFloat(""+M.flexGrow).toFixed(1)})}const Nf=kf((e,t)=>hr(jf,{...e,forwardedRef:t}));jf.displayName="Panel";Nf.displayName="forwardRef(Panel)";let Mo=null,An=null;function by(e,t){if(t){const n=(t&Af)!==0,r=(t&zf)!==0,i=(t&Of)!==0,s=(t&Pf)!==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 yy(){An!==null&&(document.head.removeChild(An),Mo=null,An=null)}function Ws(e,t){const n=by(e,t);Mo!==n&&(Mo=n,An===null&&(An=document.createElement("style"),document.head.appendChild(An)),An.innerHTML=`*{cursor: ${n}!important;}`)}function Ef(e){return e.type==="keydown"}function Cf(e){return e.type.startsWith("pointer")}function If(e){return e.type.startsWith("mouse")}function Ns(e){if(Cf(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(If(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function vy(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function wy(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 ky(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Tl(e),b:Tl(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;je(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:Il(Cl(n.a)),b:Il(Cl(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 Sy=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function _y(e){var t;const n=getComputedStyle((t=Tf(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function jy(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||_y(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"||Sy.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Cl(e){let t=e.length;for(;t--;){const n=e[t];if(je(n,"Missing node"),jy(n))return n}return null}function Il(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Tl(e){const t=[];for(;e;)t.push(e),e=Tf(e);return t}function Tf(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const Af=1,zf=2,Of=4,Pf=8,Ny=vy()==="coarse";let Zt=[],ar=!1,mn=new Map,Es=new Map;const Xr=new Set;function Ey(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),Xr.add(a),Qi(),function(){var d;Es.delete(e),Xr.delete(a);const f=(d=mn.get(o))!==null&&d!==void 0?d:1;if(mn.set(o,f-1),Qi(),f===1&&mn.delete(o),Zt.includes(a)){const p=Zt.indexOf(a);p>=0&&Zt.splice(p,1),wa(),i("up",!0,null)}}}function Al(e){const{target:t}=e,{x:n,y:r}=Ns(e);ar=!0,va({target:t,x:n,y:r}),Qi(),Zt.length>0&&(es("down",e),e.preventDefault(),e.stopPropagation())}function Ir(e){const{x:t,y:n}=Ns(e);if(ar&&e.buttons===0&&(ar=!1,es("up",e)),!ar){const{target:r}=e;va({target:r,x:t,y:n})}es("move",e),wa(),Zt.length>0&&e.preventDefault()}function Jn(e){const{target:t}=e,{x:n,y:r}=Ns(e);Es.clear(),ar=!1,Zt.length>0&&e.preventDefault(),es("up",e),va({target:t,x:n,y:r}),wa(),Qi()}function va({target:e,x:t,y:n}){Zt.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Xr.forEach(i=>{const{element:s,hitAreaMargins:o}=i,a=s.getBoundingClientRect(),{bottom:l,left:c,right:d,top:f}=a,p=Ny?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)&&ky(r,s)>0){let g=r,v=!1;for(;g&&!g.contains(s);){if(wy(g.getBoundingClientRect(),a)){v=!0;break}g=g.parentElement}if(v)return}Zt.push(i)}})}function qs(e,t){Es.set(e,t)}function wa(){let e=!1,t=!1;Zt.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;Es.forEach(r=>{n|=r}),e&&t?Ws("intersection",n):e?Ws("horizontal",n):t?Ws("vertical",n):yy()}function Qi(){mn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Jn),n.removeEventListener("pointerdown",Al),n.removeEventListener("pointerleave",Ir),n.removeEventListener("pointermove",Ir)}),window.removeEventListener("pointerup",Jn),window.removeEventListener("pointercancel",Jn),Xr.size>0&&(ar?(Zt.length>0&&mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Jn),n.addEventListener("pointerleave",Ir),n.addEventListener("pointermove",Ir))}),window.addEventListener("pointerup",Jn),window.addEventListener("pointercancel",Jn)):mn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",Al,{capture:!0}),n.addEventListener("pointermove",Ir))}))}function es(e,t){Xr.forEach(n=>{const{setResizeHandlerState:r}=n,i=Zt.includes(n);r(e,i,t)})}function Cy(){const[e,t]=or(0);return gt(()=>t(n=>n+1),[])}function je(e,t){if(!e)throw console.error(t),Error(t)}const ka=10;function Rn(e,t,n=ka){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function on(e,t,n=ka){return Rn(e,t,n)===0}function Nt(e,t,n){return Rn(e,t,n)===0}function Iy(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];je(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(ka)),n}function Rr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Nt(e,0))return t;const o=[...t],[a,l]=r;je(a!=null,"Invalid first pivot index"),je(l!=null,"Invalid second pivot index");let c=0;if(s==="keyboard"){{const f=e<0?l:a,p=n[f];je(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(je(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,h)){const b=v-S;Rn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}{const f=e<0?a:l,p=n[f];je(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(je(S!=null,`Previous layout not found for panel index ${f}`),Nt(S,v)){const b=S-h;Rn(b,Math.abs(e))>0&&(e=e<0?0-b:b)}}}}{const f=e<0?1:-1;let p=e<0?l:a,h=0;for(;;){const v=t[p];je(v!=null,`Previous layout not found for panel index ${p}`);const b=nr({panelConstraints:n,panelIndex:p,size:100})-v;if(h+=b,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];je(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(Iy(i,o))return i;{const f=e<0?l:a,p=t[f];je(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,b=e<0?l:a;for(;b>=0&&b<n.length;){const j=o[b];je(j!=null,`Previous layout not found for panel index ${b}`);const m=j+v,T=nr({panelConstraints:n,panelIndex:b,size:m});if(Nt(j,T)||(v-=T-j,o[b]=T),Nt(v,0))break;e>0?b--:b++}}}const d=o.reduce((f,p)=>p+f,0);return Nt(d,100)?o:i}function Ty({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,o=0;const a=n[0];je(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 Qr(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function Df(e,t,n=document){const i=Qr(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function Rf(e,t,n){const r=Df(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function Mf(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 Cs(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function Ay(e,t,n,r=document){var i,s,o,a;const l=Cs(t,r),c=Qr(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 zy({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:o}){wt({didWarnAboutMissingResizeHandle:!1}),On(()=>{if(!s)return;const a=Qr(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:c,valueMin:d,valueNow:f}=Ty({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),p=a[l];if(p!=null){const h=i[l];je(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;je(a,"Eager values not found");const{panelDataArray:l}=a,c=Mf(n,s);je(c!=null,`No group found for id "${n}"`);const d=Qr(n,s);je(d,`No resize handles found for group id "${n}"`);const f=d.map(p=>{const h=p.getAttribute("data-panel-resize-handle-id");je(h,"Resize handle element has no handle id attribute");const[g,v]=Ay(n,h,l,s);if(g==null||v==null)return()=>{};const S=b=>{if(!b.defaultPrevented)switch(b.key){case"Enter":{b.preventDefault();const j=l.findIndex(m=>m.id===g);if(j>=0){const m=l[j];je(m,`No panel data found for index ${j}`);const T=r[j],{collapsedSize:C=0,collapsible:w,minSize:N=0}=m.constraints;if(T!=null&&w){const H=Rr({delta:Nt(T,C)?N-C:C-T,initialLayout:r,panelConstraints:l.map(O=>O.constraints),pivotIndices:Rf(n,h,s),prevLayout:r,trigger:"keyboard"});r!==H&&o(H)}}break}}};return p.addEventListener("keydown",S),()=>{p.removeEventListener("keydown",S)}});return()=>{f.forEach(p=>p())}},[s,e,t,n,r,i,o])}function zl(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 $f(e,t){const n=e==="horizontal",{x:r,y:i}=Ns(t);return n?r:i}function Oy(e,t,n,r,i){const s=n==="horizontal",o=Cs(t,i);je(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute("data-panel-group-id");je(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=$f(n,e),d=Mf(a,i);je(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),p=s?f.width:f.height;return(c-l)/p*100}function Py(e,t,n,r,i,s){if(Ef(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:Oy(e,t,n,r,s)}function Dy({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];je(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];je(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];je(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 ji(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 Ry({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 My(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function Ol(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 Lf(e){return`react-resizable-panels:${e}`}function Ff(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 Bf(e,t){try{const n=Lf(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function $y(e,t,n){var r,i;const s=(r=Bf(e,n))!==null&&r!==void 0?r:{},o=Ff(t);return(i=s[o])!==null&&i!==void 0?i:null}function Ly(e,t,n,r,i){var s;const o=Lf(e),a=Ff(t),l=(s=Bf(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 Pl({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];je(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];je(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];je(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 Fy=100,Mr={getItem:e=>(Ol(Mr),Mr.getItem(e)),setItem:(e,t)=>{Ol(Mr),Mr.setItem(e,t)}},Dl={};function Zf({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:o=null,keyboardResizeBy:a=null,storage:l=Mr,style:c,tagName:d="div",...f}){const p=ya(s),h=wt(null),[g,v]=or(null),[S,b]=or([]),j=Cy(),m=wt({}),T=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:[]}),_f(i,()=>({getId:()=>w.current.id,getLayout:()=>{const{layout:y}=N.current;return y},setLayout:y=>{const{onLayout:Z}=w.current,{layout:V,panelDataArray:ie}=N.current,se=Pl({layout:y,panelConstraints:ie.map(re=>re.constraints)});zl(V,se)||(b(se),N.current.layout=se,Z&&Z(se),Hn(ie,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}),zy({committedValuesRef:w,eagerValuesRef:N,groupId:p,layout:S,panelDataArray:N.current.panelDataArray,setLayout:b,panelGroupElement:h.current}),zn(()=>{const{panelDataArray:y}=N.current;if(e){if(S.length===0||S.length!==y.length)return;let Z=Dl[e];Z==null&&(Z=My(Ly,Fy),Dl[e]=Z);const V=[...y],ie=new Map(T.current);Z(e,V,ie,S,l)}},[e,S,l]),zn(()=>{});const H=gt(y=>{const{onLayout:Z}=w.current,{layout:V,panelDataArray:ie}=N.current;if(y.constraints.collapsible){const se=ie.map(Ee=>Ee.constraints),{collapsedSize:re=0,panelSize:de,pivotIndices:ge}=jn(ie,y,V);if(je(de!=null,`Panel size not found for panel "${y.id}"`),!on(de,re)){T.current.set(y.id,de);const ye=Xn(ie,y)===ie.length-1?de-re:re-de,xe=Rr({delta:ye,initialLayout:V,panelConstraints:se,pivotIndices:ge,prevLayout:V,trigger:"imperative-api"});ji(V,xe)||(b(xe),N.current.layout=xe,Z&&Z(xe),Hn(ie,xe,m.current))}}},[]),O=gt((y,Z)=>{const{onLayout:V}=w.current,{layout:ie,panelDataArray:se}=N.current;if(y.constraints.collapsible){const re=se.map(W=>W.constraints),{collapsedSize:de=0,panelSize:ge=0,minSize:Ee=0,pivotIndices:ye}=jn(se,y,ie),xe=Z??Ee;if(on(ge,de)){const W=T.current.get(y.id),Oe=W!=null&&W>=xe?W:xe,ve=Xn(se,y)===se.length-1?ge-Oe:Oe-ge,E=Rr({delta:ve,initialLayout:ie,panelConstraints:re,pivotIndices:ye,prevLayout:ie,trigger:"imperative-api"});ji(ie,E)||(b(E),N.current.layout=E,V&&V(E),Hn(se,E,m.current))}}},[]),_=gt(y=>{const{layout:Z,panelDataArray:V}=N.current,{panelSize:ie}=jn(V,y,Z);return je(ie!=null,`Panel size not found for panel "${y.id}"`),ie},[]),I=gt((y,Z)=>{const{panelDataArray:V}=N.current,ie=Xn(V,y);return Ry({defaultSize:Z,dragState:g,layout:S,panelData:V,panelIndex:ie})},[g,S]),z=gt(y=>{const{layout:Z,panelDataArray:V}=N.current,{collapsedSize:ie=0,collapsible:se,panelSize:re}=jn(V,y,Z);return je(re!=null,`Panel size not found for panel "${y.id}"`),se===!0&&on(re,ie)},[]),M=gt(y=>{const{layout:Z,panelDataArray:V}=N.current,{collapsedSize:ie=0,collapsible:se,panelSize:re}=jn(V,y,Z);return je(re!=null,`Panel size not found for panel "${y.id}"`),!se||Rn(re,ie)>0},[]),A=gt(y=>{const{panelDataArray:Z}=N.current;Z.push(y),Z.sort((V,ie)=>{const se=V.order,re=ie.order;return se==null&&re==null?0:se==null?-1:re==null?1:se-re}),N.current.panelDataArrayChanged=!0,j()},[j]);On(()=>{if(N.current.panelDataArrayChanged){N.current.panelDataArrayChanged=!1;const{autoSaveId:y,onLayout:Z,storage:V}=w.current,{layout:ie,panelDataArray:se}=N.current;let re=null;if(y){const ge=$y(y,se,V);ge&&(T.current=new Map(Object.entries(ge.expandToSizes)),re=ge.layout)}re==null&&(re=Dy({panelDataArray:se}));const de=Pl({layout:re,panelConstraints:se.map(ge=>ge.constraints)});zl(ie,de)||(b(de),N.current.layout=de,Z&&Z(de),Hn(se,de,m.current))}}),On(()=>{const y=N.current;return()=>{y.layout=[]}},[]);const P=gt(y=>{let Z=!1;const V=h.current;return V&&window.getComputedStyle(V,null).getPropertyValue("direction")==="rtl"&&(Z=!0),function(se){se.preventDefault();const re=h.current;if(!re)return()=>null;const{direction:de,dragState:ge,id:Ee,keyboardResizeBy:ye,onLayout:xe}=w.current,{layout:W,panelDataArray:Oe}=N.current,{initialLayout:Q}=ge??{},ve=Rf(Ee,y,re);let E=Py(se,y,de,ge,ye,re);const R=de==="horizontal";R&&Z&&(E=-E);const L=Oe.map(ee=>ee.constraints),te=Rr({delta:E,initialLayout:Q??W,panelConstraints:L,pivotIndices:ve,prevLayout:W,trigger:Ef(se)?"keyboard":"mouse-or-touch"}),K=!ji(W,te);(Cf(se)||If(se))&&C.current!=E&&(C.current=E,!K&&E!==0?R?qs(y,E<0?Af:zf):qs(y,E<0?Of:Pf):qs(y,0)),K&&(b(te),N.current.layout=te,xe&&xe(te),Hn(Oe,te,m.current))}},[]),D=gt((y,Z)=>{const{onLayout:V}=w.current,{layout:ie,panelDataArray:se}=N.current,re=se.map(W=>W.constraints),{panelSize:de,pivotIndices:ge}=jn(se,y,ie);je(de!=null,`Panel size not found for panel "${y.id}"`);const ye=Xn(se,y)===se.length-1?de-Z:Z-de,xe=Rr({delta:ye,initialLayout:ie,panelConstraints:re,pivotIndices:ge,prevLayout:ie,trigger:"imperative-api"});ji(ie,xe)||(b(xe),N.current.layout=xe,V&&V(xe),Hn(se,xe,m.current))},[]),U=gt((y,Z)=>{const{layout:V,panelDataArray:ie}=N.current,{collapsedSize:se=0,collapsible:re}=Z,{collapsedSize:de=0,collapsible:ge,maxSize:Ee=100,minSize:ye=0}=y.constraints,{panelSize:xe}=jn(ie,y,V);xe!=null&&(re&&ge&&on(xe,se)?on(se,de)||D(y,de):xe<ye?D(y,ye):xe>Ee&&D(y,Ee))},[D]),$=gt((y,Z)=>{const{direction:V}=w.current,{layout:ie}=N.current;if(!h.current)return;const se=Cs(y,h.current);je(se,`Drag handle element not found for id "${y}"`);const re=$f(V,Z);v({dragHandleId:y,dragHandleRect:se.getBoundingClientRect(),initialCursorPosition:re,initialLayout:ie})},[]),X=gt(()=>{v(null)},[]),k=gt(y=>{const{panelDataArray:Z}=N.current,V=Xn(Z,y);V>=0&&(Z.splice(V,1),delete m.current[y.id],N.current.panelDataArrayChanged=!0,j())},[j]),oe=hy(()=>({collapsePanel:H,direction:r,dragState:g,expandPanel:O,getPanelSize:_,getPanelStyle:I,groupId:p,isPanelCollapsed:z,isPanelExpanded:M,reevaluatePanelConstraints:U,registerPanel:A,registerResizeHandle:P,resizePanel:D,startDragging:$,stopDragging:X,unregisterPanel:k,panelGroupElement:h.current}),[H,g,r,O,_,I,p,z,M,U,A,P,D,$,X,k]),G={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return hr(js.Provider,{value:oe},hr(d,{...f,children:t,className:n,id:s,ref:h,style:{...G,...c},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":p}))}const Vf=kf((e,t)=>hr(Zf,{...e,forwardedRef:t}));Zf.displayName="PanelGroup";Vf.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 By({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){zn(()=>{if(e||n==null||r==null)return;const i=Cs(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");je(a,`No group element found for id "${a}"`);const l=Qr(a,r),c=Df(a,t,r);je(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 Uf({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=Sf(js);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:b,groupId:j,registerResizeHandle:m,startDragging:T,stopDragging:C,panelGroupElement:w}=S,N=ya(i),[H,O]=or("inactive"),[_,I]=or(!1),[z,M]=or(null),A=wt({state:H});On(()=>{A.current.state=H}),zn(()=>{if(n)M(null);else{const $=m(N);M(()=>$)}},[n,N,m]);const P=(p=r==null?void 0:r.coarse)!==null&&p!==void 0?p:15,D=(h=r==null?void 0:r.fine)!==null&&h!==void 0?h:5;return zn(()=>{if(n||z==null)return;const $=g.current;return je($,"Element ref not attached"),Ey(N,$,b,{coarse:P,fine:D},(k,oe,G)=>{if(oe)switch(k){case"down":{O("drag"),je(G,'Expected event to be defined for "down" action'),T(N,G);const{onDragging:y}=v.current;y&&y(!0);break}case"move":{const{state:y}=A.current;y!=="drag"&&O("hover"),je(G,'Expected event to be defined for "move" action'),z(G);break}case"up":{O("hover"),C();const{onDragging:y}=v.current;y&&y(!1);break}}else O("inactive")})},[P,b,n,D,m,N,z,T,C]),By({disabled:n,handleId:N,resizeHandler:z,panelGroupElement:w}),hr(d,{...f,children:e,className:t,id:i,onBlur:()=>{I(!1),s==null||s()},onFocus:()=>{I(!0),a==null||a()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:c,"data-panel-group-direction":b,"data-panel-group-id":j,"data-resize-handle":"","data-resize-handle-active":H==="drag"?"pointer":_?"keyboard":void 0,"data-resize-handle-state":H,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":N})}Uf.displayName="PanelResizeHandle";const Zy=({className:e,...t})=>u.jsx(Vf,{className:q("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),Gs=Nf,Rl=({withHandle:e,className:t,...n})=>u.jsx(Uf,{className:q("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(Fg,{className:"h-2.5 w-2.5"})})}),Jf=x.forwardRef(({className:e,...t},n)=>u.jsx("textarea",{className:q("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}));Jf.displayName="Textarea";class Vy{constructor(t){Xa(this,"client");this.client=ax.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 Uy=new Vy;function Jy(){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 ${wi.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(hd.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,b=v.status==="HIT"?"HIT":v.status==="MISS"?"MISS":"UNKNOWN",j=b==="HIT"?`Served from cache (Hit rate: ${v.hitRate})`:`Generated fresh ${wi.toLowerCase()}`;o==null||o("finalizing",j);const m=globalThis.atob(g.document),T=new Uint8Array(m.length);for(let w=0;w<m.length;w++)T[w]=m.charCodeAt(w);const C=new Blob([T],{type:g.contentType});if(C.size===0)throw new Error(`Received empty ${wi.toLowerCase()} from API`);return{name:r,text:i,blob:C,filename:g.filename,fileId:g.fileId,cacheStatus:b,cacheHitRate:v.hitRate,warnings:S}}catch(c){throw c instanceof Error&&c.name==="AbortError"?new Error(`${wi} 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 Hy(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 Wy({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=Se.useState("custom");Se.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(yn,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),u.jsx(Ne,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}const Ml=ot==="docx"?["docxjs","LibreOffice"]:["LibreOffice"],Ys={docxjs:["⚡","(Fast) works in the browser — lower fidelity"],LibreOffice:["🖨️","(High fidelity) converts to PDF locally with LibreOffice"]};function qy({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:b,chatOpen:j,onTogglePreview:m,previewOpen:T}){const C=v!=="docxjs",[w,N]=x.useState(!1),[H,O]=x.useState(!1),[_,I]=x.useState(!1),[z,M]=x.useState(!1),[A,P]=x.useState(!1),[D,U]=x.useState(!1),[$,X]=x.useState(null),{toast:k}=vr(),{generateDocument:oe}=Jy(),G=x.useContext(Ed),y=x.useCallback(()=>{const Q={},{customThemes:ve}=G.getState();return Object.values(ve).forEach(E=>{E.valid&&E.parsed&&(Q[E.name]=E.parsed)}),Q},[G]),Z=Se.useMemo(()=>{if(!p)return[];try{const Q=JSON.parse(p);return[...(ot==="pptx"?pg:hg)(Q)].filter(E=>!mg(E))}catch{return[]}},[p]),[V,ie]=x.useState(!1),se=x.useCallback(async()=>{if(t){N(!0);try{await new Promise(Q=>setTimeout(Q,100)),Mi(`${e}${jr}`,t)}finally{setTimeout(()=>N(!1),500)}}},[t,e]),re=x.useCallback(async()=>{if(t){if(Z.length===0){await se();return}ie(!0)}},[t,Z.length,se]),de=x.useCallback(async Q=>{var ve;if(p){N(!0);try{const E=await oe(e,p,y(),void 0,{bypassCache:!0,fonts:{mode:Q}});if(E.blob.size===0)k({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{Mi(`${e}${jr}`,E.blob);const R=(ve=E.warnings)==null?void 0:ve.find(L=>{var te,K;return((te=L.context)==null?void 0:te.code)==="FONT_MODE_SUBSTITUTED"||((K=L.context)==null?void 0:K.code)==="FONT_MODE_CUSTOM"});R&&k({title:Q==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:R.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,y]),ge=x.useCallback(async()=>{if(!(!g||g.length===0)){O(!0);try{const Q=Hy(g);if(!Q){k({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const ve=await oe("warnings",JSON.stringify(Q,null,2),{});ve&&typeof ve=="object"&&"blob"in ve&&ve.blob&&(Mi(`${e}-warnings${jr}`,ve.blob),k({title:"Warnings downloaded",description:`Downloaded warnings document with ${g.length} warning(s).`}))}catch(Q){console.error("Failed to generate warnings document:",Q),k({title:"Download failed",description:Q instanceof Error?Q.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>O(!1),500)}}},[g,e,oe,k]),Ee=x.useCallback(async()=>{const Q=r==null?void 0:r.current;if(Q!=null&&Q.src){I(!0);try{await new Promise(E=>{let R=null,L=!1;const te=()=>{R&&(clearTimeout(R),R=null),Q.removeEventListener("load",ee),Q.removeEventListener("error",ue)},K=()=>{L||(L=!0,te(),E())},ee=()=>K(),ue=()=>K();Q.addEventListener("load",ee),Q.addEventListener("error",ue),R=setTimeout(()=>{console.warn("Iframe reload timed out after 5 seconds"),K()},5e3);const be=Q.src,B=be.includes("?")?"&":"?",Y=Date.now();Q.src=`${be}${B}_reload=${Y}`})}catch(ve){console.error("Iframe reload failed:",ve)}finally{I(!1)}}},[r]),ye=x.useCallback(async()=>{M(!0);try{await Uy.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(Q){console.error("Failed to clear cache:",Q),k({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{M(!1)}},[k]),xe=h??p,W=x.useCallback(()=>{var E,R;if(!xe){k({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(xe)}catch{k({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}U(!0);const Q=(async()=>{const L=await fetch(`/api/${ot}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:xe,customThemes:y(),options:{sourceName:e}})});if(!L.ok){let K=`Request failed with status ${L.status}`;try{const ee=await L.json(),ue=ee.error??ee.message;typeof ue=="string"&&ue&&(K=ue)}catch{}throw new Error(K)}const te=await L.json();return JSON.stringify(te.data,null,2)})();let ve;typeof ClipboardItem<"u"&&((E=navigator.clipboard)!=null&&E.write)?ve=navigator.clipboard.write([new ClipboardItem({"text/plain":Q.then(L=>new Blob([L],{type:"text/plain"}))})]):(R=navigator.clipboard)!=null&&R.writeText?ve=Q.then(L=>navigator.clipboard.writeText(L)):ve=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await ve,k({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(L){let te=null;try{te=await Q}catch(K){console.error("Error fetching standard components:",K),k({title:"Failed to get standard components",description:K instanceof Error?K.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",L),X(te)}finally{U(!1)}})()},[xe,e,y,k]),Oe=x.useCallback(async()=>{if($!=null)try{await navigator.clipboard.writeText($),k({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),X(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(kd,{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 ",jr," 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(Ne,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:o,"aria-label":"Render preview",disabled:a||l||T===!1,children:[l?u.jsx(sn,{size:"sm"}):u.jsx(Bg,{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:T===!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(ba,{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(Ne,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:Ee,disabled:_||a||l,children:_?u.jsx(sn,{size:"sm"}):u.jsx(Zg,{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(Ne,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||w||a,onClick:re,children:[w?u.jsx(sn,{size:"sm"}):u.jsx(Vg,{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 ",jr]})})]}),g&&g.length>0&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ne,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:H||a,onClick:ge,children:H?u.jsx(sn,{size:"sm"}):u.jsx(_d,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("p",{children:["Download warnings (",g.length,")"]})})]}),v&&S&&u.jsxs(qr,{value:v,onValueChange:S,children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(cr,{className:"w-[140px] h-7 text-xs hidden lg:flex",children:u.jsx(Gr,{placeholder:"Renderer"})})}),u.jsx(Ye,{children:u.jsx("p",{children:"Select the rendering library"})})]}),u.jsx(dr,{className:"text-sidebar-foreground",children:Ml.map(Q=>u.jsxs(Dn,{value:Q,children:[u.jsxs(qe,{children:[u.jsx(Ge,{tabIndex:-1,children:Ys[Q][0]}),u.jsx(Ye,{children:Ys[Q][1]})]})," ",Q]},Q))})]}),u.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),u.jsxs(ks,{children:[u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ss,{asChild:!0,children:u.jsx(Ne,{variant:"ghost",size:"icon",className:"h-7 w-7",children:u.jsx(vd,{className:"h-3.5 w-3.5"})})})}),u.jsx(Ye,{children:u.jsx("p",{children:"More actions"})})]}),u.jsxs(hi,{align:"end",className:"w-52",children:[d&&u.jsxs(Lt,{onClick:d,children:[u.jsx(Ug,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),f&&u.jsxs(Lt,{onClick:f,children:[u.jsx(ko,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),c&&u.jsxs(Lt,{onClick:c,children:[u.jsx(So,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),xe?u.jsxs(Lt,{onClick:W,disabled:D,children:[u.jsx(_o,{className:"h-4 w-4 mr-2"}),D?"Copying...":"Copy standard components"]}):u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx("span",{className:"block",children:u.jsxs(Lt,{disabled:!0,children:[u.jsx(_o,{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(fr,{}),u.jsxs(Lt,{onClick:()=>P(!0),disabled:z,className:"text-destructive focus:text-destructive",children:[u.jsx(la,{className:"h-4 w-4 mr-2"}),z?"Clearing...":"Clear all caches"]}),v&&S&&u.jsxs(u.Fragment,{children:[u.jsx(fr,{className:"lg:hidden"}),Ml.map(Q=>u.jsxs(Lt,{className:"lg:hidden",onClick:()=>S(Q),children:[u.jsx("span",{className:"mr-2",children:v===Q?"●":"○"}),Ys[Q][0]," ",Q]},Q))]})]})]}),m&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ne,{variant:T?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:m,children:T?u.jsx(jd,{className:"h-3.5 w-3.5"}):u.jsx(Jg,{className:"h-3.5 w-3.5"})})}),u.jsx(Ye,{children:u.jsxs("span",{className:"flex items-center gap-1.5",children:[T?"Hide":"Show"," Preview"," ",u.jsx(Kr,{shortcut:"mod+shift+p"})]})})]}),b&&u.jsxs(qe,{children:[u.jsx(Ge,{asChild:!0,children:u.jsx(Ne,{variant:j?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:b,children:u.jsx(Nd,{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(Kr,{shortcut:"mod+shift+j"})]})})]})]})]}),u.jsx(Wy,{open:V,onClose:()=>ie(!1),nonSafeFonts:Z,onChoose:de}),u.jsx(Ct,{open:$!=null,onOpenChange:Q=>{Q||X(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(Jf,{readOnly:!0,value:$??"",className:"h-64 font-mono text-xs",onFocus:Q=>Q.currentTarget.select()}),u.jsxs(yn,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>X(null),children:"Close"}),u.jsx(Ne,{size:"sm",onClick:Oe,children:"Copy to clipboard"})]})]})}),u.jsx(Ct,{open:A,onOpenChange:P,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(yn,{children:[u.jsx(Ne,{variant:"outline",size:"sm",onClick:()=>P(!1),children:"Cancel"}),u.jsx(Ne,{variant:"destructive",size:"sm",disabled:z,onClick:async()=>{await ye(),P(!1)},children:z?u.jsx(sn,{size:"sm"}):"Clear"})]})]})})]})}const Gy=Se.memo(qy),Hf=lg,Sa=x.forwardRef(({className:e,...t},n)=>u.jsx(dd,{ref:n,className:q("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Sa.displayName=dd.displayName;const ei=x.forwardRef(({className:e,...t},n)=>u.jsx(fd,{ref:n,className:q("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}));ei.displayName=fd.displayName;const ti=x.forwardRef(({className:e,...t},n)=>u.jsx(pd,{ref:n,className:q("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));ti.displayName=pd.displayName;async function Yy(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 Ky(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 Xy(e){const t=Ky(e);return Yy(t)}const Qy=({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),[b,j]=x.useState(!1),{toast:m}=vr(),T=Bt(M=>M.selectedPlugins),C=Array.from(T);x.useEffect(()=>{n&&i(n)},[n]);const w=x.useCallback(async()=>{d(!0),g(null);try{const M=await Ls.fetchDocumentSchema(C);o(M)}catch(M){const A=M instanceof Error?M.message:"Failed to load document schema";g(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{d(!1)}},[C,m]),N=x.useCallback(async()=>{if(!a){p(!0),S(null);try{const M=await Ls.fetchThemeSchema();l(M)}catch(M){const A=M instanceof Error?M.message:"Failed to load theme schema";S(A),m({variant:"destructive",title:"Error loading schema",description:A})}finally{p(!1)}}},[a,m]),[H,O]=x.useState([]);x.useEffect(()=>{e||(o(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const M=C.length!==H.length||C.some((A,P)=>A!==H[P]);r==="document"?(!s||M)&&(M&&(Ls.clearPluginSchemaCache(),O([...C])),c||w()):r==="theme"&&!a&&!f&&N()},[r,e,s,a,c,f,C,H,w,N]);const _=C.length,I=r==="document"?s:a,z=async()=>{if(I)try{await Xy(I)&&(j(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>j(!1),2e3))}catch(M){console.error("Copy failed:",M)}};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(Hf,{value:r,onValueChange:M=>i(M),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Sa,{children:[u.jsxs(ei,{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(ei,{value:"theme",children:"Theme"})]}),u.jsx("div",{className:"ml-auto",children:u.jsx(Ne,{variant:"ghost",size:"icon",onClick:z,disabled:b||!I,"aria-label":"Copy schema",children:b?u.jsx(bn,{className:"h-4 w-4"}):u.jsx(bs,{className:"h-4 w-4"})})})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[u.jsx(ti,{value:"document",className:"h-full",children:u.jsx(Xi,{schema:s,loading:c,error:h||void 0})}),u.jsx(ti,{value:"theme",className:"h-full",children:u.jsx(Xi,{schema:a,loading:f,error:v||void 0})})]})]})]})})};function ev(e,t,n){if(t.length===0)return n;const r=$l(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=$l(l,a);i[o]=c,i=c}return i[t[t.length-1]]=n,r}function $l(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const tv={safe:[],google:[]};function nv(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 rv(){const e=Pe(i=>i.activeTab),t=Pe(i=>i.documents),n=Pe(i=>i.documentTypes),r=Pe(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 iv(){const e=Pe(r=>r.activeTab),t=Pe(r=>r.documents),n=Pe(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=ev(o,r,i);return n(e,JSON.stringify(a,null,2)),{ok:!0,name:e}},[e,t,n])}function sv(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 Ll(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const ov=({open:e,onOpenChange:t})=>{const n=Di(D=>D.open),r=Di(D=>D.contextual),i=Di(D=>D.close),s=e??n,o=r,a=x.useCallback(D=>{t&&t(D),D||i()},[t,i]),[l,c]=x.useState(tv),[d,f]=x.useState(!1),[p,h]=x.useState(""),[g,v]=x.useState("safe"),[S,b]=x.useState(null),[j,m]=x.useState(null),{toast:T}=vr(),C=rv(),w=iv(),N=Pe(D=>D.activeTab),H=Pe(D=>D.documentTypes),O=N&&H[N]==="application/json+theme",_=!!o||O;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(f(!0),fetch("/api/fonts/catalog").then(D=>D.json()).then(D=>c(D)).catch(D=>{T({variant:"destructive",title:"Font catalog unavailable",description:D.message})}).finally(()=>f(!1))))},[s,l,T]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const D of l.google)nv(D.family,D.weights)},[g,l]);const I=x.useMemo(()=>l.safe.filter(D=>D.toLowerCase().includes(p.toLowerCase())),[l.safe,p]),z=x.useMemo(()=>l.google.filter(D=>D.family.toLowerCase().includes(p.toLowerCase())),[l.google,p]),M=x.useCallback(async D=>{try{await navigator.clipboard.writeText(D),m(D),setTimeout(()=>m(null),1500)}catch{T({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[T]),A=x.useCallback(async(D,U,$)=>{b(D);try{const X=C(k=>(sv(k,$,D),k));if(!X.ok){T({variant:"destructive",title:"Could not insert font",description:X.error});return}T({title:"Font inserted",description:`${D} set as ${$} font in "${X.name}".`})}finally{b(null)}},[C,T]),P=x.useCallback(async D=>{if(o){b(D);try{const U=w(o.jsonPath,D);if(!U.ok){T({variant:"destructive",title:"Could not insert font",description:U.error});return}T({title:"Font inserted",description:`${D} set at ${Ll(o.jsonPath)}.`}),a(!1)}finally{b(null)}}},[o,w,T,a]);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 ${Ll(o.jsonPath)}`:"Fonts"})}),!o&&!O&&u.jsx(Gi,{children:u.jsxs(Yi,{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(Hf,{value:g,onValueChange:D=>v(D),className:"flex-1 overflow-hidden flex flex-col",children:[u.jsxs("div",{className:"flex items-center gap-2",children:[u.jsxs(Sa,{children:[u.jsxs(ei,{value:"safe",children:["Safe",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),u.jsxs(ei,{value:"google",children:["Google",u.jsx(Kt,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]})]}),u.jsx(fi,{type:"search",placeholder:"Search fonts...",value:p,onChange:D=>h(D.target.value),className:"ml-auto max-w-xs"})]}),u.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[u.jsx(ti,{value:"safe",className:"m-0",children:d&&I.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(jo,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:I.map(D=>u.jsx(Fl,{family:D,meta:u.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${D}", sans-serif`},onCopy:()=>M(D),copied:j===D,contextual:!!o,onUseThis:()=>P(D),onInsertHeading:()=>A(D,"safe","heading"),onInsertBody:()=>A(D,"safe","body"),applying:S===D,disabled:!_},D))})}),u.jsx(ti,{value:"google",className:"m-0",children:d&&z.length===0?u.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[u.jsx(jo,{className:"animate-spin mr-2"})," Loading catalog..."]}):u.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:z.map(D=>u.jsx(Fl,{family:D.family,meta:u.jsxs("span",{className:"text-xs",children:[D.category," · ",D.weights.length," weights"]}),previewStyle:{fontFamily:`"${D.family}", sans-serif`},onCopy:()=>M(D.family),copied:j===D.family,contextual:!!o,onUseThis:()=>P(D.family),onInsertHeading:()=>A(D.family,"google","heading"),onInsertBody:()=>A(D.family,"google","body"),applying:S===D.family,disabled:!_,extraAction:u.jsx(lv,{family:D.family,weights:D.weights,hasItalic:D.hasItalic})},D.family))})})]})]})]})})},av="The quick brown fox jumps over the lazy dog",lv=({family:e,weights:t,hasItalic:n})=>{const r=x.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return u.jsxs(ks,{children:[u.jsx(Ss,{asChild:!0,children:u.jsx(Ne,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),u.jsxs(hi,{align:"end",className:"min-w-[260px]",children:[u.jsxs(nf,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),u.jsx(fr,{}),r.map(i=>{const s=gg[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)})]})]})},Fl=({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:av}),u.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?u.jsx(Ne,{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(Ne,{size:"sm",variant:"secondary",onClick:a,disabled:c||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),u.jsx(Ne,{size:"sm",variant:"secondary",onClick:l,disabled:c||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,u.jsx(Ne,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?u.jsx(bn,{className:"h-4 w-4"}):u.jsx(bs,{className:"h-4 w-4"})})]})]});function Bl({previewOpen:e,onTogglePreview:t}){const n=rn(O=>O.name||""),r=rn(O=>O.blob),i=rn(O=>O.isGenerating),s=rn(O=>O.text),o=rn(O=>O.warnings),a=rn(O=>O.isRendering),l=ki(O=>O.autoReload),c=ki(O=>O.renderingLibrary),d=ki(O=>O.setSettings),f=ki(O=>O.useGlobalPreviewHeader??!0),p=Pe(O=>O.activeTab),h=Pe(O=>O.documentTypes),g=p&&h[p]==="application/json+theme"?"theme":"document",v=Pe(O=>{var _;return O.activeTab&&O.documentTypes[O.activeTab]!=="application/json+theme"?(_=O.documents.find(I=>I.name===O.activeTab))==null?void 0:_.text:void 0}),S=Re(O=>O.chatOpen),b=Re(O=>O.toggleChat),[j,m]=Se.useState(!1),T=Di(O=>O.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"))},[]),H=(n==null?void 0:n.trim())||"Preview";return u.jsxs("div",{className:"sticky top-0 z-20",children:[u.jsx(Gy,{name:H,blob:r,displayReloadButton:!1,autoReload:l,onToggleAutoReload:C,onManualRender:w,isGenerating:i,isRendering:!!a,onShowCacheMetrics:N,onShowSchemas:()=>m(!0),onShowFonts:()=>T(),documentText:s,editorDocumentText:v,warnings:o,renderingLibrary:c,setRenderingLibrary:O=>d({renderingLibrary:O}),onToggleChat:b,chatOpen:S,onTogglePreview:t,previewOpen:e}),u.jsx(Qy,{open:j,onOpenChange:m,defaultTab:g==="theme"?"theme":"document"}),u.jsx(ov,{})]})}function uv(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const cv=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,dv=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,fv={};function Zl(e,t){return(fv.jsx?dv:cv).test(e)}const pv=/[ \t\n\f\r]/g;function hv(e){return typeof e=="object"?e.type==="text"?Vl(e.value):!1:Vl(e)}function Vl(e){return e.replace(pv,"")===""}class mi{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}mi.prototype.normal={};mi.prototype.property={};mi.prototype.space=void 0;function Wf(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new mi(n,r,t)}function $o(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 mv=0;const ke=Ln(),nt=Ln(),Lo=Ln(),ne=Ln(),Ze=Ln(),lr=Ln(),jt=Ln();function Ln(){return 2**++mv}const Fo=Object.freeze(Object.defineProperty({__proto__:null,boolean:ke,booleanish:nt,commaOrSpaceSeparated:jt,commaSeparated:lr,number:ne,overloadedBoolean:Lo,spaceSeparated:Ze},Symbol.toStringTag,{value:"Module"})),Ks=Object.keys(Fo);class _a extends St{constructor(t,n,r,i){let s=-1;if(super(t,n),Ul(this,"space",i),typeof r=="number")for(;++s<Ks.length;){const o=Ks[s];Ul(this,Ks[s],(r&Fo[o])===Fo[o])}}}_a.prototype.defined=!0;function Ul(e,t,n){n&&(e[t]=n)}function wr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new _a(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[$o(r)]=r,n[$o(s.attribute)]=r}return new mi(t,n,e.space)}const qf=wr({properties:{ariaActiveDescendant:null,ariaAtomic:nt,ariaAutoComplete:null,ariaBusy:nt,ariaChecked:nt,ariaColCount:ne,ariaColIndex:ne,ariaColSpan:ne,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:ne,ariaLive:null,ariaModal:nt,ariaMultiLine:nt,ariaMultiSelectable:nt,ariaOrientation:null,ariaOwns:Ze,ariaPlaceholder:null,ariaPosInSet:ne,ariaPressed:nt,ariaReadOnly:nt,ariaRelevant:null,ariaRequired:nt,ariaRoleDescription:Ze,ariaRowCount:ne,ariaRowIndex:ne,ariaRowSpan:ne,ariaSelected:nt,ariaSetSize:ne,ariaSort:null,ariaValueMax:ne,ariaValueMin:ne,ariaValueNow:ne,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function Gf(e,t){return t in e?e[t]:t}function Yf(e,t){return Gf(e,t.toLowerCase())}const gv=wr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:lr,acceptCharset:Ze,accessKey:Ze,action:null,allow:null,allowFullScreen:ke,allowPaymentRequest:ke,allowUserMedia:ke,alt:null,as:null,async:ke,autoCapitalize:null,autoComplete:Ze,autoFocus:ke,autoPlay:ke,blocking:Ze,capture:null,charSet:null,checked:ke,cite:null,className:Ze,cols:ne,colSpan:null,content:null,contentEditable:nt,controls:ke,controlsList:Ze,coords:ne|lr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:ke,defer:ke,dir:null,dirName:null,disabled:ke,download:Lo,draggable:nt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:ke,formTarget:null,headers:Ze,height:ne,hidden:Lo,high:ne,href:null,hrefLang:null,htmlFor:Ze,httpEquiv:Ze,id:null,imageSizes:null,imageSrcSet:null,inert:ke,inputMode:null,integrity:null,is:null,isMap:ke,itemId:null,itemProp:Ze,itemRef:Ze,itemScope:ke,itemType:Ze,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:ke,low:ne,manifest:null,max:null,maxLength:ne,media:null,method:null,min:null,minLength:ne,multiple:ke,muted:ke,name:null,nonce:null,noModule:ke,noValidate:ke,onAbort:null,onAfterPrint:null,onAuxClick:null,onBeforeMatch:null,onBeforePrint:null,onBeforeToggle:null,onBeforeUnload:null,onBlur:null,onCancel:null,onCanPlay:null,onCanPlayThrough:null,onChange:null,onClick:null,onClose:null,onContextLost:null,onContextMenu:null,onContextRestored:null,onCopy:null,onCueChange:null,onCut:null,onDblClick:null,onDrag:null,onDragEnd:null,onDragEnter:null,onDragExit:null,onDragLeave:null,onDragOver:null,onDragStart:null,onDrop:null,onDurationChange:null,onEmptied:null,onEnded:null,onError:null,onFocus:null,onFormData:null,onHashChange:null,onInput:null,onInvalid:null,onKeyDown:null,onKeyPress:null,onKeyUp:null,onLanguageChange:null,onLoad:null,onLoadedData:null,onLoadedMetadata:null,onLoadEnd:null,onLoadStart:null,onMessage:null,onMessageError:null,onMouseDown:null,onMouseEnter:null,onMouseLeave:null,onMouseMove:null,onMouseOut:null,onMouseOver:null,onMouseUp:null,onOffline:null,onOnline:null,onPageHide:null,onPageShow:null,onPaste:null,onPause:null,onPlay:null,onPlaying:null,onPopState:null,onProgress:null,onRateChange:null,onRejectionHandled:null,onReset:null,onResize:null,onScroll:null,onScrollEnd:null,onSecurityPolicyViolation:null,onSeeked:null,onSeeking:null,onSelect:null,onSlotChange:null,onStalled:null,onStorage:null,onSubmit:null,onSuspend:null,onTimeUpdate:null,onToggle:null,onUnhandledRejection:null,onUnload:null,onVolumeChange:null,onWaiting:null,onWheel:null,open:ke,optimum:ne,pattern:null,ping:Ze,placeholder:null,playsInline:ke,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:ke,referrerPolicy:null,rel:Ze,required:ke,reversed:ke,rows:ne,rowSpan:ne,sandbox:Ze,scope:null,scoped:ke,seamless:ke,selected:ke,shadowRootClonable:ke,shadowRootDelegatesFocus:ke,shadowRootMode:null,shape:null,size:ne,sizes:null,slot:null,span:ne,spellCheck:nt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:ne,step:null,style:null,tabIndex:ne,target:null,title:null,translate:null,type:null,typeMustMatch:ke,useMap:null,value:nt,width:ne,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ze,axis:null,background:null,bgColor:null,border:ne,borderColor:null,bottomMargin:ne,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:ke,declare:ke,event:null,face:null,frame:null,frameBorder:null,hSpace:ne,leftMargin:ne,link:null,longDesc:null,lowSrc:null,marginHeight:ne,marginWidth:ne,noResize:ke,noHref:ke,noShade:ke,noWrap:ke,object:null,profile:null,prompt:null,rev:null,rightMargin:ne,rules:null,scheme:null,scrolling:nt,standby:null,summary:null,text:null,topMargin:ne,valueType:null,version:null,vAlign:null,vLink:null,vSpace:ne,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:ke,disableRemotePlayback:ke,prefix:null,property:null,results:ne,security:null,unselectable:null},space:"html",transform:Yf}),xv=wr({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:ne,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:ne,amplitude:ne,arabicForm:null,ascent:ne,attributeName:null,attributeType:null,azimuth:ne,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:ne,by:null,calcMode:null,capHeight:ne,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:ne,diffuseConstant:ne,direction:null,display:null,dur:null,divisor:ne,dominantBaseline:null,download:ke,dx:null,dy:null,edgeMode:null,editable:null,elevation:ne,enableBackground:null,end:null,event:null,exponent:ne,externalResourcesRequired:null,fill:null,fillOpacity:ne,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:lr,g2:lr,glyphName:lr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:ne,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:ne,horizOriginX:ne,horizOriginY:ne,id:null,ideographic:ne,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:ne,k:ne,k1:ne,k2:ne,k3:ne,k4:ne,kernelMatrix:jt,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:ne,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:ne,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:ne,overlineThickness:ne,paintOrder:null,panose1:null,path:null,pathLength:ne,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ze,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:ne,pointsAtY:ne,pointsAtZ:ne,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:ne,specularExponent:ne,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:ne,strikethroughThickness:ne,string:null,stroke:null,strokeDashArray:jt,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:ne,strokeOpacity:ne,strokeWidth:null,style:null,surfaceScale:ne,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:jt,tabIndex:ne,tableValues:null,target:null,targetX:ne,targetY:ne,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:ne,underlineThickness:ne,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:ne,values:null,vAlphabetic:ne,vMathematical:ne,vectorEffect:null,vHanging:ne,vIdeographic:ne,version:null,vertAdvY:ne,vertOriginX:ne,vertOriginY:ne,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:ne,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:Gf}),Kf=wr({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()}}),Xf=wr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:Yf}),Qf=wr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),bv={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"},yv=/[A-Z]/g,Jl=/-[a-z]/g,vv=/^data[-\w.:]+$/i;function wv(e,t){const n=$o(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"&&vv.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Jl,Sv);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Jl.test(s)){let o=s.replace(yv,kv);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=_a}return new i(r,t)}function kv(e){return"-"+e.toLowerCase()}function Sv(e){return e.charAt(1).toUpperCase()}const _v=Wf([qf,gv,Kf,Xf,Qf],"html"),ja=Wf([qf,xv,Kf,Xf,Qf],"svg");function jv(e){return e.join(" ").trim()}var Wn={},Xs,Hl;function Nv(){if(Hl)return Xs;Hl=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,b){if(typeof S!="string")throw new TypeError("First argument must be a string");if(!S)return[];b=b||{};var j=1,m=1;function T(A){var P=A.match(t);P&&(j+=P.length);var D=A.lastIndexOf(l);m=~D?A.length-D:m+A.length}function C(){var A={line:j,column:m};return function(P){return P.position=new w(A),O(),P}}function w(A){this.start=A,this.end={line:j,column:m},this.source=b.source}w.prototype.content=S;function N(A){var P=new Error(b.source+":"+j+":"+m+": "+A);if(P.reason=A,P.filename=b.source,P.line=j,P.column=m,P.source=S,!b.silent)throw P}function H(A){var P=A.exec(S);if(P){var D=P[0];return T(D),S=S.slice(D.length),P}}function O(){H(n)}function _(A){var P;for(A=A||[];P=I();)P!==!1&&A.push(P);return A}function I(){var A=C();if(!(c!=S.charAt(0)||d!=S.charAt(1))){for(var P=2;f!=S.charAt(P)&&(d!=S.charAt(P)||c!=S.charAt(P+1));)++P;if(P+=2,f===S.charAt(P-1))return N("End of comment missing");var D=S.slice(2,P-2);return m+=2,T(D),S=S.slice(P),m+=2,A({type:p,comment:D})}}function z(){var A=C(),P=H(r);if(P){if(I(),!H(i))return N("property missing ':'");var D=H(s),U=A({type:h,property:v(P[0].replace(e,f)),value:D?v(D[0].replace(e,f)):f});return H(o),U}}function M(){var A=[];_(A);for(var P;P=z();)P!==!1&&(A.push(P),_(A));return A}return O(),M()}function v(S){return S?S.replace(a,f):f}return Xs=g,Xs}var Wl;function Ev(){if(Wl)return Wn;Wl=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(Nv());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 Tr={},ql;function Cv(){if(ql)return Tr;ql=1,Object.defineProperty(Tr,"__esModule",{value:!0}),Tr.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 Tr.camelCase=l,Tr}var Ar,Gl;function Iv(){if(Gl)return Ar;Gl=1;var e=Ar&&Ar.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Ev()),n=Cv();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,Ar=r,Ar}var Tv=Iv();const Av=oa(Tv),ep=tp("end"),Na=tp("start");function tp(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 zv(e){const t=Na(e),n=ep(e);if(t&&n)return{start:t,end:n}}function Jr(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Yl(e.position):"start"in e||"end"in e?Yl(e):"line"in e||"column"in e?Bo(e):""}function Bo(e){return Kl(e&&e.line)+":"+Kl(e&&e.column)}function Yl(e){return Bo(e&&e.start)+"-"+Bo(e&&e.end)}function Kl(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=Jr(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 Ea={}.hasOwnProperty,Ov=new Map,Pv=/[A-Z]/g,Dv=new Set(["table","tbody","thead","tfoot","tr"]),Rv=new Set(["td","th"]),np="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function Mv(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=Jv(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=Uv(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"?ja:_v,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=rp(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function rp(e,t,n){if(t.type==="element")return $v(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return Lv(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return Bv(e,t,n);if(t.type==="mdxjsEsm")return Fv(e,t);if(t.type==="root")return Zv(e,t,n);if(t.type==="text")return Vv(e,t)}function $v(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=ja,e.schema=i),e.ancestors.push(t);const s=sp(e,t.tagName,!1),o=Hv(e,t);let a=Ia(e,t);return Dv.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!hv(l):!0})),ip(e,o,s,t),Ca(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function Lv(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)}ni(e,t.position)}function Fv(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);ni(e,t.position)}function Bv(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=ja,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:sp(e,t.name,!0),o=Wv(e,t),a=Ia(e,t);return ip(e,o,s,t),Ca(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function Zv(e,t,n){const r={};return Ca(r,Ia(e,t)),e.create(t,e.Fragment,r,n)}function Vv(e,t){return t.value}function ip(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Ca(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function Uv(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 Jv(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),l=Na(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 Hv(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&Ea.call(t.properties,i)){const s=qv(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&Rv.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 Wv(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 ni(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 ni(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function Ia(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:Ov;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=rp(e,s,o);a!==void 0&&n.push(a)}return n}function qv(e,t,n){const r=wv(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?uv(n):jv(n)),r.property==="style"){let i=typeof n=="object"?n:Gv(e,String(n));return e.stylePropertyNameCase==="css"&&(i=Yv(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?bv[r.property]||r.property:r.attribute,n]}}function Gv(e,t){try{return Av(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=np+"#cannot-parse-style-attribute",i}}function sp(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=Zl(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=Zl(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return Ea.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);ni(e)}function ni(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=np+"#cannot-handle-mdx-estrees-without-createevaluater",n}function Yv(e){const t={};let n;for(n in e)Ea.call(e,n)&&(t[Kv(n)]=e[n]);return t}function Kv(e){let t=e.replace(Pv,Xv);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function Xv(e){return"-"+e.toLowerCase()}const Qs={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"]},Qv={};function Ta(e,t){const n=Qv,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return op(e,r,i)}function op(e,t,n){if(ew(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 Xl(e.children,t,n)}return Array.isArray(e)?Xl(e,t,n):""}function Xl(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=op(e[i],t,n);return r.join("")}function ew(e){return!!(e&&typeof e=="object")}const Ql=document.createElement("i");function Aa(e){const t="&"+e+";";Ql.innerHTML=t;const n=Ql.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function It(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?(It(e,e.length,0,t),e):t}const eu={}.hasOwnProperty;function ap(e){const t={};let n=-1;for(;++n<e.length;)tw(t,e[n]);return t}function tw(e,t){let n;for(n in t){const i=(eu.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){eu.call(i,o)||(i[o]=[]);const a=s[o];nw(i[o],Array.isArray(a)?a:a?[a]:[])}}}function nw(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);It(e,0,0,r)}function lp(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]/),rw=kn(/[#-'*+\--9=?A-Z^-~]/);function ts(e){return e!==null&&(e<32||e===127)}const Zo=kn(/\d/),iw=kn(/[\dA-Fa-f]/),sw=kn(/[!-/:-@[-`{-~]/);function he(e){return e!==null&&e<-2}function Fe(e){return e!==null&&(e<0||e===32)}function Ie(e){return e===-2||e===-1||e===32}const Is=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 kr(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 Ie(l)?(e.enter(n),a(l)):t(l)}function a(l){return Ie(l)&&s++<i?(e.consume(l),a):(e.exit(n),t(l))}}const ow={tokenize:aw};function aw(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 he(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const lw={tokenize:uw},tu={tokenize:cw};function uw(e){const t=this,n=[];let r=0,i,s,o;return a;function a(m){if(r<n.length){const T=n[r];return t.containerState=T[1],e.attempt(T[0].continuation,l,c)(m)}return c(m)}function l(m){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&j();const T=t.events.length;let C=T,w;for(;C--;)if(t.events[C][0]==="exit"&&t.events[C][1].type==="chunkFlow"){w=t.events[C][1].end;break}b(r);let N=T;for(;N<t.events.length;)t.events[N][1].end={...w},N++;return It(t.events,C+1,0,t.events.slice(T)),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(tu,d,f)(m)}function d(m){return i&&j(),b(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(tu,h,g)(m)}function h(m){return r++,n.push([t.currentConstruct,t.containerState]),p(m)}function g(m){if(m===null){i&&j(),b(0),e.consume(m);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),v(m)}function v(m){if(m===null){S(e.exit("chunkFlow"),!0),b(0),e.consume(m);return}return he(m)?(e.consume(m),S(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(m),v)}function S(m,T){const C=t.sliceStream(m);if(T&&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 H=N,O,_;for(;H--;)if(t.events[H][0]==="exit"&&t.events[H][1].type==="chunkFlow"){if(O){_=t.events[H][1].end;break}O=!0}for(b(r),w=N;w<t.events.length;)t.events[w][1].end={..._},w++;It(t.events,H+1,0,t.events.slice(N)),t.events.length=w}}function b(m){let T=n.length;for(;T-- >m;){const C=n[T];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 cw(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 mr(e){if(e===null||Fe(e)||Mn(e))return 1;if(Is(e))return 2}function Ts(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 Vo={name:"attention",resolveAll:dw,tokenize:fw};function dw(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};nu(f,-l),nu(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,Ts(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,It(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 fw(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=mr(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=mr(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 nu(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const pw={name:"autolink",tokenize:hw};function hw(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||ts(h)?n(h):(e.consume(h),l)}function c(h){return h===64?(e.consume(h),d):rw(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 gi={partial:!0,tokenize:mw};function mw(e,t,n){return r;function r(s){return Ie(s)?De(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||he(s)?t(s):n(s)}}const up={continuation:{tokenize:xw},exit:bw,name:"blockQuote",tokenize:gw};function gw(e,t,n){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),s}return n(o)}function s(o){return Ie(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function xw(e,t,n){const r=this;return i;function i(o){return Ie(o)?De(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(up,t,n)(o)}}function bw(e){e.exit("blockQuote")}const cp={name:"characterEscape",tokenize:yw};function yw(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 sw(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const dp={name:"characterReference",tokenize:vw};function vw(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=iw,d):(e.enter("characterReferenceValue"),s=7,o=Zo,d(f))}function d(f){if(f===59&&i){const p=e.exit("characterReferenceValue");return o===lt&&!Aa(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 ru={partial:!0,tokenize:kw},iu={concrete:!0,name:"codeFenced",tokenize:ww};function ww(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"),Ie(w)?De(e,f,"whitespace")(w):f(w))}function f(w){return w===null||he(w)?(e.exit("codeFencedFence"),r.interrupt?t(w):e.check(ru,v,T)(w)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(w))}function p(w){return w===null||he(w)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(w)):Ie(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||he(w)?f(w):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(w))}function g(w){return w===null||he(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,T,S)(w)}function S(w){return e.enter("lineEnding"),e.consume(w),e.exit("lineEnding"),b}function b(w){return s>0&&Ie(w)?De(e,j,"linePrefix",s+1)(w):j(w)}function j(w){return w===null||he(w)?e.check(ru,v,T)(w):(e.enter("codeFlowValue"),m(w))}function m(w){return w===null||he(w)?(e.exit("codeFlowValue"),j(w)):(e.consume(w),m)}function T(w){return e.exit("codeFenced"),t(w)}function C(w,N,H){let O=0;return _;function _(P){return w.enter("lineEnding"),w.consume(P),w.exit("lineEnding"),I}function I(P){return w.enter("codeFencedFence"),Ie(P)?De(w,z,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(P):z(P)}function z(P){return P===a?(w.enter("codeFencedFenceSequence"),M(P)):H(P)}function M(P){return P===a?(O++,w.consume(P),M):O>=o?(w.exit("codeFencedFenceSequence"),Ie(P)?De(w,A,"whitespace")(P):A(P)):H(P)}function A(P){return P===null||he(P)?(w.exit("codeFencedFence"),N(P)):H(P)}}}function kw(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 eo={name:"codeIndented",tokenize:_w},Sw={partial:!0,tokenize:jw};function _w(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):he(c)?e.attempt(Sw,o,l)(c):(e.enter("codeFlowValue"),a(c))}function a(c){return c===null||he(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):he(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):he(o)?i(o):n(o)}}const Nw={name:"codeText",previous:Cw,resolve:Ew,tokenize:Iw};function Ew(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 Cw(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function Iw(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)):he(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||he(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 Tw{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&zr(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),zr(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),zr(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);zr(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);zr(this.left,n.reverse())}}}function zr(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function fp(e){const t={};let n=-1,r,i,s,o,a,l,c;const d=new Tw(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,Aw(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 It(e,0,Number.POSITIVE_INFINITY,d.slice(0)),!c}function Aw(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 b=a.slice(S[p],S[p+1]),j=s.pop();l.push([j,j+b.length-1]),e.splice(j,2,b)}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 zw={resolve:Pw,tokenize:Dw},Ow={partial:!0,tokenize:Rw};function Pw(e){return fp(e),e}function Dw(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):he(a)?e.check(Ow,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 Rw(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||he(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 pp(e,t,n,r,i,s,o,a,l){const c=l||Number.POSITIVE_INFINITY;let d=0;return f;function f(b){return b===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(b),e.exit(s),p):b===null||b===32||b===41||ts(b)?n(b):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),v(b))}function p(b){return b===62?(e.enter(s),e.consume(b),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),h(b))}function h(b){return b===62?(e.exit("chunkString"),e.exit(a),p(b)):b===null||b===60||he(b)?n(b):(e.consume(b),b===92?g:h)}function g(b){return b===60||b===62||b===92?(e.consume(b),h):h(b)}function v(b){return!d&&(b===null||b===41||Fe(b))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(b)):d<c&&b===40?(e.consume(b),d++,v):b===41?(e.consume(b),d--,v):b===null||b===32||b===40||ts(b)?n(b):(e.consume(b),b===92?S:v)}function S(b){return b===40||b===41||b===92?(e.consume(b),v):v(b)}}function hp(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):he(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||he(h)||a++>999?(e.exit("chunkString"),d(h)):(e.consume(h),l||(l=!Ie(h)),h===92?p:f)}function p(h){return h===91||h===92||h===93?(e.consume(h),a++,f):f(h)}}function mp(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):he(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||he(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 Hr(e,t){let n;return r;function r(i){return he(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):Ie(i)?De(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const Mw={name:"definition",tokenize:Lw},$w={partial:!0,tokenize:Fw};function Lw(e,t,n){const r=this;let i;return s;function s(h){return e.enter("definition"),o(h)}function o(h){return hp.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 Fe(h)?Hr(e,c)(h):c(h)}function c(h){return pp(e,d,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(h)}function d(h){return e.attempt($w,f,f)(h)}function f(h){return Ie(h)?De(e,p,"whitespace")(h):p(h)}function p(h){return h===null||he(h)?(e.exit("definition"),r.parser.defined.push(i),t(h)):n(h)}}function Fw(e,t,n){return r;function r(a){return Fe(a)?Hr(e,i)(a):n(a)}function i(a){return mp(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return Ie(a)?De(e,o,"whitespace")(a):o(a)}function o(a){return a===null||he(a)?t(a):n(a)}}const Bw={name:"hardBreakEscape",tokenize:Zw};function Zw(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return he(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const Vw={name:"headingAtx",resolve:Uw,tokenize:Jw};function Uw(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"},It(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function Jw(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||Fe(d)?(e.exit("atxHeadingSequence"),a(d)):n(d)}function a(d){return d===35?(e.enter("atxHeadingSequence"),l(d)):d===null||he(d)?(e.exit("atxHeading"),t(d)):Ie(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||Fe(d)?(e.exit("atxHeadingText"),a(d)):(e.consume(d),c)}}const Hw=["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"],su=["pre","script","style","textarea"],Ww={concrete:!0,name:"htmlFlow",resolveTo:Yw,tokenize:Kw},qw={partial:!0,tokenize:Qw},Gw={partial:!0,tokenize:Xw};function Yw(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 Kw(e,t,n){const r=this;let i,s,o,a,l;return c;function c(y){return d(y)}function d(y){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(y),f}function f(y){return y===33?(e.consume(y),p):y===47?(e.consume(y),s=!0,v):y===63?(e.consume(y),i=3,r.interrupt?t:k):ht(y)?(e.consume(y),o=String.fromCharCode(y),S):n(y)}function p(y){return y===45?(e.consume(y),i=2,h):y===91?(e.consume(y),i=5,a=0,g):ht(y)?(e.consume(y),i=4,r.interrupt?t:k):n(y)}function h(y){return y===45?(e.consume(y),r.interrupt?t:k):n(y)}function g(y){const Z="CDATA[";return y===Z.charCodeAt(a++)?(e.consume(y),a===Z.length?r.interrupt?t:z:g):n(y)}function v(y){return ht(y)?(e.consume(y),o=String.fromCharCode(y),S):n(y)}function S(y){if(y===null||y===47||y===62||Fe(y)){const Z=y===47,V=o.toLowerCase();return!Z&&!s&&su.includes(V)?(i=1,r.interrupt?t(y):z(y)):Hw.includes(o.toLowerCase())?(i=6,Z?(e.consume(y),b):r.interrupt?t(y):z(y)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(y):s?j(y):m(y))}return y===45||lt(y)?(e.consume(y),o+=String.fromCharCode(y),S):n(y)}function b(y){return y===62?(e.consume(y),r.interrupt?t:z):n(y)}function j(y){return Ie(y)?(e.consume(y),j):_(y)}function m(y){return y===47?(e.consume(y),_):y===58||y===95||ht(y)?(e.consume(y),T):Ie(y)?(e.consume(y),m):_(y)}function T(y){return y===45||y===46||y===58||y===95||lt(y)?(e.consume(y),T):C(y)}function C(y){return y===61?(e.consume(y),w):Ie(y)?(e.consume(y),C):m(y)}function w(y){return y===null||y===60||y===61||y===62||y===96?n(y):y===34||y===39?(e.consume(y),l=y,N):Ie(y)?(e.consume(y),w):H(y)}function N(y){return y===l?(e.consume(y),l=null,O):y===null||he(y)?n(y):(e.consume(y),N)}function H(y){return y===null||y===34||y===39||y===47||y===60||y===61||y===62||y===96||Fe(y)?C(y):(e.consume(y),H)}function O(y){return y===47||y===62||Ie(y)?m(y):n(y)}function _(y){return y===62?(e.consume(y),I):n(y)}function I(y){return y===null||he(y)?z(y):Ie(y)?(e.consume(y),I):n(y)}function z(y){return y===45&&i===2?(e.consume(y),D):y===60&&i===1?(e.consume(y),U):y===62&&i===4?(e.consume(y),oe):y===63&&i===3?(e.consume(y),k):y===93&&i===5?(e.consume(y),X):he(y)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(qw,G,M)(y)):y===null||he(y)?(e.exit("htmlFlowData"),M(y)):(e.consume(y),z)}function M(y){return e.check(Gw,A,G)(y)}function A(y){return e.enter("lineEnding"),e.consume(y),e.exit("lineEnding"),P}function P(y){return y===null||he(y)?M(y):(e.enter("htmlFlowData"),z(y))}function D(y){return y===45?(e.consume(y),k):z(y)}function U(y){return y===47?(e.consume(y),o="",$):z(y)}function $(y){if(y===62){const Z=o.toLowerCase();return su.includes(Z)?(e.consume(y),oe):z(y)}return ht(y)&&o.length<8?(e.consume(y),o+=String.fromCharCode(y),$):z(y)}function X(y){return y===93?(e.consume(y),k):z(y)}function k(y){return y===62?(e.consume(y),oe):y===45&&i===2?(e.consume(y),k):z(y)}function oe(y){return y===null||he(y)?(e.exit("htmlFlowData"),G(y)):(e.consume(y),oe)}function G(y){return e.exit("htmlFlow"),t(y)}}function Xw(e,t,n){const r=this;return i;function i(o){return he(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 Qw(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(gi,t,n)}}const e0={name:"htmlText",tokenize:t0};function t0(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),H):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):he(k)?(o=f,U(k)):(e.consume(k),f)}function p(k){return k===45?(e.consume(k),h):f(k)}function h(k){return k===62?D(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):he(k)?(o=v,U(k)):(e.consume(k),v)}function S(k){return k===93?(e.consume(k),b):v(k)}function b(k){return k===62?D(k):k===93?(e.consume(k),b):v(k)}function j(k){return k===null||k===62?D(k):he(k)?(o=j,U(k)):(e.consume(k),j)}function m(k){return k===null?n(k):k===63?(e.consume(k),T):he(k)?(o=m,U(k)):(e.consume(k),m)}function T(k){return k===62?D(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 he(k)?(o=N,U(k)):Ie(k)?(e.consume(k),N):D(k)}function H(k){return k===45||lt(k)?(e.consume(k),H):k===47||k===62||Fe(k)?O(k):n(k)}function O(k){return k===47?(e.consume(k),D):k===58||k===95||ht(k)?(e.consume(k),_):he(k)?(o=O,U(k)):Ie(k)?(e.consume(k),O):D(k)}function _(k){return k===45||k===46||k===58||k===95||lt(k)?(e.consume(k),_):I(k)}function I(k){return k===61?(e.consume(k),z):he(k)?(o=I,U(k)):Ie(k)?(e.consume(k),I):O(k)}function z(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(e.consume(k),i=k,M):he(k)?(o=z,U(k)):Ie(k)?(e.consume(k),z):(e.consume(k),A)}function M(k){return k===i?(e.consume(k),i=void 0,P):k===null?n(k):he(k)?(o=M,U(k)):(e.consume(k),M)}function A(k){return k===null||k===34||k===39||k===60||k===61||k===96?n(k):k===47||k===62||Fe(k)?O(k):(e.consume(k),A)}function P(k){return k===47||k===62||Fe(k)?O(k):n(k)}function D(k){return k===62?(e.consume(k),e.exit("htmlTextData"),e.exit("htmlText"),t):n(k)}function U(k){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),$}function $(k){return Ie(k)?De(e,X,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(k):X(k)}function X(k){return e.enter("htmlTextData"),o(k)}}const za={name:"labelEnd",resolveAll:s0,resolveTo:o0,tokenize:a0},n0={tokenize:l0},r0={tokenize:u0},i0={tokenize:c0};function s0(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&&It(e,0,e.length,n),e}function o0(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,Ts(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]]),It(e,s,e.length,a),e}function a0(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(n0,d,o?d:f)(p):p===91?e.attempt(r0,d,o?c:f)(p):o?d(p):f(p)}function c(p){return e.attempt(i0,d,f)(p)}function d(p){return t(p)}function f(p){return s._balanced=!0,n(p)}}function l0(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),i}function i(f){return Fe(f)?Hr(e,s)(f):s(f)}function s(f){return f===41?d(f):pp(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function o(f){return Fe(f)?Hr(e,l)(f):d(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?mp(e,c,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):d(f)}function c(f){return Fe(f)?Hr(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 u0(e,t,n){const r=this;return i;function i(a){return hp.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 c0(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const d0={name:"labelStartImage",resolveAll:za.resolveAll,tokenize:f0};function f0(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 p0={name:"labelStartLink",resolveAll:za.resolveAll,tokenize:h0};function h0(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 to={name:"lineEnding",tokenize:m0};function m0(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),De(e,t,"linePrefix")}}const $i={name:"thematicBreak",tokenize:g0};function g0(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||he(c))?(e.exit("thematicBreak"),t(c)):n(c)}function l(c){return c===i?(e.consume(c),r++,l):(e.exit("thematicBreakSequence"),Ie(c)?De(e,a,"whitespace")(c):a(c))}}const xt={continuation:{tokenize:v0},exit:k0,name:"list",tokenize:y0},x0={partial:!0,tokenize:S0},b0={partial:!0,tokenize:w0};function y0(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:Zo(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($i,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 Zo(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(gi,r.interrupt?n:d,e.attempt(x0,p,f))}function d(h){return r.containerState.initialBlankLine=!0,s++,p(h)}function f(h){return Ie(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 v0(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(gi,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||!Ie(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(b0,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 w0(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 k0(e){e.exit(this.containerState.type)}function S0(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!Ie(s)&&o&&o[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const ou={name:"setextUnderline",resolveTo:_0,tokenize:j0};function _0(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"),Ie(c)?De(e,l,"lineSuffix")(c):l(c))}function l(c){return c===null||he(c)?(e.exit("setextHeadingLine"),t(c)):n(c)}}const N0={tokenize:E0};function E0(e){const t=this,n=e.attempt(gi,r,e.attempt(this.parser.constructs.flowInitial,i,De(e,e.attempt(this.parser.constructs.flow,i,e.attempt(zw,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 C0={resolveAll:xp()},I0=gp("string"),T0=gp("text");function gp(e){return{resolveAll:xp(e==="text"?A0: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 xp(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 A0(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 z0={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:up},O0={91:Mw},P0={[-2]:eo,[-1]:eo,32:eo},D0={35:Vw,42:$i,45:[ou,$i],60:Ww,61:ou,95:$i,96:iu,126:iu},R0={38:dp,92:cp},M0={[-5]:to,[-4]:to,[-3]:to,33:d0,38:dp,42:Vo,60:[pw,e0],91:p0,92:[Bw,cp],93:za,95:Vo,96:Nw},$0={null:[Vo,C0]},L0={null:[42,95]},F0={null:[]},B0=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:L0,contentInitial:O0,disable:F0,document:z0,flow:D0,flowInitial:P0,insideSpan:$0,string:R0,text:M0},Symbol.toStringTag,{value:"Module"}));function Z0(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:T,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(I){return o=Ot(o,I),S(),o[o.length-1]!==null?[]:(H(t,0),c.events=Ts(s,c.events,c),c.events)}function p(I,z){return U0(h(I),z)}function h(I){return V0(o,I)}function g(){const{_bufferIndex:I,_index:z,line:M,column:A,offset:P}=r;return{_bufferIndex:I,_index:z,line:M,column:A,offset:P}}function v(I){i[I.line]=I.column,_()}function S(){let I;for(;r._index<o.length;){const z=o[r._index];if(typeof z=="string")for(I=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===I&&r._bufferIndex<z.length;)b(z.charCodeAt(r._bufferIndex));else b(z)}}function b(I){d=d(I)}function j(I){he(I)?(r.line++,r.column=1,r.offset+=I===-3?2:1,_()):I!==-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=I}function m(I,z){const M=z||{};return M.type=I,M.start=g(),c.events.push(["enter",M,c]),a.push(M),M}function T(I){const z=a.pop();return z.end=g(),c.events.push(["exit",z,c]),z}function C(I,z){H(I,z.from)}function w(I,z){z.restore()}function N(I,z){return M;function M(A,P,D){let U,$,X,k;return Array.isArray(A)?G(A):"tokenize"in A?G([A]):oe(A);function oe(ie){return se;function se(re){const de=re!==null&&ie[re],ge=re!==null&&ie.null,Ee=[...Array.isArray(de)?de:de?[de]:[],...Array.isArray(ge)?ge:ge?[ge]:[]];return G(Ee)(re)}}function G(ie){return U=ie,$=0,ie.length===0?D:y(ie[$])}function y(ie){return se;function se(re){return k=O(),X=ie,ie.partial||(c.currentConstruct=ie),ie.name&&c.parser.constructs.disable.null.includes(ie.name)?V():ie.tokenize.call(z?Object.assign(Object.create(c),z):c,l,Z,V)(re)}}function Z(ie){return I(X,k),P}function V(ie){return k.restore(),++$<U.length?y(U[$]):D}}}function H(I,z){I.resolveAll&&!s.includes(I)&&s.push(I),I.resolve&&It(c.events,z,c.events.length-z,I.resolve(c.events.slice(z),c)),I.resolveTo&&(c.events=I.resolveTo(c.events,c))}function O(){const I=g(),z=c.previous,M=c.currentConstruct,A=c.events.length,P=Array.from(a);return{from:A,restore:D};function D(){r=I,c.previous=z,c.currentConstruct=M,c.events.length=A,a=P,_()}}function _(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function V0(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 U0(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 J0(e){const r={constructs:ap([B0,...(e||{}).extensions||[]]),content:i(ow),defined:[],document:i(lw),flow:i(N0),lazy:{},string:i(I0),text:i(T0)};return r;function i(s){return o;function o(a){return Z0(r,s,a)}}}function H0(e){for(;!fp(e););return e}const au=/[\0\t\n\r]/g;function W0(){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(au.lastIndex=f,c=au.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 q0=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function G0(e){return e.replace(q0,Y0)}function Y0(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return lp(n.slice(s?2:1),s?16:10)}return Aa(n)||e}const bp={}.hasOwnProperty;function K0(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),X0(n)(H0(J0(n).document().write(W0()(e,t,!0))))}function X0(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(R),autolinkProtocol:O,autolinkEmail:O,atxHeading:s(Oe),blockQuote:s(ge),characterEscape:O,characterReference:O,codeFenced:s(Ee),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(Ee,o),codeText:s(ye,o),codeTextData:O,data:O,codeFlowValue:O,definition:s(xe),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(W),hardBreakEscape:s(Q),hardBreakTrailing:s(Q),htmlFlow:s(ve,o),htmlFlowData:O,htmlText:s(ve,o),htmlTextData:O,image:s(E),label:o,link:s(R),listItem:s(te),listItemValue:p,listOrdered:s(L,f),listUnordered:s(L),paragraph:s(K),reference:y,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Oe),strong:s(ee),thematicBreak:s(be)},exit:{atxHeading:l(),atxHeadingSequence:C,autolink:l(),autolinkEmail:de,autolinkProtocol:re,blockQuote:l(),characterEscapeValue:_,characterReferenceMarkerHexadecimal:V,characterReferenceMarkerNumeric:V,characterReferenceValue:ie,characterReference:se,codeFenced:l(S),codeFencedFence:v,codeFencedFenceInfo:h,codeFencedFenceMeta:g,codeFlowValue:_,codeIndented:l(b),codeText:l(P),codeTextData:_,data:_,definition:l(),definitionDestinationString:T,definitionLabelString:j,definitionTitleString:m,emphasis:l(),hardBreakEscape:l(z),hardBreakTrailing:l(z),htmlFlow:l(M),htmlFlowData:_,htmlText:l(A),htmlTextData:_,image:l(U),label:X,labelText:$,lineEnding:I,link:l(D),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:Z,resourceDestinationString:k,resourceTitleString:oe,resource:G,setextHeading:l(H),setextHeadingLineSequence:N,setextHeadingText:w,strong:l(),thematicBreak:l()}};yp(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(B){let Y={type:"root",children:[]};const fe={stack:[Y],tokenStack:[],config:t,enter:a,exit:c,buffer:o,resume:d,data:n},_e=[];let F=-1;for(;++F<B.length;)if(B[F][1].type==="listOrdered"||B[F][1].type==="listUnordered")if(B[F][0]==="enter")_e.push(F);else{const pe=_e.pop();F=i(B,pe,F)}for(F=-1;++F<B.length;){const pe=t[B[F][0]];bp.call(pe,B[F][1].type)&&pe[B[F][1].type].call(Object.assign({sliceSerialize:B[F][2].sliceSerialize},fe),B[F][1])}if(fe.tokenStack.length>0){const pe=fe.tokenStack[fe.tokenStack.length-1];(pe[1]||lu).call(fe,void 0,pe[0])}for(Y.position={start:dn(B.length>0?B[0][1].start:{line:1,column:1,offset:0}),end:dn(B.length>0?B[B.length-2][1].end:{line:1,column:1,offset:0})},F=-1;++F<t.transforms.length;)Y=t.transforms[F](Y)||Y;return Y}function i(B,Y,fe){let _e=Y-1,F=-1,pe=!1,Te,Be,rt,tt;for(;++_e<=fe;){const at=B[_e];switch(at[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{at[0]==="enter"?F++:F--,tt=void 0;break}case"lineEndingBlank":{at[0]==="enter"&&(Te&&!tt&&!F&&!rt&&(rt=_e),tt=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:tt=void 0}if(!F&&at[0]==="enter"&&at[1].type==="listItemPrefix"||F===-1&&at[0]==="exit"&&(at[1].type==="listUnordered"||at[1].type==="listOrdered")){if(Te){let un=_e;for(Be=void 0;un--;){const en=B[un];if(en[1].type==="lineEnding"||en[1].type==="lineEndingBlank"){if(en[0]==="exit")continue;Be&&(B[Be][1].type="lineEndingBlank",pe=!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)&&(Te._spread=!0),Te.end=Object.assign({},Be?B[Be][1].start:at[1].end),B.splice(Be||_e,0,["exit",Te,at[2]]),_e++,fe++}if(at[1].type==="listItemPrefix"){const un={type:"listItem",_spread:!1,start:Object.assign({},at[1].start),end:void 0};Te=un,B.splice(_e,0,["enter",un,at[2]]),_e++,fe++,rt=void 0,tt=!0}}}return B[Y][1]._spread=pe,fe}function s(B,Y){return fe;function fe(_e){a.call(this,B(_e),_e),Y&&Y.call(this,_e)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(B,Y,fe){this.stack[this.stack.length-1].children.push(B),this.stack.push(B),this.tokenStack.push([Y,fe||void 0]),B.position={start:dn(Y.start),end:void 0}}function l(B){return Y;function Y(fe){B&&B.call(this,fe),c.call(this,fe)}}function c(B,Y){const fe=this.stack.pop(),_e=this.tokenStack.pop();if(_e)_e[0].type!==B.type&&(Y?Y.call(this,B,_e[0]):(_e[1]||lu).call(this,B,_e[0]));else throw new Error("Cannot close `"+B.type+"` ("+Jr({start:B.start,end:B.end})+"): it’s not open");fe.position.end=dn(B.end)}function d(){return Ta(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function p(B){if(this.data.expectingFirstListItemValue){const Y=this.stack[this.stack.length-2];Y.start=Number.parseInt(this.sliceSerialize(B),10),this.data.expectingFirstListItemValue=void 0}}function h(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.lang=B}function g(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.meta=B}function v(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function S(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.value=B.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function b(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.value=B.replace(/(\r?\n|\r)$/g,"")}function j(B){const Y=this.resume(),fe=this.stack[this.stack.length-1];fe.label=Y,fe.identifier=Vt(this.sliceSerialize(B)).toLowerCase()}function m(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.title=B}function T(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.url=B}function C(B){const Y=this.stack[this.stack.length-1];if(!Y.depth){const fe=this.sliceSerialize(B).length;Y.depth=fe}}function w(){this.data.setextHeadingSlurpLineEnding=!0}function N(B){const Y=this.stack[this.stack.length-1];Y.depth=this.sliceSerialize(B).codePointAt(0)===61?1:2}function H(){this.data.setextHeadingSlurpLineEnding=void 0}function O(B){const fe=this.stack[this.stack.length-1].children;let _e=fe[fe.length-1];(!_e||_e.type!=="text")&&(_e=ue(),_e.position={start:dn(B.start),end:void 0},fe.push(_e)),this.stack.push(_e)}function _(B){const Y=this.stack.pop();Y.value+=this.sliceSerialize(B),Y.position.end=dn(B.end)}function I(B){const Y=this.stack[this.stack.length-1];if(this.data.atHardBreak){const fe=Y.children[Y.children.length-1];fe.position.end=dn(B.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(Y.type)&&(O.call(this,B),_.call(this,B))}function z(){this.data.atHardBreak=!0}function M(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.value=B}function A(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.value=B}function P(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.value=B}function D(){const B=this.stack[this.stack.length-1];if(this.data.inReference){const Y=this.data.referenceType||"shortcut";B.type+="Reference",B.referenceType=Y,delete B.url,delete B.title}else delete B.identifier,delete B.label;this.data.referenceType=void 0}function U(){const B=this.stack[this.stack.length-1];if(this.data.inReference){const Y=this.data.referenceType||"shortcut";B.type+="Reference",B.referenceType=Y,delete B.url,delete B.title}else delete B.identifier,delete B.label;this.data.referenceType=void 0}function $(B){const Y=this.sliceSerialize(B),fe=this.stack[this.stack.length-2];fe.label=G0(Y),fe.identifier=Vt(Y).toLowerCase()}function X(){const B=this.stack[this.stack.length-1],Y=this.resume(),fe=this.stack[this.stack.length-1];if(this.data.inReference=!0,fe.type==="link"){const _e=B.children;fe.children=_e}else fe.alt=Y}function k(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.url=B}function oe(){const B=this.resume(),Y=this.stack[this.stack.length-1];Y.title=B}function G(){this.data.inReference=void 0}function y(){this.data.referenceType="collapsed"}function Z(B){const Y=this.resume(),fe=this.stack[this.stack.length-1];fe.label=Y,fe.identifier=Vt(this.sliceSerialize(B)).toLowerCase(),this.data.referenceType="full"}function V(B){this.data.characterReferenceType=B.type}function ie(B){const Y=this.sliceSerialize(B),fe=this.data.characterReferenceType;let _e;fe?(_e=lp(Y,fe==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):_e=Aa(Y);const F=this.stack[this.stack.length-1];F.value+=_e}function se(B){const Y=this.stack.pop();Y.position.end=dn(B.end)}function re(B){_.call(this,B);const Y=this.stack[this.stack.length-1];Y.url=this.sliceSerialize(B)}function de(B){_.call(this,B);const Y=this.stack[this.stack.length-1];Y.url="mailto:"+this.sliceSerialize(B)}function ge(){return{type:"blockquote",children:[]}}function Ee(){return{type:"code",lang:null,meta:null,value:""}}function ye(){return{type:"inlineCode",value:""}}function xe(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function W(){return{type:"emphasis",children:[]}}function Oe(){return{type:"heading",depth:0,children:[]}}function Q(){return{type:"break"}}function ve(){return{type:"html",value:""}}function E(){return{type:"image",title:null,url:"",alt:null}}function R(){return{type:"link",title:null,url:"",children:[]}}function L(B){return{type:"list",ordered:B.type==="listOrdered",start:null,spread:B._spread,children:[]}}function te(B){return{type:"listItem",spread:B._spread,checked:null,children:[]}}function K(){return{type:"paragraph",children:[]}}function ee(){return{type:"strong",children:[]}}function ue(){return{type:"text",value:""}}function be(){return{type:"thematicBreak"}}}function dn(e){return{line:e.line,column:e.column,offset:e.offset}}function yp(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?yp(e,r):Q0(e,r)}}function Q0(e,t){let n;for(n in t)if(bp.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 lu(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+Jr({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+Jr({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+Jr({start:t.start,end:t.end})+") is still open")}function ek(e){const t=this;t.parser=n;function n(r){return K0(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function tk(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function nk(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
|
|
@@ -103,4 +103,4 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
103
103
|
`;)t++;return!0}return!1}function c($){if(d($)){if(vc(e[t]))for(;t<e.length&&wc(e[t]);)t++;return o(),!0}return!1}function d($){a(!0);for(const X of $){const k=t+X.length;if(e.slice(t,k)===X)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 X;if($?(X=!0,$=!1):(X=f(","),X||(n=Mt(n,",")),o()),g(),!(j()||N(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=Pr(n,","):P();break}o();const oe=f(":"),G=t>=e.length;oe||(jc(e[t])||G?n=Mt(n,":"):D()),s()||(oe||G?n+="null":D())}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=Pr(n,",");break}return e[t]==="]"?(n+="]",t++):n=Mt(n,"]"),!0}return!1}function b(){let $=!0,X=!0;for(;X;)$?$=!1:f(",")||(n=Mt(n,",")),X=s();X||(n=Pr(n,",")),n=`[
|
|
104
104
|
${n}
|
|
105
105
|
]`}function j(){let $=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1,X=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1,k=e[t]==="\\";if(k&&(t++,k=!0),Bi(e[t])){const oe=Nc(e[t])?Nc:Ec(e[t])?Ec:sa(e[t])?sa:Pm,G=t,y=n.length;let Z='"';for(t++;;){if(t>=e.length){const V=O(t-1);return!$&&Oi(e.charAt(V))?(t=G,n=n.substring(0,y),j(!0)):(Z=Mt(Z,'"'),n+=Z,!0)}if(t===X)return Z=Mt(Z,'"'),n+=Z,!0;if(oe(e[t])){const V=t,ie=Z.length;if(Z+='"',t++,n+=Z,o(!1),$||t>=e.length||Oi(e[t])||Bi(e[t])||Cn(e[t]))return m(),!0;const se=O(V-1),re=e.charAt(se);if(re===",")return t=G,n=n.substring(0,y),j(!1,se);if(Oi(re))return t=G,n=n.substring(0,y),j(!0);n=n.substring(0,y),t=V+1,Z=`${Z.substring(0,ie)}\\${Z.substring(ie)}`}else if($&&_c(e[t])){if(e[t-1]===":"&&kc.test(e.substring(G+1,t+2)))for(;t<e.length&&Sc.test(e[t]);)Z+=e[t],t++;return Z=Mt(Z,'"'),n+=Z,m(),!0}else if(e[t]==="\\"){const V=e.charAt(t+1);if($A[V]!==void 0)Z+=e.slice(t,t+2),t+=2;else if(V==="u"){let se=2;for(;se<6&&IA(e[t+se]);)se++;se===6?(Z+=e.slice(t,t+6),t+=6):t+se>=e.length?t=e.length:U()}else Z+=V,t+=2}else{const V=e.charAt(t);V==='"'&&e[t-1]!=="\\"?(Z+=`\\${V}`,t++):zA(V)?(Z+=MA[V],t++):(TA(V)||z(V),Z+=V,t++)}k&&h()}}return!1}function m(){let $=!1;for(o();e[t]==="+";){$=!0,t++,o(),n=Pr(n,'"',!0);const X=n.length;j()?n=DA(n,X,1):n=Mt(n,'"')}return $}function T(){const $=t;if(e[t]==="-"){if(t++,_())return I($),!0;if(!Cn(e[t]))return t=$,!1}for(;Cn(e[t]);)t++;if(e[t]==="."){if(t++,_())return I($),!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 I($),!0;if(!Cn(e[t]))return t=$,!1;for(;Cn(e[t]);)t++}if(!_())return t=$,!1;if(t>$){const X=e.slice($,t),k=/^0\d/.test(X);return n+=k?`"${X}"`:X,!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($,X){return e.slice(t,t+$.length)===$?(n+=X,t+=$.length,!0):!1}function N($){const X=t;if(vc(e[t])){for(;t<e.length&&wc(e[t]);)t++;let k=t;for(;In(e,k);)k++;if(e[k]==="(")return t=k+1,s(),e[t]===")"&&(t++,e[t]===";"&&t++),!0}for(;t<e.length&&!_c(e[t])&&!Bi(e[t])&&(!$||e[t]!==":");)t++;if(e[t-1]===":"&&kc.test(e.substring(X,t+2)))for(;t<e.length&&Sc.test(e[t]);)t++;if(t>X){for(;In(e,t-1)&&t>0;)t--;const k=e.slice(X,t);return n+=k==="undefined"?"null":JSON.stringify(k),e[t]==='"'&&t++,!0}}function H(){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 O($){let X=$;for(;X>0&&In(e,X);)X--;return X}function _(){return t>=e.length||Oi(e[t])||In(e,t)}function I($){n+=`${e.slice($,t)}0`}function z($){throw new Kn(`Invalid character ${JSON.stringify($)}`,t)}function M(){throw new Kn(`Unexpected character ${JSON.stringify(e[t])}`,t)}function A(){throw new Kn("Unexpected end of json string",e.length)}function P(){throw new Kn("Object key expected",t)}function D(){throw new Kn("Colon expected",t)}function U(){const $=e.slice(t,t+6);throw new Kn(`Invalid unicode character "${$}"`,t)}}function LA(e,t){return e[t]==="*"&&e[t+1]==="/"}function FA({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 Cc(e)}catch{}const b=`{${e}}`;try{return JSON.parse(b),b}catch{}try{return Cc(b)}catch{return null}},[e]),l=x.useMemo(()=>Em(a||e),[a,e]),c=Pe(b=>b.activeTab),d=Pe(b=>b.documents),f=Pe(b=>(b.acceptedApplyIds||[]).includes(l)),p=Pe(b=>b.setPendingDiff),h=Pe(b=>b.createDocument),g=Pe(b=>b.openDocument),v=x.useCallback(()=>{if(a){o(null);try{if(c){const b=d.find(w=>w.name===c),j=(b==null?void 0:b.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=Nm(w.props.templates||[],N.templates);const H=JSON.stringify(w,null,2);p(c,j,H,l);return}}catch{}const m=t==null?void 0:t[0],{original:T,modified:C}=Cm(j,a,m);p(c,T,C,l)}else{const b=`ai-generated-${Date.now()}`;h(b,a),g(b)}}catch(b){o(b instanceof Error?b.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(Ne,{variant:"secondary",size:"sm",onClick:v,disabled:f||!a,children:f?"Applied":a?"Apply to Editor":"Invalid JSON"}),u.jsx(Ne,{variant:"ghost",size:"sm",onClick:S,children:r?u.jsx(bn,{className:"h-3.5 w-3.5"}):u.jsx(bs,{className:"h-3.5 w-3.5"})})]}),s&&u.jsx("p",{className:"text-xs text-destructive m-0",children:s})]})}function BA({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,H)=>{H.stopPropagation(),H.preventDefault(),l(N.id),d(N.title),p(null)},[]),b=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(),b()):N.key==="Escape"&&(N.preventDefault(),j())},[b,j]),T=x.useCallback((N,H)=>{H.stopPropagation(),H.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(ks,{onOpenChange:N=>{N||(l(null),p(null))},children:[u.jsx(Ss,{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(ci,{className:"h-3 w-3 shrink-0 opacity-60"})]})}),u.jsxs(hi,{align:"start",className:"w-64",children:[e.map(N=>{const H=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(bn,{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):H?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:b,className:"flex-1 min-w-0 text-sm rounded-sm border border-border bg-background px-1.5 py-0.5 outline-none focus:ring-1 focus:ring-primary/40"}),u.jsx("button",{className:"shrink-0 text-primary hover:text-primary/80 transition-colors cursor-pointer",onMouseDown:_=>{_.preventDefault(),b()},children:u.jsx(bn,{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(Lt,{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(Wg,{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:_=>T(N.id,_),children:u.jsx(la,{className:"h-3 w-3"})})]})]},N.id)}),u.jsx(fr,{}),u.jsxs(Lt,{onSelect:N=>{N.preventDefault();const H=i();H&&(l(H),d(ma()),p(null))},children:[u.jsx(nn,{className:"h-3.5 w-3.5 mr-1.5"}),"New Chat"]})]})]}),u.jsx(Ne,{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 Dm=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),ZA=Array.from(Dm).join(","),VA=20*1024*1024,Ic=10;function UA(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 Tc(e){return Array.from(e).filter(t=>Dm.has(t.type)&&t.size<=VA)}function Rm(e){return e.startsWith("image/")}function Ac(){var Y,fe,_e;const e=Re(F=>F.contextAttachments),t=Re(F=>F.addContext),n=Re(F=>F.removeContext),r=Re(F=>F.scope),i=Re(F=>F.setScope),s=Re(F=>F.model),o=Re(F=>F.setModel),a=Re(F=>F.openChat),l=Re(F=>F.closeChat),c=Re(F=>F.threads),d=Re(F=>F.activeThreadId),f=Re(F=>F.createThread),p=Re(F=>F.deleteThread),h=Re(F=>F.switchThread),g=Re(F=>F.updateThreadMessages),v=Re(F=>F.updateThreadTitle),S=Re(F=>F.deleteThreadsForDocument),b=Pe(F=>F.activeTab),j=Pe(F=>F.documents),{messages:m,sendMessage:T,status:C,error:w,setMessages:N,stop:H,getMessageContext:O,getMessageScope:_}=xA(),[I,z]=x.useState(""),[M,A]=x.useState([]),[P,D]=x.useState(!1),[U,$]=x.useState(!1),X=x.useRef(null),k=x.useRef(null),oe=x.useRef(null),G=x.useCallback(async F=>{const pe=Tc(F);if(pe.length===0)return;const Te=await Promise.all(pe.map(UA));A(Be=>{const rt=[...Be,...Te];return rt.length>Ic?rt.slice(0,Ic):rt})},[]),y=x.useCallback(F=>{A(pe=>pe.filter((Te,Be)=>Be!==F))},[]),Z=x.useCallback(F=>{var Te;const pe=(Te=F.clipboardData)==null?void 0:Te.files;if(pe&&pe.length>0){const Be=Tc(pe);Be.length>0&&(F.preventDefault(),G(Be))}},[G]),V=x.useCallback(F=>{var Te;F.preventDefault(),$(!1);const pe=(Te=F.dataTransfer)==null?void 0:Te.files;pe&&pe.length>0&&G(Array.from(pe))},[G]),ie=x.useCallback(F=>{F.preventDefault(),$(!0)},[]),se=x.useCallback(()=>$(!1),[]),re=b?d[b]:void 0,de=re?c[re]:void 0,ge=x.useMemo(()=>b?Object.values(c).filter(F=>F.documentName===b).sort((F,pe)=>pe.updatedAt-F.updatedAt):[],[c,b]);x.useEffect(()=>{b&&ge.length===0&&f(b)},[b,ge.length,f]);const Ee=x.useRef(c);Ee.current=c,x.useEffect(()=>{const F=new Set(j.map(Te=>Te.name)),pe=new Set;for(const Te of Object.values(Ee.current))!F.has(Te.documentName)&&Te.documentName!=="__migrated__"&&pe.add(Te.documentName);for(const Te of pe)S(Te)},[j,S]);const ye=x.useRef(null);x.useEffect(()=>{ye.current!==re&&(ye.current=re,N((de==null?void 0:de.messages)??[]))},[re,de,N]),x.useEffect(()=>{var F;(F=X.current)==null||F.scrollIntoView({behavior:"smooth"})},[m,C]),x.useEffect(()=>{const F=pe=>{var rt;const{documentName:Te,selection:Be}=pe.detail;t({...Be,documentName:Te}),a(),(rt=k.current)==null||rt.focus()};return window.addEventListener("monaco-selection-to-ai",F),()=>window.removeEventListener("monaco-selection-to-ai",F)},[t,a]);const xe=C==="streaming",W=C==="submitted"||xe,Oe=x.useCallback(F=>{F.preventDefault(),!(!I.trim()&&M.length===0||W)&&(T(I,M.length>0?M:void 0),z(""),A([]))},[I,M,W,T]),Q=x.useCallback(F=>{F.key==="Enter"&&!F.shiftKey&&(F.preventDefault(),Oe(F))},[Oe]),ve=x.useCallback(()=>{m.length!==0&&D(!0)},[m.length]),E=x.useCallback(()=>{D(!1),N([]),re&&(g(re,[]),v(re,ma()))},[N,re,g,v]),[R,L]=x.useState(null),te=x.useCallback(F=>{L(F)},[]),K=x.useCallback(()=>{var rt,tt;if(!R)return;const F=m.findIndex(at=>at.id===R);if(F===-1){L(null);return}const pe=m[F],Te=new Set([F]);pe.role==="user"&&((rt=m[F+1])==null?void 0:rt.role)==="assistant"?Te.add(F+1):pe.role==="assistant"&&F>0&&((tt=m[F-1])==null?void 0:tt.role)==="user"&&Te.add(F-1);const Be=m.filter((at,un)=>!Te.has(un));N(Be),re&&g(re,Be),L(null)},[R,m,N,re,g]),ee=x.useCallback(F=>{if(!W){if(ge.length<=1){ve();return}p(F)}},[W,ge.length,ve,p]),ue=x.useCallback(()=>{if(!(!b||W))return f(b)},[b,W,f]),be=x.useCallback(F=>{W||F===re||h(F)},[W,re,h]),B=x.useCallback((F,pe)=>{v(F,pe)},[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(BA,{threads:ge,activeThread:de,disabled:W,onSwitch:be,onCreate:ue,onDelete:ee,onRename:B}),u.jsxs("div",{className:"flex items-center gap-1",children:[u.jsx(Ne,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:ve,disabled:W||m.length===0,children:"Clear"}),u.jsx(Ne,{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(Yr,{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(el,{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(Kr,{shortcut:"mod+k"}),u.jsx("span",{className:"text-xs text-muted-foreground",children:"to send a selection"})]})]}),m.map((F,pe)=>{let Te;if(F.role==="user"){const tt=O(F.id);tt&&tt.length>0&&(Te=tt)}else if(F.role==="assistant"){for(let tt=pe-1;tt>=0;tt--)if(m[tt].role==="user"){Te=O(m[tt].id);break}}const Be=xe&&pe===m.length-1&&F.role==="assistant",rt=F.role==="user"?_(F.id):void 0;return u.jsx(JA,{msg:F,isStreaming:Be,context:Te,scope:rt,onDelete:W?void 0:te},F.id)}),W&&((Y=m[m.length-1])==null?void 0:Y.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(jo,{className:"h-3.5 w-3.5 animate-spin text-primary"}),u.jsx("span",{children:"Thinking..."})]})})}),w&&!W&&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:X})]})}),u.jsxs("div",{className:`border-t border-border/60 p-2.5 space-y-2 bg-surface-chat transition-colors ${U?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:V,onDragOver:ie,onDragLeave:se,children:[e.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((F,pe)=>u.jsx(Tm,{context:F,onRemove:()=>n(pe)},pe))}),u.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[u.jsx(qA,{model:s,setModel:o}),ot==="pptx"&&b&&u.jsx(YA,{scope:r,setScope:i,docSize:((_e=(fe=j.find(F=>F.name===b))==null?void 0:fe.text)==null?void 0:_e.length)??0})]}),M.length>0&&u.jsx("div",{className:"flex flex-wrap gap-1.5",children:M.map((F,pe)=>u.jsxs("div",{className:"relative group",children:[Rm(F.mediaType)?u.jsx("img",{src:F.url,alt:F.filename||"attachment",className:"h-14 w-14 rounded-md object-cover border border-border/60"}):u.jsxs("div",{className:"h-14 px-2.5 flex items-center gap-1.5 rounded-md border border-border/60 bg-muted/60 max-w-[140px]",children:[u.jsx(No,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),u.jsx("span",{className:"text-xs truncate text-muted-foreground",children:F.filename||"file"})]}),u.jsx("button",{type:"button",onClick:()=>y(pe),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"})})]},pe))}),u.jsxs("form",{onSubmit:Oe,className:"flex items-end gap-2",children:[u.jsx("input",{ref:oe,type:"file",accept:ZA,multiple:!0,className:"hidden",onChange:F=>{F.target.files&&G(Array.from(F.target.files)),F.target.value=""}}),u.jsx(Ne,{type:"button",variant:"ghost",size:"icon",className:"shrink-0 h-9 w-9 rounded-lg text-muted-foreground hover:text-foreground",onClick:()=>{var F;return(F=oe.current)==null?void 0:F.click()},title:"Attach file",children:u.jsx(No,{className:"h-4 w-4"})}),u.jsx("textarea",{ref:k,value:I,onChange:F=>{z(F.target.value);const pe=F.target;pe.style.height="auto",pe.style.height=`${Math.min(pe.scrollHeight,128)}px`},onKeyDown:Q,onPaste:Z,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}),W?u.jsx(Ne,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:H,title:"Stop generating",children:u.jsx(wd,{className:"h-4 w-4"})}):u.jsx(Ne,{type:"submit",size:"icon",disabled:!I.trim()&&M.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:u.jsx(el,{className:"h-4 w-4"})})]})]}),u.jsx(Ct,{open:P,onOpenChange:D,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(yn,{children:[u.jsx(nl,{asChild:!0,children:u.jsx(Ne,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Ne,{variant:"destructive",size:"sm",onClick:E,children:"Clear"})]})]})}),u.jsx(Ct,{open:R!==null,onOpenChange:F=>{F||L(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(yn,{children:[u.jsx(nl,{asChild:!0,children:u.jsx(Ne,{variant:"ghost",size:"sm",children:"Cancel"})}),u.jsx(Ne,{variant:"destructive",size:"sm",onClick:K,children:"Delete"})]})]})})]})}const JA=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)=>Rm(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(No,{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(Tm,{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(HA,{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(la,{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 HA({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(y1,{remarkPlugins:[z_],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(KA,{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(FA,{json:l,context:n,scope:r})]})}},children:e})})}const WA=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function qA({model:e,setModel:t}){return u.jsxs(qr,{value:e,onValueChange:n=>t(n),children:[u.jsx(cr,{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(Gr,{})}),u.jsx(dr,{children:WA.map(n=>u.jsx(Dn,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const zc={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"},GA=1e5;function YA({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(zc).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:zc[r]})]},r))})]}),e==="global"&&n>GA&&u.jsxs("div",{className:"text-[10px] text-warning flex items-center gap-1",children:[u.jsx(_d,{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 KA({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 XA({discoveryData:e}){const t=uf(),n=sb(),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,b]=x.useState(!1);x.useEffect(()=>{try{localStorage.setItem("dev-env.sidebar-open",String(s))}catch{}},[s]),x.useEffect(()=>{try{localStorage.setItem("dev-env.preview-open",String(a))}catch{}},[a]);const j=x.useRef(n);x.useEffect(()=>{n&&!j.current&&s&&(b(!0),o(!1),setTimeout(()=>{v(!0),b(!1)},h)),!n&&j.current&&!s&&(b(!0),o(!0),setTimeout(()=>{v(!1),b(!1)},h)),j.current=n},[n,s]);const m=x.useCallback(()=>{if(t){p(_=>!_);return}b(!0),o(_=>!_),setTimeout(()=>{v(_=>!_),b(!1)},h)},[t]),T=x.useCallback(()=>l(_=>!_),[]),C=x.useRef(i),w=x.useRef(m),N=x.useRef(T);x.useEffect(()=>{C.current=i}),x.useEffect(()=>{w.current=m}),x.useEffect(()=>{N.current=T}),x.useEffect(()=>{const _=I=>{(I.metaKey||I.ctrlKey)&&(I.code==="KeyB"&&!I.shiftKey&&(I.preventDefault(),w.current()),I.code==="KeyJ"&&I.shiftKey&&(I.preventDefault(),I.stopPropagation(),C.current()),I.code==="KeyP"&&I.shiftKey&&(I.preventDefault(),N.current()))};return window.addEventListener("keydown",_,!0),()=>window.removeEventListener("keydown",_,!0)},[]);const H=gA,O=[{key:"editor",icon:_o,label:"Editor"},{key:"preview",icon:jd,label:"Preview"},{key:"chat",icon:Nd,label:"Chat"}];return t?u.jsx(H,{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(of,{open:f,onOpenChange:p,children:[u.jsx(eb,{asChild:!0,children:u.jsx(Ne,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:u.jsx(Sd,{className:"h-4 w-4"})})}),u.jsx(xa,{side:"left",className:"p-0 w-72",children:u.jsx(_l,{discoveryData:e,onToggleSidebar:()=>p(!1),isCollapsed:!1})})]}),u.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:O.map(({key:_,icon:I,label:z})=>u.jsxs(Ne,{variant:c===_?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>d(_),children:[u.jsx(I,{className:"h-3.5 w-3.5"}),u.jsx("span",{className:"hidden xs:inline",children:z})]},_))})]}),c!=="chat"&&u.jsx(Bl,{previewOpen:a,onTogglePreview:T}),u.jsxs("div",{className:"flex-1 min-h-0",children:[c==="editor"&&u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(jl,{})}),c==="preview"&&u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Nl,{})}),c==="chat"&&u.jsx(Ac,{})]})]})}):u.jsx(H,{children:u.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[u.jsx("div",{className:q("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(_l,{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(Bl,{previewOpen:a,onTogglePreview:T}),u.jsxs(Zy,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[u.jsx(Gs,{defaultSize:a?50:100,minSize:20,id:"editor",order:1,children:u.jsx("div",{className:"h-full bg-surface-editor",children:u.jsx(jl,{})})}),a&&u.jsxs(u.Fragment,{children:[u.jsx(Rl,{withHandle:!0}),u.jsx(Gs,{defaultSize:50,minSize:20,id:"preview",order:2,children:u.jsx("div",{className:"h-full bg-surface-preview",children:u.jsx(Nl,{})})})]}),r&&u.jsxs(u.Fragment,{children:[u.jsx(Rl,{withHandle:!0}),u.jsx(Gs,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:u.jsx(Ac,{})})]})]})]})]})})}function QA(){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 Pi=null;async function ez(){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 tz(){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{Pi||(Pi=ez().finally(()=>{Pi=null}));const a=await Pi;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 nz(){const{data:e,loading:t,error:n}=QA(),{loadPlugins:r}=tz(),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(Kg,{children:u.jsx(Xg,{children:u.jsx(Qg,{children:u.jsx(ex,{children:u.jsx(tx,{children:u.jsx(Mx,{children:u.jsx(df,{children:u.jsx("section",{className:"flex h-screen w-full flex-col",children:u.jsx("div",{className:"grow overflow-hidden",children:u.jsx(XA,{discoveryData:e})})})})})})})})})})}const fz=Object.freeze(Object.defineProperty({__proto__:null,HomePage:nz},Symbol.toStringTag,{value:"Module"}));export{Kt as B,Ct as D,fz as H,Gy as P,Ur as S,ti as T,Hf as a,sf as b,kt as c,Ut as d,Jt as e,Jy as u};
|
|
106
|
-
//# sourceMappingURL=HomePage-
|
|
106
|
+
//# sourceMappingURL=HomePage-B6EwpLeU.js.map
|