@echoease/streamdown-edge 1.0.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 +53 -0
- package/dist/chunk-DDL734BZ.js +2 -0
- package/dist/chunk-YHGJ7S36.cjs +2 -0
- package/dist/code-block-HNJHFH25.js +2 -0
- package/dist/code-block-RZYTVPVD.cjs +2 -0
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +58 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.js +11 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Streamdown
|
|
2
|
+
|
|
3
|
+
A drop-in replacement for react-markdown, designed for AI-powered streaming.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/streamdown)
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
Formatting Markdown is easy, but when you tokenize and stream it, new challenges arise. Streamdown is built specifically to handle the unique requirements of streaming Markdown content from AI models, providing seamless formatting even with incomplete or unterminated Markdown blocks.
|
|
10
|
+
|
|
11
|
+
Streamdown powers the [AI Elements Message](https://ai-sdk.dev/elements/components/message) component but can be installed as a standalone package for your own streaming needs.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- 🚀 **Drop-in replacement** for `react-markdown`
|
|
16
|
+
- 🔄 **Streaming-optimized** - Handles incomplete Markdown gracefully
|
|
17
|
+
- 🎨 **Unterminated block parsing** - Build with `remend` for better streaming quality
|
|
18
|
+
- 📊 **GitHub Flavored Markdown** - Tables, task lists, and strikethrough support
|
|
19
|
+
- 🔢 **Math rendering** - LaTeX equations via KaTeX
|
|
20
|
+
- 📈 **Mermaid diagrams** - Render Mermaid diagrams as code blocks with a button to render them
|
|
21
|
+
- 🎯 **Code syntax highlighting** - Beautiful code blocks with Shiki
|
|
22
|
+
- 🛡️ **Security-first** - Built with `rehype-harden` for safe rendering
|
|
23
|
+
- ⚡ **Performance optimized** - Memoized rendering for efficient updates
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm i streamdown
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then, update your Tailwind `globals.css` to include the following.
|
|
32
|
+
|
|
33
|
+
```css
|
|
34
|
+
@source "../node_modules/streamdown/dist/*.js";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Make sure the path matches the location of the `node_modules` folder in your project. This will ensure that the Streamdown styles are applied to your project.
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
You can use Streamdown in your React application like this:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { Streamdown } from "streamdown";
|
|
45
|
+
|
|
46
|
+
export default function Page() {
|
|
47
|
+
const markdown = "# Hello World\n\nThis is **streaming** markdown!";
|
|
48
|
+
|
|
49
|
+
return <Streamdown>{markdown}</Streamdown>;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For more info, see the [documentation](https://streamdown.ai/docs).
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {createContext,useContext}from'react';var m=(...o)=>twMerge(clsx(o)),x=(o,t,r)=>{let n=typeof t=="string"?new Blob([t],{type:r}):t,c=URL.createObjectURL(n),e=document.createElement("a");e.href=c,e.download=o,document.body.appendChild(e),e.click(),document.body.removeChild(e),URL.revokeObjectURL(c);};var C=createContext({code:""}),y=()=>useContext(C);export{m as a,x as b,C as c,y as d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),react=require('react');var m=(...o)=>tailwindMerge.twMerge(clsx.clsx(o)),x=(o,t,r)=>{let n=typeof t=="string"?new Blob([t],{type:r}):t,c=URL.createObjectURL(n),e=document.createElement("a");e.href=c,e.download=o,document.body.appendChild(e),e.click(),document.body.removeChild(e),URL.revokeObjectURL(c);};var C=react.createContext({code:""}),y=()=>react.useContext(C);exports.a=m;exports.b=x;exports.c=C;exports.d=y;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {a,c}from'./chunk-DDL734BZ.js';import {Highlight,themes}from'prism-react-renderer';import {jsx,jsxs}from'react/jsx-runtime';var l=({className:o,language:e,style:n,...a$1})=>jsx("div",{className:a("my-4 w-full overflow-hidden rounded-xl border border-border",o),"data-language":e,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...n},...a$1});var i=({language:o,children:e})=>jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":o,"data-streamdown":"code-block-header",children:[jsx("span",{className:"ml-1 font-mono lowercase",children:o}),jsx("div",{className:"flex items-center gap-2",children:e})]});var P=a("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),z=({code:o,language:e,className:n,children:a$1,...m})=>{let p=e.toLowerCase()||"text";return jsx(c.Provider,{value:{code:o},children:jsxs(l,{language:e,children:[jsx(i,{language:e,children:a$1}),jsx(Highlight,{theme:themes.github,code:o,language:p,children:({tokens:f,getLineProps:C,getTokenProps:b,style:g})=>jsx("pre",{className:a(n,"p-4 text-sm"),"data-language":e,"data-streamdown":"code-block-body",style:g,...m,children:jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:f.map((d,k)=>jsx("span",{className:P,...C({line:d}),children:d.map((u,B)=>jsx("span",{...b({token:u})},B))},k))})})})]})})};export{z as CodeBlock};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var chunkYHGJ7S36_cjs=require('./chunk-YHGJ7S36.cjs'),prismReactRenderer=require('prism-react-renderer'),jsxRuntime=require('react/jsx-runtime');var l=({className:o,language:e,style:n,...a})=>jsxRuntime.jsx("div",{className:chunkYHGJ7S36_cjs.a("my-4 w-full overflow-hidden rounded-xl border border-border",o),"data-language":e,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...n},...a});var i=({language:o,children:e})=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":o,"data-streamdown":"code-block-header",children:[jsxRuntime.jsx("span",{className:"ml-1 font-mono lowercase",children:o}),jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:e})]});var P=chunkYHGJ7S36_cjs.a("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),z=({code:o,language:e,className:n,children:a,...m})=>{let p=e.toLowerCase()||"text";return jsxRuntime.jsx(chunkYHGJ7S36_cjs.c.Provider,{value:{code:o},children:jsxRuntime.jsxs(l,{language:e,children:[jsxRuntime.jsx(i,{language:e,children:a}),jsxRuntime.jsx(prismReactRenderer.Highlight,{theme:prismReactRenderer.themes.github,code:o,language:p,children:({tokens:f,getLineProps:C,getTokenProps:b,style:g})=>jsxRuntime.jsx("pre",{className:chunkYHGJ7S36_cjs.a(n,"p-4 text-sm"),"data-language":e,"data-streamdown":"code-block-body",style:g,...m,children:jsxRuntime.jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:f.map((d,k)=>jsxRuntime.jsx("span",{className:P,...C({line:d}),children:d.map((u,B)=>jsxRuntime.jsx("span",{...b({token:u})},B))},k))})})})]})})};exports.CodeBlock=z;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var chunkYHGJ7S36_cjs=require('./chunk-YHGJ7S36.cjs'),react=require('react'),rehypeHarden=require('rehype-harden'),G=require('rehype-katex'),Ut=require('rehype-raw'),Gt=require('rehype-sanitize'),Yt=require('remark-cjk-friendly'),Qt=require('remark-cjk-friendly-gfm-strikethrough'),Zt=require('remark-gfm'),Y=require('remark-math'),eo=require('remend'),lucideReact=require('lucide-react'),jsxRuntime=require('react/jsx-runtime'),hastUtilToJsxRuntime=require('hast-util-to-jsx-runtime'),jt=require('remark-parse'),At=require('remark-rehype'),unified=require('unified'),marked=require('marked');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var G__default=/*#__PURE__*/_interopDefault(G);var Ut__default=/*#__PURE__*/_interopDefault(Ut);var Gt__default=/*#__PURE__*/_interopDefault(Gt);var Yt__default=/*#__PURE__*/_interopDefault(Yt);var Qt__default=/*#__PURE__*/_interopDefault(Qt);var Zt__default=/*#__PURE__*/_interopDefault(Zt);var Y__default=/*#__PURE__*/_interopDefault(Y);var eo__default=/*#__PURE__*/_interopDefault(eo);var jt__default=/*#__PURE__*/_interopDefault(jt);var At__default=/*#__PURE__*/_interopDefault(At);var te=({onCopy:e,onError:t,timeout:s=2e3,children:o,className:a,code:n,...c})=>{let[r,l]=react.useState(false),d=react.useRef(0),{code:i}=chunkYHGJ7S36_cjs.d(),{isAnimating:m}=react.useContext(v),u=n!=null?n:i,b=async()=>{var y;if(typeof window=="undefined"||!((y=navigator==null?void 0:navigator.clipboard)!=null&&y.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{r||(await navigator.clipboard.writeText(u),l(!0),e==null||e(),d.current=window.setTimeout(()=>l(!1),s));}catch(k){t==null||t(k);}};react.useEffect(()=>()=>{window.clearTimeout(d.current);},[]);let f=r?lucideReact.CheckIcon:lucideReact.CopyIcon;return jsxRuntime.jsx("button",{className:chunkYHGJ7S36_cjs.a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",a),"data-streamdown":"code-block-copy-button",disabled:m,onClick:b,title:"Copy Code",type:"button",...c,children:o!=null?o:jsxRuntime.jsx(f,{size:14})})};var oe={"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"},ne=({onDownload:e,onError:t,language:s,children:o,className:a,code:n,...c})=>{let{code:r}=chunkYHGJ7S36_cjs.d(),{isAnimating:l}=react.useContext(v),d=n!=null?n:r,m=`file.${s&&s in oe?oe[s]:"txt"}`,u="text/plain",b=()=>{try{chunkYHGJ7S36_cjs.b(m,d,u),e==null||e();}catch(f){t==null||t(f);}};return jsxRuntime.jsx("button",{className:chunkYHGJ7S36_cjs.a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",a),"data-streamdown":"code-block-download-button",disabled:l,onClick:b,title:"Download file",type:"button",...c,children:o!=null?o:jsxRuntime.jsx(lucideReact.DownloadIcon,{size:14})})};var re=()=>jsxRuntime.jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsxRuntime.jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsxRuntime.jsx(lucideReact.Loader2Icon,{className:"size-4 animate-spin"})})]});var dt=/\.[^/.]+$/,ae=({node:e,className:t,src:s,alt:o,...a})=>{let n=async()=>{if(s)try{let r=await(await fetch(s)).blob(),d=new URL(s,window.location.origin).pathname.split("/").pop()||"",i=d.split(".").pop(),m=d.includes(".")&&i!==void 0&&i.length<=4,u="";if(m)u=d;else {let b=r.type,f="png";b.includes("jpeg")||b.includes("jpg")?f="jpg":b.includes("png")?f="png":b.includes("svg")?f="svg":b.includes("gif")?f="gif":b.includes("webp")&&(f="webp"),u=`${(o||d||"image").replace(dt,"")}.${f}`;}chunkYHGJ7S36_cjs.b(u,r,r.type);}catch(c){console.error("Failed to download image:",c);}};return s?jsxRuntime.jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsxRuntime.jsx("img",{alt:o,className:chunkYHGJ7S36_cjs.a("max-w-full rounded-lg",t),"data-streamdown":"image",src:s,...a}),jsxRuntime.jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsxRuntime.jsx("button",{className:chunkYHGJ7S36_cjs.a("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:jsxRuntime.jsx(lucideReact.DownloadIcon,{size:14})})]}):null};var I=e=>{var n,c;let t=[],s=[],o=e.querySelectorAll("thead th");for(let r of o)t.push(((n=r.textContent)==null?void 0:n.trim())||"");let a=e.querySelectorAll("tbody tr");for(let r of a){let l=[],d=r.querySelectorAll("td");for(let i of d)l.push(((c=i.textContent)==null?void 0:c.trim())||"");s.push(l);}return {headers:t,rows:s}},E=e=>{let{headers:t,rows:s}=e,o=r=>{let l=false,d=false;for(let i of r){if(i==='"'){l=true,d=true;break}(i===","||i===`
|
|
3
|
+
`)&&(l=true);}return l?d?`"${r.replace(/"/g,'""')}"`:`"${r}"`:r},a=t.length>0?s.length+1:s.length,n=new Array(a),c=0;t.length>0&&(n[c]=t.map(o).join(","),c+=1);for(let r of s)n[c]=r.map(o).join(","),c+=1;return n.join(`
|
|
4
|
+
`)},le=e=>{let{headers:t,rows:s}=e,o=r=>{let l=false;for(let i of r)if(i===" "||i===`
|
|
5
|
+
`||i==="\r"){l=true;break}if(!l)return r;let d=[];for(let i of r)i===" "?d.push("\\t"):i===`
|
|
6
|
+
`?d.push("\\n"):i==="\r"?d.push("\\r"):d.push(i);return d.join("")},a=t.length>0?s.length+1:s.length,n=new Array(a),c=0;t.length>0&&(n[c]=t.map(o).join(" "),c+=1);for(let r of s)n[c]=r.map(o).join(" "),c+=1;return n.join(`
|
|
7
|
+
`)},X=e=>{let t=false;for(let o of e)if(o==="\\"||o==="|"){t=true;break}if(!t)return e;let s=[];for(let o of e)o==="\\"?s.push("\\\\"):o==="|"?s.push("\\|"):s.push(o);return s.join("")},ie=e=>{let{headers:t,rows:s}=e;if(t.length===0)return "";let o=new Array(s.length+2),a=0,n=t.map(r=>X(r));o[a]=`| ${n.join(" | ")} |`,a+=1;let c=new Array(t.length);for(let r=0;r<t.length;r+=1)c[r]="---";o[a]=`| ${c.join(" | ")} |`,a+=1;for(let r of s)if(r.length<t.length){let l=new Array(t.length);for(let d=0;d<t.length;d+=1)l[d]=d<r.length?X(r[d]):"";o[a]=`| ${l.join(" | ")} |`,a+=1;}else {let l=r.map(d=>X(d));o[a]=`| ${l.join(" | ")} |`,a+=1;}return o.join(`
|
|
8
|
+
`)};var pe=({children:e,className:t,onCopy:s,onError:o,timeout:a=2e3})=>{let[n,c]=react.useState(false),[r,l]=react.useState(false),d=react.useRef(null),i=react.useRef(0),{isAnimating:m}=react.useContext(v),u=async f=>{var y,k;if(typeof window=="undefined"||!((y=navigator==null?void 0:navigator.clipboard)!=null&&y.write)){o==null||o(new Error("Clipboard API not available"));return}try{let x=(k=d.current)==null?void 0:k.closest('[data-streamdown="table-wrapper"]'),P=x==null?void 0:x.querySelector("table");if(!P){o==null||o(new Error("Table not found"));return}let T=I(P),R=f==="csv"?E(T):le(T),$=new ClipboardItem({"text/plain":new Blob([R],{type:"text/plain"}),"text/html":new Blob([P.outerHTML],{type:"text/html"})});await navigator.clipboard.write([$]),l(!0),c(!1),s==null||s(f),i.current=window.setTimeout(()=>l(!1),a);}catch(x){o==null||o(x);}};react.useEffect(()=>{let f=y=>{d.current&&!d.current.contains(y.target)&&c(false);};return document.addEventListener("mousedown",f),()=>{document.removeEventListener("mousedown",f),window.clearTimeout(i.current);}},[]);let b=r?lucideReact.CheckIcon:lucideReact.CopyIcon;return jsxRuntime.jsxs("div",{className:"relative",ref:d,children:[jsxRuntime.jsx("button",{className:chunkYHGJ7S36_cjs.a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>c(!n),title:"Copy table",type:"button",children:e!=null?e:jsxRuntime.jsx(b,{size:14})}),n?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var fe=({children:e,className:t,onDownload:s,onError:o})=>{let[a,n]=react.useState(false),c=react.useRef(null),{isAnimating:r}=react.useContext(v),l=d=>{var i;try{let m=(i=c.current)==null?void 0:i.closest('[data-streamdown="table-wrapper"]'),u=m==null?void 0:m.querySelector("table");if(!u){o==null||o(new Error("Table not found"));return}let b=I(u),f=d==="csv"?E(b):ie(b);chunkYHGJ7S36_cjs.b(`table.${d==="csv"?"csv":"md"}`,f,d==="csv"?"text/csv":"text/markdown"),n(!1),s==null||s(d);}catch(m){o==null||o(m);}};return react.useEffect(()=>{let d=i=>{c.current&&!c.current.contains(i.target)&&n(false);};return document.addEventListener("mousedown",d),()=>{document.removeEventListener("mousedown",d);}},[]),jsxRuntime.jsxs("div",{className:"relative",ref:c,children:[jsxRuntime.jsx("button",{className:chunkYHGJ7S36_cjs.a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:r,onClick:()=>n(!a),title:"Download table",type:"button",children:e!=null?e:jsxRuntime.jsx(lucideReact.DownloadIcon,{size:14})}),a?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var be=({children:e,className:t,showControls:s,...o})=>jsxRuntime.jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[s?jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsxRuntime.jsx(pe,{}),jsxRuntime.jsx(fe,{})]}):null,jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsx("table",{className:chunkYHGJ7S36_cjs.a("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]});var Tt=react.lazy(()=>import('./code-block-RZYTVPVD.cjs').then(e=>({default:e.CodeBlock}))),Ct=/language-([^\s]+)/;function O(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let s=e.position.start,o=t.position.start,a=e.position.end,n=t.position.end;return (s==null?void 0:s.line)===(o==null?void 0:o.line)&&(s==null?void 0:s.column)===(o==null?void 0:o.column)&&(a==null?void 0:a.line)===(n==null?void 0:n.line)&&(a==null?void 0:a.column)===(n==null?void 0:n.column)}function w(e,t){return e.className===t.className&&O(e.node,t.node)}var ye=(e,t)=>typeof e=="boolean"?e:e[t]!==false,W=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("ol",{className:chunkYHGJ7S36_cjs.a("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>w(e,t));W.displayName="MarkdownOl";var we=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("li",{className:chunkYHGJ7S36_cjs.a("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&O(e.node,t.node));we.displayName="MarkdownLi";var ke=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("ul",{className:chunkYHGJ7S36_cjs.a("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>w(e,t));ke.displayName="MarkdownUl";var xe=react.memo(({className:e,node:t,...s})=>jsxRuntime.jsx("hr",{className:chunkYHGJ7S36_cjs.a("my-6 border-border",e),"data-streamdown":"horizontal-rule",...s}),(e,t)=>w(e,t));xe.displayName="MarkdownHr";var ve=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("span",{className:chunkYHGJ7S36_cjs.a("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>w(e,t));ve.displayName="MarkdownStrong";var Te=react.memo(({children:e,className:t,href:s,node:o,...a})=>{let n=s==="streamdown:incomplete-link";return jsxRuntime.jsx("a",{className:chunkYHGJ7S36_cjs.a("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":n,"data-streamdown":"link",href:s,rel:"noreferrer",target:"_blank",...a,children:e})},(e,t)=>w(e,t)&&e.href===t.href);Te.displayName="MarkdownA";var Ce=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("h1",{className:chunkYHGJ7S36_cjs.a("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>w(e,t));Ce.displayName="MarkdownH1";var Pe=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("h2",{className:chunkYHGJ7S36_cjs.a("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>w(e,t));Pe.displayName="MarkdownH2";var Ne=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("h3",{className:chunkYHGJ7S36_cjs.a("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>w(e,t));Ne.displayName="MarkdownH3";var Me=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("h4",{className:chunkYHGJ7S36_cjs.a("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>w(e,t));Me.displayName="MarkdownH4";var Se=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("h5",{className:chunkYHGJ7S36_cjs.a("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>w(e,t));Se.displayName="MarkdownH5";var De=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("h6",{className:chunkYHGJ7S36_cjs.a("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>w(e,t));De.displayName="MarkdownH6";var Re=react.memo(({children:e,className:t,node:s,...o})=>{let{controls:a}=react.useContext(v),n=ye(a,"table");return jsxRuntime.jsx(be,{className:t,"data-streamdown":"table-wrapper",showControls:n,...o,children:e})},(e,t)=>w(e,t));Re.displayName="MarkdownTable";var je=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("thead",{className:chunkYHGJ7S36_cjs.a("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>w(e,t));je.displayName="MarkdownThead";var Ae=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("tbody",{className:chunkYHGJ7S36_cjs.a("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>w(e,t));Ae.displayName="MarkdownTbody";var Ie=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("tr",{className:chunkYHGJ7S36_cjs.a("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>w(e,t));Ie.displayName="MarkdownTr";var Ee=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("th",{className:chunkYHGJ7S36_cjs.a("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>w(e,t));Ee.displayName="MarkdownTh";var Le=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("td",{className:chunkYHGJ7S36_cjs.a("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>w(e,t));Le.displayName="MarkdownTd";var He=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("blockquote",{className:chunkYHGJ7S36_cjs.a("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>w(e,t));He.displayName="MarkdownBlockquote";var Be=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("sup",{className:chunkYHGJ7S36_cjs.a("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>w(e,t));Be.displayName="MarkdownSup";var Oe=react.memo(({children:e,className:t,node:s,...o})=>jsxRuntime.jsx("sub",{className:chunkYHGJ7S36_cjs.a("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>w(e,t));Oe.displayName="MarkdownSub";var qe=react.memo(({children:e,className:t,node:s,...o})=>{if("data-footnotes"in o){let n=l=>{var u,b;if(!react.isValidElement(l))return false;let d=Array.isArray(l.props.children)?l.props.children:[l.props.children],i=false,m=false;for(let f of d)if(f){if(typeof f=="string")f.trim()!==""&&(i=true);else if(react.isValidElement(f))if(((u=f.props)==null?void 0:u["data-footnote-backref"])!==void 0)m=true;else {let y=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let k of y){if(typeof k=="string"&&k.trim()!==""){i=true;break}if(react.isValidElement(k)&&((b=k.props)==null?void 0:b["data-footnote-backref"])===void 0){i=true;break}}}}return m&&!i},c=Array.isArray(e)?e.map(l=>{if(!react.isValidElement(l))return l;if(l.type===W){let i=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(m=>!n(m));return i.length===0?null:{...l,props:{...l.props,children:i}}}return l}):e;return (Array.isArray(c)?c.some(l=>l!==null):c!==null)?jsxRuntime.jsx("section",{className:t,...o,children:c}):null}return jsxRuntime.jsx("section",{className:t,...o,children:e})},(e,t)=>w(e,t));qe.displayName="MarkdownSection";var Pt=({node:e,className:t,children:s,...o})=>{var i,m,u;let a=((i=e==null?void 0:e.position)==null?void 0:i.start.line)===((m=e==null?void 0:e.position)==null?void 0:m.end.line),{controls:n}=react.useContext(v);if(a)return jsxRuntime.jsx("code",{className:chunkYHGJ7S36_cjs.a("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...o,children:s});let c=t==null?void 0:t.match(Ct),r=(u=c==null?void 0:c.at(1))!=null?u:"",l="";react.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);let d=ye(n,"code");return jsxRuntime.jsx(react.Suspense,{fallback:jsxRuntime.jsx(re,{}),children:jsxRuntime.jsx(Tt,{className:chunkYHGJ7S36_cjs.a("overflow-x-auto border-border border-t",t),code:l,language:r,children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ne,{code:l,language:r}),jsxRuntime.jsx(te,{})]}):null})})},$e=react.memo(Pt,(e,t)=>e.className===t.className&&O(e.node,t.node));$e.displayName="MarkdownCode";var Je=react.memo(ae,(e,t)=>e.className===t.className&&O(e.node,t.node));Je.displayName="MarkdownImg";var ze=react.memo(({children:e,className:t,node:s,...o})=>{var c;let n=(Array.isArray(e)?e:[e]).filter(r=>r!=null&&r!=="");return n.length===1&&react.isValidElement(n[0])&&((c=n[0].props.node)==null?void 0:c.tagName)==="img"?jsxRuntime.jsx(jsxRuntime.Fragment,{children:e}):jsxRuntime.jsx("p",{className:t,...o,children:e})},(e,t)=>w(e,t));ze.displayName="MarkdownParagraph";var Xe={ol:W,li:we,ul:ke,hr:xe,strong:ve,a:Te,h1:Ce,h2:Pe,h3:Ne,h4:Me,h5:Se,h6:De,table:Re,thead:je,tbody:Ae,tr:Ie,th:Ee,td:Le,blockquote:He,code:$e,img:Je,pre:({children:e})=>e,sup:Be,sub:Oe,p:ze,section:qe};var Ke=[],Ve={allowDangerousHtml:true},q=new WeakMap,K=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let s=this.keyCache.get(t);if(s)return s;let o=t.rehypePlugins,a=t.remarkPlugins,n=t.remarkRehypeOptions;if(!(o||a||n)){let m="default";return this.keyCache.set(t,m),m}let c=m=>{if(!m||m.length===0)return "";let u="";for(let b=0;b<m.length;b+=1){let f=m[b];if(b>0&&(u+=","),Array.isArray(f)){let[y,k]=f;if(typeof y=="function"){let x=q.get(y);x||(x=y.name,q.set(y,x)),u+=x;}else u+=String(y);u+=":",u+=JSON.stringify(k);}else if(typeof f=="function"){let y=q.get(f);y||(y=f.name,q.set(f,y)),u+=y;}else u+=String(f);}return u},r=c(o),l=c(a),d=n?JSON.stringify(n):"",i=`${l}::${r}::${d}`;return this.keyCache.set(t,i),i}get(t){let s=this.generateCacheKey(t),o=this.cache.get(s);return o&&(this.cache.delete(s),this.cache.set(s,o)),o}set(t,s){let o=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let a=this.cache.keys().next().value;a&&this.cache.delete(a);}this.cache.set(o,s);}clear(){this.cache.clear();}},Fe=new K,V=e=>{let t=Et(e),s=e.children||"";return Ht(t.runSync(t.parse(s),s),e)},Et=e=>{let t=Fe.get(e);if(t)return t;let s=Lt(e);return Fe.set(e,s),s},Lt=e=>{let t=e.rehypePlugins||Ke,s=e.remarkPlugins||Ke,o=e.remarkRehypeOptions?{...Ve,...e.remarkRehypeOptions}:Ve;return unified.unified().use(jt__default.default).use(s).use(At__default.default,o).use(t)},Ht=(e,t)=>hastUtilToJsxRuntime.toJsxRuntime(e,{Fragment:jsxRuntime.Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsxRuntime.jsx,jsxs:jsxRuntime.jsxs,passKeys:true,passNode:true});var Ot=/\[\^[^\]\s]{1,200}\](?!:)/,qt=/\[\^[^\]\s]{1,200}\]:/,$t=/<\/(\w+)>/,Jt=/<(\w+)[\s>]/,F=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},zt=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},_=e=>{let t=0;for(let s=0;s<e.length-1;s+=1)e[s]==="$"&&e[s+1]==="$"&&(t+=1,s+=1);return t},U=e=>{let t=Ot.test(e),s=qt.test(e);if(t||s)return [e];let o=marked.Lexer.lex(e,{gfm:true}),a=[],n=[];for(let c of o){let r=c.raw,l=a.length;if(n.length>0){if(a[l-1]+=r,c.type==="html"){let i=r.match($t);if(i){let m=i[1];n.at(-1)===m&&n.pop();}}continue}if(c.type==="html"&&c.block){let i=r.match(Jt);if(i){let m=i[1];r.includes(`</${m}>`)||n.push(m);}}if(r.trim()==="$$"&&l>0){let i=a[l-1],m=F(i),u=_(i);if(m&&u%2===1){a[l-1]=i+r;continue}}if(l>0&&zt(r)){let i=a[l-1],m=F(i),u=_(i),b=_(r);if(m&&u%2===1&&!F(r)&&b===1){a[l-1]=i+r;continue}}a.push(r);}return a};var _e={dependencies:{"rehype-katex":"^7.0.1"}};var to=/[^$]\$[^$]/,oo=/^\$[^$]/,so=/[^$]\$$/,no={raw:Ut__default.default,sanitize:[Gt__default.default,{}],katex:[G__default.default,{errorColor:"var(--color-muted-foreground)"}],harden:[rehypeHarden.harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},ro={gfm:[Zt__default.default,{}],math:[Y__default.default,{singleDollarTextMath:false}],cjkFriendly:[Yt__default.default,{}],cjkFriendlyGfmStrikethrough:[Qt__default.default,{}]},ao=Object.values(no),lo=Object.values(ro),io={block:" \u258B",circle:" \u25CF"},co={controls:true,isAnimating:false,mode:"streaming"},v=react.createContext(co),Ye=react.memo(({content:e,...t})=>jsxRuntime.jsx(V,{...t,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let s=Object.keys(e.components||{}),o=Object.keys(t.components||{});if(s.length!==o.length||s.some(a=>{var n,c;return ((n=e.components)==null?void 0:n[a])!==((c=t.components)==null?void 0:c[a])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Ye.displayName="Block";var mo=e=>Array.isArray(e)&&e.some(t=>Array.isArray(t)?t[0]===G__default.default:t===G__default.default),po=e=>{if(!Array.isArray(e))return false;let t=e.find(s=>Array.isArray(s)?s[0]===Y__default.default:s===Y__default.default);return t&&Array.isArray(t)&&t[1]?t[1].singleDollarTextMath===true:false},uo=(e,t)=>{let s=e.includes("$$"),o=t&&(to.test(e)||oo.test(e)||so.test(e));return s||o},fo=/^\^/,go=()=>{let e=_e.dependencies["rehype-katex"].replace(fo,"").split(".")[0],s={7:"0.16.22"}[e]||"0.16.22",o=document.createElement("link");o.rel="stylesheet",o.href=`https://cdn.jsdelivr.net/npm/katex@${s}/dist/katex.min.css`,document.head.appendChild(o);},bo=react.memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:s=true,components:o,rehypePlugins:a=ao,remarkPlugins:n=lo,className:c,controls:r=true,isAnimating:l=false,BlockComponent:d=Ye,parseMarkdownIntoBlocksFn:i=U,caret:m,...u})=>{let b=react.useId(),[f,y]=react.useTransition(),[k,x]=react.useState([]),P=react.useMemo(()=>typeof e!="string"?"":t==="streaming"&&s?eo__default.default(e):e,[e,t,s]),T=react.useMemo(()=>i(P),[P,i]);react.useEffect(()=>{t==="streaming"?y(()=>{x(T);}):x(T);},[T,t]);let R=t==="streaming"?k:T,$=react.useMemo(()=>R.map((J,N)=>`${b}-${N}`),[R.length,b]),Q=react.useMemo(()=>({controls:r,isAnimating:l,mode:t}),[r,l,t]),Z=react.useMemo(()=>({...Xe,...o}),[o]);react.useEffect(()=>{if(!mo(a))return;let N=po(n);uo(typeof e=="string"?e:"",N)&&go();},[a,n,e]);let Qe=react.useMemo(()=>m&&l?{"--streamdown-caret":`"${io[m]}"`}:void 0,[m,l]);return t==="static"?jsxRuntime.jsx(v.Provider,{value:Q,children:jsxRuntime.jsx("div",{className:chunkYHGJ7S36_cjs.a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",c),children:jsxRuntime.jsx(V,{components:Z,rehypePlugins:a,remarkPlugins:n,...u,children:e})})}):jsxRuntime.jsx(v.Provider,{value:Q,children:jsxRuntime.jsx("div",{className:chunkYHGJ7S36_cjs.a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",m?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,c),style:Qe,children:R.map((J,N)=>jsxRuntime.jsx(d,{components:Z,content:J,index:N,rehypePlugins:a,remarkPlugins:n,shouldParseIncompleteMarkdown:s,...u},$[N]))})})},(e,t)=>e.children===t.children&&e.isAnimating===t.isAnimating&&e.mode===t.mode);bo.displayName="Streamdown";
|
|
11
|
+
exports.Block=Ye;exports.Streamdown=bo;exports.StreamdownContext=v;exports.defaultRehypePlugins=no;exports.defaultRemarkPlugins=ro;exports.parseMarkdownIntoBlocks=U;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { JSX, ComponentType } from 'react';
|
|
4
|
+
import { PluggableList, Pluggable } from 'unified';
|
|
5
|
+
import { Element } from 'hast';
|
|
6
|
+
import { Options as Options$1 } from 'remark-rehype';
|
|
7
|
+
|
|
8
|
+
type ExtraProps = {
|
|
9
|
+
node?: Element | undefined;
|
|
10
|
+
};
|
|
11
|
+
type Components = {
|
|
12
|
+
[Key in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Key] & ExtraProps> | keyof JSX.IntrinsicElements;
|
|
13
|
+
};
|
|
14
|
+
type Options = {
|
|
15
|
+
children?: string;
|
|
16
|
+
components?: Components;
|
|
17
|
+
rehypePlugins?: PluggableList;
|
|
18
|
+
remarkPlugins?: PluggableList;
|
|
19
|
+
remarkRehypeOptions?: Readonly<Options$1>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
23
|
+
|
|
24
|
+
type ControlsConfig = boolean | {
|
|
25
|
+
table?: boolean;
|
|
26
|
+
code?: boolean;
|
|
27
|
+
};
|
|
28
|
+
type StreamdownProps = Options & {
|
|
29
|
+
mode?: "static" | "streaming";
|
|
30
|
+
BlockComponent?: React.ComponentType<BlockProps>;
|
|
31
|
+
parseMarkdownIntoBlocksFn?: (markdown: string) => string[];
|
|
32
|
+
parseIncompleteMarkdown?: boolean;
|
|
33
|
+
className?: string;
|
|
34
|
+
controls?: ControlsConfig;
|
|
35
|
+
isAnimating?: boolean;
|
|
36
|
+
caret?: keyof typeof carets;
|
|
37
|
+
};
|
|
38
|
+
declare const defaultRehypePlugins: Record<string, Pluggable>;
|
|
39
|
+
declare const defaultRemarkPlugins: Record<string, Pluggable>;
|
|
40
|
+
declare const carets: {
|
|
41
|
+
block: string;
|
|
42
|
+
circle: string;
|
|
43
|
+
};
|
|
44
|
+
type StreamdownContextType = {
|
|
45
|
+
controls: ControlsConfig;
|
|
46
|
+
isAnimating: boolean;
|
|
47
|
+
mode: "static" | "streaming";
|
|
48
|
+
};
|
|
49
|
+
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
50
|
+
type BlockProps = Options & {
|
|
51
|
+
content: string;
|
|
52
|
+
shouldParseIncompleteMarkdown: boolean;
|
|
53
|
+
index: number;
|
|
54
|
+
};
|
|
55
|
+
declare const Block: react.MemoExoticComponent<({ content, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
56
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, caret, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
57
|
+
|
|
58
|
+
export { Block, type ControlsConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, defaultRehypePlugins, defaultRemarkPlugins, parseMarkdownIntoBlocks };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { JSX, ComponentType } from 'react';
|
|
4
|
+
import { PluggableList, Pluggable } from 'unified';
|
|
5
|
+
import { Element } from 'hast';
|
|
6
|
+
import { Options as Options$1 } from 'remark-rehype';
|
|
7
|
+
|
|
8
|
+
type ExtraProps = {
|
|
9
|
+
node?: Element | undefined;
|
|
10
|
+
};
|
|
11
|
+
type Components = {
|
|
12
|
+
[Key in keyof JSX.IntrinsicElements]?: ComponentType<JSX.IntrinsicElements[Key] & ExtraProps> | keyof JSX.IntrinsicElements;
|
|
13
|
+
};
|
|
14
|
+
type Options = {
|
|
15
|
+
children?: string;
|
|
16
|
+
components?: Components;
|
|
17
|
+
rehypePlugins?: PluggableList;
|
|
18
|
+
remarkPlugins?: PluggableList;
|
|
19
|
+
remarkRehypeOptions?: Readonly<Options$1>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
23
|
+
|
|
24
|
+
type ControlsConfig = boolean | {
|
|
25
|
+
table?: boolean;
|
|
26
|
+
code?: boolean;
|
|
27
|
+
};
|
|
28
|
+
type StreamdownProps = Options & {
|
|
29
|
+
mode?: "static" | "streaming";
|
|
30
|
+
BlockComponent?: React.ComponentType<BlockProps>;
|
|
31
|
+
parseMarkdownIntoBlocksFn?: (markdown: string) => string[];
|
|
32
|
+
parseIncompleteMarkdown?: boolean;
|
|
33
|
+
className?: string;
|
|
34
|
+
controls?: ControlsConfig;
|
|
35
|
+
isAnimating?: boolean;
|
|
36
|
+
caret?: keyof typeof carets;
|
|
37
|
+
};
|
|
38
|
+
declare const defaultRehypePlugins: Record<string, Pluggable>;
|
|
39
|
+
declare const defaultRemarkPlugins: Record<string, Pluggable>;
|
|
40
|
+
declare const carets: {
|
|
41
|
+
block: string;
|
|
42
|
+
circle: string;
|
|
43
|
+
};
|
|
44
|
+
type StreamdownContextType = {
|
|
45
|
+
controls: ControlsConfig;
|
|
46
|
+
isAnimating: boolean;
|
|
47
|
+
mode: "static" | "streaming";
|
|
48
|
+
};
|
|
49
|
+
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
50
|
+
type BlockProps = Options & {
|
|
51
|
+
content: string;
|
|
52
|
+
shouldParseIncompleteMarkdown: boolean;
|
|
53
|
+
index: number;
|
|
54
|
+
};
|
|
55
|
+
declare const Block: react.MemoExoticComponent<({ content, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
56
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, controls, isAnimating, BlockComponent, parseMarkdownIntoBlocksFn, caret, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
57
|
+
|
|
58
|
+
export { Block, type ControlsConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, defaultRehypePlugins, defaultRemarkPlugins, parseMarkdownIntoBlocks };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {a,d,b}from'./chunk-DDL734BZ.js';import {lazy,memo,useContext,createContext,isValidElement,useId,useTransition,useState,useMemo,useEffect,Suspense,useRef}from'react';import {harden}from'rehype-harden';import G from'rehype-katex';import Ut from'rehype-raw';import Gt from'rehype-sanitize';import Yt from'remark-cjk-friendly';import Qt from'remark-cjk-friendly-gfm-strikethrough';import Zt from'remark-gfm';import Y from'remark-math';import eo from'remend';import {DownloadIcon,CheckIcon,CopyIcon,Loader2Icon}from'lucide-react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import jt from'remark-parse';import At from'remark-rehype';import {unified}from'unified';import {Lexer}from'marked';var te=({onCopy:e,onError:t,timeout:s=2e3,children:o,className:a$1,code:n,...c})=>{let[r,l]=useState(false),d$1=useRef(0),{code:i}=d(),{isAnimating:m}=useContext(v),u=n!=null?n:i,b=async()=>{var y;if(typeof window=="undefined"||!((y=navigator==null?void 0:navigator.clipboard)!=null&&y.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{r||(await navigator.clipboard.writeText(u),l(!0),e==null||e(),d$1.current=window.setTimeout(()=>l(!1),s));}catch(k){t==null||t(k);}};useEffect(()=>()=>{window.clearTimeout(d$1.current);},[]);let f=r?CheckIcon:CopyIcon;return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",a$1),"data-streamdown":"code-block-copy-button",disabled:m,onClick:b,title:"Copy Code",type:"button",...c,children:o!=null?o:jsx(f,{size:14})})};var oe={"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"},ne=({onDownload:e,onError:t,language:s,children:o,className:a$1,code:n,...c})=>{let{code:r}=d(),{isAnimating:l}=useContext(v),d$1=n!=null?n:r,m=`file.${s&&s in oe?oe[s]:"txt"}`,u="text/plain",b$1=()=>{try{b(m,d$1,u),e==null||e();}catch(f){t==null||t(f);}};return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",a$1),"data-streamdown":"code-block-download-button",disabled:l,onClick:b$1,title:"Download file",type:"button",...c,children:o!=null?o:jsx(DownloadIcon,{size:14})})};var re=()=>jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsx(Loader2Icon,{className:"size-4 animate-spin"})})]});var dt=/\.[^/.]+$/,ae=({node:e,className:t,src:s,alt:o,...a$1})=>{let n=async()=>{if(s)try{let r=await(await fetch(s)).blob(),d=new URL(s,window.location.origin).pathname.split("/").pop()||"",i=d.split(".").pop(),m=d.includes(".")&&i!==void 0&&i.length<=4,u="";if(m)u=d;else {let b=r.type,f="png";b.includes("jpeg")||b.includes("jpg")?f="jpg":b.includes("png")?f="png":b.includes("svg")?f="svg":b.includes("gif")?f="gif":b.includes("webp")&&(f="webp"),u=`${(o||d||"image").replace(dt,"")}.${f}`;}b(u,r,r.type);}catch(c){console.error("Failed to download image:",c);}};return s?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:o,className:a("max-w-full rounded-lg",t),"data-streamdown":"image",src:s,...a$1}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsx("button",{className:a("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:jsx(DownloadIcon,{size:14})})]}):null};var I=e=>{var n,c;let t=[],s=[],o=e.querySelectorAll("thead th");for(let r of o)t.push(((n=r.textContent)==null?void 0:n.trim())||"");let a=e.querySelectorAll("tbody tr");for(let r of a){let l=[],d=r.querySelectorAll("td");for(let i of d)l.push(((c=i.textContent)==null?void 0:c.trim())||"");s.push(l);}return {headers:t,rows:s}},E=e=>{let{headers:t,rows:s}=e,o=r=>{let l=false,d=false;for(let i of r){if(i==='"'){l=true,d=true;break}(i===","||i===`
|
|
3
|
+
`)&&(l=true);}return l?d?`"${r.replace(/"/g,'""')}"`:`"${r}"`:r},a=t.length>0?s.length+1:s.length,n=new Array(a),c=0;t.length>0&&(n[c]=t.map(o).join(","),c+=1);for(let r of s)n[c]=r.map(o).join(","),c+=1;return n.join(`
|
|
4
|
+
`)},le=e=>{let{headers:t,rows:s}=e,o=r=>{let l=false;for(let i of r)if(i===" "||i===`
|
|
5
|
+
`||i==="\r"){l=true;break}if(!l)return r;let d=[];for(let i of r)i===" "?d.push("\\t"):i===`
|
|
6
|
+
`?d.push("\\n"):i==="\r"?d.push("\\r"):d.push(i);return d.join("")},a=t.length>0?s.length+1:s.length,n=new Array(a),c=0;t.length>0&&(n[c]=t.map(o).join(" "),c+=1);for(let r of s)n[c]=r.map(o).join(" "),c+=1;return n.join(`
|
|
7
|
+
`)},X=e=>{let t=false;for(let o of e)if(o==="\\"||o==="|"){t=true;break}if(!t)return e;let s=[];for(let o of e)o==="\\"?s.push("\\\\"):o==="|"?s.push("\\|"):s.push(o);return s.join("")},ie=e=>{let{headers:t,rows:s}=e;if(t.length===0)return "";let o=new Array(s.length+2),a=0,n=t.map(r=>X(r));o[a]=`| ${n.join(" | ")} |`,a+=1;let c=new Array(t.length);for(let r=0;r<t.length;r+=1)c[r]="---";o[a]=`| ${c.join(" | ")} |`,a+=1;for(let r of s)if(r.length<t.length){let l=new Array(t.length);for(let d=0;d<t.length;d+=1)l[d]=d<r.length?X(r[d]):"";o[a]=`| ${l.join(" | ")} |`,a+=1;}else {let l=r.map(d=>X(d));o[a]=`| ${l.join(" | ")} |`,a+=1;}return o.join(`
|
|
8
|
+
`)};var pe=({children:e,className:t,onCopy:s,onError:o,timeout:a$1=2e3})=>{let[n,c]=useState(false),[r,l]=useState(false),d=useRef(null),i=useRef(0),{isAnimating:m}=useContext(v),u=async f=>{var y,k;if(typeof window=="undefined"||!((y=navigator==null?void 0:navigator.clipboard)!=null&&y.write)){o==null||o(new Error("Clipboard API not available"));return}try{let x=(k=d.current)==null?void 0:k.closest('[data-streamdown="table-wrapper"]'),P=x==null?void 0:x.querySelector("table");if(!P){o==null||o(new Error("Table not found"));return}let T=I(P),R=f==="csv"?E(T):le(T),$=new ClipboardItem({"text/plain":new Blob([R],{type:"text/plain"}),"text/html":new Blob([P.outerHTML],{type:"text/html"})});await navigator.clipboard.write([$]),l(!0),c(!1),s==null||s(f),i.current=window.setTimeout(()=>l(!1),a$1);}catch(x){o==null||o(x);}};useEffect(()=>{let f=y=>{d.current&&!d.current.contains(y.target)&&c(false);};return document.addEventListener("mousedown",f),()=>{document.removeEventListener("mousedown",f),window.clearTimeout(i.current);}},[]);let b=r?CheckIcon:CopyIcon;return jsxs("div",{className:"relative",ref:d,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>c(!n),title:"Copy table",type:"button",children:e!=null?e:jsx(b,{size:14})}),n?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>u("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var fe=({children:e,className:t,onDownload:s,onError:o})=>{let[a$1,n]=useState(false),c=useRef(null),{isAnimating:r}=useContext(v),l=d=>{var i;try{let m=(i=c.current)==null?void 0:i.closest('[data-streamdown="table-wrapper"]'),u=m==null?void 0:m.querySelector("table");if(!u){o==null||o(new Error("Table not found"));return}let b$1=I(u),f=d==="csv"?E(b$1):ie(b$1);b(`table.${d==="csv"?"csv":"md"}`,f,d==="csv"?"text/csv":"text/markdown"),n(!1),s==null||s(d);}catch(m){o==null||o(m);}};return useEffect(()=>{let d=i=>{c.current&&!c.current.contains(i.target)&&n(false);};return document.addEventListener("mousedown",d),()=>{document.removeEventListener("mousedown",d);}},[]),jsxs("div",{className:"relative",ref:c,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:r,onClick:()=>n(!a$1),title:"Download table",type:"button",children:e!=null?e:jsx(DownloadIcon,{size:14})}),a$1?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>l("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var be=({children:e,className:t,showControls:s,...o})=>jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[s?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(pe,{}),jsx(fe,{})]}):null,jsx("div",{className:"overflow-x-auto",children:jsx("table",{className:a("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]});var Tt=lazy(()=>import('./code-block-HNJHFH25.js').then(e=>({default:e.CodeBlock}))),Ct=/language-([^\s]+)/;function O(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let s=e.position.start,o=t.position.start,a=e.position.end,n=t.position.end;return (s==null?void 0:s.line)===(o==null?void 0:o.line)&&(s==null?void 0:s.column)===(o==null?void 0:o.column)&&(a==null?void 0:a.line)===(n==null?void 0:n.line)&&(a==null?void 0:a.column)===(n==null?void 0:n.column)}function w(e,t){return e.className===t.className&&O(e.node,t.node)}var ye=(e,t)=>typeof e=="boolean"?e:e[t]!==false,W=memo(({children:e,className:t,node:s,...o})=>jsx("ol",{className:a("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>w(e,t));W.displayName="MarkdownOl";var we=memo(({children:e,className:t,node:s,...o})=>jsx("li",{className:a("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&O(e.node,t.node));we.displayName="MarkdownLi";var ke=memo(({children:e,className:t,node:s,...o})=>jsx("ul",{className:a("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>w(e,t));ke.displayName="MarkdownUl";var xe=memo(({className:e,node:t,...s})=>jsx("hr",{className:a("my-6 border-border",e),"data-streamdown":"horizontal-rule",...s}),(e,t)=>w(e,t));xe.displayName="MarkdownHr";var ve=memo(({children:e,className:t,node:s,...o})=>jsx("span",{className:a("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>w(e,t));ve.displayName="MarkdownStrong";var Te=memo(({children:e,className:t,href:s,node:o,...a$1})=>{let n=s==="streamdown:incomplete-link";return jsx("a",{className:a("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":n,"data-streamdown":"link",href:s,rel:"noreferrer",target:"_blank",...a$1,children:e})},(e,t)=>w(e,t)&&e.href===t.href);Te.displayName="MarkdownA";var Ce=memo(({children:e,className:t,node:s,...o})=>jsx("h1",{className:a("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>w(e,t));Ce.displayName="MarkdownH1";var Pe=memo(({children:e,className:t,node:s,...o})=>jsx("h2",{className:a("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>w(e,t));Pe.displayName="MarkdownH2";var Ne=memo(({children:e,className:t,node:s,...o})=>jsx("h3",{className:a("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>w(e,t));Ne.displayName="MarkdownH3";var Me=memo(({children:e,className:t,node:s,...o})=>jsx("h4",{className:a("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>w(e,t));Me.displayName="MarkdownH4";var Se=memo(({children:e,className:t,node:s,...o})=>jsx("h5",{className:a("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>w(e,t));Se.displayName="MarkdownH5";var De=memo(({children:e,className:t,node:s,...o})=>jsx("h6",{className:a("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>w(e,t));De.displayName="MarkdownH6";var Re=memo(({children:e,className:t,node:s,...o})=>{let{controls:a}=useContext(v),n=ye(a,"table");return jsx(be,{className:t,"data-streamdown":"table-wrapper",showControls:n,...o,children:e})},(e,t)=>w(e,t));Re.displayName="MarkdownTable";var je=memo(({children:e,className:t,node:s,...o})=>jsx("thead",{className:a("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>w(e,t));je.displayName="MarkdownThead";var Ae=memo(({children:e,className:t,node:s,...o})=>jsx("tbody",{className:a("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>w(e,t));Ae.displayName="MarkdownTbody";var Ie=memo(({children:e,className:t,node:s,...o})=>jsx("tr",{className:a("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>w(e,t));Ie.displayName="MarkdownTr";var Ee=memo(({children:e,className:t,node:s,...o})=>jsx("th",{className:a("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>w(e,t));Ee.displayName="MarkdownTh";var Le=memo(({children:e,className:t,node:s,...o})=>jsx("td",{className:a("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>w(e,t));Le.displayName="MarkdownTd";var He=memo(({children:e,className:t,node:s,...o})=>jsx("blockquote",{className:a("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>w(e,t));He.displayName="MarkdownBlockquote";var Be=memo(({children:e,className:t,node:s,...o})=>jsx("sup",{className:a("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>w(e,t));Be.displayName="MarkdownSup";var Oe=memo(({children:e,className:t,node:s,...o})=>jsx("sub",{className:a("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>w(e,t));Oe.displayName="MarkdownSub";var qe=memo(({children:e,className:t,node:s,...o})=>{if("data-footnotes"in o){let n=l=>{var u,b;if(!isValidElement(l))return false;let d=Array.isArray(l.props.children)?l.props.children:[l.props.children],i=false,m=false;for(let f of d)if(f){if(typeof f=="string")f.trim()!==""&&(i=true);else if(isValidElement(f))if(((u=f.props)==null?void 0:u["data-footnote-backref"])!==void 0)m=true;else {let y=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let k of y){if(typeof k=="string"&&k.trim()!==""){i=true;break}if(isValidElement(k)&&((b=k.props)==null?void 0:b["data-footnote-backref"])===void 0){i=true;break}}}}return m&&!i},c=Array.isArray(e)?e.map(l=>{if(!isValidElement(l))return l;if(l.type===W){let i=(Array.isArray(l.props.children)?l.props.children:[l.props.children]).filter(m=>!n(m));return i.length===0?null:{...l,props:{...l.props,children:i}}}return l}):e;return (Array.isArray(c)?c.some(l=>l!==null):c!==null)?jsx("section",{className:t,...o,children:c}):null}return jsx("section",{className:t,...o,children:e})},(e,t)=>w(e,t));qe.displayName="MarkdownSection";var Pt=({node:e,className:t,children:s,...o})=>{var i,m,u;let a$1=((i=e==null?void 0:e.position)==null?void 0:i.start.line)===((m=e==null?void 0:e.position)==null?void 0:m.end.line),{controls:n}=useContext(v);if(a$1)return jsx("code",{className:a("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...o,children:s});let c=t==null?void 0:t.match(Ct),r=(u=c==null?void 0:c.at(1))!=null?u:"",l="";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);let d=ye(n,"code");return jsx(Suspense,{fallback:jsx(re,{}),children:jsx(Tt,{className:a("overflow-x-auto border-border border-t",t),code:l,language:r,children:d?jsxs(Fragment,{children:[jsx(ne,{code:l,language:r}),jsx(te,{})]}):null})})},$e=memo(Pt,(e,t)=>e.className===t.className&&O(e.node,t.node));$e.displayName="MarkdownCode";var Je=memo(ae,(e,t)=>e.className===t.className&&O(e.node,t.node));Je.displayName="MarkdownImg";var ze=memo(({children:e,className:t,node:s,...o})=>{var c;let n=(Array.isArray(e)?e:[e]).filter(r=>r!=null&&r!=="");return n.length===1&&isValidElement(n[0])&&((c=n[0].props.node)==null?void 0:c.tagName)==="img"?jsx(Fragment,{children:e}):jsx("p",{className:t,...o,children:e})},(e,t)=>w(e,t));ze.displayName="MarkdownParagraph";var Xe={ol:W,li:we,ul:ke,hr:xe,strong:ve,a:Te,h1:Ce,h2:Pe,h3:Ne,h4:Me,h5:Se,h6:De,table:Re,thead:je,tbody:Ae,tr:Ie,th:Ee,td:Le,blockquote:He,code:$e,img:Je,pre:({children:e})=>e,sup:Be,sub:Oe,p:ze,section:qe};var Ke=[],Ve={allowDangerousHtml:true},q=new WeakMap,K=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let s=this.keyCache.get(t);if(s)return s;let o=t.rehypePlugins,a=t.remarkPlugins,n=t.remarkRehypeOptions;if(!(o||a||n)){let m="default";return this.keyCache.set(t,m),m}let c=m=>{if(!m||m.length===0)return "";let u="";for(let b=0;b<m.length;b+=1){let f=m[b];if(b>0&&(u+=","),Array.isArray(f)){let[y,k]=f;if(typeof y=="function"){let x=q.get(y);x||(x=y.name,q.set(y,x)),u+=x;}else u+=String(y);u+=":",u+=JSON.stringify(k);}else if(typeof f=="function"){let y=q.get(f);y||(y=f.name,q.set(f,y)),u+=y;}else u+=String(f);}return u},r=c(o),l=c(a),d=n?JSON.stringify(n):"",i=`${l}::${r}::${d}`;return this.keyCache.set(t,i),i}get(t){let s=this.generateCacheKey(t),o=this.cache.get(s);return o&&(this.cache.delete(s),this.cache.set(s,o)),o}set(t,s){let o=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let a=this.cache.keys().next().value;a&&this.cache.delete(a);}this.cache.set(o,s);}clear(){this.cache.clear();}},Fe=new K,V=e=>{let t=Et(e),s=e.children||"";return Ht(t.runSync(t.parse(s),s),e)},Et=e=>{let t=Fe.get(e);if(t)return t;let s=Lt(e);return Fe.set(e,s),s},Lt=e=>{let t=e.rehypePlugins||Ke,s=e.remarkPlugins||Ke,o=e.remarkRehypeOptions?{...Ve,...e.remarkRehypeOptions}:Ve;return unified().use(jt).use(s).use(At,o).use(t)},Ht=(e,t)=>toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true});var Ot=/\[\^[^\]\s]{1,200}\](?!:)/,qt=/\[\^[^\]\s]{1,200}\]:/,$t=/<\/(\w+)>/,Jt=/<(\w+)[\s>]/,F=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},zt=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},_=e=>{let t=0;for(let s=0;s<e.length-1;s+=1)e[s]==="$"&&e[s+1]==="$"&&(t+=1,s+=1);return t},U=e=>{let t=Ot.test(e),s=qt.test(e);if(t||s)return [e];let o=Lexer.lex(e,{gfm:true}),a=[],n=[];for(let c of o){let r=c.raw,l=a.length;if(n.length>0){if(a[l-1]+=r,c.type==="html"){let i=r.match($t);if(i){let m=i[1];n.at(-1)===m&&n.pop();}}continue}if(c.type==="html"&&c.block){let i=r.match(Jt);if(i){let m=i[1];r.includes(`</${m}>`)||n.push(m);}}if(r.trim()==="$$"&&l>0){let i=a[l-1],m=F(i),u=_(i);if(m&&u%2===1){a[l-1]=i+r;continue}}if(l>0&&zt(r)){let i=a[l-1],m=F(i),u=_(i),b=_(r);if(m&&u%2===1&&!F(r)&&b===1){a[l-1]=i+r;continue}}a.push(r);}return a};var _e={dependencies:{"rehype-katex":"^7.0.1"}};var to=/[^$]\$[^$]/,oo=/^\$[^$]/,so=/[^$]\$$/,no={raw:Ut,sanitize:[Gt,{}],katex:[G,{errorColor:"var(--color-muted-foreground)"}],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},ro={gfm:[Zt,{}],math:[Y,{singleDollarTextMath:false}],cjkFriendly:[Yt,{}],cjkFriendlyGfmStrikethrough:[Qt,{}]},ao=Object.values(no),lo=Object.values(ro),io={block:" \u258B",circle:" \u25CF"},co={controls:true,isAnimating:false,mode:"streaming"},v=createContext(co),Ye=memo(({content:e,...t})=>jsx(V,{...t,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let s=Object.keys(e.components||{}),o=Object.keys(t.components||{});if(s.length!==o.length||s.some(a=>{var n,c;return ((n=e.components)==null?void 0:n[a])!==((c=t.components)==null?void 0:c[a])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Ye.displayName="Block";var mo=e=>Array.isArray(e)&&e.some(t=>Array.isArray(t)?t[0]===G:t===G),po=e=>{if(!Array.isArray(e))return false;let t=e.find(s=>Array.isArray(s)?s[0]===Y:s===Y);return t&&Array.isArray(t)&&t[1]?t[1].singleDollarTextMath===true:false},uo=(e,t)=>{let s=e.includes("$$"),o=t&&(to.test(e)||oo.test(e)||so.test(e));return s||o},fo=/^\^/,go=()=>{let e=_e.dependencies["rehype-katex"].replace(fo,"").split(".")[0],s={7:"0.16.22"}[e]||"0.16.22",o=document.createElement("link");o.rel="stylesheet",o.href=`https://cdn.jsdelivr.net/npm/katex@${s}/dist/katex.min.css`,document.head.appendChild(o);},bo=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:s=true,components:o,rehypePlugins:a$1=ao,remarkPlugins:n=lo,className:c,controls:r=true,isAnimating:l=false,BlockComponent:d=Ye,parseMarkdownIntoBlocksFn:i=U,caret:m,...u})=>{let b=useId(),[f,y]=useTransition(),[k,x]=useState([]),P=useMemo(()=>typeof e!="string"?"":t==="streaming"&&s?eo(e):e,[e,t,s]),T=useMemo(()=>i(P),[P,i]);useEffect(()=>{t==="streaming"?y(()=>{x(T);}):x(T);},[T,t]);let R=t==="streaming"?k:T,$=useMemo(()=>R.map((J,N)=>`${b}-${N}`),[R.length,b]),Q=useMemo(()=>({controls:r,isAnimating:l,mode:t}),[r,l,t]),Z=useMemo(()=>({...Xe,...o}),[o]);useEffect(()=>{if(!mo(a$1))return;let N=po(n);uo(typeof e=="string"?e:"",N)&&go();},[a$1,n,e]);let Qe=useMemo(()=>m&&l?{"--streamdown-caret":`"${io[m]}"`}:void 0,[m,l]);return t==="static"?jsx(v.Provider,{value:Q,children:jsx("div",{className:a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",c),children:jsx(V,{components:Z,rehypePlugins:a$1,remarkPlugins:n,...u,children:e})})}):jsx(v.Provider,{value:Q,children:jsx("div",{className:a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",m?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,c),style:Qe,children:R.map((J,N)=>jsx(d,{components:Z,content:J,index:N,rehypePlugins:a$1,remarkPlugins:n,shouldParseIncompleteMarkdown:s,...u},$[N]))})})},(e,t)=>e.children===t.children&&e.isAnimating===t.isAnimating&&e.mode===t.mode);bo.displayName="Streamdown";
|
|
11
|
+
export{Ye as Block,bo as Streamdown,v as StreamdownContext,no as defaultRehypePlugins,ro as defaultRemarkPlugins,U as parseMarkdownIntoBlocks};
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@echoease/streamdown-edge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/moraruvlad/streamdown-edge.git"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup",
|
|
25
|
+
"postbuild": "node scripts/postbuild.js"
|
|
26
|
+
},
|
|
27
|
+
"author": "EchoEase",
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"description": "Streamdown fork optimized for Edge runtime - no mermaid or shiki",
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/hast": "^3.0.4",
|
|
32
|
+
"@types/react": "^19.2.7",
|
|
33
|
+
"@types/react-dom": "^19.2.3",
|
|
34
|
+
"react": "^19.2.1",
|
|
35
|
+
"react-dom": "^19.2.1",
|
|
36
|
+
"tsup": "^8.5.1",
|
|
37
|
+
"typescript": "^5.0.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"clsx": "^2.1.1",
|
|
44
|
+
"hast": "^1.0.0",
|
|
45
|
+
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
46
|
+
"html-url-attributes": "^3.0.1",
|
|
47
|
+
"lucide-react": "^0.560.0",
|
|
48
|
+
"marked": "^17.0.1",
|
|
49
|
+
"prism-react-renderer": "^2.4.1",
|
|
50
|
+
"rehype-harden": "^1.1.7",
|
|
51
|
+
"rehype-katex": "^7.0.1",
|
|
52
|
+
"rehype-raw": "^7.0.0",
|
|
53
|
+
"rehype-sanitize": "^6.0.0",
|
|
54
|
+
"remark-cjk-friendly": "^1.2.3",
|
|
55
|
+
"remark-cjk-friendly-gfm-strikethrough": "^1.2.3",
|
|
56
|
+
"remark-gfm": "^4.0.1",
|
|
57
|
+
"remark-math": "^6.0.0",
|
|
58
|
+
"remark-parse": "^11.0.0",
|
|
59
|
+
"remark-rehype": "^11.1.2",
|
|
60
|
+
"remend": "^1.0.1",
|
|
61
|
+
"tailwind-merge": "^3.4.0",
|
|
62
|
+
"unified": "^11.0.5",
|
|
63
|
+
"unist-util-visit": "^5.0.0"
|
|
64
|
+
}
|
|
65
|
+
}
|