streamdown 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1,2 @@
1
- "use strict";"use client";var q=Object.create;var f=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var J=(t,e)=>{for(var o in e)f(t,o,{get:e[o],enumerable:!0})},N=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!F.call(t,r)&&r!==o&&f(t,r,{get:()=>e[r],enumerable:!(n=V(e,r))||n.enumerable});return t};var g=(t,e,o)=>(o=t!=null?q(G(t)):{},N(e||!t||!t.__esModule?f(o,"default",{value:t,enumerable:!0}):o,t)),Q=t=>N(f({},"__esModule",{value:!0}),t);var Bt={};J(Bt,{Streamdown:()=>I,default:()=>Mt});module.exports=Q(Bt);var d=require("react"),O=g(require("react-markdown"),1),R=g(require("rehype-katex"),1),U=g(require("remark-gfm"),1),x=g(require("remark-math"),1),At=require("katex/dist/katex.min.css"),B=g(require("harden-react-markdown"),1);var S=require("react");var b=require("lucide-react"),c=require("react"),v=require("shiki");var $=require("clsx"),w=require("tailwind-merge"),s=(...t)=>(0,w.twMerge)((0,$.clsx)(t));var p=require("react/jsx-runtime"),P=(0,c.createContext)({code:""});async function W(t,e){return await(0,v.codeToHtml)(t,{lang:e,theme:"github-light"})}var T=({code:t,language:e,className:o,children:n,...r})=>{let[i,m]=(0,c.useState)("");return(0,c.useEffect)(()=>{let l=!0;return W(t,e).then(u=>{l&&m(u)}),()=>{l=!1}},[t,e]),(0,p.jsx)(P.Provider,{value:{code:t},children:(0,p.jsxs)("div",{className:"group relative",children:[(0,p.jsx)("div",{className:s("overflow-x-auto",o),dangerouslySetInnerHTML:{__html:i},...r}),n]})})},_=({onCopy:t,onError:e,timeout:o=2e3,children:n,className:r,...i})=>{let[m,l]=(0,c.useState)(!1),{code:u}=(0,c.useContext)(P),y=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){e==null||e(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(u),l(!0),t==null||t(),setTimeout(()=>l(!1),o)}catch(M){e==null||e(M)}},C=m?b.CheckIcon:b.CopyIcon;return(0,p.jsx)("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",r),onClick:y,type:"button",...i,children:n!=null?n:(0,p.jsx)(C,{size:14})})};var a=require("react/jsx-runtime"),A={ol:({node:t,children:e,className:o,...n})=>(0,a.jsx)("ol",{className:s("ml-4 list-outside list-decimal",o),...n,children:e}),li:({node:t,children:e,className:o,...n})=>(0,a.jsx)("li",{className:s("py-1",o),...n,children:e}),ul:({node:t,children:e,className:o,...n})=>(0,a.jsx)("ul",{className:s("ml-4 list-outside list-disc",o),...n,children:e}),hr:({node:t,className:e,...o})=>(0,a.jsx)("hr",{className:s("my-6 border-border",e),...o}),strong:({node:t,children:e,className:o,...n})=>(0,a.jsx)("span",{className:s("font-semibold",o),...n,children:e}),a:({node:t,children:e,className:o,href:n,...r})=>(0,a.jsx)("a",{className:s("font-medium text-primary underline",o),href:n,rel:"noreferrer",target:"_blank",...r,children:e}),h1:({node:t,children:e,className:o,...n})=>(0,a.jsx)("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",o),...n,children:e}),h2:({node:t,children:e,className:o,...n})=>(0,a.jsx)("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",o),...n,children:e}),h3:({node:t,children:e,className:o,...n})=>(0,a.jsx)("h3",{className:s("mt-6 mb-2 font-semibold text-xl",o),...n,children:e}),h4:({node:t,children:e,className:o,...n})=>(0,a.jsx)("h4",{className:s("mt-6 mb-2 font-semibold text-lg",o),...n,children:e}),h5:({node:t,children:e,className:o,...n})=>(0,a.jsx)("h5",{className:s("mt-6 mb-2 font-semibold text-base",o),...n,children:e}),h6:({node:t,children:e,className:o,...n})=>(0,a.jsx)("h6",{className:s("mt-6 mb-2 font-semibold text-sm",o),...n,children:e}),table:({node:t,children:e,className:o,...n})=>(0,a.jsx)("div",{className:"my-4 overflow-x-auto",children:(0,a.jsx)("table",{className:s("w-full border-collapse border border-border",o),...n,children:e})}),thead:({node:t,children:e,className:o,...n})=>(0,a.jsx)("thead",{className:s("bg-muted/50",o),...n,children:e}),tbody:({node:t,children:e,className:o,...n})=>(0,a.jsx)("tbody",{className:s("divide-y divide-border",o),...n,children:e}),tr:({node:t,children:e,className:o,...n})=>(0,a.jsx)("tr",{className:s("border-border border-b",o),...n,children:e}),th:({node:t,children:e,className:o,...n})=>(0,a.jsx)("th",{className:s("px-4 py-2 text-left font-semibold text-sm",o),...n,children:e}),td:({node:t,children:e,className:o,...n})=>(0,a.jsx)("td",{className:s("px-4 py-2 text-sm",o),...n,children:e}),blockquote:({node:t,children:e,className:o,...n})=>(0,a.jsx)("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",o),...n,children:e}),code:({node:t,className:e,...o})=>{var r,i;return((r=t==null?void 0:t.position)==null?void 0:r.start.line)===((i=t==null?void 0:t.position)==null?void 0:i.end.line)?(0,a.jsx)("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",e),...o}):(0,a.jsx)("code",{className:e,...o})},pre:({node:t,className:e,children:o})=>{var i;let n="javascript";typeof((i=t==null?void 0:t.properties)==null?void 0:i.className)=="string"&&(n=t.properties.className.replace("language-",""));let r="";return(0,S.isValidElement)(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?r=o.props.children:typeof o=="string"&&(r=o),(0,a.jsx)(T,{className:s("my-4 h-auto rounded-lg border p-4",e),code:r,language:n,children:(0,a.jsx)(_,{})})},sup:({node:t,children:e,className:o,...n})=>(0,a.jsx)("sup",{className:s("text-sm",o),...n,children:e}),sub:({node:t,children:e,className:o,...n})=>(0,a.jsx)("sub",{className:s("text-sm",o),...n,children:e})};var H=require("marked"),K=t=>H.marked.lexer(t).map(o=>o.raw);var X=/(!?\[)([^\]]*?)$/,Y=/(\*\*)([^*]*?)$/,Z=/(__)([^_]*?)$/,j=/(\*)([^*]*?)$/,E=/(_)([^_]*?)$/,tt=/(`)([^`]*?)$/,et=/(~~)([^~]*?)$/,ot=/(\$)([^$]*?)$/,nt=/(\$\$)([^$]*?)$/,rt=t=>{let e=t.match(X);if(e){let o=t.lastIndexOf(e[1]);return t.substring(0,o)}return t},st=t=>t.match(Y)&&(t.match(/\*\*/g)||[]).length%2===1?`${t}**`:t,at=t=>t.match(Z)&&(t.match(/__/g)||[]).length%2===1?`${t}__`:t,it=t=>t.split("").reduce((e,o,n)=>{if(o==="*"){let r=t[n-1],i=t[n+1];if(r==="\\")return e;if(r!=="*"&&i!=="*")return e+1}return e},0),lt=t=>t.match(j)&&it(t)%2===1?`${t}*`:t,ct=t=>t.split("").reduce((e,o,n)=>{if(o==="_"){let r=t[n-1],i=t[n+1];if(r==="\\")return e;if(r!=="_"&&i!=="_")return e+1}return e},0),dt=t=>t.match(E)&&ct(t)%2===1?`${t}_`:t,mt=(t,e)=>{let o=t.substring(e,e+3)==="```",n=e>0&&t.substring(e-1,e+2)==="```",r=e>1&&t.substring(e-2,e+1)==="```";return o||n||r},pt=t=>{let e=0;for(let o=0;o<t.length;o++)t[o]==="`"&&!mt(t,o)&&e++;return e},ut=t=>{let e=(t.match(/```/g)||[]).length,o=e%2===1;return e>0&&e%2===0?t:t.match(tt)&&!o&&pt(t)%2===1?`${t}\``:t},gt=t=>t.match(et)&&(t.match(/~~/g)||[]).length%2===1?`${t}~~`:t,ht=t=>t.split("").reduce((e,o,n)=>{if(o==="$"){let r=t[n-1],i=t[n+1];if(r==="\\")return e;if(r!=="$"&&i!=="$")return e+1}return e},0),ft=t=>t.match(nt)&&(t.match(/\$\$/g)||[]).length%2===1?`${t}$$`:t,bt=t=>t.match(ot)&&ht(t)%2===1?`${t}$`:t,L=t=>{if(!t||typeof t!="string")return t;let e=t;return e=rt(e),e=st(e),e=at(e),e=lt(e),e=dt(e),e=ut(e),e=gt(e),e=ft(e),e=bt(e),e};var k=require("react/jsx-runtime"),kt=B.default.default||B.default,yt=kt(O.default),Ct=(0,d.memo)(({content:t,shouldParseIncompleteMarkdown:e,...o})=>{let n=(0,d.useMemo)(()=>typeof t=="string"&&e?L(t.trim()):t,[t,e]);return(0,k.jsx)(yt,{...o,children:n})},(t,e)=>t.content===e.content),I=(0,d.memo)(({children:t,allowedImagePrefixes:e,allowedLinkPrefixes:o,defaultOrigin:n,parseIncompleteMarkdown:r=!0,components:i,rehypePlugins:m,remarkPlugins:l,className:u,...y})=>{let C=(0,d.useId)(),h=(0,d.useMemo)(()=>K(typeof t=="string"?t:""),[t]);return(0,k.jsx)("div",{className:s("space-y-4",u),...y,children:h.map((M,D)=>(0,k.jsx)(Ct,{allowedImagePrefixes:e!=null?e:["*"],allowedLinkPrefixes:o!=null?o:["*"],components:{...A,...i},content:M,defaultOrigin:n,rehypePlugins:[R.default,...m!=null?m:[]],remarkPlugins:[U.default,x.default,...l!=null?l:[]],shouldParseIncompleteMarkdown:r},`${C}-block_${D}`))})},(t,e)=>t.children===e.children);I.displayName="Streamdown";var Mt=I;0&&(module.exports={Streamdown});
1
+ "use strict";"use client";var V=Object.create;var f=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var G=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var J=(t,e)=>{for(var n in e)f(t,n,{get:e[n],enumerable:!0})},$=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of z(e))!F.call(t,r)&&r!==n&&f(t,r,{get:()=>e[r],enumerable:!(o=W(e,r))||o.enumerable});return t};var g=(t,e,n)=>(n=t!=null?V(G(t)):{},$(e||!t||!t.__esModule?f(n,"default",{value:t,enumerable:!0}):n,t)),Q=t=>$(f({},"__esModule",{value:!0}),t);var Nt={};J(Nt,{Streamdown:()=>B,default:()=>$t});module.exports=Q(Nt);var d=require("react"),O=g(require("react-markdown"),1),R=g(require("rehype-katex"),1),U=g(require("remark-gfm"),1),D=g(require("remark-math"),1),Lt=require("katex/dist/katex.min.css"),I=g(require("harden-react-markdown"),1);var S=require("react");var b=require("lucide-react"),l=require("react"),v=require("shiki");var N=require("clsx"),w=require("tailwind-merge"),s=(...t)=>(0,w.twMerge)((0,N.clsx)(t));var p=require("react/jsx-runtime"),P=(0,l.createContext)({code:""});async function X(t,e){return await(0,v.codeToHtml)(t,{lang:e,theme:"github-light"})}var T=({code:t,language:e,className:n,children:o,...r})=>{let[i,m]=(0,l.useState)("");return(0,l.useEffect)(()=>{let c=!0;return X(t,e).then(u=>{c&&m(u)}),()=>{c=!1}},[t,e]),(0,p.jsx)(P.Provider,{value:{code:t},children:(0,p.jsxs)("div",{className:"group relative",children:[(0,p.jsx)("div",{className:s("overflow-x-auto",n),dangerouslySetInnerHTML:{__html:i},...r}),o]})})},_=({onCopy:t,onError:e,timeout:n=2e3,children:o,className:r,...i})=>{let[m,c]=(0,l.useState)(!1),{code:u}=(0,l.useContext)(P),y=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){e==null||e(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(u),c(!0),t==null||t(),setTimeout(()=>c(!1),n)}catch(M){e==null||e(M)}},C=m?b.CheckIcon:b.CopyIcon;return(0,p.jsx)("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",r),onClick:y,type:"button",...i,children:o!=null?o:(0,p.jsx)(C,{size:14})})};var a=require("react/jsx-runtime"),A={ol:({node:t,children:e,className:n,...o})=>(0,a.jsx)("ol",{className:s("ml-4 list-outside list-decimal",n),...o,children:e}),li:({node:t,children:e,className:n,...o})=>(0,a.jsx)("li",{className:s("py-1",n),...o,children:e}),ul:({node:t,children:e,className:n,...o})=>(0,a.jsx)("ul",{className:s("ml-4 list-outside list-disc",n),...o,children:e}),hr:({node:t,className:e,...n})=>(0,a.jsx)("hr",{className:s("my-6 border-border",e),...n}),strong:({node:t,children:e,className:n,...o})=>(0,a.jsx)("span",{className:s("font-semibold",n),...o,children:e}),a:({node:t,children:e,className:n,href:o,...r})=>(0,a.jsx)("a",{className:s("font-medium text-primary underline",n),href:o,rel:"noreferrer",target:"_blank",...r,children:e}),h1:({node:t,children:e,className:n,...o})=>(0,a.jsx)("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",n),...o,children:e}),h2:({node:t,children:e,className:n,...o})=>(0,a.jsx)("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",n),...o,children:e}),h3:({node:t,children:e,className:n,...o})=>(0,a.jsx)("h3",{className:s("mt-6 mb-2 font-semibold text-xl",n),...o,children:e}),h4:({node:t,children:e,className:n,...o})=>(0,a.jsx)("h4",{className:s("mt-6 mb-2 font-semibold text-lg",n),...o,children:e}),h5:({node:t,children:e,className:n,...o})=>(0,a.jsx)("h5",{className:s("mt-6 mb-2 font-semibold text-base",n),...o,children:e}),h6:({node:t,children:e,className:n,...o})=>(0,a.jsx)("h6",{className:s("mt-6 mb-2 font-semibold text-sm",n),...o,children:e}),table:({node:t,children:e,className:n,...o})=>(0,a.jsx)("div",{className:"my-4 overflow-x-auto",children:(0,a.jsx)("table",{className:s("w-full border-collapse border border-border",n),...o,children:e})}),thead:({node:t,children:e,className:n,...o})=>(0,a.jsx)("thead",{className:s("bg-muted/50",n),...o,children:e}),tbody:({node:t,children:e,className:n,...o})=>(0,a.jsx)("tbody",{className:s("divide-y divide-border",n),...o,children:e}),tr:({node:t,children:e,className:n,...o})=>(0,a.jsx)("tr",{className:s("border-border border-b",n),...o,children:e}),th:({node:t,children:e,className:n,...o})=>(0,a.jsx)("th",{className:s("px-4 py-2 text-left font-semibold text-sm",n),...o,children:e}),td:({node:t,children:e,className:n,...o})=>(0,a.jsx)("td",{className:s("px-4 py-2 text-sm",n),...o,children:e}),blockquote:({node:t,children:e,className:n,...o})=>(0,a.jsx)("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",n),...o,children:e}),code:({node:t,className:e,...n})=>{var r,i;return((r=t==null?void 0:t.position)==null?void 0:r.start.line)===((i=t==null?void 0:t.position)==null?void 0:i.end.line)?(0,a.jsx)("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",e),...n}):(0,a.jsx)("code",{className:e,...n})},pre:({node:t,className:e,children:n})=>{var i;let o="javascript";typeof((i=t==null?void 0:t.properties)==null?void 0:i.className)=="string"&&(o=t.properties.className.replace("language-",""));let r="";return(0,S.isValidElement)(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?r=n.props.children:typeof n=="string"&&(r=n),(0,a.jsx)(T,{className:s("my-4 h-auto rounded-lg border p-4",e),code:r,language:o,children:(0,a.jsx)(_,{})})},sup:({node:t,children:e,className:n,...o})=>(0,a.jsx)("sup",{className:s("text-sm",n),...o,children:e}),sub:({node:t,children:e,className:n,...o})=>(0,a.jsx)("sub",{className:s("text-sm",n),...o,children:e})};var H=require("marked"),K=t=>H.marked.lexer(t).map(n=>n.raw);var Y=/(!?\[)([^\]]*?)$/,Z=/(\*\*)([^*]*?)$/,j=/(__)([^_]*?)$/,E=/(\*\*\*)([^*]*?)$/,x=/(\*)([^*]*?)$/,tt=/(_)([^_]*?)$/,et=/(`)([^`]*?)$/,nt=/(~~)([^~]*?)$/,ot=/(\$)([^$]*?)$/,rt=/(\$\$)([^$]*?)$/,st=t=>{let e=t.match(Y);if(e){let n=t.lastIndexOf(e[1]);return t.substring(0,n)}return t},at=t=>t.match(Z)&&(t.match(/\*\*/g)||[]).length%2===1?`${t}**`:t,it=t=>t.match(j)&&(t.match(/__/g)||[]).length%2===1?`${t}__`:t,ct=t=>t.split("").reduce((e,n,o)=>{if(n==="*"){let r=t[o-1],i=t[o+1];if(r==="\\")return e;if(r!=="*"&&i!=="*")return e+1}return e},0),lt=t=>t.match(x)&&ct(t)%2===1?`${t}*`:t,dt=t=>t.split("").reduce((e,n,o)=>{if(n==="_"){let r=t[o-1],i=t[o+1];if(r==="\\")return e;if(r!=="_"&&i!=="_")return e+1}return e},0),mt=t=>t.match(tt)&&dt(t)%2===1?`${t}_`:t,pt=(t,e)=>{let n=t.substring(e,e+3)==="```",o=e>0&&t.substring(e-1,e+2)==="```",r=e>1&&t.substring(e-2,e+1)==="```";return n||o||r},ut=t=>{let e=0;for(let n=0;n<t.length;n++)t[n]==="`"&&!pt(t,n)&&e++;return e},gt=t=>{if(t.match(/^```[^`\n]*```?$/))return t.endsWith("``")&&!t.endsWith("```")?`${t}\``:t;let n=(t.match(/```/g)||[]).length,o=n%2===1;return n>0&&n%2===0&&t.includes(`
2
+ `)?t:t.match(et)&&!o&&ut(t)%2===1?`${t}\``:t},ht=t=>t.match(nt)&&(t.match(/~~/g)||[]).length%2===1?`${t}~~`:t,ft=t=>t.split("").reduce((e,n,o)=>{if(n==="$"){let r=t[o-1],i=t[o+1];if(r==="\\")return e;if(r!=="$"&&i!=="$")return e+1}return e},0),bt=t=>t.match(rt)&&(t.match(/\$\$/g)||[]).length%2===1?`${t}$$`:t,kt=t=>t.match(ot)&&ft(t)%2===1?`${t}$`:t,yt=t=>{let e=0,n=t.match(/\*+/g)||[];for(let o of n){let r=o.length;r>=3&&(e+=Math.floor(r/3))}return e},Ct=t=>/^\*{4,}$/.test(t)?t:t.match(E)&&yt(t)%2===1?`${t}***`:t,L=t=>{if(!t||typeof t!="string")return t;let e=t;return e=st(e),e=Ct(e),e=at(e),e=it(e),e=lt(e),e=mt(e),e=gt(e),e=ht(e),e=bt(e),e=kt(e),e};var k=require("react/jsx-runtime"),Mt=I.default.default||I.default,It=Mt(O.default),Bt=(0,d.memo)(({content:t,shouldParseIncompleteMarkdown:e,...n})=>{let o=(0,d.useMemo)(()=>typeof t=="string"&&e?L(t.trim()):t,[t,e]);return(0,k.jsx)(It,{...n,children:o})},(t,e)=>t.content===e.content),B=(0,d.memo)(({children:t,allowedImagePrefixes:e,allowedLinkPrefixes:n,defaultOrigin:o,parseIncompleteMarkdown:r=!0,components:i,rehypePlugins:m,remarkPlugins:c,className:u,...y})=>{let C=(0,d.useId)(),h=(0,d.useMemo)(()=>K(typeof t=="string"?t:""),[t]);return(0,k.jsx)("div",{className:s("space-y-4",u),...y,children:h.map((M,q)=>(0,k.jsx)(Bt,{allowedImagePrefixes:e!=null?e:["*"],allowedLinkPrefixes:n!=null?n:["*"],components:{...A,...i},content:M,defaultOrigin:o,rehypePlugins:[R.default,...m!=null?m:[]],remarkPlugins:[U.default,D.default,...c!=null?c:[]],shouldParseIncompleteMarkdown:r},`${C}-block_${q}`))})},(t,e)=>t.children===e.children);B.displayName="Streamdown";var $t=B;0&&(module.exports={Streamdown});
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- "use client";import{memo as $,useId as dt,useMemo as w}from"react";import mt from"react-markdown";import pt from"rehype-katex";import ut from"remark-gfm";import gt from"remark-math";import"katex/dist/katex.min.css";import N from"harden-react-markdown";import{isValidElement as x}from"react";import{CheckIcon as S,CopyIcon as A}from"lucide-react";import{createContext as H,useContext as K,useEffect as L,useState as b}from"react";import{codeToHtml as O}from"shiki";import{clsx as T}from"clsx";import{twMerge as _}from"tailwind-merge";var r=(...t)=>_(T(t));import{jsx as p,jsxs as U}from"react/jsx-runtime";var k=H({code:""});async function R(t,e){return await O(t,{lang:e,theme:"github-light"})}var y=({code:t,language:e,className:o,children:n,...s})=>{let[i,c]=b("");return L(()=>{let l=!0;return R(t,e).then(d=>{l&&c(d)}),()=>{l=!1}},[t,e]),p(k.Provider,{value:{code:t},children:U("div",{className:"group relative",children:[p("div",{className:r("overflow-x-auto",o),dangerouslySetInnerHTML:{__html:i},...s}),n]})})},C=({onCopy:t,onError:e,timeout:o=2e3,children:n,className:s,...i})=>{let[c,l]=b(!1),{code:d}=K(k),u=async()=>{var m;if(typeof window=="undefined"||!((m=navigator==null?void 0:navigator.clipboard)!=null&&m.writeText)){e==null||e(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(d),l(!0),t==null||t(),setTimeout(()=>l(!1),o)}catch(h){e==null||e(h)}},g=c?S:A;return p("button",{className:r("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",s),onClick:u,type:"button",...i,children:n!=null?n:p(g,{size:14})})};import{jsx as a}from"react/jsx-runtime";var M={ol:({node:t,children:e,className:o,...n})=>a("ol",{className:r("ml-4 list-outside list-decimal",o),...n,children:e}),li:({node:t,children:e,className:o,...n})=>a("li",{className:r("py-1",o),...n,children:e}),ul:({node:t,children:e,className:o,...n})=>a("ul",{className:r("ml-4 list-outside list-disc",o),...n,children:e}),hr:({node:t,className:e,...o})=>a("hr",{className:r("my-6 border-border",e),...o}),strong:({node:t,children:e,className:o,...n})=>a("span",{className:r("font-semibold",o),...n,children:e}),a:({node:t,children:e,className:o,href:n,...s})=>a("a",{className:r("font-medium text-primary underline",o),href:n,rel:"noreferrer",target:"_blank",...s,children:e}),h1:({node:t,children:e,className:o,...n})=>a("h1",{className:r("mt-6 mb-2 font-semibold text-3xl",o),...n,children:e}),h2:({node:t,children:e,className:o,...n})=>a("h2",{className:r("mt-6 mb-2 font-semibold text-2xl",o),...n,children:e}),h3:({node:t,children:e,className:o,...n})=>a("h3",{className:r("mt-6 mb-2 font-semibold text-xl",o),...n,children:e}),h4:({node:t,children:e,className:o,...n})=>a("h4",{className:r("mt-6 mb-2 font-semibold text-lg",o),...n,children:e}),h5:({node:t,children:e,className:o,...n})=>a("h5",{className:r("mt-6 mb-2 font-semibold text-base",o),...n,children:e}),h6:({node:t,children:e,className:o,...n})=>a("h6",{className:r("mt-6 mb-2 font-semibold text-sm",o),...n,children:e}),table:({node:t,children:e,className:o,...n})=>a("div",{className:"my-4 overflow-x-auto",children:a("table",{className:r("w-full border-collapse border border-border",o),...n,children:e})}),thead:({node:t,children:e,className:o,...n})=>a("thead",{className:r("bg-muted/50",o),...n,children:e}),tbody:({node:t,children:e,className:o,...n})=>a("tbody",{className:r("divide-y divide-border",o),...n,children:e}),tr:({node:t,children:e,className:o,...n})=>a("tr",{className:r("border-border border-b",o),...n,children:e}),th:({node:t,children:e,className:o,...n})=>a("th",{className:r("px-4 py-2 text-left font-semibold text-sm",o),...n,children:e}),td:({node:t,children:e,className:o,...n})=>a("td",{className:r("px-4 py-2 text-sm",o),...n,children:e}),blockquote:({node:t,children:e,className:o,...n})=>a("blockquote",{className:r("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",o),...n,children:e}),code:({node:t,className:e,...o})=>{var s,i;return((s=t==null?void 0:t.position)==null?void 0:s.start.line)===((i=t==null?void 0:t.position)==null?void 0:i.end.line)?a("code",{className:r("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",e),...o}):a("code",{className:e,...o})},pre:({node:t,className:e,children:o})=>{var i;let n="javascript";typeof((i=t==null?void 0:t.properties)==null?void 0:i.className)=="string"&&(n=t.properties.className.replace("language-",""));let s="";return x(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?s=o.props.children:typeof o=="string"&&(s=o),a(y,{className:r("my-4 h-auto rounded-lg border p-4",e),code:s,language:n,children:a(C,{})})},sup:({node:t,children:e,className:o,...n})=>a("sup",{className:r("text-sm",o),...n,children:e}),sub:({node:t,children:e,className:o,...n})=>a("sub",{className:r("text-sm",o),...n,children:e})};import{marked as D}from"marked";var B=t=>D.lexer(t).map(o=>o.raw);var q=/(!?\[)([^\]]*?)$/,V=/(\*\*)([^*]*?)$/,z=/(__)([^_]*?)$/,G=/(\*)([^*]*?)$/,F=/(_)([^_]*?)$/,J=/(`)([^`]*?)$/,Q=/(~~)([^~]*?)$/,W=/(\$)([^$]*?)$/,X=/(\$\$)([^$]*?)$/,Y=t=>{let e=t.match(q);if(e){let o=t.lastIndexOf(e[1]);return t.substring(0,o)}return t},Z=t=>t.match(V)&&(t.match(/\*\*/g)||[]).length%2===1?`${t}**`:t,j=t=>t.match(z)&&(t.match(/__/g)||[]).length%2===1?`${t}__`:t,E=t=>t.split("").reduce((e,o,n)=>{if(o==="*"){let s=t[n-1],i=t[n+1];if(s==="\\")return e;if(s!=="*"&&i!=="*")return e+1}return e},0),tt=t=>t.match(G)&&E(t)%2===1?`${t}*`:t,et=t=>t.split("").reduce((e,o,n)=>{if(o==="_"){let s=t[n-1],i=t[n+1];if(s==="\\")return e;if(s!=="_"&&i!=="_")return e+1}return e},0),ot=t=>t.match(F)&&et(t)%2===1?`${t}_`:t,nt=(t,e)=>{let o=t.substring(e,e+3)==="```",n=e>0&&t.substring(e-1,e+2)==="```",s=e>1&&t.substring(e-2,e+1)==="```";return o||n||s},rt=t=>{let e=0;for(let o=0;o<t.length;o++)t[o]==="`"&&!nt(t,o)&&e++;return e},st=t=>{let e=(t.match(/```/g)||[]).length,o=e%2===1;return e>0&&e%2===0?t:t.match(J)&&!o&&rt(t)%2===1?`${t}\``:t},at=t=>t.match(Q)&&(t.match(/~~/g)||[]).length%2===1?`${t}~~`:t,it=t=>t.split("").reduce((e,o,n)=>{if(o==="$"){let s=t[n-1],i=t[n+1];if(s==="\\")return e;if(s!=="$"&&i!=="$")return e+1}return e},0),lt=t=>t.match(X)&&(t.match(/\$\$/g)||[]).length%2===1?`${t}$$`:t,ct=t=>t.match(W)&&it(t)%2===1?`${t}$`:t,I=t=>{if(!t||typeof t!="string")return t;let e=t;return e=Y(e),e=Z(e),e=j(e),e=tt(e),e=ot(e),e=st(e),e=at(e),e=lt(e),e=ct(e),e};import{jsx as f}from"react/jsx-runtime";var ht=N.default||N,ft=ht(mt),bt=$(({content:t,shouldParseIncompleteMarkdown:e,...o})=>{let n=w(()=>typeof t=="string"&&e?I(t.trim()):t,[t,e]);return f(ft,{...o,children:n})},(t,e)=>t.content===e.content),v=$(({children:t,allowedImagePrefixes:e,allowedLinkPrefixes:o,defaultOrigin:n,parseIncompleteMarkdown:s=!0,components:i,rehypePlugins:c,remarkPlugins:l,className:d,...u})=>{let g=dt(),m=w(()=>B(typeof t=="string"?t:""),[t]);return f("div",{className:r("space-y-4",d),...u,children:m.map((h,P)=>f(bt,{allowedImagePrefixes:e!=null?e:["*"],allowedLinkPrefixes:o!=null?o:["*"],components:{...M,...i},content:h,defaultOrigin:n,rehypePlugins:[pt,...c!=null?c:[]],remarkPlugins:[ut,gt,...l!=null?l:[]],shouldParseIncompleteMarkdown:s},`${g}-block_${P}`))})},(t,e)=>t.children===e.children);v.displayName="Streamdown";var Jt=v;export{v as Streamdown,Jt as default};
1
+ "use client";import{memo as N,useId as ut,useMemo as w}from"react";import gt from"react-markdown";import ht from"rehype-katex";import ft from"remark-gfm";import bt from"remark-math";import"katex/dist/katex.min.css";import $ from"harden-react-markdown";import{isValidElement as D}from"react";import{CheckIcon as S,CopyIcon as A}from"lucide-react";import{createContext as H,useContext as K,useEffect as L,useState as b}from"react";import{codeToHtml as O}from"shiki";import{clsx as T}from"clsx";import{twMerge as _}from"tailwind-merge";var s=(...t)=>_(T(t));import{jsx as p,jsxs as U}from"react/jsx-runtime";var k=H({code:""});async function R(t,e){return await O(t,{lang:e,theme:"github-light"})}var y=({code:t,language:e,className:n,children:o,...r})=>{let[i,l]=b("");return L(()=>{let c=!0;return R(t,e).then(d=>{c&&l(d)}),()=>{c=!1}},[t,e]),p(k.Provider,{value:{code:t},children:U("div",{className:"group relative",children:[p("div",{className:s("overflow-x-auto",n),dangerouslySetInnerHTML:{__html:i},...r}),o]})})},C=({onCopy:t,onError:e,timeout:n=2e3,children:o,className:r,...i})=>{let[l,c]=b(!1),{code:d}=K(k),u=async()=>{var m;if(typeof window=="undefined"||!((m=navigator==null?void 0:navigator.clipboard)!=null&&m.writeText)){e==null||e(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(d),c(!0),t==null||t(),setTimeout(()=>c(!1),n)}catch(h){e==null||e(h)}},g=l?S:A;return p("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",r),onClick:u,type:"button",...i,children:o!=null?o:p(g,{size:14})})};import{jsx as a}from"react/jsx-runtime";var M={ol:({node:t,children:e,className:n,...o})=>a("ol",{className:s("ml-4 list-outside list-decimal",n),...o,children:e}),li:({node:t,children:e,className:n,...o})=>a("li",{className:s("py-1",n),...o,children:e}),ul:({node:t,children:e,className:n,...o})=>a("ul",{className:s("ml-4 list-outside list-disc",n),...o,children:e}),hr:({node:t,className:e,...n})=>a("hr",{className:s("my-6 border-border",e),...n}),strong:({node:t,children:e,className:n,...o})=>a("span",{className:s("font-semibold",n),...o,children:e}),a:({node:t,children:e,className:n,href:o,...r})=>a("a",{className:s("font-medium text-primary underline",n),href:o,rel:"noreferrer",target:"_blank",...r,children:e}),h1:({node:t,children:e,className:n,...o})=>a("h1",{className:s("mt-6 mb-2 font-semibold text-3xl",n),...o,children:e}),h2:({node:t,children:e,className:n,...o})=>a("h2",{className:s("mt-6 mb-2 font-semibold text-2xl",n),...o,children:e}),h3:({node:t,children:e,className:n,...o})=>a("h3",{className:s("mt-6 mb-2 font-semibold text-xl",n),...o,children:e}),h4:({node:t,children:e,className:n,...o})=>a("h4",{className:s("mt-6 mb-2 font-semibold text-lg",n),...o,children:e}),h5:({node:t,children:e,className:n,...o})=>a("h5",{className:s("mt-6 mb-2 font-semibold text-base",n),...o,children:e}),h6:({node:t,children:e,className:n,...o})=>a("h6",{className:s("mt-6 mb-2 font-semibold text-sm",n),...o,children:e}),table:({node:t,children:e,className:n,...o})=>a("div",{className:"my-4 overflow-x-auto",children:a("table",{className:s("w-full border-collapse border border-border",n),...o,children:e})}),thead:({node:t,children:e,className:n,...o})=>a("thead",{className:s("bg-muted/50",n),...o,children:e}),tbody:({node:t,children:e,className:n,...o})=>a("tbody",{className:s("divide-y divide-border",n),...o,children:e}),tr:({node:t,children:e,className:n,...o})=>a("tr",{className:s("border-border border-b",n),...o,children:e}),th:({node:t,children:e,className:n,...o})=>a("th",{className:s("px-4 py-2 text-left font-semibold text-sm",n),...o,children:e}),td:({node:t,children:e,className:n,...o})=>a("td",{className:s("px-4 py-2 text-sm",n),...o,children:e}),blockquote:({node:t,children:e,className:n,...o})=>a("blockquote",{className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",n),...o,children:e}),code:({node:t,className:e,...n})=>{var r,i;return((r=t==null?void 0:t.position)==null?void 0:r.start.line)===((i=t==null?void 0:t.position)==null?void 0:i.end.line)?a("code",{className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",e),...n}):a("code",{className:e,...n})},pre:({node:t,className:e,children:n})=>{var i;let o="javascript";typeof((i=t==null?void 0:t.properties)==null?void 0:i.className)=="string"&&(o=t.properties.className.replace("language-",""));let r="";return D(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?r=n.props.children:typeof n=="string"&&(r=n),a(y,{className:s("my-4 h-auto rounded-lg border p-4",e),code:r,language:o,children:a(C,{})})},sup:({node:t,children:e,className:n,...o})=>a("sup",{className:s("text-sm",n),...o,children:e}),sub:({node:t,children:e,className:n,...o})=>a("sub",{className:s("text-sm",n),...o,children:e})};import{marked as q}from"marked";var I=t=>q.lexer(t).map(n=>n.raw);var V=/(!?\[)([^\]]*?)$/,W=/(\*\*)([^*]*?)$/,z=/(__)([^_]*?)$/,G=/(\*\*\*)([^*]*?)$/,F=/(\*)([^*]*?)$/,J=/(_)([^_]*?)$/,Q=/(`)([^`]*?)$/,X=/(~~)([^~]*?)$/,Y=/(\$)([^$]*?)$/,Z=/(\$\$)([^$]*?)$/,j=t=>{let e=t.match(V);if(e){let n=t.lastIndexOf(e[1]);return t.substring(0,n)}return t},E=t=>t.match(W)&&(t.match(/\*\*/g)||[]).length%2===1?`${t}**`:t,x=t=>t.match(z)&&(t.match(/__/g)||[]).length%2===1?`${t}__`:t,tt=t=>t.split("").reduce((e,n,o)=>{if(n==="*"){let r=t[o-1],i=t[o+1];if(r==="\\")return e;if(r!=="*"&&i!=="*")return e+1}return e},0),et=t=>t.match(F)&&tt(t)%2===1?`${t}*`:t,nt=t=>t.split("").reduce((e,n,o)=>{if(n==="_"){let r=t[o-1],i=t[o+1];if(r==="\\")return e;if(r!=="_"&&i!=="_")return e+1}return e},0),ot=t=>t.match(J)&&nt(t)%2===1?`${t}_`:t,rt=(t,e)=>{let n=t.substring(e,e+3)==="```",o=e>0&&t.substring(e-1,e+2)==="```",r=e>1&&t.substring(e-2,e+1)==="```";return n||o||r},st=t=>{let e=0;for(let n=0;n<t.length;n++)t[n]==="`"&&!rt(t,n)&&e++;return e},at=t=>{if(t.match(/^```[^`\n]*```?$/))return t.endsWith("``")&&!t.endsWith("```")?`${t}\``:t;let n=(t.match(/```/g)||[]).length,o=n%2===1;return n>0&&n%2===0&&t.includes(`
2
+ `)?t:t.match(Q)&&!o&&st(t)%2===1?`${t}\``:t},it=t=>t.match(X)&&(t.match(/~~/g)||[]).length%2===1?`${t}~~`:t,ct=t=>t.split("").reduce((e,n,o)=>{if(n==="$"){let r=t[o-1],i=t[o+1];if(r==="\\")return e;if(r!=="$"&&i!=="$")return e+1}return e},0),lt=t=>t.match(Z)&&(t.match(/\$\$/g)||[]).length%2===1?`${t}$$`:t,dt=t=>t.match(Y)&&ct(t)%2===1?`${t}$`:t,mt=t=>{let e=0,n=t.match(/\*+/g)||[];for(let o of n){let r=o.length;r>=3&&(e+=Math.floor(r/3))}return e},pt=t=>/^\*{4,}$/.test(t)?t:t.match(G)&&mt(t)%2===1?`${t}***`:t,B=t=>{if(!t||typeof t!="string")return t;let e=t;return e=j(e),e=pt(e),e=E(e),e=x(e),e=et(e),e=ot(e),e=at(e),e=it(e),e=lt(e),e=dt(e),e};import{jsx as f}from"react/jsx-runtime";var kt=$.default||$,yt=kt(gt),Ct=N(({content:t,shouldParseIncompleteMarkdown:e,...n})=>{let o=w(()=>typeof t=="string"&&e?B(t.trim()):t,[t,e]);return f(yt,{...n,children:o})},(t,e)=>t.content===e.content),v=N(({children:t,allowedImagePrefixes:e,allowedLinkPrefixes:n,defaultOrigin:o,parseIncompleteMarkdown:r=!0,components:i,rehypePlugins:l,remarkPlugins:c,className:d,...u})=>{let g=ut(),m=w(()=>I(typeof t=="string"?t:""),[t]);return f("div",{className:s("space-y-4",d),...u,children:m.map((h,P)=>f(Ct,{allowedImagePrefixes:e!=null?e:["*"],allowedLinkPrefixes:n!=null?n:["*"],components:{...M,...i},content:h,defaultOrigin:o,rehypePlugins:[ht,...l!=null?l:[]],remarkPlugins:[ft,bt,...c!=null?c:[]],shouldParseIncompleteMarkdown:r},`${g}-block_${P}`))})},(t,e)=>t.children===e.children);v.displayName="Streamdown";var Yt=v;export{v as Streamdown,Yt as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamdown",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",