streamdown 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,7 +19,7 @@ Streamdown powers the [AI Elements Response](https://ai-sdk.dev/elements/compone
19
19
  - 🔢 **Math rendering** - LaTeX equations via KaTeX
20
20
  - 📈 **Mermaid diagrams** - Render Mermaid diagrams as code blocks with a button to render them
21
21
  - 🎯 **Code syntax highlighting** - Beautiful code blocks with Shiki
22
- - 🛡️ **Security-first** - Built on harden-react-markdown for safe rendering
22
+ - 🛡️ **Security-first** - Built with rehype-harden for safe rendering
23
23
  - ⚡ **Performance optimized** - Memoized rendering for efficient updates
24
24
 
25
25
  ## Installation
@@ -56,6 +56,7 @@ Streamdown supports Mermaid diagrams using the `mermaid` language identifier:
56
56
 
57
57
  ```tsx
58
58
  import { Streamdown } from 'streamdown';
59
+ import type { MermaidConfig } from 'mermaid';
59
60
 
60
61
  export default function Page() {
61
62
  const markdown = `
@@ -84,7 +85,20 @@ sequenceDiagram
84
85
  \`\`\`
85
86
  `;
86
87
 
87
- return <Streamdown>{markdown}</Streamdown>;
88
+ // Optional: Customize Mermaid theme and colors
89
+ const mermaidConfig: MermaidConfig = {
90
+ theme: 'dark',
91
+ themeVariables: {
92
+ primaryColor: '#ff0000',
93
+ primaryTextColor: '#fff'
94
+ }
95
+ };
96
+
97
+ return (
98
+ <Streamdown mermaidConfig={mermaidConfig}>
99
+ {markdown}
100
+ </Streamdown>
101
+ );
88
102
  }
89
103
  ```
90
104
 
@@ -106,7 +120,7 @@ export default function Page() {
106
120
  {messages.map(message => (
107
121
  <div key={message.id}>
108
122
  {message.parts.filter(part => part.type === 'text').map((part, index) => (
109
- <Streamdown key={index}>{part.text}</Streamdown>
123
+ <Streamdown isAnimating={status === 'streaming'} key={index}>{part.text}</Streamdown>
110
124
  ))}
111
125
  </div>
112
126
  ))}
@@ -135,6 +149,51 @@ export default function Page() {
135
149
  }
136
150
  ```
137
151
 
