@lofcz/streamdown 2.5.0 → 2.6.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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import {createContext,memo,useContext,useMemo,lazy,isValidElement,useId,useTransition,useRef,useEffect,useState,cloneElement,createElement,useCallback,Suspense}from'react';import {harden}from'rehype-harden';import on from'rehype-raw';import Pn,{defaultSchema}from'rehype-sanitize';import Js from'remark-gfm';import Us 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 ks from'remark-parse';import xs from'remark-rehype';import {unified}from'unified';import {visit}from'unist-util-visit';import {Lexer}from'marked';var An=300,On="300px",Vn=500;function Dt(e={}){let{immediate:t=false,debounceDelay:o=An,rootMargin:n=On,idleTimeout:r=Vn}=e,[s,a]=useState(false),l=useRef(null),i=useRef(null),d=useRef(null),c=useMemo(()=>u=>{let f=Date.now();return window.setTimeout(()=>{u({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-f))});},1)},[]),p=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(u,f)=>window.requestIdleCallback(u,f):c,[c]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?u=>window.cancelIdleCallback(u):u=>{clearTimeout(u);},[]);return useEffect(()=>{if(t){a(true);return}let u=l.current;if(!u)return;i.current&&(clearTimeout(i.current),i.current=null),d.current&&(m(d.current),d.current=null);let f=()=>{i.current&&(clearTimeout(i.current),i.current=null),d.current&&(m(d.current),d.current=null);},h=v=>{d.current=p(C=>{C.timeRemaining()>0||C.didTimeout?(a(true),v.disconnect()):d.current=p(()=>{a(true),v.disconnect();},{timeout:r/2});},{timeout:r});},b=v=>{f(),i.current=window.setTimeout(()=>{var N,E;let C=v.takeRecords();(C.length===0||(E=(N=C.at(-1))==null?void 0:N.isIntersecting)!=null&&E)&&h(v);},o);},g=(v,C)=>{v.isIntersecting?b(C):f();},T=new IntersectionObserver(v=>{for(let C of v)g(C,T);},{rootMargin:n,threshold:0});return T.observe(u),()=>{i.current&&clearTimeout(i.current),d.current&&m(d.current),T.disconnect();}},[t,o,n,r,m,p]),{shouldRender:s,containerRef:l}}var Bt=/\s/,zn=/^\s+$/,_n=new Set(["code","pre","svg","math","annotation"]),qn=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",$n=e=>e.some(t=>qn(t)&&_n.has(t.tagName)),Wn=e=>{let t=[],o="",n=false;for(let r of e){let s=Bt.test(r);s!==n&&o&&(t.push(o),o=""),o+=r,n=s;}return o&&t.push(o),t},Zn=e=>{let t=[],o="";for(let n of e)Bt.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},Xn=(e,t,o,n,r,s)=>{let a=`--sd-animation:sd-${t};--sd-duration:${r?0:o}ms;--sd-easing:${n}`;return s&&(a+=`;--sd-delay:${s}ms`),{type:"element",tagName:"span",properties:{"data-sd-animate":true,style:a},children:[{type:"text",value:e}]}},Kn=(e,t,o,n,r)=>{let s=t.at(-1);if(!(s&&"children"in s))return;if($n(t))return SKIP;let a=s,l=a.children.indexOf(e);if(l===-1)return;let i=e.value;if(!i.trim()){r.count+=i.length;return}let d=o.sep==="char"?Zn(i):Wn(i),c=n.prevContentLength,p=d.map(m=>{let u=r.count;if(r.count+=m.length,zn.test(m))return {type:"text",value:m};let f=c>0&&u<c,h=f?0:r.newIndex++*o.stagger;return Xn(m,o.animation,o.duration,o.easing,f,h)});return a.children.splice(l,1,...p),l+p.length},Jn=0;function xe(e){var s,a,l,i,d;let t={animation:(s=e==null?void 0:e.animation)!=null?s:"fadeIn",duration:(a=e==null?void 0:e.duration)!=null?a:150,easing:(l=e==null?void 0:e.easing)!=null?l:"ease",sep:(i=e==null?void 0:e.sep)!=null?i:"word",stagger:(d=e==null?void 0:e.stagger)!=null?d:40},o={prevContentLength:0,lastRenderCharCount:0},n=Jn++,r=()=>c=>{let p={count:0,newIndex:0};visitParents(c,"text",(m,u)=>Kn(m,u,t,o,p)),o.lastRenderCharCount=p.count,o.prevContentLength=0;};return Object.defineProperty(r,"name",{value:`rehypeAnimate$${n}`}),{name:"animate",type:"animate",rehypePlugin:r,setPrevContentLength(c){o.prevContentLength=c;},getLastRenderCharCount(){let c=o.lastRenderCharCount;return o.lastRenderCharCount=0,c}}}xe();var nt=createContext(false),rt=()=>useContext(nt);var ve=(...e)=>twMerge(clsx(e)),Yn=(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(" ")},Vt=e=>e?(...t)=>Yn(e,twMerge(clsx(t))):ve,K=(e,t,o)=>{let n=typeof t=="string"&&o.startsWith("text/csv")?"\uFEFF":"",r=typeof t=="string"?new Blob([n+t],{type:o}):t,s=URL.createObjectURL(r),a=document.createElement("a");a.href=s,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s);};var Oe=createContext(ve),w=()=>useContext(Oe);var or=ve("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"),nr=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},Ft=memo(({children:e,result:t,language:o,className:n,startLine:r,lineNumbers:s=true,...a})=>{let l=w(),i=useMemo(()=>l(or),[l]),d=useMemo(()=>{let c={};return t.bg&&(c["--sdm-bg"]=t.bg),t.fg&&(c["--sdm-fg"]=t.fg),t.rootStyle&&Object.assign(c,nr(t.rootStyle)),c},[t.bg,t.fg,t.rootStyle]);return jsx("div",{className:l(n,"overflow-x-auto rounded-md border border-border bg-background p-4 text-sm"),"data-language":o,"data-streamdown":"code-block-body",...a,children:jsx("pre",{className:l(n,"bg-[var(--sdm-bg,inherit]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]"),style:d,children:jsx("code",{className:s?l("[counter-increment:line_0] [counter-reset:line]"):void 0,style:s&&r&&r>1?{counterReset:`line ${r-1}`}:void 0,children:t.tokens.map((c,p)=>jsx("span",{className:s?i:void 0,children:c.length===0||c.length===1&&c[0].content===""?`
3
+ `:c.map((m,u)=>{let f={},h=!!m.bgColor;if(m.color&&(f["--sdm-c"]=m.color),m.bgColor&&(f["--sdm-tbg"]=m.bgColor),m.htmlStyle)for(let[b,g]of Object.entries(m.htmlStyle))b==="color"?f["--sdm-c"]=g:b==="background-color"?(f["--sdm-tbg"]=g,h=true):f[b]=g;return jsx("span",{className:l("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",h&&"bg-[var(--sdm-tbg)]",h&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:f,...m.htmlAttrs,children:m.content},u)})},p))})})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className&&e.startLine===t.startLine&&e.lineNumbers===t.lineNumbers);var st=({className:e,language:t,style:o,isIncomplete:n,...r})=>{let s=w();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 at=createContext({code:""}),Ve=()=>useContext(at);var it=({language:e})=>{let t=w();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 cr=e=>{let t=e.length;for(;t>0&&e[t-1]===`
4
+ `;)t--;return e.slice(0,t)},dr=lazy(()=>import('./highlighted-body-T7AKFYQP.js').then(e=>({default:e.HighlightedCodeBlockBody}))),lt=({code:e,language:t,className:o,children:n,isIncomplete:r=false,startLine:s,lineNumbers:a,...l})=>{let i=w(),d=useMemo(()=>cr(e),[e]),c=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:d.split(`
5
+ `).map(p=>[{content:p,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[d]);return jsx(at.Provider,{value:{code:e},children:jsxs(st,{isIncomplete:r,language:t,children:[jsx(it,{language:t}),n?jsx("div",{className:i("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:jsx("div",{className:i("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"code-block-actions",children:n})}):null,jsx(Suspense,{fallback:jsx(Ft,{className:o,language:t,lineNumbers:a,result:c,startLine:s,...l}),children:jsx(dr,{className:o,code:d,language:t,lineNumbers:a,raw:c,startLine:s,...l})})]})})};var qt=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"})}),$t=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"})}),Wt=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"})]}),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.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"})}),Kt=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"})}),Jt=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"})}),Ut=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"})}),Gt=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"})}),Yt=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 Pe={CheckIcon:qt,CopyIcon:$t,DownloadIcon:Wt,ExternalLinkIcon:Ut,Loader2Icon:Zt,Maximize2Icon:Xt,RotateCcwIcon:Kt,XIcon:Jt,ZoomInIcon:Gt,ZoomOutIcon:Yt},eo=createContext(Pe),gr=(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])},ct=({icons:e,children:t})=>{let o=useRef(e),n=useRef(e?{...Pe,...e}:Pe);gr(o.current,e)||(o.current=e,n.current=e?{...Pe,...e}:Pe);let r=n.current;return jsx(eo.Provider,{value:r,children:t})},S=()=>useContext(eo);var je={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"},Fe=createContext(je),B=()=>useContext(Fe);var ze=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...a})=>{let l=w(),[i,d]=useState(false),c=useRef(0),{code:p}=Ve(),{isAnimating:m}=useContext(M),u=B(),f=s!=null?s:p,h=async()=>{var T;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(f),d(!0),e==null||e(),c.current=window.setTimeout(()=>d(!1),o));}catch(v){t==null||t(v);}};useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let b=S(),g=i?b.CheckIcon:b.CopyIcon;return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-copy-button",disabled:m,onClick:h,title:u.copyCode,type:"button",...a,children:n!=null?n:jsx(g,{size:14})})};var oo={"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"},dt=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...a})=>{let l=w(),{code:i}=Ve(),{isAnimating:d}=useContext(M),c=B(),p=S(),m=s!=null?s:i,f=`file.${o&&o in oo?oo[o]:"txt"}`,h="text/plain",b=()=>{try{K(f,m,h),e==null||e();}catch(g){t==null||t(g);}};return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-download-button",disabled:d,onClick:b,title:c.downloadFile,type:"button",...a,children:n!=null?n:jsx(p.DownloadIcon,{size:14})})};var _e=()=>{let{Loader2Icon:e}=S(),t=w();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 Me=0,te=()=>{Me+=1,Me===1&&(document.body.style.overflow="hidden");},oe=()=>{Me=Math.max(0,Me-1),Me===0&&(document.body.style.overflow="");};var Mr=["github-light","github-dark"],Ir={enabled:true},Nr={shikiTheme:Mr,controls:true,isAnimating:false,lineNumbers:true,mode:"streaming",mermaid:void 0,linkSafety:Ir},M=createContext(Nr);var Er=/\.[^/.]+$/,so=(e,t)=>{if(typeof e=="boolean")return e;let o=e.image;return o===false?false:o===true||o===void 0?true:o[t]!==false},ao=({node:e,className:t,src:o,alt:n,onLoad:r,onError:s,onClick:a,...l})=>{let{DownloadIcon:i,XIcon:d}=S(),c=w(),p=useRef(null),[m,u]=useState(false),[f,h]=useState(false),[b,g]=useState(false),{controls:T}=useContext(M),v=B(),C=so(T,"download"),I=so(T,"fullscreen"),N=l.width!=null||l.height!=null,E=C&&(m||N)&&!f,D=f&&!N,F=I&&!!o&&!f&&m;useEffect(()=>{let y=p.current;if(y!=null&&y.complete){let H=y.naturalWidth>0;u(H),h(!H);}},[]),useEffect(()=>{if(!b)return;te();let y=H=>{H.key==="Escape"&&g(false);};return document.addEventListener("keydown",y),()=>{document.removeEventListener("keydown",y),oe();}},[b]);let z=useCallback(y=>{u(true),h(false),r==null||r(y);},[r]),W=useCallback(y=>{u(false),h(true),s==null||s(y);},[s]),_=useCallback(()=>{F&&g(true);},[F]),Z=useCallback(()=>{g(false);},[]),Q=useCallback(y=>{a==null||a(y),!y.defaultPrevented&&_();},[a,_]),X=async y=>{if(y.stopPropagation(),!!o)try{let q=await(await fetch(o)).blob(),ee=new URL(o,window.location.origin).pathname.split("/").pop()||"",se=ee.split(".").pop(),ae=ee.includes(".")&&se!==void 0&&se.length<=4,Ce="";if(ae)Ce=ee;else {let G=q.type,A="png";G.includes("jpeg")||G.includes("jpg")?A="jpg":G.includes("png")?A="png":G.includes("svg")?A="svg":G.includes("gif")?A="gif":G.includes("webp")&&(A="webp"),Ce=`${(n||ee||"image").replace(Er,"")}.${A}`;}K(Ce,q,q.type);}catch(H){window.open(o,"_blank");}};return o?jsxs(Fragment,{children:[jsxs("div",{className:c("group/image not-prose relative my-2 block max-w-full"),"data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:c("m-0 block h-auto max-w-full rounded-lg",F&&"cursor-zoom-in",D&&"hidden",t),"data-streamdown":"image",onClick:Q,onError:W,onLoad:z,ref:p,src:o,...l}),D&&jsx("span",{className:c("text-muted-foreground text-xs italic"),"data-streamdown":"image-fallback",children:v.imageNotAvailable}),E&&jsx("button",{className:c("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 focus-visible:opacity-100 group-hover/image:opacity-100"),onClick:X,title:v.downloadImage,type:"button",children:jsx(i,{size:14})})]}),b?createPortal(jsxs("div",{className:c("fixed inset-0 z-50 flex items-center justify-center bg-black/90 p-4"),"data-streamdown":"image-lightbox",onClick:Z,onKeyDown:y=>{y.key==="Escape"&&Z();},role:"button",tabIndex:0,children:[jsx("button",{className:c("absolute top-4 right-4 z-10 rounded-md p-2 text-white/80 transition-colors hover:bg-white/10 hover:text-white"),onClick:Z,title:v.exitFullscreen,type:"button",children:jsx(d,{size:20})}),jsx("div",{onClick:y=>y.stopPropagation(),onKeyDown:y=>y.stopPropagation(),role:"presentation",children:jsx("img",{alt:n,className:c("max-h-[calc(100vh-2rem)] max-w-[calc(100vw-2rem)] object-contain"),"data-streamdown":"image-lightbox-img",src:o})})]}),document.body):null]}):null};var co=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let{CheckIcon:r,CopyIcon:s,ExternalLinkIcon:a,XIcon:l}=S(),i=w(),[d,c]=useState(false),p=B(),m=useCallback(async()=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3);}catch(f){}},[e]),u=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){te();let f=h=>{h.key==="Escape"&&o();};return document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f),oe();}}},[t,o]),t?jsx("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm"),"data-streamdown":"link-safety-modal",onClick:o,onKeyDown:f=>{f.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:i("relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg"),onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),role:"presentation",children:[jsx("button",{className:i("absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:o,title:p.close,type:"button",children:jsx(l,{size:16})}),jsxs("div",{className:i("flex flex-col gap-2"),children:[jsxs("div",{className:i("flex items-center gap-2 font-semibold text-lg"),children:[jsx(a,{size:20}),jsx("span",{children:p.openExternalLink})]}),jsx("p",{className:i("text-muted-foreground text-sm"),children:p.externalLinkWarning})]}),jsx("div",{className:i("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxs("div",{className:i("flex gap-2"),children:[jsx("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted"),onClick:m,type:"button",children:d?jsxs(Fragment,{children:[jsx(r,{size:14}),jsx("span",{children:p.copied})]}):jsxs(Fragment,{children:[jsx(s,{size:14}),jsx("span",{children:p.copyLink})]})}),jsxs("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90"),onClick:u,type:"button",children:[jsx(a,{size:14}),jsx("span",{children:p.openLink})]})]})]})}):null};var qe=createContext(null),ft=()=>useContext(qe),Fi=()=>{var t;let e=ft();return (t=e==null?void 0:e.code)!=null?t:null},ge=()=>{var t;let e=ft();return (t=e==null?void 0:e.mermaid)!=null?t:null};var mo=e=>{var o;let t=ft();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 uo=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((r,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),l=new Image;l.crossOrigin="anonymous",l.onload=()=>{let i=document.createElement("canvas"),d=l.width*o,c=l.height*o;i.width=d,i.height=c;let p=i.getContext("2d");if(!p){s(new Error("Failed to create 2D canvas context for PNG export"));return}p.drawImage(l,0,0,d,c),i.toBlob(m=>{if(!m){s(new Error("Failed to create PNG blob"));return}r(m);},"image/png");},l.onerror=()=>s(new Error("Failed to load SVG image")),l.src=a;})};var fo=({chart:e,children:t,className:o,onDownload:n,config:r,onError:s})=>{let a=w(),[l,i]=useState(false),d=useRef(null),{isAnimating:c}=useContext(M),p=S(),m=ge(),u=B(),f=async h=>{try{if(h==="mmd"){K("diagram.mmd",e,"text/plain"),i(!1),n==null||n(h);return}if(!m){s==null||s(new Error("Mermaid plugin not available"));return}let b=m.getMermaid(r),g=e.split("").reduce((C,I)=>(C<<5)-C+I.charCodeAt(0)|0,0),T=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:v}=await b.render(T,e);if(!v){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(h==="svg"){K("diagram.svg",v,"image/svg+xml"),i(!1),n==null||n(h);return}if(h==="png"){let C=await uo(v);K("diagram.png",C,"image/png"),n==null||n(h),i(!1);return}}catch(b){s==null||s(b);}};return useEffect(()=>{let h=b=>{let g=b.composedPath();d.current&&!g.includes(d.current)&&i(false);};return document.addEventListener("mousedown",h),()=>{document.removeEventListener("mousedown",h);}},[]),jsxs("div",{className:a("relative"),ref:d,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:c,onClick:()=>i(!l),title:u.downloadDiagram,type:"button",children:t!=null?t:jsx(p.DownloadIcon,{size:14})}),l?jsxs("div",{className:a("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("svg"),title:u.downloadDiagramAsSvg,type:"button",children:u.mermaidFormatSvg}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("png"),title:u.downloadDiagramAsPng,type:"button",children:u.mermaidFormatPng}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("mmd"),title:u.downloadDiagramAsMmd,type:"button",children:u.mermaidFormatMmd})]}):null]})};var yo=({chart:e,config:t,onFullscreen:o,onExit:n,className:r,...s})=>{let{Maximize2Icon:a,XIcon:l}=S(),i=w(),[d,c]=useState(false),{isAnimating:p,controls:m}=useContext(M),u=B(),f=(()=>{if(typeof m=="boolean")return m;let b=m.mermaid;return b===false?false:b===true||b===void 0?true:b.panZoom!==false})(),h=()=>{c(!d);};return useEffect(()=>{if(d){te();let b=g=>{g.key==="Escape"&&c(false);};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b),oe();}}},[d]),useEffect(()=>{d?o==null||o():n&&n();},[d,o,n]),jsxs(Fragment,{children:[jsx("button",{className:i("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:p,onClick:h,title:u.viewFullscreen,type:"button",...s,children:jsx(a,{size:14})}),d?createPortal(jsxs("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"),onClick:h,onKeyDown:b=>{b.key==="Escape"&&h();},role:"button",tabIndex:0,children:[jsx("button",{className:i("absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:h,title:u.exitFullscreen,type:"button",children:jsx(l,{size:20})}),jsx("div",{className:i("flex size-full items-center justify-center p-4"),onClick:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),role:"presentation",children:jsx(ho,{chart:e,className:i("size-full [&_svg]:h-auto [&_svg]:w-auto"),config:t,fullscreen:true,showControls:f})})]}),document.body):null]})};var he=e=>{var s,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let l of n)t.push(((s=l.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let l of r){let i=[],d=l.querySelectorAll("td");for(let c of d)i.push(((a=c.textContent)==null?void 0:a.trim())||"");o.push(i);}return {headers:t,rows:o}},de=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false,d=false;for(let c of l){if(c==='"'){i=true,d=true;break}(c===","||c===`
6
+ `)&&(i=true);}return i?d?`"${l.replace(/"/g,'""')}"`:`"${l}"`:l},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(","),a+=1);for(let l of o)s[a]=l.map(n).join(","),a+=1;return s.join(`
7
+ `)},gt=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false;for(let c of l)if(c===" "||c===`
8
+ `||c==="\r"){i=true;break}if(!i)return l;let d=[];for(let c of l)c===" "?d.push("\\t"):c===`
9
+ `?d.push("\\n"):c==="\r"?d.push("\\r"):d.push(c);return d.join("")},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(" "),a+=1);for(let l of o)s[a]=l.map(n).join(" "),a+=1;return s.join(`
10
+ `)},$e=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("")},me=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=>$e(l));n[r]=`| ${s.join(" | ")} |`,r+=1;let a=new Array(t.length);for(let l=0;l<t.length;l+=1)a[l]="---";n[r]=`| ${a.join(" | ")} |`,r+=1;for(let l of o)if(l.length<t.length){let i=new Array(t.length);for(let d=0;d<t.length;d+=1)i[d]=d<l.length?$e(l[d]):"";n[r]=`| ${i.join(" | ")} |`,r+=1;}else {let i=l.map(d=>$e(d));n[r]=`| ${i.join(" | ")} |`,r+=1;}return n.join(`
11
+ `)};var Se=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3})=>{let s=w(),[a,l]=useState(false),[i,d]=useState(false),c=useRef(null),p=useRef(0),{isAnimating:m}=useContext(M),u=B(),f=async g=>{var T,v;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.write)){n==null||n(new Error("Clipboard API not available"));return}try{let C=(v=c.current)==null?void 0:v.closest('[data-streamdown="table-wrapper"]'),I=C==null?void 0:C.querySelector("table");if(!I){n==null||n(new Error("Table not found"));return}let N=he(I),F=({csv:de,tsv:gt,md:me}[g]||me)(N),z=new ClipboardItem({"text/plain":new Blob([F],{type:"text/plain"}),"text/html":new Blob([I.outerHTML],{type:"text/html"})});await navigator.clipboard.write([z]),d(!0),l(!1),o==null||o(g),p.current=window.setTimeout(()=>d(!1),r);}catch(C){n==null||n(C);}};useEffect(()=>{let g=T=>{let v=T.composedPath();c.current&&!v.includes(c.current)&&l(false);};return document.addEventListener("mousedown",g),()=>{document.removeEventListener("mousedown",g),window.clearTimeout(p.current);}},[]);let h=S(),b=i?h.CheckIcon:h.CopyIcon;return jsxs("div",{className:s("relative"),ref:c,children:[jsx("button",{className:s("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!a),title:u.copyTable,type:"button",children:e!=null?e:jsx(b,{height:14,width:14})}),a?jsxs("div",{className:s("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("md"),title:u.copyTableAsMarkdown,type:"button",children:u.tableFormatMarkdown}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("csv"),title:u.copyTableAsCsv,type:"button",children:u.tableFormatCsv}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("tsv"),title:u.copyTableAsTsv,type:"button",children:u.tableFormatTsv})]}):null]})};var Gr=({children:e,className:t,onDownload:o,onError:n,format:r="csv",filename:s})=>{let a=w(),{isAnimating:l}=useContext(M),i=B(),d=S(),c=p=>{try{let u=p.currentTarget.closest('[data-streamdown="table-wrapper"]'),f=u==null?void 0:u.querySelector("table");if(!f){n==null||n(new Error("Table not found"));return}let h=he(f),b="",g="",T="";switch(r){case "csv":b=de(h),g="text/csv",T="csv";break;case "markdown":b=me(h),g="text/markdown",T="md";break;default:b=de(h),g="text/csv",T="csv";}K(`${s||"table"}.${T}`,b,g),o==null||o();}catch(m){n==null||n(m);}};return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:c,title:r==="csv"?i.downloadTableAsCsv:i.downloadTableAsMarkdown,type:"button",children:e!=null?e:jsx(d.DownloadIcon,{size:14})})},Re=({children:e,className:t,onDownload:o,onError:n})=>{let r=w(),[s,a]=useState(false),l=useRef(null),{isAnimating:i}=useContext(M),d=B(),c=S(),p=m=>{var u;try{let f=(u=l.current)==null?void 0:u.closest('[data-streamdown="table-wrapper"]'),h=f==null?void 0:f.querySelector("table");if(!h){n==null||n(new Error("Table not found"));return}let b=he(h),g=m==="csv"?de(b):me(b);K(`table.${m==="csv"?"csv":"md"}`,g,m==="csv"?"text/csv":"text/markdown"),a(!1),o==null||o(m);}catch(f){n==null||n(f);}};return useEffect(()=>{let m=u=>{let f=u.composedPath();l.current&&!f.includes(l.current)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:r("relative"),ref:l,children:[jsx("button",{className:r("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>a(!s),title:d.downloadTable,type:"button",children:e!=null?e:jsx(c.DownloadIcon,{size:14})}),s?jsxs("div",{className:r("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>p("csv"),title:d.downloadTableAsCsv,type:"button",children:d.tableFormatCsv}),jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>p("markdown"),title:d.downloadTableAsMarkdown,type:"button",children:d.tableFormatMarkdown})]}):null]})};var To=({children:e,className:t,showCopy:o=true,showDownload:n=true})=>{let{Maximize2Icon:r,XIcon:s}=S(),a=w(),[l,i]=useState(false),{isAnimating:d}=useContext(M),c=B(),p=()=>{i(true);},m=()=>{i(false);};return useEffect(()=>{if(l){te();let u=f=>{f.key==="Escape"&&i(false);};return document.addEventListener("keydown",u),()=>{document.removeEventListener("keydown",u),oe();}}},[l]),jsxs(Fragment,{children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:p,title:c.viewFullscreen,type:"button",children:jsx(r,{size:14})}),l?createPortal(jsx("div",{"aria-label":c.viewFullscreen,"aria-modal":"true",className:a("fixed inset-0 z-50 flex flex-col bg-background"),"data-streamdown":"table-fullscreen",onClick:m,onKeyDown:u=>{u.key==="Escape"&&m();},role:"dialog",children:jsxs("div",{className:a("flex h-full flex-col"),onClick:u=>u.stopPropagation(),onKeyDown:u=>u.stopPropagation(),role:"presentation",children:[jsxs("div",{className:a("flex items-center justify-end gap-1 p-4"),children:[o?jsx(Se,{}):null,n?jsx(Re,{}):null,jsx("button",{className:a("rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:m,title:c.exitFullscreen,type:"button",children:jsx(s,{size:20})})]}),jsx("div",{className:a("flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10"),children:jsx("table",{className:a("w-full border-collapse border border-border"),"data-streamdown":"table",children:e})})]})}),document.body):null]})};var Mo=({children:e,className:t,showControls:o,showCopy:n=true,showDownload:r=true,showFullscreen:s=true,...a})=>{let l=w(),i=o&&n,d=o&&r,c=o&&s,p=i||d||c;return jsxs("div",{className:l("my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2"),"data-streamdown":"table-wrapper",children:[p?jsxs("div",{className:l("flex items-center justify-end gap-1"),children:[i?jsx(Se,{}):null,d?jsx(Re,{}):null,c?jsx(To,{showCopy:i,showDownload:d,children:e}):null]}):null,jsx("div",{className:l("border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background"),children:jsx("table",{className:l("w-full divide-y divide-border",t),"data-streamdown":"table",...a,children:e})})]})};var as=/startLine=(\d+)/,is=/\bnoLineNumbers\b/,ls=lazy(()=>import('./mermaid-OOFVDMCH.js').then(e=>({default:e.Mermaid}))),cs=/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,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 R(e,t){return e.className===t.className&&Ke(e.node,t.node)}var wt=(e,t)=>typeof e=="boolean"?e:e[t]!==false,yt=(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},No=(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},We=(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},kt=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("ol",{className:r("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e})},(e,t)=>R(e,t));kt.displayName="MarkdownOl";var Lo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("li",{className:r("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e})},(e,t)=>e.className===t.className&&Ke(e.node,t.node));Lo.displayName="MarkdownLi";var So=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("ul",{className:r("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e})},(e,t)=>R(e,t));So.displayName="MarkdownUl";var Ro=memo(({className:e,node:t,...o})=>{let n=w();return jsx("hr",{className:n("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o})},(e,t)=>R(e,t));Ro.displayName="MarkdownHr";var Eo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("span",{className:r("font-semibold",t),"data-streamdown":"strong",...n,children:e})},(e,t)=>R(e,t));Eo.displayName="MarkdownStrong";var ds=({children:e,className:t,href:o,node:n,...r})=>{let s=w(),{linkSafety:a}=useContext(M),[l,i]=useState(false),d=o==="streamdown:incomplete-link",c=useCallback(async f=>{if(!(!(a!=null&&a.enabled&&o)||d)){if(f.preventDefault(),a.onLinkCheck&&await a.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}i(true);}},[a,o,d]),p=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),m=useCallback(()=>{i(false);},[]),u={url:o!=null?o:"",isOpen:l,onClose:m,onConfirm:p};return a!=null&&a.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:s("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":d,"data-streamdown":"link",onClick:c,type:"button",children:e}),a.renderModal?a.renderModal(u):jsx(co,{...u})]}):jsx("a",{className:s("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":d,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...r,children:e})},Ho=memo(ds,(e,t)=>R(e,t)&&e.href===t.href);Ho.displayName="MarkdownA";var Do=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("h1",{className:r("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e})},(e,t)=>R(e,t));Do.displayName="MarkdownH1";var Bo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("h2",{className:r("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e})},(e,t)=>R(e,t));Bo.displayName="MarkdownH2";var Ao=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("h3",{className:r("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e})},(e,t)=>R(e,t));Ao.displayName="MarkdownH3";var Oo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("h4",{className:r("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e})},(e,t)=>R(e,t));Oo.displayName="MarkdownH4";var Vo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("h5",{className:r("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e})},(e,t)=>R(e,t));Vo.displayName="MarkdownH5";var jo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("h6",{className:r("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e})},(e,t)=>R(e,t));jo.displayName="MarkdownH6";var Fo=memo(({children:e,className:t,node:o,...n})=>{let{controls:r}=useContext(M),s=wt(r,"table"),a=yt(r,"copy"),l=yt(r,"download"),i=yt(r,"fullscreen");return jsx(Mo,{className:t,showControls:s,showCopy:a,showDownload:l,showFullscreen:i,...n,children:e})},(e,t)=>R(e,t));Fo.displayName="MarkdownTable";var zo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("thead",{className:r("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e})},(e,t)=>R(e,t));zo.displayName="MarkdownThead";var _o=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("tbody",{className:r("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e})},(e,t)=>R(e,t));_o.displayName="MarkdownTbody";var qo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("tr",{className:r("border-border",t),"data-streamdown":"table-row",...n,children:e})},(e,t)=>R(e,t));qo.displayName="MarkdownTr";var $o=memo(({children:e,className:t,node:o,...n})=>{let r=w();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)=>R(e,t));$o.displayName="MarkdownTh";var Wo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("td",{className:r("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e})},(e,t)=>R(e,t));Wo.displayName="MarkdownTd";var Zo=memo(({children:e,className:t,node:o,...n})=>{let r=w();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)=>R(e,t));Zo.displayName="MarkdownBlockquote";var Xo=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("sup",{className:r("text-sm",t),"data-streamdown":"superscript",...n,children:e})},(e,t)=>R(e,t));Xo.displayName="MarkdownSup";var Ko=memo(({children:e,className:t,node:o,...n})=>{let r=w();return jsx("sub",{className:r("text-sm",t),"data-streamdown":"subscript",...n,children:e})},(e,t)=>R(e,t));Ko.displayName="MarkdownSub";var Jo=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=i=>{var m,u;if(!isValidElement(i))return false;let d=Array.isArray(i.props.children)?i.props.children:[i.props.children],c=false,p=false;for(let f of d)if(f){if(typeof f=="string")f.trim()!==""&&(c=true);else if(isValidElement(f))if(((m=f.props)==null?void 0:m["data-footnote-backref"])!==void 0)p=true;else {let h=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let b of h){if(typeof b=="string"&&b.trim()!==""){c=true;break}if(isValidElement(b)&&((u=b.props)==null?void 0:u["data-footnote-backref"])===void 0){c=true;break}}}}return p&&!c},a=Array.isArray(e)?e.map(i=>{if(!isValidElement(i))return i;if(i.type===kt){let c=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(p=>!s(p));return c.length===0?null:{...i,props:{...i.props,children:c}}}return i}):e;return (Array.isArray(a)?a.some(i=>i!==null):a!==null)?jsx("section",{className:t,...n,children:a}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>R(e,t));Jo.displayName="MarkdownSection";var ms=({node:e,className:t,children:o,...n})=>{var D,F;let r=w(),s=!("data-block"in n),{mermaid:a,controls:l,lineNumbers:i}=useContext(M),d=ge(),c=rt(),p=t==null?void 0:t.match(cs),m=(D=p==null?void 0:p.at(1))!=null?D:"",u=mo(m);if(s)return jsx("code",{className:r("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let f=(F=e==null?void 0:e.properties)==null?void 0:F.metastring,h=f==null?void 0:f.match(as),b=h?Number.parseInt(h[1],10):void 0,g=b!==void 0&&b>=1?b:void 0,v=!(f?is.test(f):false)&&i!==false,C="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?C=o.props.children:typeof o=="string"&&(C=o),u){let z=u.component;return jsx(Suspense,{fallback:jsx(_e,{}),children:jsx(z,{code:C,isIncomplete:c,language:m,meta:f})})}if(m==="mermaid"&&d){let z=wt(l,"mermaid"),W=We(l,"download"),_=We(l,"copy"),Z=We(l,"fullscreen"),Q=We(l,"panZoom"),X=z&&(W||_||Z);return jsx(Suspense,{fallback:jsx(_e,{}),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"})}),X?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:[W?jsx(fo,{chart:C,config:a==null?void 0:a.config}):null,_?jsx(ze,{code:C}):null,Z?jsx(yo,{chart:C,config:a==null?void 0:a.config}):null]})}):null,jsx("div",{className:r("rounded-md border border-border bg-background"),children:jsx(ls,{chart:C,config:a==null?void 0:a.config,showControls:Q})})]})})}let I=wt(l,"code"),N=No(l,"download"),E=No(l,"copy");return jsx(lt,{className:t,code:C,isIncomplete:c,language:m,lineNumbers:v,startLine:g,children:I?jsxs(Fragment,{children:[N?jsx(dt,{code:C,language:m}):null,E?jsx(ze,{}):null]}):null})},Uo=memo(ms,(e,t)=>e.className===t.className&&Ke(e.node,t.node));Uo.displayName="MarkdownCode";var Go=memo(ao,(e,t)=>e.className===t.className&&Ke(e.node,t.node));Go.displayName="MarkdownImg";var Yo=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)=>R(e,t));Yo.displayName="MarkdownParagraph";var Qo={ol:kt,li:Lo,ul:So,hr:Ro,strong:Eo,a:Ho,h1:Do,h2:Bo,h3:Ao,h4:Oo,h5:Vo,h6:jo,table:Fo,thead:zo,tbody:_o,tr:qo,th:$o,td:Wo,blockquote:Zo,code:Uo,img:Go,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:Xo,sub:Ko,p:Yo,section:Jo};var us=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,ps=/\p{L}/u;function Je(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(us.test(o))return "rtl";if(ps.test(o))return "ltr"}return "ltr"}var fs=/^[ \t]{0,3}(`{3,}|~{3,})/,gs=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,xt=e=>{let t=e.split(`
12
+ `),o=null,n=0;for(let r of t){let s=fs.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},en=e=>{let t=e.split(`
13
+ `);for(let o of t){let n=o.trim();if(n.length>0&&n.includes("|")&&gs.test(n))return true}return false};var tn=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var nn=[],rn={allowDangerousHtml:true},Ue=new WeakMap,Tt=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,r=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||r||s)){let p="default";return this.keyCache.set(t,p),p}let a=p=>{if(!p||p.length===0)return "";let m="";for(let u=0;u<p.length;u+=1){let f=p[u];if(u>0&&(m+=","),Array.isArray(f)){let[h,b]=f;if(typeof h=="function"){let g=Ue.get(h);g||(g=h.name,Ue.set(h,g)),m+=g;}else m+=String(h);m+=":",m+=JSON.stringify(b);}else if(typeof f=="function"){let h=Ue.get(f);h||(h=f.name,Ue.set(f,h)),m+=h;}else m+=String(f);}return m},l=a(n),i=a(r),d=s?JSON.stringify(s):"",c=`${i}::${l}::${d}`;return this.keyCache.set(t,c),c}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let r=this.cache.keys().next().value;r&&this.cache.delete(r);}this.cache.set(n,o);}clear(){this.cache.clear();}},sn=new Tt,Pt=e=>{let t=Ps(e),o=e.children||"",n=t.runSync(t.parse(o),o);return Rs(n,e)},Ps=e=>{let t=sn.get(e);if(t)return t;let o=Is(e);return sn.set(e,o),o},Ms=e=>e.some(t=>Array.isArray(t)?t[0]===on:t===on),Is=e=>{let t=e.rehypePlugins||nn,o=e.remarkPlugins||nn,n=Ms(t)?o:[...o,tn],r=e.remarkRehypeOptions?{...rn,...e.remarkRehypeOptions}:rn;return unified().use(ks).use(n).use(xs,r).use(t)},an=e=>e,Ns=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},Ls=(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);}},Ss=(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},Rs=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:r,skipHtml:s,unwrapDisallowed:a,urlTransform:l}=t;if(o||n||r||s||l){let d=l||an;visit(e,(c,p,m)=>{if(c.type==="raw"&&m&&typeof p=="number")return Ns(m,p,s,c.value),p;if(c.type==="element"&&(Ls(c,d),Ss(c,p,m,n,r,o)&&m&&typeof p=="number"))return a&&c.children?m.children.splice(p,1,...c.children):m.children.splice(p,1),p});}return toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true})};var Hs=/\[\^[\w-]{1,200}\](?!:)/,Ds=/\[\^[\w-]{1,200}\]:/;var Bs=/<(\w+)[\s>]/,As=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ln=new Map,cn=new Map,Os=e=>{let t=e.toLowerCase(),o=ln.get(t);if(o)return o;let n=new RegExp(`<${t}(?=[\\s>/])[^>]*>`,"gi");return ln.set(t,n),n},Vs=e=>{let t=e.toLowerCase(),o=cn.get(t);if(o)return o;let n=new RegExp(`</${t}(?=[\\s>])[^>]*>`,"gi");return cn.set(t,n),n},dn=(e,t)=>{if(As.has(t.toLowerCase()))return 0;let o=e.match(Os(t));if(!o)return 0;let n=0;for(let r of o)r.trimEnd().endsWith("/>")||(n+=1);return n},mn=(e,t)=>{let o=e.match(Vs(t));return o?o.length:0},js=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},Mt=e=>{let t=Hs.test(e),o=Ds.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),r=[],s=[],a=false;for(let l of n){let i=l.raw,d=r.length;if(s.length>0){r[d-1]+=i;let c=s.at(-1),p=dn(i,c),m=mn(i,c);for(let u=0;u<p;u+=1)s.push(c);for(let u=0;u<m;u+=1)s.length>0&&s.at(-1)===c&&s.pop();continue}if(l.type==="html"&&l.block){let c=i.match(Bs);if(c){let p=c[1],m=dn(i,p),u=mn(i,p);m>u&&s.push(p);}}if(d>0&&!a){let c=r[d-1];if(js(c)%2===1){r[d-1]=c+i;continue}}r.push(i),l.type!=="space"&&(a=l.type==="code");}return r};var un=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>{if(!l.includes(`
14
+
15
+ `))return a+l+i;let d=l.replace(/\n\n/g,`
16
+ <!---->
17
+ `),c=(d.startsWith(`
18
+ `)?"":`
19
+ `)+d+(d.endsWith(`
20
+ `)?"":`
21
+ `);return `${a}${c}${i}
22
+
23
+ `});}return o};var Fs=/([\\`*_~[\]|])/g,zs=e=>e.replace(Fs,"\\$1"),pn=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>{let d=zs(l).replace(/\n\n/g,"&#10;&#10;");return a+d+i});}return o};var fn=e=>e.type==="text"?e.value:"children"in e&&Array.isArray(e.children)?e.children.map(fn).join(""):"",gn=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=fn(n);n.children=r?[{type:"text",value:r}]:[];}});};var bn=()=>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 Gs=/^[ \t]*<[\w!/?-]/,Ys=/(^|\n)[ \t]{4,}(?=<[\w!/?-])/g,Qs=e=>typeof e!="string"||e.length===0||!Gs.test(e)?e:e.replace(Ys,"$1"),Cn,kn,xn,vn,Ge={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(kn=(Cn=defaultSchema.protocols)==null?void 0:Cn.href)!=null?kn:[],"tel"]},attributes:{...defaultSchema.attributes,code:[...(vn=(xn=defaultSchema.attributes)==null?void 0:xn.code)!=null?vn:[],"metastring"]}},Nt={raw:on,sanitize:[Pn,Ge],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},ea={gfm:[Js,{}],codeMeta:bn},wn=Object.values(Nt),ta=Object.values(ea),oa={block:" \u258B",circle:" \u25CF"},na=["github-light","github-dark"],ra={enabled:true},Mn=memo(({content:e,shouldParseIncompleteMarkdown:t,shouldNormalizeHtmlIndentation:o,index:n,isIncomplete:r,dir:s,animatePlugin:a,...l})=>{if(a){let c=a.getLastRenderCharCount();a.setPrevContentLength(c);}let i=typeof e=="string"&&o?Qs(e):e,d=jsx(Pt,{...l,children:i});return jsx(nt.Provider,{value:r,children:s?jsx("div",{dir:s,style:{display:"contents"},children:d}):d})},(e,t)=>{if(e.content!==t.content||e.shouldNormalizeHtmlIndentation!==t.shouldNormalizeHtmlIndentation||e.index!==t.index||e.isIncomplete!==t.isIncomplete||e.dir!==t.dir)return false;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(r=>{var s,a;return ((s=e.components)==null?void 0:s[r])!==((a=t.components)==null?void 0:a[r])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Mn.displayName="Block";var sa=memo(({children:e,mode:t="streaming",dir:o,parseIncompleteMarkdown:n=true,normalizeHtmlIndentation:r=false,components:s,rehypePlugins:a=wn,remarkPlugins:l=ta,className:i,shikiTheme:d=na,mermaid:c,controls:p=true,isAnimating:m=false,animated:u,BlockComponent:f=Mn,parseMarkdownIntoBlocksFn:h=Mt,caret:b,plugins:g,remend:T,linkSafety:v=ra,lineNumbers:C=true,allowedTags:I,literalTagContent:N,translations:E,icons:D,prefix:F,onAnimationStart:z,onAnimationEnd:W,..._})=>{let Z=useId(),[Q,X]=useTransition(),y=useMemo(()=>Vt(F),[F]),H=useRef(null),q=useRef(z),we=useRef(W);q.current=z,we.current=W,useEffect(()=>{var O,U,ie;if(t==="static")return;let x=H.current;if(H.current=m,x===null){m&&((O=q.current)==null||O.call(q));return}m&&!x?(U=q.current)==null||U.call(q):!m&&x&&((ie=we.current)==null||ie.call(we));},[m,t]);let ee=useMemo(()=>I?Object.keys(I):[],[I]),se=useMemo(()=>{if(typeof e!="string")return "";let x=t==="streaming"&&n?Us(e,T):e;return N&&N.length>0&&(x=pn(x,N)),ee.length>0&&(x=un(x,ee)),x},[e,t,n,T,ee,N]),ae=useMemo(()=>h(se),[se,h]),[Ce,G]=useState(ae);useEffect(()=>{t==="streaming"&&!ke?X(()=>{G(ae);}):G(ae);},[ae,t]);let A=t==="streaming"?Ce:ae,Ae=useMemo(()=>o==="auto"?A.map(Je):void 0,[A,o]),Rn=useMemo(()=>A.map((x,O)=>`${Z}-${O}`),[A.length,Z]),Qe=useMemo(()=>u===true?"true":u?JSON.stringify(u):"",[u]),ke=useMemo(()=>Qe?Qe==="true"?xe():xe(u):null,[Qe]),Lt=useMemo(()=>{var x,O;return {shikiTheme:(O=(x=g==null?void 0:g.code)==null?void 0:x.getThemes())!=null?O:d,controls:p,isAnimating:m,lineNumbers:C,mode:t,mermaid:c,linkSafety:v}},[d,p,m,C,t,c,v,g==null?void 0:g.code]),En=useMemo(()=>E?JSON.stringify(E):"",[E]),St=useMemo(()=>({...je,...E}),[En]),Rt=useMemo(()=>{let{inlineCode:x,...O}=s!=null?s:{},U={...Qo,...O};if(x){let ie=U.code;U.code=fe=>"data-block"in fe?ie?createElement(ie,fe):null:createElement(x,fe);}return U},[s]),Et=useMemo(()=>{let x=[];return g!=null&&g.cjk&&(x=[...x,...g.cjk.remarkPluginsBefore]),x=[...x,...l],g!=null&&g.cjk&&(x=[...x,...g.cjk.remarkPluginsAfter]),g!=null&&g.math&&(x=[...x,g.math.remarkPlugin]),x},[l,g==null?void 0:g.math,g==null?void 0:g.cjk]),Ht=useMemo(()=>{var O;let x=a;if(I&&Object.keys(I).length>0&&a===wn){let U={...Ge,tagNames:[...(O=Ge.tagNames)!=null?O:[],...Object.keys(I)],attributes:{...Ge.attributes,...I}};x=[Nt.raw,[Pn,U],Nt.harden];}return N&&N.length>0&&(x=[...x,[gn,N]]),g!=null&&g.math&&(x=[...x,g.math.rehypePlugin]),ke&&m&&(x=[...x,ke.rehypePlugin]),x},[a,g==null?void 0:g.math,ke,m,I,N]),et=useMemo(()=>{if(!m||A.length===0)return false;let x=A.at(-1);return xt(x)||en(x)},[m,A]),Hn=useMemo(()=>b&&m&&!et?{"--streamdown-caret":`"${oa[b]}"`}:void 0,[b,m,et]);return t==="static"?jsx(Fe.Provider,{value:St,children:jsx(qe.Provider,{value:g!=null?g:null,children:jsx(M.Provider,{value:Lt,children:jsx(ct,{icons:D,children:jsx(Oe.Provider,{value:y,children:jsx("div",{className:y("space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",i),dir:o==="auto"?Je(se):o,children:jsx(Pt,{components:Rt,rehypePlugins:Ht,remarkPlugins:Et,..._,children:se})})})})})})}):jsx(Fe.Provider,{value:St,children:jsx(qe.Provider,{value:g!=null?g:null,children:jsx(M.Provider,{value:Lt,children:jsx(ct,{icons:D,children:jsx(Oe.Provider,{value:y,children:jsxs("div",{className:y("space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",b&&!et?"[&>*:last-child]:after:inline [&>*:last-child]:after:align-baseline [&>*:last-child]:after:content-[var(--streamdown-caret)]":null,i),style:Hn,children:[A.length===0&&b&&m&&jsx("span",{}),A.map((x,O)=>{var fe;let U=O===A.length-1,ie=m&&U&&xt(x);return jsx(f,{animatePlugin:ke,components:Rt,content:x,dir:(fe=Ae==null?void 0:Ae[O])!=null?fe:o!=="auto"?o:void 0,index:O,isIncomplete:ie,rehypePlugins:Ht,remarkPlugins:Et,shouldNormalizeHtmlIndentation:r,shouldParseIncompleteMarkdown:n,..._},Rn[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.lineNumbers===t.lineNumbers&&e.normalizeHtmlIndentation===t.normalizeHtmlIndentation&&e.literalTagContent===t.literalTagContent&&JSON.stringify(e.translations)===JSON.stringify(t.translations)&&e.prefix===t.prefix&&e.dir===t.dir);sa.displayName="Streamdown";var Sn=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:r=.1,showControls:s=true,initialZoom:a=1,fullscreen:l=false})=>{let{RotateCcwIcon:i,ZoomInIcon:d,ZoomOutIcon:c}=S(),p=w(),m=useRef(null),u=useRef(null),[f,h]=useState(a),[b,g]=useState({x:0,y:0}),[T,v]=useState(false),[C,I]=useState({x:0,y:0}),[N,E]=useState({x:0,y:0}),D=useCallback(y=>{h(H=>Math.max(o,Math.min(n,H+y)));},[o,n]),F=useCallback(()=>{D(r);},[D,r]),z=useCallback(()=>{D(-r);},[D,r]),W=useCallback(()=>{h(a),g({x:0,y:0});},[a]),_=useCallback(y=>{y.preventDefault();let H=y.deltaY>0?-r:r;D(H);},[D,r]),Z=useCallback(y=>{if(y.button!==0||y.isPrimary===false)return;v(true),I({x:y.clientX,y:y.clientY}),E(b);let H=y.currentTarget;H instanceof HTMLElement&&H.setPointerCapture(y.pointerId);},[b]),Q=useCallback(y=>{if(!T)return;y.preventDefault();let H=y.clientX-C.x,q=y.clientY-C.y;g({x:N.x+H,y:N.y+q});},[T,C,N]),X=useCallback(y=>{v(false);let H=y.currentTarget;H instanceof HTMLElement&&H.releasePointerCapture(y.pointerId);},[]);return useEffect(()=>{let y=m.current;if(y)return y.addEventListener("wheel",_,{passive:false}),()=>{y.removeEventListener("wheel",_);}},[_]),useEffect(()=>{let y=u.current;if(y&&T)return document.body.style.userSelect="none",y.addEventListener("pointermove",Q,{passive:false}),y.addEventListener("pointerup",X),y.addEventListener("pointercancel",X),()=>{document.body.style.userSelect="",y.removeEventListener("pointermove",Q),y.removeEventListener("pointerup",X),y.removeEventListener("pointercancel",X);}},[T,Q,X]),jsxs("div",{className:p("relative flex flex-col",l?"h-full w-full":"min-h-28 w-full",t),ref:m,style:{cursor:T?"grabbing":"grab"},children:[s?jsxs("div",{className:p("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/80 p-1 supports-[backdrop-filter]:bg-background/70 supports-[backdrop-filter]:backdrop-blur-sm",l?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:f>=n,onClick:F,title:"Zoom in",type:"button",children:jsx(d,{size:16})}),jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:f<=o,onClick:z,title:"Zoom out",type:"button",children:jsx(c,{size:16})}),jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"),onClick:W,title:"Reset zoom and pan",type:"button",children:jsx(i,{size:16})})]}):null,jsx("div",{className:p("flex-1 origin-center transition-transform duration-150 ease-out",l?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:Z,ref:u,role:"application",style:{transform:`translate(${b.x}px, ${b.y}px) scale(${f})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var ho=({chart:e,className:t,config:o,fullscreen:n=false,showControls:r=true})=>{let s=w(),[a,l]=useState(null),[i,d]=useState(false),[c,p]=useState(""),[m,u]=useState(""),[f,h]=useState(0),{mermaid:b}=useContext(M),g=ge(),T=b==null?void 0:b.errorComponent,{shouldRender:v,containerRef:C}=Dt({immediate:n});if(useEffect(()=>{if(!v)return;if(!g){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),d(!0);let E=g.getMermaid(o),D=e.split("").reduce((W,_)=>(W<<5)-W+_.charCodeAt(0)|0,0),F=`mermaid-${Math.abs(D)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:z}=await E.render(F,e);p(z),u(z);}catch(E){if(!(m||c)){let D=E instanceof Error?E.message:"Failed to render Mermaid chart";l(D);}}finally{d(false);}})();},[e,o,f,v,g]),!(v||c||m))return jsx("div",{className:s("my-4 min-h-[200px]",t),ref:C});if(i&&!c&&!m)return jsx("div",{className:s("my-4 flex justify-center p-4",t),ref:C,children:jsxs("div",{className:s("flex items-center space-x-2 text-muted-foreground"),children:[jsx("div",{className:s("h-4 w-4 animate-spin rounded-full border-current border-b-2")}),jsx("span",{className:s("text-sm"),children:"Loading diagram..."})]})});if(a&&!c&&!m){let N=()=>h(E=>E+1);return T?jsx("div",{ref:C,children:jsx(T,{chart:e,error:a,retry:N})}):jsxs("div",{className:s("rounded-md bg-red-50 p-4",t),ref:C,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 I=c||m;return jsx("div",{className:s("size-full",t),"data-streamdown":"mermaid",ref:C,children:jsx(Sn,{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:I},role:"img"})})})};export{ea as A,Mn as B,sa as C,xe as a,rt as b,Ft as c,st as d,it as e,Fi as f,lt as g,je as h,ze as i,dt as j,_e as k,M as l,ho as m,he as n,de as o,gt as p,$e as q,me as r,Se as s,Gr as t,Re as u,Je as v,an as w,Mt as x,Qs as y,Nt as z};
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import {l,f,c}from'./chunk-XMZ7XVWH.js';import {useContext,useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';var R=({code:s,language:e,raw:t,className:h,startLine:d,lineNumbers:m,...p})=>{let{shikiTheme:l$1}=useContext(l),o=f(),[a,i]=useState(t);return useEffect(()=>{if(!o){i(t);return}let r=o.highlight({code:s,language:e,themes:l$1},c=>{i(c);});r&&i(r);},[s,e,l$1,o,t]),jsx(c,{className:h,language:e,lineNumbers:m,result:a,startLine:d,...p})};export{R as HighlightedCodeBlockBody};
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import * as react from 'react';
3
2
  import react__default, { SVGProps, JSX, ComponentType, HTMLAttributes, ComponentProps } from 'react';
4
- import { MermaidConfig } from 'mermaid';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
4
  import { RemendOptions } from 'remend';
6
5
  import { Pluggable, PluggableList } from 'unified';
7
6
  import { Element, Parents } from 'hast';
8
7
  import { Options as Options$1 } from 'remark-rehype';
8
+ import { MermaidConfig } from 'mermaid';
9
9
  import { BundledTheme, ThemeRegistrationAny, BundledLanguage } from 'shiki';
10
10
  export { BundledLanguage, BundledTheme, ThemeRegistrationAny } from 'shiki';
11
11
 
@@ -220,6 +220,59 @@ interface PluginConfig {
220
220
  renderers?: CustomRenderer[];
221
221
  }
222
222
 
223
+ type ControlsConfig = boolean | {
224
+ table?: boolean | {
225
+ copy?: boolean;
226
+ download?: boolean;
227
+ fullscreen?: boolean;
228
+ };
229
+ code?: boolean | {
230
+ copy?: boolean;
231
+ download?: boolean;
232
+ };
233
+ mermaid?: boolean | {
234
+ download?: boolean;
235
+ copy?: boolean;
236
+ fullscreen?: boolean;
237
+ panZoom?: boolean;
238
+ };
239
+ image?: boolean | {
240
+ download?: boolean;
241
+ fullscreen?: boolean;
242
+ };
243
+ };
244
+ interface LinkSafetyModalProps {
245
+ isOpen: boolean;
246
+ onClose: () => void;
247
+ onConfirm: () => void;
248
+ url: string;
249
+ }
250
+ interface LinkSafetyConfig {
251
+ enabled: boolean;
252
+ onLinkCheck?: (url: string) => Promise<boolean> | boolean;
253
+ renderModal?: (props: LinkSafetyModalProps) => React.ReactNode;
254
+ }
255
+ interface MermaidErrorComponentProps {
256
+ chart: string;
257
+ error: string;
258
+ retry: () => void;
259
+ }
260
+ interface MermaidOptions {
261
+ config?: MermaidConfig;
262
+ errorComponent?: React.ComponentType<MermaidErrorComponentProps>;
263
+ }
264
+ interface StreamdownContextType {
265
+ controls: ControlsConfig;
266
+ isAnimating: boolean;
267
+ /** Show line numbers in code blocks. @default true */
268
+ lineNumbers: boolean;
269
+ linkSafety?: LinkSafetyConfig;
270
+ mermaid?: MermaidOptions;
271
+ mode: "static" | "streaming";
272
+ shikiTheme: [ThemeInput, ThemeInput];
273
+ }
274
+ declare const StreamdownContext: react.Context<StreamdownContextType>;
275
+
223
276
  interface StreamdownTranslations {
224
277
  close: string;
225
278
  copied: string;
@@ -369,43 +422,6 @@ declare const tableDataToMarkdown: (data: TableData) => string;
369
422
  * @returns The normalized string with reduced indentation before HTML tags
370
423
  */
371
424
  declare const normalizeHtmlIndentation: (content: string) => string;
372
- type ControlsConfig = boolean | {
373
- table?: boolean | {
374
- copy?: boolean;
375
- download?: boolean;
376
- fullscreen?: boolean;
377
- };
378
- code?: boolean | {
379
- copy?: boolean;
380
- download?: boolean;
381
- };
382
- mermaid?: boolean | {
383
- download?: boolean;
384
- copy?: boolean;
385
- fullscreen?: boolean;
386
- panZoom?: boolean;
387
- };
388
- };
389
- interface LinkSafetyModalProps {
390
- isOpen: boolean;
391
- onClose: () => void;
392
- onConfirm: () => void;
393
- url: string;
394
- }
395
- interface LinkSafetyConfig {
396
- enabled: boolean;
397
- onLinkCheck?: (url: string) => Promise<boolean> | boolean;
398
- renderModal?: (props: LinkSafetyModalProps) => React.ReactNode;
399
- }
400
- interface MermaidErrorComponentProps {
401
- chart: string;
402
- error: string;
403
- retry: () => void;
404
- }
405
- interface MermaidOptions {
406
- config?: MermaidConfig;
407
- errorComponent?: React.ComponentType<MermaidErrorComponentProps>;
408
- }
409
425
  type AllowedTags = Record<string, string[]>;
410
426
  type StreamdownProps = Options & {
411
427
  mode?: "static" | "streaming";
@@ -463,17 +479,6 @@ declare const carets: {
463
479
  block: string;
464
480
  circle: string;
465
481
  };
466
- interface StreamdownContextType {
467
- controls: ControlsConfig;
468
- isAnimating: boolean;
469
- /** Show line numbers in code blocks. @default true */
470
- lineNumbers: boolean;
471
- linkSafety?: LinkSafetyConfig;
472
- mermaid?: MermaidOptions;
473
- mode: "static" | "streaming";
474
- shikiTheme: [ThemeInput, ThemeInput];
475
- }
476
- declare const StreamdownContext: react.Context<StreamdownContextType>;
477
482
  type BlockProps = Options & {
478
483
  content: string;
479
484
  shouldParseIncompleteMarkdown: boolean;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- export{B as Block,g as CodeBlock,d as CodeBlockContainer,i as CodeBlockCopyButton,j as CodeBlockDownloadButton,e as CodeBlockHeader,k as CodeBlockSkeleton,C as Streamdown,A as StreamdownContext,r as TableCopyDropdown,s as TableDownloadButton,t as TableDownloadDropdown,a as createAnimatePlugin,y as defaultRehypePlugins,z as defaultRemarkPlugins,h as defaultTranslations,v as defaultUrlTransform,u as detectTextDirection,p as escapeMarkdownTableCell,m as extractTableDataFromElement,x as normalizeHtmlIndentation,w as parseMarkdownIntoBlocks,n as tableDataToCSV,q as tableDataToMarkdown,o as tableDataToTSV,b as useIsCodeFenceIncomplete}from'./chunk-BO2N2NFS.js';
2
+ export{B as Block,g as CodeBlock,d as CodeBlockContainer,i as CodeBlockCopyButton,j as CodeBlockDownloadButton,e as CodeBlockHeader,k as CodeBlockSkeleton,C as Streamdown,l as StreamdownContext,s as TableCopyDropdown,t as TableDownloadButton,u as TableDownloadDropdown,a as createAnimatePlugin,z as defaultRehypePlugins,A as defaultRemarkPlugins,h as defaultTranslations,w as defaultUrlTransform,v as detectTextDirection,q as escapeMarkdownTableCell,n as extractTableDataFromElement,y as normalizeHtmlIndentation,x as parseMarkdownIntoBlocks,o as tableDataToCSV,r as tableDataToMarkdown,p as tableDataToTSV,b as useIsCodeFenceIncomplete}from'./chunk-XMZ7XVWH.js';
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export{m as Mermaid}from'./chunk-XMZ7XVWH.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lofcz/streamdown",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -26,23 +26,10 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "scripts": {
30
- "build": "tsup",
31
- "postbuild": "node scripts/postbuild.js",
32
- "test": "vitest run",
33
- "test:ui": "vitest --ui run",
34
- "test:coverage": "vitest --coverage run",
35
- "bench": "vitest bench --run > results.txt",
36
- "bench:ui": "vitest bench --ui --run",
37
- "size": "node scripts/bundle-size.js"
38
- },
39
29
  "author": "Hayden Bleasel <hayden.bleasel@vercel.com>",
40
30
  "license": "Apache-2.0",
41
31
  "description": "A drop-in replacement for react-markdown, designed for AI-powered streaming.",
42
32
  "devDependencies": {
43
- "@streamdown/cjk": "workspace:@lofcz/streamdown-cjk@*",
44
- "@streamdown/math": "workspace:@lofcz/streamdown-math@*",
45
- "@streamdown/mermaid": "workspace:@lofcz/streamdown-mermaid@*",
46
33
  "@testing-library/jest-dom": "^6.9.1",
47
34
  "@testing-library/react": "^16.3.0",
48
35
  "@types/hast": "^3.0.4",
@@ -57,7 +44,10 @@
57
44
  "rehype-stringify": "^10.0.1",
58
45
  "shiki": "^3.19.0",
59
46
  "tsup": "^8.5.1",
60
- "vitest": "^4.0.15"
47
+ "vitest": "^4.0.15",
48
+ "@streamdown/cjk": "npm:@lofcz/streamdown-cjk@1.0.3",
49
+ "@streamdown/math": "npm:@lofcz/streamdown-math@1.0.2",
50
+ "@streamdown/mermaid": "npm:@lofcz/streamdown-mermaid@1.0.2"
61
51
  },
62
52
  "peerDependencies": {
63
53
  "react": "^18.0.0 || ^19.0.0",
@@ -74,11 +64,21 @@
74
64
  "remark-gfm": "^4.0.1",
75
65
  "remark-parse": "^11.0.0",
76
66
  "remark-rehype": "^11.1.2",
77
- "remend": "workspace:@lofcz/remend@*",
67
+ "remend": "npm:@lofcz/remend@^1.3.0",
78
68
  "tailwind-merge": "^3.4.0",
79
69
  "unified": "^11.0.5",
80
70
  "mermaid": "^11.12.2",
81
71
  "unist-util-visit": "^5.0.0",
82
72
  "unist-util-visit-parents": "^6.0.0"
73
+ },
74
+ "scripts": {
75
+ "build": "tsup",
76
+ "postbuild": "node scripts/postbuild.js",
77
+ "test": "vitest run",
78
+ "test:ui": "vitest --ui run",
79
+ "test:coverage": "vitest --coverage run",
80
+ "bench": "vitest bench --run > results.txt",
81
+ "bench:ui": "vitest bench --ui --run",
82
+ "size": "node scripts/bundle-size.js"
83
83
  }
84
- }
84
+ }
@@ -1,23 +0,0 @@
1
- "use client";
2
- import {createContext,memo,useContext,useMemo,lazy,isValidElement,useId,useTransition,useRef,useEffect,useState,cloneElement,createElement,useCallback,Suspense}from'react';import {harden}from'rehype-harden';import Yo from'rehype-raw';import kn,{defaultSchema}from'rehype-sanitize';import $s from'remark-gfm';import Ws from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import {urlAttributes}from'html-url-attributes';import gs from'remark-parse';import bs from'remark-rehype';import {unified}from'unified';import {visit}from'unist-util-visit';import {Lexer}from'marked';var Bn=300,An="300px",On=500;function Rt(e={}){let{immediate:t=false,debounceDelay:o=Bn,rootMargin:n=An,idleTimeout:r=On}=e,[s,a]=useState(false),l=useRef(null),i=useRef(null),d=useRef(null),c=useMemo(()=>u=>{let f=Date.now();return window.setTimeout(()=>{u({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-f))});},1)},[]),p=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(u,f)=>window.requestIdleCallback(u,f):c,[c]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?u=>window.cancelIdleCallback(u):u=>{clearTimeout(u);},[]);return useEffect(()=>{if(t){a(true);return}let u=l.current;if(!u)return;i.current&&(clearTimeout(i.current),i.current=null),d.current&&(m(d.current),d.current=null);let f=()=>{i.current&&(clearTimeout(i.current),i.current=null),d.current&&(m(d.current),d.current=null);},h=v=>{d.current=p(w=>{w.timeRemaining()>0||w.didTimeout?(a(true),v.disconnect()):d.current=p(()=>{a(true),v.disconnect();},{timeout:r/2});},{timeout:r});},b=v=>{f(),i.current=window.setTimeout(()=>{var M,H;let w=v.takeRecords();(w.length===0||(H=(M=w.at(-1))==null?void 0:M.isIntersecting)!=null&&H)&&h(v);},o);},g=(v,w)=>{v.isIntersecting?b(w):f();},T=new IntersectionObserver(v=>{for(let w of v)g(w,T);},{rootMargin:n,threshold:0});return T.observe(u),()=>{i.current&&clearTimeout(i.current),d.current&&m(d.current),T.disconnect();}},[t,o,n,r,m,p]),{shouldRender:s,containerRef:l}}var St=/\s/,Fn=/^\s+$/,zn=new Set(["code","pre","svg","math","annotation"]),_n=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",qn=e=>e.some(t=>_n(t)&&zn.has(t.tagName)),$n=e=>{let t=[],o="",n=false;for(let r of e){let s=St.test(r);s!==n&&o&&(t.push(o),o=""),o+=r,n=s;}return o&&t.push(o),t},Wn=e=>{let t=[],o="";for(let n of e)St.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},Zn=(e,t,o,n,r,s)=>{let a=`--sd-animation:sd-${t};--sd-duration:${r?0:o}ms;--sd-easing:${n}`;return s&&(a+=`;--sd-delay:${s}ms`),{type:"element",tagName:"span",properties:{"data-sd-animate":true,style:a},children:[{type:"text",value:e}]}},Xn=(e,t,o,n,r)=>{let s=t.at(-1);if(!(s&&"children"in s))return;if(qn(t))return SKIP;let a=s,l=a.children.indexOf(e);if(l===-1)return;let i=e.value;if(!i.trim()){r.count+=i.length;return}let d=o.sep==="char"?Wn(i):$n(i),c=n.prevContentLength,p=d.map(m=>{let u=r.count;if(r.count+=m.length,Fn.test(m))return {type:"text",value:m};let f=c>0&&u<c,h=f?0:r.newIndex++*o.stagger;return Zn(m,o.animation,o.duration,o.easing,f,h)});return a.children.splice(l,1,...p),l+p.length},Jn=0;function be(e){var s,a,l,i,d;let t={animation:(s=e==null?void 0:e.animation)!=null?s:"fadeIn",duration:(a=e==null?void 0:e.duration)!=null?a:150,easing:(l=e==null?void 0:e.easing)!=null?l:"ease",sep:(i=e==null?void 0:e.sep)!=null?i:"word",stagger:(d=e==null?void 0:e.stagger)!=null?d:40},o={prevContentLength:0,lastRenderCharCount:0},n=Jn++,r=()=>c=>{let p={count:0,newIndex:0};visitParents(c,"text",(m,u)=>Xn(m,u,t,o,p)),o.lastRenderCharCount=p.count,o.prevContentLength=0;};return Object.defineProperty(r,"name",{value:`rehypeAnimate$${n}`}),{name:"animate",type:"animate",rehypePlugin:r,setPrevContentLength(c){o.prevContentLength=c;},getLastRenderCharCount(){let c=o.lastRenderCharCount;return o.lastRenderCharCount=0,c}}}be();var et=createContext(false),tt=()=>useContext(et);var he=(...e)=>twMerge(clsx(e)),Gn=(e,t)=>{if(!e||!t)return t;let o=`${e}:`;return t.split(/\s+/).filter(Boolean).map(n=>n.startsWith(o)?n:`${e}:${n}`).join(" ")},Dt=e=>e?(...t)=>Gn(e,twMerge(clsx(t))):he,W=(e,t,o)=>{let n=typeof t=="string"&&o.startsWith("text/csv")?"\uFEFF":"",r=typeof t=="string"?new Blob([n+t],{type:o}):t,s=URL.createObjectURL(r),a=document.createElement("a");a.href=s,a.download=e,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(s);};var Ee=createContext(he),y=()=>useContext(Ee);var tr=he("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),or=e=>{let t={};for(let o of e.split(";")){let n=o.indexOf(":");if(n>0){let r=o.slice(0,n).trim(),s=o.slice(n+1).trim();r&&s&&(t[r]=s);}}return t},At=memo(({children:e,result:t,language:o,className:n,startLine:r,lineNumbers:s=true,...a})=>{let l=y(),i=useMemo(()=>l(tr),[l]),d=useMemo(()=>{let c={};return t.bg&&(c["--sdm-bg"]=t.bg),t.fg&&(c["--sdm-fg"]=t.fg),t.rootStyle&&Object.assign(c,or(t.rootStyle)),c},[t.bg,t.fg,t.rootStyle]);return jsx("div",{className:l(n,"overflow-x-auto rounded-md border border-border bg-background p-4 text-sm"),"data-language":o,"data-streamdown":"code-block-body",...a,children:jsx("pre",{className:l(n,"bg-[var(--sdm-bg,inherit]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]"),style:d,children:jsx("code",{className:s?l("[counter-increment:line_0] [counter-reset:line]"):void 0,style:s&&r&&r>1?{counterReset:`line ${r-1}`}:void 0,children:t.tokens.map((c,p)=>jsx("span",{className:s?i:void 0,children:c.length===0||c.length===1&&c[0].content===""?`
3
- `:c.map((m,u)=>{let f={},h=!!m.bgColor;if(m.color&&(f["--sdm-c"]=m.color),m.bgColor&&(f["--sdm-tbg"]=m.bgColor),m.htmlStyle)for(let[b,g]of Object.entries(m.htmlStyle))b==="color"?f["--sdm-c"]=g:b==="background-color"?(f["--sdm-tbg"]=g,h=true):f[b]=g;return jsx("span",{className:l("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",h&&"bg-[var(--sdm-tbg)]",h&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:f,...m.htmlAttrs,children:m.content},u)})},p))})})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className&&e.startLine===t.startLine&&e.lineNumbers===t.lineNumbers);var ot=({className:e,language:t,style:o,isIncomplete:n,...r})=>{let s=y();return jsx("div",{className:s("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",e),"data-incomplete":n||void 0,"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...r})};var nt=createContext({code:""}),He=()=>useContext(nt);var rt=({language:e})=>{let t=y();return jsx("div",{className:t("flex h-8 items-center text-muted-foreground text-xs"),"data-language":e,"data-streamdown":"code-block-header",children:jsx("span",{className:t("ml-1 font-mono lowercase"),children:e})})};var lr=e=>{let t=e.length;for(;t>0&&e[t-1]===`
4
- `;)t--;return e.slice(0,t)},cr=lazy(()=>import('./highlighted-body-OFNGDK62.js').then(e=>({default:e.HighlightedCodeBlockBody}))),st=({code:e,language:t,className:o,children:n,isIncomplete:r=false,startLine:s,lineNumbers:a,...l})=>{let i=y(),d=useMemo(()=>lr(e),[e]),c=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:d.split(`
5
- `).map(p=>[{content:p,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[d]);return jsx(nt.Provider,{value:{code:e},children:jsxs(ot,{isIncomplete:r,language:t,children:[jsx(rt,{language:t}),n?jsx("div",{className:i("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:jsx("div",{className:i("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"code-block-actions",children:n})}):null,jsx(Suspense,{fallback:jsx(At,{className:o,language:t,lineNumbers:a,result:c,startLine:s,...l}),children:jsx(cr,{className:o,code:d,language:t,lineNumbers:a,raw:c,startLine:s,...l})})]})})};var jt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),Ft=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),zt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),_t=e=>jsxs("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),qt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),$t=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),Wt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),Zt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",fill:"currentColor",fillRule:"evenodd"})}),Xt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),Jt=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})});var we={CheckIcon:jt,CopyIcon:Ft,DownloadIcon:zt,ExternalLinkIcon:Zt,Loader2Icon:_t,Maximize2Icon:qt,RotateCcwIcon:$t,XIcon:Wt,ZoomInIcon:Xt,ZoomOutIcon:Jt},Ut=createContext(we),fr=(e,t)=>{if(e===t)return true;if(!(e&&t))return e===t;let o=Object.keys(e),n=Object.keys(t);return o.length!==n.length?false:o.every(r=>e[r]===t[r])},at=({icons:e,children:t})=>{let o=useRef(e),n=useRef(e?{...we,...e}:we);fr(o.current,e)||(o.current=e,n.current=e?{...we,...e}:we);let r=n.current;return jsx(Ut.Provider,{value:r,children:t})},L=()=>useContext(Ut);var De={copyCode:"Copy Code",downloadFile:"Download file",downloadDiagram:"Download diagram",downloadDiagramAsSvg:"Download diagram as SVG",downloadDiagramAsPng:"Download diagram as PNG",downloadDiagramAsMmd:"Download diagram as MMD",viewFullscreen:"View fullscreen",exitFullscreen:"Exit fullscreen",mermaidFormatSvg:"SVG",mermaidFormatPng:"PNG",mermaidFormatMmd:"MMD",copyTable:"Copy table",copyTableAsMarkdown:"Copy table as Markdown",copyTableAsCsv:"Copy table as CSV",copyTableAsTsv:"Copy table as TSV",downloadTable:"Download table",downloadTableAsCsv:"Download table as CSV",downloadTableAsMarkdown:"Download table as Markdown",tableFormatMarkdown:"Markdown",tableFormatCsv:"CSV",tableFormatTsv:"TSV",imageNotAvailable:"Image not available",downloadImage:"Download image",openExternalLink:"Open external link?",externalLinkWarning:"You're about to visit an external website.",close:"Close",copyLink:"Copy link",copied:"Copied",openLink:"Open link"},Be=createContext(De),D=()=>useContext(Be);var Ae=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...a})=>{let l=y(),[i,d]=useState(false),c=useRef(0),{code:p}=He(),{isAnimating:m}=useContext(R),u=D(),f=s!=null?s:p,h=async()=>{var T;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(f),d(!0),e==null||e(),c.current=window.setTimeout(()=>d(!1),o));}catch(v){t==null||t(v);}};useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let b=L(),g=i?b.CheckIcon:b.CopyIcon;return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-copy-button",disabled:m,onClick:h,title:u.copyCode,type:"button",...a,children:n!=null?n:jsx(g,{size:14})})};var Yt={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},it=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...a})=>{let l=y(),{code:i}=He(),{isAnimating:d}=useContext(R),c=D(),p=L(),m=s!=null?s:i,f=`file.${o&&o in Yt?Yt[o]:"txt"}`,h="text/plain",b=()=>{try{W(f,m,h),e==null||e();}catch(g){t==null||t(g);}};return jsx("button",{className:l("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),"data-streamdown":"code-block-download-button",disabled:d,onClick:b,title:c.downloadFile,type:"button",...a,children:n!=null?n:jsx(p.DownloadIcon,{size:14})})};var Oe=()=>{let{Loader2Icon:e}=L(),t=y();return jsxs("div",{className:t("w-full divide-y divide-border overflow-hidden rounded-xl border border-border"),children:[jsx("div",{className:t("h-[46px] w-full bg-muted/80")}),jsx("div",{className:t("flex w-full items-center justify-center p-4"),children:jsx(e,{className:t("size-4 animate-spin")})})]})};var Mr=/\.[^/.]+$/,oo=({node:e,className:t,src:o,alt:n,onLoad:r,onError:s,...a})=>{let{DownloadIcon:l}=L(),i=y(),d=useRef(null),[c,p]=useState(false),[m,u]=useState(false),f=D(),h=a.width!=null||a.height!=null,b=(c||h)&&!m,g=m&&!h;useEffect(()=>{let P=d.current;if(P!=null&&P.complete){let M=P.naturalWidth>0;p(M),u(!M);}},[]);let T=useCallback(P=>{p(true),u(false),r==null||r(P);},[r]),v=useCallback(P=>{p(false),u(true),s==null||s(P);},[s]),w=async()=>{if(o)try{let M=await(await fetch(o)).blob(),S=new URL(o,window.location.origin).pathname.split("/").pop()||"",F=S.split(".").pop(),j=S.includes(".")&&F!==void 0&&F.length<=4,z="";if(j)z=S;else {let B=M.type,_="png";B.includes("jpeg")||B.includes("jpg")?_="jpg":B.includes("png")?_="png":B.includes("svg")?_="svg":B.includes("gif")?_="gif":B.includes("webp")&&(_="webp"),z=`${(n||S||"image").replace(Mr,"")}.${_}`;}W(z,M,M.type);}catch(P){window.open(o,"_blank");}};return o?jsxs("div",{className:i("group relative my-4 inline-block"),"data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:i("max-w-full rounded-lg",g&&"hidden",t),"data-streamdown":"image",onError:v,onLoad:T,ref:d,src:o,...a}),g&&jsx("span",{className:i("text-muted-foreground text-xs italic"),"data-streamdown":"image-fallback",children:f.imageNotAvailable}),jsx("div",{className:i("pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block")}),b&&jsx("button",{className:i("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:w,title:f.downloadImage,type:"button",children:jsx(l,{size:14})})]}):null};var ke=0,le=()=>{ke+=1,ke===1&&(document.body.style.overflow="hidden");},ce=()=>{ke=Math.max(0,ke-1),ke===0&&(document.body.style.overflow="");};var so=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let{CheckIcon:r,CopyIcon:s,ExternalLinkIcon:a,XIcon:l}=L(),i=y(),[d,c]=useState(false),p=D(),m=useCallback(async()=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3);}catch(f){}},[e]),u=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){le();let f=h=>{h.key==="Escape"&&o();};return document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f),ce();}}},[t,o]),t?jsx("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm"),"data-streamdown":"link-safety-modal",onClick:o,onKeyDown:f=>{f.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:i("relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg"),onClick:f=>f.stopPropagation(),onKeyDown:f=>f.stopPropagation(),role:"presentation",children:[jsx("button",{className:i("absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:o,title:p.close,type:"button",children:jsx(l,{size:16})}),jsxs("div",{className:i("flex flex-col gap-2"),children:[jsxs("div",{className:i("flex items-center gap-2 font-semibold text-lg"),children:[jsx(a,{size:20}),jsx("span",{children:p.openExternalLink})]}),jsx("p",{className:i("text-muted-foreground text-sm"),children:p.externalLinkWarning})]}),jsx("div",{className:i("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxs("div",{className:i("flex gap-2"),children:[jsx("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted"),onClick:m,type:"button",children:d?jsxs(Fragment,{children:[jsx(r,{size:14}),jsx("span",{children:p.copied})]}):jsxs(Fragment,{children:[jsx(s,{size:14}),jsx("span",{children:p.copyLink})]})}),jsxs("button",{className:i("flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90"),onClick:u,type:"button",children:[jsx(a,{size:14}),jsx("span",{children:p.openLink})]})]})]})}):null};var Ve=createContext(null),ct=()=>useContext(Ve),Li=()=>{var t;let e=ct();return (t=e==null?void 0:e.code)!=null?t:null},de=()=>{var t;let e=ct();return (t=e==null?void 0:e.mermaid)!=null?t:null};var ao=e=>{var o;let t=ct();return t!=null&&t.renderers&&e&&(o=t.renderers.find(n=>Array.isArray(n.language)?n.language.includes(e):n.language===e))!=null?o:null};var io=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((r,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),l=new Image;l.crossOrigin="anonymous",l.onload=()=>{let i=document.createElement("canvas"),d=l.width*o,c=l.height*o;i.width=d,i.height=c;let p=i.getContext("2d");if(!p){s(new Error("Failed to create 2D canvas context for PNG export"));return}p.drawImage(l,0,0,d,c),i.toBlob(m=>{if(!m){s(new Error("Failed to create PNG blob"));return}r(m);},"image/png");},l.onerror=()=>s(new Error("Failed to load SVG image")),l.src=a;})};var co=({chart:e,children:t,className:o,onDownload:n,config:r,onError:s})=>{let a=y(),[l,i]=useState(false),d=useRef(null),{isAnimating:c}=useContext(R),p=L(),m=de(),u=D(),f=async h=>{try{if(h==="mmd"){W("diagram.mmd",e,"text/plain"),i(!1),n==null||n(h);return}if(!m){s==null||s(new Error("Mermaid plugin not available"));return}let b=m.getMermaid(r),g=e.split("").reduce((w,P)=>(w<<5)-w+P.charCodeAt(0)|0,0),T=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:v}=await b.render(T,e);if(!v){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(h==="svg"){W("diagram.svg",v,"image/svg+xml"),i(!1),n==null||n(h);return}if(h==="png"){let w=await io(v);W("diagram.png",w,"image/png"),n==null||n(h),i(!1);return}}catch(b){s==null||s(b);}};return useEffect(()=>{let h=b=>{let g=b.composedPath();d.current&&!g.includes(d.current)&&i(false);};return document.addEventListener("mousedown",h),()=>{document.removeEventListener("mousedown",h);}},[]),jsxs("div",{className:a("relative"),ref:d,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:c,onClick:()=>i(!l),title:u.downloadDiagram,type:"button",children:t!=null?t:jsx(p.DownloadIcon,{size:14})}),l?jsxs("div",{className:a("absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("svg"),title:u.downloadDiagramAsSvg,type:"button",children:u.mermaidFormatSvg}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("png"),title:u.downloadDiagramAsPng,type:"button",children:u.mermaidFormatPng}),jsx("button",{className:a("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("mmd"),title:u.downloadDiagramAsMmd,type:"button",children:u.mermaidFormatMmd})]}):null]})};var fo=({chart:e,config:t,onFullscreen:o,onExit:n,className:r,...s})=>{let{Maximize2Icon:a,XIcon:l}=L(),i=y(),[d,c]=useState(false),{isAnimating:p,controls:m}=useContext(R),u=D(),f=(()=>{if(typeof m=="boolean")return m;let b=m.mermaid;return b===false?false:b===true||b===void 0?true:b.panZoom!==false})(),h=()=>{c(!d);};return useEffect(()=>{if(d){le();let b=g=>{g.key==="Escape"&&c(false);};return document.addEventListener("keydown",b),()=>{document.removeEventListener("keydown",b),ce();}}},[d]),useEffect(()=>{d?o==null||o():n&&n();},[d,o,n]),jsxs(Fragment,{children:[jsx("button",{className:i("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:p,onClick:h,title:u.viewFullscreen,type:"button",...s,children:jsx(a,{size:14})}),d?createPortal(jsxs("div",{className:i("fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm"),onClick:h,onKeyDown:b=>{b.key==="Escape"&&h();},role:"button",tabIndex:0,children:[jsx("button",{className:i("absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:h,title:u.exitFullscreen,type:"button",children:jsx(l,{size:20})}),jsx("div",{className:i("flex size-full items-center justify-center p-4"),onClick:b=>b.stopPropagation(),onKeyDown:b=>b.stopPropagation(),role:"presentation",children:jsx(po,{chart:e,className:i("size-full [&_svg]:h-auto [&_svg]:w-auto"),config:t,fullscreen:true,showControls:f})})]}),document.body):null]})};var ue=e=>{var s,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let l of n)t.push(((s=l.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let l of r){let i=[],d=l.querySelectorAll("td");for(let c of d)i.push(((a=c.textContent)==null?void 0:a.trim())||"");o.push(i);}return {headers:t,rows:o}},ne=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false,d=false;for(let c of l){if(c==='"'){i=true,d=true;break}(c===","||c===`
6
- `)&&(i=true);}return i?d?`"${l.replace(/"/g,'""')}"`:`"${l}"`:l},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(","),a+=1);for(let l of o)s[a]=l.map(n).join(","),a+=1;return s.join(`
7
- `)},dt=e=>{let{headers:t,rows:o}=e,n=l=>{let i=false;for(let c of l)if(c===" "||c===`
8
- `||c==="\r"){i=true;break}if(!i)return l;let d=[];for(let c of l)c===" "?d.push("\\t"):c===`
9
- `?d.push("\\n"):c==="\r"?d.push("\\r"):d.push(c);return d.join("")},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(" "),a+=1);for(let l of o)s[a]=l.map(n).join(" "),a+=1;return s.join(`
10
- `)},je=e=>{let t=false;for(let n of e)if(n==="\\"||n==="|"){t=true;break}if(!t)return e;let o=[];for(let n of e)n==="\\"?o.push("\\\\"):n==="|"?o.push("\\|"):o.push(n);return o.join("")},re=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),r=0,s=t.map(l=>je(l));n[r]=`| ${s.join(" | ")} |`,r+=1;let a=new Array(t.length);for(let l=0;l<t.length;l+=1)a[l]="---";n[r]=`| ${a.join(" | ")} |`,r+=1;for(let l of o)if(l.length<t.length){let i=new Array(t.length);for(let d=0;d<t.length;d+=1)i[d]=d<l.length?je(l[d]):"";n[r]=`| ${i.join(" | ")} |`,r+=1;}else {let i=l.map(d=>je(d));n[r]=`| ${i.join(" | ")} |`,r+=1;}return n.join(`
11
- `)};var Te=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3})=>{let s=y(),[a,l]=useState(false),[i,d]=useState(false),c=useRef(null),p=useRef(0),{isAnimating:m}=useContext(R),u=D(),f=async g=>{var T,v;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.write)){n==null||n(new Error("Clipboard API not available"));return}try{let w=(v=c.current)==null?void 0:v.closest('[data-streamdown="table-wrapper"]'),P=w==null?void 0:w.querySelector("table");if(!P){n==null||n(new Error("Table not found"));return}let M=ue(P),F=({csv:ne,tsv:dt,md:re}[g]||re)(M),j=new ClipboardItem({"text/plain":new Blob([F],{type:"text/plain"}),"text/html":new Blob([P.outerHTML],{type:"text/html"})});await navigator.clipboard.write([j]),d(!0),l(!1),o==null||o(g),p.current=window.setTimeout(()=>d(!1),r);}catch(w){n==null||n(w);}};useEffect(()=>{let g=T=>{let v=T.composedPath();c.current&&!v.includes(c.current)&&l(false);};return document.addEventListener("mousedown",g),()=>{document.removeEventListener("mousedown",g),window.clearTimeout(p.current);}},[]);let h=L(),b=i?h.CheckIcon:h.CopyIcon;return jsxs("div",{className:s("relative"),ref:c,children:[jsx("button",{className:s("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!a),title:u.copyTable,type:"button",children:e!=null?e:jsx(b,{height:14,width:14})}),a?jsxs("div",{className:s("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("md"),title:u.copyTableAsMarkdown,type:"button",children:u.tableFormatMarkdown}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("csv"),title:u.copyTableAsCsv,type:"button",children:u.tableFormatCsv}),jsx("button",{className:s("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>f("tsv"),title:u.copyTableAsTsv,type:"button",children:u.tableFormatTsv})]}):null]})};var Wr=({children:e,className:t,onDownload:o,onError:n,format:r="csv",filename:s})=>{let a=y(),{isAnimating:l}=useContext(R),i=D(),d=L(),c=p=>{try{let u=p.currentTarget.closest('[data-streamdown="table-wrapper"]'),f=u==null?void 0:u.querySelector("table");if(!f){n==null||n(new Error("Table not found"));return}let h=ue(f),b="",g="",T="";switch(r){case "csv":b=ne(h),g="text/csv",T="csv";break;case "markdown":b=re(h),g="text/markdown",T="md";break;default:b=ne(h),g="text/csv",T="csv";}W(`${s||"table"}.${T}`,b,g),o==null||o();}catch(m){n==null||n(m);}};return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:c,title:r==="csv"?i.downloadTableAsCsv:i.downloadTableAsMarkdown,type:"button",children:e!=null?e:jsx(d.DownloadIcon,{size:14})})},Pe=({children:e,className:t,onDownload:o,onError:n})=>{let r=y(),[s,a]=useState(false),l=useRef(null),{isAnimating:i}=useContext(R),d=D(),c=L(),p=m=>{var u;try{let f=(u=l.current)==null?void 0:u.closest('[data-streamdown="table-wrapper"]'),h=f==null?void 0:f.querySelector("table");if(!h){n==null||n(new Error("Table not found"));return}let b=ue(h),g=m==="csv"?ne(b):re(b);W(`table.${m==="csv"?"csv":"md"}`,g,m==="csv"?"text/csv":"text/markdown"),a(!1),o==null||o(m);}catch(f){n==null||n(f);}};return useEffect(()=>{let m=u=>{let f=u.composedPath();l.current&&!f.includes(l.current)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:r("relative"),ref:l,children:[jsx("button",{className:r("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>a(!s),title:d.downloadTable,type:"button",children:e!=null?e:jsx(c.DownloadIcon,{size:14})}),s?jsxs("div",{className:r("absolute top-full right-0 z-20 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg"),children:[jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>p("csv"),title:d.downloadTableAsCsv,type:"button",children:d.tableFormatCsv}),jsx("button",{className:r("w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40"),onClick:()=>p("markdown"),title:d.downloadTableAsMarkdown,type:"button",children:d.tableFormatMarkdown})]}):null]})};var Co=({children:e,className:t,showCopy:o=true,showDownload:n=true})=>{let{Maximize2Icon:r,XIcon:s}=L(),a=y(),[l,i]=useState(false),{isAnimating:d}=useContext(R),c=D(),p=()=>{i(true);},m=()=>{i(false);};return useEffect(()=>{if(l){le();let u=f=>{f.key==="Escape"&&i(false);};return document.addEventListener("keydown",u),()=>{document.removeEventListener("keydown",u),ce();}}},[l]),jsxs(Fragment,{children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:p,title:c.viewFullscreen,type:"button",children:jsx(r,{size:14})}),l?createPortal(jsx("div",{"aria-label":c.viewFullscreen,"aria-modal":"true",className:a("fixed inset-0 z-50 flex flex-col bg-background"),"data-streamdown":"table-fullscreen",onClick:m,onKeyDown:u=>{u.key==="Escape"&&m();},role:"dialog",children:jsxs("div",{className:a("flex h-full flex-col"),onClick:u=>u.stopPropagation(),onKeyDown:u=>u.stopPropagation(),role:"presentation",children:[jsxs("div",{className:a("flex items-center justify-end gap-1 p-4"),children:[o?jsx(Te,{}):null,n?jsx(Pe,{}):null,jsx("button",{className:a("rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground"),onClick:m,title:c.exitFullscreen,type:"button",children:jsx(s,{size:20})})]}),jsx("div",{className:a("flex-1 overflow-auto p-4 pt-0 [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10"),children:jsx("table",{className:a("w-full border-collapse border border-border"),"data-streamdown":"table",children:e})})]})}),document.body):null]})};var vo=({children:e,className:t,showControls:o,showCopy:n=true,showDownload:r=true,showFullscreen:s=true,...a})=>{let l=y(),i=o&&n,d=o&&r,c=o&&s,p=i||d||c;return jsxs("div",{className:l("my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2"),"data-streamdown":"table-wrapper",children:[p?jsxs("div",{className:l("flex items-center justify-end gap-1"),children:[i?jsx(Te,{}):null,d?jsx(Pe,{}):null,c?jsx(Co,{showCopy:i,showDownload:d,children:e}):null]}):null,jsx("div",{className:l("border-collapse overflow-x-auto overflow-y-auto rounded-md border border-border bg-background"),children:jsx("table",{className:l("w-full divide-y divide-border",t),"data-streamdown":"table",...a,children:e})})]})};var es=/startLine=(\d+)/,ts=/\bnoLineNumbers\b/,os=lazy(()=>import('./mermaid-GHXKKRXX.js').then(e=>({default:e.Mermaid}))),ns=/language-([^\s]+)/;function qe(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let o=e.position.start,n=t.position.start,r=e.position.end,s=t.position.end;return (o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(r==null?void 0:r.line)===(s==null?void 0:s.line)&&(r==null?void 0:r.column)===(s==null?void 0:s.column)}function E(e,t){return e.className===t.className&&qe(e.node,t.node)}var ft=(e,t)=>typeof e=="boolean"?e:e[t]!==false,pt=(e,t)=>{if(typeof e=="boolean")return e;let o=e.table;return o===false?false:o===true||o===void 0?true:o[t]!==false},To=(e,t)=>{if(typeof e=="boolean")return e;let o=e.code;return o===false?false:o===true||o===void 0?true:o[t]!==false},Fe=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===false?false:o===true||o===void 0?true:o[t]!==false},bt=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("ol",{className:r("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e})},(e,t)=>E(e,t));bt.displayName="MarkdownOl";var Po=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("li",{className:r("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e})},(e,t)=>e.className===t.className&&qe(e.node,t.node));Po.displayName="MarkdownLi";var Mo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("ul",{className:r("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e})},(e,t)=>E(e,t));Mo.displayName="MarkdownUl";var Io=memo(({className:e,node:t,...o})=>{let n=y();return jsx("hr",{className:n("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o})},(e,t)=>E(e,t));Io.displayName="MarkdownHr";var No=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("span",{className:r("font-semibold",t),"data-streamdown":"strong",...n,children:e})},(e,t)=>E(e,t));No.displayName="MarkdownStrong";var rs=({children:e,className:t,href:o,node:n,...r})=>{let s=y(),{linkSafety:a}=useContext(R),[l,i]=useState(false),d=o==="streamdown:incomplete-link",c=useCallback(async f=>{if(!(!(a!=null&&a.enabled&&o)||d)){if(f.preventDefault(),a.onLinkCheck&&await a.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}i(true);}},[a,o,d]),p=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),m=useCallback(()=>{i(false);},[]),u={url:o!=null?o:"",isOpen:l,onClose:m,onConfirm:p};return a!=null&&a.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:s("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":d,"data-streamdown":"link",onClick:c,type:"button",children:e}),a.renderModal?a.renderModal(u):jsx(so,{...u})]}):jsx("a",{className:s("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":d,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...r,children:e})},Lo=memo(rs,(e,t)=>E(e,t)&&e.href===t.href);Lo.displayName="MarkdownA";var Ro=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h1",{className:r("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e})},(e,t)=>E(e,t));Ro.displayName="MarkdownH1";var So=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h2",{className:r("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e})},(e,t)=>E(e,t));So.displayName="MarkdownH2";var Eo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h3",{className:r("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e})},(e,t)=>E(e,t));Eo.displayName="MarkdownH3";var Ho=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h4",{className:r("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e})},(e,t)=>E(e,t));Ho.displayName="MarkdownH4";var Do=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h5",{className:r("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e})},(e,t)=>E(e,t));Do.displayName="MarkdownH5";var Bo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("h6",{className:r("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e})},(e,t)=>E(e,t));Bo.displayName="MarkdownH6";var Ao=memo(({children:e,className:t,node:o,...n})=>{let{controls:r}=useContext(R),s=ft(r,"table"),a=pt(r,"copy"),l=pt(r,"download"),i=pt(r,"fullscreen");return jsx(vo,{className:t,showControls:s,showCopy:a,showDownload:l,showFullscreen:i,...n,children:e})},(e,t)=>E(e,t));Ao.displayName="MarkdownTable";var Oo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("thead",{className:r("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e})},(e,t)=>E(e,t));Oo.displayName="MarkdownThead";var Vo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("tbody",{className:r("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e})},(e,t)=>E(e,t));Vo.displayName="MarkdownTbody";var jo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("tr",{className:r("border-border",t),"data-streamdown":"table-row",...n,children:e})},(e,t)=>E(e,t));jo.displayName="MarkdownTr";var Fo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("th",{className:r("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e})},(e,t)=>E(e,t));Fo.displayName="MarkdownTh";var zo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("td",{className:r("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e})},(e,t)=>E(e,t));zo.displayName="MarkdownTd";var _o=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("blockquote",{className:r("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e})},(e,t)=>E(e,t));_o.displayName="MarkdownBlockquote";var qo=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("sup",{className:r("text-sm",t),"data-streamdown":"superscript",...n,children:e})},(e,t)=>E(e,t));qo.displayName="MarkdownSup";var $o=memo(({children:e,className:t,node:o,...n})=>{let r=y();return jsx("sub",{className:r("text-sm",t),"data-streamdown":"subscript",...n,children:e})},(e,t)=>E(e,t));$o.displayName="MarkdownSub";var Wo=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=i=>{var m,u;if(!isValidElement(i))return false;let d=Array.isArray(i.props.children)?i.props.children:[i.props.children],c=false,p=false;for(let f of d)if(f){if(typeof f=="string")f.trim()!==""&&(c=true);else if(isValidElement(f))if(((m=f.props)==null?void 0:m["data-footnote-backref"])!==void 0)p=true;else {let h=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let b of h){if(typeof b=="string"&&b.trim()!==""){c=true;break}if(isValidElement(b)&&((u=b.props)==null?void 0:u["data-footnote-backref"])===void 0){c=true;break}}}}return p&&!c},a=Array.isArray(e)?e.map(i=>{if(!isValidElement(i))return i;if(i.type===bt){let c=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(p=>!s(p));return c.length===0?null:{...i,props:{...i.props,children:c}}}return i}):e;return (Array.isArray(a)?a.some(i=>i!==null):a!==null)?jsx("section",{className:t,...n,children:a}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>E(e,t));Wo.displayName="MarkdownSection";var ss=({node:e,className:t,children:o,...n})=>{var S,F;let r=y(),s=!("data-block"in n),{mermaid:a,controls:l,lineNumbers:i}=useContext(R),d=de(),c=tt(),p=t==null?void 0:t.match(ns),m=(S=p==null?void 0:p.at(1))!=null?S:"",u=ao(m);if(s)return jsx("code",{className:r("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let f=(F=e==null?void 0:e.properties)==null?void 0:F.metastring,h=f==null?void 0:f.match(es),b=h?Number.parseInt(h[1],10):void 0,g=b!==void 0&&b>=1?b:void 0,v=!(f?ts.test(f):false)&&i!==false,w="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?w=o.props.children:typeof o=="string"&&(w=o),u){let j=u.component;return jsx(Suspense,{fallback:jsx(Oe,{}),children:jsx(j,{code:w,isIncomplete:c,language:m,meta:f})})}if(m==="mermaid"&&d){let j=ft(l,"mermaid"),z=Fe(l,"download"),B=Fe(l,"copy"),_=Fe(l,"fullscreen"),Q=Fe(l,"panZoom"),U=j&&(z||B||_);return jsx(Suspense,{fallback:jsx(Oe,{}),children:jsxs("div",{className:r("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",t),"data-streamdown":"mermaid-block",children:[jsx("div",{className:r("flex h-8 items-center text-muted-foreground text-xs"),children:jsx("span",{className:r("ml-1 font-mono lowercase"),children:"mermaid"})}),U?jsx("div",{className:r("pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end"),children:jsxs("div",{className:r("pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur"),"data-streamdown":"mermaid-block-actions",children:[z?jsx(co,{chart:w,config:a==null?void 0:a.config}):null,B?jsx(Ae,{code:w}):null,_?jsx(fo,{chart:w,config:a==null?void 0:a.config}):null]})}):null,jsx("div",{className:r("rounded-md border border-border bg-background"),children:jsx(os,{chart:w,config:a==null?void 0:a.config,showControls:Q})})]})})}let P=ft(l,"code"),M=To(l,"download"),H=To(l,"copy");return jsx(st,{className:t,code:w,isIncomplete:c,language:m,lineNumbers:v,startLine:g,children:P?jsxs(Fragment,{children:[M?jsx(it,{code:w,language:m}):null,H?jsx(Ae,{}):null]}):null})},Zo=memo(ss,(e,t)=>e.className===t.className&&qe(e.node,t.node));Zo.displayName="MarkdownCode";var Xo=memo(oo,(e,t)=>e.className===t.className&&qe(e.node,t.node));Xo.displayName="MarkdownImg";var Jo=memo(({children:e,node:t,...o})=>{let r=(Array.isArray(e)?e:[e]).filter(s=>s!=null&&s!=="");if(r.length===1&&isValidElement(r[0])){let s=r[0].props.node,a=s==null?void 0:s.tagName;if(a==="img")return jsx(Fragment,{children:e});if(a==="code"&&"data-block"in r[0].props)return jsx(Fragment,{children:e})}return jsx("p",{...o,children:e})},(e,t)=>E(e,t));Jo.displayName="MarkdownParagraph";var Ko={ol:bt,li:Po,ul:Mo,hr:Io,strong:No,a:Lo,h1:Ro,h2:So,h3:Eo,h4:Ho,h5:Do,h6:Bo,table:Ao,thead:Oo,tbody:Vo,tr:jo,th:Fo,td:zo,blockquote:_o,code:Zo,img:Xo,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:qo,sub:$o,p:Jo,section:Wo};var as=/[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/,is=/\p{L}/u;function $e(e){let t=e.replace(/^#{1,6}\s+/gm,"").replace(/(\*{1,3}|_{1,3})/g,"").replace(/`[^`]*`/g,"").replace(/\[([^\]]*)\]\([^)]*\)/g,"$1").replace(/^[\s>*\-+\d.]+/gm,"");for(let o of t){if(as.test(o))return "rtl";if(is.test(o))return "ltr"}return "ltr"}var ls=/^[ \t]{0,3}(`{3,}|~{3,})/,cs=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,ht=e=>{let t=e.split(`
12
- `),o=null,n=0;for(let r of t){let s=ls.exec(r);if(o===null){if(s){let a=s[1];o=a[0],n=a.length;}}else if(s){let a=s[1],l=a[0],i=a.length;l===o&&i>=n&&(o=null,n=0);}}return o!==null},Uo=e=>{let t=e.split(`
13
- `);for(let o of t){let n=o.trim();if(n.length>0&&n.includes("|")&&cs.test(n))return true}return false};var Go=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var Qo=[],en={allowDangerousHtml:true},We=new WeakMap,wt=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,r=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||r||s)){let p="default";return this.keyCache.set(t,p),p}let a=p=>{if(!p||p.length===0)return "";let m="";for(let u=0;u<p.length;u+=1){let f=p[u];if(u>0&&(m+=","),Array.isArray(f)){let[h,b]=f;if(typeof h=="function"){let g=We.get(h);g||(g=h.name,We.set(h,g)),m+=g;}else m+=String(h);m+=":",m+=JSON.stringify(b);}else if(typeof f=="function"){let h=We.get(f);h||(h=f.name,We.set(f,h)),m+=h;}else m+=String(f);}return m},l=a(n),i=a(r),d=s?JSON.stringify(s):"",c=`${i}::${l}::${d}`;return this.keyCache.set(t,c),c}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let r=this.cache.keys().next().value;r&&this.cache.delete(r);}this.cache.set(n,o);}clear(){this.cache.clear();}},tn=new wt,Ct=e=>{let t=ws(e),o=e.children||"",n=t.runSync(t.parse(o),o);return Ps(n,e)},ws=e=>{let t=tn.get(e);if(t)return t;let o=ks(e);return tn.set(e,o),o},Cs=e=>e.some(t=>Array.isArray(t)?t[0]===Yo:t===Yo),ks=e=>{let t=e.rehypePlugins||Qo,o=e.remarkPlugins||Qo,n=Cs(t)?o:[...o,Go],r=e.remarkRehypeOptions?{...en,...e.remarkRehypeOptions}:en;return unified().use(gs).use(n).use(bs,r).use(t)},on=e=>e,vs=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},xs=(e,t)=>{var o;for(let n in urlAttributes)if(Object.hasOwn(urlAttributes,n)&&Object.hasOwn(e.properties,n)){let r=e.properties[n],s=urlAttributes[n];(s===null||s.includes(e.tagName))&&(e.properties[n]=(o=t(String(r||""),n,e))!=null?o:void 0);}},Ts=(e,t,o,n,r,s)=>{let a=false;return n?a=!n.includes(e.tagName):r&&(a=r.includes(e.tagName)),!a&&s&&typeof t=="number"&&(a=!s(e,t,o)),a},Ps=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:r,skipHtml:s,unwrapDisallowed:a,urlTransform:l}=t;if(o||n||r||s||l){let d=l||on;visit(e,(c,p,m)=>{if(c.type==="raw"&&m&&typeof p=="number")return vs(m,p,s,c.value),p;if(c.type==="element"&&(xs(c,d),Ts(c,p,m,n,r,o)&&m&&typeof p=="number"))return a&&c.children?m.children.splice(p,1,...c.children):m.children.splice(p,1),p});}return toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true})};var Is=/\[\^[\w-]{1,200}\](?!:)/,Ns=/\[\^[\w-]{1,200}\]:/;var Ls=/<(\w+)[\s>]/,Rs=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),nn=new Map,rn=new Map,Ss=e=>{let t=e.toLowerCase(),o=nn.get(t);if(o)return o;let n=new RegExp(`<${t}(?=[\\s>/])[^>]*>`,"gi");return nn.set(t,n),n},Es=e=>{let t=e.toLowerCase(),o=rn.get(t);if(o)return o;let n=new RegExp(`</${t}(?=[\\s>])[^>]*>`,"gi");return rn.set(t,n),n},sn=(e,t)=>{if(Rs.has(t.toLowerCase()))return 0;let o=e.match(Ss(t));if(!o)return 0;let n=0;for(let r of o)r.trimEnd().endsWith("/>")||(n+=1);return n},an=(e,t)=>{let o=e.match(Es(t));return o?o.length:0},Hs=e=>{let t=0;for(let o=0;o<e.length-1;o+=1)e[o]==="$"&&e[o+1]==="$"&&(t+=1,o+=1);return t},kt=e=>{let t=Is.test(e),o=Ns.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),r=[],s=[],a=false;for(let l of n){let i=l.raw,d=r.length;if(s.length>0){r[d-1]+=i;let c=s.at(-1),p=sn(i,c),m=an(i,c);for(let u=0;u<p;u+=1)s.push(c);for(let u=0;u<m;u+=1)s.length>0&&s.at(-1)===c&&s.pop();continue}if(l.type==="html"&&l.block){let c=i.match(Ls);if(c){let p=c[1],m=sn(i,p),u=an(i,p);m>u&&s.push(p);}}if(d>0&&!a){let c=r[d-1];if(Hs(c)%2===1){r[d-1]=c+i;continue}}r.push(i),l.type!=="space"&&(a=l.type==="code");}return r};var ln=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>{if(!l.includes(`
14
-
15
- `))return a+l+i;let d=l.replace(/\n\n/g,`
16
- <!---->
17
- `),c=(d.startsWith(`
18
- `)?"":`
19
- `)+d+(d.endsWith(`
20
- `)?"":`
21
- `);return `${a}${c}${i}
22
-
23
- `});}return o};var Ds=/([\\`*_~[\]|])/g,Bs=e=>e.replace(Ds,"\\$1"),cn=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let r=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(r,(s,a,l,i)=>{let d=Bs(l).replace(/\n\n/g,"&#10;&#10;");return a+d+i});}return o};var dn=e=>e.type==="text"?e.value:"children"in e&&Array.isArray(e.children)?e.children.map(dn).join(""):"",mn=e=>t=>{if(!e||e.length===0)return;let o=new Set(e.map(n=>n.toLowerCase()));visit(t,"element",n=>{if(o.has(n.tagName.toLowerCase())){let r=dn(n);n.children=r?[{type:"text",value:r}]:[];}});};var un=()=>e=>{visit(e,"code",t=>{var o,n;t.meta&&(t.data=(o=t.data)!=null?o:{},t.data.hProperties={...(n=t.data.hProperties)!=null?n:{},metastring:t.meta});});};var Zs=/^[ \t]*<[\w!/?-]/,Xs=/(^|\n)[ \t]{4,}(?=<[\w!/?-])/g,Js=e=>typeof e!="string"||e.length===0||!Zs.test(e)?e:e.replace(Xs,"$1"),bn,hn,yn,wn,Ze={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(hn=(bn=defaultSchema.protocols)==null?void 0:bn.href)!=null?hn:[],"tel"]},attributes:{...defaultSchema.attributes,code:[...(wn=(yn=defaultSchema.attributes)==null?void 0:yn.code)!=null?wn:[],"metastring"]}},xt={raw:Yo,sanitize:[kn,Ze],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Ks={gfm:[$s,{}],codeMeta:un},gn=Object.values(xt),Us=Object.values(Ks),Gs={block:" \u258B",circle:" \u25CF"},vn=["github-light","github-dark"],xn={enabled:true},Ys={shikiTheme:vn,controls:true,isAnimating:false,lineNumbers:true,mode:"streaming",mermaid:void 0,linkSafety:xn},R=createContext(Ys),Tn=memo(({content:e,shouldParseIncompleteMarkdown:t,shouldNormalizeHtmlIndentation:o,index:n,isIncomplete:r,dir:s,animatePlugin:a,...l})=>{if(a){let c=a.getLastRenderCharCount();a.setPrevContentLength(c);}let i=typeof e=="string"&&o?Js(e):e,d=jsx(Ct,{...l,children:i});return jsx(et.Provider,{value:r,children:s?jsx("div",{dir:s,style:{display:"contents"},children:d}):d})},(e,t)=>{if(e.content!==t.content||e.shouldNormalizeHtmlIndentation!==t.shouldNormalizeHtmlIndentation||e.index!==t.index||e.isIncomplete!==t.isIncomplete||e.dir!==t.dir)return false;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(r=>{var s,a;return ((s=e.components)==null?void 0:s[r])!==((a=t.components)==null?void 0:a[r])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Tn.displayName="Block";var Qs=memo(({children:e,mode:t="streaming",dir:o,parseIncompleteMarkdown:n=true,normalizeHtmlIndentation:r=false,components:s,rehypePlugins:a=gn,remarkPlugins:l=Us,className:i,shikiTheme:d=vn,mermaid:c,controls:p=true,isAnimating:m=false,animated:u,BlockComponent:f=Tn,parseMarkdownIntoBlocksFn:h=kt,caret:b,plugins:g,remend:T,linkSafety:v=xn,lineNumbers:w=true,allowedTags:P,literalTagContent:M,translations:H,icons:S,prefix:F,onAnimationStart:j,onAnimationEnd:z,...B})=>{let _=useId(),[Q,U]=useTransition(),x=useMemo(()=>Dt(F),[F]),q=useRef(null),X=useRef(j),Re=useRef(z);X.current=j,Re.current=z,useEffect(()=>{var A,K,ee;if(t==="static")return;let k=q.current;if(q.current=m,k===null){m&&((A=X.current)==null||A.call(X));return}m&&!k?(K=X.current)==null||K.call(X):!m&&k&&((ee=Re.current)==null||ee.call(Re));},[m,t]);let Je=useMemo(()=>P?Object.keys(P):[],[P]),Se=useMemo(()=>{if(typeof e!="string")return "";let k=t==="streaming"&&n?Ws(e,T):e;return M&&M.length>0&&(k=cn(k,M)),Je.length>0&&(k=ln(k,Je)),k},[e,t,n,T,Je,M]),fe=useMemo(()=>h(Se),[Se,h]),[Ln,Tt]=useState(fe);useEffect(()=>{t==="streaming"&&!ge?U(()=>{Tt(fe);}):Tt(fe);},[fe,t]);let J=t==="streaming"?Ln:fe,Ke=useMemo(()=>o==="auto"?J.map($e):void 0,[J,o]),Rn=useMemo(()=>J.map((k,A)=>`${_}-${A}`),[J.length,_]),Ue=useMemo(()=>u===true?"true":u?JSON.stringify(u):"",[u]),ge=useMemo(()=>Ue?Ue==="true"?be():be(u):null,[Ue]),Pt=useMemo(()=>{var k,A;return {shikiTheme:(A=(k=g==null?void 0:g.code)==null?void 0:k.getThemes())!=null?A:d,controls:p,isAnimating:m,lineNumbers:w,mode:t,mermaid:c,linkSafety:v}},[d,p,m,w,t,c,v,g==null?void 0:g.code]),Sn=useMemo(()=>H?JSON.stringify(H):"",[H]),Mt=useMemo(()=>({...De,...H}),[Sn]),It=useMemo(()=>{let{inlineCode:k,...A}=s!=null?s:{},K={...Ko,...A};if(k){let ee=K.code;K.code=ie=>"data-block"in ie?ee?createElement(ee,ie):null:createElement(k,ie);}return K},[s]),Nt=useMemo(()=>{let k=[];return g!=null&&g.cjk&&(k=[...k,...g.cjk.remarkPluginsBefore]),k=[...k,...l],g!=null&&g.cjk&&(k=[...k,...g.cjk.remarkPluginsAfter]),g!=null&&g.math&&(k=[...k,g.math.remarkPlugin]),k},[l,g==null?void 0:g.math,g==null?void 0:g.cjk]),Lt=useMemo(()=>{var A;let k=a;if(P&&Object.keys(P).length>0&&a===gn){let K={...Ze,tagNames:[...(A=Ze.tagNames)!=null?A:[],...Object.keys(P)],attributes:{...Ze.attributes,...P}};k=[xt.raw,[kn,K],xt.harden];}return M&&M.length>0&&(k=[...k,[mn,M]]),g!=null&&g.math&&(k=[...k,g.math.rehypePlugin]),ge&&m&&(k=[...k,ge.rehypePlugin]),k},[a,g==null?void 0:g.math,ge,m,P,M]),Ge=useMemo(()=>{if(!m||J.length===0)return false;let k=J.at(-1);return ht(k)||Uo(k)},[m,J]),En=useMemo(()=>b&&m&&!Ge?{"--streamdown-caret":`"${Gs[b]}"`}:void 0,[b,m,Ge]);return t==="static"?jsx(Be.Provider,{value:Mt,children:jsx(Ve.Provider,{value:g!=null?g:null,children:jsx(R.Provider,{value:Pt,children:jsx(at,{icons:S,children:jsx(Ee.Provider,{value:x,children:jsx("div",{className:x("space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",i),dir:o==="auto"?$e(Se):o,children:jsx(Ct,{components:It,rehypePlugins:Lt,remarkPlugins:Nt,...B,children:Se})})})})})})}):jsx(Be.Provider,{value:Mt,children:jsx(Ve.Provider,{value:g!=null?g:null,children:jsx(R.Provider,{value:Pt,children:jsx(at,{icons:S,children:jsx(Ee.Provider,{value:x,children:jsxs("div",{className:x("space-y-4 whitespace-normal [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",b&&!Ge?"[&>*:last-child]:after:inline [&>*:last-child]:after:align-baseline [&>*:last-child]:after:content-[var(--streamdown-caret)]":null,i),style:En,children:[J.length===0&&b&&m&&jsx("span",{}),J.map((k,A)=>{var ie;let K=A===J.length-1,ee=m&&K&&ht(k);return jsx(f,{animatePlugin:ge,components:It,content:k,dir:(ie=Ke==null?void 0:Ke[A])!=null?ie:o!=="auto"?o:void 0,index:A,isIncomplete:ee,rehypePlugins:Lt,remarkPlugins:Nt,shouldNormalizeHtmlIndentation:r,shouldParseIncompleteMarkdown:n,...B},Rn[A])})]})})})})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.animated===t.animated&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety&&e.lineNumbers===t.lineNumbers&&e.normalizeHtmlIndentation===t.normalizeHtmlIndentation&&e.literalTagContent===t.literalTagContent&&JSON.stringify(e.translations)===JSON.stringify(t.translations)&&e.prefix===t.prefix&&e.dir===t.dir);Qs.displayName="Streamdown";var Nn=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:r=.1,showControls:s=true,initialZoom:a=1,fullscreen:l=false})=>{let{RotateCcwIcon:i,ZoomInIcon:d,ZoomOutIcon:c}=L(),p=y(),m=useRef(null),u=useRef(null),[f,h]=useState(a),[b,g]=useState({x:0,y:0}),[T,v]=useState(false),[w,P]=useState({x:0,y:0}),[M,H]=useState({x:0,y:0}),S=useCallback(x=>{h(q=>Math.max(o,Math.min(n,q+x)));},[o,n]),F=useCallback(()=>{S(r);},[S,r]),j=useCallback(()=>{S(-r);},[S,r]),z=useCallback(()=>{h(a),g({x:0,y:0});},[a]),B=useCallback(x=>{x.preventDefault();let q=x.deltaY>0?-r:r;S(q);},[S,r]),_=useCallback(x=>{if(x.button!==0||x.isPrimary===false)return;v(true),P({x:x.clientX,y:x.clientY}),H(b);let q=x.currentTarget;q instanceof HTMLElement&&q.setPointerCapture(x.pointerId);},[b]),Q=useCallback(x=>{if(!T)return;x.preventDefault();let q=x.clientX-w.x,X=x.clientY-w.y;g({x:M.x+q,y:M.y+X});},[T,w,M]),U=useCallback(x=>{v(false);let q=x.currentTarget;q instanceof HTMLElement&&q.releasePointerCapture(x.pointerId);},[]);return useEffect(()=>{let x=m.current;if(x)return x.addEventListener("wheel",B,{passive:false}),()=>{x.removeEventListener("wheel",B);}},[B]),useEffect(()=>{let x=u.current;if(x&&T)return document.body.style.userSelect="none",x.addEventListener("pointermove",Q,{passive:false}),x.addEventListener("pointerup",U),x.addEventListener("pointercancel",U),()=>{document.body.style.userSelect="",x.removeEventListener("pointermove",Q),x.removeEventListener("pointerup",U),x.removeEventListener("pointercancel",U);}},[T,Q,U]),jsxs("div",{className:p("relative flex flex-col",l?"h-full w-full":"min-h-28 w-full",t),ref:m,style:{cursor:T?"grabbing":"grab"},children:[s?jsxs("div",{className:p("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/80 p-1 supports-[backdrop-filter]:bg-background/70 supports-[backdrop-filter]:backdrop-blur-sm",l?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:f>=n,onClick:F,title:"Zoom in",type:"button",children:jsx(d,{size:16})}),jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50"),disabled:f<=o,onClick:j,title:"Zoom out",type:"button",children:jsx(c,{size:16})}),jsx("button",{className:p("flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground"),onClick:z,title:"Reset zoom and pan",type:"button",children:jsx(i,{size:16})})]}):null,jsx("div",{className:p("flex-1 origin-center transition-transform duration-150 ease-out",l?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:_,ref:u,role:"application",style:{transform:`translate(${b.x}px, ${b.y}px) scale(${f})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var po=({chart:e,className:t,config:o,fullscreen:n=false,showControls:r=true})=>{let s=y(),[a,l]=useState(null),[i,d]=useState(false),[c,p]=useState(""),[m,u]=useState(""),[f,h]=useState(0),{mermaid:b}=useContext(R),g=de(),T=b==null?void 0:b.errorComponent,{shouldRender:v,containerRef:w}=Rt({immediate:n});if(useEffect(()=>{if(!v)return;if(!g){l("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{l(null),d(!0);let H=g.getMermaid(o),S=e.split("").reduce((z,B)=>(z<<5)-z+B.charCodeAt(0)|0,0),F=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:j}=await H.render(F,e);p(j),u(j);}catch(H){if(!(m||c)){let S=H instanceof Error?H.message:"Failed to render Mermaid chart";l(S);}}finally{d(false);}})();},[e,o,f,v,g]),!(v||c||m))return jsx("div",{className:s("my-4 min-h-[200px]",t),ref:w});if(i&&!c&&!m)return jsx("div",{className:s("my-4 flex justify-center p-4",t),ref:w,children:jsxs("div",{className:s("flex items-center space-x-2 text-muted-foreground"),children:[jsx("div",{className:s("h-4 w-4 animate-spin rounded-full border-current border-b-2")}),jsx("span",{className:s("text-sm"),children:"Loading diagram..."})]})});if(a&&!c&&!m){let M=()=>h(H=>H+1);return T?jsx("div",{ref:w,children:jsx(T,{chart:e,error:a,retry:M})}):jsxs("div",{className:s("rounded-md bg-red-50 p-4",t),ref:w,children:[jsxs("p",{className:s("font-mono text-red-700 text-sm"),children:["Mermaid Error: ",a]}),jsxs("details",{className:s("mt-2"),children:[jsx("summary",{className:s("cursor-pointer text-red-600 text-xs"),children:"Show Code"}),jsx("pre",{className:s("mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs"),children:e})]})]})}let P=c||m;return jsx("div",{className:s("size-full",t),"data-streamdown":"mermaid",ref:w,children:jsx(Nn,{className:s(n?"size-full overflow-hidden":"overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:r,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:s("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:P},role:"img"})})})};export{R as A,Tn as B,Qs as C,be as a,tt as b,At as c,ot as d,rt as e,Li as f,st as g,De as h,Ae as i,it as j,Oe as k,po as l,ue as m,ne as n,dt as o,je as p,re as q,Te as r,Wr as s,Pe as t,$e as u,on as v,kt as w,Js as x,xt as y,Ks as z};
@@ -1,2 +0,0 @@
1
- "use client";
2
- import {A,f,c}from'./chunk-BO2N2NFS.js';import {useContext,useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';var R=({code:s,language:e,raw:t,className:h,startLine:d,lineNumbers:m,...p})=>{let{shikiTheme:l}=useContext(A),o=f(),[a,i]=useState(t);return useEffect(()=>{if(!o){i(t);return}let r=o.highlight({code:s,language:e,themes:l},c=>{i(c);});r&&i(r);},[s,e,l,o,t]),jsx(c,{className:h,language:e,lineNumbers:m,result:a,startLine:d,...p})};export{R as HighlightedCodeBlockBody};
@@ -1,2 +0,0 @@
1
- "use client";
2
- export{l as Mermaid}from'./chunk-BO2N2NFS.js';