streamdown 2.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -6
- package/dist/chunk-5FQGJX7Z.js +10 -0
- package/dist/chunk-QX4TVXVA.cjs +10 -0
- package/dist/code-block-37QAKDTI.js +3 -0
- package/dist/code-block-XWNGTFRY.cjs +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +140 -15
- package/dist/index.d.ts +140 -15
- package/dist/index.js +1 -1
- package/dist/mermaid-4DMBBIKO.js +2 -0
- package/dist/mermaid-UQ57JT4G.cjs +2 -0
- package/package.json +7 -12
- package/dist/chunk-4VFFRCJP.js +0 -11
- package/dist/chunk-DQKJR6WP.cjs +0 -11
- package/dist/code-block-3WZ5YY6K.cjs +0 -3
- package/dist/code-block-GEBMI5SW.js +0 -3
- package/dist/mermaid-5MRP2H6R.cjs +0 -2
- package/dist/mermaid-INZBJW3V.js +0 -2
package/README.md
CHANGED
|
@@ -38,15 +38,40 @@ Make sure the path matches the location of the `node_modules` folder in your pro
|
|
|
38
38
|
|
|
39
39
|
## Usage
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
Here's how you can use Streamdown in your React application with the AI SDK:
|
|
42
42
|
|
|
43
43
|
```tsx
|
|
44
|
+
import { useChat } from "@ai-sdk/react";
|
|
44
45
|
import { Streamdown } from "streamdown";
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
import { code } from "@streamdown/code";
|
|
47
|
+
import { mermaid } from "@streamdown/mermaid";
|
|
48
|
+
import { math } from "@streamdown/math";
|
|
49
|
+
import { cjk } from "@streamdown/cjk";
|
|
50
|
+
import "katex/dist/katex.min.css";
|
|
51
|
+
|
|
52
|
+
export default function Chat() {
|
|
53
|
+
const { messages, status } = useChat();
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div>
|
|
57
|
+
{messages.map(message => (
|
|
58
|
+
<div key={message.id}>
|
|
59
|
+
{message.role === 'user' ? 'User: ' : 'AI: '}
|
|
60
|
+
{message.parts.map((part, index) =>
|
|
61
|
+
part.type === 'text' ? (
|
|
62
|
+
<Streamdown
|
|
63
|
+
key={index}
|
|
64
|
+
plugins={{ code, mermaid, math, cjk }}
|
|
65
|
+
isAnimating={status === 'streaming'}
|
|
66
|
+
>
|
|
67
|
+
{part.text}
|
|
68
|
+
</Streamdown>
|
|
69
|
+
) : null,
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
))}
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
50
75
|
}
|
|
51
76
|
```
|
|
52
77
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {createContext,lazy,memo,useContext,isValidElement,useId,useTransition,useMemo,useState,useEffect,useCallback,Suspense,useRef}from'react';import {harden}from'rehype-harden';import pn from'rehype-raw';import un from'rehype-sanitize';import fn from'remark-gfm';import bn from'remend';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import Jo from'remark-parse';import Fo from'remark-rehype';import {unified}from'unified';import {Lexer}from'marked';var Yt=300,Qt="300px",eo=500;function Ve(e={}){let{immediate:t=false,debounceDelay:o=Yt,rootMargin:n=Qt,idleTimeout:d=eo}=e,[s,m]=useState(false),i=useRef(null),r=useRef(null),l=useRef(null),c=useMemo(()=>f=>{let a=Date.now();return window.setTimeout(()=>{f({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-a))});},1)},[]),u=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(f,a)=>window.requestIdleCallback(f,a):c,[c]),p=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?f=>window.cancelIdleCallback(f):f=>{clearTimeout(f);},[]);return useEffect(()=>{if(t){m(true);return}let f=i.current;if(!f)return;r.current&&(clearTimeout(r.current),r.current=null),l.current&&(p(l.current),l.current=null);let a=()=>{r.current&&(clearTimeout(r.current),r.current=null),l.current&&(p(l.current),l.current=null);},h=M=>{l.current=u(P=>{P.timeRemaining()>0||P.didTimeout?(m(true),M.disconnect()):l.current=u(()=>{m(true),M.disconnect();},{timeout:d/2});},{timeout:d});},y=M=>{a(),r.current=window.setTimeout(()=>{var L,D;let P=M.takeRecords();(P.length===0||(D=(L=P.at(-1))==null?void 0:L.isIntersecting)!=null&&D)&&h(M);},o);},k=(M,P)=>{M.isIntersecting?y(P):a();},C=new IntersectionObserver(M=>{for(let P of M)k(P,C);},{rootMargin:n,threshold:0});return C.observe(f),()=>{r.current&&clearTimeout(r.current),l.current&&p(l.current),C.disconnect();}},[t,o,n,d,p,u]),{shouldRender:s,containerRef:i}}var J=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),F=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),z=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),Be=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"})]}),je=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"})}),Oe=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"})}),re=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"})}),ve=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"})}),Ae=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"})}),qe=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"})});var b=(...e)=>twMerge(clsx(e)),B=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,d=URL.createObjectURL(n),s=document.createElement("a");s.href=d,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(d);};var ao=createContext({code:""}),se=()=>useContext(ao);var Ce=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:d,code:s,...m})=>{let[i,r]=useState(false),l=useRef(0),{code:c}=se(),{isAnimating:u}=useContext(N),p=s!=null?s:c,f=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(p),r(!0),e==null||e(),l.current=window.setTimeout(()=>r(!1),o));}catch(y){t==null||t(y);}};useEffect(()=>()=>{window.clearTimeout(l.current);},[]);let a=i?J:F;return jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",d),"data-streamdown":"code-block-copy-button",disabled:u,onClick:f,title:"Copy Code",type:"button",...m,children:n!=null?n:jsx(a,{size:14})})};var $e={"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"},We=({onDownload:e,onError:t,language:o,children:n,className:d,code:s,...m})=>{let{code:i}=se(),{isAnimating:r}=useContext(N),l=s!=null?s:i,u=`file.${o&&o in $e?$e[o]:"txt"}`,p="text/plain",f=()=>{try{B(u,l,p),e==null||e();}catch(a){t==null||t(a);}};return jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",d),"data-streamdown":"code-block-download-button",disabled:r,onClick:f,title:"Download file",type:"button",...m,children:n!=null?n:jsx(z,{size:14})})};var Pe=()=>jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsx(Be,{className:"size-4 animate-spin"})})]});var fo=/\.[^/.]+$/,Xe=({node:e,className:t,src:o,alt:n,...d})=>{let s=async()=>{if(o)try{let i=await(await fetch(o)).blob(),l=new URL(o,window.location.origin).pathname.split("/").pop()||"",c=l.split(".").pop(),u=l.includes(".")&&c!==void 0&&c.length<=4,p="";if(u)p=l;else {let f=i.type,a="png";f.includes("jpeg")||f.includes("jpg")?a="jpg":f.includes("png")?a="png":f.includes("svg")?a="svg":f.includes("gif")?a="gif":f.includes("webp")&&(a="webp"),p=`${(n||l||"image").replace(fo,"")}.${a}`;}B(p,i,i.type);}catch(m){window.open(o,"_blank");}};return o?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:b("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...d}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsx("button",{className:b("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:s,title:"Download image",type:"button",children:jsx(z,{size:14})})]}):null};var Q=0,yo=()=>{Q+=1,Q===1&&(document.body.style.overflow="hidden");},wo=()=>{Q=Math.max(0,Q-1),Q===0&&(document.body.style.overflow="");},Fe=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[d,s]=useState(false),m=useCallback(async()=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),2e3);}catch(r){}},[e]),i=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){yo();let r=l=>{l.key==="Escape"&&o();};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r),wo();}}},[t,o]),t?jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm","data-streamdown":"link-safety-modal",onClick:o,onKeyDown:r=>{r.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:"relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg",onClick:r=>r.stopPropagation(),onKeyDown:r=>r.stopPropagation(),role:"presentation",children:[jsx("button",{className:"absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:o,title:"Close",type:"button",children:jsx(re,{size:16})}),jsxs("div",{className:"flex flex-col gap-2",children:[jsxs("div",{className:"flex items-center gap-2 font-semibold text-lg",children:[jsx(ve,{size:20}),jsx("span",{children:"Open external link?"})]}),jsx("p",{className:"text-muted-foreground text-sm",children:"You're about to visit an external website."})]}),jsx("div",{className:b("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxs("div",{className:"flex gap-2",children:[jsx("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted",onClick:m,type:"button",children:d?jsxs(Fragment,{children:[jsx(J,{size:14}),jsx("span",{children:"Copied"})]}):jsxs(Fragment,{children:[jsx(F,{size:14}),jsx("span",{children:"Copy link"})]})}),jsxs("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90",onClick:i,type:"button",children:[jsx(ve,{size:14}),jsx("span",{children:"Open link"})]})]})]})}):null};var ie=createContext(null),Ue=()=>useContext(ie),cr=()=>{var t;let e=Ue();return (t=e==null?void 0:e.code)!=null?t:null},U=()=>{var t;let e=Ue();return (t=e==null?void 0:e.mermaid)!=null?t:null};var Ke=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((d,s)=>{let m="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),i=new Image;i.crossOrigin="anonymous",i.onload=()=>{let r=document.createElement("canvas"),l=i.width*o,c=i.height*o;r.width=l,r.height=c;let u=r.getContext("2d");if(!u){s(new Error("Failed to create 2D canvas context for PNG export"));return}u.drawImage(i,0,0,l,c),r.toBlob(p=>{if(!p){s(new Error("Failed to create PNG blob"));return}d(p);},"image/png");},i.onerror=()=>s(new Error("Failed to load SVG image")),i.src=m;})};var Ye=({chart:e,children:t,className:o,onDownload:n,config:d,onError:s})=>{let[m,i]=useState(false),r=useRef(null),{isAnimating:l}=useContext(N),c=U(),u=async p=>{try{if(p==="mmd"){B("diagram.mmd",e,"text/plain"),i(!1),n==null||n(p);return}if(!c){s==null||s(new Error("Mermaid plugin not available"));return}let f=c.getMermaid(d),a=e.split("").reduce((k,C)=>(k<<5)-k+C.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(a)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:y}=await f.render(h,e);if(!y){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(p==="svg"){B("diagram.svg",y,"image/svg+xml"),i(!1),n==null||n(p);return}if(p==="png"){let k=await Ke(y);B("diagram.png",k,"image/png"),n==null||n(p),i(!1);return}}catch(f){s==null||s(f);}};return useEffect(()=>{let p=f=>{let a=f.composedPath();r.current&&!a.includes(r.current)&&i(false);};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p);}},[]),jsxs("div",{className:"relative",ref:r,children:[jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:l,onClick:()=>i(!m),title:"Download diagram",type:"button",children:t!=null?t:jsx(z,{size:14})}),m?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var te=0,Lo=()=>{te+=1,te===1&&(document.body.style.overflow="hidden");},So=()=>{te=Math.max(0,te-1),te===0&&(document.body.style.overflow="");},ot=({chart:e,config:t,onFullscreen:o,onExit:n,className:d,...s})=>{let[m,i]=useState(false),{isAnimating:r,controls:l}=useContext(N),c=(()=>{if(typeof l=="boolean")return l;let p=l.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),u=()=>{i(!m);};return useEffect(()=>{if(m){Lo();let p=f=>{f.key==="Escape"&&i(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),So();}}},[m]),useEffect(()=>{m?o==null||o():n&&n();},[m,o,n]),jsxs(Fragment,{children:[jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",d),disabled:r,onClick:u,title:"View fullscreen",type:"button",...s,children:jsx(je,{size:14})}),m?jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:u,onKeyDown:p=>{p.key==="Escape"&&u();},role:"button",tabIndex:0,children:[jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:u,title:"Exit fullscreen",type:"button",children:jsx(re,{size:20})}),jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsx(tt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:c})})]}):null]})};var le=e=>{var s,m;let t=[],o=[],n=e.querySelectorAll("thead th");for(let i of n)t.push(((s=i.textContent)==null?void 0:s.trim())||"");let d=e.querySelectorAll("tbody tr");for(let i of d){let r=[],l=i.querySelectorAll("td");for(let c of l)r.push(((m=c.textContent)==null?void 0:m.trim())||"");o.push(r);}return {headers:t,rows:o}},ce=e=>{let{headers:t,rows:o}=e,n=i=>{let r=false,l=false;for(let c of i){if(c==='"'){r=true,l=true;break}(c===","||c===`
|
|
3
|
+
`)&&(r=true);}return r?l?`"${i.replace(/"/g,'""')}"`:`"${i}"`:i},d=t.length>0?o.length+1:o.length,s=new Array(d),m=0;t.length>0&&(s[m]=t.map(n).join(","),m+=1);for(let i of o)s[m]=i.map(n).join(","),m+=1;return s.join(`
|
|
4
|
+
`)},nt=e=>{let{headers:t,rows:o}=e,n=i=>{let r=false;for(let c of i)if(c===" "||c===`
|
|
5
|
+
`||c==="\r"){r=true;break}if(!r)return i;let l=[];for(let c of i)c===" "?l.push("\\t"):c===`
|
|
6
|
+
`?l.push("\\n"):c==="\r"?l.push("\\r"):l.push(c);return l.join("")},d=t.length>0?o.length+1:o.length,s=new Array(d),m=0;t.length>0&&(s[m]=t.map(n).join(" "),m+=1);for(let i of o)s[m]=i.map(n).join(" "),m+=1;return s.join(`
|
|
7
|
+
`)},Me=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("")},rt=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),d=0,s=t.map(i=>Me(i));n[d]=`| ${s.join(" | ")} |`,d+=1;let m=new Array(t.length);for(let i=0;i<t.length;i+=1)m[i]="---";n[d]=`| ${m.join(" | ")} |`,d+=1;for(let i of o)if(i.length<t.length){let r=new Array(t.length);for(let l=0;l<t.length;l+=1)r[l]=l<i.length?Me(i[l]):"";n[d]=`| ${r.join(" | ")} |`,d+=1;}else {let r=i.map(l=>Me(l));n[d]=`| ${r.join(" | ")} |`,d+=1;}return n.join(`
|
|
8
|
+
`)};var lt=({children:e,className:t,onCopy:o,onError:n,timeout:d=2e3})=>{let[s,m]=useState(false),[i,r]=useState(false),l=useRef(null),c=useRef(0),{isAnimating:u}=useContext(N),p=async a=>{var h,y;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){n==null||n(new Error("Clipboard API not available"));return}try{let k=(y=l.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),C=k==null?void 0:k.querySelector("table");if(!C){n==null||n(new Error("Table not found"));return}let M=le(C),P=a==="csv"?ce(M):nt(M),E=new ClipboardItem({"text/plain":new Blob([P],{type:"text/plain"}),"text/html":new Blob([C.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),r(!0),m(!1),o==null||o(a),c.current=window.setTimeout(()=>r(!1),d);}catch(k){n==null||n(k);}};useEffect(()=>{let a=h=>{let y=h.composedPath();l.current&&!y.includes(l.current)&&m(false);};return document.addEventListener("mousedown",a),()=>{document.removeEventListener("mousedown",a),window.clearTimeout(c.current);}},[]);let f=i?J:F;return jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:u,onClick:()=>m(!s),title:"Copy table",type:"button",children:e!=null?e:jsx(f,{size:14})}),s?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var dt=({children:e,className:t,onDownload:o,onError:n})=>{let[d,s]=useState(false),m=useRef(null),{isAnimating:i}=useContext(N),r=l=>{var c;try{let u=(c=m.current)==null?void 0:c.closest('[data-streamdown="table-wrapper"]'),p=u==null?void 0:u.querySelector("table");if(!p){n==null||n(new Error("Table not found"));return}let f=le(p),a=l==="csv"?ce(f):rt(f);B(`table.${l==="csv"?"csv":"md"}`,a,l==="csv"?"text/csv":"text/markdown"),s(!1),o==null||o(l);}catch(u){n==null||n(u);}};return useEffect(()=>{let l=c=>{let u=c.composedPath();m.current&&!u.includes(m.current)&&s(false);};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l);}},[]),jsxs("div",{className:"relative",ref:m,children:[jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>s(!d),title:"Download table",type:"button",children:e!=null?e:jsx(z,{size:14})}),d?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>r("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>r("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var pt=({children:e,className:t,showControls:o,...n})=>jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[o?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(lt,{}),jsx(dt,{})]}):null,jsx("div",{className:"overflow-x-auto",children:jsx("table",{className:b("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});var Oo=lazy(()=>import('./code-block-37QAKDTI.js').then(e=>({default:e.CodeBlock}))),Ao=lazy(()=>import('./mermaid-4DMBBIKO.js').then(e=>({default:e.Mermaid}))),qo=/language-([^\s]+)/;function ge(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,d=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)&&(d==null?void 0:d.line)===(s==null?void 0:s.line)&&(d==null?void 0:d.column)===(s==null?void 0:s.column)}function T(e,t){return e.className===t.className&&ge(e.node,t.node)}var Ne=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ue=(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},Se=memo(({children:e,className:t,node:o,...n})=>jsx("ol",{className:b("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>T(e,t));Se.displayName="MarkdownOl";var bt=memo(({children:e,className:t,node:o,...n})=>jsx("li",{className:b("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&ge(e.node,t.node));bt.displayName="MarkdownLi";var gt=memo(({children:e,className:t,node:o,...n})=>jsx("ul",{className:b("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>T(e,t));gt.displayName="MarkdownUl";var ht=memo(({className:e,node:t,...o})=>jsx("hr",{className:b("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>T(e,t));ht.displayName="MarkdownHr";var yt=memo(({children:e,className:t,node:o,...n})=>jsx("span",{className:b("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>T(e,t));yt.displayName="MarkdownStrong";var zo=({children:e,className:t,href:o,node:n,...d})=>{let{linkSafety:s}=useContext(N),[m,i]=useState(false),r=o==="streamdown:incomplete-link",l=useCallback(async f=>{if(!(!(s!=null&&s.enabled&&o)||r)){if(f.preventDefault(),s.onLinkCheck&&await s.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}i(true);}},[s,o,r]),c=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),u=useCallback(()=>{i(false);},[]),p={url:o!=null?o:"",isOpen:m,onClose:u,onConfirm:c};return s!=null&&s.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:b("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",onClick:l,type:"button",children:e}),s.renderModal?s.renderModal(p):jsx(Fe,{...p})]}):jsx("a",{className:b("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...d,children:e})},wt=memo(zo,(e,t)=>T(e,t)&&e.href===t.href);wt.displayName="MarkdownA";var kt=memo(({children:e,className:t,node:o,...n})=>jsx("h1",{className:b("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>T(e,t));kt.displayName="MarkdownH1";var vt=memo(({children:e,className:t,node:o,...n})=>jsx("h2",{className:b("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>T(e,t));vt.displayName="MarkdownH2";var Ct=memo(({children:e,className:t,node:o,...n})=>jsx("h3",{className:b("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>T(e,t));Ct.displayName="MarkdownH3";var xt=memo(({children:e,className:t,node:o,...n})=>jsx("h4",{className:b("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>T(e,t));xt.displayName="MarkdownH4";var Pt=memo(({children:e,className:t,node:o,...n})=>jsx("h5",{className:b("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>T(e,t));Pt.displayName="MarkdownH5";var Mt=memo(({children:e,className:t,node:o,...n})=>jsx("h6",{className:b("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>T(e,t));Mt.displayName="MarkdownH6";var Tt=memo(({children:e,className:t,node:o,...n})=>{let{controls:d}=useContext(N),s=Ne(d,"table");return jsx(pt,{className:t,showControls:s,...n,children:e})},(e,t)=>T(e,t));Tt.displayName="MarkdownTable";var Nt=memo(({children:e,className:t,node:o,...n})=>jsx("thead",{className:b("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>T(e,t));Nt.displayName="MarkdownThead";var Lt=memo(({children:e,className:t,node:o,...n})=>jsx("tbody",{className:b("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>T(e,t));Lt.displayName="MarkdownTbody";var St=memo(({children:e,className:t,node:o,...n})=>jsx("tr",{className:b("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>T(e,t));St.displayName="MarkdownTr";var Rt=memo(({children:e,className:t,node:o,...n})=>jsx("th",{className:b("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>T(e,t));Rt.displayName="MarkdownTh";var It=memo(({children:e,className:t,node:o,...n})=>jsx("td",{className:b("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>T(e,t));It.displayName="MarkdownTd";var Ht=memo(({children:e,className:t,node:o,...n})=>jsx("blockquote",{className:b("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>T(e,t));Ht.displayName="MarkdownBlockquote";var Et=memo(({children:e,className:t,node:o,...n})=>jsx("sup",{className:b("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>T(e,t));Et.displayName="MarkdownSup";var Dt=memo(({children:e,className:t,node:o,...n})=>jsx("sub",{className:b("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>T(e,t));Dt.displayName="MarkdownSub";var Vt=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=r=>{var p,f;if(!isValidElement(r))return false;let l=Array.isArray(r.props.children)?r.props.children:[r.props.children],c=false,u=false;for(let a of l)if(a){if(typeof a=="string")a.trim()!==""&&(c=true);else if(isValidElement(a))if(((p=a.props)==null?void 0:p["data-footnote-backref"])!==void 0)u=true;else {let h=Array.isArray(a.props.children)?a.props.children:[a.props.children];for(let y of h){if(typeof y=="string"&&y.trim()!==""){c=true;break}if(isValidElement(y)&&((f=y.props)==null?void 0:f["data-footnote-backref"])===void 0){c=true;break}}}}return u&&!c},m=Array.isArray(e)?e.map(r=>{if(!isValidElement(r))return r;if(r.type===Se){let c=(Array.isArray(r.props.children)?r.props.children:[r.props.children]).filter(u=>!s(u));return c.length===0?null:{...r,props:{...r.props,children:c}}}return r}):e;return (Array.isArray(m)?m.some(r=>r!==null):m!==null)?jsx("section",{className:t,...n,children:m}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>T(e,t));Vt.displayName="MarkdownSection";var $o=({node:e,className:t,children:o,...n})=>{var p,f,a;let d=((p=e==null?void 0:e.position)==null?void 0:p.start.line)===((f=e==null?void 0:e.position)==null?void 0:f.end.line),{mermaid:s,controls:m}=useContext(N),i=U();if(d)return jsx("code",{className:b("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let r=t==null?void 0:t.match(qo),l=(a=r==null?void 0:r.at(1))!=null?a:"",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),l==="mermaid"&&i){let h=Ne(m,"mermaid"),y=ue(m,"download"),k=ue(m,"copy"),C=ue(m,"fullscreen"),M=ue(m,"panZoom"),P=h&&(y||k||C);return jsx(Suspense,{fallback:jsx(Pe,{}),children:jsxs("div",{className:b("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[P?jsxs("div",{className:"flex items-center justify-end gap-2",children:[y?jsx(Ye,{chart:c,config:s==null?void 0:s.config}):null,k?jsx(Ce,{code:c}):null,C?jsx(ot,{chart:c,config:s==null?void 0:s.config}):null]}):null,jsx(Ao,{chart:c,config:s==null?void 0:s.config,showControls:M})]})})}let u=Ne(m,"code");return jsx(Suspense,{fallback:jsx(Pe,{}),children:jsx(Oo,{className:b("overflow-x-auto border-border border-t",t),code:c,language:l,children:u?jsxs(Fragment,{children:[jsx(We,{code:c,language:l}),jsx(Ce,{})]}):null})})},Bt=memo($o,(e,t)=>e.className===t.className&&ge(e.node,t.node));Bt.displayName="MarkdownCode";var jt=memo(Xe,(e,t)=>e.className===t.className&&ge(e.node,t.node));jt.displayName="MarkdownImg";var Ot=memo(({children:e,className:t,node:o,...n})=>{var m,i;let s=(Array.isArray(e)?e:[e]).filter(r=>r!=null&&r!=="");if(s.length===1&&isValidElement(s[0])){let r=s[0].props.node,l=r==null?void 0:r.tagName;if(l==="img")return jsx(Fragment,{children:e});if(l==="code"&&((m=r==null?void 0:r.position)==null?void 0:m.start.line)!==((i=r==null?void 0:r.position)==null?void 0:i.end.line))return jsx(Fragment,{children:e})}return jsx("p",{className:t,...n,children:e})},(e,t)=>T(e,t));Ot.displayName="MarkdownParagraph";var At={ol:Se,li:bt,ul:gt,hr:ht,strong:yt,a:wt,h1:kt,h2:vt,h3:Ct,h4:xt,h5:Pt,h6:Mt,table:Tt,thead:Nt,tbody:Lt,tr:St,th:Rt,td:It,blockquote:Ht,code:Bt,img:jt,pre:({children:e})=>e,sup:Et,sub:Dt,p:Ot,section:Vt};var qt=[],zt={allowDangerousHtml:true},he=new WeakMap,Re=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,d=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||d||s)){let u="default";return this.keyCache.set(t,u),u}let m=u=>{if(!u||u.length===0)return "";let p="";for(let f=0;f<u.length;f+=1){let a=u[f];if(f>0&&(p+=","),Array.isArray(a)){let[h,y]=a;if(typeof h=="function"){let k=he.get(h);k||(k=h.name,he.set(h,k)),p+=k;}else p+=String(h);p+=":",p+=JSON.stringify(y);}else if(typeof a=="function"){let h=he.get(a);h||(h=a.name,he.set(a,h)),p+=h;}else p+=String(a);}return p},i=m(n),r=m(d),l=s?JSON.stringify(s):"",c=`${r}::${i}::${l}`;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 d=this.cache.keys().next().value;d&&this.cache.delete(d);}this.cache.set(n,o);}clear(){this.cache.clear();}},$t=new Re,Ie=e=>{let t=Ko(e),o=e.children||"";return Yo(t.runSync(t.parse(o),o),e)},Ko=e=>{let t=$t.get(e);if(t)return t;let o=Go(e);return $t.set(e,o),o},Go=e=>{let t=e.rehypePlugins||qt,o=e.remarkPlugins||qt,n=e.remarkRehypeOptions?{...zt,...e.remarkRehypeOptions}:zt;return unified().use(Jo).use(o).use(Fo,n).use(t)},Yo=(e,t)=>toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true});var en=/\[\^[^\]\s]{1,200}\](?!:)/,tn=/\[\^[^\]\s]{1,200}\]:/,on=/<\/(\w+)>/,nn=/<(\w+)[\s>]/,He=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},rn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Ee=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},De=e=>{let t=en.test(e),o=tn.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),d=[],s=[];for(let m of n){let i=m.raw,r=d.length;if(s.length>0){if(d[r-1]+=i,m.type==="html"){let c=i.match(on);if(c){let u=c[1];s.at(-1)===u&&s.pop();}}continue}if(m.type==="html"&&m.block){let c=i.match(nn);if(c){let u=c[1];i.includes(`</${u}>`)||s.push(u);}}if(i.trim()==="$$"&&r>0){let c=d[r-1],u=He(c),p=Ee(c);if(u&&p%2===1){d[r-1]=c+i;continue}}if(r>0&&rn(i)){let c=d[r-1],u=He(c),p=Ee(c),f=Ee(i);if(u&&p%2===1&&!He(i)&&f===1){d[r-1]=c+i;continue}}d.push(i);}return d};var gn={raw:pn,sanitize:[un,{}],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},hn={gfm:[fn,{}]},yn=Object.values(gn),wn=Object.values(hn),kn={block:" \u258B",circle:" \u25CF"},vn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},N=createContext(vn),Wt=memo(({content:e,shouldParseIncompleteMarkdown:t,index:o,...n})=>jsx(Ie,{...n,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)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(d=>{var s,m;return ((s=e.components)==null?void 0:s[d])!==((m=t.components)==null?void 0:m[d])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Wt.displayName="Block";var Cn=["github-light","github-dark"],xn=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,components:n,rehypePlugins:d=yn,remarkPlugins:s=wn,className:m,shikiTheme:i=Cn,mermaid:r,controls:l=true,isAnimating:c=false,BlockComponent:u=Wt,parseMarkdownIntoBlocksFn:p=De,caret:f,plugins:a,remend:h,linkSafety:y={enabled:true},...k})=>{let C=useId(),[M,P]=useTransition(),E=useMemo(()=>typeof e!="string"?"":t==="streaming"&&o?bn(e,h):e,[e,t,o,h]),L=useMemo(()=>p(E),[E,p]),[D,A]=useState(L);useEffect(()=>{t==="streaming"?P(()=>{A(L);}):A(L);},[L,t]);let j=t==="streaming"?D:L,q=useMemo(()=>j.map((S,W)=>`${C}-${W}`),[j.length,C]),V=useMemo(()=>{var S,W;return {shikiTheme:(W=(S=a==null?void 0:a.code)==null?void 0:S.getThemes())!=null?W:i,controls:l,isAnimating:c,mode:t,mermaid:r,linkSafety:y}},[i,l,c,t,r,y,a==null?void 0:a.code]),w=useMemo(()=>({...At,...n}),[n]),R=useMemo(()=>{let S=[];return a!=null&&a.cjk&&(S=[...S,...a.cjk.remarkPluginsBefore]),S=[...S,...s],a!=null&&a.cjk&&(S=[...S,...a.cjk.remarkPluginsAfter]),a!=null&&a.math&&(S=[...S,a.math.remarkPlugin]),S},[s,a==null?void 0:a.math,a==null?void 0:a.cjk]),Y=useMemo(()=>a!=null&&a.math?[...d,a.math.rehypePlugin]:d,[d,a==null?void 0:a.math]),Ut=useMemo(()=>f&&c?{"--streamdown-caret":`"${kn[f]}"`}:void 0,[f,c]);return t==="static"?jsx(ie.Provider,{value:a!=null?a:null,children:jsx(N.Provider,{value:V,children:jsx("div",{className:b("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",m),children:jsx(Ie,{components:w,rehypePlugins:Y,remarkPlugins:R,...k,children:e})})})}):jsx(ie.Provider,{value:a!=null?a:null,children:jsx(N.Provider,{value:V,children:jsxs("div",{className:b("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",f?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,m),style:Ut,children:[j.length===0&&f&&c&&jsx("span",{}),j.map((S,W)=>jsx(u,{components:w,content:S,index:W,rehypePlugins:Y,remarkPlugins:R,shouldParseIncompleteMarkdown:o,...k},q[W]))]})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety);xn.displayName="Streamdown";var Ft=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:d=.1,showControls:s=true,initialZoom:m=1,fullscreen:i=false})=>{let r=useRef(null),l=useRef(null),[c,u]=useState(m),[p,f]=useState({x:0,y:0}),[a,h]=useState(false),[y,k]=useState({x:0,y:0}),[C,M]=useState({x:0,y:0}),P=useCallback(w=>{u(R=>Math.max(o,Math.min(n,R+w)));},[o,n]),E=useCallback(()=>{P(d);},[P,d]),L=useCallback(()=>{P(-d);},[P,d]),D=useCallback(()=>{u(m),f({x:0,y:0});},[m]),A=useCallback(w=>{w.preventDefault();let R=w.deltaY>0?-d:d;P(R);},[P,d]),j=useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;h(true),k({x:w.clientX,y:w.clientY}),M(p);let R=w.currentTarget;R instanceof HTMLElement&&R.setPointerCapture(w.pointerId);},[p]),q=useCallback(w=>{if(!a)return;w.preventDefault();let R=w.clientX-y.x,Y=w.clientY-y.y;f({x:C.x+R,y:C.y+Y});},[a,y,C]),V=useCallback(w=>{h(false);let R=w.currentTarget;R instanceof HTMLElement&&R.releasePointerCapture(w.pointerId);},[]);return useEffect(()=>{let w=r.current;if(w)return w.addEventListener("wheel",A,{passive:false}),()=>{w.removeEventListener("wheel",A);}},[A]),useEffect(()=>{let w=l.current;if(w&&a)return document.body.style.userSelect="none",w.addEventListener("pointermove",q,{passive:false}),w.addEventListener("pointerup",V),w.addEventListener("pointercancel",V),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",q),w.removeEventListener("pointerup",V),w.removeEventListener("pointercancel",V);}},[a,q,V]),jsxs("div",{className:b("relative flex flex-col",i?"h-full w-full":"min-h-28 w-full",t),ref:r,style:{cursor:a?"grabbing":"grab"},children:[s?jsxs("div",{className:b("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",i?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c>=n,onClick:E,title:"Zoom in",type:"button",children:jsx(Ae,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c<=o,onClick:L,title:"Zoom out",type:"button",children:jsx(qe,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:D,title:"Reset zoom and pan",type:"button",children:jsx(Oe,{size:16})})]}):null,jsx("div",{className:b("flex-1 origin-center transition-transform duration-150 ease-out",i?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:j,ref:l,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var tt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:d=true})=>{let[s,m]=useState(null),[i,r]=useState(false),[l,c]=useState(""),[u,p]=useState(""),[f,a]=useState(0),{mermaid:h}=useContext(N),y=U(),k=h==null?void 0:h.errorComponent,{shouldRender:C,containerRef:M}=Ve({immediate:n});if(useEffect(()=>{if(!C)return;if(!y){m("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{m(null),r(!0);let L=y.getMermaid(o),D=e.split("").reduce((q,V)=>(q<<5)-q+V.charCodeAt(0)|0,0),A=`mermaid-${Math.abs(D)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:j}=await L.render(A,e);c(j),p(j);}catch(L){if(!(u||l)){let D=L instanceof Error?L.message:"Failed to render Mermaid chart";m(D);}}finally{r(false);}})();},[e,o,f,C,y]),!(C||l||u))return jsx("div",{className:b("my-4 min-h-[200px]",t),ref:M});if(i&&!l&&!u)return jsx("div",{className:b("my-4 flex justify-center p-4",t),ref:M,children:jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!l&&!u){let E=()=>a(L=>L+1);return k?jsx("div",{ref:M,children:jsx(k,{chart:e,error:s,retry:E})}):jsxs("div",{className:b("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:M,children:[jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),jsxs("details",{className:"mt-2",children:[jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let P=l||u;return jsx("div",{className:b("size-full",t),"data-streamdown":"mermaid",ref:M,children:jsx(Ft,{className:b(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:d,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:b("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:P},role:"img"})})})};export{b as a,ao as b,cr as c,tt as d,De as e,gn as f,hn as g,N as h,Wt as i,xn as j};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var react=require('react'),rehypeHarden=require('rehype-harden'),pn=require('rehype-raw'),un=require('rehype-sanitize'),fn=require('remark-gfm'),bn=require('remend'),jsxRuntime=require('react/jsx-runtime'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),hastUtilToJsxRuntime=require('hast-util-to-jsx-runtime'),Jo=require('remark-parse'),Fo=require('remark-rehype'),unified=require('unified'),marked=require('marked');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var pn__default=/*#__PURE__*/_interopDefault(pn);var un__default=/*#__PURE__*/_interopDefault(un);var fn__default=/*#__PURE__*/_interopDefault(fn);var bn__default=/*#__PURE__*/_interopDefault(bn);var Jo__default=/*#__PURE__*/_interopDefault(Jo);var Fo__default=/*#__PURE__*/_interopDefault(Fo);var Yt=300,Qt="300px",eo=500;function Ve(e={}){let{immediate:t=false,debounceDelay:o=Yt,rootMargin:n=Qt,idleTimeout:d=eo}=e,[s,m]=react.useState(false),i=react.useRef(null),r=react.useRef(null),l=react.useRef(null),c=react.useMemo(()=>f=>{let a=Date.now();return window.setTimeout(()=>{f({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-a))});},1)},[]),u=react.useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(f,a)=>window.requestIdleCallback(f,a):c,[c]),p=react.useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?f=>window.cancelIdleCallback(f):f=>{clearTimeout(f);},[]);return react.useEffect(()=>{if(t){m(true);return}let f=i.current;if(!f)return;r.current&&(clearTimeout(r.current),r.current=null),l.current&&(p(l.current),l.current=null);let a=()=>{r.current&&(clearTimeout(r.current),r.current=null),l.current&&(p(l.current),l.current=null);},h=M=>{l.current=u(P=>{P.timeRemaining()>0||P.didTimeout?(m(true),M.disconnect()):l.current=u(()=>{m(true),M.disconnect();},{timeout:d/2});},{timeout:d});},y=M=>{a(),r.current=window.setTimeout(()=>{var L,D;let P=M.takeRecords();(P.length===0||(D=(L=P.at(-1))==null?void 0:L.isIntersecting)!=null&&D)&&h(M);},o);},k=(M,P)=>{M.isIntersecting?y(P):a();},C=new IntersectionObserver(M=>{for(let P of M)k(P,C);},{rootMargin:n,threshold:0});return C.observe(f),()=>{r.current&&clearTimeout(r.current),l.current&&p(l.current),C.disconnect();}},[t,o,n,d,p,u]),{shouldRender:s,containerRef:i}}var J=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),F=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),z=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),Be=e=>jsxRuntime.jsxs("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[jsxRuntime.jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),je=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),Oe=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),re=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),ve=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),Ae=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),qe=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})});var b=(...e)=>tailwindMerge.twMerge(clsx.clsx(e)),B=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,d=URL.createObjectURL(n),s=document.createElement("a");s.href=d,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(d);};var ao=react.createContext({code:""}),se=()=>react.useContext(ao);var Ce=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:d,code:s,...m})=>{let[i,r]=react.useState(false),l=react.useRef(0),{code:c}=se(),{isAnimating:u}=react.useContext(N),p=s!=null?s:c,f=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(p),r(!0),e==null||e(),l.current=window.setTimeout(()=>r(!1),o));}catch(y){t==null||t(y);}};react.useEffect(()=>()=>{window.clearTimeout(l.current);},[]);let a=i?J:F;return jsxRuntime.jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",d),"data-streamdown":"code-block-copy-button",disabled:u,onClick:f,title:"Copy Code",type:"button",...m,children:n!=null?n:jsxRuntime.jsx(a,{size:14})})};var $e={"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"},We=({onDownload:e,onError:t,language:o,children:n,className:d,code:s,...m})=>{let{code:i}=se(),{isAnimating:r}=react.useContext(N),l=s!=null?s:i,u=`file.${o&&o in $e?$e[o]:"txt"}`,p="text/plain",f=()=>{try{B(u,l,p),e==null||e();}catch(a){t==null||t(a);}};return jsxRuntime.jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",d),"data-streamdown":"code-block-download-button",disabled:r,onClick:f,title:"Download file",type:"button",...m,children:n!=null?n:jsxRuntime.jsx(z,{size:14})})};var Pe=()=>jsxRuntime.jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsxRuntime.jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsxRuntime.jsx(Be,{className:"size-4 animate-spin"})})]});var fo=/\.[^/.]+$/,Xe=({node:e,className:t,src:o,alt:n,...d})=>{let s=async()=>{if(o)try{let i=await(await fetch(o)).blob(),l=new URL(o,window.location.origin).pathname.split("/").pop()||"",c=l.split(".").pop(),u=l.includes(".")&&c!==void 0&&c.length<=4,p="";if(u)p=l;else {let f=i.type,a="png";f.includes("jpeg")||f.includes("jpg")?a="jpg":f.includes("png")?a="png":f.includes("svg")?a="svg":f.includes("gif")?a="gif":f.includes("webp")&&(a="webp"),p=`${(n||l||"image").replace(fo,"")}.${a}`;}B(p,i,i.type);}catch(m){window.open(o,"_blank");}};return o?jsxRuntime.jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsxRuntime.jsx("img",{alt:n,className:b("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...d}),jsxRuntime.jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsxRuntime.jsx("button",{className:b("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:s,title:"Download image",type:"button",children:jsxRuntime.jsx(z,{size:14})})]}):null};var Q=0,yo=()=>{Q+=1,Q===1&&(document.body.style.overflow="hidden");},wo=()=>{Q=Math.max(0,Q-1),Q===0&&(document.body.style.overflow="");},Fe=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[d,s]=react.useState(false),m=react.useCallback(async()=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),2e3);}catch(r){}},[e]),i=react.useCallback(()=>{n(),o();},[n,o]);return react.useEffect(()=>{if(t){yo();let r=l=>{l.key==="Escape"&&o();};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r),wo();}}},[t,o]),t?jsxRuntime.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm","data-streamdown":"link-safety-modal",onClick:o,onKeyDown:r=>{r.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxRuntime.jsxs("div",{className:"relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg",onClick:r=>r.stopPropagation(),onKeyDown:r=>r.stopPropagation(),role:"presentation",children:[jsxRuntime.jsx("button",{className:"absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:o,title:"Close",type:"button",children:jsxRuntime.jsx(re,{size:16})}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2 font-semibold text-lg",children:[jsxRuntime.jsx(ve,{size:20}),jsxRuntime.jsx("span",{children:"Open external link?"})]}),jsxRuntime.jsx("p",{className:"text-muted-foreground text-sm",children:"You're about to visit an external website."})]}),jsxRuntime.jsx("div",{className:b("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxRuntime.jsxs("div",{className:"flex gap-2",children:[jsxRuntime.jsx("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted",onClick:m,type:"button",children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(J,{size:14}),jsxRuntime.jsx("span",{children:"Copied"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(F,{size:14}),jsxRuntime.jsx("span",{children:"Copy link"})]})}),jsxRuntime.jsxs("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90",onClick:i,type:"button",children:[jsxRuntime.jsx(ve,{size:14}),jsxRuntime.jsx("span",{children:"Open link"})]})]})]})}):null};var ie=react.createContext(null),Ue=()=>react.useContext(ie),cr=()=>{var t;let e=Ue();return (t=e==null?void 0:e.code)!=null?t:null},U=()=>{var t;let e=Ue();return (t=e==null?void 0:e.mermaid)!=null?t:null};var Ke=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((d,s)=>{let m="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),i=new Image;i.crossOrigin="anonymous",i.onload=()=>{let r=document.createElement("canvas"),l=i.width*o,c=i.height*o;r.width=l,r.height=c;let u=r.getContext("2d");if(!u){s(new Error("Failed to create 2D canvas context for PNG export"));return}u.drawImage(i,0,0,l,c),r.toBlob(p=>{if(!p){s(new Error("Failed to create PNG blob"));return}d(p);},"image/png");},i.onerror=()=>s(new Error("Failed to load SVG image")),i.src=m;})};var Ye=({chart:e,children:t,className:o,onDownload:n,config:d,onError:s})=>{let[m,i]=react.useState(false),r=react.useRef(null),{isAnimating:l}=react.useContext(N),c=U(),u=async p=>{try{if(p==="mmd"){B("diagram.mmd",e,"text/plain"),i(!1),n==null||n(p);return}if(!c){s==null||s(new Error("Mermaid plugin not available"));return}let f=c.getMermaid(d),a=e.split("").reduce((k,C)=>(k<<5)-k+C.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(a)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:y}=await f.render(h,e);if(!y){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(p==="svg"){B("diagram.svg",y,"image/svg+xml"),i(!1),n==null||n(p);return}if(p==="png"){let k=await Ke(y);B("diagram.png",k,"image/png"),n==null||n(p),i(!1);return}}catch(f){s==null||s(f);}};return react.useEffect(()=>{let p=f=>{let a=f.composedPath();r.current&&!a.includes(r.current)&&i(false);};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p);}},[]),jsxRuntime.jsxs("div",{className:"relative",ref:r,children:[jsxRuntime.jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:l,onClick:()=>i(!m),title:"Download diagram",type:"button",children:t!=null?t:jsxRuntime.jsx(z,{size:14})}),m?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var te=0,Lo=()=>{te+=1,te===1&&(document.body.style.overflow="hidden");},So=()=>{te=Math.max(0,te-1),te===0&&(document.body.style.overflow="");},ot=({chart:e,config:t,onFullscreen:o,onExit:n,className:d,...s})=>{let[m,i]=react.useState(false),{isAnimating:r,controls:l}=react.useContext(N),c=(()=>{if(typeof l=="boolean")return l;let p=l.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),u=()=>{i(!m);};return react.useEffect(()=>{if(m){Lo();let p=f=>{f.key==="Escape"&&i(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),So();}}},[m]),react.useEffect(()=>{m?o==null||o():n&&n();},[m,o,n]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",d),disabled:r,onClick:u,title:"View fullscreen",type:"button",...s,children:jsxRuntime.jsx(je,{size:14})}),m?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:u,onKeyDown:p=>{p.key==="Escape"&&u();},role:"button",tabIndex:0,children:[jsxRuntime.jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:u,title:"Exit fullscreen",type:"button",children:jsxRuntime.jsx(re,{size:20})}),jsxRuntime.jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsxRuntime.jsx(tt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:c})})]}):null]})};var le=e=>{var s,m;let t=[],o=[],n=e.querySelectorAll("thead th");for(let i of n)t.push(((s=i.textContent)==null?void 0:s.trim())||"");let d=e.querySelectorAll("tbody tr");for(let i of d){let r=[],l=i.querySelectorAll("td");for(let c of l)r.push(((m=c.textContent)==null?void 0:m.trim())||"");o.push(r);}return {headers:t,rows:o}},ce=e=>{let{headers:t,rows:o}=e,n=i=>{let r=false,l=false;for(let c of i){if(c==='"'){r=true,l=true;break}(c===","||c===`
|
|
3
|
+
`)&&(r=true);}return r?l?`"${i.replace(/"/g,'""')}"`:`"${i}"`:i},d=t.length>0?o.length+1:o.length,s=new Array(d),m=0;t.length>0&&(s[m]=t.map(n).join(","),m+=1);for(let i of o)s[m]=i.map(n).join(","),m+=1;return s.join(`
|
|
4
|
+
`)},nt=e=>{let{headers:t,rows:o}=e,n=i=>{let r=false;for(let c of i)if(c===" "||c===`
|
|
5
|
+
`||c==="\r"){r=true;break}if(!r)return i;let l=[];for(let c of i)c===" "?l.push("\\t"):c===`
|
|
6
|
+
`?l.push("\\n"):c==="\r"?l.push("\\r"):l.push(c);return l.join("")},d=t.length>0?o.length+1:o.length,s=new Array(d),m=0;t.length>0&&(s[m]=t.map(n).join(" "),m+=1);for(let i of o)s[m]=i.map(n).join(" "),m+=1;return s.join(`
|
|
7
|
+
`)},Me=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("")},rt=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),d=0,s=t.map(i=>Me(i));n[d]=`| ${s.join(" | ")} |`,d+=1;let m=new Array(t.length);for(let i=0;i<t.length;i+=1)m[i]="---";n[d]=`| ${m.join(" | ")} |`,d+=1;for(let i of o)if(i.length<t.length){let r=new Array(t.length);for(let l=0;l<t.length;l+=1)r[l]=l<i.length?Me(i[l]):"";n[d]=`| ${r.join(" | ")} |`,d+=1;}else {let r=i.map(l=>Me(l));n[d]=`| ${r.join(" | ")} |`,d+=1;}return n.join(`
|
|
8
|
+
`)};var lt=({children:e,className:t,onCopy:o,onError:n,timeout:d=2e3})=>{let[s,m]=react.useState(false),[i,r]=react.useState(false),l=react.useRef(null),c=react.useRef(0),{isAnimating:u}=react.useContext(N),p=async a=>{var h,y;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){n==null||n(new Error("Clipboard API not available"));return}try{let k=(y=l.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),C=k==null?void 0:k.querySelector("table");if(!C){n==null||n(new Error("Table not found"));return}let M=le(C),P=a==="csv"?ce(M):nt(M),E=new ClipboardItem({"text/plain":new Blob([P],{type:"text/plain"}),"text/html":new Blob([C.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),r(!0),m(!1),o==null||o(a),c.current=window.setTimeout(()=>r(!1),d);}catch(k){n==null||n(k);}};react.useEffect(()=>{let a=h=>{let y=h.composedPath();l.current&&!y.includes(l.current)&&m(false);};return document.addEventListener("mousedown",a),()=>{document.removeEventListener("mousedown",a),window.clearTimeout(c.current);}},[]);let f=i?J:F;return jsxRuntime.jsxs("div",{className:"relative",ref:l,children:[jsxRuntime.jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:u,onClick:()=>m(!s),title:"Copy table",type:"button",children:e!=null?e:jsxRuntime.jsx(f,{size:14})}),s?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var dt=({children:e,className:t,onDownload:o,onError:n})=>{let[d,s]=react.useState(false),m=react.useRef(null),{isAnimating:i}=react.useContext(N),r=l=>{var c;try{let u=(c=m.current)==null?void 0:c.closest('[data-streamdown="table-wrapper"]'),p=u==null?void 0:u.querySelector("table");if(!p){n==null||n(new Error("Table not found"));return}let f=le(p),a=l==="csv"?ce(f):rt(f);B(`table.${l==="csv"?"csv":"md"}`,a,l==="csv"?"text/csv":"text/markdown"),s(!1),o==null||o(l);}catch(u){n==null||n(u);}};return react.useEffect(()=>{let l=c=>{let u=c.composedPath();m.current&&!u.includes(m.current)&&s(false);};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l);}},[]),jsxRuntime.jsxs("div",{className:"relative",ref:m,children:[jsxRuntime.jsx("button",{className:b("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>s(!d),title:"Download table",type:"button",children:e!=null?e:jsxRuntime.jsx(z,{size:14})}),d?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>r("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>r("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var pt=({children:e,className:t,showControls:o,...n})=>jsxRuntime.jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[o?jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsxRuntime.jsx(lt,{}),jsxRuntime.jsx(dt,{})]}):null,jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsx("table",{className:b("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});var Oo=react.lazy(()=>import('./code-block-XWNGTFRY.cjs').then(e=>({default:e.CodeBlock}))),Ao=react.lazy(()=>import('./mermaid-UQ57JT4G.cjs').then(e=>({default:e.Mermaid}))),qo=/language-([^\s]+)/;function ge(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,d=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)&&(d==null?void 0:d.line)===(s==null?void 0:s.line)&&(d==null?void 0:d.column)===(s==null?void 0:s.column)}function T(e,t){return e.className===t.className&&ge(e.node,t.node)}var Ne=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ue=(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},Se=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("ol",{className:b("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>T(e,t));Se.displayName="MarkdownOl";var bt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("li",{className:b("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&ge(e.node,t.node));bt.displayName="MarkdownLi";var gt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("ul",{className:b("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>T(e,t));gt.displayName="MarkdownUl";var ht=react.memo(({className:e,node:t,...o})=>jsxRuntime.jsx("hr",{className:b("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>T(e,t));ht.displayName="MarkdownHr";var yt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("span",{className:b("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>T(e,t));yt.displayName="MarkdownStrong";var zo=({children:e,className:t,href:o,node:n,...d})=>{let{linkSafety:s}=react.useContext(N),[m,i]=react.useState(false),r=o==="streamdown:incomplete-link",l=react.useCallback(async f=>{if(!(!(s!=null&&s.enabled&&o)||r)){if(f.preventDefault(),s.onLinkCheck&&await s.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}i(true);}},[s,o,r]),c=react.useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),u=react.useCallback(()=>{i(false);},[]),p={url:o!=null?o:"",isOpen:m,onClose:u,onConfirm:c};return s!=null&&s.enabled&&o?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{className:b("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",onClick:l,type:"button",children:e}),s.renderModal?s.renderModal(p):jsxRuntime.jsx(Fe,{...p})]}):jsxRuntime.jsx("a",{className:b("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...d,children:e})},wt=react.memo(zo,(e,t)=>T(e,t)&&e.href===t.href);wt.displayName="MarkdownA";var kt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("h1",{className:b("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>T(e,t));kt.displayName="MarkdownH1";var vt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("h2",{className:b("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>T(e,t));vt.displayName="MarkdownH2";var Ct=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("h3",{className:b("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>T(e,t));Ct.displayName="MarkdownH3";var xt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("h4",{className:b("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>T(e,t));xt.displayName="MarkdownH4";var Pt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("h5",{className:b("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>T(e,t));Pt.displayName="MarkdownH5";var Mt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("h6",{className:b("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>T(e,t));Mt.displayName="MarkdownH6";var Tt=react.memo(({children:e,className:t,node:o,...n})=>{let{controls:d}=react.useContext(N),s=Ne(d,"table");return jsxRuntime.jsx(pt,{className:t,showControls:s,...n,children:e})},(e,t)=>T(e,t));Tt.displayName="MarkdownTable";var Nt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("thead",{className:b("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>T(e,t));Nt.displayName="MarkdownThead";var Lt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("tbody",{className:b("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>T(e,t));Lt.displayName="MarkdownTbody";var St=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("tr",{className:b("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>T(e,t));St.displayName="MarkdownTr";var Rt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("th",{className:b("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>T(e,t));Rt.displayName="MarkdownTh";var It=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("td",{className:b("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>T(e,t));It.displayName="MarkdownTd";var Ht=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("blockquote",{className:b("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>T(e,t));Ht.displayName="MarkdownBlockquote";var Et=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("sup",{className:b("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>T(e,t));Et.displayName="MarkdownSup";var Dt=react.memo(({children:e,className:t,node:o,...n})=>jsxRuntime.jsx("sub",{className:b("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>T(e,t));Dt.displayName="MarkdownSub";var Vt=react.memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=r=>{var p,f;if(!react.isValidElement(r))return false;let l=Array.isArray(r.props.children)?r.props.children:[r.props.children],c=false,u=false;for(let a of l)if(a){if(typeof a=="string")a.trim()!==""&&(c=true);else if(react.isValidElement(a))if(((p=a.props)==null?void 0:p["data-footnote-backref"])!==void 0)u=true;else {let h=Array.isArray(a.props.children)?a.props.children:[a.props.children];for(let y of h){if(typeof y=="string"&&y.trim()!==""){c=true;break}if(react.isValidElement(y)&&((f=y.props)==null?void 0:f["data-footnote-backref"])===void 0){c=true;break}}}}return u&&!c},m=Array.isArray(e)?e.map(r=>{if(!react.isValidElement(r))return r;if(r.type===Se){let c=(Array.isArray(r.props.children)?r.props.children:[r.props.children]).filter(u=>!s(u));return c.length===0?null:{...r,props:{...r.props,children:c}}}return r}):e;return (Array.isArray(m)?m.some(r=>r!==null):m!==null)?jsxRuntime.jsx("section",{className:t,...n,children:m}):null}return jsxRuntime.jsx("section",{className:t,...n,children:e})},(e,t)=>T(e,t));Vt.displayName="MarkdownSection";var $o=({node:e,className:t,children:o,...n})=>{var p,f,a;let d=((p=e==null?void 0:e.position)==null?void 0:p.start.line)===((f=e==null?void 0:e.position)==null?void 0:f.end.line),{mermaid:s,controls:m}=react.useContext(N),i=U();if(d)return jsxRuntime.jsx("code",{className:b("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let r=t==null?void 0:t.match(qo),l=(a=r==null?void 0:r.at(1))!=null?a:"",c="";if(react.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),l==="mermaid"&&i){let h=Ne(m,"mermaid"),y=ue(m,"download"),k=ue(m,"copy"),C=ue(m,"fullscreen"),M=ue(m,"panZoom"),P=h&&(y||k||C);return jsxRuntime.jsx(react.Suspense,{fallback:jsxRuntime.jsx(Pe,{}),children:jsxRuntime.jsxs("div",{className:b("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[P?jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-2",children:[y?jsxRuntime.jsx(Ye,{chart:c,config:s==null?void 0:s.config}):null,k?jsxRuntime.jsx(Ce,{code:c}):null,C?jsxRuntime.jsx(ot,{chart:c,config:s==null?void 0:s.config}):null]}):null,jsxRuntime.jsx(Ao,{chart:c,config:s==null?void 0:s.config,showControls:M})]})})}let u=Ne(m,"code");return jsxRuntime.jsx(react.Suspense,{fallback:jsxRuntime.jsx(Pe,{}),children:jsxRuntime.jsx(Oo,{className:b("overflow-x-auto border-border border-t",t),code:c,language:l,children:u?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(We,{code:c,language:l}),jsxRuntime.jsx(Ce,{})]}):null})})},Bt=react.memo($o,(e,t)=>e.className===t.className&&ge(e.node,t.node));Bt.displayName="MarkdownCode";var jt=react.memo(Xe,(e,t)=>e.className===t.className&&ge(e.node,t.node));jt.displayName="MarkdownImg";var Ot=react.memo(({children:e,className:t,node:o,...n})=>{var m,i;let s=(Array.isArray(e)?e:[e]).filter(r=>r!=null&&r!=="");if(s.length===1&&react.isValidElement(s[0])){let r=s[0].props.node,l=r==null?void 0:r.tagName;if(l==="img")return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e});if(l==="code"&&((m=r==null?void 0:r.position)==null?void 0:m.start.line)!==((i=r==null?void 0:r.position)==null?void 0:i.end.line))return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}return jsxRuntime.jsx("p",{className:t,...n,children:e})},(e,t)=>T(e,t));Ot.displayName="MarkdownParagraph";var At={ol:Se,li:bt,ul:gt,hr:ht,strong:yt,a:wt,h1:kt,h2:vt,h3:Ct,h4:xt,h5:Pt,h6:Mt,table:Tt,thead:Nt,tbody:Lt,tr:St,th:Rt,td:It,blockquote:Ht,code:Bt,img:jt,pre:({children:e})=>e,sup:Et,sub:Dt,p:Ot,section:Vt};var qt=[],zt={allowDangerousHtml:true},he=new WeakMap,Re=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,d=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||d||s)){let u="default";return this.keyCache.set(t,u),u}let m=u=>{if(!u||u.length===0)return "";let p="";for(let f=0;f<u.length;f+=1){let a=u[f];if(f>0&&(p+=","),Array.isArray(a)){let[h,y]=a;if(typeof h=="function"){let k=he.get(h);k||(k=h.name,he.set(h,k)),p+=k;}else p+=String(h);p+=":",p+=JSON.stringify(y);}else if(typeof a=="function"){let h=he.get(a);h||(h=a.name,he.set(a,h)),p+=h;}else p+=String(a);}return p},i=m(n),r=m(d),l=s?JSON.stringify(s):"",c=`${r}::${i}::${l}`;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 d=this.cache.keys().next().value;d&&this.cache.delete(d);}this.cache.set(n,o);}clear(){this.cache.clear();}},$t=new Re,Ie=e=>{let t=Ko(e),o=e.children||"";return Yo(t.runSync(t.parse(o),o),e)},Ko=e=>{let t=$t.get(e);if(t)return t;let o=Go(e);return $t.set(e,o),o},Go=e=>{let t=e.rehypePlugins||qt,o=e.remarkPlugins||qt,n=e.remarkRehypeOptions?{...zt,...e.remarkRehypeOptions}:zt;return unified.unified().use(Jo__default.default).use(o).use(Fo__default.default,n).use(t)},Yo=(e,t)=>hastUtilToJsxRuntime.toJsxRuntime(e,{Fragment:jsxRuntime.Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsxRuntime.jsx,jsxs:jsxRuntime.jsxs,passKeys:true,passNode:true});var en=/\[\^[^\]\s]{1,200}\](?!:)/,tn=/\[\^[^\]\s]{1,200}\]:/,on=/<\/(\w+)>/,nn=/<(\w+)[\s>]/,He=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},rn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Ee=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},De=e=>{let t=en.test(e),o=tn.test(e);if(t||o)return [e];let n=marked.Lexer.lex(e,{gfm:true}),d=[],s=[];for(let m of n){let i=m.raw,r=d.length;if(s.length>0){if(d[r-1]+=i,m.type==="html"){let c=i.match(on);if(c){let u=c[1];s.at(-1)===u&&s.pop();}}continue}if(m.type==="html"&&m.block){let c=i.match(nn);if(c){let u=c[1];i.includes(`</${u}>`)||s.push(u);}}if(i.trim()==="$$"&&r>0){let c=d[r-1],u=He(c),p=Ee(c);if(u&&p%2===1){d[r-1]=c+i;continue}}if(r>0&&rn(i)){let c=d[r-1],u=He(c),p=Ee(c),f=Ee(i);if(u&&p%2===1&&!He(i)&&f===1){d[r-1]=c+i;continue}}d.push(i);}return d};var gn={raw:pn__default.default,sanitize:[un__default.default,{}],harden:[rehypeHarden.harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},hn={gfm:[fn__default.default,{}]},yn=Object.values(gn),wn=Object.values(hn),kn={block:" \u258B",circle:" \u25CF"},vn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},N=react.createContext(vn),Wt=react.memo(({content:e,shouldParseIncompleteMarkdown:t,index:o,...n})=>jsxRuntime.jsx(Ie,{...n,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)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(d=>{var s,m;return ((s=e.components)==null?void 0:s[d])!==((m=t.components)==null?void 0:m[d])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Wt.displayName="Block";var Cn=["github-light","github-dark"],xn=react.memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,components:n,rehypePlugins:d=yn,remarkPlugins:s=wn,className:m,shikiTheme:i=Cn,mermaid:r,controls:l=true,isAnimating:c=false,BlockComponent:u=Wt,parseMarkdownIntoBlocksFn:p=De,caret:f,plugins:a,remend:h,linkSafety:y={enabled:true},...k})=>{let C=react.useId(),[M,P]=react.useTransition(),E=react.useMemo(()=>typeof e!="string"?"":t==="streaming"&&o?bn__default.default(e,h):e,[e,t,o,h]),L=react.useMemo(()=>p(E),[E,p]),[D,A]=react.useState(L);react.useEffect(()=>{t==="streaming"?P(()=>{A(L);}):A(L);},[L,t]);let j=t==="streaming"?D:L,q=react.useMemo(()=>j.map((S,W)=>`${C}-${W}`),[j.length,C]),V=react.useMemo(()=>{var S,W;return {shikiTheme:(W=(S=a==null?void 0:a.code)==null?void 0:S.getThemes())!=null?W:i,controls:l,isAnimating:c,mode:t,mermaid:r,linkSafety:y}},[i,l,c,t,r,y,a==null?void 0:a.code]),w=react.useMemo(()=>({...At,...n}),[n]),R=react.useMemo(()=>{let S=[];return a!=null&&a.cjk&&(S=[...S,...a.cjk.remarkPluginsBefore]),S=[...S,...s],a!=null&&a.cjk&&(S=[...S,...a.cjk.remarkPluginsAfter]),a!=null&&a.math&&(S=[...S,a.math.remarkPlugin]),S},[s,a==null?void 0:a.math,a==null?void 0:a.cjk]),Y=react.useMemo(()=>a!=null&&a.math?[...d,a.math.rehypePlugin]:d,[d,a==null?void 0:a.math]),Ut=react.useMemo(()=>f&&c?{"--streamdown-caret":`"${kn[f]}"`}:void 0,[f,c]);return t==="static"?jsxRuntime.jsx(ie.Provider,{value:a!=null?a:null,children:jsxRuntime.jsx(N.Provider,{value:V,children:jsxRuntime.jsx("div",{className:b("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",m),children:jsxRuntime.jsx(Ie,{components:w,rehypePlugins:Y,remarkPlugins:R,...k,children:e})})})}):jsxRuntime.jsx(ie.Provider,{value:a!=null?a:null,children:jsxRuntime.jsx(N.Provider,{value:V,children:jsxRuntime.jsxs("div",{className:b("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",f?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,m),style:Ut,children:[j.length===0&&f&&c&&jsxRuntime.jsx("span",{}),j.map((S,W)=>jsxRuntime.jsx(u,{components:w,content:S,index:W,rehypePlugins:Y,remarkPlugins:R,shouldParseIncompleteMarkdown:o,...k},q[W]))]})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety);xn.displayName="Streamdown";var Ft=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:d=.1,showControls:s=true,initialZoom:m=1,fullscreen:i=false})=>{let r=react.useRef(null),l=react.useRef(null),[c,u]=react.useState(m),[p,f]=react.useState({x:0,y:0}),[a,h]=react.useState(false),[y,k]=react.useState({x:0,y:0}),[C,M]=react.useState({x:0,y:0}),P=react.useCallback(w=>{u(R=>Math.max(o,Math.min(n,R+w)));},[o,n]),E=react.useCallback(()=>{P(d);},[P,d]),L=react.useCallback(()=>{P(-d);},[P,d]),D=react.useCallback(()=>{u(m),f({x:0,y:0});},[m]),A=react.useCallback(w=>{w.preventDefault();let R=w.deltaY>0?-d:d;P(R);},[P,d]),j=react.useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;h(true),k({x:w.clientX,y:w.clientY}),M(p);let R=w.currentTarget;R instanceof HTMLElement&&R.setPointerCapture(w.pointerId);},[p]),q=react.useCallback(w=>{if(!a)return;w.preventDefault();let R=w.clientX-y.x,Y=w.clientY-y.y;f({x:C.x+R,y:C.y+Y});},[a,y,C]),V=react.useCallback(w=>{h(false);let R=w.currentTarget;R instanceof HTMLElement&&R.releasePointerCapture(w.pointerId);},[]);return react.useEffect(()=>{let w=r.current;if(w)return w.addEventListener("wheel",A,{passive:false}),()=>{w.removeEventListener("wheel",A);}},[A]),react.useEffect(()=>{let w=l.current;if(w&&a)return document.body.style.userSelect="none",w.addEventListener("pointermove",q,{passive:false}),w.addEventListener("pointerup",V),w.addEventListener("pointercancel",V),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",q),w.removeEventListener("pointerup",V),w.removeEventListener("pointercancel",V);}},[a,q,V]),jsxRuntime.jsxs("div",{className:b("relative flex flex-col",i?"h-full w-full":"min-h-28 w-full",t),ref:r,style:{cursor:a?"grabbing":"grab"},children:[s?jsxRuntime.jsxs("div",{className:b("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",i?"bottom-4 left-4":"bottom-2 left-2"),children:[jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c>=n,onClick:E,title:"Zoom in",type:"button",children:jsxRuntime.jsx(Ae,{size:16})}),jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:c<=o,onClick:L,title:"Zoom out",type:"button",children:jsxRuntime.jsx(qe,{size:16})}),jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:D,title:"Reset zoom and pan",type:"button",children:jsxRuntime.jsx(Oe,{size:16})})]}):null,jsxRuntime.jsx("div",{className:b("flex-1 origin-center transition-transform duration-150 ease-out",i?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:j,ref:l,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var tt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:d=true})=>{let[s,m]=react.useState(null),[i,r]=react.useState(false),[l,c]=react.useState(""),[u,p]=react.useState(""),[f,a]=react.useState(0),{mermaid:h}=react.useContext(N),y=U(),k=h==null?void 0:h.errorComponent,{shouldRender:C,containerRef:M}=Ve({immediate:n});if(react.useEffect(()=>{if(!C)return;if(!y){m("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{m(null),r(!0);let L=y.getMermaid(o),D=e.split("").reduce((q,V)=>(q<<5)-q+V.charCodeAt(0)|0,0),A=`mermaid-${Math.abs(D)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:j}=await L.render(A,e);c(j),p(j);}catch(L){if(!(u||l)){let D=L instanceof Error?L.message:"Failed to render Mermaid chart";m(D);}}finally{r(false);}})();},[e,o,f,C,y]),!(C||l||u))return jsxRuntime.jsx("div",{className:b("my-4 min-h-[200px]",t),ref:M});if(i&&!l&&!u)return jsxRuntime.jsx("div",{className:b("my-4 flex justify-center p-4",t),ref:M,children:jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsxRuntime.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsxRuntime.jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!l&&!u){let E=()=>a(L=>L+1);return k?jsxRuntime.jsx("div",{ref:M,children:jsxRuntime.jsx(k,{chart:e,error:s,retry:E})}):jsxRuntime.jsxs("div",{className:b("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:M,children:[jsxRuntime.jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),jsxRuntime.jsxs("details",{className:"mt-2",children:[jsxRuntime.jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsxRuntime.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let P=l||u;return jsxRuntime.jsx("div",{className:b("size-full",t),"data-streamdown":"mermaid",ref:M,children:jsxRuntime.jsx(Ft,{className:b(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:d,zoomStep:.1,children:jsxRuntime.jsx("div",{"aria-label":"Mermaid chart",className:b("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:P},role:"img"})})})};exports.a=b;exports.b=ao;exports.c=cr;exports.d=tt;exports.e=De;exports.f=gn;exports.g=hn;exports.h=N;exports.i=Wt;exports.j=xn;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {a,h as h$1,c,b}from'./chunk-5FQGJX7Z.js';import {memo,useMemo,useContext,useState,useEffect}from'react';import {jsx,jsxs}from'react/jsx-runtime';var H=a("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"),k=memo(({children:o,result:e,language:s,className:a$1,...p})=>{let d=useMemo(()=>({backgroundColor:e.bg,color:e.fg}),[e.bg,e.fg]);return jsx("pre",{className:a(a$1,"p-4 text-sm dark:bg-(--shiki-dark-bg)!"),"data-language":s,"data-streamdown":"code-block-body",style:d,...p,children:jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:e.tokens.map((l,r)=>jsx("span",{className:H,children:l.map((t,n)=>jsx("span",{className:"dark:bg-(--shiki-dark-bg)! dark:text-(--shiki-dark)!",style:{color:t.color,backgroundColor:t.bgColor,...t.htmlStyle},...t.htmlAttrs,children:t.content},n))},r))})})},(o,e)=>o.result===e.result&&o.language===e.language&&o.className===e.className);var C=({className:o,language:e,style:s,...a$1})=>jsx("div",{className:a("my-4 w-full overflow-hidden rounded-xl border border-border",o),"data-language":e,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...s},...a$1});var h=({language:o,children:e})=>jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":o,"data-streamdown":"code-block-header",children:[jsx("span",{className:"ml-1 font-mono lowercase",children:o}),jsx("div",{className:"flex items-center gap-2",children:e})]});var W=({code:o,language:e,className:s,children:a,...p})=>{let{shikiTheme:d}=useContext(h$1),l=c(),r=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:o.split(`
|
|
3
|
+
`).map(c=>[{content:c,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[o]),[t,n]=useState(r);return useEffect(()=>{if(!l){n(r);return}let c=l.highlight({code:o,language:e,themes:d},B=>{n(B);});if(c){n(c);return}n(r);},[o,e,d,l,r]),jsx(b.Provider,{value:{code:o},children:jsxs(C,{language:e,children:[jsx(h,{language:e,children:a}),jsx(k,{className:s,language:e,result:t,...p})]})})};export{W as CodeBlock};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var chunkQX4TVXVA_cjs=require('./chunk-QX4TVXVA.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime');var H=chunkQX4TVXVA_cjs.a("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"),k=react.memo(({children:o,result:e,language:s,className:a,...p})=>{let d=react.useMemo(()=>({backgroundColor:e.bg,color:e.fg}),[e.bg,e.fg]);return jsxRuntime.jsx("pre",{className:chunkQX4TVXVA_cjs.a(a,"p-4 text-sm dark:bg-(--shiki-dark-bg)!"),"data-language":s,"data-streamdown":"code-block-body",style:d,...p,children:jsxRuntime.jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:e.tokens.map((l,r)=>jsxRuntime.jsx("span",{className:H,children:l.map((t,n)=>jsxRuntime.jsx("span",{className:"dark:bg-(--shiki-dark-bg)! dark:text-(--shiki-dark)!",style:{color:t.color,backgroundColor:t.bgColor,...t.htmlStyle},...t.htmlAttrs,children:t.content},n))},r))})})},(o,e)=>o.result===e.result&&o.language===e.language&&o.className===e.className);var C=({className:o,language:e,style:s,...a})=>jsxRuntime.jsx("div",{className:chunkQX4TVXVA_cjs.a("my-4 w-full overflow-hidden rounded-xl border border-border",o),"data-language":e,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...s},...a});var h=({language:o,children:e})=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":o,"data-streamdown":"code-block-header",children:[jsxRuntime.jsx("span",{className:"ml-1 font-mono lowercase",children:o}),jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:e})]});var W=({code:o,language:e,className:s,children:a,...p})=>{let{shikiTheme:d}=react.useContext(chunkQX4TVXVA_cjs.h),l=chunkQX4TVXVA_cjs.c(),r=react.useMemo(()=>({bg:"transparent",fg:"inherit",tokens:o.split(`
|
|
3
|
+
`).map(c=>[{content:c,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[o]),[t,n]=react.useState(r);return react.useEffect(()=>{if(!l){n(r);return}let c=l.highlight({code:o,language:e,themes:d},B=>{n(B);});if(c){n(c);return}n(r);},[o,e,d,l,r]),jsxRuntime.jsx(chunkQX4TVXVA_cjs.b.Provider,{value:{code:o},children:jsxRuntime.jsxs(C,{language:e,children:[jsxRuntime.jsx(h,{language:e,children:a}),jsxRuntime.jsx(k,{className:s,language:e,result:t,...p})]})})};exports.CodeBlock=W;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
'use strict';var
|
|
2
|
+
'use strict';var chunkQX4TVXVA_cjs=require('./chunk-QX4TVXVA.cjs');Object.defineProperty(exports,"Block",{enumerable:true,get:function(){return chunkQX4TVXVA_cjs.i}});Object.defineProperty(exports,"Streamdown",{enumerable:true,get:function(){return chunkQX4TVXVA_cjs.j}});Object.defineProperty(exports,"StreamdownContext",{enumerable:true,get:function(){return chunkQX4TVXVA_cjs.h}});Object.defineProperty(exports,"defaultRehypePlugins",{enumerable:true,get:function(){return chunkQX4TVXVA_cjs.f}});Object.defineProperty(exports,"defaultRemarkPlugins",{enumerable:true,get:function(){return chunkQX4TVXVA_cjs.g}});Object.defineProperty(exports,"parseMarkdownIntoBlocks",{enumerable:true,get:function(){return chunkQX4TVXVA_cjs.e}});
|
package/dist/index.d.cts
CHANGED
|
@@ -2,10 +2,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { JSX, ComponentType } from 'react';
|
|
4
4
|
import { MermaidConfig } from 'mermaid';
|
|
5
|
-
export { MermaidConfig } from 'mermaid';
|
|
6
5
|
import { RemendOptions } from 'remend';
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import { BundledLanguage, BundledTheme } from 'shiki';
|
|
7
|
+
export { BundledLanguage, BundledTheme } from 'shiki';
|
|
9
8
|
import { PluggableList, Pluggable } from 'unified';
|
|
10
9
|
import { Element } from 'hast';
|
|
11
10
|
import { Options as Options$1 } from 'remark-rehype';
|
|
@@ -25,17 +24,131 @@ interface Options {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
29
|
-
* These are the most frequently used languages that should have zero latency.
|
|
30
|
-
* Other languages will be loaded on-demand from CDN.
|
|
27
|
+
* A single token in a highlighted line
|
|
31
28
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
interface HighlightToken {
|
|
30
|
+
content: string;
|
|
31
|
+
color?: string;
|
|
32
|
+
bgColor?: string;
|
|
33
|
+
htmlStyle?: Record<string, string>;
|
|
34
|
+
htmlAttrs?: Record<string, string>;
|
|
35
|
+
offset?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result from code highlighting (compatible with shiki's TokensResult)
|
|
39
|
+
*/
|
|
40
|
+
interface HighlightResult {
|
|
41
|
+
tokens: HighlightToken[][];
|
|
42
|
+
fg?: string;
|
|
43
|
+
bg?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for highlighting code
|
|
47
|
+
*/
|
|
48
|
+
interface HighlightOptions {
|
|
49
|
+
code: string;
|
|
50
|
+
language: BundledLanguage;
|
|
51
|
+
themes: [string, string];
|
|
52
|
+
}
|
|
35
53
|
/**
|
|
36
|
-
*
|
|
54
|
+
* Plugin for code syntax highlighting (Shiki)
|
|
37
55
|
*/
|
|
38
|
-
|
|
56
|
+
interface CodeHighlighterPlugin {
|
|
57
|
+
name: "shiki";
|
|
58
|
+
type: "code-highlighter";
|
|
59
|
+
/**
|
|
60
|
+
* Highlight code and return tokens
|
|
61
|
+
* Returns null if highlighting not ready yet (async loading)
|
|
62
|
+
* Use callback for async result
|
|
63
|
+
*/
|
|
64
|
+
highlight: (options: HighlightOptions, callback?: (result: HighlightResult) => void) => HighlightResult | null;
|
|
65
|
+
/**
|
|
66
|
+
* Check if language is supported
|
|
67
|
+
*/
|
|
68
|
+
supportsLanguage: (language: BundledLanguage) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Get list of supported languages
|
|
71
|
+
*/
|
|
72
|
+
getSupportedLanguages: () => BundledLanguage[];
|
|
73
|
+
/**
|
|
74
|
+
* Get the configured themes
|
|
75
|
+
*/
|
|
76
|
+
getThemes: () => [BundledTheme, BundledTheme];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Mermaid instance interface
|
|
80
|
+
*/
|
|
81
|
+
interface MermaidInstance {
|
|
82
|
+
initialize: (config: MermaidConfig) => void;
|
|
83
|
+
render: (id: string, source: string) => Promise<{
|
|
84
|
+
svg: string;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Plugin for diagram rendering (Mermaid)
|
|
89
|
+
*/
|
|
90
|
+
interface DiagramPlugin {
|
|
91
|
+
name: "mermaid";
|
|
92
|
+
type: "diagram";
|
|
93
|
+
/**
|
|
94
|
+
* Language identifier for code blocks
|
|
95
|
+
*/
|
|
96
|
+
language: string;
|
|
97
|
+
/**
|
|
98
|
+
* Get the mermaid instance (initialized with optional config)
|
|
99
|
+
*/
|
|
100
|
+
getMermaid: (config?: MermaidConfig) => MermaidInstance;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Plugin for math rendering (KaTeX)
|
|
104
|
+
*/
|
|
105
|
+
interface MathPlugin {
|
|
106
|
+
name: "katex";
|
|
107
|
+
type: "math";
|
|
108
|
+
/**
|
|
109
|
+
* Get remark plugin for parsing math syntax
|
|
110
|
+
*/
|
|
111
|
+
remarkPlugin: Pluggable;
|
|
112
|
+
/**
|
|
113
|
+
* Get rehype plugin for rendering math
|
|
114
|
+
*/
|
|
115
|
+
rehypePlugin: Pluggable;
|
|
116
|
+
/**
|
|
117
|
+
* Get CSS styles for math rendering (injected into head)
|
|
118
|
+
*/
|
|
119
|
+
getStyles?: () => string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Plugin for CJK text handling
|
|
123
|
+
*/
|
|
124
|
+
interface CjkPlugin {
|
|
125
|
+
name: "cjk";
|
|
126
|
+
type: "cjk";
|
|
127
|
+
/**
|
|
128
|
+
* Remark plugins that must run BEFORE remarkGfm
|
|
129
|
+
* (e.g., remark-cjk-friendly which modifies emphasis handling)
|
|
130
|
+
*/
|
|
131
|
+
remarkPluginsBefore: Pluggable[];
|
|
132
|
+
/**
|
|
133
|
+
* Remark plugins that must run AFTER remarkGfm
|
|
134
|
+
* (e.g., autolink boundary splitting, strikethrough enhancements)
|
|
135
|
+
*/
|
|
136
|
+
remarkPluginsAfter: Pluggable[];
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Use remarkPluginsBefore and remarkPluginsAfter instead
|
|
139
|
+
* All remark plugins (for backwards compatibility)
|
|
140
|
+
*/
|
|
141
|
+
remarkPlugins: Pluggable[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Plugin configuration passed to Streamdown
|
|
145
|
+
*/
|
|
146
|
+
interface PluginConfig {
|
|
147
|
+
code?: CodeHighlighterPlugin;
|
|
148
|
+
mermaid?: DiagramPlugin;
|
|
149
|
+
math?: MathPlugin;
|
|
150
|
+
cjk?: CjkPlugin;
|
|
151
|
+
}
|
|
39
152
|
|
|
40
153
|
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
41
154
|
|
|
@@ -49,6 +162,17 @@ type ControlsConfig = boolean | {
|
|
|
49
162
|
panZoom?: boolean;
|
|
50
163
|
};
|
|
51
164
|
};
|
|
165
|
+
interface LinkSafetyModalProps {
|
|
166
|
+
url: string;
|
|
167
|
+
isOpen: boolean;
|
|
168
|
+
onClose: () => void;
|
|
169
|
+
onConfirm: () => void;
|
|
170
|
+
}
|
|
171
|
+
interface LinkSafetyConfig {
|
|
172
|
+
enabled: boolean;
|
|
173
|
+
onLinkCheck?: (url: string) => Promise<boolean> | boolean;
|
|
174
|
+
renderModal?: (props: LinkSafetyModalProps) => React.ReactNode;
|
|
175
|
+
}
|
|
52
176
|
interface MermaidErrorComponentProps {
|
|
53
177
|
error: string;
|
|
54
178
|
chart: string;
|
|
@@ -69,8 +193,9 @@ type StreamdownProps = Options & {
|
|
|
69
193
|
controls?: ControlsConfig;
|
|
70
194
|
isAnimating?: boolean;
|
|
71
195
|
caret?: keyof typeof carets;
|
|
72
|
-
|
|
196
|
+
plugins?: PluginConfig;
|
|
73
197
|
remend?: RemendOptions;
|
|
198
|
+
linkSafety?: LinkSafetyConfig;
|
|
74
199
|
};
|
|
75
200
|
declare const defaultRehypePlugins: Record<string, Pluggable>;
|
|
76
201
|
declare const defaultRemarkPlugins: Record<string, Pluggable>;
|
|
@@ -84,7 +209,7 @@ interface StreamdownContextType {
|
|
|
84
209
|
isAnimating: boolean;
|
|
85
210
|
mode: "static" | "streaming";
|
|
86
211
|
mermaid?: MermaidOptions;
|
|
87
|
-
|
|
212
|
+
linkSafety?: LinkSafetyConfig;
|
|
88
213
|
}
|
|
89
214
|
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
90
215
|
type BlockProps = Options & {
|
|
@@ -93,6 +218,6 @@ type BlockProps = Options & {
|
|
|
93
218
|
index: number;
|
|
94
219
|
};
|
|
95
220
|
declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown: _, index: __, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
96
|
-
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, caret,
|
|
221
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, caret, plugins, remend: remendOptions, linkSafety, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
97
222
|
|
|
98
|
-
export { Block, type
|
|
223
|
+
export { Block, type CjkPlugin, type CodeHighlighterPlugin, type ControlsConfig, type DiagramPlugin, type HighlightOptions, type LinkSafetyConfig, type LinkSafetyModalProps, type MathPlugin, type MermaidErrorComponentProps, type MermaidOptions, type PluginConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, defaultRehypePlugins, defaultRemarkPlugins, parseMarkdownIntoBlocks };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,9 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { JSX, ComponentType } from 'react';
|
|
4
4
|
import { MermaidConfig } from 'mermaid';
|
|
5
|
-
export { MermaidConfig } from 'mermaid';
|
|
6
5
|
import { RemendOptions } from 'remend';
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
import { BundledLanguage, BundledTheme } from 'shiki';
|
|
7
|
+
export { BundledLanguage, BundledTheme } from 'shiki';
|
|
9
8
|
import { PluggableList, Pluggable } from 'unified';
|
|
10
9
|
import { Element } from 'hast';
|
|
11
10
|
import { Options as Options$1 } from 'remark-rehype';
|
|
@@ -25,17 +24,131 @@ interface Options {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
29
|
-
* These are the most frequently used languages that should have zero latency.
|
|
30
|
-
* Other languages will be loaded on-demand from CDN.
|
|
27
|
+
* A single token in a highlighted line
|
|
31
28
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
interface HighlightToken {
|
|
30
|
+
content: string;
|
|
31
|
+
color?: string;
|
|
32
|
+
bgColor?: string;
|
|
33
|
+
htmlStyle?: Record<string, string>;
|
|
34
|
+
htmlAttrs?: Record<string, string>;
|
|
35
|
+
offset?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Result from code highlighting (compatible with shiki's TokensResult)
|
|
39
|
+
*/
|
|
40
|
+
interface HighlightResult {
|
|
41
|
+
tokens: HighlightToken[][];
|
|
42
|
+
fg?: string;
|
|
43
|
+
bg?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Options for highlighting code
|
|
47
|
+
*/
|
|
48
|
+
interface HighlightOptions {
|
|
49
|
+
code: string;
|
|
50
|
+
language: BundledLanguage;
|
|
51
|
+
themes: [string, string];
|
|
52
|
+
}
|
|
35
53
|
/**
|
|
36
|
-
*
|
|
54
|
+
* Plugin for code syntax highlighting (Shiki)
|
|
37
55
|
*/
|
|
38
|
-
|
|
56
|
+
interface CodeHighlighterPlugin {
|
|
57
|
+
name: "shiki";
|
|
58
|
+
type: "code-highlighter";
|
|
59
|
+
/**
|
|
60
|
+
* Highlight code and return tokens
|
|
61
|
+
* Returns null if highlighting not ready yet (async loading)
|
|
62
|
+
* Use callback for async result
|
|
63
|
+
*/
|
|
64
|
+
highlight: (options: HighlightOptions, callback?: (result: HighlightResult) => void) => HighlightResult | null;
|
|
65
|
+
/**
|
|
66
|
+
* Check if language is supported
|
|
67
|
+
*/
|
|
68
|
+
supportsLanguage: (language: BundledLanguage) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Get list of supported languages
|
|
71
|
+
*/
|
|
72
|
+
getSupportedLanguages: () => BundledLanguage[];
|
|
73
|
+
/**
|
|
74
|
+
* Get the configured themes
|
|
75
|
+
*/
|
|
76
|
+
getThemes: () => [BundledTheme, BundledTheme];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Mermaid instance interface
|
|
80
|
+
*/
|
|
81
|
+
interface MermaidInstance {
|
|
82
|
+
initialize: (config: MermaidConfig) => void;
|
|
83
|
+
render: (id: string, source: string) => Promise<{
|
|
84
|
+
svg: string;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Plugin for diagram rendering (Mermaid)
|
|
89
|
+
*/
|
|
90
|
+
interface DiagramPlugin {
|
|
91
|
+
name: "mermaid";
|
|
92
|
+
type: "diagram";
|
|
93
|
+
/**
|
|
94
|
+
* Language identifier for code blocks
|
|
95
|
+
*/
|
|
96
|
+
language: string;
|
|
97
|
+
/**
|
|
98
|
+
* Get the mermaid instance (initialized with optional config)
|
|
99
|
+
*/
|
|
100
|
+
getMermaid: (config?: MermaidConfig) => MermaidInstance;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Plugin for math rendering (KaTeX)
|
|
104
|
+
*/
|
|
105
|
+
interface MathPlugin {
|
|
106
|
+
name: "katex";
|
|
107
|
+
type: "math";
|
|
108
|
+
/**
|
|
109
|
+
* Get remark plugin for parsing math syntax
|
|
110
|
+
*/
|
|
111
|
+
remarkPlugin: Pluggable;
|
|
112
|
+
/**
|
|
113
|
+
* Get rehype plugin for rendering math
|
|
114
|
+
*/
|
|
115
|
+
rehypePlugin: Pluggable;
|
|
116
|
+
/**
|
|
117
|
+
* Get CSS styles for math rendering (injected into head)
|
|
118
|
+
*/
|
|
119
|
+
getStyles?: () => string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Plugin for CJK text handling
|
|
123
|
+
*/
|
|
124
|
+
interface CjkPlugin {
|
|
125
|
+
name: "cjk";
|
|
126
|
+
type: "cjk";
|
|
127
|
+
/**
|
|
128
|
+
* Remark plugins that must run BEFORE remarkGfm
|
|
129
|
+
* (e.g., remark-cjk-friendly which modifies emphasis handling)
|
|
130
|
+
*/
|
|
131
|
+
remarkPluginsBefore: Pluggable[];
|
|
132
|
+
/**
|
|
133
|
+
* Remark plugins that must run AFTER remarkGfm
|
|
134
|
+
* (e.g., autolink boundary splitting, strikethrough enhancements)
|
|
135
|
+
*/
|
|
136
|
+
remarkPluginsAfter: Pluggable[];
|
|
137
|
+
/**
|
|
138
|
+
* @deprecated Use remarkPluginsBefore and remarkPluginsAfter instead
|
|
139
|
+
* All remark plugins (for backwards compatibility)
|
|
140
|
+
*/
|
|
141
|
+
remarkPlugins: Pluggable[];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Plugin configuration passed to Streamdown
|
|
145
|
+
*/
|
|
146
|
+
interface PluginConfig {
|
|
147
|
+
code?: CodeHighlighterPlugin;
|
|
148
|
+
mermaid?: DiagramPlugin;
|
|
149
|
+
math?: MathPlugin;
|
|
150
|
+
cjk?: CjkPlugin;
|
|
151
|
+
}
|
|
39
152
|
|
|
40
153
|
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
41
154
|
|
|
@@ -49,6 +162,17 @@ type ControlsConfig = boolean | {
|
|
|
49
162
|
panZoom?: boolean;
|
|
50
163
|
};
|
|
51
164
|
};
|
|
165
|
+
interface LinkSafetyModalProps {
|
|
166
|
+
url: string;
|
|
167
|
+
isOpen: boolean;
|
|
168
|
+
onClose: () => void;
|
|
169
|
+
onConfirm: () => void;
|
|
170
|
+
}
|
|
171
|
+
interface LinkSafetyConfig {
|
|
172
|
+
enabled: boolean;
|
|
173
|
+
onLinkCheck?: (url: string) => Promise<boolean> | boolean;
|
|
174
|
+
renderModal?: (props: LinkSafetyModalProps) => React.ReactNode;
|
|
175
|
+
}
|
|
52
176
|
interface MermaidErrorComponentProps {
|
|
53
177
|
error: string;
|
|
54
178
|
chart: string;
|
|
@@ -69,8 +193,9 @@ type StreamdownProps = Options & {
|
|
|
69
193
|
controls?: ControlsConfig;
|
|
70
194
|
isAnimating?: boolean;
|
|
71
195
|
caret?: keyof typeof carets;
|
|
72
|
-
|
|
196
|
+
plugins?: PluginConfig;
|
|
73
197
|
remend?: RemendOptions;
|
|
198
|
+
linkSafety?: LinkSafetyConfig;
|
|
74
199
|
};
|
|
75
200
|
declare const defaultRehypePlugins: Record<string, Pluggable>;
|
|
76
201
|
declare const defaultRemarkPlugins: Record<string, Pluggable>;
|
|
@@ -84,7 +209,7 @@ interface StreamdownContextType {
|
|
|
84
209
|
isAnimating: boolean;
|
|
85
210
|
mode: "static" | "streaming";
|
|
86
211
|
mermaid?: MermaidOptions;
|
|
87
|
-
|
|
212
|
+
linkSafety?: LinkSafetyConfig;
|
|
88
213
|
}
|
|
89
214
|
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
90
215
|
type BlockProps = Options & {
|
|
@@ -93,6 +218,6 @@ type BlockProps = Options & {
|
|
|
93
218
|
index: number;
|
|
94
219
|
};
|
|
95
220
|
declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown: _, index: __, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
96
|
-
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, caret,
|
|
221
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, caret, plugins, remend: remendOptions, linkSafety, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
97
222
|
|
|
98
|
-
export { Block, type
|
|
223
|
+
export { Block, type CjkPlugin, type CodeHighlighterPlugin, type ControlsConfig, type DiagramPlugin, type HighlightOptions, type LinkSafetyConfig, type LinkSafetyModalProps, type MathPlugin, type MermaidErrorComponentProps, type MermaidOptions, type PluginConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, defaultRehypePlugins, defaultRemarkPlugins, parseMarkdownIntoBlocks };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export{
|
|
2
|
+
export{i as Block,j as Streamdown,h as StreamdownContext,f as defaultRehypePlugins,g as defaultRemarkPlugins,e as parseMarkdownIntoBlocks}from'./chunk-5FQGJX7Z.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamdown",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"description": "A drop-in replacement for react-markdown, designed for AI-powered streaming.",
|
|
28
28
|
"devDependencies": {
|
|
29
|
+
"shiki": "^3.19.0",
|
|
29
30
|
"@testing-library/jest-dom": "^6.9.1",
|
|
30
31
|
"@testing-library/react": "^16.3.0",
|
|
31
32
|
"@types/hast": "^3.0.4",
|
|
@@ -35,37 +36,31 @@
|
|
|
35
36
|
"@vitest/coverage-v8": "^4.0.15",
|
|
36
37
|
"jsdom": "^27.3.0",
|
|
37
38
|
"mermaid": "^11.12.2",
|
|
38
|
-
"react": "^19.2.1",
|
|
39
|
-
"react-dom": "^19.2.1",
|
|
40
39
|
"react-markdown": "^10.1.0",
|
|
41
40
|
"tsup": "^8.5.1",
|
|
42
|
-
"vitest": "^4.0.15"
|
|
41
|
+
"vitest": "^4.0.15",
|
|
42
|
+
"@streamdown/cjk": "1.0.1",
|
|
43
|
+
"@streamdown/math": "1.0.1",
|
|
44
|
+
"@streamdown/mermaid": "1.0.1"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
47
|
"react": "^18.0.0 || ^19.0.0"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
50
|
"clsx": "^2.1.1",
|
|
49
|
-
"esbuild": "^0.27.2",
|
|
50
51
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
51
52
|
"html-url-attributes": "^3.0.1",
|
|
52
|
-
"katex": "^0.16.27",
|
|
53
53
|
"marked": "^17.0.1",
|
|
54
54
|
"rehype-harden": "^1.1.7",
|
|
55
|
-
"rehype-katex": "^7.0.1",
|
|
56
55
|
"rehype-raw": "^7.0.0",
|
|
57
56
|
"rehype-sanitize": "^6.0.0",
|
|
58
|
-
"remark-cjk-friendly": "^1.2.3",
|
|
59
|
-
"remark-cjk-friendly-gfm-strikethrough": "^1.2.3",
|
|
60
57
|
"remark-gfm": "^4.0.1",
|
|
61
|
-
"remark-math": "^6.0.0",
|
|
62
58
|
"remark-parse": "^11.0.0",
|
|
63
59
|
"remark-rehype": "^11.1.2",
|
|
64
|
-
"shiki": "^3.19.0",
|
|
65
60
|
"tailwind-merge": "^3.4.0",
|
|
66
61
|
"unified": "^11.0.5",
|
|
67
62
|
"unist-util-visit": "^5.0.0",
|
|
68
|
-
"remend": "1.0
|
|
63
|
+
"remend": "1.1.0"
|
|
69
64
|
},
|
|
70
65
|
"scripts": {
|
|
71
66
|
"build": "tsup",
|
package/dist/chunk-4VFFRCJP.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {createContext,lazy,memo,useContext,isValidElement,useId,useTransition,useState,useMemo,useEffect,Suspense,useRef,useCallback}from'react';import {harden}from'rehype-harden';import Te from'rehype-katex';import Rn from'rehype-raw';import Sn from'rehype-sanitize';import In from'remark-cjk-friendly';import En from'remark-cjk-friendly-gfm-strikethrough';import Dn from'remark-gfm';import Le from'remark-math';import Hn from'remend';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import Xo from'remark-parse';import Jo from'remark-rehype';import {unified}from'unified';import {Lexer}from'marked';import {visit}from'unist-util-visit';import qt from'shiki/langs/bash.mjs';import fn from'shiki/langs/css.mjs';import $t from'shiki/langs/go.mjs';import gn from'shiki/langs/html.mjs';import hn from'shiki/langs/javascript.mjs';import bn from'shiki/langs/json.mjs';import yn from'shiki/langs/jsx.mjs';import zt from'shiki/langs/markdown.mjs';import Zt from'shiki/langs/python.mjs';import _t from'shiki/langs/shellscript.mjs';import wn from'shiki/langs/sql.mjs';import kn from'shiki/langs/toml.mjs';import vn from'shiki/langs/tsx.mjs';import xn from'shiki/langs/typescript.mjs';import Wt from'shiki/langs/yaml.mjs';var no=300,ro="300px",so=500;function Ne(e={}){let{immediate:t=false,debounceDelay:n=no,rootMargin:o=ro,idleTimeout:s=so}=e,[r,l]=useState(false),a=useRef(null),i=useRef(null),c=useRef(null),d=useMemo(()=>f=>{let u=Date.now();return window.setTimeout(()=>{f({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-u))});},1)},[]),m=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(f,u)=>window.requestIdleCallback(f,u):d,[d]),p=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?f=>window.cancelIdleCallback(f):f=>{clearTimeout(f);},[]);return useEffect(()=>{if(t){l(true);return}let f=a.current;if(!f)return;i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);let u=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);},h=C=>{c.current=m(M=>{M.timeRemaining()>0||M.didTimeout?(l(true),C.disconnect()):c.current=m(()=>{l(true),C.disconnect();},{timeout:s/2});},{timeout:s});},y=C=>{u(),i.current=window.setTimeout(()=>{var R,S;let M=C.takeRecords();(M.length===0||(S=(R=M.at(-1))==null?void 0:R.isIntersecting)!=null&&S)&&h(C);},n);},k=(C,M)=>{C.isIntersecting?y(M):u();},L=new IntersectionObserver(C=>{for(let M of C)k(M,L);},{rootMargin:o,threshold:0});return L.observe(f),()=>{i.current&&clearTimeout(i.current),c.current&&p(c.current),L.disconnect();}},[t,n,o,s,p,m]),{shouldRender:r,containerRef:a}}var G=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"})}),Y=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"})}),V=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"})}),Re=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"})]}),Se=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"})}),Ie=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"})}),Ee=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"})}),De=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"})}),He=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"})});var g=(...e)=>twMerge(clsx(e)),H=(e,t,n)=>{let o=typeof t=="string"?new Blob([t],{type:n}):t,s=URL.createObjectURL(o),r=document.createElement("a");r.href=s,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s);};var po=createContext({code:""}),Q=()=>useContext(po);var ue=({onCopy:e,onError:t,timeout:n=2e3,children:o,className:s,code:r,...l})=>{let[a,i]=useState(false),c=useRef(0),{code:d}=Q(),{isAnimating:m}=useContext(T),p=r!=null?r:d,f=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{a||(await navigator.clipboard.writeText(p),i(!0),e==null||e(),c.current=window.setTimeout(()=>i(!1),n));}catch(y){t==null||t(y);}};useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let u=a?G:Y;return jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-copy-button",disabled:m,onClick:f,title:"Copy Code",type:"button",...l,children:o!=null?o:jsx(u,{size:14})})};var Be={"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"},Ve=({onDownload:e,onError:t,language:n,children:o,className:s,code:r,...l})=>{let{code:a}=Q(),{isAnimating:i}=useContext(T),c=r!=null?r:a,m=`file.${n&&n in Be?Be[n]:"txt"}`,p="text/plain",f=()=>{try{H(m,c,p),e==null||e();}catch(u){t==null||t(u);}};return jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-download-button",disabled:i,onClick:f,title:"Download file",type:"button",...l,children:o!=null?o:jsx(V,{size:14})})};var ge=()=>jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsx(Re,{className:"size-4 animate-spin"})})]});var wo=/\.[^/.]+$/,Oe=({node:e,className:t,src:n,alt:o,...s})=>{let r=async()=>{if(n)try{let a=await(await fetch(n)).blob(),c=new URL(n,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),m=c.includes(".")&&d!==void 0&&d.length<=4,p="";if(m)p=c;else {let f=a.type,u="png";f.includes("jpeg")||f.includes("jpg")?u="jpg":f.includes("png")?u="png":f.includes("svg")?u="svg":f.includes("gif")?u="gif":f.includes("webp")&&(u="webp"),p=`${(o||c||"image").replace(wo,"")}.${u}`;}H(p,a,a.type);}catch(l){console.error("Failed to download image:",l);}};return n?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:o,className:g("max-w-full rounded-lg",t),"data-streamdown":"image",src:n,...s}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsx("button",{className:g("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:r,title:"Download image",type:"button",children:jsx(V,{size:14})})]}):null};var F={name:"streamdown",version:"2.0.0",type:"module",main:"./dist/index.js",module:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"}},files:["dist","README.md"],homepage:"https://streamdown.ai",repository:{type:"git",url:"git+https://github.com/vercel/streamdown.git",directory:"packages/streamdown"},scripts:{build:"tsup",postbuild:"node scripts/postbuild.js",test:"vitest run","test:ui":"vitest --ui run","test:coverage":"vitest --coverage run",bench:"vitest bench --run > results.txt","bench:ui":"vitest bench --ui --run",size:"node scripts/bundle-size.js"},author:"Hayden Bleasel <hayden.bleasel@vercel.com>",license:"Apache-2.0",description:"A drop-in replacement for react-markdown, designed for AI-powered streaming.",devDependencies:{"@testing-library/jest-dom":"^6.9.1","@testing-library/react":"^16.3.0","@types/hast":"^3.0.4","@types/react":"^19.2.7","@types/react-dom":"^19.2.3","@vitejs/plugin-react":"^5.1.2","@vitest/coverage-v8":"^4.0.15",jsdom:"^27.3.0",mermaid:"^11.12.2",react:"^19.2.1","react-dom":"^19.2.1","react-markdown":"^10.1.0",tsup:"^8.5.1",vitest:"^4.0.15"},peerDependencies:{react:"^18.0.0 || ^19.0.0"},dependencies:{clsx:"^2.1.1",esbuild:"^0.27.2","hast-util-to-jsx-runtime":"^2.3.6","html-url-attributes":"^3.0.1",katex:"^0.16.27",marked:"^17.0.1","rehype-harden":"^1.1.7","rehype-katex":"^7.0.1","rehype-raw":"^7.0.0","rehype-sanitize":"^6.0.0","remark-cjk-friendly":"^1.2.3","remark-cjk-friendly-gfm-strikethrough":"^1.2.3","remark-gfm":"^4.0.1","remark-math":"^6.0.0","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",remend:"workspace:*",shiki:"^3.19.0","tailwind-merge":"^3.4.0",unified:"^11.0.5","unist-util-visit":"^5.0.0"}};var qe,$e,ze,Ze,xo=((Ze=(ze=(qe=F.dependencies)==null?void 0:qe.mermaid)!=null?ze:($e=F.devDependencies)==null?void 0:$e.mermaid)!=null?Ze:"11").replace(/^\^/,""),Co=e=>`${e}/mermaid/${xo}/mermaid.esm.min.mjs`,he=new Map,Mo=new Function("url","return import(url)"),te=async(e,t)=>{let o={...{startOnLoad:false,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:true},...e};if(t==null)throw new Error("[Streamdown] Mermaid requires a CDN URL to load. Please provide a cdnUrl prop.");let s=Co(t);if(!he.has(s)){let a=await Mo(s);he.set(s,a);}let l=he.get(s).default;return l.initialize(o),l},_e=(e,t)=>{var o;let n=(o=void 0)!=null?o:5;return new Promise((s,r)=>{let l="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),a=new Image;a.crossOrigin="anonymous",a.onload=()=>{let i=document.createElement("canvas"),c=a.width*n,d=a.height*n;i.width=c,i.height=d;let m=i.getContext("2d");if(!m){r(new Error("Failed to create 2D canvas context for PNG export"));return}m.drawImage(a,0,0,c,d),i.toBlob(p=>{if(!p){r(new Error("Failed to create PNG blob"));return}s(p);},"image/png");},a.onerror=()=>r(new Error("Failed to load SVG image")),a.src=l;})};var Fe=({chart:e,children:t,className:n,onDownload:o,config:s,onError:r})=>{let[l,a]=useState(false),i=useRef(null),{isAnimating:c}=useContext(T),d=async m=>{try{if(m==="mmd"){H("diagram.mmd",e,"text/plain"),a(!1),o==null||o(m);return}let p=await te(s),f=e.split("").reduce((y,k)=>(y<<5)-y+k.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(f)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:h}=await p.render(u,e);if(!h){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){H("diagram.svg",h,"image/svg+xml"),a(!1),o==null||o(m);return}if(m==="png"){let y=await _e(h);H("diagram.png",y,"image/png"),o==null||o(m),a(!1);return}}catch(p){r==null||r(p);}};return useEffect(()=>{let m=p=>{let f=p.composedPath();i.current&&!f.includes(i.current)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:"relative",ref:i,children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",n),disabled:c,onClick:()=>a(!l),title:"Download diagram",type:"button",children:t!=null?t:jsx(V,{size:14})}),l?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var X=0,Io=()=>{X+=1,X===1&&(document.body.style.overflow="hidden");},Eo=()=>{X=Math.max(0,X-1),X===0&&(document.body.style.overflow="");},Ke=({chart:e,config:t,onFullscreen:n,onExit:o,className:s,...r})=>{let[l,a]=useState(false),{isAnimating:i,controls:c}=useContext(T),d=(()=>{if(typeof c=="boolean")return c;let p=c.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),m=()=>{a(!l);};return useEffect(()=>{if(l){Io();let p=f=>{f.key==="Escape"&&a(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),Eo();}}},[l]),useEffect(()=>{l?n==null||n():o&&o();},[l,n,o]),jsxs(Fragment,{children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:i,onClick:m,title:"View fullscreen",type:"button",...r,children:jsx(Se,{size:14})}),l?jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:m,onKeyDown:p=>{p.key==="Escape"&&m();},role:"button",tabIndex:0,children:[jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:m,title:"Exit fullscreen",type:"button",children:jsx(Ee,{size:20})}),jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsx(Je,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var oe=e=>{var r,l;let t=[],n=[],o=e.querySelectorAll("thead th");for(let a of o)t.push(((r=a.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let a of s){let i=[],c=a.querySelectorAll("td");for(let d of c)i.push(((l=d.textContent)==null?void 0:l.trim())||"");n.push(i);}return {headers:t,rows:n}},ne=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false,c=false;for(let d of a){if(d==='"'){i=true,c=true;break}(d===","||d===`
|
|
3
|
-
`)&&(i=true);}return i?c?`"${a.replace(/"/g,'""')}"`:`"${a}"`:a},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(","),l+=1);for(let a of n)r[l]=a.map(o).join(","),l+=1;return r.join(`
|
|
4
|
-
`)},Ge=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false;for(let d of a)if(d===" "||d===`
|
|
5
|
-
`||d==="\r"){i=true;break}if(!i)return a;let c=[];for(let d of a)d===" "?c.push("\\t"):d===`
|
|
6
|
-
`?c.push("\\n"):d==="\r"?c.push("\\r"):c.push(d);return c.join("")},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(" "),l+=1);for(let a of n)r[l]=a.map(o).join(" "),l+=1;return r.join(`
|
|
7
|
-
`)},be=e=>{let t=false;for(let o of e)if(o==="\\"||o==="|"){t=true;break}if(!t)return e;let n=[];for(let o of e)o==="\\"?n.push("\\\\"):o==="|"?n.push("\\|"):n.push(o);return n.join("")},Ye=e=>{let{headers:t,rows:n}=e;if(t.length===0)return "";let o=new Array(n.length+2),s=0,r=t.map(a=>be(a));o[s]=`| ${r.join(" | ")} |`,s+=1;let l=new Array(t.length);for(let a=0;a<t.length;a+=1)l[a]="---";o[s]=`| ${l.join(" | ")} |`,s+=1;for(let a of n)if(a.length<t.length){let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]=c<a.length?be(a[c]):"";o[s]=`| ${i.join(" | ")} |`,s+=1;}else {let i=a.map(c=>be(c));o[s]=`| ${i.join(" | ")} |`,s+=1;}return o.join(`
|
|
8
|
-
`)};var ot=({children:e,className:t,onCopy:n,onError:o,timeout:s=2e3})=>{let[r,l]=useState(false),[a,i]=useState(false),c=useRef(null),d=useRef(0),{isAnimating:m}=useContext(T),p=async u=>{var h,y;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){o==null||o(new Error("Clipboard API not available"));return}try{let k=(y=c.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),L=k==null?void 0:k.querySelector("table");if(!L){o==null||o(new Error("Table not found"));return}let C=oe(L),M=u==="csv"?ne(C):Ge(C),E=new ClipboardItem({"text/plain":new Blob([M],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),i(!0),l(!1),n==null||n(u),d.current=window.setTimeout(()=>i(!1),s);}catch(k){o==null||o(k);}};useEffect(()=>{let u=h=>{let y=h.composedPath();c.current&&!y.includes(c.current)&&l(false);};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current);}},[]);let f=a?G:Y;return jsxs("div",{className:"relative",ref:c,children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!r),title:"Copy table",type:"button",children:e!=null?e:jsx(f,{size:14})}),r?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var rt=({children:e,className:t,onDownload:n,onError:o})=>{let[s,r]=useState(false),l=useRef(null),{isAnimating:a}=useContext(T),i=c=>{var d;try{let m=(d=l.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),p=m==null?void 0:m.querySelector("table");if(!p){o==null||o(new Error("Table not found"));return}let f=oe(p),u=c==="csv"?ne(f):Ye(f);H(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),r(!1),n==null||n(c);}catch(m){o==null||o(m);}};return useEffect(()=>{let c=d=>{let m=d.composedPath();l.current&&!m.includes(l.current)&&r(false);};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c);}},[]),jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:a,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:jsx(V,{size:14})}),s?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var at=({children:e,className:t,showControls:n,...o})=>jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[n?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(ot,{}),jsx(rt,{})]}):null,jsx("div",{className:"overflow-x-auto",children:jsx("table",{className:g("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]});var qo=lazy(()=>import('./code-block-GEBMI5SW.js').then(e=>({default:e.CodeBlock}))),$o=lazy(()=>import('./mermaid-INZBJW3V.js').then(e=>({default:e.Mermaid}))),zo=/language-([^\s]+)/;function le(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 n=e.position.start,o=t.position.start,s=e.position.end,r=t.position.end;return (n==null?void 0:n.line)===(o==null?void 0:o.line)&&(n==null?void 0:n.column)===(o==null?void 0:o.column)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function P(e,t){return e.className===t.className&&le(e.node,t.node)}var we=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ie=(e,t)=>{if(typeof e=="boolean")return e;let n=e.mermaid;return n===false?false:n===true||n===void 0?true:n[t]!==false},ke=memo(({children:e,className:t,node:n,...o})=>jsx("ol",{className:g("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>P(e,t));ke.displayName="MarkdownOl";var dt=memo(({children:e,className:t,node:n,...o})=>jsx("li",{className:g("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&le(e.node,t.node));dt.displayName="MarkdownLi";var mt=memo(({children:e,className:t,node:n,...o})=>jsx("ul",{className:g("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>P(e,t));mt.displayName="MarkdownUl";var pt=memo(({className:e,node:t,...n})=>jsx("hr",{className:g("my-6 border-border",e),"data-streamdown":"horizontal-rule",...n}),(e,t)=>P(e,t));pt.displayName="MarkdownHr";var ut=memo(({children:e,className:t,node:n,...o})=>jsx("span",{className:g("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>P(e,t));ut.displayName="MarkdownStrong";var ft=memo(({children:e,className:t,href:n,node:o,...s})=>{let r=n==="streamdown:incomplete-link";return jsx("a",{className:g("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...s,children:e})},(e,t)=>P(e,t)&&e.href===t.href);ft.displayName="MarkdownA";var gt=memo(({children:e,className:t,node:n,...o})=>jsx("h1",{className:g("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>P(e,t));gt.displayName="MarkdownH1";var ht=memo(({children:e,className:t,node:n,...o})=>jsx("h2",{className:g("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>P(e,t));ht.displayName="MarkdownH2";var bt=memo(({children:e,className:t,node:n,...o})=>jsx("h3",{className:g("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>P(e,t));bt.displayName="MarkdownH3";var yt=memo(({children:e,className:t,node:n,...o})=>jsx("h4",{className:g("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>P(e,t));yt.displayName="MarkdownH4";var wt=memo(({children:e,className:t,node:n,...o})=>jsx("h5",{className:g("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>P(e,t));wt.displayName="MarkdownH5";var kt=memo(({children:e,className:t,node:n,...o})=>jsx("h6",{className:g("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>P(e,t));kt.displayName="MarkdownH6";var vt=memo(({children:e,className:t,node:n,...o})=>{let{controls:s}=useContext(T),r=we(s,"table");return jsx(at,{className:t,"data-streamdown":"table-wrapper",showControls:r,...o,children:e})},(e,t)=>P(e,t));vt.displayName="MarkdownTable";var xt=memo(({children:e,className:t,node:n,...o})=>jsx("thead",{className:g("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>P(e,t));xt.displayName="MarkdownThead";var Ct=memo(({children:e,className:t,node:n,...o})=>jsx("tbody",{className:g("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>P(e,t));Ct.displayName="MarkdownTbody";var Mt=memo(({children:e,className:t,node:n,...o})=>jsx("tr",{className:g("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>P(e,t));Mt.displayName="MarkdownTr";var Pt=memo(({children:e,className:t,node:n,...o})=>jsx("th",{className:g("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>P(e,t));Pt.displayName="MarkdownTh";var Tt=memo(({children:e,className:t,node:n,...o})=>jsx("td",{className:g("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>P(e,t));Tt.displayName="MarkdownTd";var Lt=memo(({children:e,className:t,node:n,...o})=>jsx("blockquote",{className:g("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>P(e,t));Lt.displayName="MarkdownBlockquote";var Nt=memo(({children:e,className:t,node:n,...o})=>jsx("sup",{className:g("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>P(e,t));Nt.displayName="MarkdownSup";var Rt=memo(({children:e,className:t,node:n,...o})=>jsx("sub",{className:g("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>P(e,t));Rt.displayName="MarkdownSub";var St=memo(({children:e,className:t,node:n,...o})=>{if("data-footnotes"in o){let r=i=>{var p,f;if(!isValidElement(i))return false;let c=Array.isArray(i.props.children)?i.props.children:[i.props.children],d=false,m=false;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=true);else if(isValidElement(u))if(((p=u.props)==null?void 0:p["data-footnote-backref"])!==void 0)m=true;else {let h=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let y of h){if(typeof y=="string"&&y.trim()!==""){d=true;break}if(isValidElement(y)&&((f=y.props)==null?void 0:f["data-footnote-backref"])===void 0){d=true;break}}}}return m&&!d},l=Array.isArray(e)?e.map(i=>{if(!isValidElement(i))return i;if(i.type===ke){let d=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(m=>!r(m));return d.length===0?null:{...i,props:{...i.props,children:d}}}return i}):e;return (Array.isArray(l)?l.some(i=>i!==null):l!==null)?jsx("section",{className:t,...o,children:l}):null}return jsx("section",{className:t,...o,children:e})},(e,t)=>P(e,t));St.displayName="MarkdownSection";var Zo=({node:e,className:t,children:n,...o})=>{var m,p,f;let s=((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((p=e==null?void 0:e.position)==null?void 0:p.end.line),{mermaid:r,controls:l}=useContext(T);if(s)return jsx("code",{className:g("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...o,children:n});let a=t==null?void 0:t.match(zo),i=(f=a==null?void 0:a.at(1))!=null?f:"",c="";if(isValidElement(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?c=n.props.children:typeof n=="string"&&(c=n),i==="mermaid"){let u=we(l,"mermaid"),h=ie(l,"download"),y=ie(l,"copy"),k=ie(l,"fullscreen"),L=ie(l,"panZoom"),C=u&&(h||y||k);return jsx(Suspense,{fallback:jsx(ge,{}),children:jsxs("div",{className:g("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[C?jsxs("div",{className:"flex items-center justify-end gap-2",children:[h?jsx(Fe,{chart:c,config:r==null?void 0:r.config}):null,y?jsx(ue,{code:c}):null,k?jsx(Ke,{chart:c,config:r==null?void 0:r.config}):null]}):null,jsx($o,{chart:c,config:r==null?void 0:r.config,showControls:L})]})})}let d=we(l,"code");return jsx(Suspense,{fallback:jsx(ge,{}),children:jsx(qo,{className:g("overflow-x-auto border-border border-t",t),code:c,language:i,children:d?jsxs(Fragment,{children:[jsx(Ve,{code:c,language:i}),jsx(ue,{})]}):null})})},It=memo(Zo,(e,t)=>e.className===t.className&&le(e.node,t.node));It.displayName="MarkdownCode";var Et=memo(Oe,(e,t)=>e.className===t.className&&le(e.node,t.node));Et.displayName="MarkdownImg";var Dt=memo(({children:e,className:t,node:n,...o})=>{var l;let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");return r.length===1&&isValidElement(r[0])&&((l=r[0].props.node)==null?void 0:l.tagName)==="img"?jsx(Fragment,{children:e}):jsx("p",{className:t,...o,children:e})},(e,t)=>P(e,t));Dt.displayName="MarkdownParagraph";var Ht={ol:ke,li:dt,ul:mt,hr:pt,strong:ut,a:ft,h1:gt,h2:ht,h3:bt,h4:yt,h5:wt,h6:kt,table:vt,thead:xt,tbody:Ct,tr:Mt,th:Pt,td:Tt,blockquote:Lt,code:It,img:Et,pre:({children:e})=>e,sup:Nt,sub:Rt,p:Dt,section:St};var Bt=[],At={allowDangerousHtml:true},ce=new WeakMap,ve=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let n=this.keyCache.get(t);if(n)return n;let o=t.rehypePlugins,s=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(o||s||r)){let m="default";return this.keyCache.set(t,m),m}let l=m=>{if(!m||m.length===0)return "";let p="";for(let f=0;f<m.length;f+=1){let u=m[f];if(f>0&&(p+=","),Array.isArray(u)){let[h,y]=u;if(typeof h=="function"){let k=ce.get(h);k||(k=h.name,ce.set(h,k)),p+=k;}else p+=String(h);p+=":",p+=JSON.stringify(y);}else if(typeof u=="function"){let h=ce.get(u);h||(h=u.name,ce.set(u,h)),p+=h;}else p+=String(u);}return p},a=l(o),i=l(s),c=r?JSON.stringify(r):"",d=`${i}::${a}::${c}`;return this.keyCache.set(t,d),d}get(t){let n=this.generateCacheKey(t),o=this.cache.get(n);return o&&(this.cache.delete(n),this.cache.set(n,o)),o}set(t,n){let o=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let s=this.cache.keys().next().value;s&&this.cache.delete(s);}this.cache.set(o,n);}clear(){this.cache.clear();}},Vt=new ve,xe=e=>{let t=Go(e),n=e.children||"";return Qo(t.runSync(t.parse(n),n),e)},Go=e=>{let t=Vt.get(e);if(t)return t;let n=Yo(e);return Vt.set(e,n),n},Yo=e=>{let t=e.rehypePlugins||Bt,n=e.remarkPlugins||Bt,o=e.remarkRehypeOptions?{...At,...e.remarkRehypeOptions}:At;return unified().use(Xo).use(n).use(Jo,o).use(t)},Qo=(e,t)=>toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true});var tn=/\[\^[^\]\s]{1,200}\](?!:)/,on=/\[\^[^\]\s]{1,200}\]:/,nn=/<\/(\w+)>/,rn=/<(\w+)[\s>]/,Ce=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
-
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},sn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
-
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Me=e=>{let t=0;for(let n=0;n<e.length-1;n+=1)e[n]==="$"&&e[n+1]==="$"&&(t+=1,n+=1);return t},Pe=e=>{let t=tn.test(e),n=on.test(e);if(t||n)return [e];let o=Lexer.lex(e,{gfm:true}),s=[],r=[];for(let l of o){let a=l.raw,i=s.length;if(r.length>0){if(s[i-1]+=a,l.type==="html"){let d=a.match(nn);if(d){let m=d[1];r.at(-1)===m&&r.pop();}}continue}if(l.type==="html"&&l.block){let d=a.match(rn);if(d){let m=d[1];a.includes(`</${m}>`)||r.push(m);}}if(a.trim()==="$$"&&i>0){let d=s[i-1],m=Ce(d),p=Me(d);if(m&&p%2===1){s[i-1]=d+a;continue}}if(i>0&&sn(a)){let d=s[i-1],m=Ce(d),p=Me(d),f=Me(a);if(m&&p%2===1&&!Ce(a)&&f===1){s[i-1]=d+a;continue}}s.push(a);}return s};var ln=new Set(["\u3002","\uFF0E","\uFF0C","\u3001","\uFF1F","\uFF01","\uFF1A","\uFF1B","\uFF08","\uFF09","\u3010","\u3011","\u300C","\u300D","\u300E","\u300F","\u3008","\u3009","\u300A","\u300B"]),cn=/^(https?:\/\/|mailto:|www\.)/i,dn=e=>{if(e.children.length!==1)return false;let t=e.children[0];return t.type==="text"&&t.value===e.url},mn=e=>{let t=0;for(let n of e){if(ln.has(n))return t;t+=n.length;}return null},pn=(e,t)=>({...t,url:e,children:[{type:"text",value:e}]}),un=e=>({type:"text",value:e}),Ot=()=>e=>{visit(e,"link",(t,n,o)=>{if(!o||typeof n!="number"||!dn(t)||!cn.test(t.url))return;let s=mn(t.url);if(s===null||s===0)return;let r=t.url.slice(0,s),l=t.url.slice(s),a=pn(r,t),i=un(l);return o.children.splice(n,1,a,i),n+1});};var Ft={javascript:hn,typescript:xn,jsx:yn,tsx:vn,html:gn,css:fn,json:bn,bash:qt,shellscript:_t,shell:_t,sh:qt,yaml:Wt,yml:Wt,toml:kn,python:Zt,py:Zt,markdown:zt,md:zt,sql:wn,go:$t,golang:$t},Cn=e=>e in Ft;var jn=/[^$]\$[^$]/,Bn=/^\$[^$]/,An=/[^$]\$$/,Vn={raw:Rn,sanitize:[Sn,{}],katex:[Te,{errorColor:"var(--color-muted-foreground)"}],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},On={gfm:[Dn,{}],cjkAutolinkBoundary:[Ot,{}],math:[Le,{singleDollarTextMath:false}],cjkFriendly:[In,{}],cjkFriendlyGfmStrikethrough:[En,{}]},qn=Object.values(Vn),$n=Object.values(On),zn={block:" \u258B",circle:" \u25CF"},Jt="https://www.streamdown.ai/cdn",Zn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,cdnUrl:Jt},T=createContext(Zn),Kt=memo(({content:e,shouldParseIncompleteMarkdown:t,index:n,...o})=>jsx(xe,{...o,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let n=Object.keys(e.components||{}),o=Object.keys(t.components||{});if(n.length!==o.length||n.some(s=>{var r,l;return ((r=e.components)==null?void 0:r[s])!==((l=t.components)==null?void 0:l[s])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Kt.displayName="Block";var _n=["github-light","github-dark"],Wn=e=>Array.isArray(e)&&e.some(t=>Array.isArray(t)?t[0]===Te:t===Te),Fn=e=>{if(!Array.isArray(e))return false;let t=e.find(n=>Array.isArray(n)?n[0]===Le:n===Le);return t&&Array.isArray(t)&&t[1]?t[1].singleDollarTextMath===true:false},Un=(e,t)=>{let n=e.includes("$$"),o=t&&(jn.test(e)||Bn.test(e)||An.test(e));return n||o},Xn=/^\^/,Jn=e=>{let t=F.dependencies["rehype-katex"].replace(Xn,"").split(".")[0],o={7:"0.16.22"}[t]||"0.16.22",s=document.createElement("link");s.rel="stylesheet",s.href=`${e}/katex/${o}/katex.min.css`,document.head.appendChild(s);},Kn=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:n=true,components:o,rehypePlugins:s=qn,remarkPlugins:r=$n,className:l,shikiTheme:a=_n,mermaid:i,controls:c=true,isAnimating:d=false,BlockComponent:m=Kt,parseMarkdownIntoBlocksFn:p=Pe,caret:f,cdnUrl:u=Jt,remend:h,...y})=>{let k=useId(),[L,C]=useTransition(),[M,E]=useState([]),R=useMemo(()=>typeof e!="string"?"":t==="streaming"&&n?Hn(e,h):e,[e,t,n,h]),S=useMemo(()=>p(R),[R,p]);useEffect(()=>{t==="streaming"?C(()=>{E(S);}):E(S);},[S,t]);let j=t==="streaming"?M:S,z=useMemo(()=>j.map((N,A)=>`${k}-${A}`),[j.length,k]),B=useMemo(()=>({shikiTheme:a,controls:c,isAnimating:d,mode:t,mermaid:i,cdnUrl:u}),[a,c,d,t,i,u]),D=useMemo(()=>({...Ht,...o}),[o]);useEffect(()=>{if(u===null||!Wn(s))return;let A=Fn(r);Un(typeof e=="string"?e:"",A)&&Jn(u);},[s,r,e,u]);let w=useMemo(()=>f&&d?{"--streamdown-caret":`"${zn[f]}"`}:void 0,[f,d]);return t==="static"?jsx(T.Provider,{value:B,children:jsx("div",{className:g("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:jsx(xe,{components:D,rehypePlugins:s,remarkPlugins:r,...y,children:e})})}):jsx(T.Provider,{value:B,children:jsx("div",{className:g("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",f?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,l),style:w,children:j.map((N,A)=>jsx(m,{components:D,content:N,index:A,rehypePlugins:s,remarkPlugins:r,shouldParseIncompleteMarkdown:n,...y},z[A]))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode);Kn.displayName="Streamdown";var eo=({children:e,className:t,minZoom:n=.5,maxZoom:o=3,zoomStep:s=.1,showControls:r=true,initialZoom:l=1,fullscreen:a=false})=>{let i=useRef(null),c=useRef(null),[d,m]=useState(l),[p,f]=useState({x:0,y:0}),[u,h]=useState(false),[y,k]=useState({x:0,y:0}),[L,C]=useState({x:0,y:0}),M=useCallback(w=>{m(N=>Math.max(n,Math.min(o,N+w)));},[n,o]),E=useCallback(()=>{M(s);},[M,s]),R=useCallback(()=>{M(-s);},[M,s]),S=useCallback(()=>{m(l),f({x:0,y:0});},[l]),j=useCallback(w=>{w.preventDefault();let N=w.deltaY>0?-s:s;M(N);},[M,s]),z=useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;h(true),k({x:w.clientX,y:w.clientY}),C(p);let N=w.currentTarget;N instanceof HTMLElement&&N.setPointerCapture(w.pointerId);},[p]),B=useCallback(w=>{if(!u)return;w.preventDefault();let N=w.clientX-y.x,A=w.clientY-y.y;f({x:L.x+N,y:L.y+A});},[u,y,L]),D=useCallback(w=>{h(false);let N=w.currentTarget;N instanceof HTMLElement&&N.releasePointerCapture(w.pointerId);},[]);return useEffect(()=>{let w=i.current;if(w)return w.addEventListener("wheel",j,{passive:false}),()=>{w.removeEventListener("wheel",j);}},[j]),useEffect(()=>{let w=c.current;if(w&&u)return document.body.style.userSelect="none",w.addEventListener("pointermove",B,{passive:false}),w.addEventListener("pointerup",D),w.addEventListener("pointercancel",D),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",B),w.removeEventListener("pointerup",D),w.removeEventListener("pointercancel",D);}},[u,B,D]),jsxs("div",{className:g("relative flex flex-col",a?"h-full w-full":"min-h-28 w-full",t),ref:i,style:{cursor:u?"grabbing":"grab"},children:[r?jsxs("div",{className:g("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",a?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d>=o,onClick:E,title:"Zoom in",type:"button",children:jsx(De,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d<=n,onClick:R,title:"Zoom out",type:"button",children:jsx(He,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:S,title:"Reset zoom and pan",type:"button",children:jsx(Ie,{size:16})})]}):null,jsx("div",{className:g("flex-1 origin-center transition-transform duration-150 ease-out",a?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:z,ref:c,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var Je=({chart:e,className:t,config:n,fullscreen:o=false,showControls:s=true})=>{let[r,l]=useState(null),[a,i]=useState(false),[c,d]=useState(""),[m,p]=useState(""),[f,u]=useState(0),{mermaid:h,cdnUrl:y}=useContext(T),k=h==null?void 0:h.errorComponent,{shouldRender:L,containerRef:C}=Ne({immediate:o});if(useEffect(()=>{if(!L)return;(async()=>{try{l(null),i(!0);let R=await te(n,y),S=e.split("").reduce((B,D)=>(B<<5)-B+D.charCodeAt(0)|0,0),j=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:z}=await R.render(j,e);d(z),p(z);}catch(R){if(!(m||c)){let S=R instanceof Error?R.message:"Failed to render Mermaid chart";l(S);}}finally{i(false);}})();},[e,n,f,L,y]),!(L||c||m))return jsx("div",{className:g("my-4 min-h-[200px]",t),ref:C});if(a&&!c&&!m)return jsx("div",{className:g("my-4 flex justify-center p-4",t),ref:C,children:jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!c&&!m){let E=()=>u(R=>R+1);return k?jsx("div",{ref:C,children:jsx(k,{chart:e,error:r,retry:E})}):jsxs("div",{className:g("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:C,children:[jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),jsxs("details",{className:"mt-2",children:[jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let M=c||m;return jsx("div",{className:"size-full",ref:C,children:jsx(eo,{className:g(o?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:o,maxZoom:3,minZoom:.5,showControls:s,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:g("flex justify-center",o?"size-full items-center":null),dangerouslySetInnerHTML:{__html:M},role:"img"})})})};
|
|
11
|
-
export{g as a,po as b,F as c,Je as d,Ft as e,Cn as f,Pe as g,Vn as h,On as i,T as j,Kt as k,Kn as l};
|
package/dist/chunk-DQKJR6WP.cjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
'use strict';var react=require('react'),rehypeHarden=require('rehype-harden'),Te=require('rehype-katex'),Rn=require('rehype-raw'),Sn=require('rehype-sanitize'),In=require('remark-cjk-friendly'),En=require('remark-cjk-friendly-gfm-strikethrough'),Dn=require('remark-gfm'),Le=require('remark-math'),Hn=require('remend'),jsxRuntime=require('react/jsx-runtime'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),hastUtilToJsxRuntime=require('hast-util-to-jsx-runtime'),Xo=require('remark-parse'),Jo=require('remark-rehype'),unified=require('unified'),marked=require('marked'),unistUtilVisit=require('unist-util-visit'),qt=require('shiki/langs/bash.mjs'),fn=require('shiki/langs/css.mjs'),$t=require('shiki/langs/go.mjs'),gn=require('shiki/langs/html.mjs'),hn=require('shiki/langs/javascript.mjs'),bn=require('shiki/langs/json.mjs'),yn=require('shiki/langs/jsx.mjs'),zt=require('shiki/langs/markdown.mjs'),Zt=require('shiki/langs/python.mjs'),_t=require('shiki/langs/shellscript.mjs'),wn=require('shiki/langs/sql.mjs'),kn=require('shiki/langs/toml.mjs'),vn=require('shiki/langs/tsx.mjs'),xn=require('shiki/langs/typescript.mjs'),Wt=require('shiki/langs/yaml.mjs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Te__default=/*#__PURE__*/_interopDefault(Te);var Rn__default=/*#__PURE__*/_interopDefault(Rn);var Sn__default=/*#__PURE__*/_interopDefault(Sn);var In__default=/*#__PURE__*/_interopDefault(In);var En__default=/*#__PURE__*/_interopDefault(En);var Dn__default=/*#__PURE__*/_interopDefault(Dn);var Le__default=/*#__PURE__*/_interopDefault(Le);var Hn__default=/*#__PURE__*/_interopDefault(Hn);var Xo__default=/*#__PURE__*/_interopDefault(Xo);var Jo__default=/*#__PURE__*/_interopDefault(Jo);var qt__default=/*#__PURE__*/_interopDefault(qt);var fn__default=/*#__PURE__*/_interopDefault(fn);var $t__default=/*#__PURE__*/_interopDefault($t);var gn__default=/*#__PURE__*/_interopDefault(gn);var hn__default=/*#__PURE__*/_interopDefault(hn);var bn__default=/*#__PURE__*/_interopDefault(bn);var yn__default=/*#__PURE__*/_interopDefault(yn);var zt__default=/*#__PURE__*/_interopDefault(zt);var Zt__default=/*#__PURE__*/_interopDefault(Zt);var _t__default=/*#__PURE__*/_interopDefault(_t);var wn__default=/*#__PURE__*/_interopDefault(wn);var kn__default=/*#__PURE__*/_interopDefault(kn);var vn__default=/*#__PURE__*/_interopDefault(vn);var xn__default=/*#__PURE__*/_interopDefault(xn);var Wt__default=/*#__PURE__*/_interopDefault(Wt);var no=300,ro="300px",so=500;function Ne(e={}){let{immediate:t=false,debounceDelay:n=no,rootMargin:o=ro,idleTimeout:s=so}=e,[r,l]=react.useState(false),a=react.useRef(null),i=react.useRef(null),c=react.useRef(null),d=react.useMemo(()=>f=>{let u=Date.now();return window.setTimeout(()=>{f({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-u))});},1)},[]),m=react.useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(f,u)=>window.requestIdleCallback(f,u):d,[d]),p=react.useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?f=>window.cancelIdleCallback(f):f=>{clearTimeout(f);},[]);return react.useEffect(()=>{if(t){l(true);return}let f=a.current;if(!f)return;i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);let u=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);},h=C=>{c.current=m(M=>{M.timeRemaining()>0||M.didTimeout?(l(true),C.disconnect()):c.current=m(()=>{l(true),C.disconnect();},{timeout:s/2});},{timeout:s});},y=C=>{u(),i.current=window.setTimeout(()=>{var R,S;let M=C.takeRecords();(M.length===0||(S=(R=M.at(-1))==null?void 0:R.isIntersecting)!=null&&S)&&h(C);},n);},k=(C,M)=>{C.isIntersecting?y(M):u();},L=new IntersectionObserver(C=>{for(let M of C)k(M,L);},{rootMargin:o,threshold:0});return L.observe(f),()=>{i.current&&clearTimeout(i.current),c.current&&p(c.current),L.disconnect();}},[t,n,o,s,p,m]),{shouldRender:r,containerRef:a}}var G=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),Y=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),V=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),Re=e=>jsxRuntime.jsxs("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[jsxRuntime.jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),Se=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),Ie=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),Ee=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),De=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})}),He=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.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"})});var g=(...e)=>tailwindMerge.twMerge(clsx.clsx(e)),H=(e,t,n)=>{let o=typeof t=="string"?new Blob([t],{type:n}):t,s=URL.createObjectURL(o),r=document.createElement("a");r.href=s,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s);};var po=react.createContext({code:""}),Q=()=>react.useContext(po);var ue=({onCopy:e,onError:t,timeout:n=2e3,children:o,className:s,code:r,...l})=>{let[a,i]=react.useState(false),c=react.useRef(0),{code:d}=Q(),{isAnimating:m}=react.useContext(T),p=r!=null?r:d,f=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{a||(await navigator.clipboard.writeText(p),i(!0),e==null||e(),c.current=window.setTimeout(()=>i(!1),n));}catch(y){t==null||t(y);}};react.useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let u=a?G:Y;return jsxRuntime.jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-copy-button",disabled:m,onClick:f,title:"Copy Code",type:"button",...l,children:o!=null?o:jsxRuntime.jsx(u,{size:14})})};var Be={"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"},Ve=({onDownload:e,onError:t,language:n,children:o,className:s,code:r,...l})=>{let{code:a}=Q(),{isAnimating:i}=react.useContext(T),c=r!=null?r:a,m=`file.${n&&n in Be?Be[n]:"txt"}`,p="text/plain",f=()=>{try{H(m,c,p),e==null||e();}catch(u){t==null||t(u);}};return jsxRuntime.jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-download-button",disabled:i,onClick:f,title:"Download file",type:"button",...l,children:o!=null?o:jsxRuntime.jsx(V,{size:14})})};var ge=()=>jsxRuntime.jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsxRuntime.jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsxRuntime.jsx(Re,{className:"size-4 animate-spin"})})]});var wo=/\.[^/.]+$/,Oe=({node:e,className:t,src:n,alt:o,...s})=>{let r=async()=>{if(n)try{let a=await(await fetch(n)).blob(),c=new URL(n,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),m=c.includes(".")&&d!==void 0&&d.length<=4,p="";if(m)p=c;else {let f=a.type,u="png";f.includes("jpeg")||f.includes("jpg")?u="jpg":f.includes("png")?u="png":f.includes("svg")?u="svg":f.includes("gif")?u="gif":f.includes("webp")&&(u="webp"),p=`${(o||c||"image").replace(wo,"")}.${u}`;}H(p,a,a.type);}catch(l){console.error("Failed to download image:",l);}};return n?jsxRuntime.jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsxRuntime.jsx("img",{alt:o,className:g("max-w-full rounded-lg",t),"data-streamdown":"image",src:n,...s}),jsxRuntime.jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsxRuntime.jsx("button",{className:g("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:r,title:"Download image",type:"button",children:jsxRuntime.jsx(V,{size:14})})]}):null};var F={name:"streamdown",version:"2.0.0",type:"module",main:"./dist/index.js",module:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"}},files:["dist","README.md"],homepage:"https://streamdown.ai",repository:{type:"git",url:"git+https://github.com/vercel/streamdown.git",directory:"packages/streamdown"},scripts:{build:"tsup",postbuild:"node scripts/postbuild.js",test:"vitest run","test:ui":"vitest --ui run","test:coverage":"vitest --coverage run",bench:"vitest bench --run > results.txt","bench:ui":"vitest bench --ui --run",size:"node scripts/bundle-size.js"},author:"Hayden Bleasel <hayden.bleasel@vercel.com>",license:"Apache-2.0",description:"A drop-in replacement for react-markdown, designed for AI-powered streaming.",devDependencies:{"@testing-library/jest-dom":"^6.9.1","@testing-library/react":"^16.3.0","@types/hast":"^3.0.4","@types/react":"^19.2.7","@types/react-dom":"^19.2.3","@vitejs/plugin-react":"^5.1.2","@vitest/coverage-v8":"^4.0.15",jsdom:"^27.3.0",mermaid:"^11.12.2",react:"^19.2.1","react-dom":"^19.2.1","react-markdown":"^10.1.0",tsup:"^8.5.1",vitest:"^4.0.15"},peerDependencies:{react:"^18.0.0 || ^19.0.0"},dependencies:{clsx:"^2.1.1",esbuild:"^0.27.2","hast-util-to-jsx-runtime":"^2.3.6","html-url-attributes":"^3.0.1",katex:"^0.16.27",marked:"^17.0.1","rehype-harden":"^1.1.7","rehype-katex":"^7.0.1","rehype-raw":"^7.0.0","rehype-sanitize":"^6.0.0","remark-cjk-friendly":"^1.2.3","remark-cjk-friendly-gfm-strikethrough":"^1.2.3","remark-gfm":"^4.0.1","remark-math":"^6.0.0","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",remend:"workspace:*",shiki:"^3.19.0","tailwind-merge":"^3.4.0",unified:"^11.0.5","unist-util-visit":"^5.0.0"}};var qe,$e,ze,Ze,xo=((Ze=(ze=(qe=F.dependencies)==null?void 0:qe.mermaid)!=null?ze:($e=F.devDependencies)==null?void 0:$e.mermaid)!=null?Ze:"11").replace(/^\^/,""),Co=e=>`${e}/mermaid/${xo}/mermaid.esm.min.mjs`,he=new Map,Mo=new Function("url","return import(url)"),te=async(e,t)=>{let o={...{startOnLoad:false,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:true},...e};if(t==null)throw new Error("[Streamdown] Mermaid requires a CDN URL to load. Please provide a cdnUrl prop.");let s=Co(t);if(!he.has(s)){let a=await Mo(s);he.set(s,a);}let l=he.get(s).default;return l.initialize(o),l},_e=(e,t)=>{var o;let n=(o=void 0)!=null?o:5;return new Promise((s,r)=>{let l="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),a=new Image;a.crossOrigin="anonymous",a.onload=()=>{let i=document.createElement("canvas"),c=a.width*n,d=a.height*n;i.width=c,i.height=d;let m=i.getContext("2d");if(!m){r(new Error("Failed to create 2D canvas context for PNG export"));return}m.drawImage(a,0,0,c,d),i.toBlob(p=>{if(!p){r(new Error("Failed to create PNG blob"));return}s(p);},"image/png");},a.onerror=()=>r(new Error("Failed to load SVG image")),a.src=l;})};var Fe=({chart:e,children:t,className:n,onDownload:o,config:s,onError:r})=>{let[l,a]=react.useState(false),i=react.useRef(null),{isAnimating:c}=react.useContext(T),d=async m=>{try{if(m==="mmd"){H("diagram.mmd",e,"text/plain"),a(!1),o==null||o(m);return}let p=await te(s),f=e.split("").reduce((y,k)=>(y<<5)-y+k.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(f)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:h}=await p.render(u,e);if(!h){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){H("diagram.svg",h,"image/svg+xml"),a(!1),o==null||o(m);return}if(m==="png"){let y=await _e(h);H("diagram.png",y,"image/png"),o==null||o(m),a(!1);return}}catch(p){r==null||r(p);}};return react.useEffect(()=>{let m=p=>{let f=p.composedPath();i.current&&!f.includes(i.current)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxRuntime.jsxs("div",{className:"relative",ref:i,children:[jsxRuntime.jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",n),disabled:c,onClick:()=>a(!l),title:"Download diagram",type:"button",children:t!=null?t:jsxRuntime.jsx(V,{size:14})}),l?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var X=0,Io=()=>{X+=1,X===1&&(document.body.style.overflow="hidden");},Eo=()=>{X=Math.max(0,X-1),X===0&&(document.body.style.overflow="");},Ke=({chart:e,config:t,onFullscreen:n,onExit:o,className:s,...r})=>{let[l,a]=react.useState(false),{isAnimating:i,controls:c}=react.useContext(T),d=(()=>{if(typeof c=="boolean")return c;let p=c.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),m=()=>{a(!l);};return react.useEffect(()=>{if(l){Io();let p=f=>{f.key==="Escape"&&a(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),Eo();}}},[l]),react.useEffect(()=>{l?n==null||n():o&&o();},[l,n,o]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:i,onClick:m,title:"View fullscreen",type:"button",...r,children:jsxRuntime.jsx(Se,{size:14})}),l?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:m,onKeyDown:p=>{p.key==="Escape"&&m();},role:"button",tabIndex:0,children:[jsxRuntime.jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:m,title:"Exit fullscreen",type:"button",children:jsxRuntime.jsx(Ee,{size:20})}),jsxRuntime.jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsxRuntime.jsx(Je,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var oe=e=>{var r,l;let t=[],n=[],o=e.querySelectorAll("thead th");for(let a of o)t.push(((r=a.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let a of s){let i=[],c=a.querySelectorAll("td");for(let d of c)i.push(((l=d.textContent)==null?void 0:l.trim())||"");n.push(i);}return {headers:t,rows:n}},ne=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false,c=false;for(let d of a){if(d==='"'){i=true,c=true;break}(d===","||d===`
|
|
3
|
-
`)&&(i=true);}return i?c?`"${a.replace(/"/g,'""')}"`:`"${a}"`:a},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(","),l+=1);for(let a of n)r[l]=a.map(o).join(","),l+=1;return r.join(`
|
|
4
|
-
`)},Ge=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false;for(let d of a)if(d===" "||d===`
|
|
5
|
-
`||d==="\r"){i=true;break}if(!i)return a;let c=[];for(let d of a)d===" "?c.push("\\t"):d===`
|
|
6
|
-
`?c.push("\\n"):d==="\r"?c.push("\\r"):c.push(d);return c.join("")},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(" "),l+=1);for(let a of n)r[l]=a.map(o).join(" "),l+=1;return r.join(`
|
|
7
|
-
`)},be=e=>{let t=false;for(let o of e)if(o==="\\"||o==="|"){t=true;break}if(!t)return e;let n=[];for(let o of e)o==="\\"?n.push("\\\\"):o==="|"?n.push("\\|"):n.push(o);return n.join("")},Ye=e=>{let{headers:t,rows:n}=e;if(t.length===0)return "";let o=new Array(n.length+2),s=0,r=t.map(a=>be(a));o[s]=`| ${r.join(" | ")} |`,s+=1;let l=new Array(t.length);for(let a=0;a<t.length;a+=1)l[a]="---";o[s]=`| ${l.join(" | ")} |`,s+=1;for(let a of n)if(a.length<t.length){let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]=c<a.length?be(a[c]):"";o[s]=`| ${i.join(" | ")} |`,s+=1;}else {let i=a.map(c=>be(c));o[s]=`| ${i.join(" | ")} |`,s+=1;}return o.join(`
|
|
8
|
-
`)};var ot=({children:e,className:t,onCopy:n,onError:o,timeout:s=2e3})=>{let[r,l]=react.useState(false),[a,i]=react.useState(false),c=react.useRef(null),d=react.useRef(0),{isAnimating:m}=react.useContext(T),p=async u=>{var h,y;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){o==null||o(new Error("Clipboard API not available"));return}try{let k=(y=c.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),L=k==null?void 0:k.querySelector("table");if(!L){o==null||o(new Error("Table not found"));return}let C=oe(L),M=u==="csv"?ne(C):Ge(C),E=new ClipboardItem({"text/plain":new Blob([M],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),i(!0),l(!1),n==null||n(u),d.current=window.setTimeout(()=>i(!1),s);}catch(k){o==null||o(k);}};react.useEffect(()=>{let u=h=>{let y=h.composedPath();c.current&&!y.includes(c.current)&&l(false);};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current);}},[]);let f=a?G:Y;return jsxRuntime.jsxs("div",{className:"relative",ref:c,children:[jsxRuntime.jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!r),title:"Copy table",type:"button",children:e!=null?e:jsxRuntime.jsx(f,{size:14})}),r?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var rt=({children:e,className:t,onDownload:n,onError:o})=>{let[s,r]=react.useState(false),l=react.useRef(null),{isAnimating:a}=react.useContext(T),i=c=>{var d;try{let m=(d=l.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),p=m==null?void 0:m.querySelector("table");if(!p){o==null||o(new Error("Table not found"));return}let f=oe(p),u=c==="csv"?ne(f):Ye(f);H(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),r(!1),n==null||n(c);}catch(m){o==null||o(m);}};return react.useEffect(()=>{let c=d=>{let m=d.composedPath();l.current&&!m.includes(l.current)&&r(false);};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c);}},[]),jsxRuntime.jsxs("div",{className:"relative",ref:l,children:[jsxRuntime.jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:a,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:jsxRuntime.jsx(V,{size:14})}),s?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var at=({children:e,className:t,showControls:n,...o})=>jsxRuntime.jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[n?jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsxRuntime.jsx(ot,{}),jsxRuntime.jsx(rt,{})]}):null,jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsx("table",{className:g("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]});var qo=react.lazy(()=>import('./code-block-3WZ5YY6K.cjs').then(e=>({default:e.CodeBlock}))),$o=react.lazy(()=>import('./mermaid-5MRP2H6R.cjs').then(e=>({default:e.Mermaid}))),zo=/language-([^\s]+)/;function le(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 n=e.position.start,o=t.position.start,s=e.position.end,r=t.position.end;return (n==null?void 0:n.line)===(o==null?void 0:o.line)&&(n==null?void 0:n.column)===(o==null?void 0:o.column)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function P(e,t){return e.className===t.className&&le(e.node,t.node)}var we=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ie=(e,t)=>{if(typeof e=="boolean")return e;let n=e.mermaid;return n===false?false:n===true||n===void 0?true:n[t]!==false},ke=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("ol",{className:g("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>P(e,t));ke.displayName="MarkdownOl";var dt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("li",{className:g("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&le(e.node,t.node));dt.displayName="MarkdownLi";var mt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("ul",{className:g("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>P(e,t));mt.displayName="MarkdownUl";var pt=react.memo(({className:e,node:t,...n})=>jsxRuntime.jsx("hr",{className:g("my-6 border-border",e),"data-streamdown":"horizontal-rule",...n}),(e,t)=>P(e,t));pt.displayName="MarkdownHr";var ut=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("span",{className:g("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>P(e,t));ut.displayName="MarkdownStrong";var ft=react.memo(({children:e,className:t,href:n,node:o,...s})=>{let r=n==="streamdown:incomplete-link";return jsxRuntime.jsx("a",{className:g("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...s,children:e})},(e,t)=>P(e,t)&&e.href===t.href);ft.displayName="MarkdownA";var gt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h1",{className:g("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>P(e,t));gt.displayName="MarkdownH1";var ht=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h2",{className:g("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>P(e,t));ht.displayName="MarkdownH2";var bt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h3",{className:g("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>P(e,t));bt.displayName="MarkdownH3";var yt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h4",{className:g("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>P(e,t));yt.displayName="MarkdownH4";var wt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h5",{className:g("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>P(e,t));wt.displayName="MarkdownH5";var kt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h6",{className:g("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>P(e,t));kt.displayName="MarkdownH6";var vt=react.memo(({children:e,className:t,node:n,...o})=>{let{controls:s}=react.useContext(T),r=we(s,"table");return jsxRuntime.jsx(at,{className:t,"data-streamdown":"table-wrapper",showControls:r,...o,children:e})},(e,t)=>P(e,t));vt.displayName="MarkdownTable";var xt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("thead",{className:g("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>P(e,t));xt.displayName="MarkdownThead";var Ct=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("tbody",{className:g("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>P(e,t));Ct.displayName="MarkdownTbody";var Mt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("tr",{className:g("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>P(e,t));Mt.displayName="MarkdownTr";var Pt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("th",{className:g("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>P(e,t));Pt.displayName="MarkdownTh";var Tt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("td",{className:g("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>P(e,t));Tt.displayName="MarkdownTd";var Lt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("blockquote",{className:g("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>P(e,t));Lt.displayName="MarkdownBlockquote";var Nt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("sup",{className:g("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>P(e,t));Nt.displayName="MarkdownSup";var Rt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("sub",{className:g("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>P(e,t));Rt.displayName="MarkdownSub";var St=react.memo(({children:e,className:t,node:n,...o})=>{if("data-footnotes"in o){let r=i=>{var p,f;if(!react.isValidElement(i))return false;let c=Array.isArray(i.props.children)?i.props.children:[i.props.children],d=false,m=false;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=true);else if(react.isValidElement(u))if(((p=u.props)==null?void 0:p["data-footnote-backref"])!==void 0)m=true;else {let h=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let y of h){if(typeof y=="string"&&y.trim()!==""){d=true;break}if(react.isValidElement(y)&&((f=y.props)==null?void 0:f["data-footnote-backref"])===void 0){d=true;break}}}}return m&&!d},l=Array.isArray(e)?e.map(i=>{if(!react.isValidElement(i))return i;if(i.type===ke){let d=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(m=>!r(m));return d.length===0?null:{...i,props:{...i.props,children:d}}}return i}):e;return (Array.isArray(l)?l.some(i=>i!==null):l!==null)?jsxRuntime.jsx("section",{className:t,...o,children:l}):null}return jsxRuntime.jsx("section",{className:t,...o,children:e})},(e,t)=>P(e,t));St.displayName="MarkdownSection";var Zo=({node:e,className:t,children:n,...o})=>{var m,p,f;let s=((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((p=e==null?void 0:e.position)==null?void 0:p.end.line),{mermaid:r,controls:l}=react.useContext(T);if(s)return jsxRuntime.jsx("code",{className:g("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...o,children:n});let a=t==null?void 0:t.match(zo),i=(f=a==null?void 0:a.at(1))!=null?f:"",c="";if(react.isValidElement(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?c=n.props.children:typeof n=="string"&&(c=n),i==="mermaid"){let u=we(l,"mermaid"),h=ie(l,"download"),y=ie(l,"copy"),k=ie(l,"fullscreen"),L=ie(l,"panZoom"),C=u&&(h||y||k);return jsxRuntime.jsx(react.Suspense,{fallback:jsxRuntime.jsx(ge,{}),children:jsxRuntime.jsxs("div",{className:g("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[C?jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-2",children:[h?jsxRuntime.jsx(Fe,{chart:c,config:r==null?void 0:r.config}):null,y?jsxRuntime.jsx(ue,{code:c}):null,k?jsxRuntime.jsx(Ke,{chart:c,config:r==null?void 0:r.config}):null]}):null,jsxRuntime.jsx($o,{chart:c,config:r==null?void 0:r.config,showControls:L})]})})}let d=we(l,"code");return jsxRuntime.jsx(react.Suspense,{fallback:jsxRuntime.jsx(ge,{}),children:jsxRuntime.jsx(qo,{className:g("overflow-x-auto border-border border-t",t),code:c,language:i,children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Ve,{code:c,language:i}),jsxRuntime.jsx(ue,{})]}):null})})},It=react.memo(Zo,(e,t)=>e.className===t.className&&le(e.node,t.node));It.displayName="MarkdownCode";var Et=react.memo(Oe,(e,t)=>e.className===t.className&&le(e.node,t.node));Et.displayName="MarkdownImg";var Dt=react.memo(({children:e,className:t,node:n,...o})=>{var l;let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");return r.length===1&&react.isValidElement(r[0])&&((l=r[0].props.node)==null?void 0:l.tagName)==="img"?jsxRuntime.jsx(jsxRuntime.Fragment,{children:e}):jsxRuntime.jsx("p",{className:t,...o,children:e})},(e,t)=>P(e,t));Dt.displayName="MarkdownParagraph";var Ht={ol:ke,li:dt,ul:mt,hr:pt,strong:ut,a:ft,h1:gt,h2:ht,h3:bt,h4:yt,h5:wt,h6:kt,table:vt,thead:xt,tbody:Ct,tr:Mt,th:Pt,td:Tt,blockquote:Lt,code:It,img:Et,pre:({children:e})=>e,sup:Nt,sub:Rt,p:Dt,section:St};var Bt=[],At={allowDangerousHtml:true},ce=new WeakMap,ve=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let n=this.keyCache.get(t);if(n)return n;let o=t.rehypePlugins,s=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(o||s||r)){let m="default";return this.keyCache.set(t,m),m}let l=m=>{if(!m||m.length===0)return "";let p="";for(let f=0;f<m.length;f+=1){let u=m[f];if(f>0&&(p+=","),Array.isArray(u)){let[h,y]=u;if(typeof h=="function"){let k=ce.get(h);k||(k=h.name,ce.set(h,k)),p+=k;}else p+=String(h);p+=":",p+=JSON.stringify(y);}else if(typeof u=="function"){let h=ce.get(u);h||(h=u.name,ce.set(u,h)),p+=h;}else p+=String(u);}return p},a=l(o),i=l(s),c=r?JSON.stringify(r):"",d=`${i}::${a}::${c}`;return this.keyCache.set(t,d),d}get(t){let n=this.generateCacheKey(t),o=this.cache.get(n);return o&&(this.cache.delete(n),this.cache.set(n,o)),o}set(t,n){let o=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let s=this.cache.keys().next().value;s&&this.cache.delete(s);}this.cache.set(o,n);}clear(){this.cache.clear();}},Vt=new ve,xe=e=>{let t=Go(e),n=e.children||"";return Qo(t.runSync(t.parse(n),n),e)},Go=e=>{let t=Vt.get(e);if(t)return t;let n=Yo(e);return Vt.set(e,n),n},Yo=e=>{let t=e.rehypePlugins||Bt,n=e.remarkPlugins||Bt,o=e.remarkRehypeOptions?{...At,...e.remarkRehypeOptions}:At;return unified.unified().use(Xo__default.default).use(n).use(Jo__default.default,o).use(t)},Qo=(e,t)=>hastUtilToJsxRuntime.toJsxRuntime(e,{Fragment:jsxRuntime.Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsxRuntime.jsx,jsxs:jsxRuntime.jsxs,passKeys:true,passNode:true});var tn=/\[\^[^\]\s]{1,200}\](?!:)/,on=/\[\^[^\]\s]{1,200}\]:/,nn=/<\/(\w+)>/,rn=/<(\w+)[\s>]/,Ce=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
-
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},sn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
-
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Me=e=>{let t=0;for(let n=0;n<e.length-1;n+=1)e[n]==="$"&&e[n+1]==="$"&&(t+=1,n+=1);return t},Pe=e=>{let t=tn.test(e),n=on.test(e);if(t||n)return [e];let o=marked.Lexer.lex(e,{gfm:true}),s=[],r=[];for(let l of o){let a=l.raw,i=s.length;if(r.length>0){if(s[i-1]+=a,l.type==="html"){let d=a.match(nn);if(d){let m=d[1];r.at(-1)===m&&r.pop();}}continue}if(l.type==="html"&&l.block){let d=a.match(rn);if(d){let m=d[1];a.includes(`</${m}>`)||r.push(m);}}if(a.trim()==="$$"&&i>0){let d=s[i-1],m=Ce(d),p=Me(d);if(m&&p%2===1){s[i-1]=d+a;continue}}if(i>0&&sn(a)){let d=s[i-1],m=Ce(d),p=Me(d),f=Me(a);if(m&&p%2===1&&!Ce(a)&&f===1){s[i-1]=d+a;continue}}s.push(a);}return s};var ln=new Set(["\u3002","\uFF0E","\uFF0C","\u3001","\uFF1F","\uFF01","\uFF1A","\uFF1B","\uFF08","\uFF09","\u3010","\u3011","\u300C","\u300D","\u300E","\u300F","\u3008","\u3009","\u300A","\u300B"]),cn=/^(https?:\/\/|mailto:|www\.)/i,dn=e=>{if(e.children.length!==1)return false;let t=e.children[0];return t.type==="text"&&t.value===e.url},mn=e=>{let t=0;for(let n of e){if(ln.has(n))return t;t+=n.length;}return null},pn=(e,t)=>({...t,url:e,children:[{type:"text",value:e}]}),un=e=>({type:"text",value:e}),Ot=()=>e=>{unistUtilVisit.visit(e,"link",(t,n,o)=>{if(!o||typeof n!="number"||!dn(t)||!cn.test(t.url))return;let s=mn(t.url);if(s===null||s===0)return;let r=t.url.slice(0,s),l=t.url.slice(s),a=pn(r,t),i=un(l);return o.children.splice(n,1,a,i),n+1});};var Ft={javascript:hn__default.default,typescript:xn__default.default,jsx:yn__default.default,tsx:vn__default.default,html:gn__default.default,css:fn__default.default,json:bn__default.default,bash:qt__default.default,shellscript:_t__default.default,shell:_t__default.default,sh:qt__default.default,yaml:Wt__default.default,yml:Wt__default.default,toml:kn__default.default,python:Zt__default.default,py:Zt__default.default,markdown:zt__default.default,md:zt__default.default,sql:wn__default.default,go:$t__default.default,golang:$t__default.default},Cn=e=>e in Ft;var jn=/[^$]\$[^$]/,Bn=/^\$[^$]/,An=/[^$]\$$/,Vn={raw:Rn__default.default,sanitize:[Sn__default.default,{}],katex:[Te__default.default,{errorColor:"var(--color-muted-foreground)"}],harden:[rehypeHarden.harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},On={gfm:[Dn__default.default,{}],cjkAutolinkBoundary:[Ot,{}],math:[Le__default.default,{singleDollarTextMath:false}],cjkFriendly:[In__default.default,{}],cjkFriendlyGfmStrikethrough:[En__default.default,{}]},qn=Object.values(Vn),$n=Object.values(On),zn={block:" \u258B",circle:" \u25CF"},Jt="https://www.streamdown.ai/cdn",Zn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,cdnUrl:Jt},T=react.createContext(Zn),Kt=react.memo(({content:e,shouldParseIncompleteMarkdown:t,index:n,...o})=>jsxRuntime.jsx(xe,{...o,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let n=Object.keys(e.components||{}),o=Object.keys(t.components||{});if(n.length!==o.length||n.some(s=>{var r,l;return ((r=e.components)==null?void 0:r[s])!==((l=t.components)==null?void 0:l[s])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Kt.displayName="Block";var _n=["github-light","github-dark"],Wn=e=>Array.isArray(e)&&e.some(t=>Array.isArray(t)?t[0]===Te__default.default:t===Te__default.default),Fn=e=>{if(!Array.isArray(e))return false;let t=e.find(n=>Array.isArray(n)?n[0]===Le__default.default:n===Le__default.default);return t&&Array.isArray(t)&&t[1]?t[1].singleDollarTextMath===true:false},Un=(e,t)=>{let n=e.includes("$$"),o=t&&(jn.test(e)||Bn.test(e)||An.test(e));return n||o},Xn=/^\^/,Jn=e=>{let t=F.dependencies["rehype-katex"].replace(Xn,"").split(".")[0],o={7:"0.16.22"}[t]||"0.16.22",s=document.createElement("link");s.rel="stylesheet",s.href=`${e}/katex/${o}/katex.min.css`,document.head.appendChild(s);},Kn=react.memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:n=true,components:o,rehypePlugins:s=qn,remarkPlugins:r=$n,className:l,shikiTheme:a=_n,mermaid:i,controls:c=true,isAnimating:d=false,BlockComponent:m=Kt,parseMarkdownIntoBlocksFn:p=Pe,caret:f,cdnUrl:u=Jt,remend:h,...y})=>{let k=react.useId(),[L,C]=react.useTransition(),[M,E]=react.useState([]),R=react.useMemo(()=>typeof e!="string"?"":t==="streaming"&&n?Hn__default.default(e,h):e,[e,t,n,h]),S=react.useMemo(()=>p(R),[R,p]);react.useEffect(()=>{t==="streaming"?C(()=>{E(S);}):E(S);},[S,t]);let j=t==="streaming"?M:S,z=react.useMemo(()=>j.map((N,A)=>`${k}-${A}`),[j.length,k]),B=react.useMemo(()=>({shikiTheme:a,controls:c,isAnimating:d,mode:t,mermaid:i,cdnUrl:u}),[a,c,d,t,i,u]),D=react.useMemo(()=>({...Ht,...o}),[o]);react.useEffect(()=>{if(u===null||!Wn(s))return;let A=Fn(r);Un(typeof e=="string"?e:"",A)&&Jn(u);},[s,r,e,u]);let w=react.useMemo(()=>f&&d?{"--streamdown-caret":`"${zn[f]}"`}:void 0,[f,d]);return t==="static"?jsxRuntime.jsx(T.Provider,{value:B,children:jsxRuntime.jsx("div",{className:g("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:jsxRuntime.jsx(xe,{components:D,rehypePlugins:s,remarkPlugins:r,...y,children:e})})}):jsxRuntime.jsx(T.Provider,{value:B,children:jsxRuntime.jsx("div",{className:g("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",f?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,l),style:w,children:j.map((N,A)=>jsxRuntime.jsx(m,{components:D,content:N,index:A,rehypePlugins:s,remarkPlugins:r,shouldParseIncompleteMarkdown:n,...y},z[A]))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode);Kn.displayName="Streamdown";var eo=({children:e,className:t,minZoom:n=.5,maxZoom:o=3,zoomStep:s=.1,showControls:r=true,initialZoom:l=1,fullscreen:a=false})=>{let i=react.useRef(null),c=react.useRef(null),[d,m]=react.useState(l),[p,f]=react.useState({x:0,y:0}),[u,h]=react.useState(false),[y,k]=react.useState({x:0,y:0}),[L,C]=react.useState({x:0,y:0}),M=react.useCallback(w=>{m(N=>Math.max(n,Math.min(o,N+w)));},[n,o]),E=react.useCallback(()=>{M(s);},[M,s]),R=react.useCallback(()=>{M(-s);},[M,s]),S=react.useCallback(()=>{m(l),f({x:0,y:0});},[l]),j=react.useCallback(w=>{w.preventDefault();let N=w.deltaY>0?-s:s;M(N);},[M,s]),z=react.useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;h(true),k({x:w.clientX,y:w.clientY}),C(p);let N=w.currentTarget;N instanceof HTMLElement&&N.setPointerCapture(w.pointerId);},[p]),B=react.useCallback(w=>{if(!u)return;w.preventDefault();let N=w.clientX-y.x,A=w.clientY-y.y;f({x:L.x+N,y:L.y+A});},[u,y,L]),D=react.useCallback(w=>{h(false);let N=w.currentTarget;N instanceof HTMLElement&&N.releasePointerCapture(w.pointerId);},[]);return react.useEffect(()=>{let w=i.current;if(w)return w.addEventListener("wheel",j,{passive:false}),()=>{w.removeEventListener("wheel",j);}},[j]),react.useEffect(()=>{let w=c.current;if(w&&u)return document.body.style.userSelect="none",w.addEventListener("pointermove",B,{passive:false}),w.addEventListener("pointerup",D),w.addEventListener("pointercancel",D),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",B),w.removeEventListener("pointerup",D),w.removeEventListener("pointercancel",D);}},[u,B,D]),jsxRuntime.jsxs("div",{className:g("relative flex flex-col",a?"h-full w-full":"min-h-28 w-full",t),ref:i,style:{cursor:u?"grabbing":"grab"},children:[r?jsxRuntime.jsxs("div",{className:g("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",a?"bottom-4 left-4":"bottom-2 left-2"),children:[jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d>=o,onClick:E,title:"Zoom in",type:"button",children:jsxRuntime.jsx(De,{size:16})}),jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d<=n,onClick:R,title:"Zoom out",type:"button",children:jsxRuntime.jsx(He,{size:16})}),jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:S,title:"Reset zoom and pan",type:"button",children:jsxRuntime.jsx(Ie,{size:16})})]}):null,jsxRuntime.jsx("div",{className:g("flex-1 origin-center transition-transform duration-150 ease-out",a?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:z,ref:c,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var Je=({chart:e,className:t,config:n,fullscreen:o=false,showControls:s=true})=>{let[r,l]=react.useState(null),[a,i]=react.useState(false),[c,d]=react.useState(""),[m,p]=react.useState(""),[f,u]=react.useState(0),{mermaid:h,cdnUrl:y}=react.useContext(T),k=h==null?void 0:h.errorComponent,{shouldRender:L,containerRef:C}=Ne({immediate:o});if(react.useEffect(()=>{if(!L)return;(async()=>{try{l(null),i(!0);let R=await te(n,y),S=e.split("").reduce((B,D)=>(B<<5)-B+D.charCodeAt(0)|0,0),j=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:z}=await R.render(j,e);d(z),p(z);}catch(R){if(!(m||c)){let S=R instanceof Error?R.message:"Failed to render Mermaid chart";l(S);}}finally{i(false);}})();},[e,n,f,L,y]),!(L||c||m))return jsxRuntime.jsx("div",{className:g("my-4 min-h-[200px]",t),ref:C});if(a&&!c&&!m)return jsxRuntime.jsx("div",{className:g("my-4 flex justify-center p-4",t),ref:C,children:jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsxRuntime.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsxRuntime.jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!c&&!m){let E=()=>u(R=>R+1);return k?jsxRuntime.jsx("div",{ref:C,children:jsxRuntime.jsx(k,{chart:e,error:r,retry:E})}):jsxRuntime.jsxs("div",{className:g("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:C,children:[jsxRuntime.jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),jsxRuntime.jsxs("details",{className:"mt-2",children:[jsxRuntime.jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsxRuntime.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let M=c||m;return jsxRuntime.jsx("div",{className:"size-full",ref:C,children:jsxRuntime.jsx(eo,{className:g(o?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:o,maxZoom:3,minZoom:.5,showControls:s,zoomStep:.1,children:jsxRuntime.jsx("div",{"aria-label":"Mermaid chart",className:g("flex justify-center",o?"size-full items-center":null),dangerouslySetInnerHTML:{__html:M},role:"img"})})})};
|
|
11
|
-
exports.a=g;exports.b=po;exports.c=F;exports.d=Je;exports.e=Ft;exports.f=Cn;exports.g=Pe;exports.h=Vn;exports.i=On;exports.j=T;exports.k=Kt;exports.l=Kn;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
'use strict';var chunkDQKJR6WP_cjs=require('./chunk-DQKJR6WP.cjs'),react=require('react'),jsxRuntime=require('react/jsx-runtime'),core=require('shiki/core'),javascript=require('shiki/engine/javascript'),q=require('shiki/themes/github-dark.mjs'),Q=require('shiki/themes/github-light.mjs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var q__default=/*#__PURE__*/_interopDefault(q);var Q__default=/*#__PURE__*/_interopDefault(Q);var _=chunkDQKJR6WP_cjs.a("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"),M=react.memo(({children:e,result:t,language:o,className:l,...i})=>{let n=react.useMemo(()=>({backgroundColor:t.bg,color:t.fg}),[t.bg,t.fg]);return jsxRuntime.jsx("pre",{className:chunkDQKJR6WP_cjs.a(l,"p-4 text-sm dark:bg-(--shiki-dark-bg)!"),"data-language":o,"data-streamdown":"code-block-body",style:n,...i,children:jsxRuntime.jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:t.tokens.map((r,a)=>jsxRuntime.jsx("span",{className:_,children:r.map((g,s)=>jsxRuntime.jsx("span",{className:"dark:bg-(--shiki-dark-bg)! dark:text-(--shiki-dark)!",style:{color:g.color,backgroundColor:g.bgColor,...g.htmlStyle},...g.htmlAttrs,children:g.content},s))},a))})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className);var v=({className:e,language:t,style:o,...l})=>jsxRuntime.jsx("div",{className:chunkDQKJR6WP_cjs.a("my-4 w-full overflow-hidden rounded-xl border border-border",e),"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...l});var D=({language:e,children:t})=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":e,"data-streamdown":"code-block-header",children:[jsxRuntime.jsx("span",{className:"ml-1 font-mono lowercase",children:e}),jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:t})]});var p={"github-light":Q__default.default,"github-dark":q__default.default},O=e=>e in p;var W=chunkDQKJR6WP_cjs.c.dependencies.shiki.replace(/^\^/,""),K=5e3,A=e=>`${e}/shiki/${W}`,f=new Map,C=new Map,w=new Set,I=new Set,J=/JSON\.parse\(("(?:[^"\\]|\\.)*")\)/,y=/import\s+\w+\s+from\s+['"]\.\/([\w-]+)\.mjs['"]/g,T=new Set;async function X(e,t,o){let l=`${t}/${e}.mjs`,i=new AbortController,n=setTimeout(()=>i.abort(),o),r=await fetch(l,{signal:i.signal});if(clearTimeout(n),!r.ok)throw new Error(`HTTP ${r.status}: ${r.statusText}`);let a=await r.text(),g=[],s=y.exec(a);for(;s!==null;)g.push(s[1]),s=y.exec(a);y.lastIndex=0;let d=a.match(J);if(!d)throw new Error("Could not find JSON.parse() in CDN response");let c=JSON.parse(d[1]);return {grammar:JSON.parse(c),dependencies:g}}async function R(e,t,o=K){if(t==null)return null;let i=`${A(t)}/langs`,n=`${i}/${e}`;if(f.has(n))return f.get(n);if(w.has(n)||T.has(n))return null;try{T.add(n);let r=await X(e,i,o);if(!r)throw new Error("Failed to load language");let{grammar:a,dependencies:g}=r,s=[];for(let d of g){let c=`${i}/${d}`;if(f.has(c)){let k=f.get(c);s.push(...k);continue}if(T.has(c)||w.has(c))continue;let m=await R(d,t,o);m&&s.push(...m);}return s.push(a),f.set(n,[a]),s}catch(r){w.add(n);let a=r instanceof Error?r.message:"Unknown error";return console.warn(`[Streamdown] Failed to load language "${e}" from CDN: ${a}`),null}finally{T.delete(n);}}async function j(e,t,o=K){if(t==null)return null;let i=`${A(t)}/themes`,n=`${i}/${e}`;if(C.has(n))return C.get(n);if(I.has(n))return null;try{let r=`${i}/${e}.mjs`,a=new AbortController,g=setTimeout(()=>a.abort(),o),s=await fetch(r,{signal:a.signal});if(clearTimeout(g),!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);let d=await s.text();try{let c=d.match(J);if(!c)throw new Error("Could not find JSON.parse() in CDN response");let m=JSON.parse(c[1]),k=JSON.parse(m);return C.set(n,k),k}catch(c){throw new Error(`Failed to parse theme: ${c instanceof Error?c.message:"Unknown error"}`)}}catch(r){I.add(n);let a=r instanceof Error?r.message:"Unknown error";return console.warn(`[Streamdown] Failed to load theme "${e}" from CDN: ${a}`),null}}var ee=javascript.createJavaScriptRegexEngine({forgiving:true}),B=new Map,x=new Map,u=new Map,te=(e,t)=>`${e}-${t[0]}-${t[1]}`,ne=(e,t,o)=>{let l=e.slice(0,100),i=e.length>100?e.slice(-100):"";return `${t}:${o[0]}:${o[1]}:${e.length}:${l}:${i}`};async function oe(e,t){if(O(e))return p[e];let o=await j(e,t);return o||(console.warn(`[Streamdown] Theme "${e}" not found. Falling back to ${e.includes("dark")?"github-dark":"github-light"}.`),e.includes("dark")?p["github-dark"]:p["github-light"])}async function re(e,t){if(chunkDQKJR6WP_cjs.f(e))return chunkDQKJR6WP_cjs.e[e];let o=await R(e,t);return o||console.warn(`[Streamdown] Language "${e}" not found in bundled languages or CDN. Falling back to plain text.`),o}var se=(e,t,o)=>{let l=te(e,t);if(B.has(l))return B.get(l);let i=(async()=>{let n=await re(e,o),r=n?[n]:["text"],a=await Promise.all(t.map(s=>oe(s,o)));return await core.createHighlighterCore({themes:a,langs:r,engine:ee})})();return B.set(l,i),i},L=({code:e,language:t,shikiTheme:o,cdnUrl:l,callback:i})=>{let n=ne(e,t,o);return x.has(n)?x.get(n):(i&&(u.has(n)||u.set(n,new Set),u.get(n).add(i)),se(t,o,l).then(r=>{let g=r.getLoadedLanguages().includes(t)?t:"text",s=r.codeToTokens(e,{lang:g,themes:{light:o[0],dark:o[1]}});x.set(n,s);let d=u.get(n);if(d){for(let c of d)c(s);u.delete(n);}}).catch(r=>{console.error("Failed to highlight code:",r),u.delete(n);}),null)};var Ie=({code:e,language:t,className:o,children:l,...i})=>{let{shikiTheme:n,cdnUrl:r}=react.useContext(chunkDQKJR6WP_cjs.j),a=react.useMemo(()=>({bg:"transparent",fg:"inherit",tokens:e.split(`
|
|
3
|
-
`).map(d=>[{content:d,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[e]),[g,s]=react.useState(a);return react.useEffect(()=>{let d=L({code:e,language:t,shikiTheme:n,cdnUrl:r});if(d){s(d);return}s(a),L({code:e,language:t,shikiTheme:n,cdnUrl:r,callback:c=>{s(c);}});},[e,t,n,r,a]),jsxRuntime.jsx(chunkDQKJR6WP_cjs.b.Provider,{value:{code:e},children:jsxRuntime.jsxs(v,{language:t,children:[jsxRuntime.jsx(D,{language:t,children:l}),jsxRuntime.jsx(M,{className:o,language:t,result:g,...i})]})})};exports.CodeBlock=Ie;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {a,c,j as j$1,b,f as f$1,e}from'./chunk-4VFFRCJP.js';import {memo,useMemo,useContext,useState,useEffect}from'react';import {jsx,jsxs}from'react/jsx-runtime';import {createHighlighterCore}from'shiki/core';import {createJavaScriptRegexEngine}from'shiki/engine/javascript';import q from'shiki/themes/github-dark.mjs';import Q from'shiki/themes/github-light.mjs';var _=a("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"),M=memo(({children:e,result:t,language:o,className:l,...i})=>{let n=useMemo(()=>({backgroundColor:t.bg,color:t.fg}),[t.bg,t.fg]);return jsx("pre",{className:a(l,"p-4 text-sm dark:bg-(--shiki-dark-bg)!"),"data-language":o,"data-streamdown":"code-block-body",style:n,...i,children:jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:t.tokens.map((r,a)=>jsx("span",{className:_,children:r.map((g,s)=>jsx("span",{className:"dark:bg-(--shiki-dark-bg)! dark:text-(--shiki-dark)!",style:{color:g.color,backgroundColor:g.bgColor,...g.htmlStyle},...g.htmlAttrs,children:g.content},s))},a))})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className);var v=({className:e,language:t,style:o,...l})=>jsx("div",{className:a("my-4 w-full overflow-hidden rounded-xl border border-border",e),"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...l});var D=({language:e,children:t})=>jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":e,"data-streamdown":"code-block-header",children:[jsx("span",{className:"ml-1 font-mono lowercase",children:e}),jsx("div",{className:"flex items-center gap-2",children:t})]});var p={"github-light":Q,"github-dark":q},O=e=>e in p;var W=c.dependencies.shiki.replace(/^\^/,""),K=5e3,A=e=>`${e}/shiki/${W}`,f=new Map,C=new Map,w=new Set,I=new Set,J=/JSON\.parse\(("(?:[^"\\]|\\.)*")\)/,y=/import\s+\w+\s+from\s+['"]\.\/([\w-]+)\.mjs['"]/g,T=new Set;async function X(e,t,o){let l=`${t}/${e}.mjs`,i=new AbortController,n=setTimeout(()=>i.abort(),o),r=await fetch(l,{signal:i.signal});if(clearTimeout(n),!r.ok)throw new Error(`HTTP ${r.status}: ${r.statusText}`);let a=await r.text(),g=[],s=y.exec(a);for(;s!==null;)g.push(s[1]),s=y.exec(a);y.lastIndex=0;let d=a.match(J);if(!d)throw new Error("Could not find JSON.parse() in CDN response");let c=JSON.parse(d[1]);return {grammar:JSON.parse(c),dependencies:g}}async function R(e,t,o=K){if(t==null)return null;let i=`${A(t)}/langs`,n=`${i}/${e}`;if(f.has(n))return f.get(n);if(w.has(n)||T.has(n))return null;try{T.add(n);let r=await X(e,i,o);if(!r)throw new Error("Failed to load language");let{grammar:a,dependencies:g}=r,s=[];for(let d of g){let c=`${i}/${d}`;if(f.has(c)){let k=f.get(c);s.push(...k);continue}if(T.has(c)||w.has(c))continue;let m=await R(d,t,o);m&&s.push(...m);}return s.push(a),f.set(n,[a]),s}catch(r){w.add(n);let a=r instanceof Error?r.message:"Unknown error";return console.warn(`[Streamdown] Failed to load language "${e}" from CDN: ${a}`),null}finally{T.delete(n);}}async function j(e,t,o=K){if(t==null)return null;let i=`${A(t)}/themes`,n=`${i}/${e}`;if(C.has(n))return C.get(n);if(I.has(n))return null;try{let r=`${i}/${e}.mjs`,a=new AbortController,g=setTimeout(()=>a.abort(),o),s=await fetch(r,{signal:a.signal});if(clearTimeout(g),!s.ok)throw new Error(`HTTP ${s.status}: ${s.statusText}`);let d=await s.text();try{let c=d.match(J);if(!c)throw new Error("Could not find JSON.parse() in CDN response");let m=JSON.parse(c[1]),k=JSON.parse(m);return C.set(n,k),k}catch(c){throw new Error(`Failed to parse theme: ${c instanceof Error?c.message:"Unknown error"}`)}}catch(r){I.add(n);let a=r instanceof Error?r.message:"Unknown error";return console.warn(`[Streamdown] Failed to load theme "${e}" from CDN: ${a}`),null}}var ee=createJavaScriptRegexEngine({forgiving:true}),B=new Map,x=new Map,u=new Map,te=(e,t)=>`${e}-${t[0]}-${t[1]}`,ne=(e,t,o)=>{let l=e.slice(0,100),i=e.length>100?e.slice(-100):"";return `${t}:${o[0]}:${o[1]}:${e.length}:${l}:${i}`};async function oe(e,t){if(O(e))return p[e];let o=await j(e,t);return o||(console.warn(`[Streamdown] Theme "${e}" not found. Falling back to ${e.includes("dark")?"github-dark":"github-light"}.`),e.includes("dark")?p["github-dark"]:p["github-light"])}async function re(e$1,t){if(f$1(e$1))return e[e$1];let o=await R(e$1,t);return o||console.warn(`[Streamdown] Language "${e$1}" not found in bundled languages or CDN. Falling back to plain text.`),o}var se=(e,t,o)=>{let l=te(e,t);if(B.has(l))return B.get(l);let i=(async()=>{let n=await re(e,o),r=n?[n]:["text"],a=await Promise.all(t.map(s=>oe(s,o)));return await createHighlighterCore({themes:a,langs:r,engine:ee})})();return B.set(l,i),i},L=({code:e,language:t,shikiTheme:o,cdnUrl:l,callback:i})=>{let n=ne(e,t,o);return x.has(n)?x.get(n):(i&&(u.has(n)||u.set(n,new Set),u.get(n).add(i)),se(t,o,l).then(r=>{let g=r.getLoadedLanguages().includes(t)?t:"text",s=r.codeToTokens(e,{lang:g,themes:{light:o[0],dark:o[1]}});x.set(n,s);let d=u.get(n);if(d){for(let c of d)c(s);u.delete(n);}}).catch(r=>{console.error("Failed to highlight code:",r),u.delete(n);}),null)};var Ie=({code:e,language:t,className:o,children:l,...i})=>{let{shikiTheme:n,cdnUrl:r}=useContext(j$1),a=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:e.split(`
|
|
3
|
-
`).map(d=>[{content:d,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[e]),[g,s]=useState(a);return useEffect(()=>{let d=L({code:e,language:t,shikiTheme:n,cdnUrl:r});if(d){s(d);return}s(a),L({code:e,language:t,shikiTheme:n,cdnUrl:r,callback:c=>{s(c);}});},[e,t,n,r,a]),jsx(b.Provider,{value:{code:e},children:jsxs(v,{language:t,children:[jsx(D,{language:t,children:l}),jsx(M,{className:o,language:t,result:g,...i})]})})};export{Ie as CodeBlock};
|
package/dist/mermaid-INZBJW3V.js
DELETED