streamdown 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -149,6 +149,8 @@ Streamdown accepts all the same props as react-markdown, plus additional streami
149
149
  | `rehypePlugins` | `array` | `[rehypeKatex]` | Rehype plugins to use |
150
150
  | `allowedImagePrefixes` | `array` | `['*']` | Allowed image URL prefixes |
151
151
  | `allowedLinkPrefixes` | `array` | `['*']` | Allowed link URL prefixes |
152
+ | `defaultOrigin` | `string` | - | Default origin to use for relative URLs in links and images |
153
+ | `shikiTheme` | `BundledTheme` (from Shiki) | `github-light` | The theme to use for code blocks |
152
154
 
153
155
  ## Architecture
154
156
 
package/dist/index.cjs CHANGED
@@ -1,3 +1,5 @@
1
- "use strict";"use client";var Y=Object.create;var T=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},L=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!te.call(e,o)&&o!==r&&T(e,o,{get:()=>t[o],enumerable:!(n=Z(t,o))||n.enumerable});return e};var M=(e,t,r)=>(r=e!=null?Y(ee(e)):{},L(t||!e||!e.__esModule?T(r,"default",{value:e,enumerable:!0}):r,e)),ne=e=>L(T({},"__esModule",{value:!0}),e);var xe={};re(xe,{ShikiThemeContext:()=>$,Streamdown:()=>Q});module.exports=ne(xe);var k=require("react"),V=M(require("react-markdown"),1),W=M(require("rehype-katex"),1),G=M(require("remark-gfm"),1),F=M(require("remark-math"),1),Ye=require("katex/dist/katex.min.css"),P=M(require("harden-react-markdown"),1);var K=require("react");var v=require("lucide-react"),d=require("react"),w=require("shiki");var _=require("clsx"),A=require("tailwind-merge"),s=(...e)=>(0,A.twMerge)((0,_.clsx)(e));var y=require("react/jsx-runtime"),R=(0,d.createContext)({code:""});async function oe(e,t,r){return Promise.all([await(0,w.codeToHtml)(e,{lang:t,theme:r[0]}),await(0,w.codeToHtml)(e,{lang:t,theme:r[1]})])}var D=({code:e,language:t,className:r,children:n,...o})=>{let[a,c]=(0,d.useState)(""),[l,m]=(0,d.useState)(""),u=(0,d.useRef)(!1),[h,g]=(0,d.useContext)($);return(0,d.useEffect)(()=>(oe(e,t,[h,g]).then(([f,b])=>{u.current||(c(f),m(b),u.current=!0)}),()=>{u.current=!1}),[e,t,h,g]),(0,y.jsx)(R.Provider,{value:{code:e},children:(0,y.jsxs)("div",{className:"group relative",children:[(0,y.jsx)("div",{className:s("overflow-x-auto dark:hidden [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:a},...o}),(0,y.jsx)("div",{className:s("hidden overflow-x-auto dark:block [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:l},...o}),n]})})},N=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:o,code:a,...c})=>{let[l,m]=(0,d.useState)(!1),u=(0,d.useContext)(R).code,h=a!=null?a:u,g=async()=>{var b;if(typeof window=="undefined"||!((b=navigator==null?void 0:navigator.clipboard)!=null&&b.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(h),m(!0),e==null||e(),setTimeout(()=>m(!1),r)}catch(B){t==null||t(B)}},f=l?v.CheckIcon:v.CopyIcon;return(0,y.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",o),onClick:g,type:"button",...c,children:n!=null?n:(0,y.jsx)(f,{size:14})})};var C=require("react");var p=require("react/jsx-runtime"),x=!1,se=async()=>{if(!x){let r=(await import("mermaid")).default;return r.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),x=!0,r}return(await import("mermaid")).default},E=({chart:e,className:t})=>{let[r,n]=(0,C.useState)(null),[o,a]=(0,C.useState)(!0),[c,l]=(0,C.useState)(""),[m,u]=(0,C.useState)("");if((0,C.useEffect)(()=>{(async()=>{try{n(null),a(!0);let f=await se(),b=e.split("").reduce((H,X)=>(H<<5)-H+X.charCodeAt(0)|0,0),B=`mermaid-${Math.abs(b)}`,{svg:S}=await f.render(B,e);l(S),u(S)}catch(f){if(!(m||c)){let b=f instanceof Error?f.message:"Failed to render Mermaid chart";n(b)}}finally{a(!1)}})()},[e]),o&&!c&&!m)return(0,p.jsx)("div",{className:s("my-4 flex justify-center p-4",t),children:(0,p.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,p.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,p.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!c&&!m)return(0,p.jsxs)("div",{className:s("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,p.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),(0,p.jsxs)("details",{className:"mt-2",children:[(0,p.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,p.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let h=c||m;return(0,p.jsx)("div",{"aria-label":"Mermaid chart",className:s("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:h},role:"img"})};var i=require("react/jsx-runtime"),ie=/language-([^\s]+)/,ae=({node:e,className:t,children:r,...n})=>{var u,h,g;if(((u=e==null?void 0:e.position)==null?void 0:u.start.line)===((h=e==null?void 0:e.position)==null?void 0:h.end.line))return(0,i.jsx)("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),...n,children:r});let a=t==null?void 0:t.match(ie),c=(g=a==null?void 0:a.at(1))!=null?g:"plaintext",l="";return(0,K.isValidElement)(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?l=r.props.children:typeof r=="string"&&(l=r),c==="mermaid"||l.includes("graph")||l.includes("flowchart")||l.includes("sequenceDiagram")||l.includes("classDiagram")||l.includes("gantt")?(0,i.jsxs)("div",{className:s("group relative my-4 h-auto rounded-lg border p-4",t),children:[(0,i.jsx)(E,{chart:l}),(0,i.jsx)(N,{code:l})]}):(0,i.jsx)(D,{className:s("my-4 h-auto rounded-lg border p-4",t),code:l,language:c,children:(0,i.jsx)(N,{})})},O={ol:({node:e,children:t,className:r,...n})=>(0,i.jsx)("ol",{className:s("ml-4 list-outside list-decimal",r),...n,children:t}),li:({node:e,children:t,className:r,...n})=>(0,i.jsx)("li",{className:s("py-1",r),...n,children:t}),ul:({node:e,children:t,className:r,...n})=>(0,i.jsx)("ul",{className:s("ml-4 list-outside list-disc",r),...n,children:t}),hr:({node:e,className:t,...r})=>(0,i.jsx)("hr",{className:s("my-6 border-border",t),...r}),strong:({node:e,children:t,className:r,...n})=>(0,i.jsx)("span",{className:s("font-semibold",r),...n,children:t}),a:({node:e,children:t,className:r,href:n,...o})=>(0,i.jsx)("a",{className:s("font-medium text-primary underline",r),href:n,rel:"noreferrer",target:"_blank",...o,children:t}),h1:({node:e,children:t,className:r,...n})=>(0,i.jsx)("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",r),...n,children:t}),h2:({node:e,children:t,className:r,...n})=>(0,i.jsx)("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",r),...n,children:t}),h3:({node:e,children:t,className:r,...n})=>(0,i.jsx)("h3",{className:s("mt-6 mb-2 font-semibold text-xl",r),...n,children:t}),h4:({node:e,children:t,className:r,...n})=>(0,i.jsx)("h4",{className:s("mt-6 mb-2 font-semibold text-lg",r),...n,children:t}),h5:({node:e,children:t,className:r,...n})=>(0,i.jsx)("h5",{className:s("mt-6 mb-2 font-semibold text-base",r),...n,children:t}),h6:({node:e,children:t,className:r,...n})=>(0,i.jsx)("h6",{className:s("mt-6 mb-2 font-semibold text-sm",r),...n,children:t}),table:({node:e,children:t,className:r,...n})=>(0,i.jsx)("div",{className:"my-4 overflow-x-auto",children:(0,i.jsx)("table",{className:s("w-full border-collapse border border-border",r),...n,children:t})}),thead:({node:e,children:t,className:r,...n})=>(0,i.jsx)("thead",{className:s("bg-muted/50",r),...n,children:t}),tbody:({node:e,children:t,className:r,...n})=>(0,i.jsx)("tbody",{className:s("divide-y divide-border",r),...n,children:t}),tr:({node:e,children:t,className:r,...n})=>(0,i.jsx)("tr",{className:s("border-border border-b",r),...n,children:t}),th:({node:e,children:t,className:r,...n})=>(0,i.jsx)("th",{className:s("px-4 py-2 text-left font-semibold text-sm",r),...n,children:t}),td:({node:e,children:t,className:r,...n})=>(0,i.jsx)("td",{className:s("px-4 py-2 text-sm",r),...n,children:t}),blockquote:({node:e,children:t,className:r,...n})=>(0,i.jsx)("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",r),...n,children:t}),code:ae,pre:({children:e})=>e,sup:({node:e,children:t,className:r,...n})=>(0,i.jsx)("sup",{className:s("text-sm",r),...n,children:t}),sub:({node:e,children:t,className:r,...n})=>(0,i.jsx)("sub",{className:s("text-sm",r),...n,children:t})};var U=require("marked"),q=e=>U.marked.lexer(e).map(r=>r.raw);var le=/(!?\[)([^\]]*?)$/,ce=/(\*\*)([^*]*?)$/,de=/(__)([^_]*?)$/,me=/(\*\*\*)([^*]*?)$/,ue=/(\*)([^*]*?)$/,pe=/(_)([^_]*?)$/,he=/(`)([^`]*?)$/,ge=/(~~)([^~]*?)$/,fe=/(\$)([^$]*?)$/,be=/(\$\$)([^$]*?)$/,ke=e=>{let t=e.match(le);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},ye=e=>e.match(ce)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,Me=e=>e.match(de)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,Ce=e=>e.split("").reduce((t,r,n)=>{if(r==="*"){let o=e[n-1],a=e[n+1];if(o==="\\")return t;if(o!=="*"&&a!=="*")return t+1}return t},0),Be=e=>e.match(ue)&&Ce(e)%2===1?`${e}*`:e,ve=(e,t)=>{let r=!1,n=!1;for(let o=0;o<e.length&&o<t;o++){if(e[o]==="\\"&&e[o+1]==="$"){o++;continue}e[o]==="$"&&(e[o+1]==="$"?(n=!n,o++,r=!1):n||(r=!r))}return r||n},Ie=e=>e.split("").reduce((t,r,n)=>{if(r==="_"){let o=e[n-1],a=e[n+1];if(o==="\\"||ve(e,n))return t;if(o!=="_"&&a!=="_")return t+1}return t},0),Te=e=>e.match(pe)&&Ie(e)%2===1?`${e}_`:e,$e=(e,t)=>{let r=e.substring(t,t+3)==="```",n=t>0&&e.substring(t-1,t+2)==="```",o=t>1&&e.substring(t-2,t+1)==="```";return r||n||o},we=e=>{let t=0;for(let r=0;r<e.length;r++)e[r]==="`"&&!$e(e,r)&&t++;return t},Ne=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
2
- `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let r=(e.match(/```/g)||[]).length,n=r%2===1;return(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0||r>0&&r%2===0&&e.includes(`
3
- `)?e:e.match(he)&&!n&&we(e)%2===1?`${e}\``:e},Pe=e=>e.match(ge)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,Se=e=>e.split("").reduce((t,r,n)=>{if(r==="$"){let o=e[n-1],a=e[n+1];if(o==="\\")return t;if(o!=="$"&&a!=="$")return t+1}return t},0),He=e=>e.match(be)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,Le=e=>e.match(fe)&&Se(e)%2===1?`${e}$`:e,_e=e=>{let t=0,r=e.match(/\*+/g)||[];for(let n of r){let o=n.length;o>=3&&(t+=Math.floor(o/3))}return t},Ae=e=>/^\*{4,}$/.test(e)?e:e.match(me)&&_e(e)%2===1?`${e}***`:e,z=e=>{if(!e||typeof e!="string")return e;let t=e;return t=ke(t),t=Ae(t),t=ye(t),t=Me(t),t=Be(t),t=Te(t),t=Ne(t),t=Pe(t),t=He(t),t=Le(t),t};var I=require("react/jsx-runtime"),Re=P.default.default||P.default,De=Re(V.default),$=(0,k.createContext)(["github-light","github-dark"]),J=(0,k.memo)(({content:e,shouldParseIncompleteMarkdown:t,...r})=>{let n=(0,k.useMemo)(()=>typeof e=="string"&&t?z(e.trim()):e,[e,t]);return(0,I.jsx)(De,{...r,children:n})},(e,t)=>e.content===t.content);J.displayName="Block";var Q=(0,k.memo)(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:r,defaultOrigin:n,parseIncompleteMarkdown:o=!0,components:a,rehypePlugins:c,remarkPlugins:l,className:m,shikiTheme:u=["github-light","github-dark"],...h})=>{let g=(0,k.useId)(),f=(0,k.useMemo)(()=>q(typeof e=="string"?e:""),[e]);return(0,I.jsx)($.Provider,{value:u,children:(0,I.jsx)("div",{className:s("space-y-4",m),...h,children:f.map((b,B)=>(0,I.jsx)(J,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:r!=null?r:["*"],components:{...O,...a},content:b,defaultOrigin:n,rehypePlugins:[W.default,...c!=null?c:[]],remarkPlugins:[G.default,F.default,...l!=null?l:[]],shouldParseIncompleteMarkdown:o},`${g}-block_${B}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Q.displayName="Streamdown";0&&(module.exports={ShikiThemeContext,Streamdown});
1
+ "use strict";"use client";var j=Object.create;var $=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var ne=(e,t)=>{for(var r in t)$(e,r,{get:t[r],enumerable:!0})},A=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ee(t))!re.call(e,o)&&o!==r&&$(e,o,{get:()=>t[o],enumerable:!(n=x(t,o))||n.enumerable});return e};var M=(e,t,r)=>(r=e!=null?j(te(e)):{},A(t||!e||!e.__esModule?$(r,"default",{value:e,enumerable:!0}):r,e)),oe=e=>A($({},"__esModule",{value:!0}),e);var Ee={};ne(Ee,{ShikiThemeContext:()=>P,Streamdown:()=>Y});module.exports=oe(Ee);var h=require("react"),G=M(require("react-markdown"),1),F=M(require("rehype-katex"),1),J=M(require("remark-gfm"),1),Q=M(require("remark-math"),1),je=require("katex/dist/katex.min.css"),H=M(require("harden-react-markdown"),1);var U=require("react");var B=require("lucide-react"),m=require("react"),N=require("shiki");var _=require("clsx"),R=require("tailwind-merge"),s=(...e)=>(0,R.twMerge)((0,_.clsx)(e));var k=require("react/jsx-runtime"),D=(0,m.createContext)({code:""});async function se(e,t,r){return Promise.all([await(0,N.codeToHtml)(e,{lang:t,theme:r[0]}),await(0,N.codeToHtml)(e,{lang:t,theme:r[1]})])}var K=({code:e,language:t,className:r,children:n,...o})=>{let[i,d]=(0,m.useState)(""),[c,l]=(0,m.useState)(""),u=(0,m.useRef)(!1),[g,y]=(0,m.useContext)(P);return(0,m.useEffect)(()=>(se(e,t,[g,y]).then(([f,b])=>{u.current||(d(f),l(b),u.current=!0)}),()=>{u.current=!1}),[e,t,g,y]),(0,k.jsx)(D.Provider,{value:{code:e},children:(0,k.jsxs)("div",{className:"group relative",children:[(0,k.jsx)("div",{className:s("overflow-x-auto dark:hidden [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:i},...o}),(0,k.jsx)("div",{className:s("hidden overflow-x-auto dark:block [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:c},...o}),n]})})},S=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:o,code:i,...d})=>{let[c,l]=(0,m.useState)(!1),u=(0,m.useContext)(D).code,g=i!=null?i:u,y=async()=>{var b;if(typeof window=="undefined"||!((b=navigator==null?void 0:navigator.clipboard)!=null&&b.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(g),l(!0),e==null||e(),setTimeout(()=>l(!1),r)}catch(w){t==null||t(w)}},f=c?B.CheckIcon:B.CopyIcon;return(0,k.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",o),onClick:y,type:"button",...d,children:n!=null?n:(0,k.jsx)(f,{size:14})})};var C=require("react");var p=require("react/jsx-runtime"),E=!1,ae=async()=>{if(!E){let r=(await import("mermaid")).default;return r.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),E=!0,r}return(await import("mermaid")).default},O=({chart:e,className:t})=>{let[r,n]=(0,C.useState)(null),[o,i]=(0,C.useState)(!0),[d,c]=(0,C.useState)(""),[l,u]=(0,C.useState)("");if((0,C.useEffect)(()=>{(async()=>{try{n(null),i(!0);let f=await ae(),b=e.split("").reduce((L,Z)=>(L<<5)-L+Z.charCodeAt(0)|0,0),w=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:T}=await f.render(w,e);c(T),u(T)}catch(f){if(!(l||d)){let b=f instanceof Error?f.message:"Failed to render Mermaid chart";n(b)}}finally{i(!1)}})()},[e]),o&&!d&&!l)return(0,p.jsx)("div",{className:s("my-4 flex justify-center p-4",t),children:(0,p.jsxs)("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[(0,p.jsx)("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),(0,p.jsx)("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!d&&!l)return(0,p.jsxs)("div",{className:s("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[(0,p.jsxs)("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),(0,p.jsxs)("details",{className:"mt-2",children:[(0,p.jsx)("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),(0,p.jsx)("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let g=d||l;return(0,p.jsx)("div",{"aria-label":"Mermaid chart",className:s("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:g},role:"img"})};var a=require("react/jsx-runtime"),ie=/language-([^\s]+)/,de=({node:e,className:t,children:r,...n})=>{var l,u,g;if(((l=e==null?void 0:e.position)==null?void 0:l.start.line)===((u=e==null?void 0:e.position)==null?void 0:u.end.line))return(0,a.jsx)("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:r});let i=t==null?void 0:t.match(ie),d=(g=i==null?void 0:i.at(1))!=null?g:"plaintext",c="";return(0,U.isValidElement)(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?c=r.props.children:typeof r=="string"&&(c=r),d==="mermaid"?(0,a.jsxs)("div",{className:s("group relative my-4 h-auto rounded-lg border p-4",t),"data-streamdown":"mermaid-block",children:[(0,a.jsx)(O,{chart:c}),(0,a.jsx)(S,{code:c})]}):(0,a.jsx)(K,{className:s("my-4 h-auto rounded-lg border p-4",t),code:c,"data-language":d,"data-streamdown":"code-block",language:d,children:(0,a.jsx)(S,{})})},q={ol:({node:e,children:t,className:r,...n})=>(0,a.jsx)("ol",{className:s("ml-4 list-outside list-decimal",r),"data-streamdown":"ordered-list",...n,children:t}),li:({node:e,children:t,className:r,...n})=>(0,a.jsx)("li",{className:s("py-1",r),"data-streamdown":"list-item",...n,children:t}),ul:({node:e,children:t,className:r,...n})=>(0,a.jsx)("ul",{className:s("ml-4 list-outside list-disc",r),"data-streamdown":"unordered-list",...n,children:t}),hr:({node:e,className:t,...r})=>(0,a.jsx)("hr",{className:s("my-6 border-border",t),"data-streamdown":"horizontal-rule",...r}),strong:({node:e,children:t,className:r,...n})=>(0,a.jsx)("span",{className:s("font-semibold",r),"data-streamdown":"strong",...n,children:t}),a:({node:e,children:t,className:r,href:n,...o})=>(0,a.jsx)("a",{className:s("font-medium text-primary underline",r),"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...o,children:t}),h1:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",r),"data-streamdown":"heading-1",...n,children:t}),h2:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",r),"data-streamdown":"heading-2",...n,children:t}),h3:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h3",{className:s("mt-6 mb-2 font-semibold text-xl",r),"data-streamdown":"heading-3",...n,children:t}),h4:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h4",{className:s("mt-6 mb-2 font-semibold text-lg",r),"data-streamdown":"heading-4",...n,children:t}),h5:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h5",{className:s("mt-6 mb-2 font-semibold text-base",r),"data-streamdown":"heading-5",...n,children:t}),h6:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h6",{className:s("mt-6 mb-2 font-semibold text-sm",r),"data-streamdown":"heading-6",...n,children:t}),table:({node:e,children:t,className:r,...n})=>(0,a.jsx)("div",{className:"my-4 overflow-x-auto","data-streamdown":"table-wrapper",children:(0,a.jsx)("table",{className:s("w-full border-collapse border border-border",r),"data-streamdown":"table",...n,children:t})}),thead:({node:e,children:t,className:r,...n})=>(0,a.jsx)("thead",{className:s("bg-muted/50",r),"data-streamdown":"table-header",...n,children:t}),tbody:({node:e,children:t,className:r,...n})=>(0,a.jsx)("tbody",{className:s("divide-y divide-border",r),"data-streamdown":"table-body",...n,children:t}),tr:({node:e,children:t,className:r,...n})=>(0,a.jsx)("tr",{className:s("border-border border-b",r),"data-streamdown":"table-row",...n,children:t}),th:({node:e,children:t,className:r,...n})=>(0,a.jsx)("th",{className:s("px-4 py-2 text-left font-semibold text-sm",r),"data-streamdown":"table-header-cell",...n,children:t}),td:({node:e,children:t,className:r,...n})=>(0,a.jsx)("td",{className:s("px-4 py-2 text-sm",r),"data-streamdown":"table-cell",...n,children:t}),blockquote:({node:e,children:t,className:r,...n})=>(0,a.jsx)("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",r),"data-streamdown":"blockquote",...n,children:t}),code:de,pre:({children:e})=>e,sup:({node:e,children:t,className:r,...n})=>(0,a.jsx)("sup",{className:s("text-sm",r),"data-streamdown":"superscript",...n,children:t}),sub:({node:e,children:t,className:r,...n})=>(0,a.jsx)("sub",{className:s("text-sm",r),"data-streamdown":"subscript",...n,children:t})};var z=require("marked"),V=e=>z.marked.use({gfm:!0}).lexer(e).map(r=>r.raw);var le=/(!?\[)([^\]]*?)$/,ce=/(\*\*)([^*]*?)$/,me=/(__)([^_]*?)$/,ue=/(\*\*\*)([^*]*?)$/,pe=/(\*)([^*]*?)$/,ge=/(_)([^_]*?)$/,he=/(`)([^`]*?)$/,fe=/(~~)([^~]*?)$/,be=/(\$)([^$]*?)$/,ke=/(\$\$)([^$]*?)$/,v=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
2
+ `)},ye=e=>{let t=e.match(le);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},Me=e=>v(e)?e:e.match(ce)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,Ce=e=>e.match(me)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,we=e=>e.split("").reduce((t,r,n)=>{if(r==="*"){let o=e[n-1],i=e[n+1];if(o==="\\")return t;let d=n;for(let l=n-1;l>=0;l--){if(e[l]===`
3
+ `){d=l+1;break}if(l===0){d=0;break}}if(e.substring(d,n).trim()===""&&(i===" "||i===" "))return t;if(o!=="*"&&i!=="*")return t+1}return t},0),Be=e=>v(e)?e:e.match(pe)&&we(e)%2===1?`${e}*`:e,ve=(e,t)=>{let r=!1,n=!1;for(let o=0;o<e.length&&o<t;o++){if(e[o]==="\\"&&e[o+1]==="$"){o++;continue}e[o]==="$"&&(e[o+1]==="$"?(n=!n,o++,r=!1):n||(r=!r))}return r||n},Ie=e=>e.split("").reduce((t,r,n)=>{if(r==="_"){let o=e[n-1],i=e[n+1];if(o==="\\"||ve(e,n))return t;if(o!=="_"&&i!=="_")return t+1}return t},0),Te=e=>v(e)?e:e.match(ge)&&Ie(e)%2===1?`${e}_`:e,$e=(e,t)=>{let r=e.substring(t,t+3)==="```",n=t>0&&e.substring(t-1,t+2)==="```",o=t>1&&e.substring(t-2,t+1)==="```";return r||n||o},Pe=e=>{let t=0;for(let r=0;r<e.length;r++)e[r]==="`"&&!$e(e,r)&&t++;return t},Ne=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
4
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let r=(e.match(/```/g)||[]).length,n=r%2===1;return r>0&&r%2===0&&e.includes(`
5
+ `)||(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0?e:e.match(he)&&!n&&Pe(e)%2===1?`${e}\``:e},Se=e=>e.match(fe)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,He=e=>e.split("").reduce((t,r,n)=>{if(r==="$"){let o=e[n-1],i=e[n+1];if(o==="\\")return t;if(o!=="$"&&i!=="$")return t+1}return t},0),Le=e=>e.match(ke)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,Ae=e=>v(e)?e:e.match(be)&&He(e)%2===1?`${e}$`:e,_e=e=>{let t=0,r=e.match(/\*+/g)||[];for(let n of r){let o=n.length;o>=3&&(t+=Math.floor(o/3))}return t},Re=e=>v(e)||/^\*{4,}$/.test(e)?e:e.match(ue)&&_e(e)%2===1?`${e}***`:e,W=e=>{if(!e||typeof e!="string")return e;let t=e;return t=ye(t),t=Re(t),t=Me(t),t=Ce(t),t=Be(t),t=Te(t),t=Ne(t),t=Se(t),t=Le(t),t=Ae(t),t};var I=require("react/jsx-runtime"),De=H.default.default||H.default,Ke=De(G.default),P=(0,h.createContext)(["github-light","github-dark"]),X=(0,h.memo)(({content:e,shouldParseIncompleteMarkdown:t,...r})=>{let n=(0,h.useMemo)(()=>typeof e=="string"&&t?W(e.trim()):e,[e,t]);return(0,I.jsx)(Ke,{...r,children:n})},(e,t)=>e.content===t.content);X.displayName="Block";var Y=(0,h.memo)(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:r,defaultOrigin:n,parseIncompleteMarkdown:o=!0,components:i,rehypePlugins:d,remarkPlugins:c,className:l,shikiTheme:u=["github-light","github-dark"],...g})=>{let y=(0,h.useId)(),f=(0,h.useMemo)(()=>V(typeof e=="string"?e:""),[e]),b=(0,h.useMemo)(()=>()=>(0,F.default)({errorColor:"var(--color-muted-foreground)"}),[]);return(0,I.jsx)(P.Provider,{value:u,children:(0,I.jsx)("div",{className:s("space-y-4",l),...g,children:f.map((w,T)=>(0,I.jsx)(X,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:r!=null?r:["*"],components:{...q,...i},content:w,defaultOrigin:n,rehypePlugins:[b,...d!=null?d:[]],remarkPlugins:[J.default,Q.default,...c!=null?c:[]],shouldParseIncompleteMarkdown:o},`${y}-block_${T}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Y.displayName="Streamdown";0&&(module.exports={ShikiThemeContext,Streamdown});
package/dist/index.js CHANGED
@@ -1,3 +1,5 @@
1
- "use client";import{createContext as Se,memo as x,useId as He,useMemo as E}from"react";import Le from"react-markdown";import _e from"rehype-katex";import Ae from"remark-gfm";import Re from"remark-math";import"katex/dist/katex.min.css";import D from"harden-react-markdown";import{isValidElement as Z}from"react";import{CheckIcon as z,CopyIcon as V,RouteIcon as ze}from"lucide-react";import{createContext as W,useContext as N,useEffect as G,useRef as F,useState as B}from"react";import{codeToHtml as w}from"shiki";import{clsx as U}from"clsx";import{twMerge as q}from"tailwind-merge";var s=(...e)=>q(U(e));import{jsx as k,jsxs as Q}from"react/jsx-runtime";var P=W({code:""});async function J(e,t,r){return Promise.all([await w(e,{lang:t,theme:r[0]}),await w(e,{lang:t,theme:r[1]})])}var S=({code:e,language:t,className:r,children:n,...o})=>{let[a,c]=B(""),[l,d]=B(""),m=F(!1),[u,p]=N(I);return G(()=>(J(e,t,[u,p]).then(([h,g])=>{m.current||(c(h),d(g),m.current=!0)}),()=>{m.current=!1}),[e,t,u,p]),k(P.Provider,{value:{code:e},children:Q("div",{className:"group relative",children:[k("div",{className:s("overflow-x-auto dark:hidden [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:a},...o}),k("div",{className:s("hidden overflow-x-auto dark:block [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:l},...o}),n]})})},v=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:o,code:a,...c})=>{let[l,d]=B(!1),m=N(P).code,u=a!=null?a:m,p=async()=>{var g;if(typeof window=="undefined"||!((g=navigator==null?void 0:navigator.clipboard)!=null&&g.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(u),d(!0),e==null||e(),setTimeout(()=>d(!1),r)}catch(b){t==null||t(b)}},h=l?z:V;return k("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",o),onClick:p,type:"button",...c,children:n!=null?n:k(h,{size:14})})};import{useEffect as X,useState as y}from"react";import{jsx as f,jsxs as M}from"react/jsx-runtime";var H=!1,Y=async()=>{if(!H){let r=(await import("mermaid")).default;return r.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),H=!0,r}return(await import("mermaid")).default},L=({chart:e,className:t})=>{let[r,n]=y(null),[o,a]=y(!0),[c,l]=y(""),[d,m]=y("");if(X(()=>{(async()=>{try{n(null),a(!0);let h=await Y(),g=e.split("").reduce(($,O)=>($<<5)-$+O.charCodeAt(0)|0,0),b=`mermaid-${Math.abs(g)}`,{svg:T}=await h.render(b,e);l(T),m(T)}catch(h){if(!(d||c)){let g=h instanceof Error?h.message:"Failed to render Mermaid chart";n(g)}}finally{a(!1)}})()},[e]),o&&!c&&!d)return f("div",{className:s("my-4 flex justify-center p-4",t),children:M("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[f("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),f("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!c&&!d)return M("div",{className:s("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[M("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),M("details",{className:"mt-2",children:[f("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),f("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let u=c||d;return f("div",{"aria-label":"Mermaid chart",className:s("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:u},role:"img"})};import{jsx as i,jsxs as te}from"react/jsx-runtime";var j=/language-([^\s]+)/,ee=({node:e,className:t,children:r,...n})=>{var m,u,p;if(((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((u=e==null?void 0:e.position)==null?void 0:u.end.line))return i("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),...n,children:r});let a=t==null?void 0:t.match(j),c=(p=a==null?void 0:a.at(1))!=null?p:"plaintext",l="";return Z(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?l=r.props.children:typeof r=="string"&&(l=r),c==="mermaid"||l.includes("graph")||l.includes("flowchart")||l.includes("sequenceDiagram")||l.includes("classDiagram")||l.includes("gantt")?te("div",{className:s("group relative my-4 h-auto rounded-lg border p-4",t),children:[i(L,{chart:l}),i(v,{code:l})]}):i(S,{className:s("my-4 h-auto rounded-lg border p-4",t),code:l,language:c,children:i(v,{})})},_={ol:({node:e,children:t,className:r,...n})=>i("ol",{className:s("ml-4 list-outside list-decimal",r),...n,children:t}),li:({node:e,children:t,className:r,...n})=>i("li",{className:s("py-1",r),...n,children:t}),ul:({node:e,children:t,className:r,...n})=>i("ul",{className:s("ml-4 list-outside list-disc",r),...n,children:t}),hr:({node:e,className:t,...r})=>i("hr",{className:s("my-6 border-border",t),...r}),strong:({node:e,children:t,className:r,...n})=>i("span",{className:s("font-semibold",r),...n,children:t}),a:({node:e,children:t,className:r,href:n,...o})=>i("a",{className:s("font-medium text-primary underline",r),href:n,rel:"noreferrer",target:"_blank",...o,children:t}),h1:({node:e,children:t,className:r,...n})=>i("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",r),...n,children:t}),h2:({node:e,children:t,className:r,...n})=>i("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",r),...n,children:t}),h3:({node:e,children:t,className:r,...n})=>i("h3",{className:s("mt-6 mb-2 font-semibold text-xl",r),...n,children:t}),h4:({node:e,children:t,className:r,...n})=>i("h4",{className:s("mt-6 mb-2 font-semibold text-lg",r),...n,children:t}),h5:({node:e,children:t,className:r,...n})=>i("h5",{className:s("mt-6 mb-2 font-semibold text-base",r),...n,children:t}),h6:({node:e,children:t,className:r,...n})=>i("h6",{className:s("mt-6 mb-2 font-semibold text-sm",r),...n,children:t}),table:({node:e,children:t,className:r,...n})=>i("div",{className:"my-4 overflow-x-auto",children:i("table",{className:s("w-full border-collapse border border-border",r),...n,children:t})}),thead:({node:e,children:t,className:r,...n})=>i("thead",{className:s("bg-muted/50",r),...n,children:t}),tbody:({node:e,children:t,className:r,...n})=>i("tbody",{className:s("divide-y divide-border",r),...n,children:t}),tr:({node:e,children:t,className:r,...n})=>i("tr",{className:s("border-border border-b",r),...n,children:t}),th:({node:e,children:t,className:r,...n})=>i("th",{className:s("px-4 py-2 text-left font-semibold text-sm",r),...n,children:t}),td:({node:e,children:t,className:r,...n})=>i("td",{className:s("px-4 py-2 text-sm",r),...n,children:t}),blockquote:({node:e,children:t,className:r,...n})=>i("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",r),...n,children:t}),code:ee,pre:({children:e})=>e,sup:({node:e,children:t,className:r,...n})=>i("sup",{className:s("text-sm",r),...n,children:t}),sub:({node:e,children:t,className:r,...n})=>i("sub",{className:s("text-sm",r),...n,children:t})};import{marked as re}from"marked";var A=e=>re.lexer(e).map(r=>r.raw);var ne=/(!?\[)([^\]]*?)$/,oe=/(\*\*)([^*]*?)$/,se=/(__)([^_]*?)$/,ie=/(\*\*\*)([^*]*?)$/,ae=/(\*)([^*]*?)$/,le=/(_)([^_]*?)$/,ce=/(`)([^`]*?)$/,de=/(~~)([^~]*?)$/,me=/(\$)([^$]*?)$/,ue=/(\$\$)([^$]*?)$/,pe=e=>{let t=e.match(ne);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},he=e=>e.match(oe)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,ge=e=>e.match(se)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,fe=e=>e.split("").reduce((t,r,n)=>{if(r==="*"){let o=e[n-1],a=e[n+1];if(o==="\\")return t;if(o!=="*"&&a!=="*")return t+1}return t},0),be=e=>e.match(ae)&&fe(e)%2===1?`${e}*`:e,ke=(e,t)=>{let r=!1,n=!1;for(let o=0;o<e.length&&o<t;o++){if(e[o]==="\\"&&e[o+1]==="$"){o++;continue}e[o]==="$"&&(e[o+1]==="$"?(n=!n,o++,r=!1):n||(r=!r))}return r||n},ye=e=>e.split("").reduce((t,r,n)=>{if(r==="_"){let o=e[n-1],a=e[n+1];if(o==="\\"||ke(e,n))return t;if(o!=="_"&&a!=="_")return t+1}return t},0),Me=e=>e.match(le)&&ye(e)%2===1?`${e}_`:e,Ce=(e,t)=>{let r=e.substring(t,t+3)==="```",n=t>0&&e.substring(t-1,t+2)==="```",o=t>1&&e.substring(t-2,t+1)==="```";return r||n||o},Be=e=>{let t=0;for(let r=0;r<e.length;r++)e[r]==="`"&&!Ce(e,r)&&t++;return t},ve=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
2
- `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let r=(e.match(/```/g)||[]).length,n=r%2===1;return(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0||r>0&&r%2===0&&e.includes(`
3
- `)?e:e.match(ce)&&!n&&Be(e)%2===1?`${e}\``:e},Ie=e=>e.match(de)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,Te=e=>e.split("").reduce((t,r,n)=>{if(r==="$"){let o=e[n-1],a=e[n+1];if(o==="\\")return t;if(o!=="$"&&a!=="$")return t+1}return t},0),$e=e=>e.match(ue)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,we=e=>e.match(me)&&Te(e)%2===1?`${e}$`:e,Ne=e=>{let t=0,r=e.match(/\*+/g)||[];for(let n of r){let o=n.length;o>=3&&(t+=Math.floor(o/3))}return t},Pe=e=>/^\*{4,}$/.test(e)?e:e.match(ie)&&Ne(e)%2===1?`${e}***`:e,R=e=>{if(!e||typeof e!="string")return e;let t=e;return t=pe(t),t=Pe(t),t=he(t),t=ge(t),t=be(t),t=Me(t),t=ve(t),t=Ie(t),t=$e(t),t=we(t),t};import{jsx as C}from"react/jsx-runtime";var De=D.default||D,xe=De(Le),I=Se(["github-light","github-dark"]),K=x(({content:e,shouldParseIncompleteMarkdown:t,...r})=>{let n=E(()=>typeof e=="string"&&t?R(e.trim()):e,[e,t]);return C(xe,{...r,children:n})},(e,t)=>e.content===t.content);K.displayName="Block";var Ee=x(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:r,defaultOrigin:n,parseIncompleteMarkdown:o=!0,components:a,rehypePlugins:c,remarkPlugins:l,className:d,shikiTheme:m=["github-light","github-dark"],...u})=>{let p=He(),h=E(()=>A(typeof e=="string"?e:""),[e]);return C(I.Provider,{value:m,children:C("div",{className:s("space-y-4",d),...u,children:h.map((g,b)=>C(K,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:r!=null?r:["*"],components:{..._,...a},content:g,defaultOrigin:n,rehypePlugins:[_e,...c!=null?c:[]],remarkPlugins:[Ae,Re,...l!=null?l:[]],shouldParseIncompleteMarkdown:o},`${p}-block_${b}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Ee.displayName="Streamdown";export{I as ShikiThemeContext,Ee as Streamdown};
1
+ "use client";import{createContext as He,memo as O,useId as Le,useMemo as $}from"react";import Ae from"react-markdown";import _e from"rehype-katex";import Re from"remark-gfm";import De from"remark-math";import"katex/dist/katex.min.css";import E from"harden-react-markdown";import{isValidElement as x}from"react";import{CheckIcon as W,CopyIcon as G,RouteIcon as We}from"lucide-react";import{createContext as F,useContext as S,useEffect as J,useRef as Q,useState as v}from"react";import{codeToHtml as N}from"shiki";import{clsx as z}from"clsx";import{twMerge as V}from"tailwind-merge";var s=(...e)=>V(z(e));import{jsx as k,jsxs as Y}from"react/jsx-runtime";var H=F({code:""});async function X(e,t,r){return Promise.all([await N(e,{lang:t,theme:r[0]}),await N(e,{lang:t,theme:r[1]})])}var L=({code:e,language:t,className:r,children:n,...o})=>{let[i,d]=v(""),[c,l]=v(""),m=Q(!1),[u,h]=S(T);return J(()=>(X(e,t,[u,h]).then(([p,g])=>{m.current||(d(p),l(g),m.current=!0)}),()=>{m.current=!1}),[e,t,u,h]),k(H.Provider,{value:{code:e},children:Y("div",{className:"group relative",children:[k("div",{className:s("overflow-x-auto dark:hidden [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:i},...o}),k("div",{className:s("hidden overflow-x-auto dark:block [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:c},...o}),n]})})},I=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:o,code:i,...d})=>{let[c,l]=v(!1),m=S(H).code,u=i!=null?i:m,h=async()=>{var g;if(typeof window=="undefined"||!((g=navigator==null?void 0:navigator.clipboard)!=null&&g.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(u),l(!0),e==null||e(),setTimeout(()=>l(!1),r)}catch(b){t==null||t(b)}},p=c?W:G;return k("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",o),onClick:h,type:"button",...d,children:n!=null?n:k(p,{size:14})})};import{useEffect as Z,useState as C}from"react";import{jsx as f,jsxs as w}from"react/jsx-runtime";var A=!1,j=async()=>{if(!A){let r=(await import("mermaid")).default;return r.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),A=!0,r}return(await import("mermaid")).default},_=({chart:e,className:t})=>{let[r,n]=C(null),[o,i]=C(!0),[d,c]=C(""),[l,m]=C("");if(Z(()=>{(async()=>{try{n(null),i(!0);let p=await j(),g=e.split("").reduce((P,q)=>(P<<5)-P+q.charCodeAt(0)|0,0),b=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:M}=await p.render(b,e);c(M),m(M)}catch(p){if(!(l||d)){let g=p instanceof Error?p.message:"Failed to render Mermaid chart";n(g)}}finally{i(!1)}})()},[e]),o&&!d&&!l)return f("div",{className:s("my-4 flex justify-center p-4",t),children:w("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[f("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),f("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!d&&!l)return w("div",{className:s("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[w("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),w("details",{className:"mt-2",children:[f("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),f("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]});let u=d||l;return f("div",{"aria-label":"Mermaid chart",className:s("my-4 flex justify-center",t),dangerouslySetInnerHTML:{__html:u},role:"img"})};import{jsx as a,jsxs as re}from"react/jsx-runtime";var ee=/language-([^\s]+)/,te=({node:e,className:t,children:r,...n})=>{var l,m,u;if(((l=e==null?void 0:e.position)==null?void 0:l.start.line)===((m=e==null?void 0:e.position)==null?void 0:m.end.line))return a("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:r});let i=t==null?void 0:t.match(ee),d=(u=i==null?void 0:i.at(1))!=null?u:"plaintext",c="";return x(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?c=r.props.children:typeof r=="string"&&(c=r),d==="mermaid"?re("div",{className:s("group relative my-4 h-auto rounded-lg border p-4",t),"data-streamdown":"mermaid-block",children:[a(_,{chart:c}),a(I,{code:c})]}):a(L,{className:s("my-4 h-auto rounded-lg border p-4",t),code:c,"data-language":d,"data-streamdown":"code-block",language:d,children:a(I,{})})},R={ol:({node:e,children:t,className:r,...n})=>a("ol",{className:s("ml-4 list-outside list-decimal",r),"data-streamdown":"ordered-list",...n,children:t}),li:({node:e,children:t,className:r,...n})=>a("li",{className:s("py-1",r),"data-streamdown":"list-item",...n,children:t}),ul:({node:e,children:t,className:r,...n})=>a("ul",{className:s("ml-4 list-outside list-disc",r),"data-streamdown":"unordered-list",...n,children:t}),hr:({node:e,className:t,...r})=>a("hr",{className:s("my-6 border-border",t),"data-streamdown":"horizontal-rule",...r}),strong:({node:e,children:t,className:r,...n})=>a("span",{className:s("font-semibold",r),"data-streamdown":"strong",...n,children:t}),a:({node:e,children:t,className:r,href:n,...o})=>a("a",{className:s("font-medium text-primary underline",r),"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...o,children:t}),h1:({node:e,children:t,className:r,...n})=>a("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",r),"data-streamdown":"heading-1",...n,children:t}),h2:({node:e,children:t,className:r,...n})=>a("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",r),"data-streamdown":"heading-2",...n,children:t}),h3:({node:e,children:t,className:r,...n})=>a("h3",{className:s("mt-6 mb-2 font-semibold text-xl",r),"data-streamdown":"heading-3",...n,children:t}),h4:({node:e,children:t,className:r,...n})=>a("h4",{className:s("mt-6 mb-2 font-semibold text-lg",r),"data-streamdown":"heading-4",...n,children:t}),h5:({node:e,children:t,className:r,...n})=>a("h5",{className:s("mt-6 mb-2 font-semibold text-base",r),"data-streamdown":"heading-5",...n,children:t}),h6:({node:e,children:t,className:r,...n})=>a("h6",{className:s("mt-6 mb-2 font-semibold text-sm",r),"data-streamdown":"heading-6",...n,children:t}),table:({node:e,children:t,className:r,...n})=>a("div",{className:"my-4 overflow-x-auto","data-streamdown":"table-wrapper",children:a("table",{className:s("w-full border-collapse border border-border",r),"data-streamdown":"table",...n,children:t})}),thead:({node:e,children:t,className:r,...n})=>a("thead",{className:s("bg-muted/50",r),"data-streamdown":"table-header",...n,children:t}),tbody:({node:e,children:t,className:r,...n})=>a("tbody",{className:s("divide-y divide-border",r),"data-streamdown":"table-body",...n,children:t}),tr:({node:e,children:t,className:r,...n})=>a("tr",{className:s("border-border border-b",r),"data-streamdown":"table-row",...n,children:t}),th:({node:e,children:t,className:r,...n})=>a("th",{className:s("px-4 py-2 text-left font-semibold text-sm",r),"data-streamdown":"table-header-cell",...n,children:t}),td:({node:e,children:t,className:r,...n})=>a("td",{className:s("px-4 py-2 text-sm",r),"data-streamdown":"table-cell",...n,children:t}),blockquote:({node:e,children:t,className:r,...n})=>a("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",r),"data-streamdown":"blockquote",...n,children:t}),code:te,pre:({children:e})=>e,sup:({node:e,children:t,className:r,...n})=>a("sup",{className:s("text-sm",r),"data-streamdown":"superscript",...n,children:t}),sub:({node:e,children:t,className:r,...n})=>a("sub",{className:s("text-sm",r),"data-streamdown":"subscript",...n,children:t})};import{marked as ne}from"marked";var D=e=>ne.use({gfm:!0}).lexer(e).map(r=>r.raw);var oe=/(!?\[)([^\]]*?)$/,se=/(\*\*)([^*]*?)$/,ae=/(__)([^_]*?)$/,ie=/(\*\*\*)([^*]*?)$/,de=/(\*)([^*]*?)$/,le=/(_)([^_]*?)$/,ce=/(`)([^`]*?)$/,me=/(~~)([^~]*?)$/,ue=/(\$)([^$]*?)$/,pe=/(\$\$)([^$]*?)$/,y=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
2
+ `)},ge=e=>{let t=e.match(oe);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},he=e=>y(e)?e:e.match(se)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,fe=e=>e.match(ae)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,be=e=>e.split("").reduce((t,r,n)=>{if(r==="*"){let o=e[n-1],i=e[n+1];if(o==="\\")return t;let d=n;for(let l=n-1;l>=0;l--){if(e[l]===`
3
+ `){d=l+1;break}if(l===0){d=0;break}}if(e.substring(d,n).trim()===""&&(i===" "||i===" "))return t;if(o!=="*"&&i!=="*")return t+1}return t},0),ke=e=>y(e)?e:e.match(de)&&be(e)%2===1?`${e}*`:e,ye=(e,t)=>{let r=!1,n=!1;for(let o=0;o<e.length&&o<t;o++){if(e[o]==="\\"&&e[o+1]==="$"){o++;continue}e[o]==="$"&&(e[o+1]==="$"?(n=!n,o++,r=!1):n||(r=!r))}return r||n},Me=e=>e.split("").reduce((t,r,n)=>{if(r==="_"){let o=e[n-1],i=e[n+1];if(o==="\\"||ye(e,n))return t;if(o!=="_"&&i!=="_")return t+1}return t},0),Ce=e=>y(e)?e:e.match(le)&&Me(e)%2===1?`${e}_`:e,we=(e,t)=>{let r=e.substring(t,t+3)==="```",n=t>0&&e.substring(t-1,t+2)==="```",o=t>1&&e.substring(t-2,t+1)==="```";return r||n||o},Be=e=>{let t=0;for(let r=0;r<e.length;r++)e[r]==="`"&&!we(e,r)&&t++;return t},ve=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
4
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let r=(e.match(/```/g)||[]).length,n=r%2===1;return r>0&&r%2===0&&e.includes(`
5
+ `)||(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0?e:e.match(ce)&&!n&&Be(e)%2===1?`${e}\``:e},Ie=e=>e.match(me)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,Te=e=>e.split("").reduce((t,r,n)=>{if(r==="$"){let o=e[n-1],i=e[n+1];if(o==="\\")return t;if(o!=="$"&&i!=="$")return t+1}return t},0),$e=e=>e.match(pe)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,Pe=e=>y(e)?e:e.match(ue)&&Te(e)%2===1?`${e}$`:e,Ne=e=>{let t=0,r=e.match(/\*+/g)||[];for(let n of r){let o=n.length;o>=3&&(t+=Math.floor(o/3))}return t},Se=e=>y(e)||/^\*{4,}$/.test(e)?e:e.match(ie)&&Ne(e)%2===1?`${e}***`:e,K=e=>{if(!e||typeof e!="string")return e;let t=e;return t=ge(t),t=Se(t),t=he(t),t=fe(t),t=ke(t),t=Ce(t),t=ve(t),t=Ie(t),t=$e(t),t=Pe(t),t};import{jsx as B}from"react/jsx-runtime";var Ke=E.default||E,Ee=Ke(Ae),T=He(["github-light","github-dark"]),U=O(({content:e,shouldParseIncompleteMarkdown:t,...r})=>{let n=$(()=>typeof e=="string"&&t?K(e.trim()):e,[e,t]);return B(Ee,{...r,children:n})},(e,t)=>e.content===t.content);U.displayName="Block";var Oe=O(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:r,defaultOrigin:n,parseIncompleteMarkdown:o=!0,components:i,rehypePlugins:d,remarkPlugins:c,className:l,shikiTheme:m=["github-light","github-dark"],...u})=>{let h=Le(),p=$(()=>D(typeof e=="string"?e:""),[e]),g=$(()=>()=>_e({errorColor:"var(--color-muted-foreground)"}),[]);return B(T.Provider,{value:m,children:B("div",{className:s("space-y-4",l),...u,children:p.map((b,M)=>B(U,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:r!=null?r:["*"],components:{...R,...i},content:b,defaultOrigin:n,rehypePlugins:[g,...d!=null?d:[]],remarkPlugins:[Re,De,...c!=null?c:[]],shouldParseIncompleteMarkdown:o},`${h}-block_${M}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Oe.displayName="Streamdown";export{T as ShikiThemeContext,Oe as Streamdown};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamdown",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "homepage": "https://streamdown.ai",
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "https://github.com/vercel/streamdown.git",
22
+ "url": "git+https://github.com/vercel/streamdown.git",
23
23
  "directory": "packages/streamdown"
24
24
  },
25
25
  "scripts": {