@json-to-office/jto 2.3.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/cli.js +123 -39
  2. package/dist/cli.js.map +1 -1
  3. package/dist/client/assets/HomePage-BlzZ7qG4.js +245 -0
  4. package/dist/client/assets/HomePage-BlzZ7qG4.js.map +1 -0
  5. package/dist/client/assets/{JsonEditorPage-DR9E7ul1.js → JsonEditorPage-kWuP_kL3.js} +3 -3
  6. package/dist/client/assets/{JsonEditorPage-DR9E7ul1.js.map → JsonEditorPage-kWuP_kL3.js.map} +1 -1
  7. package/dist/client/assets/{MonacoPluginProvider-CdHBp1cD.js → MonacoPluginProvider-Dbv1PrO2.js} +6 -6
  8. package/dist/client/assets/{MonacoPluginProvider-CdHBp1cD.js.map → MonacoPluginProvider-Dbv1PrO2.js.map} +1 -1
  9. package/dist/client/assets/{_virtual_jto-plugin-type-libs-BlMraosv.js → _virtual_jto-plugin-type-libs-B6KyD9RL.js} +7912 -3250
  10. package/dist/client/assets/{_virtual_jto-plugin-type-libs-BlMraosv.js.map → _virtual_jto-plugin-type-libs-B6KyD9RL.js.map} +1 -1
  11. package/dist/client/assets/_virtual_jto-sandbox-runtime-Bzo2M5U7.js +2 -0
  12. package/dist/client/assets/_virtual_jto-sandbox-runtime-Bzo2M5U7.js.map +1 -0
  13. package/dist/client/assets/editor-CwEocOY2.js +16 -0
  14. package/dist/client/assets/editor-CwEocOY2.js.map +1 -0
  15. package/dist/client/assets/editor-monaco-json-D_oiidNg.js +24 -0
  16. package/dist/client/assets/editor-monaco-json-D_oiidNg.js.map +1 -0
  17. package/dist/client/assets/index--kF4jVbp.css +1 -0
  18. package/dist/client/assets/index-DFJaEoi0.js +27 -0
  19. package/dist/client/assets/index-DFJaEoi0.js.map +1 -0
  20. package/dist/client/assets/index-UheDso2P.js +2 -0
  21. package/dist/client/assets/index-UheDso2P.js.map +1 -0
  22. package/dist/client/assets/preview-CWdUATNl.js +4 -0
  23. package/dist/client/assets/preview-CWdUATNl.js.map +1 -0
  24. package/dist/client/assets/useQualityAnalysis-Cl4QPeOT.js +6 -0
  25. package/dist/client/assets/useQualityAnalysis-Cl4QPeOT.js.map +1 -0
  26. package/dist/client/index.html +2 -2
  27. package/dist/client/templates/client-report-blocks.docx.json +791 -0
  28. package/dist/client/templates/consulting-deck-blocks.pptx.json +455 -0
  29. package/dist/client/templates/data-report-presentation.pptx.json +108 -36
  30. package/dist/client/templates/management-plan.pptx.json +100 -22
  31. package/dist/client/templates/minimalist-pitch-deck.pptx.json +172 -101
  32. package/dist/prompts/instructions-edit-document-pptx-blocks.md +77 -0
  33. package/dist/prompts/instructions-edit-document-pptx-slides.md +15 -21
  34. package/dist/prompts/instructions-edit-document-pptx.md +34 -53
  35. package/dist/prompts/instructions-edit-pptx.md +9 -8
  36. package/dist/prompts/instructions-generate-pptx.md +13 -17
  37. package/dist/prompts/pptx-core.md +104 -127
  38. package/dist/prompts/pptx-design.md +115 -109
  39. package/package.json +10 -9
  40. package/dist/client/assets/HomePage-Cq_CI7_t.js +0 -251
  41. package/dist/client/assets/HomePage-Cq_CI7_t.js.map +0 -1
  42. package/dist/client/assets/_virtual_jto-sandbox-runtime-XWrhySEO.js +0 -2
  43. package/dist/client/assets/_virtual_jto-sandbox-runtime-XWrhySEO.js.map +0 -1
  44. package/dist/client/assets/editor-D-LgWzQZ.js +0 -16
  45. package/dist/client/assets/editor-D-LgWzQZ.js.map +0 -1
  46. package/dist/client/assets/editor-monaco-json-BVkSRpj1.js +0 -24
  47. package/dist/client/assets/editor-monaco-json-BVkSRpj1.js.map +0 -1
  48. package/dist/client/assets/editor-refs-store-COFjkOeo.js +0 -2
  49. package/dist/client/assets/editor-refs-store-COFjkOeo.js.map +0 -1
  50. package/dist/client/assets/index-B9j3hDSy.js +0 -5
  51. package/dist/client/assets/index-B9j3hDSy.js.map +0 -1
  52. package/dist/client/assets/index-Bj6ZAKUc.css +0 -1
  53. package/dist/client/assets/preview-D0HsunpU.js +0 -4
  54. package/dist/client/assets/preview-D0HsunpU.js.map +0 -1
  55. package/dist/client/assets/useQualityAnalysis-PZsxJDvP.js +0 -6
  56. package/dist/client/assets/useQualityAnalysis-PZsxJDvP.js.map +0 -1
  57. package/dist/prompts/instructions-edit-document-pptx-templates.md +0 -63
@@ -1,251 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/editor-D-LgWzQZ.js","assets/react-vendor-BmQ2Ko_D.js","assets/editor-monaco-json-BVkSRpj1.js","assets/index-B9j3hDSy.js","assets/query-vendor--rhYD8mC.js","assets/radix-ui-BzbaiLpZ.js","assets/ui-vendor-BsAtAN16.js","assets/monaco-editor-DJsdM0WK.js","assets/state-vendor-Cq67_JbF.js","assets/index-Bj6ZAKUc.css","assets/editor-refs-store-COFjkOeo.js","assets/MonacoPluginProvider-CdHBp1cD.js","assets/useQualityAnalysis-PZsxJDvP.js","assets/preview-D0HsunpU.js"])))=>i.map(i=>d[i]);
2
- var xg=Object.defineProperty;var yg=(e,t,n)=>t in e?xg(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Rr=(e,t,n)=>yg(e,typeof t!="symbol"?t+"":t,n);import{r as x,j as c,c as je,R as dd,g as wa}from"./react-vendor-BmQ2Ko_D.js";import{u as vn,s as fd,p as bg,a as ke,T as ka,v as vg,i as wg,b as Do,c as Xs,d as an,g as kg,e as Jt,B as Sg,f as yr,h as pd,j as jg,k as _g,S as Ng,O as Eg,l as Cg,M as Tg,D as Ig,m as Ag}from"./MonacoPluginProvider-CdHBp1cD.js";import{A as zg,F as at,c as W,u as Cr,S as cn,a as ui,T as Ri,C as Og,E as Pg,b as Dg,d as Rg,e as Ye,f as Xe,g as Qe,h as hd,_ as md,i as $i,j as $g,k as Mg,l as Fg,m as $r,s as Qs,W as gd,n as Gi}from"./index-B9j3hDSy.js";import{b as xd,c as Sa,d as yd,e as Cs,f as Ts,D as Is,O as As,g as Lg,V as Bg,G as Vg,h as bd,I as Zg,i as Ug,j as vd,k as Jg,l as wd,m as Hg,n as Wg,L as kd,S as Sd,o as jd,p as _d,q as Nd,r as Tr,s as qg,t as Gg,u as Kg,v as Ed,w as Cd,x as Td,y as Id,z as Ad,B as zd,E as Od,F as Pd,H as Dd,J as Yg,K as Xg,M as Qg,N as Rd,Q as $d,U as Md,W as Fd,X as Ld,Y as Bd,Z as Vd,_ as Zd,$ as Ud,a0 as Jd,a1 as ex,a2 as Hd,a3 as tx,a4 as nx,a5 as Wd,a6 as rx,a7 as ix,a8 as sx,a9 as ox,aa as qd,ab as Gd,ac as Kd}from"./radix-ui-BzbaiLpZ.js";import{X as wn,C as Ni,a as un,b as ax,d as Ei,G as Yd,F as lx,e as Ir,f as Xd,P as cx,g as ux,h as Qd,i as ef,E as ja,B as ns,H as dx,T as Ro,L as $o,j as fx,k as px,S as tf,I as hx,l as mx,m as Mo,n as gx,o as xx,p as yx,q as bx,r as vx,s as wx,t as kx,u as Sx,v as zs,w as jx,M as _x,x as Dt,y as nf,z as Nx,A as Ex,D as Cx,J as Tx,K as rf,N as Ix,O as Ax,Q as zx,R as Ox,U as Px,V as Dx,W as sf,Y as Rx,Z as Fo,_ as _a,$ as of,a0 as $x,a1 as af,a2 as Gr,a3 as Mx,a4 as Fx,a5 as Lx,a6 as wl,a7 as Lo}from"./ui-vendor-BsAtAN16.js";import{B as Ee,u as lf,d as kl}from"./editor-refs-store-COFjkOeo.js";import{u as Na,a as Bx,d as Vx,p as Zx,b as Ux,e as Jx}from"./state-vendor-Cq67_JbF.js";import{b as Hx}from"./query-vendor--rhYD8mC.js";let Mi=null,Mr=null;const Wx=1e4;function qx(e,t){return t.aborted?Promise.reject(Sl(t)):new Promise((n,r)=>{const i=()=>r(Sl(t));t.addEventListener("abort",i,{once:!0}),e.then(n,r).finally(()=>{t.removeEventListener("abort",i)})})}function Sl(e){return e.reason??new DOMException("Aborted","AbortError")}async function Gx(e){return Mi||(Mr||(Mr=(async()=>{const t=await fetch(`${zg}/discovery/themes/builtin`,{signal:AbortSignal.timeout(Wx)});if(!t.ok)throw new Error(`Built-in themes unavailable (${t.status})`);const n=await t.json();if(!n.success||!n.data)throw new Error(n.error??"Built-in themes unavailable");return Mi=n.data,Mi})().finally(()=>{Mr=null})),e?qx(Mr,e):Mr)}class hn extends Error{constructor(n,r,i){super(n);Rr(this,"pluginName");Rr(this,"path");this.name="PluginExpansionError",this.pluginName=r,this.path=i}}const Kx=20,Yx=1e4;function di(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function jl(e,t){const n=new Set;if(t.size===0)return n;const r=i=>{if(Array.isArray(i)){i.forEach(r);return}di(i)&&(typeof i.name=="string"&&t.has(i.name)&&n.add(i.name),Array.isArray(i.children)&&i.children.forEach(r))};return di(e)&&Array.isArray(e.children)&&e.children.forEach(r),n}const Xx=/^https?:\/\/\S+/i;function rs(e,t=new Set){if(typeof e=="string")Xx.test(e)&&t.add(e);else if(Array.isArray(e))for(const n of e)rs(n,t);else if(di(e))for(const n of Object.values(e))rs(n,t);return t}function Qx(e,t){if(!e.startsWith("/")||t.size===0)return{path:e,insidePlugin:!1};const n=e.split("/");for(let r=n.length;r>1;r--){const i=n.slice(0,r).join("/"),s=t.get(i);if(!s)continue;if(s.synthetic)return{path:s.authored,insidePlugin:!0};const o=n.slice(r).join("/");return{path:o?`${s.authored}/${o}`:s.authored,insidePlugin:!1}}return{path:e,insidePlugin:!1}}async function ey(e,t){const{plugins:n,theme:r,render:i,signal:s}=t,o=t.maxDepth??Kx,a=t.maxNodes??Yx,l=[],u=new Map,d=rs(e);let f=0;function h(k){if(s!=null&&s.aborted)throw new hn("Expansion was cancelled",void 0,k)}async function p(k,S,y,j,m){if(S>o)throw new hn(`Maximum component nesting depth exceeded (${o}). Check for circular component references.`,void 0,y);const A=[],C=(v,w,O)=>{const B=`${j}/${A.length}`;return(O||B!==w)&&u.set(B,{authored:w,synthetic:O}),A.push(v),B};for(let v=0;v<k.length;v++){h(y);const w=k[v],O=m??`${y}/${v}`,B=m!==void 0;if(!di(w)||typeof w.name!="string"){C(w,O,B);continue}const N=n.get(w.name);if(!N){if(Array.isArray(w.children)){const D=`${j}/${A.length}`,J=await p(w.children,S+1,`${O}/children`,`${D}/children`,B?m:void 0);C({...w,children:J},O,B)}else C(w,O,B);continue}if(w.enabled===!1)continue;if(w.props===void 0||w.props===null)throw new hn(`Custom component '${w.name}' must have a 'props' property. Use format: { name: '${w.name}', props: {...} }`,w.name,O);const R=typeof w.version=="string"?w.version:void 0;if(R!==void 0&&!N.versions.includes(R))throw new hn(`Component "${w.name}" does not have version "${R}". Available versions: ${N.versions.join(", ")}`,w.name,O);const T=Array.isArray(w.children)?await p(w.children,S+1,`${O}/children`,`${O}/children`,O):void 0,F=R?`${w.name}@${R}`:w.name;let z;try{z=await i({name:w.name,version:R,props:w.props,theme:r,children:T},s)}catch(D){throw s!=null&&s.aborted?D:new hn(`Error processing custom component '${w.name}': ${D instanceof Error?D.message:String(D)}`,w.name,O)}for(const D of z.warnings??[])l.push({component:F,message:D.message,severity:"warning",...D.context?{context:D.context}:{}});if(!Array.isArray(z.components))throw new hn(`Custom component '${w.name}' must render an array of components.`,w.name,O);for(const D of rs(z.components))d.has(D)||l.push({component:F,message:`Plugin output references a remote source the document did not: ${D}`,severity:"warning",context:{code:"PLUGIN_REMOTE_SOURCE",url:D,path:O}});if(f+=z.components.length,f>a)throw new hn(`Plugin expansion produced more than ${a} components; stopping at '${w.name}'.`,w.name,O);const M=await p(z.components,S+1,O,j,O);for(const D of M)C(D,O,!0)}return A}if(!di(e)||!Array.isArray(e.children))return{document:e,warnings:l,pathMap:u};const g=await p(e.children,0,"/children","/children",void 0);return{document:{...e,children:g},warnings:l,pathMap:u}}function mt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ty(e,t){if(!mt(t))return e;const n=mt(e.fonts)?e.fonts:{},r={...n};if(mt(t.fonts))for(const[o,a]of Object.entries(t.fonts)){const l=n[o],u=mt(l)?l:{};r[o]=mt(a)?{...u,...a}:a}const i=mt(e.styles)?e.styles:{},s={...i};if(mt(t.styles))for(const[o,a]of Object.entries(t.styles)){const l=i[o],u=mt(l)?l:{};s[o]=mt(a)?{...u,...a}:a}return{...e,colors:{...mt(e.colors)?e.colors:{},...mt(t.colors)?t.colors:{}},fonts:r,...Object.keys(s).length>0?{styles:s}:{}}}const _l={docx:"minimal",pptx:"default"};function ny(e,t){const{format:n,customThemes:r,builtinThemes:i}=t,s=mt(e)&&mt(e.props)?e.props:{},o=s.theme;if(n==="pptx"&&mt(o))return{theme:o};const a=typeof o=="string"&&o.length>0?o:_l[n];let l=r[a];if(l===void 0&&n==="docx"){const f=a.toLowerCase(),h=Object.keys(r).find(p=>p.toLowerCase()===f);h&&(l=r[h])}l===void 0&&(l=i[a]);let u;if(l===void 0){const f=_l[n],h=[...Object.keys(i),...Object.keys(r)].sort();u={message:`Theme "${a}" not found; falling back to "${f}". Available themes: ${h.join(", ")}.`,context:{code:"theme_not_found",requested:a,available:h}},l=i[f]}l===void 0&&(l=Object.values(i)[0]??{});const d=n==="docx"&&mt(l)&&s.themeOverrides?ty(l,s.themeOverrides):l;return u?{theme:d,warning:u}:{theme:d}}const eo=e=>({path:e,insidePlugin:!1});function ry(e){if(!e.enabled)return"is turned off — enable it in the plugin header or the sidebar";if(e.status==="compiling"||e.status==="idle")return"is still compiling — try again in a moment";const t=e.diagnostics.filter(n=>n.severity==="error");return t.length>0?`has ${t.length} error${t.length===1?"":"s"} — open ${e.docName} to fix ${t.length===1?"it":"them"}`:`failed to load — open ${e.docName}`}async function Bo(e,t={}){var y;const n=vn.getState(),r=fd(n),i=Object.values(n.records).filter(j=>j.metadata);if(i.length===0)return{text:e,warnings:[],expanded:!1,remap:eo};let s;try{s=JSON.parse(e)}catch{return{text:e,warnings:[],expanded:!1,remap:eo}}const o=new Set(r.map(j=>j.metadata.name)),a=new Map;for(const j of i){const m=j.metadata.name;!o.has(m)&&!a.has(m)&&a.set(m,j)}const l=jl(s,new Set(a.keys()));if(l.size>0){const[j]=l,m=a.get(j);throw new hn(`"${j}" is a browser plugin that ${ry(m)}.`,j)}if(jl(s,o).size===0)return{text:e,warnings:[],expanded:!1,remap:eo};const d=new Map,f=new Map;for(const j of r)d.set(j.metadata.name,{name:j.metadata.name,versions:j.metadata.versions.map(m=>m.version)}),f.set(j.metadata.name,j.docName);let h={};try{h=await Gx(t.signal)}catch(j){if((y=t.signal)!=null&&y.aborted)throw j}const p=ny(s,{format:at,customThemes:t.customThemes??{},builtinThemes:h}),g=await ey(s,{plugins:d,theme:p.theme,signal:t.signal,render:(j,m)=>bg.render(f.get(j.name),j,m)}),k=p.warning?[{component:"theme",message:p.warning.message,severity:"warning",context:p.warning.context},...g.warnings]:g.warnings,S=g.pathMap;return{text:JSON.stringify(g.document,null,2),warnings:k,expanded:!0,remap:j=>Qx(j,S)}}const ct=xd,iy=yd,Nl=Sa,cf=x.forwardRef(({className:e,...t},n)=>c.jsx(As,{ref:n,className:W("fixed inset-0 z-50 bg-black/50",e),...t}));cf.displayName=As.displayName;const lt=x.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(iy,{children:[c.jsx(cf,{}),c.jsxs(Cs,{ref:r,className:W("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,c.jsxs(Sa,{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:[c.jsx(wn,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));lt.displayName=Cs.displayName;const qt=({className:e,...t})=>c.jsx("div",{className:W("flex flex-col space-y-1.5 text-center sm:text-left",e),...t});qt.displayName="DialogHeader";const kn=({className:e,...t})=>c.jsx("div",{className:W("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",e),...t});kn.displayName="DialogFooter";const Gt=x.forwardRef(({className:e,...t},n)=>c.jsx(Ts,{ref:n,className:W("text-lg leading-none font-semibold tracking-tight",e),...t}));Gt.displayName=Ts.displayName;const dn=x.forwardRef(({className:e,...t},n)=>c.jsx(Is,{ref:n,className:W("text-muted-foreground text-sm",e),...t}));dn.displayName=Is.displayName;const fi=Lg,uf=Vg,pi=Bg,br=x.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(bd,{ref:r,className:W("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,c.jsx(Zg,{asChild:!0,children:c.jsx(Ni,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));br.displayName=bd.displayName;const df=x.forwardRef(({className:e,...t},n)=>c.jsx(Sd,{ref:n,className:W("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(ax,{className:"h-4 w-4"})}));df.displayName=Sd.displayName;const ff=x.forwardRef(({className:e,...t},n)=>c.jsx(jd,{ref:n,className:W("flex cursor-default items-center justify-center py-1",e),...t,children:c.jsx(Ni,{className:"h-4 w-4"})}));ff.displayName=jd.displayName;const vr=x.forwardRef(({className:e,children:t,position:n="popper",...r},i)=>c.jsx(Ug,{children:c.jsxs(vd,{ref:i,className:W("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:[c.jsx(df,{}),c.jsx(Jg,{className:W("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),c.jsx(ff,{})]})}));vr.displayName=vd.displayName;const Ea=x.forwardRef(({className:e,...t},n)=>c.jsx(kd,{ref:n,className:W("px-2 py-1.5 text-sm font-semibold",e),...t}));Ea.displayName=kd.displayName;const Mn=x.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(wd,{ref:r,className:W("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:[c.jsx("span",{className:"absolute right-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Hg,{children:c.jsx(un,{className:"h-4 w-4"})})}),c.jsx(Wg,{children:t})]}));Mn.displayName=wd.displayName;const sy=x.forwardRef(({className:e,...t},n)=>c.jsx(_d,{ref:n,className:W("bg-muted -mx-1 my-1 h-px",e),...t}));sy.displayName=_d.displayName;const wr=x.forwardRef(({className:e,type:t,...n},r)=>c.jsx("input",{type:t,className:W("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}));wr.displayName="Input";const oy=Ei("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),ni=x.forwardRef(({className:e,...t},n)=>c.jsx(Nd,{ref:n,className:W(oy(),e),...t}));ni.displayName=Nd.displayName;const ay=Ei("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 tn({className:e,variant:t,...n}){return c.jsx("div",{className:W(ay({variant:t}),e),...n})}const ly=({open:e,onOpenChange:t})=>{const{documents:n,documentTypes:r,activeTab:i,createDocument:s,openDocument:o}=ke(Na(T=>({documents:T.documents,documentTypes:T.documentTypes,activeTab:T.activeTab,createDocument:T.createDocument,openDocument:T.openDocument}))),a=x.useContext(ka),{toast:l}=Cr(),u=x.useMemo(()=>n.filter(T=>r[T.name]!=="application/json+theme"),[n,r]),[d,f]=x.useState(""),[h,p]=x.useState(""),[g,k]=x.useState("playground"),[S,y]=x.useState(!1),[j,m]=x.useState(null),[A,C]=x.useState(null),[v,w]=x.useState(null),O=()=>{m(null),C(null),w(null)};x.useEffect(()=>{if(!e)return;m(null),C(null),w(null);const T=u.map(z=>z.name),F=T.includes(i)?i:T[0]??"";p(F),f(T.find(z=>z!==F)??"")},[e]);const B=async()=>{const T=u.find(z=>z.name===d),F=u.find(z=>z.name===h);if(!(!T||!F)){y(!0),m(null),C(null),w(null);try{const z=a?vg(a.getState().customThemes):{},[M,D]=await Promise.all([Bo(T.text,{customThemes:z}),Bo(F.text,{customThemes:z})]),J=await fetch(ui.diff,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({oldDefinition:M.text,newDefinition:D.text,options:{author:g||"playground"}})}),Z=await J.json();if(!J.ok||!Z.success){const X=Array.isArray(Z.errors)?`: ${Z.errors.slice(0,3).map(_=>_.message||String(_)).join("; ")}`:"";throw new Error((Z.error||`Diff failed (${J.status})`)+X)}C(Z.data.summary),w(Z.data.document)}catch(z){m(z instanceof Error?z.message:"Diff failed")}finally{y(!1)}}},N=()=>{if(!v)return;const T=new Set(n.map(M=>M.name));let F=`${h}-redline`,z=2;for(;T.has(F);)F=`${h}-redline-${z++}`;s(F,JSON.stringify(v,null,2)),o(F),l({title:`Redline created: ${F}`}),t(!1)},R=A?A.tracked.modified+A.tracked.inserted+A.tracked.deleted:0;return c.jsx(ct,{open:e,onOpenChange:t,children:c.jsxs(lt,{className:"sm:max-w-[560px]",children:[c.jsxs(qt,{children:[c.jsxs(Gt,{className:"flex items-center gap-2",children:[c.jsx(Yd,{className:"size-4"}),"Compare documents"]}),c.jsx(dn,{children:"Diff two versions into a redline with native Word tracked changes (accept/reject in Word)."})]}),c.jsxs("div",{className:"grid gap-4 py-2",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[c.jsxs("div",{className:"grid gap-1.5",children:[c.jsx(ni,{htmlFor:"diff-base",children:"Base (old)"}),c.jsxs(fi,{value:d,onValueChange:T=>{f(T),O()},children:[c.jsx(br,{id:"diff-base",children:c.jsx(pi,{placeholder:"Select document"})}),c.jsx(vr,{children:u.map(T=>c.jsx(Mn,{value:T.name,children:T.name},T.name))})]})]}),c.jsxs("div",{className:"grid gap-1.5",children:[c.jsx(ni,{htmlFor:"diff-revised",children:"Revised (new)"}),c.jsxs(fi,{value:h,onValueChange:T=>{p(T),O()},children:[c.jsx(br,{id:"diff-revised",children:c.jsx(pi,{placeholder:"Select document"})}),c.jsx(vr,{children:u.map(T=>c.jsx(Mn,{value:T.name,children:T.name},T.name))})]})]})]}),c.jsxs("div",{className:"grid gap-1.5",children:[c.jsx(ni,{htmlFor:"diff-author",children:"Revision author"}),c.jsx(wr,{id:"diff-author",value:g,onChange:T=>{k(T.target.value),O()},placeholder:"playground"})]}),j&&c.jsx("p",{className:"text-sm text-destructive",role:"alert",children:j}),A&&c.jsxs("div",{className:"rounded-md border p-3 text-sm grid gap-2",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsxs(tn,{variant:"secondary",children:[A.tracked.inserted," inserted"]}),c.jsxs(tn,{variant:"secondary",children:[A.tracked.deleted," deleted"]}),c.jsxs(tn,{variant:"secondary",children:[A.tracked.modified," modified"]}),c.jsxs("span",{className:"text-muted-foreground text-xs",children:[A.unchangedBlocks," blocks unchanged"]})]}),R===0&&A.untracked.length===0&&c.jsx("p",{className:"text-muted-foreground",children:"The documents are identical."}),A.untracked.length>0&&c.jsxs("div",{className:"grid gap-1 max-h-32 overflow-y-auto",children:[c.jsxs("p",{className:"font-medium text-warning-bg-foreground",children:[A.untracked.length," change(s) not expressible as tracked changes:"]}),A.untracked.map((T,F)=>c.jsxs("p",{className:"text-xs text-muted-foreground",children:[T.path," [",T.component,"] ",T.detail]},F))]}),A.notes.map((T,F)=>c.jsxs("p",{className:"text-xs text-muted-foreground",children:["Note: ",T]},F))]})]}),c.jsx(kn,{children:A&&R+A.untracked.length>0?c.jsxs(Ee,{onClick:N,children:[c.jsx(lx,{className:"size-4 mr-1"}),"Open redline"]}):c.jsxs(Ee,{onClick:B,disabled:S||!d||!h||d===h,children:[S&&c.jsx(cn,{className:"size-4 mr-1"}),"Compare"]})})]})})};var Ci=e=>e.type==="checkbox",On=e=>e instanceof Date,gt=e=>e==null;const pf=e=>typeof e=="object";var nt=e=>!gt(e)&&!Array.isArray(e)&&pf(e)&&!On(e),hf=e=>nt(e)&&e.target?Ci(e.target)?e.target.checked:e.target.value:e,cy=e=>e.substring(0,e.search(/\.\d+(\.|$)/))||e,mf=(e,t)=>e.has(cy(t)),uy=e=>{const t=e.constructor&&e.constructor.prototype;return nt(t)&&t.hasOwnProperty("isPrototypeOf")},Ca=typeof window<"u"&&typeof window.HTMLElement<"u"&&typeof document<"u";function wt(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||nt(e)))if(t=n?[]:{},!n&&!uy(e))t=e;else for(const i in e)e.hasOwnProperty(i)&&(t[i]=wt(e[i]));else return e;return t}var Os=e=>Array.isArray(e)?e.filter(Boolean):[],tt=e=>e===void 0,ue=(e,t,n)=>{if(!t||!nt(e))return n;const r=Os(t.split(/[,[\].]+?/)).reduce((i,s)=>gt(i)?i:i[s],e);return tt(r)||r===e?tt(e[t])?n:e[t]:r},Rt=e=>typeof e=="boolean",Ta=e=>/^\w*$/.test(e),gf=e=>Os(e.replace(/["|']|\]/g,"").split(/\.|\[/)),Le=(e,t,n)=>{let r=-1;const i=Ta(t)?[t]:gf(t),s=i.length,o=s-1;for(;++r<s;){const a=i[r];let l=n;if(r!==o){const u=e[a];l=nt(u)||Array.isArray(u)?u:isNaN(+i[r+1])?{}:[]}if(a==="__proto__"||a==="constructor"||a==="prototype")return;e[a]=l,e=e[a]}return e};const is={BLUR:"blur",FOCUS_OUT:"focusout",CHANGE:"change"},Ut={onBlur:"onBlur",onChange:"onChange",onSubmit:"onSubmit",onTouched:"onTouched",all:"all"},sn={max:"max",min:"min",maxLength:"maxLength",minLength:"minLength",pattern:"pattern",required:"required",validate:"validate"},xf=je.createContext(null),Ps=()=>je.useContext(xf),dy=e=>{const{children:t,...n}=e;return je.createElement(xf.Provider,{value:n},t)};var yf=(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]!==Ut.all&&(t._proxyFormState[o]=!r||Ut.all),n&&(n[o]=!0),e[o]}});return i},kt=e=>nt(e)&&!Object.keys(e).length,bf=(e,t,n,r)=>{n(e);const{name:i,...s}=e;return kt(s)||Object.keys(s).length>=Object.keys(t).length||Object.keys(s).find(o=>t[o]===(!r||Ut.all))},ri=e=>Array.isArray(e)?e:[e],vf=(e,t,n)=>!e||!t||e===t||ri(e).some(r=>r&&(n?r===t:r.startsWith(t)||t.startsWith(r)));function Ia(e){const t=je.useRef(e);t.current=e,je.useEffect(()=>{const n=!e.disabled&&t.current.subject&&t.current.subject.subscribe({next:t.current.next});return()=>{n&&n.unsubscribe()}},[e.disabled])}function fy(e){const t=Ps(),{control:n=t.control,disabled:r,name:i,exact:s}=e||{},[o,a]=je.useState(n._formState),l=je.useRef(!0),u=je.useRef({isDirty:!1,isLoading:!1,dirtyFields:!1,touchedFields:!1,validatingFields:!1,isValidating:!1,isValid:!1,errors:!1}),d=je.useRef(i);return d.current=i,Ia({disabled:r,next:f=>l.current&&vf(d.current,f.name,s)&&bf(f,u.current,n._updateFormState)&&a({...n._formState,...f}),subject:n._subjects.state}),je.useEffect(()=>(l.current=!0,u.current.isValid&&n._updateValid(!0),()=>{l.current=!1}),[n]),je.useMemo(()=>yf(o,n,u.current,!1),[o,n])}var en=e=>typeof e=="string",wf=(e,t,n,r,i)=>en(e)?(r&&t.watch.add(e),ue(n,e,i)):Array.isArray(e)?e.map(s=>(r&&t.watch.add(s),ue(n,s))):(r&&(t.watchAll=!0),n);function py(e){const t=Ps(),{control:n=t.control,name:r,defaultValue:i,disabled:s,exact:o}=e||{},a=je.useRef(r);a.current=r,Ia({disabled:s,subject:n._subjects.values,next:d=>{vf(a.current,d.name,o)&&u(wt(wf(a.current,n._names,d.values||n._formValues,!1,i)))}});const[l,u]=je.useState(n._getWatch(r,i));return je.useEffect(()=>n._removeUnmounted()),l}function hy(e){const t=Ps(),{name:n,disabled:r,control:i=t.control,shouldUnregister:s}=e,o=mf(i._names.array,n),a=py({control:i,name:n,defaultValue:ue(i._formValues,n,ue(i._defaultValues,n,e.defaultValue)),exact:!0}),l=fy({control:i,name:n,exact:!0}),u=je.useRef(i.register(n,{...e.rules,value:a,...Rt(e.disabled)?{disabled:e.disabled}:{}})),d=je.useMemo(()=>Object.defineProperties({},{invalid:{enumerable:!0,get:()=>!!ue(l.errors,n)},isDirty:{enumerable:!0,get:()=>!!ue(l.dirtyFields,n)},isTouched:{enumerable:!0,get:()=>!!ue(l.touchedFields,n)},isValidating:{enumerable:!0,get:()=>!!ue(l.validatingFields,n)},error:{enumerable:!0,get:()=>ue(l.errors,n)}}),[l,n]),f=je.useMemo(()=>({name:n,value:a,...Rt(r)||l.disabled?{disabled:l.disabled||r}:{},onChange:h=>u.current.onChange({target:{value:hf(h),name:n},type:is.CHANGE}),onBlur:()=>u.current.onBlur({target:{value:ue(i._formValues,n),name:n},type:is.BLUR}),ref:h=>{const p=ue(i._fields,n);p&&h&&(p._f.ref={focus:()=>h.focus(),select:()=>h.select(),setCustomValidity:g=>h.setCustomValidity(g),reportValidity:()=>h.reportValidity()})}}),[n,i._formValues,r,l.disabled,a,i._fields]);return je.useEffect(()=>{const h=i._options.shouldUnregister||s,p=(g,k)=>{const S=ue(i._fields,g);S&&S._f&&(S._f.mount=k)};if(p(n,!0),h){const g=wt(ue(i._options.defaultValues,n));Le(i._defaultValues,n,g),tt(ue(i._formValues,n))&&Le(i._formValues,n,g)}return!o&&i.register(n),()=>{(o?h&&!i._state.action:h)?i.unregister(n):p(n,!1)}},[n,i,o,s]),je.useEffect(()=>{i._updateDisabledField({disabled:r,fields:i._fields,name:n})},[r,n,i]),je.useMemo(()=>({field:f,formState:l,fieldState:d}),[f,l,d])}const my=e=>e.render(hy(e));var gy=(e,t,n,r,i)=>t?{...n[e],types:{...n[e]&&n[e].types?n[e].types:{},[r]:i||!0}}:{},El=e=>({isOnSubmit:!e||e===Ut.onSubmit,isOnBlur:e===Ut.onBlur,isOnChange:e===Ut.onChange,isOnAll:e===Ut.all,isOnTouch:e===Ut.onTouched}),Cl=(e,t,n)=>!n&&(t.watchAll||t.watch.has(e)||[...t.watch].some(r=>e.startsWith(r)&&/^\.\w+/.test(e.slice(r.length))));const ii=(e,t,n,r)=>{for(const i of n||Object.keys(e)){const s=ue(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(ii(a,t))break}else if(nt(a)&&ii(a,t))break}}};var xy=(e,t,n)=>{const r=ri(ue(e,n));return Le(r,"root",t[n]),Le(e,n,r),e},Aa=e=>e.type==="file",Qt=e=>typeof e=="function",ss=e=>{if(!Ca)return!1;const t=e?e.ownerDocument:0;return e instanceof(t&&t.defaultView?t.defaultView.HTMLElement:HTMLElement)},Ki=e=>en(e),za=e=>e.type==="radio",os=e=>e instanceof RegExp;const Tl={value:!1,isValid:!1},Il={value:!0,isValid:!0};var kf=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&&!tt(e[0].attributes.value)?tt(e[0].value)||e[0].value===""?Il:{value:e[0].value,isValid:!0}:Il:Tl}return Tl};const Al={isValid:!1,value:null};var Sf=e=>Array.isArray(e)?e.reduce((t,n)=>n&&n.checked&&!n.disabled?{isValid:!0,value:n.value}:t,Al):Al;function zl(e,t,n="validate"){if(Ki(e)||Array.isArray(e)&&e.every(Ki)||Rt(e)&&!e)return{type:n,message:Ki(e)?e:"",ref:t}}var Jn=e=>nt(e)&&!os(e)?e:{value:e,message:""},Ol=async(e,t,n,r,i,s)=>{const{ref:o,refs:a,required:l,maxLength:u,minLength:d,min:f,max:h,pattern:p,validate:g,name:k,valueAsNumber:S,mount:y}=e._f,j=ue(n,k);if(!y||t.has(k))return{};const m=a?a[0]:o,A=T=>{i&&m.reportValidity&&(m.setCustomValidity(Rt(T)?"":T||""),m.reportValidity())},C={},v=za(o),w=Ci(o),O=v||w,B=(S||Aa(o))&&tt(o.value)&&tt(j)||ss(o)&&o.value===""||j===""||Array.isArray(j)&&!j.length,N=gy.bind(null,k,r,C),R=(T,F,z,M=sn.maxLength,D=sn.minLength)=>{const J=T?F:z;C[k]={type:T?M:D,message:J,ref:o,...N(T?M:D,J)}};if(s?!Array.isArray(j)||!j.length:l&&(!O&&(B||gt(j))||Rt(j)&&!j||w&&!kf(a).isValid||v&&!Sf(a).isValid)){const{value:T,message:F}=Ki(l)?{value:!!l,message:l}:Jn(l);if(T&&(C[k]={type:sn.required,message:F,ref:m,...N(sn.required,F)},!r))return A(F),C}if(!B&&(!gt(f)||!gt(h))){let T,F;const z=Jn(h),M=Jn(f);if(!gt(j)&&!isNaN(j)){const D=o.valueAsNumber||j&&+j;gt(z.value)||(T=D>z.value),gt(M.value)||(F=D<M.value)}else{const D=o.valueAsDate||new Date(j),J=_=>new Date(new Date().toDateString()+" "+_),Z=o.type=="time",X=o.type=="week";en(z.value)&&j&&(T=Z?J(j)>J(z.value):X?j>z.value:D>new Date(z.value)),en(M.value)&&j&&(F=Z?J(j)<J(M.value):X?j<M.value:D<new Date(M.value))}if((T||F)&&(R(!!T,z.message,M.message,sn.max,sn.min),!r))return A(C[k].message),C}if((u||d)&&!B&&(en(j)||s&&Array.isArray(j))){const T=Jn(u),F=Jn(d),z=!gt(T.value)&&j.length>+T.value,M=!gt(F.value)&&j.length<+F.value;if((z||M)&&(R(z,T.message,F.message),!r))return A(C[k].message),C}if(p&&!B&&en(j)){const{value:T,message:F}=Jn(p);if(os(T)&&!j.match(T)&&(C[k]={type:sn.pattern,message:F,ref:o,...N(sn.pattern,F)},!r))return A(F),C}if(g){if(Qt(g)){const T=await g(j,n),F=zl(T,m);if(F&&(C[k]={...F,...N(sn.validate,F.message)},!r))return A(F.message),C}else if(nt(g)){let T={};for(const F in g){if(!kt(T)&&!r)break;const z=zl(await g[F](j,n),m,F);z&&(T={...z,...N(F,z.message)},A(z.message),r&&(C[k]=T))}if(!kt(T)&&(C[k]={ref:m,...T},!r))return C}}return A(!0),C};function yy(e,t){const n=t.slice(0,-1).length;let r=0;for(;r<n;)e=tt(e)?r++:e[t[r++]];return e}function by(e){for(const t in e)if(e.hasOwnProperty(t)&&!tt(e[t]))return!1;return!0}function st(e,t){const n=Array.isArray(t)?t:Ta(t)?[t]:gf(t),r=n.length===1?e:yy(e,n),i=n.length-1,s=n[i];return r&&delete r[s],i!==0&&(nt(r)&&kt(r)||Array.isArray(r)&&by(r))&&st(e,n.slice(0,-1)),e}var to=()=>{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=[]}}},Vo=e=>gt(e)||!pf(e);function xn(e,t){if(Vo(e)||Vo(t))return e===t;if(On(e)&&On(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(On(s)&&On(o)||nt(s)&&nt(o)||Array.isArray(s)&&Array.isArray(o)?!xn(s,o):s!==o)return!1}}return!0}var jf=e=>e.type==="select-multiple",vy=e=>za(e)||Ci(e),no=e=>ss(e)&&e.isConnected,_f=e=>{for(const t in e)if(Qt(e[t]))return!0;return!1};function as(e,t={}){const n=Array.isArray(e);if(nt(e)||n)for(const r in e)Array.isArray(e[r])||nt(e[r])&&!_f(e[r])?(t[r]=Array.isArray(e[r])?[]:{},as(e[r],t[r])):gt(e[r])||(t[r]=!0);return t}function Nf(e,t,n){const r=Array.isArray(e);if(nt(e)||r)for(const i in e)Array.isArray(e[i])||nt(e[i])&&!_f(e[i])?tt(t)||Vo(n[i])?n[i]=Array.isArray(e[i])?as(e[i],[]):{...as(e[i])}:Nf(e[i],gt(t)?{}:t[i],n[i]):n[i]=!xn(e[i],t[i]);return n}var Fr=(e,t)=>Nf(e,t,as(t)),Ef=(e,{valueAsNumber:t,valueAsDate:n,setValueAs:r})=>tt(e)?e:t?e===""?NaN:e&&+e:n&&en(e)?new Date(e):r?r(e):e;function ro(e){const t=e.ref;return Aa(t)?t.files:za(t)?Sf(e.refs).value:jf(t)?[...t.selectedOptions].map(({value:n})=>n):Ci(t)?kf(e.refs).value:Ef(tt(t.value)?e.ref.value:t.value,e)}var wy=(e,t,n,r)=>{const i={};for(const s of e){const o=ue(t,s);o&&Le(i,s,o._f)}return{criteriaMode:n,names:[...e],fields:i,shouldUseNativeValidation:r}},Lr=e=>tt(e)?e:os(e)?e.source:nt(e)?os(e.value)?e.value.source:e.value:e;const Pl="AsyncFunction";var ky=e=>!!e&&!!e.validate&&!!(Qt(e.validate)&&e.validate.constructor.name===Pl||nt(e.validate)&&Object.values(e.validate).find(t=>t.constructor.name===Pl)),Sy=e=>e.mount&&(e.required||e.min||e.max||e.maxLength||e.minLength||e.pattern||e.validate);function Dl(e,t,n){const r=ue(e,n);if(r||Ta(n))return{error:r,name:n};const i=n.split(".");for(;i.length;){const s=i.join("."),o=ue(t,s),a=ue(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 jy=(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,_y=(e,t)=>!Os(ue(e,t)).length&&st(e,t);const Ny={mode:Ut.onSubmit,reValidateMode:Ut.onChange,shouldFocusError:!0};function Ey(e={}){let t={...Ny,...e},n={submitCount:0,isDirty:!1,isLoading:Qt(t.defaultValues),isValidating:!1,isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,touchedFields:{},dirtyFields:{},validatingFields:{},errors:t.errors||{},disabled:t.disabled||!1},r={},i=nt(t.defaultValues)||nt(t.values)?wt(t.defaultValues||t.values)||{}:{},s=t.shouldUnregister?{}:wt(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,u=0;const d={isDirty:!1,dirtyFields:!1,validatingFields:!1,touchedFields:!1,isValidating:!1,isValid:!1,errors:!1},f={values:to(),array:to(),state:to()},h=El(t.mode),p=El(t.reValidateMode),g=t.criteriaMode===Ut.all,k=E=>P=>{clearTimeout(u),u=setTimeout(E,P)},S=async E=>{if(!t.disabled&&(d.isValid||E)){const P=t.resolver?kt((await O()).errors):await N(r,!0);P!==n.isValid&&f.state.next({isValid:P})}},y=(E,P)=>{!t.disabled&&(d.isValidating||d.validatingFields)&&((E||Array.from(a.mount)).forEach(V=>{V&&(P?Le(n.validatingFields,V,P):st(n.validatingFields,V))}),f.state.next({validatingFields:n.validatingFields,isValidating:!kt(n.validatingFields)}))},j=(E,P=[],V,se,ie=!0,ee=!0)=>{if(se&&V&&!t.disabled){if(o.action=!0,ee&&Array.isArray(ue(r,E))){const me=V(ue(r,E),se.argA,se.argB);ie&&Le(r,E,me)}if(ee&&Array.isArray(ue(n.errors,E))){const me=V(ue(n.errors,E),se.argA,se.argB);ie&&Le(n.errors,E,me),_y(n.errors,E)}if(d.touchedFields&&ee&&Array.isArray(ue(n.touchedFields,E))){const me=V(ue(n.touchedFields,E),se.argA,se.argB);ie&&Le(n.touchedFields,E,me)}d.dirtyFields&&(n.dirtyFields=Fr(i,s)),f.state.next({name:E,isDirty:T(E,P),dirtyFields:n.dirtyFields,errors:n.errors,isValid:n.isValid})}else Le(s,E,P)},m=(E,P)=>{Le(n.errors,E,P),f.state.next({errors:n.errors})},A=E=>{n.errors=E,f.state.next({errors:n.errors,isValid:!1})},C=(E,P,V,se)=>{const ie=ue(r,E);if(ie){const ee=ue(s,E,tt(V)?ue(i,E):V);tt(ee)||se&&se.defaultChecked||P?Le(s,E,P?ee:ro(ie._f)):M(E,ee),o.mount&&S()}},v=(E,P,V,se,ie)=>{let ee=!1,me=!1;const we={name:E};if(!t.disabled){const U=!!(ue(r,E)&&ue(r,E)._f&&ue(r,E)._f.disabled);if(!V||se){d.isDirty&&(me=n.isDirty,n.isDirty=we.isDirty=T(),ee=me!==we.isDirty);const Y=U||xn(ue(i,E),P);me=!!(!U&&ue(n.dirtyFields,E)),Y||U?st(n.dirtyFields,E):Le(n.dirtyFields,E,!0),we.dirtyFields=n.dirtyFields,ee=ee||d.dirtyFields&&me!==!Y}if(V){const Y=ue(n.touchedFields,E);Y||(Le(n.touchedFields,E,V),we.touchedFields=n.touchedFields,ee=ee||d.touchedFields&&Y!==V)}ee&&ie&&f.state.next(we)}return ee?we:{}},w=(E,P,V,se)=>{const ie=ue(n.errors,E),ee=d.isValid&&Rt(P)&&n.isValid!==P;if(t.delayError&&V?(l=k(()=>m(E,V)),l(t.delayError)):(clearTimeout(u),l=null,V?Le(n.errors,E,V):st(n.errors,E)),(V?!xn(ie,V):ie)||!kt(se)||ee){const me={...se,...ee&&Rt(P)?{isValid:P}:{},errors:n.errors,name:E};n={...n,...me},f.state.next(me)}},O=async E=>{y(E,!0);const P=await t.resolver(s,t.context,wy(E||a.mount,r,t.criteriaMode,t.shouldUseNativeValidation));return y(E),P},B=async E=>{const{errors:P}=await O(E);if(E)for(const V of E){const se=ue(P,V);se?Le(n.errors,V,se):st(n.errors,V)}else n.errors=P;return P},N=async(E,P,V={valid:!0})=>{for(const se in E){const ie=E[se];if(ie){const{_f:ee,...me}=ie;if(ee){const we=a.array.has(ee.name),U=ie._f&&ky(ie._f);U&&d.validatingFields&&y([se],!0);const Y=await Ol(ie,a.disabled,s,g,t.shouldUseNativeValidation&&!P,we);if(U&&d.validatingFields&&y([se]),Y[ee.name]&&(V.valid=!1,P))break;!P&&(ue(Y,ee.name)?we?xy(n.errors,Y,ee.name):Le(n.errors,ee.name,Y[ee.name]):st(n.errors,ee.name))}!kt(me)&&await N(me,P,V)}}return V.valid},R=()=>{for(const E of a.unMount){const P=ue(r,E);P&&(P._f.refs?P._f.refs.every(V=>!no(V)):!no(P._f.ref))&&Q(E)}a.unMount=new Set},T=(E,P)=>!t.disabled&&(E&&P&&Le(s,E,P),!xn(ye(),i)),F=(E,P,V)=>wf(E,a,{...o.mount?s:tt(P)?i:en(E)?{[E]:P}:P},V,P),z=E=>Os(ue(o.mount?s:i,E,t.shouldUnregister?ue(i,E,[]):[])),M=(E,P,V={})=>{const se=ue(r,E);let ie=P;if(se){const ee=se._f;ee&&(!ee.disabled&&Le(s,E,Ef(P,ee)),ie=ss(ee.ref)&&gt(P)?"":P,jf(ee.ref)?[...ee.ref.options].forEach(me=>me.selected=ie.includes(me.value)):ee.refs?Ci(ee.ref)?ee.refs.length>1?ee.refs.forEach(me=>(!me.defaultChecked||!me.disabled)&&(me.checked=Array.isArray(ie)?!!ie.find(we=>we===me.value):ie===me.value)):ee.refs[0]&&(ee.refs[0].checked=!!ie):ee.refs.forEach(me=>me.checked=me.value===ie):Aa(ee.ref)?ee.ref.value="":(ee.ref.value=ie,ee.ref.type||f.values.next({name:E,values:{...s}})))}(V.shouldDirty||V.shouldTouch)&&v(E,ie,V.shouldTouch,V.shouldDirty,!0),V.shouldValidate&&_(E)},D=(E,P,V)=>{for(const se in P){const ie=P[se],ee=`${E}.${se}`,me=ue(r,ee);(a.array.has(E)||nt(ie)||me&&!me._f)&&!On(ie)?D(ee,ie,V):M(ee,ie,V)}},J=(E,P,V={})=>{const se=ue(r,E),ie=a.array.has(E),ee=wt(P);Le(s,E,ee),ie?(f.array.next({name:E,values:{...s}}),(d.isDirty||d.dirtyFields)&&V.shouldDirty&&f.state.next({name:E,dirtyFields:Fr(i,s),isDirty:T(E,ee)})):se&&!se._f&&!gt(ee)?D(E,ee,V):M(E,ee,V),Cl(E,a)&&f.state.next({...n}),f.values.next({name:o.mount?E:void 0,values:{...s}})},Z=async E=>{o.mount=!0;const P=E.target;let V=P.name,se=!0;const ie=ue(r,V),ee=()=>P.type?ro(ie._f):hf(E),me=we=>{se=Number.isNaN(we)||On(we)&&isNaN(we.getTime())||xn(we,ue(s,V,we))};if(ie){let we,U;const Y=ee(),ge=E.type===is.BLUR||E.type===is.FOCUS_OUT,_e=!Sy(ie._f)&&!t.resolver&&!ue(n.errors,V)&&!ie._f.deps||jy(ge,ue(n.touchedFields,V),n.isSubmitted,p,h),L=Cl(V,a,ge);Le(s,V,Y),ge?(ie._f.onBlur&&ie._f.onBlur(E),l&&l(0)):ie._f.onChange&&ie._f.onChange(E);const $=v(V,Y,ge,!1),xe=!kt($)||L;if(!ge&&f.values.next({name:V,type:E.type,values:{...s}}),_e)return d.isValid&&(t.mode==="onBlur"&&ge?S():ge||S()),xe&&f.state.next({name:V,...L?{}:$});if(!ge&&L&&f.state.next({...n}),t.resolver){const{errors:de}=await O([V]);if(me(Y),se){const Me=Dl(n.errors,r,V),Je=Dl(de,r,Me.name||V);we=Je.error,V=Je.name,U=kt(de)}}else y([V],!0),we=(await Ol(ie,a.disabled,s,g,t.shouldUseNativeValidation))[V],y([V]),me(Y),se&&(we?U=!1:d.isValid&&(U=await N(r,!0)));se&&(ie._f.deps&&_(ie._f.deps),w(V,U,we,$))}},X=(E,P)=>{if(ue(n.errors,P)&&E.focus)return E.focus(),1},_=async(E,P={})=>{let V,se;const ie=ri(E);if(t.resolver){const ee=await B(tt(E)?E:ie);V=kt(ee),se=E?!ie.some(me=>ue(ee,me)):V}else E?(se=(await Promise.all(ie.map(async ee=>{const me=ue(r,ee);return await N(me&&me._f?{[ee]:me}:me)}))).every(Boolean),!(!se&&!n.isValid)&&S()):se=V=await N(r);return f.state.next({...!en(E)||d.isValid&&V!==n.isValid?{}:{name:E},...t.resolver||!E?{isValid:V}:{},errors:n.errors}),P.shouldFocus&&!se&&ii(r,X,E?ie:a.mount),se},ye=E=>{const P={...o.mount?s:i};return tt(E)?P:en(E)?ue(P,E):E.map(V=>ue(P,V))},ce=(E,P)=>({invalid:!!ue((P||n).errors,E),isDirty:!!ue((P||n).dirtyFields,E),error:ue((P||n).errors,E),isValidating:!!ue(n.validatingFields,E),isTouched:!!ue((P||n).touchedFields,E)}),b=E=>{E&&ri(E).forEach(P=>st(n.errors,P)),f.state.next({errors:E?n.errors:{}})},G=(E,P,V)=>{const se=(ue(r,E,{_f:{}})._f||{}).ref,ie=ue(n.errors,E)||{},{ref:ee,message:me,type:we,...U}=ie;Le(n.errors,E,{...U,...P,ref:se}),f.state.next({name:E,errors:n.errors,isValid:!1}),V&&V.shouldFocus&&se&&se.focus&&se.focus()},ne=(E,P)=>Qt(E)?f.values.subscribe({next:V=>E(F(void 0,P),V)}):F(E,P,!0),Q=(E,P={})=>{for(const V of E?ri(E):a.mount)a.mount.delete(V),a.array.delete(V),P.keepValue||(st(r,V),st(s,V)),!P.keepError&&st(n.errors,V),!P.keepDirty&&st(n.dirtyFields,V),!P.keepTouched&&st(n.touchedFields,V),!P.keepIsValidating&&st(n.validatingFields,V),!t.shouldUnregister&&!P.keepDefaultValue&&st(i,V);f.values.next({values:{...s}}),f.state.next({...n,...P.keepDirty?{isDirty:T()}:{}}),!P.keepIsValid&&S()},oe=({disabled:E,name:P,field:V,fields:se})=>{(Rt(E)&&o.mount||E||a.disabled.has(P))&&(E?a.disabled.add(P):a.disabled.delete(P),v(P,ro(V?V._f:ue(se,P)._f),!1,!1,!0))},I=(E,P={})=>{let V=ue(r,E);const se=Rt(P.disabled)||Rt(t.disabled);return Le(r,E,{...V||{},_f:{...V&&V._f?V._f:{ref:{name:E}},name:E,mount:!0,...P}}),a.mount.add(E),V?oe({field:V,disabled:Rt(P.disabled)?P.disabled:t.disabled,name:E}):C(E,!0,P.value),{...se?{disabled:P.disabled||t.disabled}:{},...t.progressive?{required:!!P.required,min:Lr(P.min),max:Lr(P.max),minLength:Lr(P.minLength),maxLength:Lr(P.maxLength),pattern:Lr(P.pattern)}:{},name:E,onChange:Z,onBlur:Z,ref:ie=>{if(ie){I(E,P),V=ue(r,E);const ee=tt(ie.value)&&ie.querySelectorAll&&ie.querySelectorAll("input,select,textarea")[0]||ie,me=vy(ee),we=V._f.refs||[];if(me?we.find(U=>U===ee):ee===V._f.ref)return;Le(r,E,{_f:{...V._f,...me?{refs:[...we.filter(no),ee,...Array.isArray(ue(i,E))?[{}]:[]],ref:{type:ee.type,name:E}}:{ref:ee}}}),C(E,!1,void 0,ee)}else V=ue(r,E,{}),V._f&&(V._f.mount=!1),(t.shouldUnregister||P.shouldUnregister)&&!(mf(a.array,E)&&o.action)&&a.unMount.add(E)}}},re=()=>t.shouldFocusError&&ii(r,X,a.mount),ae=E=>{Rt(E)&&(f.state.next({disabled:E}),ii(r,(P,V)=>{const se=ue(r,V);se&&(P.disabled=se._f.disabled||E,Array.isArray(se._f.refs)&&se._f.refs.forEach(ie=>{ie.disabled=se._f.disabled||E}))},0,!1))},H=(E,P)=>async V=>{let se;V&&(V.preventDefault&&V.preventDefault(),V.persist&&V.persist());let ie=wt(s);if(a.disabled.size)for(const ee of a.disabled)Le(ie,ee,void 0);if(f.state.next({isSubmitting:!0}),t.resolver){const{errors:ee,values:me}=await O();n.errors=ee,ie=me}else await N(r);if(st(n.errors,"root"),kt(n.errors)){f.state.next({errors:{}});try{await E(ie,V)}catch(ee){se=ee}}else P&&await P({...n.errors},V),re(),setTimeout(re);if(f.state.next({isSubmitted:!0,isSubmitting:!1,isSubmitSuccessful:kt(n.errors)&&!se,submitCount:n.submitCount+1,errors:n.errors}),se)throw se},K=(E,P={})=>{ue(r,E)&&(tt(P.defaultValue)?J(E,wt(ue(i,E))):(J(E,P.defaultValue),Le(i,E,wt(P.defaultValue))),P.keepTouched||st(n.touchedFields,E),P.keepDirty||(st(n.dirtyFields,E),n.isDirty=P.defaultValue?T(E,wt(ue(i,E))):T()),P.keepError||(st(n.errors,E),d.isValid&&S()),f.state.next({...n}))},pe=(E,P={})=>{const V=E?wt(E):i,se=wt(V),ie=kt(E),ee=ie?i:se;if(P.keepDefaultValues||(i=V),!P.keepValues){if(P.keepDirtyValues){const me=new Set([...a.mount,...Object.keys(Fr(i,s))]);for(const we of Array.from(me))ue(n.dirtyFields,we)?Le(ee,we,ue(s,we)):J(we,ue(ee,we))}else{if(Ca&&tt(E))for(const me of a.mount){const we=ue(r,me);if(we&&we._f){const U=Array.isArray(we._f.refs)?we._f.refs[0]:we._f.ref;if(ss(U)){const Y=U.closest("form");if(Y){Y.reset();break}}}}r={}}s=t.shouldUnregister?P.keepDefaultValues?wt(i):{}:wt(ee),f.array.next({values:{...ee}}),f.values.next({values:{...ee}})}a={mount:P.keepDirtyValues?a.mount:new Set,unMount:new Set,array:new Set,disabled:new Set,watch:new Set,watchAll:!1,focus:""},o.mount=!d.isValid||!!P.keepIsValid||!!P.keepDirtyValues,o.watch=!!t.shouldUnregister,f.state.next({submitCount:P.keepSubmitCount?n.submitCount:0,isDirty:ie?!1:P.keepDirty?n.isDirty:!!(P.keepDefaultValues&&!xn(E,i)),isSubmitted:P.keepIsSubmitted?n.isSubmitted:!1,dirtyFields:ie?{}:P.keepDirtyValues?P.keepDefaultValues&&s?Fr(i,s):n.dirtyFields:P.keepDefaultValues&&E?Fr(i,E):P.keepDirty?n.dirtyFields:{},touchedFields:P.keepTouched?n.touchedFields:{},errors:P.keepErrors?n.errors:{},isSubmitSuccessful:P.keepIsSubmitSuccessful?n.isSubmitSuccessful:!1,isSubmitting:!1})},fe=(E,P)=>pe(Qt(E)?E(s):E,P);return{control:{register:I,unregister:Q,getFieldState:ce,handleSubmit:H,setError:G,_executeSchema:O,_getWatch:F,_getDirty:T,_updateValid:S,_removeUnmounted:R,_updateFieldArray:j,_updateDisabledField:oe,_getFieldArray:z,_reset:pe,_resetDefaultValues:()=>Qt(t.defaultValues)&&t.defaultValues().then(E=>{fe(E,t.resetOptions),f.state.next({isLoading:!1})}),_updateFormState:E=>{n={...n,...E}},_disableForm:ae,_subjects:f,_proxyFormState:d,_setErrors:A,get _fields(){return r},get _formValues(){return s},get _state(){return o},set _state(E){o=E},get _defaultValues(){return i},get _names(){return a},set _names(E){a=E},get _formState(){return n},set _formState(E){n=E},get _options(){return t},set _options(E){t={...t,...E}}},trigger:_,register:I,handleSubmit:H,watch:ne,setValue:J,getValues:ye,reset:fe,resetField:K,clearErrors:b,unregister:Q,setError:G,setFocus:(E,P={})=>{const V=ue(r,E),se=V&&V._f;if(se){const ie=se.refs?se.refs[0]:se.ref;ie.focus&&(ie.focus(),P.shouldSelect&&Qt(ie.select)&&ie.select())}},getFieldState:ce}}function Cy(e={}){const t=je.useRef(void 0),n=je.useRef(void 0),[r,i]=je.useState({isDirty:!1,isValidating:!1,isLoading:Qt(e.defaultValues),isSubmitted:!1,isSubmitting:!1,isSubmitSuccessful:!1,isValid:!1,submitCount:0,dirtyFields:{},touchedFields:{},validatingFields:{},errors:e.errors||{},disabled:e.disabled||!1,defaultValues:Qt(e.defaultValues)?void 0:e.defaultValues});t.current||(t.current={...Ey(e),formState:r});const s=t.current.control;return s._options=e,Ia({subject:s._subjects.state,next:o=>{bf(o,s._proxyFormState,s._updateFormState,!0)&&i({...s._formState})}}),je.useEffect(()=>s._disableForm(e.disabled),[s,e.disabled]),je.useEffect(()=>{if(s._proxyFormState.isDirty){const o=s._getDirty();o!==r.isDirty&&s._subjects.state.next({isDirty:o})}},[s,r.isDirty]),je.useEffect(()=>{e.values&&!xn(e.values,n.current)?(s._reset(e.values,s._options.resetOptions),n.current=e.values,i(o=>({...o}))):s._resetDefaultValues()},[e.values,s]),je.useEffect(()=>{e.errors&&s._setErrors(e.errors)},[e.errors,s]),je.useEffect(()=>{s._state.mount||(s._updateValid(),s._state.mount=!0),s._state.watch&&(s._state.watch=!1,s._subjects.state.next({...s._formState})),s._removeUnmounted()}),je.useEffect(()=>{e.shouldUnregister&&s._subjects.values.next({values:s._getWatch()})},[e.shouldUnregister,s]),t.current.formState=yf(r,s),t.current}function Ty(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 Iy=dy,Cf=x.createContext({}),Rl=({...e})=>c.jsx(Cf.Provider,{value:{name:e.name},children:c.jsx(my,{...e})}),Ds=()=>{const e=x.useContext(Cf),t=x.useContext(Tf),{getFieldState:n,formState:r}=Ps(),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}},Tf=x.createContext({}),Zo=x.forwardRef(({className:e,...t},n)=>{const r=x.useId();return c.jsx(Tf.Provider,{value:{id:r},children:c.jsx("div",{ref:n,className:W("space-y-2",e),...t})})});Zo.displayName="FormItem";const Uo=x.forwardRef(({className:e,...t},n)=>{const{error:r,formItemId:i}=Ds();return c.jsx(ni,{ref:n,className:W(r&&"text-destructive",e),htmlFor:i,...t})});Uo.displayName="FormLabel";const Jo=x.forwardRef(({...e},t)=>{const{error:n,formItemId:r,formDescriptionId:i,formMessageId:s}=Ds();return c.jsx(Tr,{ref:t,id:r,"aria-describedby":n?`${i} ${s}`:`${i}`,"aria-invalid":!!n,...e})});Jo.displayName="FormControl";const If=x.forwardRef(({className:e,...t},n)=>{const{formDescriptionId:r}=Ds();return c.jsx("p",{ref:n,id:r,className:W("text-muted-foreground text-[0.8rem]",e),...t})});If.displayName="FormDescription";const Ho=x.forwardRef(({className:e,children:t,...n},r)=>{const{error:i,formMessageId:s}=Ds(),o=i?String(i==null?void 0:i.message):t;return o?c.jsx("p",{ref:r,id:s,className:W("text-destructive text-[0.8rem] font-medium",e),...n,children:o}):null});Ho.displayName="FormMessage";function Oa(){const e=new Date,t=n=>String(n).padStart(2,"0");return`Chat ${t(e.getMonth()+1)}/${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`}const Af=()=>({chatOpen:!1,scope:"global",model:"opus",contextAttachments:[],threads:{},activeThreadId:{}}),Ay=(e=Af())=>Bx()(Vx(Zx((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:Oa(),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(([u])=>u!==r)),a=s.documentName,l={...i.activeThreadId};if(l[a]===r){const u=Object.values(o).filter(d=>d.documentName===a);u.length>0?(u.sort((d,f)=>f.updatedAt-d.updatedAt),l[a]=u[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,u]of Object.entries(o))u.documentName===r&&(o[l]={...u,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:Ux(()=>wg),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}}))),zf=x.createContext(void 0),zy=({children:e})=>{const t=x.useRef(null);return t.current||(t.current=Ay(Af())),c.jsx(zf.Provider,{value:t.current,children:e})},De=e=>{const t=x.useContext(zf);if(!t)throw new Error("useChatStore must be used within ChatStoreProvider");return Jx(t,e)};function Of(e){return`${e.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((n,r)=>r===0?n.charAt(0).toLowerCase()+n.slice(1):n.charAt(0).toUpperCase()+n.slice(1)).join("")||"custom"}Component`}function Oy(e){const t=Of(e);return`import { Type } from '@sinclair/typebox';
3
- import { createComponent, createVersion } from '@json-to-office/core-docx';
4
- import type { ComponentDefinition } from '@json-to-office/shared-docx';
5
-
6
- /**
7
- * Props are a TypeBox schema: it validates the JSON, drives editor
8
- * completions, and types \`props\` inside render().
9
- */
10
- const PropsSchema = Type.Object(
11
- {
12
- title: Type.String({ description: 'Short heading for the callout' }),
13
- text: Type.String({
14
- description: 'Body text; inline markdown such as **bold** is allowed',
15
- }),
16
- tone: Type.Optional(
17
- Type.Union([Type.Literal('info'), Type.Literal('warning')], {
18
- default: 'info',
19
- description: 'Which theme colour the heading takes',
20
- })
21
- ),
22
- },
23
- { additionalProperties: false }
24
- );
25
-
26
- /**
27
- * A titled callout: a heading and a paragraph, coloured from the active theme.
28
- *
29
- * @example
30
- * \`\`\`json
31
- * {
32
- * "name": "${e}",
33
- * "props": {
34
- * "title": "Note",
35
- * "text": "This block was produced by a plugin written in the playground.",
36
- * "tone": "info"
37
- * }
38
- * }
39
- * \`\`\`
40
- */
41
- export const ${t} = createComponent({
42
- name: '${e}',
43
- versions: {
44
- '1.0.0': createVersion({
45
- propsSchema: PropsSchema,
46
- description: 'Titled callout coloured from the theme',
47
- render: async ({ props, theme, addWarning }) => {
48
- const color =
49
- props.tone === 'warning' ? theme.colors.secondary : theme.colors.accent;
50
- if (!props.text.trim()) {
51
- addWarning('Callout has no text', { title: props.title });
52
- }
53
- const components: ComponentDefinition[] = [
54
- {
55
- name: 'paragraph',
56
- props: {
57
- text: props.title,
58
- font: { bold: true, size: 12, color },
59
- spacing: { before: 8, after: 2 },
60
- },
61
- },
62
- {
63
- name: 'paragraph',
64
- props: { text: props.text, spacing: { after: 10 } },
65
- },
66
- ];
67
- return components;
68
- },
69
- }),
70
- },
71
- });
72
- `}function Py(e){const t=Of(e);return`import { Type } from '@sinclair/typebox';
73
- import { createComponent, createVersion } from '@json-to-office/json-to-pptx';
74
- import type { PptxComponentDefinition } from '@json-to-office/shared-pptx';
75
-
76
- /**
77
- * Props are a TypeBox schema: it validates the JSON, drives editor
78
- * completions, and types \`props\` inside render().
79
- */
80
- const PropsSchema = Type.Object(
81
- {
82
- label: Type.String({ description: 'What the number measures' }),
83
- value: Type.String({ description: 'The number, already formatted' }),
84
- x: Type.Optional(Type.Number({ default: 0.5, description: 'Left edge, inches' })),
85
- y: Type.Optional(Type.Number({ default: 1.5, description: 'Top edge, inches' })),
86
- w: Type.Optional(Type.Number({ default: 3, description: 'Width, inches' })),
87
- },
88
- { additionalProperties: false }
89
- );
90
-
91
- /**
92
- * A KPI tile: a large value over its label, coloured from the active theme.
93
- *
94
- * @example
95
- * \`\`\`json
96
- * {
97
- * "name": "${e}",
98
- * "props": { "label": "Revenue", "value": "$4.2M", "x": 0.5, "y": 1.5, "w": 3 }
99
- * }
100
- * \`\`\`
101
- */
102
- export const ${t} = createComponent({
103
- name: '${e}',
104
- versions: {
105
- '1.0.0': createVersion({
106
- propsSchema: PropsSchema,
107
- description: 'KPI tile: large value over its label',
108
- render: async ({ props, theme, addWarning }) => {
109
- const x = props.x ?? 0.5;
110
- const y = props.y ?? 1.5;
111
- const w = props.w ?? 3;
112
- if (!props.value.trim()) {
113
- addWarning('KPI tile has no value', { label: props.label });
114
- }
115
- const components: PptxComponentDefinition[] = [
116
- {
117
- name: 'text',
118
- props: {
119
- text: props.value,
120
- x,
121
- y,
122
- w,
123
- h: 0.9,
124
- fontSize: 36,
125
- bold: true,
126
- color: theme.colors.primary,
127
- },
128
- },
129
- {
130
- name: 'text',
131
- props: {
132
- text: props.label,
133
- x,
134
- y: y + 0.9,
135
- w,
136
- h: 0.4,
137
- fontSize: 12,
138
- color: theme.colors.text2 ?? theme.colors.text,
139
- },
140
- },
141
- ];
142
- return components;
143
- },
144
- }),
145
- },
146
- });
147
- `}function Dy(e,t){return e==="docx"?Oy(t):Py(t)}function Ry(e){const t=e.match(/createComponent\s*\(\s*\{[^}]*?\bname\s*:\s*(['"`])([^'"`]+)\1/);return t?t[2]:null}function $y(e,t){return e.replace(/(createComponent\s*\(\s*\{[^}]*?\bname\s*:\s*)(['"`])([^'"`]+)\2/,(n,r,i)=>`${r}${i}${t}${i}`)}function My(e){const t=e.replace(/\.component\.ts$/i,"").replace(/\.ts$/i,"").trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");return t?/^[a-z]/.test(t)?t:`x-${t}`:"custom-block"}function Fy(e,t,n){return t.filter(r=>r.name!==n).every(r=>r.name!==e)}function Ly(e,t,n,r){const i={},s=[];e!=="delete"&&(i.name=Ri.String({minLength:1,maxLength:120,pattern:"^[a-zA-Z0-9-_. ]+$",description:"Document name (e.g., my-report.docx.json or my-theme.theme.json)"}),s.push("name")),e==="create"&&(i.template=Ri.Optional(Ri.String({description:"Template selection"})));const o=Ri.Object(i,{additionalProperties:!1,required:s.length>0?s:void 0});return{schema:o,validate:a=>{const l=[];if(!Og(o,a))for(const d of Pg(o,a))l.push({path:d.path.replace(/^\//,""),message:d.message});const u=a;if(e!=="delete"&&u.name){const d=u.name.trim();d?(u.name=d,t((r==null?void 0:r(d))??d)||l.push({path:"name",message:"Document with this name already exists"})):l.push({path:"name",message:"Name can't be empty"})}return e==="create"&&(n!=null&&n.length)&&u.template&&(n.some(d=>d.name===u.template)||l.push({path:"template",message:"You must select a valid template"})),{success:l.length===0,data:l.length===0?u:void 0,errors:l}}}}function By(e,t,n){return e==="create"?{name:"",template:t}:e==="update"?{name:n}:{}}const Vy=e=>({create:{title:e==="theme"?"New Theme":e==="plugin"?"New Plugin":"New Document",description:e==="theme"?"Create a new theme from scratch or based on discovered themes.":e==="plugin"?"Write a custom component in TypeScript. It compiles and runs in your browser; documents use it by name like any built-in component.":"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"}}),Hn="__empty__";function Zy({mode:e,shouldReset:t,postSubmit:n,selectedName:r,discoveredDocuments:i,discoveredThemes:s,discoveredPlugins:o,isTheme:a,isPlugin:l}){const[u,d]=x.useState(!1),[f,h]=x.useState(null),[p,g]=x.useState("idle"),{toast:k}=Cr(),S=l?"plugin":a?"theme":"document",y=Vy(S),{documents:j,openTabs:m,createDocument:A,renameDocument:C,deleteDocument:v,openDocument:w,closeDocument:O,documentTypes:B}=ke(I=>I),{updateTheme:N,removeTheme:R}=Do(I=>I),T=vn(I=>I.rename),F=vn(I=>I.remove),z=De(I=>I.renameThreadsForDocument),M=De(I=>I.deleteThreadsForDocument),D=x.useMemo(()=>S==="plugin"?(o||[]).map(I=>({name:I.name,path:I.filePath,location:I.location==="current"?"current":"downstream",description:I.description})):S==="theme"?s||[]:i||[],[S,i,s,o]),J=x.useMemo(()=>{const I={current:[],downstream:[]};return D.forEach(re=>{I[re.location]&&I[re.location].push(re)}),I},[D]),Z=x.useMemo(()=>D.map(I=>({name:I.name,type:"application/json",text:"",mtime:new Date,ctime:new Date,atime:new Date})),[D]),X=S==="plugin"||e==="update"&&!!r&&B[r]==="application/typescript+plugin",_=x.useMemo(()=>Ly(e,I=>Fy(I,j,r),Z,X?Xs:void 0),[e,j,r,Z,X]),ye=_.schema,ce=x.useMemo(()=>{const I=new Map;return D.forEach(re=>I.set(re.path,re)),I},[D]),b=Hn,G=Cy({resolver:Ty(_.validate),defaultValues:By(e,void 0,r)}),[ne,Q]=x.useState(b);x.useEffect(()=>{if(ne&&ne!==Hn&&e==="create"){const I=ce.get(ne);if(I){h(null),g("loading");let re=!1;const ae=S==="plugin"?`/api/discovery/plugins/${encodeURIComponent(I.name)}/source`:`/api/discovery/${S==="theme"?"themes":"documents"}/${encodeURIComponent(I.name)}/content`;return fetch(ae).then(H=>{if(!H.ok)throw new Error(`Failed to fetch content: ${H.statusText}`);return H.text()}).then(H=>{if(!re){if(S==="plugin"){const K=Ry(H);h(K?$y(H,`${K}-custom`):H)}else{const K=JSON.parse(H);h(JSON.stringify(K,null,2))}g("idle")}}).catch(H=>{re||(console.error("Failed to copy template:",H),h(null),g("error"))}),()=>{re=!0}}}g("idle")},[ne,e,ce,S]),x.useEffect(()=>{t&&(G.reset(),h(null),g("idle"),Q(b))},[G,t]);const oe=G.handleSubmit(async({name:I,template:re})=>{d(!0);try{if(await new Promise(ae=>setTimeout(ae,200)),e==="create"){const ae=ne?ce.get(ne):D.find(P=>P.name===re);let H,K=I;if(!!ne&&ne!==Hn&&f===null){k({title:p==="loading"?"Template still loading":`Could not copy ${(ae==null?void 0:ae.name)??"the selected template"}`,description:p==="loading"?"Wait for the template to finish loading, then try again.":"Pick another template, or create an empty one instead.",variant:"destructive"});return}if(S==="plugin")K=Xs(K),H=f||Dy(at,My(K));else if(a){const P=K.replace(/\.(json|theme)$/i,"").toLowerCase().replace(/\s+/g,"-"),V=at==="docx"?Dg(P):{name:P,colors:{primary:"#2563EB",secondary:"#64748B",accent:"#F8FAFC",background:"#FFFFFF",text:"#334155"},fonts:{heading:"Calibri",body:"Calibri"},defaults:{fontSize:18,fontColor:"#334155"}};H=f||JSON.stringify(V,null,2);const se=`.${at}.theme.json`;K.endsWith(se)||(K=K.replace(/\.(pptx|docx)\.theme\.json$/i,"").replace(/\.theme\.json$/i,"").replace(/\.json$/i,""),K+=se)}else{const P=ae;H=f||JSON.stringify(at==="docx"?{name:"docx",props:{theme:(P==null?void 0:P.theme)||"default",metadata:{title:(P==null?void 0:P.title)||K.replace(/\.(json|js)$/i,"")}},children:[{name:"section",props:{},children:[{name:"paragraph",props:{text:"Start writing your document content here..."}}]}]}:{name:"pptx",props:{title:(P==null?void 0:P.title)||K.replace(/\.(json|js)$/i,""),theme:(P==null?void 0:P.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 V=at==="docx"?".docx.json":".pptx.json";!K.endsWith(V)&&!K.endsWith(".json")&&(K+=V)}const fe=K.match(/(\.(pptx|docx)(\.theme)?\.json|\.json|\.component\.ts)$/i),Re=fe?fe[0]:"",Oe=K.slice(0,K.length-Re.length);let $e=K,E=1;for(;j.some(P=>P.name===$e);)E++,$e=`${Oe} (${E})${Re}`;K=$e,A(K,H),w(K),a&&N(K,H)}else if(e==="update"){const ae=r;let H=I;const K=B[ae]==="application/typescript+plugin";if(K&&(H=Xs(H)),H!==ae&&j.some(fe=>fe.name===H)){k({title:`"${H}" already exists`,description:"Pick another name.",variant:"destructive"});return}const pe=m.includes(ae);pe&&O(ae),K&&T(ae,H),C(ae,H),z(ae,H),pe&&w(H)}else if(e==="delete"){const ae=r,H=B[ae]==="application/typescript+plugin";O(ae),v(ae),M(ae),a&&R(ae),H&&F(ae)}n()}finally{d(!1)}});return c.jsx(Iy,{...G,children:c.jsxs("form",{onSubmit:oe,children:[c.jsxs(qt,{children:[c.jsx(Gt,{children:y[e].title}),c.jsx(dn,{children:y[e].description})]}),c.jsxs("div",{className:"flex flex-col gap-4 py-4",children:[ye.properties&&"name"in ye.properties&&c.jsx(Rl,{control:G.control,name:"name",render:({field:I})=>c.jsxs(Zo,{children:[c.jsx(Uo,{children:"Name"}),c.jsx(Jo,{children:c.jsx(wr,{placeholder:"Enter a name or select a template below",autoComplete:"off",...I})}),c.jsx(Ho,{})]})}),e==="create"&&c.jsx(Rl,{control:G.control,name:"template",render:({field:I})=>c.jsxs(Zo,{children:[c.jsx(Uo,{children:S==="theme"?"Base Theme":S==="plugin"?"Start from":"Base Document"}),c.jsxs(fi,{onValueChange:re=>{if(re===Hn)I.onChange(void 0),G.setValue("name",""),Q(Hn),h(null);else{const ae=ce.get(re);ae&&(I.onChange(ae.name),G.setValue("name",ae.name),Q(re))}},defaultValue:b,children:[c.jsx(Jo,{children:c.jsx(br,{children:c.jsx(pi,{placeholder:`Select a discovered ${S}`})})}),c.jsxs(vr,{className:"max-h-[300px]",children:[c.jsx(Mn,{value:Hn,children:S==="plugin"?`Starter ${at} component`:`Empty ${S}`}),Object.entries(J).map(([re,ae])=>ae.length===0?null:c.jsxs(uf,{children:[c.jsx(Ea,{children:re==="current"?"📁 Current Directory":"📦 Project"}),ae.map(H=>{let K;return H.title&&H.title!==H.name?K=H.title:H.description&&(K=H.description.length>40?H.description.substring(0,40)+"...":H.description),c.jsx(Mn,{value:H.path,className:"pl-6",children:c.jsxs("span",{className:"flex flex-col",children:[c.jsx("span",{className:"font-medium",children:H.name}),K&&c.jsx("span",{className:"text-muted-foreground text-xs",children:K})]})},H.path)})]},re))]})]}),c.jsx(If,{children:S==="plugin"?'Start from the starter component, or copy a plugin discovered on disk — the copy is renamed "<name>-custom" so both can exist':`Start empty or select a discovered ${S} as a starting point`}),c.jsx(Ho,{})]})})]}),c.jsx(kn,{children:c.jsx(Ee,{type:"submit",variant:y[e].buttonVariant,disabled:u,children:u?c.jsxs(c.Fragment,{children:[c.jsx(cn,{size:"sm",className:"mr-2"}),e==="create"?"Creating...":e==="update"?"Saving...":"Deleting..."]}):y[e].button})})]})})}const Dn=je.memo(Zy);function on(e,t){return t?e.toLowerCase().includes(t.toLowerCase()):!0}function Rs({text:e,query:t}){if(!t)return c.jsx(c.Fragment,{children:e});const n=e.toLowerCase().indexOf(t.toLowerCase());return n===-1?c.jsx(c.Fragment,{children:e}):c.jsxs(c.Fragment,{children:[e.slice(0,n),c.jsx("mark",{className:"bg-transparent p-0 font-semibold text-current",children:e.slice(n,n+t.length)}),e.slice(n+t.length)]})}function Wo({children:e,count:t,actions:n,className:r,open:i,onToggle:s}){const o=c.jsxs(c.Fragment,{children:[c.jsx(Ir,{"aria-hidden":!0,className:W("size-3 shrink-0 transition-transform duration-150 ease-out",i&&"rotate-90")}),c.jsx("span",{className:"text-[11px] font-medium tracking-[0.08em] uppercase",children:e}),t!==void 0&&c.jsx("span",{className:"text-[11px] font-normal tabular-nums text-sidebar-foreground/65",children:t})]});return c.jsxs("div",{className:W("flex h-6 shrink-0 items-center gap-1.5 select-none",r),children:[c.jsx("button",{type:"button",onClick:s,"aria-expanded":i,className:W("flex h-6 min-w-0 flex-1 cursor-pointer items-center gap-1.5 rounded-sm px-1","text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:o}),n&&c.jsx("div",{className:"flex shrink-0 items-center gap-0.5 pr-1",children:n})]})}const Ct=je.forwardRef(({className:e,...t},n)=>c.jsx("button",{ref:n,type:"button",className:W("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}));Ct.displayName="RailIconButton";function $l({tone:e,className:t}){return c.jsx("span",{"aria-hidden":!0,className:W("size-1.5 shrink-0 rounded-full",e==="preview"?"bg-data-blue":"bg-warning",t)})}function qo({icon:e,label:t,onClick:n,hint:r}){return n?c.jsxs("button",{type:"button",onClick:n,title:r,className:W("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:[c.jsx(e,{className:"size-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:t})]}):c.jsx("p",{className:"px-2 py-1 text-[12px] leading-tight text-sidebar-foreground/70",children:t})}const Pf=qg,Df=Gg,Uy=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>c.jsxs(Id,{ref:i,className:W("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,c.jsx(Ir,{className:"ml-auto h-4 w-4"})]}));Uy.displayName=Id.displayName;const Jy=x.forwardRef(({className:e,...t},n)=>c.jsx(Ad,{ref:n,className:W("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}));Jy.displayName=Ad.displayName;const Pa=x.forwardRef(({className:e,...t},n)=>c.jsx(Kg,{children:c.jsx(Ed,{ref:n,className:W("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})}));Pa.displayName=Ed.displayName;const Da=x.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Td,{ref:r,className:W("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}));Da.displayName=Td.displayName;const Hy=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>c.jsxs(zd,{ref:i,className:W("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Od,{children:c.jsx(un,{className:"h-4 w-4"})})}),t]}));Hy.displayName=zd.displayName;const Wy=x.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Pd,{ref:r,className:W("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Od,{children:c.jsx(Xd,{className:"h-4 w-4 fill-current"})})}),t]}));Wy.displayName=Pd.displayName;const qy=x.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Dd,{ref:r,className:W("text-foreground px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));qy.displayName=Dd.displayName;const Ra=x.forwardRef(({className:e,...t},n)=>c.jsx(Cd,{ref:n,className:W("bg-border -mx-1 my-1 h-px",e),...t}));Ra.displayName=Cd.displayName;const Rf=({className:e,...t})=>c.jsx("span",{className:W("text-muted-foreground ml-auto text-xs tracking-widest",e),...t});Rf.displayName="ContextMenuShortcut";const Ti=Yg,Ii=Xg,Gy=x.forwardRef(({className:e,inset:t,children:n,...r},i)=>c.jsxs(Ld,{ref:i,className:W("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,c.jsx(Ir,{className:"ml-auto"})]}));Gy.displayName=Ld.displayName;const Ky=x.forwardRef(({className:e,...t},n)=>c.jsx(Bd,{ref:n,className:W("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}));Ky.displayName=Bd.displayName;const Ar=x.forwardRef(({className:e,sideOffset:t=4,...n},r)=>c.jsx(Qg,{children:c.jsx(Rd,{ref:r,sideOffset:t,className:W("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})}));Ar.displayName=Rd.displayName;const $t=x.forwardRef(({className:e,inset:t,...n},r)=>c.jsx($d,{ref:r,className:W("focus:bg-accent focus:text-accent-foreground relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm transition-colors outline-none select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",t&&"pl-8",e),...n}));$t.displayName=$d.displayName;const Yy=x.forwardRef(({className:e,children:t,checked:n,...r},i)=>c.jsxs(Vd,{ref:i,className:W("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Zd,{children:c.jsx(un,{className:"h-4 w-4"})})}),t]}));Yy.displayName=Vd.displayName;const Xy=x.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Ud,{ref:r,className:W("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:[c.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:c.jsx(Zd,{children:c.jsx(Xd,{className:"h-2 w-2 fill-current"})})}),t]}));Xy.displayName=Ud.displayName;const $a=x.forwardRef(({className:e,inset:t,...n},r)=>c.jsx(Fd,{ref:r,className:W("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));$a.displayName=Fd.displayName;const Fn=x.forwardRef(({className:e,...t},n)=>c.jsx(Md,{ref:n,className:W("bg-muted -mx-1 my-1 h-px",e),...t}));Fn.displayName=Md.displayName;const $f=({className:e,...t})=>c.jsx("span",{className:W("ml-auto text-xs tracking-widest opacity-60",e),...t});$f.displayName="DropdownMenuShortcut";const Mf=x.forwardRef(({className:e,orientation:t="horizontal",decorative:n=!0,...r},i)=>c.jsx(Jd,{ref:i,decorative:n,orientation:t,className:W("bg-border shrink-0",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...r}));Mf.displayName=Jd.displayName;const Ff=xd,Qy=ex,eb=yd,Lf=x.forwardRef(({className:e,...t},n)=>c.jsx(As,{className:W("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}));Lf.displayName=As.displayName;const tb=Ei("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"}}),Ma=x.forwardRef(({side:e="right",className:t,children:n,...r},i)=>c.jsxs(eb,{children:[c.jsx(Lf,{}),c.jsxs(Cs,{ref:i,className:W(tb({side:e}),t),...r,children:[c.jsxs(Sa,{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:[c.jsx(wn,{className:"h-4 w-4"}),c.jsx("span",{className:"sr-only",children:"Close"})]}),n]})]}));Ma.displayName=Cs.displayName;const nb=x.forwardRef(({className:e,...t},n)=>c.jsx(Ts,{ref:n,className:W("text-foreground text-lg font-semibold",e),...t}));nb.displayName=Ts.displayName;const rb=x.forwardRef(({className:e,...t},n)=>c.jsx(Is,{ref:n,className:W("text-muted-foreground text-sm",e),...t}));rb.displayName=Is.displayName;function si({className:e,...t}){return c.jsx("div",{className:W("bg-primary/10 animate-pulse rounded-md",e),...t})}const io=768,so=1200;function Bf(e){return typeof window<"u"?window.innerWidth<e:!1}function Vf(){const[e,t]=x.useState(()=>Bf(io));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${io-1}px)`),r=()=>{t(window.innerWidth<io)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function ib(){const[e,t]=x.useState(()=>Bf(so));return x.useEffect(()=>{const n=window.matchMedia(`(max-width: ${so-1}px)`),r=()=>{t(window.innerWidth<so)};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}const sb="sidebar_state",ob=60*60*24*7,ab="16rem",lb="18rem",cb="3rem",ub="b",Zf=x.createContext(null);function $s(){const e=x.useContext(Zf);if(!e)throw new Error("useSidebar must be used within a SidebarProvider.");return e}const Uf=x.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:s,...o},a)=>{const l=Vf(),[u,d]=x.useState(!1),[f,h]=x.useState(e),p=t??f,g=x.useCallback(j=>{const m=typeof j=="function"?j(p):j;n?n(m):h(m),document.cookie=`${sb}=${m}; path=/; max-age=${ob}`},[n,p]),k=x.useCallback(()=>l?d(j=>!j):g(j=>!j),[l,g,d]);x.useEffect(()=>{const j=A=>{var w;const C=A;if(!C)return!1;const v=(w=C.tagName)==null?void 0:w.toLowerCase();return v==="input"||v==="textarea"||v==="select"||C.isContentEditable?!0:!!(C.closest&&C.closest(".monaco-editor"))},m=A=>{const C=A.metaKey||A.ctrlKey,v=A.key.toLowerCase();if(C&&v===ub){A.preventDefault(),k();return}C&&v==="s"&&!j(A.target)&&(A.preventDefault(),k())};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[k]);const S=p?"expanded":"collapsed",y=x.useMemo(()=>({state:S,open:p,setOpen:g,isMobile:l,openMobile:u,setOpenMobile:d,toggleSidebar:k}),[S,p,g,l,u,d,k]);return c.jsx(Zf.Provider,{value:y,children:c.jsx(Rg,{delayDuration:0,children:c.jsx("div",{style:{"--sidebar-width":ab,"--sidebar-width-icon":cb,...i},className:W("group/sidebar-wrapper has-[[data-variant=inset]]:bg-sidebar flex min-h-svh w-full",r),ref:a,...o,children:s})})})});Uf.displayName="SidebarProvider";const Jf=x.forwardRef(({side:e="left",variant:t="sidebar",collapsible:n="offcanvas",className:r,children:i,...s},o)=>{const{isMobile:a,state:l,openMobile:u,setOpenMobile:d}=$s();return n==="none"?c.jsx("div",{className:W("bg-sidebar text-sidebar-foreground flex h-full w-[--sidebar-width] flex-col",r),ref:o,...s,children:i}):a?c.jsx(Ff,{open:u,onOpenChange:d,...s,children:c.jsx(Ma,{"data-sidebar":"sidebar","data-mobile":"true",className:"bg-sidebar text-sidebar-foreground w-[--sidebar-width] p-0 [&>button]:hidden",style:{"--sidebar-width":lb},side:e,children:c.jsx("div",{className:"flex h-full w-full flex-col",children:i})})}):c.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:[c.jsx("div",{className:W("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]")}),c.jsx("div",{className:W("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:c.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})})]})});Jf.displayName="Sidebar";const db=x.forwardRef(({className:e,onClick:t,...n},r)=>{const{toggleSidebar:i}=$s();return c.jsxs(Ee,{ref:r,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:W("h-7 w-7",e),onClick:s=>{t==null||t(s),i()},...n,children:[c.jsx(cx,{}),c.jsx("span",{className:"sr-only",children:"Toggle Sidebar"})]})});db.displayName="SidebarTrigger";const fb=x.forwardRef(({className:e,...t},n)=>{const{toggleSidebar:r}=$s();return c.jsx("button",{ref:n,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:r,title:"Toggle Sidebar",className:W("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})});fb.displayName="SidebarRail";const pb=x.forwardRef(({className:e,...t},n)=>c.jsx("main",{ref:n,className:W("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}));pb.displayName="SidebarInset";const hb=x.forwardRef(({className:e,...t},n)=>c.jsx(wr,{ref:n,"data-sidebar":"input",className:W("bg-background focus-visible:ring-sidebar-ring h-8 w-full shadow-none focus-visible:ring-2",e),...t}));hb.displayName="SidebarInput";const Go=x.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,"data-sidebar":"header",className:W("flex flex-col gap-2 p-2",e),...t}));Go.displayName="SidebarHeader";const Hf=x.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,"data-sidebar":"footer",className:W("flex flex-col gap-2 p-2",e),...t}));Hf.displayName="SidebarFooter";const mb=x.forwardRef(({className:e,...t},n)=>c.jsx(Mf,{ref:n,"data-sidebar":"separator",className:W("bg-sidebar-border mx-2 w-auto",e),...t}));mb.displayName="SidebarSeparator";const Ko=x.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,"data-sidebar":"content",className:W("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",e),...t}));Ko.displayName="SidebarContent";const gb=x.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,"data-sidebar":"group",className:W("relative flex w-full min-w-0 flex-col p-2",e),...t}));gb.displayName="SidebarGroup";const xb=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Tr:"div";return c.jsx(i,{ref:r,"data-sidebar":"group-label",className:W("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})});xb.displayName="SidebarGroupLabel";const yb=x.forwardRef(({className:e,asChild:t=!1,...n},r)=>{const i=t?Tr:"button";return c.jsx(i,{ref:r,"data-sidebar":"group-action",className:W("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 bb=x.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,"data-sidebar":"group-content",className:W("w-full text-sm",e),...t}));bb.displayName="SidebarGroupContent";const nr=x.forwardRef(({className:e,...t},n)=>c.jsx("ul",{ref:n,"data-sidebar":"menu",className:W("flex w-full min-w-0 flex-col gap-1",e),...t}));nr.displayName="SidebarMenu";const Wf=x.forwardRef(({className:e,...t},n)=>c.jsx("li",{ref:n,"data-sidebar":"menu-item",className:W("group/menu-item relative",e),...t}));Wf.displayName="SidebarMenuItem";const vb=Ei("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"}}),qf=x.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n="default",size:r="default",tooltip:i,className:s,...o},a)=>{const l=e?Tr:"button",{isMobile:u,state:d}=$s(),f=c.jsx(l,{ref:a,"data-sidebar":"menu-button","data-size":r,"data-active":t,className:W(vb({variant:n,size:r}),s),...o});return i?(typeof i=="string"&&(i={children:i}),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:f}),c.jsx(Qe,{side:"right",align:"center",hidden:d!=="collapsed"||u,...i})]})):f});qf.displayName="SidebarMenuButton";const Gf=x.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},i)=>{const s=t?Tr:"button";return c.jsx(s,{ref:i,"data-sidebar":"menu-action",className:W("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 wb=x.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,"data-sidebar":"menu-badge",className:W("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}));wb.displayName="SidebarMenuBadge";const kb=x.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{const i=x.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return c.jsxs("div",{ref:r,"data-sidebar":"menu-skeleton",className:W("flex h-8 items-center gap-2 rounded-md px-2",e),...n,children:[t&&c.jsx(si,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),c.jsx(si,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":i}})]})});kb.displayName="SidebarMenuSkeleton";const Sb=x.forwardRef(({className:e,...t},n)=>c.jsx("ul",{ref:n,"data-sidebar":"menu-sub",className:W("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}));Sb.displayName="SidebarMenuSub";const jb=x.forwardRef(({...e},t)=>c.jsx("li",{ref:t,...e}));jb.displayName="SidebarMenuSubItem";const _b=x.forwardRef(({asChild:e=!1,size:t="md",isActive:n,className:r,...i},s)=>{const o=e?Tr:"a";return c.jsx(o,{ref:s,"data-sidebar":"menu-sub-button","data-size":t,"data-active":n,className:W("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})});_b.displayName="SidebarMenuSubButton";function oi(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 Nb=typeof window<"u"?navigator.userAgent.toUpperCase().indexOf("MAC")>=0:!1;function Eb({document:e,compact:t=!1,query:n=""}){const r=x.useRef(null),[i,s]=x.useState(!1),[o,a]=x.useState(!1),[l,u]=x.useState(!1),[d,f]=x.useState(!1),h=ke(b=>b.openDocument),p=ke(b=>b.documentTypes),g=ke(b=>b.activeTab),k=an(b=>b.name),S=an(b=>b.text),y=an(b=>b.isGenerating),j=p[e.name]||"application/json+report",m=j==="application/json+theme",A=j==="application/typescript+plugin",C=g===e.name,[v,w]=x.useState(k),[O,B]=x.useState(S),N=100,R=0;x.useEffect(()=>{const b=setTimeout(()=>{k&&S?(w(k),B(S)):y||(w(""),B(""))},y?N:R);return()=>clearTimeout(b)},[k,S,y]);const T=v===e.name,F=b=>{var ne;const G=new Set;try{const Q=JSON.parse(b);(ne=Q.props)!=null&&ne.theme&&G.add(Q.props.theme),Q.children&&Array.isArray(Q.children)&&Q.children.forEach(oe=>{var I;oe.name==="docx"&&((I=oe.props)!=null&&I.theme)&&G.add(oe.props.theme)})}catch{}return G},z=x.useMemo(()=>{if(!m||!O)return!1;try{const b=JSON.parse(e.text),G=kg(b);if(G)return F(O).has(G)}catch{}return!1},[m,O,e.text]),M=x.useCallback(()=>{u(!1)},[]),D=x.useCallback(()=>{f(!1)},[]),J=C?null:T?"preview":z?"in-use":null,Z=C?"Editing":T?"In preview":z?"Used by preview":null,X=x.useMemo(()=>[{key:"open",label:"Open",shortcut:Nb?"⌘⏎":"⌃⏎",run:()=>h(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>oi(e.name,new Blob([e.text],{type:e.type}))},{key:"rename",label:"Rename…",shortcut:"⏎",separatorBefore:!0,run:()=>u(!0)},{key:"delete",label:"Delete",shortcut:"⌫",danger:!0,run:()=>f(!0)}],[e.name,e.text,e.type,h]),_=m?ux:A?Qd:ef,ye=i||o,ce=c.jsxs(qf,{size:"sm",ref:r,"aria-label":Z?`${e.name} — ${Z}`:e.name,className:W("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",ye&&"bg-sidebar-accent/60 text-sidebar-foreground",C&&"bg-sidebar-accent text-sidebar-accent-foreground font-medium"),title:Z?`${e.name} — ${Z}`:e.name,onClick:()=>{h(e.name)},onKeyDown:b=>{var G;(b.ctrlKey||b.metaKey)&&b.key==="Enter"?(h(e.name),b.preventDefault()):b.key==="Enter"?(u(!0),b.preventDefault()):b.key==="Backspace"||b.key==="Delete"?(f(!0),b.preventDefault()):b.key==="Escape"&&((G=r.current)==null||G.blur(),b.preventDefault())},children:[C&&c.jsx("span",{"aria-hidden":!0,className:W("bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full",t&&"top-1.5 bottom-1.5")}),c.jsx(_,{className:W("size-3.5 shrink-0",m?"text-accent2":"text-sidebar-foreground/60",C&&!m&&"text-sidebar-accent-foreground/70")}),!t&&c.jsx("span",{className:"flex-1 truncate",children:c.jsx(Rs,{text:e.name,query:n})}),t&&J&&c.jsx($l,{tone:J,className:"absolute top-1 right-1 size-1.5 ring-2 ring-[hsl(var(--sidebar))]"})]});return c.jsxs(Wf,{children:[c.jsxs(Pf,{onOpenChange:s,children:[c.jsx(Df,{className:"block",children:t?c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:ce}),c.jsx(Qe,{side:"right",children:c.jsxs("div",{className:"text-xs",children:[c.jsx("div",{children:e.name}),c.jsx("div",{className:"opacity-70",children:Z??(m?"Theme":A?"Plugin":"Document")})]})})]}):ce}),c.jsx(Pa,{className:"w-44",children:X.map(b=>c.jsxs(je.Fragment,{children:[b.separatorBefore&&c.jsx(Ra,{}),c.jsxs(Da,{onClick:b.run,className:W(b.danger&&"text-destructive focus:text-destructive"),children:[b.label,b.shortcut&&c.jsx(Rf,{children:b.shortcut})]})]},b.key))})]}),!t&&c.jsxs(c.Fragment,{children:[J&&c.jsx($l,{tone:J,className:W("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")}),c.jsxs(Ti,{onOpenChange:a,children:[c.jsx(Ii,{asChild:!0,children:c.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:c.jsx(ja,{})})}),c.jsx(Ar,{side:"right",align:"start",className:"w-44",children:X.map(b=>c.jsxs(je.Fragment,{children:[b.separatorBefore&&c.jsx(Fn,{}),c.jsxs($t,{onClick:b.run,className:W(b.danger&&"text-destructive focus:text-destructive"),children:[b.label,b.shortcut&&c.jsx($f,{children:b.shortcut})]})]},b.key))})]})]}),c.jsx(ct,{open:l,onOpenChange:u,children:c.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:b=>{var G;b.preventDefault(),(G=r.current)==null||G.focus()},children:c.jsx(Dn,{mode:"update",shouldReset:!l,postSubmit:M,selectedName:e.name})})}),c.jsx(ct,{open:d,onOpenChange:f,children:c.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:b=>{var G;b.preventDefault(),(G=r.current)==null||G.focus()},children:c.jsx(Dn,{mode:"delete",shouldReset:!d,postSubmit:D,selectedName:e.name})})})]})}const Br=je.memo(Eb);function Cb(e,t=!1){const n=e.length;let r=0,i="",s=0,o=16,a=0,l=0,u=0,d=0,f=0;function h(m,A){let C=0,v=0;for(;C<m;){let w=e.charCodeAt(r);if(w>=48&&w<=57)v=v*16+w-48;else if(w>=65&&w<=70)v=v*16+w-65+10;else if(w>=97&&w<=102)v=v*16+w-97+10;else break;r++,C++}return C<m&&(v=-1),v}function p(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&&Wn(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Wn(e.charCodeAt(r)))for(r++;r<e.length&&Wn(e.charCodeAt(r));)r++;else return f=3,e.substring(m,r);let A=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&Wn(e.charCodeAt(r))){for(r++;r<e.length&&Wn(e.charCodeAt(r));)r++;A=r}else f=3;return e.substring(m,A)}function k(){let m="",A=r;for(;;){if(r>=n){m+=e.substring(A,r),f=2;break}const C=e.charCodeAt(r);if(C===34){m+=e.substring(A,r),r++;break}if(C===92){if(m+=e.substring(A,r),r++,r>=n){f=2;break}switch(e.charCodeAt(r++)){case 34:m+='"';break;case 92:m+="\\";break;case 47:m+="/";break;case 98:m+="\b";break;case 102:m+="\f";break;case 110:m+=`
148
- `;break;case 114:m+="\r";break;case 116:m+=" ";break;case 117:const w=h(4);w>=0?m+=String.fromCharCode(w):f=4;break;default:f=5}A=r;continue}if(C>=0&&C<=31)if(Vr(C)){m+=e.substring(A,r),f=2;break}else f=6;r++}return m}function S(){if(i="",f=0,s=r,l=a,d=u,r>=n)return s=n,o=17;let m=e.charCodeAt(r);if(oo(m)){do r++,i+=String.fromCharCode(m),m=e.charCodeAt(r);while(oo(m));return o=15}if(Vr(m))return r++,i+=String.fromCharCode(m),m===13&&e.charCodeAt(r)===10&&(r++,i+=`
149
- `),a++,u=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=k(),o=10;case 47:const A=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!Vr(e.charCodeAt(r));)r++;return i=e.substring(A,r),o=12}if(e.charCodeAt(r+1)===42){r+=2;const C=n-1;let v=!1;for(;r<C;){const w=e.charCodeAt(r);if(w===42&&e.charCodeAt(r+1)===47){r+=2,v=!0;break}r++,Vr(w)&&(w===13&&e.charCodeAt(r)===10&&r++,a++,u=r)}return v||(r++,f=1),i=e.substring(A,r),o=13}return i+=String.fromCharCode(m),r++,o=16;case 45:if(i+=String.fromCharCode(m),r++,r===n||!Wn(e.charCodeAt(r)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=g(),o=11;default:for(;r<n&&y(m);)r++,m=e.charCodeAt(r);if(s!==r){switch(i=e.substring(s,r),i){case"true":return o=8;case"false":return o=9;case"null":return o=7}return o=16}return i+=String.fromCharCode(m),r++,o=16}}function y(m){if(oo(m)||Vr(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:p,getPosition:()=>r,scan:t?j:S,getToken:()=>o,getTokenValue:()=>i,getTokenOffset:()=>s,getTokenLength:()=>r-s,getTokenStartLine:()=>l,getTokenStartCharacter:()=>s-d,getTokenError:()=>f}}function oo(e){return e===32||e===9}function Vr(e){return e===10||e===13}function Wn(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 qn=200;new Array(qn).fill(0).map((e,t)=>`
150
- `+" ".repeat(t)),new Array(qn).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(qn).fill(0).map((e,t)=>`\r
151
- `+" ".repeat(t)),new Array(qn).fill(0).map((e,t)=>`
152
- `+" ".repeat(t)),new Array(qn).fill(0).map((e,t)=>"\r"+" ".repeat(t)),new Array(qn).fill(0).map((e,t)=>`\r
153
- `+" ".repeat(t));var ls;(function(e){e.DEFAULT={allowTrailingComma:!1}})(ls||(ls={}));function Tb(e,t=[],n=ls.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,u,d)=>{r=s({type:"property",offset:u,length:-1,parent:r,children:[]}),r.children.push({type:"string",value:l,offset:u,length:d,parent:r})},onObjectEnd:(l,u)=>{i(l+u),r.length=l+u-r.offset,r=r.parent,i(l+u)},onArrayBegin:(l,u)=>{r=s({type:"array",offset:l,length:-1,parent:r,children:[]})},onArrayEnd:(l,u)=>{r.length=l+u-r.offset,r=r.parent,i(l+u)},onLiteralValue:(l,u,d)=>{s({type:zb(l),offset:u,length:d,parent:r,value:l}),i(u+d)},onSeparator:(l,u,d)=>{r.type==="property"&&(l===":"?r.colonOffset=u:l===","&&i(u))},onError:(l,u,d)=>{t.push({error:l,offset:u,length:d})}},n);const a=r.children[0];return a&&delete a.parent,a}function Ib(e,t){if(!e)return;let n=e;for(let r of t)if(typeof r=="string"){if(n.type!=="object"||!Array.isArray(n.children))return;let i=!1;for(const s of n.children)if(Array.isArray(s.children)&&s.children[0].value===r&&s.children.length===2){n=s.children[1],i=!0;break}if(!i)return}else{const i=r;if(n.type!=="array"||i<0||!Array.isArray(n.children)||i>=n.children.length)return;n=n.children[i]}return n}function Ab(e,t,n=ls.DEFAULT){const r=Cb(e,!1),i=[];let s=0;function o(z){return z?()=>s===0&&z(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function a(z){return z?M=>s===0&&z(M,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function l(z){return z?M=>s===0&&z(M,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function u(z){return z?()=>{s>0?s++:z(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(s=1)}:()=>!0}function d(z){return z?()=>{s>0&&s--,s===0&&z(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}const f=u(t.onObjectBegin),h=l(t.onObjectProperty),p=d(t.onObjectEnd),g=u(t.onArrayBegin),k=d(t.onArrayEnd),S=l(t.onLiteralValue),y=a(t.onSeparator),j=o(t.onComment),m=a(t.onError),A=n&&n.disallowComments,C=n&&n.allowTrailingComma;function v(){for(;;){const z=r.scan();switch(r.getTokenError()){case 4:w(14);break;case 5:w(15);break;case 3:w(13);break;case 1:A||w(11);break;case 2:w(12);break;case 6:w(16);break}switch(z){case 12:case 13:A?w(10):j();break;case 16:w(1);break;case 15:case 14:break;default:return z}}}function w(z,M=[],D=[]){if(m(z),M.length+D.length>0){let J=r.getToken();for(;J!==17;){if(M.indexOf(J)!==-1){v();break}else if(D.indexOf(J)!==-1)break;J=v()}}}function O(z){const M=r.getTokenValue();return z?S(M):(h(M),i.push(M)),v(),!0}function B(){switch(r.getToken()){case 11:const z=r.getTokenValue();let M=Number(z);isNaN(M)&&(w(2),M=0),S(M);break;case 7:S(null);break;case 8:S(!0);break;case 9:S(!1);break;default:return!1}return v(),!0}function N(){return r.getToken()!==10?(w(3,[],[2,5]),!1):(O(!1),r.getToken()===6?(y(":"),v(),F()||w(4,[],[2,5])):w(5,[],[2,5]),i.pop(),!0)}function R(){f(),v();let z=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(z||w(4,[],[]),y(","),v(),r.getToken()===2&&C)break}else z&&w(6,[],[]);N()||w(4,[],[2,5]),z=!0}return p(),r.getToken()!==2?w(7,[2],[]):v(),!0}function T(){g(),v();let z=!0,M=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(M||w(4,[],[]),y(","),v(),r.getToken()===4&&C)break}else M&&w(6,[],[]);z?(i.push(0),z=!1):i[i.length-1]++,F()||w(4,[],[4,5]),M=!0}return k(),z||i.pop(),r.getToken()!==4?w(8,[4],[]):v(),!0}function F(){switch(r.getToken()){case 3:return T();case 1:return R();case 10:return O(!0);default:return B()}}return v(),r.getToken()===17?n.allowEmptyContent?!0:(w(4,[],[]),!1):F()?(r.getToken()!==17&&w(9,[],[]),!0):(w(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 Fl;(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"})(Fl||(Fl={}));var Ll;(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"})(Ll||(Ll={}));const Ob=Tb,AO=Ib;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 ot(e){return(e==null?void 0:e.type)==="string"&&typeof e.value=="string"?e.value:void 0}function Yo(e){return(e==null?void 0:e.type)==="number"&&typeof e.value=="number"?e.value:void 0}function It(e){return(e==null?void 0:e.type)==="array"&&e.children?e.children:[]}function St(e,t=Pb,n=!1){const r=e.replace(Db,"…"),i=n?r.replace(/\s*\n\s*/g," ").trim():r.split(`
154
- `)[0].trim();return i.length>t?`${i.slice(0,t-1)}…`:i}function Rb(e){const t=It(Ae(e,"columns"));if(t.length>0)return`${Math.max(0,...t.map(i=>It(Ae(i,"cells")).length))}×${t.length}`;const n=It(Ae(e,"rows"));if(n.length>0){const r=n[0],i=(r==null?void 0:r.type)==="array"?It(r).length:It(Ae(r,"cells")).length;return i>0?`${n.length}×${i}`:`${n.length} rows`}}function $b(e){const t=ot(Ae(e,"alt"));if(t)return St(t);const n=ot(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 St(r,40)}return"image"}function Mb(e,t){var r;const n=ot(Ae(t,"text"));switch(e){case"heading":{const i=Yo(Ae(t,"level"))??1;return{label:n?St(n):"heading",detail:`H${i}`}}case"text":return{label:n?St(n):"text",detail:ot(Ae(t,"style"))};case"paragraph":return{label:n?St(n):"paragraph"};case"chart":case"highcharts":{const i=ot(Ae(t,"title"))??ot(Ae(Ae(t,"options"),"title"));return{label:i?St(i):e,detail:ot(Ae(t,"type"))}}case"table":return{label:"table",detail:Rb(t)};case"image":return{label:$b(t)};case"shape":return{label:ot(Ae(t,"type"))??"shape"};case"list":{const i=It(Ae(t,"items"));return{label:"list",detail:i.length>0?`${i.length} items`:void 0}}case"section":{const i=ot(Ae(Ae(t,"meta"),"title"))??ot(Ae(t,"title"));return{label:i?St(i):"section"}}case"statistic":{const i=ot(Ae(t,"value"))??((r=Yo(Ae(t,"value")))==null?void 0:r.toString()),s=ot(Ae(t,"label"));return{label:St(s??i??"statistic"),detail:i}}default:return{label:n?St(n):e}}}function kr(e){if(e.type!=="object")return null;const t=ot(Ae(e,"name"));return t?{name:t,props:Ae(e,"props"),childrenArr:Ae(e,"children")}:null}function Fb(e){let t;for(const n of It(e)){const r=kr(n);if(!r)continue;const i=ot(Ae(r.props,"text"));if(i){if(r.name==="heading"||r.name==="text")return St(i,48);r.name==="paragraph"&&t===void 0&&(t=St(i,48))}}return t}function cs(e,t,n){let{label:r,detail:i}=Mb(t.name,t.props);return r===t.name&&t.childrenArr&&(r=Fb(t.childrenArr)??r),{id:"",kind:t.name,label:r,detail:i,start:e.offset,end:e.offset+e.length,children:Kf(t.childrenArr),reorder:n}}function Kf(e){if(!e||e.type!=="array")return[];const t=`arr@${e.offset}`,n=[];for(const r of It(e)){const i=kr(r);i&&n.push(cs(r,i,{groupId:t,sliceStart:r.offset,sliceEnd:r.offset+r.length}))}return n}function Lb(e){const t=Ae(e,"props"),n=ot(Ae(Ae(t,"meta"),"title"));if(n)return St(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,u]=a.children,d=typeof(l==null?void 0:l.value)=="string"?l.value:"",f=u?kr(u):null,h=f?ot(Ae(f.props,"text")):void 0;i(d==="title"?0:d==="subtitle"||d.startsWith("heading")?1:2,h)}const o=(a,l)=>{const u=kr(a);if(u){if(u.name==="text"||u.name==="heading"){const d=ot(Ae(u.props,"text"));if(d){const f=ot(Ae(u.props,"style"))??"";i(f==="title"?0:f.startsWith("heading")?1:2,d)}}if(l<1)for(const d of It(u.childrenArr))o(d,l+1)}};for(const a of It(Ae(e,"children")))o(a,0);return r?St(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 It(t)){const o=kr(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:Lb(s)??`Slide ${i}`,detail:`${i}`,start:s.offset,end:s.offset+s.length,children:Kf(o.childrenArr),reorder:a})):r.push(cs(s,o,a))}return r}function Vb(e){const t=Ae(e,"children");if(!t||t.type!=="array")return[];const n=`arr@${t.offset}`,r=[],i=[];for(const o of It(t)){const a=kr(o);if(!a)continue;const l={groupId:n,sliceStart:o.offset,sliceEnd:o.offset+o.length},u=()=>i.length?i[i.length-1].node.children:r;if(a.name==="heading"){const d=Yo(Ae(a.props,"level"))??1;for(;i.length&&i[i.length-1].level>=d;)i.pop();const f=cs(o,a,l);u().push(f),i.push({level:d,node:f})}else u().push(cs(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 Vl(e){switch(e.type){case"string":return St(String(e.value??""),24);case"number":case"boolean":return String(e.value);case"array":return`${It(e).length} items`;case"object":return;default:return}}function Zb(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,u]=a.children,d=typeof(l==null?void 0:l.value)=="string"?l.value:void 0;!d||!u||o.push({id:"",kind:"key",label:d,detail:Vl(u),start:a.offset,end:a.offset+a.length,children:[]})}t.push({id:"",kind:"key",label:s,detail:o.length===0?Vl(i):void 0,start:n.offset,end:n.offset+n.length,children:o})}return t}function Zl(e,t,n){if(!e.trim())return[];const r=Ob(e,[],{allowTrailingComma:!0});if(!r)return[];const i=n==="theme"?Zb(r):t==="pptx"?Bb(r):Vb(r);return Yf(i,""),i}function Yf(e,t){e.forEach((n,r)=>{n.id=t?`${t}.${r}`:`${r}`,Yf(n.children,n.id)})}function Xf(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 Xf(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 u="";return l.forEach((d,f)=>{u+=o[d],f<a.length&&(u+=a[f])}),{start:i[0].sliceStart,end:i[i.length-1].sliceEnd,text:u}}const Hb={slide:yx,heading:xx,text:Ro,paragraph:gx,chart:Mo,highcharts:Mo,table:mx,image:hx,shape:tf,list:px,toc:fx,section:$o,columns:$o,"text-box":Ro,statistic:dx,key:ns};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}=ke(Na(w=>({activeTab:w.activeTab,documentTypes:w.documentTypes}))),n=ke(w=>{var O;return w.activeTab?(O=w.documents.find(B=>B.name===w.activeTab))==null?void 0:O.text:void 0}),r=lf(w=>e?w.editors.get(e)??null:null),i=e&&t[e]==="application/json+theme"?"theme":"document",[s,o]=x.useState([]),[a,l]=x.useState(null),[u,d]=x.useState(()=>new Set),[f,h]=x.useState(()=>new Set),[p,g]=x.useState(null),k=x.useRef(s);k.current=s;const S=x.useRef(null),y=x.useRef(null),j=x.useCallback(()=>{var B;if(!e){o([]);return}const w=((B=r==null?void 0:r.editor.getModel())==null?void 0:B.getValue())??n??"",O=Zl(w,at,i);if(o(O),y.current!==e){y.current=e;const N=new Set;if(i==="document"&&at==="docx")for(const R of O)R.kind==="heading"&&N.add(R.id);h(N),l(null)}},[e,r,n,i]);x.useEffect(()=>{j();const w=r==null?void 0:r.editor.getModel();if(!w)return;const O=kl(j,300),B=w.onDidChangeContent(()=>O());return()=>{O.cancel(),B.dispose()}},[j,r]),x.useEffect(()=>{if(!r)return;const{editor:w}=r,O=kl(()=>{const N=w.getModel(),R=w.getPosition();if(!N||!R)return;const T=N.getOffsetAt(R),F=Xf(k.current,T);if(F.length===0){l(null);return}l(F[F.length-1]);const z=F.slice(0,-1);z.length&&h(M=>{if(z.every(J=>M.has(J)))return M;const D=new Set(M);for(const J of z)D.add(J);return D})},150),B=w.onDidChangeCursorPosition(()=>O());return()=>{O.cancel(),B.dispose()}},[r]),x.useEffect(()=>{if(!a||!S.current)return;const w=S.current.querySelector(`[data-oid="${CSS.escape(a)}"]`);w==null||w.scrollIntoView({block:"nearest"})},[a]),x.useEffect(()=>{if(!r){d(new Set);return}const{editor:w,monaco:O}=r,B=()=>{const R=w.getModel();if(!R)return;const T=O.editor.getModelMarkers({resource:R.uri}).filter(F=>F.severity===O.MarkerSeverity.Error).map(F=>R.getOffsetAt({lineNumber:F.startLineNumber,column:F.startColumn}));d(Ub(k.current,T))};B();const N=O.editor.onDidChangeMarkers(R=>{const T=w.getModel();T&&R.some(F=>F.toString()===T.uri.toString())&&B()});return()=>N.dispose()},[r,s]);const m=x.useCallback(w=>{h(O=>{const B=new Set(O);return B.has(w)?B.delete(w):B.add(w),B})},[]),A=x.useCallback(w=>{if(l(w.id),!r)return;const{editor:O,monaco:B}=r,N=O.getModel();if(!N)return;const R=N.getPositionAt(w.start),T=N.getPositionAt(w.end),F=new B.Range(R.lineNumber,R.column,T.lineNumber,T.column);O.revealRangeNearTopIfOutsideViewport(F,B.editor.ScrollType.Smooth),O.setPosition(R),O.focus();const z=O.deltaDecorations([],[{range:F,options:{className:"jto-outline-flash"}}]);window.setTimeout(()=>O.deltaDecorations(z,[]),700)},[r]),C=x.useCallback(w=>{var ye;if(!r||!w.overId)return;const{editor:O,monaco:B,collapse:N}=r,R=O.getModel();if(!R)return;const T=R.getValue(),F=Zl(T,at,i),z=w.parentId?((ye=Wb(F,w.parentId))==null?void 0:ye.children)??[]:F,M=z.findIndex(ce=>ce.id===w.dragId),D=z.findIndex(ce=>ce.id===w.overId);if(M===-1||D===-1)return;let J=D+(w.overHalf==="after"?1:0);M<J&&(J-=1);const Z=Jb(T,z,M,J);if(!Z)return;const X=R.getPositionAt(Z.start),_=R.getPositionAt(Z.end);O.executeEdits("outline-reorder",[{range:new B.Range(X.lineNumber,X.column,_.lineNumber,_.column),text:Z.text}]),N==null||N.resyncDecorations()},[r,i]),v=x.useMemo(()=>{const w=[],O=(B,N,R)=>{var z,M;const T=(M=(z=B[0])==null?void 0:z.reorder)==null?void 0:M.groupId,F=B.length>1&&T!==void 0&&B.every(D=>{var J;return((J=D.reorder)==null?void 0:J.groupId)===T});B.forEach(D=>{const J=Hb[D.kind]??bx,Z=D.children.length>0,X=f.has(D.id),_=a===D.id,ye=(p==null?void 0:p.overId)===D.id;w.push(c.jsxs("div",{"data-oid":D.id,role:"treeitem","aria-selected":_,"aria-expanded":Z?X:void 0,tabIndex:0,draggable:F,onClick:()=>A(D),onKeyDown:ce=>{(ce.key==="Enter"||ce.key===" ")&&(ce.preventDefault(),A(D)),ce.key==="ArrowRight"&&Z&&!X&&m(D.id),ce.key==="ArrowLeft"&&Z&&X&&m(D.id)},onDragStart:ce=>{ce.dataTransfer.setData("text/plain",D.id),ce.dataTransfer.effectAllowed="move",g({dragId:D.id,parentId:R,overId:null,overHalf:"before"})},onDragOver:ce=>{if(!p||p.dragId===D.id||qb(p.dragId)!==R)return;ce.preventDefault(),ce.dataTransfer.dropEffect="move";const b=ce.currentTarget.getBoundingClientRect(),G=ce.clientY<b.top+b.height/2?"before":"after";(p.overId!==D.id||p.overHalf!==G)&&g({...p,overId:D.id,overHalf:G})},onDrop:ce=>{ce.preventDefault(),p&&C({...p,overId:D.id,overHalf:p.overHalf}),g(null)},onDragEnd:()=>g(null),className:W("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",_&&"bg-sidebar-accent font-medium text-sidebar-foreground",ye&&(p==null?void 0:p.overHalf)==="before"&&"shadow-[inset_0_2px_0_hsl(var(--ring))]",ye&&(p==null?void 0:p.overHalf)==="after"&&"shadow-[inset_0_-2px_0_hsl(var(--ring))]"),style:{paddingLeft:4+N*12},children:[Z?c.jsx("span",{role:"button","aria-label":X?"Collapse":"Expand",onClick:ce=>{ce.stopPropagation(),m(D.id)},className:"flex size-3.5 shrink-0 items-center justify-center rounded-xs text-sidebar-foreground/55 hover:text-sidebar-foreground",children:c.jsx(Ir,{className:W("size-3 transition-transform",X&&"rotate-90")})}):c.jsx("span",{className:"size-3.5 shrink-0"}),D.kind==="slide"&&c.jsx("span",{className:"w-3 shrink-0 text-right text-[10px] tabular-nums text-sidebar-foreground/50",children:D.detail}),c.jsx(J,{className:"size-3.5 shrink-0 text-sidebar-foreground/55"}),c.jsx("span",{className:"min-w-0 flex-1 truncate",children:D.label}),D.kind!=="slide"&&D.detail&&c.jsx("span",{className:"shrink-0 text-[10px] text-sidebar-foreground/50",children:D.detail}),u.has(D.id)&&c.jsx("span",{"aria-label":"Contains validation errors",className:"bg-destructive size-1.5 shrink-0 rounded-full"})]},D.id)),Z&&X&&O(D.children,N+1,D.id)})};return O(s,0,""),w},[s,f,a,u,p,A,m,C]);return!e||s.length===0?null:c.jsx("li",{className:"list-none",children:c.jsx("div",{ref:S,role:"tree","aria-label":`Outline of ${e}`,className:"border-sidebar-border/70 my-0.5 ml-[15px] max-h-[38vh] overflow-y-auto border-l pl-1",children:v})})}const Ul=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 hi=x.forwardRef(({className:e,children:t,...n},r)=>c.jsxs(Hd,{ref:r,className:W("relative overflow-hidden",e),...n,children:[c.jsx(tx,{className:"h-full w-full rounded-[inherit]",children:t}),c.jsx(Qf,{}),c.jsx(nx,{})]}));hi.displayName=Hd.displayName;const Qf=x.forwardRef(({className:e,orientation:t="vertical",...n},r)=>c.jsx(Wd,{ref:r,orientation:t,className:W("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:c.jsx(rx,{className:"bg-border relative flex-1 rounded-full"})}));Qf.displayName=Wd.displayName;function Fa({className:e,...t}){return c.jsx(ix,{"data-slot":"switch",className:W("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:c.jsx(sx,{"data-slot":"switch-thumb",className:W("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 Yb=Ei("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"}}),ur=x.forwardRef(({className:e,variant:t,...n},r)=>c.jsx("div",{ref:r,role:"alert",className:W(Yb({variant:t}),e),...n}));ur.displayName="Alert";const Xb=x.forwardRef(({className:e,...t},n)=>c.jsx("h5",{ref:n,className:W("mb-1 font-medium leading-none tracking-tight",e),...t}));Xb.displayName="AlertTitle";const dr=x.forwardRef(({className:e,...t},n)=>c.jsx("div",{ref:n,className:W("text-sm [&_p]:leading-relaxed",e),...t}));dr.displayName="AlertDescription";const us=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),u=()=>t===null?c.jsx("span",{className:"text-muted-foreground",children:"null"}):t===void 0?c.jsx("span",{className:"text-muted-foreground",children:"undefined"}):typeof t=="boolean"?c.jsx("span",{className:"text-warning",children:String(t)}):typeof t=="number"?c.jsx("span",{className:"text-success",children:t}):typeof t=="string"?t.startsWith("http")?c.jsxs("span",{className:"text-data-blue",children:['"',t,'"']}):t.startsWith("#/")?c.jsxs("span",{className:"text-warning",children:['"',t,'"']}):c.jsxs("span",{className:"text-destructive",children:['"',t,'"']}):null,d=o?Object.keys(t).length:0;return c.jsxs("div",{className:W("text-sm",n>0&&"ml-4"),children:[c.jsxs("div",{className:"flex items-start hover:bg-muted/30 rounded-sm px-1 py-0.5",children:[o&&c.jsx("button",{onClick:l,className:"mr-1 hover:bg-muted rounded-sm p-0.5","aria-label":i?"Collapse":"Expand",children:i?c.jsx(Ni,{className:"h-3 w-3"}):c.jsx(Ir,{className:"h-3 w-3"})}),!o&&c.jsx("span",{className:"w-4"}),e&&c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"text-data-blue",children:['"',e,'"']}),c.jsx("span",{className:"mx-1",children:":"})]}),o?c.jsxs("span",{className:"text-muted-foreground",children:[a?"[":"{",!i&&c.jsxs("span",{className:"mx-1 text-xs",children:[d," ",a?"items":"properties"]}),!i&&(a?"]":"}")]}):u(),!o&&!r&&c.jsx("span",{className:"text-muted-foreground",children:","})]}),o&&i&&c.jsxs("div",{className:"ml-4",children:[a?t.map((f,h)=>c.jsx(us,{keyName:String(h),value:f,depth:n+1,isLast:h===t.length-1},h)):Object.entries(t).map(([f,h],p,g)=>c.jsx(us,{keyName:f,value:h,depth:n+1,isLast:p===g.length-1},f)),c.jsx("div",{className:"ml-4",children:c.jsxs("span",{className:"text-muted-foreground",children:[a?"]":"}",!r&&","]})})]})]})});us.displayName="JsonNode";const ds=x.memo(({schema:e,loading:t=!1,error:n,className:r})=>t?c.jsxs("div",{className:W("space-y-4",r),children:[c.jsx(si,{className:"h-8 w-64"}),c.jsx(si,{className:"h-4 w-full"}),c.jsx(si,{className:"h-64 w-full"})]}):n?c.jsx(ur,{variant:"destructive",className:r,children:c.jsx(dr,{children:n})}):e?c.jsx(hi,{className:W("h-full w-full rounded-md border bg-muted/10 p-4",r),children:c.jsx("div",{className:"font-mono text-xs",children:c.jsx(us,{value:e})})}):c.jsx(ur,{className:r,children:c.jsx(dr,{children:"No schema available"})}));ds.displayName="SchemaViewer";function Qb({plugins:e,initialFocusedPlugin:t}){var m,A;const n=Jt(C=>C.togglePlugin),r=Jt(C=>C.isPluginSelected),i=Jt(C=>C.selectedPlugins),s=Jt(C=>C.isApplyingPlugins),[o,a]=x.useState(null),[l,u]=x.useState(null),[d,f]=x.useState("properties");x.useEffect(()=>{if(t){const C=e.find(v=>v.name===t);if(C){a(C);return}}e.length>0&&!o&&a(e[0])},[t,e]);const h=x.useMemo(()=>{const C={current:[],downstream:[],upstream:[]};return e.forEach(v=>{C[v.location]&&C[v.location].push(v)}),C},[e]),p=async(C,v)=>{o&&(await Kb(o.name,C.props),u(v),setTimeout(()=>u(null),2e3))},g=C=>{switch(C){case"current":return"Current Directory";case"downstream":return"Project";case"upstream":return"Parent Directories";default:return C}},k=C=>{switch(C){case"current":return c.jsx(_x,{className:"size-3"});case"downstream":return c.jsx(jx,{className:"size-3"});case"upstream":return c.jsx(ef,{className:"size-3"});default:return null}},S=((m=o==null?void 0:o.schema)==null?void 0:m.properties)&&Object.keys(o.schema.properties).length>0,y=(A=o==null?void 0:o.schema)==null?void 0:A.jsonSchema,j=(o==null?void 0:o.examples)&&o.examples.length>0;return c.jsxs(c.Fragment,{children:[c.jsxs(qt,{children:[c.jsxs(Gt,{className:"flex items-center gap-2",children:[c.jsx(vx,{className:"size-5 text-warning"}),"Plugins",c.jsxs(tn,{variant:"secondary",className:"font-normal",children:[i.size," active"]})]}),c.jsxs(dn,{children:[e.length," plugin",e.length!==1?"s":""," discovered in your project"]})]}),c.jsxs("div",{className:"mt-3 flex gap-0 h-[600px] border rounded-lg overflow-hidden",children:[c.jsx("div",{className:"w-[240px] flex-none border-r bg-muted/30",children:c.jsx(hi,{className:"h-full",children:c.jsx("div",{className:"p-2 space-y-3",children:Object.entries(h).map(([C,v])=>v.length===0?null:c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:[k(C),g(C)]}),c.jsx("div",{className:"space-y-0.5",children:v.map(w=>{const O=r(w.name),B=(o==null?void 0:o.name)===w.name;return c.jsxs("button",{onClick:()=>a(w),className:W("w-full text-left px-2 py-1.5 rounded-md transition-colors cursor-pointer","flex items-center gap-2",B?"bg-accent text-accent-foreground":"hover:bg-accent/50 text-foreground"),children:[c.jsx("div",{className:W("size-1.5 rounded-full flex-none transition-colors",O?"bg-warning":"bg-muted-foreground/30")}),c.jsx("span",{className:"text-sm font-medium truncate flex-1",children:w.name})]},w.name)})})]},C))})})}),o?c.jsxs("div",{className:"flex-1 flex flex-col min-w-0",children:[c.jsxs("div",{className:"flex-none px-5 py-4 border-b bg-background",children:[c.jsxs("div",{className:"flex items-start justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2.5",children:[c.jsx("h3",{className:"text-base font-semibold truncate",children:o.name}),o.version&&c.jsxs(tn,{variant:"outline",className:"font-mono text-[11px] flex-none",children:["v",o.version]})]}),o.description&&c.jsx("p",{className:"text-sm text-muted-foreground mt-1 line-clamp-2",children:o.description})]}),c.jsxs("div",{className:"flex items-center gap-2 flex-none pt-0.5",children:[c.jsx("span",{className:"text-xs text-muted-foreground",children:r(o.name)?"On":"Off"}),c.jsx(Fa,{checked:r(o.name),onCheckedChange:()=>n(o),disabled:s,"aria-label":`Toggle ${o.name}`})]})]}),c.jsxs("div",{className:"flex items-center gap-1.5 mt-2 text-xs text-muted-foreground",children:[k(o.location),c.jsx("span",{children:g(o.location)}),c.jsx("span",{className:"text-muted-foreground/60 mx-1",children:"/"}),c.jsx("span",{className:"font-mono truncate",children:o.relativePath})]})]}),c.jsxs("div",{className:"flex-none px-5 pt-3 pb-0 flex gap-1 border-b bg-background",children:[S&&c.jsx("button",{onClick:()=>f("properties"),className:W("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:c.jsxs("span",{className:"flex items-center gap-1.5",children:[c.jsx(ns,{className:"size-3.5"}),"Properties"]})}),y&&c.jsx("button",{onClick:()=>f("schema"),className:W("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:c.jsxs("span",{className:"flex items-center gap-1.5",children:[c.jsx(wx,{className:"size-3.5"}),"Schema"]})}),j&&c.jsx("button",{onClick:()=>f("examples"),className:W("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:c.jsxs("span",{className:"flex items-center gap-1.5",children:[c.jsx(kx,{className:"size-3.5"}),"Examples",c.jsx(tn,{variant:"secondary",className:"text-[10px] px-1.5 py-0 h-4",children:o.examples.length})]})})]}),c.jsx(hi,{className:"flex-1",children:c.jsxs("div",{className:"p-5",children:[d==="properties"&&S&&c.jsx("div",{className:"space-y-1",children:Object.entries(o.schema.properties).map(([C,v])=>c.jsx(ev,{name:C,prop:v},C))}),d==="schema"&&y&&c.jsx(ds,{schema:o.schema.jsonSchema,loading:!1,className:"h-[420px]"}),d==="examples"&&j&&o.examples.map((C,v)=>c.jsxs("div",{className:W(v>0&&"mt-4 pt-4 border-t"),children:[c.jsxs("div",{className:"flex items-center justify-between mb-2",children:[c.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[C.title&&c.jsx("span",{className:"font-medium text-sm truncate",children:C.title}),!C.title&&c.jsxs("span",{className:"text-sm text-muted-foreground",children:["Example ",v+1]})]}),c.jsx(Ee,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs flex-none",onClick:()=>p(C,v),children:l===v?c.jsxs(c.Fragment,{children:[c.jsx(Sx,{className:"size-3 mr-1 text-success"}),"Copied"]}):c.jsxs(c.Fragment,{children:[c.jsx(zs,{className:"size-3 mr-1"}),"Copy"]})})]}),C.description&&c.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:C.description}),c.jsx("pre",{className:"p-3 bg-muted rounded-md overflow-x-auto text-xs font-mono leading-relaxed",children:JSON.stringify(C.props,null,2)})]},v)),!S&&!y&&!j&&c.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[c.jsx(ns,{className:"size-10 mx-auto mb-3 opacity-20"}),c.jsx("p",{className:"text-sm",children:"No schema or examples available for this plugin"})]})]})})]}):c.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:c.jsx("p",{className:"text-sm",children:"Select a plugin to view details"})})]})]})}function ev({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 c.jsxs("div",{className:"rounded-md border",children:[c.jsxs("button",{onClick:()=>i&&r(!n),className:W("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?c.jsx(Ni,{className:"size-3 text-muted-foreground flex-none"}):c.jsx(Ir,{className:"size-3 text-muted-foreground flex-none"}):c.jsx("span",{className:"size-3 flex-none"}),c.jsx("span",{className:"font-mono font-medium text-xs",children:e}),c.jsx(tn,{variant:"outline",className:"text-[10px] px-1.5 py-0 h-4 flex-none",children:s}),t.optional===!1&&c.jsx("span",{className:"text-[10px] text-destructive font-medium flex-none",children:"required"}),c.jsx("span",{className:"flex-1"}),t.default!==void 0&&c.jsxs("span",{className:"text-[10px] font-mono text-muted-foreground flex-none",children:["= ",JSON.stringify(t.default)]})]}),n&&i&&c.jsxs("div",{className:"px-3 pb-2 pt-0 ml-5 text-xs space-y-1 text-muted-foreground",children:[t.description&&c.jsx("p",{children:t.description}),t.enum&&c.jsxs("p",{children:[c.jsx("span",{className:"font-medium text-foreground",children:"Values: "}),t.enum.map((a,l)=>c.jsxs("span",{children:[l>0&&", ",c.jsx("code",{className:"bg-muted px-1 rounded-sm",children:JSON.stringify(a)})]},l))]}),((o=t.items)==null?void 0:o.type)&&c.jsxs("p",{children:[c.jsx("span",{className:"font-medium text-foreground",children:"Items: "}),t.items.type]})]})]})}const tv={current:"Current directory",downstream:"Project"};function Jl({location:e}){return c.jsx("li",{className:"list-none px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:tv[e]??e})}function Hl({name:e,subtitle:t,query:n,onSelect:r}){return c.jsx("li",{className:"list-none",children:c.jsxs("button",{type:"button",onClick:r,title:t?`${e} — ${t}`:e,"aria-label":`Add ${e} to workspace`,className:W("group/row flex h-7 w-full cursor-pointer items-center gap-2 rounded-sm pr-1 pl-2","text-[13px] text-sidebar-foreground/70 transition-colors","hover:bg-sidebar-accent/60 hover:text-sidebar-foreground","focus-visible:ring-sidebar-ring focus-visible:ring-1 focus-visible:outline-none"),children:[c.jsx("span",{className:"min-w-0 flex-1 truncate text-left",children:c.jsx(Rs,{text:e,query:n})}),c.jsx(Dt,{"aria-hidden":!0,className:"size-3.5 shrink-0 text-sidebar-foreground/45 opacity-0 transition-opacity group-hover/row:opacity-100 group-focus-visible/row:opacity-100"})]})})}function Wl({children:e}){return c.jsx("div",{className:"px-2 pt-2 pb-0.5 text-[10px] tracking-[0.08em] text-sidebar-foreground/65 uppercase",children:e})}function nv({document:e,query:t}){var B;const n=x.useRef(null),[r,i]=x.useState(!1),[s,o]=x.useState(!1),[a,l]=x.useState(!1),[u,d]=x.useState(!1),f=ke(N=>N.openDocument),h=ke(N=>N.activeTab),p=vn(N=>N.records[e.name]),g=vn(N=>N.setEnabled),k=h===e.name,S=(p==null?void 0:p.enabled)??!0,y=(p==null?void 0:p.status)??"idle",j=(B=p==null?void 0:p.metadata)==null?void 0:B.name,m=((p==null?void 0:p.diagnostics)??[]).filter(N=>N.severity==="error").length,A=y==="ready"?`Ready${j?` — used as "${j}"`:""}`:y==="error"?m>0?`${m} error${m===1?"":"s"} — open to fix`:"Failed to load — open to fix":y==="compiling"?"Compiling…":"Not compiled yet",C=x.useCallback(N=>{g(e.name,N),window.dispatchEvent(new CustomEvent(Sg,{detail:{docName:e.name}}))},[e.name,g]),v=x.useMemo(()=>[{key:"open",label:"Open",run:()=>f(e.name)},{key:"download",label:"Download…",separatorBefore:!0,run:()=>oi(e.name,new Blob([e.text],{type:"text/typescript"}))},{key:"rename",label:"Rename…",separatorBefore:!0,run:()=>l(!0)},{key:"delete",label:"Delete",danger:!0,run:()=>d(!0)}],[e.name,e.text,f]),w=`browser-plugin-${e.name}`,O=r||s;return c.jsxs("li",{className:"group/menu-item relative list-none",children:[c.jsxs(Pf,{onOpenChange:o,children:[c.jsx(Df,{className:"block",children:c.jsxs("div",{className:W("flex h-7 w-full items-center gap-1 rounded-sm pr-1 pl-2 transition-colors","hover:bg-sidebar-accent/60",O&&"bg-sidebar-accent/60",k&&"bg-sidebar-accent font-medium"),title:`${e.name} — ${A}`,children:[k&&c.jsx("span",{"aria-hidden":!0,className:"bg-primary absolute top-1 bottom-1 left-0 w-[2px] rounded-full"}),c.jsxs("button",{ref:n,type:"button",onClick:()=>f(e.name),"aria-label":`${e.name} — ${A}`,className:W("flex h-7 min-w-0 flex-1 cursor-pointer items-center gap-2 text-[13px]","focus-visible:ring-sidebar-ring rounded-sm focus-visible:ring-1 focus-visible:outline-none",S?"text-sidebar-foreground/85":"text-sidebar-foreground/60"),children:[c.jsx(Qd,{className:W("size-3.5 shrink-0",k?"text-sidebar-accent-foreground/70":"text-sidebar-foreground/60")}),c.jsx("span",{className:"truncate",children:c.jsx(Rs,{text:e.name,query:t})}),y==="compiling"&&c.jsx(cn,{size:"sm",className:"shrink-0"}),y==="ready"&&c.jsx(Nx,{"aria-hidden":!0,className:"size-3 shrink-0 text-success"}),y==="error"&&c.jsx(Ex,{"aria-hidden":!0,className:"size-3 shrink-0 text-destructive"})]}),c.jsxs(Ti,{onOpenChange:i,children:[c.jsx(Ii,{asChild:!0,children:c.jsx(Ct,{"aria-label":`Actions for ${e.name}`,className:W("opacity-0 group-hover/menu-item:opacity-100 focus-visible:opacity-100",O&&"opacity-100"),children:c.jsx(ja,{})})}),c.jsx(Ar,{side:"right",align:"start",className:"w-44",children:v.map(N=>c.jsxs(je.Fragment,{children:[N.separatorBefore&&c.jsx(Fn,{}),c.jsx($t,{onClick:N.run,className:W(N.danger&&"text-destructive focus:text-destructive"),children:N.label})]},N.key))})]}),c.jsx(Fa,{id:w,checked:S,onCheckedChange:C,className:"shrink-0","aria-label":`Enable ${e.name}`,title:"On: expanded in every build. Off: a document that names it fails to build until it is switched back on."})]})}),c.jsx(Pa,{className:"w-44",children:v.map(N=>c.jsxs(je.Fragment,{children:[N.separatorBefore&&c.jsx(Ra,{}),c.jsx(Da,{onClick:N.run,className:W(N.danger&&"text-destructive focus:text-destructive"),children:N.label})]},N.key))})]}),c.jsx(ct,{open:a,onOpenChange:l,children:c.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:N=>{var R;N.preventDefault(),(R=n.current)==null||R.focus()},children:c.jsx(Dn,{mode:"update",shouldReset:!a,postSubmit:()=>l(!1),selectedName:e.name,isPlugin:!0})})}),c.jsx(ct,{open:u,onOpenChange:d,children:c.jsx(lt,{className:"sm:max-w-[425px]",onCloseAutoFocus:N=>{var R;N.preventDefault(),(R=n.current)==null||R.focus()},children:c.jsx(Dn,{mode:"delete",shouldReset:!u,postSubmit:()=>d(!1),selectedName:e.name,isPlugin:!0})})})]})}const rv=je.memo(nv);function iv({plugins:e,browserPlugins:t,query:n,open:r,onToggleSection:i,onShowPluginDetails:s,onNewPlugin:o,isPluginSelected:a,onTogglePlugin:l,isApplyingPlugins:u,diskPluginsLoadable:d,activeCount:f,totalCount:h}){const p=e.length>0&&t.length>0;return c.jsxs("section",{className:"border-sidebar-border/70 mt-3 border-t pt-2",children:[c.jsx(Wo,{open:r,onToggle:i,count:h>0?`${f}/${h}`:void 0,actions:c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{"aria-label":"New plugin",onClick:o,children:c.jsx(Dt,{})})}),c.jsx(Qe,{side:"bottom",children:"New plugin"})]}),children:"Plugins"}),r&&c.jsxs("div",{className:"flex flex-col gap-0.5",children:[p&&c.jsx(Wl,{children:"In this browser"}),c.jsx("ul",{className:"flex flex-col gap-0.5",children:t.map(g=>c.jsx(rv,{document:g,query:n},g.name))}),p&&c.jsx(Wl,{children:"On disk"}),e.length>0&&!d&&c.jsxs("p",{className:"text-sidebar-foreground/60 px-2 pt-0.5 pb-1 text-[11px] leading-snug",children:["This server does not load plugins from disk, so these cannot be switched on. Set ",c.jsx("code",{children:"PLUGIN_AUTOLOAD=true"})," on the deployment, or write one in the browser."]}),e.map(g=>{const k=a(g.name)&&d,S=`plugin-switch-${g.filePath||g.name}`;return c.jsxs("div",{title:g.description?`${g.name} — ${g.description}`:g.name,className:W("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:[c.jsx("button",{type:"button",onClick:()=>s(g.name),"aria-label":`Details for ${g.name}`,className:W("flex h-7 min-w-0 flex-1 cursor-pointer items-center text-[13px]","focus-visible:ring-sidebar-ring rounded-sm focus-visible:ring-1 focus-visible:outline-none",k?"text-sidebar-foreground":"text-sidebar-foreground/70"),children:c.jsx("span",{className:"truncate",children:c.jsx(Rs,{text:g.name,query:n})})}),c.jsx(Ct,{"aria-label":`Details for ${g.name}`,onClick:y=>{y.stopPropagation(),s(g.name)},className:"opacity-0 group-hover/row:opacity-100 focus-visible:opacity-100",children:c.jsx(nf,{})}),c.jsx(Fa,{id:S,checked:k,onCheckedChange:()=>l(g),disabled:u||!d,className:"shrink-0","aria-label":`Toggle ${g.name} plugin`,title:d?"On: the server loads this plugin from disk for every build.":"This server does not load plugins from disk (PLUGIN_AUTOLOAD is off)."})]},g.filePath||g.name)}),e.length+t.length===0&&c.jsx(qo,{icon:Dt,label:"New plugin",hint:"Write a custom component in TypeScript, in the browser",onClick:o})]})]})}function ql(e){return x.useMemo(()=>{const t=["current","downstream"],n=new Map;return e.forEach(r=>{const i=n.get(r.location);i?i.push(r):n.set(r.location,[r])}),[...n.entries()].sort(([r],[i])=>t.indexOf(r)-t.indexOf(i))},[e])}function ep({children:e,className:t}){return c.jsx("kbd",{"data-slot":"kbd",className:W("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",t),children:e})}function sv({children:e,className:t}){return c.jsx("span",{className:W("inline-flex items-center gap-0.5",t),children:e})}const Fi=typeof navigator<"u"&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);function mi({shortcut:e,className:t}){const r=e.split("+").map(i=>i.trim().toLowerCase()).map(i=>{switch(i){case"mod":return Fi?"⌘":"Ctrl";case"shift":return Fi?"⇧":"Shift";case"alt":return Fi?"⌥":"Alt";case"ctrl":return Fi?"⌃":"Ctrl";case"enter":return"↵";default:return i.toUpperCase()}});return c.jsx(sv,{className:t,children:r.map((i,s)=>c.jsx(ep,{children:i},s))})}function ov({className:e}={}){const{theme:t,setTheme:n}=hd(),r=t==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":t,i=x.useCallback(()=>{n(r==="dark"?"light":"dark")},[r,n]);return c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsxs(Ee,{variant:"ghost",size:"icon",onClick:i,className:e,children:[c.jsx(Cx,{className:"hidden dark:block"}),c.jsx(Tx,{className:"block dark:hidden"}),c.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),c.jsx(Qe,{children:c.jsx("p",{children:"Toggle theme"})})]})}function av({discoveryData:e,onToggleSidebar:t,isCollapsed:n=!1,isAnimating:r=!1}){const{documents:i,documentTypes:s,createDocument:o,openDocument:a,activeTab:l}=ke(Na($=>({documents:$.documents,documentTypes:$.documentTypes,createDocument:$.createDocument,openDocument:$.openDocument,activeTab:$.activeTab}))),u=Do($=>$.updateTheme),d=Do($=>$.removeTheme),f=x.useContext(ka),[h,p]=x.useState(!1),[g,k]=x.useState(!1),[S,y]=x.useState(!1),[j,m]=x.useState(!1),A=vn($=>fd($).length),[C,v]=x.useState(null),w=Jt($=>$.togglePlugin),O=Jt($=>$.isPluginSelected),B=Jt($=>$.selectedPlugins),N=Jt($=>$.isApplyingPlugins),[R,T]=x.useState(!1),[F,z]=x.useState(new Set(["documents","themes"])),[M,D]=x.useState(""),J=x.useRef(null),{toast:Z}=Cr(),X=i.filter($=>(s[$.name]??"application/json+report")==="application/json+report"),_=i.filter($=>s[$.name]==="application/json+theme"),ye=i.filter($=>s[$.name]==="application/typescript+plugin"),ce=x.useCallback(()=>{p(!1)},[]),b=x.useCallback(()=>{k(!1)},[]),G=x.useCallback(()=>{y(!1),z($=>new Set($).add("plugins"))},[]),ne=x.useRef(new Map);x.useEffect(()=>{const $=ne.current,xe=new Map;_.forEach(de=>{xe.set(de.name,de.text),$.get(de.name)!==de.text&&u(de.name,de.text)}),$.forEach((de,Me)=>{xe.has(Me)||d(Me)}),ne.current=xe},[_,u,d]);const Q=x.useRef(!1);x.useEffect(()=>{if(Q.current||!f)return;Q.current=!0;const $=new Set(_.map(de=>de.name));Object.keys(f.getState().customThemes).forEach(de=>{$.has(de)||d(de)})},[_,d,f]);const oe=x.useCallback($=>{z(xe=>{const de=new Set(xe);return de.has($)?de.delete($):de.add($),de})},[]),{resolvedTheme:I}=hd(),re=I==="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",ae=x.useCallback(async($,xe)=>{if(i.some(de=>de.name===$)){a($);return}try{const de=await fetch(`/api/discovery/${xe?"themes":"documents"}/${encodeURIComponent($)}/content`);if(!de.ok)throw new Error(de.statusText);const Me=await de.text(),Je=JSON.parse(Me);o($,JSON.stringify(Je,null,2),{templateSource:$}),a($),Z({title:`Added ${xe?"theme":"document"}: ${$}`})}catch{Z({title:"Failed to load",description:`Could not load ${$}`,variant:"destructive"})}},[i,o,a,Z]);x.useEffect(()=>{if(n)return;const $=xe=>{var Je,it,Lt,Ot,vl;if(xe.key!=="/"||xe.metaKey||xe.ctrlKey||xe.altKey)return;const de=xe.target,Me=(Je=de==null?void 0:de.tagName)==null?void 0:Je.toLowerCase();Me==="input"||Me==="textarea"||Me==="select"||de!=null&&de.isContentEditable||(it=de==null?void 0:de.closest)!=null&&it.call(de,".monaco-editor")||(Lt=J.current)!=null&&Lt.closest('[aria-hidden="true"], [inert]')||(xe.preventDefault(),(Ot=J.current)==null||Ot.focus(),(vl=J.current)==null||vl.select())};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[n]);const H=M.trim(),K=x.useMemo(()=>new Set(i.map($=>$.name)),[i]),pe=x.useMemo(()=>X.filter($=>on($.name,H)),[X,H]),fe=x.useMemo(()=>_.filter($=>on($.name,H)),[_,H]),Re=x.useMemo(()=>ye.filter($=>on($.name,H)),[ye,H]),Oe=x.useMemo(()=>((e==null?void 0:e.documents)??[]).filter($=>!K.has($.name)&&(on($.name,H)||on($.title??"",H))),[e,H,K]),$e=x.useMemo(()=>((e==null?void 0:e.themes)??[]).filter($=>!K.has($.name)&&(on($.name,H)||on($.description??"",H))),[e,H,K]),E=ql(Oe),P=ql($e),V=(e==null?void 0:e.pluginAutoload)??!0,se=x.useMemo(()=>(V?((e==null?void 0:e.plugins)??[]).filter(xe=>B.has(xe.name)).length:0)+A,[e,B,V,A]),ie=((e==null?void 0:e.plugins.length)??0)+ye.length,ee=x.useMemo(()=>((e==null?void 0:e.plugins)??[]).filter($=>on($.name,H)||on($.description??"",H)),[e,H]),me=$=>H.length>0||F.has($),we=me("documents"),U=me("themes"),Y=pe.length+Oe.length,ge=fe.length+$e.length,_e=H.length>0&&pe.length===0&&fe.length===0&&Re.length===0&&Oe.length===0&&$e.length===0&&ee.length===0,L=W("transition-opacity duration-150 ease-out",r?"opacity-0":"opacity-100");return c.jsxs(c.Fragment,{children:[c.jsxs(Jf,{collapsible:"none",style:{"--sidebar-width":n?"3rem":"16rem"},children:[n?c.jsxs(c.Fragment,{children:[c.jsx(Go,{className:W("gap-0 p-1.5",L),children:c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{className:"mx-auto size-7","aria-label":"Expand sidebar","aria-expanded":!1,onClick:t,children:c.jsx(rf,{})})}),c.jsxs(Qe,{side:"right",className:"flex items-center gap-2",children:[c.jsx("span",{children:"Expand sidebar"}),c.jsx(mi,{shortcut:"mod+b"})]})]})}),c.jsxs(Ko,{className:W("gap-2 px-1 py-1",L),children:[c.jsxs(nr,{className:"items-center gap-0.5",children:[X.map($=>c.jsx(Br,{document:$,compact:!0},$.name)),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{className:"size-7","aria-label":"New document",onClick:()=>p(!0),children:c.jsx(Dt,{})})}),c.jsx(Qe,{side:"right",children:"New document"})]})]}),c.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),c.jsxs(nr,{className:"items-center gap-0.5",children:[_.map($=>c.jsx(Br,{document:$,compact:!0},$.name)),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{className:"size-7","aria-label":"New theme",onClick:()=>k(!0),children:c.jsx(Dt,{})})}),c.jsx(Qe,{side:"right",children:"New theme"})]})]}),c.jsx("div",{className:"bg-sidebar-border/70 mx-auto h-px w-6"}),c.jsxs(nr,{className:"items-center gap-0.5",children:[ye.map($=>c.jsx(Br,{document:$,compact:!0},$.name)),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{className:"size-7","aria-label":"New plugin",onClick:()=>y(!0),children:c.jsx(Dt,{})})}),c.jsx(Qe,{side:"right",children:"New plugin"})]})]})]})]}):c.jsxs(c.Fragment,{children:[c.jsxs(Go,{className:W("gap-0 p-2",L),children:[c.jsxs("div",{className:"flex h-7 items-center justify-between gap-1",children:[c.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:c.jsx("img",{src:re,alt:"Wiseair",className:"h-[18px] w-auto max-w-[110px] shrink-0"})}),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{"aria-label":"Collapse sidebar","aria-expanded":!0,onClick:t,children:c.jsx(Ix,{})})}),c.jsxs(Qe,{side:"right",className:"flex items-center gap-2",children:[c.jsx("span",{children:"Collapse sidebar"}),c.jsx(mi,{shortcut:"mod+b"})]})]})]}),c.jsxs("div",{className:"relative mt-2",children:[c.jsx(Ax,{"aria-hidden":!0,className:"pointer-events-none absolute top-1/2 left-2 size-3.5 -translate-y-1/2 text-sidebar-foreground/40"}),c.jsx("input",{ref:J,type:"text",value:M,spellCheck:!1,autoComplete:"off",placeholder:"Filter files…","aria-label":"Filter documents, themes and plugins",onChange:$=>D($.target.value),onKeyDown:$=>{$.key==="Escape"&&($.preventDefault(),D(""),$.currentTarget.blur())},className:W("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")}),H?c.jsx(Ct,{"aria-label":"Clear filter",onClick:()=>{var $;D(""),($=J.current)==null||$.focus()},className:"absolute top-1/2 right-1 -translate-y-1/2",children:c.jsx(wn,{})}):c.jsx(ep,{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:"/"})]})]}),c.jsx(Ko,{className:W("gap-0 px-2 pb-2",L),children:_e?c.jsxs("div",{className:"px-1 py-6 text-center",children:[c.jsxs("p",{className:"text-[13px] text-sidebar-foreground/70",children:["No files match “",H,"”"]}),c.jsx("button",{type:"button",onClick:()=>{var $;D(""),($=J.current)==null||$.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"})]}):c.jsxs(c.Fragment,{children:[(Y>0||!H)&&c.jsxs("section",{children:[c.jsx(Wo,{open:we,onToggle:()=>oe("documents"),count:Y||void 0,actions:c.jsxs(c.Fragment,{children:[at==="docx"&&c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{"aria-label":"Compare documents",disabled:X.length<2,onClick:()=>T(!0),children:c.jsx(Yd,{})})}),c.jsx(Qe,{side:"bottom",children:X.length<2?"Compare needs two documents":"Compare documents (redline)"})]}),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{"aria-label":"New document",onClick:()=>p(!0),children:c.jsx(Dt,{})})}),c.jsx(Qe,{side:"bottom",children:"New document"})]})]}),children:"Documents"}),we&&c.jsxs(nr,{className:"gap-0.5",children:[pe.map($=>c.jsxs(x.Fragment,{children:[c.jsx(Br,{document:$,query:H}),!H&&l===$.name&&c.jsx(Ul,{})]},$.name)),E.map(([$,xe])=>c.jsxs(x.Fragment,{children:[E.length>1&&c.jsx(Jl,{location:$}),xe.map(de=>c.jsx(Hl,{name:de.name,subtitle:de.title,query:H,onSelect:()=>ae(de.name,!1)},de.path||de.name))]},$)),Y===0&&c.jsx("li",{className:"list-none",children:c.jsx(qo,{icon:Dt,label:"New document",onClick:()=>p(!0)})})]})]}),(ge>0||!H)&&c.jsxs("section",{className:"mt-3",children:[c.jsx(Wo,{open:U,onToggle:()=>oe("themes"),count:ge||void 0,actions:c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ct,{"aria-label":"New theme",onClick:()=>k(!0),children:c.jsx(Dt,{})})}),c.jsx(Qe,{side:"bottom",children:"New theme"})]}),children:"Themes"}),U&&c.jsxs(nr,{className:"gap-0.5",children:[fe.map($=>c.jsxs(x.Fragment,{children:[c.jsx(Br,{document:$,query:H}),!H&&l===$.name&&c.jsx(Ul,{})]},$.name)),P.map(([$,xe])=>c.jsxs(x.Fragment,{children:[P.length>1&&c.jsx(Jl,{location:$}),xe.map(de=>c.jsx(Hl,{name:de.name,subtitle:de.description,query:H,onSelect:()=>ae(de.name,!0)},de.path||de.name))]},$)),ge===0&&c.jsx("li",{className:"list-none",children:c.jsx(qo,{icon:Dt,label:"New theme",onClick:()=>k(!0)})})]})]}),c.jsx(iv,{plugins:ee,browserPlugins:Re,query:H,open:me("plugins"),onToggleSection:()=>oe("plugins"),onShowPluginDetails:$=>{v($),m(!0)},onNewPlugin:()=>y(!0),isPluginSelected:O,onTogglePlugin:w,isApplyingPlugins:N,diskPluginsLoadable:V,activeCount:se,totalCount:ie})]})})]}),c.jsx(Hf,{className:W("border-sidebar-border/70 gap-0 border-t p-1.5",L),children:c.jsx("div",{className:W("flex items-center",n?"justify-center":"justify-start"),children:c.jsx(ov,{className:"size-7 rounded-sm text-sidebar-foreground/70 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground [&_svg]:size-3.5"})})})]}),c.jsx(ct,{open:h,onOpenChange:p,children:c.jsx(lt,{className:"sm:max-w-[525px]",children:c.jsx(Dn,{mode:"create",shouldReset:!h,postSubmit:ce,discoveredDocuments:(e==null?void 0:e.documents)||[]})})}),c.jsx(ct,{open:g,onOpenChange:k,children:c.jsx(lt,{className:"sm:max-w-[525px]",children:c.jsx(Dn,{mode:"create",shouldReset:!g,postSubmit:b,discoveredThemes:(e==null?void 0:e.themes)||[],isTheme:!0})})}),c.jsx(ct,{open:S,onOpenChange:y,children:c.jsx(lt,{className:"sm:max-w-[525px]",children:c.jsx(Dn,{mode:"create",shouldReset:!S,postSubmit:G,discoveredPlugins:(e==null?void 0:e.plugins)||[],isPlugin:!0})})}),c.jsx(ct,{open:j,onOpenChange:$=>{m($),$||v(null)},children:c.jsx(lt,{className:"max-h-[85vh] overflow-hidden sm:max-w-5xl",children:c.jsx(Qb,{plugins:(e==null?void 0:e.plugins)||[],initialFocusedPlugin:C})})}),c.jsx(ly,{open:R,onOpenChange:T})]})}const Gl=x.memo(av),lv=x.lazy(()=>md(()=>import("./editor-D-LgWzQZ.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(e=>({default:e.Editor})));function Kl(){return c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"flex items-center justify-center h-full",children:c.jsxs("div",{className:"text-center",children:[c.jsx(cn,{className:"w-8 h-8 mx-auto mb-2"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading editor..."})]})}),children:c.jsx(lv,{})})}const cv=x.lazy(()=>md(()=>import("./preview-D0HsunpU.js"),__vite__mapDeps([13,1,3,4,5,6,7,8,9,10,12,11])).then(e=>({default:e.Preview})));function Yl(){return c.jsx(x.Suspense,{fallback:c.jsx("div",{className:"flex items-center justify-center h-full",children:c.jsxs("div",{className:"text-center",children:[c.jsx(cn,{className:"w-8 h-8 mx-auto mb-2"}),c.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading preview..."})]})}),children:c.jsx(cv,{})})}const{createElement:Sr,createContext:uv,forwardRef:tp,useCallback:bt,useContext:np,useEffect:Rn,useImperativeHandle:rp,useLayoutEffect:dv,useMemo:fv,useRef:jt,useState:fr}=dd,Xl=dd[`useId${Math.random()}`.slice(0,5)],pv=dv,Ms=uv(null);Ms.displayName="PanelGroupContext";const $n=pv,hv=typeof Xl=="function"?Xl:()=>null;let mv=0;function La(e=null){const t=hv(),n=jt(e||t||null);return n.current===null&&(n.current=""+mv++),e??n.current}function ip({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:i,forwardedRef:s,id:o,maxSize:a,minSize:l,onCollapse:u,onExpand:d,onResize:f,order:h,style:p,tagName:g="div",...k}){const S=np(Ms);if(S===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:j,getPanelSize:m,getPanelStyle:A,groupId:C,isPanelCollapsed:v,reevaluatePanelConstraints:w,registerPanel:O,resizePanel:B,unregisterPanel:N}=S,R=La(o),T=jt({callbacks:{onCollapse:u,onExpand:d,onResize:f},constraints:{collapsedSize:n,collapsible:r,defaultSize:i,maxSize:a,minSize:l},id:R,idIsFromProps:o!==void 0,order:h});jt({didLogMissingDefaultSizeWarning:!1}),$n(()=>{const{callbacks:z,constraints:M}=T.current,D={...M};T.current.id=R,T.current.idIsFromProps=o!==void 0,T.current.order=h,z.onCollapse=u,z.onExpand=d,z.onResize=f,M.collapsedSize=n,M.collapsible=r,M.defaultSize=i,M.maxSize=a,M.minSize=l,(D.collapsedSize!==M.collapsedSize||D.collapsible!==M.collapsible||D.maxSize!==M.maxSize||D.minSize!==M.minSize)&&w(T.current,D)}),$n(()=>{const z=T.current;return O(z),()=>{N(z)}},[h,R,O,N]),rp(s,()=>({collapse:()=>{y(T.current)},expand:z=>{j(T.current,z)},getId(){return R},getSize(){return m(T.current)},isCollapsed(){return v(T.current)},isExpanded(){return!v(T.current)},resize:z=>{B(T.current,z)}}),[y,j,m,v,R,B]);const F=A(T.current,i);return Sr(g,{...k,children:e,className:t,id:o,style:{...F,...p},"data-panel":"","data-panel-collapsible":r||void 0,"data-panel-group-id":C,"data-panel-id":R,"data-panel-size":parseFloat(""+F.flexGrow).toFixed(1)})}const sp=tp((e,t)=>Sr(ip,{...e,forwardedRef:t}));ip.displayName="Panel";sp.displayName="forwardRef(Panel)";let Xo=null,Pn=null;function gv(e,t){if(t){const n=(t&up)!==0,r=(t&dp)!==0,i=(t&fp)!==0,s=(t&pp)!==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 xv(){Pn!==null&&(document.head.removeChild(Pn),Xo=null,Pn=null)}function ao(e,t){const n=gv(e,t);Xo!==n&&(Xo=n,Pn===null&&(Pn=document.createElement("style"),document.head.appendChild(Pn)),Pn.innerHTML=`*{cursor: ${n}!important;}`)}function op(e){return e.type==="keydown"}function ap(e){return e.type.startsWith("pointer")}function lp(e){return e.type.startsWith("mouse")}function Fs(e){if(ap(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(lp(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function yv(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function bv(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 vv(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:tc(e),b:tc(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ce(r,"Stacking order can only be calculated for elements with a common ancestor");const i={a:ec(Ql(n.a)),b:ec(Ql(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 wv=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function kv(e){var t;const n=getComputedStyle((t=cp(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function Sv(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||kv(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"||wv.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Ql(e){let t=e.length;for(;t--;){const n=e[t];if(Ce(n,"Missing node"),Sv(n))return n}return null}function ec(e){return e&&Number(getComputedStyle(e).zIndex)||0}function tc(e){const t=[];for(;e;)t.push(e),e=cp(e);return t}function cp(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const up=1,dp=2,fp=4,pp=8,jv=yv()==="coarse";let Ht=[],pr=!1,yn=new Map,Ls=new Map;const gi=new Set;function _v(e,t,n,r,i){var s;const{ownerDocument:o}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:i},l=(s=yn.get(o))!==null&&s!==void 0?s:0;return yn.set(o,l+1),gi.add(a),fs(),function(){var d;Ls.delete(e),gi.delete(a);const f=(d=yn.get(o))!==null&&d!==void 0?d:1;if(yn.set(o,f-1),fs(),f===1&&yn.delete(o),Ht.includes(a)){const h=Ht.indexOf(a);h>=0&&Ht.splice(h,1),Va(),i("up",!0,null)}}}function nc(e){const{target:t}=e,{x:n,y:r}=Fs(e);pr=!0,Ba({target:t,x:n,y:r}),fs(),Ht.length>0&&(ps("down",e),e.preventDefault(),e.stopPropagation())}function Zr(e){const{x:t,y:n}=Fs(e);if(pr&&e.buttons===0&&(pr=!1,ps("up",e)),!pr){const{target:r}=e;Ba({target:r,x:t,y:n})}ps("move",e),Va(),Ht.length>0&&e.preventDefault()}function Gn(e){const{target:t}=e,{x:n,y:r}=Fs(e);Ls.clear(),pr=!1,Ht.length>0&&e.preventDefault(),ps("up",e),Ba({target:t,x:n,y:r}),Va(),fs()}function Ba({target:e,x:t,y:n}){Ht.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),gi.forEach(i=>{const{element:s,hitAreaMargins:o}=i,a=s.getBoundingClientRect(),{bottom:l,left:u,right:d,top:f}=a,h=jv?o.coarse:o.fine;if(t>=u-h&&t<=d+h&&n>=f-h&&n<=l+h){if(r!==null&&document.contains(r)&&s!==r&&!s.contains(r)&&!r.contains(s)&&vv(r,s)>0){let g=r,k=!1;for(;g&&!g.contains(s);){if(bv(g.getBoundingClientRect(),a)){k=!0;break}g=g.parentElement}if(k)return}Ht.push(i)}})}function lo(e,t){Ls.set(e,t)}function Va(){let e=!1,t=!1;Ht.forEach(r=>{const{direction:i}=r;i==="horizontal"?e=!0:t=!0});let n=0;Ls.forEach(r=>{n|=r}),e&&t?ao("intersection",n):e?ao("horizontal",n):t?ao("vertical",n):xv()}function fs(){yn.forEach((e,t)=>{const{body:n}=t;n.removeEventListener("contextmenu",Gn),n.removeEventListener("pointerdown",nc),n.removeEventListener("pointerleave",Zr),n.removeEventListener("pointermove",Zr)}),window.removeEventListener("pointerup",Gn),window.removeEventListener("pointercancel",Gn),gi.size>0&&(pr?(Ht.length>0&&yn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("contextmenu",Gn),n.addEventListener("pointerleave",Zr),n.addEventListener("pointermove",Zr))}),window.addEventListener("pointerup",Gn),window.addEventListener("pointercancel",Gn)):yn.forEach((e,t)=>{const{body:n}=t;e>0&&(n.addEventListener("pointerdown",nc,{capture:!0}),n.addEventListener("pointermove",Zr))}))}function ps(e,t){gi.forEach(n=>{const{setResizeHandlerState:r}=n,i=Ht.includes(n);r(e,i,t)})}function Nv(){const[e,t]=fr(0);return bt(()=>t(n=>n+1),[])}function Ce(e,t){if(!e)throw console.error(t),Error(t)}const Za=10;function Ln(e,t,n=Za){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function ln(e,t,n=Za){return Ln(e,t,n)===0}function Tt(e,t,n){return Ln(e,t,n)===0}function Ev(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(!Tt(i,s,n))return!1}return!0}function ar({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ce(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:i=0,collapsible:s,maxSize:o=100,minSize:a=0}=r;if(Ln(n,a)<0)if(s){const l=(i+a)/2;Ln(n,l)<0?n=i:n=a}else n=a;return n=Math.min(o,n),n=parseFloat(n.toFixed(Za)),n}function Kr({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:i,trigger:s}){if(Tt(e,0))return t;const o=[...t],[a,l]=r;Ce(a!=null,"Invalid first pivot index"),Ce(l!=null,"Invalid second pivot index");let u=0;if(s==="keyboard"){{const f=e<0?l:a,h=n[f];Ce(h,`Panel constraints not found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:k=0}=h;if(g){const S=t[f];if(Ce(S!=null,`Previous layout not found for panel index ${f}`),Tt(S,p)){const y=k-S;Ln(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const f=e<0?a:l,h=n[f];Ce(h,`No panel constraints found for index ${f}`);const{collapsedSize:p=0,collapsible:g,minSize:k=0}=h;if(g){const S=t[f];if(Ce(S!=null,`Previous layout not found for panel index ${f}`),Tt(S,k)){const y=S-p;Ln(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const f=e<0?1:-1;let h=e<0?l:a,p=0;for(;;){const k=t[h];Ce(k!=null,`Previous layout not found for panel index ${h}`);const y=ar({panelConstraints:n,panelIndex:h,size:100})-k;if(p+=y,h+=f,h<0||h>=n.length)break}const g=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-g:g}{let h=e<0?a:l;for(;h>=0&&h<n.length;){const p=Math.abs(e)-Math.abs(u),g=t[h];Ce(g!=null,`Previous layout not found for panel index ${h}`);const k=g-p,S=ar({panelConstraints:n,panelIndex:h,size:k});if(!Tt(g,S)&&(u+=g-S,o[h]=S,u.toPrecision(3).localeCompare(Math.abs(e).toPrecision(3),void 0,{numeric:!0})>=0))break;e<0?h--:h++}}if(Ev(i,o))return i;{const f=e<0?l:a,h=t[f];Ce(h!=null,`Previous layout not found for panel index ${f}`);const p=h+u,g=ar({panelConstraints:n,panelIndex:f,size:p});if(o[f]=g,!Tt(g,p)){let k=p-g,y=e<0?l:a;for(;y>=0&&y<n.length;){const j=o[y];Ce(j!=null,`Previous layout not found for panel index ${y}`);const m=j+k,A=ar({panelConstraints:n,panelIndex:y,size:m});if(Tt(j,A)||(k-=A-j,o[y]=A),Tt(k,0))break;e>0?y--:y++}}}const d=o.reduce((f,h)=>h+f,0);return Tt(d,100)?o:i}function Cv({layout:e,panelsArray:t,pivotIndices:n}){let r=0,i=100,s=0,o=0;const a=n[0];Ce(a!=null,"No pivot index found"),t.forEach((f,h)=>{const{constraints:p}=f,{maxSize:g=100,minSize:k=0}=p;h===a?(r=k,i=g):(s+=k,o+=g)});const l=Math.min(i,100-s),u=Math.max(r,100-o),d=e[a];return{valueMax:l,valueMin:u,valueNow:d}}function xi(e,t=document){return Array.from(t.querySelectorAll(`[data-panel-resize-handle-id][data-panel-group-id="${e}"]`))}function hp(e,t,n=document){const i=xi(e,n).findIndex(s=>s.getAttribute("data-panel-resize-handle-id")===t);return i??null}function mp(e,t,n){const r=hp(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function gp(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 Bs(e,t=document){const n=t.querySelector(`[data-panel-resize-handle-id="${e}"]`);return n||null}function Tv(e,t,n,r=document){var i,s,o,a;const l=Bs(t,r),u=xi(e,r),d=l?u.indexOf(l):-1,f=(i=(s=n[d])===null||s===void 0?void 0:s.id)!==null&&i!==void 0?i:null,h=(o=(a=n[d+1])===null||a===void 0?void 0:a.id)!==null&&o!==void 0?o:null;return[f,h]}function Iv({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:i,panelGroupElement:s,setLayout:o}){jt({didWarnAboutMissingResizeHandle:!1}),$n(()=>{if(!s)return;const a=xi(n,s);for(let l=0;l<i.length-1;l++){const{valueMax:u,valueMin:d,valueNow:f}=Cv({layout:r,panelsArray:i,pivotIndices:[l,l+1]}),h=a[l];if(h!=null){const p=i[l];Ce(p,`No panel data found for index "${l}"`),h.setAttribute("aria-controls",p.id),h.setAttribute("aria-valuemax",""+Math.round(u)),h.setAttribute("aria-valuemin",""+Math.round(d)),h.setAttribute("aria-valuenow",f!=null?""+Math.round(f):"")}}return()=>{a.forEach((l,u)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,i,s]),Rn(()=>{if(!s)return;const a=t.current;Ce(a,"Eager values not found");const{panelDataArray:l}=a,u=gp(n,s);Ce(u!=null,`No group found for id "${n}"`);const d=xi(n,s);Ce(d,`No resize handles found for group id "${n}"`);const f=d.map(h=>{const p=h.getAttribute("data-panel-resize-handle-id");Ce(p,"Resize handle element has no handle id attribute");const[g,k]=Tv(n,p,l,s);if(g==null||k==null)return()=>{};const S=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const j=l.findIndex(m=>m.id===g);if(j>=0){const m=l[j];Ce(m,`No panel data found for index ${j}`);const A=r[j],{collapsedSize:C=0,collapsible:v,minSize:w=0}=m.constraints;if(A!=null&&v){const O=Kr({delta:Tt(A,C)?w-C:C-A,initialLayout:r,panelConstraints:l.map(B=>B.constraints),pivotIndices:mp(n,p,s),prevLayout:r,trigger:"keyboard"});r!==O&&o(O)}}break}}};return h.addEventListener("keydown",S),()=>{h.removeEventListener("keydown",S)}});return()=>{f.forEach(h=>h())}},[s,e,t,n,r,i,o])}function rc(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 xp(e,t){const n=e==="horizontal",{x:r,y:i}=Fs(t);return n?r:i}function Av(e,t,n,r,i){const s=n==="horizontal",o=Bs(t,i);Ce(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute("data-panel-group-id");Ce(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const u=xp(n,e),d=gp(a,i);Ce(d,`No group element found for id "${a}"`);const f=d.getBoundingClientRect(),h=s?f.width:f.height;return(u-l)/h*100}function zv(e,t,n,r,i,s){if(op(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:Av(e,t,n,r,s)}function Ov({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];Ce(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];Ce(o,`Panel constraints not found for index ${s}`);const{defaultSize:a}=o;if(a!=null)continue;const l=e.length-r,u=i/l;r++,t[s]=u,i-=u}return t}function Kn(e,t,n){t.forEach((r,i)=>{const s=e[i];Ce(s,`Panel data not found for index ${i}`);const{callbacks:o,constraints:a,id:l}=s,{collapsedSize:u=0,collapsible:d}=a,f=n[l];if(f==null||r!==f){n[l]=r;const{onCollapse:h,onExpand:p,onResize:g}=o;g&&g(r,f),d&&(h||p)&&(p&&(f==null||ln(f,u))&&!ln(r,u)&&p(),h&&(f==null||!ln(f,u))&&ln(r,u)&&h())}})}function Li(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 Pv({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 Dv(e,t=10){let n=null;return(...i)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...i)},t)}}function ic(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 yp(e){return`react-resizable-panels:${e}`}function bp(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 vp(e,t){try{const n=yp(e),r=t.getItem(n);if(r){const i=JSON.parse(r);if(typeof i=="object"&&i!=null)return i}}catch{}return null}function Rv(e,t,n){var r,i;const s=(r=vp(e,n))!==null&&r!==void 0?r:{},o=bp(t);return(i=s[o])!==null&&i!==void 0?i:null}function $v(e,t,n,r,i){var s;const o=yp(e),a=bp(t),l=(s=vp(e,i))!==null&&s!==void 0?s:{};l[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{i.setItem(o,JSON.stringify(l))}catch(u){console.error(u)}}function sc({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(!Tt(r,100)&&n.length>0)for(let s=0;s<t.length;s++){const o=n[s];Ce(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];Ce(o!=null,`No layout data found for index ${s}`);const a=ar({panelConstraints:t,panelIndex:s,size:o});o!=a&&(i+=o-a,n[s]=a)}if(!Tt(i,0))for(let s=0;s<t.length;s++){const o=n[s];Ce(o!=null,`No layout data found for index ${s}`);const a=o+i,l=ar({panelConstraints:t,panelIndex:s,size:a});if(o!==l&&(i-=l-o,n[s]=l,Tt(i,0)))break}return n}const Mv=100,Yr={getItem:e=>(ic(Yr),Yr.getItem(e)),setItem:(e,t)=>{ic(Yr),Yr.setItem(e,t)}},oc={};function wp({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:i,id:s=null,onLayout:o=null,keyboardResizeBy:a=null,storage:l=Yr,style:u,tagName:d="div",...f}){const h=La(s),p=jt(null),[g,k]=fr(null),[S,y]=fr([]),j=Nv(),m=jt({}),A=jt(new Map),C=jt(0),v=jt({autoSaveId:e,direction:r,dragState:g,id:h,keyboardResizeBy:a,onLayout:o,storage:l}),w=jt({layout:S,panelDataArray:[],panelDataArrayChanged:!1});jt({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),rp(i,()=>({getId:()=>v.current.id,getLayout:()=>{const{layout:b}=w.current;return b},setLayout:b=>{const{onLayout:G}=v.current,{layout:ne,panelDataArray:Q}=w.current,oe=sc({layout:b,panelConstraints:Q.map(I=>I.constraints)});rc(ne,oe)||(y(oe),w.current.layout=oe,G&&G(oe),Kn(Q,oe,m.current))}}),[]),$n(()=>{v.current.autoSaveId=e,v.current.direction=r,v.current.dragState=g,v.current.id=h,v.current.onLayout=o,v.current.storage=l}),Iv({committedValuesRef:v,eagerValuesRef:w,groupId:h,layout:S,panelDataArray:w.current.panelDataArray,setLayout:y,panelGroupElement:p.current}),Rn(()=>{const{panelDataArray:b}=w.current;if(e){if(S.length===0||S.length!==b.length)return;let G=oc[e];G==null&&(G=Dv($v,Mv),oc[e]=G);const ne=[...b],Q=new Map(A.current);G(e,ne,Q,S,l)}},[e,S,l]),Rn(()=>{});const O=bt(b=>{const{onLayout:G}=v.current,{layout:ne,panelDataArray:Q}=w.current;if(b.constraints.collapsible){const oe=Q.map(H=>H.constraints),{collapsedSize:I=0,panelSize:re,pivotIndices:ae}=Cn(Q,b,ne);if(Ce(re!=null,`Panel size not found for panel "${b.id}"`),!ln(re,I)){A.current.set(b.id,re);const K=rr(Q,b)===Q.length-1?re-I:I-re,pe=Kr({delta:K,initialLayout:ne,panelConstraints:oe,pivotIndices:ae,prevLayout:ne,trigger:"imperative-api"});Li(ne,pe)||(y(pe),w.current.layout=pe,G&&G(pe),Kn(Q,pe,m.current))}}},[]),B=bt((b,G)=>{const{onLayout:ne}=v.current,{layout:Q,panelDataArray:oe}=w.current;if(b.constraints.collapsible){const I=oe.map(fe=>fe.constraints),{collapsedSize:re=0,panelSize:ae=0,minSize:H=0,pivotIndices:K}=Cn(oe,b,Q),pe=G??H;if(ln(ae,re)){const fe=A.current.get(b.id),Re=fe!=null&&fe>=pe?fe:pe,$e=rr(oe,b)===oe.length-1?ae-Re:Re-ae,E=Kr({delta:$e,initialLayout:Q,panelConstraints:I,pivotIndices:K,prevLayout:Q,trigger:"imperative-api"});Li(Q,E)||(y(E),w.current.layout=E,ne&&ne(E),Kn(oe,E,m.current))}}},[]),N=bt(b=>{const{layout:G,panelDataArray:ne}=w.current,{panelSize:Q}=Cn(ne,b,G);return Ce(Q!=null,`Panel size not found for panel "${b.id}"`),Q},[]),R=bt((b,G)=>{const{panelDataArray:ne}=w.current,Q=rr(ne,b);return Pv({defaultSize:G,dragState:g,layout:S,panelData:ne,panelIndex:Q})},[g,S]),T=bt(b=>{const{layout:G,panelDataArray:ne}=w.current,{collapsedSize:Q=0,collapsible:oe,panelSize:I}=Cn(ne,b,G);return Ce(I!=null,`Panel size not found for panel "${b.id}"`),oe===!0&&ln(I,Q)},[]),F=bt(b=>{const{layout:G,panelDataArray:ne}=w.current,{collapsedSize:Q=0,collapsible:oe,panelSize:I}=Cn(ne,b,G);return Ce(I!=null,`Panel size not found for panel "${b.id}"`),!oe||Ln(I,Q)>0},[]),z=bt(b=>{const{panelDataArray:G}=w.current;G.push(b),G.sort((ne,Q)=>{const oe=ne.order,I=Q.order;return oe==null&&I==null?0:oe==null?-1:I==null?1:oe-I}),w.current.panelDataArrayChanged=!0,j()},[j]);$n(()=>{if(w.current.panelDataArrayChanged){w.current.panelDataArrayChanged=!1;const{autoSaveId:b,onLayout:G,storage:ne}=v.current,{layout:Q,panelDataArray:oe}=w.current;let I=null;if(b){const ae=Rv(b,oe,ne);ae&&(A.current=new Map(Object.entries(ae.expandToSizes)),I=ae.layout)}I==null&&(I=Ov({panelDataArray:oe}));const re=sc({layout:I,panelConstraints:oe.map(ae=>ae.constraints)});rc(Q,re)||(y(re),w.current.layout=re,G&&G(re),Kn(oe,re,m.current))}}),$n(()=>{const b=w.current;return()=>{b.layout=[]}},[]);const M=bt(b=>{let G=!1;const ne=p.current;return ne&&window.getComputedStyle(ne,null).getPropertyValue("direction")==="rtl"&&(G=!0),function(oe){oe.preventDefault();const I=p.current;if(!I)return()=>null;const{direction:re,dragState:ae,id:H,keyboardResizeBy:K,onLayout:pe}=v.current,{layout:fe,panelDataArray:Re}=w.current,{initialLayout:Oe}=ae??{},$e=mp(H,b,I);let E=zv(oe,b,re,ae,K,I);const P=re==="horizontal";P&&G&&(E=-E);const V=Re.map(ee=>ee.constraints),se=Kr({delta:E,initialLayout:Oe??fe,panelConstraints:V,pivotIndices:$e,prevLayout:fe,trigger:op(oe)?"keyboard":"mouse-or-touch"}),ie=!Li(fe,se);(ap(oe)||lp(oe))&&C.current!=E&&(C.current=E,!ie&&E!==0?P?lo(b,E<0?up:dp):lo(b,E<0?fp:pp):lo(b,0)),ie&&(y(se),w.current.layout=se,pe&&pe(se),Kn(Re,se,m.current))}},[]),D=bt((b,G)=>{const{onLayout:ne}=v.current,{layout:Q,panelDataArray:oe}=w.current,I=oe.map(fe=>fe.constraints),{panelSize:re,pivotIndices:ae}=Cn(oe,b,Q);Ce(re!=null,`Panel size not found for panel "${b.id}"`);const K=rr(oe,b)===oe.length-1?re-G:G-re,pe=Kr({delta:K,initialLayout:Q,panelConstraints:I,pivotIndices:ae,prevLayout:Q,trigger:"imperative-api"});Li(Q,pe)||(y(pe),w.current.layout=pe,ne&&ne(pe),Kn(oe,pe,m.current))},[]),J=bt((b,G)=>{const{layout:ne,panelDataArray:Q}=w.current,{collapsedSize:oe=0,collapsible:I}=G,{collapsedSize:re=0,collapsible:ae,maxSize:H=100,minSize:K=0}=b.constraints,{panelSize:pe}=Cn(Q,b,ne);pe!=null&&(I&&ae&&ln(pe,oe)?ln(oe,re)||D(b,re):pe<K?D(b,K):pe>H&&D(b,H))},[D]),Z=bt((b,G)=>{const{direction:ne}=v.current,{layout:Q}=w.current;if(!p.current)return;const oe=Bs(b,p.current);Ce(oe,`Drag handle element not found for id "${b}"`);const I=xp(ne,G);k({dragHandleId:b,dragHandleRect:oe.getBoundingClientRect(),initialCursorPosition:I,initialLayout:Q})},[]),X=bt(()=>{k(null)},[]),_=bt(b=>{const{panelDataArray:G}=w.current,ne=rr(G,b);ne>=0&&(G.splice(ne,1),delete m.current[b.id],w.current.panelDataArrayChanged=!0,j())},[j]),ye=fv(()=>({collapsePanel:O,direction:r,dragState:g,expandPanel:B,getPanelSize:N,getPanelStyle:R,groupId:h,isPanelCollapsed:T,isPanelExpanded:F,reevaluatePanelConstraints:J,registerPanel:z,registerResizeHandle:M,resizePanel:D,startDragging:Z,stopDragging:X,unregisterPanel:_,panelGroupElement:p.current}),[O,g,r,B,N,R,h,T,F,J,z,M,D,Z,X,_]),ce={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return Sr(Ms.Provider,{value:ye},Sr(d,{...f,children:t,className:n,id:s,ref:p,style:{...ce,...u},"data-panel-group":"","data-panel-group-direction":r,"data-panel-group-id":h}))}const kp=tp((e,t)=>Sr(wp,{...e,forwardedRef:t}));wp.displayName="PanelGroup";kp.displayName="forwardRef(PanelGroup)";function rr(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function Cn(e,t,n){const r=rr(e,t),s=r===e.length-1?[r-1,r]:[r,r+1],o=n[r];return{...t.constraints,panelSize:o,pivotIndices:s}}function Fv({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){Rn(()=>{if(e||n==null||r==null)return;const i=Bs(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");Ce(a,`No group element found for id "${a}"`);const l=xi(a,r),u=hp(a,t,r);Ce(u!==null,`No resize element found for id "${t}"`);const d=o.shiftKey?u>0?u-1:l.length-1:u+1<l.length?u+1:0;l[d].focus();break}}};return i.addEventListener("keydown",s),()=>{i.removeEventListener("keydown",s)}},[r,e,t,n])}function Sp({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:i,onBlur:s,onDragging:o,onFocus:a,style:l={},tabIndex:u=0,tagName:d="div",...f}){var h,p;const g=jt(null),k=jt({onDragging:o});Rn(()=>{k.current.onDragging=o});const S=np(Ms);if(S===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:y,groupId:j,registerResizeHandle:m,startDragging:A,stopDragging:C,panelGroupElement:v}=S,w=La(i),[O,B]=fr("inactive"),[N,R]=fr(!1),[T,F]=fr(null),z=jt({state:O});$n(()=>{z.current.state=O}),Rn(()=>{if(n)F(null);else{const Z=m(w);F(()=>Z)}},[n,w,m]);const M=(h=r==null?void 0:r.coarse)!==null&&h!==void 0?h:15,D=(p=r==null?void 0:r.fine)!==null&&p!==void 0?p:5;return Rn(()=>{if(n||T==null)return;const Z=g.current;return Ce(Z,"Element ref not attached"),_v(w,Z,y,{coarse:M,fine:D},(_,ye,ce)=>{if(ye)switch(_){case"down":{B("drag"),Ce(ce,'Expected event to be defined for "down" action'),A(w,ce);const{onDragging:b}=k.current;b&&b(!0);break}case"move":{const{state:b}=z.current;b!=="drag"&&B("hover"),Ce(ce,'Expected event to be defined for "move" action'),T(ce);break}case"up":{B("hover"),C();const{onDragging:b}=k.current;b&&b(!1);break}}else B("inactive")})},[M,y,n,D,m,w,T,A,C]),Fv({disabled:n,handleId:w,resizeHandler:T,panelGroupElement:v}),Sr(d,{...f,children:e,className:t,id:i,onBlur:()=>{R(!1),s==null||s()},onFocus:()=>{R(!0),a==null||a()},ref:g,role:"separator",style:{...{touchAction:"none",userSelect:"none"},...l},tabIndex:u,"data-panel-group-direction":y,"data-panel-group-id":j,"data-resize-handle":"","data-resize-handle-active":O==="drag"?"pointer":N?"keyboard":void 0,"data-resize-handle-state":O,"data-panel-resize-handle-enabled":!n,"data-panel-resize-handle-id":w})}Sp.displayName="PanelResizeHandle";const Lv=({className:e,...t})=>c.jsx(kp,{className:W("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",e),...t}),co=sp,ac=({withHandle:e,className:t,...n})=>c.jsx(Sp,{className:W("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&&c.jsx("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-sm border",children:c.jsx(zx,{className:"h-2.5 w-2.5"})})}),jp=x.forwardRef(({className:e,...t},n)=>c.jsx("textarea",{className:W("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}));jp.displayName="Textarea";class Bv{constructor(t){Rr(this,"client");this.client=Hx.create({baseURL:t||void 0||"/api",headers:{"Content-Type":"application/json"}})}get(t,n){return this.client.get(t,n)}post(t,n,r){return this.client.post(t,n,r)}put(t,n,r){return this.client.put(t,n,r)}delete(t,n){return this.client.delete(t,n)}patch(t,n,r){return this.client.patch(t,n,r)}}const Vv=new Bv;class Zv extends Error{constructor(n,r){super(n);Rr(this,"quality");this.name="QualityGateFailedError",this.quality=r}}function Uv(e,t){return e??t}function Jv(e){var n;const t=(n=e==null?void 0:e.split(";",1)[0])==null?void 0:n.trim().toLowerCase();return t?t==="application/json"||t.startsWith("application/")&&t.endsWith("+json"):!1}async function Hv(e){if(Jv(e.headers.get("content-type")))try{return await e.json()}catch{return}}function lc(e,t){if(t!=null&&t.error)return t.error;if(t!=null&&t.message)return t.message;if(e.ok)return`The server answered ${e.status} but not with a document. This usually means a proxy or extension replaced the response.`;switch(e.status){case 502:case 503:case 504:return`The server did not finish generating (${e.status}). It usually ran out of memory or restarted mid-request — documents with many full-page images or inline SVGs are the common cause. Try again, or split the document and generate it in parts.`;case 413:return"The document is too large for the server to accept (413). Remove or shrink its largest embedded assets.";case 429:return"Too many requests (429). Wait a moment before generating again.";default:return`Generation failed (${e.status}${e.statusText?` ${e.statusText}`:""}).`}}function Wv(){const e=x.useRef(null),t=yr(s=>s.generationBackend),n=pd(),r=x.useCallback(async(s,o,a,l,u)=>{e.current&&e.current.abort();const d=new AbortController;e.current=d;const f=Uv(u==null?void 0:u.renderer,t);try{l==null||l("parsing","Validating JSON structure...");let h;try{h=JSON.parse(o)}catch(B){throw new Error(`Invalid JSON: ${B instanceof Error?B.message:"Unknown parse error"}`)}l==null||l("building",`Building ${$i.toLowerCase()} structure...`);const p={jsonDefinition:h,options:{...u,sourceName:n(s),...f?{renderer:f}:{}}};p.customThemes=a??{},l==null||l("rendering",`Generating ${at.toUpperCase()} content...`);const g={"Content-Type":"application/json"};u!=null&&u.bypassCache&&(g["X-Bypass-Cache"]="true");const k=await fetch(ui.generate,{method:"POST",headers:g,body:JSON.stringify(p),signal:d.signal}),S=await Hv(k);if(k.status===400&&(S==null?void 0:S.code)==="QUALITY_GATE_FAILED")throw new Zv(lc(k,S),S.quality);if(!k.ok||!(S!=null&&S.success))throw new Error(lc(k,S));const{data:y,cache:j,warnings:m}=S,A=j.status==="HIT"?"HIT":j.status==="MISS"?"MISS":"UNKNOWN",C=A==="HIT"?`Served from cache (Hit rate: ${j.hitRate})`:`Generated fresh ${$i.toLowerCase()}`;l==null||l("finalizing",C);const v=globalThis.atob(y.document),w=new Uint8Array(v.length);for(let B=0;B<v.length;B++)w[B]=v.charCodeAt(B);const O=new Blob([w],{type:y.contentType});if(O.size===0)throw new Error(`Received empty ${$i.toLowerCase()} from API`);return{name:s,text:o,blob:O,...f?{renderer:f}:{},filename:y.filename,fileId:y.fileId,cacheStatus:A,cacheHitRate:j.hitRate,warnings:m}}catch(h){throw h instanceof Error&&h.name==="AbortError"?new Error(`${$i} generation was cancelled`):h}finally{e.current===d&&(e.current=null)}},[t,n]),i=x.useCallback(()=>{e.current&&(e.current.abort(),e.current=null)},[]);return{generatePresentation:r,generateDocument:r,cancelGeneration:i}}const Yi={ids:[],default:null};let cc;function qv(){return cc??(cc=(async()=>{var e;try{const t=await fetch(ui.renderers);if(!t.ok)return Yi;const n=await t.json();return!(n!=null&&n.success)||!Array.isArray((e=n.data)==null?void 0:e.ids)?Yi:n.data}catch{return Yi}})()),cc}function Gv(){const[e,t]=x.useState(Yi);return x.useEffect(()=>{let n=!1;return qv().then(r=>{n||t(r)}),()=>{n=!0}},[]),e}function Kv(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(([u,d])=>`${u}: ${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 Yv({open:e,onClose:t,nonSafeFonts:n,onChoose:r}){const[i,s]=je.useState("custom");je.useEffect(()=>{e&&s("custom")},[e]);const o=n.length===1?n[0]:n.slice(0,3).join(", ")+(n.length>3?` +${n.length-3} more`:""),a=[{value:"custom",title:"Keep custom fonts",desc:"Recipients with the font installed see the authored typeface. Others get a generic fallback."},{value:"substitute",title:"Convert to safe fonts",desc:"Rewrite non-safe families to Calibri / Georgia / Consolas so every recipient sees the same glyphs."}];return c.jsx(ct,{open:e,onOpenChange:l=>!l&&t(),children:c.jsxs(lt,{className:"max-w-md",children:[c.jsxs(qt,{children:[c.jsx(Gt,{children:"Non-safe fonts in this document"}),c.jsxs(dn,{children:[o," ",n.length===1?"is":"are"," not in the built-in safe list. Choose how to export."]})]}),c.jsx("div",{className:"grid gap-2 py-2",children:a.map(l=>{const u=i===l.value;return c.jsxs("button",{type:"button",onClick:()=>s(l.value),className:`text-left rounded-md border px-3 py-2 transition-colors ${u?"border-primary bg-primary/5":"border-border hover:bg-muted/40"}`,children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`h-3.5 w-3.5 rounded-full border flex items-center justify-center ${u?"border-primary":"border-muted-foreground/50"}`,children:u&&c.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-primary"})}),c.jsx("span",{className:"text-sm font-medium",children:l.title})]}),c.jsx("p",{className:"mt-1 text-xs text-muted-foreground pl-6",children:l.desc})]},l.value)})}),c.jsxs(kn,{children:[c.jsx(Ee,{variant:"outline",size:"sm",onClick:t,children:"Cancel"}),c.jsx(Ee,{size:"sm",onClick:()=>{r(i),t()},children:"Download"})]})]})})}function Xv(e){const t=e.hasPendingDiff?"Review the proposed change first":e.parses?void 0:"The visual view needs the JSON to parse";return{view:t?"json":e.preferred??"visual",forcedReason:t}}function Qv(e){try{const t=JSON.parse(e);return!!t&&typeof t=="object"&&!Array.isArray(t)}catch{return!1}}function ew(){const e=yr(l=>l.setSettings),t=yr(l=>l.themeEditorView),n=ke(l=>l.activeTab&&l.documentTypes[l.activeTab]==="application/json+theme"?l.activeTab:""),r=ke(l=>{if(!n)return!0;const u=l.documents.find(d=>d.name===n);return u?Qv(u.text):!0}),i=ke(l=>!!n&&l.pendingDiffs[n]!==void 0),s=x.useCallback(l=>e({themeEditorView:l}),[e]);if(!n)return null;const{view:o,forcedReason:a}=Xv({preferred:t,parses:r,hasPendingDiff:i});return c.jsxs("div",{role:"tablist","aria-label":"Theme editor view",title:a,className:"flex h-7 shrink-0 items-center rounded-sm border border-border/70 bg-muted/60 p-0.5",children:[c.jsx(uc,{active:o==="visual",disabled:a!==void 0,onClick:()=>s("visual"),icon:Ox,label:"Visual"}),c.jsx(uc,{active:o==="json",onClick:()=>s("json"),icon:ns,label:"JSON"})]})}function uc({active:e,disabled:t,onClick:n,icon:r,label:i}){return c.jsxs("button",{type:"button",role:"tab","aria-selected":e,"aria-label":i,disabled:t,onClick:n,className:W("flex h-6 cursor-pointer items-center gap-1.5 rounded-[3px] px-2 text-xs transition-colors","focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none","disabled:cursor-not-allowed disabled:opacity-50",e?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[c.jsx(r,{className:"size-3.5"}),c.jsx("span",{className:"hidden md:inline",children:i})]})}const tw=je.memo(ew);function uo(){return c.jsx("span",{className:"rounded-sm bg-warning/15 px-1 py-px text-[10px] font-semibold uppercase leading-none tracking-wide text-warning",children:"experimental"})}function dc(){return c.jsx("span",{className:"rounded-sm bg-muted px-1 py-px text-[10px] font-semibold uppercase leading-none tracking-wide text-muted-foreground",children:"default"})}function nw({name:e,blob:t,onManualRender:n,isGenerating:r,isRendering:i,onShowCacheMetrics:s,onShowSchemas:o,onShowFonts:a,documentText:l,editorDocumentText:u,editorDocumentName:d,warnings:f,onToggleChat:h,chatOpen:p,onTogglePreview:g,previewOpen:k}){const[S,y]=x.useState(!1),[j,m]=x.useState(!1),[A,C]=x.useState(!1),[v,w]=x.useState(!1),[O,B]=x.useState(!1),[N,R]=x.useState(null),{toast:T}=Cr(),F=pd(),{generateDocument:z}=Wv(),M=x.useContext(ka),D=Gv(),J=yr(K=>K.generationBackend),Z=yr(K=>K.setSettings),X=J??D.default??void 0,_=x.useCallback(()=>{const K={},{customThemes:pe}=M.getState();return Object.values(pe).forEach(fe=>{fe.valid&&fe.parsed&&(K[fe.name]=fe.parsed)}),K},[M]),ye=je.useMemo(()=>{if(!l)return[];try{const K=JSON.parse(l);return[...(at==="pptx"?$g:Mg)(K)].filter(fe=>!Fg(fe))}catch{return[]}},[l]),[ce,b]=x.useState(!1),G=x.useCallback(async()=>{if(t){y(!0);try{await new Promise(K=>setTimeout(K,100)),oi(`${e}${$r}`,t)}finally{setTimeout(()=>y(!1),500)}}},[t,e]),ne=x.useCallback(async()=>{if(t){if(ye.length===0){await G();return}b(!0)}},[t,ye.length,G]),Q=x.useCallback(async K=>{var pe;if(l){y(!0);try{const fe=await z(e,l,_(),void 0,{bypassCache:!0,fonts:{mode:K}});if(fe.blob.size===0)T({title:"Export failed",description:"The server returned an empty document.",variant:"destructive"});else{oi(`${e}${$r}`,fe.blob);const Re=(pe=fe.warnings)==null?void 0:pe.find(Oe=>{var $e,E;return(($e=Oe.context)==null?void 0:$e.code)==="FONT_MODE_SUBSTITUTED"||((E=Oe.context)==null?void 0:E.code)==="FONT_MODE_CUSTOM"});Re&&T({title:K==="substitute"?"Fonts substituted":"Non-safe fonts kept",description:Re.message})}}catch(fe){T({title:"Export failed",description:fe instanceof Error?fe.message:String(fe),variant:"destructive"})}finally{setTimeout(()=>y(!1),500)}}},[l,e,z,T,_]),oe=x.useCallback(async()=>{if(!(!f||f.length===0)){m(!0);try{const K=Kv(f);if(!K){T({title:"No warnings",description:"There are no warnings to download.",variant:"destructive"});return}const pe=await z("warnings",JSON.stringify(K,null,2),{});pe&&typeof pe=="object"&&"blob"in pe&&pe.blob&&(oi(`${e}-warnings${$r}`,pe.blob),T({title:"Warnings downloaded",description:`Downloaded warnings document with ${f.length} warning(s).`}))}catch(K){console.error("Failed to generate warnings document:",K),T({title:"Download failed",description:K instanceof Error?K.message:"Failed to generate warnings document",variant:"destructive"})}finally{setTimeout(()=>m(!1),500)}}},[f,e,z,T]),I=x.useCallback(async()=>{C(!0);try{await Vv.delete(`/${at}/cache`),window.dispatchEvent(new CustomEvent("cache:cleared")),T({title:"Cache Cleared",description:"All active caches have been successfully cleared.",variant:"default"})}catch(K){console.error("Failed to clear cache:",K),T({title:"Cache Clear Failed",description:"Failed to clear caches. Please try again.",variant:"destructive"})}finally{C(!1)}},[T]),re=u??l,ae=x.useCallback(()=>{var fe,Re;if(!re){T({title:"No document available",description:"Please select a document to copy standard components",variant:"destructive"});return}try{JSON.parse(re)}catch{T({title:"Document is not valid JSON",description:"Fix the JSON errors in the editor, then copy again",variant:"destructive"});return}B(!0);const K=(async()=>{const Oe=_(),$e=await Bo(re,{customThemes:Oe}),E=await fetch(`/api/${at}/standard-components`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({jsonDefinition:$e.text,customThemes:Oe,options:{sourceName:F(d??e)}})});if(!E.ok){let V=`Request failed with status ${E.status}`;try{const se=await E.json(),ie=se.error??se.message;typeof ie=="string"&&ie&&(V=ie)}catch{}throw new Error(V)}const P=await E.json();return JSON.stringify(P.data,null,2)})();let pe;typeof ClipboardItem<"u"&&((fe=navigator.clipboard)!=null&&fe.write)?pe=navigator.clipboard.write([new ClipboardItem({"text/plain":K.then(Oe=>new Blob([Oe],{type:"text/plain"}))})]):(Re=navigator.clipboard)!=null&&Re.writeText?pe=K.then(Oe=>navigator.clipboard.writeText(Oe)):pe=Promise.reject(new Error("Clipboard is not available in this context")),(async()=>{try{await pe,T({title:"Copied to clipboard",description:"Standard components JSON has been copied"})}catch(Oe){let $e=null;try{$e=await K}catch(E){console.error("Error fetching standard components:",E),T({title:"Failed to get standard components",description:E instanceof Error?E.message:"Request failed",variant:"destructive"});return}console.error("Clipboard write failed:",Oe),R($e)}finally{B(!1)}})()},[re,e,d,F,_,T]),H=x.useCallback(async()=>{if(N!=null)try{await navigator.clipboard.writeText(N),T({title:"Copied to clipboard",description:"Standard components JSON has been copied"}),R(null)}catch{T({title:"Clipboard unavailable",description:"Select the JSON in the dialog and copy it manually",variant:"destructive"})}},[N,T]);return c.jsxs(c.Fragment,{children:[c.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:[c.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[c.jsx("p",{className:"text-foreground text-sm font-semibold tracking-tight truncate flex-1 min-w-0",children:e}),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.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:c.jsx(nf,{className:"h-3.5 w-3.5 text-muted-foreground"})})}),c.jsx(Qe,{className:"max-w-sm",children:c.jsxs("p",{className:"text-sm",children:["Preview converts the file to a PDF with LibreOffice. Download the ",$r," to verify fidelity."]})})]})]}),c.jsxs("div",{className:"flex flex-row items-center gap-x-1 shrink-0",children:[c.jsx(tw,{}),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsxs(Ee,{variant:"default",size:"sm",className:"gap-1.5 h-7 px-2.5",onClick:n,"aria-label":"Render preview",disabled:r||i||k===!1,children:[i?c.jsx(cn,{size:"sm"}):c.jsx(Px,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Run"})]})}),c.jsx(Qe,{children:c.jsx("p",{children:k===!1?"Open preview to run":i?"Rendering preview...":"Render preview"})})]}),c.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsxs(Ee,{variant:"outline",size:"sm",className:"gap-1.5 h-7 px-2.5",disabled:!t||S||r,onClick:ne,children:[S?c.jsx(cn,{size:"sm"}):c.jsx(Dx,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-xs font-medium hidden sm:inline",children:"Download"})]})}),c.jsx(Qe,{children:c.jsxs("p",{children:["Download ",$r]})})]}),f&&f.length>0&&c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ee,{variant:"outline",size:"icon",className:"h-7 w-7 border-transparent bg-warning/10 text-warning hover:bg-warning/20",disabled:j||r,onClick:oe,children:j?c.jsx(cn,{size:"sm"}):c.jsx(sf,{className:"h-3.5 w-3.5"})})}),c.jsx(Qe,{children:c.jsxs("p",{children:["Download warnings (",f.length,")"]})})]}),D.ids.length>1&&c.jsxs(fi,{value:X,onValueChange:K=>Z({generationBackend:K}),children:[c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsxs(br,{"aria-label":"Renderer",className:"hidden h-7 w-auto min-h-0 gap-1.5 px-2 text-xs lg:flex [&>span]:flex [&>span]:items-center [&>span]:gap-1.5 [&>span]:whitespace-nowrap",children:[c.jsx($o,{className:"h-3.5 w-3.5 shrink-0 opacity-60"}),c.jsxs(pi,{placeholder:"Renderer",children:[c.jsx("span",{className:"font-medium",children:X}),X!==D.default&&c.jsx(uo,{})]})]})}),c.jsx(Qe,{children:c.jsxs("p",{children:["Renderer that writes the ",at.toUpperCase()," file. A non-default one may refuse a document it cannot express."]})})]}),c.jsx(vr,{className:"min-w-[var(--radix-select-trigger-width)] text-sidebar-foreground",children:c.jsxs(uf,{children:[c.jsx(Ea,{className:"px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),D.ids.map(K=>c.jsx(Mn,{value:K,className:"text-xs",children:c.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap",children:[c.jsx("span",{className:"font-medium",children:K}),K===D.default?c.jsx(dc,{}):c.jsx(uo,{})]})},K))]})})]}),c.jsx("div",{className:"w-px h-4 bg-border/60 mx-1"}),c.jsxs(Ti,{children:[c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ii,{asChild:!0,children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"h-7 w-7",children:c.jsx(ja,{className:"h-3.5 w-3.5"})})})}),c.jsx(Qe,{children:c.jsx("p",{children:"More actions"})})]}),c.jsxs(Ar,{align:"end",className:"w-52",children:[o&&c.jsxs($t,{onClick:o,children:[c.jsx(Rx,{className:"h-4 w-4 mr-2"}),"View JSON Schemas"]}),a&&c.jsxs($t,{onClick:a,children:[c.jsx(Ro,{className:"h-4 w-4 mr-2"}),"Browse fonts"]}),s&&c.jsxs($t,{onClick:s,children:[c.jsx(Mo,{className:"h-4 w-4 mr-2"}),"View cache metrics"]}),re?c.jsxs($t,{onClick:ae,disabled:O,children:[c.jsx(Fo,{className:"h-4 w-4 mr-2"}),O?"Copying...":"Copy standard components"]}):c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx("span",{className:"block",children:c.jsxs($t,{disabled:!0,children:[c.jsx(Fo,{className:"h-4 w-4 mr-2"}),"Copy standard components"]})})}),c.jsx(Qe,{side:"left",children:c.jsx("p",{children:"No document selected — open or select a document first"})})]}),c.jsx(Fn,{}),c.jsxs($t,{onClick:()=>w(!0),disabled:A,className:"text-destructive focus:text-destructive",children:[c.jsx(_a,{className:"h-4 w-4 mr-2"}),A?"Clearing...":"Clear all caches"]}),D.ids.length>1&&c.jsxs(c.Fragment,{children:[c.jsx(Fn,{className:"lg:hidden"}),c.jsx($a,{className:"lg:hidden px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground",children:"Renderer"}),D.ids.map(K=>c.jsxs($t,{className:"lg:hidden gap-1.5",onClick:()=>Z({generationBackend:K}),children:[c.jsx(un,{className:`h-3.5 w-3.5 shrink-0 ${X===K?"opacity-100":"opacity-0"}`}),c.jsx("span",{className:"font-medium",children:K}),K===D.default?c.jsx(dc,{}):c.jsx(uo,{})]},K))]})]})]}),g&&c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ee,{variant:k?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:g,children:k?c.jsx(of,{className:"h-3.5 w-3.5"}):c.jsx($x,{className:"h-3.5 w-3.5"})})}),c.jsx(Qe,{children:c.jsxs("span",{className:"flex items-center gap-1.5",children:[k?"Hide":"Show"," Preview"," ",c.jsx(mi,{shortcut:"mod+shift+p"})]})})]}),h&&c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.jsx(Ee,{variant:p?"default":"ghost",size:"icon",className:"h-7 w-7",onClick:h,children:c.jsx(af,{className:"h-3.5 w-3.5"})})}),c.jsx(Qe,{children:c.jsxs("span",{className:"flex items-center gap-1.5",children:[p?"Close":"Open"," AI Chat"," ",c.jsx(mi,{shortcut:"mod+shift+j"})]})})]})]})]}),c.jsx(Yv,{open:ce,onClose:()=>b(!1),nonSafeFonts:ye,onChoose:Q}),c.jsx(ct,{open:N!=null,onOpenChange:K=>{K||R(null)},children:c.jsxs(lt,{className:"max-w-lg",children:[c.jsxs(qt,{children:[c.jsx(Gt,{children:"Standard components"}),c.jsx(dn,{children:"The browser blocked the automatic clipboard write. Copy the JSON from here instead."})]}),c.jsx(jp,{readOnly:!0,value:N??"",className:"h-64 font-mono text-xs",onFocus:K=>K.currentTarget.select()}),c.jsxs(kn,{children:[c.jsx(Ee,{variant:"outline",size:"sm",onClick:()=>R(null),children:"Close"}),c.jsx(Ee,{size:"sm",onClick:H,children:"Copy to clipboard"})]})]})}),c.jsx(ct,{open:v,onOpenChange:w,children:c.jsxs(lt,{className:"max-w-sm",children:[c.jsxs(qt,{children:[c.jsx(Gt,{children:"Clear all caches?"}),c.jsx(dn,{children:"This will clear the document, component, and rasterized-visual caches. Next generation will be uncached."})]}),c.jsxs(kn,{children:[c.jsx(Ee,{variant:"outline",size:"sm",onClick:()=>w(!1),children:"Cancel"}),c.jsx(Ee,{variant:"destructive",size:"sm",disabled:A,onClick:async()=>{await I(),w(!1)},children:A?c.jsx(cn,{size:"sm"}):"Clear"})]})]})})]})}const rw=je.memo(nw),_p=ox,Ua=x.forwardRef(({className:e,...t},n)=>c.jsx(qd,{ref:n,className:W("bg-muted text-muted-foreground inline-flex h-9 items-center justify-center rounded-sm p-1",e),...t}));Ua.displayName=qd.displayName;const hr=x.forwardRef(({className:e,...t},n)=>c.jsx(Gd,{ref:n,className:W("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}));hr.displayName=Gd.displayName;const mr=x.forwardRef(({className:e,...t},n)=>c.jsx(Kd,{ref:n,className:W("ring-offset-background focus-visible:ring-ring mt-2 focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none",e),...t}));mr.displayName=Kd.displayName;async function iw(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 sw(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 ow(e){const t=sw(e);return iw(t)}const aw=({open:e,onOpenChange:t,defaultTab:n="document"})=>{const[r,i]=x.useState(n),[s,o]=x.useState(null),[a,l]=x.useState(null),[u,d]=x.useState(!1),[f,h]=x.useState(!1),[p,g]=x.useState(null),[k,S]=x.useState(null),[y,j]=x.useState(!1),{toast:m}=Cr(),A=Jt(D=>D.selectedPlugins),C=Array.from(A),v=vn(jg);x.useEffect(()=>{n&&i(n)},[n]);const w=x.useCallback(async()=>{d(!0),g(null);try{const D=await Qs.fetchDocumentSchema(C,_g(vn.getState()));o(D)}catch(D){const J=D instanceof Error?D.message:"Failed to load document schema";g(J),m({variant:"destructive",title:"Error loading schema",description:J})}finally{d(!1)}},[C,v,m]),O=x.useCallback(async()=>{if(!a){h(!0),S(null);try{const D=await Qs.fetchThemeSchema();l(D)}catch(D){const J=D instanceof Error?D.message:"Failed to load theme schema";S(J),m({variant:"destructive",title:"Error loading schema",description:J})}finally{h(!1)}}},[a,m]),[B,N]=x.useState([]),[R,T]=x.useState(v);x.useEffect(()=>{e||(o(null),g(null))},[e]),x.useEffect(()=>{if(!e)return;const D=C.length!==B.length||C.some((Z,X)=>Z!==B[X]),J=v!==R;r==="document"?(!s||D||J)&&((D||J)&&(Qs.clearPluginSchemaCache(),N([...C]),T(v)),u||w()):r==="theme"&&!a&&!f&&O()},[r,e,s,a,u,f,C,B,v,R,w,O]);const F=C.length,z=r==="document"?s:a,M=async()=>{if(z)try{await ow(z)&&(j(!0),m({title:"Schema copied",description:"The JSON schema has been copied to your clipboard"}),setTimeout(()=>j(!1),2e3))}catch(D){console.error("Copy failed:",D)}};return c.jsx(ct,{open:e,onOpenChange:t,children:c.jsxs(lt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[c.jsx(qt,{children:c.jsx(Gt,{children:"Schema Viewer"})}),c.jsxs(_p,{value:r,onValueChange:D=>i(D),className:"flex-1 overflow-hidden flex flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ua,{children:[c.jsxs(hr,{value:"document",className:"flex items-center gap-1",children:["Document",F>0&&c.jsxs(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:["+",F]})]}),c.jsx(hr,{value:"theme",children:"Theme"})]}),c.jsx("div",{className:"ml-auto",children:c.jsx(Ee,{variant:"ghost",size:"icon",onClick:M,disabled:y||!z,"aria-label":"Copy schema",children:y?c.jsx(un,{className:"h-4 w-4"}):c.jsx(zs,{className:"h-4 w-4"})})})]}),c.jsxs("div",{className:"flex-1 overflow-auto mt-4",children:[c.jsx(mr,{value:"document",className:"h-full",children:c.jsx(ds,{schema:s,loading:u,error:p||void 0})}),c.jsx(mr,{value:"theme",className:"h-full",children:c.jsx(ds,{schema:a,loading:f,error:k||void 0})})]})]})]})})};function Ja(e,t){var r;const n=lf.getState().getEditor(e);return(r=n==null?void 0:n.flushPendingSave)==null||r.call(n),n?n.toStorageValue(n.editor.getValue()):t}function Np(e,t,n){if(t.length===0)return n;const r=fc(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],u=fc(l,a);i[o]=u,i=u}return i[t[t.length-1]]=n,r}function fc(e,t){return typeof t=="number"?Array.isArray(e)?[...e]:[]:e&&typeof e=="object"&&!Array.isArray(e)?{...e}:{}}const pc=2*1024*1024,hc=12*1024*1024;function lw(e){if(e.length<4)return"unknown";const[t,n,r,i]=e;return t===0&&n===1&&r===0&&i===0||t===116&&n===114&&r===117&&i===101||t===116&&n===116&&r===99&&i===102?"ttf":t===79&&n===84&&r===84&&i===79?"otf":t===119&&n===79&&r===70&&i===70?"woff":t===119&&n===79&&r===70&&i===50?"woff2":"unknown"}function cw(e){let n="";for(let r=0;r<e.length;r+=32768)n+=String.fromCharCode(...e.subarray(r,r+32768));return btoa(n)}function hs(e){return e>=1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${Math.round(e/1024)} KB`}function uw(e,t){if(t.length===0)return{ok:!1,message:`"${e}" is empty.`};if(t.length>pc)return{ok:!1,message:`"${e}" is ${hs(t.length)}. The limit is ${hs(pc)} per font, because the bytes travel inside the document JSON.`};const n=lw(t);return n==="woff"||n==="woff2"?{ok:!1,message:`"${e}" is a ${n.toUpperCase()} file. Upload the TTF or OTF instead — the preview renderer cannot register web font formats.`}:n!=="ttf"&&n!=="otf"?{ok:!1,message:`"${e}" does not look like a TTF or OTF font file.`}:{ok:!0,format:n,base64:cw(t)}}const dw=new Set(["italic","oblique"]);function fw(e){const t=e.replace(/\.[^.]+$/,""),n=t.split(/[-_\s]+/).filter(Boolean),r=new Map;for(const[o,a]of Object.entries(gd))r.set(a.toLowerCase(),Number(o));let i=400,s=!1;for(;n.length>1;){const o=n[n.length-1].toLowerCase();if(dw.has(o)){s=!0,n.pop();continue}const a=r.get(o);if(a!==void 0){i=a,n.pop();continue}break}return{family:n.join(" ")||t,weight:i,italic:s}}function pw(e,t){const n=Array.isArray(e)?[...e]:[],r=n.findIndex(i=>{var s;return((s=i==null?void 0:i.family)==null?void 0:s.toLowerCase())===t.family.toLowerCase()});return r>=0?n[r]=t:n.push(t),n}function hw(e){return e.kind==="safe"||e.kind==="google"?null:{weight:"weight"in e&&e.weight?e.weight:400,italic:"italic"in e?!!e.italic:!1}}function mw(e,t,n,r){const i=((e==null?void 0:e.sources)??[]).filter(a=>{const l=hw(a);return l?!n.some(u=>u.weight===l.weight&&u.italic===l.italic):!0}),s=n.map(a=>({kind:"data",data:a.data,weight:a.weight,italic:a.italic})),o=r??(e==null?void 0:e.category);return{id:(e==null?void 0:e.id)??t,family:t,...o?{category:o}:{},sources:[...i,...s]}}function gw(e,t){let n=Array.isArray(e)?[...e]:[];for(const r of t){const i=r.sources.filter(o=>o.kind==="data").map(o=>({data:o.data,weight:o.weight??400,italic:o.italic??!1}));if(i.length===0)continue;const s=n.find(o=>{var a;return((a=o==null?void 0:o.family)==null?void 0:a.toLowerCase())===r.family.toLowerCase()});n=pw(n,mw(s,r.family,i,r.category))}return n}function xw(e,t){const n=(e.sources??[]).filter(r=>r.format==="ttf"||r.format==="otf").map(r=>({kind:"data",data:r.data,weight:r.weight,italic:r.italic}));return n.length===0?null:{id:e.family,family:e.family,...t?{category:t}:{},sources:n}}function yw(e){const t=new TextEncoder().encode(e).length;return t<=hc?null:`Adding this font would push the document to ${hs(t)}, past the ${hs(hc)} limit. Remove a font from props.fontRegistry, or use fewer weights.`}const mc=new Set,bw=(e,t,n)=>`${e.toLowerCase()}|${t}|${n?"i":"r"}`;function gc(e,t){var d;if(typeof document>"u"||!e.trim())return;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,h)=>f-h).join(";"),l=`https://fonts.googleapis.com/css2?family=${encodeURIComponent(e)}:wght@${a}&display=swap`,u=r??document.createElement("link");r||(u.id=n,u.rel="stylesheet",document.head.appendChild(u)),u.href=l,u.dataset.weights=[...o].sort((f,h)=>f-h).join(",")}function vw(e){const t=e.startsWith("data:")?e.slice(e.indexOf(",")+1):e,n=atob(t),r=new Uint8Array(n.length);for(let i=0;i<n.length;i++)r[i]=n.charCodeAt(i);return r}async function ww(e,t,n,r){const i=bw(e,n,r);if(!mc.has(i))try{if(typeof FontFace>"u"||!(document!=null&&document.fonts))return;const s=vw(t),o=new FontFace(e,s.buffer,{weight:String(n),style:r?"italic":"normal"});await o.load(),document.fonts.add(o),mc.add(i)}catch{}}const kw={safe:[],google:[]};function Sw(){const e=ke(i=>i.activeTab),t=ke(i=>i.documents),n=ke(i=>i.documentTypes),r=ke(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(u=>u.name===e);if(!s)return{ok:!1,error:"Active theme not found"};const o=Ja(e,s.text);let a;try{a=JSON.parse(o)}catch(u){return{ok:!1,error:`Active theme is not valid JSON: ${u.message}`}}const l=i(a);return r(e,JSON.stringify(l,null,2)),{ok:!0,name:e}},[e,t,n,r])}function jw(){const e=ke(r=>r.activeTab),t=ke(r=>r.documents),n=ke(r=>r.saveDocument);return x.useCallback((r,i)=>{if(!e)return{ok:!1,error:"No active file"};const s=t.find(u=>u.name===e);if(!s)return{ok:!1,error:"Active document not found"};const o=Ja(e,s.text);let a;try{a=JSON.parse(o)}catch(u){return{ok:!1,error:`Active document is not valid JSON: ${u.message}`}}const l=Np(a,r,i);return n(e,JSON.stringify(l,null,2)),{ok:!0,name:e}},[e,t,n])}function _w(){const e=ke(i=>i.activeTab),t=ke(i=>i.documents),n=ke(i=>i.documentTypes),r=ke(i=>i.saveDocument);return x.useCallback(i=>{var h;if(i.length===0)return{ok:!0,name:e};if(!e)return{ok:!1,error:"No active file"};if(n[e]==="application/json+theme")return{ok:!1,error:"Custom fonts are registered on the document, not the theme. Open the .docx.json / .pptx.json tab and try again."};const s=t.find(p=>p.name===e);if(!s)return{ok:!1,error:"Active document not found"};const o=Ja(e,s.text);let a;try{a=JSON.parse(o)}catch(p){return{ok:!1,error:`Active document is not valid JSON: ${p.message}`}}const l=gw((h=a==null?void 0:a.props)==null?void 0:h.fontRegistry,i),u=Np(a,["props","fontRegistry"],l),d=JSON.stringify(u,null,2),f=yw(d);return f?{ok:!1,error:f}:(r(e,d),{ok:!0,name:e})},[e,t,n,r])}function Nw(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 xc(e){return e.map((t,n)=>typeof t=="number"?`[${t}]`:n===0?t:`.${t}`).join("")}const Ew=({open:e,onOpenChange:t})=>{const n=Gi(I=>I.open),r=Gi(I=>I.contextual),i=Gi(I=>I.close),s=e??n,o=r,a=x.useCallback(I=>{t&&t(I),I||i()},[t,i]),[l,u]=x.useState(kw),[d,f]=x.useState(!1),[h,p]=x.useState(""),[g,k]=x.useState("safe"),[S,y]=x.useState(null),[j,m]=x.useState(null),[A,C]=x.useState(!1),[v,w]=x.useState(!1),[O,B]=x.useState(""),[N,R]=x.useState([]),T=x.useRef(null),{toast:F}=Cr(),z=Sw(),M=jw(),D=_w(),J=ke(I=>I.activeTab),Z=ke(I=>I.documentTypes),X=J&&Z[J]==="application/json+theme",_=!!o||X;x.useEffect(()=>{s&&(l.safe.length>0||l.google.length>0||(f(!0),fetch(ui.fonts.catalog).then(I=>I.json()).then(I=>u(I)).catch(I=>{F({variant:"destructive",title:"Font catalog unavailable",description:I.message})}).finally(()=>f(!1))))},[s,l,F]),x.useEffect(()=>{if(!(g!=="google"||l.google.length===0))for(const I of l.google)gc(I.family,I.weights)},[g,l]);const ye=x.useMemo(()=>l.safe.filter(I=>I.toLowerCase().includes(h.toLowerCase())),[l.safe,h]),ce=x.useMemo(()=>l.google.filter(I=>I.family.toLowerCase().includes(h.toLowerCase())),[l.google,h]),b=x.useCallback(async I=>{try{await navigator.clipboard.writeText(I),m(I),setTimeout(()=>m(null),1500)}catch{F({variant:"destructive",title:"Copy failed",description:"Your browser blocked clipboard write."})}},[F]),G=x.useCallback(async(I,re,ae)=>{y(I);try{const H=z(K=>(Nw(K,ae,I),K));if(!H.ok){F({variant:"destructive",title:"Could not insert font",description:H.error});return}F({title:"Font inserted",description:`${I} set as ${ae} font in "${H.name}".`})}finally{y(null)}},[z,F]),ne=x.useCallback(async I=>{if(o){y(I);try{const re=M(o.jsonPath,I);if(!re.ok){F({variant:"destructive",title:"Could not insert font",description:re.error});return}F({title:"Font inserted",description:`${I} set at ${xc(o.jsonPath)}.`}),a(!1)}finally{y(null)}}},[o,M,F,a]),Q=x.useCallback(async I=>{if(!(!I||I.length===0)){C(!0);try{const re=[];for(const H of Array.from(I)){const K=new Uint8Array(await H.arrayBuffer()),pe=uw(H.name,K);if(!pe.ok){F({variant:"destructive",title:"Font rejected",description:pe.message});continue}re.push({identity:fw(H.name),base64:pe.base64})}if(re.length===0)return;const ae=D(re.map(({identity:H,base64:K})=>({id:H.family,family:H.family,sources:[{kind:"data",data:K,weight:H.weight,italic:H.italic}]})));if(!ae.ok){F({variant:"destructive",title:"Could not register font",description:ae.error});return}for(const{identity:H,base64:K}of re)ww(H.family,K,H.weight,H.italic),F({title:`Added ${H.family}`,description:`Registered at weight ${H.weight}${H.italic?" italic":""} in props.fontRegistry. Reference it as "${H.family}".`})}catch(re){F({variant:"destructive",title:"Upload failed",description:re.message})}finally{C(!1),T.current&&(T.current.value="")}}},[D,F]),oe=x.useCallback(async()=>{var re,ae;const I=O.trim();if(I){w(!0),R([]);try{const H=await fetch(ui.fonts.materialize,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({family:I,weights:[400,700],italics:!1})});if(H.status===429)throw new Error("Too many font fetches — the playground allows 20 every 15 minutes. Try again shortly.");if(!H.ok){const Oe=await H.json().catch(()=>({}));throw new Error(Oe.error??`Materialize failed (${H.status})`)}const K=await H.json();R(K.warnings??[]);const pe=(re=l.google.find(Oe=>Oe.family.toLowerCase()===K.family.toLowerCase()))==null?void 0:re.category,fe=xw(K,pe);if(!fe){F({variant:"destructive",title:"Nothing to embed",description:((ae=K.warnings)==null?void 0:ae.join(" · "))||`Google Fonts has no family named "${I}".`});return}const Re=D([fe]);if(!Re.ok){F({variant:"destructive",title:"Could not register font",description:Re.error});return}gc(K.family,[400,700]),F({title:`Added ${K.family}`,description:`Embedded ${fe.sources.length} weight(s) in props.fontRegistry.`})}catch(H){F({variant:"destructive",title:"Google Fonts fetch failed",description:H.message})}finally{w(!1)}}},[O,l.google,D,F]);return c.jsx(ct,{open:s,onOpenChange:a,children:c.jsxs(lt,{className:"max-w-4xl max-h-[90vh] overflow-hidden flex flex-col",children:[c.jsx(qt,{children:c.jsx(Gt,{children:o?`Font for ${xc(o.jsonPath)}`:"Fonts"})}),!o&&!X&&g!=="custom"&&c.jsx(ur,{children:c.jsxs(dr,{children:["Fonts are registered on themes. Open a ",c.jsx("code",{children:".theme.json"})," ","file to apply a font — the buttons below are disabled until you do."]})}),c.jsxs(_p,{value:g,onValueChange:I=>k(I),className:"flex-1 overflow-hidden flex flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs(Ua,{children:[c.jsxs(hr,{value:"safe",children:["Safe",c.jsx(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.safe.length})]}),c.jsxs(hr,{value:"google",children:["Google",c.jsx(tn,{variant:"secondary",className:"ml-1 text-xs px-1 py-0",children:l.google.length})]}),c.jsx(hr,{value:"custom",children:"Custom"})]}),c.jsx(wr,{type:"search",placeholder:"Search fonts...",value:h,onChange:I=>p(I.target.value),className:"ml-auto max-w-xs"})]}),c.jsxs("div",{className:"flex-1 overflow-auto mt-4 pr-2",children:[c.jsx(mr,{value:"safe",className:"m-0",children:d&&ye.length===0?c.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[c.jsx(Gr,{className:"animate-spin mr-2"})," Loading catalog..."]}):c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ye.map(I=>c.jsx(yc,{family:I,meta:c.jsx("span",{className:"text-xs",children:"Installed with Office"}),previewStyle:{fontFamily:`"${I}", sans-serif`},onCopy:()=>b(I),copied:j===I,contextual:!!o,onUseThis:()=>ne(I),onInsertHeading:()=>G(I,"safe","heading"),onInsertBody:()=>G(I,"safe","body"),applying:S===I,disabled:!_},I))})}),c.jsx(mr,{value:"google",className:"m-0",children:d&&ce.length===0?c.jsxs("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[c.jsx(Gr,{className:"animate-spin mr-2"})," Loading catalog..."]}):c.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:ce.map(I=>c.jsx(yc,{family:I.family,meta:c.jsxs("span",{className:"text-xs",children:[I.category," · ",I.weights.length," weights"]}),previewStyle:{fontFamily:`"${I.family}", sans-serif`},onCopy:()=>b(I.family),copied:j===I.family,contextual:!!o,onUseThis:()=>ne(I.family),onInsertHeading:()=>G(I.family,"google","heading"),onInsertBody:()=>G(I.family,"google","body"),applying:S===I.family,disabled:!_,extraAction:c.jsx(Tw,{family:I.family,weights:I.weights,hasItalic:I.hasItalic})},I.family))})}),c.jsx(mr,{value:"custom",className:"m-0 flex flex-col gap-6",children:X?c.jsx(ur,{children:c.jsxs(dr,{children:["Custom fonts are stored on the document (",c.jsx("code",{children:"props.fontRegistry"}),"), because the bytes travel with the JSON. Open a document tab to add one."]})}):c.jsxs(c.Fragment,{children:[c.jsxs("section",{className:"flex flex-col gap-2",children:[c.jsx("h3",{className:"text-sm font-medium",children:"Upload a font file"}),c.jsxs("p",{className:"text-xs text-muted-foreground",children:["TTF or OTF, up to 2 MB each. The font is embedded in the document as base64, so it survives export and re-import — and renders in the preview. The family and weight are guessed from the filename (e.g."," ",c.jsx("code",{children:"Geist-SemiBold.ttf"}),")."]}),c.jsxs("div",{onDragOver:I=>I.preventDefault(),onDrop:I=>{I.preventDefault(),Q(I.dataTransfer.files)},className:"rounded-md border border-dashed p-6 text-center",children:[c.jsx("input",{ref:T,type:"file",accept:".ttf,.otf,font/ttf,font/otf",multiple:!0,className:"hidden",onChange:I=>void Q(I.target.files)}),c.jsxs(Ee,{variant:"secondary",disabled:A,onClick:()=>{var I;return(I=T.current)==null?void 0:I.click()},children:[A?c.jsx(Gr,{className:"animate-spin mr-2 h-4 w-4"}):c.jsx(Mx,{className:"mr-2 h-4 w-4"}),"Choose font files"]}),c.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"or drop them here"})]})]}),c.jsxs("section",{className:"flex flex-col gap-2",children:[c.jsx("h3",{className:"text-sm font-medium",children:"Embed any Google font"}),c.jsxs("p",{className:"text-xs text-muted-foreground",children:["Not limited to the ",l.google.length," curated families — type any Google Fonts family name and its regular and bold weights are fetched and embedded."]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx(wr,{placeholder:"e.g. Geist",value:O,onChange:I=>B(I.target.value),onKeyDown:I=>{I.key==="Enter"&&oe()}}),c.jsxs(Ee,{onClick:()=>void oe(),disabled:v||O.trim()==="",children:[v&&c.jsx(Gr,{className:"animate-spin mr-2 h-4 w-4"}),"Embed"]})]}),N.length>0&&c.jsx(ur,{children:c.jsx(dr,{className:"text-xs",children:N.join(" · ")})})]})]})})]})]})]})})},Cw="The quick brown fox jumps over the lazy dog",Tw=({family:e,weights:t,hasItalic:n})=>{const r=x.useMemo(()=>[...t].sort((i,s)=>i-s),[t]);return c.jsxs(Ti,{children:[c.jsx(Ii,{asChild:!0,children:c.jsx(Ee,{size:"sm",variant:"ghost","aria-label":"Show variants",children:"Variants"})}),c.jsxs(Ar,{align:"end",className:"min-w-[260px]",children:[c.jsxs($a,{className:"text-xs text-muted-foreground",children:[r.length," weight",r.length===1?"":"s",n?" · italic available":""]}),c.jsx(Fn,{}),r.map(i=>{const s=gd[i]??String(i);return c.jsxs("div",{className:"flex flex-col gap-0.5 px-2 py-1.5",children:[c.jsx("span",{className:"truncate",style:{fontFamily:`"${e}", sans-serif`,fontWeight:i},children:s}),c.jsxs("span",{className:"text-xs text-muted-foreground font-mono",children:["fontWeight: ",i]})]},i)})]})]})},yc=({family:e,meta:t,previewStyle:n,onCopy:r,copied:i,contextual:s,onUseThis:o,onInsertHeading:a,onInsertBody:l,applying:u,disabled:d,extraAction:f})=>c.jsxs("div",{className:"border rounded-md p-3 flex flex-col gap-2 bg-card",children:[c.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[c.jsx("div",{className:"font-medium truncate",children:e}),c.jsx("div",{className:"text-muted-foreground",children:t})]}),c.jsx("div",{className:"text-lg truncate",style:n,"aria-hidden":!0,children:Cw}),c.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[s?c.jsx(Ee,{size:"sm",onClick:o,disabled:u||d,"aria-label":`Use ${e} at the target path`,children:"Use this font"}):c.jsxs(c.Fragment,{children:[c.jsx(Ee,{size:"sm",variant:"secondary",onClick:a,disabled:u||d,"aria-label":`Set ${e} as heading font`,children:"Set heading"}),c.jsx(Ee,{size:"sm",variant:"secondary",onClick:l,disabled:u||d,"aria-label":`Set ${e} as body font`,children:"Set body"})]}),f,c.jsx(Ee,{size:"sm",variant:"ghost",className:"ml-auto",onClick:r,"aria-label":`Copy ${e}`,children:i?c.jsx(un,{className:"h-4 w-4"}):c.jsx(zs,{className:"h-4 w-4"})})]})]});function bc({previewOpen:e,onTogglePreview:t}){const n=an(v=>v.name||""),r=an(v=>v.blob),i=an(v=>v.isGenerating),s=an(v=>v.text),o=an(v=>v.warnings),a=an(v=>v.isRendering),l=yr(v=>v.useGlobalPreviewHeader??!0),u=ke(v=>v.activeTab),d=ke(v=>v.documentTypes),f=u&&d[u]==="application/json+theme"?"theme":"document",h=ke(v=>{var w;return v.activeTab&&(v.documentTypes[v.activeTab]??"application/json+report")==="application/json+report"?(w=v.documents.find(O=>O.name===v.activeTab))==null?void 0:w.text:void 0}),p=ke(v=>v.activeTab&&(v.documentTypes[v.activeTab]??"application/json+report")==="application/json+report"?v.activeTab:void 0),g=De(v=>v.chatOpen),k=De(v=>v.toggleChat),[S,y]=je.useState(!1),j=Gi(v=>v.openFor);if(!l)return null;const m=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:manualRender"))},[]),A=x.useCallback(()=>{window.dispatchEvent(new CustomEvent("preview:showCacheMetrics"))},[]),C=(n==null?void 0:n.trim())||"Preview";return c.jsxs("div",{className:"sticky top-0 z-20",children:[c.jsx(rw,{name:C,blob:r,onManualRender:m,isGenerating:i,isRendering:!!a,onShowCacheMetrics:A,onShowSchemas:()=>y(!0),onShowFonts:()=>j(),documentText:s,editorDocumentText:h,editorDocumentName:p,warnings:o,onToggleChat:k,chatOpen:g,onTogglePreview:t,previewOpen:e}),c.jsx(aw,{open:S,onOpenChange:y,defaultTab:f==="theme"?"theme":"document"}),c.jsx(Ew,{})]})}function Iw(e,t){const n={};return(e[e.length-1]===""?[...e,""]:e).join((n.padRight?" ":"")+","+(n.padLeft===!1?"":" ")).trim()}const Aw=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,zw=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Ow={};function vc(e,t){return(Ow.jsx?zw:Aw).test(e)}const Pw=/[ \t\n\f\r]/g;function Dw(e){return typeof e=="object"?e.type==="text"?wc(e.value):!1:wc(e)}function wc(e){return e.replace(Pw,"")===""}class Ai{constructor(t,n,r){this.normal=n,this.property=t,r&&(this.space=r)}}Ai.prototype.normal={};Ai.prototype.property={};Ai.prototype.space=void 0;function Ep(e,t){const n={},r={};for(const i of e)Object.assign(n,i.property),Object.assign(r,i.normal);return new Ai(n,r,t)}function Qo(e){return e.toLowerCase()}class _t{constructor(t,n){this.attribute=n,this.property=t}}_t.prototype.attribute="";_t.prototype.booleanish=!1;_t.prototype.boolean=!1;_t.prototype.commaOrSpaceSeparated=!1;_t.prototype.commaSeparated=!1;_t.prototype.defined=!1;_t.prototype.mustUseProperty=!1;_t.prototype.number=!1;_t.prototype.overloadedBoolean=!1;_t.prototype.property="";_t.prototype.spaceSeparated=!1;_t.prototype.space=void 0;let Rw=0;const Ne=Zn(),rt=Zn(),ea=Zn(),te=Zn(),Ze=Zn(),gr=Zn(),Et=Zn();function Zn(){return 2**++Rw}const ta=Object.freeze(Object.defineProperty({__proto__:null,boolean:Ne,booleanish:rt,commaOrSpaceSeparated:Et,commaSeparated:gr,number:te,overloadedBoolean:ea,spaceSeparated:Ze},Symbol.toStringTag,{value:"Module"})),fo=Object.keys(ta);class Ha extends _t{constructor(t,n,r,i){let s=-1;if(super(t,n),kc(this,"space",i),typeof r=="number")for(;++s<fo.length;){const o=fo[s];kc(this,fo[s],(r&ta[o])===ta[o])}}}Ha.prototype.defined=!0;function kc(e,t,n){n&&(e[t]=n)}function zr(e){const t={},n={};for(const[r,i]of Object.entries(e.properties)){const s=new Ha(r,e.transform(e.attributes||{},r),i,e.space);e.mustUseProperty&&e.mustUseProperty.includes(r)&&(s.mustUseProperty=!0),t[r]=s,n[Qo(r)]=r,n[Qo(s.attribute)]=r}return new Ai(t,n,e.space)}const Cp=zr({properties:{ariaActiveDescendant:null,ariaAtomic:rt,ariaAutoComplete:null,ariaBusy:rt,ariaChecked:rt,ariaColCount:te,ariaColIndex:te,ariaColSpan:te,ariaControls:Ze,ariaCurrent:null,ariaDescribedBy:Ze,ariaDetails:null,ariaDisabled:rt,ariaDropEffect:Ze,ariaErrorMessage:null,ariaExpanded:rt,ariaFlowTo:Ze,ariaGrabbed:rt,ariaHasPopup:null,ariaHidden:rt,ariaInvalid:null,ariaKeyShortcuts:null,ariaLabel:null,ariaLabelledBy:Ze,ariaLevel:te,ariaLive:null,ariaModal:rt,ariaMultiLine:rt,ariaMultiSelectable:rt,ariaOrientation:null,ariaOwns:Ze,ariaPlaceholder:null,ariaPosInSet:te,ariaPressed:rt,ariaReadOnly:rt,ariaRelevant:null,ariaRequired:rt,ariaRoleDescription:Ze,ariaRowCount:te,ariaRowIndex:te,ariaRowSpan:te,ariaSelected:rt,ariaSetSize:te,ariaSort:null,ariaValueMax:te,ariaValueMin:te,ariaValueNow:te,ariaValueText:null,role:null},transform(e,t){return t==="role"?t:"aria-"+t.slice(4).toLowerCase()}});function Tp(e,t){return t in e?e[t]:t}function Ip(e,t){return Tp(e,t.toLowerCase())}const $w=zr({attributes:{acceptcharset:"accept-charset",classname:"class",htmlfor:"for",httpequiv:"http-equiv"},mustUseProperty:["checked","multiple","muted","selected"],properties:{abbr:null,accept:gr,acceptCharset:Ze,accessKey:Ze,action:null,allow:null,allowFullScreen:Ne,allowPaymentRequest:Ne,allowUserMedia:Ne,alt:null,as:null,async:Ne,autoCapitalize:null,autoComplete:Ze,autoFocus:Ne,autoPlay:Ne,blocking:Ze,capture:null,charSet:null,checked:Ne,cite:null,className:Ze,cols:te,colSpan:null,content:null,contentEditable:rt,controls:Ne,controlsList:Ze,coords:te|gr,crossOrigin:null,data:null,dateTime:null,decoding:null,default:Ne,defer:Ne,dir:null,dirName:null,disabled:Ne,download:ea,draggable:rt,encType:null,enterKeyHint:null,fetchPriority:null,form:null,formAction:null,formEncType:null,formMethod:null,formNoValidate:Ne,formTarget:null,headers:Ze,height:te,hidden:ea,high:te,href:null,hrefLang:null,htmlFor:Ze,httpEquiv:Ze,id:null,imageSizes:null,imageSrcSet:null,inert:Ne,inputMode:null,integrity:null,is:null,isMap:Ne,itemId:null,itemProp:Ze,itemRef:Ze,itemScope:Ne,itemType:Ze,kind:null,label:null,lang:null,language:null,list:null,loading:null,loop:Ne,low:te,manifest:null,max:null,maxLength:te,media:null,method:null,min:null,minLength:te,multiple:Ne,muted:Ne,name:null,nonce:null,noModule:Ne,noValidate:Ne,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:Ne,optimum:te,pattern:null,ping:Ze,placeholder:null,playsInline:Ne,popover:null,popoverTarget:null,popoverTargetAction:null,poster:null,preload:null,readOnly:Ne,referrerPolicy:null,rel:Ze,required:Ne,reversed:Ne,rows:te,rowSpan:te,sandbox:Ze,scope:null,scoped:Ne,seamless:Ne,selected:Ne,shadowRootClonable:Ne,shadowRootDelegatesFocus:Ne,shadowRootMode:null,shape:null,size:te,sizes:null,slot:null,span:te,spellCheck:rt,src:null,srcDoc:null,srcLang:null,srcSet:null,start:te,step:null,style:null,tabIndex:te,target:null,title:null,translate:null,type:null,typeMustMatch:Ne,useMap:null,value:rt,width:te,wrap:null,writingSuggestions:null,align:null,aLink:null,archive:Ze,axis:null,background:null,bgColor:null,border:te,borderColor:null,bottomMargin:te,cellPadding:null,cellSpacing:null,char:null,charOff:null,classId:null,clear:null,code:null,codeBase:null,codeType:null,color:null,compact:Ne,declare:Ne,event:null,face:null,frame:null,frameBorder:null,hSpace:te,leftMargin:te,link:null,longDesc:null,lowSrc:null,marginHeight:te,marginWidth:te,noResize:Ne,noHref:Ne,noShade:Ne,noWrap:Ne,object:null,profile:null,prompt:null,rev:null,rightMargin:te,rules:null,scheme:null,scrolling:rt,standby:null,summary:null,text:null,topMargin:te,valueType:null,version:null,vAlign:null,vLink:null,vSpace:te,allowTransparency:null,autoCorrect:null,autoSave:null,disablePictureInPicture:Ne,disableRemotePlayback:Ne,prefix:null,property:null,results:te,security:null,unselectable:null},space:"html",transform:Ip}),Mw=zr({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:Et,accentHeight:te,accumulate:null,additive:null,alignmentBaseline:null,alphabetic:te,amplitude:te,arabicForm:null,ascent:te,attributeName:null,attributeType:null,azimuth:te,bandwidth:null,baselineShift:null,baseFrequency:null,baseProfile:null,bbox:null,begin:null,bias:te,by:null,calcMode:null,capHeight:te,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:te,diffuseConstant:te,direction:null,display:null,dur:null,divisor:te,dominantBaseline:null,download:Ne,dx:null,dy:null,edgeMode:null,editable:null,elevation:te,enableBackground:null,end:null,event:null,exponent:te,externalResourcesRequired:null,fill:null,fillOpacity:te,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:gr,g2:gr,glyphName:gr,glyphOrientationHorizontal:null,glyphOrientationVertical:null,glyphRef:null,gradientTransform:null,gradientUnits:null,handler:null,hanging:te,hatchContentUnits:null,hatchUnits:null,height:null,href:null,hrefLang:null,horizAdvX:te,horizOriginX:te,horizOriginY:te,id:null,ideographic:te,imageRendering:null,initialVisibility:null,in:null,in2:null,intercept:te,k:te,k1:te,k2:te,k3:te,k4:te,kernelMatrix:Et,kernelUnitLength:null,keyPoints:null,keySplines:null,keyTimes:null,kerning:null,lang:null,lengthAdjust:null,letterSpacing:null,lightingColor:null,limitingConeAngle:te,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:te,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:te,overlineThickness:te,paintOrder:null,panose1:null,path:null,pathLength:te,patternContentUnits:null,patternTransform:null,patternUnits:null,phase:null,ping:Ze,pitch:null,playbackOrder:null,pointerEvents:null,points:null,pointsAtX:te,pointsAtY:te,pointsAtZ:te,preserveAlpha:null,preserveAspectRatio:null,primitiveUnits:null,propagate:null,property:Et,r:null,radius:null,referrerPolicy:null,refX:null,refY:null,rel:Et,rev:Et,renderingIntent:null,repeatCount:null,repeatDur:null,requiredExtensions:Et,requiredFeatures:Et,requiredFonts:Et,requiredFormats:Et,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:te,specularExponent:te,spreadMethod:null,spacing:null,startOffset:null,stdDeviation:null,stemh:null,stemv:null,stitchTiles:null,stopColor:null,stopOpacity:null,strikethroughPosition:te,strikethroughThickness:te,string:null,stroke:null,strokeDashArray:Et,strokeDashOffset:null,strokeLineCap:null,strokeLineJoin:null,strokeMiterLimit:te,strokeOpacity:te,strokeWidth:null,style:null,surfaceScale:te,syncBehavior:null,syncBehaviorDefault:null,syncMaster:null,syncTolerance:null,syncToleranceDefault:null,systemLanguage:Et,tabIndex:te,tableValues:null,target:null,targetX:te,targetY:te,textAnchor:null,textDecoration:null,textRendering:null,textLength:null,timelineBegin:null,title:null,transformBehavior:null,type:null,typeOf:Et,to:null,transform:null,transformOrigin:null,u1:null,u2:null,underlinePosition:te,underlineThickness:te,unicode:null,unicodeBidi:null,unicodeRange:null,unitsPerEm:te,values:null,vAlphabetic:te,vMathematical:te,vectorEffect:null,vHanging:te,vIdeographic:te,version:null,vertAdvY:te,vertOriginX:te,vertOriginY:te,viewBox:null,viewTarget:null,visibility:null,width:null,widths:null,wordSpacing:null,writingMode:null,x:null,x1:null,x2:null,xChannelSelector:null,xHeight:te,y:null,y1:null,y2:null,yChannelSelector:null,z:null,zoomAndPan:null},space:"svg",transform:Tp}),Ap=zr({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()}}),zp=zr({attributes:{xmlnsxlink:"xmlns:xlink"},properties:{xmlnsXLink:null,xmlns:null},space:"xmlns",transform:Ip}),Op=zr({properties:{xmlBase:null,xmlLang:null,xmlSpace:null},space:"xml",transform(e,t){return"xml:"+t.slice(3).toLowerCase()}}),Fw={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"},Lw=/[A-Z]/g,Sc=/-[a-z]/g,Bw=/^data[-\w.:]+$/i;function Vw(e,t){const n=Qo(t);let r=t,i=_t;if(n in e.normal)return e.property[e.normal[n]];if(n.length>4&&n.slice(0,4)==="data"&&Bw.test(t)){if(t.charAt(4)==="-"){const s=t.slice(5).replace(Sc,Uw);r="data"+s.charAt(0).toUpperCase()+s.slice(1)}else{const s=t.slice(4);if(!Sc.test(s)){let o=s.replace(Lw,Zw);o.charAt(0)!=="-"&&(o="-"+o),t="data"+o}}i=Ha}return new i(r,t)}function Zw(e){return"-"+e.toLowerCase()}function Uw(e){return e.charAt(1).toUpperCase()}const Jw=Ep([Cp,$w,Ap,zp,Op],"html"),Wa=Ep([Cp,Mw,Ap,zp,Op],"svg");function Hw(e){return e.join(" ").trim()}var Yn={},po,jc;function Ww(){if(jc)return po;jc=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=`
155
- `,u="/",d="*",f="",h="comment",p="declaration";function g(S,y){if(typeof S!="string")throw new TypeError("First argument must be a string");if(!S)return[];y=y||{};var j=1,m=1;function A(z){var M=z.match(t);M&&(j+=M.length);var D=z.lastIndexOf(l);m=~D?z.length-D:m+z.length}function C(){var z={line:j,column:m};return function(M){return M.position=new v(z),B(),M}}function v(z){this.start=z,this.end={line:j,column:m},this.source=y.source}v.prototype.content=S;function w(z){var M=new Error(y.source+":"+j+":"+m+": "+z);if(M.reason=z,M.filename=y.source,M.line=j,M.column=m,M.source=S,!y.silent)throw M}function O(z){var M=z.exec(S);if(M){var D=M[0];return A(D),S=S.slice(D.length),M}}function B(){O(n)}function N(z){var M;for(z=z||[];M=R();)M!==!1&&z.push(M);return z}function R(){var z=C();if(!(u!=S.charAt(0)||d!=S.charAt(1))){for(var M=2;f!=S.charAt(M)&&(d!=S.charAt(M)||u!=S.charAt(M+1));)++M;if(M+=2,f===S.charAt(M-1))return w("End of comment missing");var D=S.slice(2,M-2);return m+=2,A(D),S=S.slice(M),m+=2,z({type:h,comment:D})}}function T(){var z=C(),M=O(r);if(M){if(R(),!O(i))return w("property missing ':'");var D=O(s),J=z({type:p,property:k(M[0].replace(e,f)),value:D?k(D[0].replace(e,f)):f});return O(o),J}}function F(){var z=[];N(z);for(var M;M=T();)M!==!1&&(z.push(M),N(z));return z}return B(),F()}function k(S){return S?S.replace(a,f):f}return po=g,po}var _c;function qw(){if(_c)return Yn;_c=1;var e=Yn&&Yn.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Yn,"__esModule",{value:!0}),Yn.default=n;const t=e(Ww());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:u,value:d}=l;a?i(u,d,l):d&&(s=s||{},s[u]=d)}),s}return Yn}var Ur={},Nc;function Gw(){if(Nc)return Ur;Nc=1,Object.defineProperty(Ur,"__esModule",{value:!0}),Ur.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(u){return!u||n.test(u)||e.test(u)},o=function(u,d){return d.toUpperCase()},a=function(u,d){return"".concat(d,"-")},l=function(u,d){return d===void 0&&(d={}),s(u)?u:(u=u.toLowerCase(),d.reactCompat?u=u.replace(i,a):u=u.replace(r,a),u.replace(t,o))};return Ur.camelCase=l,Ur}var Jr,Ec;function Kw(){if(Ec)return Jr;Ec=1;var e=Jr&&Jr.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(qw()),n=Gw();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,Jr=r,Jr}var Yw=Kw();const Xw=wa(Yw),Pp=Dp("end"),qa=Dp("start");function Dp(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function Qw(e){const t=qa(e),n=Pp(e);if(t&&n)return{start:t,end:n}}function ai(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?Cc(e.position):"start"in e||"end"in e?Cc(e):"line"in e||"column"in e?na(e):""}function na(e){return Tc(e&&e.line)+":"+Tc(e&&e.column)}function Cc(e){return na(e&&e.start)+"-"+na(e&&e.end)}function Tc(e){return e&&typeof e=="number"?e:1}class dt 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=ai(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}}dt.prototype.file="";dt.prototype.name="";dt.prototype.reason="";dt.prototype.message="";dt.prototype.stack="";dt.prototype.column=void 0;dt.prototype.line=void 0;dt.prototype.ancestors=void 0;dt.prototype.cause=void 0;dt.prototype.fatal=void 0;dt.prototype.place=void 0;dt.prototype.ruleId=void 0;dt.prototype.source=void 0;const Ga={}.hasOwnProperty,e0=new Map,t0=/[A-Z]/g,n0=new Set(["table","tbody","thead","tfoot","tr"]),r0=new Set(["td","th"]),Rp="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function i0(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=f0(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=d0(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"?Wa:Jw,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=$p(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function $p(e,t,n){if(t.type==="element")return s0(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return o0(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return l0(e,t,n);if(t.type==="mdxjsEsm")return a0(e,t);if(t.type==="root")return c0(e,t,n);if(t.type==="text")return u0(e,t)}function s0(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=Wa,e.schema=i),e.ancestors.push(t);const s=Fp(e,t.tagName,!1),o=p0(e,t);let a=Ya(e,t);return n0.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!Dw(l):!0})),Mp(e,o,s,t),Ka(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function o0(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)}yi(e,t.position)}function a0(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);yi(e,t.position)}function l0(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=Wa,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:Fp(e,t.name,!0),o=h0(e,t),a=Ya(e,t);return Mp(e,o,s,t),Ka(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function c0(e,t,n){const r={};return Ka(r,Ya(e,t)),e.create(t,e.Fragment,r,n)}function u0(e,t){return t.value}function Mp(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Ka(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function d0(e,t,n){return r;function r(i,s,o,a){const u=Array.isArray(o.children)?n:t;return a?u(s,o,a):u(s,o)}}function f0(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),l=qa(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 p0(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&Ga.call(t.properties,i)){const s=m0(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&r0.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 h0(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 yi(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 yi(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function Ya(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:e0;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 u=i.get(l)||0;o=l+"-"+u,i.set(l,u+1)}}const a=$p(e,s,o);a!==void 0&&n.push(a)}return n}function m0(e,t,n){const r=Vw(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?Iw(n):Hw(n)),r.property==="style"){let i=typeof n=="object"?n:g0(e,String(n));return e.stylePropertyNameCase==="css"&&(i=x0(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?Fw[r.property]||r.property:r.attribute,n]}}function g0(e,t){try{return Xw(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new dt("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=Rp+"#cannot-parse-style-attribute",i}}function Fp(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,o;for(;++s<i.length;){const a=vc(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=vc(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return Ga.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);yi(e)}function yi(e,t){const n=new dt("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=Rp+"#cannot-handle-mdx-estrees-without-createevaluater",n}function x0(e){const t={};let n;for(n in e)Ga.call(e,n)&&(t[y0(n)]=e[n]);return t}function y0(e){let t=e.replace(t0,b0);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function b0(e){return"-"+e.toLowerCase()}const ho={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"]},v0={};function Xa(e,t){const n=v0,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Lp(e,r,i)}function Lp(e,t,n){if(w0(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 Ic(e.children,t,n)}return Array.isArray(e)?Ic(e,t,n):""}function Ic(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=Lp(e[i],t,n);return r.join("")}function w0(e){return!!(e&&typeof e=="object")}const Ac=document.createElement("i");function Qa(e){const t="&"+e+";";Ac.innerHTML=t;const n=Ac.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function At(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 Mt(e,t){return e.length>0?(At(e,e.length,0,t),e):t}const zc={}.hasOwnProperty;function Bp(e){const t={};let n=-1;for(;++n<e.length;)k0(t,e[n]);return t}function k0(e,t){let n;for(n in t){const i=(zc.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){zc.call(i,o)||(i[o]=[]);const a=s[o];S0(i[o],Array.isArray(a)?a:a?[a]:[])}}}function S0(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);At(e,0,0,r)}function Vp(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 Wt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const xt=_n(/[A-Za-z]/),ut=_n(/[\dA-Za-z]/),j0=_n(/[#-'*+\--9=?A-Z^-~]/);function ms(e){return e!==null&&(e<32||e===127)}const ra=_n(/\d/),_0=_n(/[\dA-Fa-f]/),N0=_n(/[!-/:-@[-`{-~]/);function be(e){return e!==null&&e<-2}function Ve(e){return e!==null&&(e<0||e===32)}function Ie(e){return e===-2||e===-1||e===32}const Vs=_n(new RegExp("\\p{P}|\\p{S}","u")),Bn=_n(/\s/);function _n(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Or(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let o="";if(s===37&&ut(e.charCodeAt(n+1))&&ut(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 Pe(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 E0={tokenize:C0};function C0(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"),Pe(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 be(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const T0={tokenize:I0},Oc={tokenize:A0};function I0(e){const t=this,n=[];let r=0,i,s,o;return a;function a(m){if(r<n.length){const A=n[r];return t.containerState=A[1],e.attempt(A[0].continuation,l,u)(m)}return u(m)}function l(m){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&j();const A=t.events.length;let C=A,v;for(;C--;)if(t.events[C][0]==="exit"&&t.events[C][1].type==="chunkFlow"){v=t.events[C][1].end;break}y(r);let w=A;for(;w<t.events.length;)t.events[w][1].end={...v},w++;return At(t.events,C+1,0,t.events.slice(A)),t.events.length=w,u(m)}return a(m)}function u(m){if(r===n.length){if(!i)return h(m);if(i.currentConstruct&&i.currentConstruct.concrete)return g(m);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(Oc,d,f)(m)}function d(m){return i&&j(),y(r),h(m)}function f(m){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,g(m)}function h(m){return t.containerState={},e.attempt(Oc,p,g)(m)}function p(m){return r++,n.push([t.currentConstruct,t.containerState]),h(m)}function g(m){if(m===null){i&&j(),y(0),e.consume(m);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),k(m)}function k(m){if(m===null){S(e.exit("chunkFlow"),!0),y(0),e.consume(m);return}return be(m)?(e.consume(m),S(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(m),k)}function S(m,A){const C=t.sliceStream(m);if(A&&C.push(null),m.previous=s,s&&(s.next=m),s=m,i.defineSkip(m.start),i.write(C),t.parser.lazy[m.start.line]){let v=i.events.length;for(;v--;)if(i.events[v][1].start.offset<o&&(!i.events[v][1].end||i.events[v][1].end.offset>o))return;const w=t.events.length;let O=w,B,N;for(;O--;)if(t.events[O][0]==="exit"&&t.events[O][1].type==="chunkFlow"){if(B){N=t.events[O][1].end;break}B=!0}for(y(r),v=w;v<t.events.length;)t.events[v][1].end={...N},v++;At(t.events,O+1,0,t.events.slice(w)),t.events.length=v}}function y(m){let A=n.length;for(;A-- >m;){const C=n[A];t.containerState=C[1],C[0].exit.call(t,e)}n.length=m}function j(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function A0(e,t,n){return Pe(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function jr(e){if(e===null||Ve(e)||Bn(e))return 1;if(Vs(e))return 2}function Zs(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 ia={name:"attention",resolveAll:z0,tokenize:O0};function z0(e,t){let n=-1,r,i,s,o,a,l,u,d;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},h={...e[n][1].start};Pc(f,-l),Pc(h,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:h},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},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=Mt(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=Mt(u,[["enter",i,t],["enter",o,t],["exit",o,t],["enter",s,t]]),u=Mt(u,Zs(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=Mt(u,[["exit",s,t],["enter",a,t],["exit",a,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(d=2,u=Mt(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):d=0,At(e,r-1,n-r+3,u),n=r+u.length-d-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function O0(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=jr(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 u=e.exit("attentionSequence"),d=jr(l),f=!d||d===2&&i||n.includes(l),h=!i||i===2&&d||n.includes(r);return u._open=!!(s===42?f:f&&(i||!h)),u._close=!!(s===42?h:h&&(d||!f)),t(l)}}function Pc(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const P0={name:"autolink",tokenize:D0};function D0(e,t,n){let r=0;return i;function i(p){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(p){return xt(p)?(e.consume(p),o):p===64?n(p):u(p)}function o(p){return p===43||p===45||p===46||ut(p)?(r=1,a(p)):u(p)}function a(p){return p===58?(e.consume(p),r=0,l):(p===43||p===45||p===46||ut(p))&&r++<32?(e.consume(p),a):(r=0,u(p))}function l(p){return p===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):p===null||p===32||p===60||ms(p)?n(p):(e.consume(p),l)}function u(p){return p===64?(e.consume(p),d):j0(p)?(e.consume(p),u):n(p)}function d(p){return ut(p)?f(p):n(p)}function f(p){return p===46?(e.consume(p),r=0,d):p===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(p),e.exit("autolinkMarker"),e.exit("autolink"),t):h(p)}function h(p){if((p===45||ut(p))&&r++<63){const g=p===45?h:f;return e.consume(p),g}return n(p)}}const zi={partial:!0,tokenize:R0};function R0(e,t,n){return r;function r(s){return Ie(s)?Pe(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||be(s)?t(s):n(s)}}const Zp={continuation:{tokenize:M0},exit:F0,name:"blockQuote",tokenize:$0};function $0(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 M0(e,t,n){const r=this;return i;function i(o){return Ie(o)?Pe(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(Zp,t,n)(o)}}function F0(e){e.exit("blockQuote")}const Up={name:"characterEscape",tokenize:L0};function L0(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 N0(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const Jp={name:"characterReference",tokenize:B0};function B0(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"),u):(e.enter("characterReferenceValue"),s=31,o=ut,d(f))}function u(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,o=_0,d):(e.enter("characterReferenceValue"),s=7,o=ra,d(f))}function d(f){if(f===59&&i){const h=e.exit("characterReferenceValue");return o===ut&&!Qa(r.sliceSerialize(h))?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 Dc={partial:!0,tokenize:Z0},Rc={concrete:!0,name:"codeFenced",tokenize:V0};function V0(e,t,n){const r=this,i={partial:!0,tokenize:C};let s=0,o=0,a;return l;function l(v){return u(v)}function u(v){const w=r.events[r.events.length-1];return s=w&&w[1].type==="linePrefix"?w[2].sliceSerialize(w[1],!0).length:0,a=v,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),d(v)}function d(v){return v===a?(o++,e.consume(v),d):o<3?n(v):(e.exit("codeFencedFenceSequence"),Ie(v)?Pe(e,f,"whitespace")(v):f(v))}function f(v){return v===null||be(v)?(e.exit("codeFencedFence"),r.interrupt?t(v):e.check(Dc,k,A)(v)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),h(v))}function h(v){return v===null||be(v)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(v)):Ie(v)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),Pe(e,p,"whitespace")(v)):v===96&&v===a?n(v):(e.consume(v),h)}function p(v){return v===null||be(v)?f(v):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(v))}function g(v){return v===null||be(v)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(v)):v===96&&v===a?n(v):(e.consume(v),g)}function k(v){return e.attempt(i,A,S)(v)}function S(v){return e.enter("lineEnding"),e.consume(v),e.exit("lineEnding"),y}function y(v){return s>0&&Ie(v)?Pe(e,j,"linePrefix",s+1)(v):j(v)}function j(v){return v===null||be(v)?e.check(Dc,k,A)(v):(e.enter("codeFlowValue"),m(v))}function m(v){return v===null||be(v)?(e.exit("codeFlowValue"),j(v)):(e.consume(v),m)}function A(v){return e.exit("codeFenced"),t(v)}function C(v,w,O){let B=0;return N;function N(M){return v.enter("lineEnding"),v.consume(M),v.exit("lineEnding"),R}function R(M){return v.enter("codeFencedFence"),Ie(M)?Pe(v,T,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(M):T(M)}function T(M){return M===a?(v.enter("codeFencedFenceSequence"),F(M)):O(M)}function F(M){return M===a?(B++,v.consume(M),F):B>=o?(v.exit("codeFencedFenceSequence"),Ie(M)?Pe(v,z,"whitespace")(M):z(M)):O(M)}function z(M){return M===null||be(M)?(v.exit("codeFencedFence"),w(M)):O(M)}}}function Z0(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 mo={name:"codeIndented",tokenize:J0},U0={partial:!0,tokenize:H0};function J0(e,t,n){const r=this;return i;function i(u){return e.enter("codeIndented"),Pe(e,s,"linePrefix",5)(u)}function s(u){const d=r.events[r.events.length-1];return d&&d[1].type==="linePrefix"&&d[2].sliceSerialize(d[1],!0).length>=4?o(u):n(u)}function o(u){return u===null?l(u):be(u)?e.attempt(U0,o,l)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||be(u)?(e.exit("codeFlowValue"),o(u)):(e.consume(u),a)}function l(u){return e.exit("codeIndented"),t(u)}}function H0(e,t,n){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):be(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):Pe(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):be(o)?i(o):n(o)}}const W0={name:"codeText",previous:G0,resolve:q0,tokenize:K0};function q0(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 G0(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function K0(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)):be(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(f))}function u(f){return f===null||f===32||f===96||be(f)?(e.exit("codeTextData"),l(f)):(e.consume(f),u)}function d(f){return f===96?(e.consume(f),i++,d):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(s.type="codeTextData",u(f))}}class Y0{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&&Hr(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),Hr(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Hr(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);Hr(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Hr(this.left,n.reverse())}}}function Hr(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 Hp(e){const t={};let n=-1,r,i,s,o,a,l,u;const d=new Y0(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,X0(d,n)),n=t[n],u=!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 At(e,0,Number.POSITIVE_INFINITY,d.slice(0)),!u}function X0(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=[],u={};let d,f,h=-1,p=n,g=0,k=0;const S=[k];for(;p;){for(;e.get(++i)[1]!==p;);s.push(i),p._tokenizer||(d=r.sliceStream(p),p.next||d.push(null),f&&o.defineSkip(p.start),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(d),p._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),f=p,p=p.next}for(p=n;++h<a.length;)a[h][0]==="exit"&&a[h-1][0]==="enter"&&a[h][1].type===a[h-1][1].type&&a[h][1].start.line!==a[h][1].end.line&&(k=h+1,S.push(k),p._tokenizer=void 0,p.previous=void 0,p=p.next);for(o.events=[],p?(p._tokenizer=void 0,p.previous=void 0):S.pop(),h=S.length;h--;){const y=a.slice(S[h],S[h+1]),j=s.pop();l.push([j,j+y.length-1]),e.splice(j,2,y)}for(l.reverse(),h=-1;++h<l.length;)u[g+l[h][0]]=g+l[h][1],g+=l[h][1]-l[h][0]-1;return u}const Q0={resolve:tk,tokenize:nk},ek={partial:!0,tokenize:rk};function tk(e){return Hp(e),e}function nk(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):be(a)?e.check(ek,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 rk(e,t,n){const r=this;return i;function i(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),Pe(e,s,"linePrefix")}function s(o){if(o===null||be(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 Wp(e,t,n,r,i,s,o,a,l){const u=l||Number.POSITIVE_INFINITY;let d=0;return f;function f(y){return y===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(y),e.exit(s),h):y===null||y===32||y===41||ms(y)?n(y):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),k(y))}function h(y){return y===62?(e.enter(s),e.consume(y),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),p(y))}function p(y){return y===62?(e.exit("chunkString"),e.exit(a),h(y)):y===null||y===60||be(y)?n(y):(e.consume(y),y===92?g:p)}function g(y){return y===60||y===62||y===92?(e.consume(y),p):p(y)}function k(y){return!d&&(y===null||y===41||Ve(y))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(y)):d<u&&y===40?(e.consume(y),d++,k):y===41?(e.consume(y),d--,k):y===null||y===32||y===40||ms(y)?n(y):(e.consume(y),y===92?S:k)}function S(y){return y===40||y===41||y===92?(e.consume(y),k):k(y)}}function qp(e,t,n,r,i,s){const o=this;let a=0,l;return u;function u(p){return e.enter(r),e.enter(i),e.consume(p),e.exit(i),e.enter(s),d}function d(p){return a>999||p===null||p===91||p===93&&!l||p===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(p):p===93?(e.exit(s),e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):be(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),d):(e.enter("chunkString",{contentType:"string"}),f(p))}function f(p){return p===null||p===91||p===93||be(p)||a++>999?(e.exit("chunkString"),d(p)):(e.consume(p),l||(l=!Ie(p)),p===92?h:f)}function h(p){return p===91||p===92||p===93?(e.consume(p),a++,f):f(p)}}function Gp(e,t,n,r,i,s){let o;return a;function a(h){return h===34||h===39||h===40?(e.enter(r),e.enter(i),e.consume(h),e.exit(i),o=h===40?41:h,l):n(h)}function l(h){return h===o?(e.enter(i),e.consume(h),e.exit(i),e.exit(r),t):(e.enter(s),u(h))}function u(h){return h===o?(e.exit(s),l(o)):h===null?n(h):be(h)?(e.enter("lineEnding"),e.consume(h),e.exit("lineEnding"),Pe(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),d(h))}function d(h){return h===o||h===null||be(h)?(e.exit("chunkString"),u(h)):(e.consume(h),h===92?f:d)}function f(h){return h===o||h===92?(e.consume(h),d):d(h)}}function li(e,t){let n;return r;function r(i){return be(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):Ie(i)?Pe(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const ik={name:"definition",tokenize:ok},sk={partial:!0,tokenize:ak};function ok(e,t,n){const r=this;let i;return s;function s(p){return e.enter("definition"),o(p)}function o(p){return qp.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(p)}function a(p){return i=Wt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),p===58?(e.enter("definitionMarker"),e.consume(p),e.exit("definitionMarker"),l):n(p)}function l(p){return Ve(p)?li(e,u)(p):u(p)}function u(p){return Wp(e,d,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(p)}function d(p){return e.attempt(sk,f,f)(p)}function f(p){return Ie(p)?Pe(e,h,"whitespace")(p):h(p)}function h(p){return p===null||be(p)?(e.exit("definition"),r.parser.defined.push(i),t(p)):n(p)}}function ak(e,t,n){return r;function r(a){return Ve(a)?li(e,i)(a):n(a)}function i(a){return Gp(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return Ie(a)?Pe(e,o,"whitespace")(a):o(a)}function o(a){return a===null||be(a)?t(a):n(a)}}const lk={name:"hardBreakEscape",tokenize:ck};function ck(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return be(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const uk={name:"headingAtx",resolve:dk,tokenize:fk};function dk(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"},At(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function fk(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||Ve(d)?(e.exit("atxHeadingSequence"),a(d)):n(d)}function a(d){return d===35?(e.enter("atxHeadingSequence"),l(d)):d===null||be(d)?(e.exit("atxHeading"),t(d)):Ie(d)?Pe(e,a,"whitespace")(d):(e.enter("atxHeadingText"),u(d))}function l(d){return d===35?(e.consume(d),l):(e.exit("atxHeadingSequence"),a(d))}function u(d){return d===null||d===35||Ve(d)?(e.exit("atxHeadingText"),a(d)):(e.consume(d),u)}}const pk=["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"],$c=["pre","script","style","textarea"],hk={concrete:!0,name:"htmlFlow",resolveTo:xk,tokenize:yk},mk={partial:!0,tokenize:vk},gk={partial:!0,tokenize:bk};function xk(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 yk(e,t,n){const r=this;let i,s,o,a,l;return u;function u(b){return d(b)}function d(b){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(b),f}function f(b){return b===33?(e.consume(b),h):b===47?(e.consume(b),s=!0,k):b===63?(e.consume(b),i=3,r.interrupt?t:_):xt(b)?(e.consume(b),o=String.fromCharCode(b),S):n(b)}function h(b){return b===45?(e.consume(b),i=2,p):b===91?(e.consume(b),i=5,a=0,g):xt(b)?(e.consume(b),i=4,r.interrupt?t:_):n(b)}function p(b){return b===45?(e.consume(b),r.interrupt?t:_):n(b)}function g(b){const G="CDATA[";return b===G.charCodeAt(a++)?(e.consume(b),a===G.length?r.interrupt?t:T:g):n(b)}function k(b){return xt(b)?(e.consume(b),o=String.fromCharCode(b),S):n(b)}function S(b){if(b===null||b===47||b===62||Ve(b)){const G=b===47,ne=o.toLowerCase();return!G&&!s&&$c.includes(ne)?(i=1,r.interrupt?t(b):T(b)):pk.includes(o.toLowerCase())?(i=6,G?(e.consume(b),y):r.interrupt?t(b):T(b)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(b):s?j(b):m(b))}return b===45||ut(b)?(e.consume(b),o+=String.fromCharCode(b),S):n(b)}function y(b){return b===62?(e.consume(b),r.interrupt?t:T):n(b)}function j(b){return Ie(b)?(e.consume(b),j):N(b)}function m(b){return b===47?(e.consume(b),N):b===58||b===95||xt(b)?(e.consume(b),A):Ie(b)?(e.consume(b),m):N(b)}function A(b){return b===45||b===46||b===58||b===95||ut(b)?(e.consume(b),A):C(b)}function C(b){return b===61?(e.consume(b),v):Ie(b)?(e.consume(b),C):m(b)}function v(b){return b===null||b===60||b===61||b===62||b===96?n(b):b===34||b===39?(e.consume(b),l=b,w):Ie(b)?(e.consume(b),v):O(b)}function w(b){return b===l?(e.consume(b),l=null,B):b===null||be(b)?n(b):(e.consume(b),w)}function O(b){return b===null||b===34||b===39||b===47||b===60||b===61||b===62||b===96||Ve(b)?C(b):(e.consume(b),O)}function B(b){return b===47||b===62||Ie(b)?m(b):n(b)}function N(b){return b===62?(e.consume(b),R):n(b)}function R(b){return b===null||be(b)?T(b):Ie(b)?(e.consume(b),R):n(b)}function T(b){return b===45&&i===2?(e.consume(b),D):b===60&&i===1?(e.consume(b),J):b===62&&i===4?(e.consume(b),ye):b===63&&i===3?(e.consume(b),_):b===93&&i===5?(e.consume(b),X):be(b)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(mk,ce,F)(b)):b===null||be(b)?(e.exit("htmlFlowData"),F(b)):(e.consume(b),T)}function F(b){return e.check(gk,z,ce)(b)}function z(b){return e.enter("lineEnding"),e.consume(b),e.exit("lineEnding"),M}function M(b){return b===null||be(b)?F(b):(e.enter("htmlFlowData"),T(b))}function D(b){return b===45?(e.consume(b),_):T(b)}function J(b){return b===47?(e.consume(b),o="",Z):T(b)}function Z(b){if(b===62){const G=o.toLowerCase();return $c.includes(G)?(e.consume(b),ye):T(b)}return xt(b)&&o.length<8?(e.consume(b),o+=String.fromCharCode(b),Z):T(b)}function X(b){return b===93?(e.consume(b),_):T(b)}function _(b){return b===62?(e.consume(b),ye):b===45&&i===2?(e.consume(b),_):T(b)}function ye(b){return b===null||be(b)?(e.exit("htmlFlowData"),ce(b)):(e.consume(b),ye)}function ce(b){return e.exit("htmlFlow"),t(b)}}function bk(e,t,n){const r=this;return i;function i(o){return be(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 vk(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(zi,t,n)}}const wk={name:"htmlText",tokenize:kk};function kk(e,t,n){const r=this;let i,s,o;return a;function a(_){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(_),l}function l(_){return _===33?(e.consume(_),u):_===47?(e.consume(_),C):_===63?(e.consume(_),m):xt(_)?(e.consume(_),O):n(_)}function u(_){return _===45?(e.consume(_),d):_===91?(e.consume(_),s=0,g):xt(_)?(e.consume(_),j):n(_)}function d(_){return _===45?(e.consume(_),p):n(_)}function f(_){return _===null?n(_):_===45?(e.consume(_),h):be(_)?(o=f,J(_)):(e.consume(_),f)}function h(_){return _===45?(e.consume(_),p):f(_)}function p(_){return _===62?D(_):_===45?h(_):f(_)}function g(_){const ye="CDATA[";return _===ye.charCodeAt(s++)?(e.consume(_),s===ye.length?k:g):n(_)}function k(_){return _===null?n(_):_===93?(e.consume(_),S):be(_)?(o=k,J(_)):(e.consume(_),k)}function S(_){return _===93?(e.consume(_),y):k(_)}function y(_){return _===62?D(_):_===93?(e.consume(_),y):k(_)}function j(_){return _===null||_===62?D(_):be(_)?(o=j,J(_)):(e.consume(_),j)}function m(_){return _===null?n(_):_===63?(e.consume(_),A):be(_)?(o=m,J(_)):(e.consume(_),m)}function A(_){return _===62?D(_):m(_)}function C(_){return xt(_)?(e.consume(_),v):n(_)}function v(_){return _===45||ut(_)?(e.consume(_),v):w(_)}function w(_){return be(_)?(o=w,J(_)):Ie(_)?(e.consume(_),w):D(_)}function O(_){return _===45||ut(_)?(e.consume(_),O):_===47||_===62||Ve(_)?B(_):n(_)}function B(_){return _===47?(e.consume(_),D):_===58||_===95||xt(_)?(e.consume(_),N):be(_)?(o=B,J(_)):Ie(_)?(e.consume(_),B):D(_)}function N(_){return _===45||_===46||_===58||_===95||ut(_)?(e.consume(_),N):R(_)}function R(_){return _===61?(e.consume(_),T):be(_)?(o=R,J(_)):Ie(_)?(e.consume(_),R):B(_)}function T(_){return _===null||_===60||_===61||_===62||_===96?n(_):_===34||_===39?(e.consume(_),i=_,F):be(_)?(o=T,J(_)):Ie(_)?(e.consume(_),T):(e.consume(_),z)}function F(_){return _===i?(e.consume(_),i=void 0,M):_===null?n(_):be(_)?(o=F,J(_)):(e.consume(_),F)}function z(_){return _===null||_===34||_===39||_===60||_===61||_===96?n(_):_===47||_===62||Ve(_)?B(_):(e.consume(_),z)}function M(_){return _===47||_===62||Ve(_)?B(_):n(_)}function D(_){return _===62?(e.consume(_),e.exit("htmlTextData"),e.exit("htmlText"),t):n(_)}function J(_){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(_),e.exit("lineEnding"),Z}function Z(_){return Ie(_)?Pe(e,X,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(_):X(_)}function X(_){return e.enter("htmlTextData"),o(_)}}const el={name:"labelEnd",resolveAll:Nk,resolveTo:Ek,tokenize:Ck},Sk={tokenize:Tk},jk={tokenize:Ik},_k={tokenize:Ak};function Nk(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&&At(e,0,e.length,n),e}function Ek(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}},u={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",u,t]],a=Mt(a,e.slice(s+1,s+r+3)),a=Mt(a,[["enter",d,t]]),a=Mt(a,Zs(t.parser.constructs.insideSpan.null,e.slice(s+r+4,o-3),t)),a=Mt(a,[["exit",d,t],e[o-2],e[o-1],["exit",u,t]]),a=Mt(a,e.slice(o+1)),a=Mt(a,[["exit",l,t]]),At(e,s,e.length,a),e}function Ck(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(h){return s?s._inactive?f(h):(o=r.parser.defined.includes(Wt(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(h),e.exit("labelMarker"),e.exit("labelEnd"),l):n(h)}function l(h){return h===40?e.attempt(Sk,d,o?d:f)(h):h===91?e.attempt(jk,d,o?u:f)(h):o?d(h):f(h)}function u(h){return e.attempt(_k,d,f)(h)}function d(h){return t(h)}function f(h){return s._balanced=!0,n(h)}}function Tk(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 Ve(f)?li(e,s)(f):s(f)}function s(f){return f===41?d(f):Wp(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function o(f){return Ve(f)?li(e,l)(f):d(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?Gp(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):d(f)}function u(f){return Ve(f)?li(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 Ik(e,t,n){const r=this;return i;function i(a){return qp.call(r,e,s,o,"reference","referenceMarker","referenceString")(a)}function s(a){return r.parser.defined.includes(Wt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function Ak(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 zk={name:"labelStartImage",resolveAll:el.resolveAll,tokenize:Ok};function Ok(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 Pk={name:"labelStartLink",resolveAll:el.resolveAll,tokenize:Dk};function Dk(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 go={name:"lineEnding",tokenize:Rk};function Rk(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),Pe(e,t,"linePrefix")}}const Xi={name:"thematicBreak",tokenize:$k};function $k(e,t,n){let r=0,i;return s;function s(u){return e.enter("thematicBreak"),o(u)}function o(u){return i=u,a(u)}function a(u){return u===i?(e.enter("thematicBreakSequence"),l(u)):r>=3&&(u===null||be(u))?(e.exit("thematicBreak"),t(u)):n(u)}function l(u){return u===i?(e.consume(u),r++,l):(e.exit("thematicBreakSequence"),Ie(u)?Pe(e,a,"whitespace")(u):a(u))}}const vt={continuation:{tokenize:Bk},exit:Zk,name:"list",tokenize:Lk},Mk={partial:!0,tokenize:Uk},Fk={partial:!0,tokenize:Vk};function Lk(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(p){const g=r.containerState.type||(p===42||p===43||p===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||p===r.containerState.marker:ra(p)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),p===42||p===45?e.check(Xi,n,u)(p):u(p);if(!r.interrupt||p===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(p)}return n(p)}function l(p){return ra(p)&&++o<10?(e.consume(p),l):(!r.interrupt||o<2)&&(r.containerState.marker?p===r.containerState.marker:p===41||p===46)?(e.exit("listItemValue"),u(p)):n(p)}function u(p){return e.enter("listItemMarker"),e.consume(p),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||p,e.check(zi,r.interrupt?n:d,e.attempt(Mk,h,f))}function d(p){return r.containerState.initialBlankLine=!0,s++,h(p)}function f(p){return Ie(p)?(e.enter("listItemPrefixWhitespace"),e.consume(p),e.exit("listItemPrefixWhitespace"),h):n(p)}function h(p){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(p)}}function Bk(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(zi,i,s);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,Pe(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(Fk,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,Pe(e,e.attempt(vt,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function Vk(e,t,n){const r=this;return Pe(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 Zk(e){e.exit(this.containerState.type)}function Uk(e,t,n){const r=this;return Pe(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 Mc={name:"setextUnderline",resolveTo:Jk,tokenize:Hk};function Jk(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 Hk(e,t,n){const r=this;let i;return s;function s(u){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=u,o(u)):n(u)}function o(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===i?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),Ie(u)?Pe(e,l,"lineSuffix")(u):l(u))}function l(u){return u===null||be(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const Wk={tokenize:qk};function qk(e){const t=this,n=e.attempt(zi,r,e.attempt(this.parser.constructs.flowInitial,i,Pe(e,e.attempt(this.parser.constructs.flow,i,e.attempt(Q0,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 Gk={resolveAll:Yp()},Kk=Kp("string"),Yk=Kp("text");function Kp(e){return{resolveAll:Yp(e==="text"?Xk: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 u(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 u(d)?(n.exit("data"),s(d)):(n.consume(d),l)}function u(d){if(d===null)return!0;const f=i[d];let h=-1;if(f)for(;++h<f.length;){const p=f[h];if(!p.previous||p.previous.call(r,r.previous))return!0}return!1}}}function Yp(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 Xk(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 u=i[s];if(typeof u=="string"){for(o=u.length;u.charCodeAt(o-1)===32;)a++,o--;if(o)break;o=-1}else if(u===-2)l=!0,a++;else if(u!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={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={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const Qk={42:vt,43:vt,45:vt,48:vt,49:vt,50:vt,51:vt,52:vt,53:vt,54:vt,55:vt,56:vt,57:vt,62:Zp},e1={91:ik},t1={[-2]:mo,[-1]:mo,32:mo},n1={35:uk,42:Xi,45:[Mc,Xi],60:hk,61:Mc,95:Xi,96:Rc,126:Rc},r1={38:Jp,92:Up},i1={[-5]:go,[-4]:go,[-3]:go,33:zk,38:Jp,42:ia,60:[P0,wk],91:Pk,92:[lk,Up],93:el,95:ia,96:W0},s1={null:[ia,Gk]},o1={null:[42,95]},a1={null:[]},l1=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:o1,contentInitial:e1,disable:a1,document:Qk,flow:n1,flowInitial:t1,insideSpan:s1,string:r1,text:i1},Symbol.toStringTag,{value:"Module"}));function c1(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:w(C),check:w(v),consume:j,enter:m,exit:A,interrupt:w(v,{interrupt:!0})},u={code:null,containerState:{},defineSkip:k,events:[],now:g,parser:e,previous:null,sliceSerialize:h,sliceStream:p,write:f};let d=t.tokenize.call(u,l);return t.resolveAll&&s.push(t),u;function f(R){return o=Mt(o,R),S(),o[o.length-1]!==null?[]:(O(t,0),u.events=Zs(s,u.events,u),u.events)}function h(R,T){return d1(p(R),T)}function p(R){return u1(o,R)}function g(){const{_bufferIndex:R,_index:T,line:F,column:z,offset:M}=r;return{_bufferIndex:R,_index:T,line:F,column:z,offset:M}}function k(R){i[R.line]=R.column,N()}function S(){let R;for(;r._index<o.length;){const T=o[r._index];if(typeof T=="string")for(R=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===R&&r._bufferIndex<T.length;)y(T.charCodeAt(r._bufferIndex));else y(T)}}function y(R){d=d(R)}function j(R){be(R)?(r.line++,r.column=1,r.offset+=R===-3?2:1,N()):R!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=R}function m(R,T){const F=T||{};return F.type=R,F.start=g(),u.events.push(["enter",F,u]),a.push(F),F}function A(R){const T=a.pop();return T.end=g(),u.events.push(["exit",T,u]),T}function C(R,T){O(R,T.from)}function v(R,T){T.restore()}function w(R,T){return F;function F(z,M,D){let J,Z,X,_;return Array.isArray(z)?ce(z):"tokenize"in z?ce([z]):ye(z);function ye(Q){return oe;function oe(I){const re=I!==null&&Q[I],ae=I!==null&&Q.null,H=[...Array.isArray(re)?re:re?[re]:[],...Array.isArray(ae)?ae:ae?[ae]:[]];return ce(H)(I)}}function ce(Q){return J=Q,Z=0,Q.length===0?D:b(Q[Z])}function b(Q){return oe;function oe(I){return _=B(),X=Q,Q.partial||(u.currentConstruct=Q),Q.name&&u.parser.constructs.disable.null.includes(Q.name)?ne():Q.tokenize.call(T?Object.assign(Object.create(u),T):u,l,G,ne)(I)}}function G(Q){return R(X,_),M}function ne(Q){return _.restore(),++Z<J.length?b(J[Z]):D}}}function O(R,T){R.resolveAll&&!s.includes(R)&&s.push(R),R.resolve&&At(u.events,T,u.events.length-T,R.resolve(u.events.slice(T),u)),R.resolveTo&&(u.events=R.resolveTo(u.events,u))}function B(){const R=g(),T=u.previous,F=u.currentConstruct,z=u.events.length,M=Array.from(a);return{from:z,restore:D};function D(){r=R,u.previous=T,u.currentConstruct=F,u.events.length=z,a=M,N()}}function N(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function u1(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 d1(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=`
156
- `;break}case-3:{o=`\r
157
- `;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 f1(e){const r={constructs:Bp([l1,...(e||{}).extensions||[]]),content:i(E0),defined:[],document:i(T0),flow:i(Wk),lazy:{},string:i(Kk),text:i(Yk)};return r;function i(s){return o;function o(a){return c1(r,s,a)}}}function p1(e){for(;!Hp(e););return e}const Fc=/[\0\t\n\r]/g;function h1(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const l=[];let u,d,f,h,p;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(Fc.lastIndex=f,u=Fc.exec(s),h=u&&u.index!==void 0?u.index:s.length,p=s.charCodeAt(h),!u){t=s.slice(f);break}if(p===10&&f===h&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<h&&(l.push(s.slice(f,h)),e+=h-f),p){case 0:{l.push(65533),e++;break}case 9:{for(d=Math.ceil(e/4)*4,l.push(-2);e++<d;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}f=h+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const m1=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function g1(e){return e.replace(m1,x1)}function x1(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Vp(n.slice(s?2:1),s?16:10)}return Qa(n)||e}const Xp={}.hasOwnProperty;function y1(e,t,n){return t&&typeof t=="object"&&(n=t,t=void 0),b1(n)(p1(f1(n).document().write(h1()(e,t,!0))))}function b1(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(P),autolinkProtocol:B,autolinkEmail:B,atxHeading:s(Re),blockQuote:s(ae),characterEscape:B,characterReference:B,codeFenced:s(H),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(H,o),codeText:s(K,o),codeTextData:B,data:B,codeFlowValue:B,definition:s(pe),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(fe),hardBreakEscape:s(Oe),hardBreakTrailing:s(Oe),htmlFlow:s($e,o),htmlFlowData:B,htmlText:s($e,o),htmlTextData:B,image:s(E),label:o,link:s(P),listItem:s(se),listItemValue:h,listOrdered:s(V,f),listUnordered:s(V),paragraph:s(ie),reference:b,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Re),strong:s(ee),thematicBreak:s(we)},exit:{atxHeading:l(),atxHeadingSequence:C,autolink:l(),autolinkEmail:re,autolinkProtocol:I,blockQuote:l(),characterEscapeValue:N,characterReferenceMarkerHexadecimal:ne,characterReferenceMarkerNumeric:ne,characterReferenceValue:Q,characterReference:oe,codeFenced:l(S),codeFencedFence:k,codeFencedFenceInfo:p,codeFencedFenceMeta:g,codeFlowValue:N,codeIndented:l(y),codeText:l(M),codeTextData:N,data:N,definition:l(),definitionDestinationString:A,definitionLabelString:j,definitionTitleString:m,emphasis:l(),hardBreakEscape:l(T),hardBreakTrailing:l(T),htmlFlow:l(F),htmlFlowData:N,htmlText:l(z),htmlTextData:N,image:l(J),label:X,labelText:Z,lineEnding:R,link:l(D),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:G,resourceDestinationString:_,resourceTitleString:ye,resource:ce,setextHeading:l(O),setextHeadingLineSequence:w,setextHeadingText:v,strong:l(),thematicBreak:l()}};Qp(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(U){let Y={type:"root",children:[]};const ge={stack:[Y],tokenStack:[],config:t,enter:a,exit:u,buffer:o,resume:d,data:n},_e=[];let L=-1;for(;++L<U.length;)if(U[L][1].type==="listOrdered"||U[L][1].type==="listUnordered")if(U[L][0]==="enter")_e.push(L);else{const $=_e.pop();L=i(U,$,L)}for(L=-1;++L<U.length;){const $=t[U[L][0]];Xp.call($,U[L][1].type)&&$[U[L][1].type].call(Object.assign({sliceSerialize:U[L][2].sliceSerialize},ge),U[L][1])}if(ge.tokenStack.length>0){const $=ge.tokenStack[ge.tokenStack.length-1];($[1]||Lc).call(ge,void 0,$[0])}for(Y.position={start:pn(U.length>0?U[0][1].start:{line:1,column:1,offset:0}),end:pn(U.length>0?U[U.length-2][1].end:{line:1,column:1,offset:0})},L=-1;++L<t.transforms.length;)Y=t.transforms[L](Y)||Y;return Y}function i(U,Y,ge){let _e=Y-1,L=-1,$=!1,xe,de,Me,Je;for(;++_e<=ge;){const it=U[_e];switch(it[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{it[0]==="enter"?L++:L--,Je=void 0;break}case"lineEndingBlank":{it[0]==="enter"&&(xe&&!Je&&!L&&!Me&&(Me=_e),Je=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Je=void 0}if(!L&&it[0]==="enter"&&it[1].type==="listItemPrefix"||L===-1&&it[0]==="exit"&&(it[1].type==="listUnordered"||it[1].type==="listOrdered")){if(xe){let Lt=_e;for(de=void 0;Lt--;){const Ot=U[Lt];if(Ot[1].type==="lineEnding"||Ot[1].type==="lineEndingBlank"){if(Ot[0]==="exit")continue;de&&(U[de][1].type="lineEndingBlank",$=!0),Ot[1].type="lineEnding",de=Lt}else if(!(Ot[1].type==="linePrefix"||Ot[1].type==="blockQuotePrefix"||Ot[1].type==="blockQuotePrefixWhitespace"||Ot[1].type==="blockQuoteMarker"||Ot[1].type==="listItemIndent"))break}Me&&(!de||Me<de)&&(xe._spread=!0),xe.end=Object.assign({},de?U[de][1].start:it[1].end),U.splice(de||_e,0,["exit",xe,it[2]]),_e++,ge++}if(it[1].type==="listItemPrefix"){const Lt={type:"listItem",_spread:!1,start:Object.assign({},it[1].start),end:void 0};xe=Lt,U.splice(_e,0,["enter",Lt,it[2]]),_e++,ge++,Me=void 0,Je=!0}}}return U[Y][1]._spread=$,ge}function s(U,Y){return ge;function ge(_e){a.call(this,U(_e),_e),Y&&Y.call(this,_e)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(U,Y,ge){this.stack[this.stack.length-1].children.push(U),this.stack.push(U),this.tokenStack.push([Y,ge||void 0]),U.position={start:pn(Y.start),end:void 0}}function l(U){return Y;function Y(ge){U&&U.call(this,ge),u.call(this,ge)}}function u(U,Y){const ge=this.stack.pop(),_e=this.tokenStack.pop();if(_e)_e[0].type!==U.type&&(Y?Y.call(this,U,_e[0]):(_e[1]||Lc).call(this,U,_e[0]));else throw new Error("Cannot close `"+U.type+"` ("+ai({start:U.start,end:U.end})+"): it’s not open");ge.position.end=pn(U.end)}function d(){return Xa(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function h(U){if(this.data.expectingFirstListItemValue){const Y=this.stack[this.stack.length-2];Y.start=Number.parseInt(this.sliceSerialize(U),10),this.data.expectingFirstListItemValue=void 0}}function p(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.lang=U}function g(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.meta=U}function k(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function S(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function y(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U.replace(/(\r?\n|\r)$/g,"")}function j(U){const Y=this.resume(),ge=this.stack[this.stack.length-1];ge.label=Y,ge.identifier=Wt(this.sliceSerialize(U)).toLowerCase()}function m(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.title=U}function A(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.url=U}function C(U){const Y=this.stack[this.stack.length-1];if(!Y.depth){const ge=this.sliceSerialize(U).length;Y.depth=ge}}function v(){this.data.setextHeadingSlurpLineEnding=!0}function w(U){const Y=this.stack[this.stack.length-1];Y.depth=this.sliceSerialize(U).codePointAt(0)===61?1:2}function O(){this.data.setextHeadingSlurpLineEnding=void 0}function B(U){const ge=this.stack[this.stack.length-1].children;let _e=ge[ge.length-1];(!_e||_e.type!=="text")&&(_e=me(),_e.position={start:pn(U.start),end:void 0},ge.push(_e)),this.stack.push(_e)}function N(U){const Y=this.stack.pop();Y.value+=this.sliceSerialize(U),Y.position.end=pn(U.end)}function R(U){const Y=this.stack[this.stack.length-1];if(this.data.atHardBreak){const ge=Y.children[Y.children.length-1];ge.position.end=pn(U.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(Y.type)&&(B.call(this,U),N.call(this,U))}function T(){this.data.atHardBreak=!0}function F(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U}function z(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U}function M(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.value=U}function D(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Y=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Y,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function J(){const U=this.stack[this.stack.length-1];if(this.data.inReference){const Y=this.data.referenceType||"shortcut";U.type+="Reference",U.referenceType=Y,delete U.url,delete U.title}else delete U.identifier,delete U.label;this.data.referenceType=void 0}function Z(U){const Y=this.sliceSerialize(U),ge=this.stack[this.stack.length-2];ge.label=g1(Y),ge.identifier=Wt(Y).toLowerCase()}function X(){const U=this.stack[this.stack.length-1],Y=this.resume(),ge=this.stack[this.stack.length-1];if(this.data.inReference=!0,ge.type==="link"){const _e=U.children;ge.children=_e}else ge.alt=Y}function _(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.url=U}function ye(){const U=this.resume(),Y=this.stack[this.stack.length-1];Y.title=U}function ce(){this.data.inReference=void 0}function b(){this.data.referenceType="collapsed"}function G(U){const Y=this.resume(),ge=this.stack[this.stack.length-1];ge.label=Y,ge.identifier=Wt(this.sliceSerialize(U)).toLowerCase(),this.data.referenceType="full"}function ne(U){this.data.characterReferenceType=U.type}function Q(U){const Y=this.sliceSerialize(U),ge=this.data.characterReferenceType;let _e;ge?(_e=Vp(Y,ge==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):_e=Qa(Y);const L=this.stack[this.stack.length-1];L.value+=_e}function oe(U){const Y=this.stack.pop();Y.position.end=pn(U.end)}function I(U){N.call(this,U);const Y=this.stack[this.stack.length-1];Y.url=this.sliceSerialize(U)}function re(U){N.call(this,U);const Y=this.stack[this.stack.length-1];Y.url="mailto:"+this.sliceSerialize(U)}function ae(){return{type:"blockquote",children:[]}}function H(){return{type:"code",lang:null,meta:null,value:""}}function K(){return{type:"inlineCode",value:""}}function pe(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function fe(){return{type:"emphasis",children:[]}}function Re(){return{type:"heading",depth:0,children:[]}}function Oe(){return{type:"break"}}function $e(){return{type:"html",value:""}}function E(){return{type:"image",title:null,url:"",alt:null}}function P(){return{type:"link",title:null,url:"",children:[]}}function V(U){return{type:"list",ordered:U.type==="listOrdered",start:null,spread:U._spread,children:[]}}function se(U){return{type:"listItem",spread:U._spread,checked:null,children:[]}}function ie(){return{type:"paragraph",children:[]}}function ee(){return{type:"strong",children:[]}}function me(){return{type:"text",value:""}}function we(){return{type:"thematicBreak"}}}function pn(e){return{line:e.line,column:e.column,offset:e.offset}}function Qp(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?Qp(e,r):v1(e,r)}}function v1(e,t){let n;for(n in t)if(Xp.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 Lc(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+ai({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+ai({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+ai({start:t.start,end:t.end})+") is still open")}function w1(e){const t=this;t.parser=n;function n(r){return y1(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function k1(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 S1(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
158
- `}]}function j1(e,t){const n=t.value?t.value+`
159
- `:"",r={},i=t.lang?t.lang.split(/\s+/):[];i.length>0&&(r.className=["language-"+i[0]]);let s={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return t.meta&&(s.data={meta:t.meta}),e.patch(t,s),s=e.applyData(t,s),s={type:"element",tagName:"pre",properties:{},children:[s]},e.patch(t,s),s}function _1(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function N1(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function E1(e,t){const n=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",r=String(t.identifier).toUpperCase(),i=Or(r.toLowerCase()),s=e.footnoteOrder.indexOf(r);let o,a=e.footnoteCounts.get(r);a===void 0?(a=0,e.footnoteOrder.push(r),o=e.footnoteOrder.length):o=s+1,a+=1,e.footnoteCounts.set(r,a);const l={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+i,id:n+"fnref-"+i+(a>1?"-"+a:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(o)}]};e.patch(t,l);const u={type:"element",tagName:"sup",properties:{},children:[l]};return e.patch(t,u),e.applyData(t,u)}function C1(e,t){const n={type:"element",tagName:"h"+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function T1(e,t){if(e.options.allowDangerousHtml){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}}function eh(e,t){const n=t.referenceType;let r="]";if(n==="collapsed"?r+="[]":n==="full"&&(r+="["+(t.label||t.identifier)+"]"),t.type==="imageReference")return[{type:"text",value:"!["+t.alt+r}];const i=e.all(t),s=i[0];s&&s.type==="text"?s.value="["+s.value:i.unshift({type:"text",value:"["});const o=i[i.length-1];return o&&o.type==="text"?o.value+=r:i.push({type:"text",value:r}),i}function I1(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return eh(e,t);const i={src:Or(r.url||""),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"img",properties:i,children:[]};return e.patch(t,s),e.applyData(t,s)}function A1(e,t){const n={src:Or(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"img",properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function z1(e,t){const n={type:"text",value:t.value.replace(/\r?\n|\r/g," ")};e.patch(t,n);const r={type:"element",tagName:"code",properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function O1(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return eh(e,t);const i={href:Or(r.url||"")};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"a",properties:i,children:e.all(t)};return e.patch(t,s),e.applyData(t,s)}function P1(e,t){const n={href:Or(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"a",properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function D1(e,t,n){const r=e.all(t),i=n?R1(n):th(t),s={},o=[];if(typeof t.checked=="boolean"){const d=r[0];let f;d&&d.type==="element"&&d.tagName==="p"?f=d:(f={type:"element",tagName:"p",properties:{},children:[]},r.unshift(f)),f.children.length>0&&f.children.unshift({type:"text",value:" "}),f.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),s.className=["task-list-item"]}let a=-1;for(;++a<r.length;){const d=r[a];(i||a!==0||d.type!=="element"||d.tagName!=="p")&&o.push({type:"text",value:`
160
- `}),d.type==="element"&&d.tagName==="p"&&!i?o.push(...d.children):o.push(d)}const l=r[r.length-1];l&&(i||l.type!=="element"||l.tagName!=="p")&&o.push({type:"text",value:`
161
- `});const u={type:"element",tagName:"li",properties:s,children:o};return e.patch(t,u),e.applyData(t,u)}function R1(e){let t=!1;if(e.type==="list"){t=e.spread||!1;const n=e.children;let r=-1;for(;!t&&++r<n.length;)t=th(n[r])}return t}function th(e){const t=e.spread;return t??e.children.length>1}function $1(e,t){const n={},r=e.all(t);let i=-1;for(typeof t.start=="number"&&t.start!==1&&(n.start=t.start);++i<r.length;){const o=r[i];if(o.type==="element"&&o.tagName==="li"&&o.properties&&Array.isArray(o.properties.className)&&o.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const s={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,s),e.applyData(t,s)}function M1(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function F1(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function L1(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function B1(e,t){const n=e.all(t),r=n.shift(),i=[];if(r){const o={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],o),i.push(o)}if(n.length>0){const o={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},a=qa(t.children[1]),l=Pp(t.children[t.children.length-1]);a&&l&&(o.position={start:a,end:l}),i.push(o)}const s={type:"element",tagName:"table",properties:{},children:e.wrap(i,!0)};return e.patch(t,s),e.applyData(t,s)}function V1(e,t,n){const r=n?n.children:void 0,s=(r?r.indexOf(t):1)===0?"th":"td",o=n&&n.type==="table"?n.align:void 0,a=o?o.length:t.children.length;let l=-1;const u=[];for(;++l<a;){const f=t.children[l],h={},p=o?o[l]:void 0;p&&(h.align=p);let g={type:"element",tagName:s,properties:h,children:[]};f&&(g.children=e.all(f),e.patch(f,g),g=e.applyData(f,g)),u.push(g)}const d={type:"element",tagName:"tr",properties:{},children:e.wrap(u,!0)};return e.patch(t,d),e.applyData(t,d)}function Z1(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}const Bc=9,Vc=32;function U1(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),i=0;const s=[];for(;r;)s.push(Zc(t.slice(i,r.index),i>0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return s.push(Zc(t.slice(i),i>0,!1)),s.join("")}function Zc(e,t,n){let r=0,i=e.length;if(t){let s=e.codePointAt(r);for(;s===Bc||s===Vc;)r++,s=e.codePointAt(r)}if(n){let s=e.codePointAt(i-1);for(;s===Bc||s===Vc;)i--,s=e.codePointAt(i-1)}return i>r?e.slice(r,i):""}function J1(e,t){const n={type:"text",value:U1(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function H1(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}const W1={blockquote:k1,break:S1,code:j1,delete:_1,emphasis:N1,footnoteReference:E1,heading:C1,html:T1,imageReference:I1,image:A1,inlineCode:z1,linkReference:O1,link:P1,listItem:D1,list:$1,paragraph:M1,root:F1,strong:L1,table:B1,tableCell:Z1,tableRow:V1,text:J1,thematicBreak:H1,toml:Bi,yaml:Bi,definition:Bi,footnoteDefinition:Bi};function Bi(){}const nh=-1,Us=0,ci=1,gs=2,tl=3,nl=4,rl=5,il=6,rh=7,ih=8,Uc=typeof self=="object"?self:globalThis,q1=(e,t)=>{const n=(i,s)=>(e.set(s,i),i),r=i=>{if(e.has(i))return e.get(i);const[s,o]=t[i];switch(s){case Us:case nh:return n(o,i);case ci:{const a=n([],i);for(const l of o)a.push(r(l));return a}case gs:{const a=n({},i);for(const[l,u]of o)a[r(l)]=r(u);return a}case tl:return n(new Date(o),i);case nl:{const{source:a,flags:l}=o;return n(new RegExp(a,l),i)}case rl:{const a=n(new Map,i);for(const[l,u]of o)a.set(r(l),r(u));return a}case il:{const a=n(new Set,i);for(const l of o)a.add(r(l));return a}case rh:{const{name:a,message:l}=o;return n(new Uc[a](l),i)}case ih:return n(BigInt(o),i);case"BigInt":return n(Object(BigInt(o)),i);case"ArrayBuffer":return n(new Uint8Array(o).buffer,o);case"DataView":{const{buffer:a}=new Uint8Array(o);return n(new DataView(a),o)}}return n(new Uc[s](o),i)};return r},Jc=e=>q1(new Map,e)(0),Xn="",{toString:G1}={},{keys:K1}=Object,Wr=e=>{const t=typeof e;if(t!=="object"||!e)return[Us,t];const n=G1.call(e).slice(8,-1);switch(n){case"Array":return[ci,Xn];case"Object":return[gs,Xn];case"Date":return[tl,Xn];case"RegExp":return[nl,Xn];case"Map":return[rl,Xn];case"Set":return[il,Xn];case"DataView":return[ci,n]}return n.includes("Array")?[ci,n]:n.includes("Error")?[rh,n]:[gs,n]},Vi=([e,t])=>e===Us&&(t==="function"||t==="symbol"),Y1=(e,t,n,r)=>{const i=(o,a)=>{const l=r.push(o)-1;return n.set(a,l),l},s=o=>{if(n.has(o))return n.get(o);let[a,l]=Wr(o);switch(a){case Us:{let d=o;switch(l){case"bigint":a=ih,d=o.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+l);d=null;break;case"undefined":return i([nh],o)}return i([a,d],o)}case ci:{if(l){let h=o;return l==="DataView"?h=new Uint8Array(o.buffer):l==="ArrayBuffer"&&(h=new Uint8Array(o)),i([l,[...h]],o)}const d=[],f=i([a,d],o);for(const h of o)d.push(s(h));return f}case gs:{if(l)switch(l){case"BigInt":return i([l,o.toString()],o);case"Boolean":case"Number":case"String":return i([l,o.valueOf()],o)}if(t&&"toJSON"in o)return s(o.toJSON());const d=[],f=i([a,d],o);for(const h of K1(o))(e||!Vi(Wr(o[h])))&&d.push([s(h),s(o[h])]);return f}case tl:return i([a,o.toISOString()],o);case nl:{const{source:d,flags:f}=o;return i([a,{source:d,flags:f}],o)}case rl:{const d=[],f=i([a,d],o);for(const[h,p]of o)(e||!(Vi(Wr(h))||Vi(Wr(p))))&&d.push([s(h),s(p)]);return f}case il:{const d=[],f=i([a,d],o);for(const h of o)(e||!Vi(Wr(h)))&&d.push(s(h));return f}}const{message:u}=o;return i([a,{name:l,message:u}],o)};return s},Hc=(e,{json:t,lossy:n}={})=>{const r=[];return Y1(!(t||n),!!t,new Map,r)(e),r},xs=typeof structuredClone=="function"?(e,t)=>t&&("json"in t||"lossy"in t)?Jc(Hc(e,t)):structuredClone(e):(e,t)=>Jc(Hc(e,t));function X1(e,t){const n=[{type:"text",value:"↩"}];return t>1&&n.push({type:"element",tagName:"sup",properties:{},children:[{type:"text",value:String(t)}]}),n}function Q1(e,t){return"Back to reference "+(e+1)+(t>1?"-"+t:"")}function eS(e){const t=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",n=e.options.footnoteBackContent||X1,r=e.options.footnoteBackLabel||Q1,i=e.options.footnoteLabel||"Footnotes",s=e.options.footnoteLabelTagName||"h2",o=e.options.footnoteLabelProperties||{className:["sr-only"]},a=[];let l=-1;for(;++l<e.footnoteOrder.length;){const u=e.footnoteById.get(e.footnoteOrder[l]);if(!u)continue;const d=e.all(u),f=String(u.identifier).toUpperCase(),h=Or(f.toLowerCase());let p=0;const g=[],k=e.footnoteCounts.get(f);for(;k!==void 0&&++p<=k;){g.length>0&&g.push({type:"text",value:" "});let j=typeof n=="string"?n:n(l,p);typeof j=="string"&&(j={type:"text",value:j}),g.push({type:"element",tagName:"a",properties:{href:"#"+t+"fnref-"+h+(p>1?"-"+p:""),dataFootnoteBackref:"",ariaLabel:typeof r=="string"?r:r(l,p),className:["data-footnote-backref"]},children:Array.isArray(j)?j:[j]})}const S=d[d.length-1];if(S&&S.type==="element"&&S.tagName==="p"){const j=S.children[S.children.length-1];j&&j.type==="text"?j.value+=" ":S.children.push({type:"text",value:" "}),S.children.push(...g)}else d.push(...g);const y={type:"element",tagName:"li",properties:{id:t+"fn-"+h},children:e.wrap(d,!0)};e.patch(u,y),a.push(y)}if(a.length!==0)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:s,properties:{...xs(o),id:"footnote-label"},children:[{type:"text",value:i}]},{type:"text",value:`
162
- `},{type:"element",tagName:"ol",properties:{},children:e.wrap(a,!0)},{type:"text",value:`
163
- `}]}}const Js=function(e){if(e==null)return iS;if(typeof e=="function")return Hs(e);if(typeof e=="object")return Array.isArray(e)?tS(e):nS(e);if(typeof e=="string")return rS(e);throw new Error("Expected function, string, or object as test")};function tS(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=Js(e[n]);return Hs(r);function r(...i){let s=-1;for(;++s<t.length;)if(t[s].apply(this,i))return!0;return!1}}function nS(e){const t=e;return Hs(n);function n(r){const i=r;let s;for(s in e)if(i[s]!==t[s])return!1;return!0}}function rS(e){return Hs(t);function t(n){return n&&n.type===e}}function Hs(e){return t;function t(n,r,i){return!!(sS(n)&&e.call(this,n,typeof r=="number"?r:void 0,i||void 0))}}function iS(){return!0}function sS(e){return e!==null&&typeof e=="object"&&"type"in e}const sh=[],oS=!0,sa=!1,aS="skip";function oh(e,t,n,r){let i;typeof t=="function"&&typeof n!="function"?(r=n,n=t):i=t;const s=Js(i),o=r?-1:1;a(e,void 0,[])();function a(l,u,d){const f=l&&typeof l=="object"?l:{};if(typeof f.type=="string"){const p=typeof f.tagName=="string"?f.tagName:typeof f.name=="string"?f.name:void 0;Object.defineProperty(h,"name",{value:"node ("+(l.type+(p?"<"+p+">":""))+")"})}return h;function h(){let p=sh,g,k,S;if((!t||s(l,u,d[d.length-1]||void 0))&&(p=lS(n(l,d)),p[0]===sa))return p;if("children"in l&&l.children){const y=l;if(y.children&&p[0]!==aS)for(k=(r?y.children.length:-1)+o,S=d.concat(y);k>-1&&k<y.children.length;){const j=y.children[k];if(g=a(j,k,S)(),g[0]===sa)return g;k=typeof g[1]=="number"?g[1]:k+o}}return p}}}function lS(e){return Array.isArray(e)?e:typeof e=="number"?[oS,e]:e==null?sh:[e]}function sl(e,t,n,r){let i,s,o;typeof t=="function"&&typeof n!="function"?(s=void 0,o=t,i=n):(s=t,o=n,i=r),oh(e,s,a,i);function a(l,u){const d=u[u.length-1],f=d?d.children.indexOf(l):void 0;return o(l,f,d)}}const oa={}.hasOwnProperty,cS={};function uS(e,t){const n=t||cS,r=new Map,i=new Map,s=new Map,o={...W1,...n.handlers},a={all:u,applyData:fS,definitionById:r,footnoteById:i,footnoteCounts:s,footnoteOrder:[],handlers:o,one:l,options:n,patch:dS,wrap:hS};return sl(e,function(d){if(d.type==="definition"||d.type==="footnoteDefinition"){const f=d.type==="definition"?r:i,h=String(d.identifier).toUpperCase();f.has(h)||f.set(h,d)}}),a;function l(d,f){const h=d.type,p=a.handlers[h];if(oa.call(a.handlers,h)&&p)return p(a,d,f);if(a.options.passThrough&&a.options.passThrough.includes(h)){if("children"in d){const{children:k,...S}=d,y=xs(S);return y.children=a.all(d),y}return xs(d)}return(a.options.unknownHandler||pS)(a,d,f)}function u(d){const f=[];if("children"in d){const h=d.children;let p=-1;for(;++p<h.length;){const g=a.one(h[p],d);if(g){if(p&&h[p-1].type==="break"&&(!Array.isArray(g)&&g.type==="text"&&(g.value=Wc(g.value)),!Array.isArray(g)&&g.type==="element")){const k=g.children[0];k&&k.type==="text"&&(k.value=Wc(k.value))}Array.isArray(g)?f.push(...g):f.push(g)}}}return f}}function dS(e,t){e.position&&(t.position=Qw(e))}function fS(e,t){let n=t;if(e&&e.data){const r=e.data.hName,i=e.data.hChildren,s=e.data.hProperties;if(typeof r=="string")if(n.type==="element")n.tagName=r;else{const o="children"in n?n.children:[n];n={type:"element",tagName:r,properties:{},children:o}}n.type==="element"&&s&&Object.assign(n.properties,xs(s)),"children"in n&&n.children&&i!==null&&i!==void 0&&(n.children=i)}return n}function pS(e,t){const n=t.data||{},r="value"in t&&!(oa.call(n,"hProperties")||oa.call(n,"hChildren"))?{type:"text",value:t.value}:{type:"element",tagName:"div",properties:{},children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function hS(e,t){const n=[];let r=-1;for(t&&n.push({type:"text",value:`
164
- `});++r<e.length;)r&&n.push({type:"text",value:`
165
- `}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
166
- `}),n}function Wc(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function qc(e,t){const n=uS(e,t),r=n.one(e,void 0),i=eS(n),s=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&s.children.push({type:"text",value:`
167
- `},i),s}function mS(e,t){return e&&"run"in e?async function(n,r){const i=qc(n,{file:r,...t});await e.run(i,r)}:function(n,r){return qc(n,{file:r,...e||t})}}function Gc(e){if(e)throw e}var xo,Kc;function gS(){if(Kc)return xo;Kc=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},s=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var d=e.call(u,"constructor"),f=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!d&&!f)return!1;var h;for(h in u);return typeof h>"u"||e.call(u,h)},o=function(u,d){n&&d.name==="__proto__"?n(u,d.name,{enumerable:!0,configurable:!0,value:d.newValue,writable:!0}):u[d.name]=d.newValue},a=function(u,d){if(d==="__proto__")if(e.call(u,d)){if(r)return r(u,d).value}else return;return u[d]};return xo=function l(){var u,d,f,h,p,g,k=arguments[0],S=1,y=arguments.length,j=!1;for(typeof k=="boolean"&&(j=k,k=arguments[1]||{},S=2),(k==null||typeof k!="object"&&typeof k!="function")&&(k={});S<y;++S)if(u=arguments[S],u!=null)for(d in u)f=a(k,d),h=a(u,d),k!==h&&(j&&h&&(s(h)||(p=i(h)))?(p?(p=!1,g=f&&i(f)?f:[]):g=f&&s(f)?f:{},o(k,{name:d,newValue:l(j,g,h)})):typeof h<"u"&&o(k,{name:d,newValue:h}));return k},xo}var xS=gS();const yo=wa(xS);function aa(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function yS(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(l,...u){const d=e[++s];let f=-1;if(l){o(l);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,d?bS(d,a)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function bS(e,t){let n;return r;function r(...o){const a=e.length>o.length;let l;a&&o.push(i);try{l=e.apply(this,o)}catch(u){const d=u;if(a&&n)throw d;return i(d)}a||(l&&l.then&&typeof l.then=="function"?l.then(s,i):l instanceof Error?i(l):s(l))}function i(o,...a){n||(n=!0,t(o,...a))}function s(o){i(null,o)}}const Yt={basename:vS,dirname:wS,extname:kS,join:SS,sep:"/"};function vS(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');Oi(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,a=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),a>-1&&(e.codePointAt(i)===t.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function wS(e){if(Oi(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function kS(e){Oi(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const a=e.codePointAt(t);if(a===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),a===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function SS(...e){let t=-1,n;for(;++t<e.length;)Oi(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":jS(n)}function jS(e){Oi(e);const t=e.codePointAt(0)===47;let n=_S(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function _S(e,t){let n="",r=0,i=-1,s=0,o=-1,a,l;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else a===46&&s>-1?s++:s=-1}return n}function Oi(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const NS={cwd:ES};function ES(){return"/"}function la(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function CS(e){if(typeof e=="string")e=new URL(e);else if(!la(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return TS(e)}function TS(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const bo=["history","path","basename","stem","extname","dirname"];class ah{constructor(t){let n;t?la(t)?n={path:t}:typeof t=="string"||IS(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":NS.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<bo.length;){const s=bo[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)bo.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?Yt.basename(this.path):void 0}set basename(t){wo(t,"basename"),vo(t,"basename"),this.path=Yt.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?Yt.dirname(this.path):void 0}set dirname(t){Yc(this.basename,"dirname"),this.path=Yt.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?Yt.extname(this.path):void 0}set extname(t){if(vo(t,"extname"),Yc(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=Yt.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){la(t)&&(t=CS(t)),wo(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?Yt.basename(this.path,this.extname):void 0}set stem(t){wo(t,"stem"),vo(t,"stem"),this.path=Yt.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new dt(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function vo(e,t){if(e&&e.includes(Yt.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+Yt.sep+"`")}function wo(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function Yc(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function IS(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const AS=function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s},zS={}.hasOwnProperty;class ol extends AS{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=yS()}copy(){const t=new ol;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(yo(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(jo("data",this.frozen),this.namespace[t]=n,this):zS.call(this.namespace,t)&&this.namespace[t]||void 0:t?(jo("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=Zi(t),r=this.parser||this.Parser;return ko("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),ko("process",this.parser||this.Parser),So("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=Zi(t),l=r.parse(a);r.run(l,a,function(d,f,h){if(d||!f||!h)return u(d);const p=f,g=r.stringify(p,h);DS(g)?h.value=g:h.result=g,u(d,h)});function u(d,f){d||!f?o(d):s?s(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),ko("processSync",this.parser||this.Parser),So("processSync",this.compiler||this.Compiler),this.process(t,i),Qc("processSync","process",n),r;function i(s,o){n=!0,Gc(s),r=o}}run(t,n,r){Xc(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,a){const l=Zi(n);i.run(t,l,u);function u(d,f,h){const p=f||t;d?a(d):o?o(p):r(void 0,p,h)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),Qc("runSync","run",r),i;function s(o,a){Gc(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=Zi(n),i=this.compiler||this.Compiler;return So("stringify",i),Xc(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(jo("use",this.frozen),t!=null)if(typeof t=="function")l(t,n);else if(typeof t=="object")Array.isArray(t)?a(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(u){if(typeof u=="function")l(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[d,...f]=u;l(d,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(u.plugins),u.settings&&(i.settings=yo(!0,i.settings,u.settings))}function a(u){let d=-1;if(u!=null)if(Array.isArray(u))for(;++d<u.length;){const f=u[d];s(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function l(u,d){let f=-1,h=-1;for(;++f<r.length;)if(r[f][0]===u){h=f;break}if(h===-1)r.push([u,...d]);else if(d.length>0){let[p,...g]=d;const k=r[h][1];aa(k)&&aa(p)&&(p=yo(!0,k,p)),r[h]=[u,p,...g]}}}}const OS=new ol().freeze();function ko(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function So(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function jo(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function Xc(e){if(!aa(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function Qc(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Zi(e){return PS(e)?e:new ah(e)}function PS(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function DS(e){return typeof e=="string"||RS(e)}function RS(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const $S="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",eu=[],tu={allowDangerousHtml:!0},MS=/^(https?|ircs?|mailto|xmpp)$/i,FS=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function LS(e){const t=BS(e),n=VS(e);return ZS(t.runSync(t.parse(n),n),e)}function BS(e){const t=e.rehypePlugins||eu,n=e.remarkPlugins||eu,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...tu}:tu;return OS().use(w1).use(n).use(mS,r).use(t)}function VS(e){const t=e.children||"",n=new ah;return typeof t=="string"&&(n.value=t),n}function ZS(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,l=t.urlTransform||US;for(const d of FS)Object.hasOwn(t,d.from)&&(""+d.from+(d.to?"use `"+d.to+"` instead":"remove it")+$S+d.id,void 0);return sl(e,u),i0(e,{Fragment:c.Fragment,components:i,ignoreInvalidStyle:!0,jsx:c.jsx,jsxs:c.jsxs,passKeys:!0,passNode:!0});function u(d,f,h){if(d.type==="raw"&&h&&typeof f=="number")return o?h.children.splice(f,1):h.children[f]={type:"text",value:d.value},f;if(d.type==="element"){let p;for(p in ho)if(Object.hasOwn(ho,p)&&Object.hasOwn(d.properties,p)){const g=d.properties[p],k=ho[p];(k===null||k.includes(d.tagName))&&(d.properties[p]=l(String(g||""),p,d))}}if(d.type==="element"){let p=n?!n.includes(d.tagName):s?s.includes(d.tagName):!1;if(!p&&r&&typeof f=="number"&&(p=!r(d,f,h)),p&&h&&typeof f=="number")return a&&d.children?h.children.splice(f,1,...d.children):h.children.splice(f,1),f}}}function US(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||MS.test(e.slice(0,t))?e:""}function nu(e,t){const n=String(e);if(typeof t!="string")throw new TypeError("Expected character");let r=0,i=n.indexOf(t);for(;i!==-1;)r++,i=n.indexOf(t,i+t.length);return r}function JS(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function HS(e,t,n){const i=Js((n||{}).ignore||[]),s=WS(t);let o=-1;for(;++o<s.length;)oh(e,"text",a);function a(u,d){let f=-1,h;for(;++f<d.length;){const p=d[f],g=h?h.children:void 0;if(i(p,g?g.indexOf(p):void 0,h))return;h=p}if(h)return l(u,d)}function l(u,d){const f=d[d.length-1],h=s[o][0],p=s[o][1];let g=0;const S=f.children.indexOf(u);let y=!1,j=[];h.lastIndex=0;let m=h.exec(u.value);for(;m;){const A=m.index,C={index:m.index,input:m.input,stack:[...d,u]};let v=p(...m,C);if(typeof v=="string"&&(v=v.length>0?{type:"text",value:v}:void 0),v===!1?h.lastIndex=A+1:(g!==A&&j.push({type:"text",value:u.value.slice(g,A)}),Array.isArray(v)?j.push(...v):v&&j.push(v),g=A+m[0].length,y=!0),!h.global)break;m=h.exec(u.value)}return y?(g<u.value.length&&j.push({type:"text",value:u.value.slice(g)}),f.children.splice(S,1,...j)):j=[u],S+j.length}}function WS(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const i=n[r];t.push([qS(i[0]),GS(i[1])])}return t}function qS(e){return typeof e=="string"?new RegExp(JS(e),"g"):e}function GS(e){return typeof e=="function"?e:function(){return e}}const _o="phrasing",No=["autolink","link","image","label"];function KS(){return{transforms:[rj],enter:{literalAutolink:XS,literalAutolinkEmail:Eo,literalAutolinkHttp:Eo,literalAutolinkWww:Eo},exit:{literalAutolink:nj,literalAutolinkEmail:tj,literalAutolinkHttp:QS,literalAutolinkWww:ej}}}function YS(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:_o,notInConstruct:No},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:_o,notInConstruct:No},{character:":",before:"[ps]",after:"\\/",inConstruct:_o,notInConstruct:No}]}}function XS(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function Eo(e){this.config.enter.autolinkProtocol.call(this,e)}function QS(e){this.config.exit.autolinkProtocol.call(this,e)}function ej(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function tj(e){this.config.exit.autolinkEmail.call(this,e)}function nj(e){this.exit(e)}function rj(e){HS(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,ij],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),sj]],{ignore:["link","linkReference"]})}function ij(e,t,n,r,i){let s="";if(!lh(i)||(/^w/i.test(t)&&(n=t+n,t="",s="http://"),!oj(n)))return!1;const o=aj(n+r);if(!o[0])return!1;const a={type:"link",title:null,url:s+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[a,{type:"text",value:o[1]}]:a}function sj(e,t,n,r){return!lh(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function oj(e){const t=e.split(".");return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function aj(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const i=nu(e,"(");let s=nu(e,")");for(;r!==-1&&i>s;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),s++;return[e,n]}function lh(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||Bn(n)||Vs(n))&&(!t||n!==47)}ch.peek=gj;function lj(){this.buffer()}function cj(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function uj(){this.buffer()}function dj(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function fj(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Wt(this.sliceSerialize(e)).toLowerCase(),n.label=t}function pj(e){this.exit(e)}function hj(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=Wt(this.sliceSerialize(e)).toLowerCase(),n.label=t}function mj(e){this.exit(e)}function gj(){return"["}function ch(e,t,n,r){const i=n.createTracker(r);let s=i.move("[^");const o=n.enter("footnoteReference"),a=n.enter("reference");return s+=i.move(n.safe(n.associationId(e),{after:"]",before:s})),a(),o(),s+=i.move("]"),s}function xj(){return{enter:{gfmFootnoteCallString:lj,gfmFootnoteCall:cj,gfmFootnoteDefinitionLabelString:uj,gfmFootnoteDefinition:dj},exit:{gfmFootnoteCallString:fj,gfmFootnoteCall:pj,gfmFootnoteDefinitionLabelString:hj,gfmFootnoteDefinition:mj}}}function yj(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:ch},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,s,o){const a=s.createTracker(o);let l=a.move("[^");const u=s.enter("footnoteDefinition"),d=s.enter("label");return l+=a.move(s.safe(s.associationId(r),{before:l,after:"]"})),d(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((t?`
168
- `:" ")+s.indentLines(s.containerFlow(r,a.current()),t?uh:bj))),u(),l}}function bj(e,t,n){return t===0?e:uh(e,t,n)}function uh(e,t,n){return(n?"":" ")+e}const vj=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];dh.peek=_j;function wj(){return{canContainEols:["delete"],enter:{strikethrough:Sj},exit:{strikethrough:jj}}}function kj(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:vj}],handlers:{delete:dh}}}function Sj(e){this.enter({type:"delete",children:[]},e)}function jj(e){this.exit(e)}function dh(e,t,n,r){const i=n.createTracker(r),s=n.enter("strikethrough");let o=i.move("~~");return o+=n.containerPhrasing(e,{...i.current(),before:o,after:"~"}),o+=i.move("~~"),s(),o}function _j(){return"~"}function Nj(e){return e.length}function Ej(e,t){const n=t||{},r=(n.align||[]).concat(),i=n.stringLength||Nj,s=[],o=[],a=[],l=[];let u=0,d=-1;for(;++d<e.length;){const k=[],S=[];let y=-1;for(e[d].length>u&&(u=e[d].length);++y<e[d].length;){const j=Cj(e[d][y]);if(n.alignDelimiters!==!1){const m=i(j);S[y]=m,(l[y]===void 0||m>l[y])&&(l[y]=m)}k.push(j)}o[d]=k,a[d]=S}let f=-1;if(typeof r=="object"&&"length"in r)for(;++f<u;)s[f]=ru(r[f]);else{const k=ru(r);for(;++f<u;)s[f]=k}f=-1;const h=[],p=[];for(;++f<u;){const k=s[f];let S="",y="";k===99?(S=":",y=":"):k===108?S=":":k===114&&(y=":");let j=n.alignDelimiters===!1?1:Math.max(1,l[f]-S.length-y.length);const m=S+"-".repeat(j)+y;n.alignDelimiters!==!1&&(j=S.length+j+y.length,j>l[f]&&(l[f]=j),p[f]=j),h[f]=m}o.splice(1,0,h),a.splice(1,0,p),d=-1;const g=[];for(;++d<o.length;){const k=o[d],S=a[d];f=-1;const y=[];for(;++f<u;){const j=k[f]||"";let m="",A="";if(n.alignDelimiters!==!1){const C=l[f]-(S[f]||0),v=s[f];v===114?m=" ".repeat(C):v===99?C%2?(m=" ".repeat(C/2+.5),A=" ".repeat(C/2-.5)):(m=" ".repeat(C/2),A=m):A=" ".repeat(C)}n.delimiterStart!==!1&&!f&&y.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&j==="")&&(n.delimiterStart!==!1||f)&&y.push(" "),n.alignDelimiters!==!1&&y.push(m),y.push(j),n.alignDelimiters!==!1&&y.push(A),n.padding!==!1&&y.push(" "),(n.delimiterEnd!==!1||f!==u-1)&&y.push("|")}g.push(n.delimiterEnd===!1?y.join("").replace(/ +$/,""):y.join(""))}return g.join(`
169
- `)}function Cj(e){return e==null?"":String(e)}function ru(e){const t=typeof e=="string"?e.codePointAt(0):0;return t===67||t===99?99:t===76||t===108?108:t===82||t===114?114:0}function Tj(e,t,n,r){const i=n.enter("blockquote"),s=n.createTracker(r);s.move("> "),s.shift(2);const o=n.indentLines(n.containerFlow(e,s.current()),Ij);return i(),o}function Ij(e,t,n){return">"+(n?"":" ")+e}function Aj(e,t){return iu(e,t.inConstruct,!0)&&!iu(e,t.notInConstruct,!1)}function iu(e,t,n){if(typeof t=="string"&&(t=[t]),!t||t.length===0)return n;let r=-1;for(;++r<t.length;)if(e.includes(t[r]))return!0;return!1}function su(e,t,n,r){let i=-1;for(;++i<n.unsafe.length;)if(n.unsafe[i].character===`
170
- `&&Aj(n.stack,n.unsafe[i]))return/[ \t]/.test(r.before)?"":" ";return`\\
171
- `}function zj(e,t){const n=String(e);let r=n.indexOf(t),i=r,s=0,o=0;if(typeof t!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===i?++s>o&&(o=s):s=1,i=r+t.length,r=n.indexOf(t,i);return o}function Oj(e,t){return!!(t.options.fences===!1&&e.value&&!e.lang&&/[^ \r\n]/.test(e.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(e.value))}function Pj(e){const t=e.options.fence||"`";if(t!=="`"&&t!=="~")throw new Error("Cannot serialize code with `"+t+"` for `options.fence`, expected `` ` `` or `~`");return t}function Dj(e,t,n,r){const i=Pj(n),s=e.value||"",o=i==="`"?"GraveAccent":"Tilde";if(Oj(e,n)){const f=n.enter("codeIndented"),h=n.indentLines(s,Rj);return f(),h}const a=n.createTracker(r),l=i.repeat(Math.max(zj(s,i)+1,3)),u=n.enter("codeFenced");let d=a.move(l);if(e.lang){const f=n.enter(`codeFencedLang${o}`);d+=a.move(n.safe(e.lang,{before:d,after:" ",encode:["`"],...a.current()})),f()}if(e.lang&&e.meta){const f=n.enter(`codeFencedMeta${o}`);d+=a.move(" "),d+=a.move(n.safe(e.meta,{before:d,after:`
172
- `,encode:["`"],...a.current()})),f()}return d+=a.move(`
173
- `),s&&(d+=a.move(s+`
174
- `)),d+=a.move(l),u(),d}function Rj(e,t,n){return(n?"":" ")+e}function al(e){const t=e.options.quote||'"';if(t!=='"'&&t!=="'")throw new Error("Cannot serialize title with `"+t+"` for `options.quote`, expected `\"`, or `'`");return t}function $j(e,t,n,r){const i=al(n),s=i==='"'?"Quote":"Apostrophe",o=n.enter("definition");let a=n.enter("label");const l=n.createTracker(r);let u=l.move("[");return u+=l.move(n.safe(n.associationId(e),{before:u,after:"]",...l.current()})),u+=l.move("]: "),a(),!e.url||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),u+=l.move("<"),u+=l.move(n.safe(e.url,{before:u,after:">",...l.current()})),u+=l.move(">")):(a=n.enter("destinationRaw"),u+=l.move(n.safe(e.url,{before:u,after:e.title?" ":`
175
- `,...l.current()}))),a(),e.title&&(a=n.enter(`title${s}`),u+=l.move(" "+i),u+=l.move(n.safe(e.title,{before:u,after:i,...l.current()})),u+=l.move(i),a()),o(),u}function Mj(e){const t=e.options.emphasis||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize emphasis with `"+t+"` for `options.emphasis`, expected `*`, or `_`");return t}function bi(e){return"&#x"+e.toString(16).toUpperCase()+";"}function ys(e,t,n){const r=jr(e),i=jr(t);return r===void 0?i===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}fh.peek=Fj;function fh(e,t,n,r){const i=Mj(n),s=n.enter("emphasis"),o=n.createTracker(r),a=o.move(i);let l=o.move(n.containerPhrasing(e,{after:i,before:a,...o.current()}));const u=l.charCodeAt(0),d=ys(r.before.charCodeAt(r.before.length-1),u,i);d.inside&&(l=bi(u)+l.slice(1));const f=l.charCodeAt(l.length-1),h=ys(r.after.charCodeAt(0),f,i);h.inside&&(l=l.slice(0,-1)+bi(f));const p=o.move(i);return s(),n.attentionEncodeSurroundingInfo={after:h.outside,before:d.outside},a+l+p}function Fj(e,t,n){return n.options.emphasis||"*"}function Lj(e,t){let n=!1;return sl(e,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,sa}),!!((!e.depth||e.depth<3)&&Xa(e)&&(t.options.setext||n))}function Bj(e,t,n,r){const i=Math.max(Math.min(6,e.depth||1),1),s=n.createTracker(r);if(Lj(e,n)){const d=n.enter("headingSetext"),f=n.enter("phrasing"),h=n.containerPhrasing(e,{...s.current(),before:`
176
- `,after:`
177
- `});return f(),d(),h+`
178
- `+(i===1?"=":"-").repeat(h.length-(Math.max(h.lastIndexOf("\r"),h.lastIndexOf(`
179
- `))+1))}const o="#".repeat(i),a=n.enter("headingAtx"),l=n.enter("phrasing");s.move(o+" ");let u=n.containerPhrasing(e,{before:"# ",after:`
180
- `,...s.current()});return/^[\t ]/.test(u)&&(u=bi(u.charCodeAt(0))+u.slice(1)),u=u?o+" "+u:o,n.options.closeAtx&&(u+=" "+o),l(),a(),u}ph.peek=Vj;function ph(e){return e.value||""}function Vj(){return"<"}hh.peek=Zj;function hh(e,t,n,r){const i=al(n),s=i==='"'?"Quote":"Apostrophe",o=n.enter("image");let a=n.enter("label");const l=n.createTracker(r);let u=l.move("![");return u+=l.move(n.safe(e.alt,{before:u,after:"]",...l.current()})),u+=l.move("]("),a(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),u+=l.move("<"),u+=l.move(n.safe(e.url,{before:u,after:">",...l.current()})),u+=l.move(">")):(a=n.enter("destinationRaw"),u+=l.move(n.safe(e.url,{before:u,after:e.title?" ":")",...l.current()}))),a(),e.title&&(a=n.enter(`title${s}`),u+=l.move(" "+i),u+=l.move(n.safe(e.title,{before:u,after:i,...l.current()})),u+=l.move(i),a()),u+=l.move(")"),o(),u}function Zj(){return"!"}mh.peek=Uj;function mh(e,t,n,r){const i=e.referenceType,s=n.enter("imageReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("![");const u=n.safe(e.alt,{before:l,after:"]",...a.current()});l+=a.move(u+"]["),o();const d=n.stack;n.stack=[],o=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=d,s(),i==="full"||!u||u!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function Uj(){return"!"}gh.peek=Jj;function gh(e,t,n){let r=e.value||"",i="`",s=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<n.unsafe.length;){const o=n.unsafe[s],a=n.compilePattern(o);let l;if(o.atBreak)for(;l=a.exec(r);){let u=l.index;r.charCodeAt(u)===10&&r.charCodeAt(u-1)===13&&u--,r=r.slice(0,u)+" "+r.slice(l.index+1)}}return i+r+i}function Jj(){return"`"}function xh(e,t){const n=Xa(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}yh.peek=Hj;function yh(e,t,n,r){const i=al(n),s=i==='"'?"Quote":"Apostrophe",o=n.createTracker(r);let a,l;if(xh(e,n)){const d=n.stack;n.stack=[],a=n.enter("autolink");let f=o.move("<");return f+=o.move(n.containerPhrasing(e,{before:f,after:">",...o.current()})),f+=o.move(">"),a(),n.stack=d,f}a=n.enter("link"),l=n.enter("label");let u=o.move("[");return u+=o.move(n.containerPhrasing(e,{before:u,after:"](",...o.current()})),u+=o.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),u+=o.move("<"),u+=o.move(n.safe(e.url,{before:u,after:">",...o.current()})),u+=o.move(">")):(l=n.enter("destinationRaw"),u+=o.move(n.safe(e.url,{before:u,after:e.title?" ":")",...o.current()}))),l(),e.title&&(l=n.enter(`title${s}`),u+=o.move(" "+i),u+=o.move(n.safe(e.title,{before:u,after:i,...o.current()})),u+=o.move(i),l()),u+=o.move(")"),a(),u}function Hj(e,t,n){return xh(e,n)?"<":"["}bh.peek=Wj;function bh(e,t,n,r){const i=e.referenceType,s=n.enter("linkReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("[");const u=n.containerPhrasing(e,{before:l,after:"]",...a.current()});l+=a.move(u+"]["),o();const d=n.stack;n.stack=[],o=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=d,s(),i==="full"||!u||u!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function Wj(){return"["}function ll(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function qj(e){const t=ll(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function Gj(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function vh(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function Kj(e,t,n,r){const i=n.enter("list"),s=n.bulletCurrent;let o=e.ordered?Gj(n):ll(n);const a=e.ordered?o==="."?")":".":qj(n);let l=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){const d=e.children?e.children[0]:void 0;if((o==="*"||o==="-")&&d&&(!d.children||!d.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),vh(n)===o&&d){let f=-1;for(;++f<e.children.length;){const h=e.children[f];if(h&&h.type==="listItem"&&h.children&&h.children[0]&&h.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(o=a),n.bulletCurrent=o;const u=n.containerFlow(e,r);return n.bulletLastUsed=o,n.bulletCurrent=s,i(),u}function Yj(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function Xj(e,t,n,r){const i=Yj(n);let s=n.bulletCurrent||ll(n);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let o=s.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);const a=n.createTracker(r);a.move(s+" ".repeat(o-s.length)),a.shift(o);const l=n.enter("listItem"),u=n.indentLines(n.containerFlow(e,a.current()),d);return l(),u;function d(f,h,p){return h?(p?"":" ".repeat(o))+f:(p?s:s+" ".repeat(o-s.length))+f}}function Qj(e,t,n,r){const i=n.enter("paragraph"),s=n.enter("phrasing"),o=n.containerPhrasing(e,r);return s(),i(),o}const e_=Js(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function t_(e,t,n,r){return(e.children.some(function(o){return e_(o)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function n_(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}wh.peek=r_;function wh(e,t,n,r){const i=n_(n),s=n.enter("strong"),o=n.createTracker(r),a=o.move(i+i);let l=o.move(n.containerPhrasing(e,{after:i,before:a,...o.current()}));const u=l.charCodeAt(0),d=ys(r.before.charCodeAt(r.before.length-1),u,i);d.inside&&(l=bi(u)+l.slice(1));const f=l.charCodeAt(l.length-1),h=ys(r.after.charCodeAt(0),f,i);h.inside&&(l=l.slice(0,-1)+bi(f));const p=o.move(i+i);return s(),n.attentionEncodeSurroundingInfo={after:h.outside,before:d.outside},a+l+p}function r_(e,t,n){return n.options.strong||"*"}function i_(e,t,n,r){return n.safe(e.value,r)}function s_(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function o_(e,t,n){const r=(vh(n)+(n.options.ruleSpaces?" ":"")).repeat(s_(n));return n.options.ruleSpaces?r.slice(0,-1):r}const kh={blockquote:Tj,break:su,code:Dj,definition:$j,emphasis:fh,hardBreak:su,heading:Bj,html:ph,image:hh,imageReference:mh,inlineCode:gh,link:yh,linkReference:bh,list:Kj,listItem:Xj,paragraph:Qj,root:t_,strong:wh,text:i_,thematicBreak:o_};function a_(){return{enter:{table:l_,tableData:ou,tableHeader:ou,tableRow:u_},exit:{codeText:d_,table:c_,tableData:Co,tableHeader:Co,tableRow:Co}}}function l_(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function c_(e){this.exit(e),this.data.inTable=void 0}function u_(e){this.enter({type:"tableRow",children:[]},e)}function Co(e){this.exit(e)}function ou(e){this.enter({type:"tableCell",children:[]},e)}function d_(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,f_));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function f_(e,t){return t==="|"?t:e}function p_(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,s=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
181
- `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:h,table:o,tableCell:l,tableRow:a}};function o(p,g,k,S){return u(d(p,k,S),p.align)}function a(p,g,k,S){const y=f(p,k,S),j=u([y]);return j.slice(0,j.indexOf(`
182
- `))}function l(p,g,k,S){const y=k.enter("tableCell"),j=k.enter("phrasing"),m=k.containerPhrasing(p,{...S,before:s,after:s});return j(),y(),m}function u(p,g){return Ej(p,{align:g,alignDelimiters:r,padding:n,stringLength:i})}function d(p,g,k){const S=p.children;let y=-1;const j=[],m=g.enter("table");for(;++y<S.length;)j[y]=f(S[y],g,k);return m(),j}function f(p,g,k){const S=p.children;let y=-1;const j=[],m=g.enter("tableRow");for(;++y<S.length;)j[y]=l(S[y],p,g,k);return m(),j}function h(p,g,k){let S=kh.inlineCode(p,g,k);return k.stack.includes("tableCell")&&(S=S.replace(/\|/g,"\\$&")),S}}function h_(){return{exit:{taskListCheckValueChecked:au,taskListCheckValueUnchecked:au,paragraph:g_}}}function m_(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:x_}}}function au(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function g_(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const a=i[s];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function x_(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(o);let l=kh.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),l;function u(d){return d+o}}function y_(){return[KS(),xj(),wj(),a_(),h_()]}function b_(e){return{extensions:[YS(),yj(e),kj(),p_(e),m_()]}}const v_={tokenize:N_,partial:!0},Sh={tokenize:E_,partial:!0},jh={tokenize:C_,partial:!0},_h={tokenize:T_,partial:!0},w_={tokenize:I_,partial:!0},Nh={name:"wwwAutolink",tokenize:j_,previous:Ch},Eh={name:"protocolAutolink",tokenize:__,previous:Th},fn={name:"emailAutolink",tokenize:S_,previous:Ih},rn={};function k_(){return{text:rn}}let Tn=48;for(;Tn<123;)rn[Tn]=fn,Tn++,Tn===58?Tn=65:Tn===91&&(Tn=97);rn[43]=fn;rn[45]=fn;rn[46]=fn;rn[95]=fn;rn[72]=[fn,Eh];rn[104]=[fn,Eh];rn[87]=[fn,Nh];rn[119]=[fn,Nh];function S_(e,t,n){const r=this;let i,s;return o;function o(f){return!ca(f)||!Ih.call(r,r.previous)||cl(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(f))}function a(f){return ca(f)?(e.consume(f),a):f===64?(e.consume(f),l):n(f)}function l(f){return f===46?e.check(w_,d,u)(f):f===45||f===95||ut(f)?(s=!0,e.consume(f),l):d(f)}function u(f){return e.consume(f),i=!0,l}function d(f){return s&&i&&xt(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function j_(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!Ch.call(r,r.previous)||cl(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(v_,e.attempt(Sh,e.attempt(jh,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function __(e,t,n){const r=this;let i="",s=!1;return o;function o(f){return(f===72||f===104)&&Th.call(r,r.previous)&&!cl(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),a):n(f)}function a(f){if(xt(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),a;if(f===58){const h=i.toLowerCase();if(h==="http"||h==="https")return e.consume(f),l}return n(f)}function l(f){return f===47?(e.consume(f),s?u:(s=!0,l)):n(f)}function u(f){return f===null||ms(f)||Ve(f)||Bn(f)||Vs(f)?n(f):e.attempt(Sh,e.attempt(jh,d),n)(f)}function d(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function N_(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function E_(e,t,n){let r,i,s;return o;function o(u){return u===46||u===95?e.check(_h,l,a)(u):u===null||Ve(u)||Bn(u)||u!==45&&Vs(u)?l(u):(s=!0,e.consume(u),o)}function a(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function l(u){return i||r||!s?n(u):t(u)}}function C_(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(_h,t,s)(o):o===null||Ve(o)||Bn(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function T_(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),i):a===60||a===null||Ve(a)||Bn(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||Ve(a)||Bn(a)?t(a):r(a)}function s(a){return xt(a)?o(a):n(a)}function o(a){return a===59?(e.consume(a),r):xt(a)?(e.consume(a),o):n(a)}}function I_(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return ut(s)?n(s):t(s)}}function Ch(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Ve(e)}function Th(e){return!xt(e)}function Ih(e){return!(e===47||ca(e))}function ca(e){return e===43||e===45||e===46||e===95||ut(e)}function cl(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const A_={tokenize:F_,partial:!0};function z_(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:R_,continuation:{tokenize:$_},exit:M_}},text:{91:{name:"gfmFootnoteCall",tokenize:D_},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:O_,resolveTo:P_}}}}function O_(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const u=Wt(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!s.includes(u.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function P_(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function D_(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return a;function a(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(s>999||f===93&&!o||f===null||f===91||Ve(f))return n(f);if(f===93){e.exit("chunkString");const h=e.exit("gfmFootnoteCallString");return i.includes(Wt(r.sliceSerialize(h)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return Ve(f)||(o=!0),s++,e.consume(f),f===92?d:u}function d(f){return f===91||f===92||f===93?(e.consume(f),s++,u):u(f)}}function R_(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,a;return l;function l(g){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(g){return g===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",d):n(g)}function d(g){if(o>999||g===93&&!a||g===null||g===91||Ve(g))return n(g);if(g===93){e.exit("chunkString");const k=e.exit("gfmFootnoteDefinitionLabelString");return s=Wt(r.sliceSerialize(k)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),h}return Ve(g)||(a=!0),o++,e.consume(g),g===92?f:d}function f(g){return g===91||g===92||g===93?(e.consume(g),o++,d):d(g)}function h(g){return g===58?(e.enter("definitionMarker"),e.consume(g),e.exit("definitionMarker"),i.includes(s)||i.push(s),Pe(e,p,"gfmFootnoteDefinitionWhitespace")):n(g)}function p(g){return t(g)}}function $_(e,t,n){return e.check(zi,t,e.attempt(A_,t,n))}function M_(e){e.exit("gfmFootnoteDefinition")}function F_(e,t,n){const r=this;return Pe(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function L_(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let u=l;for(;u--;)if(o[u][0]==="exit"&&o[u][1].type==="strikethroughSequenceTemporary"&&o[u][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[u][1].end.offset-o[u][1].start.offset){o[l][1].type="strikethroughSequence",o[u][1].type="strikethroughSequence";const d={type:"strikethrough",start:Object.assign({},o[u][1].start),end:Object.assign({},o[l][1].end)},f={type:"strikethroughText",start:Object.assign({},o[u][1].end),end:Object.assign({},o[l][1].start)},h=[["enter",d,a],["enter",o[u][1],a],["exit",o[u][1],a],["enter",f,a]],p=a.parser.constructs.insideSpan.null;p&&At(h,h.length,0,Zs(p,o.slice(u+1,l),a)),At(h,h.length,0,[["exit",f,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",d,a]]),At(o,u-1,l-u+3,h),l=u+h.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function s(o,a,l){const u=this.previous,d=this.events;let f=0;return h;function h(g){return u===126&&d[d.length-1][1].type!=="characterEscape"?l(g):(o.enter("strikethroughSequenceTemporary"),p(g))}function p(g){const k=jr(u);if(g===126)return f>1?l(g):(o.consume(g),f++,p);if(f<2&&!n)return l(g);const S=o.exit("strikethroughSequenceTemporary"),y=jr(g);return S._open=!y||y===2&&!!k,S._close=!k||k===2&&!!y,a(g)}}}class B_{constructor(){this.map=[]}add(t,n,r){V_(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function V_(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function Z_(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function U_(){return{flow:{null:{name:"table",tokenize:J_,resolveAll:H_}}}}function J_(e,t,n){const r=this;let i=0,s=0,o;return a;function a(N){let R=r.events.length-1;for(;R>-1;){const z=r.events[R][1].type;if(z==="lineEnding"||z==="linePrefix")R--;else break}const T=R>-1?r.events[R][1].type:null,F=T==="tableHead"||T==="tableRow"?v:l;return F===v&&r.parser.lazy[r.now().line]?n(N):F(N)}function l(N){return e.enter("tableHead"),e.enter("tableRow"),u(N)}function u(N){return N===124||(o=!0,s+=1),d(N)}function d(N){return N===null?n(N):be(N)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(N),e.exit("lineEnding"),p):n(N):Ie(N)?Pe(e,d,"whitespace")(N):(s+=1,o&&(o=!1,i+=1),N===124?(e.enter("tableCellDivider"),e.consume(N),e.exit("tableCellDivider"),o=!0,d):(e.enter("data"),f(N)))}function f(N){return N===null||N===124||Ve(N)?(e.exit("data"),d(N)):(e.consume(N),N===92?h:f)}function h(N){return N===92||N===124?(e.consume(N),f):f(N)}function p(N){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(N):(e.enter("tableDelimiterRow"),o=!1,Ie(N)?Pe(e,g,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(N):g(N))}function g(N){return N===45||N===58?S(N):N===124?(o=!0,e.enter("tableCellDivider"),e.consume(N),e.exit("tableCellDivider"),k):C(N)}function k(N){return Ie(N)?Pe(e,S,"whitespace")(N):S(N)}function S(N){return N===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(N),e.exit("tableDelimiterMarker"),y):N===45?(s+=1,y(N)):N===null||be(N)?A(N):C(N)}function y(N){return N===45?(e.enter("tableDelimiterFiller"),j(N)):C(N)}function j(N){return N===45?(e.consume(N),j):N===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(N),e.exit("tableDelimiterMarker"),m):(e.exit("tableDelimiterFiller"),m(N))}function m(N){return Ie(N)?Pe(e,A,"whitespace")(N):A(N)}function A(N){return N===124?g(N):N===null||be(N)?!o||i!==s?C(N):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(N)):C(N)}function C(N){return n(N)}function v(N){return e.enter("tableRow"),w(N)}function w(N){return N===124?(e.enter("tableCellDivider"),e.consume(N),e.exit("tableCellDivider"),w):N===null||be(N)?(e.exit("tableRow"),t(N)):Ie(N)?Pe(e,w,"whitespace")(N):(e.enter("data"),O(N))}function O(N){return N===null||N===124||Ve(N)?(e.exit("data"),w(N)):(e.consume(N),N===92?B:O)}function B(N){return N===92||N===124?(e.consume(N),O):O(N)}}function H_(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,u,d,f;const h=new B_;for(;++n<e.length;){const p=e[n],g=p[1];p[0]==="enter"?g.type==="tableHead"?(a=!1,l!==0&&(lu(h,t,l,u,d),d=void 0,l=0),u={type:"table",start:Object.assign({},g.start),end:Object.assign({},g.end)},h.add(n,0,[["enter",u,t]])):g.type==="tableRow"||g.type==="tableDelimiterRow"?(r=!0,f=void 0,s=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,d={type:"tableBody",start:Object.assign({},g.start),end:Object.assign({},g.end)},h.add(n,0,[["enter",d,t]])),i=g.type==="tableDelimiterRow"?2:d?3:1):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],f=Ui(h,t,s,i,void 0,f),s=[0,0,0,0]),o[2]=n)):g.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],f=Ui(h,t,s,i,void 0,f)),s=o,o=[s[1],n,0,0])):g.type==="tableHead"?(a=!0,l=n):g.type==="tableRow"||g.type==="tableDelimiterRow"?(l=n,s[1]!==0?(o[0]=o[1],f=Ui(h,t,s,i,n,f)):o[1]!==0&&(f=Ui(h,t,o,i,n,f)),i=0):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&lu(h,t,l,u,d),h.consume(t.events),n=-1;++n<t.events.length;){const p=t.events[n];p[0]==="enter"&&p[1].type==="table"&&(p[1]._align=Z_(t.events,n))}return e}function Ui(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},ir(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=ir(t.events,n[1]);if(s={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const u=ir(t.events,n[2]),d=ir(t.events,n[3]),f={type:a,start:Object.assign({},u),end:Object.assign({},d)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const h=t.events[n[2]],p=t.events[n[3]];if(h[1].end=Object.assign({},p[1].end),h[1].type="chunkText",h[1].contentType="text",n[3]>n[2]+1){const g=n[2]+1,k=n[3]-n[2]-1;e.add(g,k,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return i!==void 0&&(s.end=Object.assign({},ir(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function lu(e,t,n,r,i){const s=[],o=ir(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function ir(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const W_={name:"tasklistCheck",tokenize:G_};function q_(){return{text:{91:W_}}}function G_(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return Ve(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return be(l)?t(l):Ie(l)?e.check({tokenize:K_},t,n)(l):n(l)}}function K_(e,t,n){return Pe(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function Y_(e){return Bp([k_(),z_(),L_(e),U_(),q_()])}const X_={};function Q_(e){const t=this,n=e||X_,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(Y_(n)),s.push(y_()),o.push(b_(n))}var Ah="vercel.ai.error",eN=Symbol.for(Ah),cu,uu,nn=class zh extends(uu=Error,cu=eN,uu){constructor({name:t,message:n,cause:r}){super(n),this[cu]=!0,this.name=t,this.cause=r}static isInstance(t){return zh.hasMarker(t,Ah)}static hasMarker(t,n){const r=Symbol.for(n);return t!=null&&typeof t=="object"&&r in t&&typeof t[r]=="boolean"&&t[r]===!0}};function Oh(e){return e==null?"unknown error":typeof e=="string"?e:e instanceof Error?e.message:JSON.stringify(e)}var Ph="AI_InvalidArgumentError",Dh=`vercel.ai.error.${Ph}`,tN=Symbol.for(Dh),du,fu,nN=class extends(fu=nn,du=tN,fu){constructor({message:e,cause:t,argument:n}){super({name:Ph,message:e,cause:t}),this[du]=!0,this.argument=n}static isInstance(e){return nn.hasMarker(e,Dh)}},Rh="AI_JSONParseError",$h=`vercel.ai.error.${Rh}`,rN=Symbol.for($h),pu,hu,mu=class extends(hu=nn,pu=rN,hu){constructor({text:e,cause:t}){super({name:Rh,message:`JSON parsing failed: Text: ${e}.
183
- Error message: ${Oh(t)}`,cause:t}),this[pu]=!0,this.text=e}static isInstance(e){return nn.hasMarker(e,$h)}},Mh="AI_TypeValidationError",Fh=`vercel.ai.error.${Mh}`,iN=Symbol.for(Fh),gu,xu,_r=class ua extends(xu=nn,gu=iN,xu){constructor({value:t,cause:n,context:r}){let i="Type validation failed";if(r!=null&&r.field&&(i+=` for ${r.field}`),r!=null&&r.entityName||r!=null&&r.entityId){i+=" (";const s=[];r.entityName&&s.push(r.entityName),r.entityId&&s.push(`id: "${r.entityId}"`),i+=s.join(", "),i+=")"}super({name:Mh,message:`${i}: Value: ${JSON.stringify(t)}.
184
- Error message: ${Oh(n)}`,cause:n}),this[gu]=!0,this.value=t,this.context=r}static isInstance(t){return nn.hasMarker(t,Fh)}static wrap({value:t,cause:n,context:r}){var i,s,o;return ua.isInstance(n)&&n.value===t&&((i=n.context)==null?void 0:i.field)===(r==null?void 0:r.field)&&((s=n.context)==null?void 0:s.entityName)===(r==null?void 0:r.entityName)&&((o=n.context)==null?void 0:o.entityId)===(r==null?void 0:r.entityId)?n:new ua({value:t,cause:n,context:r})}};function q(e,t,n){function r(a,l){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:l,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,l);const u=o.prototype,d=Object.keys(u);for(let f=0;f<d.length;f++){const h=d[f];h in a||(a[h]=u[h].bind(a))}}const i=(n==null?void 0:n.Parent)??Object;class s extends i{}Object.defineProperty(s,"name",{value:e});function o(a){var l;const u=n!=null&&n.Parent?new s:this;r(u,a),(l=u._zod).deferred??(l.deferred=[]);for(const d of u._zod.deferred)d();return u}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var l,u;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(u=(l=a==null?void 0:a._zod)==null?void 0:l.traits)==null?void 0:u.has(e)}}),Object.defineProperty(o,"name",{value:e}),o}class xr extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Lh extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const Bh={};function Sn(e){return Bh}function Vh(e){const t=Object.values(e).filter(r=>typeof r=="number");return Object.entries(e).filter(([r,i])=>t.indexOf(+r)===-1).map(([r,i])=>i)}function da(e,t){return typeof t=="bigint"?t.toString():t}function Ws(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function ul(e){return e==null}function dl(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function sN(e,t){const n=(e.toString().split(".")[1]||"").length,r=t.toString();let i=(r.split(".")[1]||"").length;if(i===0&&/\d?e-\d?/.test(r)){const l=r.match(/\d?e-(\d?)/);l!=null&&l[1]&&(i=Number.parseInt(l[1]))}const s=n>i?n:i,o=Number.parseInt(e.toFixed(s).replace(".","")),a=Number.parseInt(t.toFixed(s).replace(".",""));return o%a/10**s}const yu=Symbol("evaluating");function ze(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==yu)return r===void 0&&(r=yu,r=n()),r},set(i){Object.defineProperty(e,t,{value:i})},configurable:!0})}function Un(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Nn(...e){const t={};for(const n of e){const r=Object.getOwnPropertyDescriptors(n);Object.assign(t,r)}return Object.defineProperties({},t)}function bu(e){return JSON.stringify(e)}function oN(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const Zh="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function vi(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const aN=Ws(()=>{var e;if(typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)!=null&&e.includes("Cloudflare")))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Nr(e){if(vi(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(vi(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Uh(e){return Nr(e)?{...e}:Array.isArray(e)?[...e]:e}const lN=new Set(["string","number","symbol"]);function Er(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function En(e,t,n){const r=new e._zod.constr(t??e._zod.def);return(!t||n!=null&&n.parent)&&(r._zod.parent=e),r}function he(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if((t==null?void 0:t.message)!==void 0){if((t==null?void 0:t.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function cN(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const uN={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function dN(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const s=Nn(e._zod.def,{get shape(){const o={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(o[a]=n.shape[a])}return Un(this,"shape",o),o},checks:[]});return En(e,s)}function fN(e,t){const n=e._zod.def,r=n.checks;if(r&&r.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const s=Nn(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete o[a]}return Un(this,"shape",o),o},checks:[]});return En(e,s)}function pN(e,t){if(!Nr(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const s=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(s,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const i=Nn(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return Un(this,"shape",s),s}});return En(e,i)}function hN(e,t){if(!Nr(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Nn(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t};return Un(this,"shape",r),r}});return En(e,n)}function mN(e,t){const n=Nn(e._zod.def,{get shape(){const r={...e._zod.def.shape,...t._zod.def.shape};return Un(this,"shape",r),r},get catchall(){return t._zod.def.catchall},checks:[]});return En(e,n)}function gN(e,t,n){const i=t._zod.def.checks;if(i&&i.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=Nn(t._zod.def,{get shape(){const a=t._zod.def.shape,l={...a};if(n)for(const u in n){if(!(u in a))throw new Error(`Unrecognized key: "${u}"`);n[u]&&(l[u]=e?new e({type:"optional",innerType:a[u]}):a[u])}else for(const u in a)l[u]=e?new e({type:"optional",innerType:a[u]}):a[u];return Un(this,"shape",l),l},checks:[]});return En(t,o)}function xN(e,t,n){const r=Nn(t._zod.def,{get shape(){const i=t._zod.def.shape,s={...i};if(n)for(const o in n){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(s[o]=new e({type:"nonoptional",innerType:i[o]}))}else for(const o in i)s[o]=new e({type:"nonoptional",innerType:i[o]});return Un(this,"shape",s),s}});return En(t,r)}function lr(e,t=0){var n;if(e.aborted===!0)return!0;for(let r=t;r<e.issues.length;r++)if(((n=e.issues[r])==null?void 0:n.continue)!==!0)return!0;return!1}function cr(e,t){return t.map(n=>{var r;return(r=n).path??(r.path=[]),n.path.unshift(e),n})}function Ji(e){return typeof e=="string"?e:e==null?void 0:e.message}function jn(e,t,n){var i,s,o,a,l,u;const r={...e,path:e.path??[]};if(!e.message){const d=Ji((o=(s=(i=e.inst)==null?void 0:i._zod.def)==null?void 0:s.error)==null?void 0:o.call(s,e))??Ji((a=t==null?void 0:t.error)==null?void 0:a.call(t,e))??Ji((l=n.customError)==null?void 0:l.call(n,e))??Ji((u=n.localeError)==null?void 0:u.call(n,e))??"Invalid input";r.message=d}return delete r.inst,delete r.continue,t!=null&&t.reportInput||delete r.input,r}function fl(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function wi(...e){const[t,n,r]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:r}:{...t}}const Jh=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,da,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Hh=q("$ZodError",Jh),Wh=q("$ZodError",Jh,{Parent:Error});function yN(e,t=n=>n.message){const n={},r=[];for(const i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function bN(e,t=n=>n.message){const n={_errors:[]},r=i=>{for(const s of i.issues)if(s.code==="invalid_union"&&s.errors.length)s.errors.map(o=>r({issues:o}));else if(s.code==="invalid_key")r({issues:s.issues});else if(s.code==="invalid_element")r({issues:s.issues});else if(s.path.length===0)n._errors.push(t(s));else{let o=n,a=0;for(;a<s.path.length;){const l=s.path[a];a===s.path.length-1?(o[l]=o[l]||{_errors:[]},o[l]._errors.push(t(s))):o[l]=o[l]||{_errors:[]},o=o[l],a++}}};return r(e),n}const pl=e=>(t,n,r,i)=>{const s=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},s);if(o instanceof Promise)throw new xr;if(o.issues.length){const a=new((i==null?void 0:i.Err)??e)(o.issues.map(l=>jn(l,s,Sn())));throw Zh(a,i==null?void 0:i.callee),a}return o.value},hl=e=>async(t,n,r,i)=>{const s=r?Object.assign(r,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},s);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((i==null?void 0:i.Err)??e)(o.issues.map(l=>jn(l,s,Sn())));throw Zh(a,i==null?void 0:i.callee),a}return o.value},qs=e=>(t,n,r)=>{const i=r?{...r,async:!1}:{async:!1},s=t._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw new xr;return s.issues.length?{success:!1,error:new(e??Hh)(s.issues.map(o=>jn(o,i,Sn())))}:{success:!0,data:s.value}},vN=qs(Wh),Gs=e=>async(t,n,r)=>{const i=r?Object.assign(r,{async:!0}):{async:!0};let s=t._zod.run({value:n,issues:[]},i);return s instanceof Promise&&(s=await s),s.issues.length?{success:!1,error:new e(s.issues.map(o=>jn(o,i,Sn())))}:{success:!0,data:s.value}},wN=Gs(Wh),kN=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return pl(e)(t,n,i)},SN=e=>(t,n,r)=>pl(e)(t,n,r),jN=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return hl(e)(t,n,i)},_N=e=>async(t,n,r)=>hl(e)(t,n,r),NN=e=>(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return qs(e)(t,n,i)},EN=e=>(t,n,r)=>qs(e)(t,n,r),CN=e=>async(t,n,r)=>{const i=r?Object.assign(r,{direction:"backward"}):{direction:"backward"};return Gs(e)(t,n,i)},TN=e=>async(t,n,r)=>Gs(e)(t,n,r),IN=/^[cC][^\s-]{8,}$/,AN=/^[0-9a-z]+$/,zN=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,ON=/^[0-9a-vA-V]{20}$/,PN=/^[A-Za-z0-9]{27}$/,DN=/^[a-zA-Z0-9_-]{21}$/,RN=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,$N=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,vu=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,MN=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,FN="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function LN(){return new RegExp(FN,"u")}const BN=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,VN=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,ZN=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,UN=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,JN=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,qh=/^[A-Za-z0-9_-]*$/,HN=/^\+[1-9]\d{6,14}$/,Gh="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",WN=new RegExp(`^${Gh}$`);function Kh(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function qN(e){return new RegExp(`^${Kh(e)}$`)}function GN(e){const t=Kh({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const r=`${t}(?:${n.join("|")})`;return new RegExp(`^${Gh}T(?:${r})$`)}const KN=e=>{const t=e?`[\\s\\S]{${(e==null?void 0:e.minimum)??0},${(e==null?void 0:e.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},YN=/^-?\d+$/,Yh=/^-?\d+(?:\.\d+)?$/,XN=/^(?:true|false)$/i,QN=/^null$/i,eE=/^[^A-Z]*$/,tE=/^[^a-z]*$/,Nt=q("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Xh={number:"number",bigint:"bigint",object:"date"},Qh=q("$ZodCheckLessThan",(e,t)=>{Nt.init(e,t);const n=Xh[typeof t.value];e._zod.onattach.push(r=>{const i=r._zod.bag,s=(t.inclusive?i.maximum:i.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<s&&(t.inclusive?i.maximum=t.value:i.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),em=q("$ZodCheckGreaterThan",(e,t)=>{Nt.init(e,t);const n=Xh[typeof t.value];e._zod.onattach.push(r=>{const i=r._zod.bag,s=(t.inclusive?i.minimum:i.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>s&&(t.inclusive?i.minimum=t.value:i.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),nE=q("$ZodCheckMultipleOf",(e,t)=>{Nt.init(e,t),e._zod.onattach.push(n=>{var r;(r=n._zod.bag).multipleOf??(r.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):sN(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),rE=q("$ZodCheckNumberFormat",(e,t)=>{var o;Nt.init(e,t),t.format=t.format||"float64";const n=(o=t.format)==null?void 0:o.includes("int"),r=n?"int":"number",[i,s]=uN[t.format];e._zod.onattach.push(a=>{const l=a._zod.bag;l.format=t.format,l.minimum=i,l.maximum=s,n&&(l.pattern=YN)}),e._zod.check=a=>{const l=a.value;if(n){if(!Number.isInteger(l)){a.issues.push({expected:r,format:t.format,code:"invalid_type",continue:!1,input:l,inst:e});return}if(!Number.isSafeInteger(l)){l>0?a.issues.push({input:l,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort}):a.issues.push({input:l,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}l<i&&a.issues.push({origin:"number",input:l,code:"too_small",minimum:i,inclusive:!0,inst:e,continue:!t.abort}),l>s&&a.issues.push({origin:"number",input:l,code:"too_big",maximum:s,inclusive:!0,inst:e,continue:!t.abort})}}),iE=q("$ZodCheckMaxLength",(e,t)=>{var n;Nt.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!ul(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<i&&(r._zod.bag.maximum=t.maximum)}),e._zod.check=r=>{const i=r.value;if(i.length<=t.maximum)return;const o=fl(i);r.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),sE=q("$ZodCheckMinLength",(e,t)=>{var n;Nt.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!ul(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>i&&(r._zod.bag.minimum=t.minimum)}),e._zod.check=r=>{const i=r.value;if(i.length>=t.minimum)return;const o=fl(i);r.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:i,inst:e,continue:!t.abort})}}),oE=q("$ZodCheckLengthEquals",(e,t)=>{var n;Nt.init(e,t),(n=e._zod.def).when??(n.when=r=>{const i=r.value;return!ul(i)&&i.length!==void 0}),e._zod.onattach.push(r=>{const i=r._zod.bag;i.minimum=t.length,i.maximum=t.length,i.length=t.length}),e._zod.check=r=>{const i=r.value,s=i.length;if(s===t.length)return;const o=fl(i),a=s>t.length;r.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:r.value,inst:e,continue:!t.abort})}}),Ks=q("$ZodCheckStringFormat",(e,t)=>{var n,r;Nt.init(e,t),e._zod.onattach.push(i=>{const s=i._zod.bag;s.format=t.format,t.pattern&&(s.patterns??(s.patterns=new Set),s.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=i=>{t.pattern.lastIndex=0,!t.pattern.test(i.value)&&i.issues.push({origin:"string",code:"invalid_format",format:t.format,input:i.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),aE=q("$ZodCheckRegex",(e,t)=>{Ks.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),lE=q("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=eE),Ks.init(e,t)}),cE=q("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=tE),Ks.init(e,t)}),uE=q("$ZodCheckIncludes",(e,t)=>{Nt.init(e,t);const n=Er(t.includes),r=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(i=>{const s=i._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),e._zod.check=i=>{i.value.includes(t.includes,t.position)||i.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:i.value,inst:e,continue:!t.abort})}}),dE=q("$ZodCheckStartsWith",(e,t)=>{Nt.init(e,t);const n=new RegExp(`^${Er(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=r=>{r.value.startsWith(t.prefix)||r.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:r.value,inst:e,continue:!t.abort})}}),fE=q("$ZodCheckEndsWith",(e,t)=>{Nt.init(e,t);const n=new RegExp(`.*${Er(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(n)}),e._zod.check=r=>{r.value.endsWith(t.suffix)||r.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:r.value,inst:e,continue:!t.abort})}}),pE=q("$ZodCheckOverwrite",(e,t)=>{Nt.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class hE{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const r=t.split(`
185
- `).filter(o=>o),i=Math.min(...r.map(o=>o.length-o.trimStart().length)),s=r.map(o=>o.slice(i)).map(o=>" ".repeat(this.indent*2)+o);for(const o of s)this.content.push(o)}compile(){const t=Function,n=this==null?void 0:this.args,i=[...((this==null?void 0:this.content)??[""]).map(s=>` ${s}`)];return new t(...n,i.join(`
186
- `))}}const mE={major:4,minor:3,patch:6},qe=q("$ZodType",(e,t)=>{var i;var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=mE;const r=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&r.unshift(e);for(const s of r)for(const o of s._zod.onattach)o(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),(i=e._zod.deferred)==null||i.push(()=>{e._zod.run=e._zod.parse});else{const s=(a,l,u)=>{let d=lr(a),f;for(const h of l){if(h._zod.def.when){if(!h._zod.def.when(a))continue}else if(d)continue;const p=a.issues.length,g=h._zod.check(a);if(g instanceof Promise&&(u==null?void 0:u.async)===!1)throw new xr;if(f||g instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await g,a.issues.length!==p&&(d||(d=lr(a,p)))});else{if(a.issues.length===p)continue;d||(d=lr(a,p))}}return f?f.then(()=>a):a},o=(a,l,u)=>{if(lr(a))return a.aborted=!0,a;const d=s(l,r,u);if(d instanceof Promise){if(u.async===!1)throw new xr;return d.then(f=>e._zod.parse(f,u))}return e._zod.parse(d,u)};e._zod.run=(a,l)=>{if(l.skipChecks)return e._zod.parse(a,l);if(l.direction==="backward"){const d=e._zod.parse({value:a.value,issues:[]},{...l,skipChecks:!0});return d instanceof Promise?d.then(f=>o(f,a,l)):o(d,a,l)}const u=e._zod.parse(a,l);if(u instanceof Promise){if(l.async===!1)throw new xr;return u.then(d=>s(d,r,l))}return s(u,r,l)}}ze(e,"~standard",()=>({validate:s=>{var o;try{const a=vN(e,s);return a.success?{value:a.data}:{issues:(o=a.error)==null?void 0:o.issues}}catch{return wN(e,s).then(l=>{var u;return l.success?{value:l.data}:{issues:(u=l.error)==null?void 0:u.issues}})}},vendor:"zod",version:1}))}),ml=q("$ZodString",(e,t)=>{var n;qe.init(e,t),e._zod.pattern=[...((n=e==null?void 0:e._zod.bag)==null?void 0:n.patterns)??[]].pop()??KN(e._zod.bag),e._zod.parse=(r,i)=>{if(t.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:e}),r}}),Ke=q("$ZodStringFormat",(e,t)=>{Ks.init(e,t),ml.init(e,t)}),gE=q("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=$N),Ke.init(e,t)}),xE=q("$ZodUUID",(e,t)=>{if(t.version){const r={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(r===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=vu(r))}else t.pattern??(t.pattern=vu());Ke.init(e,t)}),yE=q("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=MN),Ke.init(e,t)}),bE=q("$ZodURL",(e,t)=>{Ke.init(e,t),e._zod.check=n=>{try{const r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(":")?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=i.href:n.value=r;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),vE=q("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=LN()),Ke.init(e,t)}),wE=q("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=DN),Ke.init(e,t)}),kE=q("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=IN),Ke.init(e,t)}),SE=q("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=AN),Ke.init(e,t)}),jE=q("$ZodULID",(e,t)=>{t.pattern??(t.pattern=zN),Ke.init(e,t)}),_E=q("$ZodXID",(e,t)=>{t.pattern??(t.pattern=ON),Ke.init(e,t)}),NE=q("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=PN),Ke.init(e,t)}),EE=q("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=GN(t)),Ke.init(e,t)}),CE=q("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=WN),Ke.init(e,t)}),TE=q("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=qN(t)),Ke.init(e,t)}),IE=q("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=RN),Ke.init(e,t)}),AE=q("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=BN),Ke.init(e,t),e._zod.bag.format="ipv4"}),zE=q("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=VN),Ke.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),OE=q("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=ZN),Ke.init(e,t)}),PE=q("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=UN),Ke.init(e,t),e._zod.check=n=>{const r=n.value.split("/");try{if(r.length!==2)throw new Error;const[i,s]=r;if(!s)throw new Error;const o=Number(s);if(`${o}`!==s)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${i}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function tm(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const DE=q("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=JN),Ke.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{tm(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function RE(e){if(!qh.test(e))return!1;const t=e.replace(/[-_]/g,r=>r==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return tm(n)}const $E=q("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=qh),Ke.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{RE(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),ME=q("$ZodE164",(e,t)=>{t.pattern??(t.pattern=HN),Ke.init(e,t)});function FE(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[r]=n;if(!r)return!1;const i=JSON.parse(atob(r));return!("typ"in i&&(i==null?void 0:i.typ)!=="JWT"||!i.alg||t&&(!("alg"in i)||i.alg!==t))}catch{return!1}}const LE=q("$ZodJWT",(e,t)=>{Ke.init(e,t),e._zod.check=n=>{FE(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),nm=q("$ZodNumber",(e,t)=>{qe.init(e,t),e._zod.pattern=e._zod.bag.pattern??Yh,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const i=n.value;if(typeof i=="number"&&!Number.isNaN(i)&&Number.isFinite(i))return n;const s=typeof i=="number"?Number.isNaN(i)?"NaN":Number.isFinite(i)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:i,inst:e,...s?{received:s}:{}}),n}}),BE=q("$ZodNumberFormat",(e,t)=>{rE.init(e,t),nm.init(e,t)}),VE=q("$ZodBoolean",(e,t)=>{qe.init(e,t),e._zod.pattern=XN,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}const i=n.value;return typeof i=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:i,inst:e}),n}}),ZE=q("$ZodNull",(e,t)=>{qe.init(e,t),e._zod.pattern=QN,e._zod.values=new Set([null]),e._zod.parse=(n,r)=>{const i=n.value;return i===null||n.issues.push({expected:"null",code:"invalid_type",input:i,inst:e}),n}}),UE=q("$ZodUnknown",(e,t)=>{qe.init(e,t),e._zod.parse=n=>n}),JE=q("$ZodNever",(e,t)=>{qe.init(e,t),e._zod.parse=(n,r)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function wu(e,t,n){e.issues.length&&t.issues.push(...cr(n,e.issues)),t.value[n]=e.value}const HE=q("$ZodArray",(e,t)=>{qe.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Array.isArray(i))return n.issues.push({expected:"array",code:"invalid_type",input:i,inst:e}),n;n.value=Array(i.length);const s=[];for(let o=0;o<i.length;o++){const a=i[o],l=t.element._zod.run({value:a,issues:[]},r);l instanceof Promise?s.push(l.then(u=>wu(u,n,o))):wu(l,n,o)}return s.length?Promise.all(s).then(()=>n):n}});function bs(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...cr(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function rm(e){var r,i,s,o;const t=Object.keys(e.shape);for(const a of t)if(!((o=(s=(i=(r=e.shape)==null?void 0:r[a])==null?void 0:i._zod)==null?void 0:s.traits)!=null&&o.has("$ZodType")))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=cN(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function im(e,t,n,r,i,s){const o=[],a=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optout==="optional";for(const f in t){if(a.has(f))continue;if(u==="never"){o.push(f);continue}const h=l.run({value:t[f],issues:[]},r);h instanceof Promise?e.push(h.then(p=>bs(p,n,f,t,d))):bs(h,n,f,t,d)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:t,inst:s}),e.length?Promise.all(e).then(()=>n):n}const WE=q("$ZodObject",(e,t)=>{qe.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!(n!=null&&n.get)){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const l={...a};return Object.defineProperty(t,"shape",{value:l}),l}})}const r=Ws(()=>rm(t));ze(e._zod,"propValues",()=>{const a=t.shape,l={};for(const u in a){const d=a[u]._zod;if(d.values){l[u]??(l[u]=new Set);for(const f of d.values)l[u].add(f)}}return l});const i=vi,s=t.catchall;let o;e._zod.parse=(a,l)=>{o??(o=r.value);const u=a.value;if(!i(u))return a.issues.push({expected:"object",code:"invalid_type",input:u,inst:e}),a;a.value={};const d=[],f=o.shape;for(const h of o.keys){const p=f[h],g=p._zod.optout==="optional",k=p._zod.run({value:u[h],issues:[]},l);k instanceof Promise?d.push(k.then(S=>bs(S,a,h,u,g))):bs(k,a,h,u,g)}return s?im(d,u,a,l,r.value,e):d.length?Promise.all(d).then(()=>a):a}}),qE=q("$ZodObjectJIT",(e,t)=>{WE.init(e,t);const n=e._zod.parse,r=Ws(()=>rm(t)),i=h=>{var m;const p=new hE(["shape","payload","ctx"]),g=r.value,k=A=>{const C=bu(A);return`shape[${C}]._zod.run({ value: input[${C}], issues: [] }, ctx)`};p.write("const input = payload.value;");const S=Object.create(null);let y=0;for(const A of g.keys)S[A]=`key_${y++}`;p.write("const newResult = {};");for(const A of g.keys){const C=S[A],v=bu(A),w=h[A],O=((m=w==null?void 0:w._zod)==null?void 0:m.optout)==="optional";p.write(`const ${C} = ${k(A)};`),O?p.write(`
187
- if (${C}.issues.length) {
188
- if (${v} in input) {
189
- payload.issues = payload.issues.concat(${C}.issues.map(iss => ({
190
- ...iss,
191
- path: iss.path ? [${v}, ...iss.path] : [${v}]
192
- })));
193
- }
194
- }
195
-
196
- if (${C}.value === undefined) {
197
- if (${v} in input) {
198
- newResult[${v}] = undefined;
199
- }
200
- } else {
201
- newResult[${v}] = ${C}.value;
202
- }
203
-
204
- `):p.write(`
205
- if (${C}.issues.length) {
206
- payload.issues = payload.issues.concat(${C}.issues.map(iss => ({
207
- ...iss,
208
- path: iss.path ? [${v}, ...iss.path] : [${v}]
209
- })));
210
- }
211
-
212
- if (${C}.value === undefined) {
213
- if (${v} in input) {
214
- newResult[${v}] = undefined;
215
- }
216
- } else {
217
- newResult[${v}] = ${C}.value;
218
- }
219
-
220
- `)}p.write("payload.value = newResult;"),p.write("return payload;");const j=p.compile();return(A,C)=>j(h,A,C)};let s;const o=vi,a=!Bh.jitless,u=a&&aN.value,d=t.catchall;let f;e._zod.parse=(h,p)=>{f??(f=r.value);const g=h.value;return o(g)?a&&u&&(p==null?void 0:p.async)===!1&&p.jitless!==!0?(s||(s=i(t.shape)),h=s(h,p),d?im([],g,h,p,f,e):h):n(h,p):(h.issues.push({expected:"object",code:"invalid_type",input:g,inst:e}),h)}});function ku(e,t,n,r){for(const s of e)if(s.issues.length===0)return t.value=s.value,t;const i=e.filter(s=>!lr(s));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(s=>s.issues.map(o=>jn(o,r,Sn())))}),t)}const sm=q("$ZodUnion",(e,t)=>{qe.init(e,t),ze(e._zod,"optin",()=>t.options.some(i=>i._zod.optin==="optional")?"optional":void 0),ze(e._zod,"optout",()=>t.options.some(i=>i._zod.optout==="optional")?"optional":void 0),ze(e._zod,"values",()=>{if(t.options.every(i=>i._zod.values))return new Set(t.options.flatMap(i=>Array.from(i._zod.values)))}),ze(e._zod,"pattern",()=>{if(t.options.every(i=>i._zod.pattern)){const i=t.options.map(s=>s._zod.pattern);return new RegExp(`^(${i.map(s=>dl(s.source)).join("|")})$`)}});const n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,s)=>{if(n)return r(i,s);let o=!1;const a=[];for(const l of t.options){const u=l._zod.run({value:i.value,issues:[]},s);if(u instanceof Promise)a.push(u),o=!0;else{if(u.issues.length===0)return u;a.push(u)}}return o?Promise.all(a).then(l=>ku(l,i,e,s)):ku(a,i,e,s)}}),GE=q("$ZodDiscriminatedUnion",(e,t)=>{t.inclusive=!1,sm.init(e,t);const n=e._zod.parse;ze(e._zod,"propValues",()=>{const i={};for(const s of t.options){const o=s._zod.propValues;if(!o||Object.keys(o).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(s)}"`);for(const[a,l]of Object.entries(o)){i[a]||(i[a]=new Set);for(const u of l)i[a].add(u)}}return i});const r=Ws(()=>{var o;const i=t.options,s=new Map;for(const a of i){const l=(o=a._zod.propValues)==null?void 0:o[t.discriminator];if(!l||l.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(a)}"`);for(const u of l){if(s.has(u))throw new Error(`Duplicate discriminator value "${String(u)}"`);s.set(u,a)}}return s});e._zod.parse=(i,s)=>{const o=i.value;if(!vi(o))return i.issues.push({code:"invalid_type",expected:"object",input:o,inst:e}),i;const a=r.value.get(o==null?void 0:o[t.discriminator]);return a?a._zod.run(i,s):t.unionFallback?n(i,s):(i.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),i)}}),KE=q("$ZodIntersection",(e,t)=>{qe.init(e,t),e._zod.parse=(n,r)=>{const i=n.value,s=t.left._zod.run({value:i,issues:[]},r),o=t.right._zod.run({value:i,issues:[]},r);return s instanceof Promise||o instanceof Promise?Promise.all([s,o]).then(([l,u])=>Su(n,l,u)):Su(n,s,o)}});function fa(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Nr(e)&&Nr(t)){const n=Object.keys(t),r=Object.keys(e).filter(s=>n.indexOf(s)!==-1),i={...e,...t};for(const s of r){const o=fa(e[s],t[s]);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};i[s]=o.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const i=e[r],s=t[r],o=fa(i,s);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function Su(e,t,n){const r=new Map;let i;for(const a of t.issues)if(a.code==="unrecognized_keys"){i??(i=a);for(const l of a.keys)r.has(l)||r.set(l,{}),r.get(l).l=!0}else e.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const l of a.keys)r.has(l)||r.set(l,{}),r.get(l).r=!0;else e.issues.push(a);const s=[...r].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(s.length&&i&&e.issues.push({...i,keys:s}),lr(e))return e;const o=fa(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const YE=q("$ZodRecord",(e,t)=>{qe.init(e,t),e._zod.parse=(n,r)=>{const i=n.value;if(!Nr(i))return n.issues.push({expected:"record",code:"invalid_type",input:i,inst:e}),n;const s=[],o=t.keyType._zod.values;if(o){n.value={};const a=new Set;for(const u of o)if(typeof u=="string"||typeof u=="number"||typeof u=="symbol"){a.add(typeof u=="number"?u.toString():u);const d=t.valueType._zod.run({value:i[u],issues:[]},r);d instanceof Promise?s.push(d.then(f=>{f.issues.length&&n.issues.push(...cr(u,f.issues)),n.value[u]=f.value})):(d.issues.length&&n.issues.push(...cr(u,d.issues)),n.value[u]=d.value)}let l;for(const u in i)a.has(u)||(l=l??[],l.push(u));l&&l.length>0&&n.issues.push({code:"unrecognized_keys",input:i,inst:e,keys:l})}else{n.value={};for(const a of Reflect.ownKeys(i)){if(a==="__proto__")continue;let l=t.keyType._zod.run({value:a,issues:[]},r);if(l instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&Yh.test(a)&&l.issues.length){const f=t.keyType._zod.run({value:Number(a),issues:[]},r);if(f instanceof Promise)throw new Error("Async schemas not supported in object keys currently");f.issues.length===0&&(l=f)}if(l.issues.length){t.mode==="loose"?n.value[a]=i[a]:n.issues.push({code:"invalid_key",origin:"record",issues:l.issues.map(f=>jn(f,r,Sn())),input:a,path:[a],inst:e});continue}const d=t.valueType._zod.run({value:i[a],issues:[]},r);d instanceof Promise?s.push(d.then(f=>{f.issues.length&&n.issues.push(...cr(a,f.issues)),n.value[l.value]=f.value})):(d.issues.length&&n.issues.push(...cr(a,d.issues)),n.value[l.value]=d.value)}}return s.length?Promise.all(s).then(()=>n):n}}),XE=q("$ZodEnum",(e,t)=>{qe.init(e,t);const n=Vh(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=new RegExp(`^(${n.filter(i=>lN.has(typeof i)).map(i=>typeof i=="string"?Er(i):i.toString()).join("|")})$`),e._zod.parse=(i,s)=>{const o=i.value;return r.has(o)||i.issues.push({code:"invalid_value",values:n,input:o,inst:e}),i}}),QE=q("$ZodLiteral",(e,t)=>{if(qe.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?Er(r):r?Er(r.toString()):String(r)).join("|")})$`),e._zod.parse=(r,i)=>{const s=r.value;return n.has(s)||r.issues.push({code:"invalid_value",values:t.values,input:s,inst:e}),r}}),eC=q("$ZodTransform",(e,t)=>{qe.init(e,t),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Lh(e.constructor.name);const i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(o=>(n.value=o,n));if(i instanceof Promise)throw new xr;return n.value=i,n}});function ju(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const om=q("$ZodOptional",(e,t)=>{qe.init(e,t),e._zod.optin="optional",e._zod.optout="optional",ze(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),ze(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${dl(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>{if(t.innerType._zod.optin==="optional"){const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>ju(s,n.value)):ju(i,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,r)}}),tC=q("$ZodExactOptional",(e,t)=>{om.init(e,t),ze(e._zod,"values",()=>t.innerType._zod.values),ze(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,r)=>t.innerType._zod.run(n,r)}),nC=q("$ZodNullable",(e,t)=>{qe.init(e,t),ze(e._zod,"optin",()=>t.innerType._zod.optin),ze(e._zod,"optout",()=>t.innerType._zod.optout),ze(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${dl(n.source)}|null)$`):void 0}),ze(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),rC=q("$ZodDefault",(e,t)=>{qe.init(e,t),e._zod.optin="optional",ze(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);if(n.value===void 0)return n.value=t.defaultValue,n;const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>_u(s,t)):_u(i,t)}});function _u(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const iC=q("$ZodPrefault",(e,t)=>{qe.init(e,t),e._zod.optin="optional",ze(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(r.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),sC=q("$ZodNonOptional",(e,t)=>{qe.init(e,t),ze(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>Nu(s,e)):Nu(i,e)}});function Nu(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const oC=q("$ZodCatch",(e,t)=>{qe.init(e,t),ze(e._zod,"optin",()=>t.innerType._zod.optin),ze(e._zod,"optout",()=>t.innerType._zod.optout),ze(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(s=>(n.value=s.value,s.issues.length&&(n.value=t.catchValue({...n,error:{issues:s.issues.map(o=>jn(o,r,Sn()))},input:n.value}),n.issues=[]),n)):(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(s=>jn(s,r,Sn()))},input:n.value}),n.issues=[]),n)}}),aC=q("$ZodPipe",(e,t)=>{qe.init(e,t),ze(e._zod,"values",()=>t.in._zod.values),ze(e._zod,"optin",()=>t.in._zod.optin),ze(e._zod,"optout",()=>t.out._zod.optout),ze(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(n,r);return s instanceof Promise?s.then(o=>Hi(o,t.in,r)):Hi(s,t.in,r)}const i=t.in._zod.run(n,r);return i instanceof Promise?i.then(s=>Hi(s,t.out,r)):Hi(i,t.out,r)}});function Hi(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const lC=q("$ZodReadonly",(e,t)=>{qe.init(e,t),ze(e._zod,"propValues",()=>t.innerType._zod.propValues),ze(e._zod,"values",()=>t.innerType._zod.values),ze(e._zod,"optin",()=>{var n,r;return(r=(n=t.innerType)==null?void 0:n._zod)==null?void 0:r.optin}),ze(e._zod,"optout",()=>{var n,r;return(r=(n=t.innerType)==null?void 0:n._zod)==null?void 0:r.optout}),e._zod.parse=(n,r)=>{if(r.direction==="backward")return t.innerType._zod.run(n,r);const i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(Eu):Eu(i)}});function Eu(e){return e.value=Object.freeze(e.value),e}const cC=q("$ZodLazy",(e,t)=>{qe.init(e,t),ze(e._zod,"innerType",()=>t.getter()),ze(e._zod,"pattern",()=>{var n,r;return(r=(n=e._zod.innerType)==null?void 0:n._zod)==null?void 0:r.pattern}),ze(e._zod,"propValues",()=>{var n,r;return(r=(n=e._zod.innerType)==null?void 0:n._zod)==null?void 0:r.propValues}),ze(e._zod,"optin",()=>{var n,r;return((r=(n=e._zod.innerType)==null?void 0:n._zod)==null?void 0:r.optin)??void 0}),ze(e._zod,"optout",()=>{var n,r;return((r=(n=e._zod.innerType)==null?void 0:n._zod)==null?void 0:r.optout)??void 0}),e._zod.parse=(n,r)=>e._zod.innerType._zod.run(n,r)}),uC=q("$ZodCustom",(e,t)=>{Nt.init(e,t),qe.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(s=>Cu(s,n,r,e));Cu(i,n,r,e)}});function Cu(e,t,n,r){if(!e){const i={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(i.params=r._zod.def.params),t.issues.push(wi(i))}}var Tu;class dC{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const r=n[0];return this._map.set(t,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};delete r.id;const i={...r,...this._map.get(t)};return Object.keys(i).length?i:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function fC(){return new dC}(Tu=globalThis).__zod_globalRegistry??(Tu.__zod_globalRegistry=fC());const Xr=globalThis.__zod_globalRegistry;function pC(e,t){return new e({type:"string",...he(t)})}function hC(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...he(t)})}function Iu(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...he(t)})}function mC(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...he(t)})}function gC(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...he(t)})}function xC(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...he(t)})}function yC(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...he(t)})}function bC(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...he(t)})}function vC(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...he(t)})}function wC(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...he(t)})}function kC(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...he(t)})}function SC(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...he(t)})}function jC(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...he(t)})}function _C(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...he(t)})}function NC(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...he(t)})}function EC(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...he(t)})}function CC(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...he(t)})}function TC(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...he(t)})}function IC(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...he(t)})}function AC(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...he(t)})}function zC(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...he(t)})}function OC(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...he(t)})}function PC(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...he(t)})}function DC(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...he(t)})}function RC(e,t){return new e({type:"string",format:"date",check:"string_format",...he(t)})}function $C(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...he(t)})}function MC(e,t){return new e({type:"string",format:"duration",check:"string_format",...he(t)})}function FC(e,t){return new e({type:"number",checks:[],...he(t)})}function LC(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...he(t)})}function BC(e,t){return new e({type:"boolean",...he(t)})}function VC(e,t){return new e({type:"null",...he(t)})}function ZC(e){return new e({type:"unknown"})}function UC(e,t){return new e({type:"never",...he(t)})}function Au(e,t){return new Qh({check:"less_than",...he(t),value:e,inclusive:!1})}function To(e,t){return new Qh({check:"less_than",...he(t),value:e,inclusive:!0})}function zu(e,t){return new em({check:"greater_than",...he(t),value:e,inclusive:!1})}function Io(e,t){return new em({check:"greater_than",...he(t),value:e,inclusive:!0})}function Ou(e,t){return new nE({check:"multiple_of",...he(t),value:e})}function am(e,t){return new iE({check:"max_length",...he(t),maximum:e})}function vs(e,t){return new sE({check:"min_length",...he(t),minimum:e})}function lm(e,t){return new oE({check:"length_equals",...he(t),length:e})}function JC(e,t){return new aE({check:"string_format",format:"regex",...he(t),pattern:e})}function HC(e){return new lE({check:"string_format",format:"lowercase",...he(e)})}function WC(e){return new cE({check:"string_format",format:"uppercase",...he(e)})}function qC(e,t){return new uE({check:"string_format",format:"includes",...he(t),includes:e})}function GC(e,t){return new dE({check:"string_format",format:"starts_with",...he(t),prefix:e})}function KC(e,t){return new fE({check:"string_format",format:"ends_with",...he(t),suffix:e})}function Pr(e){return new pE({check:"overwrite",tx:e})}function YC(e){return Pr(t=>t.normalize(e))}function XC(){return Pr(e=>e.trim())}function QC(){return Pr(e=>e.toLowerCase())}function eT(){return Pr(e=>e.toUpperCase())}function tT(){return Pr(e=>oN(e))}function nT(e,t,n){return new e({type:"array",element:t,...he(n)})}function rT(e,t,n){const r=he(n);return r.abort??(r.abort=!0),new e({type:"custom",check:"custom",fn:t,...r})}function iT(e,t,n){return new e({type:"custom",check:"custom",fn:t,...he(n)})}function sT(e){const t=oT(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(wi(r,n.value,t._zod.def));else{const i=r;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=n.value),i.inst??(i.inst=t),i.continue??(i.continue=!t._zod.def.abort),n.issues.push(wi(i))}},e(n.value,n)));return t}function oT(e,t){const n=new Nt({check:"custom",...he(t)});return n._zod.check=e,n}function ws(e){let t=(e==null?void 0:e.target)??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:(e==null?void 0:e.metadata)??Xr,target:t,unrepresentable:(e==null?void 0:e.unrepresentable)??"throw",override:(e==null?void 0:e.override)??(()=>{}),io:(e==null?void 0:e.io)??"output",counter:0,seen:new Map,cycles:(e==null?void 0:e.cycles)??"ref",reused:(e==null?void 0:e.reused)??"inline",external:(e==null?void 0:e.external)??void 0}}function Ue(e,t,n={path:[],schemaPath:[]}){var d,f;var r;const i=e._zod.def,s=t.seen.get(e);if(s)return s.count++,n.schemaPath.includes(e)&&(s.cycle=n.path),s.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);const a=(f=(d=e._zod).toJSONSchema)==null?void 0:f.call(d);if(a)o.schema=a;else{const h={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,h);else{const g=o.schema,k=t.processors[i.type];if(!k)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);k(e,t,g,h)}const p=e._zod.parent;p&&(o.ref||(o.ref=p),Ue(p,t,h),t.seen.get(p).isParent=!0)}const l=t.metadataRegistry.get(e);return l&&Object.assign(o.schema,l),t.io==="input"&&pt(e)&&(delete o.schema.examples,delete o.schema.default),t.io==="input"&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function ks(e,t){var o,a,l,u;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const d of e.seen.entries()){const f=(o=e.metadataRegistry.get(d[0]))==null?void 0:o.id;if(f){const h=r.get(f);if(h&&h!==d[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(f,d[0])}}const i=d=>{var k;const f=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const S=(k=e.external.registry.get(d[0]))==null?void 0:k.id,y=e.external.uri??(m=>m);if(S)return{ref:y(S)};const j=d[1].defId??d[1].schema.id??`schema${e.counter++}`;return d[1].defId=j,{defId:j,ref:`${y("__shared")}#/${f}/${j}`}}if(d[1]===n)return{ref:"#"};const p=`#/${f}/`,g=d[1].schema.id??`__schema${e.counter++}`;return{defId:g,ref:p+g}},s=d=>{if(d[1].schema.$ref)return;const f=d[1],{ref:h,defId:p}=i(d);f.def={...f.schema},p&&(f.defId=p);const g=f.schema;for(const k in g)delete g[k];g.$ref=h};if(e.cycles==="throw")for(const d of e.seen.entries()){const f=d[1];if(f.cycle)throw new Error(`Cycle detected: #/${(a=f.cycle)==null?void 0:a.join("/")}/<root>
221
-
222
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const d of e.seen.entries()){const f=d[1];if(t===d[0]){s(d);continue}if(e.external){const p=(l=e.external.registry.get(d[0]))==null?void 0:l.id;if(t!==d[0]&&p){s(d);continue}}if((u=e.metadataRegistry.get(d[0]))==null?void 0:u.id){s(d);continue}if(f.cycle){s(d);continue}if(f.count>1&&e.reused==="ref"){s(d);continue}}}function Ss(e,t){var o,a,l;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=u=>{const d=e.seen.get(u);if(d.ref===null)return;const f=d.def??d.schema,h={...f},p=d.ref;if(d.ref=null,p){r(p);const k=e.seen.get(p),S=k.schema;if(S.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(f.allOf=f.allOf??[],f.allOf.push(S)):Object.assign(f,S),Object.assign(f,h),u._zod.parent===p)for(const j in f)j==="$ref"||j==="allOf"||j in h||delete f[j];if(S.$ref&&k.def)for(const j in f)j==="$ref"||j==="allOf"||j in k.def&&JSON.stringify(f[j])===JSON.stringify(k.def[j])&&delete f[j]}const g=u._zod.parent;if(g&&g!==p){r(g);const k=e.seen.get(g);if(k!=null&&k.schema.$ref&&(f.$ref=k.schema.$ref,k.def))for(const S in f)S==="$ref"||S==="allOf"||S in k.def&&JSON.stringify(f[S])===JSON.stringify(k.def[S])&&delete f[S]}e.override({zodSchema:u,jsonSchema:f,path:d.path??[]})};for(const u of[...e.seen.entries()].reverse())r(u[0]);const i={};if(e.target==="draft-2020-12"?i.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?i.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?i.$schema="http://json-schema.org/draft-04/schema#":e.target,(o=e.external)!=null&&o.uri){const u=(a=e.external.registry.get(t))==null?void 0:a.id;if(!u)throw new Error("Schema is missing an `id` property");i.$id=e.external.uri(u)}Object.assign(i,n.def??n.schema);const s=((l=e.external)==null?void 0:l.defs)??{};for(const u of e.seen.entries()){const d=u[1];d.def&&d.defId&&(s[d.defId]=d.def)}e.external||Object.keys(s).length>0&&(e.target==="draft-2020-12"?i.$defs=s:i.definitions=s);try{const u=JSON.parse(JSON.stringify(i));return Object.defineProperty(u,"~standard",{value:{...t["~standard"],jsonSchema:{input:js(t,"input",e.processors),output:js(t,"output",e.processors)}},enumerable:!1,writable:!1}),u}catch{throw new Error("Error converting schema to JSON.")}}function pt(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const r=e._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return pt(r.element,n);if(r.type==="set")return pt(r.valueType,n);if(r.type==="lazy")return pt(r.getter(),n);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return pt(r.innerType,n);if(r.type==="intersection")return pt(r.left,n)||pt(r.right,n);if(r.type==="record"||r.type==="map")return pt(r.keyType,n)||pt(r.valueType,n);if(r.type==="pipe")return pt(r.in,n)||pt(r.out,n);if(r.type==="object"){for(const i in r.shape)if(pt(r.shape[i],n))return!0;return!1}if(r.type==="union"){for(const i of r.options)if(pt(i,n))return!0;return!1}if(r.type==="tuple"){for(const i of r.items)if(pt(i,n))return!0;return!!(r.rest&&pt(r.rest,n))}return!1}const aT=(e,t={})=>n=>{const r=ws({...n,processors:t});return Ue(e,r),ks(r,e),Ss(r,e)},js=(e,t,n={})=>r=>{const{libraryOptions:i,target:s}=r??{},o=ws({...i??{},target:s,io:t,processors:n});return Ue(e,o),ks(o,e),Ss(o,e)},lT={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},cm=(e,t,n,r)=>{const i=n;i.type="string";const{minimum:s,maximum:o,format:a,patterns:l,contentEncoding:u}=e._zod.bag;if(typeof s=="number"&&(i.minLength=s),typeof o=="number"&&(i.maxLength=o),a&&(i.format=lT[a]??a,i.format===""&&delete i.format,a==="time"&&delete i.format),u&&(i.contentEncoding=u),l&&l.size>0){const d=[...l];d.length===1?i.pattern=d[0].source:d.length>1&&(i.allOf=[...d.map(f=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},um=(e,t,n,r)=>{const i=n,{minimum:s,maximum:o,format:a,multipleOf:l,exclusiveMaximum:u,exclusiveMinimum:d}=e._zod.bag;typeof a=="string"&&a.includes("int")?i.type="integer":i.type="number",typeof d=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(i.minimum=d,i.exclusiveMinimum=!0):i.exclusiveMinimum=d),typeof s=="number"&&(i.minimum=s,typeof d=="number"&&t.target!=="draft-04"&&(d>=s?delete i.minimum:delete i.exclusiveMinimum)),typeof u=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(i.maximum=u,i.exclusiveMaximum=!0):i.exclusiveMaximum=u),typeof o=="number"&&(i.maximum=o,typeof u=="number"&&t.target!=="draft-04"&&(u<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof l=="number"&&(i.multipleOf=l)},dm=(e,t,n,r)=>{n.type="boolean"},cT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("BigInt cannot be represented in JSON Schema")},uT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Symbols cannot be represented in JSON Schema")},fm=(e,t,n,r)=>{t.target==="openapi-3.0"?(n.type="string",n.nullable=!0,n.enum=[null]):n.type="null"},dT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Undefined cannot be represented in JSON Schema")},fT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Void cannot be represented in JSON Schema")},pm=(e,t,n,r)=>{n.not={}},pT=(e,t,n,r)=>{},hm=(e,t,n,r)=>{},hT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Date cannot be represented in JSON Schema")},mm=(e,t,n,r)=>{const i=e._zod.def,s=Vh(i.entries);s.every(o=>typeof o=="number")&&(n.type="number"),s.every(o=>typeof o=="string")&&(n.type="string"),n.enum=s},gm=(e,t,n,r)=>{const i=e._zod.def,s=[];for(const o of i.values)if(o===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");s.push(Number(o))}else s.push(o);if(s.length!==0)if(s.length===1){const o=s[0];n.type=o===null?"null":typeof o,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[o]:n.const=o}else s.every(o=>typeof o=="number")&&(n.type="number"),s.every(o=>typeof o=="string")&&(n.type="string"),s.every(o=>typeof o=="boolean")&&(n.type="boolean"),s.every(o=>o===null)&&(n.type="null"),n.enum=s},mT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("NaN cannot be represented in JSON Schema")},gT=(e,t,n,r)=>{const i=n,s=e._zod.pattern;if(!s)throw new Error("Pattern not found in template literal");i.type="string",i.pattern=s.source},xT=(e,t,n,r)=>{const i=n,s={type:"string",format:"binary",contentEncoding:"binary"},{minimum:o,maximum:a,mime:l}=e._zod.bag;o!==void 0&&(s.minLength=o),a!==void 0&&(s.maxLength=a),l?l.length===1?(s.contentMediaType=l[0],Object.assign(i,s)):(Object.assign(i,s),i.anyOf=l.map(u=>({contentMediaType:u}))):Object.assign(i,s)},yT=(e,t,n,r)=>{n.type="boolean"},xm=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},bT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Function types cannot be represented in JSON Schema")},ym=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},vT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Map cannot be represented in JSON Schema")},wT=(e,t,n,r)=>{if(t.unrepresentable==="throw")throw new Error("Set cannot be represented in JSON Schema")},bm=(e,t,n,r)=>{const i=n,s=e._zod.def,{minimum:o,maximum:a}=e._zod.bag;typeof o=="number"&&(i.minItems=o),typeof a=="number"&&(i.maxItems=a),i.type="array",i.items=Ue(s.element,t,{...r,path:[...r.path,"items"]})},vm=(e,t,n,r)=>{var u;const i=n,s=e._zod.def;i.type="object",i.properties={};const o=s.shape;for(const d in o)i.properties[d]=Ue(o[d],t,{...r,path:[...r.path,"properties",d]});const a=new Set(Object.keys(o)),l=new Set([...a].filter(d=>{const f=s.shape[d]._zod;return t.io==="input"?f.optin===void 0:f.optout===void 0}));l.size>0&&(i.required=Array.from(l)),((u=s.catchall)==null?void 0:u._zod.def.type)==="never"?i.additionalProperties=!1:s.catchall?s.catchall&&(i.additionalProperties=Ue(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(i.additionalProperties=!1)},wm=(e,t,n,r)=>{const i=e._zod.def,s=i.inclusive===!1,o=i.options.map((a,l)=>Ue(a,t,{...r,path:[...r.path,s?"oneOf":"anyOf",l]}));s?n.oneOf=o:n.anyOf=o},km=(e,t,n,r)=>{const i=e._zod.def,s=Ue(i.left,t,{...r,path:[...r.path,"allOf",0]}),o=Ue(i.right,t,{...r,path:[...r.path,"allOf",1]}),a=u=>"allOf"in u&&Object.keys(u).length===1,l=[...a(s)?s.allOf:[s],...a(o)?o.allOf:[o]];n.allOf=l},kT=(e,t,n,r)=>{const i=n,s=e._zod.def;i.type="array";const o=t.target==="draft-2020-12"?"prefixItems":"items",a=t.target==="draft-2020-12"||t.target==="openapi-3.0"?"items":"additionalItems",l=s.items.map((h,p)=>Ue(h,t,{...r,path:[...r.path,o,p]})),u=s.rest?Ue(s.rest,t,{...r,path:[...r.path,a,...t.target==="openapi-3.0"?[s.items.length]:[]]}):null;t.target==="draft-2020-12"?(i.prefixItems=l,u&&(i.items=u)):t.target==="openapi-3.0"?(i.items={anyOf:l},u&&i.items.anyOf.push(u),i.minItems=l.length,u||(i.maxItems=l.length)):(i.items=l,u&&(i.additionalItems=u));const{minimum:d,maximum:f}=e._zod.bag;typeof d=="number"&&(i.minItems=d),typeof f=="number"&&(i.maxItems=f)},Sm=(e,t,n,r)=>{const i=n,s=e._zod.def;i.type="object";const o=s.keyType,a=o._zod.bag,l=a==null?void 0:a.patterns;if(s.mode==="loose"&&l&&l.size>0){const d=Ue(s.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});i.patternProperties={};for(const f of l)i.patternProperties[f.source]=d}else(t.target==="draft-07"||t.target==="draft-2020-12")&&(i.propertyNames=Ue(s.keyType,t,{...r,path:[...r.path,"propertyNames"]})),i.additionalProperties=Ue(s.valueType,t,{...r,path:[...r.path,"additionalProperties"]});const u=o._zod.values;if(u){const d=[...u].filter(f=>typeof f=="string"||typeof f=="number");d.length>0&&(i.required=d)}},jm=(e,t,n,r)=>{const i=e._zod.def,s=Ue(i.innerType,t,r),o=t.seen.get(e);t.target==="openapi-3.0"?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[s,{type:"null"}]},_m=(e,t,n,r)=>{const i=e._zod.def;Ue(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType},Nm=(e,t,n,r)=>{const i=e._zod.def;Ue(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Em=(e,t,n,r)=>{const i=e._zod.def;Ue(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Cm=(e,t,n,r)=>{const i=e._zod.def;Ue(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},Tm=(e,t,n,r)=>{const i=e._zod.def,s=t.io==="input"?i.in._zod.def.type==="transform"?i.out:i.in:i.out;Ue(s,t,r);const o=t.seen.get(e);o.ref=s},Im=(e,t,n,r)=>{const i=e._zod.def;Ue(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType,n.readOnly=!0},ST=(e,t,n,r)=>{const i=e._zod.def;Ue(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType},gl=(e,t,n,r)=>{const i=e._zod.def;Ue(i.innerType,t,r);const s=t.seen.get(e);s.ref=i.innerType},Am=(e,t,n,r)=>{const i=e._zod.innerType;Ue(i,t,r);const s=t.seen.get(e);s.ref=i},Pu={string:cm,number:um,boolean:dm,bigint:cT,symbol:uT,null:fm,undefined:dT,void:fT,never:pm,any:pT,unknown:hm,date:hT,enum:mm,literal:gm,nan:mT,template_literal:gT,file:xT,success:yT,custom:xm,function:bT,transform:ym,map:vT,set:wT,array:bm,object:vm,union:wm,intersection:km,tuple:kT,record:Sm,nullable:jm,nonoptional:_m,default:Nm,prefault:Em,catch:Cm,pipe:Tm,readonly:Im,promise:ST,optional:gl,lazy:Am};function jT(e,t){if("_idmap"in e){const r=e,i=ws({...t,processors:Pu}),s={};for(const l of r._idmap.entries()){const[u,d]=l;Ue(d,i)}const o={},a={registry:r,uri:t==null?void 0:t.uri,defs:s};i.external=a;for(const l of r._idmap.entries()){const[u,d]=l;ks(i,d),o[u]=Ss(i,d)}if(Object.keys(s).length>0){const l=i.target==="draft-2020-12"?"$defs":"definitions";o.__shared={[l]:s}}return{schemas:o}}const n=ws({...t,processors:Pu});return Ue(e,n),ks(n,e),Ss(n,e)}const _T=q("ZodISODateTime",(e,t)=>{EE.init(e,t),et.init(e,t)});function NT(e){return DC(_T,e)}const ET=q("ZodISODate",(e,t)=>{CE.init(e,t),et.init(e,t)});function CT(e){return RC(ET,e)}const TT=q("ZodISOTime",(e,t)=>{TE.init(e,t),et.init(e,t)});function IT(e){return $C(TT,e)}const AT=q("ZodISODuration",(e,t)=>{IE.init(e,t),et.init(e,t)});function zT(e){return MC(AT,e)}const OT=(e,t)=>{Hh.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>bN(e,n)},flatten:{value:n=>yN(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,da,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,da,2)}},isEmpty:{get(){return e.issues.length===0}}})},Ft=q("ZodError",OT,{Parent:Error}),PT=pl(Ft),DT=hl(Ft),RT=qs(Ft),zm=Gs(Ft),$T=kN(Ft),MT=SN(Ft),FT=jN(Ft),LT=_N(Ft),BT=NN(Ft),VT=EN(Ft),ZT=CN(Ft),UT=TN(Ft),Ge=q("ZodType",(e,t)=>(qe.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:js(e,"input"),output:js(e,"output")}}),e.toJSONSchema=aT(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Nn(t,{checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),e.with=e.check,e.clone=(n,r)=>En(e,n,r),e.brand=()=>e,e.register=(n,r)=>(n.add(e,r),e),e.parse=(n,r)=>PT(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>RT(e,n,r),e.parseAsync=async(n,r)=>DT(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>zm(e,n,r),e.spa=e.safeParseAsync,e.encode=(n,r)=>$T(e,n,r),e.decode=(n,r)=>MT(e,n,r),e.encodeAsync=async(n,r)=>FT(e,n,r),e.decodeAsync=async(n,r)=>LT(e,n,r),e.safeEncode=(n,r)=>BT(e,n,r),e.safeDecode=(n,r)=>VT(e,n,r),e.safeEncodeAsync=async(n,r)=>ZT(e,n,r),e.safeDecodeAsync=async(n,r)=>UT(e,n,r),e.refine=(n,r)=>e.check(LI(n,r)),e.superRefine=n=>e.check(BI(n)),e.overwrite=n=>e.check(Pr(n)),e.optional=()=>$u(e),e.exactOptional=()=>NI(e),e.nullable=()=>Mu(e),e.nullish=()=>$u(Mu(e)),e.nonoptional=n=>zI(e,n),e.array=()=>Dr(e),e.or=n=>yt([e,n]),e.and=n=>vI(e,n),e.transform=n=>Fu(e,jI(n)),e.default=n=>TI(e,n),e.prefault=n=>AI(e,n),e.catch=n=>PI(e,n),e.pipe=n=>Fu(e,n),e.readonly=()=>$I(e),e.describe=n=>{const r=e.clone();return Xr.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){var n;return(n=Xr.get(e))==null?void 0:n.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return Xr.get(e);const r=e.clone();return Xr.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),Om=q("_ZodString",(e,t)=>{ml.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(r,i,s)=>cm(e,r,i);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...r)=>e.check(JC(...r)),e.includes=(...r)=>e.check(qC(...r)),e.startsWith=(...r)=>e.check(GC(...r)),e.endsWith=(...r)=>e.check(KC(...r)),e.min=(...r)=>e.check(vs(...r)),e.max=(...r)=>e.check(am(...r)),e.length=(...r)=>e.check(lm(...r)),e.nonempty=(...r)=>e.check(vs(1,...r)),e.lowercase=r=>e.check(HC(r)),e.uppercase=r=>e.check(WC(r)),e.trim=()=>e.check(XC()),e.normalize=(...r)=>e.check(YC(...r)),e.toLowerCase=()=>e.check(QC()),e.toUpperCase=()=>e.check(eT()),e.slugify=()=>e.check(tT())}),JT=q("ZodString",(e,t)=>{ml.init(e,t),Om.init(e,t),e.email=n=>e.check(hC(HT,n)),e.url=n=>e.check(bC(WT,n)),e.jwt=n=>e.check(PC(lI,n)),e.emoji=n=>e.check(vC(qT,n)),e.guid=n=>e.check(Iu(Du,n)),e.uuid=n=>e.check(mC(Wi,n)),e.uuidv4=n=>e.check(gC(Wi,n)),e.uuidv6=n=>e.check(xC(Wi,n)),e.uuidv7=n=>e.check(yC(Wi,n)),e.nanoid=n=>e.check(wC(GT,n)),e.guid=n=>e.check(Iu(Du,n)),e.cuid=n=>e.check(kC(KT,n)),e.cuid2=n=>e.check(SC(YT,n)),e.ulid=n=>e.check(jC(XT,n)),e.base64=n=>e.check(AC(sI,n)),e.base64url=n=>e.check(zC(oI,n)),e.xid=n=>e.check(_C(QT,n)),e.ksuid=n=>e.check(NC(eI,n)),e.ipv4=n=>e.check(EC(tI,n)),e.ipv6=n=>e.check(CC(nI,n)),e.cidrv4=n=>e.check(TC(rI,n)),e.cidrv6=n=>e.check(IC(iI,n)),e.e164=n=>e.check(OC(aI,n)),e.datetime=n=>e.check(NT(n)),e.date=n=>e.check(CT(n)),e.time=n=>e.check(IT(n)),e.duration=n=>e.check(zT(n))});function le(e){return pC(JT,e)}const et=q("ZodStringFormat",(e,t)=>{Ke.init(e,t),Om.init(e,t)}),HT=q("ZodEmail",(e,t)=>{yE.init(e,t),et.init(e,t)}),Du=q("ZodGUID",(e,t)=>{gE.init(e,t),et.init(e,t)}),Wi=q("ZodUUID",(e,t)=>{xE.init(e,t),et.init(e,t)}),WT=q("ZodURL",(e,t)=>{bE.init(e,t),et.init(e,t)}),qT=q("ZodEmoji",(e,t)=>{vE.init(e,t),et.init(e,t)}),GT=q("ZodNanoID",(e,t)=>{wE.init(e,t),et.init(e,t)}),KT=q("ZodCUID",(e,t)=>{kE.init(e,t),et.init(e,t)}),YT=q("ZodCUID2",(e,t)=>{SE.init(e,t),et.init(e,t)}),XT=q("ZodULID",(e,t)=>{jE.init(e,t),et.init(e,t)}),QT=q("ZodXID",(e,t)=>{_E.init(e,t),et.init(e,t)}),eI=q("ZodKSUID",(e,t)=>{NE.init(e,t),et.init(e,t)}),tI=q("ZodIPv4",(e,t)=>{AE.init(e,t),et.init(e,t)}),nI=q("ZodIPv6",(e,t)=>{zE.init(e,t),et.init(e,t)}),rI=q("ZodCIDRv4",(e,t)=>{OE.init(e,t),et.init(e,t)}),iI=q("ZodCIDRv6",(e,t)=>{PE.init(e,t),et.init(e,t)}),sI=q("ZodBase64",(e,t)=>{DE.init(e,t),et.init(e,t)}),oI=q("ZodBase64URL",(e,t)=>{$E.init(e,t),et.init(e,t)}),aI=q("ZodE164",(e,t)=>{ME.init(e,t),et.init(e,t)}),lI=q("ZodJWT",(e,t)=>{LE.init(e,t),et.init(e,t)}),Pm=q("ZodNumber",(e,t)=>{nm.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(r,i,s)=>um(e,r,i),e.gt=(r,i)=>e.check(zu(r,i)),e.gte=(r,i)=>e.check(Io(r,i)),e.min=(r,i)=>e.check(Io(r,i)),e.lt=(r,i)=>e.check(Au(r,i)),e.lte=(r,i)=>e.check(To(r,i)),e.max=(r,i)=>e.check(To(r,i)),e.int=r=>e.check(Ru(r)),e.safe=r=>e.check(Ru(r)),e.positive=r=>e.check(zu(0,r)),e.nonnegative=r=>e.check(Io(0,r)),e.negative=r=>e.check(Au(0,r)),e.nonpositive=r=>e.check(To(0,r)),e.multipleOf=(r,i)=>e.check(Ou(r,i)),e.step=(r,i)=>e.check(Ou(r,i)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function cI(e){return FC(Pm,e)}const uI=q("ZodNumberFormat",(e,t)=>{BE.init(e,t),Pm.init(e,t)});function Ru(e){return LC(uI,e)}const dI=q("ZodBoolean",(e,t)=>{VE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>dm(e,n,r)});function ht(e){return BC(dI,e)}const fI=q("ZodNull",(e,t)=>{ZE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>fm(e,n,r)});function pI(e){return VC(fI,e)}const hI=q("ZodUnknown",(e,t)=>{UE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>hm()});function Xt(){return ZC(hI)}const mI=q("ZodNever",(e,t)=>{JE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>pm(e,n,r)});function Dm(e){return UC(mI,e)}const gI=q("ZodArray",(e,t)=>{HE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>bm(e,n,r,i),e.element=t.element,e.min=(n,r)=>e.check(vs(n,r)),e.nonempty=n=>e.check(vs(1,n)),e.max=(n,r)=>e.check(am(n,r)),e.length=(n,r)=>e.check(lm(n,r)),e.unwrap=()=>e.element});function Dr(e,t){return nT(gI,e,t)}const Rm=q("ZodObject",(e,t)=>{qE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>vm(e,n,r,i),ze(e,"shape",()=>t.shape),e.keyof=()=>Mm(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Xt()}),e.loose=()=>e.clone({...e._zod.def,catchall:Xt()}),e.strict=()=>e.clone({...e._zod.def,catchall:Dm()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>pN(e,n),e.safeExtend=n=>hN(e,n),e.merge=n=>mN(e,n),e.pick=n=>dN(e,n),e.omit=n=>fN(e,n),e.partial=(...n)=>gN(Fm,e,n[0]),e.required=(...n)=>xN(Lm,e,n[0])});function Be(e,t){const n={type:"object",shape:e??{},...he(t)};return new Rm(n)}function He(e,t){return new Rm({type:"object",shape:e,catchall:Dm(),...he(t)})}const $m=q("ZodUnion",(e,t)=>{sm.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>wm(e,n,r,i),e.options=t.options});function yt(e,t){return new $m({type:"union",options:e,...he(t)})}const xI=q("ZodDiscriminatedUnion",(e,t)=>{$m.init(e,t),GE.init(e,t)});function yI(e,t,n){return new xI({type:"union",options:t,discriminator:e,...he(n)})}const bI=q("ZodIntersection",(e,t)=>{KE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>km(e,n,r,i)});function vI(e,t){return new bI({type:"intersection",left:e,right:t})}const wI=q("ZodRecord",(e,t)=>{YE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>Sm(e,n,r,i),e.keyType=t.keyType,e.valueType=t.valueType});function ki(e,t,n){return new wI({type:"record",keyType:e,valueType:t,...he(n)})}const pa=q("ZodEnum",(e,t)=>{XE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(r,i,s)=>mm(e,r,i),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,i)=>{const s={};for(const o of r)if(n.has(o))s[o]=t.entries[o];else throw new Error(`Key ${o} not found in enum`);return new pa({...t,checks:[],...he(i),entries:s})},e.exclude=(r,i)=>{const s={...t.entries};for(const o of r)if(n.has(o))delete s[o];else throw new Error(`Key ${o} not found in enum`);return new pa({...t,checks:[],...he(i),entries:s})}});function Mm(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new pa({type:"enum",entries:n,...he(t)})}const kI=q("ZodLiteral",(e,t)=>{QE.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>gm(e,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function ve(e,t){return new kI({type:"literal",values:Array.isArray(e)?e:[e],...he(t)})}const SI=q("ZodTransform",(e,t)=>{eC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>ym(e,n),e._zod.parse=(n,r)=>{if(r.direction==="backward")throw new Lh(e.constructor.name);n.addIssue=s=>{if(typeof s=="string")n.issues.push(wi(s,n.value,t));else{const o=s;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),n.issues.push(wi(o))}};const i=t.transform(n.value,n);return i instanceof Promise?i.then(s=>(n.value=s,n)):(n.value=i,n)}});function jI(e){return new SI({type:"transform",transform:e})}const Fm=q("ZodOptional",(e,t)=>{om.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>gl(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function $u(e){return new Fm({type:"optional",innerType:e})}const _I=q("ZodExactOptional",(e,t)=>{tC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>gl(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function NI(e){return new _I({type:"optional",innerType:e})}const EI=q("ZodNullable",(e,t)=>{nC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>jm(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function Mu(e){return new EI({type:"nullable",innerType:e})}const CI=q("ZodDefault",(e,t)=>{rC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>Nm(e,n,r,i),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function TI(e,t){return new CI({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Uh(t)}})}const II=q("ZodPrefault",(e,t)=>{iC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>Em(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function AI(e,t){return new II({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Uh(t)}})}const Lm=q("ZodNonOptional",(e,t)=>{sC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>_m(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function zI(e,t){return new Lm({type:"nonoptional",innerType:e,...he(t)})}const OI=q("ZodCatch",(e,t)=>{oC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>Cm(e,n,r,i),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function PI(e,t){return new OI({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const DI=q("ZodPipe",(e,t)=>{aC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>Tm(e,n,r,i),e.in=t.in,e.out=t.out});function Fu(e,t){return new DI({type:"pipe",in:e,out:t})}const RI=q("ZodReadonly",(e,t)=>{lC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>Im(e,n,r,i),e.unwrap=()=>e._zod.def.innerType});function $I(e){return new RI({type:"readonly",innerType:e})}const MI=q("ZodLazy",(e,t)=>{cC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>Am(e,n,r,i),e.unwrap=()=>e._zod.def.getter()});function FI(e){return new MI({type:"lazy",getter:e})}const xl=q("ZodCustom",(e,t)=>{uC.init(e,t),Ge.init(e,t),e._zod.processJSONSchema=(n,r,i)=>xm(e,n)});function Bm(e,t){return rT(xl,e??(()=>!0),t)}function LI(e,t={}){return iT(xl,e,t)}function BI(e){return sT(e)}function _s(e,t={}){const n=new xl({type:"custom",check:"custom",fn:r=>r instanceof e,abort:!0,...he(t)});return n._zod.bag.Class=e,n._zod.check=r=>{r.value instanceof e||r.issues.push({code:"invalid_type",expected:e.name,input:r.value,inst:n,path:[...n._zod.def.path??[]]})},n}var Si;(function(e){e.assertEqual=i=>{};function t(i){}e.assertIs=t;function n(i){throw new Error}e.assertNever=n,e.arrayToEnum=i=>{const s={};for(const o of i)s[o]=o;return s},e.getValidEnumValues=i=>{const s=e.objectKeys(i).filter(a=>typeof i[i[a]]!="number"),o={};for(const a of s)o[a]=i[a];return e.objectValues(o)},e.objectValues=i=>e.objectKeys(i).map(function(s){return i[s]}),e.objectKeys=typeof Object.keys=="function"?i=>Object.keys(i):i=>{const s=[];for(const o in i)Object.prototype.hasOwnProperty.call(i,o)&&s.push(o);return s},e.find=(i,s)=>{for(const o of i)if(s(o))return o},e.isInteger=typeof Number.isInteger=="function"?i=>Number.isInteger(i):i=>typeof i=="number"&&Number.isFinite(i)&&Math.floor(i)===i;function r(i,s=" | "){return i.map(o=>typeof o=="string"?`'${o}'`:o).join(s)}e.joinValues=r,e.jsonStringifyReplacer=(i,s)=>typeof s=="bigint"?s.toString():s})(Si||(Si={}));var Lu;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(Lu||(Lu={}));Si.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]);Si.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class Ns extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}format(t){const n=t||function(s){return s.message},r={_errors:[]},i=s=>{for(const o of s.issues)if(o.code==="invalid_union")o.unionErrors.map(i);else if(o.code==="invalid_return_type")i(o.returnTypeError);else if(o.code==="invalid_arguments")i(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,l=0;for(;l<o.path.length;){const u=o.path[l];l===o.path.length-1?(a[u]=a[u]||{_errors:[]},a[u]._errors.push(n(o))):a[u]=a[u]||{_errors:[]},a=a[u],l++}}};return i(this),r}static assert(t){if(!(t instanceof Ns))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Si.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){const n=Object.create(null),r=[];for(const i of this.issues)if(i.path.length>0){const s=i.path[0];n[s]=n[s]||[],n[s].push(t(i))}else r.push(t(i));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}Ns.create=e=>new Ns(e);var Bu;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t==null?void 0:t.message})(Bu||(Bu={}));var Se;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(Se||(Se={}));class Vu extends Error{constructor(t,n){super(t),this.name="ParseError",this.type=n.type,this.field=n.field,this.value=n.value,this.line=n.line}}function Ao(e){}function VI(e){if(typeof e=="function")throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:t=Ao,onError:n=Ao,onRetry:r=Ao,onComment:i}=e;let s="",o=!0,a,l="",u="";function d(k){const S=o?k.replace(/^\xEF\xBB\xBF/,""):k,[y,j]=ZI(`${s}${S}`);for(const m of y)f(m);s=j,o=!1}function f(k){if(k===""){p();return}if(k.startsWith(":")){i&&i(k.slice(k.startsWith(": ")?2:1));return}const S=k.indexOf(":");if(S!==-1){const y=k.slice(0,S),j=k[S+1]===" "?2:1,m=k.slice(S+j);h(y,m,k);return}h(k,"",k)}function h(k,S,y){switch(k){case"event":u=S;break;case"data":l=`${l}${S}
223
- `;break;case"id":a=S.includes("\0")?void 0:S;break;case"retry":/^\d+$/.test(S)?r(parseInt(S,10)):n(new Vu(`Invalid \`retry\` value: "${S}"`,{type:"invalid-retry",value:S,line:y}));break;default:n(new Vu(`Unknown field "${k.length>20?`${k.slice(0,20)}…`:k}"`,{type:"unknown-field",field:k,value:S,line:y}));break}}function p(){l.length>0&&t({id:a,event:u||void 0,data:l.endsWith(`
224
- `)?l.slice(0,-1):l}),a=void 0,l="",u=""}function g(k={}){s&&k.consume&&f(s),o=!0,a=void 0,l="",u="",s=""}return{feed:d,reset:g}}function ZI(e){const t=[];let n="",r=0;for(;r<e.length;){const i=e.indexOf("\r",r),s=e.indexOf(`
225
- `,r);let o=-1;if(i!==-1&&s!==-1?o=Math.min(i,s):i!==-1?i===e.length-1?o=-1:o=i:s!==-1&&(o=s),o===-1){n=e.slice(r);break}else{const a=e.slice(r,o);t.push(a),r=o+1,e[r-1]==="\r"&&e[r]===`
226
- `&&r++}}return[t,n]}class UI extends TransformStream{constructor({onError:t,onRetry:n,onComment:r}={}){let i;super({start(s){i=VI({onEvent:o=>{s.enqueue(o)},onError(o){t==="terminate"?s.error(o):typeof t=="function"&&t(o)},onRetry:n,onComment:r})},transform(s){i.feed(s)}})}}var Pi=({prefix:e,size:t=16,alphabet:n="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",separator:r="-"}={})=>{const i=()=>{const s=n.length,o=new Array(t);for(let a=0;a<t;a++)o[a]=n[Math.random()*s|0];return o.join("")};if(e==null)return i;if(n.includes(r))throw new nN({argument:"separator",message:`The separator "${r}" must not be part of the alphabet "${n}".`});return()=>`${e}${r}${i()}`},JI=Pi();function Qn(e){if(e==null)return{};const t={};if(e instanceof Headers)e.forEach((n,r)=>{t[r.toLowerCase()]=n});else{Array.isArray(e)||(e=Object.entries(e));for(const[n,r]of e)r!=null&&(t[n.toLowerCase()]=r)}return t}var HI=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,WI=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function Zu(e){const t=JSON.parse(e);return t===null||typeof t!="object"||HI.test(e)===!1&&WI.test(e)===!1?t:qI(t)}function qI(e){let t=[e];for(;t.length;){const n=t;t=[];for(const r of n){if(Object.prototype.hasOwnProperty.call(r,"__proto__"))throw new SyntaxError("Object contains forbidden prototype property");if(Object.prototype.hasOwnProperty.call(r,"constructor")&&r.constructor!==null&&typeof r.constructor=="object"&&Object.prototype.hasOwnProperty.call(r.constructor,"prototype"))throw new SyntaxError("Object contains forbidden prototype property");for(const i in r){const s=r[i];s&&typeof s=="object"&&t.push(s)}}}return e}function GI(e){const{stackTraceLimit:t}=Error;try{Error.stackTraceLimit=0}catch{return Zu(e)}try{return Zu(e)}finally{Error.stackTraceLimit=t}}function yl(e){if(e.type==="object"||Array.isArray(e.type)&&e.type.includes("object")){e.additionalProperties=!1;const{properties:n}=e;if(n!=null)for(const r of Object.keys(n))n[r]=In(n[r])}e.items!=null&&(e.items=Array.isArray(e.items)?e.items.map(In):In(e.items)),e.anyOf!=null&&(e.anyOf=e.anyOf.map(In)),e.allOf!=null&&(e.allOf=e.allOf.map(In)),e.oneOf!=null&&(e.oneOf=e.oneOf.map(In));const{definitions:t}=e;if(t!=null)for(const n of Object.keys(t))t[n]=In(t[n]);return e}function In(e){return typeof e=="boolean"?e:yl(e)}var KI=Symbol("Let zodToJsonSchema decide on which parser to use"),Uu={name:void 0,$refStrategy:"root",basePath:["#"],effectStrategy:"input",pipeStrategy:"all",dateStrategy:"format:date-time",mapStrategy:"entries",removeAdditionalStrategy:"passthrough",allowedAdditionalProperties:!0,rejectedAdditionalProperties:!1,definitionPath:"definitions",strictUnions:!1,definitions:{},errorMessages:!1,patternStrategy:"escape",applyRegexFlags:!1,emailStrategy:"format:email",base64Strategy:"contentEncoding:base64",nameStrategy:"ref"},YI=e=>typeof e=="string"?{...Uu,name:e}:{...Uu,...e};function zt(){return{}}function XI(e,t){var n,r,i;const s={type:"array"};return(n=e.type)!=null&&n._def&&((i=(r=e.type)==null?void 0:r._def)==null?void 0:i.typeName)!==Se.ZodAny&&(s.items=Fe(e.type._def,{...t,currentPath:[...t.currentPath,"items"]})),e.minLength&&(s.minItems=e.minLength.value),e.maxLength&&(s.maxItems=e.maxLength.value),e.exactLength&&(s.minItems=e.exactLength.value,s.maxItems=e.exactLength.value),s}function QI(e){const t={type:"integer",format:"int64"};if(!e.checks)return t;for(const n of e.checks)switch(n.kind){case"min":n.inclusive?t.minimum=n.value:t.exclusiveMinimum=n.value;break;case"max":n.inclusive?t.maximum=n.value:t.exclusiveMaximum=n.value;break;case"multipleOf":t.multipleOf=n.value;break}return t}function eA(){return{type:"boolean"}}function Vm(e,t){return Fe(e.type._def,t)}var tA=(e,t)=>Fe(e.innerType._def,t);function Zm(e,t,n){const r=n??t.dateStrategy;if(Array.isArray(r))return{anyOf:r.map((i,s)=>Zm(e,t,i))};switch(r){case"string":case"format:date-time":return{type:"string",format:"date-time"};case"format:date":return{type:"string",format:"date"};case"integer":return nA(e)}}var nA=e=>{const t={type:"integer",format:"unix-time"};for(const n of e.checks)switch(n.kind){case"min":t.minimum=n.value;break;case"max":t.maximum=n.value;break}return t};function rA(e,t){return{...Fe(e.innerType._def,t),default:e.defaultValue()}}function iA(e,t){return t.effectStrategy==="input"?Fe(e.schema._def,t):zt()}function sA(e){return{type:"string",enum:Array.from(e.values)}}var oA=e=>"type"in e&&e.type==="string"?!1:"allOf"in e;function aA(e,t){const n=[Fe(e.left._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),Fe(e.right._def,{...t,currentPath:[...t.currentPath,"allOf","1"]})].filter(i=>!!i),r=[];return n.forEach(i=>{if(oA(i))r.push(...i.allOf);else{let s=i;if("additionalProperties"in i&&i.additionalProperties===!1){const{additionalProperties:o,...a}=i;s=a}r.push(s)}}),r.length?{allOf:r}:void 0}function lA(e){const t=typeof e.value;return t!=="bigint"&&t!=="number"&&t!=="boolean"&&t!=="string"?{type:Array.isArray(e.value)?"array":"object"}:{type:t==="bigint"?"integer":t,const:e.value}}var zo=void 0,Bt={cuid:/^[cC][^\s-]{8,}$/,cuid2:/^[0-9a-z]+$/,ulid:/^[0-9A-HJKMNP-TV-Z]{26}$/,email:/^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,emoji:()=>(zo===void 0&&(zo=RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),zo),uuid:/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,ipv4:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,ipv4Cidr:/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ipv6:/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ipv6Cidr:/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,base64:/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,base64url:/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,nanoid:/^[a-zA-Z0-9_-]{21}$/,jwt:/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/};function Um(e,t){const n={type:"string"};if(e.checks)for(const r of e.checks)switch(r.kind){case"min":n.minLength=typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value;break;case"max":n.maxLength=typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value;break;case"email":switch(t.emailStrategy){case"format:email":Vt(n,"email",r.message,t);break;case"format:idn-email":Vt(n,"idn-email",r.message,t);break;case"pattern:zod":ft(n,Bt.email,r.message,t);break}break;case"url":Vt(n,"uri",r.message,t);break;case"uuid":Vt(n,"uuid",r.message,t);break;case"regex":ft(n,r.regex,r.message,t);break;case"cuid":ft(n,Bt.cuid,r.message,t);break;case"cuid2":ft(n,Bt.cuid2,r.message,t);break;case"startsWith":ft(n,RegExp(`^${Oo(r.value,t)}`),r.message,t);break;case"endsWith":ft(n,RegExp(`${Oo(r.value,t)}$`),r.message,t);break;case"datetime":Vt(n,"date-time",r.message,t);break;case"date":Vt(n,"date",r.message,t);break;case"time":Vt(n,"time",r.message,t);break;case"duration":Vt(n,"duration",r.message,t);break;case"length":n.minLength=typeof n.minLength=="number"?Math.max(n.minLength,r.value):r.value,n.maxLength=typeof n.maxLength=="number"?Math.min(n.maxLength,r.value):r.value;break;case"includes":{ft(n,RegExp(Oo(r.value,t)),r.message,t);break}case"ip":{r.version!=="v6"&&Vt(n,"ipv4",r.message,t),r.version!=="v4"&&Vt(n,"ipv6",r.message,t);break}case"base64url":ft(n,Bt.base64url,r.message,t);break;case"jwt":ft(n,Bt.jwt,r.message,t);break;case"cidr":{r.version!=="v6"&&ft(n,Bt.ipv4Cidr,r.message,t),r.version!=="v4"&&ft(n,Bt.ipv6Cidr,r.message,t);break}case"emoji":ft(n,Bt.emoji(),r.message,t);break;case"ulid":{ft(n,Bt.ulid,r.message,t);break}case"base64":{switch(t.base64Strategy){case"format:binary":{Vt(n,"binary",r.message,t);break}case"contentEncoding:base64":{n.contentEncoding="base64";break}case"pattern:zod":{ft(n,Bt.base64,r.message,t);break}}break}case"nanoid":ft(n,Bt.nanoid,r.message,t)}return n}function Oo(e,t){return t.patternStrategy==="escape"?uA(e):e}var cA=new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");function uA(e){let t="";for(let n=0;n<e.length;n++)cA.has(e[n])||(t+="\\"),t+=e[n];return t}function Vt(e,t,n,r){var i;e.format||(i=e.anyOf)!=null&&i.some(s=>s.format)?(e.anyOf||(e.anyOf=[]),e.format&&(e.anyOf.push({format:e.format}),delete e.format),e.anyOf.push({format:t,...n&&r.errorMessages&&{errorMessage:{format:n}}})):e.format=t}function ft(e,t,n,r){var i;e.pattern||(i=e.allOf)!=null&&i.some(s=>s.pattern)?(e.allOf||(e.allOf=[]),e.pattern&&(e.allOf.push({pattern:e.pattern}),delete e.pattern),e.allOf.push({pattern:Ju(t,r),...n&&r.errorMessages&&{errorMessage:{pattern:n}}})):e.pattern=Ju(t,r)}function Ju(e,t){var n;if(!t.applyRegexFlags||!e.flags)return e.source;const r={i:e.flags.includes("i"),m:e.flags.includes("m"),s:e.flags.includes("s")},i=r.i?e.source.toLowerCase():e.source;let s="",o=!1,a=!1,l=!1;for(let u=0;u<i.length;u++){if(o){s+=i[u],o=!1;continue}if(r.i){if(a){if(i[u].match(/[a-z]/)){l?(s+=i[u],s+=`${i[u-2]}-${i[u]}`.toUpperCase(),l=!1):i[u+1]==="-"&&((n=i[u+2])!=null&&n.match(/[a-z]/))?(s+=i[u],l=!0):s+=`${i[u]}${i[u].toUpperCase()}`;continue}}else if(i[u].match(/[a-z]/)){s+=`[${i[u]}${i[u].toUpperCase()}]`;continue}}if(r.m){if(i[u]==="^"){s+=`(^|(?<=[\r
227
- ]))`;continue}else if(i[u]==="$"){s+=`($|(?=[\r
228
- ]))`;continue}}if(r.s&&i[u]==="."){s+=a?`${i[u]}\r
229
- `:`[${i[u]}\r
230
- ]`;continue}s+=i[u],i[u]==="\\"?o=!0:a&&i[u]==="]"?a=!1:!a&&i[u]==="["&&(a=!0)}try{new RegExp(s)}catch{return console.warn(`Could not convert regex pattern at ${t.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`),e.source}return s}function Jm(e,t){var n,r,i,s,o,a;const l={type:"object",additionalProperties:(n=Fe(e.valueType._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]}))!=null?n:t.allowedAdditionalProperties};if(((r=e.keyType)==null?void 0:r._def.typeName)===Se.ZodString&&((i=e.keyType._def.checks)!=null&&i.length)){const{type:u,...d}=Um(e.keyType._def,t);return{...l,propertyNames:d}}else{if(((s=e.keyType)==null?void 0:s._def.typeName)===Se.ZodEnum)return{...l,propertyNames:{enum:e.keyType._def.values}};if(((o=e.keyType)==null?void 0:o._def.typeName)===Se.ZodBranded&&e.keyType._def.type._def.typeName===Se.ZodString&&((a=e.keyType._def.type._def.checks)!=null&&a.length)){const{type:u,...d}=Vm(e.keyType._def,t);return{...l,propertyNames:d}}}return l}function dA(e,t){if(t.mapStrategy==="record")return Jm(e,t);const n=Fe(e.keyType._def,{...t,currentPath:[...t.currentPath,"items","items","0"]})||zt(),r=Fe(e.valueType._def,{...t,currentPath:[...t.currentPath,"items","items","1"]})||zt();return{type:"array",maxItems:125,items:{type:"array",items:[n,r],minItems:2,maxItems:2}}}function fA(e){const t=e.values,r=Object.keys(e.values).filter(s=>typeof t[t[s]]!="number").map(s=>t[s]),i=Array.from(new Set(r.map(s=>typeof s)));return{type:i.length===1?i[0]==="string"?"string":"number":["string","number"],enum:r}}function pA(){return{not:zt()}}function hA(){return{type:"null"}}var ha={ZodString:"string",ZodNumber:"number",ZodBigInt:"integer",ZodBoolean:"boolean",ZodNull:"null"};function mA(e,t){const n=e.options instanceof Map?Array.from(e.options.values()):e.options;if(n.every(r=>r._def.typeName in ha&&(!r._def.checks||!r._def.checks.length))){const r=n.reduce((i,s)=>{const o=ha[s._def.typeName];return o&&!i.includes(o)?[...i,o]:i},[]);return{type:r.length>1?r:r[0]}}else if(n.every(r=>r._def.typeName==="ZodLiteral"&&!r.description)){const r=n.reduce((i,s)=>{const o=typeof s._def.value;switch(o){case"string":case"number":case"boolean":return[...i,o];case"bigint":return[...i,"integer"];case"object":if(s._def.value===null)return[...i,"null"];case"symbol":case"undefined":case"function":default:return i}},[]);if(r.length===n.length){const i=r.filter((s,o,a)=>a.indexOf(s)===o);return{type:i.length>1?i:i[0],enum:n.reduce((s,o)=>s.includes(o._def.value)?s:[...s,o._def.value],[])}}}else if(n.every(r=>r._def.typeName==="ZodEnum"))return{type:"string",enum:n.reduce((r,i)=>[...r,...i._def.values.filter(s=>!r.includes(s))],[])};return gA(e,t)}var gA=(e,t)=>{const n=(e.options instanceof Map?Array.from(e.options.values()):e.options).map((r,i)=>Fe(r._def,{...t,currentPath:[...t.currentPath,"anyOf",`${i}`]})).filter(r=>!!r&&(!t.strictUnions||typeof r=="object"&&Object.keys(r).length>0));return n.length?{anyOf:n}:void 0};function xA(e,t){if(["ZodString","ZodNumber","ZodBigInt","ZodBoolean","ZodNull"].includes(e.innerType._def.typeName)&&(!e.innerType._def.checks||!e.innerType._def.checks.length))return{type:[ha[e.innerType._def.typeName],"null"]};const n=Fe(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","0"]});return n&&{anyOf:[n,{type:"null"}]}}function yA(e){const t={type:"number"};if(!e.checks)return t;for(const n of e.checks)switch(n.kind){case"int":t.type="integer";break;case"min":n.inclusive?t.minimum=n.value:t.exclusiveMinimum=n.value;break;case"max":n.inclusive?t.maximum=n.value:t.exclusiveMaximum=n.value;break;case"multipleOf":t.multipleOf=n.value;break}return t}function bA(e,t){const n={type:"object",properties:{}},r=[],i=e.shape();for(const o in i){let a=i[o];if(a===void 0||a._def===void 0)continue;const l=wA(a),u=Fe(a._def,{...t,currentPath:[...t.currentPath,"properties",o],propertyPath:[...t.currentPath,"properties",o]});u!==void 0&&(n.properties[o]=u,l||r.push(o))}r.length&&(n.required=r);const s=vA(e,t);return s!==void 0&&(n.additionalProperties=s),n}function vA(e,t){if(e.catchall._def.typeName!=="ZodNever")return Fe(e.catchall._def,{...t,currentPath:[...t.currentPath,"additionalProperties"]});switch(e.unknownKeys){case"passthrough":return t.allowedAdditionalProperties;case"strict":return t.rejectedAdditionalProperties;case"strip":return t.removeAdditionalStrategy==="strict"?t.allowedAdditionalProperties:t.rejectedAdditionalProperties}}function wA(e){try{return e.isOptional()}catch{return!0}}var kA=(e,t)=>{var n;if(t.currentPath.toString()===((n=t.propertyPath)==null?void 0:n.toString()))return Fe(e.innerType._def,t);const r=Fe(e.innerType._def,{...t,currentPath:[...t.currentPath,"anyOf","1"]});return r?{anyOf:[{not:zt()},r]}:zt()},SA=(e,t)=>{if(t.pipeStrategy==="input")return Fe(e.in._def,t);if(t.pipeStrategy==="output")return Fe(e.out._def,t);const n=Fe(e.in._def,{...t,currentPath:[...t.currentPath,"allOf","0"]}),r=Fe(e.out._def,{...t,currentPath:[...t.currentPath,"allOf",n?"1":"0"]});return{allOf:[n,r].filter(i=>i!==void 0)}};function jA(e,t){return Fe(e.type._def,t)}function _A(e,t){const r={type:"array",uniqueItems:!0,items:Fe(e.valueType._def,{...t,currentPath:[...t.currentPath,"items"]})};return e.minSize&&(r.minItems=e.minSize.value),e.maxSize&&(r.maxItems=e.maxSize.value),r}function NA(e,t){return e.rest?{type:"array",minItems:e.items.length,items:e.items.map((n,r)=>Fe(n._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[]),additionalItems:Fe(e.rest._def,{...t,currentPath:[...t.currentPath,"additionalItems"]})}:{type:"array",minItems:e.items.length,maxItems:e.items.length,items:e.items.map((n,r)=>Fe(n._def,{...t,currentPath:[...t.currentPath,"items",`${r}`]})).reduce((n,r)=>r===void 0?n:[...n,r],[])}}function EA(){return{not:zt()}}function CA(){return zt()}var TA=(e,t)=>Fe(e.innerType._def,t),IA=(e,t,n)=>{switch(t){case Se.ZodString:return Um(e,n);case Se.ZodNumber:return yA(e);case Se.ZodObject:return bA(e,n);case Se.ZodBigInt:return QI(e);case Se.ZodBoolean:return eA();case Se.ZodDate:return Zm(e,n);case Se.ZodUndefined:return EA();case Se.ZodNull:return hA();case Se.ZodArray:return XI(e,n);case Se.ZodUnion:case Se.ZodDiscriminatedUnion:return mA(e,n);case Se.ZodIntersection:return aA(e,n);case Se.ZodTuple:return NA(e,n);case Se.ZodRecord:return Jm(e,n);case Se.ZodLiteral:return lA(e);case Se.ZodEnum:return sA(e);case Se.ZodNativeEnum:return fA(e);case Se.ZodNullable:return xA(e,n);case Se.ZodOptional:return kA(e,n);case Se.ZodMap:return dA(e,n);case Se.ZodSet:return _A(e,n);case Se.ZodLazy:return()=>e.getter()._def;case Se.ZodPromise:return jA(e,n);case Se.ZodNaN:case Se.ZodNever:return pA();case Se.ZodEffects:return iA(e,n);case Se.ZodAny:return zt();case Se.ZodUnknown:return CA();case Se.ZodDefault:return rA(e,n);case Se.ZodBranded:return Vm(e,n);case Se.ZodReadonly:return TA(e,n);case Se.ZodCatch:return tA(e,n);case Se.ZodPipeline:return SA(e,n);case Se.ZodFunction:case Se.ZodVoid:case Se.ZodSymbol:return;default:return(r=>{})()}},AA=(e,t)=>{let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];n++);return[(e.length-n).toString(),...t.slice(n)].join("/")};function Fe(e,t,n=!1){var r;const i=t.seen.get(e);if(t.override){const l=(r=t.override)==null?void 0:r.call(t,e,t,i,n);if(l!==KI)return l}if(i&&!n){const l=zA(i,t);if(l!==void 0)return l}const s={def:e,path:t.currentPath,jsonSchema:void 0};t.seen.set(e,s);const o=IA(e,e.typeName,t),a=typeof o=="function"?Fe(o(),t):o;if(a&&OA(e,t,a),t.postProcess){const l=t.postProcess(a,e,t);return s.jsonSchema=a,l}return s.jsonSchema=a,a}var zA=(e,t)=>{switch(t.$refStrategy){case"root":return{$ref:e.path.join("/")};case"relative":return{$ref:AA(t.currentPath,e.path)};case"none":case"seen":return e.path.length<t.currentPath.length&&e.path.every((n,r)=>t.currentPath[r]===n)?(console.warn(`Recursive reference detected at ${t.currentPath.join("/")}! Defaulting to any`),zt()):t.$refStrategy==="seen"?zt():void 0}},OA=(e,t,n)=>(e.description&&(n.description=e.description),n),PA=e=>{const t=YI(e),n=t.name!==void 0?[...t.basePath,t.definitionPath,t.name]:t.basePath;return{...t,currentPath:n,propertyPath:void 0,seen:new Map(Object.entries(t.definitions).map(([r,i])=>[i._def,{def:i._def,path:[...t.basePath,t.definitionPath,r],jsonSchema:void 0}]))}},DA=(e,t)=>{var n;const r=PA(t);let i=typeof t=="object"&&t.definitions?Object.entries(t.definitions).reduce((u,[d,f])=>{var h;return{...u,[d]:(h=Fe(f._def,{...r,currentPath:[...r.basePath,r.definitionPath,d]},!0))!=null?h:zt()}},{}):void 0;const s=typeof t=="string"?t:(t==null?void 0:t.nameStrategy)==="title"||t==null?void 0:t.name,o=(n=Fe(e._def,s===void 0?r:{...r,currentPath:[...r.basePath,r.definitionPath,s]},!1))!=null?n:zt(),a=typeof t=="object"&&t.name!==void 0&&t.nameStrategy==="title"?t.name:void 0;a!==void 0&&(o.title=a);const l=s===void 0?i?{...o,[r.definitionPath]:i}:o:{$ref:[...r.$refStrategy==="relative"?[]:r.basePath,r.definitionPath,s].join("/"),[r.definitionPath]:{...i,[s]:o}};return l.$schema="http://json-schema.org/draft-07/schema#",l},ma=Symbol.for("vercel.ai.schema");function RA(e){let t;return()=>(t==null&&(t=e()),t)}function Ys(e,{validate:t}={}){return{[ma]:!0,_type:void 0,get jsonSchema(){return typeof e=="function"&&(e=e()),e},validate:t}}function $A(e){return typeof e=="object"&&e!==null&&ma in e&&e[ma]===!0&&"jsonSchema"in e&&"validate"in e}function bl(e){return e==null?Ys({properties:{},additionalProperties:!1}):$A(e)?e:"~standard"in e?e["~standard"].vendor==="zod"?Hm(e):MA(e):e()}function MA(e){return Ys(()=>yl(e["~standard"].jsonSchema.input({target:"draft-07"})),{validate:async t=>{const n=await e["~standard"].validate(t);return"value"in n?{success:!0,value:n.value}:{success:!1,error:new _r({value:t,cause:n.issues})}}})}function FA(e,t){var n;const r=(n=void 0)!=null?n:!1;return Ys(()=>DA(e,{$refStrategy:r?"root":"none"}),{validate:async i=>{const s=await e.safeParseAsync(i);return s.success?{success:!0,value:s.data}:{success:!1,error:s.error}}})}function LA(e,t){var n;const r=(n=void 0)!=null?n:!1;return Ys(()=>yl(jT(e,{target:"draft-7",io:"input",reused:r?"ref":"inline"})),{validate:async i=>{const s=await zm(e,i);return s.success?{success:!0,value:s.data}:{success:!1,error:s.error}}})}function BA(e){return"_zod"in e}function Hm(e,t){return BA(e)?LA(e):FA(e)}async function Hu({value:e,schema:t,context:n}){const r=await ji({value:e,schema:t,context:n});if(!r.success)throw _r.wrap({value:e,cause:r.error,context:n});return r.value}async function ji({value:e,schema:t,context:n}){const r=bl(t);try{if(r.validate==null)return{success:!0,value:e,rawValue:e};const i=await r.validate(e);return i.success?{success:!0,value:i.value,rawValue:e}:{success:!1,error:_r.wrap({value:e,cause:i.error,context:n}),rawValue:e}}catch(i){return{success:!1,error:_r.wrap({value:e,cause:i,context:n}),rawValue:e}}}async function Vn({text:e,schema:t}){try{const n=GI(e);return t==null?{success:!0,value:n,rawValue:n}:await ji({value:n,schema:t})}catch(n){return{success:!1,error:mu.isInstance(n)?n:new mu({text:e,cause:n}),rawValue:void 0}}}function VA({stream:e,schema:t}){return e.pipeThrough(new TextDecoderStream).pipeThrough(new UI).pipeThrough(new TransformStream({async transform({data:n},r){n!=="[DONE]"&&r.enqueue(await Vn({text:n,schema:t}))}}))}async function gn(e){return typeof e=="function"&&(e=e()),Promise.resolve(e)}var ZA=Object.defineProperty,UA=(e,t)=>{for(var n in t)ZA(e,n,{get:t[n],enumerable:!0})},Wm="AI_NoObjectGeneratedError",qm=`vercel.ai.error.${Wm}`,JA=Symbol.for(qm),Gm,bn=class extends nn{constructor({message:e="No object generated.",cause:t,text:n,response:r,usage:i,finishReason:s}){super({name:Wm,message:e,cause:t}),this[Gm]=!0,this.text=n,this.response=r,this.usage=i,this.finishReason=s}static isInstance(e){return nn.hasMarker(e,qm)}};Gm=JA;var Km="AI_UIMessageStreamError",Ym=`vercel.ai.error.${Km}`,HA=Symbol.for(Ym),Xm,er=class extends nn{constructor({chunkType:e,chunkId:t,message:n}){super({name:Km,message:n}),this[Xm]=!0,this.chunkType=e,this.chunkId=t}static isInstance(e){return nn.hasMarker(e,Ym)}};Xm=HA;var Qm=yt([le(),_s(Uint8Array),_s(ArrayBuffer),Bm(e=>{var t,n;return(n=(t=globalThis.Buffer)==null?void 0:t.isBuffer(e))!=null?n:!1},{message:"Must be a Buffer"})]),_i=FI(()=>yt([pI(),le(),cI(),ht(),ki(le(),_i.optional()),Dr(_i)])),Te=ki(le(),ki(le(),_i.optional())),eg=Be({type:ve("text"),text:le(),providerOptions:Te.optional()}),WA=Be({type:ve("image"),image:yt([Qm,_s(URL)]),mediaType:le().optional(),providerOptions:Te.optional()}),tg=Be({type:ve("file"),data:yt([Qm,_s(URL)]),filename:le().optional(),mediaType:le(),providerOptions:Te.optional()}),qA=Be({type:ve("reasoning"),text:le(),providerOptions:Te.optional()}),GA=Be({type:ve("tool-call"),toolCallId:le(),toolName:le(),input:Xt(),providerOptions:Te.optional(),providerExecuted:ht().optional()}),KA=yI("type",[Be({type:ve("text"),value:le(),providerOptions:Te.optional()}),Be({type:ve("json"),value:_i,providerOptions:Te.optional()}),Be({type:ve("execution-denied"),reason:le().optional(),providerOptions:Te.optional()}),Be({type:ve("error-text"),value:le(),providerOptions:Te.optional()}),Be({type:ve("error-json"),value:_i,providerOptions:Te.optional()}),Be({type:ve("content"),value:Dr(yt([Be({type:ve("text"),text:le(),providerOptions:Te.optional()}),Be({type:ve("media"),data:le(),mediaType:le()}),Be({type:ve("file-data"),data:le(),mediaType:le(),filename:le().optional(),providerOptions:Te.optional()}),Be({type:ve("file-url"),url:le(),providerOptions:Te.optional()}),Be({type:ve("file-id"),fileId:yt([le(),ki(le(),le())]),providerOptions:Te.optional()}),Be({type:ve("image-data"),data:le(),mediaType:le(),providerOptions:Te.optional()}),Be({type:ve("image-url"),url:le(),providerOptions:Te.optional()}),Be({type:ve("image-file-id"),fileId:yt([le(),ki(le(),le())]),providerOptions:Te.optional()}),Be({type:ve("custom"),providerOptions:Te.optional()})]))})]),ng=Be({type:ve("tool-result"),toolCallId:le(),toolName:le(),output:KA,providerOptions:Te.optional()}),YA=Be({type:ve("tool-approval-request"),approvalId:le(),toolCallId:le()}),XA=Be({type:ve("tool-approval-response"),approvalId:le(),approved:ht(),reason:le().optional()}),QA=Be({role:ve("system"),content:le(),providerOptions:Te.optional()}),ez=Be({role:ve("user"),content:yt([le(),Dr(yt([eg,WA,tg]))]),providerOptions:Te.optional()}),tz=Be({role:ve("assistant"),content:yt([le(),Dr(yt([eg,tg,qA,GA,ng,YA]))]),providerOptions:Te.optional()}),nz=Be({role:ve("tool"),content:Dr(yt([ng,XA])),providerOptions:Te.optional()});yt([QA,ez,tz,nz]);function rg(e,t){if(e===void 0&&t===void 0)return;if(e===void 0)return t;if(t===void 0)return e;const n={...e};for(const r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const i=t[r];if(i===void 0)continue;const s=r in e?e[r]:void 0,o=i!==null&&typeof i=="object"&&!Array.isArray(i)&&!(i instanceof Date)&&!(i instanceof RegExp),a=s!=null&&typeof s=="object"&&!Array.isArray(s)&&!(s instanceof Date)&&!(s instanceof RegExp);o&&a?n[r]=rg(s,i):n[r]=i}return n}var rz={};UA(rz,{array:()=>az,choice:()=>lz,json:()=>cz,object:()=>oz,text:()=>sz});function iz(e){const t=["ROOT"];let n=-1,r=null;function i(l,u,d){switch(l){case'"':{n=u,t.pop(),t.push(d),t.push("INSIDE_STRING");break}case"f":case"t":case"n":{n=u,r=u,t.pop(),t.push(d),t.push("INSIDE_LITERAL");break}case"-":{t.pop(),t.push(d),t.push("INSIDE_NUMBER");break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{n=u,t.pop(),t.push(d),t.push("INSIDE_NUMBER");break}case"{":{n=u,t.pop(),t.push(d),t.push("INSIDE_OBJECT_START");break}case"[":{n=u,t.pop(),t.push(d),t.push("INSIDE_ARRAY_START");break}}}function s(l,u){switch(l){case",":{t.pop(),t.push("INSIDE_OBJECT_AFTER_COMMA");break}case"}":{n=u,t.pop();break}}}function o(l,u){switch(l){case",":{t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{n=u,t.pop();break}}}for(let l=0;l<e.length;l++){const u=e[l];switch(t[t.length-1]){case"ROOT":i(u,l,"FINISH");break;case"INSIDE_OBJECT_START":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_KEY");break}case"}":{n=l,t.pop();break}}break}case"INSIDE_OBJECT_AFTER_COMMA":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_KEY");break}}break}case"INSIDE_OBJECT_KEY":{switch(u){case'"':{t.pop(),t.push("INSIDE_OBJECT_AFTER_KEY");break}}break}case"INSIDE_OBJECT_AFTER_KEY":{switch(u){case":":{t.pop(),t.push("INSIDE_OBJECT_BEFORE_VALUE");break}}break}case"INSIDE_OBJECT_BEFORE_VALUE":{i(u,l,"INSIDE_OBJECT_AFTER_VALUE");break}case"INSIDE_OBJECT_AFTER_VALUE":{s(u,l);break}case"INSIDE_STRING":{switch(u){case'"':{t.pop(),n=l;break}case"\\":{t.push("INSIDE_STRING_ESCAPE");break}default:n=l}break}case"INSIDE_ARRAY_START":{switch(u){case"]":{n=l,t.pop();break}default:{n=l,i(u,l,"INSIDE_ARRAY_AFTER_VALUE");break}}break}case"INSIDE_ARRAY_AFTER_VALUE":{switch(u){case",":{t.pop(),t.push("INSIDE_ARRAY_AFTER_COMMA");break}case"]":{n=l,t.pop();break}default:{n=l;break}}break}case"INSIDE_ARRAY_AFTER_COMMA":{i(u,l,"INSIDE_ARRAY_AFTER_VALUE");break}case"INSIDE_STRING_ESCAPE":{t.pop(),n=l;break}case"INSIDE_NUMBER":{switch(u){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{n=l;break}case"e":case"E":case"-":case".":break;case",":{t.pop(),t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&o(u,l),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&s(u,l);break}case"}":{t.pop(),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&s(u,l);break}case"]":{t.pop(),t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&o(u,l);break}default:{t.pop();break}}break}case"INSIDE_LITERAL":{const f=e.substring(r,l+1);!"false".startsWith(f)&&!"true".startsWith(f)&&!"null".startsWith(f)?(t.pop(),t[t.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?s(u,l):t[t.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&o(u,l)):n=l;break}}}let a=e.slice(0,n+1);for(let l=t.length-1;l>=0;l--)switch(t[l]){case"INSIDE_STRING":{a+='"';break}case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":{a+="}";break}case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":{a+="]";break}case"INSIDE_LITERAL":{const d=e.substring(r,e.length);"true".startsWith(d)?a+="true".slice(d.length):"false".startsWith(d)?a+="false".slice(d.length):"null".startsWith(d)&&(a+="null".slice(d.length))}}return a}async function Di(e){if(e===void 0)return{value:void 0,state:"undefined-input"};let t=await Vn({text:e});return t.success?{value:t.value,state:"successful-parse"}:(t=await Vn({text:iz(e)}),t.success?{value:t.value,state:"repaired-parse"}:{value:void 0,state:"failed-parse"})}var sz=()=>({name:"text",responseFormat:Promise.resolve({type:"text"}),async parseCompleteOutput({text:e}){return e},async parsePartialOutput({text:e}){return{partial:e}},createElementStreamTransform(){}}),oz=({schema:e,name:t,description:n})=>{const r=bl(e);return{name:"object",responseFormat:gn(r.jsonSchema).then(i=>({type:"json",schema:i,...t!=null&&{name:t},...n!=null&&{description:n}})),async parseCompleteOutput({text:i},s){const o=await Vn({text:i});if(!o.success)throw new bn({message:"No object generated: could not parse the response.",cause:o.error,text:i,response:s.response,usage:s.usage,finishReason:s.finishReason});const a=await ji({value:o.value,schema:r});if(!a.success)throw new bn({message:"No object generated: response did not match schema.",cause:a.error,text:i,response:s.response,usage:s.usage,finishReason:s.finishReason});return a.value},async parsePartialOutput({text:i}){const s=await Di(i);switch(s.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return{partial:s.value}}},createElementStreamTransform(){}}},az=({element:e,name:t,description:n})=>{const r=bl(e);return{name:"array",responseFormat:gn(r.jsonSchema).then(i=>{const{$schema:s,...o}=i;return{type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{elements:{type:"array",items:o}},required:["elements"],additionalProperties:!1},...t!=null&&{name:t},...n!=null&&{description:n}}}),async parseCompleteOutput({text:i},s){const o=await Vn({text:i});if(!o.success)throw new bn({message:"No object generated: could not parse the response.",cause:o.error,text:i,response:s.response,usage:s.usage,finishReason:s.finishReason});const a=o.value;if(a==null||typeof a!="object"||!("elements"in a)||!Array.isArray(a.elements))throw new bn({message:"No object generated: response did not match schema.",cause:new _r({value:a,cause:"response must be an object with an elements array"}),text:i,response:s.response,usage:s.usage,finishReason:s.finishReason});for(const l of a.elements){const u=await ji({value:l,schema:r});if(!u.success)throw new bn({message:"No object generated: response did not match schema.",cause:u.error,text:i,response:s.response,usage:s.usage,finishReason:s.finishReason})}return a.elements},async parsePartialOutput({text:i}){const s=await Di(i);switch(s.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{const o=s.value;if(o==null||typeof o!="object"||!("elements"in o)||!Array.isArray(o.elements))return;const a=s.state==="repaired-parse"&&o.elements.length>0?o.elements.slice(0,-1):o.elements,l=[];for(const u of a){const d=await ji({value:u,schema:r});d.success&&l.push(d.value)}return{partial:l}}}},createElementStreamTransform(){let i=0;return new TransformStream({transform({partialOutput:s},o){if(s!=null)for(;i<s.length;i++)o.enqueue(s[i])}})}}},lz=({options:e,name:t,description:n})=>({name:"choice",responseFormat:Promise.resolve({type:"json",schema:{$schema:"http://json-schema.org/draft-07/schema#",type:"object",properties:{result:{type:"string",enum:e}},required:["result"],additionalProperties:!1},...t!=null&&{name:t},...n!=null&&{description:n}}),async parseCompleteOutput({text:r},i){const s=await Vn({text:r});if(!s.success)throw new bn({message:"No object generated: could not parse the response.",cause:s.error,text:r,response:i.response,usage:i.usage,finishReason:i.finishReason});const o=s.value;if(o==null||typeof o!="object"||!("result"in o)||typeof o.result!="string"||!e.includes(o.result))throw new bn({message:"No object generated: response did not match schema.",cause:new _r({value:o,cause:"response must be an object that contains a choice value."}),text:r,response:i.response,usage:i.usage,finishReason:i.finishReason});return o.result},async parsePartialOutput({text:r}){const i=await Di(r);switch(i.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":{const s=i.value;if(s==null||typeof s!="object"||!("result"in s)||typeof s.result!="string")return;const o=e.filter(a=>a.startsWith(s.result));return i.state==="successful-parse"?o.includes(s.result)?{partial:s.result}:void 0:o.length===1?{partial:o[0]}:void 0}}},createElementStreamTransform(){}}),cz=({name:e,description:t}={})=>({name:"json",responseFormat:Promise.resolve({type:"json",...e!=null&&{name:e},...t!=null&&{description:t}}),async parseCompleteOutput({text:n},r){const i=await Vn({text:n});if(!i.success)throw new bn({message:"No object generated: could not parse the response.",cause:i.error,text:n,response:r.response,usage:r.usage,finishReason:r.finishReason});return i.value},async parsePartialOutput({text:n}){const r=await Di(n);switch(r.state){case"failed-parse":case"undefined-input":return;case"repaired-parse":case"successful-parse":return r.value===void 0?void 0:{partial:r.value}}},createElementStreamTransform(){}});Pi({prefix:"aitxt",size:24});(class extends TransformStream{constructor(){super({transform(e,t){t.enqueue(`data: ${JSON.stringify(e)}
231
-
232
- `)},flush(e){e.enqueue(`data: [DONE]
233
-
234
- `)}})}});var uz=RA(()=>Hm(yt([He({type:ve("text-start"),id:le(),providerMetadata:Te.optional()}),He({type:ve("text-delta"),id:le(),delta:le(),providerMetadata:Te.optional()}),He({type:ve("text-end"),id:le(),providerMetadata:Te.optional()}),He({type:ve("error"),errorText:le()}),He({type:ve("tool-input-start"),toolCallId:le(),toolName:le(),providerExecuted:ht().optional(),providerMetadata:Te.optional(),dynamic:ht().optional(),title:le().optional()}),He({type:ve("tool-input-delta"),toolCallId:le(),inputTextDelta:le()}),He({type:ve("tool-input-available"),toolCallId:le(),toolName:le(),input:Xt(),providerExecuted:ht().optional(),providerMetadata:Te.optional(),dynamic:ht().optional(),title:le().optional()}),He({type:ve("tool-input-error"),toolCallId:le(),toolName:le(),input:Xt(),providerExecuted:ht().optional(),providerMetadata:Te.optional(),dynamic:ht().optional(),errorText:le(),title:le().optional()}),He({type:ve("tool-approval-request"),approvalId:le(),toolCallId:le()}),He({type:ve("tool-output-available"),toolCallId:le(),output:Xt(),providerExecuted:ht().optional(),providerMetadata:Te.optional(),dynamic:ht().optional(),preliminary:ht().optional()}),He({type:ve("tool-output-error"),toolCallId:le(),errorText:le(),providerExecuted:ht().optional(),providerMetadata:Te.optional(),dynamic:ht().optional()}),He({type:ve("tool-output-denied"),toolCallId:le()}),He({type:ve("reasoning-start"),id:le(),providerMetadata:Te.optional()}),He({type:ve("reasoning-delta"),id:le(),delta:le(),providerMetadata:Te.optional()}),He({type:ve("reasoning-end"),id:le(),providerMetadata:Te.optional()}),He({type:ve("source-url"),sourceId:le(),url:le(),title:le().optional(),providerMetadata:Te.optional()}),He({type:ve("source-document"),sourceId:le(),mediaType:le(),title:le(),filename:le().optional(),providerMetadata:Te.optional()}),He({type:ve("file"),url:le(),mediaType:le(),providerMetadata:Te.optional()}),He({type:Bm(e=>typeof e=="string"&&e.startsWith("data-"),{message:'Type must start with "data-"'}),id:le().optional(),data:Xt(),transient:ht().optional()}),He({type:ve("start-step")}),He({type:ve("finish-step")}),He({type:ve("start"),messageId:le().optional(),messageMetadata:Xt().optional()}),He({type:ve("finish"),finishReason:Mm(["stop","length","content-filter","tool-calls","error","other"]).optional(),messageMetadata:Xt().optional()}),He({type:ve("abort"),reason:le().optional()}),He({type:ve("message-metadata"),messageMetadata:Xt()})])));function dz(e){return e.type.startsWith("data-")}function ga(e){return e.type.startsWith("tool-")}function fz(e){return e.type==="dynamic-tool"}function Es(e){return ga(e)||fz(e)}function Wu(e){return e.type.split("-").slice(1).join("-")}function pz({lastMessage:e,messageId:t}){return{message:(e==null?void 0:e.role)==="assistant"?e:{id:t,metadata:void 0,role:"assistant",parts:[]},activeTextParts:{},activeReasoningParts:{},partialToolCalls:{}}}function hz({stream:e,messageMetadataSchema:t,dataPartSchemas:n,runUpdateMessageJob:r,onError:i,onToolCall:s,onData:o}){return e.pipeThrough(new TransformStream({async transform(a,l){await r(async({state:u,write:d})=>{var f,h,p,g;function k(m){const C=u.message.parts.filter(Es).find(v=>v.toolCallId===m);if(C==null)throw new er({chunkType:"tool-invocation",chunkId:m,message:`No tool invocation found for tool call ID "${m}".`});return C}function S(m){var A;const C=u.message.parts.find(O=>ga(O)&&O.toolCallId===m.toolCallId),v=m,w=C;if(C!=null){C.state=m.state,w.input=v.input,w.output=v.output,w.errorText=v.errorText,w.rawInput=v.rawInput,w.preliminary=v.preliminary,m.title!==void 0&&(w.title=m.title),w.providerExecuted=(A=v.providerExecuted)!=null?A:C.providerExecuted;const O=v.providerMetadata;if(O!=null)if(m.state==="output-available"||m.state==="output-error"){const B=C;B.resultProviderMetadata=O}else C.callProviderMetadata=O}else u.message.parts.push({type:`tool-${m.toolName}`,toolCallId:m.toolCallId,state:m.state,title:m.title,input:v.input,output:v.output,rawInput:v.rawInput,errorText:v.errorText,providerExecuted:v.providerExecuted,preliminary:v.preliminary,...v.providerMetadata!=null&&(m.state==="output-available"||m.state==="output-error")?{resultProviderMetadata:v.providerMetadata}:{},...v.providerMetadata!=null&&!(m.state==="output-available"||m.state==="output-error")?{callProviderMetadata:v.providerMetadata}:{}})}function y(m){var A,C;const v=u.message.parts.find(B=>B.type==="dynamic-tool"&&B.toolCallId===m.toolCallId),w=m,O=v;if(v!=null){v.state=m.state,O.toolName=m.toolName,O.input=w.input,O.output=w.output,O.errorText=w.errorText,O.rawInput=(A=w.rawInput)!=null?A:O.rawInput,O.preliminary=w.preliminary,m.title!==void 0&&(O.title=m.title),O.providerExecuted=(C=w.providerExecuted)!=null?C:v.providerExecuted;const B=w.providerMetadata;if(B!=null)if(m.state==="output-available"||m.state==="output-error"){const N=v;N.resultProviderMetadata=B}else v.callProviderMetadata=B}else u.message.parts.push({type:"dynamic-tool",toolName:m.toolName,toolCallId:m.toolCallId,state:m.state,input:w.input,output:w.output,errorText:w.errorText,preliminary:w.preliminary,providerExecuted:w.providerExecuted,title:m.title,...w.providerMetadata!=null&&(m.state==="output-available"||m.state==="output-error")?{resultProviderMetadata:w.providerMetadata}:{},...w.providerMetadata!=null&&!(m.state==="output-available"||m.state==="output-error")?{callProviderMetadata:w.providerMetadata}:{}})}async function j(m){if(m!=null){const A=u.message.metadata!=null?rg(u.message.metadata,m):m;t!=null&&await Hu({value:A,schema:t,context:{field:"message.metadata",entityId:u.message.id}}),u.message.metadata=A}}switch(a.type){case"text-start":{const m={type:"text",text:"",providerMetadata:a.providerMetadata,state:"streaming"};u.activeTextParts[a.id]=m,u.message.parts.push(m),d();break}case"text-delta":{const m=u.activeTextParts[a.id];if(m==null)throw new er({chunkType:"text-delta",chunkId:a.id,message:`Received text-delta for missing text part with ID "${a.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`});m.text+=a.delta,m.providerMetadata=(f=a.providerMetadata)!=null?f:m.providerMetadata,d();break}case"text-end":{const m=u.activeTextParts[a.id];if(m==null)throw new er({chunkType:"text-end",chunkId:a.id,message:`Received text-end for missing text part with ID "${a.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`});m.state="done",m.providerMetadata=(h=a.providerMetadata)!=null?h:m.providerMetadata,delete u.activeTextParts[a.id],d();break}case"reasoning-start":{const m={type:"reasoning",text:"",providerMetadata:a.providerMetadata,state:"streaming"};u.activeReasoningParts[a.id]=m,u.message.parts.push(m),d();break}case"reasoning-delta":{const m=u.activeReasoningParts[a.id];if(m==null)throw new er({chunkType:"reasoning-delta",chunkId:a.id,message:`Received reasoning-delta for missing reasoning part with ID "${a.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`});m.text+=a.delta,m.providerMetadata=(p=a.providerMetadata)!=null?p:m.providerMetadata,d();break}case"reasoning-end":{const m=u.activeReasoningParts[a.id];if(m==null)throw new er({chunkType:"reasoning-end",chunkId:a.id,message:`Received reasoning-end for missing reasoning part with ID "${a.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`});m.providerMetadata=(g=a.providerMetadata)!=null?g:m.providerMetadata,m.state="done",delete u.activeReasoningParts[a.id],d();break}case"file":{u.message.parts.push({type:"file",mediaType:a.mediaType,url:a.url,...a.providerMetadata!=null?{providerMetadata:a.providerMetadata}:{}}),d();break}case"source-url":{u.message.parts.push({type:"source-url",sourceId:a.sourceId,url:a.url,title:a.title,providerMetadata:a.providerMetadata}),d();break}case"source-document":{u.message.parts.push({type:"source-document",sourceId:a.sourceId,mediaType:a.mediaType,title:a.title,filename:a.filename,providerMetadata:a.providerMetadata}),d();break}case"tool-input-start":{const m=u.message.parts.filter(ga);u.partialToolCalls[a.toolCallId]={text:"",toolName:a.toolName,index:m.length,dynamic:a.dynamic,title:a.title},a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted,title:a.title,providerMetadata:a.providerMetadata}):S({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-streaming",input:void 0,providerExecuted:a.providerExecuted,title:a.title,providerMetadata:a.providerMetadata}),d();break}case"tool-input-delta":{const m=u.partialToolCalls[a.toolCallId];if(m==null)throw new er({chunkType:"tool-input-delta",chunkId:a.toolCallId,message:`Received tool-input-delta for missing tool call with ID "${a.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`});m.text+=a.inputTextDelta;const{value:A}=await Di(m.text);m.dynamic?y({toolCallId:a.toolCallId,toolName:m.toolName,state:"input-streaming",input:A,title:m.title}):S({toolCallId:a.toolCallId,toolName:m.toolName,state:"input-streaming",input:A,title:m.title}),d();break}case"tool-input-available":{a.dynamic?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:a.title}):S({toolCallId:a.toolCallId,toolName:a.toolName,state:"input-available",input:a.input,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:a.title}),d(),s&&!a.providerExecuted&&await s({toolCall:a});break}case"tool-input-error":{const m=u.message.parts.filter(Es).find(C=>C.toolCallId===a.toolCallId);(m!=null?m.type==="dynamic-tool":!!a.dynamic)?y({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}):S({toolCallId:a.toolCallId,toolName:a.toolName,state:"output-error",input:void 0,rawInput:a.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata}),d();break}case"tool-approval-request":{const m=k(a.toolCallId);m.state="approval-requested",m.approval={id:a.approvalId},d();break}case"tool-output-denied":{const m=k(a.toolCallId);m.state="output-denied",d();break}case"tool-output-available":{const m=k(a.toolCallId);m.type==="dynamic-tool"?y({toolCallId:a.toolCallId,toolName:m.toolName,state:"output-available",input:m.input,output:a.output,preliminary:a.preliminary,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:m.title}):S({toolCallId:a.toolCallId,toolName:Wu(m),state:"output-available",input:m.input,output:a.output,providerExecuted:a.providerExecuted,preliminary:a.preliminary,providerMetadata:a.providerMetadata,title:m.title}),d();break}case"tool-output-error":{const m=k(a.toolCallId);m.type==="dynamic-tool"?y({toolCallId:a.toolCallId,toolName:m.toolName,state:"output-error",input:m.input,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:m.title}):S({toolCallId:a.toolCallId,toolName:Wu(m),state:"output-error",input:m.input,rawInput:m.rawInput,errorText:a.errorText,providerExecuted:a.providerExecuted,providerMetadata:a.providerMetadata,title:m.title}),d();break}case"start-step":{u.message.parts.push({type:"step-start"});break}case"finish-step":{u.activeTextParts={},u.activeReasoningParts={};break}case"start":{a.messageId!=null&&(u.message.id=a.messageId),await j(a.messageMetadata),(a.messageId!=null||a.messageMetadata!=null)&&d();break}case"finish":{a.finishReason!=null&&(u.finishReason=a.finishReason),await j(a.messageMetadata),a.messageMetadata!=null&&d();break}case"message-metadata":{await j(a.messageMetadata),a.messageMetadata!=null&&d();break}case"error":{i==null||i(new Error(a.errorText));break}default:if(dz(a)){if((n==null?void 0:n[a.type])!=null){const C=u.message.parts.findIndex(w=>"id"in w&&"data"in w&&w.id===a.id&&w.type===a.type),v=C>=0?C:u.message.parts.length;await Hu({value:a.data,schema:n[a.type],context:{field:`message.parts[${v}].data`,entityName:a.type,entityId:a.id}})}const m=a;if(m.transient){o==null||o(m);break}const A=m.id!=null?u.message.parts.find(C=>m.type===C.type&&m.id===C.id):void 0;A!=null?A.data=m.data:u.message.parts.push(m),o==null||o(m),d()}}l.enqueue(a)})}}))}async function mz({stream:e,onError:t}){const n=e.getReader();try{for(;;){const{done:r}=await n.read();if(r)break}}catch(r){t==null||t(r)}finally{n.releaseLock()}}Pi({prefix:"aitxt",size:24});Pi({prefix:"aiobj",size:24});var gz=class{constructor(){this.queue=[],this.isProcessing=!1}async processQueue(){if(!this.isProcessing){for(this.isProcessing=!0;this.queue.length>0;)await this.queue[0](),this.queue.shift();this.isProcessing=!1}}async run(e){return new Promise((t,n)=>{this.queue.push(async()=>{try{await e(),t()}catch(r){n(r)}}),this.processQueue()})}};Pi({prefix:"aiobj",size:24});async function xz(e){if(e==null)return[];if(!globalThis.FileList||!(e instanceof globalThis.FileList))throw new Error("FileList is not supported in the current environment");return Promise.all(Array.from(e).map(async t=>{const{name:n,type:r}=t,i=await new Promise((s,o)=>{const a=new FileReader;a.onload=l=>{var u;s((u=l.target)==null?void 0:u.result)},a.onerror=l=>o(l),a.readAsDataURL(t)});return{type:"file",mediaType:r,filename:n,url:i}}))}var yz=class{constructor({api:e="/api/chat",credentials:t,headers:n,body:r,fetch:i,prepareSendMessagesRequest:s,prepareReconnectToStreamRequest:o}){this.api=e,this.credentials=t,this.headers=n,this.body=r,this.fetch=i,this.prepareSendMessagesRequest=s,this.prepareReconnectToStreamRequest=o}async sendMessages({abortSignal:e,...t}){var n,r,i,s,o;const a=await gn(this.body),l=await gn(this.headers),u=await gn(this.credentials),d={...Qn(l),...Qn(t.headers)},f=await((n=this.prepareSendMessagesRequest)==null?void 0:n.call(this,{api:this.api,id:t.chatId,messages:t.messages,body:{...a,...t.body},headers:d,credentials:u,requestMetadata:t.metadata,trigger:t.trigger,messageId:t.messageId})),h=(r=f==null?void 0:f.api)!=null?r:this.api,p=(f==null?void 0:f.headers)!==void 0?Qn(f.headers):d,g=(f==null?void 0:f.body)!==void 0?f.body:{...a,...t.body,id:t.chatId,messages:t.messages,trigger:t.trigger,messageId:t.messageId},k=(i=f==null?void 0:f.credentials)!=null?i:u,y=await((s=this.fetch)!=null?s:globalThis.fetch)(h,{method:"POST",headers:{"Content-Type":"application/json",...p},body:JSON.stringify(g),credentials:k,signal:e});if(!y.ok)throw new Error((o=await y.text())!=null?o:"Failed to fetch the chat response.");if(!y.body)throw new Error("The response body is empty.");return this.processResponseStream(y.body)}async reconnectToStream(e){var t,n,r,i,s;const o=await gn(this.body),a=await gn(this.headers),l=await gn(this.credentials),u={...Qn(a),...Qn(e.headers)},d=await((t=this.prepareReconnectToStreamRequest)==null?void 0:t.call(this,{api:this.api,id:e.chatId,body:{...o,...e.body},headers:u,credentials:l,requestMetadata:e.metadata})),f=(n=d==null?void 0:d.api)!=null?n:`${this.api}/${e.chatId}/stream`,h=(d==null?void 0:d.headers)!==void 0?Qn(d.headers):u,p=(r=d==null?void 0:d.credentials)!=null?r:l,k=await((i=this.fetch)!=null?i:globalThis.fetch)(f,{method:"GET",headers:h,credentials:p});if(k.status===204)return null;if(!k.ok)throw new Error((s=await k.text())!=null?s:"Failed to fetch the chat response.");if(!k.body)throw new Error("The response body is empty.");return this.processResponseStream(k.body)}},ig=class extends yz{constructor(e={}){super(e)}processResponseStream(e){return VA({stream:e,schema:uz}).pipeThrough(new TransformStream({async transform(t,n){if(!t.success)throw t.error;n.enqueue(t.value)}}))}},bz=class{constructor({generateId:e=JI,id:t=e(),transport:n=new ig,messageMetadataSchema:r,dataPartSchemas:i,state:s,onError:o,onToolCall:a,onFinish:l,onData:u,sendAutomaticallyWhen:d}){this.activeResponse=void 0,this.jobExecutor=new gz,this.sendMessage=async(f,h)=>{var p,g,k,S;if(f==null){await this.makeRequest({trigger:"submit-message",messageId:(p=this.lastMessage)==null?void 0:p.id,...h});return}let y;if("text"in f||"files"in f?y={parts:[...Array.isArray(f.files)?f.files:await xz(f.files),..."text"in f&&f.text!=null?[{type:"text",text:f.text}]:[]]}:y=f,f.messageId!=null){const j=this.state.messages.findIndex(m=>m.id===f.messageId);if(j===-1)throw new Error(`message with id ${f.messageId} not found`);if(this.state.messages[j].role!=="user")throw new Error(`message with id ${f.messageId} is not a user message`);this.state.messages=this.state.messages.slice(0,j+1),this.state.replaceMessage(j,{...y,id:f.messageId,role:(g=y.role)!=null?g:"user",metadata:f.metadata})}else this.state.pushMessage({...y,id:(k=y.id)!=null?k:this.generateId(),role:(S=y.role)!=null?S:"user",metadata:f.metadata});await this.makeRequest({trigger:"submit-message",messageId:f.messageId,...h})},this.regenerate=async({messageId:f,...h}={})=>{const p=f==null?this.state.messages.length-1:this.state.messages.findIndex(g=>g.id===f);if(p===-1)throw new Error(`message ${f} not found`);this.state.messages=this.state.messages.slice(0,this.messages[p].role==="assistant"?p:p+1),await this.makeRequest({trigger:"regenerate-message",messageId:f,...h})},this.resumeStream=async(f={})=>{await this.makeRequest({trigger:"resume-stream",...f})},this.clearError=()=>{this.status==="error"&&(this.state.error=void 0,this.setStatus({status:"ready"}))},this.addToolApprovalResponse=async({id:f,approved:h,reason:p,options:g})=>this.jobExecutor.run(async()=>{const k=this.state.messages,S=k[k.length-1],y=j=>Es(j)&&j.state==="approval-requested"&&j.approval.id===f?{...j,state:"approval-responded",approval:{id:f,approved:h,reason:p}}:j;this.state.replaceMessage(k.length-1,{...S,parts:S.parts.map(y)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(y)),this.status!=="streaming"&&this.status!=="submitted"&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(j=>{var m;j&&this.makeRequest({trigger:"submit-message",messageId:(m=this.lastMessage)==null?void 0:m.id,...g})})}),this.addToolOutput=async({state:f="output-available",toolCallId:h,output:p,errorText:g,options:k})=>this.jobExecutor.run(async()=>{const S=this.state.messages,y=S[S.length-1],j=m=>Es(m)&&m.toolCallId===h?{...m,state:f,output:p,errorText:g}:m;this.state.replaceMessage(S.length-1,{...y,parts:y.parts.map(j)}),this.activeResponse&&(this.activeResponse.state.message.parts=this.activeResponse.state.message.parts.map(j)),this.status!=="streaming"&&this.status!=="submitted"&&this.sendAutomaticallyWhen&&this.shouldSendAutomatically().then(m=>{var A;m&&this.makeRequest({trigger:"submit-message",messageId:(A=this.lastMessage)==null?void 0:A.id,...k})})}),this.addToolResult=this.addToolOutput,this.stop=async()=>{var f;this.status!=="streaming"&&this.status!=="submitted"||(f=this.activeResponse)!=null&&f.abortController&&this.activeResponse.abortController.abort()},this.id=t,this.transport=n,this.generateId=e,this.messageMetadataSchema=r,this.dataPartSchemas=i,this.state=s,this.onError=o,this.onToolCall=a,this.onFinish=l,this.onData=u,this.sendAutomaticallyWhen=d}get status(){return this.state.status}setStatus({status:e,error:t}){this.status!==e&&(this.state.status=e,this.state.error=t)}get error(){return this.state.error}get messages(){return this.state.messages}get lastMessage(){return this.state.messages[this.state.messages.length-1]}set messages(e){this.state.messages=e}async shouldSendAutomatically(){if(!this.sendAutomaticallyWhen)return!1;const e=this.sendAutomaticallyWhen({messages:this.state.messages});return e&&typeof e=="object"&&"then"in e?await e:e}async makeRequest({trigger:e,metadata:t,headers:n,body:r,messageId:i}){var s,o,a;let l;if(e==="resume-stream")try{const p=await this.transport.reconnectToStream({chatId:this.id,metadata:t,headers:n,body:r});if(p==null)return;l=p}catch(p){this.onError&&p instanceof Error&&this.onError(p),this.setStatus({status:"error",error:p});return}this.setStatus({status:"submitted",error:void 0});const u=this.lastMessage;let d=!1,f=!1,h=!1;try{const p={state:pz({lastMessage:this.state.snapshot(u),messageId:this.generateId()}),abortController:new AbortController};p.abortController.signal.addEventListener("abort",()=>{d=!0}),this.activeResponse=p;let g;e==="resume-stream"?g=l:g=await this.transport.sendMessages({chatId:this.id,messages:this.state.messages,abortSignal:p.abortController.signal,metadata:t,headers:n,body:r,trigger:e,messageId:i});const k=S=>this.jobExecutor.run(()=>S({state:p.state,write:()=>{var y;this.setStatus({status:"streaming"}),p.state.message.id===((y=this.lastMessage)==null?void 0:y.id)?this.state.replaceMessage(this.state.messages.length-1,p.state.message):this.state.pushMessage(p.state.message)}}));await mz({stream:hz({stream:g,onToolCall:this.onToolCall,onData:this.onData,messageMetadataSchema:this.messageMetadataSchema,dataPartSchemas:this.dataPartSchemas,runUpdateMessageJob:k,onError:S=>{throw S}}),onError:S=>{throw S}}),this.setStatus({status:"ready"})}catch(p){if(d||p.name==="AbortError")return d=!0,this.setStatus({status:"ready"}),null;h=!0,p instanceof TypeError&&(p.message.toLowerCase().includes("fetch")||p.message.toLowerCase().includes("network"))&&(f=!0),this.onError&&p instanceof Error&&this.onError(p),this.setStatus({status:"error",error:p})}finally{try{(o=this.onFinish)==null||o.call(this,{message:this.activeResponse.state.message,messages:this.state.messages,isAbort:d,isDisconnect:f,isError:h,finishReason:(s=this.activeResponse)==null?void 0:s.state.finishReason})}catch(p){console.error(p)}this.activeResponse=void 0}!h&&await this.shouldSendAutomatically()&&await this.makeRequest({trigger:"submit-message",messageId:(a=this.lastMessage)==null?void 0:a.id,metadata:t,headers:n,body:r})}},Po,qu;function vz(){if(qu)return Po;qu=1;function e(t,n){if(typeof t!="function")throw new TypeError(`Expected the first argument to be a \`function\`, got \`${typeof t}\`.`);let r,i=0;return function(...o){clearTimeout(r);const a=Date.now(),l=a-i,u=n-l;u<=0?(i=a,t.apply(this,o)):r=setTimeout(()=>{i=Date.now(),t.apply(this,o)},u)}}return Po=e,Po}var wz=vz();const kz=wa(wz);var sg=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},We=(e,t,n)=>(sg(e,t,"read from private field"),n?n.call(e):t.get(e)),Kt=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},mn=(e,t,n,r)=>(sg(e,t,"write to private field"),t.set(e,n),n);function Sz(e,t){return t!=null?kz(e,t):e}var Pt,Qi,es,Qr,ei,ti,sr,xa,ya,jz=class{constructor(e=[]){Kt(this,Pt,void 0),Kt(this,Qi,"ready"),Kt(this,es,void 0),Kt(this,Qr,new Set),Kt(this,ei,new Set),Kt(this,ti,new Set),this.pushMessage=t=>{mn(this,Pt,We(this,Pt).concat(t)),We(this,sr).call(this)},this.popMessage=()=>{mn(this,Pt,We(this,Pt).slice(0,-1)),We(this,sr).call(this)},this.replaceMessage=(t,n)=>{mn(this,Pt,[...We(this,Pt).slice(0,t),this.snapshot(n),...We(this,Pt).slice(t+1)]),We(this,sr).call(this)},this.snapshot=t=>structuredClone(t),this["~registerMessagesCallback"]=(t,n)=>{const r=n?Sz(t,n):t;return We(this,Qr).add(r),()=>{We(this,Qr).delete(r)}},this["~registerStatusCallback"]=t=>(We(this,ei).add(t),()=>{We(this,ei).delete(t)}),this["~registerErrorCallback"]=t=>(We(this,ti).add(t),()=>{We(this,ti).delete(t)}),Kt(this,sr,()=>{We(this,Qr).forEach(t=>t())}),Kt(this,xa,()=>{We(this,ei).forEach(t=>t())}),Kt(this,ya,()=>{We(this,ti).forEach(t=>t())}),mn(this,Pt,e)}get status(){return We(this,Qi)}set status(e){mn(this,Qi,e),We(this,xa).call(this)}get error(){return We(this,es)}set error(e){mn(this,es,e),We(this,ya).call(this)}get messages(){return We(this,Pt)}set messages(e){mn(this,Pt,[...e]),We(this,sr).call(this)}};Pt=new WeakMap;Qi=new WeakMap;es=new WeakMap;Qr=new WeakMap;ei=new WeakMap;ti=new WeakMap;sr=new WeakMap;xa=new WeakMap;ya=new WeakMap;var or,Gu=class extends bz{constructor({messages:e,...t}){const n=new jz(e);super({...t,state:n}),Kt(this,or,void 0),this["~registerMessagesCallback"]=(r,i)=>We(this,or)["~registerMessagesCallback"](r,i),this["~registerStatusCallback"]=r=>We(this,or)["~registerStatusCallback"](r),this["~registerErrorCallback"]=r=>We(this,or)["~registerErrorCallback"](r),mn(this,or,n)}};or=new WeakMap;function _z({experimental_throttle:e,resume:t=!1,...n}={}){const r=x.useRef("chat"in n?{}:{onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});"chat"in n||(r.current={onToolCall:n.onToolCall,onData:n.onData,onFinish:n.onFinish,onError:n.onError,sendAutomaticallyWhen:n.sendAutomaticallyWhen});const i={...n,onToolCall:h=>{var p,g;return(g=(p=r.current).onToolCall)==null?void 0:g.call(p,h)},onData:h=>{var p,g;return(g=(p=r.current).onData)==null?void 0:g.call(p,h)},onFinish:h=>{var p,g;return(g=(p=r.current).onFinish)==null?void 0:g.call(p,h)},onError:h=>{var p,g;return(g=(p=r.current).onError)==null?void 0:g.call(p,h)},sendAutomaticallyWhen:h=>{var p,g,k;return(k=(g=(p=r.current).sendAutomaticallyWhen)==null?void 0:g.call(p,h))!=null?k:!1}},s=x.useRef("chat"in n?n.chat:new Gu(i));("chat"in n&&n.chat!==s.current||"id"in n&&s.current.id!==n.id)&&(s.current="chat"in n?n.chat:new Gu(i));const a=x.useCallback(h=>s.current["~registerMessagesCallback"](h,e),[e,s.current.id]),l=x.useSyncExternalStore(a,()=>s.current.messages,()=>s.current.messages),u=x.useSyncExternalStore(s.current["~registerStatusCallback"],()=>s.current.status,()=>s.current.status),d=x.useSyncExternalStore(s.current["~registerErrorCallback"],()=>s.current.error,()=>s.current.error),f=x.useCallback(h=>{typeof h=="function"&&(h=h(s.current.messages)),s.current.messages=h},[s]);return x.useEffect(()=>{t&&s.current.resumeStream()},[t,s]),{id:s.current.id,messages:l,setMessages:f,sendMessage:s.current.sendMessage,regenerate:s.current.regenerate,clearError:s.current.clearError,stop:s.current.stop,error:d,resumeStream:s.current.resumeStream,status:u,addToolResult:s.current.addToolOutput,addToolOutput:s.current.addToolOutput,addToolApprovalResponse:s.current.addToolApprovalResponse}}function og(e,t){const n=[...e];for(const r of t){if(!r||typeof r.name!="string")continue;const i=n.findIndex(s=>s.name===r.name);r._delete?i!==-1&&n.splice(i,1):i!==-1?n[i]=r:n.push(r)}return n}function ag(e){let t=0;for(let n=0;n<e.length;n++)t=Math.imul(31,t)+e.charCodeAt(n)|0;return(t>>>0).toString(36)}function lg(e,t,n){if(!(n!=null&&n.selectedText)){const i=Nz(e,t);if(i)return i}if(n!=null&&n.selectedText){const i=n.selectedText,s=e.indexOf(i);if(s!==-1){const a=e.indexOf(i,s+1);let l;if(a===-1)l=s;else if(n.startLine&&n.startLine>0){const f=zz(e,n.startLine);l=Oz(e,i,f)}else l=s;const u=e.slice(0,l),d=e.slice(l+i.length);return{original:e,modified:u+t+d}}if(n.startLine&&n.endLine){const a=Iz(e,t,n.startLine,n.endLine);if(a)return a}const o=Ku(e,t);return o||{original:e,modified:t}}const r=Ku(e,t);return r||{original:e,modified:t}}function Nz(e,t){let n;try{n=JSON.parse(t)}catch{return null}if(!n||typeof n!="object"||Array.isArray(n))return null;const r=n.name;if(typeof r!="string"||!r)return null;let i;try{i=JSON.parse(e)}catch{return null}const s=e.match(/\n(\s+)"/),o=s?s[1].length:2;if(!ba(i,r,n))return null;const a=JSON.stringify(i,null,o);return{original:e,modified:a}}function ba(e,t,n){if(Array.isArray(e)){for(let r=0;r<e.length;r++){const i=e[r];if(i&&typeof i=="object"&&!Array.isArray(i)&&i.name===t)return e[r]=n,!0;if(ba(i,t,n))return!0}return!1}if(e&&typeof e=="object"){for(const r of Object.values(e))if(ba(r,t,n))return!0}return!1}function Ku(e,t){try{const s=JSON.parse(t);if(s&&typeof s=="object"&&!Array.isArray(s))try{const o=JSON.parse(e);if(o&&typeof o=="object"&&!Array.isArray(o)){const a=Object.keys(s).sort().join(","),l=Object.keys(o).sort().join(",");if(a===l)return null}}catch{}}catch{}const n=Ez(t);if(n.length===0)return null;let r=e,i=!1;for(const s of n){const o=Cz(r,t,s);o&&(r=o,i=!0)}return i?{original:e,modified:r}:null}function Ez(e){const t=[],n=e.split(`
235
- `),r=n.find(s=>s.trim().length>0);if(!r)return t;const i=r.search(/\S/);for(const s of n){const o=s.search(/\S/);if(o<0||o!==i)continue;const a=s.match(/^\s*"([^"]+)"\s*:/);a&&t.push(a[1])}return[...new Set(t)]}function Cz(e,t,n){const r=`"${n}"`,i=Yu(e,r);if(i.length===0)return null;const s=Yu(t,r);if(s.length===0)return null;const o=s[0],a=t.slice(o.start,o.end);let l=0;if(i.length>1){let d=-1;for(let f=0;f<i.length;f++){const h=e.slice(i[f].start,i[f].end),p=Az(h,a);p>d&&(d=p,l=f)}}const u=i[l];return e.slice(0,u.start)+a+e.slice(u.end)}function Yu(e,t){const n=[];let r=0;for(;;){const i=e.indexOf(t,r);if(i===-1)break;let s=i-1;for(;s>=0&&(e[s]===" "||e[s]===" ");)s--;const o=s<0?"":e[s];if(o!==""&&o!=="{"&&o!==","&&o!==`
236
- `&&o!=="\r"){r=i+1;continue}const a=e.indexOf(":",i+t.length);if(a===-1){r=i+1;continue}const l=a+1,u=Tz(e,l);if(u===-1){r=i+1;continue}n.push({start:i,end:u}),r=u}return n}function Tz(e,t){for(;t<e.length&&/\s/.test(e[t]);)t++;if(t>=e.length)return-1;const n=e[t];if(n==='"'){let i=t+1;for(;i<e.length;){if(e[i]==="\\"){i+=2;continue}if(e[i]==='"')return i+1;i++}return-1}if(n==="["||n==="{"){const i=n,s=n==="["?"]":"}";let o=1,a=t+1,l=!1;for(;a<e.length&&o>0;){if(e[a]==="\\"&&l){a+=2;continue}e[a]==='"'&&(l=!l),l||(e[a]===i?o++:e[a]===s&&o--),a++}return o===0?a:-1}let r=t;for(;r<e.length&&/[^\s,\]}]/.test(e[r]);)r++;return r>t?r:-1}function Iz(e,t,n,r){const i=e.split(`
237
- `);if(n<1||r<n||n>i.length)return null;const s=i.slice(0,n-1).join(`
238
- `),o=i.slice(r).join(`
239
- `),a=s+(s?`
240
- `:"")+t+(o?`
241
- `:"")+o;return{original:e,modified:a}}function Az(e,t){if(e===t)return 1;if(!e.length||!t.length)return 0;const n=3,r=new Set;for(let o=0;o<=e.length-n;o++)r.add(e.slice(o,o+n));let i=0;for(let o=0;o<=t.length-n;o++)r.has(t.slice(o,o+n))&&i++;const s=Math.max(e.length-n+1,t.length-n+1);return s>0?i/s:0}function zz(e,t){let n=0;const r=e.split(`
242
- `);for(let i=0;i<Math.min(t-1,r.length);i++)n+=r[i].length+1;return n}function Oz(e,t,n){let r=-1,i=1/0,s=e.indexOf(t);for(;s!==-1;){const o=Math.abs(s-n);o<i&&(i=o,r=s),s=e.indexOf(t,s+1)}return r}function Pz(e){const t=e[e.length-1][1];try{return JSON.parse(t),t}catch{}if(e.length>1){const n=e.map(r=>r[1]).join(`
243
- `);try{return JSON.parse(n),n}catch{}}return null}function Dz(e,t,n){if(n==="global")return null;try{const r=JSON.parse(e),i=JSON.parse(t);if(n==="slides"&&Array.isArray(i.children))r.children=i.children;else if(n==="templates"&&Array.isArray(i.templates))r.props||(r.props={}),r.props.templates=og(r.props.templates||[],i.templates);else return null;return{original:e,modified:JSON.stringify(r,null,2)}}catch{return null}}function Rz(){const e=De(J=>J.threads),t=De(J=>J.activeThreadId),n=De(J=>J.updateThreadMessages),r=De(J=>J.updateThreadTitle),i=De(J=>J.clearContext),s=De(J=>J.contextAttachments),o=De(J=>J.scope),a=De(J=>J.model),l=ke(J=>J.activeTab),u=ke(J=>J.documents),d=ke(J=>J.documentTypes),f=ke(J=>J.setPendingDiff),h=ke(J=>J.createDocument),p=ke(J=>J.openDocument),g=x.useRef(e);g.current=e;const k=x.useRef(l);k.current=l;const S=x.useRef(u);S.current=u;const y=x.useRef(d);y.current=d;const j=x.useRef(t);j.current=t;const m=l?t[l]:void 0,A=x.useRef(m);A.current=m;const C=x.useRef([]),v=x.useRef([]),w=x.useRef({}),O=x.useRef({}),[,B]=x.useState(0),N=x.useCallback(()=>B(J=>J+1),[]),R=x.useRef(null);R.current||(R.current=new ig({api:"/api/ai/chat"}));const T=x.useCallback(()=>{const J=S.current.find(Z=>Z.name===k.current);return J?{name:J.name,text:J.text}:void 0},[]),F=x.useCallback(J=>w.current[J]||[],[]),z=_z({transport:R.current,onError:()=>{C.current.shift(),v.current.shift(),i()},onFinish:({messages:J})=>{var G,ne;const Z=A.current;if(Z){n(Z,J);const Q=g.current[Z];if(Q&&Q.title.startsWith("Chat ")){const oe=J.find(I=>I.role==="user");if(oe){const I=((G=oe.parts)==null?void 0:G.filter(re=>re.type==="text").map(re=>re.text).join(""))||"";if(I){const re=I.length>50?I.slice(0,50)+"...":I;r(Z,re)}}}}const X=C.current.shift()||[],_=v.current.shift()||"global",ye=J.filter(Q=>Q.role==="user"),ce=ye[ye.length-1];ce!=null&&ce.id&&(w.current[ce.id]=X,O.current[ce.id]=_);const b=J.filter(Q=>Q.role==="assistant").pop();if(b){const oe=[...(((ne=b.parts)==null?void 0:ne.filter(I=>I.type==="text").map(I=>I.text).join(""))||"").matchAll(/```(?:json|jsonc)\s*\n([\s\S]*?)```/g)];if(oe.length>0){const I=Pz(oe);if(I){const re=oe[oe.length-1][1],ae=k.current;if(ae){const H=S.current.find($e=>$e.name===ae),K=(H==null?void 0:H.text)||"",pe=X[0],fe=Dz(K,I,_);!fe&&_!=="global"&&console.warn(`[chat] scopedMerge failed for scope="${_}", falling back to text merge`);const{original:Re,modified:Oe}=fe??lg(K,I,pe);f(ae,Re,Oe,ag(re.replace(/\n$/,"")))}else{const H=`ai-generated-${Date.now()}`;h(H,I),p(H)}}}}i()}});x.useEffect(()=>{const J=z.messages.filter(Z=>Z.role==="user");for(let Z=J.length-1;Z>=0;Z--){const X=J[Z].id;if(X in w.current)break;C.current.length>0&&(w.current[X]=C.current[0],O.current[X]=v.current[0]||"global",N());break}},[z.messages,N]);const M=x.useCallback((J,Z)=>{C.current.push([...s]),v.current.push(o),i();const X={text:J};Z!=null&&Z.length&&(X.files=Z),z.sendMessage(X,{body:{format:at,context:s,activeDocument:T(),documentType:k.current&&y.current[k.current]||"application/json+report",scope:o,model:a}})},[z.sendMessage,s,T,i,o,a]),D=x.useCallback(J=>O.current[J],[]);return{messages:z.messages,sendMessage:M,status:z.status,error:z.error,setMessages:z.setMessages,stop:z.stop,getMessageContext:F,getMessageScope:D}}const cg=x.createContext(null);function $z({children:e}){const t=Rz();return c.jsx(cg.Provider,{value:t,children:e})}function Mz(){const e=x.useContext(cg);if(!e)throw new Error("useChatSessionContext must be used within ChatSessionProvider");return e}function Fz(e){try{const t=JSON.parse(e.selectedText);if(t!=null&&t.name)return t.name}catch{}return e.propertyKey?e.propertyKey:e.jsonPath?(e.jsonPath.split(".").pop()??e.jsonPath).replace(/\[\d+\]/g,""):"selection"}function Lz(e,t=50){const n=e.replace(/[\n\r]+/g," ").replace(/\s+/g," ").trim();return n.length>t?n.slice(0,t)+"…":n}function ug({context:e,onRemove:t,variant:n="default"}){var u;const r=Fz(e),i=((u=e.documentName)==null?void 0:u.replace(/\.json$/,""))??"",s=i?`${i} › ${r}`:r,o=Lz(e.selectedText),a=n==="sent",l=c.jsxs("div",{className:`group flex items-center gap-1.5 rounded-md border pl-2 ${t?"pr-1":"pr-2"} py-1 text-xs max-w-[280px] transition-colors ${a?"border-primary-foreground/20 bg-primary-foreground/10 hover:bg-primary-foreground/20":"border-primary/20 bg-primary/5 hover:bg-primary/10"}`,children:[c.jsx(Fx,{className:`h-3 w-3 shrink-0 ${a?"text-primary-foreground/60":"text-primary/60"}`}),c.jsx("span",{className:"truncate font-medium",children:s}),t&&c.jsx("button",{type:"button",onClick:t,className:"shrink-0 rounded-sm p-0.5 opacity-60 hover:opacity-100 hover:bg-muted transition-opacity cursor-pointer","aria-label":"Remove context",children:c.jsx(wn,{className:"h-3 w-3"})})]});return c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:l}),c.jsxs(Qe,{side:"top",className:"max-w-xs",children:[c.jsx("p",{className:"text-xs font-medium mb-0.5",children:s}),c.jsx("p",{className:"text-xs text-muted-foreground font-mono",children:o}),e.jsonPath&&c.jsx("p",{className:"text-[10px] text-muted-foreground/60 mt-1",children:e.jsonPath})]})]})}class tr extends Error{constructor(t,n){super(`${t} at position ${n}`),this.position=n}}const dg=32,Bz=10,fg=9,pg=13,Vz=160,Zz=6158,Uz=8192,Jz=8203,Hz=8239,Wz=8287,qz=12288,Gz=65279;function Kz(e){return/^[0-9A-Fa-f]$/.test(e)}function An(e){return e>="0"&&e<="9"}function Yz(e){return e>=" "}function qi(e){return`,:[]/{}()
244
- +`.includes(e)}function Xu(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"||e==="$"}function Qu(e){return e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="_"||e==="$"||e>="0"&&e<="9"}const ed=/^(http|https|ftp|mailto|file|data|irc):\/\/$/,td=/^[A-Za-z0-9-._~:/?#@!$&'()*+;=]$/;function nd(e){return`,[]/{}
245
- +`.includes(e)}function rd(e){return ts(e)||Xz.test(e)}const Xz=/^[[{\w-]$/;function Qz(e){return e===`
246
- `||e==="\r"||e===" "||e==="\b"||e==="\f"}function zn(e,t){const n=e.charCodeAt(t);return n===dg||n===Bz||n===fg||n===pg}function eO(e,t){const n=e.charCodeAt(t);return n===dg||n===fg||n===pg}function tO(e,t){const n=e.charCodeAt(t);return n===Vz||n===Zz||n>=Uz&&n<=Jz||n===Hz||n===Wz||n===qz||n===Gz}function ts(e){return hg(e)||va(e)}function hg(e){return e==='"'||e==="“"||e==="”"}function id(e){return e==='"'}function va(e){return e==="'"||e==="‘"||e==="’"||e==="`"||e==="´"}function sd(e){return e==="'"}function qr(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!1;const r=e.lastIndexOf(t);return r!==-1?e.substring(0,r)+(n?"":e.substring(r+1)):e}function Zt(e,t){let n=e.length;if(!zn(e,n-1))return e+t;for(;zn(e,n-1);)n--;return e.substring(0,n)+t+e.substring(n)}function nO(e,t,n){return e.substring(0,t)+e.substring(t+n)}function rO(e){return/[,\n][ \t\r]*$/.test(e)}const iO={"\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t"},sO={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
247
- `,r:"\r",t:" "};function od(e){let t=0,n="";u(["```","[```","{```"]),s()||z(),u(["```","```]","```}"]);const i=f(",");for(i&&o(),rd(e[t])&&rO(n)?(i||(n=Zt(n,",")),y()):i&&(n=qr(n,","));e[t]==="}"||e[t]==="]";)t++,o();if(t>=e.length)return n;F();function s(){o();const Z=k()||S()||j()||A()||C()||w(!1)||O();return o(),Z}function o(){let Z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!0;const X=t;let _=a(Z);do _=l(),_&&(_=a(Z));while(_);return t>X}function a(Z){const X=Z?zn:eO;let _="";for(;;)if(X(e,t))_+=e[t],t++;else if(tO(e,t))_+=" ",t++;else break;return _.length>0?(n+=_,!0):!1}function l(){if(e[t]==="/"&&e[t+1]==="*"){for(;t<e.length&&!oO(e,t);)t++;return t+=2,!0}if(e[t]==="/"&&e[t+1]==="/"){for(;t<e.length&&e[t]!==`
248
- `;)t++;return!0}return!1}function u(Z){if(d(Z)){if(Xu(e[t]))for(;t<e.length&&Qu(e[t]);)t++;return o(),!0}return!1}function d(Z){a(!0);for(const X of Z){const _=t+X.length;if(e.slice(t,_)===X)return t=_,!0}return!1}function f(Z){return e[t]===Z?(n+=e[t],t++,!0):!1}function h(Z){return e[t]===Z?(t++,!0):!1}function p(){return h("\\")}function g(){return o(),e[t]==="."&&e[t+1]==="."&&e[t+2]==="."?(t+=3,o(),h(","),!0):!1}function k(){if(e[t]==="{"){n+="{",t++,o(),h(",")&&o();let Z=!0;for(;t<e.length&&e[t]!=="}";){let X;if(Z?(X=!0,Z=!1):(X=f(","),X||(n=Zt(n,",")),o()),g(),!(j()||w(!0))){e[t]==="}"||e[t]==="{"||e[t]==="]"||e[t]==="["||e[t]===void 0?n=qr(n,","):M();break}o();const ye=f(":"),ce=t>=e.length;ye||(rd(e[t])||ce?n=Zt(n,":"):D()),s()||(ye||ce?n+="null":D())}return e[t]==="}"?(n+="}",t++):n=Zt(n,"}"),!0}return!1}function S(){if(e[t]==="["){n+="[",t++,o(),h(",")&&o();let Z=!0;for(;t<e.length&&e[t]!=="]";)if(Z?Z=!1:f(",")||(n=Zt(n,",")),g(),!s()){n=qr(n,",");break}return e[t]==="]"?(n+="]",t++):n=Zt(n,"]"),!0}return!1}function y(){let Z=!0,X=!0;for(;X;)Z?Z=!1:f(",")||(n=Zt(n,",")),X=s();X||(n=qr(n,",")),n=`[
249
- ${n}
250
- ]`}function j(){let Z=arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1,X=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1,_=e[t]==="\\";if(_&&(t++,_=!0),ts(e[t])){const ye=id(e[t])?id:sd(e[t])?sd:va(e[t])?va:hg,ce=t,b=n.length;let G='"';for(t++;;){if(t>=e.length){const ne=B(t-1);return!Z&&qi(e.charAt(ne))?(t=ce,n=n.substring(0,b),j(!0)):(G=Zt(G,'"'),n+=G,!0)}if(t===X)return G=Zt(G,'"'),n+=G,!0;if(ye(e[t])){const ne=t,Q=G.length;if(G+='"',t++,n+=G,o(!1),Z||t>=e.length||qi(e[t])||ts(e[t])||An(e[t]))return m(),!0;const oe=B(ne-1),I=e.charAt(oe);if(I===",")return t=ce,n=n.substring(0,b),j(!1,oe);if(qi(I))return t=ce,n=n.substring(0,b),j(!0);n=n.substring(0,b),t=ne+1,G=`${G.substring(0,Q)}\\${G.substring(Q)}`}else if(Z&&nd(e[t])){if(e[t-1]===":"&&ed.test(e.substring(ce+1,t+2)))for(;t<e.length&&td.test(e[t]);)G+=e[t],t++;return G=Zt(G,'"'),n+=G,m(),!0}else if(e[t]==="\\"){const ne=e.charAt(t+1);if(sO[ne]!==void 0)G+=e.slice(t,t+2),t+=2;else if(ne==="u"){let oe=2;for(;oe<6&&Kz(e[t+oe]);)oe++;oe===6?(G+=e.slice(t,t+6),t+=6):t+oe>=e.length?t=e.length:J()}else G+=ne,t+=2}else{const ne=e.charAt(t);ne==='"'&&e[t-1]!=="\\"?(G+=`\\${ne}`,t++):Qz(ne)?(G+=iO[ne],t++):(Yz(ne)||T(ne),G+=ne,t++)}_&&p()}}return!1}function m(){let Z=!1;for(o();e[t]==="+";){Z=!0,t++,o(),n=qr(n,'"',!0);const X=n.length;j()?n=nO(n,X,1):n=Zt(n,'"')}return Z}function A(){const Z=t;if(e[t]==="-"){if(t++,N())return R(Z),!0;if(!An(e[t]))return t=Z,!1}for(;An(e[t]);)t++;if(e[t]==="."){if(t++,N())return R(Z),!0;if(!An(e[t]))return t=Z,!1;for(;An(e[t]);)t++}if(e[t]==="e"||e[t]==="E"){if(t++,(e[t]==="-"||e[t]==="+")&&t++,N())return R(Z),!0;if(!An(e[t]))return t=Z,!1;for(;An(e[t]);)t++}if(!N())return t=Z,!1;if(t>Z){const X=e.slice(Z,t),_=/^0\d/.test(X);return n+=_?`"${X}"`:X,!0}return!1}function C(){return v("true","true")||v("false","false")||v("null","null")||v("True","true")||v("False","false")||v("None","null")}function v(Z,X){return e.slice(t,t+Z.length)===Z?(n+=X,t+=Z.length,!0):!1}function w(Z){const X=t;if(Xu(e[t])){for(;t<e.length&&Qu(e[t]);)t++;let _=t;for(;zn(e,_);)_++;if(e[_]==="(")return t=_+1,s(),e[t]===")"&&(t++,e[t]===";"&&t++),!0}for(;t<e.length&&!nd(e[t])&&!ts(e[t])&&(!Z||e[t]!==":");)t++;if(e[t-1]===":"&&ed.test(e.substring(X,t+2)))for(;t<e.length&&td.test(e[t]);)t++;if(t>X){for(;zn(e,t-1)&&t>0;)t--;const _=e.slice(X,t);return n+=_==="undefined"?"null":JSON.stringify(_),e[t]==='"'&&t++,!0}}function O(){if(e[t]==="/"){const Z=t;for(t++;t<e.length&&(e[t]!=="/"||e[t-1]==="\\");)t++;return t++,n+=JSON.stringify(e.substring(Z,t)),!0}}function B(Z){let X=Z;for(;X>0&&zn(e,X);)X--;return X}function N(){return t>=e.length||qi(e[t])||zn(e,t)}function R(Z){n+=`${e.slice(Z,t)}0`}function T(Z){throw new tr(`Invalid character ${JSON.stringify(Z)}`,t)}function F(){throw new tr(`Unexpected character ${JSON.stringify(e[t])}`,t)}function z(){throw new tr("Unexpected end of json string",e.length)}function M(){throw new tr("Object key expected",t)}function D(){throw new tr("Colon expected",t)}function J(){const Z=e.slice(t,t+6);throw new tr(`Invalid unicode character "${Z}"`,t)}}function oO(e,t){return e[t]==="*"&&e[t+1]==="/"}function aO({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 od(e)}catch{}const y=`{${e}}`;try{return JSON.parse(y),y}catch{}try{return od(y)}catch{return null}},[e]),l=x.useMemo(()=>ag(a||e),[a,e]),u=ke(y=>y.activeTab),d=ke(y=>y.documents),f=ke(y=>(y.acceptedApplyIds||[]).includes(l)),h=ke(y=>y.setPendingDiff),p=ke(y=>y.createDocument),g=ke(y=>y.openDocument),k=x.useCallback(()=>{if(a){o(null);try{if(u){const y=d.find(v=>v.name===u),j=(y==null?void 0:y.text)||"";if(n==="templates")try{const v=JSON.parse(j),w=JSON.parse(a);if(Array.isArray(w.templates)){v.props||(v.props={}),v.props.templates=og(v.props.templates||[],w.templates);const O=JSON.stringify(v,null,2);h(u,j,O,l);return}}catch{}const m=t==null?void 0:t[0],{original:A,modified:C}=lg(j,a,m);h(u,A,C,l)}else{const y=`ai-generated-${Date.now()}`;p(y,a),g(y)}}catch(y){o(y instanceof Error?y.message:"Merge failed")}}},[a,u,d,h,p,g,t,n,l]),S=x.useCallback(async()=>{await navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),1500)},[e]);return c.jsxs("div",{className:"flex flex-col gap-1 px-3 py-2 border-t",children:[c.jsxs("div",{className:"flex gap-1.5",children:[c.jsx(Ee,{variant:"secondary",size:"sm",onClick:k,disabled:f||!a,children:f?"Applied":a?"Apply to Editor":"Invalid JSON"}),c.jsx(Ee,{variant:"ghost",size:"sm",onClick:S,children:r?c.jsx(un,{className:"h-3.5 w-3.5"}):c.jsx(zs,{className:"h-3.5 w-3.5"})})]}),s&&c.jsx("p",{className:"text-xs text-destructive m-0",children:s})]})}function lO({threads:e,activeThread:t,disabled:n,onSwitch:r,onCreate:i,onDelete:s,onRename:o}){const[a,l]=x.useState(null),[u,d]=x.useState(""),[f,h]=x.useState(null),p=x.useRef(null),g=(t==null?void 0:t.title)||"New Chat",k=g.length>24?g.slice(0,24)+"...":g;x.useEffect(()=>{a&&requestAnimationFrame(()=>{var w;return(w=p.current)==null?void 0:w.focus()})},[a]);const S=x.useCallback((w,O)=>{O.stopPropagation(),O.preventDefault(),l(w.id),d(w.title),h(null)},[]),y=x.useCallback(()=>{a&&u.trim()&&o(a,u.trim()),l(null),d("")},[a,u,o]),j=x.useCallback(()=>{l(null),d("")},[]),m=x.useCallback(w=>{w.stopPropagation(),w.key==="Enter"?(w.preventDefault(),y()):w.key==="Escape"&&(w.preventDefault(),j())},[y,j]),A=x.useCallback((w,O)=>{O.stopPropagation(),O.preventDefault(),h(w),l(null)},[]),C=x.useCallback(w=>{w.stopPropagation(),w.preventDefault(),f&&(s(f),h(null))},[f,s]),v=x.useCallback(w=>{w.stopPropagation(),w.preventDefault(),h(null)},[]);return c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsxs(Ti,{onOpenChange:w=>{w||(l(null),h(null))},children:[c.jsx(Ii,{asChild:!0,disabled:n,children:c.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:[c.jsx("div",{className:"h-2 w-2 rounded-full bg-primary/70 shrink-0"}),c.jsx("span",{className:"truncate",children:k}),c.jsx(Ni,{className:"h-3 w-3 shrink-0 opacity-60"})]})}),c.jsxs(Ar,{align:"start",className:"w-64",children:[e.map(w=>{const O=a===w.id;return f===w.id?c.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 text-sm",children:[c.jsx("span",{className:"text-destructive text-xs flex-1 truncate",children:"Delete this thread?"}),c.jsx("button",{className:"shrink-0 text-destructive hover:text-destructive/80 transition-colors cursor-pointer",onClick:C,children:c.jsx(un,{className:"h-3.5 w-3.5"})}),c.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onClick:v,children:c.jsx(wn,{className:"h-3.5 w-3.5"})})]},w.id):O?c.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1",onClick:N=>N.stopPropagation(),onPointerDown:N=>N.stopPropagation(),children:[c.jsx("input",{ref:p,type:"text",value:u,onChange:N=>d(N.target.value),onKeyDown:m,onBlur:y,className:"flex-1 min-w-0 text-sm rounded-sm border border-border bg-background px-1.5 py-0.5 outline-none focus:ring-1 focus:ring-primary/40"}),c.jsx("button",{className:"shrink-0 text-primary hover:text-primary/80 transition-colors cursor-pointer",onMouseDown:N=>{N.preventDefault(),y()},children:c.jsx(un,{className:"h-3.5 w-3.5"})}),c.jsx("button",{className:"shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",onMouseDown:N=>{N.preventDefault(),j()},children:c.jsx(wn,{className:"h-3.5 w-3.5"})})]},w.id):c.jsxs($t,{onSelect:()=>r(w.id),className:`group ${w.id===(t==null?void 0:t.id)?"bg-accent":""}`,children:[c.jsx("span",{className:"truncate flex-1",children:w.title.length>30?w.title.slice(0,30)+"...":w.title}),c.jsxs("div",{className:"ml-auto shrink-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity",children:[c.jsx("button",{className:"text-muted-foreground hover:text-foreground transition-colors p-0.5 cursor-pointer",onClick:N=>S(w,N),children:c.jsx(Lx,{className:"h-3 w-3"})}),e.length>1&&c.jsx("button",{className:"text-muted-foreground hover:text-destructive transition-colors p-0.5 cursor-pointer",onClick:N=>A(w.id,N),children:c.jsx(_a,{className:"h-3 w-3"})})]})]},w.id)}),c.jsx(Fn,{}),c.jsxs($t,{onSelect:w=>{w.preventDefault();const O=i();O&&(l(O),d(Oa()),h(null))},children:[c.jsx(Dt,{className:"h-3.5 w-3.5 mr-1.5"}),"New Chat"]})]})]}),c.jsx(Ee,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-foreground",onClick:()=>i(),disabled:n,title:"New chat thread",children:c.jsx(Dt,{className:"h-3.5 w-3.5"})})]})}const mg=new Set(["image/png","image/jpeg","image/gif","image/webp","application/pdf","text/plain","text/markdown","text/csv","text/html"]),cO=Array.from(mg).join(","),uO=20*1024*1024,ad=10;function dO(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 ld(e){return Array.from(e).filter(t=>mg.has(t.type)&&t.size<=uO)}function gg(e){return e.startsWith("image/")}function cd(){var Y,ge,_e;const e=De(L=>L.contextAttachments),t=De(L=>L.addContext),n=De(L=>L.removeContext),r=De(L=>L.scope),i=De(L=>L.setScope),s=De(L=>L.model),o=De(L=>L.setModel),a=De(L=>L.openChat),l=De(L=>L.closeChat),u=De(L=>L.threads),d=De(L=>L.activeThreadId),f=De(L=>L.createThread),h=De(L=>L.deleteThread),p=De(L=>L.switchThread),g=De(L=>L.updateThreadMessages),k=De(L=>L.updateThreadTitle),S=De(L=>L.deleteThreadsForDocument),y=ke(L=>L.activeTab),j=ke(L=>L.documents),{messages:m,sendMessage:A,status:C,error:v,setMessages:w,stop:O,getMessageContext:B,getMessageScope:N}=Mz(),[R,T]=x.useState(""),[F,z]=x.useState([]),[M,D]=x.useState(!1),[J,Z]=x.useState(!1),X=x.useRef(null),_=x.useRef(null),ye=x.useRef(null),ce=x.useCallback(async L=>{const $=ld(L);if($.length===0)return;const xe=await Promise.all($.map(dO));z(de=>{const Me=[...de,...xe];return Me.length>ad?Me.slice(0,ad):Me})},[]),b=x.useCallback(L=>{z($=>$.filter((xe,de)=>de!==L))},[]),G=x.useCallback(L=>{var xe;const $=(xe=L.clipboardData)==null?void 0:xe.files;if($&&$.length>0){const de=ld($);de.length>0&&(L.preventDefault(),ce(de))}},[ce]),ne=x.useCallback(L=>{var xe;L.preventDefault(),Z(!1);const $=(xe=L.dataTransfer)==null?void 0:xe.files;$&&$.length>0&&ce(Array.from($))},[ce]),Q=x.useCallback(L=>{L.preventDefault(),Z(!0)},[]),oe=x.useCallback(()=>Z(!1),[]),I=y?d[y]:void 0,re=I?u[I]:void 0,ae=x.useMemo(()=>y?Object.values(u).filter(L=>L.documentName===y).sort((L,$)=>$.updatedAt-L.updatedAt):[],[u,y]);x.useEffect(()=>{y&&ae.length===0&&f(y)},[y,ae.length,f]);const H=x.useRef(u);H.current=u,x.useEffect(()=>{const L=new Set(j.map(xe=>xe.name)),$=new Set;for(const xe of Object.values(H.current))!L.has(xe.documentName)&&xe.documentName!=="__migrated__"&&$.add(xe.documentName);for(const xe of $)S(xe)},[j,S]);const K=x.useRef(null);x.useEffect(()=>{K.current!==I&&(K.current=I,w((re==null?void 0:re.messages)??[]))},[I,re,w]),x.useEffect(()=>{var L;(L=X.current)==null||L.scrollIntoView({behavior:"smooth"})},[m,C]),x.useEffect(()=>{const L=$=>{var Me;const{documentName:xe,selection:de}=$.detail;t({...de,documentName:xe}),a(),(Me=_.current)==null||Me.focus()};return window.addEventListener("monaco-selection-to-ai",L),()=>window.removeEventListener("monaco-selection-to-ai",L)},[t,a]);const pe=C==="streaming",fe=C==="submitted"||pe,Re=x.useCallback(L=>{L.preventDefault(),!(!R.trim()&&F.length===0||fe)&&(A(R,F.length>0?F:void 0),T(""),z([]))},[R,F,fe,A]),Oe=x.useCallback(L=>{L.key==="Enter"&&!L.shiftKey&&(L.preventDefault(),Re(L))},[Re]),$e=x.useCallback(()=>{m.length!==0&&D(!0)},[m.length]),E=x.useCallback(()=>{D(!1),w([]),I&&(g(I,[]),k(I,Oa()))},[w,I,g,k]),[P,V]=x.useState(null),se=x.useCallback(L=>{V(L)},[]),ie=x.useCallback(()=>{var Me,Je;if(!P)return;const L=m.findIndex(it=>it.id===P);if(L===-1){V(null);return}const $=m[L],xe=new Set([L]);$.role==="user"&&((Me=m[L+1])==null?void 0:Me.role)==="assistant"?xe.add(L+1):$.role==="assistant"&&L>0&&((Je=m[L-1])==null?void 0:Je.role)==="user"&&xe.add(L-1);const de=m.filter((it,Lt)=>!xe.has(Lt));w(de),I&&g(I,de),V(null)},[P,m,w,I,g]),ee=x.useCallback(L=>{if(!fe){if(ae.length<=1){$e();return}h(L)}},[fe,ae.length,$e,h]),me=x.useCallback(()=>{if(!(!y||fe))return f(y)},[y,fe,f]),we=x.useCallback(L=>{fe||L===I||p(L)},[fe,I,p]),U=x.useCallback((L,$)=>{k(L,$)},[k]);return c.jsxs("div",{className:"flex flex-col h-full border-l bg-surface-chat",children:[c.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-border/60 bg-surface-chat",children:[c.jsx(lO,{threads:ae,activeThread:re,disabled:fe,onSwitch:we,onCreate:me,onDelete:ee,onRename:U}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx(Ee,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs text-muted-foreground hover:text-foreground",onClick:$e,disabled:fe||m.length===0,children:"Clear"}),c.jsx(Ee,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-foreground",onClick:l,title:"Close chat",children:c.jsx(wn,{className:"h-3.5 w-3.5"})})]})]}),c.jsx(hi,{className:"flex-1 min-h-0 [&_[data-radix-scroll-area-viewport]>div]:!block",children:c.jsxs("div",{className:"p-3 space-y-4 min-w-0",children:[m.length===0&&c.jsxs("div",{className:"flex flex-col items-center justify-center py-12 px-4",children:[c.jsx("div",{className:"rounded-xl bg-primary/10 p-3 mb-4",children:c.jsx(wl,{className:"h-5 w-5 text-primary"})}),c.jsx("p",{className:"text-sm font-medium text-foreground/80 mb-1",children:"JSON Assistant"}),c.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."}),c.jsxs("div",{className:"flex items-center gap-1.5 rounded-md bg-muted/50 px-2.5 py-1.5",children:[c.jsx(mi,{shortcut:"mod+k"}),c.jsx("span",{className:"text-xs text-muted-foreground",children:"to send a selection"})]})]}),m.map((L,$)=>{let xe;if(L.role==="user"){const Je=B(L.id);Je&&Je.length>0&&(xe=Je)}else if(L.role==="assistant"){for(let Je=$-1;Je>=0;Je--)if(m[Je].role==="user"){xe=B(m[Je].id);break}}const de=pe&&$===m.length-1&&L.role==="assistant",Me=L.role==="user"?N(L.id):void 0;return c.jsx(fO,{msg:L,isStreaming:de,context:xe,scope:Me,onDelete:fe?void 0:se},L.id)}),fe&&((Y=m[m.length-1])==null?void 0:Y.role)!=="assistant"&&c.jsx("div",{className:"flex justify-start",children:c.jsx("div",{className:"rounded-lg px-3 py-2 bg-muted/60 border border-border/40",children:c.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.jsx(Gr,{className:"h-3.5 w-3.5 animate-spin text-primary"}),c.jsx("span",{children:"Thinking..."})]})})}),v&&!fe&&c.jsx("div",{className:"flex justify-start",children:c.jsx("div",{className:"rounded-lg px-3 py-2 bg-destructive/10 border border-destructive/30 text-destructive text-sm max-w-[90%]",children:v.message||"Something went wrong"})}),c.jsx("div",{ref:X})]})}),c.jsxs("div",{className:`border-t border-border/60 p-2.5 space-y-2 bg-surface-chat transition-colors ${J?"ring-2 ring-primary/40 bg-primary/5":""}`,onDrop:ne,onDragOver:Q,onDragLeave:oe,children:[e.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.map((L,$)=>c.jsx(ug,{context:L,onRemove:()=>n($)},$))}),c.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[c.jsx(mO,{model:s,setModel:o}),at==="pptx"&&y&&c.jsx(xO,{scope:r,setScope:i,docSize:((_e=(ge=j.find(L=>L.name===y))==null?void 0:ge.text)==null?void 0:_e.length)??0})]}),F.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1.5",children:F.map((L,$)=>c.jsxs("div",{className:"relative group",children:[gg(L.mediaType)?c.jsx("img",{src:L.url,alt:L.filename||"attachment",className:"h-14 w-14 rounded-md object-cover border border-border/60"}):c.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:[c.jsx(Lo,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"text-xs truncate text-muted-foreground",children:L.filename||"file"})]}),c.jsx("button",{type:"button",onClick:()=>b($),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:c.jsx(wn,{className:"h-3 w-3"})})]},$))}),c.jsxs("form",{onSubmit:Re,className:"flex items-end gap-2",children:[c.jsx("input",{ref:ye,type:"file",accept:cO,multiple:!0,className:"hidden",onChange:L=>{L.target.files&&ce(Array.from(L.target.files)),L.target.value=""}}),c.jsx(Ee,{type:"button",variant:"ghost",size:"icon",className:"shrink-0 h-9 w-9 rounded-lg text-muted-foreground hover:text-foreground",onClick:()=>{var L;return(L=ye.current)==null?void 0:L.click()},title:"Attach file",children:c.jsx(Lo,{className:"h-4 w-4"})}),c.jsx("textarea",{ref:_,value:R,onChange:L=>{T(L.target.value);const $=L.target;$.style.height="auto",$.style.height=`${Math.min($.scrollHeight,128)}px`},onKeyDown:Oe,onPaste:G,placeholder:e.length>0?"Describe how to edit the selection...":r==="slides"?"Add, edit, or remove slides...":r==="templates"?"Edit template layouts and placeholders...":"Ask AI to generate or edit JSON...",className:"flex-1 min-h-[36px] max-h-32 resize-none overflow-y-auto rounded-lg border border-border/60 bg-background px-3 py-1.5 text-sm placeholder:text-muted-foreground placeholder:whitespace-nowrap placeholder:overflow-hidden placeholder:text-ellipsis focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/30 focus-visible:border-primary/50 transition-shadow",rows:1}),fe?c.jsx(Ee,{type:"button",size:"icon",variant:"destructive",className:"shrink-0 h-9 w-9 rounded-lg",onClick:O,title:"Stop generating",children:c.jsx(tf,{className:"h-4 w-4"})}):c.jsx(Ee,{type:"submit",size:"icon",disabled:!R.trim()&&F.length===0,className:"shrink-0 h-9 w-9 rounded-lg",children:c.jsx(wl,{className:"h-4 w-4"})})]})]}),c.jsx(ct,{open:M,onOpenChange:D,children:c.jsxs(lt,{className:"max-w-sm",children:[c.jsxs(qt,{children:[c.jsx(Gt,{children:"Clear thread"}),c.jsx(dn,{children:"This will delete all messages in this thread. This action cannot be undone."})]}),c.jsxs(kn,{children:[c.jsx(Nl,{asChild:!0,children:c.jsx(Ee,{variant:"ghost",size:"sm",children:"Cancel"})}),c.jsx(Ee,{variant:"destructive",size:"sm",onClick:E,children:"Clear"})]})]})}),c.jsx(ct,{open:P!==null,onOpenChange:L=>{L||V(null)},children:c.jsxs(lt,{className:"max-w-sm",children:[c.jsxs(qt,{children:[c.jsx(Gt,{children:"Delete message"}),c.jsx(dn,{children:"This will delete the message and its paired response. This action cannot be undone."})]}),c.jsxs(kn,{children:[c.jsx(Nl,{asChild:!0,children:c.jsx(Ee,{variant:"ghost",size:"sm",children:"Cancel"})}),c.jsx(Ee,{variant:"destructive",size:"sm",onClick:ie,children:"Delete"})]})]})})]})}const fO=x.memo(function({msg:t,isStreaming:n,context:r,scope:i,onDelete:s}){var l,u;const o=((l=t.parts)==null?void 0:l.filter(d=>d.type==="text").map(d=>d.text).join(""))||"",a=((u=t.parts)==null?void 0:u.filter(d=>d.type==="file"))||[];return c.jsx("div",{className:`group/msg flex ${t.role==="user"?"justify-end":"justify-start"}`,children:c.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"?c.jsxs("div",{children:[a.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:a.map((d,f)=>gg(d.mediaType)?c.jsx("img",{src:d.url,alt:d.filename||"image",className:"h-20 max-w-[160px] rounded-sm object-cover"},f):c.jsxs("div",{className:"flex items-center gap-1.5 rounded-sm bg-primary-foreground/20 px-2 py-1",children:[c.jsx(Lo,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"text-xs truncate max-w-[120px]",children:d.filename||"file"})]},f))}),r&&r.length>0&&c.jsx("div",{className:"flex flex-wrap gap-1 mb-1.5",children:r.map((d,f)=>c.jsx(ug,{context:d,variant:"sent"},f))}),o&&c.jsx("div",{className:"whitespace-pre-wrap text-sm break-words",children:o}),i&&i!=="global"&&c.jsx("span",{className:"text-[10px] text-primary-foreground/60 mt-0.5 block text-right",children:i})]}):c.jsx(pO,{text:o,isStreaming:n,context:r,scope:i}),s&&!n&&c.jsx("div",{className:"opacity-0 transition-opacity group-hover/msg:opacity-100 focus-within:opacity-100 mt-1",children:c.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:c.jsx(_a,{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 pO({text:e,isStreaming:t,context:n,scope:r}){return t?c.jsx("div",{className:"text-sm prose prose-sm dark:prose-invert break-words [&_pre]:overflow-x-auto [&_p]:my-1",children:c.jsx("pre",{className:"whitespace-pre-wrap font-sans text-sm m-0 p-0 bg-transparent border-none",children:e})}):c.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:c.jsx(LS,{remarkPlugins:[Q_],components:{pre:({children:i})=>c.jsx(c.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 c.jsx("code",{className:"rounded-sm bg-muted px-1 py-0.5 text-xs font-mono",children:s});const u=a==="json"||a==="jsonc";return c.jsxs("div",{className:"my-2 rounded-lg border bg-card",children:[c.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-muted/60 border-b text-xs text-muted-foreground",children:[c.jsx("span",{className:"font-mono",children:a||"code"}),!u&&c.jsx(yO,{text:l})]}),c.jsx("pre",{className:"p-3 text-xs font-mono overflow-x-auto max-h-80 overflow-y-auto m-0",children:c.jsx("code",{children:l})}),u&&c.jsx(aO,{json:l,context:n,scope:r})]})}},children:e})})}const hO=[{value:"opus",label:"Opus"},{value:"sonnet",label:"Sonnet"},{value:"haiku",label:"Haiku"}];function mO({model:e,setModel:t}){return c.jsxs(fi,{value:e,onValueChange:n=>t(n),children:[c.jsx(br,{className:"h-6 w-auto gap-1 border-none bg-muted/40 px-2 py-0 text-[10px] shadow-none focus:ring-0",children:c.jsx(pi,{})}),c.jsx(vr,{children:hO.map(n=>c.jsx(Mn,{value:n.value,className:"text-xs",children:n.label},n.value))})]})}const ud={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"},gO=1e5;function xO({scope:e,setScope:t,docSize:n}){return c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Scope"}),c.jsx("div",{className:"flex items-center bg-muted/40 rounded-md p-0.5 gap-px",children:Object.keys(ud).map(r=>c.jsxs(Ye,{children:[c.jsx(Xe,{asChild:!0,children:c.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})}),c.jsx(Qe,{side:"top",className:"text-xs max-w-[200px]",children:ud[r]})]},r))})]}),e==="global"&&n>gO&&c.jsxs("div",{className:"text-[10px] text-warning flex items-center gap-1",children:[c.jsx(sf,{className:"h-3 w-3 shrink-0"}),c.jsxs("span",{children:["Large doc — switch to"," ",c.jsx("button",{type:"button",onClick:()=>t("slides"),className:"underline cursor-pointer hover:text-warning/80",children:"slides"})," ","or"," ",c.jsx("button",{type:"button",onClick:()=>t("templates"),className:"underline cursor-pointer hover:text-warning/80",children:"templates"})]})]})]})}function yO({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 c.jsx("button",{onClick:r,className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:t?"Copied!":"Copy"})}function bO({discoveryData:e}){const t=Vf(),n=ib(),r=De(N=>N.chatOpen),i=De(N=>N.toggleChat),[s,o]=x.useState(()=>{try{const N=localStorage.getItem("dev-env.sidebar-open");return n?!1:N?N==="true":!0}catch{return!n}}),[a,l]=x.useState(()=>{try{const N=localStorage.getItem("dev-env.preview-open");return N?N==="true":!0}catch{return!0}}),[u,d]=x.useState("editor"),[f,h]=x.useState(!1),p=150,[g,k]=x.useState(!s),[S,y]=x.useState(!1);x.useEffect(()=>{try{localStorage.setItem("dev-env.sidebar-open",String(s))}catch{}},[s]),x.useEffect(()=>{try{localStorage.setItem("dev-env.preview-open",String(a))}catch{}},[a]);const j=x.useRef(n);x.useEffect(()=>{n&&!j.current&&s&&(y(!0),o(!1),setTimeout(()=>{k(!0),y(!1)},p)),!n&&j.current&&!s&&(y(!0),o(!0),setTimeout(()=>{k(!1),y(!1)},p)),j.current=n},[n,s]);const m=x.useCallback(()=>{if(t){h(N=>!N);return}y(!0),o(N=>!N),setTimeout(()=>{k(N=>!N),y(!1)},p)},[t]),A=x.useCallback(()=>l(N=>!N),[]),C=x.useRef(i),v=x.useRef(m),w=x.useRef(A);x.useEffect(()=>{C.current=i}),x.useEffect(()=>{v.current=m}),x.useEffect(()=>{w.current=A}),x.useEffect(()=>{const N=R=>{(R.metaKey||R.ctrlKey)&&(R.code==="KeyB"&&!R.shiftKey&&(R.preventDefault(),v.current()),R.code==="KeyJ"&&R.shiftKey&&(R.preventDefault(),R.stopPropagation(),C.current()),R.code==="KeyP"&&R.shiftKey&&(R.preventDefault(),w.current()))};return window.addEventListener("keydown",N,!0),()=>window.removeEventListener("keydown",N,!0)},[]);const O=$z,B=[{key:"editor",icon:Fo,label:"Editor"},{key:"preview",icon:of,label:"Preview"},{key:"chat",icon:af,label:"Chat"}];return t?c.jsx(O,{children:c.jsxs("div",{className:"flex flex-col h-full w-full overflow-hidden",children:[c.jsxs("div",{className:"flex items-center gap-1 px-2 py-1.5 border-b bg-sidebar shrink-0",children:[c.jsxs(Ff,{open:f,onOpenChange:h,children:[c.jsx(Qy,{asChild:!0,children:c.jsx(Ee,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0",children:c.jsx(rf,{className:"h-4 w-4"})})}),c.jsx(Ma,{side:"left",className:"p-0 w-72",children:c.jsx(Gl,{discoveryData:e,onToggleSidebar:()=>h(!1),isCollapsed:!1})})]}),c.jsx("div",{className:"flex gap-0.5 flex-1 min-w-0",children:B.map(({key:N,icon:R,label:T})=>c.jsxs(Ee,{variant:u===N?"default":"ghost",size:"sm",className:"h-7 gap-1.5 text-xs flex-1",onClick:()=>d(N),children:[c.jsx(R,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden xs:inline",children:T})]},N))})]}),u!=="chat"&&c.jsx(bc,{previewOpen:a,onTogglePreview:A}),c.jsxs("div",{className:"flex-1 min-h-0",children:[u==="editor"&&c.jsx("div",{className:"h-full bg-surface-editor",children:c.jsx(Kl,{})}),u==="preview"&&c.jsx("div",{className:"h-full bg-surface-preview",children:c.jsx(Yl,{})}),u==="chat"&&c.jsx(cd,{})]})]})}):c.jsx(O,{children:c.jsxs("div",{className:"flex h-full w-full overflow-hidden",children:[c.jsx("div",{className:W("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:c.jsx(Gl,{discoveryData:e,onToggleSidebar:m,isCollapsed:g,isAnimating:S})}),c.jsxs("div",{className:"flex-1 min-w-0 flex flex-col h-full",children:[c.jsx(bc,{previewOpen:a,onTogglePreview:A}),c.jsxs(Lv,{direction:"horizontal",autoSaveId:"layout-main",className:"flex-1 min-h-0",children:[c.jsx(co,{defaultSize:a?50:100,minSize:20,id:"editor",order:1,children:c.jsx("div",{className:"h-full bg-surface-editor",children:c.jsx(Kl,{})})}),a&&c.jsxs(c.Fragment,{children:[c.jsx(ac,{withHandle:!0}),c.jsx(co,{defaultSize:50,minSize:20,id:"preview",order:2,children:c.jsx("div",{className:"h-full bg-surface-preview",children:c.jsx(Yl,{})})})]}),r&&c.jsxs(c.Fragment,{children:[c.jsx(ac,{withHandle:!0}),c.jsx(co,{defaultSize:30,minSize:25,maxSize:50,id:"chat",order:3,children:c.jsx(cd,{})})]})]})]})]})})}function vO(){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({pluginAutoload:!0,...l.data})}catch(a){console.error("Discovery error:",a),s(a instanceof Error?a.message:"Failed to fetch discovered items"),t({plugins:[],documents:[],themes:[],pluginAutoload:!0})}finally{r(!1)}},[]);return x.useEffect(()=>{o()},[o]),{data:e,loading:n,error:i,refetch:o}}function wO(){const{data:e,loading:t,error:n}=vO(),r=Jt(s=>s.applyPluginsWithValidation),i=x.useMemo(()=>(e==null?void 0:e.plugins.map(s=>s.name))??[],[e]);return x.useEffect(()=>{if(!e)return;Jt.getState().selectedPlugins.size>0&&r()},[e,r]),t?c.jsx("div",{className:"flex items-center justify-center h-screen",children:c.jsxs("div",{className:"text-center",children:[c.jsx("div",{className:"text-lg font-medium",children:"Discovering project resources..."}),c.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:"Searching for documents, themes, and plugins"})]})}):n?c.jsx("div",{className:"flex items-center justify-center h-screen",children:c.jsxs("div",{className:"text-center",children:[c.jsx("div",{className:"text-lg font-medium text-destructive",children:"Discovery failed"}),c.jsx("div",{className:"text-sm text-muted-foreground mt-2",children:n}),c.jsx("div",{className:"text-xs text-muted-foreground mt-4",children:"The playground will work with limited functionality."})]})}):c.jsx(Ng,{children:c.jsx(Eg,{children:c.jsx(Cg,{children:c.jsx(Tg,{children:c.jsx(Ig,{children:c.jsx(Ag,{diskPluginNames:i,children:c.jsx(zy,{children:c.jsx(Uf,{children:c.jsx("section",{className:"flex h-screen w-full flex-col",children:c.jsx("div",{className:"grow overflow-hidden",children:c.jsx(bO,{discoveryData:e})})})})})})})})})})})}const zO=Object.freeze(Object.defineProperty({__proto__:null,HomePage:wO},Symbol.toStringTag,{value:"Module"}));export{Gt as A,tn as B,Np as C,Ti as D,Jv as E,zO as H,wr as I,ni as L,rw as P,Zv as Q,fi as S,jp as T,br as a,pi as b,vr as c,Mn as d,hi as e,Ii as f,Ar as g,$a as h,Fn as i,$t as j,Fa as k,oi as l,mr as m,Bo as n,_p as o,si as p,Ob as q,AO as r,gc as s,Xv as t,Wv as u,Ja as v,Mf as w,ct as x,lt as y,qt as z};
251
- //# sourceMappingURL=HomePage-Cq_CI7_t.js.map