152
+ ### Customizing Plugins
153
+
154
+ When you need to override the default plugins (e.g., to configure security settings), you can import the default plugin configurations and selectively modify them:
155
+
156
+ ```tsx
157
+ import { Streamdown, defaultRehypePlugins } from 'streamdown';
158
+ import { harden } from 'rehype-harden';
159
+
160
+ export default function Page() {
161
+ const markdown = `
162
+ [Safe link](https://example.com)
163
+ [Unsafe link](https://malicious-site.com)
164
+ `;
165
+
166
+ return (
167
+ <Streamdown
168
+ rehypePlugins={[
169
+ defaultRehypePlugins.raw,
170
+ defaultRehypePlugins.katex,
171
+ [
172
+ harden,
173
+ {
174
+ defaultOrigin: 'https://example.com',
175
+ allowedLinkPrefixes: ['https://example.com'],
176
+ },
177
+ ],
178
+ ]}
179
+ >
180
+ {markdown}
181
+ </Streamdown>
182
+ );
183
+ }
184
+ ```
185
+
186
+ The `defaultRehypePlugins` and `defaultRemarkPlugins` exports provide access to:
187
+
188
+ **defaultRehypePlugins:**
189
+ - `harden` - Security hardening with rehype-harden (configured with wildcard permissions by default)
190
+ - `raw` - HTML support
191
+ - `katex` - Math rendering with KaTeX
192
+
193
+ **defaultRemarkPlugins:**
194
+ - `gfm` - GitHub Flavored Markdown support
195
+ - `math` - Math syntax support
196
+
138
197
  ## Props
139
198
 
140
199
  Streamdown accepts all the same props as react-markdown, plus additional streaming-specific options:
@@ -145,12 +204,12 @@ Streamdown accepts all the same props as react-markdown, plus additional streami
145
204
  | `parseIncompleteMarkdown` | `boolean` | `true` | Parse and style unterminated Markdown blocks |
146
205
  | `className` | `string` | - | CSS class for the container |
147
206
  | `components` | `object` | - | Custom component overrides |
148
- | `remarkPlugins` | `array` | `[remarkGfm, remarkMath]` | Remark plugins to use |
149
- | `rehypePlugins` | `array` | `[rehypeKatex]` | Rehype plugins to use |
150
- | `allowedImagePrefixes` | `array` | `['*']` | Allowed image URL prefixes |
151
- | `allowedLinkPrefixes` | `array` | `['*']` | Allowed link URL prefixes |
152
- | `defaultOrigin` | `string` | - | Default origin to use for relative URLs in links and images |
153
- | `shikiTheme` | `BundledTheme` (from Shiki) | `github-light` | The theme to use for code blocks |
207
+ | `rehypePlugins` | `array` | `[[harden, { allowedImagePrefixes: ["*"], allowedLinkPrefixes: ["*"], defaultOrigin: undefined }], rehypeRaw, [rehypeKatex, { errorColor: "var(--color-muted-foreground)" }]]` | Rehype plugins to use. Includes rehype-harden for security, rehype-raw for HTML support, and rehype-katex for math rendering by default |
208
+ | `remarkPlugins` | `array` | `[[remarkGfm, {}], [remarkMath, { singleDollarTextMath: false }]]` | Remark plugins to use. Includes GitHub Flavored Markdown and math support by default |
209
+ | `shikiTheme` | `[BundledTheme, BundledTheme]` | `['github-light', 'github-dark']` | The light and dark themes to use for code blocks |
210
+ | `mermaidConfig` | `MermaidConfig` | - | Custom configuration for Mermaid diagrams (theme, colors, etc.) |
211
+ | `controls` | `boolean \| { table?: boolean, code?: boolean, mermaid?: boolean }` | `true` | Control visibility of copy/download buttons |
212
+ | `isAnimating` | `boolean` | `false` | Whether the component is currently animating. This is used to disable the copy and download buttons when the component is animating. |
154
213
 
155
214
  ## Architecture
156
215
 
package/dist/index.cjs CHANGED
@@ -1,15 +1,15 @@
1
- "use strict";"use client";var he=Object.create;var S=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var ye=(e,t)=>{for(var s in t)S(e,s,{get:t[s],enumerable:!0})},U=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ke(t))!ve.call(e,n)&&n!==s&&S(e,n,{get:()=>t[n],enumerable:!(r=be(t,n))||r.enumerable});return e};var I=(e,t,s)=>(s=e!=null?he(we(e)):{},U(t||!e||!e.__esModule?S(s,"default",{value:e,enumerable:!0}):s,e)),Te=e=>U(S({},"__esModule",{value:!0}),e);var et={};ye(et,{ShikiThemeContext:()=>H,Streamdown:()=>fe});module.exports=Te(et);var y=require("react"),de=I(require("react-markdown"),1),me=I(require("rehype-katex"),1),ue=I(require("remark-gfm"),1),pe=I(require("remark-math"),1),vt=require("katex/dist/katex.min.css"),E=I(require("harden-react-markdown"),1);var oe=require("react");var P=require("lucide-react"),b=require("react"),q=require("shiki"),K=require("shiki/engine/javascript");var W=require("clsx"),G=require("tailwind-merge"),c=(...e)=>(0,G.twMerge)((0,W.clsx)(e)),N=(e,t,s)=>{let r=typeof t=="string"?new Blob([t],{type:s}):t,n=URL.createObjectURL(r),o=document.createElement("a");o.href=n,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(n)};var k=require("react/jsx-runtime"),Ce=/<pre(\s|>)/,_=(0,b.createContext)({code:""}),A=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}async ensureHighlightersInitialized(t,s){var u,m;let[r,n]=t,o=(0,K.createJavaScriptRegexEngine)({forgiving:!0}),a=!this.lightHighlighter||this.lightTheme!==r,l=!this.darkHighlighter||this.darkTheme!==n;(a||l)&&this.loadedLanguages.clear();let i=!this.loadedLanguages.has(s);if(a?(this.lightHighlighter=await(0,q.createHighlighter)({themes:[r],langs:[s],engine:o}),this.lightTheme=r,this.loadedLanguages.add(s)):i&&await((u=this.lightHighlighter)==null?void 0:u.loadLanguage(s)),l){let f=i?[...this.loadedLanguages,s]:Array.from(this.loadedLanguages);this.darkHighlighter=await(0,q.createHighlighter)({themes:[n],langs:f.length>0?f:[s],engine:o}),this.darkTheme=n}else i&&await((m=this.darkHighlighter)==null?void 0:m.loadLanguage(s));i&&this.loadedLanguages.add(s)}async highlightCode(t,s,r,n){var m,f;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(r,s),await this.initializationPromise,this.initializationPromise=null;let o=p=>n?p.replace(Ce,`<pre class="${n}"$1`):p,[a,l]=r,i=(m=this.lightHighlighter)==null?void 0:m.codeToHtml(t,{lang:s,theme:a}),u=(f=this.darkHighlighter)==null?void 0:f.codeToHtml(t,{lang:s,theme:l});return[V(o(i)),V(o(u))]}},Me=new A,V=e=>e.replace(/(<pre[^>]*)(style="[^"]*background[^";]*;?[^"]*")([^>]*>)/g,"$1$3"),X=({code:e,language:t,className:s,children:r,preClassName:n,...o})=>{let[a,l]=(0,b.useState)(""),[i,u]=(0,b.useState)(""),m=(0,b.useRef)(!1),[f,p]=(0,b.useContext)(H);return(0,b.useEffect)(()=>(m.current=!0,Me.highlightCode(e,t,[f,p],n).then(([g,h])=>{m.current&&(l(g),u(h))}),()=>{m.current=!1}),[e,t,f,p,n]),(0,k.jsx)(_.Provider,{value:{code:e},children:(0,k.jsxs)("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[(0,k.jsxs)("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-code-block-header":!0,"data-language":t,children:[(0,k.jsx)("span",{className:"ml-1 font-mono lowercase",children:t}),(0,k.jsx)("div",{className:"flex items-center gap-2",children:r})]}),(0,k.jsx)("div",{className:"w-full",children:(0,k.jsxs)("div",{className:"min-w-full",children:[(0,k.jsx)("div",{className:c("overflow-x-auto dark:hidden",s),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...o}),(0,k.jsx)("div",{className:c("hidden overflow-x-auto dark:block",s),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...o})]})})]})})},F={"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"},O=({onDownload:e,onError:t,language:s,children:r,className:n,code:o,...a})=>{let l=(0,b.useContext)(_).code,i=o!=null?o:l,m=`file.${s&&s in F?F[s]:"txt"}`,f="text/plain",p=()=>{try{N(m,i,f),e==null||e()}catch(g){t==null||t(g)}};return(0,k.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,title:"Download file",type:"button",...a,children:r!=null?r:(0,k.jsx)(P.DownloadIcon,{size:14})})},z=({onCopy:e,onError:t,timeout:s=2e3,children:r,className:n,code:o,...a})=>{let[l,i]=(0,b.useState)(!1),u=(0,b.useRef)(0),m=(0,b.useContext)(_).code,f=o!=null?o:m,p=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{l||(await navigator.clipboard.writeText(f),i(!0),e==null||e(),u.current=window.setTimeout(()=>i(!1),s))}catch(v){t==null||t(v)}};(0,b.useEffect)(()=>()=>{window.clearTimeout(u.current)},[]);let g=l?P.CheckIcon:P.CopyIcon;return(0,k.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,type:"button",...a,children:r!=null?r:(0,k.jsx)(g,{size:14})})};var J=require("lucide-react");var $=require("react/jsx-runtime"),Q=({node:e,className:t,src:s,alt:r,...n})=>{let o=async()=>{var a;if(s)try{let i=await(await fetch(s)).blob(),m=new URL(s,window.location.origin).pathname.split("/").pop()||"",f=m.includes(".")&&((a=m.split(".").pop())==null?void 0:a.length)<=4,p="";if(f)p=m;else{let g=i.type,h="png";g.includes("jpeg")||g.includes("jpg")?h="jpg":g.includes("png")?h="png":g.includes("svg")?h="svg":g.includes("gif")?h="gif":g.includes("webp")&&(h="webp"),p=`${(r||m||"image").replace(/\.[^/.]+$/,"")}.${h}`}N(p,i,i.type)}catch(l){console.error("Failed to download image:",l)}};return s?(0,$.jsxs)("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[(0,$.jsx)("img",{alt:r,className:c("max-w-full rounded-lg",t),"data-streamdown":"image",src:s,...n}),(0,$.jsx)("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),(0,$.jsx)("button",{className:c("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:o,title:"Download image",type:"button",children:(0,$.jsx)(J.DownloadIcon,{size:14})})]}):null};var x=require("react");var w=require("react/jsx-runtime"),Y=!1,Be=async()=>{if(!Y){let s=(await import("mermaid")).default;return s.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),Y=!0,s}return(await import("mermaid")).default},Z=({chart:e,className:t})=>{let[s,r]=(0,x.useState)(null),[n,o]=(0,x.useState)(!0),[a,l]=(0,x.useState)(""),[i,u]=(0,x.useState)("");if((0,x.useEffect)(()=>{(async()=>{try{r(null),o(!0);let p=await Be(),g=e.split("").reduce((M,B)=>(M<<5)-M+B.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:v}=await p.render(h,e);l(v),u(v)}catch(p){if(!(i||a)){let g=p instanceof Error?p.message:"Failed to render Mermaid chart";r(g)}}finally{o(!1)}})()},[e]),n&&!a&&!i)return(0,w.jsx)("div",{className:c("my-4 flex justify-center p-4",t),children:(0,w.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,w.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,w.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!a&&!i)return(0,w.jsxs)("div",{className:c("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,w.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),(0,w.jsxs)("details",{className:"mt-2",children:[(0,w.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,w.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let m=a||i;return(0,w.jsx)("div",{"aria-label":"Mermaid chart",className:c("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:m},role:"img"})};var L=require("lucide-react"),C=require("react");var T=require("react/jsx-runtime");function ee(e){var o,a;let t=[],s=[],r=e.querySelectorAll("thead th");for(let l of r)t.push(((o=l.textContent)==null?void 0:o.trim())||"");let n=e.querySelectorAll("tbody tr");for(let l of n){let i=[],u=l.querySelectorAll("td");for(let m of u)i.push(((a=m.textContent)==null?void 0:a.trim())||"");s.push(i)}return{headers:t,rows:s}}function R(e){let{headers:t,rows:s}=e,r=o=>o.includes(",")||o.includes('"')||o.includes(`
2
- `)?`"${o.replace(/"/g,'""')}"`:o,n=[];t.length>0&&n.push(t.map(r).join(","));for(let o of s)n.push(o.map(r).join(","));return n.join(`
3
- `)}function te(e){let{headers:t,rows:s}=e;if(t.length===0)return"";let r=[],n=t.map(o=>o.replace(/\|/g,"\\|"));r.push(`| ${n.join(" | ")} |`),r.push(`| ${t.map(()=>"---").join(" | ")} |`);for(let o of s){let a=[...o];for(;a.length<t.length;)a.push("");let l=a.map(i=>i.replace(/\|/g,"\\|"));r.push(`| ${l.join(" | ")} |`)}return r.join(`
4
- `)}var se=({children:e,className:t,onCopy:s,onError:r,timeout:n=2e3,format:o="markdown"})=>{let[a,l]=(0,C.useState)(!1),i=(0,C.useRef)(0),u=async f=>{var p;if(typeof window=="undefined"||!((p=navigator==null?void 0:navigator.clipboard)!=null&&p.writeText)){r==null||r(new Error("Clipboard API not available"));return}try{if(!a){let h=f.currentTarget.closest('[data-streamdown="table-wrapper"]'),v=h==null?void 0:h.querySelector("table");if(!v){r==null||r(new Error("Table not found"));return}let M=ee(v),B="";switch(o){case"csv":B=R(M);break;case"markdown":B=te(M);break;case"text":B=R(M).replace(/,/g," ");break;default:B=R(M)}await navigator.clipboard.writeText(B),l(!0),s==null||s(),i.current=window.setTimeout(()=>l(!1),n)}}catch(g){r==null||r(g)}};(0,C.useEffect)(()=>()=>{window.clearTimeout(i.current)},[]);let m=a?L.CheckIcon:L.CopyIcon;return(0,T.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:u,title:`Copy table as ${o}`,type:"button",children:e!=null?e:(0,T.jsx)(m,{size:14})})};var re=({children:e,className:t,onDownload:s,onError:r})=>{let[n,o]=(0,C.useState)(!1),a=(0,C.useRef)(null),l=i=>{var u;try{let m=(u=a.current)==null?void 0:u.closest('[data-streamdown="table-wrapper"]'),f=m==null?void 0:m.querySelector("table");if(!f){r==null||r(new Error("Table not found"));return}let p=ee(f),g=i==="csv"?R(p):te(p);N(`table.${i==="csv"?"csv":"md"}`,g,i==="csv"?"text/csv":"text/markdown"),o(!1),s==null||s(i)}catch(m){r==null||r(m)}};return(0,C.useEffect)(()=>{let i=u=>{a.current&&!a.current.contains(u.target)&&o(!1)};return document.addEventListener("mousedown",i),()=>{document.removeEventListener("mousedown",i)}},[]),(0,T.jsxs)("div",{className:"relative",ref:a,children:[(0,T.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:()=>o(!n),title:"Download table",type:"button",children:e!=null?e:(0,T.jsx)(L.DownloadIcon,{size:14})}),n&&(0,T.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] rounded-md border border-border bg-white shadow-lg",children:[(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("csv"),type:"button",children:"CSV"}),(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("markdown"),type:"button",children:"Markdown"})]})]})};var d=require("react/jsx-runtime"),Ie=/language-([^\s]+)/,$e=({node:e,className:t,children:s,...r})=>{var i,u,m;if(((i=e==null?void 0:e.position)==null?void 0:i.start.line)===((u=e==null?void 0:e.position)==null?void 0:u.end.line))return(0,d.jsx)("code",{className:c("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...r,children:s});let o=t==null?void 0:t.match(Ie),a=(m=o==null?void 0:o.at(1))!=null?m:"",l="";return(0,oe.isValidElement)(s)&&s.props&&typeof s.props=="object"&&"children"in s.props&&typeof s.props.children=="string"?l=s.props.children:typeof s=="string"&&(l=s),a==="mermaid"?(0,d.jsxs)("div",{className:c("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[(0,d.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,d.jsx)(O,{code:l,language:a}),(0,d.jsx)(z,{code:l})]}),(0,d.jsx)(Z,{chart:l})]}):(0,d.jsxs)(X,{className:c("overflow-x-auto border-t",t),code:l,"data-language":a,"data-streamdown":"code-block",language:a,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:[(0,d.jsx)(O,{code:l,language:a}),(0,d.jsx)(z,{})]})},ne={ol:({node:e,children:t,className:s,...r})=>(0,d.jsx)("ol",{className:c("ml-4 list-outside list-decimal whitespace-normal",s),"data-streamdown":"ordered-list",...r,children:t}),li:({node:e,children:t,className:s,...r})=>(0,d.jsx)("li",{className:c("py-1",s),"data-streamdown":"list-item",...r,children:t}),ul:({node:e,children:t,className:s,...r})=>(0,d.jsx)("ul",{className:c("ml-4 list-outside list-disc whitespace-normal",s),"data-streamdown":"unordered-list",...r,children:t}),hr:({node:e,className:t,...s})=>(0,d.jsx)("hr",{className:c("my-6 border-border",t),"data-streamdown":"horizontal-rule",...s}),strong:({node:e,children:t,className:s,...r})=>(0,d.jsx)("span",{className:c("font-semibold",s),"data-streamdown":"strong",...r,children:t}),a:({node:e,children:t,className:s,href:r,...n})=>{let o=r==="streamdown:incomplete-link";return(0,d.jsx)("a",{className:c("font-medium text-primary underline",s),"data-incomplete":o,"data-streamdown":"link",href:r,rel:"noreferrer",target:"_blank",...n,children:t})},h1:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h1",{className:c("mt-6 mb-2 font-semibold text-3xl",s),"data-streamdown":"heading-1",...r,children:t}),h2:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h2",{className:c("mt-6 mb-2 font-semibold text-2xl",s),"data-streamdown":"heading-2",...r,children:t}),h3:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h3",{className:c("mt-6 mb-2 font-semibold text-xl",s),"data-streamdown":"heading-3",...r,children:t}),h4:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h4",{className:c("mt-6 mb-2 font-semibold text-lg",s),"data-streamdown":"heading-4",...r,children:t}),h5:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h5",{className:c("mt-6 mb-2 font-semibold text-base",s),"data-streamdown":"heading-5",...r,children:t}),h6:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h6",{className:c("mt-6 mb-2 font-semibold text-sm",s),"data-streamdown":"heading-6",...r,children:t}),table:({node:e,children:t,className:s,...r})=>(0,d.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[(0,d.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,d.jsx)(se,{}),(0,d.jsx)(re,{})]}),(0,d.jsx)("div",{className:"overflow-x-auto",children:(0,d.jsx)("table",{className:c("w-full border-collapse border border-border",s),"data-streamdown":"table",...r,children:t})})]}),thead:({node:e,children:t,className:s,...r})=>(0,d.jsx)("thead",{className:c("bg-muted/80",s),"data-streamdown":"table-header",...r,children:t}),tbody:({node:e,children:t,className:s,...r})=>(0,d.jsx)("tbody",{className:c("divide-y divide-border bg-muted/40",s),"data-streamdown":"table-body",...r,children:t}),tr:({node:e,children:t,className:s,...r})=>(0,d.jsx)("tr",{className:c("border-border border-b",s),"data-streamdown":"table-row",...r,children:t}),th:({node:e,children:t,className:s,...r})=>(0,d.jsx)("th",{className:c("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",s),"data-streamdown":"table-header-cell",...r,children:t}),td:({node:e,children:t,className:s,...r})=>(0,d.jsx)("td",{className:c("px-4 py-2 text-sm",s),"data-streamdown":"table-cell",...r,children:t}),blockquote:({node:e,children:t,className:s,...r})=>(0,d.jsx)("blockquote",{className:c("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",s),"data-streamdown":"blockquote",...r,children:t}),code:$e,img:Q,pre:({children:e})=>e,sup:({node:e,children:t,className:s,...r})=>(0,d.jsx)("sup",{className:c("text-sm",s),"data-streamdown":"superscript",...r,children:t}),sub:({node:e,children:t,className:s,...r})=>(0,d.jsx)("sub",{className:c("text-sm",s),"data-streamdown":"subscript",...r,children:t})};var ae=require("marked"),ie=e=>{let s=ae.marked.use({gfm:!0}).lexer(e).map(n=>n.raw),r=[];for(let n=0;n<s.length;n++){let o=s[n];if(o.trim()==="$$"&&r.length>0){let a=r.at(-1),l=a.trimStart().startsWith("$$"),i=(a.match(/\$\$/g)||[]).length;if(l&&i%2===1){r[r.length-1]=a+o;continue}}if(r.length>0&&o.trimEnd().endsWith("$$")){let a=r.at(-1),l=a.trimStart().startsWith("$$"),i=(a.match(/\$\$/g)||[]).length,u=(o.match(/\$\$/g)||[]).length;if(l&&i%2===1&&!o.trimStart().startsWith("$$")&&u===1){r[r.length-1]=a+o;continue}}r.push(o)}return r};var xe=/(!?\[)([^\]]*?)$/,Ne=/(\*\*)([^*]*?)$/,Pe=/(__)([^_]*?)$/,Le=/(\*\*\*)([^*]*?)$/,je=/(\*)([^*]*?)$/,Se=/(_)([^_]*?)$/,He=/(`)([^`]*?)$/,Re=/(~~)([^~]*?)$/,D=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
5
- `)},De=e=>{let t=e.match(xe);if(t){if(t[1].startsWith("!")){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return`${e}](streamdown:incomplete-link)`}return e},qe=e=>{if(D(e))return e;let t=e.match(Ne);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;let r=e.lastIndexOf(t[1]),o=e.substring(0,r).lastIndexOf(`
6
- `),a=o===-1?0:o+1,l=e.substring(a,r);if(/^[\s]*[-*+][\s]+$/.test(l)&&s.includes(`
7
- `))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},Ae=e=>{let t=e.match(Pe);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;let r=e.lastIndexOf(t[1]),o=e.substring(0,r).lastIndexOf(`
8
- `),a=o===-1?0:o+1,l=e.substring(a,r);if(/^[\s]*[-*+][\s]+$/.test(l)&&s.includes(`
9
- `))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},_e=e=>e.split("").reduce((t,s,r)=>{if(s==="*"){let n=e[r-1],o=e[r+1];if(n==="\\")return t;let a=r;for(let i=r-1;i>=0;i--){if(e[i]===`
10
- `){a=i+1;break}if(i===0){a=0;break}}if(e.substring(a,r).trim()===""&&(o===" "||o===" "))return t;if(n!=="*"&&o!=="*")return t+1}return t},0),Oe=e=>{if(D(e))return e;if(e.match(je)){let s=-1;for(let o=0;o<e.length;o++)if(e[o]==="*"&&e[o-1]!=="*"&&e[o+1]!=="*"){s=o;break}if(s===-1)return e;let r=e.substring(s+1);if(!r||/^[\s_~*`]*$/.test(r))return e;if(_e(e)%2===1)return`${e}*`}return e},le=(e,t)=>{let s=!1,r=!1;for(let n=0;n<e.length&&n<t;n++){if(e[n]==="\\"&&e[n+1]==="$"){n++;continue}e[n]==="$"&&(e[n+1]==="$"?(r=!r,n++,s=!1):r||(s=!s))}return s||r},ze=e=>e.split("").reduce((t,s,r)=>{if(s==="_"){let n=e[r-1],o=e[r+1];if(n==="\\"||le(e,r))return t;if(n!=="_"&&o!=="_")return t+1}return t},0),Ee=e=>{if(D(e))return e;if(e.match(Se)){let s=-1;for(let o=0;o<e.length;o++)if(e[o]==="_"&&e[o-1]!=="_"&&e[o+1]!=="_"&&!le(e,o)){s=o;break}if(s===-1)return e;let r=e.substring(s+1);if(!r||/^[\s_~*`]*$/.test(r))return e;if(ze(e)%2===1)return`${e}_`}return e},Ue=(e,t)=>{let s=e.substring(t,t+3)==="```",r=t>0&&e.substring(t-1,t+2)==="```",n=t>1&&e.substring(t-2,t+1)==="```";return s||r||n},We=e=>{let t=0;for(let s=0;s<e.length;s++)e[s]==="`"&&!Ue(e,s)&&t++;return t},Ge=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
11
- `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let s=(e.match(/```/g)||[]).length,r=s%2===1;if(s>0&&s%2===0&&e.includes(`
12
- `)||(e.endsWith("```\n")||e.endsWith("```"))&&s%2===0)return e;let n=e.match(He);if(n&&!r){let o=n[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if(We(e)%2===1)return`${e}\``}return e},Ve=e=>{let t=e.match(Re);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e};var Fe=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let s=e.indexOf("$$");return s!==-1&&e.indexOf(`
13
- `,s)!==-1&&!e.endsWith(`
1
+ "use strict";"use client";var Ge=Object.create;var q=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var Ye=Object.getPrototypeOf,Ze=Object.prototype.hasOwnProperty;var et=(e,t)=>{for(var o in t)q(e,o,{get:t[o],enumerable:!0})},K=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Qe(t))!Ze.call(e,r)&&r!==o&&q(e,r,{get:()=>t[r],enumerable:!(n=Ke(t,r))||n.enumerable});return e};var x=(e,t,o)=>(o=e!=null?Ge(Ye(e)):{},K(t||!e||!e.__esModule?q(o,"default",{value:e,enumerable:!0}):o,e)),tt=e=>K(q({},"__esModule",{value:!0}),e);var Lt={};et(Lt,{ControlsContext:()=>D,MermaidConfigContext:()=>O,ShikiThemeContext:()=>E,Streamdown:()=>Ve,StreamdownRuntimeContext:()=>I,defaultRehypePlugins:()=>Xe,defaultRemarkPlugins:()=>Je});module.exports=tt(Lt);var M=require("react"),Ee=x(require("react-markdown"),1),_e=x(require("rehype-katex"),1),Oe=x(require("rehype-raw"),1),We=x(require("remark-gfm"),1),Ue=x(require("remark-math"),1),Qt=require("katex/dist/katex.min.css"),ze=require("rehype-harden");var g=require("react");var A=require("lucide-react"),y=require("react"),R=require("shiki"),ee=require("shiki/engine/javascript");var Q=require("clsx"),Y=require("tailwind-merge"),p=(...e)=>(0,Y.twMerge)((0,Q.clsx)(e)),H=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r)};var w=require("react/jsx-runtime"),ot=/<pre(\s|>)/,X=(0,y.createContext)({code:""}),z=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}isLanguageSupported(t){return Object.hasOwn(R.bundledLanguages,t)}getFallbackLanguage(){return"text"}async ensureHighlightersInitialized(t,o){var c,u;let[n,r]=t,s=(0,ee.createJavaScriptRegexEngine)({forgiving:!0}),i=!this.lightHighlighter||this.lightTheme!==n,d=!this.darkHighlighter||this.darkTheme!==r;(i||d)&&this.loadedLanguages.clear();let a=this.isLanguageSupported(o),l=!this.loadedLanguages.has(o)&&a;if(i?(this.lightHighlighter=await(0,R.createHighlighter)({themes:[n],langs:a?[o]:[],engine:s}),this.lightTheme=n,a&&this.loadedLanguages.add(o)):l&&await((c=this.lightHighlighter)==null?void 0:c.loadLanguage(o)),d){let b=l?[...this.loadedLanguages].concat(a?[o]:[]):Array.from(this.loadedLanguages);this.darkHighlighter=await(0,R.createHighlighter)({themes:[r],langs:b.length>0?b:a?[o]:[],engine:s}),this.darkTheme=r}else l&&await((u=this.darkHighlighter)==null?void 0:u.loadLanguage(o));l&&this.loadedLanguages.add(o)}async highlightCode(t,o,n,r){var u,b;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(n,o),await this.initializationPromise,this.initializationPromise=null;let[s,i]=n,d=this.isLanguageSupported(o)?o:this.getFallbackLanguage(),a=(u=this.lightHighlighter)==null?void 0:u.codeToHtml(t,{lang:d,theme:s}),l=(b=this.darkHighlighter)==null?void 0:b.codeToHtml(t,{lang:d,theme:i}),c=f=>r?f.replace(ot,`<pre class="${r}"$1`):f;return[c(a),c(l)]}},nt=new z,te=({code:e,language:t,className:o,children:n,preClassName:r,...s})=>{let[i,d]=(0,y.useState)(""),[a,l]=(0,y.useState)(""),c=(0,y.useRef)(!1),[u,b]=(0,y.useContext)(E);return(0,y.useEffect)(()=>(c.current=!0,nt.highlightCode(e,t,[u,b],r).then(([f,h])=>{c.current&&(d(f),l(h))}),()=>{c.current=!1}),[e,t,u,b,r]),(0,w.jsx)(X.Provider,{value:{code:e},children:(0,w.jsxs)("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[(0,w.jsxs)("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-code-block-header":!0,"data-language":t,children:[(0,w.jsx)("span",{className:"ml-1 font-mono lowercase",children:t}),(0,w.jsx)("div",{className:"flex items-center gap-2",children:n})]}),(0,w.jsx)("div",{className:"w-full",children:(0,w.jsxs)("div",{className:"min-w-full",children:[(0,w.jsx)("div",{className:p("overflow-x-auto dark:hidden",o),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...s}),(0,w.jsx)("div",{className:p("hidden overflow-x-auto dark:block",o),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...s})]})})]})})},Z={"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"},J=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...i})=>{let{code:d}=(0,y.useContext)(X),{isAnimating:a}=(0,y.useContext)(I),l=s!=null?s:d,u=`file.${o&&o in Z?Z[o]:"txt"}`,b="text/plain",f=()=>{try{H(u,l,b),e==null||e()}catch(h){t==null||t(h)}};return(0,w.jsx)("button",{className:p("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:a,onClick:f,title:"Download file",type:"button",...i,children:n!=null?n:(0,w.jsx)(A.DownloadIcon,{size:14})})},F=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...i})=>{let[d,a]=(0,y.useState)(!1),l=(0,y.useRef)(0),{code:c}=(0,y.useContext)(X),{isAnimating:u}=(0,y.useContext)(I),b=s!=null?s:c,f=async()=>{var T;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{d||(await navigator.clipboard.writeText(b),a(!0),e==null||e(),l.current=window.setTimeout(()=>a(!1),o))}catch(v){t==null||t(v)}};(0,y.useEffect)(()=>()=>{window.clearTimeout(l.current)},[]);let h=d?A.CheckIcon:A.CopyIcon;return(0,w.jsx)("button",{className:p("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:u,onClick:f,type:"button",...i,children:n!=null?n:(0,w.jsx)(h,{size:14})})};var oe=require("lucide-react");var L=require("react/jsx-runtime"),ne=({node:e,className:t,src:o,alt:n,...r})=>{let s=async()=>{var i;if(o)try{let a=await(await fetch(o)).blob(),c=new URL(o,window.location.origin).pathname.split("/").pop()||"",u=c.includes(".")&&((i=c.split(".").pop())==null?void 0:i.length)<=4,b="";if(u)b=c;else{let f=a.type,h="png";f.includes("jpeg")||f.includes("jpg")?h="jpg":f.includes("png")?h="png":f.includes("svg")?h="svg":f.includes("gif")?h="gif":f.includes("webp")&&(h="webp"),b=`${(n||c||"image").replace(/\.[^/.]+$/,"")}.${h}`}H(b,a,a.type)}catch(d){console.error("Failed to download image:",d)}};return o?(0,L.jsxs)("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[(0,L.jsx)("img",{alt:n,className:p("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...r}),(0,L.jsx)("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),(0,L.jsx)("button",{className:p("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:(0,L.jsx)(oe.DownloadIcon,{size:14})})]}):null};var B=require("react");var C=require("react/jsx-runtime"),st=async e=>{let o={...{startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0},...e},r=(await import("mermaid")).default;return r.initialize(o),r},se=({chart:e,className:t,config:o})=>{let[n,r]=(0,B.useState)(null),[s,i]=(0,B.useState)(!0),[d,a]=(0,B.useState)(""),[l,c]=(0,B.useState)("");if((0,B.useEffect)(()=>{(async()=>{try{r(null),i(!0);let f=await st(o),h=e.split("").reduce(($,U)=>($<<5)-$+U.charCodeAt(0)|0,0),T=`mermaid-${Math.abs(h)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:v}=await f.render(T,e);a(v),c(v)}catch(f){if(!(l||d)){let h=f instanceof Error?f.message:"Failed to render Mermaid chart";r(h)}}finally{i(!1)}})()},[e,o]),s&&!d&&!l)return(0,C.jsx)("div",{className:p("my-4 flex justify-center p-4",t),children:(0,C.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,C.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,C.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(n&&!d&&!l)return(0,C.jsxs)("div",{className:p("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,C.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",n]}),(0,C.jsxs)("details",{className:"mt-2",children:[(0,C.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,C.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let u=d||l;return(0,C.jsx)("div",{"aria-label":"Mermaid chart",className:p("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:u},role:"img"})};var j=require("lucide-react"),P=require("react");var N=require("react/jsx-runtime");function re(e){var s,i;let t=[],o=[],n=e.querySelectorAll("thead th");for(let d of n)t.push(((s=d.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let d of r){let a=[],l=d.querySelectorAll("td");for(let c of l)a.push(((i=c.textContent)==null?void 0:i.trim())||"");o.push(a)}return{headers:t,rows:o}}function ae(e){let{headers:t,rows:o}=e,n=s=>s.includes(",")||s.includes('"')||s.includes(`
2
+ `)?`"${s.replace(/"/g,'""')}"`:s,r=[];t.length>0&&r.push(t.map(n).join(","));for(let s of o)r.push(s.map(n).join(","));return r.join(`
3
+ `)}function ie(e){let{headers:t,rows:o}=e;if(t.length===0)return"";let n=[],r=t.map(s=>s.replace(/\|/g,"\\|"));n.push(`| ${r.join(" | ")} |`),n.push(`| ${t.map(()=>"---").join(" | ")} |`);for(let s of o){let i=[...s];for(;i.length<t.length;)i.push("");let d=i.map(a=>a.replace(/\|/g,"\\|"));n.push(`| ${d.join(" | ")} |`)}return n.join(`
4
+ `)}var le=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3,format:s="markdown"})=>{let[i,d]=(0,P.useState)(!1),a=(0,P.useRef)(0),{isAnimating:l}=(0,P.useContext)(I),c=async b=>{var f;if(typeof window=="undefined"||!((f=navigator==null?void 0:navigator.clipboard)!=null&&f.write)){n==null||n(new Error("Clipboard API not available"));return}try{if(!i){let T=b.currentTarget.closest('[data-streamdown="table-wrapper"]'),v=T==null?void 0:T.querySelector("table");if(!v){n==null||n(new Error("Table not found"));return}let $=re(v),U=new ClipboardItem({"text/plain":s==="markdown"?ie($):ae($),"text/html":new Blob([v.outerHTML],{type:"text/html"})});await navigator.clipboard.write([U]),d(!0),o==null||o(),a.current=window.setTimeout(()=>d(!1),r)}}catch(h){n==null||n(h)}};(0,P.useEffect)(()=>()=>{window.clearTimeout(a.current)},[]);let u=i?j.CheckIcon:j.CopyIcon;return(0,N.jsx)("button",{className:p("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:c,title:`Copy table as ${s}`,type:"button",children:e!=null?e:(0,N.jsx)(u,{size:14})})};var de=({children:e,className:t,onDownload:o,onError:n})=>{let[r,s]=(0,P.useState)(!1),i=(0,P.useRef)(null),{isAnimating:d}=(0,P.useContext)(I),a=l=>{var c;try{let u=(c=i.current)==null?void 0:c.closest('[data-streamdown="table-wrapper"]'),b=u==null?void 0:u.querySelector("table");if(!b){n==null||n(new Error("Table not found"));return}let f=re(b),h=l==="csv"?ae(f):ie(f);H(`table.${l==="csv"?"csv":"md"}`,h,l==="csv"?"text/csv":"text/markdown"),s(!1),o==null||o(l)}catch(u){n==null||n(u)}};return(0,P.useEffect)(()=>{let l=c=>{i.current&&!i.current.contains(c.target)&&s(!1)};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l)}},[]),(0,N.jsxs)("div",{className:"relative",ref:i,children:[(0,N.jsx)("button",{className:p("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:()=>s(!r),title:"Download table",type:"button",children:e!=null?e:(0,N.jsx)(j.DownloadIcon,{size:14})}),r&&(0,N.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] rounded-md border border-border bg-background shadow-lg",children:[(0,N.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>a("csv"),type:"button",children:"CSV"}),(0,N.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>a("markdown"),type:"button",children:"Markdown"})]})]})};var m=require("react/jsx-runtime"),rt=/language-([^\s]+)/;function _(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return!0;if(!(e!=null&&e.position&&(t!=null&&t.position)))return!1;let o=e.position.start,n=t.position.start,r=e.position.end,s=t.position.end;return(o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(r==null?void 0:r.line)===(s==null?void 0:s.line)&&(r==null?void 0:r.column)===(s==null?void 0:s.column)}function k(e,t){return e.className===t.className&&_(e.node,t.node)}var V=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,G=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("ol",{className:p("ml-4 list-outside list-decimal whitespace-normal",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>k(e,t));G.displayName="MarkdownOl";var ce=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("li",{className:p("py-1",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&_(e.node,t.node));ce.displayName="MarkdownLi";var me=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("ul",{className:p("ml-4 list-outside list-disc whitespace-normal",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>k(e,t));me.displayName="MarkdownUl";var pe=(0,g.memo)(({className:e,node:t,...o})=>(0,m.jsx)("hr",{className:p("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>k(e,t));pe.displayName="MarkdownHr";var ue=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("span",{className:p("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>k(e,t));ue.displayName="MarkdownStrong";var ge=(0,g.memo)(({children:e,className:t,href:o,node:n,...r})=>{let s=o==="streamdown:incomplete-link";return(0,m.jsx)("a",{className:p("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...r,children:e})},(e,t)=>k(e,t)&&e.href===t.href);ge.displayName="MarkdownA";var fe=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("h1",{className:p("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>k(e,t));fe.displayName="MarkdownH1";var he=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("h2",{className:p("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>k(e,t));he.displayName="MarkdownH2";var be=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("h3",{className:p("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>k(e,t));be.displayName="MarkdownH3";var ke=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("h4",{className:p("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>k(e,t));ke.displayName="MarkdownH4";var ye=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("h5",{className:p("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>k(e,t));ye.displayName="MarkdownH5";var we=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("h6",{className:p("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>k(e,t));we.displayName="MarkdownH6";var ve=(0,g.memo)(({children:e,className:t,node:o,...n})=>{let r=(0,g.useContext)(D),s=V(r,"table");return(0,m.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[s&&(0,m.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,m.jsx)(le,{}),(0,m.jsx)(de,{})]}),(0,m.jsx)("div",{className:"overflow-x-auto",children:(0,m.jsx)("table",{className:p("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]})},(e,t)=>k(e,t));ve.displayName="MarkdownTable";var Me=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("thead",{className:p("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>k(e,t));Me.displayName="MarkdownThead";var Te=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("tbody",{className:p("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>k(e,t));Te.displayName="MarkdownTbody";var Ce=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("tr",{className:p("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>k(e,t));Ce.displayName="MarkdownTr";var Pe=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("th",{className:p("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>k(e,t));Pe.displayName="MarkdownTh";var Ne=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("td",{className:p("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>k(e,t));Ne.displayName="MarkdownTd";var Ie=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("blockquote",{className:p("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>k(e,t));Ie.displayName="MarkdownBlockquote";var Se=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("sup",{className:p("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>k(e,t));Se.displayName="MarkdownSup";var Le=(0,g.memo)(({children:e,className:t,node:o,...n})=>(0,m.jsx)("sub",{className:p("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>k(e,t));Le.displayName="MarkdownSub";var Be=(0,g.memo)(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=a=>{var b,f;if(!(0,g.isValidElement)(a))return!1;let l=Array.isArray(a.props.children)?a.props.children:[a.props.children],c=!1,u=!1;for(let h of l)if(h){if(typeof h=="string")h.trim()!==""&&(c=!0);else if((0,g.isValidElement)(h))if(((b=h.props)==null?void 0:b["data-footnote-backref"])!==void 0)u=!0;else{let T=Array.isArray(h.props.children)?h.props.children:[h.props.children];for(let v of T){if(typeof v=="string"&&v.trim()!==""){c=!0;break}if((0,g.isValidElement)(v)&&((f=v.props)==null?void 0:f["data-footnote-backref"])===void 0){c=!0;break}}}}return u&&!c},i=Array.isArray(e)?e.map(a=>{if(!(0,g.isValidElement)(a))return a;if(a.type===G){let c=(Array.isArray(a.props.children)?a.props.children:[a.props.children]).filter(u=>!s(u));return c.length===0?null:{...a,props:{...a.props,children:c}}}return a}):e;return(Array.isArray(i)?i.some(a=>a!==null):i!==null)?(0,m.jsx)("section",{className:t,...n,children:i}):null}return(0,m.jsx)("section",{className:t,...n,children:e})},(e,t)=>k(e,t));Be.displayName="MarkdownSection";var at=({node:e,className:t,children:o,...n})=>{var u,b,f;let r=((u=e==null?void 0:e.position)==null?void 0:u.start.line)===((b=e==null?void 0:e.position)==null?void 0:b.end.line),s=(0,g.useContext)(O),i=(0,g.useContext)(D);if(r)return(0,m.jsx)("code",{className:p("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let d=t==null?void 0:t.match(rt),a=(f=d==null?void 0:d.at(1))!=null?f:"",l="";if((0,g.isValidElement)(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?l=o.props.children:typeof o=="string"&&(l=o),a==="mermaid"){let h=V(i,"mermaid");return(0,m.jsxs)("div",{className:p("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[h&&(0,m.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,m.jsx)(J,{code:l,language:a}),(0,m.jsx)(F,{code:l})]}),(0,m.jsx)(se,{chart:l,config:s})]})}let c=V(i,"code");return(0,m.jsx)(te,{className:p("overflow-x-auto border-t",t),code:l,"data-language":a,"data-streamdown":"code-block",language:a,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:c&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(J,{code:l,language:a}),(0,m.jsx)(F,{})]})})},$e=(0,g.memo)(at,(e,t)=>e.className===t.className&&_(e.node,t.node));$e.displayName="MarkdownCode";var xe=(0,g.memo)(ne,(e,t)=>e.className===t.className&&_(e.node,t.node));xe.displayName="MarkdownImg";var He=(0,g.memo)(({children:e,className:t,node:o,...n})=>{var i;let s=(Array.isArray(e)?e:[e]).filter(d=>d!=null&&d!=="");return s.length===1&&(0,g.isValidElement)(s[0])&&((i=s[0].props.node)==null?void 0:i.tagName)==="img"?(0,m.jsx)(m.Fragment,{children:e}):(0,m.jsx)("p",{className:t,...n,children:e})},(e,t)=>k(e,t));He.displayName="MarkdownParagraph";var Ae={ol:G,li:ce,ul:me,hr:pe,strong:ue,a:ge,h1:fe,h2:he,h3:be,h4:ke,h5:ye,h6:we,table:ve,thead:Me,tbody:Te,tr:Ce,th:Pe,td:Ne,blockquote:Ie,code:$e,img:xe,pre:({children:e})=>e,sup:Se,sub:Le,p:He,section:Be};var je=require("marked"),Re=e=>{let t=/\[\^[^\]\s]{1,200}\](?!:)/.test(e),o=/\[\^[^\]\s]{1,200}\]:/.test(e);if(t||o)return[e];let n=je.Lexer.lex(e,{gfm:!0}),r=[],s=[];for(let i=0;i<n.length;i++){let d=n[i],a=d.raw;if(s.length>0){if(r[r.length-1]+=a,d.type==="html"){let l=a.match(/<\/(\w+)>/);if(l){let c=l[1];s[s.length-1]===c&&s.pop()}}continue}if(d.type==="html"&&d.block){let l=a.match(/<(\w+)[\s>]/);if(l){let c=l[1];a.includes(`</${c}>`)||s.push(c)}}if(a.trim()==="$$"&&r.length>0){let l=r.at(-1);if(!l){r.push(a);continue}let c=l.trimStart().startsWith("$$"),u=(l.match(/\$\$/g)||[]).length;if(c&&u%2===1){r[r.length-1]=l+a;continue}}if(r.length>0&&a.trimEnd().endsWith("$$")){let l=r.at(-1);if(!l){r.push(a);continue}let c=l.trimStart().startsWith("$$"),u=(l.match(/\$\$/g)||[]).length,b=(a.match(/\$\$/g)||[]).length;if(c&&u%2===1&&!a.trimStart().startsWith("$$")&&b===1){r[r.length-1]=l+a;continue}}r.push(a)}return r};var it=/(!?\[)([^\]]*?)$/,lt=/(\*\*)([^*]*?)$/,dt=/(__)([^_]*?)$/,ct=/(\*\*\*)([^*]*?)$/,mt=/(\*)([^*]*?)$/,pt=/(_)([^_]*?)$/,ut=/(`)([^`]*?)$/,gt=/(~~)([^~]*?)$/,W=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
5
+ `)},ft=e=>{let t=/(!?)\[([^\]]+)\]\(([^)]+)$/,o=e.match(t);if(o){let r=o[1]==="!",s=o[2],i=o[3],d=e.lastIndexOf(`${r?"!":""}[${s}](${i}`),a=e.substring(0,d);return r?a:`${a}[${s}](streamdown:incomplete-link)`}let n=e.match(it);if(n){if(n[1].startsWith("!")){let s=e.lastIndexOf(n[1]);return e.substring(0,s)}return`${e}](streamdown:incomplete-link)`}return e},ht=e=>{if(W(e))return e;let t=e.match(lt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
6
+ `),i=s===-1?0:s+1,d=e.substring(i,n);if(/^[\s]*[-*+][\s]+$/.test(d)&&o.includes(`
7
+ `))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},bt=e=>{let t=e.match(dt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
8
+ `),i=s===-1?0:s+1,d=e.substring(i,n);if(/^[\s]*[-*+][\s]+$/.test(d)&&o.includes(`
9
+ `))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},kt=e=>e.split("").reduce((t,o,n)=>{if(o==="*"){let r=e[n-1],s=e[n+1];if(r==="\\")return t;let i=n;for(let a=n-1;a>=0;a--){if(e[a]===`
10
+ `){i=a+1;break}if(a===0){i=0;break}}if(e.substring(i,n).trim()===""&&(s===" "||s===" "))return t;if(r!=="*"&&s!=="*")return t+1}return t},0),yt=e=>{if(W(e))return e;if(e.match(mt)){let o=-1;for(let s=0;s<e.length;s++)if(e[s]==="*"&&e[s-1]!=="*"&&e[s+1]!=="*"){o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||/^[\s_~*`]*$/.test(n))return e;if(kt(e)%2===1)return`${e}*`}return e},De=(e,t)=>{let o=!1,n=!1;for(let r=0;r<e.length&&r<t;r++){if(e[r]==="\\"&&e[r+1]==="$"){r++;continue}e[r]==="$"&&(e[r+1]==="$"?(n=!n,r++,o=!1):n||(o=!o))}return o||n},wt=e=>e.split("").reduce((t,o,n)=>{if(o==="_"){let r=e[n-1],s=e[n+1];if(r==="\\"||De(e,n)||r&&s&&/[\p{L}\p{N}_]/u.test(r)&&/[\p{L}\p{N}_]/u.test(s))return t;if(r!=="_"&&s!=="_")return t+1}return t},0),vt=e=>{if(W(e))return e;if(e.match(pt)){let o=-1;for(let s=0;s<e.length;s++)if(e[s]==="_"&&e[s-1]!=="_"&&e[s+1]!=="_"&&e[s-1]!=="\\"&&!De(e,s)){let i=s>0?e[s-1]:"",d=s<e.length-1?e[s+1]:"";if(i&&d&&/[\p{L}\p{N}_]/u.test(i)&&/[\p{L}\p{N}_]/u.test(d))continue;o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||/^[\s_~*`]*$/.test(n))return e;if(wt(e)%2===1){let s=e.match(/\n+$/);return s?`${e.slice(0,-s[0].length)}_${s[0]}`:`${e}_`}}return e},Mt=(e,t)=>{let o=e.substring(t,t+3)==="```",n=t>0&&e.substring(t-1,t+2)==="```",r=t>1&&e.substring(t-2,t+1)==="```";return o||n||r},Tt=e=>{let t=0;for(let o=0;o<e.length;o++)e[o]==="`"&&!Mt(e,o)&&t++;return t},Ct=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
11
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let o=(e.match(/```/g)||[]).length,n=o%2===1;if(o>0&&o%2===0&&e.includes(`
12
+ `)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let r=e.match(ut);if(r&&!n){let s=r[2];if(!s||/^[\s_~*`]*$/.test(s))return e;if(Tt(e)%2===1)return`${e}\``}return e},Pt=e=>{let t=e.match(gt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e};var Nt=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let o=e.indexOf("$$");return o!==-1&&e.indexOf(`
13
+ `,o)!==-1&&!e.endsWith(`
14
14
  `)?`${e}
15
- $$`:`${e}$$`},Ke=e=>{let t=0,s=e.match(/\*+/g)||[];for(let r of s){let n=r.length;n>=3&&(t+=Math.floor(n/3))}return t},Xe=e=>{if(D(e)||/^\*{4,}$/.test(e))return e;let t=e.match(Le);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;if(Ke(e)%2===1)return`${e}***`}return e},ce=e=>{if(!e||typeof e!="string")return e;let t=e,s=De(t);return s.endsWith("](streamdown:incomplete-link)")?s:(t=s,t=Xe(t),t=qe(t),t=Ae(t),t=Oe(t),t=Ee(t),t=Ge(t),t=Ve(t),t=Fe(t),t)};var j=require("react/jsx-runtime"),Je=E.default.default||E.default,Qe=Je(de.default),H=(0,y.createContext)(["github-light","github-dark"]),Ye={singleDollarTextMath:!1},Ze={},ge=(0,y.memo)(({content:e,shouldParseIncompleteMarkdown:t,...s})=>{let r=(0,y.useMemo)(()=>typeof e=="string"&&t?ce(e.trim()):e,[e,t]);return(0,j.jsx)(Qe,{...s,children:r})},(e,t)=>e.content===t.content);ge.displayName="Block";var fe=(0,y.memo)(({children:e,allowedImagePrefixes:t=["*"],allowedLinkPrefixes:s=["*"],defaultOrigin:r,parseIncompleteMarkdown:n=!0,components:o,rehypePlugins:a,remarkPlugins:l,className:i,shikiTheme:u=["github-light","github-dark"],...m})=>{let f=(0,y.useId)(),p=(0,y.useMemo)(()=>ie(typeof e=="string"?e:""),[e]),g=(0,y.useMemo)(()=>()=>(0,me.default)({errorColor:"var(--color-muted-foreground)"}),[]);return(0,j.jsx)(H.Provider,{value:u,children:(0,j.jsx)("div",{className:c("space-y-4",i),...m,children:p.map((h,v)=>(0,j.jsx)(ge,{allowedImagePrefixes:t,allowedLinkPrefixes:s,components:{...ne,...o},content:h,defaultOrigin:r,rehypePlugins:[g,...a!=null?a:[]],remarkPlugins:[[ue.default,Ze],[pe.default,Ye],...l!=null?l:[]],shouldParseIncompleteMarkdown:n},`${f}-block_${v}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);fe.displayName="Streamdown";0&&(module.exports={ShikiThemeContext,Streamdown});
15
+ $$`:`${e}$$`},It=e=>{let t=0,o=e.match(/\*+/g)||[];for(let n of o){let r=n.length;r>=3&&(t+=Math.floor(r/3))}return t},St=e=>{if(W(e)||/^\*{4,}$/.test(e))return e;let t=e.match(ct);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if(It(e)%2===1)return`${e}***`}return e},qe=e=>{if(!e||typeof e!="string")return e;let t=e,o=ft(t);return o.endsWith("](streamdown:incomplete-link)")?o:(t=o,t=St(t),t=ht(t),t=bt(t),t=yt(t),t=vt(t),t=Ct(t),t=Pt(t),t=Nt(t),t)};var S=require("react/jsx-runtime"),Xe={harden:[ze.harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],defaultOrigin:void 0,allowDataImages:!0}],raw:Oe.default,katex:[_e.default,{errorColor:"var(--color-muted-foreground)"}]},Je={gfm:[We.default,{}],math:[Ue.default,{singleDollarTextMath:!1}]},E=(0,M.createContext)(["github-light","github-dark"]),O=(0,M.createContext)(void 0),D=(0,M.createContext)(!0),I=(0,M.createContext)({isAnimating:!1}),Fe=(0,M.memo)(({content:e,shouldParseIncompleteMarkdown:t,...o})=>{let n=(0,M.useMemo)(()=>typeof e=="string"&&t?qe(e.trim()):e,[e,t]);return(0,S.jsx)(Ee.default,{...o,children:n})},(e,t)=>e.content===t.content);Fe.displayName="Block";var Ve=(0,M.memo)(({children:e,parseIncompleteMarkdown:t=!0,components:o,rehypePlugins:n=Object.values(Xe),remarkPlugins:r=Object.values(Je),className:s,shikiTheme:i=["github-light","github-dark"],mermaidConfig:d,controls:a=!0,isAnimating:l=!1,...c})=>{let u=(0,M.useId)(),b=(0,M.useMemo)(()=>Re(typeof e=="string"?e:""),[e]);return(0,S.jsx)(E.Provider,{value:i,children:(0,S.jsx)(O.Provider,{value:d,children:(0,S.jsx)(D.Provider,{value:a,children:(0,S.jsx)(I.Provider,{value:{isAnimating:l},children:(0,S.jsx)("div",{className:p("space-y-4",s),children:b.map((f,h)=>(0,S.jsx)(Fe,{components:{...Ae,...o},content:f,rehypePlugins:n,remarkPlugins:r,shouldParseIncompleteMarkdown:t,...c},`${u}-block-${h}`))})})})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating);Ve.displayName="Streamdown";0&&(module.exports={ControlsContext,MermaidConfigContext,ShikiThemeContext,Streamdown,StreamdownRuntimeContext,defaultRehypePlugins,defaultRemarkPlugins});
package/dist/index.d.cts CHANGED
@@ -2,18 +2,32 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { Options } from 'react-markdown';
4
4
  import { BundledTheme } from 'shiki';
5
+ import { MermaidConfig } from 'mermaid';
6
+ export { MermaidConfig } from 'mermaid';
7
+ import { Pluggable } from 'unified';
5
8
 
6
- type HardenReactMarkdownProps = Options & {
7
- defaultOrigin?: string;
8
- allowedLinkPrefixes?: string[];
9
- allowedImagePrefixes?: string[];
9
+ type ControlsConfig = boolean | {
10
+ table?: boolean;
11
+ code?: boolean;
12
+ mermaid?: boolean;
10
13
  };
11
- type StreamdownProps = HardenReactMarkdownProps & {
14
+ type StreamdownProps = Options & {
12
15
  parseIncompleteMarkdown?: boolean;
13
16
  className?: string;
14
17
  shikiTheme?: [BundledTheme, BundledTheme];
18
+ mermaidConfig?: MermaidConfig;
19
+ controls?: ControlsConfig;
20
+ isAnimating?: boolean;
15
21
  };
22
+ declare const defaultRehypePlugins: Record<string, Pluggable>;
23
+ declare const defaultRemarkPlugins: Record<string, Pluggable>;
16
24
  declare const ShikiThemeContext: react.Context<[BundledTheme, BundledTheme]>;
17
- declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
25
+ declare const MermaidConfigContext: react.Context<MermaidConfig | undefined>;
26
+ declare const ControlsContext: react.Context<ControlsConfig>;
27
+ type StreamdownRuntimeContextType = {
28
+ isAnimating: boolean;
29
+ };
30
+ declare const StreamdownRuntimeContext: react.Context<StreamdownRuntimeContextType>;
31
+ declare const Streamdown: react.MemoExoticComponent<({ children, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaidConfig, controls, isAnimating, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
18
32
 
19
- export { ShikiThemeContext, Streamdown, type StreamdownProps };
33
+ export { type ControlsConfig, ControlsContext, MermaidConfigContext, ShikiThemeContext, Streamdown, type StreamdownProps, StreamdownRuntimeContext, type StreamdownRuntimeContextType, defaultRehypePlugins, defaultRemarkPlugins };
package/dist/index.d.ts CHANGED
@@ -2,18 +2,32 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
3
  import { Options } from 'react-markdown';
4
4
  import { BundledTheme } from 'shiki';
5
+ import { MermaidConfig } from 'mermaid';
6
+ export { MermaidConfig } from 'mermaid';
7
+ import { Pluggable } from 'unified';
5
8
 
6
- type HardenReactMarkdownProps = Options & {
7
- defaultOrigin?: string;
8
- allowedLinkPrefixes?: string[];
9
- allowedImagePrefixes?: string[];
9
+ type ControlsConfig = boolean | {
10
+ table?: boolean;
11
+ code?: boolean;
12
+ mermaid?: boolean;
10
13
  };
11
- type StreamdownProps = HardenReactMarkdownProps & {
14
+ type StreamdownProps = Options & {
12
15
  parseIncompleteMarkdown?: boolean;
13
16
  className?: string;
14
17
  shikiTheme?: [BundledTheme, BundledTheme];
18
+ mermaidConfig?: MermaidConfig;
19
+ controls?: ControlsConfig;
20
+ isAnimating?: boolean;
15
21
  };
22
+ declare const defaultRehypePlugins: Record<string, Pluggable>;
23
+ declare const defaultRemarkPlugins: Record<string, Pluggable>;
16
24
  declare const ShikiThemeContext: react.Context<[BundledTheme, BundledTheme]>;
17
- declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
25
+ declare const MermaidConfigContext: react.Context<MermaidConfig | undefined>;
26
+ declare const ControlsContext: react.Context<ControlsConfig>;
27
+ type StreamdownRuntimeContextType = {
28
+ isAnimating: boolean;
29
+ };
30
+ declare const StreamdownRuntimeContext: react.Context<StreamdownRuntimeContextType>;
31
+ declare const Streamdown: react.MemoExoticComponent<({ children, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaidConfig, controls, isAnimating, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
18
32
 
19
- export { ShikiThemeContext, Streamdown, type StreamdownProps };
33
+ export { type ControlsConfig, ControlsContext, MermaidConfigContext, ShikiThemeContext, Streamdown, type StreamdownProps, StreamdownRuntimeContext, type StreamdownRuntimeContextType, defaultRehypePlugins, defaultRemarkPlugins };
package/dist/index.js CHANGED
@@ -1,15 +1,15 @@
1
- "use client";import{createContext as Ye,memo as le,useId as Ze,useMemo as _}from"react";import et from"react-markdown";import tt from"rehype-katex";import st from"remark-gfm";import rt from"remark-math";import"katex/dist/katex.min.css";import ie from"harden-react-markdown";import{isValidElement as Ie}from"react";import{CheckIcon as ue,CopyIcon as pe,DownloadIcon as ge}from"lucide-react";import{createContext as fe,useContext as H,useEffect as U,useRef as W,useState as j}from"react";import{createHighlighter as O}from"shiki";import{createJavaScriptRegexEngine as he}from"shiki/engine/javascript";import{clsx as de}from"clsx";import{twMerge as me}from"tailwind-merge";var c=(...e)=>me(de(e)),y=(e,t,s)=>{let r=typeof t=="string"?new Blob([t],{type:s}):t,n=URL.createObjectURL(r),o=document.createElement("a");o.href=n,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(n)};import{jsx as k,jsxs as L}from"react/jsx-runtime";var be=/<pre(\s|>)/,R=fe({code:""}),S=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}async ensureHighlightersInitialized(t,s){var m,d;let[r,n]=t,o=he({forgiving:!0}),a=!this.lightHighlighter||this.lightTheme!==r,l=!this.darkHighlighter||this.darkTheme!==n;(a||l)&&this.loadedLanguages.clear();let i=!this.loadedLanguages.has(s);if(a?(this.lightHighlighter=await O({themes:[r],langs:[s],engine:o}),this.lightTheme=r,this.loadedLanguages.add(s)):i&&await((m=this.lightHighlighter)==null?void 0:m.loadLanguage(s)),l){let f=i?[...this.loadedLanguages,s]:Array.from(this.loadedLanguages);this.darkHighlighter=await O({themes:[n],langs:f.length>0?f:[s],engine:o}),this.darkTheme=n}else i&&await((d=this.darkHighlighter)==null?void 0:d.loadLanguage(s));i&&this.loadedLanguages.add(s)}async highlightCode(t,s,r,n){var d,f;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(r,s),await this.initializationPromise,this.initializationPromise=null;let o=p=>n?p.replace(be,`<pre class="${n}"$1`):p,[a,l]=r,i=(d=this.lightHighlighter)==null?void 0:d.codeToHtml(t,{lang:s,theme:a}),m=(f=this.darkHighlighter)==null?void 0:f.codeToHtml(t,{lang:s,theme:l});return[z(o(i)),z(o(m))]}},ke=new S,z=e=>e.replace(/(<pre[^>]*)(style="[^"]*background[^";]*;?[^"]*")([^>]*>)/g,"$1$3"),G=({code:e,language:t,className:s,children:r,preClassName:n,...o})=>{let[a,l]=j(""),[i,m]=j(""),d=W(!1),[f,p]=H(A);return U(()=>(d.current=!0,ke.highlightCode(e,t,[f,p],n).then(([g,h])=>{d.current&&(l(g),m(h))}),()=>{d.current=!1}),[e,t,f,p,n]),k(R.Provider,{value:{code:e},children:L("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[L("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-code-block-header":!0,"data-language":t,children:[k("span",{className:"ml-1 font-mono lowercase",children:t}),k("div",{className:"flex items-center gap-2",children:r})]}),k("div",{className:"w-full",children:L("div",{className:"min-w-full",children:[k("div",{className:c("overflow-x-auto dark:hidden",s),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...o}),k("div",{className:c("hidden overflow-x-auto dark:block",s),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...o})]})})]})})},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"},D=({onDownload:e,onError:t,language:s,children:r,className:n,code:o,...a})=>{let l=H(R).code,i=o!=null?o:l,d=`file.${s&&s in E?E[s]:"txt"}`,f="text/plain",p=()=>{try{y(d,i,f),e==null||e()}catch(g){t==null||t(g)}};return k("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,title:"Download file",type:"button",...a,children:r!=null?r:k(ge,{size:14})})},q=({onCopy:e,onError:t,timeout:s=2e3,children:r,className:n,code:o,...a})=>{let[l,i]=j(!1),m=W(0),d=H(R).code,f=o!=null?o:d,p=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{l||(await navigator.clipboard.writeText(f),i(!0),e==null||e(),m.current=window.setTimeout(()=>i(!1),s))}catch(b){t==null||t(b)}};U(()=>()=>{window.clearTimeout(m.current)},[]);let g=l?ue:pe;return k("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,type:"button",...a,children:r!=null?r:k(g,{size:14})})};import{DownloadIcon as we}from"lucide-react";import{jsx as B,jsxs as ve}from"react/jsx-runtime";var V=({node:e,className:t,src:s,alt:r,...n})=>{let o=async()=>{var a;if(s)try{let i=await(await fetch(s)).blob(),d=new URL(s,window.location.origin).pathname.split("/").pop()||"",f=d.includes(".")&&((a=d.split(".").pop())==null?void 0:a.length)<=4,p="";if(f)p=d;else{let g=i.type,h="png";g.includes("jpeg")||g.includes("jpg")?h="jpg":g.includes("png")?h="png":g.includes("svg")?h="svg":g.includes("gif")?h="gif":g.includes("webp")&&(h="webp"),p=`${(r||d||"image").replace(/\.[^/.]+$/,"")}.${h}`}y(p,i,i.type)}catch(l){console.error("Failed to download image:",l)}};return s?ve("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[B("img",{alt:r,className:c("max-w-full rounded-lg",t),"data-streamdown":"image",src:s,...n}),B("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),B("button",{className:c("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:o,title:"Download image",type:"button",children:B(we,{size:14})})]}):null};import{useEffect as ye,useState as I}from"react";import{jsx as T,jsxs as $}from"react/jsx-runtime";var F=!1,Te=async()=>{if(!F){let s=(await import("mermaid")).default;return s.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),F=!0,s}return(await import("mermaid")).default},K=({chart:e,className:t})=>{let[s,r]=I(null),[n,o]=I(!0),[a,l]=I(""),[i,m]=I("");if(ye(()=>{(async()=>{try{r(null),o(!0);let p=await Te(),g=e.split("").reduce((w,v)=>(w<<5)-w+v.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:b}=await p.render(h,e);l(b),m(b)}catch(p){if(!(i||a)){let g=p instanceof Error?p.message:"Failed to render Mermaid chart";r(g)}}finally{o(!1)}})()},[e]),n&&!a&&!i)return T("div",{className:c("my-4 flex justify-center p-4",t),children:$("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[T("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),T("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!a&&!i)return $("div",{className:c("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[$("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),$("details",{className:"mt-2",children:[T("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),T("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let d=a||i;return T("div",{"aria-label":"Mermaid chart",className:c("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:d},role:"img"})};import{CheckIcon as Ce,CopyIcon as Me,DownloadIcon as Be}from"lucide-react";import{useEffect as J,useRef as Q,useState as Y}from"react";import{jsx as C,jsxs as X}from"react/jsx-runtime";function Z(e){var o,a;let t=[],s=[],r=e.querySelectorAll("thead th");for(let l of r)t.push(((o=l.textContent)==null?void 0:o.trim())||"");let n=e.querySelectorAll("tbody tr");for(let l of n){let i=[],m=l.querySelectorAll("td");for(let d of m)i.push(((a=d.textContent)==null?void 0:a.trim())||"");s.push(i)}return{headers:t,rows:s}}function x(e){let{headers:t,rows:s}=e,r=o=>o.includes(",")||o.includes('"')||o.includes(`
2
- `)?`"${o.replace(/"/g,'""')}"`:o,n=[];t.length>0&&n.push(t.map(r).join(","));for(let o of s)n.push(o.map(r).join(","));return n.join(`
3
- `)}function ee(e){let{headers:t,rows:s}=e;if(t.length===0)return"";let r=[],n=t.map(o=>o.replace(/\|/g,"\\|"));r.push(`| ${n.join(" | ")} |`),r.push(`| ${t.map(()=>"---").join(" | ")} |`);for(let o of s){let a=[...o];for(;a.length<t.length;)a.push("");let l=a.map(i=>i.replace(/\|/g,"\\|"));r.push(`| ${l.join(" | ")} |`)}return r.join(`
4
- `)}var te=({children:e,className:t,onCopy:s,onError:r,timeout:n=2e3,format:o="markdown"})=>{let[a,l]=Y(!1),i=Q(0),m=async f=>{var p;if(typeof window=="undefined"||!((p=navigator==null?void 0:navigator.clipboard)!=null&&p.writeText)){r==null||r(new Error("Clipboard API not available"));return}try{if(!a){let h=f.currentTarget.closest('[data-streamdown="table-wrapper"]'),b=h==null?void 0:h.querySelector("table");if(!b){r==null||r(new Error("Table not found"));return}let w=Z(b),v="";switch(o){case"csv":v=x(w);break;case"markdown":v=ee(w);break;case"text":v=x(w).replace(/,/g," ");break;default:v=x(w)}await navigator.clipboard.writeText(v),l(!0),s==null||s(),i.current=window.setTimeout(()=>l(!1),n)}}catch(g){r==null||r(g)}};J(()=>()=>{window.clearTimeout(i.current)},[]);let d=a?Ce:Me;return C("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:m,title:`Copy table as ${o}`,type:"button",children:e!=null?e:C(d,{size:14})})};var se=({children:e,className:t,onDownload:s,onError:r})=>{let[n,o]=Y(!1),a=Q(null),l=i=>{var m;try{let d=(m=a.current)==null?void 0:m.closest('[data-streamdown="table-wrapper"]'),f=d==null?void 0:d.querySelector("table");if(!f){r==null||r(new Error("Table not found"));return}let p=Z(f),g=i==="csv"?x(p):ee(p);y(`table.${i==="csv"?"csv":"md"}`,g,i==="csv"?"text/csv":"text/markdown"),o(!1),s==null||s(i)}catch(d){r==null||r(d)}};return J(()=>{let i=m=>{a.current&&!a.current.contains(m.target)&&o(!1)};return document.addEventListener("mousedown",i),()=>{document.removeEventListener("mousedown",i)}},[]),X("div",{className:"relative",ref:a,children:[C("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:()=>o(!n),title:"Download table",type:"button",children:e!=null?e:C(Be,{size:14})}),n&&X("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] rounded-md border border-border bg-white shadow-lg",children:[C("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("csv"),type:"button",children:"CSV"}),C("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("markdown"),type:"button",children:"Markdown"})]})]})};import{jsx as u,jsxs as M}from"react/jsx-runtime";var $e=/language-([^\s]+)/,xe=({node:e,className:t,children:s,...r})=>{var i,m,d;if(((i=e==null?void 0:e.position)==null?void 0:i.start.line)===((m=e==null?void 0:e.position)==null?void 0:m.end.line))return u("code",{className:c("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...r,children:s});let o=t==null?void 0:t.match($e),a=(d=o==null?void 0:o.at(1))!=null?d:"",l="";return Ie(s)&&s.props&&typeof s.props=="object"&&"children"in s.props&&typeof s.props.children=="string"?l=s.props.children:typeof s=="string"&&(l=s),a==="mermaid"?M("div",{className:c("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[M("div",{className:"flex items-center justify-end gap-2",children:[u(D,{code:l,language:a}),u(q,{code:l})]}),u(K,{chart:l})]}):M(G,{className:c("overflow-x-auto border-t",t),code:l,"data-language":a,"data-streamdown":"code-block",language:a,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:[u(D,{code:l,language:a}),u(q,{})]})},re={ol:({node:e,children:t,className:s,...r})=>u("ol",{className:c("ml-4 list-outside list-decimal whitespace-normal",s),"data-streamdown":"ordered-list",...r,children:t}),li:({node:e,children:t,className:s,...r})=>u("li",{className:c("py-1",s),"data-streamdown":"list-item",...r,children:t}),ul:({node:e,children:t,className:s,...r})=>u("ul",{className:c("ml-4 list-outside list-disc whitespace-normal",s),"data-streamdown":"unordered-list",...r,children:t}),hr:({node:e,className:t,...s})=>u("hr",{className:c("my-6 border-border",t),"data-streamdown":"horizontal-rule",...s}),strong:({node:e,children:t,className:s,...r})=>u("span",{className:c("font-semibold",s),"data-streamdown":"strong",...r,children:t}),a:({node:e,children:t,className:s,href:r,...n})=>{let o=r==="streamdown:incomplete-link";return u("a",{className:c("font-medium text-primary underline",s),"data-incomplete":o,"data-streamdown":"link",href:r,rel:"noreferrer",target:"_blank",...n,children:t})},h1:({node:e,children:t,className:s,...r})=>u("h1",{className:c("mt-6 mb-2 font-semibold text-3xl",s),"data-streamdown":"heading-1",...r,children:t}),h2:({node:e,children:t,className:s,...r})=>u("h2",{className:c("mt-6 mb-2 font-semibold text-2xl",s),"data-streamdown":"heading-2",...r,children:t}),h3:({node:e,children:t,className:s,...r})=>u("h3",{className:c("mt-6 mb-2 font-semibold text-xl",s),"data-streamdown":"heading-3",...r,children:t}),h4:({node:e,children:t,className:s,...r})=>u("h4",{className:c("mt-6 mb-2 font-semibold text-lg",s),"data-streamdown":"heading-4",...r,children:t}),h5:({node:e,children:t,className:s,...r})=>u("h5",{className:c("mt-6 mb-2 font-semibold text-base",s),"data-streamdown":"heading-5",...r,children:t}),h6:({node:e,children:t,className:s,...r})=>u("h6",{className:c("mt-6 mb-2 font-semibold text-sm",s),"data-streamdown":"heading-6",...r,children:t}),table:({node:e,children:t,className:s,...r})=>M("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[M("div",{className:"flex items-center justify-end gap-1",children:[u(te,{}),u(se,{})]}),u("div",{className:"overflow-x-auto",children:u("table",{className:c("w-full border-collapse border border-border",s),"data-streamdown":"table",...r,children:t})})]}),thead:({node:e,children:t,className:s,...r})=>u("thead",{className:c("bg-muted/80",s),"data-streamdown":"table-header",...r,children:t}),tbody:({node:e,children:t,className:s,...r})=>u("tbody",{className:c("divide-y divide-border bg-muted/40",s),"data-streamdown":"table-body",...r,children:t}),tr:({node:e,children:t,className:s,...r})=>u("tr",{className:c("border-border border-b",s),"data-streamdown":"table-row",...r,children:t}),th:({node:e,children:t,className:s,...r})=>u("th",{className:c("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",s),"data-streamdown":"table-header-cell",...r,children:t}),td:({node:e,children:t,className:s,...r})=>u("td",{className:c("px-4 py-2 text-sm",s),"data-streamdown":"table-cell",...r,children:t}),blockquote:({node:e,children:t,className:s,...r})=>u("blockquote",{className:c("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",s),"data-streamdown":"blockquote",...r,children:t}),code:xe,img:V,pre:({children:e})=>e,sup:({node:e,children:t,className:s,...r})=>u("sup",{className:c("text-sm",s),"data-streamdown":"superscript",...r,children:t}),sub:({node:e,children:t,className:s,...r})=>u("sub",{className:c("text-sm",s),"data-streamdown":"subscript",...r,children:t})};import{marked as Ne}from"marked";var oe=e=>{let s=Ne.use({gfm:!0}).lexer(e).map(n=>n.raw),r=[];for(let n=0;n<s.length;n++){let o=s[n];if(o.trim()==="$$"&&r.length>0){let a=r.at(-1),l=a.trimStart().startsWith("$$"),i=(a.match(/\$\$/g)||[]).length;if(l&&i%2===1){r[r.length-1]=a+o;continue}}if(r.length>0&&o.trimEnd().endsWith("$$")){let a=r.at(-1),l=a.trimStart().startsWith("$$"),i=(a.match(/\$\$/g)||[]).length,m=(o.match(/\$\$/g)||[]).length;if(l&&i%2===1&&!o.trimStart().startsWith("$$")&&m===1){r[r.length-1]=a+o;continue}}r.push(o)}return r};var Pe=/(!?\[)([^\]]*?)$/,Le=/(\*\*)([^*]*?)$/,je=/(__)([^_]*?)$/,Se=/(\*\*\*)([^*]*?)$/,He=/(\*)([^*]*?)$/,Re=/(_)([^_]*?)$/,De=/(`)([^`]*?)$/,qe=/(~~)([^~]*?)$/,N=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
5
- `)},Ae=e=>{let t=e.match(Pe);if(t){if(t[1].startsWith("!")){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return`${e}](streamdown:incomplete-link)`}return e},_e=e=>{if(N(e))return e;let t=e.match(Le);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;let r=e.lastIndexOf(t[1]),o=e.substring(0,r).lastIndexOf(`
6
- `),a=o===-1?0:o+1,l=e.substring(a,r);if(/^[\s]*[-*+][\s]+$/.test(l)&&s.includes(`
7
- `))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},Oe=e=>{let t=e.match(je);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;let r=e.lastIndexOf(t[1]),o=e.substring(0,r).lastIndexOf(`
8
- `),a=o===-1?0:o+1,l=e.substring(a,r);if(/^[\s]*[-*+][\s]+$/.test(l)&&s.includes(`
9
- `))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},ze=e=>e.split("").reduce((t,s,r)=>{if(s==="*"){let n=e[r-1],o=e[r+1];if(n==="\\")return t;let a=r;for(let i=r-1;i>=0;i--){if(e[i]===`
10
- `){a=i+1;break}if(i===0){a=0;break}}if(e.substring(a,r).trim()===""&&(o===" "||o===" "))return t;if(n!=="*"&&o!=="*")return t+1}return t},0),Ee=e=>{if(N(e))return e;if(e.match(He)){let s=-1;for(let o=0;o<e.length;o++)if(e[o]==="*"&&e[o-1]!=="*"&&e[o+1]!=="*"){s=o;break}if(s===-1)return e;let r=e.substring(s+1);if(!r||/^[\s_~*`]*$/.test(r))return e;if(ze(e)%2===1)return`${e}*`}return e},ne=(e,t)=>{let s=!1,r=!1;for(let n=0;n<e.length&&n<t;n++){if(e[n]==="\\"&&e[n+1]==="$"){n++;continue}e[n]==="$"&&(e[n+1]==="$"?(r=!r,n++,s=!1):r||(s=!s))}return s||r},Ue=e=>e.split("").reduce((t,s,r)=>{if(s==="_"){let n=e[r-1],o=e[r+1];if(n==="\\"||ne(e,r))return t;if(n!=="_"&&o!=="_")return t+1}return t},0),We=e=>{if(N(e))return e;if(e.match(Re)){let s=-1;for(let o=0;o<e.length;o++)if(e[o]==="_"&&e[o-1]!=="_"&&e[o+1]!=="_"&&!ne(e,o)){s=o;break}if(s===-1)return e;let r=e.substring(s+1);if(!r||/^[\s_~*`]*$/.test(r))return e;if(Ue(e)%2===1)return`${e}_`}return e},Ge=(e,t)=>{let s=e.substring(t,t+3)==="```",r=t>0&&e.substring(t-1,t+2)==="```",n=t>1&&e.substring(t-2,t+1)==="```";return s||r||n},Ve=e=>{let t=0;for(let s=0;s<e.length;s++)e[s]==="`"&&!Ge(e,s)&&t++;return t},Fe=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
11
- `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let s=(e.match(/```/g)||[]).length,r=s%2===1;if(s>0&&s%2===0&&e.includes(`
12
- `)||(e.endsWith("```\n")||e.endsWith("```"))&&s%2===0)return e;let n=e.match(De);if(n&&!r){let o=n[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if(Ve(e)%2===1)return`${e}\``}return e},Ke=e=>{let t=e.match(qe);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e};var Xe=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let s=e.indexOf("$$");return s!==-1&&e.indexOf(`
13
- `,s)!==-1&&!e.endsWith(`
1
+ "use client";import{createContext as D,memo as We,useId as Ht,useMemo as Ue}from"react";import At from"react-markdown";import jt from"rehype-katex";import Rt from"rehype-raw";import Dt from"remark-gfm";import qt from"remark-math";import"katex/dist/katex.min.css";import{harden as Et}from"rehype-harden";import{isValidElement as S,memo as b,useContext as J}from"react";import{CheckIcon as Fe,CopyIcon as Ve,DownloadIcon as Ge}from"lucide-react";import{createContext as Ke,useContext as L,useEffect as Y,useRef as Z,useState as _}from"react";import{bundledLanguages as Qe,createHighlighter as K}from"shiki";import{createJavaScriptRegexEngine as Ye}from"shiki/engine/javascript";import{clsx as Xe}from"clsx";import{twMerge as Je}from"tailwind-merge";var m=(...e)=>Je(Xe(e)),P=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,r=URL.createObjectURL(n),s=document.createElement("a");s.href=r,s.download=e,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(r)};import{jsx as v,jsxs as E}from"react/jsx-runtime";var Ze=/<pre(\s|>)/,W=Ke({code:""}),O=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}isLanguageSupported(t){return Object.hasOwn(Qe,t)}getFallbackLanguage(){return"text"}async ensureHighlightersInitialized(t,o){var c,p;let[n,r]=t,s=Ye({forgiving:!0}),i=!this.lightHighlighter||this.lightTheme!==n,d=!this.darkHighlighter||this.darkTheme!==r;(i||d)&&this.loadedLanguages.clear();let a=this.isLanguageSupported(o),l=!this.loadedLanguages.has(o)&&a;if(i?(this.lightHighlighter=await K({themes:[n],langs:a?[o]:[],engine:s}),this.lightTheme=n,a&&this.loadedLanguages.add(o)):l&&await((c=this.lightHighlighter)==null?void 0:c.loadLanguage(o)),d){let h=l?[...this.loadedLanguages].concat(a?[o]:[]):Array.from(this.loadedLanguages);this.darkHighlighter=await K({themes:[r],langs:h.length>0?h:a?[o]:[],engine:s}),this.darkTheme=r}else l&&await((p=this.darkHighlighter)==null?void 0:p.loadLanguage(o));l&&this.loadedLanguages.add(o)}async highlightCode(t,o,n,r){var p,h;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(n,o),await this.initializationPromise,this.initializationPromise=null;let[s,i]=n,d=this.isLanguageSupported(o)?o:this.getFallbackLanguage(),a=(p=this.lightHighlighter)==null?void 0:p.codeToHtml(t,{lang:d,theme:s}),l=(h=this.darkHighlighter)==null?void 0:h.codeToHtml(t,{lang:d,theme:i}),c=g=>r?g.replace(Ze,`<pre class="${r}"$1`):g;return[c(a),c(l)]}},et=new O,ee=({code:e,language:t,className:o,children:n,preClassName:r,...s})=>{let[i,d]=_(""),[a,l]=_(""),c=Z(!1),[p,h]=L(X);return Y(()=>(c.current=!0,et.highlightCode(e,t,[p,h],r).then(([g,f])=>{c.current&&(d(g),l(f))}),()=>{c.current=!1}),[e,t,p,h,r]),v(W.Provider,{value:{code:e},children:E("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[E("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-code-block-header":!0,"data-language":t,children:[v("span",{className:"ml-1 font-mono lowercase",children:t}),v("div",{className:"flex items-center gap-2",children:n})]}),v("div",{className:"w-full",children:E("div",{className:"min-w-full",children:[v("div",{className:m("overflow-x-auto dark:hidden",o),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...s}),v("div",{className:m("hidden overflow-x-auto dark:block",o),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...s})]})})]})})},Q={"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"},U=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...i})=>{let{code:d}=L(W),{isAnimating:a}=L(M),l=s!=null?s:d,p=`file.${o&&o in Q?Q[o]:"txt"}`,h="text/plain",g=()=>{try{P(p,l,h),e==null||e()}catch(f){t==null||t(f)}};return v("button",{className:m("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:a,onClick:g,title:"Download file",type:"button",...i,children:n!=null?n:v(Ge,{size:14})})},z=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...i})=>{let[d,a]=_(!1),l=Z(0),{code:c}=L(W),{isAnimating:p}=L(M),h=s!=null?s:c,g=async()=>{var w;if(typeof window=="undefined"||!((w=navigator==null?void 0:navigator.clipboard)!=null&&w.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{d||(await navigator.clipboard.writeText(h),a(!0),e==null||e(),l.current=window.setTimeout(()=>a(!1),o))}catch(y){t==null||t(y)}};Y(()=>()=>{window.clearTimeout(l.current)},[]);let f=d?Fe:Ve;return v("button",{className:m("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:p,onClick:g,type:"button",...i,children:n!=null?n:v(f,{size:14})})};import{DownloadIcon as tt}from"lucide-react";import{jsx as $,jsxs as ot}from"react/jsx-runtime";var te=({node:e,className:t,src:o,alt:n,...r})=>{let s=async()=>{var i;if(o)try{let a=await(await fetch(o)).blob(),c=new URL(o,window.location.origin).pathname.split("/").pop()||"",p=c.includes(".")&&((i=c.split(".").pop())==null?void 0:i.length)<=4,h="";if(p)h=c;else{let g=a.type,f="png";g.includes("jpeg")||g.includes("jpg")?f="jpg":g.includes("png")?f="png":g.includes("svg")?f="svg":g.includes("gif")?f="gif":g.includes("webp")&&(f="webp"),h=`${(n||c||"image").replace(/\.[^/.]+$/,"")}.${f}`}P(h,a,a.type)}catch(d){console.error("Failed to download image:",d)}};return o?ot("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[$("img",{alt:n,className:m("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...r}),$("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),$("button",{className:m("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:$(tt,{size:14})})]}):null};import{useEffect as nt,useState as x}from"react";import{jsx as N,jsxs as H}from"react/jsx-runtime";var st=async e=>{let o={...{startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0},...e},r=(await import("mermaid")).default;return r.initialize(o),r},oe=({chart:e,className:t,config:o})=>{let[n,r]=x(null),[s,i]=x(!0),[d,a]=x(""),[l,c]=x("");if(nt(()=>{(async()=>{try{r(null),i(!0);let g=await st(o),f=e.split("").reduce((C,q)=>(C<<5)-C+q.charCodeAt(0)|0,0),w=`mermaid-${Math.abs(f)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:y}=await g.render(w,e);a(y),c(y)}catch(g){if(!(l||d)){let f=g instanceof Error?g.message:"Failed to render Mermaid chart";r(f)}}finally{i(!1)}})()},[e,o]),s&&!d&&!l)return N("div",{className:m("my-4 flex justify-center p-4",t),children:H("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[N("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),N("span",{className:"text-sm",children:"Loading diagram..."})]})});if(n&&!d&&!l)return H("div",{className:m("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[H("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",n]}),H("details",{className:"mt-2",children:[N("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),N("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let p=d||l;return N("div",{"aria-label":"Mermaid chart",className:m("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:p},role:"img"})};import{CheckIcon as rt,CopyIcon as at,DownloadIcon as it}from"lucide-react";import{useContext as se,useEffect as re,useRef as ae,useState as ie}from"react";import{jsx as I,jsxs as ne}from"react/jsx-runtime";function le(e){var s,i;let t=[],o=[],n=e.querySelectorAll("thead th");for(let d of n)t.push(((s=d.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let d of r){let a=[],l=d.querySelectorAll("td");for(let c of l)a.push(((i=c.textContent)==null?void 0:i.trim())||"");o.push(a)}return{headers:t,rows:o}}function de(e){let{headers:t,rows:o}=e,n=s=>s.includes(",")||s.includes('"')||s.includes(`
2
+ `)?`"${s.replace(/"/g,'""')}"`:s,r=[];t.length>0&&r.push(t.map(n).join(","));for(let s of o)r.push(s.map(n).join(","));return r.join(`
3
+ `)}function ce(e){let{headers:t,rows:o}=e;if(t.length===0)return"";let n=[],r=t.map(s=>s.replace(/\|/g,"\\|"));n.push(`| ${r.join(" | ")} |`),n.push(`| ${t.map(()=>"---").join(" | ")} |`);for(let s of o){let i=[...s];for(;i.length<t.length;)i.push("");let d=i.map(a=>a.replace(/\|/g,"\\|"));n.push(`| ${d.join(" | ")} |`)}return n.join(`
4
+ `)}var me=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3,format:s="markdown"})=>{let[i,d]=ie(!1),a=ae(0),{isAnimating:l}=se(M),c=async h=>{var g;if(typeof window=="undefined"||!((g=navigator==null?void 0:navigator.clipboard)!=null&&g.write)){n==null||n(new Error("Clipboard API not available"));return}try{if(!i){let w=h.currentTarget.closest('[data-streamdown="table-wrapper"]'),y=w==null?void 0:w.querySelector("table");if(!y){n==null||n(new Error("Table not found"));return}let C=le(y),q=new ClipboardItem({"text/plain":s==="markdown"?ce(C):de(C),"text/html":new Blob([y.outerHTML],{type:"text/html"})});await navigator.clipboard.write([q]),d(!0),o==null||o(),a.current=window.setTimeout(()=>d(!1),r)}}catch(f){n==null||n(f)}};re(()=>()=>{window.clearTimeout(a.current)},[]);let p=i?rt:at;return I("button",{className:m("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:l,onClick:c,title:`Copy table as ${s}`,type:"button",children:e!=null?e:I(p,{size:14})})};var pe=({children:e,className:t,onDownload:o,onError:n})=>{let[r,s]=ie(!1),i=ae(null),{isAnimating:d}=se(M),a=l=>{var c;try{let p=(c=i.current)==null?void 0:c.closest('[data-streamdown="table-wrapper"]'),h=p==null?void 0:p.querySelector("table");if(!h){n==null||n(new Error("Table not found"));return}let g=le(h),f=l==="csv"?de(g):ce(g);P(`table.${l==="csv"?"csv":"md"}`,f,l==="csv"?"text/csv":"text/markdown"),s(!1),o==null||o(l)}catch(p){n==null||n(p)}};return re(()=>{let l=c=>{i.current&&!i.current.contains(c.target)&&s(!1)};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l)}},[]),ne("div",{className:"relative",ref:i,children:[I("button",{className:m("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:()=>s(!r),title:"Download table",type:"button",children:e!=null?e:I(it,{size:14})}),r&&ne("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] rounded-md border border-border bg-background shadow-lg",children:[I("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>a("csv"),type:"button",children:"CSV"}),I("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>a("markdown"),type:"button",children:"Markdown"})]})]})};import{Fragment as qe,jsx as u,jsxs as B}from"react/jsx-runtime";var lt=/language-([^\s]+)/;function A(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return!0;if(!(e!=null&&e.position&&(t!=null&&t.position)))return!1;let o=e.position.start,n=t.position.start,r=e.position.end,s=t.position.end;return(o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(r==null?void 0:r.line)===(s==null?void 0:s.line)&&(r==null?void 0:r.column)===(s==null?void 0:s.column)}function k(e,t){return e.className===t.className&&A(e.node,t.node)}var F=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,V=b(({children:e,className:t,node:o,...n})=>u("ol",{className:m("ml-4 list-outside list-decimal whitespace-normal",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>k(e,t));V.displayName="MarkdownOl";var ue=b(({children:e,className:t,node:o,...n})=>u("li",{className:m("py-1",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&A(e.node,t.node));ue.displayName="MarkdownLi";var ge=b(({children:e,className:t,node:o,...n})=>u("ul",{className:m("ml-4 list-outside list-disc whitespace-normal",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>k(e,t));ge.displayName="MarkdownUl";var fe=b(({className:e,node:t,...o})=>u("hr",{className:m("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>k(e,t));fe.displayName="MarkdownHr";var he=b(({children:e,className:t,node:o,...n})=>u("span",{className:m("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>k(e,t));he.displayName="MarkdownStrong";var be=b(({children:e,className:t,href:o,node:n,...r})=>{let s=o==="streamdown:incomplete-link";return u("a",{className:m("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...r,children:e})},(e,t)=>k(e,t)&&e.href===t.href);be.displayName="MarkdownA";var ke=b(({children:e,className:t,node:o,...n})=>u("h1",{className:m("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>k(e,t));ke.displayName="MarkdownH1";var ye=b(({children:e,className:t,node:o,...n})=>u("h2",{className:m("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>k(e,t));ye.displayName="MarkdownH2";var we=b(({children:e,className:t,node:o,...n})=>u("h3",{className:m("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>k(e,t));we.displayName="MarkdownH3";var ve=b(({children:e,className:t,node:o,...n})=>u("h4",{className:m("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>k(e,t));ve.displayName="MarkdownH4";var Me=b(({children:e,className:t,node:o,...n})=>u("h5",{className:m("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>k(e,t));Me.displayName="MarkdownH5";var Te=b(({children:e,className:t,node:o,...n})=>u("h6",{className:m("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>k(e,t));Te.displayName="MarkdownH6";var Ce=b(({children:e,className:t,node:o,...n})=>{let r=J(j),s=F(r,"table");return B("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[s&&B("div",{className:"flex items-center justify-end gap-1",children:[u(me,{}),u(pe,{})]}),u("div",{className:"overflow-x-auto",children:u("table",{className:m("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]})},(e,t)=>k(e,t));Ce.displayName="MarkdownTable";var Pe=b(({children:e,className:t,node:o,...n})=>u("thead",{className:m("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>k(e,t));Pe.displayName="MarkdownThead";var Ne=b(({children:e,className:t,node:o,...n})=>u("tbody",{className:m("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>k(e,t));Ne.displayName="MarkdownTbody";var Ie=b(({children:e,className:t,node:o,...n})=>u("tr",{className:m("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>k(e,t));Ie.displayName="MarkdownTr";var Se=b(({children:e,className:t,node:o,...n})=>u("th",{className:m("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>k(e,t));Se.displayName="MarkdownTh";var Le=b(({children:e,className:t,node:o,...n})=>u("td",{className:m("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>k(e,t));Le.displayName="MarkdownTd";var Be=b(({children:e,className:t,node:o,...n})=>u("blockquote",{className:m("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>k(e,t));Be.displayName="MarkdownBlockquote";var $e=b(({children:e,className:t,node:o,...n})=>u("sup",{className:m("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>k(e,t));$e.displayName="MarkdownSup";var xe=b(({children:e,className:t,node:o,...n})=>u("sub",{className:m("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>k(e,t));xe.displayName="MarkdownSub";var He=b(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=a=>{var h,g;if(!S(a))return!1;let l=Array.isArray(a.props.children)?a.props.children:[a.props.children],c=!1,p=!1;for(let f of l)if(f){if(typeof f=="string")f.trim()!==""&&(c=!0);else if(S(f))if(((h=f.props)==null?void 0:h["data-footnote-backref"])!==void 0)p=!0;else{let w=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let y of w){if(typeof y=="string"&&y.trim()!==""){c=!0;break}if(S(y)&&((g=y.props)==null?void 0:g["data-footnote-backref"])===void 0){c=!0;break}}}}return p&&!c},i=Array.isArray(e)?e.map(a=>{if(!S(a))return a;if(a.type===V){let c=(Array.isArray(a.props.children)?a.props.children:[a.props.children]).filter(p=>!s(p));return c.length===0?null:{...a,props:{...a.props,children:c}}}return a}):e;return(Array.isArray(i)?i.some(a=>a!==null):i!==null)?u("section",{className:t,...n,children:i}):null}return u("section",{className:t,...n,children:e})},(e,t)=>k(e,t));He.displayName="MarkdownSection";var dt=({node:e,className:t,children:o,...n})=>{var p,h,g;let r=((p=e==null?void 0:e.position)==null?void 0:p.start.line)===((h=e==null?void 0:e.position)==null?void 0:h.end.line),s=J(G),i=J(j);if(r)return u("code",{className:m("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let d=t==null?void 0:t.match(lt),a=(g=d==null?void 0:d.at(1))!=null?g:"",l="";if(S(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?l=o.props.children:typeof o=="string"&&(l=o),a==="mermaid"){let f=F(i,"mermaid");return B("div",{className:m("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[f&&B("div",{className:"flex items-center justify-end gap-2",children:[u(U,{code:l,language:a}),u(z,{code:l})]}),u(oe,{chart:l,config:s})]})}let c=F(i,"code");return u(ee,{className:m("overflow-x-auto border-t",t),code:l,"data-language":a,"data-streamdown":"code-block",language:a,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:c&&B(qe,{children:[u(U,{code:l,language:a}),u(z,{})]})})},Ae=b(dt,(e,t)=>e.className===t.className&&A(e.node,t.node));Ae.displayName="MarkdownCode";var je=b(te,(e,t)=>e.className===t.className&&A(e.node,t.node));je.displayName="MarkdownImg";var Re=b(({children:e,className:t,node:o,...n})=>{var i;let s=(Array.isArray(e)?e:[e]).filter(d=>d!=null&&d!=="");return s.length===1&&S(s[0])&&((i=s[0].props.node)==null?void 0:i.tagName)==="img"?u(qe,{children:e}):u("p",{className:t,...n,children:e})},(e,t)=>k(e,t));Re.displayName="MarkdownParagraph";var De={ol:V,li:ue,ul:ge,hr:fe,strong:he,a:be,h1:ke,h2:ye,h3:we,h4:ve,h5:Me,h6:Te,table:Ce,thead:Pe,tbody:Ne,tr:Ie,th:Se,td:Le,blockquote:Be,code:Ae,img:je,pre:({children:e})=>e,sup:$e,sub:xe,p:Re,section:He};import{Lexer as ct}from"marked";var Ee=e=>{let t=/\[\^[^\]\s]{1,200}\](?!:)/.test(e),o=/\[\^[^\]\s]{1,200}\]:/.test(e);if(t||o)return[e];let n=ct.lex(e,{gfm:!0}),r=[],s=[];for(let i=0;i<n.length;i++){let d=n[i],a=d.raw;if(s.length>0){if(r[r.length-1]+=a,d.type==="html"){let l=a.match(/<\/(\w+)>/);if(l){let c=l[1];s[s.length-1]===c&&s.pop()}}continue}if(d.type==="html"&&d.block){let l=a.match(/<(\w+)[\s>]/);if(l){let c=l[1];a.includes(`</${c}>`)||s.push(c)}}if(a.trim()==="$$"&&r.length>0){let l=r.at(-1);if(!l){r.push(a);continue}let c=l.trimStart().startsWith("$$"),p=(l.match(/\$\$/g)||[]).length;if(c&&p%2===1){r[r.length-1]=l+a;continue}}if(r.length>0&&a.trimEnd().endsWith("$$")){let l=r.at(-1);if(!l){r.push(a);continue}let c=l.trimStart().startsWith("$$"),p=(l.match(/\$\$/g)||[]).length,h=(a.match(/\$\$/g)||[]).length;if(c&&p%2===1&&!a.trimStart().startsWith("$$")&&h===1){r[r.length-1]=l+a;continue}}r.push(a)}return r};var mt=/(!?\[)([^\]]*?)$/,pt=/(\*\*)([^*]*?)$/,ut=/(__)([^_]*?)$/,gt=/(\*\*\*)([^*]*?)$/,ft=/(\*)([^*]*?)$/,ht=/(_)([^_]*?)$/,bt=/(`)([^`]*?)$/,kt=/(~~)([^~]*?)$/,R=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
5
+ `)},yt=e=>{let t=/(!?)\[([^\]]+)\]\(([^)]+)$/,o=e.match(t);if(o){let r=o[1]==="!",s=o[2],i=o[3],d=e.lastIndexOf(`${r?"!":""}[${s}](${i}`),a=e.substring(0,d);return r?a:`${a}[${s}](streamdown:incomplete-link)`}let n=e.match(mt);if(n){if(n[1].startsWith("!")){let s=e.lastIndexOf(n[1]);return e.substring(0,s)}return`${e}](streamdown:incomplete-link)`}return e},wt=e=>{if(R(e))return e;let t=e.match(pt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
6
+ `),i=s===-1?0:s+1,d=e.substring(i,n);if(/^[\s]*[-*+][\s]+$/.test(d)&&o.includes(`
7
+ `))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},vt=e=>{let t=e.match(ut);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
8
+ `),i=s===-1?0:s+1,d=e.substring(i,n);if(/^[\s]*[-*+][\s]+$/.test(d)&&o.includes(`
9
+ `))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},Mt=e=>e.split("").reduce((t,o,n)=>{if(o==="*"){let r=e[n-1],s=e[n+1];if(r==="\\")return t;let i=n;for(let a=n-1;a>=0;a--){if(e[a]===`
10
+ `){i=a+1;break}if(a===0){i=0;break}}if(e.substring(i,n).trim()===""&&(s===" "||s===" "))return t;if(r!=="*"&&s!=="*")return t+1}return t},0),Tt=e=>{if(R(e))return e;if(e.match(ft)){let o=-1;for(let s=0;s<e.length;s++)if(e[s]==="*"&&e[s-1]!=="*"&&e[s+1]!=="*"){o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||/^[\s_~*`]*$/.test(n))return e;if(Mt(e)%2===1)return`${e}*`}return e},_e=(e,t)=>{let o=!1,n=!1;for(let r=0;r<e.length&&r<t;r++){if(e[r]==="\\"&&e[r+1]==="$"){r++;continue}e[r]==="$"&&(e[r+1]==="$"?(n=!n,r++,o=!1):n||(o=!o))}return o||n},Ct=e=>e.split("").reduce((t,o,n)=>{if(o==="_"){let r=e[n-1],s=e[n+1];if(r==="\\"||_e(e,n)||r&&s&&/[\p{L}\p{N}_]/u.test(r)&&/[\p{L}\p{N}_]/u.test(s))return t;if(r!=="_"&&s!=="_")return t+1}return t},0),Pt=e=>{if(R(e))return e;if(e.match(ht)){let o=-1;for(let s=0;s<e.length;s++)if(e[s]==="_"&&e[s-1]!=="_"&&e[s+1]!=="_"&&e[s-1]!=="\\"&&!_e(e,s)){let i=s>0?e[s-1]:"",d=s<e.length-1?e[s+1]:"";if(i&&d&&/[\p{L}\p{N}_]/u.test(i)&&/[\p{L}\p{N}_]/u.test(d))continue;o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||/^[\s_~*`]*$/.test(n))return e;if(Ct(e)%2===1){let s=e.match(/\n+$/);return s?`${e.slice(0,-s[0].length)}_${s[0]}`:`${e}_`}}return e},Nt=(e,t)=>{let o=e.substring(t,t+3)==="```",n=t>0&&e.substring(t-1,t+2)==="```",r=t>1&&e.substring(t-2,t+1)==="```";return o||n||r},It=e=>{let t=0;for(let o=0;o<e.length;o++)e[o]==="`"&&!Nt(e,o)&&t++;return t},St=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
11
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let o=(e.match(/```/g)||[]).length,n=o%2===1;if(o>0&&o%2===0&&e.includes(`
12
+ `)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let r=e.match(bt);if(r&&!n){let s=r[2];if(!s||/^[\s_~*`]*$/.test(s))return e;if(It(e)%2===1)return`${e}\``}return e},Lt=e=>{let t=e.match(kt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e};var Bt=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let o=e.indexOf("$$");return o!==-1&&e.indexOf(`
13
+ `,o)!==-1&&!e.endsWith(`
14
14
  `)?`${e}
15
- $$`:`${e}$$`},Je=e=>{let t=0,s=e.match(/\*+/g)||[];for(let r of s){let n=r.length;n>=3&&(t+=Math.floor(n/3))}return t},Qe=e=>{if(N(e)||/^\*{4,}$/.test(e))return e;let t=e.match(Se);if(t){let s=t[2];if(!s||/^[\s_~*`]*$/.test(s))return e;if(Je(e)%2===1)return`${e}***`}return e},ae=e=>{if(!e||typeof e!="string")return e;let t=e,s=Ae(t);return s.endsWith("](streamdown:incomplete-link)")?s:(t=s,t=Qe(t),t=_e(t),t=Oe(t),t=Ee(t),t=We(t),t=Fe(t),t=Ke(t),t=Xe(t),t)};import{jsx as P}from"react/jsx-runtime";var ot=ie.default||ie,nt=ot(et),A=Ye(["github-light","github-dark"]),at={singleDollarTextMath:!1},it={},ce=le(({content:e,shouldParseIncompleteMarkdown:t,...s})=>{let r=_(()=>typeof e=="string"&&t?ae(e.trim()):e,[e,t]);return P(nt,{...s,children:r})},(e,t)=>e.content===t.content);ce.displayName="Block";var lt=le(({children:e,allowedImagePrefixes:t=["*"],allowedLinkPrefixes:s=["*"],defaultOrigin:r,parseIncompleteMarkdown:n=!0,components:o,rehypePlugins:a,remarkPlugins:l,className:i,shikiTheme:m=["github-light","github-dark"],...d})=>{let f=Ze(),p=_(()=>oe(typeof e=="string"?e:""),[e]),g=_(()=>()=>tt({errorColor:"var(--color-muted-foreground)"}),[]);return P(A.Provider,{value:m,children:P("div",{className:c("space-y-4",i),...d,children:p.map((h,b)=>P(ce,{allowedImagePrefixes:t,allowedLinkPrefixes:s,components:{...re,...o},content:h,defaultOrigin:r,rehypePlugins:[g,...a!=null?a:[]],remarkPlugins:[[st,it],[rt,at],...l!=null?l:[]],shouldParseIncompleteMarkdown:n},`${f}-block_${b}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);lt.displayName="Streamdown";export{A as ShikiThemeContext,lt as Streamdown};
15
+ $$`:`${e}$$`},$t=e=>{let t=0,o=e.match(/\*+/g)||[];for(let n of o){let r=n.length;r>=3&&(t+=Math.floor(r/3))}return t},xt=e=>{if(R(e)||/^\*{4,}$/.test(e))return e;let t=e.match(gt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if($t(e)%2===1)return`${e}***`}return e},Oe=e=>{if(!e||typeof e!="string")return e;let t=e,o=yt(t);return o.endsWith("](streamdown:incomplete-link)")?o:(t=o,t=xt(t),t=wt(t),t=vt(t),t=Tt(t),t=Pt(t),t=St(t),t=Lt(t),t=Bt(t),t)};import{jsx as T}from"react/jsx-runtime";var _t={harden:[Et,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],defaultOrigin:void 0,allowDataImages:!0}],raw:Rt,katex:[jt,{errorColor:"var(--color-muted-foreground)"}]},Ot={gfm:[Dt,{}],math:[qt,{singleDollarTextMath:!1}]},X=D(["github-light","github-dark"]),G=D(void 0),j=D(!0),M=D({isAnimating:!1}),ze=We(({content:e,shouldParseIncompleteMarkdown:t,...o})=>{let n=Ue(()=>typeof e=="string"&&t?Oe(e.trim()):e,[e,t]);return T(At,{...o,children:n})},(e,t)=>e.content===t.content);ze.displayName="Block";var Wt=We(({children:e,parseIncompleteMarkdown:t=!0,components:o,rehypePlugins:n=Object.values(_t),remarkPlugins:r=Object.values(Ot),className:s,shikiTheme:i=["github-light","github-dark"],mermaidConfig:d,controls:a=!0,isAnimating:l=!1,...c})=>{let p=Ht(),h=Ue(()=>Ee(typeof e=="string"?e:""),[e]);return T(X.Provider,{value:i,children:T(G.Provider,{value:d,children:T(j.Provider,{value:a,children:T(M.Provider,{value:{isAnimating:l},children:T("div",{className:m("space-y-4",s),children:h.map((g,f)=>T(ze,{components:{...De,...o},content:g,rehypePlugins:n,remarkPlugins:r,shouldParseIncompleteMarkdown:t,...c},`${p}-block-${f}`))})})})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating);Wt.displayName="Streamdown";export{j as ControlsContext,G as MermaidConfigContext,X as ShikiThemeContext,Wt as Streamdown,M as StreamdownRuntimeContext,_t as defaultRehypePlugins,Ot as defaultRemarkPlugins};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamdown",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -36,6 +36,7 @@
36
36
  "react": "^19.1.1",
37
37
  "react-dom": "^19.1.1",
38
38
  "tsup": "^8.5.0",
39
+ "unified": "^11.0.5",
39
40
  "vitest": "^3.2.4"
40
41
  },
41
42
  "peerDependencies": {
@@ -43,13 +44,14 @@
43
44
  },
44
45
  "dependencies": {
45
46
  "clsx": "^2.1.1",
46
- "harden-react-markdown": "^1.0.5",
47
47
  "katex": "^0.16.22",
48
48
  "lucide-react": "^0.542.0",
49
49
  "marked": "^16.2.1",
50
50
  "mermaid": "^11.11.0",
51
51
  "react-markdown": "^10.1.0",
52
+ "rehype-harden": "^1.1.5",
52
53
  "rehype-katex": "^7.0.1",
54
+ "rehype-raw": "^7.0.0",
53
55
  "remark-gfm": "^4.0.1",
54
56
  "remark-math": "^6.0.0",
55
57
  "shiki": "^3.12.2",