streamdown 1.2.0 → 1.3.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 +18 -2
- package/dist/index.cjs +14 -14
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +14 -14
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -56,6 +56,7 @@ Streamdown supports Mermaid diagrams using the `mermaid` language identifier:
|
|
|
56
56
|
|
|
57
57
|
```tsx
|
|
58
58
|
import { Streamdown } from 'streamdown';
|
|
59
|
+
import type { MermaidConfig } from 'mermaid';
|
|
59
60
|
|
|
60
61
|
export default function Page() {
|
|
61
62
|
const markdown = `
|
|
@@ -84,7 +85,20 @@ sequenceDiagram
|
|
|
84
85
|
\`\`\`
|
|
85
86
|
`;
|
|
86
87
|
|
|
87
|
-
|
|
88
|
+
// Optional: Customize Mermaid theme and colors
|
|
89
|
+
const mermaidConfig: MermaidConfig = {
|
|
90
|
+
theme: 'dark',
|
|
91
|
+
themeVariables: {
|
|
92
|
+
primaryColor: '#ff0000',
|
|
93
|
+
primaryTextColor: '#fff'
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Streamdown mermaidConfig={mermaidConfig}>
|
|
99
|
+
{markdown}
|
|
100
|
+
</Streamdown>
|
|
101
|
+
);
|
|
88
102
|
}
|
|
89
103
|
```
|
|
90
104
|
|
|
@@ -150,7 +164,9 @@ Streamdown accepts all the same props as react-markdown, plus additional streami
|
|
|
150
164
|
| `allowedImagePrefixes` | `array` | `['*']` | Allowed image URL prefixes |
|
|
151
165
|
| `allowedLinkPrefixes` | `array` | `['*']` | Allowed link URL prefixes |
|
|
152
166
|
| `defaultOrigin` | `string` | - | Default origin to use for relative URLs in links and images |
|
|
153
|
-
| `shikiTheme` | `BundledTheme`
|
|
167
|
+
| `shikiTheme` | `[BundledTheme, BundledTheme]` | `['github-light', 'github-dark']` | The light and dark themes to use for code blocks |
|
|
168
|
+
| `mermaidConfig` | `MermaidConfig` | - | Custom configuration for Mermaid diagrams (theme, colors, etc.) |
|
|
169
|
+
| `controls` | `boolean \| { table?: boolean, code?: boolean, mermaid?: boolean }` | `true` | Control visibility of copy/download buttons |
|
|
154
170
|
|
|
155
171
|
## Architecture
|
|
156
172
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use strict";"use client";var he=Object.create;var S=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var ye=(e,t)=>{for(var s in t)S(e,s,{get:t[s],enumerable:!0})},U=(e,t,s,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ke(t))!ve.call(e,n)&&n!==s&&S(e,n,{get:()=>t[n],enumerable:!(r=be(t,n))||r.enumerable});return e};var I=(e,t,s)=>(s=e!=null?he(we(e)):{},U(t||!e||!e.__esModule?S(s,"default",{value:e,enumerable:!0}):s,e)),Te=e=>U(S({},"__esModule",{value:!0}),e);var et={};ye(et,{ShikiThemeContext:()=>H,Streamdown:()=>fe});module.exports=Te(et);var y=require("react"),de=I(require("react-markdown"),1),me=I(require("rehype-katex"),1),ue=I(require("remark-gfm"),1),pe=I(require("remark-math"),1),vt=require("katex/dist/katex.min.css"),E=I(require("harden-react-markdown"),1);var oe=require("react");var P=require("lucide-react"),b=require("react"),q=require("shiki"),K=require("shiki/engine/javascript");var W=require("clsx"),G=require("tailwind-merge"),c=(...e)=>(0,G.twMerge)((0,W.clsx)(e)),N=(e,t,s)=>{let r=typeof t=="string"?new Blob([t],{type:s}):t,n=URL.createObjectURL(r),o=document.createElement("a");o.href=n,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(n)};var k=require("react/jsx-runtime"),Ce=/<pre(\s|>)/,_=(0,b.createContext)({code:""}),A=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}async ensureHighlightersInitialized(t,s){var u,m;let[r,n]=t,o=(0,K.createJavaScriptRegexEngine)({forgiving:!0}),a=!this.lightHighlighter||this.lightTheme!==r,l=!this.darkHighlighter||this.darkTheme!==n;(a||l)&&this.loadedLanguages.clear();let i=!this.loadedLanguages.has(s);if(a?(this.lightHighlighter=await(0,q.createHighlighter)({themes:[r],langs:[s],engine:o}),this.lightTheme=r,this.loadedLanguages.add(s)):i&&await((u=this.lightHighlighter)==null?void 0:u.loadLanguage(s)),l){let f=i?[...this.loadedLanguages,s]:Array.from(this.loadedLanguages);this.darkHighlighter=await(0,q.createHighlighter)({themes:[n],langs:f.length>0?f:[s],engine:o}),this.darkTheme=n}else i&&await((m=this.darkHighlighter)==null?void 0:m.loadLanguage(s));i&&this.loadedLanguages.add(s)}async highlightCode(t,s,r,n){var m,f;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(r,s),await this.initializationPromise,this.initializationPromise=null;let o=p=>n?p.replace(Ce,`<pre class="${n}"$1`):p,[a,l]=r,i=(m=this.lightHighlighter)==null?void 0:m.codeToHtml(t,{lang:s,theme:a}),u=(f=this.darkHighlighter)==null?void 0:f.codeToHtml(t,{lang:s,theme:l});return[V(o(i)),V(o(u))]}},Me=new A,V=e=>e.replace(/(<pre[^>]*)(style="[^"]*background[^";]*;?[^"]*")([^>]*>)/g,"$1$3"),X=({code:e,language:t,className:s,children:r,preClassName:n,...o})=>{let[a,l]=(0,b.useState)(""),[i,u]=(0,b.useState)(""),m=(0,b.useRef)(!1),[f,p]=(0,b.useContext)(H);return(0,b.useEffect)(()=>(m.current=!0,Me.highlightCode(e,t,[f,p],n).then(([g,h])=>{m.current&&(l(g),u(h))}),()=>{m.current=!1}),[e,t,f,p,n]),(0,k.jsx)(_.Provider,{value:{code:e},children:(0,k.jsxs)("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[(0,k.jsxs)("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-code-block-header":!0,"data-language":t,children:[(0,k.jsx)("span",{className:"ml-1 font-mono lowercase",children:t}),(0,k.jsx)("div",{className:"flex items-center gap-2",children:r})]}),(0,k.jsx)("div",{className:"w-full",children:(0,k.jsxs)("div",{className:"min-w-full",children:[(0,k.jsx)("div",{className:c("overflow-x-auto dark:hidden",s),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...o}),(0,k.jsx)("div",{className:c("hidden overflow-x-auto dark:block",s),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...o})]})})]})})},F={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},O=({onDownload:e,onError:t,language:s,children:r,className:n,code:o,...a})=>{let l=(0,b.useContext)(_).code,i=o!=null?o:l,m=`file.${s&&s in F?F[s]:"txt"}`,f="text/plain",p=()=>{try{N(m,i,f),e==null||e()}catch(g){t==null||t(g)}};return(0,k.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,title:"Download file",type:"button",...a,children:r!=null?r:(0,k.jsx)(P.DownloadIcon,{size:14})})},z=({onCopy:e,onError:t,timeout:s=2e3,children:r,className:n,code:o,...a})=>{let[l,i]=(0,b.useState)(!1),u=(0,b.useRef)(0),m=(0,b.useContext)(_).code,f=o!=null?o:m,p=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{l||(await navigator.clipboard.writeText(f),i(!0),e==null||e(),u.current=window.setTimeout(()=>i(!1),s))}catch(v){t==null||t(v)}};(0,b.useEffect)(()=>()=>{window.clearTimeout(u.current)},[]);let g=l?P.CheckIcon:P.CopyIcon;return(0,k.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,type:"button",...a,children:r!=null?r:(0,k.jsx)(g,{size:14})})};var J=require("lucide-react");var $=require("react/jsx-runtime"),Q=({node:e,className:t,src:s,alt:r,...n})=>{let o=async()=>{var a;if(s)try{let i=await(await fetch(s)).blob(),m=new URL(s,window.location.origin).pathname.split("/").pop()||"",f=m.includes(".")&&((a=m.split(".").pop())==null?void 0:a.length)<=4,p="";if(f)p=m;else{let g=i.type,h="png";g.includes("jpeg")||g.includes("jpg")?h="jpg":g.includes("png")?h="png":g.includes("svg")?h="svg":g.includes("gif")?h="gif":g.includes("webp")&&(h="webp"),p=`${(r||m||"image").replace(/\.[^/.]+$/,"")}.${h}`}N(p,i,i.type)}catch(l){console.error("Failed to download image:",l)}};return s?(0,$.jsxs)("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[(0,$.jsx)("img",{alt:r,className:c("max-w-full rounded-lg",t),"data-streamdown":"image",src:s,...n}),(0,$.jsx)("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),(0,$.jsx)("button",{className:c("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:o,title:"Download image",type:"button",children:(0,$.jsx)(J.DownloadIcon,{size:14})})]}):null};var x=require("react");var w=require("react/jsx-runtime"),Y=!1,Be=async()=>{if(!Y){let s=(await import("mermaid")).default;return s.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),Y=!0,s}return(await import("mermaid")).default},Z=({chart:e,className:t})=>{let[s,r]=(0,x.useState)(null),[n,o]=(0,x.useState)(!0),[a,l]=(0,x.useState)(""),[i,u]=(0,x.useState)("");if((0,x.useEffect)(()=>{(async()=>{try{r(null),o(!0);let p=await Be(),g=e.split("").reduce((M,B)=>(M<<5)-M+B.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:v}=await p.render(h,e);l(v),u(v)}catch(p){if(!(i||a)){let g=p instanceof Error?p.message:"Failed to render Mermaid chart";r(g)}}finally{o(!1)}})()},[e]),n&&!a&&!i)return(0,w.jsx)("div",{className:c("my-4 flex justify-center p-4",t),children:(0,w.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,w.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,w.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!a&&!i)return(0,w.jsxs)("div",{className:c("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,w.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),(0,w.jsxs)("details",{className:"mt-2",children:[(0,w.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,w.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let m=a||i;return(0,w.jsx)("div",{"aria-label":"Mermaid chart",className:c("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:m},role:"img"})};var L=require("lucide-react"),C=require("react");var T=require("react/jsx-runtime");function ee(e){var o,a;let t=[],s=[],r=e.querySelectorAll("thead th");for(let l of r)t.push(((o=l.textContent)==null?void 0:o.trim())||"");let n=e.querySelectorAll("tbody tr");for(let l of n){let i=[],u=l.querySelectorAll("td");for(let m of u)i.push(((a=m.textContent)==null?void 0:a.trim())||"");s.push(i)}return{headers:t,rows:s}}function R(e){let{headers:t,rows:s}=e,r=o=>o.includes(",")||o.includes('"')||o.includes(`
|
|
2
|
-
`)?`"${
|
|
3
|
-
`)}function
|
|
4
|
-
`)}var se=({children:e,className:t,onCopy:s,onError:r,timeout:n=2e3,format:o="markdown"})=>{let[a,l]=(0,C.useState)(!1),i=(0,C.useRef)(0),u=async f=>{var p;if(typeof window=="undefined"||!((p=navigator==null?void 0:navigator.clipboard)!=null&&p.writeText)){r==null||r(new Error("Clipboard API not available"));return}try{if(!a){let h=f.currentTarget.closest('[data-streamdown="table-wrapper"]'),v=h==null?void 0:h.querySelector("table");if(!v){r==null||r(new Error("Table not found"));return}let M=ee(v),B="";switch(o){case"csv":B=R(M);break;case"markdown":B=te(M);break;case"text":B=R(M).replace(/,/g," ");break;default:B=R(M)}await navigator.clipboard.writeText(B),l(!0),s==null||s(),i.current=window.setTimeout(()=>l(!1),n)}}catch(g){r==null||r(g)}};(0,C.useEffect)(()=>()=>{window.clearTimeout(i.current)},[]);let m=a?L.CheckIcon:L.CopyIcon;return(0,T.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:u,title:`Copy table as ${o}`,type:"button",children:e!=null?e:(0,T.jsx)(m,{size:14})})};var re=({children:e,className:t,onDownload:s,onError:r})=>{let[n,o]=(0,C.useState)(!1),a=(0,C.useRef)(null),l=i=>{var u;try{let m=(u=a.current)==null?void 0:u.closest('[data-streamdown="table-wrapper"]'),f=m==null?void 0:m.querySelector("table");if(!f){r==null||r(new Error("Table not found"));return}let p=ee(f),g=i==="csv"?R(p):te(p);N(`table.${i==="csv"?"csv":"md"}`,g,i==="csv"?"text/csv":"text/markdown"),o(!1),s==null||s(i)}catch(m){r==null||r(m)}};return(0,C.useEffect)(()=>{let i=u=>{a.current&&!a.current.contains(u.target)&&o(!1)};return document.addEventListener("mousedown",i),()=>{document.removeEventListener("mousedown",i)}},[]),(0,T.jsxs)("div",{className:"relative",ref:a,children:[(0,T.jsx)("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:()=>o(!n),title:"Download table",type:"button",children:e!=null?e:(0,T.jsx)(L.DownloadIcon,{size:14})}),n&&(0,T.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] rounded-md border border-border bg-white shadow-lg",children:[(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("csv"),type:"button",children:"CSV"}),(0,T.jsx)("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("markdown"),type:"button",children:"Markdown"})]})]})};var d=require("react/jsx-runtime"),Ie=/language-([^\s]+)/,$e=({node:e,className:t,children:s,...r})=>{var i,u,m;if(((i=e==null?void 0:e.position)==null?void 0:i.start.line)===((u=e==null?void 0:e.position)==null?void 0:u.end.line))return(0,d.jsx)("code",{className:c("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...r,children:s});let o=t==null?void 0:t.match(Ie),a=(m=o==null?void 0:o.at(1))!=null?m:"",l="";return(0,oe.isValidElement)(s)&&s.props&&typeof s.props=="object"&&"children"in s.props&&typeof s.props.children=="string"?l=s.props.children:typeof s=="string"&&(l=s),a==="mermaid"?(0,d.jsxs)("div",{className:c("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[(0,d.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,d.jsx)(O,{code:l,language:a}),(0,d.jsx)(z,{code:l})]}),(0,d.jsx)(Z,{chart:l})]}):(0,d.jsxs)(X,{className:c("overflow-x-auto border-t",t),code:l,"data-language":a,"data-streamdown":"code-block",language:a,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:[(0,d.jsx)(O,{code:l,language:a}),(0,d.jsx)(z,{})]})},ne={ol:({node:e,children:t,className:s,...r})=>(0,d.jsx)("ol",{className:c("ml-4 list-outside list-decimal whitespace-normal",s),"data-streamdown":"ordered-list",...r,children:t}),li:({node:e,children:t,className:s,...r})=>(0,d.jsx)("li",{className:c("py-1",s),"data-streamdown":"list-item",...r,children:t}),ul:({node:e,children:t,className:s,...r})=>(0,d.jsx)("ul",{className:c("ml-4 list-outside list-disc whitespace-normal",s),"data-streamdown":"unordered-list",...r,children:t}),hr:({node:e,className:t,...s})=>(0,d.jsx)("hr",{className:c("my-6 border-border",t),"data-streamdown":"horizontal-rule",...s}),strong:({node:e,children:t,className:s,...r})=>(0,d.jsx)("span",{className:c("font-semibold",s),"data-streamdown":"strong",...r,children:t}),a:({node:e,children:t,className:s,href:r,...n})=>{let o=r==="streamdown:incomplete-link";return(0,d.jsx)("a",{className:c("font-medium text-primary underline",s),"data-incomplete":o,"data-streamdown":"link",href:r,rel:"noreferrer",target:"_blank",...n,children:t})},h1:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h1",{className:c("mt-6 mb-2 font-semibold text-3xl",s),"data-streamdown":"heading-1",...r,children:t}),h2:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h2",{className:c("mt-6 mb-2 font-semibold text-2xl",s),"data-streamdown":"heading-2",...r,children:t}),h3:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h3",{className:c("mt-6 mb-2 font-semibold text-xl",s),"data-streamdown":"heading-3",...r,children:t}),h4:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h4",{className:c("mt-6 mb-2 font-semibold text-lg",s),"data-streamdown":"heading-4",...r,children:t}),h5:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h5",{className:c("mt-6 mb-2 font-semibold text-base",s),"data-streamdown":"heading-5",...r,children:t}),h6:({node:e,children:t,className:s,...r})=>(0,d.jsx)("h6",{className:c("mt-6 mb-2 font-semibold text-sm",s),"data-streamdown":"heading-6",...r,children:t}),table:({node:e,children:t,className:s,...r})=>(0,d.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[(0,d.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,d.jsx)(se,{}),(0,d.jsx)(re,{})]}),(0,d.jsx)("div",{className:"overflow-x-auto",children:(0,d.jsx)("table",{className:c("w-full border-collapse border border-border",s),"data-streamdown":"table",...r,children:t})})]}),thead:({node:e,children:t,className:s,...r})=>(0,d.jsx)("thead",{className:c("bg-muted/80",s),"data-streamdown":"table-header",...r,children:t}),tbody:({node:e,children:t,className:s,...r})=>(0,d.jsx)("tbody",{className:c("divide-y divide-border bg-muted/40",s),"data-streamdown":"table-body",...r,children:t}),tr:({node:e,children:t,className:s,...r})=>(0,d.jsx)("tr",{className:c("border-border border-b",s),"data-streamdown":"table-row",...r,children:t}),th:({node:e,children:t,className:s,...r})=>(0,d.jsx)("th",{className:c("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",s),"data-streamdown":"table-header-cell",...r,children:t}),td:({node:e,children:t,className:s,...r})=>(0,d.jsx)("td",{className:c("px-4 py-2 text-sm",s),"data-streamdown":"table-cell",...r,children:t}),blockquote:({node:e,children:t,className:s,...r})=>(0,d.jsx)("blockquote",{className:c("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",s),"data-streamdown":"blockquote",...r,children:t}),code:$e,img:Q,pre:({children:e})=>e,sup:({node:e,children:t,className:s,...r})=>(0,d.jsx)("sup",{className:c("text-sm",s),"data-streamdown":"superscript",...r,children:t}),sub:({node:e,children:t,className:s,...r})=>(0,d.jsx)("sub",{className:c("text-sm",s),"data-streamdown":"subscript",...r,children:t})};var ae=require("marked"),ie=e=>{let s=ae.marked.use({gfm:!0}).lexer(e).map(n=>n.raw),r=[];for(let n=0;n<s.length;n++){let o=s[n];if(o.trim()==="$$"&&r.length>0){let a=r.at(-1),l=a.trimStart().startsWith("$$"),i=(a.match(/\$\$/g)||[]).length;if(l&&i%2===1){r[r.length-1]=a+o;continue}}if(r.length>0&&o.trimEnd().endsWith("$$")){let a=r.at(-1),l=a.trimStart().startsWith("$$"),i=(a.match(/\$\$/g)||[]).length,u=(o.match(/\$\$/g)||[]).length;if(l&&i%2===1&&!o.trimStart().startsWith("$$")&&u===1){r[r.length-1]=a+o;continue}}r.push(o)}return r};var xe=/(!?\[)([^\]]*?)$/,Ne=/(\*\*)([^*]*?)$/,Pe=/(__)([^_]*?)$/,Le=/(\*\*\*)([^*]*?)$/,je=/(\*)([^*]*?)$/,Se=/(_)([^_]*?)$/,He=/(`)([^`]*?)$/,Re=/(~~)([^~]*?)$/,D=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
|
|
5
|
-
`)},
|
|
6
|
-
`),a=
|
|
7
|
-
`))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},
|
|
8
|
-
`),a=
|
|
9
|
-
`))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},
|
|
10
|
-
`){a=i+1;break}if(i===0){a=0;break}}if(e.substring(a,
|
|
11
|
-
`))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let
|
|
12
|
-
`)||(e.endsWith("```\n")||e.endsWith("```"))&&
|
|
13
|
-
`,
|
|
1
|
+
"use strict";"use client";var Xe=Object.create;var q=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ge=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var Ke=(e,t)=>{for(var o in t)q(e,o,{get:t[o],enumerable:!0})},G=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Fe(t))!Ve.call(e,r)&&r!==o&&q(e,r,{get:()=>t[r],enumerable:!(s=Je(t,r))||s.enumerable});return e};var I=(e,t,o)=>(o=e!=null?Xe(Ge(e)):{},G(t||!e||!e.__esModule?q(o,"default",{value:e,enumerable:!0}):o,e)),Qe=e=>G(q({},"__esModule",{value:!0}),e);var Lt={};Ke(Lt,{ControlsContext:()=>A,MermaidConfigContext:()=>_,ShikiThemeContext:()=>D,Streamdown:()=>Ue});module.exports=Qe(Lt);var v=require("react"),qe=I(require("react-markdown"),1),De=I(require("rehype-katex"),1),Ee=I(require("rehype-raw"),1),_e=I(require("remark-gfm"),1),Oe=I(require("remark-math"),1),Kt=require("katex/dist/katex.min.css"),F=I(require("harden-react-markdown"),1);var g=require("react");var x=require("lucide-react"),w=require("react"),R=require("shiki"),Z=require("shiki/engine/javascript");var V=require("clsx"),K=require("tailwind-merge"),d=(...e)=>(0,K.twMerge)((0,V.clsx)(e)),H=(e,t,o)=>{let s=typeof t=="string"?new Blob([t],{type:o}):t,r=URL.createObjectURL(s),n=document.createElement("a");n.href=r,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)};var y=require("react/jsx-runtime"),Ye=/<pre(\s|>)/,U=(0,w.createContext)({code:""}),W=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}isLanguageSupported(t){return Object.hasOwn(R.bundledLanguages,t)}getFallbackLanguage(){return"text"}async ensureHighlightersInitialized(t,o){var p,f;let[s,r]=t,n=(0,Z.createJavaScriptRegexEngine)({forgiving:!0}),a=!this.lightHighlighter||this.lightTheme!==s,l=!this.darkHighlighter||this.darkTheme!==r;(a||l)&&this.loadedLanguages.clear();let i=this.isLanguageSupported(o),m=!this.loadedLanguages.has(o)&&i;if(a?(this.lightHighlighter=await(0,R.createHighlighter)({themes:[s],langs:i?[o]:[],engine:n}),this.lightTheme=s,i&&this.loadedLanguages.add(o)):m&&await((p=this.lightHighlighter)==null?void 0:p.loadLanguage(o)),l){let h=m?[...this.loadedLanguages].concat(i?[o]:[]):Array.from(this.loadedLanguages);this.darkHighlighter=await(0,R.createHighlighter)({themes:[r],langs:h.length>0?h:i?[o]:[],engine:n}),this.darkTheme=r}else m&&await((f=this.darkHighlighter)==null?void 0:f.loadLanguage(o));m&&this.loadedLanguages.add(o)}async highlightCode(t,o,s,r){var f,h;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(s,o),await this.initializationPromise,this.initializationPromise=null;let[n,a]=s,l=this.isLanguageSupported(o)?o:this.getFallbackLanguage(),i=(f=this.lightHighlighter)==null?void 0:f.codeToHtml(t,{lang:l,theme:n}),m=(h=this.darkHighlighter)==null?void 0:h.codeToHtml(t,{lang:l,theme:a}),p=u=>r?u.replace(Ye,`<pre class="${r}"$1`):u;return[Q(p(i)),Q(p(m))]}},Ze=new W,Q=e=>e.replace(/(<pre[^>]*)(style="[^"]*background[^";]*;?[^"]*")([^>]*>)/g,"$1$3"),ee=({code:e,language:t,className:o,children:s,preClassName:r,...n})=>{let[a,l]=(0,w.useState)(""),[i,m]=(0,w.useState)(""),p=(0,w.useRef)(!1),[f,h]=(0,w.useContext)(D);return(0,w.useEffect)(()=>(p.current=!0,Ze.highlightCode(e,t,[f,h],r).then(([u,b])=>{p.current&&(l(u),m(b))}),()=>{p.current=!1}),[e,t,f,h,r]),(0,y.jsx)(U.Provider,{value:{code:e},children:(0,y.jsxs)("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[(0,y.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,y.jsx)("span",{className:"ml-1 font-mono lowercase",children:t}),(0,y.jsx)("div",{className:"flex items-center gap-2",children:s})]}),(0,y.jsx)("div",{className:"w-full",children:(0,y.jsxs)("div",{className:"min-w-full",children:[(0,y.jsx)("div",{className:d("overflow-x-auto dark:hidden",o),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...n}),(0,y.jsx)("div",{className:d("hidden overflow-x-auto dark:block",o),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...n})]})})]})})},Y={"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"},z=({onDownload:e,onError:t,language:o,children:s,className:r,code:n,...a})=>{let l=(0,w.useContext)(U).code,i=n!=null?n:l,p=`file.${o&&o in Y?Y[o]:"txt"}`,f="text/plain",h=()=>{try{H(p,i,f),e==null||e()}catch(u){t==null||t(u)}};return(0,y.jsx)("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",r),onClick:h,title:"Download file",type:"button",...a,children:s!=null?s:(0,y.jsx)(x.DownloadIcon,{size:14})})},X=({onCopy:e,onError:t,timeout:o=2e3,children:s,className:r,code:n,...a})=>{let[l,i]=(0,w.useState)(!1),m=(0,w.useRef)(0),p=(0,w.useContext)(U).code,f=n!=null?n:p,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{l||(await navigator.clipboard.writeText(f),i(!0),e==null||e(),m.current=window.setTimeout(()=>i(!1),o))}catch(T){t==null||t(T)}};(0,w.useEffect)(()=>()=>{window.clearTimeout(m.current)},[]);let u=l?x.CheckIcon:x.CopyIcon;return(0,y.jsx)("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",r),onClick:h,type:"button",...a,children:s!=null?s:(0,y.jsx)(u,{size:14})})};var te=require("lucide-react");var B=require("react/jsx-runtime"),oe=({node:e,className:t,src:o,alt:s,...r})=>{let n=async()=>{var a;if(o)try{let i=await(await fetch(o)).blob(),p=new URL(o,window.location.origin).pathname.split("/").pop()||"",f=p.includes(".")&&((a=p.split(".").pop())==null?void 0:a.length)<=4,h="";if(f)h=p;else{let u=i.type,b="png";u.includes("jpeg")||u.includes("jpg")?b="jpg":u.includes("png")?b="png":u.includes("svg")?b="svg":u.includes("gif")?b="gif":u.includes("webp")&&(b="webp"),h=`${(s||p||"image").replace(/\.[^/.]+$/,"")}.${b}`}H(h,i,i.type)}catch(l){console.error("Failed to download image:",l)}};return o?(0,B.jsxs)("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[(0,B.jsx)("img",{alt:s,className:d("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...r}),(0,B.jsx)("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),(0,B.jsx)("button",{className:d("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:n,title:"Download image",type:"button",children:(0,B.jsx)(te.DownloadIcon,{size:14})})]}):null};var L=require("react");var M=require("react/jsx-runtime"),et=async e=>{let o={...{startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0},...e},r=(await import("mermaid")).default;return r.initialize(o),r},se=({chart:e,className:t,config:o})=>{let[s,r]=(0,L.useState)(null),[n,a]=(0,L.useState)(!0),[l,i]=(0,L.useState)(""),[m,p]=(0,L.useState)("");if((0,L.useEffect)(()=>{(async()=>{try{r(null),a(!0);let u=await et(o),b=e.split("").reduce(($,ze)=>($<<5)-$+ze.charCodeAt(0)|0,0),T=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:P}=await u.render(T,e);i(P),p(P)}catch(u){if(!(m||l)){let b=u instanceof Error?u.message:"Failed to render Mermaid chart";r(b)}}finally{a(!1)}})()},[e,o]),n&&!l&&!m)return(0,M.jsx)("div",{className:d("my-4 flex justify-center p-4",t),children:(0,M.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,M.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,M.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!l&&!m)return(0,M.jsxs)("div",{className:d("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,M.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),(0,M.jsxs)("details",{className:"mt-2",children:[(0,M.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,M.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let f=l||m;return(0,M.jsx)("div",{"aria-label":"Mermaid chart",className:d("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:f},role:"img"})};var j=require("lucide-react"),N=require("react");var C=require("react/jsx-runtime");function ne(e){var n,a;let t=[],o=[],s=e.querySelectorAll("thead th");for(let l of s)t.push(((n=l.textContent)==null?void 0:n.trim())||"");let r=e.querySelectorAll("tbody tr");for(let l of r){let i=[],m=l.querySelectorAll("td");for(let p of m)i.push(((a=p.textContent)==null?void 0:a.trim())||"");o.push(i)}return{headers:t,rows:o}}function re(e){let{headers:t,rows:o}=e,s=n=>n.includes(",")||n.includes('"')||n.includes(`
|
|
2
|
+
`)?`"${n.replace(/"/g,'""')}"`:n,r=[];t.length>0&&r.push(t.map(s).join(","));for(let n of o)r.push(n.map(s).join(","));return r.join(`
|
|
3
|
+
`)}function ae(e){let{headers:t,rows:o}=e;if(t.length===0)return"";let s=[],r=t.map(n=>n.replace(/\|/g,"\\|"));s.push(`| ${r.join(" | ")} |`),s.push(`| ${t.map(()=>"---").join(" | ")} |`);for(let n of o){let a=[...n];for(;a.length<t.length;)a.push("");let l=a.map(i=>i.replace(/\|/g,"\\|"));s.push(`| ${l.join(" | ")} |`)}return s.join(`
|
|
4
|
+
`)}var ie=({children:e,className:t,onCopy:o,onError:s,timeout:r=2e3,format:n="markdown"})=>{let[a,l]=(0,N.useState)(!1),i=(0,N.useRef)(0),m=async f=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){s==null||s(new Error("Clipboard API not available"));return}try{if(!a){let b=f.currentTarget.closest('[data-streamdown="table-wrapper"]'),T=b==null?void 0:b.querySelector("table");if(!T){s==null||s(new Error("Table not found"));return}let P=ne(T),$=new ClipboardItem({"text/plain":n==="markdown"?ae(P):re(P),"text/html":new Blob([T.outerHTML],{type:"text/html"})});await navigator.clipboard.write([$]),l(!0),o==null||o(),i.current=window.setTimeout(()=>l(!1),r)}}catch(u){s==null||s(u)}};(0,N.useEffect)(()=>()=>{window.clearTimeout(i.current)},[]);let p=a?j.CheckIcon:j.CopyIcon;return(0,C.jsx)("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:m,title:`Copy table as ${n}`,type:"button",children:e!=null?e:(0,C.jsx)(p,{size:14})})};var le=({children:e,className:t,onDownload:o,onError:s})=>{let[r,n]=(0,N.useState)(!1),a=(0,N.useRef)(null),l=i=>{var m;try{let p=(m=a.current)==null?void 0:m.closest('[data-streamdown="table-wrapper"]'),f=p==null?void 0:p.querySelector("table");if(!f){s==null||s(new Error("Table not found"));return}let h=ne(f),u=i==="csv"?re(h):ae(h);H(`table.${i==="csv"?"csv":"md"}`,u,i==="csv"?"text/csv":"text/markdown"),n(!1),o==null||o(i)}catch(p){s==null||s(p)}};return(0,N.useEffect)(()=>{let i=m=>{a.current&&!a.current.contains(m.target)&&n(!1)};return document.addEventListener("mousedown",i),()=>{document.removeEventListener("mousedown",i)}},[]),(0,C.jsxs)("div",{className:"relative",ref:a,children:[(0,C.jsx)("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:()=>n(!r),title:"Download table",type:"button",children:e!=null?e:(0,C.jsx)(j.DownloadIcon,{size:14})}),r&&(0,C.jsxs)("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] rounded-md border border-border bg-background shadow-lg",children:[(0,C.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,C.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 c=require("react/jsx-runtime"),tt=/language-([^\s]+)/;function E(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,s=t.position.start,r=e.position.end,n=t.position.end;return(o==null?void 0:o.line)===(s==null?void 0:s.line)&&(o==null?void 0:o.column)===(s==null?void 0:s.column)&&(r==null?void 0:r.line)===(n==null?void 0:n.line)&&(r==null?void 0:r.column)===(n==null?void 0:n.column)}function k(e,t){return e.className===t.className&&E(e.node,t.node)}var J=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,de=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("ol",{className:d("ml-4 list-outside list-decimal whitespace-normal",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>k(e,t));de.displayName="MarkdownOl";var ce=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("li",{className:d("py-1",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&E(e.node,t.node));ce.displayName="MarkdownLi";var me=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("ul",{className:d("ml-4 list-outside list-disc whitespace-normal",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>k(e,t));me.displayName="MarkdownUl";var pe=(0,g.memo)(({className:e,...t})=>(0,c.jsx)("hr",{className:d("my-6 border-border",e),"data-streamdown":"horizontal-rule",...t}),(e,t)=>k(e,t));pe.displayName="MarkdownHr";var ue=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("span",{className:d("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>k(e,t));ue.displayName="MarkdownStrong";var ge=(0,g.memo)(({children:e,className:t,href:o,...s})=>{let r=o==="streamdown:incomplete-link";return(0,c.jsx)("a",{className:d("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)=>k(e,t)&&e.href===t.href);ge.displayName="MarkdownA";var he=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("h1",{className:d("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>k(e,t));he.displayName="MarkdownH1";var fe=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("h2",{className:d("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>k(e,t));fe.displayName="MarkdownH2";var be=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("h3",{className:d("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>k(e,t));be.displayName="MarkdownH3";var ke=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("h4",{className:d("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>k(e,t));ke.displayName="MarkdownH4";var we=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("h5",{className:d("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>k(e,t));we.displayName="MarkdownH5";var ye=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("h6",{className:d("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>k(e,t));ye.displayName="MarkdownH6";var ve=(0,g.memo)(({children:e,className:t,...o})=>{let s=(0,g.useContext)(A),r=J(s,"table");return(0,c.jsxs)("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[r&&(0,c.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,c.jsx)(ie,{}),(0,c.jsx)(le,{})]}),(0,c.jsx)("div",{className:"overflow-x-auto",children:(0,c.jsx)("table",{className:d("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]})},(e,t)=>k(e,t));ve.displayName="MarkdownTable";var Me=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("thead",{className:d("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>k(e,t));Me.displayName="MarkdownThead";var Te=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("tbody",{className:d("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>k(e,t));Te.displayName="MarkdownTbody";var Ce=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("tr",{className:d("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>k(e,t));Ce.displayName="MarkdownTr";var Ne=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("th",{className:d("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>k(e,t));Ne.displayName="MarkdownTh";var Pe=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("td",{className:d("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>k(e,t));Pe.displayName="MarkdownTd";var Ie=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("blockquote",{className:d("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>k(e,t));Ie.displayName="MarkdownBlockquote";var Be=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("sup",{className:d("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>k(e,t));Be.displayName="MarkdownSup";var Le=(0,g.memo)(({children:e,className:t,...o})=>(0,c.jsx)("sub",{className:d("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>k(e,t));Le.displayName="MarkdownSub";var ot=({node:e,className:t,children:o,...s})=>{var f,h,u;let r=((f=e==null?void 0:e.position)==null?void 0:f.start.line)===((h=e==null?void 0:e.position)==null?void 0:h.end.line),n=(0,g.useContext)(_),a=(0,g.useContext)(A);if(r)return(0,c.jsx)("code",{className:d("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...s,children:o});let l=t==null?void 0:t.match(tt),i=(u=l==null?void 0:l.at(1))!=null?u:"",m="";if((0,g.isValidElement)(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?m=o.props.children:typeof o=="string"&&(m=o),i==="mermaid"){let b=J(a,"mermaid");return(0,c.jsxs)("div",{className:d("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[b&&(0,c.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,c.jsx)(z,{code:m,language:i}),(0,c.jsx)(X,{code:m})]}),(0,c.jsx)(se,{chart:m,config:n})]})}let p=J(a,"code");return(0,c.jsx)(ee,{className:d("overflow-x-auto border-t",t),code:m,"data-language":i,"data-streamdown":"code-block",language:i,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:p&&(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(z,{code:m,language:i}),(0,c.jsx)(X,{})]})})},Se=(0,g.memo)(ot,(e,t)=>e.className===t.className&&E(e.node,t.node));Se.displayName="MarkdownCode";var $e=(0,g.memo)(oe,(e,t)=>e.className===t.className&&E(e.node,t.node));$e.displayName="MarkdownImg";var He={ol:de,li:ce,ul:me,hr:pe,strong:ue,a:ge,h1:he,h2:fe,h3:be,h4:ke,h5:we,h6:ye,table:ve,thead:Me,tbody:Te,tr:Ce,th:Ne,td:Pe,blockquote:Ie,code:Se,img:$e,pre:({children:e})=>e,sup:Be,sub:Le};var xe=require("marked"),je=e=>{let o=xe.Lexer.lex(e,{gfm:!0}).map(r=>r.raw),s=[];for(let r of o){if(r.trim()==="$$"&&s.length>0){let n=s.at(-1);if(!n)continue;let a=n.trimStart().startsWith("$$"),l=(n.match(/\$\$/g)||[]).length;if(a&&l%2===1){s[s.length-1]=n+r;continue}}if(s.length>0&&r.trimEnd().endsWith("$$")){let n=s.at(-1);if(!n)continue;let a=n.trimStart().startsWith("$$"),l=(n.match(/\$\$/g)||[]).length,i=(r.match(/\$\$/g)||[]).length;if(a&&l%2===1&&!r.trimStart().startsWith("$$")&&i===1){s[s.length-1]=n+r;continue}}s.push(r)}return s};var st=/(!?\[)([^\]]*?)$/,nt=/(\*\*)([^*]*?)$/,rt=/(__)([^_]*?)$/,at=/(\*\*\*)([^*]*?)$/,it=/(\*)([^*]*?)$/,lt=/(_)([^_]*?)$/,dt=/(`)([^`]*?)$/,ct=/(~~)([^~]*?)$/,O=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
|
|
5
|
+
`)},mt=e=>{let t=e.match(st);if(t){if(t[1].startsWith("!")){let s=e.lastIndexOf(t[1]);return e.substring(0,s)}return`${e}](streamdown:incomplete-link)`}return e},pt=e=>{if(O(e))return e;let t=e.match(nt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let s=e.lastIndexOf(t[1]),n=e.substring(0,s).lastIndexOf(`
|
|
6
|
+
`),a=n===-1?0:n+1,l=e.substring(a,s);if(/^[\s]*[-*+][\s]+$/.test(l)&&o.includes(`
|
|
7
|
+
`))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},ut=e=>{let t=e.match(rt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let s=e.lastIndexOf(t[1]),n=e.substring(0,s).lastIndexOf(`
|
|
8
|
+
`),a=n===-1?0:n+1,l=e.substring(a,s);if(/^[\s]*[-*+][\s]+$/.test(l)&&o.includes(`
|
|
9
|
+
`))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},gt=e=>e.split("").reduce((t,o,s)=>{if(o==="*"){let r=e[s-1],n=e[s+1];if(r==="\\")return t;let a=s;for(let i=s-1;i>=0;i--){if(e[i]===`
|
|
10
|
+
`){a=i+1;break}if(i===0){a=0;break}}if(e.substring(a,s).trim()===""&&(n===" "||n===" "))return t;if(r!=="*"&&n!=="*")return t+1}return t},0),ht=e=>{if(O(e))return e;if(e.match(it)){let o=-1;for(let n=0;n<e.length;n++)if(e[n]==="*"&&e[n-1]!=="*"&&e[n+1]!=="*"){o=n;break}if(o===-1)return e;let s=e.substring(o+1);if(!s||/^[\s_~*`]*$/.test(s))return e;if(gt(e)%2===1)return`${e}*`}return e},Re=(e,t)=>{let o=!1,s=!1;for(let r=0;r<e.length&&r<t;r++){if(e[r]==="\\"&&e[r+1]==="$"){r++;continue}e[r]==="$"&&(e[r+1]==="$"?(s=!s,r++,o=!1):s||(o=!o))}return o||s},ft=e=>e.split("").reduce((t,o,s)=>{if(o==="_"){let r=e[s-1],n=e[s+1];if(r==="\\"||Re(e,s)||r&&n&&/[\p{L}\p{N}_]/u.test(r)&&/[\p{L}\p{N}_]/u.test(n))return t;if(r!=="_"&&n!=="_")return t+1}return t},0),bt=e=>{if(O(e))return e;if(e.match(lt)){let o=-1;for(let n=0;n<e.length;n++)if(e[n]==="_"&&e[n-1]!=="_"&&e[n+1]!=="_"&&e[n-1]!=="\\"&&!Re(e,n)){let a=n>0?e[n-1]:"",l=n<e.length-1?e[n+1]:"";if(a&&l&&/[\p{L}\p{N}_]/u.test(a)&&/[\p{L}\p{N}_]/u.test(l))continue;o=n;break}if(o===-1)return e;let s=e.substring(o+1);if(!s||/^[\s_~*`]*$/.test(s))return e;if(ft(e)%2===1){let n=e.match(/\n+$/);return n?`${e.slice(0,-n[0].length)}_${n[0]}`:`${e}_`}}return e},kt=(e,t)=>{let o=e.substring(t,t+3)==="```",s=t>0&&e.substring(t-1,t+2)==="```",r=t>1&&e.substring(t-2,t+1)==="```";return o||s||r},wt=e=>{let t=0;for(let o=0;o<e.length;o++)e[o]==="`"&&!kt(e,o)&&t++;return t},yt=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
|
|
11
|
+
`))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let o=(e.match(/```/g)||[]).length,s=o%2===1;if(o>0&&o%2===0&&e.includes(`
|
|
12
|
+
`)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let r=e.match(dt);if(r&&!s){let n=r[2];if(!n||/^[\s_~*`]*$/.test(n))return e;if(wt(e)%2===1)return`${e}\``}return e},vt=e=>{let t=e.match(ct);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e};var Mt=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let o=e.indexOf("$$");return o!==-1&&e.indexOf(`
|
|
13
|
+
`,o)!==-1&&!e.endsWith(`
|
|
14
14
|
`)?`${e}
|
|
15
|
-
$$`:`${e}$$`},
|
|
15
|
+
$$`:`${e}$$`},Tt=e=>{let t=0,o=e.match(/\*+/g)||[];for(let s of o){let r=s.length;r>=3&&(t+=Math.floor(r/3))}return t},Ct=e=>{if(O(e)||/^\*{4,}$/.test(e))return e;let t=e.match(at);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if(Tt(e)%2===1)return`${e}***`}return e},Ae=e=>{if(!e||typeof e!="string")return e;let t=e,o=mt(t);return o.endsWith("](streamdown:incomplete-link)")?o:(t=o,t=Ct(t),t=pt(t),t=ut(t),t=ht(t),t=bt(t),t=yt(t),t=vt(t),t=Mt(t),t)};var S=require("react/jsx-runtime"),Nt=F.default.default||F.default,Pt=Nt(qe.default),D=(0,v.createContext)(["github-light","github-dark"]),_=(0,v.createContext)(void 0),A=(0,v.createContext)(!0),It={singleDollarTextMath:!1},Bt={},We=(0,v.memo)(({content:e,shouldParseIncompleteMarkdown:t,...o})=>{let s=(0,v.useMemo)(()=>typeof e=="string"&&t?Ae(e.trim()):e,[e,t]);return(0,S.jsx)(Pt,{...o,children:s})},(e,t)=>e.content===t.content);We.displayName="Block";var Ue=(0,v.memo)(({children:e,allowedImagePrefixes:t=["*"],allowedLinkPrefixes:o=["*"],defaultOrigin:s,parseIncompleteMarkdown:r=!0,components:n,rehypePlugins:a,remarkPlugins:l,className:i,shikiTheme:m=["github-light","github-dark"],mermaidConfig:p,controls:f=!0,...h})=>{let u=(0,v.useId)(),b=(0,v.useMemo)(()=>je(typeof e=="string"?e:""),[e]),T=(0,v.useMemo)(()=>()=>(0,De.default)({errorColor:"var(--color-muted-foreground)"}),[]);return(0,S.jsx)(D.Provider,{value:m,children:(0,S.jsx)(_.Provider,{value:p,children:(0,S.jsx)(A.Provider,{value:f,children:(0,S.jsx)("div",{className:d("space-y-4",i),...h,children:b.map((P,$)=>(0,S.jsx)(We,{allowedImagePrefixes:t,allowedLinkPrefixes:o,components:{...He,...n},content:P,defaultOrigin:s,rehypePlugins:[Ee.default,T,...a!=null?a:[]],remarkPlugins:[[_e.default,Bt],[Oe.default,It],...l!=null?l:[]],shouldParseIncompleteMarkdown:r},`${u}-block_${$}`))})})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Ue.displayName="Streamdown";0&&(module.exports={ControlsContext,MermaidConfigContext,ShikiThemeContext,Streamdown});
|
package/dist/index.d.cts
CHANGED
|
@@ -2,18 +2,29 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { Options } from 'react-markdown';
|
|
4
4
|
import { BundledTheme } from 'shiki';
|
|
5
|
+
import { MermaidConfig } from 'mermaid';
|
|
6
|
+
export { MermaidConfig } from 'mermaid';
|
|
5
7
|
|
|
6
8
|
type HardenReactMarkdownProps = Options & {
|
|
7
9
|
defaultOrigin?: string;
|
|
8
10
|
allowedLinkPrefixes?: string[];
|
|
9
11
|
allowedImagePrefixes?: string[];
|
|
10
12
|
};
|
|
13
|
+
type ControlsConfig = boolean | {
|
|
14
|
+
table?: boolean;
|
|
15
|
+
code?: boolean;
|
|
16
|
+
mermaid?: boolean;
|
|
17
|
+
};
|
|
11
18
|
type StreamdownProps = HardenReactMarkdownProps & {
|
|
12
19
|
parseIncompleteMarkdown?: boolean;
|
|
13
20
|
className?: string;
|
|
14
21
|
shikiTheme?: [BundledTheme, BundledTheme];
|
|
22
|
+
mermaidConfig?: MermaidConfig;
|
|
23
|
+
controls?: ControlsConfig;
|
|
15
24
|
};
|
|
16
25
|
declare const ShikiThemeContext: react.Context<[BundledTheme, BundledTheme]>;
|
|
17
|
-
declare const
|
|
26
|
+
declare const MermaidConfigContext: react.Context<MermaidConfig | undefined>;
|
|
27
|
+
declare const ControlsContext: react.Context<ControlsConfig>;
|
|
28
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaidConfig, controls, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
18
29
|
|
|
19
|
-
export { ShikiThemeContext, Streamdown, type StreamdownProps };
|
|
30
|
+
export { type ControlsConfig, ControlsContext, MermaidConfigContext, ShikiThemeContext, Streamdown, type StreamdownProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,18 +2,29 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { Options } from 'react-markdown';
|
|
4
4
|
import { BundledTheme } from 'shiki';
|
|
5
|
+
import { MermaidConfig } from 'mermaid';
|
|
6
|
+
export { MermaidConfig } from 'mermaid';
|
|
5
7
|
|
|
6
8
|
type HardenReactMarkdownProps = Options & {
|
|
7
9
|
defaultOrigin?: string;
|
|
8
10
|
allowedLinkPrefixes?: string[];
|
|
9
11
|
allowedImagePrefixes?: string[];
|
|
10
12
|
};
|
|
13
|
+
type ControlsConfig = boolean | {
|
|
14
|
+
table?: boolean;
|
|
15
|
+
code?: boolean;
|
|
16
|
+
mermaid?: boolean;
|
|
17
|
+
};
|
|
11
18
|
type StreamdownProps = HardenReactMarkdownProps & {
|
|
12
19
|
parseIncompleteMarkdown?: boolean;
|
|
13
20
|
className?: string;
|
|
14
21
|
shikiTheme?: [BundledTheme, BundledTheme];
|
|
22
|
+
mermaidConfig?: MermaidConfig;
|
|
23
|
+
controls?: ControlsConfig;
|
|
15
24
|
};
|
|
16
25
|
declare const ShikiThemeContext: react.Context<[BundledTheme, BundledTheme]>;
|
|
17
|
-
declare const
|
|
26
|
+
declare const MermaidConfigContext: react.Context<MermaidConfig | undefined>;
|
|
27
|
+
declare const ControlsContext: react.Context<ControlsConfig>;
|
|
28
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaidConfig, controls, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
18
29
|
|
|
19
|
-
export { ShikiThemeContext, Streamdown, type StreamdownProps };
|
|
30
|
+
export { type ControlsConfig, ControlsContext, MermaidConfigContext, ShikiThemeContext, Streamdown, type StreamdownProps };
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
"use client";import{createContext as Ye,memo as le,useId as Ze,useMemo as _}from"react";import et from"react-markdown";import tt from"rehype-katex";import st from"remark-gfm";import rt from"remark-math";import"katex/dist/katex.min.css";import ie from"harden-react-markdown";import{isValidElement as Ie}from"react";import{CheckIcon as ue,CopyIcon as pe,DownloadIcon as ge}from"lucide-react";import{createContext as fe,useContext as H,useEffect as U,useRef as W,useState as j}from"react";import{createHighlighter as O}from"shiki";import{createJavaScriptRegexEngine as he}from"shiki/engine/javascript";import{clsx as de}from"clsx";import{twMerge as me}from"tailwind-merge";var c=(...e)=>me(de(e)),y=(e,t,s)=>{let r=typeof t=="string"?new Blob([t],{type:s}):t,n=URL.createObjectURL(r),o=document.createElement("a");o.href=n,o.download=e,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(n)};import{jsx as k,jsxs as L}from"react/jsx-runtime";var be=/<pre(\s|>)/,R=fe({code:""}),S=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}async ensureHighlightersInitialized(t,s){var m,d;let[r,n]=t,o=he({forgiving:!0}),a=!this.lightHighlighter||this.lightTheme!==r,l=!this.darkHighlighter||this.darkTheme!==n;(a||l)&&this.loadedLanguages.clear();let i=!this.loadedLanguages.has(s);if(a?(this.lightHighlighter=await O({themes:[r],langs:[s],engine:o}),this.lightTheme=r,this.loadedLanguages.add(s)):i&&await((m=this.lightHighlighter)==null?void 0:m.loadLanguage(s)),l){let f=i?[...this.loadedLanguages,s]:Array.from(this.loadedLanguages);this.darkHighlighter=await O({themes:[n],langs:f.length>0?f:[s],engine:o}),this.darkTheme=n}else i&&await((d=this.darkHighlighter)==null?void 0:d.loadLanguage(s));i&&this.loadedLanguages.add(s)}async highlightCode(t,s,r,n){var d,f;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(r,s),await this.initializationPromise,this.initializationPromise=null;let o=p=>n?p.replace(be,`<pre class="${n}"$1`):p,[a,l]=r,i=(d=this.lightHighlighter)==null?void 0:d.codeToHtml(t,{lang:s,theme:a}),m=(f=this.darkHighlighter)==null?void 0:f.codeToHtml(t,{lang:s,theme:l});return[z(o(i)),z(o(m))]}},ke=new S,z=e=>e.replace(/(<pre[^>]*)(style="[^"]*background[^";]*;?[^"]*")([^>]*>)/g,"$1$3"),G=({code:e,language:t,className:s,children:r,preClassName:n,...o})=>{let[a,l]=j(""),[i,m]=j(""),d=W(!1),[f,p]=H(A);return U(()=>(d.current=!0,ke.highlightCode(e,t,[f,p],n).then(([g,h])=>{d.current&&(l(g),m(h))}),()=>{d.current=!1}),[e,t,f,p,n]),k(R.Provider,{value:{code:e},children:L("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[L("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-code-block-header":!0,"data-language":t,children:[k("span",{className:"ml-1 font-mono lowercase",children:t}),k("div",{className:"flex items-center gap-2",children:r})]}),k("div",{className:"w-full",children:L("div",{className:"min-w-full",children:[k("div",{className:c("overflow-x-auto dark:hidden",s),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...o}),k("div",{className:c("hidden overflow-x-auto dark:block",s),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...o})]})})]})})},E={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},D=({onDownload:e,onError:t,language:s,children:r,className:n,code:o,...a})=>{let l=H(R).code,i=o!=null?o:l,d=`file.${s&&s in E?E[s]:"txt"}`,f="text/plain",p=()=>{try{y(d,i,f),e==null||e()}catch(g){t==null||t(g)}};return k("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,title:"Download file",type:"button",...a,children:r!=null?r:k(ge,{size:14})})},q=({onCopy:e,onError:t,timeout:s=2e3,children:r,className:n,code:o,...a})=>{let[l,i]=j(!1),m=W(0),d=H(R).code,f=o!=null?o:d,p=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{l||(await navigator.clipboard.writeText(f),i(!0),e==null||e(),m.current=window.setTimeout(()=>i(!1),s))}catch(b){t==null||t(b)}};U(()=>()=>{window.clearTimeout(m.current)},[]);let g=l?ue:pe;return k("button",{className:c("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",n),onClick:p,type:"button",...a,children:r!=null?r:k(g,{size:14})})};import{DownloadIcon as we}from"lucide-react";import{jsx as B,jsxs as ve}from"react/jsx-runtime";var V=({node:e,className:t,src:s,alt:r,...n})=>{let o=async()=>{var a;if(s)try{let i=await(await fetch(s)).blob(),d=new URL(s,window.location.origin).pathname.split("/").pop()||"",f=d.includes(".")&&((a=d.split(".").pop())==null?void 0:a.length)<=4,p="";if(f)p=d;else{let g=i.type,h="png";g.includes("jpeg")||g.includes("jpg")?h="jpg":g.includes("png")?h="png":g.includes("svg")?h="svg":g.includes("gif")?h="gif":g.includes("webp")&&(h="webp"),p=`${(r||d||"image").replace(/\.[^/.]+$/,"")}.${h}`}y(p,i,i.type)}catch(l){console.error("Failed to download image:",l)}};return s?ve("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[B("img",{alt:r,className:c("max-w-full rounded-lg",t),"data-streamdown":"image",src:s,...n}),B("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),B("button",{className:c("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:o,title:"Download image",type:"button",children:B(we,{size:14})})]}):null};import{useEffect as ye,useState as I}from"react";import{jsx as T,jsxs as $}from"react/jsx-runtime";var F=!1,Te=async()=>{if(!F){let s=(await import("mermaid")).default;return s.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),F=!0,s}return(await import("mermaid")).default},K=({chart:e,className:t})=>{let[s,r]=I(null),[n,o]=I(!0),[a,l]=I(""),[i,m]=I("");if(ye(()=>{(async()=>{try{r(null),o(!0);let p=await Te(),g=e.split("").reduce((w,v)=>(w<<5)-w+v.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:b}=await p.render(h,e);l(b),m(b)}catch(p){if(!(i||a)){let g=p instanceof Error?p.message:"Failed to render Mermaid chart";r(g)}}finally{o(!1)}})()},[e]),n&&!a&&!i)return T("div",{className:c("my-4 flex justify-center p-4",t),children:$("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[T("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),T("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!a&&!i)return $("div",{className:c("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[$("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),$("details",{className:"mt-2",children:[T("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),T("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let d=a||i;return T("div",{"aria-label":"Mermaid chart",className:c("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:d},role:"img"})};import{CheckIcon as Ce,CopyIcon as Me,DownloadIcon as Be}from"lucide-react";import{useEffect as J,useRef as Q,useState as Y}from"react";import{jsx as C,jsxs as X}from"react/jsx-runtime";function Z(e){var o,a;let t=[],s=[],r=e.querySelectorAll("thead th");for(let l of r)t.push(((o=l.textContent)==null?void 0:o.trim())||"");let n=e.querySelectorAll("tbody tr");for(let l of n){let i=[],m=l.querySelectorAll("td");for(let d of m)i.push(((a=d.textContent)==null?void 0:a.trim())||"");s.push(i)}return{headers:t,rows:s}}function x(e){let{headers:t,rows:s}=e,r=o=>o.includes(",")||o.includes('"')||o.includes(`
|
|
2
|
-
`)?`"${
|
|
3
|
-
`)}function
|
|
4
|
-
`)}var
|
|
5
|
-
`)},
|
|
6
|
-
`),a=
|
|
7
|
-
`))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},
|
|
8
|
-
`),a=
|
|
9
|
-
`))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},
|
|
10
|
-
`){a=i+1;break}if(i===0){a=0;break}}if(e.substring(a,
|
|
11
|
-
`))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let
|
|
12
|
-
`)||(e.endsWith("```\n")||e.endsWith("```"))&&
|
|
13
|
-
`,
|
|
1
|
+
"use client";import{createContext as J,memo as De,useId as $t,useMemo as X}from"react";import Ht from"react-markdown";import xt from"rehype-katex";import jt from"rehype-raw";import Rt from"remark-gfm";import At from"remark-math";import"katex/dist/katex.min.css";import qe from"harden-react-markdown";import{isValidElement as nt,memo as b,useContext as W}from"react";import{CheckIcon as Ue,CopyIcon as ze,DownloadIcon as Xe}from"lucide-react";import{createContext as Je,useContext as q,useEffect as K,useRef as Q,useState as R}from"react";import{bundledLanguages as Fe,createHighlighter as F}from"shiki";import{createJavaScriptRegexEngine as Ge}from"shiki/engine/javascript";import{clsx as Oe}from"clsx";import{twMerge as We}from"tailwind-merge";var d=(...e)=>We(Oe(e)),T=(e,t,o)=>{let s=typeof t=="string"?new Blob([t],{type:o}):t,r=URL.createObjectURL(s),n=document.createElement("a");n.href=r,n.download=e,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)};import{jsx as y,jsxs as j}from"react/jsx-runtime";var Ve=/<pre(\s|>)/,D=Je({code:""}),A=class{constructor(){this.lightHighlighter=null;this.darkHighlighter=null;this.lightTheme=null;this.darkTheme=null;this.loadedLanguages=new Set;this.initializationPromise=null}isLanguageSupported(t){return Object.hasOwn(Fe,t)}getFallbackLanguage(){return"text"}async ensureHighlightersInitialized(t,o){var m,h;let[s,r]=t,n=Ge({forgiving:!0}),a=!this.lightHighlighter||this.lightTheme!==s,l=!this.darkHighlighter||this.darkTheme!==r;(a||l)&&this.loadedLanguages.clear();let i=this.isLanguageSupported(o),c=!this.loadedLanguages.has(o)&&i;if(a?(this.lightHighlighter=await F({themes:[s],langs:i?[o]:[],engine:n}),this.lightTheme=s,i&&this.loadedLanguages.add(o)):c&&await((m=this.lightHighlighter)==null?void 0:m.loadLanguage(o)),l){let g=c?[...this.loadedLanguages].concat(i?[o]:[]):Array.from(this.loadedLanguages);this.darkHighlighter=await F({themes:[r],langs:g.length>0?g:i?[o]:[],engine:n}),this.darkTheme=r}else c&&await((h=this.darkHighlighter)==null?void 0:h.loadLanguage(o));c&&this.loadedLanguages.add(o)}async highlightCode(t,o,s,r){var h,g;this.initializationPromise&&await this.initializationPromise,this.initializationPromise=this.ensureHighlightersInitialized(s,o),await this.initializationPromise,this.initializationPromise=null;let[n,a]=s,l=this.isLanguageSupported(o)?o:this.getFallbackLanguage(),i=(h=this.lightHighlighter)==null?void 0:h.codeToHtml(t,{lang:l,theme:n}),c=(g=this.darkHighlighter)==null?void 0:g.codeToHtml(t,{lang:l,theme:a}),m=u=>r?u.replace(Ve,`<pre class="${r}"$1`):u;return[G(m(i)),G(m(c))]}},Ke=new A,G=e=>e.replace(/(<pre[^>]*)(style="[^"]*background[^";]*;?[^"]*")([^>]*>)/g,"$1$3"),Y=({code:e,language:t,className:o,children:s,preClassName:r,...n})=>{let[a,l]=R(""),[i,c]=R(""),m=Q(!1),[h,g]=q(O);return K(()=>(m.current=!0,Ke.highlightCode(e,t,[h,g],r).then(([u,f])=>{m.current&&(l(u),c(f))}),()=>{m.current=!1}),[e,t,h,g,r]),y(D.Provider,{value:{code:e},children:j("div",{className:"my-4 w-full overflow-hidden rounded-xl border","data-code-block-container":!0,"data-language":t,children:[j("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:[y("span",{className:"ml-1 font-mono lowercase",children:t}),y("div",{className:"flex items-center gap-2",children:s})]}),y("div",{className:"w-full",children:j("div",{className:"min-w-full",children:[y("div",{className:d("overflow-x-auto dark:hidden",o),dangerouslySetInnerHTML:{__html:a},"data-code-block":!0,"data-language":t,...n}),y("div",{className:d("hidden overflow-x-auto dark:block",o),dangerouslySetInnerHTML:{__html:i},"data-code-block":!0,"data-language":t,...n})]})})]})})},V={"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"},E=({onDownload:e,onError:t,language:o,children:s,className:r,code:n,...a})=>{let l=q(D).code,i=n!=null?n:l,m=`file.${o&&o in V?V[o]:"txt"}`,h="text/plain",g=()=>{try{T(m,i,h),e==null||e()}catch(u){t==null||t(u)}};return y("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",r),onClick:g,title:"Download file",type:"button",...a,children:s!=null?s:y(Xe,{size:14})})},_=({onCopy:e,onError:t,timeout:o=2e3,children:s,className:r,code:n,...a})=>{let[l,i]=R(!1),c=Q(0),m=q(D).code,h=n!=null?n:m,g=async()=>{var f;if(typeof window=="undefined"||!((f=navigator==null?void 0:navigator.clipboard)!=null&&f.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{l||(await navigator.clipboard.writeText(h),i(!0),e==null||e(),c.current=window.setTimeout(()=>i(!1),o))}catch(w){t==null||t(w)}};K(()=>()=>{window.clearTimeout(c.current)},[]);let u=l?Ue:ze;return y("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",r),onClick:g,type:"button",...a,children:s!=null?s:y(u,{size:14})})};import{DownloadIcon as Qe}from"lucide-react";import{jsx as B,jsxs as Ye}from"react/jsx-runtime";var Z=({node:e,className:t,src:o,alt:s,...r})=>{let n=async()=>{var a;if(o)try{let i=await(await fetch(o)).blob(),m=new URL(o,window.location.origin).pathname.split("/").pop()||"",h=m.includes(".")&&((a=m.split(".").pop())==null?void 0:a.length)<=4,g="";if(h)g=m;else{let u=i.type,f="png";u.includes("jpeg")||u.includes("jpg")?f="jpg":u.includes("png")?f="png":u.includes("svg")?f="svg":u.includes("gif")?f="gif":u.includes("webp")&&(f="webp"),g=`${(s||m||"image").replace(/\.[^/.]+$/,"")}.${f}`}T(g,i,i.type)}catch(l){console.error("Failed to download image:",l)}};return o?Ye("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[B("img",{alt:s,className:d("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...r}),B("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),B("button",{className:d("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:n,title:"Download image",type:"button",children:B(Qe,{size:14})})]}):null};import{useEffect as Ze,useState as L}from"react";import{jsx as C,jsxs as S}from"react/jsx-runtime";var et=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},ee=({chart:e,className:t,config:o})=>{let[s,r]=L(null),[n,a]=L(!0),[l,i]=L(""),[c,m]=L("");if(Ze(()=>{(async()=>{try{r(null),a(!0);let u=await et(o),f=e.split("").reduce((M,_e)=>(M<<5)-M+_e.charCodeAt(0)|0,0),w=`mermaid-${Math.abs(f)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:v}=await u.render(w,e);i(v),m(v)}catch(u){if(!(c||l)){let f=u instanceof Error?u.message:"Failed to render Mermaid chart";r(f)}}finally{a(!1)}})()},[e,o]),n&&!l&&!c)return C("div",{className:d("my-4 flex justify-center p-4",t),children:S("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[C("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),C("span",{className:"text-sm",children:"Loading diagram..."})]})});if(s&&!l&&!c)return S("div",{className:d("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[S("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",s]}),S("details",{className:"mt-2",children:[C("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),C("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let h=l||c;return C("div",{"aria-label":"Mermaid chart",className:d("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:h},role:"img"})};import{CheckIcon as tt,CopyIcon as ot,DownloadIcon as st}from"lucide-react";import{useEffect as oe,useRef as se,useState as ne}from"react";import{jsx as N,jsxs as te}from"react/jsx-runtime";function re(e){var n,a;let t=[],o=[],s=e.querySelectorAll("thead th");for(let l of s)t.push(((n=l.textContent)==null?void 0:n.trim())||"");let r=e.querySelectorAll("tbody tr");for(let l of r){let i=[],c=l.querySelectorAll("td");for(let m of c)i.push(((a=m.textContent)==null?void 0:a.trim())||"");o.push(i)}return{headers:t,rows:o}}function ae(e){let{headers:t,rows:o}=e,s=n=>n.includes(",")||n.includes('"')||n.includes(`
|
|
2
|
+
`)?`"${n.replace(/"/g,'""')}"`:n,r=[];t.length>0&&r.push(t.map(s).join(","));for(let n of o)r.push(n.map(s).join(","));return r.join(`
|
|
3
|
+
`)}function ie(e){let{headers:t,rows:o}=e;if(t.length===0)return"";let s=[],r=t.map(n=>n.replace(/\|/g,"\\|"));s.push(`| ${r.join(" | ")} |`),s.push(`| ${t.map(()=>"---").join(" | ")} |`);for(let n of o){let a=[...n];for(;a.length<t.length;)a.push("");let l=a.map(i=>i.replace(/\|/g,"\\|"));s.push(`| ${l.join(" | ")} |`)}return s.join(`
|
|
4
|
+
`)}var le=({children:e,className:t,onCopy:o,onError:s,timeout:r=2e3,format:n="markdown"})=>{let[a,l]=ne(!1),i=se(0),c=async h=>{var g;if(typeof window=="undefined"||!((g=navigator==null?void 0:navigator.clipboard)!=null&&g.write)){s==null||s(new Error("Clipboard API not available"));return}try{if(!a){let f=h.currentTarget.closest('[data-streamdown="table-wrapper"]'),w=f==null?void 0:f.querySelector("table");if(!w){s==null||s(new Error("Table not found"));return}let v=re(w),M=new ClipboardItem({"text/plain":n==="markdown"?ie(v):ae(v),"text/html":new Blob([w.outerHTML],{type:"text/html"})});await navigator.clipboard.write([M]),l(!0),o==null||o(),i.current=window.setTimeout(()=>l(!1),r)}}catch(u){s==null||s(u)}};oe(()=>()=>{window.clearTimeout(i.current)},[]);let m=a?tt:ot;return N("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:c,title:`Copy table as ${n}`,type:"button",children:e!=null?e:N(m,{size:14})})};var de=({children:e,className:t,onDownload:o,onError:s})=>{let[r,n]=ne(!1),a=se(null),l=i=>{var c;try{let m=(c=a.current)==null?void 0:c.closest('[data-streamdown="table-wrapper"]'),h=m==null?void 0:m.querySelector("table");if(!h){s==null||s(new Error("Table not found"));return}let g=re(h),u=i==="csv"?ae(g):ie(g);T(`table.${i==="csv"?"csv":"md"}`,u,i==="csv"?"text/csv":"text/markdown"),n(!1),o==null||o(i)}catch(m){s==null||s(m)}};return oe(()=>{let i=c=>{a.current&&!a.current.contains(c.target)&&n(!1)};return document.addEventListener("mousedown",i),()=>{document.removeEventListener("mousedown",i)}},[]),te("div",{className:"relative",ref:a,children:[N("button",{className:d("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground",t),onClick:()=>n(!r),title:"Download table",type:"button",children:e!=null?e:N(st,{size:14})}),r&&te("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] rounded-md border border-border bg-background shadow-lg",children:[N("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"}),N("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 it,jsx as p,jsxs as I}from"react/jsx-runtime";var rt=/language-([^\s]+)/;function $(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return!0;if(!(e!=null&&e.position&&(t!=null&&t.position)))return!1;let o=e.position.start,s=t.position.start,r=e.position.end,n=t.position.end;return(o==null?void 0:o.line)===(s==null?void 0:s.line)&&(o==null?void 0:o.column)===(s==null?void 0:s.column)&&(r==null?void 0:r.line)===(n==null?void 0:n.line)&&(r==null?void 0:r.column)===(n==null?void 0:n.column)}function k(e,t){return e.className===t.className&&$(e.node,t.node)}var U=(e,t)=>typeof e=="boolean"?e:e[t]!==!1,ce=b(({children:e,className:t,...o})=>p("ol",{className:d("ml-4 list-outside list-decimal whitespace-normal",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>k(e,t));ce.displayName="MarkdownOl";var me=b(({children:e,className:t,...o})=>p("li",{className:d("py-1",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&$(e.node,t.node));me.displayName="MarkdownLi";var pe=b(({children:e,className:t,...o})=>p("ul",{className:d("ml-4 list-outside list-disc whitespace-normal",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>k(e,t));pe.displayName="MarkdownUl";var ue=b(({className:e,...t})=>p("hr",{className:d("my-6 border-border",e),"data-streamdown":"horizontal-rule",...t}),(e,t)=>k(e,t));ue.displayName="MarkdownHr";var ge=b(({children:e,className:t,...o})=>p("span",{className:d("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>k(e,t));ge.displayName="MarkdownStrong";var he=b(({children:e,className:t,href:o,...s})=>{let r=o==="streamdown:incomplete-link";return p("a",{className:d("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)=>k(e,t)&&e.href===t.href);he.displayName="MarkdownA";var fe=b(({children:e,className:t,...o})=>p("h1",{className:d("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>k(e,t));fe.displayName="MarkdownH1";var be=b(({children:e,className:t,...o})=>p("h2",{className:d("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>k(e,t));be.displayName="MarkdownH2";var ke=b(({children:e,className:t,...o})=>p("h3",{className:d("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>k(e,t));ke.displayName="MarkdownH3";var we=b(({children:e,className:t,...o})=>p("h4",{className:d("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>k(e,t));we.displayName="MarkdownH4";var ye=b(({children:e,className:t,...o})=>p("h5",{className:d("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>k(e,t));ye.displayName="MarkdownH5";var ve=b(({children:e,className:t,...o})=>p("h6",{className:d("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>k(e,t));ve.displayName="MarkdownH6";var Me=b(({children:e,className:t,...o})=>{let s=W(H),r=U(s,"table");return I("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[r&&I("div",{className:"flex items-center justify-end gap-1",children:[p(le,{}),p(de,{})]}),p("div",{className:"overflow-x-auto",children:p("table",{className:d("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]})},(e,t)=>k(e,t));Me.displayName="MarkdownTable";var Te=b(({children:e,className:t,...o})=>p("thead",{className:d("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>k(e,t));Te.displayName="MarkdownThead";var Ce=b(({children:e,className:t,...o})=>p("tbody",{className:d("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>k(e,t));Ce.displayName="MarkdownTbody";var Ne=b(({children:e,className:t,...o})=>p("tr",{className:d("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>k(e,t));Ne.displayName="MarkdownTr";var Pe=b(({children:e,className:t,...o})=>p("th",{className:d("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>k(e,t));Pe.displayName="MarkdownTh";var Ie=b(({children:e,className:t,...o})=>p("td",{className:d("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>k(e,t));Ie.displayName="MarkdownTd";var Be=b(({children:e,className:t,...o})=>p("blockquote",{className:d("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>k(e,t));Be.displayName="MarkdownBlockquote";var Le=b(({children:e,className:t,...o})=>p("sup",{className:d("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>k(e,t));Le.displayName="MarkdownSup";var Se=b(({children:e,className:t,...o})=>p("sub",{className:d("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>k(e,t));Se.displayName="MarkdownSub";var at=({node:e,className:t,children:o,...s})=>{var h,g,u;let r=((h=e==null?void 0:e.position)==null?void 0:h.start.line)===((g=e==null?void 0:e.position)==null?void 0:g.end.line),n=W(z),a=W(H);if(r)return p("code",{className:d("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...s,children:o});let l=t==null?void 0:t.match(rt),i=(u=l==null?void 0:l.at(1))!=null?u:"",c="";if(nt(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),i==="mermaid"){let f=U(a,"mermaid");return I("div",{className:d("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[f&&I("div",{className:"flex items-center justify-end gap-2",children:[p(E,{code:c,language:i}),p(_,{code:c})]}),p(ee,{chart:c,config:n})]})}let m=U(a,"code");return p(Y,{className:d("overflow-x-auto border-t",t),code:c,"data-language":i,"data-streamdown":"code-block",language:i,preClassName:"overflow-x-auto font-mono text-xs p-4 bg-muted/40",children:m&&I(it,{children:[p(E,{code:c,language:i}),p(_,{})]})})},$e=b(at,(e,t)=>e.className===t.className&&$(e.node,t.node));$e.displayName="MarkdownCode";var He=b(Z,(e,t)=>e.className===t.className&&$(e.node,t.node));He.displayName="MarkdownImg";var xe={ol:ce,li:me,ul:pe,hr:ue,strong:ge,a:he,h1:fe,h2:be,h3:ke,h4:we,h5:ye,h6:ve,table:Me,thead:Te,tbody:Ce,tr:Ne,th:Pe,td:Ie,blockquote:Be,code:$e,img:He,pre:({children:e})=>e,sup:Le,sub:Se};import{Lexer as lt}from"marked";var je=e=>{let o=lt.lex(e,{gfm:!0}).map(r=>r.raw),s=[];for(let r of o){if(r.trim()==="$$"&&s.length>0){let n=s.at(-1);if(!n)continue;let a=n.trimStart().startsWith("$$"),l=(n.match(/\$\$/g)||[]).length;if(a&&l%2===1){s[s.length-1]=n+r;continue}}if(s.length>0&&r.trimEnd().endsWith("$$")){let n=s.at(-1);if(!n)continue;let a=n.trimStart().startsWith("$$"),l=(n.match(/\$\$/g)||[]).length,i=(r.match(/\$\$/g)||[]).length;if(a&&l%2===1&&!r.trimStart().startsWith("$$")&&i===1){s[s.length-1]=n+r;continue}}s.push(r)}return s};var dt=/(!?\[)([^\]]*?)$/,ct=/(\*\*)([^*]*?)$/,mt=/(__)([^_]*?)$/,pt=/(\*\*\*)([^*]*?)$/,ut=/(\*)([^*]*?)$/,gt=/(_)([^_]*?)$/,ht=/(`)([^`]*?)$/,ft=/(~~)([^~]*?)$/,x=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
|
|
5
|
+
`)},bt=e=>{let t=e.match(dt);if(t){if(t[1].startsWith("!")){let s=e.lastIndexOf(t[1]);return e.substring(0,s)}return`${e}](streamdown:incomplete-link)`}return e},kt=e=>{if(x(e))return e;let t=e.match(ct);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let s=e.lastIndexOf(t[1]),n=e.substring(0,s).lastIndexOf(`
|
|
6
|
+
`),a=n===-1?0:n+1,l=e.substring(a,s);if(/^[\s]*[-*+][\s]+$/.test(l)&&o.includes(`
|
|
7
|
+
`))return e;if((e.match(/\*\*/g)||[]).length%2===1)return`${e}**`}return e},wt=e=>{let t=e.match(mt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;let s=e.lastIndexOf(t[1]),n=e.substring(0,s).lastIndexOf(`
|
|
8
|
+
`),a=n===-1?0:n+1,l=e.substring(a,s);if(/^[\s]*[-*+][\s]+$/.test(l)&&o.includes(`
|
|
9
|
+
`))return e;if((e.match(/__/g)||[]).length%2===1)return`${e}__`}return e},yt=e=>e.split("").reduce((t,o,s)=>{if(o==="*"){let r=e[s-1],n=e[s+1];if(r==="\\")return t;let a=s;for(let i=s-1;i>=0;i--){if(e[i]===`
|
|
10
|
+
`){a=i+1;break}if(i===0){a=0;break}}if(e.substring(a,s).trim()===""&&(n===" "||n===" "))return t;if(r!=="*"&&n!=="*")return t+1}return t},0),vt=e=>{if(x(e))return e;if(e.match(ut)){let o=-1;for(let n=0;n<e.length;n++)if(e[n]==="*"&&e[n-1]!=="*"&&e[n+1]!=="*"){o=n;break}if(o===-1)return e;let s=e.substring(o+1);if(!s||/^[\s_~*`]*$/.test(s))return e;if(yt(e)%2===1)return`${e}*`}return e},Re=(e,t)=>{let o=!1,s=!1;for(let r=0;r<e.length&&r<t;r++){if(e[r]==="\\"&&e[r+1]==="$"){r++;continue}e[r]==="$"&&(e[r+1]==="$"?(s=!s,r++,o=!1):s||(o=!o))}return o||s},Mt=e=>e.split("").reduce((t,o,s)=>{if(o==="_"){let r=e[s-1],n=e[s+1];if(r==="\\"||Re(e,s)||r&&n&&/[\p{L}\p{N}_]/u.test(r)&&/[\p{L}\p{N}_]/u.test(n))return t;if(r!=="_"&&n!=="_")return t+1}return t},0),Tt=e=>{if(x(e))return e;if(e.match(gt)){let o=-1;for(let n=0;n<e.length;n++)if(e[n]==="_"&&e[n-1]!=="_"&&e[n+1]!=="_"&&e[n-1]!=="\\"&&!Re(e,n)){let a=n>0?e[n-1]:"",l=n<e.length-1?e[n+1]:"";if(a&&l&&/[\p{L}\p{N}_]/u.test(a)&&/[\p{L}\p{N}_]/u.test(l))continue;o=n;break}if(o===-1)return e;let s=e.substring(o+1);if(!s||/^[\s_~*`]*$/.test(s))return e;if(Mt(e)%2===1){let n=e.match(/\n+$/);return n?`${e.slice(0,-n[0].length)}_${n[0]}`:`${e}_`}}return e},Ct=(e,t)=>{let o=e.substring(t,t+3)==="```",s=t>0&&e.substring(t-1,t+2)==="```",r=t>1&&e.substring(t-2,t+1)==="```";return o||s||r},Nt=e=>{let t=0;for(let o=0;o<e.length;o++)e[o]==="`"&&!Ct(e,o)&&t++;return t},Pt=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
|
|
11
|
+
`))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let o=(e.match(/```/g)||[]).length,s=o%2===1;if(o>0&&o%2===0&&e.includes(`
|
|
12
|
+
`)||(e.endsWith("```\n")||e.endsWith("```"))&&o%2===0)return e;let r=e.match(ht);if(r&&!s){let n=r[2];if(!n||/^[\s_~*`]*$/.test(n))return e;if(Nt(e)%2===1)return`${e}\``}return e},It=e=>{let t=e.match(ft);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if((e.match(/~~/g)||[]).length%2===1)return`${e}~~`}return e};var Bt=e=>{if((e.match(/\$\$/g)||[]).length%2===0)return e;let o=e.indexOf("$$");return o!==-1&&e.indexOf(`
|
|
13
|
+
`,o)!==-1&&!e.endsWith(`
|
|
14
14
|
`)?`${e}
|
|
15
|
-
$$`:`${e}$$`},
|
|
15
|
+
$$`:`${e}$$`},Lt=e=>{let t=0,o=e.match(/\*+/g)||[];for(let s of o){let r=s.length;r>=3&&(t+=Math.floor(r/3))}return t},St=e=>{if(x(e)||/^\*{4,}$/.test(e))return e;let t=e.match(pt);if(t){let o=t[2];if(!o||/^[\s_~*`]*$/.test(o))return e;if(Lt(e)%2===1)return`${e}***`}return e},Ae=e=>{if(!e||typeof e!="string")return e;let t=e,o=bt(t);return o.endsWith("](streamdown:incomplete-link)")?o:(t=o,t=St(t),t=kt(t),t=wt(t),t=vt(t),t=Tt(t),t=Pt(t),t=It(t),t=Bt(t),t)};import{jsx as P}from"react/jsx-runtime";var qt=qe.default||qe,Dt=qt(Ht),O=J(["github-light","github-dark"]),z=J(void 0),H=J(!0),Et={singleDollarTextMath:!1},_t={},Ee=De(({content:e,shouldParseIncompleteMarkdown:t,...o})=>{let s=X(()=>typeof e=="string"&&t?Ae(e.trim()):e,[e,t]);return P(Dt,{...o,children:s})},(e,t)=>e.content===t.content);Ee.displayName="Block";var Ot=De(({children:e,allowedImagePrefixes:t=["*"],allowedLinkPrefixes:o=["*"],defaultOrigin:s,parseIncompleteMarkdown:r=!0,components:n,rehypePlugins:a,remarkPlugins:l,className:i,shikiTheme:c=["github-light","github-dark"],mermaidConfig:m,controls:h=!0,...g})=>{let u=$t(),f=X(()=>je(typeof e=="string"?e:""),[e]),w=X(()=>()=>xt({errorColor:"var(--color-muted-foreground)"}),[]);return P(O.Provider,{value:c,children:P(z.Provider,{value:m,children:P(H.Provider,{value:h,children:P("div",{className:d("space-y-4",i),...g,children:f.map((v,M)=>P(Ee,{allowedImagePrefixes:t,allowedLinkPrefixes:o,components:{...xe,...n},content:v,defaultOrigin:s,rehypePlugins:[jt,w,...a!=null?a:[]],remarkPlugins:[[Rt,_t],[At,Et],...l!=null?l:[]],shouldParseIncompleteMarkdown:r},`${u}-block_${M}`))})})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Ot.displayName="Streamdown";export{H as ControlsContext,z as MermaidConfigContext,O as ShikiThemeContext,Ot as Streamdown};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamdown",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"mermaid": "^11.11.0",
|
|
51
51
|
"react-markdown": "^10.1.0",
|
|
52
52
|
"rehype-katex": "^7.0.1",
|
|
53
|
+
"rehype-raw": "^7.0.0",
|
|
53
54
|
"remark-gfm": "^4.0.1",
|
|
54
55
|
"remark-math": "^6.0.0",
|
|
55
56
|
"shiki": "^3.12.2",
|