streamdown 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -65,6 +65,44 @@ monorepo/
65
65
 
66
66
  Adjust the number of `../` segments based on where your CSS file lives relative to the root `node_modules`. If you install Streamdown plugins, add their respective `@source` entries only when those packages are installed.
67
67
 
68
+ ### CSS Custom Properties (Design Tokens)
69
+
70
+ Streamdown components are built using shadcn/ui's design system and rely on CSS custom properties for colors, border radius, and spacing. Without these variables defined, components may render with missing backgrounds, borders, or incorrect spacing.
71
+
72
+ If you are already using shadcn/ui, these variables are set up automatically. If not, add the following minimal set to your global CSS:
73
+
74
+ ```css
75
+ :root {
76
+ --background: oklch(1 0 0);
77
+ --foreground: oklch(0.145 0 0);
78
+ --card: oklch(1 0 0);
79
+ --card-foreground: oklch(0.145 0 0);
80
+ --muted: oklch(0.97 0 0);
81
+ --muted-foreground: oklch(0.556 0 0);
82
+ --border: oklch(0.922 0 0);
83
+ --input: oklch(0.922 0 0);
84
+ --primary: oklch(0.205 0 0);
85
+ --primary-foreground: oklch(0.985 0 0);
86
+ --radius: 0.625rem;
87
+ }
88
+
89
+ .dark {
90
+ --background: oklch(0.145 0 0);
91
+ --foreground: oklch(0.985 0 0);
92
+ --card: oklch(0.205 0 0);
93
+ --card-foreground: oklch(0.985 0 0);
94
+ --muted: oklch(0.269 0 0);
95
+ --muted-foreground: oklch(0.708 0 0);
96
+ --border: oklch(0.269 0 0);
97
+ --input: oklch(0.269 0 0);
98
+ --primary: oklch(0.985 0 0);
99
+ --primary-foreground: oklch(0.205 0 0);
100
+ --radius: 0.625rem;
101
+ }
102
+ ```
103
+
104
+ You can also use the shadcn/ui [theme generator](https://ui.shadcn.com/themes) to create a custom palette and copy the generated CSS variables directly into your project.
105
+
68
106
  ## Usage
69
107
 
70
108
  Here's how you can use Streamdown in your React application with the AI SDK:
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import {createContext,memo,useContext,useMemo,lazy,isValidElement,useId,useTransition,useRef,useEffect,useState,cloneElement,createElement,useCallback,Suspense}from'react';import {harden}from'rehype-harden';import Yo from'rehype-raw';import kn,{defaultSchema}from'rehype-sanitize';import $s from'remark-gfm';import Ws from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import {urlAttributes}from'html-url-attributes';import gs from'remark-parse';import bs from'remark-rehype';import {unified}from'unified';import {visit}from'unist-util-visit';import {Lexer}from'marked';var Bn=300,An="300px",On=500;function Rt(e={}){let{immediate:t=false,debounceDelay:o=Bn,rootMargin:n=An,idleTimeout:r=On}=e,[s,a]=useState(false),l=useRef(null),i=useRef(null),d=useRef(null),c=useMemo(()=>u=>{let f=Date.now();return window.setTimeout(()=>{u({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-f))});},1)},[]),p=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(u,f)=>window.requestIdleCallback(u,f):c,[c]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?u=>window.cancelIdleCallback(u):u=>{clearTimeout(u);},[]);return useEffect(()=>{if(t){a(true);return}let u=l.current;if(!u)return;i.current&&(clearTimeout(i.current),i.current=null),d.current&&(m(d.current),d.current=null);let f=()=>{i.current&&(clearTimeout(i.current),i.current=null),d.current&&(m(d.current),d.current=null);},h=v=>{d.current=p(w=>{w.timeRemaining()>0||w.didTimeout?(a(true),v.disconnect()):d.current=p(()=>{a(true),v.disconnect();},{timeout:r/2});},{timeout:r});},b=v=>{f(),i.current=window.setTimeout(()=>{var M,H;let w=v.takeRecords();(w.length===0||(H=(M=w.at(-1))==null?void 0:M.isIntersecting)!=null&&H)&&h(v);},o);},g=(v,w)=>{v.isIntersecting?b(w):f();},T=new IntersectionObserver(v=>{for(let w of v)g(w,T);},{rootMargin:n,threshold:0});return T.observe(u),()=>{i.current&&clearTimeout(i.current),d.current&&m(d.current),T.disconnect();}},[t,o,n,r,m,p]),{shouldRender:s,containerRef:l}}var St=/\s/,Fn=/^\s+$/,zn=new Set(["code","pre","svg","math","annotation"]),_n=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",qn=e=>e.some(t=>_n(t)&&zn.has(t.tagName)),$n=e=>{let t=[],o="",n=false;for(let r of e){let s=St.test(r);s!==n&&o&&(t.push(o),o=""),o+=r,n=s;}return o&&t.push(o),t},Wn=e=>{let t=[],o="";for(let n of e)St.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},Zn=(e,t,o,n,r,s)=>{let a=`--sd-animation:sd-${t};--sd-duration:${r?0:o}ms;--sd-easing:${n}`;return s&&(a+=`;--sd-delay:${s}ms`),{type:"element",tagName:"span",properties:{"data-sd-animate":true,style:a},children:[{type:"text",value:e}]}},Xn=(e,t,o,n,r)=>{let s=t.at(-1);if(!(s&&"children"in s))return;if(qn(t))return SKIP;let a=s,l=a.children.indexOf(e);if(l===-1)return;let i=e.value;if(!i.trim()){r.count+=i.length;return}let d=o.sep==="char"?Wn(i):$n(i),c=n.prevContentLength,p=d.map(m=>{let u=r.count;if(r.count+=m.length,Fn.test(m))return {type:"text",value:m};let f=c>0&&u<c,h=f?0:r.newIndex++*o.stagger;return Zn(m,o.animation,o.duration,o.easing,f,h)});return a.children.splice(l,1,...p),l+p.length},Jn=0;function be(e){var s,a,l,i,d;let t={animation:(s=e==null?void 0:e.animation)!=null?s:"fadeIn",duration:(a=e==null?void 0:e.duration)!=null?a:150,easing:(l=e==null?void 0:e.easing)!=null?l:"ease",sep:(i=e==null?void 0:e.sep)!=null?i:"word",stagger:(d=e==null?void 0:e.stagger)!=null?d:40},o={prevContentLength:0,lastRenderCharCount:0},n=Jn++,r=()=>c=>{let p={count:0,newIndex:0};visitParents(c,"text",(m,u)=>Xn(m,u,t,o,p)),o.lastRenderCharCount=p.count,o.prevContentLength=0;};return Object.defineProperty(r,"name",{value:`rehypeAnimate$${n}`}),{name:"animate",type:"animate",rehypePlugin:r,setPrevContentLength(c){o.prevContentLength=c;},getLastRenderCharCount(){let c=o.lastRenderCharCount;return o.lastRenderCharCount=0,c}}}be();var et=createContext(false),tt=()=>useContext(et);var he=(...e)=>twMerge(clsx(e)),Gn=(e,t)=>{if(!e||!t)return t;let o=`${e}:`;return t.split(/\s+/).filter(Boolean).map(n=>n.startsWith(o)?n:`${e}:${n}`).join(" ")},Dt=e=>e?(...t)=>Gn(e,twMerge(clsx(t))):he,W=(e,t,o)=>{let n=typeof t=="string"&&o.startsWith("text/csv")?"\uFEFF":"",r=typeof t=="string"?new Blob([n+t],{type:o}):t,s=URL.createObjectURL(r),a=document.createElement("a");a.href=s,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s);};var Ee=createContext(he),y=()=>useContext(Ee);var tr=he("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),or=e=>{let t={};for(let o of e.split(";")){let n=o.indexOf(":");if(n>0){let r=o.slice(0,n).trim(),s=o.slice(n+1).trim();r&&s&&(t[r]=s);}}return t},At=memo(({children:e,result:t,language:o,className:n,startLine:r,lineNumbers:s=true,...a})=>{let l=y(),i=useMemo(()=>l(tr),[l]),d=useMemo(()=>{let c={};return t.bg&&(c["--sdm-bg"]=t.bg),t.fg&&(c["--sdm-fg"]=t.fg),t.rootStyle&&Object.assign(c,or(t.rootStyle)),c},[t.bg,t.fg,t.rootStyle]);return jsx("div",{className:l(n,"overflow-x-auto rounded-md border border-border bg-background p-4 text-sm"),"data-language":o,"data-streamdown":"code-block-body",...a,children:jsx("pre",{className:l(n,"bg-[var(--sdm-bg,inherit]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]"),style:d,children:jsx("code",{className:s?l("[counter-increment:line_0] [counter-reset:line]"):void 0,style:s&&r&&r>1?{counterReset:`line ${r-1}`}:void 0,children:t.tokens.map((c,p)=>jsx("span",{className:s?i:void 0,children:c.length===0||c.length===1&&c[0].content===""?`
3
+ `:c.map((m,u)=>{let f={},h=!!m.bgColor;if(m.color&&(f["--sdm-c"]=m.color),m.bgColor&&(f["--sdm-tbg"]=m.bgColor),m.htmlStyle)for(let[b,g]of Object.entries(m.htmlStyle))b==="color"?f["--sdm-c"]=g:b==="background-color"?(f["--sdm-tbg"]=g,h=true):f[b]=g;return jsx("span",{className:l("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",h&&"bg-[var(--sdm-tbg)]",h&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:f,...m.htmlAttrs,children:m.content},u)})},p))})})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className&&e.startLine===t.startLine&&e.lineNumbers===t.lineNumbers);var ot=({className:e,language:t,style:o,isIncomplete:n,...r})=>{let s=y();return jsx("div",{className:s("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",e),"data-incomplete":n||void 0,"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...r})};var nt=createContext({code:""}),He=()=>useContext(nt);var rt=({language:e})=>{let t=y();return jsx("div",{className:t("flex h-8 items-center text-muted-foreground text-xs"),"data-language":e,"data-streamdown":"code-block-header",children:jsx("span",{className:t("ml-1 font-mono lowercase"),children:e})})};var lr=e=>{let t=e.length;for(;t>0&&e[t-1]===`
4
+ `;)t--;return e.slice(0,t)},cr=lazy(()=>import('./highlighted-body-OFNGDK62.js').then(e=>({default:e.HighlightedCodeBlockBody}))),st=({code:e,language:t,className:o,children:n,isIncomplete:r=false,startLine:s,lineNumbers:a,...l})=>{let i=y(),d=useMemo(()=>lr(e),[e]),c=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:d.split(`
5
+ `).map(p=>[{content:p,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[d]);return jsx(nt.Provider,{value:{code:e},children:jsxs(ot,{isIncomplete:r,language:t,children:[jsx(rt,{language:t}),n?jsx("div",{className:i("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:jsx("div",{className:i("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"code-block-actions",children:n})}):null,jsx(Suspense,{fallback:jsx(At,{className:o,language:t,lineNumbers:a,result:c,startLine:s,...l}),children:jsx(cr,{className:o,code:d,language:t,lineNumbers:a,raw:c,startLine:s,...l})})]})})};var jt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),Ft=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),zt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),_t=e=>jsxs("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),qt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),$t=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),Wt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),Zt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",fill:"currentColor",fillRule:"evenodd"})}),Xt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),Jt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})});var we={CheckIcon:jt,CopyIcon:Ft,DownloadIcon:zt,ExternalLinkIcon:Zt,Loader2Icon:_t,Maximize2Icon:qt,RotateCcwIcon:$t,XIcon:Wt,ZoomInIcon:Xt,ZoomOutIcon:Jt},Ut=createContext(we),fr=(e,t)=>{if(e===t)return true;if(!(e&&t))return e===t;let o=Object.keys(e),n=Object.keys(t);return o.length!==n.length?false:o.every(r=>e[r]===t[r])},at=({icons:e,children:t})=>{let o=useRef(e),n=useRef(e?{...we,...e}:we);fr(o.current,e)||(o.current=e,n.current=e?{...we,...e}:we);let r=n.current;return jsx(Ut.Provider,{value:r,children:t})},L=()=>useContext(Ut);var De={copyCode:"Copy Code",downloadFile:"Download file",downloadDiagram:"Download diagram",downloadDiagramAsSvg:"Download diagram as SVG",downloadDiagramAsPng:"Download diagram as PNG",downloadDiagramAsMmd:"Download diagram as MMD",viewFullscreen:"View fullscreen",exitFullscreen:"Exit fullscreen",mermaidFormatSvg:"SVG",mermaidFormatPng:"PNG",mermaidFormatMmd:"MMD",copyTable:"Copy table",copyTableAsMarkdown:"Copy table as Markdown",copyTableAsCsv:"Copy table as CSV",copyTableAsTsv:"Copy table as TSV",downloadTable:"Download table",downloadTableAsCsv:"Download table as CSV",downloadTableAsMarkdown:"Download table as Markdown",tableFormatMarkdown:"Markdown",tableFormatCsv:"CSV",tableFormatTsv:"TSV",imageNotAvailable:"Image not available",downloadImage:"Download image",openExternalLink:"Open external link?",externalLinkWarning:"You're about to visit an external website.",close:"Close",copyLink:"Copy link",copied:"Copied",openLink:"Open link"},Be=createContext(De),D=()=>useContext(Be);var Ae=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...a})=>{let l=y(),[i,d]=useState(false),c=useRef(0),{code:p}=He(),{isAnimating:m}=useContext(R),u=D(),f=s!=null?s:p,h=async()=>{var T;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(f),d(!0),e==null||e(),c.current=window.setTimeout(()=>d(!1),o));}catch(v){t==null||t(v);}};useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let b=L(),g=i?b.CheckIcon:b.CopyIcon;return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-copy-button",disabled:m,onClick:h,title:u.copyCode,type:"button",...a,children:n!=null?n:jsx(g,{size:14})})};var Yt={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},it=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...a})=>{let l=y(),{code:i}=He(),{isAnimating:d}=useContext(R),c=D(),p=L(),m=s!=null?s:i,f=`file.${o&&o in Yt?Yt[o]:"txt"}`,h="text/plain",b=()=>{try{W(f,m,h),e==null||e();}catch(g){t==null||t(g);}};return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-download-button",disabled:d,onClick:b,title:c.downloadFile,type:"button",...a,children:n!=null?n:jsx(p.DownloadIcon,{size:14})})};var Oe=()=>{let{Loader2Icon:e}=L(),t=y();return jsxs("div",{className:t("w-full divide-y divide-border overflow-hidden rounded-xl border border-border"),children:[jsx("div",{className:t("h-[46px] w-full bg-muted/80")}),jsx("div",{className:t("flex w-full items-center justify-center p-4"),children:jsx(e,{className:t("size-4 animate-spin")})})]})};var Mr=/\.[^/.]+$/,oo=({node:e,className:t,src:o,alt:n,onLoad:r,onError:s,...a})=>{let{DownloadIcon:l}=L(),i=y(),d=useRef(null),[c,p]=useState(false),[m,u]=useState(false),f=D(),h=a.width!=null||a.height!=null,b=(c||h)&&!m,g=m&&!h;useEffect(()=>{let P=d.current;if(P!=null&&P.complete){let M=P.naturalWidth>0;p(M),u(!M);}},[]);let T=useCallback(P=>{p(true),u(false),r==null||r(P);},[r]),v=useCallback(P=>{p(false),u(true),s==null||s(P);},[s]),w=async()=>{if(o)try{let M=await(await fetch(o)).blob(),S=new URL(o,window.location.origin).pathname.split("/").pop()||"",F=S.split(".").pop(),j=S.includes(".")&&F!==void 0&&F.length<=4,z="";if(j)z=S;else {let B=M.type,_="png";B.includes("jpeg")||B.includes("jpg")?_="jpg":B.includes("png")?_="png":B.includes("svg")?_="svg":B.includes("gif")?_="gif":B.includes("webp")&&(_="webp"),z=`${(n||S||"image").replace(Mr,"")}.${_}`;}W(z,M,M.type);}catch(P){window.open(o,"_blank");}};return o?jsxs("div",{className:i("group relative my-4 inline-block"),"data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:i("max-w-full rounded-lg",g&&"hidden",t),"data-streamdown":"image",onError:v,onLoad:T,ref:d,src:o,...a}),g&&jsx("span",{className:i("text-muted-foreground text-xs italic"),"data-streamdown":"image-fallback",children:f.imageNotAvailable}),jsx("div",{className:i("pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block")}),b&&jsx("button",{className:i("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:w,title:f.downloadImage,type:"button",children:jsx(l,{size:14})})]}):null};var ke=0,le=()=>{ke+=1,ke===1&&(document.body.style.overflow="hidden");},ce=()=>{ke=Math.max(0,ke-1),ke===0&&(document.body.style.overflow="");};var so=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let{CheckIcon:r,CopyIcon:s,ExternalLinkIcon:a,XIcon:l}=L(),i=y(),[d,c]=useState(false),p=D(),m=useCallback(async()=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3);}catch(f){}},[e]),u=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){le();let f=h=>{h.key==="Escape"&&o();};return document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f),ce();}}},[t,o]),t?jsx("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm"),"data-streamdown":"link-safety-modal",onClick:o,onKeyDown:f=>{f.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:i("relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg"),onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),role:"presentation",children:[jsx("button",{className:i("absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:o,title:p.close,type:"button",children:jsx(l,{size:16})}),jsxs("div",{className:i("flex flex-col gap-2"),children:[jsxs("div",{className:i("flex items-center gap-2 font-semibold text-lg"),children:[jsx(a,{size:20}),jsx("span",{children:p.openExternalLink})]}),jsx("p",{className:i("text-muted-foreground text-sm"),children:p.externalLinkWarning})]}),jsx("div",{className:i("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxs("div",{className:i("flex gap-2"),children:[jsx("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted"),onClick:m,type:"button",children:d?jsxs(Fragment,{children:[jsx(r,{size:14}),jsx("span",{children:p.copied})]}):jsxs(Fragment,{children:[jsx(s,{size:14}),jsx("span",{children:p.copyLink})]})}),jsxs("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90"),onClick:u,type:"button",children:[jsx(a,{size:14}),jsx("span",{children:p.openLink})]})]})]})}):null};var Ve=createContext(null),ct=()=>useContext(Ve),Li=()=>{var t;let e=ct();return (t=e==null?void 0:e.code)!=null?t:null},de=()=>{var t;let e=ct();return (t=e==null?void 0:e.mermaid)!=null?t:null};var ao=e=>{var o;let t=ct();return t!=null&&t.renderers&&e&&(o=t.renderers.find(n=>Array.isArray(n.language)?n.language.includes(e):n.language===e))!=null?o:null};var io=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((r,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),l=new Image;l.crossOrigin="anonymous",l.onload=()=>{let i=document.createElement("canvas"),d=l.width*o,c=l.height*o;i.width=d,i.height=c;let p=i.getContext("2d");if(!p){s(new Error("Failed to create 2D canvas context for PNG export"));return}p.drawImage(l,0,0,d,c),i.toBlob(m=>{if(!m){s(new Error("Failed to create PNG blob"));return}r(m);},"image/png");},l.onerror=()=>s(new Error("Failed to load SVG image")),l.src=a;})};var co=({chart:e,children:t,className:o,onDownload:n,config:r,onError:s})=>{let a=y(),[l,i]=useState(false),d=useRef(null),{isAnimating:c}=useContext(R),p=L(),m=de(),u=D(),f=async h=>{try{if(h==="mmd"){W("diagram.mmd",e,"text/plain"),i(!1),n==null||n(h);return}if(!m){s==null||s(new Error("Mermaid plugin not available"));return}let b=m.getMermaid(r),g=e.split("").reduce((w,P)=>(w<<5)-w+P.charCodeAt(0)|0,0),T=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:v}=await b.render(T,e);if(!v){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(h==="svg"){W("diagram.svg",v,"image/svg+xml"),i(!1),n==null||n(h);return}if(h==="png"){let w=await io(v);W("diagram.png",w,"image/png"),n==null||n(h),i(!1);return}}catch(b){s==null||s(b);}};return useEffect(()=>{let h=b=>{let g=b.composedPath();d.current&&!g.includes(d.current)&&i(false);};return document.addEventListener("mousedown",h),()=>{document.removeEventListener("mousedown",h);}},[]),jsxs("div",{className:a("relative"),ref:d,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:c,onClick:()=>i(!l),title:u.downloadDiagram,type:"button",children:t!=null?t:jsx(p.DownloadIcon,{size:14})}),l?jsxs("div",{className:a("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("svg"),title:u.downloadDiagramAsSvg,type:"button",children:u.mermaidFormatSvg}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("png"),title:u.downloadDiagramAsPng,type:"button",children:u.mermaidFormatPng}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("mmd"),title:u.downloadDiagramAsMmd,type:"button",children:u.mermaidFormatMmd})]}):null]})};var fo=({chart:e,config:t,onFullscreen:o,onExit:n,className:r,...s})=>{let{Maximize2Icon:a,XIcon:l}=L(),i=y(),[d,c]=useState(false),{isAnimating:p,controls:m}=useContext(R),u=D(),f=(()=>{if(typeof m=="boolean")return m;let b=m.mermaid;return b===false?false:b===true||b===void 0?true:b.panZoom!==false})(),h=()=>{c(!d);};return useEffect(()=>{if(d){le();let b=g=>{g.key==="Escape"&&c(false);};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b),ce();}}},[d]),useEffect(()=>{d?o==null||o():n&&n();},[d,o,n]),jsxs(Fragment,{children:[jsx("button",{className:i("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:p,onClick:h,title:u.viewFullscreen,type:"button",...s,children:jsx(a,{size:14})}),d?createPortal(jsxs("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"),onClick:h,onKeyDown:b=>{b.key==="Escape"&&h();},role:"button",tabIndex:0,children:[jsx("button",{className:i("absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:h,title:u.exitFullscreen,type:"button",children:jsx(l,{size:20})}),jsx("div",{className:i("flex size-full items-center justify-center p-4"),onClick:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),role:"presentation",children:jsx(po,{chart:e,className:i("size-full [&_svg]:h-auto [&_svg]:w-auto"),config:t,fullscreen:true,showControls:f})})]}),document.body):null]})};var ue=e=>{var s,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let l of n)t.push(((s=l.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let l of r){let i=[],d=l.querySelectorAll("td");for(let c of d)i.push(((a=c.textContent)==null?void 0:a.trim())||"");o.push(i);}return {headers:t,rows:o}},ne=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false,d=false;for(let c of l){if(c==='"'){i=true,d=true;break}(c===","||c===`
6
+ `)&&(i=true);}return i?d?`"${l.replace(/"/g,'""')}"`:`"${l}"`:l},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(","),a+=1);for(let l of o)s[a]=l.map(n).join(","),a+=1;return s.join(`
7
+ `)},dt=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false;for(let c of l)if(c===" "||c===`
8
+ `||c==="\r"){i=true;break}if(!i)return l;let d=[];for(let c of l)c===" "?d.push("\\t"):c===`
9
+ `?d.push("\\n"):c==="\r"?d.push("\\r"):d.push(c);return d.join("")},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(" "),a+=1);for(let l of o)s[a]=l.map(n).join(" "),a+=1;return s.join(`
10
+ `)},je=e=>{let t=false;for(let n of e)if(n==="\\"||n==="|"){t=true;break}if(!t)return e;let o=[];for(let n of e)n==="\\"?o.push("\\\\"):n==="|"?o.push("\\|"):o.push(n);return o.join("")},re=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),r=0,s=t.map(l=>je(l));n[r]=`| ${s.join(" | ")} |`,r+=1;let a=new Array(t.length);for(let l=0;l<t.length;l+=1)a[l]="---";n[r]=`| ${a.join(" | ")} |`,r+=1;for(let l of o)if(l.length<t.length){let i=new Array(t.length);for(let d=0;d<t.length;d+=1)i[d]=d<l.length?je(l[d]):"";n[r]=`| ${i.join(" | ")} |`,r+=1;}else {let i=l.map(d=>je(d));n[r]=`| ${i.join(" | ")} |`,r+=1;}return n.join(`
11
+ `)};var Te=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3})=>{let s=y(),[a,l]=useState(false),[i,d]=useState(false),c=useRef(null),p=useRef(0),{isAnimating:m}=useContext(R),u=D(),f=async g=>{var T,v;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.write)){n==null||n(new Error("Clipboard API not available"));return}try{let w=(v=c.current)==null?void 0:v.closest('[data-streamdown="table-wrapper"]'),P=w==null?void 0:w.querySelector("table");if(!P){n==null||n(new Error("Table not found"));return}let M=ue(P),F=({csv:ne,tsv:dt,md:re}[g]||re)(M),j=new ClipboardItem({"text/plain":new Blob([F],{type:"text/plain"}),"text/html":new Blob([P.outerHTML],{type:"text/html"})});await navigator.clipboard.write([j]),d(!0),l(!1),o==null||o(g),p.current=window.setTimeout(()=>d(!1),r);}catch(w){n==null||n(w);}};useEffect(()=>{let g=T=>{let v=T.composedPath();c.current&&!v.includes(c.current)&&l(false);};return document.addEventListener("mousedown",g),()=>{document.removeEventListener("mousedown",g),window.clearTimeout(p.current);}},[]);let h=L(),b=i?h.CheckIcon:h.CopyIcon;return jsxs("div",{className:s("relative"),ref:c,children:[jsx("button",{className:s("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!a),title:u.copyTable,type:"button",children:e!=null?e:jsx(b,{height:14,width:14})}),a?jsxs("div",{className:s("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("md"),title:u.copyTableAsMarkdown,type:"button",children:u.tableFormatMarkdown}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("csv"),title:u.copyTableAsCsv,type:"button",children:u.tableFormatCsv}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("tsv"),title:u.copyTableAsTsv,type:"button",children:u.tableFormatTsv})]}):null]})};var Wr=({children:e,className:t,onDownload:o,onError:n,format:r="csv",filename:s})=>{let a=y(),{isAnimating:l}=useContext(R),i=D(),d=L(),c=p=>{try{let u=p.currentTarget.closest('[data-streamdown="table-wrapper"]'),f=u==null?void 0:u.querySelector("table");if(!f){n==null||n(new Error("Table not found"));return}let h=ue(f),b="",g="",T="";switch(r){case "csv":b=ne(h),g="text/csv",T="csv";break;case "markdown":b=re(h),g="text/markdown",T="md";break;default:b=ne(h),g="text/csv",T="csv";}W(`${s||"table"}.${T}`,b,g),o==null||o();}catch(m){n==null||n(m);}};return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:c,title:r==="csv"?i.downloadTableAsCsv:i.downloadTableAsMarkdown,type:"button",children:e!=null?e:jsx(d.DownloadIcon,{size:14})})},Pe=({children:e,className:t,onDownload:o,onError:n})=>{let r=y(),[s,a]=useState(false),l=useRef(null),{isAnimating:i}=useContext(R),d=D(),c=L(),p=m=>{var u;try{let f=(u=l.current)==null?void 0:u.closest('[data-streamdown="table-wrapper"]'),h=f==null?void 0:f.querySelector("table");if(!h){n==null||n(new Error("Table not found"));return}let b=ue(h),g=m==="csv"?ne(b):re(b);W(`table.${m==="csv"?"csv":"md"}`,g,m==="csv"?"text/csv":"text/markdown"),a(!1),o==null||o(m);}catch(f){n==null||n(f);}};return useEffect(()=>{let m=u=>{let f=u.composedPath();l.current&&!f.includes(l.current)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:r("relative"),ref:l,children:[jsx("button",{className:r("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>a(!s),title:d.downloadTable,type:"button",children:e!=null?e:jsx(c.DownloadIcon,{size:14})}),s?jsxs("div",{className:r("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>p("csv"),title:d.downloadTableAsCsv,type:"button",children:d.tableFormatCsv}),jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>p("markdown"),title:d.downloadTableAsMarkdown,type:"button",children:d.tableFormatMarkdown})]}):null]})};var Co=({children:e,className:t,showCopy:o=true,showDownload:n=true})=>{let{Maximize2Icon:r,XIcon:s}=L(),a=y(),[l,i]=useState(false),{isAnimating:d}=useContext(R),c=D(),p=()=>{i(true);},m=()=>{i(false);};return useEffect(()=>{if(l){le();let u=f=>{f.key==="Escape"&&i(false);};return document.addEventListener("keydown",u),()=>{document.removeEventListener("keydown",u),ce();}}},[l]),jsxs(Fragment,{children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:p,title:c.viewFullscreen,type:"button",children:jsx(r,{size:14})}),l?createPortal(jsx("div",{"aria-label":c.viewFullscreen,"aria-modal":"true",className:a("fixed inset-0 z-50 flex flex-col bg-background"),"data-streamdown":"table-fullscreen",onClick:m,onKeyDown:u=>{u.key==="Escape"&&m();},role:"dialog",children:jsxs("div",{className:a("flex h-full flex-col"),onClick:u=>u.stopPropagation(),onKeyDown:u=>u.stopPropagation(),role:"presentation",children:[jsxs("div",{className:a("flex items-center justify-end gap-1 p-4"),children:[o?jsx(Te,{}):null,n?jsx(Pe,{}):null,jsx("button",{className:a("rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:m,title:c.exitFullscreen,type:"button",children:jsx(s,{size:20})})]}),jsx("div",{className:a("flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10"),children:jsx("table",{className:a("w-full border-collapse border border-border"),"data-streamdown":"table",children:e})})]})}),document.body):null]})};var vo=({children:e,className:t,showControls:o,showCopy:n=true,showDownload:r=true,showFullscreen:s=true,...a})=>{let l=y(),i=o&&n,d=o&&r,c=o&&s,p=i||d||c;return jsxs("div",{className:l("my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2"),"data-streamdown":"table-wrapper",children:[p?jsxs("div",{className:l("flex items-center justify-end gap-1"),children:[i?jsx(Te,{}):null,d?jsx(Pe,{}):null,c?jsx(Co,{showCopy:i,showDownload:d,children:e}):null]}):null,jsx("div",{className:l("border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background"),children:jsx("table",{className:l("w-full divide-y divide-border",t),"data-streamdown":"table",...a,children:e})})]})};var es=/startLine=(\d+)/,ts=/\bnoLineNumbers\b/,os=lazy(()=>import('./mermaid-GHXKKRXX.js').then(e=>({default:e.Mermaid}))),ns=/language-([^\s]+)/;function qe(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let o=e.position.start,n=t.position.start,r=e.position.end,s=t.position.end;return (o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(r==null?void 0:r.line)===(s==null?void 0:s.line)&&(r==null?void 0:r.column)===(s==null?void 0:s.column)}function E(e,t){return e.className===t.className&&qe(e.node,t.node)}var ft=(e,t)=>typeof e=="boolean"?e:e[t]!==false,pt=(e,t)=>{if(typeof e=="boolean")return e;let o=e.table;return o===false?false:o===true||o===void 0?true:o[t]!==false},To=(e,t)=>{if(typeof e=="boolean")return e;let o=e.code;return o===false?false:o===true||o===void 0?true:o[t]!==false},Fe=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===false?false:o===true||o===void 0?true:o[t]!==false},bt=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("ol",{className:r("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e})},(e,t)=>E(e,t));bt.displayName="MarkdownOl";var Po=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("li",{className:r("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e})},(e,t)=>e.className===t.className&&qe(e.node,t.node));Po.displayName="MarkdownLi";var Mo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("ul",{className:r("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e})},(e,t)=>E(e,t));Mo.displayName="MarkdownUl";var Io=memo(({className:e,node:t,...o})=>{let n=y();return jsx("hr",{className:n("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o})},(e,t)=>E(e,t));Io.displayName="MarkdownHr";var No=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("span",{className:r("font-semibold",t),"data-streamdown":"strong",...n,children:e})},(e,t)=>E(e,t));No.displayName="MarkdownStrong";var rs=({children:e,className:t,href:o,node:n,...r})=>{let s=y(),{linkSafety:a}=useContext(R),[l,i]=useState(false),d=o==="streamdown:incomplete-link",c=useCallback(async f=>{if(!(!(a!=null&&a.enabled&&o)||d)){if(f.preventDefault(),a.onLinkCheck&&await a.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}i(true);}},[a,o,d]),p=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),m=useCallback(()=>{i(false);},[]),u={url:o!=null?o:"",isOpen:l,onClose:m,onConfirm:p};return a!=null&&a.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:s("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":d,"data-streamdown":"link",onClick:c,type:"button",children:e}),a.renderModal?a.renderModal(u):jsx(so,{...u})]}):jsx("a",{className:s("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":d,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...r,children:e})},Lo=memo(rs,(e,t)=>E(e,t)&&e.href===t.href);Lo.displayName="MarkdownA";var Ro=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h1",{className:r("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e})},(e,t)=>E(e,t));Ro.displayName="MarkdownH1";var So=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h2",{className:r("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e})},(e,t)=>E(e,t));So.displayName="MarkdownH2";var Eo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h3",{className:r("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e})},(e,t)=>E(e,t));Eo.displayName="MarkdownH3";var Ho=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h4",{className:r("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e})},(e,t)=>E(e,t));Ho.displayName="MarkdownH4";var Do=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h5",{className:r("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e})},(e,t)=>E(e,t));Do.displayName="MarkdownH5";var Bo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h6",{className:r("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e})},(e,t)=>E(e,t));Bo.displayName="MarkdownH6";var Ao=memo(({children:e,className:t,node:o,...n})=>{let{controls:r}=useContext(R),s=ft(r,"table"),a=pt(r,"copy"),l=pt(r,"download"),i=pt(r,"fullscreen");return jsx(vo,{className:t,showControls:s,showCopy:a,showDownload:l,showFullscreen:i,...n,children:e})},(e,t)=>E(e,t));Ao.displayName="MarkdownTable";var Oo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("thead",{className:r("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e})},(e,t)=>E(e,t));Oo.displayName="MarkdownThead";var Vo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("tbody",{className:r("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e})},(e,t)=>E(e,t));Vo.displayName="MarkdownTbody";var jo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("tr",{className:r("border-border",t),"data-streamdown":"table-row",...n,children:e})},(e,t)=>E(e,t));jo.displayName="MarkdownTr";var Fo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("th",{className:r("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e})},(e,t)=>E(e,t));Fo.displayName="MarkdownTh";var zo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("td",{className:r("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e})},(e,t)=>E(e,t));zo.displayName="MarkdownTd";var _o=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("blockquote",{className:r("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e})},(e,t)=>E(e,t));_o.displayName="MarkdownBlockquote";var qo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("sup",{className:r("text-sm",t),"data-streamdown":"superscript",...n,children:e})},(e,t)=>E(e,t));qo.displayName="MarkdownSup";var $o=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("sub",{className:r("text-sm",t),"data-streamdown":"subscript",...n,children:e})},(e,t)=>E(e,t));$o.displayName="MarkdownSub";var Wo=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=i=>{var m,u;if(!isValidElement(i))return false;let d=Array.isArray(i.props.children)?i.props.children:[i.props.children],c=false,p=false;for(let f of d)if(f){if(typeof f=="string")f.trim()!==""&&(c=true);else if(isValidElement(f))if(((m=f.props)==null?void 0:m["data-footnote-backref"])!==void 0)p=true;else {let h=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let b of h){if(typeof b=="string"&&b.trim()!==""){c=true;break}if(isValidElement(b)&&((u=b.props)==null?void 0:u["data-footnote-backref"])===void 0){c=true;break}}}}return p&&!c},a=Array.isArray(e)?e.map(i=>{if(!isValidElement(i))return i;if(i.type===bt){let c=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(p=>!s(p));return c.length===0?null:{...i,props:{...i.props,children:c}}}return i}):e;return (Array.isArray(a)?a.some(i=>i!==null):a!==null)?jsx("section",{className:t,...n,children:a}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>E(e,t));Wo.displayName="MarkdownSection";var ss=({node:e,className:t,children:o,...n})=>{var S,F;let r=y(),s=!("data-block"in n),{mermaid:a,controls:l,lineNumbers:i}=useContext(R),d=de(),c=tt(),p=t==null?void 0:t.match(ns),m=(S=p==null?void 0:p.at(1))!=null?S:"",u=ao(m);if(s)return jsx("code",{className:r("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let f=(F=e==null?void 0:e.properties)==null?void 0:F.metastring,h=f==null?void 0:f.match(es),b=h?Number.parseInt(h[1],10):void 0,g=b!==void 0&&b>=1?b:void 0,v=!(f?ts.test(f):false)&&i!==false,w="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?w=o.props.children:typeof o=="string"&&(w=o),u){let j=u.component;return jsx(Suspense,{fallback:jsx(Oe,{}),children:jsx(j,{code:w,isIncomplete:c,language:m,meta:f})})}if(m==="mermaid"&&d){let j=ft(l,"mermaid"),z=Fe(l,"download"),B=Fe(l,"copy"),_=Fe(l,"fullscreen"),Q=Fe(l,"panZoom"),U=j&&(z||B||_);return jsx(Suspense,{fallback:jsx(Oe,{}),children:jsxs("div",{className:r("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",t),"data-streamdown":"mermaid-block",children:[jsx("div",{className:r("flex h-8 items-center text-muted-foreground text-xs"),children:jsx("span",{className:r("ml-1 font-mono lowercase"),children:"mermaid"})}),U?jsx("div",{className:r("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:jsxs("div",{className:r("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"mermaid-block-actions",children:[z?jsx(co,{chart:w,config:a==null?void 0:a.config}):null,B?jsx(Ae,{code:w}):null,_?jsx(fo,{chart:w,config:a==null?void 0:a.config}):null]})}):null,jsx("div",{className:r("rounded-md border border-border bg-background"),children:jsx(os,{chart:w,config:a==null?void 0:a.config,showControls:Q})})]})})}let P=ft(l,"code"),M=To(l,"download"),H=To(l,"copy");return jsx(st,{className:t,code:w,isIncomplete:c,language:m,lineNumbers:v,startLine:g,children:P?jsxs(Fragment,{children:[M?jsx(it,{code:w,language:m}):null,H?jsx(Ae,{}):null]}):null})},Zo=memo(ss,(e,t)=>e.className===t.className&&qe(e.node,t.node));Zo.displayName="MarkdownCode";var Xo=memo(oo,(e,t)=>e.className===t.className&&qe(e.node,t.node));Xo.displayName="MarkdownImg";var Jo=memo(({children:e,node:t,...o})=>{let r=(Array.isArray(e)?e:[e]).filter(s=>s!=null&&s!=="");if(r.length===1&&isValidElement(r[0])){let s=r[0].props.node,a=s==null?void 0:s.tagName;if(a==="img")return jsx(Fragment,{children:e});if(a==="code"&&"data-block"in r[0].props)return jsx(Fragment,{children:e})}return jsx("p",{...o,children:e})},(e,t)=>E(e,t));Jo.displayName="MarkdownParagraph";var Ko={ol:bt,li:Po,ul:Mo,hr:Io,strong:No,a:Lo,h1:Ro,h2:So,h3:Eo,h4:Ho,h5:Do,h6:Bo,table:Ao,thead:Oo,tbody:Vo,tr:jo,th:Fo,td:zo,blockquote:_o,code:Zo,img:Xo,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:qo,sub:$o,p:Jo,section:Wo};var as=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,is=/\p{L}/u;function $e(e){let t=e.replace(/^#{1,6}\s+/gm,"").replace(/(\*{1,3}|_{1,3})/g,"").replace(/`[^`]*`/g,"").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/^[\s>*\-+\d.]+/gm,"");for(let o of t){if(as.test(o))return "rtl";if(is.test(o))return "ltr"}return "ltr"}var ls=/^[ \t]{0,3}(`{3,}|~{3,})/,cs=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,ht=e=>{let t=e.split(`
12
+ `),o=null,n=0;for(let r of t){let s=ls.exec(r);if(o===null){if(s){let a=s[1];o=a[0],n=a.length;}}else if(s){let a=s[1],l=a[0],i=a.length;l===o&&i>=n&&(o=null,n=0);}}return o!==null},Uo=e=>{let t=e.split(`
13
+ `);for(let o of t){let n=o.trim();if(n.length>0&&n.includes("|")&&cs.test(n))return true}return false};var Go=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var Qo=[],en={allowDangerousHtml:true},We=new WeakMap,wt=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,r=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||r||s)){let p="default";return this.keyCache.set(t,p),p}let a=p=>{if(!p||p.length===0)return "";let m="";for(let u=0;u<p.length;u+=1){let f=p[u];if(u>0&&(m+=","),Array.isArray(f)){let[h,b]=f;if(typeof h=="function"){let g=We.get(h);g||(g=h.name,We.set(h,g)),m+=g;}else m+=String(h);m+=":",m+=JSON.stringify(b);}else if(typeof f=="function"){let h=We.get(f);h||(h=f.name,We.set(f,h)),m+=h;}else m+=String(f);}return m},l=a(n),i=a(r),d=s?JSON.stringify(s):"",c=`${i}::${l}::${d}`;return this.keyCache.set(t,c),c}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let r=this.cache.keys().next().value;r&&this.cache.delete(r);}this.cache.set(n,o);}clear(){this.cache.clear();}},tn=new wt,Ct=e=>{let t=ws(e),o=e.children||"",n=t.runSync(t.parse(o),o);return Ps(n,e)},ws=e=>{let t=tn.get(e);if(t)return t;let o=ks(e);return tn.set(e,o),o},Cs=e=>e.some(t=>Array.isArray(t)?t[0]===Yo:t===Yo),ks=e=>{let t=e.rehypePlugins||Qo,o=e.remarkPlugins||Qo,n=Cs(t)?o:[...o,Go],r=e.remarkRehypeOptions?{...en,...e.remarkRehypeOptions}:en;return unified().use(gs).use(n).use(bs,r).use(t)},on=e=>e,vs=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},xs=(e,t)=>{var o;for(let n in urlAttributes)if(Object.hasOwn(urlAttributes,n)&&Object.hasOwn(e.properties,n)){let r=e.properties[n],s=urlAttributes[n];(s===null||s.includes(e.tagName))&&(e.properties[n]=(o=t(String(r||""),n,e))!=null?o:void 0);}},Ts=(e,t,o,n,r,s)=>{let a=false;return n?a=!n.includes(e.tagName):r&&(a=r.includes(e.tagName)),!a&&s&&typeof t=="number"&&(a=!s(e,t,o)),a},Ps=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:r,skipHtml:s,unwrapDisallowed:a,urlTransform:l}=t;if(o||n||r||s||l){let d=l||on;visit(e,(c,p,m)=>{if(c.type==="raw"&&m&&typeof p=="number")return vs(m,p,s,c.value),p;if(c.type==="element"&&(xs(c,d),Ts(c,p,m,n,r,o)&&m&&typeof p=="number"))return a&&c.children?m.children.splice(p,1,...c.children):m.children.splice(p,1),p});}return toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true})};var Is=/\[\^[\w-]{1,200}\](?!:)/,Ns=/\[\^[\w-]{1,200}\]:/;var Ls=/<(\w+)[\s>]/,Rs=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),nn=new Map,rn=new Map,Ss=e=>{let t=e.toLowerCase(),o=nn.get(t);if(o)return o;let n=new RegExp(`<${t}(?=[\\s>/])[^>]*>`,"gi");return nn.set(t,n),n},Es=e=>{let t=e.toLowerCase(),o=rn.get(t);if(o)return o;let n=new RegExp(`</${t}(?=[\\s>])[^>]*>`,"gi");return rn.set(t,n),n},sn=(e,t)=>{if(Rs.has(t.toLowerCase()))return 0;let o=e.match(Ss(t));if(!o)return 0;let n=0;for(let r of o)r.trimEnd().endsWith("/>")||(n+=1);return n},an=(e,t)=>{let o=e.match(Es(t));return o?o.length:0},Hs=e=>{let t=0;for(let o=0;o<e.length-1;o+=1)e[o]==="$"&&e[o+1]==="$"&&(t+=1,o+=1);return t},kt=e=>{let t=Is.test(e),o=Ns.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),r=[],s=[],a=false;for(let l of n){let i=l.raw,d=r.length;if(s.length>0){r[d-1]+=i;let c=s.at(-1),p=sn(i,c),m=an(i,c);for(let u=0;u<p;u+=1)s.push(c);for(let u=0;u<m;u+=1)s.length>0&&s.at(-1)===c&&s.pop();continue}if(l.type==="html"&&l.block){let c=i.match(Ls);if(c){let p=c[1],m=sn(i,p),u=an(i,p);m>u&&s.push(p);}}if(d>0&&!a){let c=r[d-1];if(Hs(c)%2===1){r[d-1]=c+i;continue}}r.push(i),l.type!=="space"&&(a=l.type==="code");}return r};var ln=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>{if(!l.includes(`
14
+
15
+ `))return a+l+i;let d=l.replace(/\n\n/g,`
16
+ <!---->
17
+ `),c=(d.startsWith(`
18
+ `)?"":`
19
+ `)+d+(d.endsWith(`
20
+ `)?"":`
21
+ `);return `${a}${c}${i}
22
+
23
+ `});}return o};var Ds=/([\\`*_~[\]|])/g,Bs=e=>e.replace(Ds,"\\$1"),cn=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>{let d=Bs(l).replace(/\n\n/g,"&#10;&#10;");return a+d+i});}return o};var dn=e=>e.type==="text"?e.value:"children"in e&&Array.isArray(e.children)?e.children.map(dn).join(""):"",mn=e=>t=>{if(!e||e.length===0)return;let o=new Set(e.map(n=>n.toLowerCase()));visit(t,"element",n=>{if(o.has(n.tagName.toLowerCase())){let r=dn(n);n.children=r?[{type:"text",value:r}]:[];}});};var un=()=>e=>{visit(e,"code",t=>{var o,n;t.meta&&(t.data=(o=t.data)!=null?o:{},t.data.hProperties={...(n=t.data.hProperties)!=null?n:{},metastring:t.meta});});};var Zs=/^[ \t]*<[\w!/?-]/,Xs=/(^|\n)[ \t]{4,}(?=<[\w!/?-])/g,Js=e=>typeof e!="string"||e.length===0||!Zs.test(e)?e:e.replace(Xs,"$1"),bn,hn,yn,wn,Ze={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(hn=(bn=defaultSchema.protocols)==null?void 0:bn.href)!=null?hn:[],"tel"]},attributes:{...defaultSchema.attributes,code:[...(wn=(yn=defaultSchema.attributes)==null?void 0:yn.code)!=null?wn:[],"metastring"]}},xt={raw:Yo,sanitize:[kn,Ze],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Ks={gfm:[$s,{}],codeMeta:un},gn=Object.values(xt),Us=Object.values(Ks),Gs={block:" \u258B",circle:" \u25CF"},vn=["github-light","github-dark"],xn={enabled:true},Ys={shikiTheme:vn,controls:true,isAnimating:false,lineNumbers:true,mode:"streaming",mermaid:void 0,linkSafety:xn},R=createContext(Ys),Tn=memo(({content:e,shouldParseIncompleteMarkdown:t,shouldNormalizeHtmlIndentation:o,index:n,isIncomplete:r,dir:s,animatePlugin:a,...l})=>{if(a){let c=a.getLastRenderCharCount();a.setPrevContentLength(c);}let i=typeof e=="string"&&o?Js(e):e,d=jsx(Ct,{...l,children:i});return jsx(et.Provider,{value:r,children:s?jsx("div",{dir:s,style:{display:"contents"},children:d}):d})},(e,t)=>{if(e.content!==t.content||e.shouldNormalizeHtmlIndentation!==t.shouldNormalizeHtmlIndentation||e.index!==t.index||e.isIncomplete!==t.isIncomplete||e.dir!==t.dir)return false;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(r=>{var s,a;return ((s=e.components)==null?void 0:s[r])!==((a=t.components)==null?void 0:a[r])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Tn.displayName="Block";var Qs=memo(({children:e,mode:t="streaming",dir:o,parseIncompleteMarkdown:n=true,normalizeHtmlIndentation:r=false,components:s,rehypePlugins:a=gn,remarkPlugins:l=Us,className:i,shikiTheme:d=vn,mermaid:c,controls:p=true,isAnimating:m=false,animated:u,BlockComponent:f=Tn,parseMarkdownIntoBlocksFn:h=kt,caret:b,plugins:g,remend:T,linkSafety:v=xn,lineNumbers:w=true,allowedTags:P,literalTagContent:M,translations:H,icons:S,prefix:F,onAnimationStart:j,onAnimationEnd:z,...B})=>{let _=useId(),[Q,U]=useTransition(),x=useMemo(()=>Dt(F),[F]),q=useRef(null),X=useRef(j),Re=useRef(z);X.current=j,Re.current=z,useEffect(()=>{var A,K,ee;if(t==="static")return;let k=q.current;if(q.current=m,k===null){m&&((A=X.current)==null||A.call(X));return}m&&!k?(K=X.current)==null||K.call(X):!m&&k&&((ee=Re.current)==null||ee.call(Re));},[m,t]);let Je=useMemo(()=>P?Object.keys(P):[],[P]),Se=useMemo(()=>{if(typeof e!="string")return "";let k=t==="streaming"&&n?Ws(e,T):e;return M&&M.length>0&&(k=cn(k,M)),Je.length>0&&(k=ln(k,Je)),k},[e,t,n,T,Je,M]),fe=useMemo(()=>h(Se),[Se,h]),[Ln,Tt]=useState(fe);useEffect(()=>{t==="streaming"&&!ge?U(()=>{Tt(fe);}):Tt(fe);},[fe,t]);let J=t==="streaming"?Ln:fe,Ke=useMemo(()=>o==="auto"?J.map($e):void 0,[J,o]),Rn=useMemo(()=>J.map((k,A)=>`${_}-${A}`),[J.length,_]),Ue=useMemo(()=>u===true?"true":u?JSON.stringify(u):"",[u]),ge=useMemo(()=>Ue?Ue==="true"?be():be(u):null,[Ue]),Pt=useMemo(()=>{var k,A;return {shikiTheme:(A=(k=g==null?void 0:g.code)==null?void 0:k.getThemes())!=null?A:d,controls:p,isAnimating:m,lineNumbers:w,mode:t,mermaid:c,linkSafety:v}},[d,p,m,w,t,c,v,g==null?void 0:g.code]),Sn=useMemo(()=>H?JSON.stringify(H):"",[H]),Mt=useMemo(()=>({...De,...H}),[Sn]),It=useMemo(()=>{let{inlineCode:k,...A}=s!=null?s:{},K={...Ko,...A};if(k){let ee=K.code;K.code=ie=>"data-block"in ie?ee?createElement(ee,ie):null:createElement(k,ie);}return K},[s]),Nt=useMemo(()=>{let k=[];return g!=null&&g.cjk&&(k=[...k,...g.cjk.remarkPluginsBefore]),k=[...k,...l],g!=null&&g.cjk&&(k=[...k,...g.cjk.remarkPluginsAfter]),g!=null&&g.math&&(k=[...k,g.math.remarkPlugin]),k},[l,g==null?void 0:g.math,g==null?void 0:g.cjk]),Lt=useMemo(()=>{var A;let k=a;if(P&&Object.keys(P).length>0&&a===gn){let K={...Ze,tagNames:[...(A=Ze.tagNames)!=null?A:[],...Object.keys(P)],attributes:{...Ze.attributes,...P}};k=[xt.raw,[kn,K],xt.harden];}return M&&M.length>0&&(k=[...k,[mn,M]]),g!=null&&g.math&&(k=[...k,g.math.rehypePlugin]),ge&&m&&(k=[...k,ge.rehypePlugin]),k},[a,g==null?void 0:g.math,ge,m,P,M]),Ge=useMemo(()=>{if(!m||J.length===0)return false;let k=J.at(-1);return ht(k)||Uo(k)},[m,J]),En=useMemo(()=>b&&m&&!Ge?{"--streamdown-caret":`"${Gs[b]}"`}:void 0,[b,m,Ge]);return t==="static"?jsx(Be.Provider,{value:Mt,children:jsx(Ve.Provider,{value:g!=null?g:null,children:jsx(R.Provider,{value:Pt,children:jsx(at,{icons:S,children:jsx(Ee.Provider,{value:x,children:jsx("div",{className:x("space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",i),dir:o==="auto"?$e(Se):o,children:jsx(Ct,{components:It,rehypePlugins:Lt,remarkPlugins:Nt,...B,children:Se})})})})})})}):jsx(Be.Provider,{value:Mt,children:jsx(Ve.Provider,{value:g!=null?g:null,children:jsx(R.Provider,{value:Pt,children:jsx(at,{icons:S,children:jsx(Ee.Provider,{value:x,children:jsxs("div",{className:x("space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",b&&!Ge?"[&>*:last-child]:after:inline [&>*:last-child]:after:align-baseline [&>*:last-child]:after:content-[var(--streamdown-caret)]":null,i),style:En,children:[J.length===0&&b&&m&&jsx("span",{}),J.map((k,A)=>{var ie;let K=A===J.length-1,ee=m&&K&&ht(k);return jsx(f,{animatePlugin:ge,components:It,content:k,dir:(ie=Ke==null?void 0:Ke[A])!=null?ie:o!=="auto"?o:void 0,index:A,isIncomplete:ee,rehypePlugins:Lt,remarkPlugins:Nt,shouldNormalizeHtmlIndentation:r,shouldParseIncompleteMarkdown:n,...B},Rn[A])})]})})})})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.animated===t.animated&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety&&e.lineNumbers===t.lineNumbers&&e.normalizeHtmlIndentation===t.normalizeHtmlIndentation&&e.literalTagContent===t.literalTagContent&&JSON.stringify(e.translations)===JSON.stringify(t.translations)&&e.prefix===t.prefix&&e.dir===t.dir);Qs.displayName="Streamdown";var Nn=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:r=.1,showControls:s=true,initialZoom:a=1,fullscreen:l=false})=>{let{RotateCcwIcon:i,ZoomInIcon:d,ZoomOutIcon:c}=L(),p=y(),m=useRef(null),u=useRef(null),[f,h]=useState(a),[b,g]=useState({x:0,y:0}),[T,v]=useState(false),[w,P]=useState({x:0,y:0}),[M,H]=useState({x:0,y:0}),S=useCallback(x=>{h(q=>Math.max(o,Math.min(n,q+x)));},[o,n]),F=useCallback(()=>{S(r);},[S,r]),j=useCallback(()=>{S(-r);},[S,r]),z=useCallback(()=>{h(a),g({x:0,y:0});},[a]),B=useCallback(x=>{x.preventDefault();let q=x.deltaY>0?-r:r;S(q);},[S,r]),_=useCallback(x=>{if(x.button!==0||x.isPrimary===false)return;v(true),P({x:x.clientX,y:x.clientY}),H(b);let q=x.currentTarget;q instanceof HTMLElement&&q.setPointerCapture(x.pointerId);},[b]),Q=useCallback(x=>{if(!T)return;x.preventDefault();let q=x.clientX-w.x,X=x.clientY-w.y;g({x:M.x+q,y:M.y+X});},[T,w,M]),U=useCallback(x=>{v(false);let q=x.currentTarget;q instanceof HTMLElement&&q.releasePointerCapture(x.pointerId);},[]);return useEffect(()=>{let x=m.current;if(x)return x.addEventListener("wheel",B,{passive:false}),()=>{x.removeEventListener("wheel",B);}},[B]),useEffect(()=>{let x=u.current;if(x&&T)return document.body.style.userSelect="none",x.addEventListener("pointermove",Q,{passive:false}),x.addEventListener("pointerup",U),x.addEventListener("pointercancel",U),()=>{document.body.style.userSelect="",x.removeEventListener("pointermove",Q),x.removeEventListener("pointerup",U),x.removeEventListener("pointercancel",U);}},[T,Q,U]),jsxs("div",{className:p("relative flex flex-col",l?"h-full w-full":"min-h-28 w-full",t),ref:m,style:{cursor:T?"grabbing":"grab"},children:[s?jsxs("div",{className:p("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/80 p-1 supports-[backdrop-filter]:bg-background/70 supports-[backdrop-filter]:backdrop-blur-sm",l?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:f>=n,onClick:F,title:"Zoom in",type:"button",children:jsx(d,{size:16})}),jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:f<=o,onClick:j,title:"Zoom out",type:"button",children:jsx(c,{size:16})}),jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"),onClick:z,title:"Reset zoom and pan",type:"button",children:jsx(i,{size:16})})]}):null,jsx("div",{className:p("flex-1 origin-center transition-transform duration-150 ease-out",l?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:_,ref:u,role:"application",style:{transform:`translate(${b.x}px, ${b.y}px) scale(${f})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var po=({chart:e,className:t,config:o,fullscreen:n=false,showControls:r=true})=>{let s=y(),[a,l]=useState(null),[i,d]=useState(false),[c,p]=useState(""),[m,u]=useState(""),[f,h]=useState(0),{mermaid:b}=useContext(R),g=de(),T=b==null?void 0:b.errorComponent,{shouldRender:v,containerRef:w}=Rt({immediate:n});if(useEffect(()=>{if(!v)return;if(!g){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),d(!0);let H=g.getMermaid(o),S=e.split("").reduce((z,B)=>(z<<5)-z+B.charCodeAt(0)|0,0),F=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:j}=await H.render(F,e);p(j),u(j);}catch(H){if(!(m||c)){let S=H instanceof Error?H.message:"Failed to render Mermaid chart";l(S);}}finally{d(false);}})();},[e,o,f,v,g]),!(v||c||m))return jsx("div",{className:s("my-4 min-h-[200px]",t),ref:w});if(i&&!c&&!m)return jsx("div",{className:s("my-4 flex justify-center p-4",t),ref:w,children:jsxs("div",{className:s("flex items-center space-x-2 text-muted-foreground"),children:[jsx("div",{className:s("h-4 w-4 animate-spin rounded-full border-current border-b-2")}),jsx("span",{className:s("text-sm"),children:"Loading diagram..."})]})});if(a&&!c&&!m){let M=()=>h(H=>H+1);return T?jsx("div",{ref:w,children:jsx(T,{chart:e,error:a,retry:M})}):jsxs("div",{className:s("rounded-md bg-red-50 p-4",t),ref:w,children:[jsxs("p",{className:s("font-mono text-red-700 text-sm"),children:["Mermaid Error: ",a]}),jsxs("details",{className:s("mt-2"),children:[jsx("summary",{className:s("cursor-pointer text-red-600 text-xs"),children:"Show Code"}),jsx("pre",{className:s("mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs"),children:e})]})]})}let P=c||m;return jsx("div",{className:s("size-full",t),"data-streamdown":"mermaid",ref:w,children:jsx(Nn,{className:s(n?"size-full overflow-hidden":"overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:s("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:P},role:"img"})})})};export{R as A,Tn as B,Qs as C,be as a,tt as b,At as c,ot as d,rt as e,Li as f,st as g,De as h,Ae as i,it as j,Oe as k,po as l,ue as m,ne as n,dt as o,je as p,re as q,Te as r,Wr as s,Pe as t,$e as u,on as v,kt as w,Js as x,xt as y,Ks as z};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import {A,f,c}from'./chunk-BO2N2NFS.js';import {useContext,useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';var R=({code:s,language:e,raw:t,className:h,startLine:d,lineNumbers:m,...p})=>{let{shikiTheme:l}=useContext(A),o=f(),[a,i]=useState(t);return useEffect(()=>{if(!o){i(t);return}let r=o.highlight({code:s,language:e,themes:l},c=>{i(c);});r&&i(r);},[s,e,l,o,t]),jsx(c,{className:h,language:e,lineNumbers:m,result:a,startLine:d,...p})};export{R as HighlightedCodeBlockBody};
package/dist/index.d.ts CHANGED
@@ -31,6 +31,7 @@ interface AnimateOptions {
31
31
  duration?: number;
32
32
  easing?: string;
33
33
  sep?: "word" | "char";
34
+ stagger?: number;
34
35
  }
35
36
  declare function createAnimatePlugin(options?: AnimateOptions): AnimatePlugin;
36
37
 
@@ -199,6 +200,10 @@ interface CustomRendererProps {
199
200
  code: string;
200
201
  isIncomplete: boolean;
201
202
  language: string;
203
+ /** Raw metastring from the code fence (everything after the language identifier).
204
+ * e.g. ```rust {1} title="foo" → meta = '{1} title="foo"'
205
+ * Undefined when no metastring is present. */
206
+ meta?: string;
202
207
  }
203
208
  interface CustomRenderer {
204
209
  component: react__default.ComponentType<CustomRendererProps>;
@@ -264,8 +269,10 @@ type CodeBlockProps = HTMLAttributes<HTMLDivElement> & {
264
269
  isIncomplete?: boolean;
265
270
  /** Custom starting line number for line numbering (default: 1) */
266
271
  startLine?: number;
272
+ /** Show line numbers in code blocks. @default true */
273
+ lineNumbers?: boolean;
267
274
  };
268
- declare const CodeBlock: ({ code, language, className, children, isIncomplete, startLine, ...rest }: CodeBlockProps) => react_jsx_runtime.JSX.Element;
275
+ declare const CodeBlock: ({ code, language, className, children, isIncomplete, startLine, lineNumbers, ...rest }: CodeBlockProps) => react_jsx_runtime.JSX.Element;
269
276
 
270
277
  type CodeBlockContainerProps = ComponentProps<"div"> & {
271
278
  language: string;
@@ -443,6 +450,8 @@ type StreamdownProps = Options & {
443
450
  icons?: Partial<IconMap>;
444
451
  /** Tailwind CSS prefix to prepend to all utility classes (e.g. `"tw"` produces `tw:flex` instead of `flex`). Enables Tailwind v4's `prefix()` support. Note: user-supplied `className` values are also prefixed. */
445
452
  prefix?: string;
453
+ /** Show line numbers in code blocks. @default true */
454
+ lineNumbers?: boolean;
446
455
  /** Called when isAnimating transitions from false to true. Suppressed in mode="static". */
447
456
  onAnimationStart?: () => void;
448
457
  /** Called when isAnimating transitions from true to false. Suppressed in mode="static". */
@@ -457,6 +466,8 @@ declare const carets: {
457
466
  interface StreamdownContextType {
458
467
  controls: ControlsConfig;
459
468
  isAnimating: boolean;
469
+ /** Show line numbers in code blocks. @default true */
470
+ lineNumbers: boolean;
460
471
  linkSafety?: LinkSafetyConfig;
461
472
  mermaid?: MermaidOptions;
462
473
  mode: "static" | "streaming";
@@ -476,6 +487,6 @@ type BlockProps = Options & {
476
487
  animatePlugin?: AnimatePlugin | null;
477
488
  };
478
489
  declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown: _, shouldNormalizeHtmlIndentation, index: __, isIncomplete, dir, animatePlugin: animatePluginProp, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
479
- declare const Streamdown: react.MemoExoticComponent<({ children, mode, dir, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, normalizeHtmlIndentation: shouldNormalizeHtmlIndentation, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, animated, BlockComponent, parseMarkdownIntoBlocksFn, caret, plugins, remend: remendOptions, linkSafety, allowedTags, literalTagContent, translations, icons: iconOverrides, prefix, onAnimationStart, onAnimationEnd, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
490
+ declare const Streamdown: react.MemoExoticComponent<({ children, mode, dir, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, normalizeHtmlIndentation: shouldNormalizeHtmlIndentation, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, animated, BlockComponent, parseMarkdownIntoBlocksFn, caret, plugins, remend: remendOptions, linkSafety, lineNumbers, allowedTags, literalTagContent, translations, icons: iconOverrides, prefix, onAnimationStart, onAnimationEnd, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
480
491
 
481
492
  export { type AllowElement, type AllowedTags, type AnimateOptions, Block, type BlockProps, type CjkPlugin, CodeBlock, CodeBlockContainer, CodeBlockCopyButton, CodeBlockDownloadButton, CodeBlockHeader, CodeBlockSkeleton, type CodeHighlighterPlugin, type Components, type ControlsConfig, type CustomRenderer, type CustomRendererProps, type DiagramPlugin, type ExtraProps, type HighlightOptions, type IconMap, type LinkSafetyConfig, type LinkSafetyModalProps, type MathPlugin, type MermaidErrorComponentProps, type MermaidOptions, type PluginConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, type StreamdownTranslations, TableCopyDropdown, type TableCopyDropdownProps, type TableData, TableDownloadButton, type TableDownloadButtonProps, TableDownloadDropdown, type TableDownloadDropdownProps, type ThemeInput, type UrlTransform, createAnimatePlugin, defaultRehypePlugins, defaultRemarkPlugins, defaultTranslations, defaultUrlTransform, detectTextDirection, escapeMarkdownTableCell, extractTableDataFromElement, normalizeHtmlIndentation, parseMarkdownIntoBlocks, tableDataToCSV, tableDataToMarkdown, tableDataToTSV, useIsCodeFenceIncomplete };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- export{B as Block,g as CodeBlock,d as CodeBlockContainer,i as CodeBlockCopyButton,j as CodeBlockDownloadButton,e as CodeBlockHeader,k as CodeBlockSkeleton,C as Streamdown,A as StreamdownContext,r as TableCopyDropdown,s as TableDownloadButton,t as TableDownloadDropdown,a as createAnimatePlugin,y as defaultRehypePlugins,z as defaultRemarkPlugins,h as defaultTranslations,v as defaultUrlTransform,u as detectTextDirection,p as escapeMarkdownTableCell,m as extractTableDataFromElement,x as normalizeHtmlIndentation,w as parseMarkdownIntoBlocks,n as tableDataToCSV,q as tableDataToMarkdown,o as tableDataToTSV,b as useIsCodeFenceIncomplete}from'./chunk-FRKYWMV7.js';
2
+ export{B as Block,g as CodeBlock,d as CodeBlockContainer,i as CodeBlockCopyButton,j as CodeBlockDownloadButton,e as CodeBlockHeader,k as CodeBlockSkeleton,C as Streamdown,A as StreamdownContext,r as TableCopyDropdown,s as TableDownloadButton,t as TableDownloadDropdown,a as createAnimatePlugin,y as defaultRehypePlugins,z as defaultRemarkPlugins,h as defaultTranslations,v as defaultUrlTransform,u as detectTextDirection,p as escapeMarkdownTableCell,m as extractTableDataFromElement,x as normalizeHtmlIndentation,w as parseMarkdownIntoBlocks,n as tableDataToCSV,q as tableDataToMarkdown,o as tableDataToTSV,b as useIsCodeFenceIncomplete}from'./chunk-BO2N2NFS.js';
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export{l as Mermaid}from'./chunk-BO2N2NFS.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamdown",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -36,14 +36,13 @@
36
36
  "@vitejs/plugin-react": "^5.1.2",
37
37
  "@vitest/coverage-v8": "^4.0.15",
38
38
  "jsdom": "^27.3.0",
39
- "mermaid": "^11.12.2",
40
39
  "react-markdown": "^10.1.0",
41
40
  "rehype-parse": "^9.0.1",
42
41
  "rehype-stringify": "^10.0.1",
43
42
  "shiki": "^3.19.0",
44
43
  "tsup": "^8.5.1",
45
44
  "vitest": "^4.0.15",
46
- "@streamdown/cjk": "1.0.2",
45
+ "@streamdown/cjk": "1.0.3",
47
46
  "@streamdown/math": "1.0.2",
48
47
  "@streamdown/mermaid": "1.0.2"
49
48
  },
@@ -64,9 +63,10 @@
64
63
  "remark-rehype": "^11.1.2",
65
64
  "tailwind-merge": "^3.4.0",
66
65
  "unified": "^11.0.5",
66
+ "mermaid": "^11.12.2",
67
67
  "unist-util-visit": "^5.0.0",
68
68
  "unist-util-visit-parents": "^6.0.0",
69
- "remend": "1.2.2"
69
+ "remend": "1.3.0"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "tsup",
package/styles.css CHANGED
@@ -31,5 +31,5 @@
31
31
 
32
32
  [data-sd-animate] {
33
33
  animation: var(--sd-animation, sd-fadeIn) var(--sd-duration, 150ms)
34
- var(--sd-easing, ease) both;
34
+ var(--sd-easing, ease) var(--sd-delay, 0ms) both;
35
35
  }
@@ -1,14 +0,0 @@
1
- "use client";
2
- import {createContext,memo,useContext,useMemo,lazy,isValidElement,useId,useTransition,useRef,useEffect,useState,cloneElement,createElement,useCallback,Suspense}from'react';import {harden}from'rehype-harden';import Go from'rehype-raw';import Cn,{defaultSchema}from'rehype-sanitize';import Fs from'remark-gfm';import zs from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import {urlAttributes}from'html-url-attributes';import ms from'remark-parse';import us from'remark-rehype';import {unified}from'unified';import {visit}from'unist-util-visit';import {Lexer}from'marked';var En=300,Hn="300px",Dn=500;function Lt(e={}){let{immediate:t=false,debounceDelay:o=En,rootMargin:n=Hn,idleTimeout:r=Dn}=e,[s,a]=useState(false),l=useRef(null),i=useRef(null),c=useRef(null),d=useMemo(()=>p=>{let g=Date.now();return window.setTimeout(()=>{p({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-g))});},1)},[]),u=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(p,g)=>window.requestIdleCallback(p,g):d,[d]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?p=>window.cancelIdleCallback(p):p=>{clearTimeout(p);},[]);return useEffect(()=>{if(t){a(true);return}let p=l.current;if(!p)return;i.current&&(clearTimeout(i.current),i.current=null),c.current&&(m(c.current),c.current=null);let g=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(m(c.current),c.current=null);},h=x=>{c.current=u(w=>{w.timeRemaining()>0||w.didTimeout?(a(true),x.disconnect()):c.current=u(()=>{a(true),x.disconnect();},{timeout:r/2});},{timeout:r});},b=x=>{g(),i.current=window.setTimeout(()=>{var I,H;let w=x.takeRecords();(w.length===0||(H=(I=w.at(-1))==null?void 0:I.isIntersecting)!=null&&H)&&h(x);},o);},f=(x,w)=>{x.isIntersecting?b(w):g();},T=new IntersectionObserver(x=>{for(let w of x)f(w,T);},{rootMargin:n,threshold:0});return T.observe(p),()=>{i.current&&clearTimeout(i.current),c.current&&m(c.current),T.disconnect();}},[t,o,n,r,m,u]),{shouldRender:s,containerRef:l}}var Rt=/\s/,On=/^\s+$/,Vn=new Set(["code","pre","svg","math","annotation"]),jn=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",Fn=e=>e.some(t=>jn(t)&&Vn.has(t.tagName)),zn=e=>{let t=[],o="",n=false;for(let r of e){let s=Rt.test(r);s!==n&&o&&(t.push(o),o=""),o+=r,n=s;}return o&&t.push(o),t},_n=e=>{let t=[],o="";for(let n of e)Rt.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},qn=(e,t,o,n,r)=>({type:"element",tagName:"span",properties:{"data-sd-animate":true,style:r?`--sd-animation:sd-${t};--sd-duration:0ms;--sd-easing:${n}`:`--sd-animation:sd-${t};--sd-duration:${o}ms;--sd-easing:${n}`},children:[{type:"text",value:e}]}),$n=(e,t,o,n,r)=>{let s=t.at(-1);if(!(s&&"children"in s))return;if(Fn(t))return SKIP;let a=s,l=a.children.indexOf(e);if(l===-1)return;let i=e.value;if(!i.trim()){r.count+=i.length;return}let c=o.sep==="char"?_n(i):zn(i),d=n.prevContentLength,u=c.map(m=>{let p=r.count;if(r.count+=m.length,On.test(m))return {type:"text",value:m};let g=d>0&&p<d;return qn(m,o.animation,o.duration,o.easing,g)});return a.children.splice(l,1,...u),l+u.length},Wn=0;function be(e){var s,a,l,i;let t={animation:(s=e==null?void 0:e.animation)!=null?s:"fadeIn",duration:(a=e==null?void 0:e.duration)!=null?a:150,easing:(l=e==null?void 0:e.easing)!=null?l:"ease",sep:(i=e==null?void 0:e.sep)!=null?i:"word"},o={prevContentLength:0,lastRenderCharCount:0},n=Wn++,r=()=>c=>{let d={count:0};visitParents(c,"text",(u,m)=>$n(u,m,t,o,d)),o.lastRenderCharCount=d.count,o.prevContentLength=0;};return Object.defineProperty(r,"name",{value:`rehypeAnimate$${n}`}),{name:"animate",type:"animate",rehypePlugin:r,setPrevContentLength(c){o.prevContentLength=c;},getLastRenderCharCount(){let c=o.lastRenderCharCount;return o.lastRenderCharCount=0,c}}}be();var Qe=createContext(false),et=()=>useContext(Qe);var he=(...e)=>twMerge(clsx(e)),Jn=(e,t)=>{if(!e||!t)return t;let o=`${e}:`;return t.split(/\s+/).filter(Boolean).map(n=>n.startsWith(o)?n:`${e}:${n}`).join(" ")},Ht=e=>e?(...t)=>Jn(e,twMerge(clsx(t))):he,J=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r);};var Se=createContext(he),y=()=>useContext(Se);var Yn=he("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),Qn=e=>{let t={};for(let o of e.split(";")){let n=o.indexOf(":");if(n>0){let r=o.slice(0,n).trim(),s=o.slice(n+1).trim();r&&s&&(t[r]=s);}}return t},Bt=memo(({children:e,result:t,language:o,className:n,startLine:r,...s})=>{let a=y(),l=useMemo(()=>a(Yn),[a]),i=useMemo(()=>{let c={};return t.bg&&(c["--sdm-bg"]=t.bg),t.fg&&(c["--sdm-fg"]=t.fg),t.rootStyle&&Object.assign(c,Qn(t.rootStyle)),c},[t.bg,t.fg,t.rootStyle]);return jsx("div",{className:a(n,"overflow-hidden rounded-md border border-border bg-background p-4 text-sm"),"data-language":o,"data-streamdown":"code-block-body",...s,children:jsx("pre",{className:a(n,"bg-[var(--sdm-bg,inherit]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]"),style:i,children:jsx("code",{className:a("[counter-increment:line_0] [counter-reset:line]"),style:r&&r>1?{counterReset:`line ${r-1}`}:void 0,children:t.tokens.map((c,d)=>jsx("span",{className:l,children:c.length===0||c.length===1&&c[0].content===""?`
3
- `:c.map((u,m)=>{let p={},g=!!u.bgColor;if(u.color&&(p["--sdm-c"]=u.color),u.bgColor&&(p["--sdm-tbg"]=u.bgColor),u.htmlStyle)for(let[h,b]of Object.entries(u.htmlStyle))h==="color"?p["--sdm-c"]=b:h==="background-color"?(p["--sdm-tbg"]=b,g=true):p[h]=b;return jsx("span",{className:a("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",g&&"bg-[var(--sdm-tbg)]",g&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:p,...u.htmlAttrs,children:u.content},m)})},d))})})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className&&e.startLine===t.startLine);var tt=({className:e,language:t,style:o,isIncomplete:n,...r})=>{let s=y();return jsx("div",{className:s("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",e),"data-incomplete":n||void 0,"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...r})};var ot=createContext({code:""}),Ee=()=>useContext(ot);var nt=({language:e})=>{let t=y();return jsx("div",{className:t("flex h-8 items-center text-muted-foreground text-xs"),"data-language":e,"data-streamdown":"code-block-header",children:jsx("span",{className:t("ml-1 font-mono lowercase"),children:e})})};var sr=/\n+$/,ar=lazy(()=>import('./highlighted-body-TPN3WLV5.js').then(e=>({default:e.HighlightedCodeBlockBody}))),rt=({code:e,language:t,className:o,children:n,isIncomplete:r=false,startLine:s,...a})=>{let l=y(),i=useMemo(()=>e.replace(sr,""),[e]),c=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:i.split(`
4
- `).map(d=>[{content:d,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[i]);return jsx(ot.Provider,{value:{code:e},children:jsxs(tt,{isIncomplete:r,language:t,children:[jsx(nt,{language:t}),n?jsx("div",{className:l("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:jsx("div",{className:l("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"code-block-actions",children:n})}):null,jsx(Suspense,{fallback:jsx(Bt,{className:o,language:t,result:c,startLine:s,...a}),children:jsx(ar,{className:o,code:i,language:t,raw:c,startLine:s,...a})})]})})};var Vt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),jt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),Ft=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),zt=e=>jsxs("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),_t=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),qt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),$t=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),Wt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",fill:"currentColor",fillRule:"evenodd"})}),Zt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),Xt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})});var we={CheckIcon:Vt,CopyIcon:jt,DownloadIcon:Ft,ExternalLinkIcon:Wt,Loader2Icon:zt,Maximize2Icon:_t,RotateCcwIcon:qt,XIcon:$t,ZoomInIcon:Zt,ZoomOutIcon:Xt},Kt=createContext(we),mr=(e,t)=>{if(e===t)return true;if(!(e&&t))return e===t;let o=Object.keys(e),n=Object.keys(t);return o.length!==n.length?false:o.every(r=>e[r]===t[r])},st=({icons:e,children:t})=>{let o=useRef(e),n=useRef(e?{...we,...e}:we);mr(o.current,e)||(o.current=e,n.current=e?{...we,...e}:we);let r=n.current;return jsx(Kt.Provider,{value:r,children:t})},L=()=>useContext(Kt);var He={copyCode:"Copy Code",downloadFile:"Download file",downloadDiagram:"Download diagram",downloadDiagramAsSvg:"Download diagram as SVG",downloadDiagramAsPng:"Download diagram as PNG",downloadDiagramAsMmd:"Download diagram as MMD",viewFullscreen:"View fullscreen",exitFullscreen:"Exit fullscreen",mermaidFormatSvg:"SVG",mermaidFormatPng:"PNG",mermaidFormatMmd:"MMD",copyTable:"Copy table",copyTableAsMarkdown:"Copy table as Markdown",copyTableAsCsv:"Copy table as CSV",copyTableAsTsv:"Copy table as TSV",downloadTable:"Download table",downloadTableAsCsv:"Download table as CSV",downloadTableAsMarkdown:"Download table as Markdown",tableFormatMarkdown:"Markdown",tableFormatCsv:"CSV",tableFormatTsv:"TSV",imageNotAvailable:"Image not available",downloadImage:"Download image",openExternalLink:"Open external link?",externalLinkWarning:"You're about to visit an external website.",close:"Close",copyLink:"Copy link",copied:"Copied",openLink:"Open link"},De=createContext(He),B=()=>useContext(De);var Be=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...a})=>{let l=y(),[i,c]=useState(false),d=useRef(0),{code:u}=Ee(),{isAnimating:m}=useContext(R),p=B(),g=s!=null?s:u,h=async()=>{var T;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(g),c(!0),e==null||e(),d.current=window.setTimeout(()=>c(!1),o));}catch(x){t==null||t(x);}};useEffect(()=>()=>{window.clearTimeout(d.current);},[]);let b=L(),f=i?b.CheckIcon:b.CopyIcon;return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-copy-button",disabled:m,onClick:h,title:p.copyCode,type:"button",...a,children:n!=null?n:jsx(f,{size:14})})};var Gt={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},at=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...a})=>{let l=y(),{code:i}=Ee(),{isAnimating:c}=useContext(R),d=B(),u=L(),m=s!=null?s:i,g=`file.${o&&o in Gt?Gt[o]:"txt"}`,h="text/plain",b=()=>{try{J(g,m,h),e==null||e();}catch(f){t==null||t(f);}};return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-download-button",disabled:c,onClick:b,title:d.downloadFile,type:"button",...a,children:n!=null?n:jsx(u.DownloadIcon,{size:14})})};var Ae=()=>{let{Loader2Icon:e}=L(),t=y();return jsxs("div",{className:t("w-full divide-y divide-border overflow-hidden rounded-xl border border-border"),children:[jsx("div",{className:t("h-[46px] w-full bg-muted/80")}),jsx("div",{className:t("flex w-full items-center justify-center p-4"),children:jsx(e,{className:t("size-4 animate-spin")})})]})};var xr=/\.[^/.]+$/,to=({node:e,className:t,src:o,alt:n,onLoad:r,onError:s,...a})=>{let{DownloadIcon:l}=L(),i=y(),c=useRef(null),[d,u]=useState(false),[m,p]=useState(false),g=B(),h=a.width!=null||a.height!=null,b=(d||h)&&!m,f=m&&!h;useEffect(()=>{let k=c.current;if(k!=null&&k.complete){let I=k.naturalWidth>0;u(I),p(!I);}},[]);let T=useCallback(k=>{u(true),p(false),r==null||r(k);},[r]),x=useCallback(k=>{u(false),p(true),s==null||s(k);},[s]),w=async()=>{if(o)try{let I=await(await fetch(o)).blob(),S=new URL(o,window.location.origin).pathname.split("/").pop()||"",F=S.split(".").pop(),z=S.includes(".")&&F!==void 0&&F.length<=4,q="";if(z)q=S;else {let A=I.type,K="png";A.includes("jpeg")||A.includes("jpg")?K="jpg":A.includes("png")?K="png":A.includes("svg")?K="svg":A.includes("gif")?K="gif":A.includes("webp")&&(K="webp"),q=`${(n||S||"image").replace(xr,"")}.${K}`;}J(q,I,I.type);}catch(k){window.open(o,"_blank");}};return o?jsxs("div",{className:i("group relative my-4 inline-block"),"data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:i("max-w-full rounded-lg",f&&"hidden",t),"data-streamdown":"image",onError:x,onLoad:T,ref:c,src:o,...a}),f&&jsx("span",{className:i("text-muted-foreground text-xs italic"),"data-streamdown":"image-fallback",children:g.imageNotAvailable}),jsx("div",{className:i("pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block")}),b&&jsx("button",{className:i("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:w,title:g.downloadImage,type:"button",children:jsx(l,{size:14})})]}):null};var ke=0,le=()=>{ke+=1,ke===1&&(document.body.style.overflow="hidden");},ce=()=>{ke=Math.max(0,ke-1),ke===0&&(document.body.style.overflow="");};var ro=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let{CheckIcon:r,CopyIcon:s,ExternalLinkIcon:a,XIcon:l}=L(),i=y(),[c,d]=useState(false),u=B(),m=useCallback(async()=>{try{await navigator.clipboard.writeText(e),d(!0),setTimeout(()=>d(!1),2e3);}catch(g){}},[e]),p=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){le();let g=h=>{h.key==="Escape"&&o();};return document.addEventListener("keydown",g),()=>{document.removeEventListener("keydown",g),ce();}}},[t,o]),t?jsx("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm"),"data-streamdown":"link-safety-modal",onClick:o,onKeyDown:g=>{g.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:i("relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg"),onClick:g=>g.stopPropagation(),onKeyDown:g=>g.stopPropagation(),role:"presentation",children:[jsx("button",{className:i("absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:o,title:u.close,type:"button",children:jsx(l,{size:16})}),jsxs("div",{className:i("flex flex-col gap-2"),children:[jsxs("div",{className:i("flex items-center gap-2 font-semibold text-lg"),children:[jsx(a,{size:20}),jsx("span",{children:u.openExternalLink})]}),jsx("p",{className:i("text-muted-foreground text-sm"),children:u.externalLinkWarning})]}),jsx("div",{className:i("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxs("div",{className:i("flex gap-2"),children:[jsx("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted"),onClick:m,type:"button",children:c?jsxs(Fragment,{children:[jsx(r,{size:14}),jsx("span",{children:u.copied})]}):jsxs(Fragment,{children:[jsx(s,{size:14}),jsx("span",{children:u.copyLink})]})}),jsxs("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90"),onClick:p,type:"button",children:[jsx(a,{size:14}),jsx("span",{children:u.openLink})]})]})]})}):null};var Oe=createContext(null),lt=()=>useContext(Oe),Mi=()=>{var t;let e=lt();return (t=e==null?void 0:e.code)!=null?t:null},de=()=>{var t;let e=lt();return (t=e==null?void 0:e.mermaid)!=null?t:null};var so=e=>{var o;let t=lt();return t!=null&&t.renderers&&e&&(o=t.renderers.find(n=>Array.isArray(n.language)?n.language.includes(e):n.language===e))!=null?o:null};var ao=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((r,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),l=new Image;l.crossOrigin="anonymous",l.onload=()=>{let i=document.createElement("canvas"),c=l.width*o,d=l.height*o;i.width=c,i.height=d;let u=i.getContext("2d");if(!u){s(new Error("Failed to create 2D canvas context for PNG export"));return}u.drawImage(l,0,0,c,d),i.toBlob(m=>{if(!m){s(new Error("Failed to create PNG blob"));return}r(m);},"image/png");},l.onerror=()=>s(new Error("Failed to load SVG image")),l.src=a;})};var lo=({chart:e,children:t,className:o,onDownload:n,config:r,onError:s})=>{let a=y(),[l,i]=useState(false),c=useRef(null),{isAnimating:d}=useContext(R),u=L(),m=de(),p=B(),g=async h=>{try{if(h==="mmd"){J("diagram.mmd",e,"text/plain"),i(!1),n==null||n(h);return}if(!m){s==null||s(new Error("Mermaid plugin not available"));return}let b=m.getMermaid(r),f=e.split("").reduce((w,k)=>(w<<5)-w+k.charCodeAt(0)|0,0),T=`mermaid-${Math.abs(f)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:x}=await b.render(T,e);if(!x){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(h==="svg"){J("diagram.svg",x,"image/svg+xml"),i(!1),n==null||n(h);return}if(h==="png"){let w=await ao(x);J("diagram.png",w,"image/png"),n==null||n(h),i(!1);return}}catch(b){s==null||s(b);}};return useEffect(()=>{let h=b=>{let f=b.composedPath();c.current&&!f.includes(c.current)&&i(false);};return document.addEventListener("mousedown",h),()=>{document.removeEventListener("mousedown",h);}},[]),jsxs("div",{className:a("relative"),ref:c,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:d,onClick:()=>i(!l),title:p.downloadDiagram,type:"button",children:t!=null?t:jsx(u.DownloadIcon,{size:14})}),l?jsxs("div",{className:a("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>g("svg"),title:p.downloadDiagramAsSvg,type:"button",children:p.mermaidFormatSvg}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>g("png"),title:p.downloadDiagramAsPng,type:"button",children:p.mermaidFormatPng}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>g("mmd"),title:p.downloadDiagramAsMmd,type:"button",children:p.mermaidFormatMmd})]}):null]})};var po=({chart:e,config:t,onFullscreen:o,onExit:n,className:r,...s})=>{let{Maximize2Icon:a,XIcon:l}=L(),i=y(),[c,d]=useState(false),{isAnimating:u,controls:m}=useContext(R),p=B(),g=(()=>{if(typeof m=="boolean")return m;let b=m.mermaid;return b===false?false:b===true||b===void 0?true:b.panZoom!==false})(),h=()=>{d(!c);};return useEffect(()=>{if(c){le();let b=f=>{f.key==="Escape"&&d(false);};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b),ce();}}},[c]),useEffect(()=>{c?o==null||o():n&&n();},[c,o,n]),jsxs(Fragment,{children:[jsx("button",{className:i("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:u,onClick:h,title:p.viewFullscreen,type:"button",...s,children:jsx(a,{size:14})}),c?createPortal(jsxs("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"),onClick:h,onKeyDown:b=>{b.key==="Escape"&&h();},role:"button",tabIndex:0,children:[jsx("button",{className:i("absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:h,title:p.exitFullscreen,type:"button",children:jsx(l,{size:20})}),jsx("div",{className:i("flex size-full items-center justify-center p-4"),onClick:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),role:"presentation",children:jsx(uo,{chart:e,className:i("size-full [&_svg]:h-auto [&_svg]:w-auto"),config:t,fullscreen:true,showControls:g})})]}),document.body):null]})};var ue=e=>{var s,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let l of n)t.push(((s=l.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let l of r){let i=[],c=l.querySelectorAll("td");for(let d of c)i.push(((a=d.textContent)==null?void 0:a.trim())||"");o.push(i);}return {headers:t,rows:o}},oe=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false,c=false;for(let d of l){if(d==='"'){i=true,c=true;break}(d===","||d===`
5
- `)&&(i=true);}return i?c?`"${l.replace(/"/g,'""')}"`:`"${l}"`:l},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(","),a+=1);for(let l of o)s[a]=l.map(n).join(","),a+=1;return s.join(`
6
- `)},ct=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false;for(let d of l)if(d===" "||d===`
7
- `||d==="\r"){i=true;break}if(!i)return l;let c=[];for(let d of l)d===" "?c.push("\\t"):d===`
8
- `?c.push("\\n"):d==="\r"?c.push("\\r"):c.push(d);return c.join("")},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(" "),a+=1);for(let l of o)s[a]=l.map(n).join(" "),a+=1;return s.join(`
9
- `)},Ve=e=>{let t=false;for(let n of e)if(n==="\\"||n==="|"){t=true;break}if(!t)return e;let o=[];for(let n of e)n==="\\"?o.push("\\\\"):n==="|"?o.push("\\|"):o.push(n);return o.join("")},ne=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),r=0,s=t.map(l=>Ve(l));n[r]=`| ${s.join(" | ")} |`,r+=1;let a=new Array(t.length);for(let l=0;l<t.length;l+=1)a[l]="---";n[r]=`| ${a.join(" | ")} |`,r+=1;for(let l of o)if(l.length<t.length){let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]=c<l.length?Ve(l[c]):"";n[r]=`| ${i.join(" | ")} |`,r+=1;}else {let i=l.map(c=>Ve(c));n[r]=`| ${i.join(" | ")} |`,r+=1;}return n.join(`
10
- `)};var Te=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3})=>{let s=y(),[a,l]=useState(false),[i,c]=useState(false),d=useRef(null),u=useRef(0),{isAnimating:m}=useContext(R),p=B(),g=async f=>{var T,x;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.write)){n==null||n(new Error("Clipboard API not available"));return}try{let w=(x=d.current)==null?void 0:x.closest('[data-streamdown="table-wrapper"]'),k=w==null?void 0:w.querySelector("table");if(!k){n==null||n(new Error("Table not found"));return}let I=ue(k),F=({csv:oe,tsv:ct,md:ne}[f]||ne)(I),z=new ClipboardItem({"text/plain":new Blob([F],{type:"text/plain"}),"text/html":new Blob([k.outerHTML],{type:"text/html"})});await navigator.clipboard.write([z]),c(!0),l(!1),o==null||o(f),u.current=window.setTimeout(()=>c(!1),r);}catch(w){n==null||n(w);}};useEffect(()=>{let f=T=>{let x=T.composedPath();d.current&&!x.includes(d.current)&&l(false);};return document.addEventListener("mousedown",f),()=>{document.removeEventListener("mousedown",f),window.clearTimeout(u.current);}},[]);let h=L(),b=i?h.CheckIcon:h.CopyIcon;return jsxs("div",{className:s("relative"),ref:d,children:[jsx("button",{className:s("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!a),title:p.copyTable,type:"button",children:e!=null?e:jsx(b,{height:14,width:14})}),a?jsxs("div",{className:s("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>g("md"),title:p.copyTableAsMarkdown,type:"button",children:p.tableFormatMarkdown}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>g("csv"),title:p.copyTableAsCsv,type:"button",children:p.tableFormatCsv}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>g("tsv"),title:p.copyTableAsTsv,type:"button",children:p.tableFormatTsv})]}):null]})};var _r=({children:e,className:t,onDownload:o,onError:n,format:r="csv",filename:s})=>{let a=y(),{isAnimating:l}=useContext(R),i=B(),c=L(),d=u=>{try{let p=u.currentTarget.closest('[data-streamdown="table-wrapper"]'),g=p==null?void 0:p.querySelector("table");if(!g){n==null||n(new Error("Table not found"));return}let h=ue(g),b="",f="",T="";switch(r){case "csv":b=oe(h),f="text/csv",T="csv";break;case "markdown":b=ne(h),f="text/markdown",T="md";break;default:b=oe(h),f="text/csv",T="csv";}let x=new Blob([b],{type:f}),w=URL.createObjectURL(x),k=document.createElement("a");k.href=w,k.download=`${s||"table"}.${T}`,document.body.appendChild(k),k.click(),document.body.removeChild(k),URL.revokeObjectURL(w),o==null||o();}catch(m){n==null||n(m);}};return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:d,title:r==="csv"?i.downloadTableAsCsv:i.downloadTableAsMarkdown,type:"button",children:e!=null?e:jsx(c.DownloadIcon,{size:14})})},Pe=({children:e,className:t,onDownload:o,onError:n})=>{let r=y(),[s,a]=useState(false),l=useRef(null),{isAnimating:i}=useContext(R),c=B(),d=L(),u=m=>{var p;try{let g=(p=l.current)==null?void 0:p.closest('[data-streamdown="table-wrapper"]'),h=g==null?void 0:g.querySelector("table");if(!h){n==null||n(new Error("Table not found"));return}let b=ue(h),f=m==="csv"?oe(b):ne(b);J(`table.${m==="csv"?"csv":"md"}`,f,m==="csv"?"text/csv":"text/markdown"),a(!1),o==null||o(m);}catch(g){n==null||n(g);}};return useEffect(()=>{let m=p=>{let g=p.composedPath();l.current&&!g.includes(l.current)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:r("relative"),ref:l,children:[jsx("button",{className:r("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>a(!s),title:c.downloadTable,type:"button",children:e!=null?e:jsx(d.DownloadIcon,{size:14})}),s?jsxs("div",{className:r("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>u("csv"),title:c.downloadTableAsCsv,type:"button",children:c.tableFormatCsv}),jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>u("markdown"),title:c.downloadTableAsMarkdown,type:"button",children:c.tableFormatMarkdown})]}):null]})};var wo=({children:e,className:t,showCopy:o=true,showDownload:n=true})=>{let{Maximize2Icon:r,XIcon:s}=L(),a=y(),[l,i]=useState(false),{isAnimating:c}=useContext(R),d=B(),u=()=>{i(true);},m=()=>{i(false);};return useEffect(()=>{if(l){le();let p=g=>{g.key==="Escape"&&i(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),ce();}}},[l]),jsxs(Fragment,{children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:c,onClick:u,title:d.viewFullscreen,type:"button",children:jsx(r,{size:14})}),l?createPortal(jsx("div",{"aria-label":d.viewFullscreen,"aria-modal":"true",className:a("fixed inset-0 z-50 flex flex-col bg-background"),"data-streamdown":"table-fullscreen",onClick:m,onKeyDown:p=>{p.key==="Escape"&&m();},role:"dialog",children:jsxs("div",{className:a("flex h-full flex-col"),onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:[jsxs("div",{className:a("flex items-center justify-end gap-1 p-4"),children:[o?jsx(Te,{}):null,n?jsx(Pe,{}):null,jsx("button",{className:a("rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:m,title:d.exitFullscreen,type:"button",children:jsx(s,{size:20})})]}),jsx("div",{className:a("flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10"),children:jsx("table",{className:a("w-full border-collapse border border-border"),"data-streamdown":"table",children:e})})]})}),document.body):null]})};var ko=({children:e,className:t,showControls:o,showCopy:n=true,showDownload:r=true,showFullscreen:s=true,...a})=>{let l=y(),i=o&&n,c=o&&r,d=o&&s,u=i||c||d;return jsxs("div",{className:l("my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2"),"data-streamdown":"table-wrapper",children:[u?jsxs("div",{className:l("flex items-center justify-end gap-1"),children:[i?jsx(Te,{}):null,c?jsx(Pe,{}):null,d?jsx(wo,{showCopy:i,showDownload:c,children:e}):null]}):null,jsx("div",{className:l("border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background"),children:jsx("table",{className:l("w-full divide-y divide-border",t),"data-streamdown":"table",...a,children:e})})]})};var Gr=/startLine=(\d+)/,Yr=lazy(()=>import('./mermaid-O7DHMXV3.js').then(e=>({default:e.Mermaid}))),Qr=/language-([^\s]+)/;function _e(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let o=e.position.start,n=t.position.start,r=e.position.end,s=t.position.end;return (o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(r==null?void 0:r.line)===(s==null?void 0:s.line)&&(r==null?void 0:r.column)===(s==null?void 0:s.column)}function E(e,t){return e.className===t.className&&_e(e.node,t.node)}var pt=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ut=(e,t)=>{if(typeof e=="boolean")return e;let o=e.table;return o===false?false:o===true||o===void 0?true:o[t]!==false},xo=(e,t)=>{if(typeof e=="boolean")return e;let o=e.code;return o===false?false:o===true||o===void 0?true:o[t]!==false},je=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===false?false:o===true||o===void 0?true:o[t]!==false},gt=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("ol",{className:r("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e})},(e,t)=>E(e,t));gt.displayName="MarkdownOl";var To=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("li",{className:r("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e})},(e,t)=>e.className===t.className&&_e(e.node,t.node));To.displayName="MarkdownLi";var Po=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("ul",{className:r("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e})},(e,t)=>E(e,t));Po.displayName="MarkdownUl";var Mo=memo(({className:e,node:t,...o})=>{let n=y();return jsx("hr",{className:n("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o})},(e,t)=>E(e,t));Mo.displayName="MarkdownHr";var Io=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("span",{className:r("font-semibold",t),"data-streamdown":"strong",...n,children:e})},(e,t)=>E(e,t));Io.displayName="MarkdownStrong";var es=({children:e,className:t,href:o,node:n,...r})=>{let s=y(),{linkSafety:a}=useContext(R),[l,i]=useState(false),c=o==="streamdown:incomplete-link",d=useCallback(async g=>{if(!(!(a!=null&&a.enabled&&o)||c)){if(g.preventDefault(),a.onLinkCheck&&await a.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}i(true);}},[a,o,c]),u=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),m=useCallback(()=>{i(false);},[]),p={url:o!=null?o:"",isOpen:l,onClose:m,onConfirm:u};return a!=null&&a.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:s("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":c,"data-streamdown":"link",onClick:d,type:"button",children:e}),a.renderModal?a.renderModal(p):jsx(ro,{...p})]}):jsx("a",{className:s("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":c,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...r,children:e})},No=memo(es,(e,t)=>E(e,t)&&e.href===t.href);No.displayName="MarkdownA";var Lo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h1",{className:r("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e})},(e,t)=>E(e,t));Lo.displayName="MarkdownH1";var Ro=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h2",{className:r("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e})},(e,t)=>E(e,t));Ro.displayName="MarkdownH2";var So=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h3",{className:r("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e})},(e,t)=>E(e,t));So.displayName="MarkdownH3";var Eo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h4",{className:r("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e})},(e,t)=>E(e,t));Eo.displayName="MarkdownH4";var Ho=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h5",{className:r("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e})},(e,t)=>E(e,t));Ho.displayName="MarkdownH5";var Do=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h6",{className:r("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e})},(e,t)=>E(e,t));Do.displayName="MarkdownH6";var Bo=memo(({children:e,className:t,node:o,...n})=>{let{controls:r}=useContext(R),s=pt(r,"table"),a=ut(r,"copy"),l=ut(r,"download"),i=ut(r,"fullscreen");return jsx(ko,{className:t,showControls:s,showCopy:a,showDownload:l,showFullscreen:i,...n,children:e})},(e,t)=>E(e,t));Bo.displayName="MarkdownTable";var Ao=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("thead",{className:r("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e})},(e,t)=>E(e,t));Ao.displayName="MarkdownThead";var Oo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("tbody",{className:r("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e})},(e,t)=>E(e,t));Oo.displayName="MarkdownTbody";var Vo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("tr",{className:r("border-border",t),"data-streamdown":"table-row",...n,children:e})},(e,t)=>E(e,t));Vo.displayName="MarkdownTr";var jo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("th",{className:r("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e})},(e,t)=>E(e,t));jo.displayName="MarkdownTh";var Fo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("td",{className:r("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e})},(e,t)=>E(e,t));Fo.displayName="MarkdownTd";var zo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("blockquote",{className:r("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e})},(e,t)=>E(e,t));zo.displayName="MarkdownBlockquote";var _o=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("sup",{className:r("text-sm",t),"data-streamdown":"superscript",...n,children:e})},(e,t)=>E(e,t));_o.displayName="MarkdownSup";var qo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("sub",{className:r("text-sm",t),"data-streamdown":"subscript",...n,children:e})},(e,t)=>E(e,t));qo.displayName="MarkdownSub";var $o=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=i=>{var m,p;if(!isValidElement(i))return false;let c=Array.isArray(i.props.children)?i.props.children:[i.props.children],d=false,u=false;for(let g of c)if(g){if(typeof g=="string")g.trim()!==""&&(d=true);else if(isValidElement(g))if(((m=g.props)==null?void 0:m["data-footnote-backref"])!==void 0)u=true;else {let h=Array.isArray(g.props.children)?g.props.children:[g.props.children];for(let b of h){if(typeof b=="string"&&b.trim()!==""){d=true;break}if(isValidElement(b)&&((p=b.props)==null?void 0:p["data-footnote-backref"])===void 0){d=true;break}}}}return u&&!d},a=Array.isArray(e)?e.map(i=>{if(!isValidElement(i))return i;if(i.type===gt){let d=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(u=>!s(u));return d.length===0?null:{...i,props:{...i.props,children:d}}}return i}):e;return (Array.isArray(a)?a.some(i=>i!==null):a!==null)?jsx("section",{className:t,...n,children:a}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>E(e,t));$o.displayName="MarkdownSection";var ts=({node:e,className:t,children:o,...n})=>{var k,I;let r=y(),s=!("data-block"in n),{mermaid:a,controls:l}=useContext(R),i=de(),c=et(),d=t==null?void 0:t.match(Qr),u=(k=d==null?void 0:d.at(1))!=null?k:"",m=so(u);if(s)return jsx("code",{className:r("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let p=(I=e==null?void 0:e.properties)==null?void 0:I.metastring,g=p==null?void 0:p.match(Gr),h=g?Number.parseInt(g[1],10):void 0,b=h!==void 0&&h>=1?h:void 0,f="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?f=o.props.children:typeof o=="string"&&(f=o),m){let H=m.component;return jsx(Suspense,{fallback:jsx(Ae,{}),children:jsx(H,{code:f,isIncomplete:c,language:u})})}if(u==="mermaid"&&i){let H=pt(l,"mermaid"),S=je(l,"download"),F=je(l,"copy"),z=je(l,"fullscreen"),q=je(l,"panZoom"),A=H&&(S||F||z);return jsx(Suspense,{fallback:jsx(Ae,{}),children:jsxs("div",{className:r("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",t),"data-streamdown":"mermaid-block",children:[jsx("div",{className:r("flex h-8 items-center text-muted-foreground text-xs"),children:jsx("span",{className:r("ml-1 font-mono lowercase"),children:"mermaid"})}),A?jsx("div",{className:r("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:jsxs("div",{className:r("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"mermaid-block-actions",children:[S?jsx(lo,{chart:f,config:a==null?void 0:a.config}):null,F?jsx(Be,{code:f}):null,z?jsx(po,{chart:f,config:a==null?void 0:a.config}):null]})}):null,jsx("div",{className:r("rounded-md border border-border bg-background"),children:jsx(Yr,{chart:f,config:a==null?void 0:a.config,showControls:q})})]})})}let T=pt(l,"code"),x=xo(l,"download"),w=xo(l,"copy");return jsx(rt,{className:t,code:f,isIncomplete:c,language:u,startLine:b,children:T?jsxs(Fragment,{children:[x?jsx(at,{code:f,language:u}):null,w?jsx(Be,{}):null]}):null})},Wo=memo(ts,(e,t)=>e.className===t.className&&_e(e.node,t.node));Wo.displayName="MarkdownCode";var Zo=memo(to,(e,t)=>e.className===t.className&&_e(e.node,t.node));Zo.displayName="MarkdownImg";var Xo=memo(({children:e,node:t,...o})=>{let r=(Array.isArray(e)?e:[e]).filter(s=>s!=null&&s!=="");if(r.length===1&&isValidElement(r[0])){let s=r[0].props.node,a=s==null?void 0:s.tagName;if(a==="img")return jsx(Fragment,{children:e});if(a==="code"&&"data-block"in r[0].props)return jsx(Fragment,{children:e})}return jsx("p",{...o,children:e})},(e,t)=>E(e,t));Xo.displayName="MarkdownParagraph";var Jo={ol:gt,li:To,ul:Po,hr:Mo,strong:Io,a:No,h1:Lo,h2:Ro,h3:So,h4:Eo,h5:Ho,h6:Do,table:Bo,thead:Ao,tbody:Oo,tr:Vo,th:jo,td:Fo,blockquote:zo,code:Wo,img:Zo,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:_o,sub:qo,p:Xo,section:$o};var os=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,ns=/\p{L}/u;function qe(e){let t=e.replace(/^#{1,6}\s+/gm,"").replace(/(\*{1,3}|_{1,3})/g,"").replace(/`[^`]*`/g,"").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/^[\s>*\-+\d.]+/gm,"");for(let o of t){if(os.test(o))return "rtl";if(ns.test(o))return "ltr"}return "ltr"}var rs=/^[ \t]{0,3}(`{3,}|~{3,})/,ss=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,bt=e=>{let t=e.split(`
11
- `),o=null,n=0;for(let r of t){let s=rs.exec(r);if(o===null){if(s){let a=s[1];o=a[0],n=a.length;}}else if(s){let a=s[1],l=a[0],i=a.length;l===o&&i>=n&&(o=null,n=0);}}return o!==null},Ko=e=>{let t=e.split(`
12
- `);for(let o of t){let n=o.trim();if(n.length>0&&n.includes("|")&&ss.test(n))return true}return false};var Uo=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var Yo=[],Qo={allowDangerousHtml:true},$e=new WeakMap,yt=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,r=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||r||s)){let u="default";return this.keyCache.set(t,u),u}let a=u=>{if(!u||u.length===0)return "";let m="";for(let p=0;p<u.length;p+=1){let g=u[p];if(p>0&&(m+=","),Array.isArray(g)){let[h,b]=g;if(typeof h=="function"){let f=$e.get(h);f||(f=h.name,$e.set(h,f)),m+=f;}else m+=String(h);m+=":",m+=JSON.stringify(b);}else if(typeof g=="function"){let h=$e.get(g);h||(h=g.name,$e.set(g,h)),m+=h;}else m+=String(g);}return m},l=a(n),i=a(r),c=s?JSON.stringify(s):"",d=`${i}::${l}::${c}`;return this.keyCache.set(t,d),d}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let r=this.cache.keys().next().value;r&&this.cache.delete(r);}this.cache.set(n,o);}clear(){this.cache.clear();}},en=new yt,wt=e=>{let t=gs(e),o=e.children||"",n=t.runSync(t.parse(o),o);return ks(n,e)},gs=e=>{let t=en.get(e);if(t)return t;let o=hs(e);return en.set(e,o),o},bs=e=>e.some(t=>Array.isArray(t)?t[0]===Go:t===Go),hs=e=>{let t=e.rehypePlugins||Yo,o=e.remarkPlugins||Yo,n=bs(t)?o:[...o,Uo],r=e.remarkRehypeOptions?{...Qo,...e.remarkRehypeOptions}:Qo;return unified().use(ms).use(n).use(us,r).use(t)},tn=e=>e,ys=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},ws=(e,t)=>{var o;for(let n in urlAttributes)if(Object.hasOwn(urlAttributes,n)&&Object.hasOwn(e.properties,n)){let r=e.properties[n],s=urlAttributes[n];(s===null||s.includes(e.tagName))&&(e.properties[n]=(o=t(String(r||""),n,e))!=null?o:void 0);}},Cs=(e,t,o,n,r,s)=>{let a=false;return n?a=!n.includes(e.tagName):r&&(a=r.includes(e.tagName)),!a&&s&&typeof t=="number"&&(a=!s(e,t,o)),a},ks=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:r,skipHtml:s,unwrapDisallowed:a,urlTransform:l}=t;if(o||n||r||s||l){let c=l||tn;visit(e,(d,u,m)=>{if(d.type==="raw"&&m&&typeof u=="number")return ys(m,u,s,d.value),u;if(d.type==="element"&&(ws(d,c),Cs(d,u,m,n,r,o)&&m&&typeof u=="number"))return a&&d.children?m.children.splice(u,1,...d.children):m.children.splice(u,1),u});}return toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true})};var xs=/\[\^[\w-]{1,200}\](?!:)/,Ts=/\[\^[\w-]{1,200}\]:/;var Ps=/<(\w+)[\s>]/,Ms=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),on=new Map,nn=new Map,Is=e=>{let t=e.toLowerCase(),o=on.get(t);if(o)return o;let n=new RegExp(`<${t}(?=[\\s>/])[^>]*>`,"gi");return on.set(t,n),n},Ns=e=>{let t=e.toLowerCase(),o=nn.get(t);if(o)return o;let n=new RegExp(`</${t}(?=[\\s>])[^>]*>`,"gi");return nn.set(t,n),n},rn=(e,t)=>{if(Ms.has(t.toLowerCase()))return 0;let o=e.match(Is(t));if(!o)return 0;let n=0;for(let r of o)r.trimEnd().endsWith("/>")||(n+=1);return n},sn=(e,t)=>{let o=e.match(Ns(t));return o?o.length:0},Ls=e=>{let t=0;for(let o=0;o<e.length-1;o+=1)e[o]==="$"&&e[o+1]==="$"&&(t+=1,o+=1);return t},Ct=e=>{let t=xs.test(e),o=Ts.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),r=[],s=[],a=false;for(let l of n){let i=l.raw,c=r.length;if(s.length>0){r[c-1]+=i;let d=s.at(-1),u=rn(i,d),m=sn(i,d);for(let p=0;p<u;p+=1)s.push(d);for(let p=0;p<m;p+=1)s.length>0&&s.at(-1)===d&&s.pop();continue}if(l.type==="html"&&l.block){let d=i.match(Ps);if(d){let u=d[1],m=rn(i,u),p=sn(i,u);m>p&&s.push(u);}}if(c>0&&!a){let d=r[c-1];if(Ls(d)%2===1){r[c-1]=d+i;continue}}r.push(i),l.type!=="space"&&(a=l.type==="code");}return r};var an=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>{let c=l.replace(/\n\n/g,`
13
- <!---->
14
- `);return a+c+i});}return o};var Rs=/([\\`*_~[\]|])/g,Ss=e=>e.replace(Rs,"\\$1"),ln=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>a+Ss(l)+i);}return o};var cn=e=>e.type==="text"?e.value:"children"in e&&Array.isArray(e.children)?e.children.map(cn).join(""):"",dn=e=>t=>{if(!e||e.length===0)return;let o=new Set(e.map(n=>n.toLowerCase()));visit(t,"element",n=>{if(o.has(n.tagName.toLowerCase())){let r=cn(n);n.children=r?[{type:"text",value:r}]:[];}});};var mn=()=>e=>{visit(e,"code",t=>{var o,n;t.meta&&(t.data=(o=t.data)!=null?o:{},t.data.hProperties={...(n=t.data.hProperties)!=null?n:{},metastring:t.meta});});};var _s=/^[ \t]*<[\w!/?-]/,qs=/(^|\n)[ \t]{4,}(?=<[\w!/?-])/g,$s=e=>typeof e!="string"||e.length===0||!_s.test(e)?e:e.replace(qs,"$1"),gn,bn,hn,yn,We={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(bn=(gn=defaultSchema.protocols)==null?void 0:gn.href)!=null?bn:[],"tel"]},attributes:{...defaultSchema.attributes,code:[...(yn=(hn=defaultSchema.attributes)==null?void 0:hn.code)!=null?yn:[],"metastring"]}},vt={raw:Go,sanitize:[Cn,We],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Ws={gfm:[Fs,{}],codeMeta:mn},fn=Object.values(vt),Zs=Object.values(Ws),Xs={block:" \u258B",circle:" \u25CF"},Js={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},R=createContext(Js),kn=memo(({content:e,shouldParseIncompleteMarkdown:t,shouldNormalizeHtmlIndentation:o,index:n,isIncomplete:r,dir:s,animatePlugin:a,...l})=>{if(a){let d=a.getLastRenderCharCount();a.setPrevContentLength(d);}let i=typeof e=="string"&&o?$s(e):e,c=jsx(wt,{...l,children:i});return jsx(Qe.Provider,{value:r,children:s?jsx("div",{dir:s,style:{display:"contents"},children:c}):c})},(e,t)=>{if(e.content!==t.content||e.shouldNormalizeHtmlIndentation!==t.shouldNormalizeHtmlIndentation||e.index!==t.index||e.isIncomplete!==t.isIncomplete||e.dir!==t.dir)return false;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(r=>{var s,a;return ((s=e.components)==null?void 0:s[r])!==((a=t.components)==null?void 0:a[r])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});kn.displayName="Block";var Ks=["github-light","github-dark"],Us=memo(({children:e,mode:t="streaming",dir:o,parseIncompleteMarkdown:n=true,normalizeHtmlIndentation:r=false,components:s,rehypePlugins:a=fn,remarkPlugins:l=Zs,className:i,shikiTheme:c=Ks,mermaid:d,controls:u=true,isAnimating:m=false,animated:p,BlockComponent:g=kn,parseMarkdownIntoBlocksFn:h=Ct,caret:b,plugins:f,remend:T,linkSafety:x={enabled:true},allowedTags:w,literalTagContent:k,translations:I,icons:H,prefix:S,onAnimationStart:F,onAnimationEnd:z,...q})=>{let A=useId(),[K,ae]=useTransition(),W=useMemo(()=>Ht(S),[S]),P=useRef(null),D=useRef(F),Y=useRef(z);D.current=F,Y.current=z,useEffect(()=>{var O,X,Q;if(t==="static")return;let v=P.current;if(P.current=m,v===null){m&&((O=D.current)==null||O.call(D));return}m&&!v?(X=D.current)==null||X.call(D):!m&&v&&((Q=Y.current)==null||Q.call(Y));},[m,t]);let Xe=useMemo(()=>w?Object.keys(w):[],[w]),Re=useMemo(()=>{if(typeof e!="string")return "";let v=t==="streaming"&&n?zs(e,T):e;return k&&k.length>0&&(v=ln(v,k)),Xe.length>0&&(v=an(v,Xe)),v},[e,t,n,T,Xe,k]),fe=useMemo(()=>h(Re),[Re,h]),[Mn,xt]=useState(fe);useEffect(()=>{t==="streaming"&&!ge?ae(()=>{xt(fe);}):xt(fe);},[fe,t]);let Z=t==="streaming"?Mn:fe,Je=useMemo(()=>o==="auto"?Z.map(qe):void 0,[Z,o]),In=useMemo(()=>Z.map((v,O)=>`${A}-${O}`),[Z.length,A]),Ke=useMemo(()=>p===true?"true":p?JSON.stringify(p):"",[p]),ge=useMemo(()=>Ke?Ke==="true"?be():be(p):null,[Ke]),Tt=useMemo(()=>{var v,O;return {shikiTheme:(O=(v=f==null?void 0:f.code)==null?void 0:v.getThemes())!=null?O:c,controls:u,isAnimating:m,mode:t,mermaid:d,linkSafety:x}},[c,u,m,t,d,x,f==null?void 0:f.code]),Nn=useMemo(()=>I?JSON.stringify(I):"",[I]),Pt=useMemo(()=>({...He,...I}),[Nn]),Mt=useMemo(()=>{let{inlineCode:v,...O}=s!=null?s:{},X={...Jo,...O};if(v){let Q=X.code;X.code=ie=>"data-block"in ie?Q?createElement(Q,ie):null:createElement(v,ie);}return X},[s]),It=useMemo(()=>{let v=[];return f!=null&&f.cjk&&(v=[...v,...f.cjk.remarkPluginsBefore]),v=[...v,...l],f!=null&&f.cjk&&(v=[...v,...f.cjk.remarkPluginsAfter]),f!=null&&f.math&&(v=[...v,f.math.remarkPlugin]),v},[l,f==null?void 0:f.math,f==null?void 0:f.cjk]),Nt=useMemo(()=>{var O;let v=a;if(w&&Object.keys(w).length>0&&a===fn){let X={...We,tagNames:[...(O=We.tagNames)!=null?O:[],...Object.keys(w)],attributes:{...We.attributes,...w}};v=[vt.raw,[Cn,X],vt.harden];}return k&&k.length>0&&(v=[...v,[dn,k]]),f!=null&&f.math&&(v=[...v,f.math.rehypePlugin]),ge&&m&&(v=[...v,ge.rehypePlugin]),v},[a,f==null?void 0:f.math,ge,m,w,k]),Ue=useMemo(()=>{if(!m||Z.length===0)return false;let v=Z.at(-1);return bt(v)||Ko(v)},[m,Z]),Ln=useMemo(()=>b&&m&&!Ue?{"--streamdown-caret":`"${Xs[b]}"`}:void 0,[b,m,Ue]);return t==="static"?jsx(De.Provider,{value:Pt,children:jsx(Oe.Provider,{value:f!=null?f:null,children:jsx(R.Provider,{value:Tt,children:jsx(st,{icons:H,children:jsx(Se.Provider,{value:W,children:jsx("div",{className:W("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",i),dir:o==="auto"?qe(Re):o,children:jsx(wt,{components:Mt,rehypePlugins:Nt,remarkPlugins:It,...q,children:Re})})})})})})}):jsx(De.Provider,{value:Pt,children:jsx(Oe.Provider,{value:f!=null?f:null,children:jsx(R.Provider,{value:Tt,children:jsx(st,{icons:H,children:jsx(Se.Provider,{value:W,children:jsxs("div",{className:W("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",b&&!Ue?"*:last:after:inline *:last:after:align-baseline *:last:after:content-[var(--streamdown-caret)]":null,i),style:Ln,children:[Z.length===0&&b&&m&&jsx("span",{}),Z.map((v,O)=>{var ie;let X=O===Z.length-1,Q=m&&X&&bt(v);return jsx(g,{animatePlugin:ge,components:Mt,content:v,dir:(ie=Je==null?void 0:Je[O])!=null?ie:o!=="auto"?o:void 0,index:O,isIncomplete:Q,rehypePlugins:Nt,remarkPlugins:It,shouldNormalizeHtmlIndentation:r,shouldParseIncompleteMarkdown:n,...q},In[O])})]})})})})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.animated===t.animated&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety&&e.normalizeHtmlIndentation===t.normalizeHtmlIndentation&&e.literalTagContent===t.literalTagContent&&JSON.stringify(e.translations)===JSON.stringify(t.translations)&&e.prefix===t.prefix&&e.dir===t.dir);Us.displayName="Streamdown";var Pn=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:r=.1,showControls:s=true,initialZoom:a=1,fullscreen:l=false})=>{let{RotateCcwIcon:i,ZoomInIcon:c,ZoomOutIcon:d}=L(),u=y(),m=useRef(null),p=useRef(null),[g,h]=useState(a),[b,f]=useState({x:0,y:0}),[T,x]=useState(false),[w,k]=useState({x:0,y:0}),[I,H]=useState({x:0,y:0}),S=useCallback(P=>{h(D=>Math.max(o,Math.min(n,D+P)));},[o,n]),F=useCallback(()=>{S(r);},[S,r]),z=useCallback(()=>{S(-r);},[S,r]),q=useCallback(()=>{h(a),f({x:0,y:0});},[a]),A=useCallback(P=>{P.preventDefault();let D=P.deltaY>0?-r:r;S(D);},[S,r]),K=useCallback(P=>{if(P.button!==0||P.isPrimary===false)return;x(true),k({x:P.clientX,y:P.clientY}),H(b);let D=P.currentTarget;D instanceof HTMLElement&&D.setPointerCapture(P.pointerId);},[b]),ae=useCallback(P=>{if(!T)return;P.preventDefault();let D=P.clientX-w.x,Y=P.clientY-w.y;f({x:I.x+D,y:I.y+Y});},[T,w,I]),W=useCallback(P=>{x(false);let D=P.currentTarget;D instanceof HTMLElement&&D.releasePointerCapture(P.pointerId);},[]);return useEffect(()=>{let P=m.current;if(P)return P.addEventListener("wheel",A,{passive:false}),()=>{P.removeEventListener("wheel",A);}},[A]),useEffect(()=>{let P=p.current;if(P&&T)return document.body.style.userSelect="none",P.addEventListener("pointermove",ae,{passive:false}),P.addEventListener("pointerup",W),P.addEventListener("pointercancel",W),()=>{document.body.style.userSelect="",P.removeEventListener("pointermove",ae),P.removeEventListener("pointerup",W),P.removeEventListener("pointercancel",W);}},[T,ae,W]),jsxs("div",{className:u("relative flex flex-col",l?"h-full w-full":"min-h-28 w-full",t),ref:m,style:{cursor:T?"grabbing":"grab"},children:[s?jsxs("div",{className:u("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/80 p-1 supports-[backdrop-filter]:bg-background/70 supports-[backdrop-filter]:backdrop-blur-sm",l?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:u("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:g>=n,onClick:F,title:"Zoom in",type:"button",children:jsx(c,{size:16})}),jsx("button",{className:u("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:g<=o,onClick:z,title:"Zoom out",type:"button",children:jsx(d,{size:16})}),jsx("button",{className:u("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"),onClick:q,title:"Reset zoom and pan",type:"button",children:jsx(i,{size:16})})]}):null,jsx("div",{className:u("flex-1 origin-center transition-transform duration-150 ease-out",l?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:K,ref:p,role:"application",style:{transform:`translate(${b.x}px, ${b.y}px) scale(${g})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var uo=({chart:e,className:t,config:o,fullscreen:n=false,showControls:r=true})=>{let s=y(),[a,l]=useState(null),[i,c]=useState(false),[d,u]=useState(""),[m,p]=useState(""),[g,h]=useState(0),{mermaid:b}=useContext(R),f=de(),T=b==null?void 0:b.errorComponent,{shouldRender:x,containerRef:w}=Lt({immediate:n});if(useEffect(()=>{if(!x)return;if(!f){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),c(!0);let H=f.getMermaid(o),S=e.split("").reduce((q,A)=>(q<<5)-q+A.charCodeAt(0)|0,0),F=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:z}=await H.render(F,e);u(z),p(z);}catch(H){if(!(m||d)){let S=H instanceof Error?H.message:"Failed to render Mermaid chart";l(S);}}finally{c(false);}})();},[e,o,g,x,f]),!(x||d||m))return jsx("div",{className:s("my-4 min-h-[200px]",t),ref:w});if(i&&!d&&!m)return jsx("div",{className:s("my-4 flex justify-center p-4",t),ref:w,children:jsxs("div",{className:s("flex items-center space-x-2 text-muted-foreground"),children:[jsx("div",{className:s("h-4 w-4 animate-spin rounded-full border-current border-b-2")}),jsx("span",{className:s("text-sm"),children:"Loading diagram..."})]})});if(a&&!d&&!m){let I=()=>h(H=>H+1);return T?jsx("div",{ref:w,children:jsx(T,{chart:e,error:a,retry:I})}):jsxs("div",{className:s("rounded-md bg-red-50 p-4",t),ref:w,children:[jsxs("p",{className:s("font-mono text-red-700 text-sm"),children:["Mermaid Error: ",a]}),jsxs("details",{className:s("mt-2"),children:[jsx("summary",{className:s("cursor-pointer text-red-600 text-xs"),children:"Show Code"}),jsx("pre",{className:s("mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs"),children:e})]})]})}let k=d||m;return jsx("div",{className:s("size-full",t),"data-streamdown":"mermaid",ref:w,children:jsx(Pn,{className:s(n?"size-full overflow-hidden":"overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:s("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:k},role:"img"})})})};export{R as A,kn as B,Us as C,be as a,et as b,Bt as c,tt as d,nt as e,Mi as f,rt as g,He as h,Be as i,at as j,Ae as k,uo as l,ue as m,oe as n,ct as o,Ve as p,ne as q,Te as r,_r as s,Pe as t,qe as u,tn as v,Ct as w,$s as x,vt as y,Ws as z};
@@ -1,2 +0,0 @@
1
- "use client";
2
- import {A,f,c}from'./chunk-FRKYWMV7.js';import {useContext,useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';var R=({code:s,language:t,raw:e,className:h,startLine:d,...m})=>{let{shikiTheme:l}=useContext(A),o=f(),[p,i]=useState(e);return useEffect(()=>{if(!o){i(e);return}let r=o.highlight({code:s,language:t,themes:l},c=>{i(c);});r&&i(r);},[s,t,l,o,e]),jsx(c,{className:h,language:t,result:p,startLine:d,...m})};export{R as HighlightedCodeBlockBody};
@@ -1,2 +0,0 @@
1
- "use client";
2
- export{l as Mermaid}from'./chunk-FRKYWMV7.js';