streamdown 2.3.0 → 2.4.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 +10 -1
- package/dist/chunk-FRKYWMV7.js +14 -0
- package/dist/highlighted-body-TPN3WLV5.js +2 -0
- package/dist/index.d.ts +216 -12
- package/dist/index.js +1 -1
- package/dist/mermaid-O7DHMXV3.js +2 -0
- package/package.json +4 -4
- package/dist/chunk-RLXIAIE6.js +0 -13
- package/dist/highlighted-body-B3W2YXNL.js +0 -2
- package/dist/mermaid-3ZIDBTTL.js +0 -2
package/README.md
CHANGED
|
@@ -36,6 +36,15 @@ Then, update your Tailwind `globals.css` to include the following so that Tailwi
|
|
|
36
36
|
|
|
37
37
|
The path must be relative from your CSS file to the `node_modules` folder containing `streamdown`. In a standard Next.js project where `globals.css` lives in `app/`, the default path above should work.
|
|
38
38
|
|
|
39
|
+
If you install optional Streamdown plugins, add their matching `@source` lines from the relevant plugin docs (`/docs/plugins/code`, `/docs/plugins/cjk`, `/docs/plugins/math`, `/docs/plugins/mermaid`). Only include plugin `@source` entries for packages that are actually installed.
|
|
40
|
+
|
|
41
|
+
Example:
|
|
42
|
+
|
|
43
|
+
```css
|
|
44
|
+
@source "../node_modules/@streamdown/code/dist/*.js";
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
39
48
|
### Monorepo setup
|
|
40
49
|
|
|
41
50
|
In a monorepo (npm workspaces, Turbo, pnpm, etc.), dependencies are typically hoisted to the root `node_modules`. You need to adjust the relative path to point there:
|
|
@@ -54,7 +63,7 @@ monorepo/
|
|
|
54
63
|
@source "../../../node_modules/streamdown/dist/*.js";
|
|
55
64
|
```
|
|
56
65
|
|
|
57
|
-
Adjust the number of `../` segments based on where your CSS file lives relative to the root `node_modules`.
|
|
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.
|
|
58
67
|
|
|
59
68
|
## Usage
|
|
60
69
|
|
|
@@ -0,0 +1,14 @@
|
|
|
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};
|
|
@@ -0,0 +1,2 @@
|
|
|
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};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
-
import { JSX, ComponentType } from 'react';
|
|
3
|
+
import react__default, { SVGProps, JSX, ComponentType, HTMLAttributes, ComponentProps } from 'react';
|
|
4
4
|
import { MermaidConfig } from 'mermaid';
|
|
5
5
|
import { RemendOptions } from 'remend';
|
|
6
|
-
import { BundledLanguage, BundledTheme } from 'shiki';
|
|
7
|
-
export { BundledLanguage, BundledTheme } from 'shiki';
|
|
8
6
|
import { Pluggable, PluggableList } from 'unified';
|
|
9
7
|
import { Element, Parents } from 'hast';
|
|
10
8
|
import { Options as Options$1 } from 'remark-rehype';
|
|
9
|
+
import { BundledTheme, ThemeRegistrationAny, BundledLanguage } from 'shiki';
|
|
10
|
+
export { BundledLanguage, BundledTheme, ThemeRegistrationAny } from 'shiki';
|
|
11
11
|
|
|
12
12
|
interface AnimatePlugin {
|
|
13
|
+
/**
|
|
14
|
+
* Returns the total HAST text node character count from the last
|
|
15
|
+
* rehype run, then resets to 0. Use this value as the argument to
|
|
16
|
+
* setPrevContentLength on the next render.
|
|
17
|
+
*/
|
|
18
|
+
getLastRenderCharCount: () => number;
|
|
13
19
|
name: "animate";
|
|
14
20
|
rehypePlugin: Pluggable;
|
|
21
|
+
/**
|
|
22
|
+
* Set the number of HAST text characters from a previous render.
|
|
23
|
+
* Characters up to this count will get duration=0ms, preventing
|
|
24
|
+
* re-animation of already-visible content during streaming updates.
|
|
25
|
+
*/
|
|
26
|
+
setPrevContentLength: (length: number) => void;
|
|
15
27
|
type: "animate";
|
|
16
28
|
}
|
|
17
29
|
interface AnimateOptions {
|
|
@@ -22,6 +34,22 @@ interface AnimateOptions {
|
|
|
22
34
|
}
|
|
23
35
|
declare function createAnimatePlugin(options?: AnimateOptions): AnimatePlugin;
|
|
24
36
|
|
|
37
|
+
type IconComponent = React.ComponentType<SVGProps<SVGSVGElement> & {
|
|
38
|
+
size?: number;
|
|
39
|
+
}>;
|
|
40
|
+
interface IconMap {
|
|
41
|
+
CheckIcon: IconComponent;
|
|
42
|
+
CopyIcon: IconComponent;
|
|
43
|
+
DownloadIcon: IconComponent;
|
|
44
|
+
ExternalLinkIcon: IconComponent;
|
|
45
|
+
Loader2Icon: IconComponent;
|
|
46
|
+
Maximize2Icon: IconComponent;
|
|
47
|
+
RotateCcwIcon: IconComponent;
|
|
48
|
+
XIcon: IconComponent;
|
|
49
|
+
ZoomInIcon: IconComponent;
|
|
50
|
+
ZoomOutIcon: IconComponent;
|
|
51
|
+
}
|
|
52
|
+
|
|
25
53
|
interface ExtraProps {
|
|
26
54
|
node?: Element | undefined;
|
|
27
55
|
}
|
|
@@ -30,6 +58,7 @@ type UrlTransform = (url: string, key: string, node: Readonly<Element>) => strin
|
|
|
30
58
|
type Components = {
|
|
31
59
|
[Key in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Key] & ExtraProps> | keyof JSX.IntrinsicElements;
|
|
32
60
|
} & {
|
|
61
|
+
inlineCode?: ComponentType<JSX.IntrinsicElements["code"] & ExtraProps>;
|
|
33
62
|
[key: string]: ComponentType<Record<string, unknown> & ExtraProps> | keyof JSX.IntrinsicElements | undefined;
|
|
34
63
|
};
|
|
35
64
|
interface Options {
|
|
@@ -47,6 +76,7 @@ interface Options {
|
|
|
47
76
|
}
|
|
48
77
|
declare const defaultUrlTransform: UrlTransform;
|
|
49
78
|
|
|
79
|
+
type ThemeInput = BundledTheme | ThemeRegistrationAny;
|
|
50
80
|
/**
|
|
51
81
|
* A single token in a highlighted line
|
|
52
82
|
*/
|
|
@@ -73,7 +103,7 @@ interface HighlightResult {
|
|
|
73
103
|
interface HighlightOptions {
|
|
74
104
|
code: string;
|
|
75
105
|
language: BundledLanguage;
|
|
76
|
-
themes: [
|
|
106
|
+
themes: [ThemeInput, ThemeInput];
|
|
77
107
|
}
|
|
78
108
|
/**
|
|
79
109
|
* Plugin for code syntax highlighting (Shiki)
|
|
@@ -86,7 +116,7 @@ interface CodeHighlighterPlugin {
|
|
|
86
116
|
/**
|
|
87
117
|
* Get the configured themes
|
|
88
118
|
*/
|
|
89
|
-
getThemes: () => [
|
|
119
|
+
getThemes: () => [ThemeInput, ThemeInput];
|
|
90
120
|
/**
|
|
91
121
|
* Highlight code and return tokens
|
|
92
122
|
* Returns null if highlighting not ready yet (async loading)
|
|
@@ -165,6 +195,15 @@ interface CjkPlugin {
|
|
|
165
195
|
remarkPluginsBefore: Pluggable[];
|
|
166
196
|
type: "cjk";
|
|
167
197
|
}
|
|
198
|
+
interface CustomRendererProps {
|
|
199
|
+
code: string;
|
|
200
|
+
isIncomplete: boolean;
|
|
201
|
+
language: string;
|
|
202
|
+
}
|
|
203
|
+
interface CustomRenderer {
|
|
204
|
+
component: react__default.ComponentType<CustomRendererProps>;
|
|
205
|
+
language: string | string[];
|
|
206
|
+
}
|
|
168
207
|
/**
|
|
169
208
|
* Plugin configuration passed to Streamdown
|
|
170
209
|
*/
|
|
@@ -173,7 +212,41 @@ interface PluginConfig {
|
|
|
173
212
|
code?: CodeHighlighterPlugin;
|
|
174
213
|
math?: MathPlugin;
|
|
175
214
|
mermaid?: DiagramPlugin;
|
|
215
|
+
renderers?: CustomRenderer[];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface StreamdownTranslations {
|
|
219
|
+
close: string;
|
|
220
|
+
copied: string;
|
|
221
|
+
copyCode: string;
|
|
222
|
+
copyLink: string;
|
|
223
|
+
copyTable: string;
|
|
224
|
+
copyTableAsCsv: string;
|
|
225
|
+
copyTableAsMarkdown: string;
|
|
226
|
+
copyTableAsTsv: string;
|
|
227
|
+
downloadDiagram: string;
|
|
228
|
+
downloadDiagramAsMmd: string;
|
|
229
|
+
downloadDiagramAsPng: string;
|
|
230
|
+
downloadDiagramAsSvg: string;
|
|
231
|
+
downloadFile: string;
|
|
232
|
+
downloadImage: string;
|
|
233
|
+
downloadTable: string;
|
|
234
|
+
downloadTableAsCsv: string;
|
|
235
|
+
downloadTableAsMarkdown: string;
|
|
236
|
+
exitFullscreen: string;
|
|
237
|
+
externalLinkWarning: string;
|
|
238
|
+
imageNotAvailable: string;
|
|
239
|
+
mermaidFormatMmd: string;
|
|
240
|
+
mermaidFormatPng: string;
|
|
241
|
+
mermaidFormatSvg: string;
|
|
242
|
+
openExternalLink: string;
|
|
243
|
+
openLink: string;
|
|
244
|
+
tableFormatCsv: string;
|
|
245
|
+
tableFormatMarkdown: string;
|
|
246
|
+
tableFormatTsv: string;
|
|
247
|
+
viewFullscreen: string;
|
|
176
248
|
}
|
|
249
|
+
declare const defaultTranslations: StreamdownTranslations;
|
|
177
250
|
|
|
178
251
|
/**
|
|
179
252
|
* Hook to check if the current block has an incomplete (unclosed) code fence.
|
|
@@ -184,8 +257,100 @@ interface PluginConfig {
|
|
|
184
257
|
*/
|
|
185
258
|
declare const useIsCodeFenceIncomplete: () => boolean;
|
|
186
259
|
|
|
260
|
+
type CodeBlockProps = HTMLAttributes<HTMLDivElement> & {
|
|
261
|
+
code: string;
|
|
262
|
+
language: string;
|
|
263
|
+
/** Whether the code block is still being streamed (incomplete) */
|
|
264
|
+
isIncomplete?: boolean;
|
|
265
|
+
/** Custom starting line number for line numbering (default: 1) */
|
|
266
|
+
startLine?: number;
|
|
267
|
+
};
|
|
268
|
+
declare const CodeBlock: ({ code, language, className, children, isIncomplete, startLine, ...rest }: CodeBlockProps) => react_jsx_runtime.JSX.Element;
|
|
269
|
+
|
|
270
|
+
type CodeBlockContainerProps = ComponentProps<"div"> & {
|
|
271
|
+
language: string;
|
|
272
|
+
/** Whether the code block is still being streamed (incomplete) */
|
|
273
|
+
isIncomplete?: boolean;
|
|
274
|
+
};
|
|
275
|
+
declare const CodeBlockContainer: ({ className, language, style, isIncomplete, ...props }: CodeBlockContainerProps) => react_jsx_runtime.JSX.Element;
|
|
276
|
+
|
|
277
|
+
type CodeBlockCopyButtonProps = ComponentProps<"button"> & {
|
|
278
|
+
onCopy?: () => void;
|
|
279
|
+
onError?: (error: Error) => void;
|
|
280
|
+
timeout?: number;
|
|
281
|
+
};
|
|
282
|
+
declare const CodeBlockCopyButton: ({ onCopy, onError, timeout, children, className, code: propCode, ...props }: CodeBlockCopyButtonProps & {
|
|
283
|
+
code?: string;
|
|
284
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
285
|
+
|
|
286
|
+
type CodeBlockDownloadButtonProps = ComponentProps<"button"> & {
|
|
287
|
+
onDownload?: () => void;
|
|
288
|
+
onError?: (error: Error) => void;
|
|
289
|
+
};
|
|
290
|
+
declare const CodeBlockDownloadButton: ({ onDownload, onError, language, children, className, code: propCode, ...props }: CodeBlockDownloadButtonProps & {
|
|
291
|
+
code?: string;
|
|
292
|
+
language?: string;
|
|
293
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
294
|
+
|
|
295
|
+
interface CodeBlockHeaderProps {
|
|
296
|
+
language: string;
|
|
297
|
+
}
|
|
298
|
+
declare const CodeBlockHeader: ({ language }: CodeBlockHeaderProps) => react_jsx_runtime.JSX.Element;
|
|
299
|
+
|
|
300
|
+
declare const CodeBlockSkeleton: () => react_jsx_runtime.JSX.Element;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Detect text direction using the "first strong character" algorithm.
|
|
304
|
+
* Strips common markdown syntax then finds the first Unicode letter
|
|
305
|
+
* with strong directionality.
|
|
306
|
+
*
|
|
307
|
+
* Note: markdown stripping is best-effort — nested formatting,
|
|
308
|
+
* multi-line fenced code blocks, and raw HTML are not fully handled.
|
|
309
|
+
* This is acceptable since the algorithm only needs to reach the first
|
|
310
|
+
* strong character, which is almost always in plain prose.
|
|
311
|
+
*
|
|
312
|
+
* @returns "rtl" if first strong char is RTL, "ltr" otherwise
|
|
313
|
+
*/
|
|
314
|
+
declare function detectTextDirection(text: string): "ltr" | "rtl";
|
|
315
|
+
|
|
187
316
|
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
188
317
|
|
|
318
|
+
interface TableCopyDropdownProps {
|
|
319
|
+
children?: React.ReactNode;
|
|
320
|
+
className?: string;
|
|
321
|
+
onCopy?: (format: "csv" | "tsv" | "md") => void;
|
|
322
|
+
onError?: (error: Error) => void;
|
|
323
|
+
timeout?: number;
|
|
324
|
+
}
|
|
325
|
+
declare const TableCopyDropdown: ({ children, className, onCopy, onError, timeout, }: TableCopyDropdownProps) => react_jsx_runtime.JSX.Element;
|
|
326
|
+
|
|
327
|
+
interface TableDownloadButtonProps {
|
|
328
|
+
children?: React.ReactNode;
|
|
329
|
+
className?: string;
|
|
330
|
+
filename?: string;
|
|
331
|
+
format?: "csv" | "markdown";
|
|
332
|
+
onDownload?: () => void;
|
|
333
|
+
onError?: (error: Error) => void;
|
|
334
|
+
}
|
|
335
|
+
declare const TableDownloadButton: ({ children, className, onDownload, onError, format, filename, }: TableDownloadButtonProps) => react_jsx_runtime.JSX.Element;
|
|
336
|
+
interface TableDownloadDropdownProps {
|
|
337
|
+
children?: React.ReactNode;
|
|
338
|
+
className?: string;
|
|
339
|
+
onDownload?: (format: "csv" | "markdown") => void;
|
|
340
|
+
onError?: (error: Error) => void;
|
|
341
|
+
}
|
|
342
|
+
declare const TableDownloadDropdown: ({ children, className, onDownload, onError, }: TableDownloadDropdownProps) => react_jsx_runtime.JSX.Element;
|
|
343
|
+
|
|
344
|
+
interface TableData {
|
|
345
|
+
headers: string[];
|
|
346
|
+
rows: string[][];
|
|
347
|
+
}
|
|
348
|
+
declare const extractTableDataFromElement: (tableElement: HTMLElement) => TableData;
|
|
349
|
+
declare const tableDataToCSV: (data: TableData) => string;
|
|
350
|
+
declare const tableDataToTSV: (data: TableData) => string;
|
|
351
|
+
declare const escapeMarkdownTableCell: (cell: string) => string;
|
|
352
|
+
declare const tableDataToMarkdown: (data: TableData) => string;
|
|
353
|
+
|
|
189
354
|
/**
|
|
190
355
|
* Normalizes indentation in HTML blocks to prevent Markdown parsers from
|
|
191
356
|
* treating indented HTML tags as code blocks (4+ spaces = code in Markdown).
|
|
@@ -198,8 +363,15 @@ declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
|
198
363
|
*/
|
|
199
364
|
declare const normalizeHtmlIndentation: (content: string) => string;
|
|
200
365
|
type ControlsConfig = boolean | {
|
|
201
|
-
table?: boolean
|
|
202
|
-
|
|
366
|
+
table?: boolean | {
|
|
367
|
+
copy?: boolean;
|
|
368
|
+
download?: boolean;
|
|
369
|
+
fullscreen?: boolean;
|
|
370
|
+
};
|
|
371
|
+
code?: boolean | {
|
|
372
|
+
copy?: boolean;
|
|
373
|
+
download?: boolean;
|
|
374
|
+
};
|
|
203
375
|
mermaid?: boolean | {
|
|
204
376
|
download?: boolean;
|
|
205
377
|
copy?: boolean;
|
|
@@ -230,13 +402,15 @@ interface MermaidOptions {
|
|
|
230
402
|
type AllowedTags = Record<string, string[]>;
|
|
231
403
|
type StreamdownProps = Options & {
|
|
232
404
|
mode?: "static" | "streaming";
|
|
405
|
+
/** Text direction for blocks. "auto" detects per-block using first strong character algorithm. */
|
|
406
|
+
dir?: "auto" | "ltr" | "rtl";
|
|
233
407
|
BlockComponent?: React.ComponentType<BlockProps>;
|
|
234
408
|
parseMarkdownIntoBlocksFn?: (markdown: string) => string[];
|
|
235
409
|
parseIncompleteMarkdown?: boolean;
|
|
236
410
|
/** Normalize HTML block indentation to prevent 4+ spaces being treated as code blocks. @default false */
|
|
237
411
|
normalizeHtmlIndentation?: boolean;
|
|
238
412
|
className?: string;
|
|
239
|
-
shikiTheme?: [
|
|
413
|
+
shikiTheme?: [ThemeInput, ThemeInput];
|
|
240
414
|
mermaid?: MermaidOptions;
|
|
241
415
|
controls?: ControlsConfig;
|
|
242
416
|
isAnimating?: boolean;
|
|
@@ -247,6 +421,32 @@ type StreamdownProps = Options & {
|
|
|
247
421
|
linkSafety?: LinkSafetyConfig;
|
|
248
422
|
/** Custom tags to allow through sanitization with their permitted attributes */
|
|
249
423
|
allowedTags?: AllowedTags;
|
|
424
|
+
/**
|
|
425
|
+
* Tags whose children should be treated as plain text (no markdown parsing).
|
|
426
|
+
* Useful for mention/entity tags in AI UIs where child content is a data
|
|
427
|
+
* label rather than prose. Requires the tag to also be listed in `allowedTags`.
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```tsx
|
|
431
|
+
* <Streamdown
|
|
432
|
+
* allowedTags={{ mention: ['user_id'] }}
|
|
433
|
+
* literalTagContent={['mention']}
|
|
434
|
+
* >
|
|
435
|
+
* {`<mention user_id="123">@_some_username_</mention>`}
|
|
436
|
+
* </Streamdown>
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
literalTagContent?: string[];
|
|
440
|
+
/** Override UI strings for i18n / custom labels */
|
|
441
|
+
translations?: Partial<StreamdownTranslations>;
|
|
442
|
+
/** Custom icons to override the default icons used in controls */
|
|
443
|
+
icons?: Partial<IconMap>;
|
|
444
|
+
/** 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
|
+
prefix?: string;
|
|
446
|
+
/** Called when isAnimating transitions from false to true. Suppressed in mode="static". */
|
|
447
|
+
onAnimationStart?: () => void;
|
|
448
|
+
/** Called when isAnimating transitions from true to false. Suppressed in mode="static". */
|
|
449
|
+
onAnimationEnd?: () => void;
|
|
250
450
|
};
|
|
251
451
|
declare const defaultRehypePlugins: Record<string, Pluggable>;
|
|
252
452
|
declare const defaultRemarkPlugins: Record<string, Pluggable>;
|
|
@@ -260,7 +460,7 @@ interface StreamdownContextType {
|
|
|
260
460
|
linkSafety?: LinkSafetyConfig;
|
|
261
461
|
mermaid?: MermaidOptions;
|
|
262
462
|
mode: "static" | "streaming";
|
|
263
|
-
shikiTheme: [
|
|
463
|
+
shikiTheme: [ThemeInput, ThemeInput];
|
|
264
464
|
}
|
|
265
465
|
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
266
466
|
type BlockProps = Options & {
|
|
@@ -270,8 +470,12 @@ type BlockProps = Options & {
|
|
|
270
470
|
index: number;
|
|
271
471
|
/** Whether this block is incomplete (still being streamed) */
|
|
272
472
|
isIncomplete: boolean;
|
|
473
|
+
/** Resolved text direction for this block */
|
|
474
|
+
dir?: "ltr" | "rtl";
|
|
475
|
+
/** Animate plugin instance for tracking previous content length */
|
|
476
|
+
animatePlugin?: AnimatePlugin | null;
|
|
273
477
|
};
|
|
274
|
-
declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown: _, shouldNormalizeHtmlIndentation, index: __, isIncomplete, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
275
|
-
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, normalizeHtmlIndentation: shouldNormalizeHtmlIndentation, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, animated, BlockComponent, parseMarkdownIntoBlocksFn, caret, plugins, remend: remendOptions, linkSafety, allowedTags, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
478
|
+
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>;
|
|
276
480
|
|
|
277
|
-
export { type AllowElement, type AllowedTags, type AnimateOptions, Block, type BlockProps, type CjkPlugin, type CodeHighlighterPlugin, type Components, type ControlsConfig, type DiagramPlugin, type ExtraProps, type HighlightOptions, type LinkSafetyConfig, type LinkSafetyModalProps, type MathPlugin, type MermaidErrorComponentProps, type MermaidOptions, type PluginConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, type UrlTransform, createAnimatePlugin, defaultRehypePlugins, defaultRemarkPlugins, defaultUrlTransform, normalizeHtmlIndentation, parseMarkdownIntoBlocks, useIsCodeFenceIncomplete };
|
|
481
|
+
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{
|
|
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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamdown",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"tsup": "^8.5.1",
|
|
45
45
|
"vitest": "^4.0.15",
|
|
46
46
|
"@streamdown/cjk": "1.0.2",
|
|
47
|
-
"@streamdown/
|
|
48
|
-
"@streamdown/
|
|
47
|
+
"@streamdown/math": "1.0.2",
|
|
48
|
+
"@streamdown/mermaid": "1.0.2"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"unified": "^11.0.5",
|
|
67
67
|
"unist-util-visit": "^5.0.0",
|
|
68
68
|
"unist-util-visit-parents": "^6.0.0",
|
|
69
|
-
"remend": "1.2.
|
|
69
|
+
"remend": "1.2.2"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"build": "tsup",
|
package/dist/chunk-RLXIAIE6.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {createContext,memo,useMemo,lazy,useContext,isValidElement,useId,useTransition,useState,useEffect,cloneElement,useCallback,useRef,Suspense}from'react';import {harden}from'rehype-harden';import po from'rehype-raw';import To,{defaultSchema}from'rehype-sanitize';import Er from'remark-gfm';import Hr 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 ar from'remark-parse';import ir from'remark-rehype';import {unified}from'unified';import {visit}from'unist-util-visit';import {Lexer}from'marked';var Oo=300,Vo="300px",Ao=500;function Ge(e={}){let{immediate:t=false,debounceDelay:o=Oo,rootMargin:n=Vo,idleTimeout:s=Ao}=e,[r,i]=useState(false),c=useRef(null),a=useRef(null),l=useRef(null),m=useMemo(()=>g=>{let b=Date.now();return window.setTimeout(()=>{g({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-b))});},1)},[]),d=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(g,b)=>window.requestIdleCallback(g,b):m,[m]),p=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?g=>window.cancelIdleCallback(g):g=>{clearTimeout(g);},[]);return useEffect(()=>{if(t){i(true);return}let g=c.current;if(!g)return;a.current&&(clearTimeout(a.current),a.current=null),l.current&&(p(l.current),l.current=null);let b=()=>{a.current&&(clearTimeout(a.current),a.current=null),l.current&&(p(l.current),l.current=null);},h=w=>{l.current=d(T=>{T.timeRemaining()>0||T.didTimeout?(i(true),w.disconnect()):l.current=d(()=>{i(true),w.disconnect();},{timeout:s/2});},{timeout:s});},u=w=>{b(),a.current=window.setTimeout(()=>{var S,B;let T=w.takeRecords();(T.length===0||(B=(S=T.at(-1))==null?void 0:S.isIntersecting)!=null&&B)&&h(w);},o);},C=(w,T)=>{w.isIntersecting?u(T):b();},k=new IntersectionObserver(w=>{for(let T of w)C(T,k);},{rootMargin:n,threshold:0});return k.observe(g),()=>{a.current&&clearTimeout(a.current),l.current&&p(l.current),k.disconnect();}},[t,o,n,s,p,d]),{shouldRender:r,containerRef:c}}var Ye=/\s/,qo=/^\s+$/,_o=new Set(["code","pre","svg","math","annotation"]),Zo=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",Wo=e=>e.some(t=>Zo(t)&&_o.has(t.tagName)),$o=e=>{let t=[],o="",n=false;for(let s of e){let r=Ye.test(s);r!==n&&o&&(t.push(o),o=""),o+=s,n=r;}return o&&t.push(o),t},Fo=e=>{let t=[],o="";for(let n of e)Ye.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},Uo=(e,t,o,n)=>({type:"element",tagName:"span",properties:{"data-sd-animate":true,style:`--sd-animation:sd-${t};--sd-duration:${o}ms;--sd-easing:${n}`},children:[{type:"text",value:e}]}),Xo=(e,t,o)=>{let n=t.at(-1);if(!(n&&"children"in n))return;if(Wo(t))return SKIP;let s=n,r=s.children.indexOf(e);if(r===-1)return;let i=e.value;if(!i.trim())return;let a=(o.sep==="char"?Fo(i):$o(i)).map(l=>qo.test(l)?{type:"text",value:l}:Uo(l,o.animation,o.duration,o.easing));return s.children.splice(r,1,...a),r+a.length};function Q(e){var n,s,r,i;let t={animation:(n=e==null?void 0:e.animation)!=null?n:"fadeIn",duration:(s=e==null?void 0:e.duration)!=null?s:150,easing:(r=e==null?void 0:e.easing)!=null?r:"ease",sep:(i=e==null?void 0:e.sep)!=null?i:"word"};return {name:"animate",type:"animate",rehypePlugin:()=>c=>{visitParents(c,"text",(a,l)=>Xo(a,l,t));}}}Q();var Re=createContext(false),Ie=()=>useContext(Re);var f=(...e)=>twMerge(clsx(e)),q=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s);};var tn=f("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"),on=e=>{let t={};for(let o of e.split(";")){let n=o.indexOf(":");if(n>0){let s=o.slice(0,n).trim(),r=o.slice(n+1).trim();s&&r&&(t[s]=r);}}return t},Qe=memo(({children:e,result:t,language:o,className:n,...s})=>{let r=useMemo(()=>{let i={};return t.bg&&(i["--sdm-bg"]=t.bg),t.fg&&(i["--sdm-fg"]=t.fg),t.rootStyle&&Object.assign(i,on(t.rootStyle)),i},[t.bg,t.fg,t.rootStyle]);return jsx("div",{className:f(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:f(n,"bg-[var(--sdm-bg,inherit]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]"),style:r,children:jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:t.tokens.map((i,c)=>jsx("span",{className:tn,children:i.map((a,l)=>{let m={},d=!!a.bgColor;if(a.color&&(m["--sdm-c"]=a.color),a.bgColor&&(m["--sdm-tbg"]=a.bgColor),a.htmlStyle)for(let[p,g]of Object.entries(a.htmlStyle))p==="color"?m["--sdm-c"]=g:p==="background-color"?(m["--sdm-tbg"]=g,d=true):m[p]=g;return jsx("span",{className:f("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",d&&"bg-[var(--sdm-tbg)]",d&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:m,...a.htmlAttrs,children:a.content},l)})},c))})})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className);var et=({className:e,language:t,style:o,isIncomplete:n,...s})=>jsx("div",{className:f("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},...s});var Se=createContext({code:""}),de=()=>useContext(Se);var ot=({language:e})=>jsx("div",{className:"flex h-8 items-center text-muted-foreground text-xs","data-language":e,"data-streamdown":"code-block-header",children:jsx("span",{className:"ml-1 font-mono lowercase",children:e})});var cn=/\n+$/,dn=lazy(()=>import('./highlighted-body-B3W2YXNL.js').then(e=>({default:e.HighlightedCodeBlockBody}))),rt=({code:e,language:t,className:o,children:n,isIncomplete:s=false,...r})=>{let i=useMemo(()=>e.replace(cn,""),[e]),c=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:i.split(`
|
|
3
|
-
`).map(a=>[{content:a,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[i]);return jsx(Se.Provider,{value:{code:e},children:jsxs(et,{isIncomplete:s,language:t,children:[jsx(ot,{language:t}),n?jsx("div",{className:"pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end",children:jsx("div",{className:"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(Qe,{className:o,language:t,result:c,...r}),children:jsx(dn,{className:o,code:i,language:t,raw:c,...r})})]})})};var J=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"})}),K=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"})}),Z=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"})}),st=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"})]}),at=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"})}),it=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"})}),me=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"})}),Ee=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"})}),lt=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"})}),ct=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 He=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:s,code:r,...i})=>{let[c,a]=useState(false),l=useRef(0),{code:m}=de(),{isAnimating:d}=useContext(R),p=r!=null?r:m,g=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{c||(await navigator.clipboard.writeText(p),a(!0),e==null||e(),l.current=window.setTimeout(()=>a(!1),o));}catch(u){t==null||t(u);}};useEffect(()=>()=>{window.clearTimeout(l.current);},[]);let b=c?J:K;return jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-copy-button",disabled:d,onClick:g,title:"Copy Code",type:"button",...i,children:n!=null?n:jsx(b,{size:14})})};var mt={"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"},ut=({onDownload:e,onError:t,language:o,children:n,className:s,code:r,...i})=>{let{code:c}=de(),{isAnimating:a}=useContext(R),l=r!=null?r:c,d=`file.${o&&o in mt?mt[o]:"txt"}`,p="text/plain",g=()=>{try{q(d,l,p),e==null||e();}catch(b){t==null||t(b);}};return jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-download-button",disabled:a,onClick:g,title:"Download file",type:"button",...i,children:n!=null?n:jsx(Z,{size:14})})};var ft=()=>jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsx(st,{className:"size-4 animate-spin"})})]});var Cn=/\.[^/.]+$/,ht=({node:e,className:t,src:o,alt:n,onLoad:s,onError:r,...i})=>{let c=useRef(null),[a,l]=useState(false),[m,d]=useState(false),p=i.width!=null||i.height!=null,g=(a||p)&&!m,b=m&&!p;useEffect(()=>{let k=c.current;if(k!=null&&k.complete){let w=k.naturalWidth>0;l(w),d(!w);}},[]);let h=useCallback(k=>{l(true),d(false),s==null||s(k);},[s]),u=useCallback(k=>{l(false),d(true),r==null||r(k);},[r]),C=async()=>{if(o)try{let w=await(await fetch(o)).blob(),H=new URL(o,window.location.origin).pathname.split("/").pop()||"",S=H.split(".").pop(),B=H.includes(".")&&S!==void 0&&S.length<=4,O="";if(B)O=H;else {let E=w.type,I="png";E.includes("jpeg")||E.includes("jpg")?I="jpg":E.includes("png")?I="png":E.includes("svg")?I="svg":E.includes("gif")?I="gif":E.includes("webp")&&(I="webp"),O=`${(n||H||"image").replace(Cn,"")}.${I}`;}q(O,w,w.type);}catch(k){window.open(o,"_blank");}};return o?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:f("max-w-full rounded-lg",b&&"hidden",t),"data-streamdown":"image",onError:u,onLoad:h,ref:c,src:o,...i}),b&&jsx("span",{className:"text-muted-foreground text-xs italic","data-streamdown":"image-fallback",children:"Image not available"}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),g&&jsx("button",{className:f("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:C,title:"Download image",type:"button",children:jsx(Z,{size:14})})]}):null};var oe=0,Mn=()=>{oe+=1,oe===1&&(document.body.style.overflow="hidden");},Tn=()=>{oe=Math.max(0,oe-1),oe===0&&(document.body.style.overflow="");},kt=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[s,r]=useState(false),i=useCallback(async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3);}catch(a){}},[e]),c=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){Mn();let a=l=>{l.key==="Escape"&&o();};return document.addEventListener("keydown",a),()=>{document.removeEventListener("keydown",a),Tn();}}},[t,o]),t?jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm","data-streamdown":"link-safety-modal",onClick:o,onKeyDown:a=>{a.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:"relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg",onClick:a=>a.stopPropagation(),onKeyDown:a=>a.stopPropagation(),role:"presentation",children:[jsx("button",{className:"absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:o,title:"Close",type:"button",children:jsx(me,{size:16})}),jsxs("div",{className:"flex flex-col gap-2",children:[jsxs("div",{className:"flex items-center gap-2 font-semibold text-lg",children:[jsx(Ee,{size:20}),jsx("span",{children:"Open external link?"})]}),jsx("p",{className:"text-muted-foreground text-sm",children:"You're about to visit an external website."})]}),jsx("div",{className:f("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:"flex gap-2",children:[jsx("button",{className:"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:i,type:"button",children:s?jsxs(Fragment,{children:[jsx(J,{size:14}),jsx("span",{children:"Copied"})]}):jsxs(Fragment,{children:[jsx(K,{size:14}),jsx("span",{children:"Copy link"})]})}),jsxs("button",{className:"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:c,type:"button",children:[jsx(Ee,{size:14}),jsx("span",{children:"Open link"})]})]})]})}):null};var pe=createContext(null),Ct=()=>useContext(pe),Ks=()=>{var t;let e=Ct();return (t=e==null?void 0:e.code)!=null?t:null},G=()=>{var t;let e=Ct();return (t=e==null?void 0:e.mermaid)!=null?t:null};var vt=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((s,r)=>{let i="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),c=new Image;c.crossOrigin="anonymous",c.onload=()=>{let a=document.createElement("canvas"),l=c.width*o,m=c.height*o;a.width=l,a.height=m;let d=a.getContext("2d");if(!d){r(new Error("Failed to create 2D canvas context for PNG export"));return}d.drawImage(c,0,0,l,m),a.toBlob(p=>{if(!p){r(new Error("Failed to create PNG blob"));return}s(p);},"image/png");},c.onerror=()=>r(new Error("Failed to load SVG image")),c.src=i;})};var Pt=({chart:e,children:t,className:o,onDownload:n,config:s,onError:r})=>{let[i,c]=useState(false),a=useRef(null),{isAnimating:l}=useContext(R),m=G(),d=async p=>{try{if(p==="mmd"){q("diagram.mmd",e,"text/plain"),c(!1),n==null||n(p);return}if(!m){r==null||r(new Error("Mermaid plugin not available"));return}let g=m.getMermaid(s),b=e.split("").reduce((C,k)=>(C<<5)-C+k.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:u}=await g.render(h,e);if(!u){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(p==="svg"){q("diagram.svg",u,"image/svg+xml"),c(!1),n==null||n(p);return}if(p==="png"){let C=await vt(u);q("diagram.png",C,"image/png"),n==null||n(p),c(!1);return}}catch(g){r==null||r(g);}};return useEffect(()=>{let p=g=>{let b=g.composedPath();a.current&&!b.includes(a.current)&&c(false);};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p);}},[]),jsxs("div",{className:"relative",ref:a,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:l,onClick:()=>c(!i),title:"Download diagram",type:"button",children:t!=null?t:jsx(Z,{size:14})}),i?jsxs("div",{className:"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:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var re=0,On=()=>{re+=1,re===1&&(document.body.style.overflow="hidden");},Vn=()=>{re=Math.max(0,re-1),re===0&&(document.body.style.overflow="");},Lt=({chart:e,config:t,onFullscreen:o,onExit:n,className:s,...r})=>{let[i,c]=useState(false),{isAnimating:a,controls:l}=useContext(R),m=(()=>{if(typeof l=="boolean")return l;let p=l.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),d=()=>{c(!i);};return useEffect(()=>{if(i){On();let p=g=>{g.key==="Escape"&&c(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),Vn();}}},[i]),useEffect(()=>{i?o==null||o():n&&n();},[i,o,n]),jsxs(Fragment,{children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:a,onClick:d,title:"View fullscreen",type:"button",...r,children:jsx(at,{size:14})}),i?createPortal(jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:d,onKeyDown:p=>{p.key==="Escape"&&d();},role:"button",tabIndex:0,children:[jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:d,title:"Exit fullscreen",type:"button",children:jsx(me,{size:20})}),jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsx(Nt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:m})})]}),document.body):null]})};var ue=e=>{var r,i;let t=[],o=[],n=e.querySelectorAll("thead th");for(let c of n)t.push(((r=c.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let c of s){let a=[],l=c.querySelectorAll("td");for(let m of l)a.push(((i=m.textContent)==null?void 0:i.trim())||"");o.push(a);}return {headers:t,rows:o}},fe=e=>{let{headers:t,rows:o}=e,n=c=>{let a=false,l=false;for(let m of c){if(m==='"'){a=true,l=true;break}(m===","||m===`
|
|
4
|
-
`)&&(a=true);}return a?l?`"${c.replace(/"/g,'""')}"`:`"${c}"`:c},s=t.length>0?o.length+1:o.length,r=new Array(s),i=0;t.length>0&&(r[i]=t.map(n).join(","),i+=1);for(let c of o)r[i]=c.map(n).join(","),i+=1;return r.join(`
|
|
5
|
-
`)},Rt=e=>{let{headers:t,rows:o}=e,n=c=>{let a=false;for(let m of c)if(m===" "||m===`
|
|
6
|
-
`||m==="\r"){a=true;break}if(!a)return c;let l=[];for(let m of c)m===" "?l.push("\\t"):m===`
|
|
7
|
-
`?l.push("\\n"):m==="\r"?l.push("\\r"):l.push(m);return l.join("")},s=t.length>0?o.length+1:o.length,r=new Array(s),i=0;t.length>0&&(r[i]=t.map(n).join(" "),i+=1);for(let c of o)r[i]=c.map(n).join(" "),i+=1;return r.join(`
|
|
8
|
-
`)},De=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("")},se=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),s=0,r=t.map(c=>De(c));n[s]=`| ${r.join(" | ")} |`,s+=1;let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]="---";n[s]=`| ${i.join(" | ")} |`,s+=1;for(let c of o)if(c.length<t.length){let a=new Array(t.length);for(let l=0;l<t.length;l+=1)a[l]=l<c.length?De(c[l]):"";n[s]=`| ${a.join(" | ")} |`,s+=1;}else {let a=c.map(l=>De(l));n[s]=`| ${a.join(" | ")} |`,s+=1;}return n.join(`
|
|
9
|
-
`)};var Ht=({children:e,className:t,onCopy:o,onError:n,timeout:s=2e3})=>{let[r,i]=useState(false),[c,a]=useState(false),l=useRef(null),m=useRef(0),{isAnimating:d}=useContext(R),p=async b=>{var h,u;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){n==null||n(new Error("Clipboard API not available"));return}try{let C=(u=l.current)==null?void 0:u.closest('[data-streamdown="table-wrapper"]'),k=C==null?void 0:C.querySelector("table");if(!k){n==null||n(new Error("Table not found"));return}let w=ue(k),S=({csv:fe,tsv:Rt,md:se}[b]||se)(w),B=new ClipboardItem({"text/plain":new Blob([S],{type:"text/plain"}),"text/html":new Blob([k.outerHTML],{type:"text/html"})});await navigator.clipboard.write([B]),a(!0),i(!1),o==null||o(b),m.current=window.setTimeout(()=>a(!1),s);}catch(C){n==null||n(C);}};useEffect(()=>{let b=h=>{let u=h.composedPath();l.current&&!u.includes(l.current)&&i(false);};return document.addEventListener("mousedown",b),()=>{document.removeEventListener("mousedown",b),window.clearTimeout(m.current);}},[]);let g=c?J:K;return jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:()=>i(!r),title:"Copy table",type:"button",children:e!=null?e:jsx(g,{size:14})}),r?jsxs("div",{className:"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:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("md"),title:"Copy table as Markdown",type:"button",children:"Markdown"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var Dt=({children:e,className:t,onDownload:o,onError:n})=>{let[s,r]=useState(false),i=useRef(null),{isAnimating:c}=useContext(R),a=l=>{var m;try{let d=(m=i.current)==null?void 0:m.closest('[data-streamdown="table-wrapper"]'),p=d==null?void 0:d.querySelector("table");if(!p){n==null||n(new Error("Table not found"));return}let g=ue(p),b=l==="csv"?fe(g):se(g);q(`table.${l==="csv"?"csv":"md"}`,b,l==="csv"?"text/csv":"text/markdown"),r(!1),o==null||o(l);}catch(d){n==null||n(d);}};return useEffect(()=>{let l=m=>{let d=m.composedPath();i.current&&!d.includes(i.current)&&r(false);};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l);}},[]),jsxs("div",{className:"relative",ref:i,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:c,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:jsx(Z,{size:14})}),s?jsxs("div",{className:"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:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>a("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>a("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var Vt=({children:e,className:t,showControls:o,...n})=>jsxs("div",{className:"my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2","data-streamdown":"table-wrapper",children:[o?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(Ht,{}),jsx(Dt,{})]}):null,jsx("div",{className:"border-collapse overflow-x-auto overscroll-y-auto rounded-md border border-border bg-background",children:jsx("table",{className:f("w-full divide-y divide-border",t),"data-streamdown":"table",...n,children:e})})]});var Jn=lazy(()=>import('./mermaid-3ZIDBTTL.js').then(e=>({default:e.Mermaid}))),Kn=/language-([^\s]+)/;function ke(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,s=e.position.end,r=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)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function N(e,t){return e.className===t.className&&ke(e.node,t.node)}var Ve=(e,t)=>typeof e=="boolean"?e:e[t]!==false,he=(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},je=memo(({children:e,className:t,node:o,...n})=>jsx("ol",{className:f("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>N(e,t));je.displayName="MarkdownOl";var At=memo(({children:e,className:t,node:o,...n})=>jsx("li",{className:f("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&ke(e.node,t.node));At.displayName="MarkdownLi";var jt=memo(({children:e,className:t,node:o,...n})=>jsx("ul",{className:f("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>N(e,t));jt.displayName="MarkdownUl";var zt=memo(({className:e,node:t,...o})=>jsx("hr",{className:f("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>N(e,t));zt.displayName="MarkdownHr";var qt=memo(({children:e,className:t,node:o,...n})=>jsx("span",{className:f("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>N(e,t));qt.displayName="MarkdownStrong";var Gn=({children:e,className:t,href:o,node:n,...s})=>{let{linkSafety:r}=useContext(R),[i,c]=useState(false),a=o==="streamdown:incomplete-link",l=useCallback(async g=>{if(!(!(r!=null&&r.enabled&&o)||a)){if(g.preventDefault(),r.onLinkCheck&&await r.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}c(true);}},[r,o,a]),m=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),d=useCallback(()=>{c(false);},[]),p={url:o!=null?o:"",isOpen:i,onClose:d,onConfirm:m};return r!=null&&r.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:f("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":a,"data-streamdown":"link",onClick:l,type:"button",children:e}),r.renderModal?r.renderModal(p):jsx(kt,{...p})]}):jsx("a",{className:f("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":a,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...s,children:e})},_t=memo(Gn,(e,t)=>N(e,t)&&e.href===t.href);_t.displayName="MarkdownA";var Zt=memo(({children:e,className:t,node:o,...n})=>jsx("h1",{className:f("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>N(e,t));Zt.displayName="MarkdownH1";var Wt=memo(({children:e,className:t,node:o,...n})=>jsx("h2",{className:f("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>N(e,t));Wt.displayName="MarkdownH2";var $t=memo(({children:e,className:t,node:o,...n})=>jsx("h3",{className:f("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>N(e,t));$t.displayName="MarkdownH3";var Ft=memo(({children:e,className:t,node:o,...n})=>jsx("h4",{className:f("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>N(e,t));Ft.displayName="MarkdownH4";var Ut=memo(({children:e,className:t,node:o,...n})=>jsx("h5",{className:f("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>N(e,t));Ut.displayName="MarkdownH5";var Xt=memo(({children:e,className:t,node:o,...n})=>jsx("h6",{className:f("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>N(e,t));Xt.displayName="MarkdownH6";var Jt=memo(({children:e,className:t,node:o,...n})=>{let{controls:s}=useContext(R),r=Ve(s,"table");return jsx(Vt,{className:t,showControls:r,...n,children:e})},(e,t)=>N(e,t));Jt.displayName="MarkdownTable";var Kt=memo(({children:e,className:t,node:o,...n})=>jsx("thead",{className:f("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>N(e,t));Kt.displayName="MarkdownThead";var Gt=memo(({children:e,className:t,node:o,...n})=>jsx("tbody",{className:f("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>N(e,t));Gt.displayName="MarkdownTbody";var Yt=memo(({children:e,className:t,node:o,...n})=>jsx("tr",{className:f("border-border",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>N(e,t));Yt.displayName="MarkdownTr";var Qt=memo(({children:e,className:t,node:o,...n})=>jsx("th",{className:f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>N(e,t));Qt.displayName="MarkdownTh";var eo=memo(({children:e,className:t,node:o,...n})=>jsx("td",{className:f("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>N(e,t));eo.displayName="MarkdownTd";var to=memo(({children:e,className:t,node:o,...n})=>jsx("blockquote",{className:f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>N(e,t));to.displayName="MarkdownBlockquote";var oo=memo(({children:e,className:t,node:o,...n})=>jsx("sup",{className:f("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>N(e,t));oo.displayName="MarkdownSup";var no=memo(({children:e,className:t,node:o,...n})=>jsx("sub",{className:f("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>N(e,t));no.displayName="MarkdownSub";var ro=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let r=a=>{var p,g;if(!isValidElement(a))return false;let l=Array.isArray(a.props.children)?a.props.children:[a.props.children],m=false,d=false;for(let b of l)if(b){if(typeof b=="string")b.trim()!==""&&(m=true);else if(isValidElement(b))if(((p=b.props)==null?void 0:p["data-footnote-backref"])!==void 0)d=true;else {let h=Array.isArray(b.props.children)?b.props.children:[b.props.children];for(let u of h){if(typeof u=="string"&&u.trim()!==""){m=true;break}if(isValidElement(u)&&((g=u.props)==null?void 0:g["data-footnote-backref"])===void 0){m=true;break}}}}return d&&!m},i=Array.isArray(e)?e.map(a=>{if(!isValidElement(a))return a;if(a.type===je){let m=(Array.isArray(a.props.children)?a.props.children:[a.props.children]).filter(d=>!r(d));return m.length===0?null:{...a,props:{...a.props,children:m}}}return a}):e;return (Array.isArray(i)?i.some(a=>a!==null):i!==null)?jsx("section",{className:t,...n,children:i}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>N(e,t));ro.displayName="MarkdownSection";var Yn=({node:e,className:t,children:o,...n})=>{var g;let s=!("data-block"in n),{mermaid:r,controls:i}=useContext(R),c=G(),a=Ie();if(s)return jsx("code",{className:f("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let l=t==null?void 0:t.match(Kn),m=(g=l==null?void 0:l.at(1))!=null?g:"",d="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?d=o.props.children:typeof o=="string"&&(d=o),m==="mermaid"&&c){let b=Ve(i,"mermaid"),h=he(i,"download"),u=he(i,"copy"),C=he(i,"fullscreen"),k=he(i,"panZoom"),w=b&&(h||u||C);return jsx(Suspense,{fallback:jsx(ft,{}),children:jsxs("div",{className:f("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:"flex h-8 items-center text-muted-foreground text-xs",children:jsx("span",{className:"ml-1 font-mono lowercase",children:"mermaid"})}),w?jsx("div",{className:"pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end",children:jsxs("div",{className:"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:[h?jsx(Pt,{chart:d,config:r==null?void 0:r.config}):null,u?jsx(He,{code:d}):null,C?jsx(Lt,{chart:d,config:r==null?void 0:r.config}):null]})}):null,jsx("div",{className:"rounded-md border border-border bg-background",children:jsx(Jn,{chart:d,config:r==null?void 0:r.config,showControls:k})})]})})}let p=Ve(i,"code");return jsx(rt,{className:t,code:d,isIncomplete:a,language:m,children:p?jsxs(Fragment,{children:[jsx(ut,{code:d,language:m}),jsx(He,{})]}):null})},so=memo(Yn,(e,t)=>e.className===t.className&&ke(e.node,t.node));so.displayName="MarkdownCode";var ao=memo(ht,(e,t)=>e.className===t.className&&ke(e.node,t.node));ao.displayName="MarkdownImg";var io=memo(({children:e,node:t,...o})=>{let s=(Array.isArray(e)?e:[e]).filter(r=>r!=null&&r!=="");if(s.length===1&&isValidElement(s[0])){let r=s[0].props.node,i=r==null?void 0:r.tagName;if(i==="img")return jsx(Fragment,{children:e});if(i==="code"&&"data-block"in s[0].props)return jsx(Fragment,{children:e})}return jsx("p",{...o,children:e})},(e,t)=>N(e,t));io.displayName="MarkdownParagraph";var lo={ol:je,li:At,ul:jt,hr:zt,strong:qt,a:_t,h1:Zt,h2:Wt,h3:$t,h4:Ft,h5:Ut,h6:Xt,table:Jt,thead:Kt,tbody:Gt,tr:Yt,th:Qt,td:eo,blockquote:to,code:so,img:ao,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:oo,sub:no,p:io,section:ro};var Qn=/^[ \t]{0,3}(`{3,}|~{3,})/,er=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,ze=e=>{let t=e.split(`
|
|
10
|
-
`),o=null,n=0;for(let s of t){let r=Qn.exec(s);if(o===null){if(r){let i=r[1];o=i[0],n=i.length;}}else if(r){let i=r[1],c=i[0],a=i.length;c===o&&a>=n&&(o=null,n=0);}}return o!==null},co=e=>{let t=e.split(`
|
|
11
|
-
`);for(let o of t){let n=o.trim();if(n.length>0&&n.includes("|")&&er.test(n))return true}return false};var mo=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var uo=[],fo={allowDangerousHtml:true},Ce=new WeakMap,_e=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,s=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(n||s||r)){let d="default";return this.keyCache.set(t,d),d}let i=d=>{if(!d||d.length===0)return "";let p="";for(let g=0;g<d.length;g+=1){let b=d[g];if(g>0&&(p+=","),Array.isArray(b)){let[h,u]=b;if(typeof h=="function"){let C=Ce.get(h);C||(C=h.name,Ce.set(h,C)),p+=C;}else p+=String(h);p+=":",p+=JSON.stringify(u);}else if(typeof b=="function"){let h=Ce.get(b);h||(h=b.name,Ce.set(b,h)),p+=h;}else p+=String(b);}return p},c=i(n),a=i(s),l=r?JSON.stringify(r):"",m=`${a}::${c}::${l}`;return this.keyCache.set(t,m),m}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 s=this.cache.keys().next().value;s&&this.cache.delete(s);}this.cache.set(n,o);}clear(){this.cache.clear();}},go=new _e,Ze=e=>{let t=dr(e),o=e.children||"";return br(t.runSync(t.parse(o),o),e)},dr=e=>{let t=go.get(e);if(t)return t;let o=pr(e);return go.set(e,o),o},mr=e=>e.some(t=>Array.isArray(t)?t[0]===po:t===po),pr=e=>{let t=e.rehypePlugins||uo,o=e.remarkPlugins||uo,n=mr(t)?o:[...o,mo],s=e.remarkRehypeOptions?{...fo,...e.remarkRehypeOptions}:fo;return unified().use(ar).use(n).use(ir,s).use(t)},bo=e=>e,ur=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},fr=(e,t)=>{var o;for(let n in urlAttributes)if(Object.hasOwn(urlAttributes,n)&&Object.hasOwn(e.properties,n)){let s=e.properties[n],r=urlAttributes[n];(r===null||r.includes(e.tagName))&&(e.properties[n]=(o=t(String(s||""),n,e))!=null?o:void 0);}},gr=(e,t,o,n,s,r)=>{let i=false;return n?i=!n.includes(e.tagName):s&&(i=s.includes(e.tagName)),!i&&r&&typeof t=="number"&&(i=!r(e,t,o)),i},br=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:s,skipHtml:r,unwrapDisallowed:i,urlTransform:c}=t;if(o||n||s||r||c){let l=c||bo;visit(e,(m,d,p)=>{if(m.type==="raw"&&p&&typeof d=="number")return ur(p,d,r,m.value),d;if(m.type==="element"&&(fr(m,l),gr(m,d,p,n,s,o)&&p&&typeof d=="number"))return i&&m.children?p.children.splice(d,1,...m.children):p.children.splice(d,1),d});}return toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true})};var yr=/\[\^[\w-]{1,200}\](?!:)/,wr=/\[\^[\w-]{1,200}\]:/;var kr=/<(\w+)[\s>]/,Cr=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ho=new Map,yo=new Map,vr=e=>{let t=e.toLowerCase(),o=ho.get(t);if(o)return o;let n=new RegExp(`<${t}(?=[\\s>/])[^>]*>`,"gi");return ho.set(t,n),n},xr=e=>{let t=e.toLowerCase(),o=yo.get(t);if(o)return o;let n=new RegExp(`</${t}(?=[\\s>])[^>]*>`,"gi");return yo.set(t,n),n},wo=(e,t)=>{if(Cr.has(t.toLowerCase()))return 0;let o=e.match(vr(t));if(!o)return 0;let n=0;for(let s of o)s.trimEnd().endsWith("/>")||(n+=1);return n},ko=(e,t)=>{let o=e.match(xr(t));return o?o.length:0},Pr=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},We=e=>{let t=yr.test(e),o=wr.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),s=[],r=[],i=false;for(let c of n){let a=c.raw,l=s.length;if(r.length>0){s[l-1]+=a;let m=r.at(-1),d=wo(a,m),p=ko(a,m);for(let g=0;g<d;g+=1)r.push(m);for(let g=0;g<p;g+=1)r.length>0&&r.at(-1)===m&&r.pop();continue}if(c.type==="html"&&c.block){let m=a.match(kr);if(m){let d=m[1],p=wo(a,d),g=ko(a,d);p>g&&r.push(d);}}if(l>0&&!i){let m=s[l-1];if(Pr(m)%2===1){s[l-1]=m+a;continue}}s.push(a),c.type!=="space"&&(i=c.type==="code");}return s};var Co=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let s=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(s,(r,i,c,a)=>{let l=c.replace(/\n\n/g,`
|
|
12
|
-
<!---->
|
|
13
|
-
`);return i+l+a});}return o};var Br=/^[ \t]*<[\w!/?-]/,Dr=/(^|\n)[ \t]{4,}(?=<[\w!/?-])/g,Or=e=>typeof e!="string"||e.length===0||!Br.test(e)?e:e.replace(Dr,"$1"),xo,Po,ve={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(Po=(xo=defaultSchema.protocols)==null?void 0:xo.href)!=null?Po:[],"tel"]}},Fe={raw:po,sanitize:[To,ve],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Vr={gfm:[Er,{}]},vo=Object.values(Fe),Ar=Object.values(Vr),jr={block:" \u258B",circle:" \u25CF"},zr={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},R=createContext(zr),No=memo(({content:e,shouldParseIncompleteMarkdown:t,shouldNormalizeHtmlIndentation:o,index:n,isIncomplete:s,...r})=>{let i=typeof e=="string"&&o?Or(e):e;return jsx(Re.Provider,{value:s,children:jsx(Ze,{...r,children:i})})},(e,t)=>{if(e.content!==t.content||e.shouldNormalizeHtmlIndentation!==t.shouldNormalizeHtmlIndentation||e.index!==t.index||e.isIncomplete!==t.isIncomplete)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(s=>{var r,i;return ((r=e.components)==null?void 0:r[s])!==((i=t.components)==null?void 0:i[s])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});No.displayName="Block";var qr=["github-light","github-dark"],_r=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,normalizeHtmlIndentation:n=false,components:s,rehypePlugins:r=vo,remarkPlugins:i=Ar,className:c,shikiTheme:a=qr,mermaid:l,controls:m=true,isAnimating:d=false,animated:p,BlockComponent:g=No,parseMarkdownIntoBlocksFn:b=We,caret:h,plugins:u,remend:C,linkSafety:k={enabled:true},allowedTags:w,...T})=>{let H=useId(),[S,B]=useTransition(),O=useMemo(()=>w?Object.keys(w):[],[w]),E=useMemo(()=>{if(typeof e!="string")return "";let x=t==="streaming"&&o?Hr(e,C):e;return O.length>0&&(x=Co(x,O)),x},[e,t,o,C,O]),I=useMemo(()=>b(E),[E,b]),[z,v]=useState(I);useEffect(()=>{t==="streaming"?B(()=>{v(I);}):v(I);},[I,t]);let L=t==="streaming"?z:I,ce=useMemo(()=>L.map((x,V)=>`${H}-${V}`),[L.length,H]),Pe=useMemo(()=>p?p===true?Q():Q(p):null,[p]),Ue=useMemo(()=>{var x,V;return {shikiTheme:(V=(x=u==null?void 0:u.code)==null?void 0:x.getThemes())!=null?V:a,controls:m,isAnimating:d,mode:t,mermaid:l,linkSafety:k}},[a,m,d,t,l,k,u==null?void 0:u.code]),Xe=useMemo(()=>({...lo,...s}),[s]),Je=useMemo(()=>{let x=[];return u!=null&&u.cjk&&(x=[...x,...u.cjk.remarkPluginsBefore]),x=[...x,...i],u!=null&&u.cjk&&(x=[...x,...u.cjk.remarkPluginsAfter]),u!=null&&u.math&&(x=[...x,u.math.remarkPlugin]),x},[i,u==null?void 0:u.math,u==null?void 0:u.cjk]),Ke=useMemo(()=>{var V;let x=r;if(w&&Object.keys(w).length>0&&r===vo){let Te={...ve,tagNames:[...(V=ve.tagNames)!=null?V:[],...Object.keys(w)],attributes:{...ve.attributes,...w}};x=[Fe.raw,[To,Te],Fe.harden];}return u!=null&&u.math&&(x=[...x,u.math.rehypePlugin]),Pe&&d&&(x=[...x,Pe.rehypePlugin]),x},[r,u==null?void 0:u.math,Pe,d,w]),Me=useMemo(()=>{if(!d||L.length===0)return false;let x=L.at(-1);return ze(x)||co(x)},[d,L]),Eo=useMemo(()=>h&&d&&!Me?{"--streamdown-caret":`"${jr[h]}"`}:void 0,[h,d,Me]);return t==="static"?jsx(pe.Provider,{value:u!=null?u:null,children:jsx(R.Provider,{value:Ue,children:jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",c),children:jsx(Ze,{components:Xe,rehypePlugins:Ke,remarkPlugins:Je,...T,children:E})})})}):jsx(pe.Provider,{value:u!=null?u:null,children:jsx(R.Provider,{value:Ue,children:jsxs("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",h&&!Me?"*:last:after:inline *:last:after:align-baseline *:last:after:content-[var(--streamdown-caret)]":null,c),style:Eo,children:[L.length===0&&h&&d&&jsx("span",{}),L.map((x,V)=>{let Te=V===L.length-1,Ho=d&&Te&&ze(x);return jsx(g,{components:Xe,content:x,index:V,isIncomplete:Ho,rehypePlugins:Ke,remarkPlugins:Je,shouldNormalizeHtmlIndentation:n,shouldParseIncompleteMarkdown:o,...T},ce[V])})]})})})},(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);_r.displayName="Streamdown";var So=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:s=.1,showControls:r=true,initialZoom:i=1,fullscreen:c=false})=>{let a=useRef(null),l=useRef(null),[m,d]=useState(i),[p,g]=useState({x:0,y:0}),[b,h]=useState(false),[u,C]=useState({x:0,y:0}),[k,w]=useState({x:0,y:0}),T=useCallback(v=>{d(L=>Math.max(o,Math.min(n,L+v)));},[o,n]),H=useCallback(()=>{T(s);},[T,s]),S=useCallback(()=>{T(-s);},[T,s]),B=useCallback(()=>{d(i),g({x:0,y:0});},[i]),O=useCallback(v=>{v.preventDefault();let L=v.deltaY>0?-s:s;T(L);},[T,s]),E=useCallback(v=>{if(v.button!==0||v.isPrimary===false)return;h(true),C({x:v.clientX,y:v.clientY}),w(p);let L=v.currentTarget;L instanceof HTMLElement&&L.setPointerCapture(v.pointerId);},[p]),I=useCallback(v=>{if(!b)return;v.preventDefault();let L=v.clientX-u.x,ce=v.clientY-u.y;g({x:k.x+L,y:k.y+ce});},[b,u,k]),z=useCallback(v=>{h(false);let L=v.currentTarget;L instanceof HTMLElement&&L.releasePointerCapture(v.pointerId);},[]);return useEffect(()=>{let v=a.current;if(v)return v.addEventListener("wheel",O,{passive:false}),()=>{v.removeEventListener("wheel",O);}},[O]),useEffect(()=>{let v=l.current;if(v&&b)return document.body.style.userSelect="none",v.addEventListener("pointermove",I,{passive:false}),v.addEventListener("pointerup",z),v.addEventListener("pointercancel",z),()=>{document.body.style.userSelect="",v.removeEventListener("pointermove",I),v.removeEventListener("pointerup",z),v.removeEventListener("pointercancel",z);}},[b,I,z]),jsxs("div",{className:f("relative flex flex-col",c?"h-full w-full":"min-h-28 w-full",t),ref:a,style:{cursor:b?"grabbing":"grab"},children:[r?jsxs("div",{className:f("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",c?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:"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:m>=n,onClick:H,title:"Zoom in",type:"button",children:jsx(lt,{size:16})}),jsx("button",{className:"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:m<=o,onClick:S,title:"Zoom out",type:"button",children:jsx(ct,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:B,title:"Reset zoom and pan",type:"button",children:jsx(it,{size:16})})]}):null,jsx("div",{className:f("flex-1 origin-center transition-transform duration-150 ease-out",c?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:E,ref:l,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${m})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var Nt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:s=true})=>{let[r,i]=useState(null),[c,a]=useState(false),[l,m]=useState(""),[d,p]=useState(""),[g,b]=useState(0),{mermaid:h}=useContext(R),u=G(),C=h==null?void 0:h.errorComponent,{shouldRender:k,containerRef:w}=Ge({immediate:n});if(useEffect(()=>{if(!k)return;if(!u){i("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{i(null),a(!0);let S=u.getMermaid(o),B=e.split("").reduce((I,z)=>(I<<5)-I+z.charCodeAt(0)|0,0),O=`mermaid-${Math.abs(B)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:E}=await S.render(O,e);m(E),p(E);}catch(S){if(!(d||l)){let B=S instanceof Error?S.message:"Failed to render Mermaid chart";i(B);}}finally{a(false);}})();},[e,o,g,k,u]),!(k||l||d))return jsx("div",{className:f("my-4 min-h-[200px]",t),ref:w});if(c&&!l&&!d)return jsx("div",{className:f("my-4 flex justify-center p-4",t),ref:w,children:jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!l&&!d){let H=()=>b(S=>S+1);return C?jsx("div",{ref:w,children:jsx(C,{chart:e,error:r,retry:H})}):jsxs("div",{className:f("rounded-md bg-red-50 p-4",t),ref:w,children:[jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),jsxs("details",{className:"mt-2",children:[jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let T=l||d;return jsx("div",{className:f("size-full",t),"data-streamdown":"mermaid",ref:w,children:jsx(So,{className:f(n?"size-full overflow-hidden":"overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:s,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:f("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:T},role:"img"})})})};export{Q as a,Ie as b,Qe as c,Ks as d,Nt as e,bo as f,We as g,Or as h,Fe as i,Vr as j,R as k,No as l,_r as m};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {k,d,c}from'./chunk-RLXIAIE6.js';import {useContext,useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';var L=({code:s,language:t,raw:e,className:n,...d$1})=>{let{shikiTheme:l}=useContext(k),o=d(),[m,i]=useState(e);return useEffect(()=>{if(!o){i(e);return}let g=o.highlight({code:s,language:t,themes:l},p=>{i(p);});g&&i(g);},[s,t,l,o,e]),jsx(c,{className:n,language:t,result:m,...d$1})};export{L as HighlightedCodeBlockBody};
|
package/dist/mermaid-3ZIDBTTL.js
DELETED