streamdown 1.1.5 → 1.1.6

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
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(`
1
+ "use strict";"use client";var j=Object.create;var T=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)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&&T(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?T(r,"default",{value:e,enumerable:!0}):r,e)),oe=e=>A(T({},"__esModule",{value:!0}),e);var Re={};ne(Re,{ShikiThemeContext:()=>$,Streamdown:()=>Y});module.exports=oe(Re);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),Xe=require("katex/dist/katex.min.css"),H=M(require("harden-react-markdown"),1);var K=require("react");var B=require("lucide-react"),m=require("react"),P=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,P.codeToHtml)(e,{lang:t,theme:r[0]}),await(0,P.codeToHtml)(e,{lang:t,theme:r[1]})])}var E=({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)($);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"),O=!1,ae=async()=>{if(!O){let r=(await import("mermaid")).default;return r.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),O=!0,r}return(await import("mermaid")).default},U=({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:I}=await f.render(w,e);c(I),u(I)}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,K.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)(U,{chart:c}),(0,a.jsx)(S,{code:c})]}):(0,a.jsx)(E,{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=/(\$\$)([^$]*?)$/,N=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
2
+ `)},ke=e=>{let t=e.match(le);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},ye=e=>N(e)?e:e.match(ce)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,Me=e=>e.match(me)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,Ce=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),we=e=>N(e)?e:e.match(pe)&&Ce(e)%2===1?`${e}*`:e,Be=(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},ve=e=>e.split("").reduce((t,r,n)=>{if(r==="_"){let o=e[n-1],i=e[n+1];if(o==="\\"||Be(e,n))return t;if(o!=="_"&&i!=="_")return t+1}return t},0),Ie=e=>N(e)?e:e.match(ge)&&ve(e)%2===1?`${e}_`:e,Te=(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},$e=e=>{let t=0;for(let r=0;r<e.length;r++)e[r]==="`"&&!Te(e,r)&&t++;return t},Ne=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
4
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});
5
+ `)||(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0?e:e.match(he)&&!n&&$e(e)%2===1?`${e}\``:e},Pe=e=>e.match(fe)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e;var Se=e=>e.match(be)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e;var He=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},Le=e=>N(e)||/^\*{4,}$/.test(e)?e:e.match(ue)&&He(e)%2===1?`${e}***`:e,W=e=>{if(!e||typeof e!="string")return e;let t=e;return t=ke(t),t=Le(t),t=ye(t),t=Me(t),t=we(t),t=Ie(t),t=Ne(t),t=Pe(t),t=Se(t),t};var v=require("react/jsx-runtime"),Ae=H.default.default||H.default,_e=Ae(G.default),$=(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,v.jsx)(_e,{...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,v.jsx)($.Provider,{value:u,children:(0,v.jsx)("div",{className:s("space-y-4",l),...g,children:f.map((w,I)=>(0,v.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,{singleDollarTextMath:!1}],...c!=null?c:[]],shouldParseIncompleteMarkdown:o},`${y}-block_${I}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Y.displayName="Streamdown";0&&(module.exports={ShikiThemeContext,Streamdown});
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
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(`
1
+ "use client";import{createContext as Ne,memo as U,useId as Pe,useMemo as $}from"react";import Se from"react-markdown";import He from"rehype-katex";import Le from"remark-gfm";import Ae from"remark-math";import"katex/dist/katex.min.css";import O from"harden-react-markdown";import{isValidElement as x}from"react";import{CheckIcon as W,CopyIcon as G,RouteIcon as qe}from"lucide-react";import{createContext as F,useContext as S,useEffect as J,useRef as Q,useState as v}from"react";import{codeToHtml as P}from"shiki";import{clsx as z}from"clsx";import{twMerge as V}from"tailwind-merge";var o=(...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 P(e,{lang:t,theme:r[0]}),await P(e,{lang:t,theme:r[1]})])}var L=({code:e,language:t,className:r,children:n,...s})=>{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:o("overflow-x-auto dark:hidden [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:i},...s}),k("div",{className:o("hidden overflow-x-auto dark:block [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:c},...s}),n]})})},I=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:s,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:o("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",s),onClick:h,type:"button",...d,children:n!=null?n:k(p,{size:14})})};import{useEffect as Z,useState as M}from"react";import{jsx as f,jsxs as C}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]=M(null),[s,i]=M(!0),[d,c]=M(""),[l,m]=M("");if(Z(()=>{(async()=>{try{n(null),i(!0);let p=await j(),g=e.split("").reduce((N,q)=>(N<<5)-N+q.charCodeAt(0)|0,0),b=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:y}=await p.render(b,e);c(y),m(y)}catch(p){if(!(l||d)){let g=p instanceof Error?p.message:"Failed to render Mermaid chart";n(g)}}finally{i(!1)}})()},[e]),s&&!d&&!l)return f("div",{className:o("my-4 flex justify-center p-4",t),children:C("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 C("div",{className:o("rounded-lg border border-red-200 bg-red-50 p-4",t),children:[C("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),C("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:o("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:o("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:o("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:o("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:o("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:o("py-1",r),"data-streamdown":"list-item",...n,children:t}),ul:({node:e,children:t,className:r,...n})=>a("ul",{className:o("ml-4 list-outside list-disc",r),"data-streamdown":"unordered-list",...n,children:t}),hr:({node:e,className:t,...r})=>a("hr",{className:o("my-6 border-border",t),"data-streamdown":"horizontal-rule",...r}),strong:({node:e,children:t,className:r,...n})=>a("span",{className:o("font-semibold",r),"data-streamdown":"strong",...n,children:t}),a:({node:e,children:t,className:r,href:n,...s})=>a("a",{className:o("font-medium text-primary underline",r),"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...s,children:t}),h1:({node:e,children:t,className:r,...n})=>a("h1",{className:o("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:o("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:o("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:o("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:o("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:o("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:o("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:o("bg-muted/50",r),"data-streamdown":"table-header",...n,children:t}),tbody:({node:e,children:t,className:r,...n})=>a("tbody",{className:o("divide-y divide-border",r),"data-streamdown":"table-body",...n,children:t}),tr:({node:e,children:t,className:r,...n})=>a("tr",{className:o("border-border border-b",r),"data-streamdown":"table-row",...n,children:t}),th:({node:e,children:t,className:r,...n})=>a("th",{className:o("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:o("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:o("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:o("text-sm",r),"data-streamdown":"superscript",...n,children:t}),sub:({node:e,children:t,className:r,...n})=>a("sub",{className:o("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=/(\$\$)([^$]*?)$/,w=e=>{let t=(e.match(/```/g)||[]).length;return t>0&&t%2===0&&e.includes(`
2
+ `)},pe=e=>{let t=e.match(oe);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},ge=e=>w(e)?e:e.match(se)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,he=e=>e.match(ae)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,fe=e=>e.split("").reduce((t,r,n)=>{if(r==="*"){let s=e[n-1],i=e[n+1];if(s==="\\")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(s!=="*"&&i!=="*")return t+1}return t},0),be=e=>w(e)?e:e.match(de)&&fe(e)%2===1?`${e}*`:e,ke=(e,t)=>{let r=!1,n=!1;for(let s=0;s<e.length&&s<t;s++){if(e[s]==="\\"&&e[s+1]==="$"){s++;continue}e[s]==="$"&&(e[s+1]==="$"?(n=!n,s++,r=!1):n||(r=!r))}return r||n},ye=e=>e.split("").reduce((t,r,n)=>{if(r==="_"){let s=e[n-1],i=e[n+1];if(s==="\\"||ke(e,n))return t;if(s!=="_"&&i!=="_")return t+1}return t},0),Me=e=>w(e)?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)==="```",s=t>1&&e.substring(t-2,t+1)==="```";return r||n||s},we=e=>{let t=0;for(let r=0;r<e.length;r++)e[r]==="`"&&!Ce(e,r)&&t++;return t},Be=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
4
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};
5
+ `)||(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0?e:e.match(ce)&&!n&&we(e)%2===1?`${e}\``:e},ve=e=>e.match(me)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e;var Ie=e=>e.match(ue)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e;var Te=e=>{let t=0,r=e.match(/\*+/g)||[];for(let n of r){let s=n.length;s>=3&&(t+=Math.floor(s/3))}return t},$e=e=>w(e)||/^\*{4,}$/.test(e)?e:e.match(ie)&&Te(e)%2===1?`${e}***`:e,E=e=>{if(!e||typeof e!="string")return e;let t=e;return t=pe(t),t=$e(t),t=ge(t),t=he(t),t=be(t),t=Me(t),t=Be(t),t=ve(t),t=Ie(t),t};import{jsx as B}from"react/jsx-runtime";var _e=O.default||O,Re=_e(Se),T=Ne(["github-light","github-dark"]),K=U(({content:e,shouldParseIncompleteMarkdown:t,...r})=>{let n=$(()=>typeof e=="string"&&t?E(e.trim()):e,[e,t]);return B(Re,{...r,children:n})},(e,t)=>e.content===t.content);K.displayName="Block";var De=U(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:r,defaultOrigin:n,parseIncompleteMarkdown:s=!0,components:i,rehypePlugins:d,remarkPlugins:c,className:l,shikiTheme:m=["github-light","github-dark"],...u})=>{let h=Pe(),p=$(()=>D(typeof e=="string"?e:""),[e]),g=$(()=>()=>He({errorColor:"var(--color-muted-foreground)"}),[]);return B(T.Provider,{value:m,children:B("div",{className:o("space-y-4",l),...u,children:p.map((b,y)=>B(K,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:r!=null?r:["*"],components:{...R,...i},content:b,defaultOrigin:n,rehypePlugins:[g,...d!=null?d:[]],remarkPlugins:[Le,[Ae,{singleDollarTextMath:!1}],...c!=null?c:[]],shouldParseIncompleteMarkdown:s},`${h}-block_${y}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);De.displayName="Streamdown";export{T as ShikiThemeContext,De as Streamdown};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamdown",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -22,12 +22,6 @@
22
22
  "url": "git+https://github.com/vercel/streamdown.git",
23
23
  "directory": "packages/streamdown"
24
24
  },
25
- "scripts": {
26
- "build": "tsup",
27
- "test": "vitest run",
28
- "test:ui": "vitest --ui run",
29
- "test:coverage": "vitest --coverage run"
30
- },
31
25
  "author": "Hayden Bleasel <hayden.bleasel@vercel.com>",
32
26
  "license": "Apache-2.0",
33
27
  "description": "A drop-in replacement for react-markdown, designed for AI-powered streaming.",
@@ -60,5 +54,11 @@
60
54
  "remark-math": "^6.0.0",
61
55
  "shiki": "^3.9.2",
62
56
  "tailwind-merge": "^3.3.1"
57
+ },
58
+ "scripts": {
59
+ "build": "tsup",
60
+ "test": "vitest run",
61
+ "test:ui": "vitest --ui run",
62
+ "test:coverage": "vitest --coverage run"
63
63
  }
64
- }
64
+ }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../index.tsx","../lib/components.tsx","../lib/code-block.tsx","../lib/utils.ts","../lib/parse-blocks.tsx","../lib/parse-incomplete-markdown.ts"],"sourcesContent":["'use client';\n\nimport type { ComponentProps } from 'react';\nimport { memo, useId, useMemo } from 'react';\nimport ReactMarkdown from 'react-markdown';\nimport rehypeKatex from 'rehype-katex';\nimport remarkGfm from 'remark-gfm';\nimport remarkMath from 'remark-math';\nimport 'katex/dist/katex.min.css';\nimport hardenReactMarkdownImport from 'harden-react-markdown';\nimport { components as defaultComponents } from './lib/components';\nimport { parseMarkdownIntoBlocks } from './lib/parse-blocks';\nimport { parseIncompleteMarkdown } from './lib/parse-incomplete-markdown';\nimport { cn } from './lib/utils';\n\n// Handle both ESM and CJS imports\nconst hardenReactMarkdown = (hardenReactMarkdownImport as any).default || hardenReactMarkdownImport;\n\n// Create a hardened version of ReactMarkdown\nconst HardenedMarkdown: ReturnType<typeof hardenReactMarkdown> =\n hardenReactMarkdown(ReactMarkdown);\n\nexport type StreamdownProps = ComponentProps<typeof HardenedMarkdown> & {\n parseIncompleteMarkdown?: boolean;\n className?: string;\n};\n\ntype BlockProps = ComponentProps<typeof HardenedMarkdown> & {\n content: string;\n shouldParseIncompleteMarkdown: boolean;\n};\n\nconst Block = memo(\n ({ content, shouldParseIncompleteMarkdown, ...props }: BlockProps) => {\n const parsedContent = useMemo(\n () =>\n typeof content === 'string' && shouldParseIncompleteMarkdown\n ? parseIncompleteMarkdown(content.trim())\n : content,\n [content, shouldParseIncompleteMarkdown]\n );\n\n return <HardenedMarkdown {...props}>{parsedContent}</HardenedMarkdown>;\n },\n (prevProps, nextProps) => prevProps.content === nextProps.content\n);\n\nexport const Streamdown = memo(\n ({\n children,\n allowedImagePrefixes,\n allowedLinkPrefixes,\n defaultOrigin,\n parseIncompleteMarkdown: shouldParseIncompleteMarkdown = true,\n components,\n rehypePlugins,\n remarkPlugins,\n className,\n ...props\n }: StreamdownProps) => {\n // Parse the children to remove incomplete markdown tokens if enabled\n const generatedId = useId();\n const blocks = useMemo(\n () =>\n parseMarkdownIntoBlocks(typeof children === 'string' ? children : ''),\n [children]\n );\n\n return (\n <div className={cn('space-y-4', className)} {...props}>\n {blocks.map((block, index) => (\n <Block\n allowedImagePrefixes={allowedImagePrefixes ?? ['*']}\n allowedLinkPrefixes={allowedLinkPrefixes ?? ['*']}\n components={{\n ...defaultComponents,\n ...components,\n }}\n content={block}\n defaultOrigin={defaultOrigin}\n // biome-ignore lint/suspicious/noArrayIndexKey: \"required\"\n key={`${generatedId}-block_${index}`}\n rehypePlugins={[rehypeKatex, ...(rehypePlugins ?? [])]}\n remarkPlugins={[remarkGfm, remarkMath, ...(remarkPlugins ?? [])]}\n shouldParseIncompleteMarkdown={shouldParseIncompleteMarkdown}\n />\n ))}\n </div>\n );\n },\n (prevProps, nextProps) => prevProps.children === nextProps.children\n);\nStreamdown.displayName = 'Streamdown';\n\nexport default Streamdown;\n","import { isValidElement } from 'react';\nimport type { Options } from 'react-markdown';\nimport type { BundledLanguage } from 'shiki';\nimport { CodeBlock, CodeBlockCopyButton } from './code-block';\nimport { cn } from './utils';\n\nexport const components: Options['components'] = {\n ol: ({ node, children, className, ...props }) => (\n <ol className={cn('ml-4 list-outside list-decimal', className)} {...props}>\n {children}\n </ol>\n ),\n li: ({ node, children, className, ...props }) => (\n <li className={cn('py-1', className)} {...props}>\n {children}\n </li>\n ),\n ul: ({ node, children, className, ...props }) => (\n <ul className={cn('ml-4 list-outside list-disc', className)} {...props}>\n {children}\n </ul>\n ),\n hr: ({ node, className, ...props }) => (\n <hr className={cn('my-6 border-border', className)} {...props} />\n ),\n strong: ({ node, children, className, ...props }) => (\n <span className={cn('font-semibold', className)} {...props}>\n {children}\n </span>\n ),\n a: ({ node, children, className, href, ...props }) => (\n <a\n className={cn('font-medium text-primary underline', className)}\n href={href}\n rel=\"noreferrer\"\n target=\"_blank\"\n {...props}\n >\n {children}\n </a>\n ),\n h1: ({ node, children, className, ...props }) => (\n <h1\n className={cn('mt-6 mb-2 font-semibold text-3xl', className)}\n {...props}\n >\n {children}\n </h1>\n ),\n h2: ({ node, children, className, ...props }) => (\n <h2\n className={cn('mt-6 mb-2 font-semibold text-2xl', className)}\n {...props}\n >\n {children}\n </h2>\n ),\n h3: ({ node, children, className, ...props }) => (\n <h3 className={cn('mt-6 mb-2 font-semibold text-xl', className)} {...props}>\n {children}\n </h3>\n ),\n h4: ({ node, children, className, ...props }) => (\n <h4 className={cn('mt-6 mb-2 font-semibold text-lg', className)} {...props}>\n {children}\n </h4>\n ),\n h5: ({ node, children, className, ...props }) => (\n <h5\n className={cn('mt-6 mb-2 font-semibold text-base', className)}\n {...props}\n >\n {children}\n </h5>\n ),\n h6: ({ node, children, className, ...props }) => (\n <h6 className={cn('mt-6 mb-2 font-semibold text-sm', className)} {...props}>\n {children}\n </h6>\n ),\n table: ({ node, children, className, ...props }) => (\n <div className=\"my-4 overflow-x-auto\">\n <table\n className={cn('w-full border-collapse border border-border', className)}\n {...props}\n >\n {children}\n </table>\n </div>\n ),\n thead: ({ node, children, className, ...props }) => (\n <thead className={cn('bg-muted/50', className)} {...props}>\n {children}\n </thead>\n ),\n tbody: ({ node, children, className, ...props }) => (\n <tbody className={cn('divide-y divide-border', className)} {...props}>\n {children}\n </tbody>\n ),\n tr: ({ node, children, className, ...props }) => (\n <tr className={cn('border-border border-b', className)} {...props}>\n {children}\n </tr>\n ),\n th: ({ node, children, className, ...props }) => (\n <th\n className={cn('px-4 py-2 text-left font-semibold text-sm', className)}\n {...props}\n >\n {children}\n </th>\n ),\n td: ({ node, children, className, ...props }) => (\n <td className={cn('px-4 py-2 text-sm', className)} {...props}>\n {children}\n </td>\n ),\n blockquote: ({ node, children, className, ...props }) => (\n <blockquote\n className={cn(\n 'my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic',\n className\n )}\n {...props}\n >\n {children}\n </blockquote>\n ),\n code: ({ node, className, ...props }) => {\n const inline = node?.position?.start.line === node?.position?.end.line;\n\n if (!inline) {\n return <code className={className} {...props} />;\n }\n\n return (\n <code\n className={cn(\n 'rounded bg-muted px-1.5 py-0.5 font-mono text-sm',\n className\n )}\n {...props}\n />\n );\n },\n pre: ({ node, className, children }) => {\n let language: BundledLanguage = 'javascript';\n\n if (typeof node?.properties?.className === 'string') {\n language = node.properties.className.replace(\n 'language-',\n ''\n ) as BundledLanguage;\n }\n\n // Extract code content from children safely\n let code = '';\n if (\n isValidElement(children) &&\n children.props &&\n typeof children.props === 'object' &&\n 'children' in children.props &&\n typeof children.props.children === 'string'\n ) {\n code = children.props.children;\n } else if (typeof children === 'string') {\n code = children;\n }\n\n return (\n <CodeBlock\n className={cn('my-4 h-auto rounded-lg border p-4', className)}\n code={code}\n language={language}\n >\n <CodeBlockCopyButton />\n </CodeBlock>\n );\n },\n sup: ({ node, children, className, ...props }) => (\n <sup className={cn('text-sm', className)} {...props}>\n {children}\n </sup>\n ),\n sub: ({ node, children, className, ...props }) => (\n <sub className={cn('text-sm', className)} {...props}>\n {children}\n </sub>\n ),\n};\n","'use client';\n\nimport { CheckIcon, CopyIcon } from 'lucide-react';\nimport {\n type ComponentProps,\n createContext,\n type HTMLAttributes,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { type BundledLanguage, codeToHtml } from 'shiki';\nimport { cn } from './utils';\n\ntype CodeBlockProps = HTMLAttributes<HTMLDivElement> & {\n code: string;\n language: BundledLanguage;\n};\n\ntype CodeBlockContextType = {\n code: string;\n};\n\nconst CodeBlockContext = createContext<CodeBlockContextType>({\n code: '',\n});\n\nexport async function highlightCode(code: string, language: BundledLanguage) {\n return await codeToHtml(code, {\n lang: language,\n theme: 'github-light',\n });\n}\n\nexport const CodeBlock = ({\n code,\n language,\n className,\n children,\n ...props\n}: CodeBlockProps) => {\n const [html, setHtml] = useState<string>('');\n\n useEffect(() => {\n let isMounted = true;\n\n highlightCode(code, language).then((result) => {\n if (isMounted) {\n setHtml(result);\n }\n });\n\n return () => {\n isMounted = false;\n };\n }, [code, language]);\n\n return (\n <CodeBlockContext.Provider value={{ code }}>\n <div className=\"group relative\">\n <div\n className={cn('overflow-x-auto', className)}\n // biome-ignore lint/security/noDangerouslySetInnerHtml: \"this is needed.\"\n dangerouslySetInnerHTML={{ __html: html }}\n {...props}\n />\n {children}\n </div>\n </CodeBlockContext.Provider>\n );\n};\n\nexport type CodeBlockCopyButtonProps = ComponentProps<'button'> & {\n onCopy?: () => void;\n onError?: (error: Error) => void;\n timeout?: number;\n};\n\nexport const CodeBlockCopyButton = ({\n onCopy,\n onError,\n timeout = 2000,\n children,\n className,\n ...props\n}: CodeBlockCopyButtonProps) => {\n const [isCopied, setIsCopied] = useState(false);\n const { code } = useContext(CodeBlockContext);\n\n const copyToClipboard = async () => {\n if (typeof window === 'undefined' || !navigator?.clipboard?.writeText) {\n onError?.(new Error('Clipboard API not available'));\n return;\n }\n\n try {\n await navigator.clipboard.writeText(code);\n setIsCopied(true);\n onCopy?.();\n setTimeout(() => setIsCopied(false), timeout);\n } catch (error) {\n onError?.(error as Error);\n }\n };\n\n const Icon = isCopied ? CheckIcon : CopyIcon;\n\n return (\n <button\n className={cn(\n 'absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all',\n 'hover:bg-secondary group-hover:opacity-100',\n className\n )}\n onClick={copyToClipboard}\n type=\"button\"\n {...props}\n >\n {children ?? <Icon size={14} />}\n </button>\n );\n};\n","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));\n","import { marked } from 'marked';\n\nexport const parseMarkdownIntoBlocks = (markdown: string): string[] => {\n const tokens = marked.lexer(markdown);\n return tokens.map((token) => token.raw);\n};\n","const linkImagePattern = /(!?\\[)([^\\]]*?)$/;\nconst boldPattern = /(\\*\\*)([^*]*?)$/;\nconst italicPattern = /(__)([^_]*?)$/;\nconst singleAsteriskPattern = /(\\*)([^*]*?)$/;\nconst singleUnderscorePattern = /(_)([^_]*?)$/;\nconst inlineCodePattern = /(`)([^`]*?)$/;\nconst strikethroughPattern = /(~~)([^~]*?)$/;\nconst inlineKatexPattern = /(\\$)([^$]*?)$/;\nconst blockKatexPattern = /(\\$\\$)([^$]*?)$/;\n\n// Handles incomplete links and images by removing them if not closed\nconst handleIncompleteLinksAndImages = (text: string): string => {\n const linkMatch = text.match(linkImagePattern);\n\n if (linkMatch) {\n const startIndex = text.lastIndexOf(linkMatch[1]);\n return text.substring(0, startIndex);\n }\n\n return text;\n};\n\n// Completes incomplete bold formatting (**)\nconst handleIncompleteBold = (text: string): string => {\n const boldMatch = text.match(boldPattern);\n\n if (boldMatch) {\n const asteriskPairs = (text.match(/\\*\\*/g) || []).length;\n if (asteriskPairs % 2 === 1) {\n return `${text}**`;\n }\n }\n\n return text;\n};\n\n// Completes incomplete italic formatting with double underscores (__)\nconst handleIncompleteDoubleUnderscoreItalic = (text: string): string => {\n const italicMatch = text.match(italicPattern);\n\n if (italicMatch) {\n const underscorePairs = (text.match(/__/g) || []).length;\n if (underscorePairs % 2 === 1) {\n return `${text}__`;\n }\n }\n\n return text;\n};\n\n// Counts single asterisks that are not part of double asterisks and not escaped\nconst countSingleAsterisks = (text: string): number => {\n return text.split('').reduce((acc, char, index) => {\n if (char === '*') {\n const prevChar = text[index - 1];\n const nextChar = text[index + 1];\n // Skip if escaped with backslash\n if (prevChar === '\\\\') {\n return acc;\n }\n if (prevChar !== '*' && nextChar !== '*') {\n return acc + 1;\n }\n }\n return acc;\n }, 0);\n};\n\n// Completes incomplete italic formatting with single asterisks (*)\nconst handleIncompleteSingleAsteriskItalic = (text: string): string => {\n const singleAsteriskMatch = text.match(singleAsteriskPattern);\n\n if (singleAsteriskMatch) {\n const singleAsterisks = countSingleAsterisks(text);\n if (singleAsterisks % 2 === 1) {\n return `${text}*`;\n }\n }\n\n return text;\n};\n\n// Counts single underscores that are not part of double underscores and not escaped\nconst countSingleUnderscores = (text: string): number => {\n return text.split('').reduce((acc, char, index) => {\n if (char === '_') {\n const prevChar = text[index - 1];\n const nextChar = text[index + 1];\n // Skip if escaped with backslash\n if (prevChar === '\\\\') {\n return acc;\n }\n if (prevChar !== '_' && nextChar !== '_') {\n return acc + 1;\n }\n }\n return acc;\n }, 0);\n};\n\n// Completes incomplete italic formatting with single underscores (_)\nconst handleIncompleteSingleUnderscoreItalic = (text: string): string => {\n const singleUnderscoreMatch = text.match(singleUnderscorePattern);\n\n if (singleUnderscoreMatch) {\n const singleUnderscores = countSingleUnderscores(text);\n if (singleUnderscores % 2 === 1) {\n return `${text}_`;\n }\n }\n\n return text;\n};\n\n// Checks if a backtick at position i is part of a triple backtick sequence\nconst isPartOfTripleBacktick = (text: string, i: number): boolean => {\n const isTripleStart = text.substring(i, i + 3) === '```';\n const isTripleMiddle = i > 0 && text.substring(i - 1, i + 2) === '```';\n const isTripleEnd = i > 1 && text.substring(i - 2, i + 1) === '```';\n\n return isTripleStart || isTripleMiddle || isTripleEnd;\n};\n\n// Counts single backticks that are not part of triple backticks\nconst countSingleBackticks = (text: string): number => {\n let count = 0;\n for (let i = 0; i < text.length; i++) {\n if (text[i] === '`' && !isPartOfTripleBacktick(text, i)) {\n count++;\n }\n }\n return count;\n};\n\n// Completes incomplete inline code formatting (`)\n// Avoids completing if inside an incomplete code block\nconst handleIncompleteInlineCode = (text: string): string => {\n // Check if we're inside a code block (complete or incomplete)\n const allTripleBackticks = (text.match(/```/g) || []).length;\n const insideIncompleteCodeBlock = allTripleBackticks % 2 === 1;\n \n // Don't modify text if we have complete code blocks (even pairs of ```)\n if (allTripleBackticks > 0 && allTripleBackticks % 2 === 0) {\n // We have complete code blocks, don't add any backticks\n return text;\n }\n\n const inlineCodeMatch = text.match(inlineCodePattern);\n\n if (inlineCodeMatch && !insideIncompleteCodeBlock) {\n const singleBacktickCount = countSingleBackticks(text);\n if (singleBacktickCount % 2 === 1) {\n return `${text}\\``;\n }\n }\n\n return text;\n};\n\n// Completes incomplete strikethrough formatting (~~)\nconst handleIncompleteStrikethrough = (text: string): string => {\n const strikethroughMatch = text.match(strikethroughPattern);\n\n if (strikethroughMatch) {\n const tildePairs = (text.match(/~~/g) || []).length;\n if (tildePairs % 2 === 1) {\n return `${text}~~`;\n }\n }\n\n return text;\n};\n\n// Counts single dollar signs that are not part of double dollar signs and not escaped\nconst countSingleDollarSigns = (text: string): number => {\n return text.split('').reduce((acc, char, index) => {\n if (char === '$') {\n const prevChar = text[index - 1];\n const nextChar = text[index + 1];\n // Skip if escaped with backslash\n if (prevChar === '\\\\') {\n return acc;\n }\n if (prevChar !== '$' && nextChar !== '$') {\n return acc + 1;\n }\n }\n return acc;\n }, 0);\n};\n\n// Completes incomplete block KaTeX formatting ($$)\nconst handleIncompleteBlockKatex = (text: string): string => {\n const blockKatexMatch = text.match(blockKatexPattern);\n\n if (blockKatexMatch) {\n const dollarPairs = (text.match(/\\$\\$/g) || []).length;\n if (dollarPairs % 2 === 1) {\n return `${text}$$`;\n }\n }\n\n return text;\n};\n\n// Completes incomplete inline KaTeX formatting ($)\nconst handleIncompleteInlineKatex = (text: string): string => {\n const inlineKatexMatch = text.match(inlineKatexPattern);\n\n if (inlineKatexMatch) {\n const singleDollars = countSingleDollarSigns(text);\n if (singleDollars % 2 === 1) {\n return `${text}$`;\n }\n }\n\n return text;\n};\n\n// Parses markdown text and removes incomplete tokens to prevent partial rendering\nexport const parseIncompleteMarkdown = (text: string): string => {\n if (!text || typeof text !== 'string') {\n return text;\n }\n\n let result = text;\n\n // Handle incomplete links and images first (removes content)\n result = handleIncompleteLinksAndImages(result);\n\n // Handle various formatting completions\n result = handleIncompleteBold(result);\n result = handleIncompleteDoubleUnderscoreItalic(result);\n result = handleIncompleteSingleAsteriskItalic(result);\n result = handleIncompleteSingleUnderscoreItalic(result);\n result = handleIncompleteInlineCode(result);\n result = handleIncompleteStrikethrough(result);\n \n // Handle KaTeX formatting (block first, then inline)\n result = handleIncompleteBlockKatex(result);\n result = handleIncompleteInlineKatex(result);\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,IAAAA,gBAAqC;AACrC,4BAA0B;AAC1B,0BAAwB;AACxB,wBAAsB;AACtB,yBAAuB;AACvB,uBAAO;AACP,mCAAsC;;;ACTtC,IAAAC,gBAA+B;;;ACE/B,0BAAoC;AACpC,mBAOO;AACP,mBAAiD;;;ACXjD,kBAAsC;AACtC,4BAAwB;AAEjB,IAAM,KAAK,IAAI,eAAyB,mCAAQ,kBAAK,MAAM,CAAC;;;ADwD7D;AApCN,IAAM,uBAAmB,4BAAoC;AAAA,EAC3D,MAAM;AACR,CAAC;AAED,eAAsB,cAAc,MAAc,UAA2B;AAC3E,SAAO,UAAM,yBAAW,MAAM;AAAA,IAC5B,MAAM;AAAA,IACN,OAAO;AAAA,EACT,CAAC;AACH;AAEO,IAAM,YAAY,CAAC;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAsB;AACpB,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAiB,EAAE;AAE3C,8BAAU,MAAM;AACd,QAAI,YAAY;AAEhB,kBAAc,MAAM,QAAQ,EAAE,KAAK,CAAC,WAAW;AAC7C,UAAI,WAAW;AACb,gBAAQ,MAAM;AAAA,MAChB;AAAA,IACF,CAAC;AAED,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,MAAM,QAAQ,CAAC;AAEnB,SACE,4CAAC,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,KAAK,GACvC,uDAAC,SAAI,WAAU,kBACb;AAAA;AAAA,MAAC;AAAA;AAAA,QACC,WAAW,GAAG,m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AAA,IACzC;AAEA,WAAO,6CAAC,oBAAkB,GAAG,OAAQ,yBAAc;AAAA,EACrD;AAAA,EACA,CAAC,WAAW,cAAc,UAAU,YAAY,UAAU;AAC5D;AAEO,IAAM,iBAAa;AAAA,EACxB,CAAC;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,yBAAyB,gCAAgC;AAAA,IACzD,YAAAC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,MAAuB;AAErB,UAAM,kBAAc,qBAAM;AAC1B,UAAM,aAAS;AAAA,MACb,MACE,wBAAwB,OAAO,aAAa,WAAW,WAAW,EAAE;AAAA,MACtE,CAAC,QAAQ;AAAA,IACX;AAEA,WACE,6CAAC,SAAI,WAAW,GAAG,aAAa,SAAS,GAAI,GAAG,OAC7C,iBAAO,IAAI,CAAC,OAAO,UAClB;AAAA,MAAC;AAAA;AAAA,QACC,sBAAsB,sDAAwB,CAAC,GAAG;AAAA,QAClD,qBAAqB,oDAAuB,CAAC,GAAG;AAAA,QAChD,YAAY;AAAA,UACV,GAAG;AAAA,UACH,GAAGA;AAAA,QACL;AAAA,QACA,SAAS;AAAA,QACT;AAAA,QAGA,eAAe,CAAC,oBAAAC,SAAa,GAAI,wCAAiB,CAAC,CAAE;AAAA,QACrD,eAAe,CAAC,kBAAAC,SAAW,mBAAAC,SAAY,GAAI,wCAAiB,CAAC,CAAE;AAAA,QAC/D;AAAA;AAAA,MAHK,GAAG,WAAW,UAAU,KAAK;AAAA,IAIpC,CACD,GACH;AAAA,EAEJ;AAAA,EACA,CAAC,WAAW,cAAc,UAAU,aAAa,UAAU;AAC7D;AACA,WAAW,cAAc;AAEzB,IAAO,gBAAQ;","names":["import_react","import_react","import_jsx_runtime","import_jsx_runtime","hardenReactMarkdownImport","ReactMarkdown","components","rehypeKatex","remarkGfm","remarkMath"]}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../index.tsx","../lib/components.tsx","../lib/code-block.tsx","../lib/utils.ts","../lib/parse-blocks.tsx","../lib/parse-incomplete-markdown.ts"],"sourcesContent":["'use client';\n\nimport type { ComponentProps } from 'react';\nimport { memo, useId, useMemo } from 'react';\nimport ReactMarkdown from 'react-markdown';\nimport rehypeKatex from 'rehype-katex';\nimport remarkGfm from 'remark-gfm';\nimport remarkMath from 'remark-math';\nimport 'katex/dist/katex.min.css';\nimport hardenReactMarkdownImport from 'harden-react-markdown';\nimport { components as defaultComponents } from './lib/components';\nimport { parseMarkdownIntoBlocks } from './lib/parse-blocks';\nimport { parseIncompleteMarkdown } from './lib/parse-incomplete-markdown';\nimport { cn } from './lib/utils';\n\n// Handle both ESM and CJS imports\nconst hardenReactMarkdown = (hardenReactMarkdownImport as any).default || hardenReactMarkdownImport;\n\n// Create a hardened version of ReactMarkdown\nconst HardenedMarkdown: ReturnType<typeof hardenReactMarkdown> =\n hardenReactMarkdown(ReactMarkdown);\n\nexport type StreamdownProps = ComponentProps<typeof HardenedMarkdown> & {\n parseIncompleteMarkdown?: boolean;\n className?: string;\n};\n\ntype BlockProps = ComponentProps<typeof HardenedMarkdown> & {\n content: string;\n shouldParseIncompleteMarkdown: boolean;\n};\n\nconst Block = memo(\n ({ content, shouldParseIncompleteMarkdown, ...props }: BlockProps) => {\n const parsedContent = useMemo(\n () =>\n typeof content === 'string' && shouldParseIncompleteMarkdown\n ? parseIncompleteMarkdown(content.trim())\n : content,\n [content, shouldParseIncompleteMarkdown]\n );\n\n return <HardenedMarkdown {...props}>{parsedContent}</HardenedMarkdown>;\n },\n (prevProps, nextProps) => prevProps.content === nextProps.content\n);\n\nexport const Streamdown = memo(\n ({\n children,\n allowedImagePrefixes,\n allowedLinkPrefixes,\n defaultOrigin,\n parseIncompleteMarkdown: shouldParseIncompleteMarkdown = true,\n components,\n rehypePlugins,\n remarkPlugins,\n className,\n ...props\n }: StreamdownProps) => {\n // Parse the children to remove incomplete markdown tokens if enabled\n const generatedId = useId();\n const blocks = useMemo(\n () =>\n parseMarkdownIntoBlocks(typeof children === 'string' ? children : ''),\n [children]\n );\n\n return (\n <div className={cn('space-y-4', className)} {...props}>\n {blocks.map((block, index) => (\n <Block\n allowedImagePrefixes={allowedImagePrefixes ?? ['*']}\n allowedLinkPrefixes={allowedLinkPrefixes ?? ['*']}\n components={{\n ...defaultComponents,\n ...components,\n }}\n content={block}\n defaultOrigin={defaultOrigin}\n // biome-ignore lint/suspicious/noArrayIndexKey: \"required\"\n key={`${generatedId}-block_${index}`}\n rehypePlugins={[rehypeKatex, ...(rehypePlugins ?? [])]}\n remarkPlugins={[remarkGfm, remarkMath, ...(remarkPlugins ?? [])]}\n shouldParseIncompleteMarkdown={shouldParseIncompleteMarkdown}\n />\n ))}\n </div>\n );\n },\n (prevProps, nextProps) => prevProps.children === nextProps.children\n);\nStreamdown.displayName = 'Streamdown';\n\nexport default Streamdown;\n","import { isValidElement } from 'react';\nimport type { Options } from 'react-markdown';\nimport type { BundledLanguage } from 'shiki';\nimport { CodeBlock, CodeBlockCopyButton } from './code-block';\nimport { cn } from './utils';\n\nexport const components: Options['components'] = {\n ol: ({ node, children, className, ...props }) => (\n <ol className={cn('ml-4 list-outside list-decimal', className)} {...props}>\n {children}\n </ol>\n ),\n li: ({ node, children, className, ...props }) => (\n <li className={cn('py-1', className)} {...props}>\n {children}\n </li>\n ),\n ul: ({ node, children, className, ...props }) => (\n <ul className={cn('ml-4 list-outside list-disc', className)} {...props}>\n {children}\n </ul>\n ),\n hr: ({ node, className, ...props }) => (\n <hr className={cn('my-6 border-border', className)} {...props} />\n ),\n strong: ({ node, children, className, ...props }) => (\n <span className={cn('font-semibold', className)} {...props}>\n {children}\n </span>\n ),\n a: ({ node, children, className, href, ...props }) => (\n <a\n className={cn('font-medium text-primary underline', className)}\n href={href}\n rel=\"noreferrer\"\n target=\"_blank\"\n {...props}\n >\n {children}\n </a>\n ),\n h1: ({ node, children, className, ...props }) => (\n <h1\n className={cn('mt-6 mb-2 font-semibold text-3xl', className)}\n {...props}\n >\n {children}\n </h1>\n ),\n h2: ({ node, children, className, ...props }) => (\n <h2\n className={cn('mt-6 mb-2 font-semibold text-2xl', className)}\n {...props}\n >\n {children}\n </h2>\n ),\n h3: ({ node, children, className, ...props }) => (\n <h3 className={cn('mt-6 mb-2 font-semibold text-xl', className)} {...props}>\n {children}\n </h3>\n ),\n h4: ({ node, children, className, ...props }) => (\n <h4 className={cn('mt-6 mb-2 font-semibold text-lg', className)} {...props}>\n {children}\n </h4>\n ),\n h5: ({ node, children, className, ...props }) => (\n <h5\n className={cn('mt-6 mb-2 font-semibold text-base', className)}\n {...props}\n >\n {children}\n </h5>\n ),\n h6: ({ node, children, className, ...props }) => (\n <h6 className={cn('mt-6 mb-2 font-semibold text-sm', className)} {...props}>\n {children}\n </h6>\n ),\n table: ({ node, children, className, ...props }) => (\n <div className=\"my-4 overflow-x-auto\">\n <table\n className={cn('w-full border-collapse border border-border', className)}\n {...props}\n >\n {children}\n </table>\n </div>\n ),\n thead: ({ node, children, className, ...props }) => (\n <thead className={cn('bg-muted/50', className)} {...props}>\n {children}\n </thead>\n ),\n tbody: ({ node, children, className, ...props }) => (\n <tbody className={cn('divide-y divide-border', className)} {...props}>\n {children}\n </tbody>\n ),\n tr: ({ node, children, className, ...props }) => (\n <tr className={cn('border-border border-b', className)} {...props}>\n {children}\n </tr>\n ),\n th: ({ node, children, className, ...props }) => (\n <th\n className={cn('px-4 py-2 text-left font-semibold text-sm', className)}\n {...props}\n >\n {children}\n </th>\n ),\n td: ({ node, children, className, ...props }) => (\n <td className={cn('px-4 py-2 text-sm', className)} {...props}>\n {children}\n </td>\n ),\n blockquote: ({ node, children, className, ...props }) => (\n <blockquote\n className={cn(\n 'my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic',\n className\n )}\n {...props}\n >\n {children}\n </blockquote>\n ),\n code: ({ node, className, ...props }) => {\n const inline = node?.position?.start.line === node?.position?.end.line;\n\n if (!inline) {\n return <code className={className} {...props} />;\n }\n\n return (\n <code\n className={cn(\n 'rounded bg-muted px-1.5 py-0.5 font-mono text-sm',\n className\n )}\n {...props}\n />\n );\n },\n pre: ({ node, className, children }) => {\n let language: BundledLanguage = 'javascript';\n\n if (typeof node?.properties?.className === 'string') {\n language = node.properties.className.replace(\n 'language-',\n ''\n ) as BundledLanguage;\n }\n\n // Extract code content from children safely\n let code = '';\n if (\n isValidElement(children) &&\n children.props &&\n typeof children.props === 'object' &&\n 'children' in children.props &&\n typeof children.props.children === 'string'\n ) {\n code = children.props.children;\n } else if (typeof children === 'string') {\n code = children;\n }\n\n return (\n <CodeBlock\n className={cn('my-4 h-auto rounded-lg border p-4', className)}\n code={code}\n language={language}\n >\n <CodeBlockCopyButton />\n </CodeBlock>\n );\n },\n sup: ({ node, children, className, ...props }) => (\n <sup className={cn('text-sm', className)} {...props}>\n {children}\n </sup>\n ),\n sub: ({ node, children, className, ...props }) => (\n <sub className={cn('text-sm', className)} {...props}>\n {children}\n </sub>\n ),\n};\n","'use client';\n\nimport { CheckIcon, CopyIcon } from 'lucide-react';\nimport {\n type ComponentProps,\n createContext,\n type HTMLAttributes,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { type BundledLanguage, codeToHtml } from 'shiki';\nimport { cn } from './utils';\n\ntype CodeBlockProps = HTMLAttributes<HTMLDivElement> & {\n code: string;\n language: BundledLanguage;\n};\n\ntype CodeBlockContextType = {\n code: string;\n};\n\nconst CodeBlockContext = createContext<CodeBlockContextType>({\n code: '',\n});\n\nexport async function highlightCode(code: string, language: BundledLanguage) {\n return await codeToHtml(code, {\n lang: language,\n theme: 'github-light',\n });\n}\n\nexport const CodeBlock = ({\n code,\n language,\n className,\n children,\n ...props\n}: CodeBlockProps) => {\n const [html, setHtml] = useState<string>('');\n\n useEffect(() => {\n let isMounted = true;\n\n highlightCode(code, language).then((result) => {\n if (isMounted) {\n setHtml(result);\n }\n });\n\n return () => {\n isMounted = false;\n };\n }, [code, language]);\n\n return (\n <CodeBlockContext.Provider value={{ code }}>\n <div className=\"group relative\">\n <div\n className={cn('overflow-x-auto', className)}\n // biome-ignore lint/security/noDangerouslySetInnerHtml: \"this is needed.\"\n dangerouslySetInnerHTML={{ __html: html }}\n {...props}\n />\n {children}\n </div>\n </CodeBlockContext.Provider>\n );\n};\n\nexport type CodeBlockCopyButtonProps = ComponentProps<'button'> & {\n onCopy?: () => void;\n onError?: (error: Error) => void;\n timeout?: number;\n};\n\nexport const CodeBlockCopyButton = ({\n onCopy,\n onError,\n timeout = 2000,\n children,\n className,\n ...props\n}: CodeBlockCopyButtonProps) => {\n const [isCopied, setIsCopied] = useState(false);\n const { code } = useContext(CodeBlockContext);\n\n const copyToClipboard = async () => {\n if (typeof window === 'undefined' || !navigator?.clipboard?.writeText) {\n onError?.(new Error('Clipboard API not available'));\n return;\n }\n\n try {\n await navigator.clipboard.writeText(code);\n setIsCopied(true);\n onCopy?.();\n setTimeout(() => setIsCopied(false), timeout);\n } catch (error) {\n onError?.(error as Error);\n }\n };\n\n const Icon = isCopied ? CheckIcon : CopyIcon;\n\n return (\n <button\n className={cn(\n 'absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all',\n 'hover:bg-secondary group-hover:opacity-100',\n className\n )}\n onClick={copyToClipboard}\n type=\"button\"\n {...props}\n >\n {children ?? <Icon size={14} />}\n </button>\n );\n};\n","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));\n","import { marked } from 'marked';\n\nexport const parseMarkdownIntoBlocks = (markdown: string): string[] => {\n const tokens = marked.lexer(markdown);\n return tokens.map((token) => token.raw);\n};\n","const linkImagePattern = /(!?\\[)([^\\]]*?)$/;\nconst boldPattern = /(\\*\\*)([^*]*?)$/;\nconst italicPattern = /(__)([^_]*?)$/;\nconst singleAsteriskPattern = /(\\*)([^*]*?)$/;\nconst singleUnderscorePattern = /(_)([^_]*?)$/;\nconst inlineCodePattern = /(`)([^`]*?)$/;\nconst strikethroughPattern = /(~~)([^~]*?)$/;\nconst inlineKatexPattern = /(\\$)([^$]*?)$/;\nconst blockKatexPattern = /(\\$\\$)([^$]*?)$/;\n\n// Handles incomplete links and images by removing them if not closed\nconst handleIncompleteLinksAndImages = (text: string): string => {\n const linkMatch = text.match(linkImagePattern);\n\n if (linkMatch) {\n const startIndex = text.lastIndexOf(linkMatch[1]);\n return text.substring(0, startIndex);\n }\n\n return text;\n};\n\n// Completes incomplete bold formatting (**)\nconst handleIncompleteBold = (text: string): string => {\n const boldMatch = text.match(boldPattern);\n\n if (boldMatch) {\n const asteriskPairs = (text.match(/\\*\\*/g) || []).length;\n if (asteriskPairs % 2 === 1) {\n return `${text}**`;\n }\n }\n\n return text;\n};\n\n// Completes incomplete italic formatting with double underscores (__)\nconst handleIncompleteDoubleUnderscoreItalic = (text: string): string => {\n const italicMatch = text.match(italicPattern);\n\n if (italicMatch) {\n const underscorePairs = (text.match(/__/g) || []).length;\n if (underscorePairs % 2 === 1) {\n return `${text}__`;\n }\n }\n\n return text;\n};\n\n// Counts single asterisks that are not part of double asterisks and not escaped\nconst countSingleAsterisks = (text: string): number => {\n return text.split('').reduce((acc, char, index) => {\n if (char === '*') {\n const prevChar = text[index - 1];\n const nextChar = text[index + 1];\n // Skip if escaped with backslash\n if (prevChar === '\\\\') {\n return acc;\n }\n if (prevChar !== '*' && nextChar !== '*') {\n return acc + 1;\n }\n }\n return acc;\n }, 0);\n};\n\n// Completes incomplete italic formatting with single asterisks (*)\nconst handleIncompleteSingleAsteriskItalic = (text: string): string => {\n const singleAsteriskMatch = text.match(singleAsteriskPattern);\n\n if (singleAsteriskMatch) {\n const singleAsterisks = countSingleAsterisks(text);\n if (singleAsterisks % 2 === 1) {\n return `${text}*`;\n }\n }\n\n return text;\n};\n\n// Counts single underscores that are not part of double underscores and not escaped\nconst countSingleUnderscores = (text: string): number => {\n return text.split('').reduce((acc, char, index) => {\n if (char === '_') {\n const prevChar = text[index - 1];\n const nextChar = text[index + 1];\n // Skip if escaped with backslash\n if (prevChar === '\\\\') {\n return acc;\n }\n if (prevChar !== '_' && nextChar !== '_') {\n return acc + 1;\n }\n }\n return acc;\n }, 0);\n};\n\n// Completes incomplete italic formatting with single underscores (_)\nconst handleIncompleteSingleUnderscoreItalic = (text: string): string => {\n const singleUnderscoreMatch = text.match(singleUnderscorePattern);\n\n if (singleUnderscoreMatch) {\n const singleUnderscores = countSingleUnderscores(text);\n if (singleUnderscores % 2 === 1) {\n return `${text}_`;\n }\n }\n\n return text;\n};\n\n// Checks if a backtick at position i is part of a triple backtick sequence\nconst isPartOfTripleBacktick = (text: string, i: number): boolean => {\n const isTripleStart = text.substring(i, i + 3) === '```';\n const isTripleMiddle = i > 0 && text.substring(i - 1, i + 2) === '```';\n const isTripleEnd = i > 1 && text.substring(i - 2, i + 1) === '```';\n\n return isTripleStart || isTripleMiddle || isTripleEnd;\n};\n\n// Counts single backticks that are not part of triple backticks\nconst countSingleBackticks = (text: string): number => {\n let count = 0;\n for (let i = 0; i < text.length; i++) {\n if (text[i] === '`' && !isPartOfTripleBacktick(text, i)) {\n count++;\n }\n }\n return count;\n};\n\n// Completes incomplete inline code formatting (`)\n// Avoids completing if inside an incomplete code block\nconst handleIncompleteInlineCode = (text: string): string => {\n // Check if we're inside a code block (complete or incomplete)\n const allTripleBackticks = (text.match(/```/g) || []).length;\n const insideIncompleteCodeBlock = allTripleBackticks % 2 === 1;\n \n // Don't modify text if we have complete code blocks (even pairs of ```)\n if (allTripleBackticks > 0 && allTripleBackticks % 2 === 0) {\n // We have complete code blocks, don't add any backticks\n return text;\n }\n\n const inlineCodeMatch = text.match(inlineCodePattern);\n\n if (inlineCodeMatch && !insideIncompleteCodeBlock) {\n const singleBacktickCount = countSingleBackticks(text);\n if (singleBacktickCount % 2 === 1) {\n return `${text}\\``;\n }\n }\n\n return text;\n};\n\n// Completes incomplete strikethrough formatting (~~)\nconst handleIncompleteStrikethrough = (text: string): string => {\n const strikethroughMatch = text.match(strikethroughPattern);\n\n if (strikethroughMatch) {\n const tildePairs = (text.match(/~~/g) || []).length;\n if (tildePairs % 2 === 1) {\n return `${text}~~`;\n }\n }\n\n return text;\n};\n\n// Counts single dollar signs that are not part of double dollar signs and not escaped\nconst countSingleDollarSigns = (text: string): number => {\n return text.split('').reduce((acc, char, index) => {\n if (char === '$') {\n const prevChar = text[index - 1];\n const nextChar = text[index + 1];\n // Skip if escaped with backslash\n if (prevChar === '\\\\') {\n return acc;\n }\n if (prevChar !== '$' && nextChar !== '$') {\n return acc + 1;\n }\n }\n return acc;\n }, 0);\n};\n\n// Completes incomplete block KaTeX formatting ($$)\nconst handleIncompleteBlockKatex = (text: string): string => {\n const blockKatexMatch = text.match(blockKatexPattern);\n\n if (blockKatexMatch) {\n const dollarPairs = (text.match(/\\$\\$/g) || []).length;\n if (dollarPairs % 2 === 1) {\n return `${text}$$`;\n }\n }\n\n return text;\n};\n\n// Completes incomplete inline KaTeX formatting ($)\nconst handleIncompleteInlineKatex = (text: string): string => {\n const inlineKatexMatch = text.match(inlineKatexPattern);\n\n if (inlineKatexMatch) {\n const singleDollars = countSingleDollarSigns(text);\n if (singleDollars % 2 === 1) {\n return `${text}$`;\n }\n }\n\n return text;\n};\n\n// Parses markdown text and removes incomplete tokens to prevent partial rendering\nexport const parseIncompleteMarkdown = (text: string): string => {\n if (!text || typeof text !== 'string') {\n return text;\n }\n\n let result = text;\n\n // Handle incomplete links and images first (removes content)\n result = handleIncompleteLinksAndImages(result);\n\n // Handle various formatting completions\n result = handleIncompleteBold(result);\n result = handleIncompleteDoubleUnderscoreItalic(result);\n result = handleIncompleteSingleAsteriskItalic(result);\n result = handleIncompleteSingleUnderscoreItalic(result);\n result = handleIncompleteInlineCode(result);\n result = handleIncompleteStrikethrough(result);\n \n // Handle KaTeX formatting (block first, then inline)\n result = handleIncompleteBlockKatex(result);\n result = handleIncompleteInlineKatex(result);\n\n return result;\n};\n"],"mappings":";;;AAGA,SAAS,MAAM,OAAO,eA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