streamdown 1.0.11 → 1.0.12

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/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";"use client";var W=Object.create;var f=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var J=(t,e)=>{for(var n in e)f(t,n,{get:e[n],enumerable:!0})},$=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!F.call(t,r)&&r!==n&&f(t,r,{get:()=>e[r],enumerable:!(o=V(e,r))||o.enumerable});return t};var g=(t,e,n)=>(n=t!=null?W(G(t)):{},$(e||!t||!t.__esModule?f(n,"default",{value:t,enumerable:!0}):n,t)),Q=t=>$(f({},"__esModule",{value:!0}),t);var Nt={};J(Nt,{Streamdown:()=>B,default:()=>$t});module.exports=Q(Nt);var d=require("react"),O=g(require("react-markdown"),1),R=g(require("rehype-katex"),1),U=g(require("remark-gfm"),1),D=g(require("remark-math"),1),Lt=require("katex/dist/katex.min.css"),I=g(require("harden-react-markdown"),1);var S=require("react");var b=require("lucide-react"),l=require("react"),v=require("shiki");var N=require("clsx"),w=require("tailwind-merge"),s=(...t)=>(0,w.twMerge)((0,N.clsx)(t));var p=require("react/jsx-runtime"),P=(0,l.createContext)({code:""});async function X(t,e){return await(0,v.codeToHtml)(t,{lang:e,theme:"github-light"})}var T=({code:t,language:e,className:n,children:o,...r})=>{let[a,m]=(0,l.useState)("");return(0,l.useEffect)(()=>{let c=!0;return X(t,e).then(u=>{c&&m(u)}),()=>{c=!1}},[t,e]),(0,p.jsx)(P.Provider,{value:{code:t},children:(0,p.jsxs)("div",{className:"group relative",children:[(0,p.jsx)("div",{className:s("overflow-x-auto",n),dangerouslySetInnerHTML:{__html:a},...r}),o]})})},_=({onCopy:t,onError:e,timeout:n=2e3,children:o,className:r,...a})=>{let[m,c]=(0,l.useState)(!1),{code:u}=(0,l.useContext)(P),y=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){e==null||e(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(u),c(!0),t==null||t(),setTimeout(()=>c(!1),n)}catch(M){e==null||e(M)}},C=m?b.CheckIcon:b.CopyIcon;return(0,p.jsx)("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",r),onClick:y,type:"button",...a,children:o!=null?o:(0,p.jsx)(C,{size:14})})};var i=require("react/jsx-runtime"),A={ol:({node:t,children:e,className:n,...o})=>(0,i.jsx)("ol",{className:s("ml-4 list-outside list-decimal",n),...o,children:e}),li:({node:t,children:e,className:n,...o})=>(0,i.jsx)("li",{className:s("py-1",n),...o,children:e}),ul:({node:t,children:e,className:n,...o})=>(0,i.jsx)("ul",{className:s("ml-4 list-outside list-disc",n),...o,children:e}),hr:({node:t,className:e,...n})=>(0,i.jsx)("hr",{className:s("my-6 border-border",e),...n}),strong:({node:t,children:e,className:n,...o})=>(0,i.jsx)("span",{className:s("font-semibold",n),...o,children:e}),a:({node:t,children:e,className:n,href:o,...r})=>(0,i.jsx)("a",{className:s("font-medium text-primary underline",n),href:o,rel:"noreferrer",target:"_blank",...r,children:e}),h1:({node:t,children:e,className:n,...o})=>(0,i.jsx)("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",n),...o,children:e}),h2:({node:t,children:e,className:n,...o})=>(0,i.jsx)("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",n),...o,children:e}),h3:({node:t,children:e,className:n,...o})=>(0,i.jsx)("h3",{className:s("mt-6 mb-2 font-semibold text-xl",n),...o,children:e}),h4:({node:t,children:e,className:n,...o})=>(0,i.jsx)("h4",{className:s("mt-6 mb-2 font-semibold text-lg",n),...o,children:e}),h5:({node:t,children:e,className:n,...o})=>(0,i.jsx)("h5",{className:s("mt-6 mb-2 font-semibold text-base",n),...o,children:e}),h6:({node:t,children:e,className:n,...o})=>(0,i.jsx)("h6",{className:s("mt-6 mb-2 font-semibold text-sm",n),...o,children:e}),table:({node:t,children:e,className:n,...o})=>(0,i.jsx)("div",{className:"my-4 overflow-x-auto",children:(0,i.jsx)("table",{className:s("w-full border-collapse border border-border",n),...o,children:e})}),thead:({node:t,children:e,className:n,...o})=>(0,i.jsx)("thead",{className:s("bg-muted/50",n),...o,children:e}),tbody:({node:t,children:e,className:n,...o})=>(0,i.jsx)("tbody",{className:s("divide-y divide-border",n),...o,children:e}),tr:({node:t,children:e,className:n,...o})=>(0,i.jsx)("tr",{className:s("border-border border-b",n),...o,children:e}),th:({node:t,children:e,className:n,...o})=>(0,i.jsx)("th",{className:s("px-4 py-2 text-left font-semibold text-sm",n),...o,children:e}),td:({node:t,children:e,className:n,...o})=>(0,i.jsx)("td",{className:s("px-4 py-2 text-sm",n),...o,children:e}),blockquote:({node:t,children:e,className:n,...o})=>(0,i.jsx)("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",n),...o,children:e}),code:({node:t,className:e,...n})=>{var r,a;return((r=t==null?void 0:t.position)==null?void 0:r.start.line)===((a=t==null?void 0:t.position)==null?void 0:a.end.line)?(0,i.jsx)("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",e),...n}):(0,i.jsx)("code",{className:e,...n})},pre:({node:t,className:e,children:n})=>{var a;let o="javascript";typeof((a=t==null?void 0:t.properties)==null?void 0:a.className)=="string"&&(o=t.properties.className.replace("language-",""));let r="";return(0,S.isValidElement)(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?r=n.props.children:typeof n=="string"&&(r=n),(0,i.jsx)(T,{className:s("my-4 h-auto rounded-lg border p-4",e),code:r,language:o,children:(0,i.jsx)(_,{})})},sup:({node:t,children:e,className:n,...o})=>(0,i.jsx)("sup",{className:s("text-sm",n),...o,children:e}),sub:({node:t,children:e,className:n,...o})=>(0,i.jsx)("sub",{className:s("text-sm",n),...o,children:e})};var H=require("marked"),K=t=>H.marked.lexer(t).map(n=>n.raw);var Y=/(!?\[)([^\]]*?)$/,Z=/(\*\*)([^*]*?)$/,j=/(__)([^_]*?)$/,E=/(\*\*\*)([^*]*?)$/,x=/(\*)([^*]*?)$/,tt=/(_)([^_]*?)$/,et=/(`)([^`]*?)$/,nt=/(~~)([^~]*?)$/,ot=/(\$)([^$]*?)$/,rt=/(\$\$)([^$]*?)$/,st=t=>{let e=t.match(Y);if(e){let n=t.lastIndexOf(e[1]);return t.substring(0,n)}return t},it=t=>t.match(Z)&&(t.match(/\*\*/g)||[]).length%2===1?`${t}**`:t,at=t=>t.match(j)&&(t.match(/__/g)||[]).length%2===1?`${t}__`:t,ct=t=>t.split("").reduce((e,n,o)=>{if(n==="*"){let r=t[o-1],a=t[o+1];if(r==="\\")return e;if(r!=="*"&&a!=="*")return e+1}return e},0),lt=t=>t.match(x)&&ct(t)%2===1?`${t}*`:t,dt=t=>t.split("").reduce((e,n,o)=>{if(n==="_"){let r=t[o-1],a=t[o+1];if(r==="\\")return e;if(r!=="_"&&a!=="_")return e+1}return e},0),mt=t=>t.match(tt)&&dt(t)%2===1?`${t}_`:t,pt=(t,e)=>{let n=t.substring(e,e+3)==="```",o=e>0&&t.substring(e-1,e+2)==="```",r=e>1&&t.substring(e-2,e+1)==="```";return n||o||r},ut=t=>{let e=0;for(let n=0;n<t.length;n++)t[n]==="`"&&!pt(t,n)&&e++;return e},gt=t=>{if(t.match(/^```[^`\n]*```?$/)&&!t.includes(`
2
- `))return t.endsWith("``")&&!t.endsWith("```")?`${t}\``:t;let n=(t.match(/```/g)||[]).length,o=n%2===1;return(t.endsWith("```\n")||t.endsWith("```"))&&n%2===0||n>0&&n%2===0&&t.includes(`
3
- `)?t:t.match(et)&&!o&&ut(t)%2===1?`${t}\``:t},ht=t=>t.match(nt)&&(t.match(/~~/g)||[]).length%2===1?`${t}~~`:t,ft=t=>t.split("").reduce((e,n,o)=>{if(n==="$"){let r=t[o-1],a=t[o+1];if(r==="\\")return e;if(r!=="$"&&a!=="$")return e+1}return e},0),bt=t=>t.match(rt)&&(t.match(/\$\$/g)||[]).length%2===1?`${t}$$`:t,kt=t=>t.match(ot)&&ft(t)%2===1?`${t}$`:t,yt=t=>{let e=0,n=t.match(/\*+/g)||[];for(let o of n){let r=o.length;r>=3&&(e+=Math.floor(r/3))}return e},Ct=t=>/^\*{4,}$/.test(t)?t:t.match(E)&&yt(t)%2===1?`${t}***`:t,L=t=>{if(!t||typeof t!="string")return t;let e=t;return e=st(e),e=Ct(e),e=it(e),e=at(e),e=lt(e),e=mt(e),e=gt(e),e=ht(e),e=bt(e),e=kt(e),e};var k=require("react/jsx-runtime"),Mt=I.default.default||I.default,It=Mt(O.default),Bt=(0,d.memo)(({content:t,shouldParseIncompleteMarkdown:e,...n})=>{let o=(0,d.useMemo)(()=>typeof t=="string"&&e?L(t.trim()):t,[t,e]);return(0,k.jsx)(It,{...n,children:o})},(t,e)=>t.content===e.content),B=(0,d.memo)(({children:t,allowedImagePrefixes:e,allowedLinkPrefixes:n,defaultOrigin:o,parseIncompleteMarkdown:r=!0,components:a,rehypePlugins:m,remarkPlugins:c,className:u,...y})=>{let C=(0,d.useId)(),h=(0,d.useMemo)(()=>K(typeof t=="string"?t:""),[t]);return(0,k.jsx)("div",{className:s("space-y-4",u),...y,children:h.map((M,q)=>(0,k.jsx)(Bt,{allowedImagePrefixes:e!=null?e:["*"],allowedLinkPrefixes:n!=null?n:["*"],components:{...A,...a},content:M,defaultOrigin:o,rehypePlugins:[R.default,...m!=null?m:[]],remarkPlugins:[U.default,D.default,...c!=null?c:[]],shouldParseIncompleteMarkdown:r},`${C}-block_${q}`))})},(t,e)=>t.children===e.children);B.displayName="Streamdown";var $t=B;0&&(module.exports={Streamdown});
1
+ "use strict";"use client";var z=Object.create;var b=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var X=(e,t)=>{for(var n in t)b(e,n,{get:t[n],enumerable:!0})},N=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of F(t))!Q.call(e,r)&&r!==n&&b(e,r,{get:()=>t[r],enumerable:!(o=G(t,r))||o.enumerable});return e};var g=(e,t,n)=>(n=e!=null?z(J(e)):{},N(t||!e||!e.__esModule?b(n,"default",{value:e,enumerable:!0}):n,e)),Y=e=>N(b({},"__esModule",{value:!0}),e);var ve={};X(ve,{ShikiThemeContext:()=>C,Streamdown:()=>$,default:()=>Te});module.exports=Y(ve);var l=require("react"),R=g(require("react-markdown"),1),U=g(require("rehype-katex"),1),D=g(require("remark-gfm"),1),q=g(require("remark-math"),1),Ue=require("katex/dist/katex.min.css"),I=g(require("harden-react-markdown"),1);var A=require("react");var y=require("lucide-react"),c=require("react"),w=require("shiki");var T=require("clsx"),v=require("tailwind-merge"),s=(...e)=>(0,v.twMerge)((0,T.clsx)(e));var p=require("react/jsx-runtime"),P=(0,c.createContext)({code:""});async function Z(e,t,n){return await(0,w.codeToHtml)(e,{lang:t,theme:n})}var S=({code:e,language:t,className:n,children:o,...r})=>{let[a,m]=(0,c.useState)(""),d=(0,c.useContext)(C);return(0,c.useEffect)(()=>{let u=!0;return Z(e,t,d).then(h=>{u&&m(h)}),()=>{u=!1}},[e,t,d]),(0,p.jsx)(P.Provider,{value:{code:e},children:(0,p.jsxs)("div",{className:"group relative",children:[(0,p.jsx)("div",{className:s("overflow-x-auto",n),dangerouslySetInnerHTML:{__html:a},...r}),o]})})},_=({onCopy:e,onError:t,timeout:n=2e3,children:o,className:r,...a})=>{let[m,d]=(0,c.useState)(!1),{code:u}=(0,c.useContext)(P),h=async()=>{var k;if(typeof window=="undefined"||!((k=navigator==null?void 0:navigator.clipboard)!=null&&k.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(u),d(!0),e==null||e(),setTimeout(()=>d(!1),n)}catch(B){t==null||t(B)}},M=m?y.CheckIcon:y.CopyIcon;return(0,p.jsx)("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",r),onClick:h,type:"button",...a,children:o!=null?o:(0,p.jsx)(M,{size:14})})};var i=require("react/jsx-runtime"),H={ol:({node:e,children:t,className:n,...o})=>(0,i.jsx)("ol",{className:s("ml-4 list-outside list-decimal",n),...o,children:t}),li:({node:e,children:t,className:n,...o})=>(0,i.jsx)("li",{className:s("py-1",n),...o,children:t}),ul:({node:e,children:t,className:n,...o})=>(0,i.jsx)("ul",{className:s("ml-4 list-outside list-disc",n),...o,children:t}),hr:({node:e,className:t,...n})=>(0,i.jsx)("hr",{className:s("my-6 border-border",t),...n}),strong:({node:e,children:t,className:n,...o})=>(0,i.jsx)("span",{className:s("font-semibold",n),...o,children:t}),a:({node:e,children:t,className:n,href:o,...r})=>(0,i.jsx)("a",{className:s("font-medium text-primary underline",n),href:o,rel:"noreferrer",target:"_blank",...r,children:t}),h1:({node:e,children:t,className:n,...o})=>(0,i.jsx)("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",n),...o,children:t}),h2:({node:e,children:t,className:n,...o})=>(0,i.jsx)("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",n),...o,children:t}),h3:({node:e,children:t,className:n,...o})=>(0,i.jsx)("h3",{className:s("mt-6 mb-2 font-semibold text-xl",n),...o,children:t}),h4:({node:e,children:t,className:n,...o})=>(0,i.jsx)("h4",{className:s("mt-6 mb-2 font-semibold text-lg",n),...o,children:t}),h5:({node:e,children:t,className:n,...o})=>(0,i.jsx)("h5",{className:s("mt-6 mb-2 font-semibold text-base",n),...o,children:t}),h6:({node:e,children:t,className:n,...o})=>(0,i.jsx)("h6",{className:s("mt-6 mb-2 font-semibold text-sm",n),...o,children:t}),table:({node:e,children:t,className:n,...o})=>(0,i.jsx)("div",{className:"my-4 overflow-x-auto",children:(0,i.jsx)("table",{className:s("w-full border-collapse border border-border",n),...o,children:t})}),thead:({node:e,children:t,className:n,...o})=>(0,i.jsx)("thead",{className:s("bg-muted/50",n),...o,children:t}),tbody:({node:e,children:t,className:n,...o})=>(0,i.jsx)("tbody",{className:s("divide-y divide-border",n),...o,children:t}),tr:({node:e,children:t,className:n,...o})=>(0,i.jsx)("tr",{className:s("border-border border-b",n),...o,children:t}),th:({node:e,children:t,className:n,...o})=>(0,i.jsx)("th",{className:s("px-4 py-2 text-left font-semibold text-sm",n),...o,children:t}),td:({node:e,children:t,className:n,...o})=>(0,i.jsx)("td",{className:s("px-4 py-2 text-sm",n),...o,children:t}),blockquote:({node:e,children:t,className:n,...o})=>(0,i.jsx)("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",n),...o,children:t}),code:({node:e,className:t,...n})=>{var r,a;return((r=e==null?void 0:e.position)==null?void 0:r.start.line)===((a=e==null?void 0:e.position)==null?void 0:a.end.line)?(0,i.jsx)("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),...n}):(0,i.jsx)("code",{className:t,...n})},pre:({node:e,className:t,children:n})=>{var a;let o="javascript";typeof((a=e==null?void 0:e.properties)==null?void 0:a.className)=="string"&&(o=e.properties.className.replace("language-",""));let r="";return(0,A.isValidElement)(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?r=n.props.children:typeof n=="string"&&(r=n),(0,i.jsx)(S,{className:s("my-4 h-auto rounded-lg border p-4",t),code:r,language:o,children:(0,i.jsx)(_,{})})},sup:({node:e,children:t,className:n,...o})=>(0,i.jsx)("sup",{className:s("text-sm",n),...o,children:t}),sub:({node:e,children:t,className:n,...o})=>(0,i.jsx)("sub",{className:s("text-sm",n),...o,children:t})};var K=require("marked"),L=e=>K.marked.lexer(e).map(n=>n.raw);var j=/(!?\[)([^\]]*?)$/,E=/(\*\*)([^*]*?)$/,x=/(__)([^_]*?)$/,ee=/(\*\*\*)([^*]*?)$/,te=/(\*)([^*]*?)$/,ne=/(_)([^_]*?)$/,oe=/(`)([^`]*?)$/,re=/(~~)([^~]*?)$/,se=/(\$)([^$]*?)$/,ie=/(\$\$)([^$]*?)$/,ae=e=>{let t=e.match(j);if(t){let n=e.lastIndexOf(t[1]);return e.substring(0,n)}return e},ce=e=>e.match(E)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,le=e=>e.match(x)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,de=e=>e.split("").reduce((t,n,o)=>{if(n==="*"){let r=e[o-1],a=e[o+1];if(r==="\\")return t;if(r!=="*"&&a!=="*")return t+1}return t},0),me=e=>e.match(te)&&de(e)%2===1?`${e}*`:e,pe=e=>e.split("").reduce((t,n,o)=>{if(n==="_"){let r=e[o-1],a=e[o+1];if(r==="\\")return t;if(r!=="_"&&a!=="_")return t+1}return t},0),ue=e=>e.match(ne)&&pe(e)%2===1?`${e}_`:e,he=(e,t)=>{let n=e.substring(t,t+3)==="```",o=t>0&&e.substring(t-1,t+2)==="```",r=t>1&&e.substring(t-2,t+1)==="```";return n||o||r},ge=e=>{let t=0;for(let n=0;n<e.length;n++)e[n]==="`"&&!he(e,n)&&t++;return t},fe=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
2
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let n=(e.match(/```/g)||[]).length,o=n%2===1;return(e.endsWith("```\n")||e.endsWith("```"))&&n%2===0||n>0&&n%2===0&&e.includes(`
3
+ `)?e:e.match(oe)&&!o&&ge(e)%2===1?`${e}\``:e},ke=e=>e.match(re)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,be=e=>e.split("").reduce((t,n,o)=>{if(n==="$"){let r=e[o-1],a=e[o+1];if(r==="\\")return t;if(r!=="$"&&a!=="$")return t+1}return t},0),ye=e=>e.match(ie)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,Ce=e=>e.match(se)&&be(e)%2===1?`${e}$`:e,Me=e=>{let t=0,n=e.match(/\*+/g)||[];for(let o of n){let r=o.length;r>=3&&(t+=Math.floor(r/3))}return t},Be=e=>/^\*{4,}$/.test(e)?e:e.match(ee)&&Me(e)%2===1?`${e}***`:e,O=e=>{if(!e||typeof e!="string")return e;let t=e;return t=ae(t),t=Be(t),t=ce(t),t=le(t),t=me(t),t=ue(t),t=fe(t),t=ke(t),t=ye(t),t=Ce(t),t};var f=require("react/jsx-runtime"),Ie=I.default.default||I.default,$e=Ie(R.default),C=(0,l.createContext)("github-light"),Ne=(0,l.memo)(({content:e,shouldParseIncompleteMarkdown:t,...n})=>{let o=(0,l.useMemo)(()=>typeof e=="string"&&t?O(e.trim()):e,[e,t]);return(0,f.jsx)($e,{...n,children:o})},(e,t)=>e.content===t.content),$=(0,l.memo)(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:n,defaultOrigin:o,parseIncompleteMarkdown:r=!0,components:a,rehypePlugins:m,remarkPlugins:d,className:u,shikiTheme:h="github-light",...M})=>{let k=(0,l.useId)(),B=(0,l.useMemo)(()=>L(typeof e=="string"?e:""),[e]);return(0,f.jsx)(C.Provider,{value:h,children:(0,f.jsx)("div",{className:s("space-y-4",u),...M,children:B.map((W,V)=>(0,f.jsx)(Ne,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:n!=null?n:["*"],components:{...H,...a},content:W,defaultOrigin:o,rehypePlugins:[U.default,...m!=null?m:[]],remarkPlugins:[D.default,q.default,...d!=null?d:[]],shouldParseIncompleteMarkdown:r},`${k}-block_${V}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);$.displayName="Streamdown";var Te=$;0&&(module.exports={ShikiThemeContext,Streamdown});
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
- import * as react from 'react';
2
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
3
  import { Options } from 'react-markdown';
4
+ import { BundledTheme } from 'shiki';
4
5
 
5
6
  type HardenReactMarkdownProps = Options & {
6
7
  defaultOrigin?: string;
@@ -10,7 +11,9 @@ type HardenReactMarkdownProps = Options & {
10
11
  type StreamdownProps = HardenReactMarkdownProps & {
11
12
  parseIncompleteMarkdown?: boolean;
12
13
  className?: string;
14
+ shikiTheme?: BundledTheme;
13
15
  };
14
- declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
16
+ declare const ShikiThemeContext: react.Context<BundledTheme>;
17
+ declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
15
18
 
16
- export { Streamdown, type StreamdownProps, Streamdown as default };
19
+ export { ShikiThemeContext, Streamdown, type StreamdownProps, Streamdown as default };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import * as react from 'react';
2
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
3
  import { Options } from 'react-markdown';
4
+ import { BundledTheme } from 'shiki';
4
5
 
5
6
  type HardenReactMarkdownProps = Options & {
6
7
  defaultOrigin?: string;
@@ -10,7 +11,9 @@ type HardenReactMarkdownProps = Options & {
10
11
  type StreamdownProps = HardenReactMarkdownProps & {
11
12
  parseIncompleteMarkdown?: boolean;
12
13
  className?: string;
14
+ shikiTheme?: BundledTheme;
13
15
  };
14
- declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
16
+ declare const ShikiThemeContext: react.Context<BundledTheme>;
17
+ declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
15
18
 
16
- export { Streamdown, type StreamdownProps, Streamdown as default };
19
+ export { ShikiThemeContext, Streamdown, type StreamdownProps, Streamdown as default };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use client";import{memo as N,useId as ut,useMemo as w}from"react";import gt from"react-markdown";import ht from"rehype-katex";import ft from"remark-gfm";import bt from"remark-math";import"katex/dist/katex.min.css";import $ from"harden-react-markdown";import{isValidElement as D}from"react";import{CheckIcon as S,CopyIcon as A}from"lucide-react";import{createContext as H,useContext as K,useEffect as L,useState as b}from"react";import{codeToHtml as O}from"shiki";import{clsx as T}from"clsx";import{twMerge as _}from"tailwind-merge";var s=(...t)=>_(T(t));import{jsx as p,jsxs as U}from"react/jsx-runtime";var k=H({code:""});async function R(t,e){return await O(t,{lang:e,theme:"github-light"})}var y=({code:t,language:e,className:n,children:o,...r})=>{let[a,l]=b("");return L(()=>{let c=!0;return R(t,e).then(d=>{c&&l(d)}),()=>{c=!1}},[t,e]),p(k.Provider,{value:{code:t},children:U("div",{className:"group relative",children:[p("div",{className:s("overflow-x-auto",n),dangerouslySetInnerHTML:{__html:a},...r}),o]})})},C=({onCopy:t,onError:e,timeout:n=2e3,children:o,className:r,...a})=>{let[l,c]=b(!1),{code:d}=K(k),u=async()=>{var m;if(typeof window=="undefined"||!((m=navigator==null?void 0:navigator.clipboard)!=null&&m.writeText)){e==null||e(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(d),c(!0),t==null||t(),setTimeout(()=>c(!1),n)}catch(h){e==null||e(h)}},g=l?S:A;return p("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",r),onClick:u,type:"button",...a,children:o!=null?o:p(g,{size:14})})};import{jsx as i}from"react/jsx-runtime";var M={ol:({node:t,children:e,className:n,...o})=>i("ol",{className:s("ml-4 list-outside list-decimal",n),...o,children:e}),li:({node:t,children:e,className:n,...o})=>i("li",{className:s("py-1",n),...o,children:e}),ul:({node:t,children:e,className:n,...o})=>i("ul",{className:s("ml-4 list-outside list-disc",n),...o,children:e}),hr:({node:t,className:e,...n})=>i("hr",{className:s("my-6 border-border",e),...n}),strong:({node:t,children:e,className:n,...o})=>i("span",{className:s("font-semibold",n),...o,children:e}),a:({node:t,children:e,className:n,href:o,...r})=>i("a",{className:s("font-medium text-primary underline",n),href:o,rel:"noreferrer",target:"_blank",...r,children:e}),h1:({node:t,children:e,className:n,...o})=>i("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",n),...o,children:e}),h2:({node:t,children:e,className:n,...o})=>i("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",n),...o,children:e}),h3:({node:t,children:e,className:n,...o})=>i("h3",{className:s("mt-6 mb-2 font-semibold text-xl",n),...o,children:e}),h4:({node:t,children:e,className:n,...o})=>i("h4",{className:s("mt-6 mb-2 font-semibold text-lg",n),...o,children:e}),h5:({node:t,children:e,className:n,...o})=>i("h5",{className:s("mt-6 mb-2 font-semibold text-base",n),...o,children:e}),h6:({node:t,children:e,className:n,...o})=>i("h6",{className:s("mt-6 mb-2 font-semibold text-sm",n),...o,children:e}),table:({node:t,children:e,className:n,...o})=>i("div",{className:"my-4 overflow-x-auto",children:i("table",{className:s("w-full border-collapse border border-border",n),...o,children:e})}),thead:({node:t,children:e,className:n,...o})=>i("thead",{className:s("bg-muted/50",n),...o,children:e}),tbody:({node:t,children:e,className:n,...o})=>i("tbody",{className:s("divide-y divide-border",n),...o,children:e}),tr:({node:t,children:e,className:n,...o})=>i("tr",{className:s("border-border border-b",n),...o,children:e}),th:({node:t,children:e,className:n,...o})=>i("th",{className:s("px-4 py-2 text-left font-semibold text-sm",n),...o,children:e}),td:({node:t,children:e,className:n,...o})=>i("td",{className:s("px-4 py-2 text-sm",n),...o,children:e}),blockquote:({node:t,children:e,className:n,...o})=>i("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",n),...o,children:e}),code:({node:t,className:e,...n})=>{var r,a;return((r=t==null?void 0:t.position)==null?void 0:r.start.line)===((a=t==null?void 0:t.position)==null?void 0:a.end.line)?i("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",e),...n}):i("code",{className:e,...n})},pre:({node:t,className:e,children:n})=>{var a;let o="javascript";typeof((a=t==null?void 0:t.properties)==null?void 0:a.className)=="string"&&(o=t.properties.className.replace("language-",""));let r="";return D(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?r=n.props.children:typeof n=="string"&&(r=n),i(y,{className:s("my-4 h-auto rounded-lg border p-4",e),code:r,language:o,children:i(C,{})})},sup:({node:t,children:e,className:n,...o})=>i("sup",{className:s("text-sm",n),...o,children:e}),sub:({node:t,children:e,className:n,...o})=>i("sub",{className:s("text-sm",n),...o,children:e})};import{marked as q}from"marked";var I=t=>q.lexer(t).map(n=>n.raw);var W=/(!?\[)([^\]]*?)$/,V=/(\*\*)([^*]*?)$/,z=/(__)([^_]*?)$/,G=/(\*\*\*)([^*]*?)$/,F=/(\*)([^*]*?)$/,J=/(_)([^_]*?)$/,Q=/(`)([^`]*?)$/,X=/(~~)([^~]*?)$/,Y=/(\$)([^$]*?)$/,Z=/(\$\$)([^$]*?)$/,j=t=>{let e=t.match(W);if(e){let n=t.lastIndexOf(e[1]);return t.substring(0,n)}return t},E=t=>t.match(V)&&(t.match(/\*\*/g)||[]).length%2===1?`${t}**`:t,x=t=>t.match(z)&&(t.match(/__/g)||[]).length%2===1?`${t}__`:t,tt=t=>t.split("").reduce((e,n,o)=>{if(n==="*"){let r=t[o-1],a=t[o+1];if(r==="\\")return e;if(r!=="*"&&a!=="*")return e+1}return e},0),et=t=>t.match(F)&&tt(t)%2===1?`${t}*`:t,nt=t=>t.split("").reduce((e,n,o)=>{if(n==="_"){let r=t[o-1],a=t[o+1];if(r==="\\")return e;if(r!=="_"&&a!=="_")return e+1}return e},0),ot=t=>t.match(J)&&nt(t)%2===1?`${t}_`:t,rt=(t,e)=>{let n=t.substring(e,e+3)==="```",o=e>0&&t.substring(e-1,e+2)==="```",r=e>1&&t.substring(e-2,e+1)==="```";return n||o||r},st=t=>{let e=0;for(let n=0;n<t.length;n++)t[n]==="`"&&!rt(t,n)&&e++;return e},it=t=>{if(t.match(/^```[^`\n]*```?$/)&&!t.includes(`
2
- `))return t.endsWith("``")&&!t.endsWith("```")?`${t}\``:t;let n=(t.match(/```/g)||[]).length,o=n%2===1;return(t.endsWith("```\n")||t.endsWith("```"))&&n%2===0||n>0&&n%2===0&&t.includes(`
3
- `)?t:t.match(Q)&&!o&&st(t)%2===1?`${t}\``:t},at=t=>t.match(X)&&(t.match(/~~/g)||[]).length%2===1?`${t}~~`:t,ct=t=>t.split("").reduce((e,n,o)=>{if(n==="$"){let r=t[o-1],a=t[o+1];if(r==="\\")return e;if(r!=="$"&&a!=="$")return e+1}return e},0),lt=t=>t.match(Z)&&(t.match(/\$\$/g)||[]).length%2===1?`${t}$$`:t,dt=t=>t.match(Y)&&ct(t)%2===1?`${t}$`:t,mt=t=>{let e=0,n=t.match(/\*+/g)||[];for(let o of n){let r=o.length;r>=3&&(e+=Math.floor(r/3))}return e},pt=t=>/^\*{4,}$/.test(t)?t:t.match(G)&&mt(t)%2===1?`${t}***`:t,B=t=>{if(!t||typeof t!="string")return t;let e=t;return e=j(e),e=pt(e),e=E(e),e=x(e),e=et(e),e=ot(e),e=it(e),e=at(e),e=lt(e),e=dt(e),e};import{jsx as f}from"react/jsx-runtime";var kt=$.default||$,yt=kt(gt),Ct=N(({content:t,shouldParseIncompleteMarkdown:e,...n})=>{let o=w(()=>typeof t=="string"&&e?B(t.trim()):t,[t,e]);return f(yt,{...n,children:o})},(t,e)=>t.content===e.content),v=N(({children:t,allowedImagePrefixes:e,allowedLinkPrefixes:n,defaultOrigin:o,parseIncompleteMarkdown:r=!0,components:a,rehypePlugins:l,remarkPlugins:c,className:d,...u})=>{let g=ut(),m=w(()=>I(typeof t=="string"?t:""),[t]);return f("div",{className:s("space-y-4",d),...u,children:m.map((h,P)=>f(Ct,{allowedImagePrefixes:e!=null?e:["*"],allowedLinkPrefixes:n!=null?n:["*"],components:{...M,...a},content:h,defaultOrigin:o,rehypePlugins:[ht,...l!=null?l:[]],remarkPlugins:[ft,bt,...c!=null?c:[]],shouldParseIncompleteMarkdown:r},`${g}-block_${P}`))})},(t,e)=>t.children===e.children);v.displayName="Streamdown";var Yt=v;export{v as Streamdown,Yt as default};
1
+ "use client";import{createContext as ge,memo as v,useId as fe,useMemo as w}from"react";import ke from"react-markdown";import be from"rehype-katex";import ye from"remark-gfm";import Ce from"remark-math";import"katex/dist/katex.min.css";import T from"harden-react-markdown";import{isValidElement as W}from"react";import{CheckIcon as K,CopyIcon as L}from"lucide-react";import{createContext as O,useContext as b,useEffect as R,useState as y}from"react";import{codeToHtml as U}from"shiki";import{clsx as A}from"clsx";import{twMerge as H}from"tailwind-merge";var s=(...e)=>H(A(e));import{jsx as u,jsxs as q}from"react/jsx-runtime";var C=O({code:""});async function D(e,t,n){return await U(e,{lang:t,theme:n})}var M=({code:e,language:t,className:n,children:o,...r})=>{let[a,l]=y(""),c=b(k);return R(()=>{let d=!0;return D(e,t,c).then(m=>{d&&l(m)}),()=>{d=!1}},[e,t,c]),u(C.Provider,{value:{code:e},children:q("div",{className:"group relative",children:[u("div",{className:s("overflow-x-auto",n),dangerouslySetInnerHTML:{__html:a},...r}),o]})})},B=({onCopy:e,onError:t,timeout:n=2e3,children:o,className:r,...a})=>{let[l,c]=y(!1),{code:d}=b(C),m=async()=>{var p;if(typeof window=="undefined"||!((p=navigator==null?void 0:navigator.clipboard)!=null&&p.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(d),c(!0),e==null||e(),setTimeout(()=>c(!1),n)}catch(f){t==null||t(f)}},g=l?K:L;return u("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",r),onClick:m,type:"button",...a,children:o!=null?o:u(g,{size:14})})};import{jsx as i}from"react/jsx-runtime";var I={ol:({node:e,children:t,className:n,...o})=>i("ol",{className:s("ml-4 list-outside list-decimal",n),...o,children:t}),li:({node:e,children:t,className:n,...o})=>i("li",{className:s("py-1",n),...o,children:t}),ul:({node:e,children:t,className:n,...o})=>i("ul",{className:s("ml-4 list-outside list-disc",n),...o,children:t}),hr:({node:e,className:t,...n})=>i("hr",{className:s("my-6 border-border",t),...n}),strong:({node:e,children:t,className:n,...o})=>i("span",{className:s("font-semibold",n),...o,children:t}),a:({node:e,children:t,className:n,href:o,...r})=>i("a",{className:s("font-medium text-primary underline",n),href:o,rel:"noreferrer",target:"_blank",...r,children:t}),h1:({node:e,children:t,className:n,...o})=>i("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",n),...o,children:t}),h2:({node:e,children:t,className:n,...o})=>i("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",n),...o,children:t}),h3:({node:e,children:t,className:n,...o})=>i("h3",{className:s("mt-6 mb-2 font-semibold text-xl",n),...o,children:t}),h4:({node:e,children:t,className:n,...o})=>i("h4",{className:s("mt-6 mb-2 font-semibold text-lg",n),...o,children:t}),h5:({node:e,children:t,className:n,...o})=>i("h5",{className:s("mt-6 mb-2 font-semibold text-base",n),...o,children:t}),h6:({node:e,children:t,className:n,...o})=>i("h6",{className:s("mt-6 mb-2 font-semibold text-sm",n),...o,children:t}),table:({node:e,children:t,className:n,...o})=>i("div",{className:"my-4 overflow-x-auto",children:i("table",{className:s("w-full border-collapse border border-border",n),...o,children:t})}),thead:({node:e,children:t,className:n,...o})=>i("thead",{className:s("bg-muted/50",n),...o,children:t}),tbody:({node:e,children:t,className:n,...o})=>i("tbody",{className:s("divide-y divide-border",n),...o,children:t}),tr:({node:e,children:t,className:n,...o})=>i("tr",{className:s("border-border border-b",n),...o,children:t}),th:({node:e,children:t,className:n,...o})=>i("th",{className:s("px-4 py-2 text-left font-semibold text-sm",n),...o,children:t}),td:({node:e,children:t,className:n,...o})=>i("td",{className:s("px-4 py-2 text-sm",n),...o,children:t}),blockquote:({node:e,children:t,className:n,...o})=>i("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",n),...o,children:t}),code:({node:e,className:t,...n})=>{var r,a;return((r=e==null?void 0:e.position)==null?void 0:r.start.line)===((a=e==null?void 0:e.position)==null?void 0:a.end.line)?i("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),...n}):i("code",{className:t,...n})},pre:({node:e,className:t,children:n})=>{var a;let o="javascript";typeof((a=e==null?void 0:e.properties)==null?void 0:a.className)=="string"&&(o=e.properties.className.replace("language-",""));let r="";return W(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?r=n.props.children:typeof n=="string"&&(r=n),i(M,{className:s("my-4 h-auto rounded-lg border p-4",t),code:r,language:o,children:i(B,{})})},sup:({node:e,children:t,className:n,...o})=>i("sup",{className:s("text-sm",n),...o,children:t}),sub:({node:e,children:t,className:n,...o})=>i("sub",{className:s("text-sm",n),...o,children:t})};import{marked as V}from"marked";var $=e=>V.lexer(e).map(n=>n.raw);var z=/(!?\[)([^\]]*?)$/,G=/(\*\*)([^*]*?)$/,F=/(__)([^_]*?)$/,J=/(\*\*\*)([^*]*?)$/,Q=/(\*)([^*]*?)$/,X=/(_)([^_]*?)$/,Y=/(`)([^`]*?)$/,Z=/(~~)([^~]*?)$/,j=/(\$)([^$]*?)$/,E=/(\$\$)([^$]*?)$/,x=e=>{let t=e.match(z);if(t){let n=e.lastIndexOf(t[1]);return e.substring(0,n)}return e},ee=e=>e.match(G)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,te=e=>e.match(F)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,ne=e=>e.split("").reduce((t,n,o)=>{if(n==="*"){let r=e[o-1],a=e[o+1];if(r==="\\")return t;if(r!=="*"&&a!=="*")return t+1}return t},0),oe=e=>e.match(Q)&&ne(e)%2===1?`${e}*`:e,re=e=>e.split("").reduce((t,n,o)=>{if(n==="_"){let r=e[o-1],a=e[o+1];if(r==="\\")return t;if(r!=="_"&&a!=="_")return t+1}return t},0),se=e=>e.match(X)&&re(e)%2===1?`${e}_`:e,ie=(e,t)=>{let n=e.substring(t,t+3)==="```",o=t>0&&e.substring(t-1,t+2)==="```",r=t>1&&e.substring(t-2,t+1)==="```";return n||o||r},ae=e=>{let t=0;for(let n=0;n<e.length;n++)e[n]==="`"&&!ie(e,n)&&t++;return t},ce=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
2
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let n=(e.match(/```/g)||[]).length,o=n%2===1;return(e.endsWith("```\n")||e.endsWith("```"))&&n%2===0||n>0&&n%2===0&&e.includes(`
3
+ `)?e:e.match(Y)&&!o&&ae(e)%2===1?`${e}\``:e},le=e=>e.match(Z)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,de=e=>e.split("").reduce((t,n,o)=>{if(n==="$"){let r=e[o-1],a=e[o+1];if(r==="\\")return t;if(r!=="$"&&a!=="$")return t+1}return t},0),me=e=>e.match(E)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,pe=e=>e.match(j)&&de(e)%2===1?`${e}$`:e,ue=e=>{let t=0,n=e.match(/\*+/g)||[];for(let o of n){let r=o.length;r>=3&&(t+=Math.floor(r/3))}return t},he=e=>/^\*{4,}$/.test(e)?e:e.match(J)&&ue(e)%2===1?`${e}***`:e,N=e=>{if(!e||typeof e!="string")return e;let t=e;return t=x(t),t=he(t),t=ee(t),t=te(t),t=oe(t),t=se(t),t=ce(t),t=le(t),t=me(t),t=pe(t),t};import{jsx as h}from"react/jsx-runtime";var Me=T.default||T,Be=Me(ke),k=ge("github-light"),Ie=v(({content:e,shouldParseIncompleteMarkdown:t,...n})=>{let o=w(()=>typeof e=="string"&&t?N(e.trim()):e,[e,t]);return h(Be,{...n,children:o})},(e,t)=>e.content===t.content),P=v(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:n,defaultOrigin:o,parseIncompleteMarkdown:r=!0,components:a,rehypePlugins:l,remarkPlugins:c,className:d,shikiTheme:m="github-light",...g})=>{let p=fe(),f=w(()=>$(typeof e=="string"?e:""),[e]);return h(k.Provider,{value:m,children:h("div",{className:s("space-y-4",d),...g,children:f.map((S,_)=>h(Ie,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:n!=null?n:["*"],components:{...I,...a},content:S,defaultOrigin:o,rehypePlugins:[be,...l!=null?l:[]],remarkPlugins:[ye,Ce,...c!=null?c:[]],shouldParseIncompleteMarkdown:r},`${p}-block_${_}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);P.displayName="Streamdown";var xe=P;export{k as ShikiThemeContext,P as Streamdown,xe as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamdown",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "vitest": "^3.2.4"
40
40
  },
41
41
  "peerDependencies": {
42
- "react": "^19.1.1"
42
+ "react": "^18.0.0 || ^19.0.0"
43
43
  },
44
44
  "dependencies": {
45
45
  "clsx": "^2.1.1",