streamdown 1.1.2 → 1.1.4

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 ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";"use client";var Y=Object.create;var T=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var ee=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var r in t)T(e,r,{get:t[r],enumerable:!0})},L=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!te.call(e,o)&&o!==r&&T(e,o,{get:()=>t[o],enumerable:!(n=Z(t,o))||n.enumerable});return e};var M=(e,t,r)=>(r=e!=null?Y(ee(e)):{},L(t||!e||!e.__esModule?T(r,"default",{value:e,enumerable:!0}):r,e)),ne=e=>L(T({},"__esModule",{value:!0}),e);var Ke={};re(Ke,{ShikiThemeContext:()=>$,Streamdown:()=>Q});module.exports=ne(Ke);var h=require("react"),V=M(require("react-markdown"),1),W=M(require("rehype-katex"),1),G=M(require("remark-gfm"),1),F=M(require("remark-math"),1),Ye=require("katex/dist/katex.min.css"),S=M(require("harden-react-markdown"),1);var O=require("react");var B=require("lucide-react"),m=require("react"),P=require("shiki");var A=require("clsx"),_=require("tailwind-merge"),s=(...e)=>(0,_.twMerge)((0,A.clsx)(e));var y=require("react/jsx-runtime"),R=(0,m.createContext)({code:""});async function oe(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 D=({code:e,language:t,className:r,children:n,...o})=>{let[i,l]=(0,m.useState)(""),[d,c]=(0,m.useState)(""),u=(0,m.useRef)(!1),[g,f]=(0,m.useContext)($);return(0,m.useEffect)(()=>(oe(e,t,[g,f]).then(([b,k])=>{u.current||(l(b),c(k),u.current=!0)}),()=>{u.current=!1}),[e,t,g,f]),(0,y.jsx)(R.Provider,{value:{code:e},children:(0,y.jsxs)("div",{className:"group relative",children:[(0,y.jsx)("div",{className:s("overflow-x-auto dark:hidden [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:i},...o}),(0,y.jsx)("div",{className:s("hidden overflow-x-auto dark:block [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:d},...o}),n]})})},N=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:o,code:i,...l})=>{let[d,c]=(0,m.useState)(!1),u=(0,m.useContext)(R).code,g=i!=null?i:u,f=async()=>{var k;if(typeof window=="undefined"||!((k=navigator==null?void 0:navigator.clipboard)!=null&&k.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(g),c(!0),e==null||e(),setTimeout(()=>c(!1),r)}catch(C){t==null||t(C)}},b=d?B.CheckIcon:B.CopyIcon;return(0,y.jsx)("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",o),onClick:f,type:"button",...l,children:n!=null?n:(0,y.jsx)(b,{size:14})})};var w=require("react");var p=require("react/jsx-runtime"),K=!1,se=async()=>{if(!K){let r=(await import("mermaid")).default;return r.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),K=!0,r}return(await import("mermaid")).default},E=({chart:e,className:t})=>{let[r,n]=(0,w.useState)(null),[o,i]=(0,w.useState)(!0),[l,d]=(0,w.useState)(""),[c,u]=(0,w.useState)("");if((0,w.useEffect)(()=>{(async()=>{try{n(null),i(!0);let b=await se(),k=e.split("").reduce((H,X)=>(H<<5)-H+X.charCodeAt(0)|0,0),C=`mermaid-${Math.abs(k)}`,{svg:I}=await b.render(C,e);d(I),u(I)}catch(b){if(!(c||l)){let k=b instanceof Error?b.message:"Failed to render Mermaid chart";n(k)}}finally{i(!1)}})()},[e]),o&&!l&&!c)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&&!l&&!c)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=l||c;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"),ae=/language-([^\s]+)/,ie=({node:e,className:t,children:r,...n})=>{var u,g,f;if(((u=e==null?void 0:e.position)==null?void 0:u.start.line)===((g=e==null?void 0:e.position)==null?void 0:g.end.line))return(0,a.jsx)("code",{"data-streamdown":"inline-code",className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),...n,children:r});let i=t==null?void 0:t.match(ae),l=(f=i==null?void 0:i.at(1))!=null?f:"plaintext",d="";return(0,O.isValidElement)(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?d=r.props.children:typeof r=="string"&&(d=r),l==="mermaid"||d.includes("graph")||d.includes("flowchart")||d.includes("sequenceDiagram")||d.includes("classDiagram")||d.includes("gantt")?(0,a.jsxs)("div",{"data-streamdown":"mermaid-block",className:s("group relative my-4 h-auto rounded-lg border p-4",t),children:[(0,a.jsx)(E,{chart:d}),(0,a.jsx)(N,{code:d})]}):(0,a.jsx)(D,{"data-streamdown":"code-block","data-language":l,className:s("my-4 h-auto rounded-lg border p-4",t),code:d,language:l,children:(0,a.jsx)(N,{})})},U={ol:({node:e,children:t,className:r,...n})=>(0,a.jsx)("ol",{"data-streamdown":"ordered-list",className:s("ml-4 list-outside list-decimal",r),...n,children:t}),li:({node:e,children:t,className:r,...n})=>(0,a.jsx)("li",{"data-streamdown":"list-item",className:s("py-1",r),...n,children:t}),ul:({node:e,children:t,className:r,...n})=>(0,a.jsx)("ul",{"data-streamdown":"unordered-list",className:s("ml-4 list-outside list-disc",r),...n,children:t}),hr:({node:e,className:t,...r})=>(0,a.jsx)("hr",{"data-streamdown":"horizontal-rule",className:s("my-6 border-border",t),...r}),strong:({node:e,children:t,className:r,...n})=>(0,a.jsx)("span",{"data-streamdown":"strong",className:s("font-semibold",r),...n,children:t}),a:({node:e,children:t,className:r,href:n,...o})=>(0,a.jsx)("a",{"data-streamdown":"link",className:s("font-medium text-primary underline",r),href:n,rel:"noreferrer",target:"_blank",...o,children:t}),h1:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h1",{"data-streamdown":"heading-1",className:s("mt-6 mb-2 font-semibold text-3xl",r),...n,children:t}),h2:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h2",{"data-streamdown":"heading-2",className:s("mt-6 mb-2 font-semibold text-2xl",r),...n,children:t}),h3:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h3",{"data-streamdown":"heading-3",className:s("mt-6 mb-2 font-semibold text-xl",r),...n,children:t}),h4:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h4",{"data-streamdown":"heading-4",className:s("mt-6 mb-2 font-semibold text-lg",r),...n,children:t}),h5:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h5",{"data-streamdown":"heading-5",className:s("mt-6 mb-2 font-semibold text-base",r),...n,children:t}),h6:({node:e,children:t,className:r,...n})=>(0,a.jsx)("h6",{"data-streamdown":"heading-6",className:s("mt-6 mb-2 font-semibold text-sm",r),...n,children:t}),table:({node:e,children:t,className:r,...n})=>(0,a.jsx)("div",{"data-streamdown":"table-wrapper",className:"my-4 overflow-x-auto",children:(0,a.jsx)("table",{"data-streamdown":"table",className:s("w-full border-collapse border border-border",r),...n,children:t})}),thead:({node:e,children:t,className:r,...n})=>(0,a.jsx)("thead",{"data-streamdown":"table-header",className:s("bg-muted/50",r),...n,children:t}),tbody:({node:e,children:t,className:r,...n})=>(0,a.jsx)("tbody",{"data-streamdown":"table-body",className:s("divide-y divide-border",r),...n,children:t}),tr:({node:e,children:t,className:r,...n})=>(0,a.jsx)("tr",{"data-streamdown":"table-row",className:s("border-border border-b",r),...n,children:t}),th:({node:e,children:t,className:r,...n})=>(0,a.jsx)("th",{"data-streamdown":"table-header-cell",className:s("px-4 py-2 text-left font-semibold text-sm",r),...n,children:t}),td:({node:e,children:t,className:r,...n})=>(0,a.jsx)("td",{"data-streamdown":"table-cell",className:s("px-4 py-2 text-sm",r),...n,children:t}),blockquote:({node:e,children:t,className:r,...n})=>(0,a.jsx)("blockquote",{"data-streamdown":"blockquote",className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",r),...n,children:t}),code:ie,pre:({children:e})=>e,sup:({node:e,children:t,className:r,...n})=>(0,a.jsx)("sup",{"data-streamdown":"superscript",className:s("text-sm",r),...n,children:t}),sub:({node:e,children:t,className:r,...n})=>(0,a.jsx)("sub",{"data-streamdown":"subscript",className:s("text-sm",r),...n,children:t})};var q=require("marked"),x=e=>q.marked.lexer(e).map(r=>r.raw);var de=/(!?\[)([^\]]*?)$/,le=/(\*\*)([^*]*?)$/,ce=/(__)([^_]*?)$/,me=/(\*\*\*)([^*]*?)$/,ue=/(\*)([^*]*?)$/,pe=/(_)([^_]*?)$/,ge=/(`)([^`]*?)$/,he=/(~~)([^~]*?)$/,fe=/(\$)([^$]*?)$/,be=/(\$\$)([^$]*?)$/,ke=e=>{let t=e.match(de);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},ye=e=>e.match(le)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,Me=e=>e.match(ce)&&(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 l=n;for(let c=n-1;c>=0;c--){if(e[c]===`
2
+ `){l=c+1;break}if(c===0){l=0;break}}if(e.substring(l,n).trim()===""&&(i===" "||i===" "))return t;if(o!=="*"&&i!=="*")return t+1}return t},0),Ce=e=>e.match(ue)&&we(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=>e.match(pe)&&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},Pe=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
3
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let r=(e.match(/```/g)||[]).length,n=r%2===1;return(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0||r>0&&r%2===0&&e.includes(`
4
+ `)?e:e.match(ge)&&!n&&$e(e)%2===1?`${e}\``:e},Ne=e=>e.match(he)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,Se=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),He=e=>e.match(be)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,Le=e=>e.match(fe)&&Se(e)%2===1?`${e}$`:e,Ae=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},_e=e=>/^\*{4,}$/.test(e)?e:e.match(me)&&Ae(e)%2===1?`${e}***`:e,z=e=>{if(!e||typeof e!="string")return e;let t=e;return t=ke(t),t=_e(t),t=ye(t),t=Me(t),t=Ce(t),t=Ie(t),t=Pe(t),t=Ne(t),t=He(t),t=Le(t),t};var v=require("react/jsx-runtime"),Re=S.default.default||S.default,De=Re(V.default),$=(0,h.createContext)(["github-light","github-dark"]),J=(0,h.memo)(({content:e,shouldParseIncompleteMarkdown:t,...r})=>{let n=(0,h.useMemo)(()=>typeof e=="string"&&t?z(e.trim()):e,[e,t]);return(0,v.jsx)(De,{...r,children:n})},(e,t)=>e.content===t.content);J.displayName="Block";var Q=(0,h.memo)(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:r,defaultOrigin:n,parseIncompleteMarkdown:o=!0,components:i,rehypePlugins:l,remarkPlugins:d,className:c,shikiTheme:u=["github-light","github-dark"],...g})=>{let f=(0,h.useId)(),b=(0,h.useMemo)(()=>x(typeof e=="string"?e:""),[e]),k=(0,h.useMemo)(()=>()=>(0,W.default)({errorColor:"var(--color-muted-foreground)"}),[]);return(0,v.jsx)($.Provider,{value:u,children:(0,v.jsx)("div",{className:s("space-y-4",c),...g,children:b.map((C,I)=>(0,v.jsx)(J,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:r!=null?r:["*"],components:{...U,...i},content:C,defaultOrigin:n,rehypePlugins:[k,...l!=null?l:[]],remarkPlugins:[G.default,F.default,...d!=null?d:[]],shouldParseIncompleteMarkdown:o},`${f}-block_${I}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Q.displayName="Streamdown";0&&(module.exports={ShikiThemeContext,Streamdown});
@@ -0,0 +1,19 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { Options } from 'react-markdown';
4
+ import { BundledTheme } from 'shiki';
5
+
6
+ type HardenReactMarkdownProps = Options & {
7
+ defaultOrigin?: string;
8
+ allowedLinkPrefixes?: string[];
9
+ allowedImagePrefixes?: string[];
10
+ };
11
+ type StreamdownProps = HardenReactMarkdownProps & {
12
+ parseIncompleteMarkdown?: boolean;
13
+ className?: string;
14
+ shikiTheme?: [BundledTheme, BundledTheme];
15
+ };
16
+ declare const ShikiThemeContext: react.Context<[BundledTheme, BundledTheme]>;
17
+ declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
18
+
19
+ export { ShikiThemeContext, Streamdown, type StreamdownProps };
@@ -0,0 +1,19 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as react from 'react';
3
+ import { Options } from 'react-markdown';
4
+ import { BundledTheme } from 'shiki';
5
+
6
+ type HardenReactMarkdownProps = Options & {
7
+ defaultOrigin?: string;
8
+ allowedLinkPrefixes?: string[];
9
+ allowedImagePrefixes?: string[];
10
+ };
11
+ type StreamdownProps = HardenReactMarkdownProps & {
12
+ parseIncompleteMarkdown?: boolean;
13
+ className?: string;
14
+ shikiTheme?: [BundledTheme, BundledTheme];
15
+ };
16
+ declare const ShikiThemeContext: react.Context<[BundledTheme, BundledTheme]>;
17
+ declare const Streamdown: react.MemoExoticComponent<({ children, allowedImagePrefixes, allowedLinkPrefixes, defaultOrigin, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
18
+
19
+ export { ShikiThemeContext, Streamdown, type StreamdownProps };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use client";import{createContext as Se,memo as E,useId as He,useMemo as T}from"react";import Le from"react-markdown";import Ae from"rehype-katex";import _e from"remark-gfm";import Re from"remark-math";import"katex/dist/katex.min.css";import K from"harden-react-markdown";import{isValidElement as Z}from"react";import{CheckIcon as z,CopyIcon as V,RouteIcon as ze}from"lucide-react";import{createContext as W,useContext as N,useEffect as G,useRef as F,useState as B}from"react";import{codeToHtml as P}from"shiki";import{clsx as q}from"clsx";import{twMerge as x}from"tailwind-merge";var s=(...e)=>x(q(e));import{jsx as k,jsxs as Q}from"react/jsx-runtime";var S=W({code:""});async function J(e,t,r){return Promise.all([await P(e,{lang:t,theme:r[0]}),await P(e,{lang:t,theme:r[1]})])}var H=({code:e,language:t,className:r,children:n,...o})=>{let[i,l]=B(""),[d,c]=B(""),m=F(!1),[u,p]=N(I);return G(()=>(J(e,t,[u,p]).then(([g,h])=>{m.current||(l(g),c(h),m.current=!0)}),()=>{m.current=!1}),[e,t,u,p]),k(S.Provider,{value:{code:e},children:Q("div",{className:"group relative",children:[k("div",{className:s("overflow-x-auto dark:hidden [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:i},...o}),k("div",{className:s("hidden overflow-x-auto dark:block [&>pre]:bg-transparent!",r),dangerouslySetInnerHTML:{__html:d},...o}),n]})})},v=({onCopy:e,onError:t,timeout:r=2e3,children:n,className:o,code:i,...l})=>{let[d,c]=B(!1),m=N(S).code,u=i!=null?i:m,p=async()=>{var h;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{await navigator.clipboard.writeText(u),c(!0),e==null||e(),setTimeout(()=>c(!1),r)}catch(b){t==null||t(b)}},g=d?z:V;return k("button",{className:s("absolute top-2 right-2 shrink-0 rounded-md p-3 opacity-0 transition-all","hover:bg-secondary group-hover:opacity-100",o),onClick:p,type:"button",...l,children:n!=null?n:k(g,{size:14})})};import{useEffect as X,useState as M}from"react";import{jsx as f,jsxs as w}from"react/jsx-runtime";var L=!1,Y=async()=>{if(!L){let r=(await import("mermaid")).default;return r.initialize({startOnLoad:!1,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:!0}),L=!0,r}return(await import("mermaid")).default},A=({chart:e,className:t})=>{let[r,n]=M(null),[o,i]=M(!0),[l,d]=M(""),[c,m]=M("");if(X(()=>{(async()=>{try{n(null),i(!0);let g=await Y(),h=e.split("").reduce(($,U)=>($<<5)-$+U.charCodeAt(0)|0,0),b=`mermaid-${Math.abs(h)}`,{svg:y}=await g.render(b,e);d(y),m(y)}catch(g){if(!(c||l)){let h=g instanceof Error?g.message:"Failed to render Mermaid chart";n(h)}}finally{i(!1)}})()},[e]),o&&!l&&!c)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&&!l&&!c)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=l||c;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 te}from"react/jsx-runtime";var j=/language-([^\s]+)/,ee=({node:e,className:t,children:r,...n})=>{var m,u,p;if(((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((u=e==null?void 0:e.position)==null?void 0:u.end.line))return a("code",{"data-streamdown":"inline-code",className:s("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),...n,children:r});let i=t==null?void 0:t.match(j),l=(p=i==null?void 0:i.at(1))!=null?p:"plaintext",d="";return Z(r)&&r.props&&typeof r.props=="object"&&"children"in r.props&&typeof r.props.children=="string"?d=r.props.children:typeof r=="string"&&(d=r),l==="mermaid"||d.includes("graph")||d.includes("flowchart")||d.includes("sequenceDiagram")||d.includes("classDiagram")||d.includes("gantt")?te("div",{"data-streamdown":"mermaid-block",className:s("group relative my-4 h-auto rounded-lg border p-4",t),children:[a(A,{chart:d}),a(v,{code:d})]}):a(H,{"data-streamdown":"code-block","data-language":l,className:s("my-4 h-auto rounded-lg border p-4",t),code:d,language:l,children:a(v,{})})},_={ol:({node:e,children:t,className:r,...n})=>a("ol",{"data-streamdown":"ordered-list",className:s("ml-4 list-outside list-decimal",r),...n,children:t}),li:({node:e,children:t,className:r,...n})=>a("li",{"data-streamdown":"list-item",className:s("py-1",r),...n,children:t}),ul:({node:e,children:t,className:r,...n})=>a("ul",{"data-streamdown":"unordered-list",className:s("ml-4 list-outside list-disc",r),...n,children:t}),hr:({node:e,className:t,...r})=>a("hr",{"data-streamdown":"horizontal-rule",className:s("my-6 border-border",t),...r}),strong:({node:e,children:t,className:r,...n})=>a("span",{"data-streamdown":"strong",className:s("font-semibold",r),...n,children:t}),a:({node:e,children:t,className:r,href:n,...o})=>a("a",{"data-streamdown":"link",className:s("font-medium text-primary underline",r),href:n,rel:"noreferrer",target:"_blank",...o,children:t}),h1:({node:e,children:t,className:r,...n})=>a("h1",{"data-streamdown":"heading-1",className:s("mt-6 mb-2 font-semibold text-3xl",r),...n,children:t}),h2:({node:e,children:t,className:r,...n})=>a("h2",{"data-streamdown":"heading-2",className:s("mt-6 mb-2 font-semibold text-2xl",r),...n,children:t}),h3:({node:e,children:t,className:r,...n})=>a("h3",{"data-streamdown":"heading-3",className:s("mt-6 mb-2 font-semibold text-xl",r),...n,children:t}),h4:({node:e,children:t,className:r,...n})=>a("h4",{"data-streamdown":"heading-4",className:s("mt-6 mb-2 font-semibold text-lg",r),...n,children:t}),h5:({node:e,children:t,className:r,...n})=>a("h5",{"data-streamdown":"heading-5",className:s("mt-6 mb-2 font-semibold text-base",r),...n,children:t}),h6:({node:e,children:t,className:r,...n})=>a("h6",{"data-streamdown":"heading-6",className:s("mt-6 mb-2 font-semibold text-sm",r),...n,children:t}),table:({node:e,children:t,className:r,...n})=>a("div",{"data-streamdown":"table-wrapper",className:"my-4 overflow-x-auto",children:a("table",{"data-streamdown":"table",className:s("w-full border-collapse border border-border",r),...n,children:t})}),thead:({node:e,children:t,className:r,...n})=>a("thead",{"data-streamdown":"table-header",className:s("bg-muted/50",r),...n,children:t}),tbody:({node:e,children:t,className:r,...n})=>a("tbody",{"data-streamdown":"table-body",className:s("divide-y divide-border",r),...n,children:t}),tr:({node:e,children:t,className:r,...n})=>a("tr",{"data-streamdown":"table-row",className:s("border-border border-b",r),...n,children:t}),th:({node:e,children:t,className:r,...n})=>a("th",{"data-streamdown":"table-header-cell",className:s("px-4 py-2 text-left font-semibold text-sm",r),...n,children:t}),td:({node:e,children:t,className:r,...n})=>a("td",{"data-streamdown":"table-cell",className:s("px-4 py-2 text-sm",r),...n,children:t}),blockquote:({node:e,children:t,className:r,...n})=>a("blockquote",{"data-streamdown":"blockquote",className:s("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",r),...n,children:t}),code:ee,pre:({children:e})=>e,sup:({node:e,children:t,className:r,...n})=>a("sup",{"data-streamdown":"superscript",className:s("text-sm",r),...n,children:t}),sub:({node:e,children:t,className:r,...n})=>a("sub",{"data-streamdown":"subscript",className:s("text-sm",r),...n,children:t})};import{marked as re}from"marked";var R=e=>re.lexer(e).map(r=>r.raw);var ne=/(!?\[)([^\]]*?)$/,oe=/(\*\*)([^*]*?)$/,se=/(__)([^_]*?)$/,ae=/(\*\*\*)([^*]*?)$/,ie=/(\*)([^*]*?)$/,de=/(_)([^_]*?)$/,le=/(`)([^`]*?)$/,ce=/(~~)([^~]*?)$/,me=/(\$)([^$]*?)$/,ue=/(\$\$)([^$]*?)$/,pe=e=>{let t=e.match(ne);if(t){let r=e.lastIndexOf(t[1]);return e.substring(0,r)}return e},ge=e=>e.match(oe)&&(e.match(/\*\*/g)||[]).length%2===1?`${e}**`:e,he=e=>e.match(se)&&(e.match(/__/g)||[]).length%2===1?`${e}__`:e,fe=e=>e.split("").reduce((t,r,n)=>{if(r==="*"){let o=e[n-1],i=e[n+1];if(o==="\\")return t;let l=n;for(let c=n-1;c>=0;c--){if(e[c]===`
2
+ `){l=c+1;break}if(c===0){l=0;break}}if(e.substring(l,n).trim()===""&&(i===" "||i===" "))return t;if(o!=="*"&&i!=="*")return t+1}return t},0),be=e=>e.match(ie)&&fe(e)%2===1?`${e}*`:e,ke=(e,t)=>{let r=!1,n=!1;for(let o=0;o<e.length&&o<t;o++){if(e[o]==="\\"&&e[o+1]==="$"){o++;continue}e[o]==="$"&&(e[o+1]==="$"?(n=!n,o++,r=!1):n||(r=!r))}return r||n},ye=e=>e.split("").reduce((t,r,n)=>{if(r==="_"){let o=e[n-1],i=e[n+1];if(o==="\\"||ke(e,n))return t;if(o!=="_"&&i!=="_")return t+1}return t},0),Me=e=>e.match(de)&&ye(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},Ce=e=>{let t=0;for(let r=0;r<e.length;r++)e[r]==="`"&&!we(e,r)&&t++;return t},Be=e=>{if(e.match(/^```[^`\n]*```?$/)&&!e.includes(`
3
+ `))return e.endsWith("``")&&!e.endsWith("```")?`${e}\``:e;let r=(e.match(/```/g)||[]).length,n=r%2===1;return(e.endsWith("```\n")||e.endsWith("```"))&&r%2===0||r>0&&r%2===0&&e.includes(`
4
+ `)?e:e.match(le)&&!n&&Ce(e)%2===1?`${e}\``:e},ve=e=>e.match(ce)&&(e.match(/~~/g)||[]).length%2===1?`${e}~~`:e,Ie=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),Te=e=>e.match(ue)&&(e.match(/\$\$/g)||[]).length%2===1?`${e}$$`:e,$e=e=>e.match(me)&&Ie(e)%2===1?`${e}$`:e,Pe=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},Ne=e=>/^\*{4,}$/.test(e)?e:e.match(ae)&&Pe(e)%2===1?`${e}***`:e,D=e=>{if(!e||typeof e!="string")return e;let t=e;return t=pe(t),t=Ne(t),t=ge(t),t=he(t),t=be(t),t=Me(t),t=Be(t),t=ve(t),t=Te(t),t=$e(t),t};import{jsx as C}from"react/jsx-runtime";var De=K.default||K,Ke=De(Le),I=Se(["github-light","github-dark"]),O=E(({content:e,shouldParseIncompleteMarkdown:t,...r})=>{let n=T(()=>typeof e=="string"&&t?D(e.trim()):e,[e,t]);return C(Ke,{...r,children:n})},(e,t)=>e.content===t.content);O.displayName="Block";var Ee=E(({children:e,allowedImagePrefixes:t,allowedLinkPrefixes:r,defaultOrigin:n,parseIncompleteMarkdown:o=!0,components:i,rehypePlugins:l,remarkPlugins:d,className:c,shikiTheme:m=["github-light","github-dark"],...u})=>{let p=He(),g=T(()=>R(typeof e=="string"?e:""),[e]),h=T(()=>()=>Ae({errorColor:"var(--color-muted-foreground)"}),[]);return C(I.Provider,{value:m,children:C("div",{className:s("space-y-4",c),...u,children:g.map((b,y)=>C(O,{allowedImagePrefixes:t!=null?t:["*"],allowedLinkPrefixes:r!=null?r:["*"],components:{..._,...i},content:b,defaultOrigin:n,rehypePlugins:[h,...l!=null?l:[]],remarkPlugins:[_e,Re,...d!=null?d:[]],shouldParseIncompleteMarkdown:o},`${p}-block_${y}`))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme);Ee.displayName="Streamdown";export{I as ShikiThemeContext,Ee as Streamdown};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "streamdown",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -19,15 +19,9 @@
19
19
  "homepage": "https://streamdown.ai",
20
20
  "repository": {
21
21
  "type": "git",
22
- "url": "https://github.com/vercel/streamdown.git",
22
+ "url": "git+https://github.com/vercel/streamdown.git",
23
23
  "directory": "packages/streamdown"
24
24
  },
25
- "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
+ }