streamdown 1.5.1 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -3
- package/dist/index.cjs +19 -15
- package/dist/index.d.cts +37 -11
- package/dist/index.d.ts +37 -11
- package/dist/index.js +19 -15
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ A drop-in replacement for react-markdown, designed for AI-powered streaming.
|
|
|
8
8
|
|
|
9
9
|
Formatting Markdown is easy, but when you tokenize and stream it, new challenges arise. Streamdown is built specifically to handle the unique requirements of streaming Markdown content from AI models, providing seamless formatting even with incomplete or unterminated Markdown blocks.
|
|
10
10
|
|
|
11
|
-
Streamdown powers the [AI Elements
|
|
11
|
+
Streamdown powers the [AI Elements Message](https://ai-sdk.dev/elements/components/message) component but can be installed as a standalone package for your own streaming needs.
|
|
12
12
|
|
|
13
13
|
## Features
|
|
14
14
|
|
|
@@ -41,7 +41,7 @@ Make sure the path matches the location of the `node_modules` folder in your pro
|
|
|
41
41
|
You can use Streamdown in your React application like this:
|
|
42
42
|
|
|
43
43
|
```tsx
|
|
44
|
-
import { Streamdown } from
|
|
44
|
+
import { Streamdown } from "streamdown";
|
|
45
45
|
|
|
46
46
|
export default function Page() {
|
|
47
47
|
const markdown = "# Hello World\n\nThis is **streaming** markdown!";
|
|
@@ -50,4 +50,17 @@ export default function Page() {
|
|
|
50
50
|
}
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
For more info, see the [documentation](https://streamdown.ai/docs).
|
|
53
|
+
For more info, see the [documentation](https://streamdown.ai/docs).
|
|
54
|
+
|
|
55
|
+
## Browser Support
|
|
56
|
+
|
|
57
|
+
Streamdown requires browsers that support [RegExp lookbehind assertions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Lookbehind_assertion). This means:
|
|
58
|
+
|
|
59
|
+
- **Safari 16.5+** (iOS 16.5+, macOS Ventura 13.4+)
|
|
60
|
+
- Chrome 62+
|
|
61
|
+
- Edge 79+
|
|
62
|
+
- Firefox 78+
|
|
63
|
+
|
|
64
|
+
The lookbehind assertion requirement comes from dependencies (particularly Shiki for syntax highlighting and mdast-util-gfm-autolink-literal). Older browsers will crash when attempting to parse these regular expressions.
|
|
65
|
+
|
|
66
|
+
If you need to support older browsers, particularly iOS Safari < 16.5, you may need to implement conditional loading or provide a fallback rendering solution.
|
package/dist/index.cjs
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
"use strict";"use client";var
|
|
2
|
-
`),o=t>=0?e.slice(0,t+1):"",n=t>=0?e.slice(t+1):e;return[o,n]},Lt=e=>e?[{pre(o){return this.addClassToHast(o,e),o}}]:[],ie=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null;this.loadLanguagePromise=null;this.cache=new Map;this.cacheKeys=[];this.MAX_CACHE_SIZE=50;this.highlightQueue=new Map}isLanguageSupported(t){return Object.hasOwn(W.bundledLanguages,t)}getFallbackLanguage(){return"text"}getCacheKey(t,o,n){return`${o}::${n||""}::${t}`}addToCache(t,o){if(this.cache.size>=this.MAX_CACHE_SIZE){let n=this.cacheKeys.shift();n&&this.cache.delete(n)}this.cache.set(t,o),this.cacheKeys.push(t)}needsHighlightersInitialization(t){let[o,n]=t,s=!this.lightHighlighter||this.lightTheme!==o,r=!this.darkHighlighter||this.darkTheme!==n;return[s,r]}async ensureHighlightersInitialized(t,o){let[n,s]=o,[r,i]=t,a=(0,ke.createJavaScriptRegexEngine)({forgiving:!0});this.loadedLanguages.clear(),this.cache.clear(),this.cacheKeys=[],this.highlightQueue.clear(),n&&(this.lightHighlighter=await(0,W.createHighlighter)({themes:[r],langs:[],engine:a}),this.lightTheme=r),s&&(this.darkHighlighter=await(0,W.createHighlighter)({themes:[i],langs:[],engine:a}),this.darkTheme=i)}async loadLanguage(t){var o,n;await((o=this.darkHighlighter)==null?void 0:o.loadLanguage(t)),await((n=this.lightHighlighter)==null?void 0:n.loadLanguage(t)),this.loadedLanguages.add(t)}async initializeHighlighters(t){this.initializationPromise&&await this.initializationPromise;let o=this.needsHighlightersInitialization(t),[n,s]=o;(n||s)&&(this.initializationPromise=this.ensureHighlightersInitialized(t,o),await this.initializationPromise,this.initializationPromise=null)}performHighlights(t,o,n){let s=this.isLanguageSupported(o)?o:this.getFallbackLanguage();if(this.lightHighlighter===null||this.darkHighlighter===null||this.lightTheme===null||this.darkTheme===null)throw new Error("highlightCode must be called after initializeHighlighters.");let r=Lt(n),i=this.lightHighlighter.codeToHtml(t,{lang:s,theme:this.lightTheme,transformers:r}),a=this.darkHighlighter.codeToHtml(t,{lang:s,theme:this.darkTheme,transformers:r});return[i,a]}async highlightCode(t,o,n,s){let r=this.getCacheKey(t,o,n),i=this.cache.get(r);if(i)return this.cacheKeys=this.cacheKeys.filter(d=>d!==r),this.cacheKeys.push(r),i;let a=this.highlightQueue.get(r);if(a)return a;let l=()=>{if(s!=null&&s.aborted)throw new DOMException("Aborted","AbortError")},c=(async()=>{try{await new Promise(w=>setTimeout(w,0)),l(),this.initializationPromise&&await this.initializationPromise,l(),this.loadLanguagePromise&&await this.loadLanguagePromise,l(),!this.loadedLanguages.has(o)&&this.isLanguageSupported(o)&&(this.loadLanguagePromise=this.loadLanguage(o),await this.loadLanguagePromise,this.loadLanguagePromise=null),l();let h=this.performHighlights(t,o,n);return this.addToCache(r,h),h}finally{this.highlightQueue.delete(r)}})();return this.highlightQueue.set(r,c),c}},se=new ie,ve=({code:e,language:t,className:o,children:n,preClassName:s,...r})=>{let[i,a]=(0,b.useState)(""),[l,c]=(0,b.useState)(""),[d,h]=(0,b.useState)(""),[w,f]=(0,b.useState)(""),u=Pt(e),T=(0,b.useRef)(0),k=(0,b.useRef)(!1),y=(0,b.useRef)(null),L=(0,b.useRef)(0),[z,J]=(0,b.useContext)(Q);(0,b.useEffect)(()=>{se.initializeHighlighters([z,J])},[z,J]),(0,b.useEffect)(()=>{k.current=!0,y.current&&y.current.abort(),y.current=new AbortController;let _=y.current.signal;T.current&&clearTimeout(T.current);let[K,U]=St(u),gt=u.split(`
|
|
3
|
-
`).length,{minHighlightInterval:ht,debounceMs:ft}=Nt(gt);if(K&&K!==d){let x=Date.now();x-L.current>ht||!U?(L.current=x,se.highlightCode(K,t,s,_).then(([V,bt])=>{k.current&&!_.aborted&&(0,b.startTransition)(()=>{a(V),c(bt),h(K),f(U)})}).catch(V=>{if(V.name!=="AbortError")throw V})):f(U)}else f(U);return T.current=window.setTimeout(()=>{U&&u!==d&&!_.aborted&&se.highlightCode(u,t,s,_).then(([x,he])=>{k.current&&!_.aborted&&(0,b.startTransition)(()=>{a(x),c(he),h(u),f("")})}).catch(x=>{if(x.name!=="AbortError")throw x})},ft),()=>{var x;k.current=!1,(x=y.current)==null||x.abort()}},[u,t,s]);let D=w?`<span class="line"><span>${It(w)}</span></span>`:"";return(0,P.jsx)(ae.Provider,{value:{code:e},children:(0,P.jsxs)("div",{className:"my-4 w-full overflow-hidden rounded-xl border border-border","data-code-block-container":!0,"data-language":t,children:[(0,P.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,P.jsx)("span",{className:"ml-1 font-mono lowercase",children:t}),(0,P.jsx)("div",{className:"flex items-center gap-2",children:n})]}),(0,P.jsx)("div",{className:"w-full",children:(0,P.jsxs)("div",{className:"min-w-full",children:[(0,P.jsx)("div",{className:p("overflow-x-auto dark:hidden",o),dangerouslySetInnerHTML:{__html:D?i+D:i},"data-code-block":!0,"data-language":t,...r}),(0,P.jsx)("div",{className:p("hidden overflow-x-auto dark:block",o),dangerouslySetInnerHTML:{__html:D?l+D:l},"data-code-block":!0,"data-language":t,...r})]})})]})})},ye={"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"},le=({onDownload:e,onError:t,language:o,children:n,className:s,code:r,...i})=>{let{code:a}=(0,b.useContext)(ae),{isAnimating:l}=(0,b.useContext)(H),c=r!=null?r:a,h=`file.${o&&o in ye?ye[o]:"txt"}`,w="text/plain",f=()=>{try{E(h,c,w),e==null||e()}catch(u){t==null||t(u)}};return(0,P.jsx)("button",{className:p("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:l,onClick:f,title:"Download file",type:"button",...i,children:n!=null?n:(0,P.jsx)(q.DownloadIcon,{size:14})})},ce=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:s,code:r,...i})=>{let[a,l]=(0,b.useState)(!1),c=(0,b.useRef)(0),{code:d}=(0,b.useContext)(ae),{isAnimating:h}=(0,b.useContext)(H),w=r!=null?r:d,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{a||(await navigator.clipboard.writeText(w),l(!0),e==null||e(),c.current=window.setTimeout(()=>l(!1),o))}catch(k){t==null||t(k)}};(0,b.useEffect)(()=>()=>{window.clearTimeout(c.current)},[]);let u=a?q.CheckIcon:q.CopyIcon;return(0,P.jsx)("button",{className:p("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:h,onClick:f,type:"button",...i,children:n!=null?n:(0,P.jsx)(u,{size:14})})};var Te=require("lucide-react");var j=require("react/jsx-runtime"),xt=/\.[^/.]+$/,Ce=({node:e,className:t,src:o,alt:n,...s})=>{let r=async()=>{if(o)try{let a=await(await fetch(o)).blob(),c=new URL(o,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),h=c.includes(".")&&d!==void 0&&d.length<=4,w="";if(h)w=c;else{let f=a.type,u="png";f.includes("jpeg")||f.includes("jpg")?u="jpg":f.includes("png")?u="png":f.includes("svg")?u="svg":f.includes("gif")?u="gif":f.includes("webp")&&(u="webp"),w=`${(n||c||"image").replace(xt,"")}.${u}`}E(w,a,a.type)}catch(i){console.error("Failed to download image:",i)}};return o?(0,j.jsxs)("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[(0,j.jsx)("img",{alt:n,className:p("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...s}),(0,j.jsx)("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),(0,j.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:r,title:"Download image",type:"button",children:(0,j.jsx)(Te.DownloadIcon,{size:14})})]}):null};var Z=require("lucide-react"),S=require("react");var v=require("react/jsx-runtime"),F=0,Ht=()=>{F+=1,F===1&&(document.body.style.overflow="hidden")},Bt=()=>{F=Math.max(0,F-1),F===0&&(document.body.style.overflow="")},At=async e=>{let o={...{startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0},...e},s=(await import("mermaid")).default;return s.initialize(o),s},Me=({chart:e,config:t,onFullscreen:o,onExit:n,className:s,...r})=>{let[i,a]=(0,S.useState)(!1),{isAnimating:l}=(0,S.useContext)(H),c=()=>{a(!i)};return(0,S.useEffect)(()=>{if(i){Ht();let d=h=>{h.key==="Escape"&&a(!1)};return document.addEventListener("keydown",d),()=>{document.removeEventListener("keydown",d),Bt()}}},[i]),(0,S.useEffect)(()=>{i?o==null||o():n&&n()},[i,o,n]),(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("button",{className:p("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:l,onClick:c,title:"View fullscreen",type:"button",...r,children:(0,v.jsx)(Z.Maximize2Icon,{size:14})}),i&&(0,v.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:c,onKeyDown:d=>{d.key==="Escape"&&c()},role:"button",tabIndex:0,children:[(0,v.jsx)("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:c,title:"Exit fullscreen",type:"button",children:(0,v.jsx)(Z.XIcon,{size:20})}),(0,v.jsx)("div",{className:"flex h-full w-full items-center justify-center p-12",onClick:d=>d.stopPropagation(),onKeyDown:d=>d.stopPropagation(),role:"presentation",children:(0,v.jsx)("div",{className:"max-h-full max-w-full",children:(0,v.jsx)(de,{chart:e,className:"[&>div]:my-0 [&_svg]:h-auto [&_svg]:min-h-[60vh] [&_svg]:w-auto [&_svg]:min-w-[60vw]",config:t})})})]})]})},de=({chart:e,className:t,config:o})=>{let[n,s]=(0,S.useState)(null),[r,i]=(0,S.useState)(!0),[a,l]=(0,S.useState)(""),[c,d]=(0,S.useState)("");if((0,S.useEffect)(()=>{(async()=>{try{s(null),i(!0);let f=await At(o),u=e.split("").reduce((y,L)=>(y<<5)-y+L.charCodeAt(0)|0,0),T=`mermaid-${Math.abs(u)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:k}=await f.render(T,e);l(k),d(k)}catch(f){if(!(c||a)){let u=f instanceof Error?f.message:"Failed to render Mermaid chart";s(u)}}finally{i(!1)}})()},[e,o]),r&&!a&&!c)return(0,v.jsx)("div",{className:p("my-4 flex justify-center p-4",t),children:(0,v.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,v.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,v.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(n&&!a&&!c)return(0,v.jsxs)("div",{className:p("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,v.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",n]}),(0,v.jsxs)("details",{className:"mt-2",children:[(0,v.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,v.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let h=a||c;return(0,v.jsx)("div",{"aria-label":"Mermaid chart",className:p("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:h},role:"img"})};var O=require("lucide-react"),I=require("react");var N=require("react/jsx-runtime");function Pe(e){var r,i;let t=[],o=[],n=e.querySelectorAll("thead th");for(let a of n)t.push(((r=a.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let a of s){let l=[],c=a.querySelectorAll("td");for(let d of c)l.push(((i=d.textContent)==null?void 0:i.trim())||"");o.push(l)}return{headers:t,rows:o}}function Ne(e){let{headers:t,rows:o}=e,n=r=>r.includes(",")||r.includes('"')||r.includes(`
|
|
4
|
-
`)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`)}var Ie=({children:e,className:t,onCopy:o,onError:n,timeout:s=2e3})=>{let[r,i]=(0,I.useState)(!1),[a,l]=(0,I.useState)(!1),c=(0,I.useRef)(null),d=(0,I.useRef)(0),{isAnimating:h}=(0,I.useContext)(H),w=async u=>{var T,k;if(typeof window=="undefined"||!((T=navigator==null?void 0:navigator.clipboard)!=null&&T.write)){n==null||n(new Error("Clipboard API not available"));return}try{let y=(k=c.current)==null?void 0:k.closest('[data-streamdown="table-wrapper"]'),L=y==null?void 0:y.querySelector("table");if(!L){n==null||n(new Error("Table not found"));return}let z=Pe(L),J=u==="csv"?Ne(z):$t(z),D=new ClipboardItem({"text/plain":new Blob([J],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([D]),l(!0),i(!1),o==null||o(u),d.current=window.setTimeout(()=>l(!1),s)}catch(y){n==null||n(y)}};(0,I.useEffect)(()=>{let u=T=>{c.current&&!c.current.contains(T.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current)}},[]);let f=a?O.CheckIcon:O.CopyIcon;return(0,N.jsxs)("div",{className:"relative",ref:c,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:h,onClick:()=>i(!r),title:"Copy table",type:"button",children:e!=null?e:(0,N.jsx)(f,{size:14})}),r&&(0,N.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,N.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>w("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:()=>w("tsv"),type:"button",children:"TSV"})]})]})};var Se=({children:e,className:t,onDownload:o,onError:n})=>{let[s,r]=(0,I.useState)(!1),i=(0,I.useRef)(null),{isAnimating:a}=(0,I.useContext)(H),l=c=>{var d;try{let h=(d=i.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),w=h==null?void 0:h.querySelector("table");if(!w){n==null||n(new Error("Table not found"));return}let f=Pe(w),u=c==="csv"?Ne(f):jt(f);E(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),r(!1),o==null||o(c)}catch(h){n==null||n(h)}};return(0,I.useEffect)(()=>{let c=d=>{i.current&&!i.current.contains(d.target)&&r(!1)};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c)}},[]),(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:a,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:(0,N.jsx)(O.DownloadIcon,{size:14})}),s&&(0,N.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,N.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,N.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 m=require("react/jsx-runtime"),Rt=/language-([^\s]+)/;function Y(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,s=e.position.end,r=t.position.end;return(o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function C(e,t){return e.className===t.className&&Y(e.node,t.node)}var ue=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,me=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===!1?!1:o===!0||o===void 0?!0:o[t]!==!1},pe=(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)=>C(e,t));pe.displayName="MarkdownOl";var Le=(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&&Y(e.node,t.node));Le.displayName="MarkdownLi";var xe=(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)=>C(e,t));xe.displayName="MarkdownUl";var He=(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)=>C(e,t));He.displayName="MarkdownHr";var Be=(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)=>C(e,t));Be.displayName="MarkdownStrong";var Ae=(0,g.memo)(({children:e,className:t,href:o,node:n,...s})=>{let r=o==="streamdown:incomplete-link";return(0,m.jsx)("a",{className:p("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...s,children:e})},(e,t)=>C(e,t)&&e.href===t.href);Ae.displayName="MarkdownA";var $e=(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)=>C(e,t));$e.displayName="MarkdownH1";var je=(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)=>C(e,t));je.displayName="MarkdownH2";var Re=(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)=>C(e,t));Re.displayName="MarkdownH3";var De=(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)=>C(e,t));De.displayName="MarkdownH4";var Ee=(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)=>C(e,t));Ee.displayName="MarkdownH5";var qe=(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)=>C(e,t));qe.displayName="MarkdownH6";var Oe=(0,g.memo)(({children:e,className:t,node:o,...n})=>{let s=(0,g.useContext)(X),r=ue(s,"table");return(0,m.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[r&&(0,m.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,m.jsx)(Ie,{}),(0,m.jsx)(Se,{})]}),(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)=>C(e,t));Oe.displayName="MarkdownTable";var ze=(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)=>C(e,t));ze.displayName="MarkdownThead";var _e=(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)=>C(e,t));_e.displayName="MarkdownTbody";var Ue=(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)=>C(e,t));Ue.displayName="MarkdownTr";var We=(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)=>C(e,t));We.displayName="MarkdownTh";var Fe=(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)=>C(e,t));Fe.displayName="MarkdownTd";var Xe=(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)=>C(e,t));Xe.displayName="MarkdownBlockquote";var Je=(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)=>C(e,t));Je.displayName="MarkdownSup";var Ke=(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)=>C(e,t));Ke.displayName="MarkdownSub";var Ve=(0,g.memo)(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let r=l=>{var w,f;if(!(0,g.isValidElement)(l))return!1;let c=Array.isArray(l.props.children)?l.props.children:[l.props.children],d=!1,h=!1;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=!0);else if((0,g.isValidElement)(u))if(((w=u.props)==null?void 0:w["data-footnote-backref"])!==void 0)h=!0;else{let T=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let k of T){if(typeof k=="string"&&k.trim()!==""){d=!0;break}if((0,g.isValidElement)(k)&&((f=k.props)==null?void 0:f["data-footnote-backref"])===void 0){d=!0;break}}}}return h&&!d},i=Array.isArray(e)?e.map(l=>{if(!(0,g.isValidElement)(l))return l;if(l.type===pe){let d=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(h=>!r(h));return d.length===0?null:{...l,props:{...l.props,children:d}}}return l}):e;return(Array.isArray(i)?i.some(l=>l!==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)=>C(e,t));Ve.displayName="MarkdownSection";var Dt=({node:e,className:t,children:o,...n})=>{var h,w,f;let s=((h=e==null?void 0:e.position)==null?void 0:h.start.line)===((w=e==null?void 0:e.position)==null?void 0:w.end.line),r=(0,g.useContext)(ee),i=(0,g.useContext)(X);if(s)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 a=t==null?void 0:t.match(Rt),l=(f=a==null?void 0:a.at(1))!=null?f:"",c="";if((0,g.isValidElement)(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?c=o.props.children:typeof o=="string"&&(c=o),l==="mermaid"){let u=ue(i,"mermaid"),T=me(i,"download"),k=me(i,"copy"),y=me(i,"fullscreen");return(0,m.jsxs)("div",{className:p("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[u&&(T||k||y)&&(0,m.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[T&&(0,m.jsx)(le,{code:c,language:l}),k&&(0,m.jsx)(ce,{code:c}),y&&(0,m.jsx)(Me,{chart:c,config:r})]}),(0,m.jsx)(de,{chart:c,config:r})]})}let d=ue(i,"code");return(0,m.jsx)(ve,{className:p("overflow-x-auto border-border border-t",t),code:c,"data-language":l,"data-streamdown":"code-block",language:l,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:d&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(le,{code:c,language:l}),(0,m.jsx)(ce,{})]})})},Ge=(0,g.memo)(Dt,(e,t)=>e.className===t.className&&Y(e.node,t.node));Ge.displayName="MarkdownCode";var Qe=(0,g.memo)(Ce,(e,t)=>e.className===t.className&&Y(e.node,t.node));Qe.displayName="MarkdownImg";var Ze=(0,g.memo)(({children:e,className:t,node:o,...n})=>{var i;let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");return r.length===1&&(0,g.isValidElement)(r[0])&&((i=r[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)=>C(e,t));Ze.displayName="MarkdownParagraph";var Ye={ol:pe,li:Le,ul:xe,hr:He,strong:Be,a:Ae,h1:$e,h2:je,h3:Re,h4:De,h5:Ee,h6:qe,table:Oe,thead:ze,tbody:_e,tr:Ue,th:We,td:Fe,blockquote:Xe,code:Ge,img:Qe,pre:({children:e})=>e,sup:Je,sub:Ke,p:Ze,section:Ve};var et=require("marked"),Et=/\[\^[^\]\s]{1,200}\](?!:)/,qt=/\[\^[^\]\s]{1,200}\]:/,Ot=/<\/(\w+)>/,zt=/<(\w+)[\s>]/,te=e=>{let t=Et.test(e),o=qt.test(e);if(t||o)return[e];let n=et.Lexer.lex(e,{gfm:!0}),s=[],r=[];for(let i of n){let a=i.raw;if(r.length>0){if(s[s.length-1]+=a,i.type==="html"){let l=a.match(Ot);if(l){let c=l[1];r.at(-1)===c&&r.pop()}}continue}if(i.type==="html"&&i.block){let l=a.match(zt);if(l){let c=l[1];a.includes(`</${c}>`)||r.push(c)}}if(a.trim()==="$$"&&s.length>0){let l=s.at(-1);if(!l){s.push(a);continue}let c=l.trimStart().startsWith("$$"),d=(l.match(/\$\$/g)||[]).length;if(c&&d%2===1){s[s.length-1]=l+a;continue}}if(s.length>0&&a.trimEnd().endsWith("$$")){let l=s.at(-1);if(!l){s.push(a);continue}let c=l.trimStart().startsWith("$$"),d=(l.match(/\$\$/g)||[]).length,h=(a.match(/\$\$/g)||[]).length;if(c&&d%2===1&&!a.trimStart().startsWith("$$")&&h===1){s[s.length-1]=l+a;continue}}s.push(a)}return s};var _t=/(!?\[)([^\]]*?)$/,Ut=/(\*\*)([^*]*?)$/,Wt=/(__)([^_]*?)$/,Ft=/(\*\*\*)([^*]*?)$/,Xt=/(\*)([^*]*?)$/,Jt=/(_)([^_]*?)$/,Kt=/(`)([^`]*?)$/,Vt=/(~~)([^~]*?)$/,Gt=/(!?)\[([^\]]+)\]\(([^)]+)$/,R=/^[\s_~*`]*$/,tt=/^[\s]*[-*+][\s]+$/,A=/[\p{L}\p{N}_]/u,Qt=/\n+$/,Zt=/^```[^`\n]*```?$/,Yt=/^\*{4,}$/,oe=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
|
|
8
|
-
`)},eo=e=>{let t=e.match(Gt);if(t){let n=t[1]==="!",s=t[2],r=t[3],i=e.lastIndexOf(`${n?"!":""}[${s}](${r}`),a=e.substring(0,i);return n?a:`${a}[${s}](streamdown:incomplete-link)`}let o=e.match(_t);if(o){if(o[1].startsWith("!")){let s=e.lastIndexOf(o[1]);return e.substring(0,s)}return`${e}](streamdown:incomplete-link)`}return e},to=e=>{if(oe(e))return e;let t=e.match(Ut);if(t){let o=t[2];if(!o||R.test(o))return e;let n=e.lastIndexOf(t[1]),r=e.substring(0,n).lastIndexOf(`
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`),
|
|
12
|
-
`)
|
|
13
|
-
`)
|
|
1
|
+
"use strict";"use client";var Vo=Object.create;var ue=Object.defineProperty;var Xo=Object.getOwnPropertyDescriptor;var Jo=Object.getOwnPropertyNames;var Ko=Object.getPrototypeOf,Zo=Object.prototype.hasOwnProperty;var Go=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Yo=(e,t)=>{for(var o in t)ue(e,o,{get:t[o],enumerable:!0})},ut=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Jo(t))!Zo.call(e,r)&&r!==o&&ue(e,r,{get:()=>t[r],enumerable:!(n=Xo(t,r))||n.enumerable});return e};var E=(e,t,o)=>(o=e!=null?Vo(Ko(e)):{},ut(t||!e||!e.__esModule?ue(o,"default",{value:e,enumerable:!0}):o,e)),Qo=e=>ut(ue({},"__esModule",{value:!0}),e);var ko=Go((fs,wo)=>{"use strict";var Pe=Object.prototype.hasOwnProperty,yo=Object.prototype.toString,po=Object.defineProperty,uo=Object.getOwnPropertyDescriptor,fo=function(t){return typeof Array.isArray=="function"?Array.isArray(t):yo.call(t)==="[object Array]"},ho=function(t){if(!t||yo.call(t)!=="[object Object]")return!1;var o=Pe.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&Pe.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!o&&!n)return!1;var r;for(r in t);return typeof r=="undefined"||Pe.call(t,r)},go=function(t,o){po&&o.name==="__proto__"?po(t,o.name,{enumerable:!0,configurable:!0,value:o.newValue,writable:!0}):t[o.name]=o.newValue},bo=function(t,o){if(o==="__proto__")if(Pe.call(t,o)){if(uo)return uo(t,o).value}else return;return t[o]};wo.exports=function e(){var t,o,n,r,s,a,i=arguments[0],l=1,c=arguments.length,d=!1;for(typeof i=="boolean"&&(d=i,i=arguments[1]||{},l=2),(i==null||typeof i!="object"&&typeof i!="function")&&(i={});l<c;++l)if(t=arguments[l],t!=null)for(o in t)n=bo(i,o),r=bo(t,o),i!==r&&(d&&r&&(ho(r)||(s=fo(r)))?(s?(s=!1,a=n&&fo(n)?n:[]):a=n&&ho(n)?n:{},go(i,{name:o,newValue:e(d,a,r)})):typeof r!="undefined"&&go(i,{name:o,newValue:r}));return i}});var er={};Yo(er,{Block:()=>mt,Streamdown:()=>Wo,StreamdownContext:()=>v,defaultRehypePlugins:()=>Fo,defaultRemarkPlugins:()=>Uo,parseIncompleteMarkdown:()=>Le,parseMarkdownIntoBlocks:()=>Be});module.exports=Qo(er);var P=require("react"),Do=require("rehype-harden"),Ae=E(require("rehype-katex"),1),Ho=E(require("rehype-raw"),1),Oo=E(require("remark-cjk-friendly"),1),zo=E(require("remark-cjk-friendly-gfm-strikethrough"),1),qo=E(require("remark-gfm"),1),_o=E(require("remark-math"),1);var y=require("react");var _=require("react");var fe=require("react");var ft=require("clsx"),ht=require("tailwind-merge"),f=(...e)=>(0,ht.twMerge)((0,ft.clsx)(e)),D=(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 le=require("react/jsx-runtime"),en=f("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-4","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),gt=(0,fe.memo)(({children:e,result:t,language:o,className:n,...r})=>{let s=(0,fe.useMemo)(()=>({backgroundColor:t.bg,color:t.fg}),[t.bg,t.fg]);return(0,le.jsx)("pre",{className:f(n,"p-4 text-sm"),"data-code-block":!0,"data-language":o,style:s,...r,children:(0,le.jsx)("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:t.tokens.map((a,i)=>(0,le.jsx)("span",{className:en,children:a.map((l,c)=>(0,le.jsx)("span",{style:{color:l.color,backgroundColor:l.bgColor,...l.htmlStyle},...l.htmlAttrs,children:l.content},c))},i))})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className);var yt=require("react/jsx-runtime"),bt=({className:e,language:t,style:o,...n})=>(0,yt.jsx)("div",{className:f("my-4 w-full overflow-hidden rounded-xl border border-border",e),"data-code-block-container":!0,"data-language":t,style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...n});var he=require("react"),je=(0,he.createContext)({code:""}),ge=()=>(0,he.useContext)(je);var ce=require("react/jsx-runtime"),wt=({language:e,children:t})=>(0,ce.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":e,children:[(0,ce.jsx)("span",{className:"ml-1 font-mono lowercase",children:e}),(0,ce.jsx)("div",{className:"flex items-center gap-2",children:t})]});var kt=require("shiki"),Ct=require("shiki/engine/javascript"),tn=(0,Ct.createJavaScriptRegexEngine)({forgiving:!0}),$e=new Map,De=new Map,ne=new Map,on=(e,t)=>`${e}-${t[0]}-${t[1]}`,nn=(e,t,o)=>{let n=e.slice(0,100),r=e.length>100?e.slice(-100):"";return`${t}:${o[0]}:${o[1]}:${e.length}:${n}:${r}`},rn=(e,t)=>{let o=on(e,t);if($e.has(o))return $e.get(o);let n=(0,kt.createHighlighter)({themes:t,langs:[e],engine:tn});return $e.set(o,n),n},He=(e,t,o,n)=>{let r=nn(e,t,o);return De.has(r)?De.get(r):(n&&(ne.has(r)||ne.set(r,new Set),ne.get(r).add(n)),rn(t,o).then(s=>{let a=s.codeToTokens(e,{lang:t,themes:{light:o[0],dark:o[1]}});De.set(r,a);let i=ne.get(r);if(i){for(let l of i)l(a);ne.delete(r)}}).catch(s=>{console.error("Failed to highlight code:",s),ne.delete(r)}),null)};var re=require("react/jsx-runtime"),vt=({code:e,language:t,className:o,children:n,preClassName:r,...s})=>{let{shikiTheme:a}=(0,_.useContext)(v),i=(0,_.useMemo)(()=>({bg:"transparent",fg:"inherit",tokens:e.split(`
|
|
2
|
+
`).map(d=>[{content:d,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[e]),[l,c]=(0,_.useState)(i);return(0,_.useEffect)(()=>{let d=He(e,t,a);if(d){c(d);return}He(e,t,a,m=>{c(m)})},[e,t,a]),(0,re.jsx)(je.Provider,{value:{code:e},children:(0,re.jsxs)(bt,{language:t,children:[(0,re.jsx)(wt,{language:t,children:n}),(0,re.jsx)(gt,{className:o,language:t,result:l,...s})]})})};var be=require("lucide-react"),F=require("react");var Oe=require("react/jsx-runtime"),ze=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...a})=>{let[i,l]=(0,F.useState)(!1),c=(0,F.useRef)(0),{code:d}=ge(),{isAnimating:m}=(0,F.useContext)(v),p=s!=null?s:d,h=async()=>{var b;if(typeof window=="undefined"||!((b=navigator==null?void 0:navigator.clipboard)!=null&&b.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(p),l(!0),e==null||e(),c.current=window.setTimeout(()=>l(!1),o))}catch(w){t==null||t(w)}};(0,F.useEffect)(()=>()=>{window.clearTimeout(c.current)},[]);let u=i?be.CheckIcon:be.CopyIcon;return(0,Oe.jsx)("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:m,onClick:h,type:"button",...a,children:n!=null?n:(0,Oe.jsx)(u,{size:14})})};var Tt=require("lucide-react"),Pt=require("react");var qe=require("react/jsx-runtime"),Mt={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},xt=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...a})=>{let{code:i}=ge(),{isAnimating:l}=(0,Pt.useContext)(v),c=s!=null?s:i,m=`file.${o&&o in Mt?Mt[o]:"txt"}`,p="text/plain",h=()=>{try{D(m,c,p),e==null||e()}catch(u){t==null||t(u)}};return(0,qe.jsx)("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:l,onClick:h,title:"Download file",type:"button",...a,children:n!=null?n:(0,qe.jsx)(Tt.DownloadIcon,{size:14})})};var Nt=require("lucide-react");var Y=require("react/jsx-runtime"),sn=/\.[^/.]+$/,It=({node:e,className:t,src:o,alt:n,...r})=>{let s=async()=>{if(o)try{let i=await(await fetch(o)).blob(),c=new URL(o,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),m=c.includes(".")&&d!==void 0&&d.length<=4,p="";if(m)p=c;else{let h=i.type,u="png";h.includes("jpeg")||h.includes("jpg")?u="jpg":h.includes("png")?u="png":h.includes("svg")?u="svg":h.includes("gif")?u="gif":h.includes("webp")&&(u="webp"),p=`${(n||c||"image").replace(sn,"")}.${u}`}D(p,i,i.type)}catch(a){console.error("Failed to download image:",a)}};return o?(0,Y.jsxs)("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[(0,Y.jsx)("img",{alt:n,className:f("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...r}),(0,Y.jsx)("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),(0,Y.jsx)("button",{className:f("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:s,title:"Download image",type:"button",children:(0,Y.jsx)(Nt.DownloadIcon,{size:14})})]}):null};var H=require("react");var se=require("lucide-react"),T=require("react");var j=require("react/jsx-runtime"),St=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:r=.1,showControls:s=!0,initialZoom:a=1,fullscreen:i=!1})=>{let l=(0,T.useRef)(null),c=(0,T.useRef)(null),[d,m]=(0,T.useState)(a),[p,h]=(0,T.useState)({x:0,y:0}),[u,b]=(0,T.useState)(!1),[w,C]=(0,T.useState)({x:0,y:0}),[N,B]=(0,T.useState)({x:0,y:0}),I=(0,T.useCallback)(k=>{m(R=>Math.max(o,Math.min(n,R+k)))},[o,n]),q=(0,T.useCallback)(()=>{I(r)},[I,r]),G=(0,T.useCallback)(()=>{I(-r)},[I,r]),te=(0,T.useCallback)(()=>{m(a),h({x:0,y:0})},[a]),$=(0,T.useCallback)(k=>{k.preventDefault();let R=k.deltaY>0?-r:r;I(R)},[I,r]),oe=(0,T.useCallback)(k=>{if(k.button!==0||k.isPrimary===!1)return;b(!0),C({x:k.clientX,y:k.clientY}),B(p);let R=k.currentTarget;R instanceof HTMLElement&&R.setPointerCapture(k.pointerId)},[p]),Re=(0,T.useCallback)(k=>{if(!u)return;k.preventDefault();let R=k.clientX-w.x,pt=k.clientY-w.y;h({x:N.x+R,y:N.y+pt})},[u,w,N]),ae=(0,T.useCallback)(k=>{b(!1);let R=k.currentTarget;R instanceof HTMLElement&&R.releasePointerCapture(k.pointerId)},[]);return(0,T.useEffect)(()=>{let k=l.current;if(k)return k.addEventListener("wheel",$,{passive:!1}),()=>{k.removeEventListener("wheel",$)}},[$]),(0,T.useEffect)(()=>{let k=c.current;if(k&&u)return document.body.style.userSelect="none",k.addEventListener("pointermove",Re,{passive:!1}),k.addEventListener("pointerup",ae),k.addEventListener("pointercancel",ae),()=>{document.body.style.userSelect="",k.removeEventListener("pointermove",Re),k.removeEventListener("pointerup",ae),k.removeEventListener("pointercancel",ae)}},[u,Re,ae]),(0,j.jsxs)("div",{className:f("relative",i?"h-full w-full":"w-full",t),ref:l,style:{cursor:u?"grabbing":"grab"},children:[s&&(0,j.jsxs)("div",{className:f("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",i?"bottom-4 left-4":"bottom-2 left-2"),children:[(0,j.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d>=n,onClick:q,title:"Zoom in",type:"button",children:(0,j.jsx)(se.ZoomInIcon,{size:16})}),(0,j.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d<=o,onClick:G,title:"Zoom out",type:"button",children:(0,j.jsx)(se.ZoomOutIcon,{size:16})}),(0,j.jsx)("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:te,title:"Reset zoom and pan",type:"button",children:(0,j.jsx)(se.RotateCcwIcon,{size:16})})]}),(0,j.jsx)("div",{className:f("origin-center transition-transform duration-150 ease-out",i&&"flex h-full w-full items-center justify-center"),onPointerDown:oe,ref:c,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var ye=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},Bt=(e,t)=>{var n;let o=(n=t==null?void 0:t.scale)!=null?n:5;return new Promise((r,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),i=new Image;i.crossOrigin="anonymous",i.onload=()=>{let l=document.createElement("canvas"),c=i.width*o,d=i.height*o;l.width=c,l.height=d;let m=l.getContext("2d");if(!m){s(new Error("Failed to create 2D canvas context for PNG export"));return}m.drawImage(i,0,0,c,d),l.toBlob(p=>{if(!p){s(new Error("Failed to create PNG blob"));return}r(p)},"image/png")},i.onerror=()=>s(new Error("Failed to load SVG image")),i.src=a})};var S=require("react/jsx-runtime"),we=({chart:e,className:t,config:o,fullscreen:n=!1})=>{let[r,s]=(0,H.useState)(null),[a,i]=(0,H.useState)(!0),[l,c]=(0,H.useState)(""),[d,m]=(0,H.useState)(""),[p,h]=(0,H.useState)(0),{mermaid:u}=(0,H.useContext)(v),b=u==null?void 0:u.errorComponent;if((0,H.useEffect)(()=>{(async()=>{try{s(null),i(!0);let N=await ye(o),B=e.split("").reduce((G,te)=>(G<<5)-G+te.charCodeAt(0)|0,0),I=`mermaid-${Math.abs(B)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:q}=await N.render(I,e);c(q),m(q)}catch(N){if(!(d||l)){let B=N instanceof Error?N.message:"Failed to render Mermaid chart";s(B)}}finally{i(!1)}})()},[e,o,p]),a&&!l&&!d)return(0,S.jsx)("div",{className:f("my-4 flex justify-center p-4",t),children:(0,S.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,S.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,S.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!l&&!d){let C=()=>h(N=>N+1);return b?(0,S.jsx)(b,{chart:e,error:r,retry:C}):(0,S.jsxs)("div",{className:f("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,S.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),(0,S.jsxs)("details",{className:"mt-2",children:[(0,S.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,S.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let w=l||d;return(0,S.jsx)(St,{className:f(n?"h-full w-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:!0,zoomStep:.1,children:(0,S.jsx)("div",{"aria-label":"Mermaid chart",className:f("flex justify-center",n&&"h-full w-full items-center"),dangerouslySetInnerHTML:{__html:w},role:"img"})})};var Et=require("lucide-react"),U=require("react");var z=require("react/jsx-runtime"),Lt=({chart:e,children:t,className:o,onDownload:n,config:r,onError:s})=>{let[a,i]=(0,U.useState)(!1),l=(0,U.useRef)(null),{isAnimating:c}=(0,U.useContext)(v),d=async m=>{try{if(m==="mmd"){D("diagram.mmd",e,"text/plain"),i(!1),n==null||n(m);return}let p=await ye(r),h=e.split("").reduce((w,C)=>(w<<5)-w+C.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(h)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:b}=await p.render(u,e);if(!b){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){D("diagram.svg",b,"image/svg+xml"),i(!1),n==null||n(m);return}if(m==="png"){let w=await Bt(b);D("diagram.png",w,"image/png"),n==null||n(m),i(!1);return}}catch(p){s==null||s(p)}};return(0,U.useEffect)(()=>{let m=p=>{l.current&&!l.current.contains(p.target)&&i(!1)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),(0,z.jsxs)("div",{className:"relative",ref:l,children:[(0,z.jsx)("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:c,onClick:()=>i(!a),title:"Download diagram",type:"button",children:t!=null?t:(0,z.jsx)(Et.DownloadIcon,{size:14})}),a&&(0,z.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,z.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),type:"button",children:"SVG"}),(0,z.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),type:"button",children:"PNG"}),(0,z.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),type:"button",children:"MMD"})]})]})};var ke=require("lucide-react"),Q=require("react");var L=require("react/jsx-runtime"),de=0,an=()=>{de+=1,de===1&&(document.body.style.overflow="hidden")},ln=()=>{de=Math.max(0,de-1),de===0&&(document.body.style.overflow="")},At=({chart:e,config:t,onFullscreen:o,onExit:n,className:r,...s})=>{let[a,i]=(0,Q.useState)(!1),{isAnimating:l}=(0,Q.useContext)(v),c=()=>{i(!a)};return(0,Q.useEffect)(()=>{if(a){an();let d=m=>{m.key==="Escape"&&i(!1)};return document.addEventListener("keydown",d),()=>{document.removeEventListener("keydown",d),ln()}}},[a]),(0,Q.useEffect)(()=>{a?o==null||o():n&&n()},[a,o,n]),(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:l,onClick:c,title:"View fullscreen",type:"button",...s,children:(0,L.jsx)(ke.Maximize2Icon,{size:14})}),a&&(0,L.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:c,onKeyDown:d=>{d.key==="Escape"&&c()},role:"button",tabIndex:0,children:[(0,L.jsx)("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:c,title:"Exit fullscreen",type:"button",children:(0,L.jsx)(ke.XIcon,{size:20})}),(0,L.jsx)("div",{className:"flex h-full w-full items-center justify-center p-4",onClick:d=>d.stopPropagation(),onKeyDown:d=>d.stopPropagation(),role:"presentation",children:(0,L.jsx)(we,{chart:e,className:"h-full w-full [&>div]:h-full [&>div]:overflow-hidden [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:!0})})]})]})};var Me=require("lucide-react"),O=require("react");var Ce=e=>{var s,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let i of n)t.push(((s=i.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let i of r){let l=[],c=i.querySelectorAll("td");for(let d of c)l.push(((a=d.textContent)==null?void 0:a.trim())||"");o.push(l)}return{headers:t,rows:o}},ve=e=>{let{headers:t,rows:o}=e,n=i=>{let l=!1,c=!1;for(let d=0;d<i.length;d+=1){let m=i[d];if(m==='"'){l=!0,c=!0;break}(m===","||m===`
|
|
3
|
+
`)&&(l=!0)}return l?c?`"${i.replace(/"/g,'""')}"`:`"${i}"`:i},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(","),a+=1);for(let i of o)s[a]=i.map(n).join(","),a+=1;return s.join(`
|
|
4
|
+
`)},Rt=e=>{let{headers:t,rows:o}=e,n=i=>{let l=!1;for(let d=0;d<i.length;d+=1){let m=i[d];if(m===" "||m===`
|
|
5
|
+
`||m==="\r"){l=!0;break}}if(!l)return i;let c=[];for(let d=0;d<i.length;d+=1){let m=i[d];m===" "?c.push("\\t"):m===`
|
|
6
|
+
`?c.push("\\n"):m==="\r"?c.push("\\r"):c.push(m)}return c.join("")},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(" "),a+=1);for(let i of o)s[a]=i.map(n).join(" "),a+=1;return s.join(`
|
|
7
|
+
`)},_e=e=>{let t=!1;for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="\\"||r==="|"){t=!0;break}}if(!t)return e;let o=[];for(let n=0;n<e.length;n+=1){let r=e[n];r==="\\"?o.push("\\\\"):r==="|"?o.push("\\|"):o.push(r)}return o.join("")},jt=e=>{let{headers:t,rows:o}=e;if(t.length===0)return"";let n=new Array(o.length+2),r=0,s=t.map(i=>_e(i));n[r]=`| ${s.join(" | ")} |`,r+=1;let a=new Array(t.length);for(let i=0;i<t.length;i+=1)a[i]="---";n[r]=`| ${a.join(" | ")} |`,r+=1;for(let i of o)if(i.length<t.length){let l=new Array(t.length);for(let c=0;c<t.length;c+=1)l[c]=c<i.length?_e(i[c]):"";n[r]=`| ${l.join(" | ")} |`,r+=1}else{let l=i.map(c=>_e(c));n[r]=`| ${l.join(" | ")} |`,r+=1}return n.join(`
|
|
8
|
+
`)};var W=require("react/jsx-runtime"),$t=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3})=>{let[s,a]=(0,O.useState)(!1),[i,l]=(0,O.useState)(!1),c=(0,O.useRef)(null),d=(0,O.useRef)(0),{isAnimating:m}=(0,O.useContext)(v),p=async u=>{var b,w;if(typeof window=="undefined"||!((b=navigator==null?void 0:navigator.clipboard)!=null&&b.write)){n==null||n(new Error("Clipboard API not available"));return}try{let C=(w=c.current)==null?void 0:w.closest('[data-streamdown="table-wrapper"]'),N=C==null?void 0:C.querySelector("table");if(!N){n==null||n(new Error("Table not found"));return}let B=Ce(N),I=u==="csv"?ve(B):Rt(B),q=new ClipboardItem({"text/plain":new Blob([I],{type:"text/plain"}),"text/html":new Blob([N.outerHTML],{type:"text/html"})});await navigator.clipboard.write([q]),l(!0),a(!1),o==null||o(u),d.current=window.setTimeout(()=>l(!1),r)}catch(C){n==null||n(C)}};(0,O.useEffect)(()=>{let u=b=>{c.current&&!c.current.contains(b.target)&&a(!1)};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current)}},[]);let h=i?Me.CheckIcon:Me.CopyIcon;return(0,W.jsxs)("div",{className:"relative",ref:c,children:[(0,W.jsx)("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>a(!s),title:"Copy table",type:"button",children:e!=null?e:(0,W.jsx)(h,{size:14})}),s&&(0,W.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,W.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),type:"button",children:"CSV"}),(0,W.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),type:"button",children:"TSV"})]})]})};var Dt=require("lucide-react"),X=require("react");var V=require("react/jsx-runtime");var Ht=({children:e,className:t,onDownload:o,onError:n})=>{let[r,s]=(0,X.useState)(!1),a=(0,X.useRef)(null),{isAnimating:i}=(0,X.useContext)(v),l=c=>{var d;try{let m=(d=a.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),p=m==null?void 0:m.querySelector("table");if(!p){n==null||n(new Error("Table not found"));return}let h=Ce(p),u=c==="csv"?ve(h):jt(h);D(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),s(!1),o==null||o(c)}catch(m){n==null||n(m)}};return(0,X.useEffect)(()=>{let c=d=>{a.current&&!a.current.contains(d.target)&&s(!1)};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c)}},[]),(0,V.jsxs)("div",{className:"relative",ref:a,children:[(0,V.jsx)("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>s(!r),title:"Download table",type:"button",children:e!=null?e:(0,V.jsx)(Dt.DownloadIcon,{size:14})}),r&&(0,V.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[(0,V.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,V.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 J=require("react/jsx-runtime"),Ot=({children:e,className:t,showControls:o,...n})=>(0,J.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[o&&(0,J.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,J.jsx)($t,{}),(0,J.jsx)(Ht,{})]}),(0,J.jsx)("div",{className:"overflow-x-auto",children:(0,J.jsx)("table",{className:f("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});var g=require("react/jsx-runtime"),cn=/language-([^\s]+)/;function Te(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 M(e,t){return e.className===t.className&&Te(e.node,t.node)}var Ue=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,Fe=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===!1?!1:o===!0||o===void 0?!0:o[t]!==!1},We=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("ol",{className:f("list-inside list-decimal whitespace-normal",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>M(e,t));We.displayName="MarkdownOl";var zt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("li",{className:f("py-1",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&Te(e.node,t.node));zt.displayName="MarkdownLi";var qt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("ul",{className:f("list-inside list-disc whitespace-normal",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>M(e,t));qt.displayName="MarkdownUl";var _t=(0,y.memo)(({className:e,node:t,...o})=>(0,g.jsx)("hr",{className:f("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>M(e,t));_t.displayName="MarkdownHr";var Ft=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("span",{className:f("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>M(e,t));Ft.displayName="MarkdownStrong";var Ut=(0,y.memo)(({children:e,className:t,href:o,node:n,...r})=>{let s=o==="streamdown:incomplete-link";return(0,g.jsx)("a",{className:f("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)=>M(e,t)&&e.href===t.href);Ut.displayName="MarkdownA";var Wt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("h1",{className:f("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>M(e,t));Wt.displayName="MarkdownH1";var Vt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("h2",{className:f("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>M(e,t));Vt.displayName="MarkdownH2";var Xt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("h3",{className:f("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>M(e,t));Xt.displayName="MarkdownH3";var Jt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("h4",{className:f("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>M(e,t));Jt.displayName="MarkdownH4";var Kt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("h5",{className:f("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>M(e,t));Kt.displayName="MarkdownH5";var Zt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("h6",{className:f("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>M(e,t));Zt.displayName="MarkdownH6";var Gt=(0,y.memo)(({children:e,className:t,node:o,...n})=>{let{controls:r}=(0,y.useContext)(v),s=Ue(r,"table");return(0,g.jsx)(Ot,{className:t,"data-streamdown":"table-wrapper",showControls:s,...n,children:e})},(e,t)=>M(e,t));Gt.displayName="MarkdownTable";var Yt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("thead",{className:f("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>M(e,t));Yt.displayName="MarkdownThead";var Qt=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("tbody",{className:f("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>M(e,t));Qt.displayName="MarkdownTbody";var eo=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("tr",{className:f("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>M(e,t));eo.displayName="MarkdownTr";var to=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("th",{className:f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>M(e,t));to.displayName="MarkdownTh";var oo=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("td",{className:f("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>M(e,t));oo.displayName="MarkdownTd";var no=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("blockquote",{className:f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>M(e,t));no.displayName="MarkdownBlockquote";var ro=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("sup",{className:f("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>M(e,t));ro.displayName="MarkdownSup";var so=(0,y.memo)(({children:e,className:t,node:o,...n})=>(0,g.jsx)("sub",{className:f("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>M(e,t));so.displayName="MarkdownSub";var io=(0,y.memo)(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=l=>{var p,h;if(!(0,y.isValidElement)(l))return!1;let c=Array.isArray(l.props.children)?l.props.children:[l.props.children],d=!1,m=!1;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=!0);else if((0,y.isValidElement)(u))if(((p=u.props)==null?void 0:p["data-footnote-backref"])!==void 0)m=!0;else{let b=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let w of b){if(typeof w=="string"&&w.trim()!==""){d=!0;break}if((0,y.isValidElement)(w)&&((h=w.props)==null?void 0:h["data-footnote-backref"])===void 0){d=!0;break}}}}return m&&!d},a=Array.isArray(e)?e.map(l=>{if(!(0,y.isValidElement)(l))return l;if(l.type===We){let d=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(m=>!s(m));return d.length===0?null:{...l,props:{...l.props,children:d}}}return l}):e;return(Array.isArray(a)?a.some(l=>l!==null):a!==null)?(0,g.jsx)("section",{className:t,...n,children:a}):null}return(0,g.jsx)("section",{className:t,...n,children:e})},(e,t)=>M(e,t));io.displayName="MarkdownSection";var dn=({node:e,className:t,children:o,...n})=>{var m,p,h;let r=((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((p=e==null?void 0:e.position)==null?void 0:p.end.line),{mermaid:s,controls:a}=(0,y.useContext)(v);if(r)return(0,g.jsx)("code",{className:f("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let i=t==null?void 0:t.match(cn),l=(h=i==null?void 0:i.at(1))!=null?h:"",c="";if((0,y.isValidElement)(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?c=o.props.children:typeof o=="string"&&(c=o),l==="mermaid"){let u=Ue(a,"mermaid"),b=Fe(a,"download"),w=Fe(a,"copy"),C=Fe(a,"fullscreen");return(0,g.jsxs)("div",{className:f("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[u&&(b||w||C)&&(0,g.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[b&&(0,g.jsx)(Lt,{chart:c,config:s==null?void 0:s.config}),w&&(0,g.jsx)(ze,{code:c}),C&&(0,g.jsx)(At,{chart:c,config:s==null?void 0:s.config})]}),(0,g.jsx)(we,{chart:c,config:s==null?void 0:s.config})]})}let d=Ue(a,"code");return(0,g.jsx)(vt,{className:f("overflow-x-auto border-border border-t",t),code:c,"data-language":l,"data-streamdown":"code-block",language:l,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:d&&(0,g.jsxs)(g.Fragment,{children:[(0,g.jsx)(xt,{code:c,language:l}),(0,g.jsx)(ze,{})]})})},ao=(0,y.memo)(dn,(e,t)=>e.className===t.className&&Te(e.node,t.node));ao.displayName="MarkdownCode";var lo=(0,y.memo)(It,(e,t)=>e.className===t.className&&Te(e.node,t.node));lo.displayName="MarkdownImg";var co=(0,y.memo)(({children:e,className:t,node:o,...n})=>{var a;let s=(Array.isArray(e)?e:[e]).filter(i=>i!=null&&i!=="");return s.length===1&&(0,y.isValidElement)(s[0])&&((a=s[0].props.node)==null?void 0:a.tagName)==="img"?(0,g.jsx)(g.Fragment,{children:e}):(0,g.jsx)("p",{className:t,...n,children:e})},(e,t)=>M(e,t));co.displayName="MarkdownParagraph";var mo={ol:We,li:zt,ul:qt,hr:_t,strong:Ft,a:Ut,h1:Wt,h2:Vt,h3:Xt,h4:Jt,h5:Kt,h6:Zt,table:Gt,thead:Yt,tbody:Qt,tr:eo,th:to,td:oo,blockquote:no,code:ao,img:lo,pre:({children:e})=>e,sup:ro,sub:so,p:co,section:io};var Eo=require("hast-util-to-jsx-runtime"),ie=require("react/jsx-runtime"),Lo=E(require("remark-parse"),1),Ao=E(require("remark-rehype"),1);function Ve(e){if(e)throw e}var Ie=E(ko(),1);function me(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function Xe(){let e=[],t={run:o,use:n};return t;function o(...r){let s=-1,a=r.pop();if(typeof a!="function")throw new TypeError("Expected function as last argument, not "+a);i(null,...r);function i(l,...c){let d=e[++s],m=-1;if(l){a(l);return}for(;++m<r.length;)(c[m]===null||c[m]===void 0)&&(c[m]=r[m]);r=c,d?Co(d,i)(...c):a(null,...c)}}function n(r){if(typeof r!="function")throw new TypeError("Expected `middelware` to be a function, not "+r);return e.push(r),t}}function Co(e,t){let o;return n;function n(...a){let i=e.length>a.length,l;i&&a.push(r);try{l=e.apply(this,a)}catch(c){let d=c;if(i&&o)throw d;return r(d)}i||(l&&l.then&&typeof l.then=="function"?l.then(s,r):l instanceof Error?r(l):s(l))}function r(a,...i){o||(o=!0,t(a,...i))}function s(a){r(null,a)}}function Ke(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?vo(e.position):"start"in e||"end"in e?vo(e):"line"in e||"column"in e?Je(e):""}function Je(e){return Mo(e&&e.line)+":"+Mo(e&&e.column)}function vo(e){return Je(e&&e.start)+"-"+Je(e&&e.end)}function Mo(e){return e&&typeof e=="number"?e:1}var x=class extends Error{constructor(t,o,n){super(),typeof o=="string"&&(n=o,o=void 0);let r="",s={},a=!1;if(o&&("line"in o&&"column"in o?s={place:o}:"start"in o&&"end"in o?s={place:o}:"type"in o?s={ancestors:[o],place:o.position}:s={...o}),typeof t=="string"?r=t:!s.cause&&t&&(a=!0,r=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof n=="string"){let l=n.indexOf(":");l===-1?s.ruleId=n:(s.source=n.slice(0,l),s.ruleId=n.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){let l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}let i=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=i?i.column:void 0,this.fatal=void 0,this.file="",this.message=r,this.line=i?i.line:void 0,this.name=Ke(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=a&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};x.prototype.file="";x.prototype.name="";x.prototype.reason="";x.prototype.message="";x.prototype.stack="";x.prototype.column=void 0;x.prototype.line=void 0;x.prototype.ancestors=void 0;x.prototype.cause=void 0;x.prototype.fatal=void 0;x.prototype.place=void 0;x.prototype.ruleId=void 0;x.prototype.source=void 0;var A=E(require("path"),1);var Ze=E(require("process"),1);var Ge=require("url");function xe(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}var Ye=["history","path","basename","stem","extname","dirname"],pe=class{constructor(t){let o;t?xe(t)?o={path:t}:typeof t=="string"||mn(t)?o={value:t}:o=t:o={},this.cwd="cwd"in o?"":Ze.default.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<Ye.length;){let s=Ye[n];s in o&&o[s]!==void 0&&o[s]!==null&&(this[s]=s==="history"?[...o[s]]:o[s])}let r;for(r in o)Ye.includes(r)||(this[r]=o[r])}get basename(){return typeof this.path=="string"?A.default.basename(this.path):void 0}set basename(t){et(t,"basename"),Qe(t,"basename"),this.path=A.default.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?A.default.dirname(this.path):void 0}set dirname(t){To(this.basename,"dirname"),this.path=A.default.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?A.default.extname(this.path):void 0}set extname(t){if(Qe(t,"extname"),To(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=A.default.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){xe(t)&&(t=(0,Ge.fileURLToPath)(t)),et(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?A.default.basename(this.path,this.extname):void 0}set stem(t){et(t,"stem"),Qe(t,"stem"),this.path=A.default.join(this.dirname||"",t+(this.extname||""))}fail(t,o,n){let r=this.message(t,o,n);throw r.fatal=!0,r}info(t,o,n){let r=this.message(t,o,n);return r.fatal=void 0,r}message(t,o,n){let r=new x(t,o,n);return this.path&&(r.name=this.path+":"+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}};function Qe(e,t){if(e&&e.includes(A.default.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+A.default.sep+"`")}function et(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function To(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function mn(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}var Po=(function(e){let n=this.constructor.prototype,r=n[e],s=function(){return r.apply(s,arguments)};return Object.setPrototypeOf(s,n),s});var pn={}.hasOwnProperty,rt=class e extends Po{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=Xe()}copy(){let t=new e,o=-1;for(;++o<this.attachers.length;){let n=this.attachers[o];t.use(...n)}return t.data((0,Ie.default)(!0,{},this.namespace)),t}data(t,o){return typeof t=="string"?arguments.length===2?(nt("data",this.frozen),this.namespace[t]=o,this):pn.call(this.namespace,t)&&this.namespace[t]||void 0:t?(nt("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;let t=this;for(;++this.freezeIndex<this.attachers.length;){let[o,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=o.call(t,...n);typeof r=="function"&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();let o=Ne(t),n=this.parser||this.Parser;return tt("parse",n),n(String(o),o)}process(t,o){let n=this;return this.freeze(),tt("process",this.parser||this.Parser),ot("process",this.compiler||this.Compiler),o?r(void 0,o):new Promise(r);function r(s,a){let i=Ne(t),l=n.parse(i);n.run(l,i,function(d,m,p){if(d||!m||!p)return c(d);let h=m,u=n.stringify(h,p);fn(u)?p.value=u:p.result=u,c(d,p)});function c(d,m){d||!m?a(d):s?s(m):o(void 0,m)}}}processSync(t){let o=!1,n;return this.freeze(),tt("processSync",this.parser||this.Parser),ot("processSync",this.compiler||this.Compiler),this.process(t,r),No("processSync","process",o),n;function r(s,a){o=!0,Ve(s),n=a}}run(t,o,n){xo(t),this.freeze();let r=this.transformers;return!n&&typeof o=="function"&&(n=o,o=void 0),n?s(void 0,n):new Promise(s);function s(a,i){let l=Ne(o);r.run(t,l,c);function c(d,m,p){let h=m||t;d?i(d):a?a(h):n(void 0,h,p)}}}runSync(t,o){let n=!1,r;return this.run(t,o,s),No("runSync","run",n),r;function s(a,i){Ve(a),r=i,n=!0}}stringify(t,o){this.freeze();let n=Ne(o),r=this.compiler||this.Compiler;return ot("stringify",r),xo(t),r(t,n)}use(t,...o){let n=this.attachers,r=this.namespace;if(nt("use",this.frozen),t!=null)if(typeof t=="function")l(t,o);else if(typeof t=="object")Array.isArray(t)?i(t):a(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(c){if(typeof c=="function")l(c,[]);else if(typeof c=="object")if(Array.isArray(c)){let[d,...m]=c;l(d,m)}else a(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function a(c){if(!("plugins"in c)&&!("settings"in c))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");i(c.plugins),c.settings&&(r.settings=(0,Ie.default)(!0,r.settings,c.settings))}function i(c){let d=-1;if(c!=null)if(Array.isArray(c))for(;++d<c.length;){let m=c[d];s(m)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function l(c,d){let m=-1,p=-1;for(;++m<n.length;)if(n[m][0]===c){p=m;break}if(p===-1)n.push([c,...d]);else if(d.length>0){let[h,...u]=d,b=n[p][1];me(b)&&me(h)&&(h=(0,Ie.default)(!0,b,h)),n[p]=[c,h,...u]}}}},st=new rt().freeze();function tt(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function ot(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function nt(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function xo(e){if(!me(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function No(e,t,o){if(!o)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function Ne(e){return un(e)?e:new pe(e)}function un(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function fn(e){return typeof e=="string"||hn(e)}function hn(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}var Io=[],So={allowDangerousHtml:!0},Se=new WeakMap,it=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,r=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||r||s)){let m="default";return this.keyCache.set(t,m),m}let a=m=>{if(!m||m.length===0)return"";let p="";for(let h=0;h<m.length;h+=1){let u=m[h];if(h>0&&(p+=","),Array.isArray(u)){let[b,w]=u;if(typeof b=="function"){let C=Se.get(b);C||(C=b.name,Se.set(b,C)),p+=C}else p+=String(b);p+=":",p+=JSON.stringify(w)}else if(typeof u=="function"){let b=Se.get(u);b||(b=u.name,Se.set(u,b)),p+=b}else p+=String(u)}return p},i=a(n),l=a(r),c=s?JSON.stringify(s):"",d=`${l}::${i}::${c}`;return this.keyCache.set(t,d),d}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let r=this.cache.keys().next().value;r&&this.cache.delete(r)}this.cache.set(n,o)}clear(){this.cache.clear()}},Bo=new it,at=e=>{let t=gn(e),o=e.children||"";return yn(t.runSync(t.parse(o),o),e)},gn=e=>{let t=Bo.get(e);if(t)return t;let o=bn(e);return Bo.set(e,o),o},bn=e=>{let t=e.rehypePlugins||Io,o=e.remarkPlugins||Io,n=e.remarkRehypeOptions?{...So,...e.remarkRehypeOptions}:So;return st().use(Lo.default).use(o).use(Ao.default,n).use(t)},yn=(e,t)=>(0,Eo.toJsxRuntime)(e,{Fragment:ie.Fragment,components:t.components,ignoreInvalidStyle:!0,jsx:ie.jsx,jsxs:ie.jsxs,passKeys:!0,passNode:!0});var Ro=require("marked"),wn=/\[\^[^\]\s]{1,200}\](?!:)/,kn=/\[\^[^\]\s]{1,200}\]:/,Cn=/<\/(\w+)>/,vn=/<(\w+)[\s>]/,lt=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},Mn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},ct=e=>{let t=0;for(let o=0;o<e.length-1;o+=1)e[o]==="$"&&e[o+1]==="$"&&(t+=1,o+=1);return t},Be=e=>{let t=wn.test(e),o=kn.test(e);if(t||o)return[e];let n=Ro.Lexer.lex(e,{gfm:!0}),r=[],s=[];for(let a of n){let i=a.raw,l=r.length;if(s.length>0){if(r[l-1]+=i,a.type==="html"){let d=i.match(Cn);if(d){let m=d[1];s.at(-1)===m&&s.pop()}}continue}if(a.type==="html"&&a.block){let d=i.match(vn);if(d){let m=d[1];i.includes(`</${m}>`)||s.push(m)}}if(i.trim()==="$$"&&l>0){let d=r[l-1],m=lt(d),p=ct(d);if(m&&p%2===1){r[l-1]=d+i;continue}}if(l>0&&Mn(i)){let d=r[l-1],m=lt(d),p=ct(d),h=ct(i);if(m&&p%2===1&&!lt(i)&&h===1){r[l-1]=d+i;continue}}r.push(i)}return r};var Tn=/(\*\*)([^*]*?)$/,Pn=/(__)([^_]*?)$/,xn=/(\*\*\*)([^*]*?)$/,Nn=/(\*)([^*]*?)$/,In=/(_)([^_]*?)$/,Sn=/(`)([^`]*?)$/,Bn=/(~~)([^~]*?)$/,ee=/^[\s_~*`]*$/,jo=/^[\s]*[-*+][\s]+$/,En=/[\p{L}\p{N}_]/u,Ln=/^```[^`\n]*```?$/,An=/^\*{4,}$/,K=e=>{if(!e)return!1;let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95?!0:En.test(e)},Ee=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
|
|
11
|
+
`)};var Rn=(e,t)=>{let o=1;for(let n=t-1;n>=0;n-=1)if(e[n]==="]")o+=1;else if(e[n]==="["&&(o-=1,o===0))return n;return-1},jn=(e,t)=>{let o=1;for(let n=t+1;n<e.length;n+=1)if(e[n]==="[")o+=1;else if(e[n]==="]"&&(o-=1,o===0))return n;return-1},dt=(e,t)=>{let o=!1,n=!1;for(let r=0;r<t;r+=1){if(e.substring(r,r+3)==="```"){n=!n,r+=2;continue}!n&&e[r]==="`"&&(o=!o)}return o||n},$n=e=>{let t=e.lastIndexOf("](");if(t!==-1&&!dt(e,t)&&!e.substring(t+2).includes(")")){let n=Rn(e,t);if(n!==-1&&!dt(e,n)){let r=n>0&&e[n-1]==="!",s=r?n-1:n,a=e.substring(0,s),i=e.substring(n+1,t);return r?a:`${a}[${i}](streamdown:incomplete-link)`}}for(let o=e.length-1;o>=0;o-=1)if(e[o]==="["&&!dt(e,o)){let n=o>0&&e[o-1]==="!",r=n?o-1:o;if(!e.substring(o+1).includes("]")){let i=e.substring(0,r);return n?i:`${e}](streamdown:incomplete-link)`}if(jn(e,o)===-1){let i=e.substring(0,r);return n?i:`${e}](streamdown:incomplete-link)`}}return e},Dn=e=>{if(Ee(e))return e;let t=e.match(Tn);if(t){let o=t[2];if(!o||ee.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
|
|
12
|
+
`),a=s===-1?0:s+1,i=e.substring(a,n);if(jo.test(i)&&o.includes(`
|
|
13
|
+
`))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},Hn=e=>{let t=e.match(Pn);if(t){let o=t[2];if(!o||ee.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
|
|
14
|
+
`),a=s===-1?0:s+1,i=e.substring(a,n);if(jo.test(i)&&o.includes(`
|
|
15
|
+
`))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},On=e=>{let t=0,o=e.length;for(let n=0;n<o;n+=1){if(e[n]!=="*")continue;let r=n>0?e[n-1]:"",s=n<o-1?e[n+1]:"";if(r==="\\"||r==="*"||s==="*"||r&&s&&K(r)&&K(s))continue;let a=0;for(let l=n-1;l>=0;l-=1)if(e[l]===`
|
|
16
|
+
`){a=l+1;break}let i=!0;for(let l=a;l<n;l+=1)if(e[l]!==" "&&e[l]!==" "){i=!1;break}i&&(s===" "||s===" ")||(t+=1)}return t},zn=e=>{if(Ee(e))return e;if(e.match(Nn)){let o=-1;for(let s=0;s<e.length;s+=1)if(e[s]==="*"&&e[s-1]!=="*"&&e[s+1]!=="*"&&e[s-1]!=="\\"){let a=s>0?e[s-1]:"",i=s<e.length-1?e[s+1]:"";if(a&&i&&K(a)&&K(i))continue;o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||ee.test(n))return e;if(On(e)%2===1)return`${e}*`}return e},$o=(e,t)=>{let o=!1,n=!1;for(let r=0;r<e.length&&r<t;r+=1){if(e[r]==="\\"&&e[r+1]==="$"){r+=1;continue}e[r]==="$"&&(e[r+1]==="$"?(n=!n,r+=1,o=!1):n||(o=!o))}return o||n},qn=e=>{let t=e.includes("$"),o=0,n=e.length;for(let r=0;r<n;r+=1){if(e[r]!=="_")continue;let s=r>0?e[r-1]:"",a=r<n-1?e[r+1]:"";s!=="\\"&&(t&&$o(e,r)||s==="_"||a==="_"||s&&a&&K(s)&&K(a)||(o+=1))}return o},_n=e=>{if(Ee(e))return e;if(e.match(In)){let o=-1;for(let s=0;s<e.length;s+=1)if(e[s]==="_"&&e[s-1]!=="_"&&e[s+1]!=="_"&&e[s-1]!=="\\"&&!$o(e,s)){let a=s>0?e[s-1]:"",i=s<e.length-1?e[s+1]:"";if(a&&i&&K(a)&&K(i))continue;o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||ee.test(n))return e;if(qn(e)%2===1){let s=e.length;for(;s>0&&e[s-1]===`
|
|
17
|
+
`;)s-=1;if(s<e.length){let a=e.slice(0,s),i=e.slice(s);return`${a}_${i}`}return`${e}_`}}return e},Fn=(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},Un=e=>{let t=0;for(let o=0;o<e.length;o+=1)e[o]==="`"&&!Fn(e,o)&&(t+=1);return t},Wn=e=>{if(e.match(Ln)&&!e.includes(`
|
|
14
18
|
`))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(`
|
|
15
|
-
`)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let
|
|
19
|
+
`)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let r=e.match(Sn);if(r&&!n){let s=r[2];if(!s||ee.test(s))return e;if(Un(e)%2===1)return`${e}\``}return e},Vn=e=>{let t=e.match(Bn);if(t){let o=t[2];if(!o||ee.test(o))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e},Xn=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let o=e.indexOf("$$");return o!==-1&&e.indexOf(`
|
|
16
20
|
`,o)!==-1&&!e.endsWith(`
|
|
17
21
|
`)?`${e}
|
|
18
|
-
$$`:`${e}$$`},
|
|
22
|
+
$$`:`${e}$$`},Jn=e=>{let t=0,o=0;for(let n=0;n<e.length;n+=1)e[n]==="*"?o+=1:(o>=3&&(t+=Math.floor(o/3)),o=0);return o>=3&&(t+=Math.floor(o/3)),t},Kn=e=>{if(Ee(e)||An.test(e))return e;let t=e.match(xn);if(t){let o=t[2];if(!o||ee.test(o))return e;if(Jn(e)%2===1)return`${e}***`}return e},Le=e=>{if(!e||typeof e!="string")return e;let t=e,o=$n(t);return o.endsWith("](streamdown:incomplete-link)")?o:(t=o,t=Kn(t),t=Dn(t),t=Hn(t),t=zn(t),t=_n(t),t=Wn(t),t=Vn(t),t=Xn(t),t)};var Z=require("react/jsx-runtime"),Fo={harden:[Do.harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],defaultOrigin:void 0,allowDataImages:!0}],raw:Ho.default,katex:[Ae.default,{errorColor:"var(--color-muted-foreground)"}]},Uo={gfm:[qo.default,{}],math:[_o.default,{singleDollarTextMath:!1}],cjkFriendly:[Oo.default,{}],cjkFriendlyGfmStrikethrough:[zo.default,{}]},Zn=Object.values(Fo),Gn=Object.values(Uo),Yn={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0},v=(0,P.createContext)(Yn),mt=(0,P.memo)(({content:e,shouldParseIncompleteMarkdown:t,...o})=>{let n=(0,P.useMemo)(()=>typeof e=="string"&&t?Le(e.trim()):e,[e,t]);return(0,Z.jsx)(at,{...o,children:n})},(e,t)=>{if(e.content!==t.content||e.shouldParseIncompleteMarkdown!==t.shouldParseIncompleteMarkdown||e.index!==t.index)return!1;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(r=>{var s,a;return((s=e.components)==null?void 0:s[r])!==((a=t.components)==null?void 0:a[r])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});mt.displayName="Block";var Qn=["github-light","github-dark"],Wo=(0,P.memo)(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=!0,components:n,rehypePlugins:r=Zn,remarkPlugins:s=Gn,className:a,shikiTheme:i=Qn,mermaid:l,controls:c=!0,isAnimating:d=!1,BlockComponent:m=mt,parseMarkdownIntoBlocksFn:p=Be,...h})=>{let u=(0,P.useId)(),[b,w]=(0,P.useTransition)(),[C,N]=(0,P.useState)([]),B=(0,P.useMemo)(()=>p(typeof e=="string"?e:""),[e,p]);(0,P.useEffect)(()=>{t==="streaming"?w(()=>{N(B)}):N(B)},[B,t]);let I=t==="streaming"?C:B,q=(0,P.useMemo)(()=>I.map(($,oe)=>`${u}-${oe}`),[I.length,u]),G=(0,P.useMemo)(()=>({shikiTheme:i,controls:c,isAnimating:d,mode:t,mermaid:l}),[i,c,d,t,l]),te=(0,P.useMemo)(()=>({...mo,...n}),[n]);return(0,P.useEffect)(()=>{Array.isArray(r)&&r.some($=>Array.isArray($)?$[0]===Ae.default:$===Ae.default)&&import("katex/dist/katex.min.css")},[r]),t==="static"?(0,Z.jsx)(v.Provider,{value:G,children:(0,Z.jsx)("div",{className:f("space-y-4",a),children:(0,Z.jsx)(at,{components:te,rehypePlugins:r,remarkPlugins:s,...h,children:e})})}):(0,Z.jsx)(v.Provider,{value:G,children:(0,Z.jsx)("div",{className:f("space-y-4",a),children:I.map(($,oe)=>(0,Z.jsx)(m,{components:te,content:$,index:oe,rehypePlugins:r,remarkPlugins:s,shouldParseIncompleteMarkdown:o,...h},q[oe]))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode);Wo.displayName="Streamdown";0&&(module.exports={Block,Streamdown,StreamdownContext,defaultRehypePlugins,defaultRemarkPlugins,parseIncompleteMarkdown,parseMarkdownIntoBlocks});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
+
import { JSX, ComponentType } from 'react';
|
|
3
4
|
import { MermaidConfig } from 'mermaid';
|
|
4
5
|
export { MermaidConfig } from 'mermaid';
|
|
5
|
-
import { Options } from 'react-markdown';
|
|
6
|
-
export { defaultUrlTransform } from 'react-markdown';
|
|
7
6
|
import { BundledTheme } from 'shiki';
|
|
8
|
-
import { Pluggable } from 'unified';
|
|
7
|
+
import { PluggableList, Pluggable } from 'unified';
|
|
8
|
+
import { Element } from 'hast';
|
|
9
|
+
import { Options as Options$1 } from 'remark-rehype';
|
|
10
|
+
|
|
11
|
+
type ExtraProps = {
|
|
12
|
+
node?: Element | undefined;
|
|
13
|
+
};
|
|
14
|
+
type Components = {
|
|
15
|
+
[Key in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Key] & ExtraProps> | keyof JSX.IntrinsicElements;
|
|
16
|
+
};
|
|
17
|
+
type Options = {
|
|
18
|
+
children?: string;
|
|
19
|
+
components?: Components;
|
|
20
|
+
rehypePlugins?: PluggableList;
|
|
21
|
+
remarkPlugins?: PluggableList;
|
|
22
|
+
remarkRehypeOptions?: Readonly<Options$1>;
|
|
23
|
+
};
|
|
9
24
|
|
|
10
25
|
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
11
26
|
|
|
@@ -20,31 +35,42 @@ type ControlsConfig = boolean | {
|
|
|
20
35
|
fullscreen?: boolean;
|
|
21
36
|
};
|
|
22
37
|
};
|
|
38
|
+
type MermaidErrorComponentProps = {
|
|
39
|
+
error: string;
|
|
40
|
+
chart: string;
|
|
41
|
+
retry: () => void;
|
|
42
|
+
};
|
|
43
|
+
type MermaidOptions = {
|
|
44
|
+
config?: MermaidConfig;
|
|
45
|
+
errorComponent?: React.ComponentType<MermaidErrorComponentProps>;
|
|
46
|
+
};
|
|
23
47
|
type StreamdownProps = Options & {
|
|
48
|
+
mode?: "static" | "streaming";
|
|
24
49
|
BlockComponent?: React.ComponentType<BlockProps>;
|
|
25
50
|
parseMarkdownIntoBlocksFn?: (markdown: string) => string[];
|
|
26
51
|
parseIncompleteMarkdown?: boolean;
|
|
27
52
|
className?: string;
|
|
28
53
|
shikiTheme?: [BundledTheme, BundledTheme];
|
|
29
|
-
|
|
54
|
+
mermaid?: MermaidOptions;
|
|
30
55
|
controls?: ControlsConfig;
|
|
31
56
|
isAnimating?: boolean;
|
|
32
57
|
};
|
|
33
58
|
declare const defaultRehypePlugins: Record<string, Pluggable>;
|
|
34
59
|
declare const defaultRemarkPlugins: Record<string, Pluggable>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
type StreamdownRuntimeContextType = {
|
|
60
|
+
type StreamdownContextType = {
|
|
61
|
+
shikiTheme: [BundledTheme, BundledTheme];
|
|
62
|
+
controls: ControlsConfig;
|
|
39
63
|
isAnimating: boolean;
|
|
64
|
+
mode: "static" | "streaming";
|
|
65
|
+
mermaid?: MermaidOptions;
|
|
40
66
|
};
|
|
41
|
-
declare const
|
|
67
|
+
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
42
68
|
type BlockProps = Options & {
|
|
43
69
|
content: string;
|
|
44
70
|
shouldParseIncompleteMarkdown: boolean;
|
|
45
71
|
index: number;
|
|
46
72
|
};
|
|
47
73
|
declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
48
|
-
declare const Streamdown: react.MemoExoticComponent<({ children, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme,
|
|
74
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
49
75
|
|
|
50
|
-
export { Block, type ControlsConfig,
|
|
76
|
+
export { Block, type ControlsConfig, type MermaidErrorComponentProps, type MermaidOptions, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, defaultRehypePlugins, defaultRemarkPlugins, parseIncompleteMarkdown, parseMarkdownIntoBlocks };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
|
+
import { JSX, ComponentType } from 'react';
|
|
3
4
|
import { MermaidConfig } from 'mermaid';
|
|
4
5
|
export { MermaidConfig } from 'mermaid';
|
|
5
|
-
import { Options } from 'react-markdown';
|
|
6
|
-
export { defaultUrlTransform } from 'react-markdown';
|
|
7
6
|
import { BundledTheme } from 'shiki';
|
|
8
|
-
import { Pluggable } from 'unified';
|
|
7
|
+
import { PluggableList, Pluggable } from 'unified';
|
|
8
|
+
import { Element } from 'hast';
|
|
9
|
+
import { Options as Options$1 } from 'remark-rehype';
|
|
10
|
+
|
|
11
|
+
type ExtraProps = {
|
|
12
|
+
node?: Element | undefined;
|
|
13
|
+
};
|
|
14
|
+
type Components = {
|
|
15
|
+
[Key in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Key] & ExtraProps> | keyof JSX.IntrinsicElements;
|
|
16
|
+
};
|
|
17
|
+
type Options = {
|
|
18
|
+
children?: string;
|
|
19
|
+
components?: Components;
|
|
20
|
+
rehypePlugins?: PluggableList;
|
|
21
|
+
remarkPlugins?: PluggableList;
|
|
22
|
+
remarkRehypeOptions?: Readonly<Options$1>;
|
|
23
|
+
};
|
|
9
24
|
|
|
10
25
|
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
11
26
|
|
|
@@ -20,31 +35,42 @@ type ControlsConfig = boolean | {
|
|
|
20
35
|
fullscreen?: boolean;
|
|
21
36
|
};
|
|
22
37
|
};
|
|
38
|
+
type MermaidErrorComponentProps = {
|
|
39
|
+
error: string;
|
|
40
|
+
chart: string;
|
|
41
|
+
retry: () => void;
|
|
42
|
+
};
|
|
43
|
+
type MermaidOptions = {
|
|
44
|
+
config?: MermaidConfig;
|
|
45
|
+
errorComponent?: React.ComponentType<MermaidErrorComponentProps>;
|
|
46
|
+
};
|
|
23
47
|
type StreamdownProps = Options & {
|
|
48
|
+
mode?: "static" | "streaming";
|
|
24
49
|
BlockComponent?: React.ComponentType<BlockProps>;
|
|
25
50
|
parseMarkdownIntoBlocksFn?: (markdown: string) => string[];
|
|
26
51
|
parseIncompleteMarkdown?: boolean;
|
|
27
52
|
className?: string;
|
|
28
53
|
shikiTheme?: [BundledTheme, BundledTheme];
|
|
29
|
-
|
|
54
|
+
mermaid?: MermaidOptions;
|
|
30
55
|
controls?: ControlsConfig;
|
|
31
56
|
isAnimating?: boolean;
|
|
32
57
|
};
|
|
33
58
|
declare const defaultRehypePlugins: Record<string, Pluggable>;
|
|
34
59
|
declare const defaultRemarkPlugins: Record<string, Pluggable>;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
type StreamdownRuntimeContextType = {
|
|
60
|
+
type StreamdownContextType = {
|
|
61
|
+
shikiTheme: [BundledTheme, BundledTheme];
|
|
62
|
+
controls: ControlsConfig;
|
|
39
63
|
isAnimating: boolean;
|
|
64
|
+
mode: "static" | "streaming";
|
|
65
|
+
mermaid?: MermaidOptions;
|
|
40
66
|
};
|
|
41
|
-
declare const
|
|
67
|
+
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
42
68
|
type BlockProps = Options & {
|
|
43
69
|
content: string;
|
|
44
70
|
shouldParseIncompleteMarkdown: boolean;
|
|
45
71
|
index: number;
|
|
46
72
|
};
|
|
47
73
|
declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
48
|
-
declare const Streamdown: react.MemoExoticComponent<({ children, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme,
|
|
74
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
49
75
|
|
|
50
|
-
export { Block, type ControlsConfig,
|
|
76
|
+
export { Block, type ControlsConfig, type MermaidErrorComponentProps, type MermaidOptions, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, defaultRehypePlugins, defaultRemarkPlugins, parseIncompleteMarkdown, parseMarkdownIntoBlocks };
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
"use client";import{createContext as
|
|
2
|
-
`),o=t>=0?e.slice(0,t+1):"",n=t>=0?e.slice(t+1):e;return[o,n]},Pt=e=>e?[{pre(o){return this.addClassToHast(o,e),o}}]:[],oe=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null;this.loadLanguagePromise=null;this.cache=new Map;this.cacheKeys=[];this.MAX_CACHE_SIZE=50;this.highlightQueue=new Map}isLanguageSupported(t){return Object.hasOwn(yt,t)}getFallbackLanguage(){return"text"}getCacheKey(t,o,n){return`${o}::${n||""}::${t}`}addToCache(t,o){if(this.cache.size>=this.MAX_CACHE_SIZE){let n=this.cacheKeys.shift();n&&this.cache.delete(n)}this.cache.set(t,o),this.cacheKeys.push(t)}needsHighlightersInitialization(t){let[o,n]=t,s=!this.lightHighlighter||this.lightTheme!==o,r=!this.darkHighlighter||this.darkTheme!==n;return[s,r]}async ensureHighlightersInitialized(t,o){let[n,s]=o,[r,i]=t,a=kt({forgiving:!0});this.loadedLanguages.clear(),this.cache.clear(),this.cacheKeys=[],this.highlightQueue.clear(),n&&(this.lightHighlighter=await Te({themes:[r],langs:[],engine:a}),this.lightTheme=r),s&&(this.darkHighlighter=await Te({themes:[i],langs:[],engine:a}),this.darkTheme=i)}async loadLanguage(t){var o,n;await((o=this.darkHighlighter)==null?void 0:o.loadLanguage(t)),await((n=this.lightHighlighter)==null?void 0:n.loadLanguage(t)),this.loadedLanguages.add(t)}async initializeHighlighters(t){this.initializationPromise&&await this.initializationPromise;let o=this.needsHighlightersInitialization(t),[n,s]=o;(n||s)&&(this.initializationPromise=this.ensureHighlightersInitialized(t,o),await this.initializationPromise,this.initializationPromise=null)}performHighlights(t,o,n){let s=this.isLanguageSupported(o)?o:this.getFallbackLanguage();if(this.lightHighlighter===null||this.darkHighlighter===null||this.lightTheme===null||this.darkTheme===null)throw new Error("highlightCode must be called after initializeHighlighters.");let r=Pt(n),i=this.lightHighlighter.codeToHtml(t,{lang:s,theme:this.lightTheme,transformers:r}),a=this.darkHighlighter.codeToHtml(t,{lang:s,theme:this.darkTheme,transformers:r});return[i,a]}async highlightCode(t,o,n,s){let r=this.getCacheKey(t,o,n),i=this.cache.get(r);if(i)return this.cacheKeys=this.cacheKeys.filter(d=>d!==r),this.cacheKeys.push(r),i;let a=this.highlightQueue.get(r);if(a)return a;let l=()=>{if(s!=null&&s.aborted)throw new DOMException("Aborted","AbortError")},c=(async()=>{try{await new Promise(f=>setTimeout(f,0)),l(),this.initializationPromise&&await this.initializationPromise,l(),this.loadLanguagePromise&&await this.loadLanguagePromise,l(),!this.loadedLanguages.has(o)&&this.isLanguageSupported(o)&&(this.loadLanguagePromise=this.loadLanguage(o),await this.loadLanguagePromise,this.loadLanguagePromise=null),l();let g=this.performHighlights(t,o,n);return this.addToCache(r,g),g}finally{this.highlightQueue.delete(r)}})();return this.highlightQueue.set(r,c),c}},ee=new oe,Me=({code:e,language:t,className:o,children:n,preClassName:s,...r})=>{let[i,a]=$(""),[l,c]=$(""),[d,g]=$(""),[f,h]=$(""),m=vt(e),k=L(0),y=L(!1),w=L(null),C=L(0),[D,W]=O(ie);J(()=>{ee.initializeHighlighters([D,W])},[D,W]),J(()=>{y.current=!0,w.current&&w.current.abort(),w.current=new AbortController;let E=w.current.signal;k.current&&clearTimeout(k.current);let[F,q]=Mt(m),ct=m.split(`
|
|
3
|
-
`).length,{minHighlightInterval:dt,debounceMs:mt}=Tt(ct);if(F&&F!==d){let M=Date.now();M-C.current>dt||!q?(C.current=M,ee.highlightCode(F,t,s,E).then(([X,ut])=>{y.current&&!E.aborted&&ve(()=>{a(X),c(ut),g(F),h(q)})}).catch(X=>{if(X.name!=="AbortError")throw X})):h(q)}else h(q);return k.current=window.setTimeout(()=>{q&&m!==d&&!E.aborted&&ee.highlightCode(m,t,s,E).then(([M,ke])=>{y.current&&!E.aborted&&ve(()=>{a(M),c(ke),g(m),h("")})}).catch(M=>{if(M.name!=="AbortError")throw M})},mt),()=>{var M;y.current=!1,(M=w.current)==null||M.abort()}},[m,t,s]);let B=f?`<span class="line"><span>${Ct(f)}</span></span>`:"";return P(ne.Provider,{value:{code:e},children:te("div",{className:"my-4 w-full overflow-hidden rounded-xl border border-border","data-code-block-container":!0,"data-language":t,children:[te("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:[P("span",{className:"ml-1 font-mono lowercase",children:t}),P("div",{className:"flex items-center gap-2",children:n})]}),P("div",{className:"w-full",children:te("div",{className:"min-w-full",children:[P("div",{className:u("overflow-x-auto dark:hidden",o),dangerouslySetInnerHTML:{__html:B?i+B:i},"data-code-block":!0,"data-language":t,...r}),P("div",{className:u("hidden overflow-x-auto dark:block",o),dangerouslySetInnerHTML:{__html:B?l+B:l},"data-code-block":!0,"data-language":t,...r})]})})]})})},Ce={"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"},re=({onDownload:e,onError:t,language:o,children:n,className:s,code:r,...i})=>{let{code:a}=O(ne),{isAnimating:l}=O(N),c=r!=null?r:a,g=`file.${o&&o in Ce?Ce[o]:"txt"}`,f="text/plain",h=()=>{try{A(g,c,f),e==null||e()}catch(m){t==null||t(m)}};return P("button",{className:u("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:l,onClick:h,title:"Download file",type:"button",...i,children:n!=null?n:P(bt,{size:14})})},se=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:s,code:r,...i})=>{let[a,l]=$(!1),c=L(0),{code:d}=O(ne),{isAnimating:g}=O(N),f=r!=null?r:d,h=async()=>{var k;if(typeof window=="undefined"||!((k=navigator==null?void 0:navigator.clipboard)!=null&&k.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{a||(await navigator.clipboard.writeText(f),l(!0),e==null||e(),c.current=window.setTimeout(()=>l(!1),o))}catch(y){t==null||t(y)}};J(()=>()=>{window.clearTimeout(c.current)},[]);let m=a?ht:ft;return P("button",{className:u("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:g,onClick:h,type:"button",...i,children:n!=null?n:P(m,{size:14})})};import{DownloadIcon as Nt}from"lucide-react";import{jsx as K,jsxs as St}from"react/jsx-runtime";var It=/\.[^/.]+$/,Pe=({node:e,className:t,src:o,alt:n,...s})=>{let r=async()=>{if(o)try{let a=await(await fetch(o)).blob(),c=new URL(o,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),g=c.includes(".")&&d!==void 0&&d.length<=4,f="";if(g)f=c;else{let h=a.type,m="png";h.includes("jpeg")||h.includes("jpg")?m="jpg":h.includes("png")?m="png":h.includes("svg")?m="svg":h.includes("gif")?m="gif":h.includes("webp")&&(m="webp"),f=`${(n||c||"image").replace(It,"")}.${m}`}A(f,a,a.type)}catch(i){console.error("Failed to download image:",i)}};return o?St("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[K("img",{alt:n,className:u("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...s}),K("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),K("button",{className:u("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:r,title:"Download image",type:"button",children:K(Nt,{size:14})})]}):null};import{Maximize2Icon as Lt,XIcon as xt}from"lucide-react";import{useContext as Ht,useEffect as ae,useState as z}from"react";import{Fragment as jt,jsx as T,jsxs as j}from"react/jsx-runtime";var _=0,Bt=()=>{_+=1,_===1&&(document.body.style.overflow="hidden")},At=()=>{_=Math.max(0,_-1),_===0&&(document.body.style.overflow="")},$t=async e=>{let o={...{startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0},...e},s=(await import("mermaid")).default;return s.initialize(o),s},Ne=({chart:e,config:t,onFullscreen:o,onExit:n,className:s,...r})=>{let[i,a]=z(!1),{isAnimating:l}=Ht(N),c=()=>{a(!i)};return ae(()=>{if(i){Bt();let d=g=>{g.key==="Escape"&&a(!1)};return document.addEventListener("keydown",d),()=>{document.removeEventListener("keydown",d),At()}}},[i]),ae(()=>{i?o==null||o():n&&n()},[i,o,n]),j(jt,{children:[T("button",{className:u("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:l,onClick:c,title:"View fullscreen",type:"button",...r,children:T(Lt,{size:14})}),i&&j("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:c,onKeyDown:d=>{d.key==="Escape"&&c()},role:"button",tabIndex:0,children:[T("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:c,title:"Exit fullscreen",type:"button",children:T(xt,{size:20})}),T("div",{className:"flex h-full w-full items-center justify-center p-12",onClick:d=>d.stopPropagation(),onKeyDown:d=>d.stopPropagation(),role:"presentation",children:T("div",{className:"max-h-full max-w-full",children:T(le,{chart:e,className:"[&>div]:my-0 [&_svg]:h-auto [&_svg]:min-h-[60vh] [&_svg]:w-auto [&_svg]:min-w-[60vw]",config:t})})})]})]})},le=({chart:e,className:t,config:o})=>{let[n,s]=z(null),[r,i]=z(!0),[a,l]=z(""),[c,d]=z("");if(ae(()=>{(async()=>{try{s(null),i(!0);let h=await $t(o),m=e.split("").reduce((w,C)=>(w<<5)-w+C.charCodeAt(0)|0,0),k=`mermaid-${Math.abs(m)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:y}=await h.render(k,e);l(y),d(y)}catch(h){if(!(c||a)){let m=h instanceof Error?h.message:"Failed to render Mermaid chart";s(m)}}finally{i(!1)}})()},[e,o]),r&&!a&&!c)return T("div",{className:u("my-4 flex justify-center p-4",t),children:j("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(n&&!a&&!c)return j("div",{className:u("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[j("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",n]}),j("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 g=a||c;return T("div",{"aria-label":"Mermaid chart",className:u("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:g},role:"img"})};import{CheckIcon as Rt,CopyIcon as Dt,DownloadIcon as Et}from"lucide-react";import{useContext as Ie,useEffect as Se,useRef as ce,useState as de}from"react";import{jsx as I,jsxs as V}from"react/jsx-runtime";function Le(e){var r,i;let t=[],o=[],n=e.querySelectorAll("thead th");for(let a of n)t.push(((r=a.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let a of s){let l=[],c=a.querySelectorAll("td");for(let d of c)l.push(((i=d.textContent)==null?void 0:i.trim())||"");o.push(l)}return{headers:t,rows:o}}function xe(e){let{headers:t,rows:o}=e,n=r=>r.includes(",")||r.includes('"')||r.includes(`
|
|
4
|
-
`)
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
`)}var He=({children:e,className:t,onCopy:o,onError:n,timeout:s=2e3})=>{let[r,i]=de(!1),[a,l]=de(!1),c=ce(null),d=ce(0),{isAnimating:g}=Ie(N),f=async m=>{var k,y;if(typeof window=="undefined"||!((k=navigator==null?void 0:navigator.clipboard)!=null&&k.write)){n==null||n(new Error("Clipboard API not available"));return}try{let w=(y=c.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),C=w==null?void 0:w.querySelector("table");if(!C){n==null||n(new Error("Table not found"));return}let D=Le(C),W=m==="csv"?xe(D):qt(D),B=new ClipboardItem({"text/plain":new Blob([W],{type:"text/plain"}),"text/html":new Blob([C.outerHTML],{type:"text/html"})});await navigator.clipboard.write([B]),l(!0),i(!1),o==null||o(m),d.current=window.setTimeout(()=>l(!1),s)}catch(w){n==null||n(w)}};Se(()=>{let m=k=>{c.current&&!c.current.contains(k.target)&&i(!1)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m),window.clearTimeout(d.current)}},[]);let h=a?Rt:Dt;return V("div",{className:"relative",ref:c,children:[I("button",{className:u("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:g,onClick:()=>i(!r),title:"Copy table",type:"button",children:e!=null?e:I(h,{size:14})}),r&&V("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[I("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>f("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:()=>f("tsv"),type:"button",children:"TSV"})]})]})};var Be=({children:e,className:t,onDownload:o,onError:n})=>{let[s,r]=de(!1),i=ce(null),{isAnimating:a}=Ie(N),l=c=>{var d;try{let g=(d=i.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),f=g==null?void 0:g.querySelector("table");if(!f){n==null||n(new Error("Table not found"));return}let h=Le(f),m=c==="csv"?xe(h):Ot(h);A(`table.${c==="csv"?"csv":"md"}`,m,c==="csv"?"text/csv":"text/markdown"),r(!1),o==null||o(c)}catch(g){n==null||n(g)}};return Se(()=>{let c=d=>{i.current&&!i.current.contains(d.target)&&r(!1)};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c)}},[]),V("div",{className:"relative",ref:i,children:[I("button",{className:u("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:a,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:I(Et,{size:14})}),s&&V("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[I("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"}),I("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{Fragment as rt,jsx as p,jsxs as U}from"react/jsx-runtime";var zt=/language-([^\s]+)/;function G(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,s=e.position.end,r=t.position.end;return(o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function v(e,t){return e.className===t.className&&G(e.node,t.node)}var pe=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,me=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===!1?!1:o===!0||o===void 0?!0:o[t]!==!1},ge=b(({children:e,className:t,node:o,...n})=>p("ol",{className:u("ml-4 list-outside list-decimal whitespace-normal",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>v(e,t));ge.displayName="MarkdownOl";var Ae=b(({children:e,className:t,node:o,...n})=>p("li",{className:u("py-1",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&G(e.node,t.node));Ae.displayName="MarkdownLi";var $e=b(({children:e,className:t,node:o,...n})=>p("ul",{className:u("ml-4 list-outside list-disc whitespace-normal",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>v(e,t));$e.displayName="MarkdownUl";var je=b(({className:e,node:t,...o})=>p("hr",{className:u("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>v(e,t));je.displayName="MarkdownHr";var Re=b(({children:e,className:t,node:o,...n})=>p("span",{className:u("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>v(e,t));Re.displayName="MarkdownStrong";var De=b(({children:e,className:t,href:o,node:n,...s})=>{let r=o==="streamdown:incomplete-link";return p("a",{className:u("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...s,children:e})},(e,t)=>v(e,t)&&e.href===t.href);De.displayName="MarkdownA";var Ee=b(({children:e,className:t,node:o,...n})=>p("h1",{className:u("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>v(e,t));Ee.displayName="MarkdownH1";var qe=b(({children:e,className:t,node:o,...n})=>p("h2",{className:u("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>v(e,t));qe.displayName="MarkdownH2";var Oe=b(({children:e,className:t,node:o,...n})=>p("h3",{className:u("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>v(e,t));Oe.displayName="MarkdownH3";var ze=b(({children:e,className:t,node:o,...n})=>p("h4",{className:u("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>v(e,t));ze.displayName="MarkdownH4";var _e=b(({children:e,className:t,node:o,...n})=>p("h5",{className:u("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>v(e,t));_e.displayName="MarkdownH5";var Ue=b(({children:e,className:t,node:o,...n})=>p("h6",{className:u("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>v(e,t));Ue.displayName="MarkdownH6";var We=b(({children:e,className:t,node:o,...n})=>{let s=ue(Q),r=pe(s,"table");return U("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[r&&U("div",{className:"flex items-center justify-end gap-1",children:[p(He,{}),p(Be,{})]}),p("div",{className:"overflow-x-auto",children:p("table",{className:u("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]})},(e,t)=>v(e,t));We.displayName="MarkdownTable";var Fe=b(({children:e,className:t,node:o,...n})=>p("thead",{className:u("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>v(e,t));Fe.displayName="MarkdownThead";var Xe=b(({children:e,className:t,node:o,...n})=>p("tbody",{className:u("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>v(e,t));Xe.displayName="MarkdownTbody";var Je=b(({children:e,className:t,node:o,...n})=>p("tr",{className:u("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>v(e,t));Je.displayName="MarkdownTr";var Ke=b(({children:e,className:t,node:o,...n})=>p("th",{className:u("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>v(e,t));Ke.displayName="MarkdownTh";var Ve=b(({children:e,className:t,node:o,...n})=>p("td",{className:u("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>v(e,t));Ve.displayName="MarkdownTd";var Ge=b(({children:e,className:t,node:o,...n})=>p("blockquote",{className:u("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>v(e,t));Ge.displayName="MarkdownBlockquote";var Qe=b(({children:e,className:t,node:o,...n})=>p("sup",{className:u("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>v(e,t));Qe.displayName="MarkdownSup";var Ze=b(({children:e,className:t,node:o,...n})=>p("sub",{className:u("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>v(e,t));Ze.displayName="MarkdownSub";var Ye=b(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let r=l=>{var f,h;if(!R(l))return!1;let c=Array.isArray(l.props.children)?l.props.children:[l.props.children],d=!1,g=!1;for(let m of c)if(m){if(typeof m=="string")m.trim()!==""&&(d=!0);else if(R(m))if(((f=m.props)==null?void 0:f["data-footnote-backref"])!==void 0)g=!0;else{let k=Array.isArray(m.props.children)?m.props.children:[m.props.children];for(let y of k){if(typeof y=="string"&&y.trim()!==""){d=!0;break}if(R(y)&&((h=y.props)==null?void 0:h["data-footnote-backref"])===void 0){d=!0;break}}}}return g&&!d},i=Array.isArray(e)?e.map(l=>{if(!R(l))return l;if(l.type===ge){let d=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(g=>!r(g));return d.length===0?null:{...l,props:{...l.props,children:d}}}return l}):e;return(Array.isArray(i)?i.some(l=>l!==null):i!==null)?p("section",{className:t,...n,children:i}):null}return p("section",{className:t,...n,children:e})},(e,t)=>v(e,t));Ye.displayName="MarkdownSection";var _t=({node:e,className:t,children:o,...n})=>{var g,f,h;let s=((g=e==null?void 0:e.position)==null?void 0:g.start.line)===((f=e==null?void 0:e.position)==null?void 0:f.end.line),r=ue(he),i=ue(Q);if(s)return p("code",{className:u("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let a=t==null?void 0:t.match(zt),l=(h=a==null?void 0:a.at(1))!=null?h:"",c="";if(R(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?c=o.props.children:typeof o=="string"&&(c=o),l==="mermaid"){let m=pe(i,"mermaid"),k=me(i,"download"),y=me(i,"copy"),w=me(i,"fullscreen");return U("div",{className:u("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[m&&(k||y||w)&&U("div",{className:"flex items-center justify-end gap-2",children:[k&&p(re,{code:c,language:l}),y&&p(se,{code:c}),w&&p(Ne,{chart:c,config:r})]}),p(le,{chart:c,config:r})]})}let d=pe(i,"code");return p(Me,{className:u("overflow-x-auto border-border border-t",t),code:c,"data-language":l,"data-streamdown":"code-block",language:l,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:d&&U(rt,{children:[p(re,{code:c,language:l}),p(se,{})]})})},et=b(_t,(e,t)=>e.className===t.className&&G(e.node,t.node));et.displayName="MarkdownCode";var tt=b(Pe,(e,t)=>e.className===t.className&&G(e.node,t.node));tt.displayName="MarkdownImg";var ot=b(({children:e,className:t,node:o,...n})=>{var i;let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");return r.length===1&&R(r[0])&&((i=r[0].props.node)==null?void 0:i.tagName)==="img"?p(rt,{children:e}):p("p",{className:t,...n,children:e})},(e,t)=>v(e,t));ot.displayName="MarkdownParagraph";var nt={ol:ge,li:Ae,ul:$e,hr:je,strong:Re,a:De,h1:Ee,h2:qe,h3:Oe,h4:ze,h5:_e,h6:Ue,table:We,thead:Fe,tbody:Xe,tr:Je,th:Ke,td:Ve,blockquote:Ge,code:et,img:tt,pre:({children:e})=>e,sup:Qe,sub:Ze,p:ot,section:Ye};import{Lexer as Ut}from"marked";var Wt=/\[\^[^\]\s]{1,200}\](?!:)/,Ft=/\[\^[^\]\s]{1,200}\]:/,Xt=/<\/(\w+)>/,Jt=/<(\w+)[\s>]/,fe=e=>{let t=Wt.test(e),o=Ft.test(e);if(t||o)return[e];let n=Ut.lex(e,{gfm:!0}),s=[],r=[];for(let i of n){let a=i.raw;if(r.length>0){if(s[s.length-1]+=a,i.type==="html"){let l=a.match(Xt);if(l){let c=l[1];r.at(-1)===c&&r.pop()}}continue}if(i.type==="html"&&i.block){let l=a.match(Jt);if(l){let c=l[1];a.includes(`</${c}>`)||r.push(c)}}if(a.trim()==="$$"&&s.length>0){let l=s.at(-1);if(!l){s.push(a);continue}let c=l.trimStart().startsWith("$$"),d=(l.match(/\$\$/g)||[]).length;if(c&&d%2===1){s[s.length-1]=l+a;continue}}if(s.length>0&&a.trimEnd().endsWith("$$")){let l=s.at(-1);if(!l){s.push(a);continue}let c=l.trimStart().startsWith("$$"),d=(l.match(/\$\$/g)||[]).length,g=(a.match(/\$\$/g)||[]).length;if(c&&d%2===1&&!a.trimStart().startsWith("$$")&&g===1){s[s.length-1]=l+a;continue}}s.push(a)}return s};var Kt=/(!?\[)([^\]]*?)$/,Vt=/(\*\*)([^*]*?)$/,Gt=/(__)([^_]*?)$/,Qt=/(\*\*\*)([^*]*?)$/,Zt=/(\*)([^*]*?)$/,Yt=/(_)([^_]*?)$/,eo=/(`)([^`]*?)$/,to=/(~~)([^~]*?)$/,oo=/(!?)\[([^\]]+)\]\(([^)]+)$/,x=/^[\s_~*`]*$/,st=/^[\s]*[-*+][\s]+$/,S=/[\p{L}\p{N}_]/u,no=/\n+$/,ro=/^```[^`\n]*```?$/,so=/^\*{4,}$/,Z=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
|
|
8
|
-
`)},io=e=>{let t=e.match(oo);if(t){let n=t[1]==="!",s=t[2],r=t[3],i=e.lastIndexOf(`${n?"!":""}[${s}](${r}`),a=e.substring(0,i);return n?a:`${a}[${s}](streamdown:incomplete-link)`}let o=e.match(Kt);if(o){if(o[1].startsWith("!")){let s=e.lastIndexOf(o[1]);return e.substring(0,s)}return`${e}](streamdown:incomplete-link)`}return e},ao=e=>{if(Z(e))return e;let t=e.match(Vt);if(t){let o=t[2];if(!o||x.test(o))return e;let n=e.lastIndexOf(t[1]),r=e.substring(0,n).lastIndexOf(`
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
`),
|
|
12
|
-
`)
|
|
13
|
-
`)
|
|
1
|
+
"use client";var No=Object.create;var Ze=Object.defineProperty;var Io=Object.getOwnPropertyDescriptor;var So=Object.getOwnPropertyNames;var Bo=Object.getPrototypeOf,Eo=Object.prototype.hasOwnProperty;var Lo=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ao=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of So(t))!Eo.call(e,r)&&r!==o&&Ze(e,r,{get:()=>t[r],enumerable:!(n=Io(t,r))||n.enumerable});return e};var Ro=(e,t,o)=>(o=e!=null?No(Bo(e)):{},Ao(t||!e||!e.__esModule?Ze(o,"default",{value:e,enumerable:!0}):o,e));var lo=Lo((Ji,ao)=>{"use strict";var me=Object.prototype.hasOwnProperty,io=Object.prototype.toString,eo=Object.defineProperty,to=Object.getOwnPropertyDescriptor,oo=function(t){return typeof Array.isArray=="function"?Array.isArray(t):io.call(t)==="[object Array]"},no=function(t){if(!t||io.call(t)!=="[object Object]")return!1;var o=me.call(t,"constructor"),n=t.constructor&&t.constructor.prototype&&me.call(t.constructor.prototype,"isPrototypeOf");if(t.constructor&&!o&&!n)return!1;var r;for(r in t);return typeof r=="undefined"||me.call(t,r)},ro=function(t,o){eo&&o.name==="__proto__"?eo(t,o.name,{enumerable:!0,configurable:!0,value:o.newValue,writable:!0}):t[o.name]=o.newValue},so=function(t,o){if(o==="__proto__")if(me.call(t,o)){if(to)return to(t,o).value}else return;return t[o]};ao.exports=function e(){var t,o,n,r,s,a,i=arguments[0],l=1,c=arguments.length,d=!1;for(typeof i=="boolean"&&(d=i,i=arguments[1]||{},l=2),(i==null||typeof i!="object"&&typeof i!="function")&&(i={});l<c;++l)if(t=arguments[l],t!=null)for(o in t)n=so(i,o),r=so(t,o),i!==r&&(d&&r&&(no(r)||(s=oo(r)))?(s?(s=!1,a=n&&oo(n)?n:[]):a=n&&no(n)?n:{},ro(i,{name:o,newValue:e(d,a,r)})):typeof r!="undefined"&&ro(i,{name:o,newValue:r}));return i}});import{createContext as Ar,memo as Po,useEffect as To,useId as Rr,useMemo as Y,useState as jr,useTransition as $r}from"react";import{harden as Dr}from"rehype-harden";import Je from"rehype-katex";import Hr from"rehype-raw";import Or from"remark-cjk-friendly";import zr from"remark-cjk-friendly-gfm-strikethrough";import qr from"remark-gfm";import _r from"remark-math";import{isValidElement as U,memo as C,useContext as Nt}from"react";import{useContext as Zo,useEffect as Go,useMemo as Yo,useState as Qo}from"react";import{memo as Do,useMemo as Ho}from"react";import{clsx as jo}from"clsx";import{twMerge as $o}from"tailwind-merge";var f=(...e)=>$o(jo(e)),E=(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 Q}from"react/jsx-runtime";var Oo=f("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-4","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),Ge=Do(({children:e,result:t,language:o,className:n,...r})=>{let s=Ho(()=>({backgroundColor:t.bg,color:t.fg}),[t.bg,t.fg]);return Q("pre",{className:f(n,"p-4 text-sm"),"data-code-block":!0,"data-language":o,style:s,...r,children:Q("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:t.tokens.map((a,i)=>Q("span",{className:Oo,children:a.map((l,c)=>Q("span",{style:{color:l.color,backgroundColor:l.bgColor,...l.htmlStyle},...l.htmlAttrs,children:l.content},c))},i))})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className);import{jsx as zo}from"react/jsx-runtime";var Ye=({className:e,language:t,style:o,...n})=>zo("div",{className:f("my-4 w-full overflow-hidden rounded-xl border border-border",e),"data-code-block-container":!0,"data-language":t,style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...n});import{createContext as qo,useContext as _o}from"react";var ye=qo({code:""}),ee=()=>_o(ye);import{jsx as Qe,jsxs as Fo}from"react/jsx-runtime";var et=({language:e,children:t})=>Fo("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-code-block-header":!0,"data-language":e,children:[Qe("span",{className:"ml-1 font-mono lowercase",children:e}),Qe("div",{className:"flex items-center gap-2",children:t})]});import{createHighlighter as Uo}from"shiki";import{createJavaScriptRegexEngine as Wo}from"shiki/engine/javascript";var Vo=Wo({forgiving:!0}),we=new Map,ke=new Map,_=new Map,Xo=(e,t)=>`${e}-${t[0]}-${t[1]}`,Jo=(e,t,o)=>{let n=e.slice(0,100),r=e.length>100?e.slice(-100):"";return`${t}:${o[0]}:${o[1]}:${e.length}:${n}:${r}`},Ko=(e,t)=>{let o=Xo(e,t);if(we.has(o))return we.get(o);let n=Uo({themes:t,langs:[e],engine:Vo});return we.set(o,n),n},Ce=(e,t,o,n)=>{let r=Jo(e,t,o);return ke.has(r)?ke.get(r):(n&&(_.has(r)||_.set(r,new Set),_.get(r).add(n)),Ko(t,o).then(s=>{let a=s.codeToTokens(e,{lang:t,themes:{light:o[0],dark:o[1]}});ke.set(r,a);let i=_.get(r);if(i){for(let l of i)l(a);_.delete(r)}}).catch(s=>{console.error("Failed to highlight code:",s),_.delete(r)}),null)};import{jsx as ve,jsxs as en}from"react/jsx-runtime";var tt=({code:e,language:t,className:o,children:n,preClassName:r,...s})=>{let{shikiTheme:a}=Zo(M),i=Yo(()=>({bg:"transparent",fg:"inherit",tokens:e.split(`
|
|
2
|
+
`).map(d=>[{content:d,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[e]),[l,c]=Qo(i);return Go(()=>{let d=Ce(e,t,a);if(d){c(d);return}Ce(e,t,a,m=>{c(m)})},[e,t,a]),ve(ye.Provider,{value:{code:e},children:en(Ye,{language:t,children:[ve(et,{language:t,children:n}),ve(Ge,{className:o,language:t,result:l,...s})]})})};import{CheckIcon as tn,CopyIcon as on}from"lucide-react";import{useContext as nn,useEffect as rn,useRef as sn,useState as an}from"react";import{jsx as ot}from"react/jsx-runtime";var Me=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:r,code:s,...a})=>{let[i,l]=an(!1),c=sn(0),{code:d}=ee(),{isAnimating:m}=nn(M),p=s!=null?s:d,h=async()=>{var g;if(typeof window=="undefined"||!((g=navigator==null?void 0:navigator.clipboard)!=null&&g.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{i||(await navigator.clipboard.writeText(p),l(!0),e==null||e(),c.current=window.setTimeout(()=>l(!1),o))}catch(y){t==null||t(y)}};rn(()=>()=>{window.clearTimeout(c.current)},[]);let u=i?tn:on;return ot("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:m,onClick:h,type:"button",...a,children:n!=null?n:ot(u,{size:14})})};import{DownloadIcon as ln}from"lucide-react";import{useContext as cn}from"react";import{jsx as rt}from"react/jsx-runtime";var nt={"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"},st=({onDownload:e,onError:t,language:o,children:n,className:r,code:s,...a})=>{let{code:i}=ee(),{isAnimating:l}=cn(M),c=s!=null?s:i,m=`file.${o&&o in nt?nt[o]:"txt"}`,p="text/plain",h=()=>{try{E(m,c,p),e==null||e()}catch(u){t==null||t(u)}};return rt("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:l,onClick:h,title:"Download file",type:"button",...a,children:n!=null?n:rt(ln,{size:14})})};import{DownloadIcon as dn}from"lucide-react";import{jsx as te,jsxs as pn}from"react/jsx-runtime";var mn=/\.[^/.]+$/,it=({node:e,className:t,src:o,alt:n,...r})=>{let s=async()=>{if(o)try{let i=await(await fetch(o)).blob(),c=new URL(o,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),m=c.includes(".")&&d!==void 0&&d.length<=4,p="";if(m)p=c;else{let h=i.type,u="png";h.includes("jpeg")||h.includes("jpg")?u="jpg":h.includes("png")?u="png":h.includes("svg")?u="svg":h.includes("gif")?u="gif":h.includes("webp")&&(u="webp"),p=`${(n||c||"image").replace(mn,"")}.${u}`}E(p,i,i.type)}catch(a){console.error("Failed to download image:",a)}};return o?pn("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[te("img",{alt:n,className:f("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...r}),te("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),te("button",{className:f("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:s,title:"Download image",type:"button",children:te(dn,{size:14})})]}):null};import{useContext as gn,useEffect as bn,useState as X}from"react";import{RotateCcwIcon as un,ZoomInIcon as fn,ZoomOutIcon as hn}from"lucide-react";import{useCallback as A,useEffect as at,useRef as lt,useState as V}from"react";import{jsx as D,jsxs as ct}from"react/jsx-runtime";var dt=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:r=.1,showControls:s=!0,initialZoom:a=1,fullscreen:i=!1})=>{let l=lt(null),c=lt(null),[d,m]=V(a),[p,h]=V({x:0,y:0}),[u,g]=V(!1),[y,k]=V({x:0,y:0}),[P,N]=V({x:0,y:0}),x=A(w=>{m(I=>Math.max(o,Math.min(n,I+w)))},[o,n]),L=A(()=>{x(r)},[x,r]),$=A(()=>{x(-r)},[x,r]),z=A(()=>{m(a),h({x:0,y:0})},[a]),B=A(w=>{w.preventDefault();let I=w.deltaY>0?-r:r;x(I)},[x,r]),q=A(w=>{if(w.button!==0||w.isPrimary===!1)return;g(!0),k({x:w.clientX,y:w.clientY}),N(p);let I=w.currentTarget;I instanceof HTMLElement&&I.setPointerCapture(w.pointerId)},[p]),be=A(w=>{if(!u)return;w.preventDefault();let I=w.clientX-y.x,Ke=w.clientY-y.y;h({x:P.x+I,y:P.y+Ke})},[u,y,P]),W=A(w=>{g(!1);let I=w.currentTarget;I instanceof HTMLElement&&I.releasePointerCapture(w.pointerId)},[]);return at(()=>{let w=l.current;if(w)return w.addEventListener("wheel",B,{passive:!1}),()=>{w.removeEventListener("wheel",B)}},[B]),at(()=>{let w=c.current;if(w&&u)return document.body.style.userSelect="none",w.addEventListener("pointermove",be,{passive:!1}),w.addEventListener("pointerup",W),w.addEventListener("pointercancel",W),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",be),w.removeEventListener("pointerup",W),w.removeEventListener("pointercancel",W)}},[u,be,W]),ct("div",{className:f("relative",i?"h-full w-full":"w-full",t),ref:l,style:{cursor:u?"grabbing":"grab"},children:[s&&ct("div",{className:f("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",i?"bottom-4 left-4":"bottom-2 left-2"),children:[D("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d>=n,onClick:L,title:"Zoom in",type:"button",children:D(fn,{size:16})}),D("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d<=o,onClick:$,title:"Zoom out",type:"button",children:D(hn,{size:16})}),D("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:z,title:"Reset zoom and pan",type:"button",children:D(un,{size:16})})]}),D("div",{className:f("origin-center transition-transform duration-150 ease-out",i&&"flex h-full w-full items-center justify-center"),onPointerDown:q,ref:c,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var oe=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},mt=(e,t)=>{var n;let o=(n=t==null?void 0:t.scale)!=null?n:5;return new Promise((r,s)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),i=new Image;i.crossOrigin="anonymous",i.onload=()=>{let l=document.createElement("canvas"),c=i.width*o,d=i.height*o;l.width=c,l.height=d;let m=l.getContext("2d");if(!m){s(new Error("Failed to create 2D canvas context for PNG export"));return}m.drawImage(i,0,0,c,d),l.toBlob(p=>{if(!p){s(new Error("Failed to create PNG blob"));return}r(p)},"image/png")},i.onerror=()=>s(new Error("Failed to load SVG image")),i.src=a})};import{jsx as R,jsxs as ne}from"react/jsx-runtime";var re=({chart:e,className:t,config:o,fullscreen:n=!1})=>{let[r,s]=X(null),[a,i]=X(!0),[l,c]=X(""),[d,m]=X(""),[p,h]=X(0),{mermaid:u}=gn(M),g=u==null?void 0:u.errorComponent;if(bn(()=>{(async()=>{try{s(null),i(!0);let P=await oe(o),N=e.split("").reduce(($,z)=>($<<5)-$+z.charCodeAt(0)|0,0),x=`mermaid-${Math.abs(N)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:L}=await P.render(x,e);c(L),m(L)}catch(P){if(!(d||l)){let N=P instanceof Error?P.message:"Failed to render Mermaid chart";s(N)}}finally{i(!1)}})()},[e,o,p]),a&&!l&&!d)return R("div",{className:f("my-4 flex justify-center p-4",t),children:ne("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[R("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),R("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!l&&!d){let k=()=>h(P=>P+1);return g?R(g,{chart:e,error:r,retry:k}):ne("div",{className:f("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[ne("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),ne("details",{className:"mt-2",children:[R("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),R("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let y=l||d;return R(dt,{className:f(n?"h-full w-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:!0,zoomStep:.1,children:R("div",{"aria-label":"Mermaid chart",className:f("flex justify-center",n&&"h-full w-full items-center"),dangerouslySetInnerHTML:{__html:y},role:"img"})})};import{DownloadIcon as yn}from"lucide-react";import{useContext as wn,useEffect as kn,useRef as Cn,useState as vn}from"react";import{jsx as J,jsxs as pt}from"react/jsx-runtime";var ut=({chart:e,children:t,className:o,onDownload:n,config:r,onError:s})=>{let[a,i]=vn(!1),l=Cn(null),{isAnimating:c}=wn(M),d=async m=>{try{if(m==="mmd"){E("diagram.mmd",e,"text/plain"),i(!1),n==null||n(m);return}let p=await oe(r),h=e.split("").reduce((y,k)=>(y<<5)-y+k.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(h)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:g}=await p.render(u,e);if(!g){s==null||s(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){E("diagram.svg",g,"image/svg+xml"),i(!1),n==null||n(m);return}if(m==="png"){let y=await mt(g);E("diagram.png",y,"image/png"),n==null||n(m),i(!1);return}}catch(p){s==null||s(p)}};return kn(()=>{let m=p=>{l.current&&!l.current.contains(p.target)&&i(!1)};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m)}},[]),pt("div",{className:"relative",ref:l,children:[J("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:c,onClick:()=>i(!a),title:"Download diagram",type:"button",children:t!=null?t:J(yn,{size:14})}),a&&pt("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[J("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),type:"button",children:"SVG"}),J("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),type:"button",children:"PNG"}),J("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),type:"button",children:"MMD"})]})]})};import{Maximize2Icon as Mn,XIcon as Tn}from"lucide-react";import{useContext as Pn,useEffect as ft,useState as xn}from"react";import{Fragment as Sn,jsx as F,jsxs as ht}from"react/jsx-runtime";var K=0,Nn=()=>{K+=1,K===1&&(document.body.style.overflow="hidden")},In=()=>{K=Math.max(0,K-1),K===0&&(document.body.style.overflow="")},gt=({chart:e,config:t,onFullscreen:o,onExit:n,className:r,...s})=>{let[a,i]=xn(!1),{isAnimating:l}=Pn(M),c=()=>{i(!a)};return ft(()=>{if(a){Nn();let d=m=>{m.key==="Escape"&&i(!1)};return document.addEventListener("keydown",d),()=>{document.removeEventListener("keydown",d),In()}}},[a]),ft(()=>{a?o==null||o():n&&n()},[a,o,n]),ht(Sn,{children:[F("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",r),disabled:l,onClick:c,title:"View fullscreen",type:"button",...s,children:F(Mn,{size:14})}),a&&ht("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:c,onKeyDown:d=>{d.key==="Escape"&&c()},role:"button",tabIndex:0,children:[F("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:c,title:"Exit fullscreen",type:"button",children:F(Tn,{size:20})}),F("div",{className:"flex h-full w-full items-center justify-center p-4",onClick:d=>d.stopPropagation(),onKeyDown:d=>d.stopPropagation(),role:"presentation",children:F(re,{chart:e,className:"h-full w-full [&>div]:h-full [&>div]:overflow-hidden [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:!0})})]})]})};import{CheckIcon as Bn,CopyIcon as En}from"lucide-react";import{useContext as Ln,useEffect as An,useRef as wt,useState as kt}from"react";var se=e=>{var s,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let i of n)t.push(((s=i.textContent)==null?void 0:s.trim())||"");let r=e.querySelectorAll("tbody tr");for(let i of r){let l=[],c=i.querySelectorAll("td");for(let d of c)l.push(((a=d.textContent)==null?void 0:a.trim())||"");o.push(l)}return{headers:t,rows:o}},ie=e=>{let{headers:t,rows:o}=e,n=i=>{let l=!1,c=!1;for(let d=0;d<i.length;d+=1){let m=i[d];if(m==='"'){l=!0,c=!0;break}(m===","||m===`
|
|
3
|
+
`)&&(l=!0)}return l?c?`"${i.replace(/"/g,'""')}"`:`"${i}"`:i},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(","),a+=1);for(let i of o)s[a]=i.map(n).join(","),a+=1;return s.join(`
|
|
4
|
+
`)},bt=e=>{let{headers:t,rows:o}=e,n=i=>{let l=!1;for(let d=0;d<i.length;d+=1){let m=i[d];if(m===" "||m===`
|
|
5
|
+
`||m==="\r"){l=!0;break}}if(!l)return i;let c=[];for(let d=0;d<i.length;d+=1){let m=i[d];m===" "?c.push("\\t"):m===`
|
|
6
|
+
`?c.push("\\n"):m==="\r"?c.push("\\r"):c.push(m)}return c.join("")},r=t.length>0?o.length+1:o.length,s=new Array(r),a=0;t.length>0&&(s[a]=t.map(n).join(" "),a+=1);for(let i of o)s[a]=i.map(n).join(" "),a+=1;return s.join(`
|
|
7
|
+
`)},Te=e=>{let t=!1;for(let n=0;n<e.length;n+=1){let r=e[n];if(r==="\\"||r==="|"){t=!0;break}}if(!t)return e;let o=[];for(let n=0;n<e.length;n+=1){let r=e[n];r==="\\"?o.push("\\\\"):r==="|"?o.push("\\|"):o.push(r)}return o.join("")},yt=e=>{let{headers:t,rows:o}=e;if(t.length===0)return"";let n=new Array(o.length+2),r=0,s=t.map(i=>Te(i));n[r]=`| ${s.join(" | ")} |`,r+=1;let a=new Array(t.length);for(let i=0;i<t.length;i+=1)a[i]="---";n[r]=`| ${a.join(" | ")} |`,r+=1;for(let i of o)if(i.length<t.length){let l=new Array(t.length);for(let c=0;c<t.length;c+=1)l[c]=c<i.length?Te(i[c]):"";n[r]=`| ${l.join(" | ")} |`,r+=1}else{let l=i.map(c=>Te(c));n[r]=`| ${l.join(" | ")} |`,r+=1}return n.join(`
|
|
8
|
+
`)};import{jsx as ae,jsxs as Ct}from"react/jsx-runtime";var vt=({children:e,className:t,onCopy:o,onError:n,timeout:r=2e3})=>{let[s,a]=kt(!1),[i,l]=kt(!1),c=wt(null),d=wt(0),{isAnimating:m}=Ln(M),p=async u=>{var g,y;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{let k=(y=c.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),P=k==null?void 0:k.querySelector("table");if(!P){n==null||n(new Error("Table not found"));return}let N=se(P),x=u==="csv"?ie(N):bt(N),L=new ClipboardItem({"text/plain":new Blob([x],{type:"text/plain"}),"text/html":new Blob([P.outerHTML],{type:"text/html"})});await navigator.clipboard.write([L]),l(!0),a(!1),o==null||o(u),d.current=window.setTimeout(()=>l(!1),r)}catch(k){n==null||n(k)}};An(()=>{let u=g=>{c.current&&!c.current.contains(g.target)&&a(!1)};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current)}},[]);let h=i?Bn:En;return Ct("div",{className:"relative",ref:c,children:[ae("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>a(!s),title:"Copy table",type:"button",children:e!=null?e:ae(h,{size:14})}),s&&Ct("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[ae("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),type:"button",children:"CSV"}),ae("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),type:"button",children:"TSV"})]})]})};import{DownloadIcon as Rn}from"lucide-react";import{useContext as jn,useEffect as $n,useRef as Dn,useState as Hn}from"react";import{jsx as le,jsxs as Mt}from"react/jsx-runtime";var Tt=({children:e,className:t,onDownload:o,onError:n})=>{let[r,s]=Hn(!1),a=Dn(null),{isAnimating:i}=jn(M),l=c=>{var d;try{let m=(d=a.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),p=m==null?void 0:m.querySelector("table");if(!p){n==null||n(new Error("Table not found"));return}let h=se(p),u=c==="csv"?ie(h):yt(h);E(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),s(!1),o==null||o(c)}catch(m){n==null||n(m)}};return $n(()=>{let c=d=>{a.current&&!a.current.contains(d.target)&&s(!1)};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c)}},[]),Mt("div",{className:"relative",ref:a,children:[le("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:i,onClick:()=>s(!r),title:"Download table",type:"button",children:e!=null?e:le(Rn,{size:14})}),r&&Mt("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[le("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"}),le("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 ce,jsxs as Pt}from"react/jsx-runtime";var xt=({children:e,className:t,showControls:o,...n})=>Pt("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[o&&Pt("div",{className:"flex items-center justify-end gap-1",children:[ce(vt,{}),ce(Tt,{})]}),ce("div",{className:"overflow-x-auto",children:ce("table",{className:f("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});import{Fragment as Qt,jsx as b,jsxs as xe}from"react/jsx-runtime";var On=/language-([^\s]+)/;function de(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 v(e,t){return e.className===t.className&&de(e.node,t.node)}var Ne=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,Pe=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===!1?!1:o===!0||o===void 0?!0:o[t]!==!1},Ie=C(({children:e,className:t,node:o,...n})=>b("ol",{className:f("list-inside list-decimal whitespace-normal",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>v(e,t));Ie.displayName="MarkdownOl";var It=C(({children:e,className:t,node:o,...n})=>b("li",{className:f("py-1",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&de(e.node,t.node));It.displayName="MarkdownLi";var St=C(({children:e,className:t,node:o,...n})=>b("ul",{className:f("list-inside list-disc whitespace-normal",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>v(e,t));St.displayName="MarkdownUl";var Bt=C(({className:e,node:t,...o})=>b("hr",{className:f("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>v(e,t));Bt.displayName="MarkdownHr";var Et=C(({children:e,className:t,node:o,...n})=>b("span",{className:f("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>v(e,t));Et.displayName="MarkdownStrong";var Lt=C(({children:e,className:t,href:o,node:n,...r})=>{let s=o==="streamdown:incomplete-link";return b("a",{className:f("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)=>v(e,t)&&e.href===t.href);Lt.displayName="MarkdownA";var At=C(({children:e,className:t,node:o,...n})=>b("h1",{className:f("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>v(e,t));At.displayName="MarkdownH1";var Rt=C(({children:e,className:t,node:o,...n})=>b("h2",{className:f("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>v(e,t));Rt.displayName="MarkdownH2";var jt=C(({children:e,className:t,node:o,...n})=>b("h3",{className:f("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>v(e,t));jt.displayName="MarkdownH3";var $t=C(({children:e,className:t,node:o,...n})=>b("h4",{className:f("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>v(e,t));$t.displayName="MarkdownH4";var Dt=C(({children:e,className:t,node:o,...n})=>b("h5",{className:f("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>v(e,t));Dt.displayName="MarkdownH5";var Ht=C(({children:e,className:t,node:o,...n})=>b("h6",{className:f("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>v(e,t));Ht.displayName="MarkdownH6";var Ot=C(({children:e,className:t,node:o,...n})=>{let{controls:r}=Nt(M),s=Ne(r,"table");return b(xt,{className:t,"data-streamdown":"table-wrapper",showControls:s,...n,children:e})},(e,t)=>v(e,t));Ot.displayName="MarkdownTable";var zt=C(({children:e,className:t,node:o,...n})=>b("thead",{className:f("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>v(e,t));zt.displayName="MarkdownThead";var qt=C(({children:e,className:t,node:o,...n})=>b("tbody",{className:f("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>v(e,t));qt.displayName="MarkdownTbody";var _t=C(({children:e,className:t,node:o,...n})=>b("tr",{className:f("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>v(e,t));_t.displayName="MarkdownTr";var Ft=C(({children:e,className:t,node:o,...n})=>b("th",{className:f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>v(e,t));Ft.displayName="MarkdownTh";var Ut=C(({children:e,className:t,node:o,...n})=>b("td",{className:f("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>v(e,t));Ut.displayName="MarkdownTd";var Wt=C(({children:e,className:t,node:o,...n})=>b("blockquote",{className:f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>v(e,t));Wt.displayName="MarkdownBlockquote";var Vt=C(({children:e,className:t,node:o,...n})=>b("sup",{className:f("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>v(e,t));Vt.displayName="MarkdownSup";var Xt=C(({children:e,className:t,node:o,...n})=>b("sub",{className:f("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>v(e,t));Xt.displayName="MarkdownSub";var Jt=C(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let s=l=>{var p,h;if(!U(l))return!1;let c=Array.isArray(l.props.children)?l.props.children:[l.props.children],d=!1,m=!1;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=!0);else if(U(u))if(((p=u.props)==null?void 0:p["data-footnote-backref"])!==void 0)m=!0;else{let g=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let y of g){if(typeof y=="string"&&y.trim()!==""){d=!0;break}if(U(y)&&((h=y.props)==null?void 0:h["data-footnote-backref"])===void 0){d=!0;break}}}}return m&&!d},a=Array.isArray(e)?e.map(l=>{if(!U(l))return l;if(l.type===Ie){let d=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(m=>!s(m));return d.length===0?null:{...l,props:{...l.props,children:d}}}return l}):e;return(Array.isArray(a)?a.some(l=>l!==null):a!==null)?b("section",{className:t,...n,children:a}):null}return b("section",{className:t,...n,children:e})},(e,t)=>v(e,t));Jt.displayName="MarkdownSection";var zn=({node:e,className:t,children:o,...n})=>{var m,p,h;let r=((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((p=e==null?void 0:e.position)==null?void 0:p.end.line),{mermaid:s,controls:a}=Nt(M);if(r)return b("code",{className:f("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let i=t==null?void 0:t.match(On),l=(h=i==null?void 0:i.at(1))!=null?h:"",c="";if(U(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?c=o.props.children:typeof o=="string"&&(c=o),l==="mermaid"){let u=Ne(a,"mermaid"),g=Pe(a,"download"),y=Pe(a,"copy"),k=Pe(a,"fullscreen");return xe("div",{className:f("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[u&&(g||y||k)&&xe("div",{className:"flex items-center justify-end gap-2",children:[g&&b(ut,{chart:c,config:s==null?void 0:s.config}),y&&b(Me,{code:c}),k&&b(gt,{chart:c,config:s==null?void 0:s.config})]}),b(re,{chart:c,config:s==null?void 0:s.config})]})}let d=Ne(a,"code");return b(tt,{className:f("overflow-x-auto border-border border-t",t),code:c,"data-language":l,"data-streamdown":"code-block",language:l,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:d&&xe(Qt,{children:[b(st,{code:c,language:l}),b(Me,{})]})})},Kt=C(zn,(e,t)=>e.className===t.className&&de(e.node,t.node));Kt.displayName="MarkdownCode";var Zt=C(it,(e,t)=>e.className===t.className&&de(e.node,t.node));Zt.displayName="MarkdownImg";var Gt=C(({children:e,className:t,node:o,...n})=>{var a;let s=(Array.isArray(e)?e:[e]).filter(i=>i!=null&&i!=="");return s.length===1&&U(s[0])&&((a=s[0].props.node)==null?void 0:a.tagName)==="img"?b(Qt,{children:e}):b("p",{className:t,...n,children:e})},(e,t)=>v(e,t));Gt.displayName="MarkdownParagraph";var Yt={ol:Ie,li:It,ul:St,hr:Bt,strong:Et,a:Lt,h1:At,h2:Rt,h3:jt,h4:$t,h5:Dt,h6:Ht,table:Ot,thead:zt,tbody:qt,tr:_t,th:Ft,td:Ut,blockquote:Wt,code:Kt,img:Zt,pre:({children:e})=>e,sup:Vt,sub:Xt,p:Gt,section:Jt};import{toJsxRuntime as Vn}from"hast-util-to-jsx-runtime";import{Fragment as Xn,jsx as Jn,jsxs as Kn}from"react/jsx-runtime";import Zn from"remark-parse";import Gn from"remark-rehype";function Se(e){if(e)throw e}var fe=Ro(lo(),1);function Z(e){if(typeof e!="object"||e===null)return!1;let t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function Be(){let e=[],t={run:o,use:n};return t;function o(...r){let s=-1,a=r.pop();if(typeof a!="function")throw new TypeError("Expected function as last argument, not "+a);i(null,...r);function i(l,...c){let d=e[++s],m=-1;if(l){a(l);return}for(;++m<r.length;)(c[m]===null||c[m]===void 0)&&(c[m]=r[m]);r=c,d?co(d,i)(...c):a(null,...c)}}function n(r){if(typeof r!="function")throw new TypeError("Expected `middelware` to be a function, not "+r);return e.push(r),t}}function co(e,t){let o;return n;function n(...a){let i=e.length>a.length,l;i&&a.push(r);try{l=e.apply(this,a)}catch(c){let d=c;if(i&&o)throw d;return r(d)}i||(l&&l.then&&typeof l.then=="function"?l.then(s,r):l instanceof Error?r(l):s(l))}function r(a,...i){o||(o=!0,t(a,...i))}function s(a){r(null,a)}}function Le(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?mo(e.position):"start"in e||"end"in e?mo(e):"line"in e||"column"in e?Ee(e):""}function Ee(e){return po(e&&e.line)+":"+po(e&&e.column)}function mo(e){return Ee(e&&e.start)+"-"+Ee(e&&e.end)}function po(e){return e&&typeof e=="number"?e:1}var T=class extends Error{constructor(t,o,n){super(),typeof o=="string"&&(n=o,o=void 0);let r="",s={},a=!1;if(o&&("line"in o&&"column"in o?s={place:o}:"start"in o&&"end"in o?s={place:o}:"type"in o?s={ancestors:[o],place:o.position}:s={...o}),typeof t=="string"?r=t:!s.cause&&t&&(a=!0,r=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof n=="string"){let l=n.indexOf(":");l===-1?s.ruleId=n:(s.source=n.slice(0,l),s.ruleId=n.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){let l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}let i=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=i?i.column:void 0,this.fatal=void 0,this.file="",this.message=r,this.line=i?i.line:void 0,this.name=Le(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=a&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}};T.prototype.file="";T.prototype.name="";T.prototype.reason="";T.prototype.message="";T.prototype.stack="";T.prototype.column=void 0;T.prototype.line=void 0;T.prototype.ancestors=void 0;T.prototype.cause=void 0;T.prototype.fatal=void 0;T.prototype.place=void 0;T.prototype.ruleId=void 0;T.prototype.source=void 0;import{default as S}from"path";import{default as uo}from"process";import{fileURLToPath as fo}from"url";function pe(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}var Ae=["history","path","basename","stem","extname","dirname"],G=class{constructor(t){let o;t?pe(t)?o={path:t}:typeof t=="string"||qn(t)?o={value:t}:o=t:o={},this.cwd="cwd"in o?"":uo.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let n=-1;for(;++n<Ae.length;){let s=Ae[n];s in o&&o[s]!==void 0&&o[s]!==null&&(this[s]=s==="history"?[...o[s]]:o[s])}let r;for(r in o)Ae.includes(r)||(this[r]=o[r])}get basename(){return typeof this.path=="string"?S.basename(this.path):void 0}set basename(t){je(t,"basename"),Re(t,"basename"),this.path=S.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?S.dirname(this.path):void 0}set dirname(t){ho(this.basename,"dirname"),this.path=S.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?S.extname(this.path):void 0}set extname(t){if(Re(t,"extname"),ho(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=S.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){pe(t)&&(t=fo(t)),je(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?S.basename(this.path,this.extname):void 0}set stem(t){je(t,"stem"),Re(t,"stem"),this.path=S.join(this.dirname||"",t+(this.extname||""))}fail(t,o,n){let r=this.message(t,o,n);throw r.fatal=!0,r}info(t,o,n){let r=this.message(t,o,n);return r.fatal=void 0,r}message(t,o,n){let r=new T(t,o,n);return this.path&&(r.name=this.path+":"+r.name,r.file=this.path),r.fatal=!1,this.messages.push(r),r}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}};function Re(e,t){if(e&&e.includes(S.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+S.sep+"`")}function je(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function ho(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function qn(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}var go=(function(e){let n=this.constructor.prototype,r=n[e],s=function(){return r.apply(s,arguments)};return Object.setPrototypeOf(s,n),s});var _n={}.hasOwnProperty,Oe=class e extends go{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=Be()}copy(){let t=new e,o=-1;for(;++o<this.attachers.length;){let n=this.attachers[o];t.use(...n)}return t.data((0,fe.default)(!0,{},this.namespace)),t}data(t,o){return typeof t=="string"?arguments.length===2?(He("data",this.frozen),this.namespace[t]=o,this):_n.call(this.namespace,t)&&this.namespace[t]||void 0:t?(He("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;let t=this;for(;++this.freezeIndex<this.attachers.length;){let[o,...n]=this.attachers[this.freezeIndex];if(n[0]===!1)continue;n[0]===!0&&(n[0]=void 0);let r=o.call(t,...n);typeof r=="function"&&this.transformers.use(r)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();let o=ue(t),n=this.parser||this.Parser;return $e("parse",n),n(String(o),o)}process(t,o){let n=this;return this.freeze(),$e("process",this.parser||this.Parser),De("process",this.compiler||this.Compiler),o?r(void 0,o):new Promise(r);function r(s,a){let i=ue(t),l=n.parse(i);n.run(l,i,function(d,m,p){if(d||!m||!p)return c(d);let h=m,u=n.stringify(h,p);Un(u)?p.value=u:p.result=u,c(d,p)});function c(d,m){d||!m?a(d):s?s(m):o(void 0,m)}}}processSync(t){let o=!1,n;return this.freeze(),$e("processSync",this.parser||this.Parser),De("processSync",this.compiler||this.Compiler),this.process(t,r),yo("processSync","process",o),n;function r(s,a){o=!0,Se(s),n=a}}run(t,o,n){bo(t),this.freeze();let r=this.transformers;return!n&&typeof o=="function"&&(n=o,o=void 0),n?s(void 0,n):new Promise(s);function s(a,i){let l=ue(o);r.run(t,l,c);function c(d,m,p){let h=m||t;d?i(d):a?a(h):n(void 0,h,p)}}}runSync(t,o){let n=!1,r;return this.run(t,o,s),yo("runSync","run",n),r;function s(a,i){Se(a),r=i,n=!0}}stringify(t,o){this.freeze();let n=ue(o),r=this.compiler||this.Compiler;return De("stringify",r),bo(t),r(t,n)}use(t,...o){let n=this.attachers,r=this.namespace;if(He("use",this.frozen),t!=null)if(typeof t=="function")l(t,o);else if(typeof t=="object")Array.isArray(t)?i(t):a(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(c){if(typeof c=="function")l(c,[]);else if(typeof c=="object")if(Array.isArray(c)){let[d,...m]=c;l(d,m)}else a(c);else throw new TypeError("Expected usable value, not `"+c+"`")}function a(c){if(!("plugins"in c)&&!("settings"in c))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");i(c.plugins),c.settings&&(r.settings=(0,fe.default)(!0,r.settings,c.settings))}function i(c){let d=-1;if(c!=null)if(Array.isArray(c))for(;++d<c.length;){let m=c[d];s(m)}else throw new TypeError("Expected a list of plugins, not `"+c+"`")}function l(c,d){let m=-1,p=-1;for(;++m<n.length;)if(n[m][0]===c){p=m;break}if(p===-1)n.push([c,...d]);else if(d.length>0){let[h,...u]=d,g=n[p][1];Z(g)&&Z(h)&&(h=(0,fe.default)(!0,g,h)),n[p]=[c,h,...u]}}}},ze=new Oe().freeze();function $e(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function De(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function He(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function bo(e){if(!Z(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function yo(e,t,o){if(!o)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function ue(e){return Fn(e)?e:new G(e)}function Fn(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Un(e){return typeof e=="string"||Wn(e)}function Wn(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}var wo=[],ko={allowDangerousHtml:!0},he=new WeakMap,qe=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,r=t.remarkPlugins,s=t.remarkRehypeOptions;if(!(n||r||s)){let m="default";return this.keyCache.set(t,m),m}let a=m=>{if(!m||m.length===0)return"";let p="";for(let h=0;h<m.length;h+=1){let u=m[h];if(h>0&&(p+=","),Array.isArray(u)){let[g,y]=u;if(typeof g=="function"){let k=he.get(g);k||(k=g.name,he.set(g,k)),p+=k}else p+=String(g);p+=":",p+=JSON.stringify(y)}else if(typeof u=="function"){let g=he.get(u);g||(g=u.name,he.set(u,g)),p+=g}else p+=String(u)}return p},i=a(n),l=a(r),c=s?JSON.stringify(s):"",d=`${l}::${i}::${c}`;return this.keyCache.set(t,d),d}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let r=this.cache.keys().next().value;r&&this.cache.delete(r)}this.cache.set(n,o)}clear(){this.cache.clear()}},Co=new qe,_e=e=>{let t=Yn(e),o=e.children||"";return er(t.runSync(t.parse(o),o),e)},Yn=e=>{let t=Co.get(e);if(t)return t;let o=Qn(e);return Co.set(e,o),o},Qn=e=>{let t=e.rehypePlugins||wo,o=e.remarkPlugins||wo,n=e.remarkRehypeOptions?{...ko,...e.remarkRehypeOptions}:ko;return ze().use(Zn).use(o).use(Gn,n).use(t)},er=(e,t)=>Vn(e,{Fragment:Xn,components:t.components,ignoreInvalidStyle:!0,jsx:Jn,jsxs:Kn,passKeys:!0,passNode:!0});import{Lexer as tr}from"marked";var or=/\[\^[^\]\s]{1,200}\](?!:)/,nr=/\[\^[^\]\s]{1,200}\]:/,rr=/<\/(\w+)>/,sr=/<(\w+)[\s>]/,Fe=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},ir=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Ue=e=>{let t=0;for(let o=0;o<e.length-1;o+=1)e[o]==="$"&&e[o+1]==="$"&&(t+=1,o+=1);return t},We=e=>{let t=or.test(e),o=nr.test(e);if(t||o)return[e];let n=tr.lex(e,{gfm:!0}),r=[],s=[];for(let a of n){let i=a.raw,l=r.length;if(s.length>0){if(r[l-1]+=i,a.type==="html"){let d=i.match(rr);if(d){let m=d[1];s.at(-1)===m&&s.pop()}}continue}if(a.type==="html"&&a.block){let d=i.match(sr);if(d){let m=d[1];i.includes(`</${m}>`)||s.push(m)}}if(i.trim()==="$$"&&l>0){let d=r[l-1],m=Fe(d),p=Ue(d);if(m&&p%2===1){r[l-1]=d+i;continue}}if(l>0&&ir(i)){let d=r[l-1],m=Fe(d),p=Ue(d),h=Ue(i);if(m&&p%2===1&&!Fe(i)&&h===1){r[l-1]=d+i;continue}}r.push(i)}return r};var ar=/(\*\*)([^*]*?)$/,lr=/(__)([^_]*?)$/,cr=/(\*\*\*)([^*]*?)$/,dr=/(\*)([^*]*?)$/,mr=/(_)([^_]*?)$/,pr=/(`)([^`]*?)$/,ur=/(~~)([^~]*?)$/,H=/^[\s_~*`]*$/,vo=/^[\s]*[-*+][\s]+$/,fr=/[\p{L}\p{N}_]/u,hr=/^```[^`\n]*```?$/,gr=/^\*{4,}$/,j=e=>{if(!e)return!1;let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||t===95?!0:fr.test(e)},ge=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
|
|
11
|
+
`)};var br=(e,t)=>{let o=1;for(let n=t-1;n>=0;n-=1)if(e[n]==="]")o+=1;else if(e[n]==="["&&(o-=1,o===0))return n;return-1},yr=(e,t)=>{let o=1;for(let n=t+1;n<e.length;n+=1)if(e[n]==="[")o+=1;else if(e[n]==="]"&&(o-=1,o===0))return n;return-1},Ve=(e,t)=>{let o=!1,n=!1;for(let r=0;r<t;r+=1){if(e.substring(r,r+3)==="```"){n=!n,r+=2;continue}!n&&e[r]==="`"&&(o=!o)}return o||n},wr=e=>{let t=e.lastIndexOf("](");if(t!==-1&&!Ve(e,t)&&!e.substring(t+2).includes(")")){let n=br(e,t);if(n!==-1&&!Ve(e,n)){let r=n>0&&e[n-1]==="!",s=r?n-1:n,a=e.substring(0,s),i=e.substring(n+1,t);return r?a:`${a}[${i}](streamdown:incomplete-link)`}}for(let o=e.length-1;o>=0;o-=1)if(e[o]==="["&&!Ve(e,o)){let n=o>0&&e[o-1]==="!",r=n?o-1:o;if(!e.substring(o+1).includes("]")){let i=e.substring(0,r);return n?i:`${e}](streamdown:incomplete-link)`}if(yr(e,o)===-1){let i=e.substring(0,r);return n?i:`${e}](streamdown:incomplete-link)`}}return e},kr=e=>{if(ge(e))return e;let t=e.match(ar);if(t){let o=t[2];if(!o||H.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
|
|
12
|
+
`),a=s===-1?0:s+1,i=e.substring(a,n);if(vo.test(i)&&o.includes(`
|
|
13
|
+
`))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},Cr=e=>{let t=e.match(lr);if(t){let o=t[2];if(!o||H.test(o))return e;let n=e.lastIndexOf(t[1]),s=e.substring(0,n).lastIndexOf(`
|
|
14
|
+
`),a=s===-1?0:s+1,i=e.substring(a,n);if(vo.test(i)&&o.includes(`
|
|
15
|
+
`))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},vr=e=>{let t=0,o=e.length;for(let n=0;n<o;n+=1){if(e[n]!=="*")continue;let r=n>0?e[n-1]:"",s=n<o-1?e[n+1]:"";if(r==="\\"||r==="*"||s==="*"||r&&s&&j(r)&&j(s))continue;let a=0;for(let l=n-1;l>=0;l-=1)if(e[l]===`
|
|
16
|
+
`){a=l+1;break}let i=!0;for(let l=a;l<n;l+=1)if(e[l]!==" "&&e[l]!==" "){i=!1;break}i&&(s===" "||s===" ")||(t+=1)}return t},Mr=e=>{if(ge(e))return e;if(e.match(dr)){let o=-1;for(let s=0;s<e.length;s+=1)if(e[s]==="*"&&e[s-1]!=="*"&&e[s+1]!=="*"&&e[s-1]!=="\\"){let a=s>0?e[s-1]:"",i=s<e.length-1?e[s+1]:"";if(a&&i&&j(a)&&j(i))continue;o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||H.test(n))return e;if(vr(e)%2===1)return`${e}*`}return e},Mo=(e,t)=>{let o=!1,n=!1;for(let r=0;r<e.length&&r<t;r+=1){if(e[r]==="\\"&&e[r+1]==="$"){r+=1;continue}e[r]==="$"&&(e[r+1]==="$"?(n=!n,r+=1,o=!1):n||(o=!o))}return o||n},Tr=e=>{let t=e.includes("$"),o=0,n=e.length;for(let r=0;r<n;r+=1){if(e[r]!=="_")continue;let s=r>0?e[r-1]:"",a=r<n-1?e[r+1]:"";s!=="\\"&&(t&&Mo(e,r)||s==="_"||a==="_"||s&&a&&j(s)&&j(a)||(o+=1))}return o},Pr=e=>{if(ge(e))return e;if(e.match(mr)){let o=-1;for(let s=0;s<e.length;s+=1)if(e[s]==="_"&&e[s-1]!=="_"&&e[s+1]!=="_"&&e[s-1]!=="\\"&&!Mo(e,s)){let a=s>0?e[s-1]:"",i=s<e.length-1?e[s+1]:"";if(a&&i&&j(a)&&j(i))continue;o=s;break}if(o===-1)return e;let n=e.substring(o+1);if(!n||H.test(n))return e;if(Tr(e)%2===1){let s=e.length;for(;s>0&&e[s-1]===`
|
|
17
|
+
`;)s-=1;if(s<e.length){let a=e.slice(0,s),i=e.slice(s);return`${a}_${i}`}return`${e}_`}}return e},xr=(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},Nr=e=>{let t=0;for(let o=0;o<e.length;o+=1)e[o]==="`"&&!xr(e,o)&&(t+=1);return t},Ir=e=>{if(e.match(hr)&&!e.includes(`
|
|
14
18
|
`))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(`
|
|
15
|
-
`)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let
|
|
19
|
+
`)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let r=e.match(pr);if(r&&!n){let s=r[2];if(!s||H.test(s))return e;if(Nr(e)%2===1)return`${e}\``}return e},Sr=e=>{let t=e.match(ur);if(t){let o=t[2];if(!o||H.test(o))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e},Br=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let o=e.indexOf("$$");return o!==-1&&e.indexOf(`
|
|
16
20
|
`,o)!==-1&&!e.endsWith(`
|
|
17
21
|
`)?`${e}
|
|
18
|
-
$$`:`${e}$$`},
|
|
22
|
+
$$`:`${e}$$`},Er=e=>{let t=0,o=0;for(let n=0;n<e.length;n+=1)e[n]==="*"?o+=1:(o>=3&&(t+=Math.floor(o/3)),o=0);return o>=3&&(t+=Math.floor(o/3)),t},Lr=e=>{if(ge(e)||gr.test(e))return e;let t=e.match(cr);if(t){let o=t[2];if(!o||H.test(o))return e;if(Er(e)%2===1)return`${e}***`}return e},Xe=e=>{if(!e||typeof e!="string")return e;let t=e,o=wr(t);return o.endsWith("](streamdown:incomplete-link)")?o:(t=o,t=Lr(t),t=kr(t),t=Cr(t),t=Mr(t),t=Pr(t),t=Ir(t),t=Sr(t),t=Br(t),t)};import{jsx as O}from"react/jsx-runtime";var Fr={harden:[Dr,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],defaultOrigin:void 0,allowDataImages:!0}],raw:Hr,katex:[Je,{errorColor:"var(--color-muted-foreground)"}]},Ur={gfm:[qr,{}],math:[_r,{singleDollarTextMath:!1}],cjkFriendly:[Or,{}],cjkFriendlyGfmStrikethrough:[zr,{}]},Wr=Object.values(Fr),Vr=Object.values(Ur),Xr={shikiTheme:["github-light","github-dark"],controls:!0,isAnimating:!1,mode:"streaming",mermaid:void 0},M=Ar(Xr),xo=Po(({content:e,shouldParseIncompleteMarkdown:t,...o})=>{let n=Y(()=>typeof e=="string"&&t?Xe(e.trim()):e,[e,t]);return O(_e,{...o,children:n})},(e,t)=>{if(e.content!==t.content||e.shouldParseIncompleteMarkdown!==t.shouldParseIncompleteMarkdown||e.index!==t.index)return!1;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(r=>{var s,a;return((s=e.components)==null?void 0:s[r])!==((a=t.components)==null?void 0:a[r])}))return!1}return!(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});xo.displayName="Block";var Jr=["github-light","github-dark"],Kr=Po(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=!0,components:n,rehypePlugins:r=Wr,remarkPlugins:s=Vr,className:a,shikiTheme:i=Jr,mermaid:l,controls:c=!0,isAnimating:d=!1,BlockComponent:m=xo,parseMarkdownIntoBlocksFn:p=We,...h})=>{let u=Rr(),[g,y]=$r(),[k,P]=jr([]),N=Y(()=>p(typeof e=="string"?e:""),[e,p]);To(()=>{t==="streaming"?y(()=>{P(N)}):P(N)},[N,t]);let x=t==="streaming"?k:N,L=Y(()=>x.map((B,q)=>`${u}-${q}`),[x.length,u]),$=Y(()=>({shikiTheme:i,controls:c,isAnimating:d,mode:t,mermaid:l}),[i,c,d,t,l]),z=Y(()=>({...Yt,...n}),[n]);return To(()=>{Array.isArray(r)&&r.some(B=>Array.isArray(B)?B[0]===Je:B===Je)&&import("katex/dist/katex.min.css")},[r]),t==="static"?O(M.Provider,{value:$,children:O("div",{className:f("space-y-4",a),children:O(_e,{components:z,rehypePlugins:r,remarkPlugins:s,...h,children:e})})}):O(M.Provider,{value:$,children:O("div",{className:f("space-y-4",a),children:x.map((B,q)=>O(m,{components:z,content:B,index:q,rehypePlugins:r,remarkPlugins:s,shouldParseIncompleteMarkdown:o,...h},L[q]))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode);Kr.displayName="Streamdown";export{xo as Block,Kr as Streamdown,M as StreamdownContext,Fr as defaultRehypePlugins,Ur as defaultRemarkPlugins,Xe as parseIncompleteMarkdown,We as parseMarkdownIntoBlocks};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamdown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@testing-library/jest-dom": "^6.8.0",
|
|
30
30
|
"@testing-library/react": "^16.3.0",
|
|
31
|
+
"@types/hast": "^3.0.4",
|
|
31
32
|
"@types/react": "^19.1.12",
|
|
32
33
|
"@types/react-dom": "^19.1.9",
|
|
33
34
|
"@vitejs/plugin-react": "^5.0.2",
|
|
@@ -35,6 +36,7 @@
|
|
|
35
36
|
"jsdom": "^26.1.0",
|
|
36
37
|
"react": "^19.1.1",
|
|
37
38
|
"react-dom": "^19.1.1",
|
|
39
|
+
"react-markdown": "^10.1.0",
|
|
38
40
|
"tsup": "^8.5.0",
|
|
39
41
|
"unified": "^11.0.5",
|
|
40
42
|
"vitest": "^3.2.4"
|
|
@@ -44,11 +46,13 @@
|
|
|
44
46
|
},
|
|
45
47
|
"dependencies": {
|
|
46
48
|
"clsx": "^2.1.1",
|
|
49
|
+
"hast": "^1.0.0",
|
|
50
|
+
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
51
|
+
"html-url-attributes": "^3.0.1",
|
|
47
52
|
"katex": "^0.16.22",
|
|
48
53
|
"lucide-react": "^0.542.0",
|
|
49
54
|
"marked": "^16.2.1",
|
|
50
55
|
"mermaid": "^11.11.0",
|
|
51
|
-
"react-markdown": "^10.1.0",
|
|
52
56
|
"rehype-harden": "^1.1.5",
|
|
53
57
|
"rehype-katex": "^7.0.1",
|
|
54
58
|
"rehype-raw": "^7.0.0",
|
|
@@ -56,13 +60,18 @@
|
|
|
56
60
|
"remark-cjk-friendly-gfm-strikethrough": "^1.2.3",
|
|
57
61
|
"remark-gfm": "^4.0.1",
|
|
58
62
|
"remark-math": "^6.0.0",
|
|
63
|
+
"remark-parse": "^11.0.0",
|
|
64
|
+
"remark-rehype": "^11.1.2",
|
|
59
65
|
"shiki": "^3.12.2",
|
|
60
|
-
"tailwind-merge": "^3.3.1"
|
|
66
|
+
"tailwind-merge": "^3.3.1",
|
|
67
|
+
"unist-util-visit": "^5.0.0"
|
|
61
68
|
},
|
|
62
69
|
"scripts": {
|
|
63
70
|
"build": "tsup",
|
|
64
71
|
"test": "vitest run",
|
|
65
72
|
"test:ui": "vitest --ui run",
|
|
66
|
-
"test:coverage": "vitest --coverage run"
|
|
73
|
+
"test:coverage": "vitest --coverage run",
|
|
74
|
+
"bench": "vitest bench --run > results.txt",
|
|
75
|
+
"bench:ui": "vitest bench --ui --run"
|
|
67
76
|
}
|
|
68
77
|
}
|