streamdown 2.0.0-canary.1 → 2.0.0-canary.2
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/chunk-3NQCVKSQ.cjs +11 -0
- package/dist/chunk-EMZTOZ6T.js +11 -0
- package/dist/chunk-G4G4O3YV.js +11 -0
- package/dist/chunk-IXJS3HW4.cjs +11 -0
- package/dist/chunk-NXEH3KDW.js +11 -0
- package/dist/chunk-PIZWQ67B.js +10 -0
- package/dist/chunk-PSEVJFYH.cjs +10 -0
- package/dist/chunk-VBSB5TKO.cjs +11 -0
- package/dist/chunk-XFBDXTBQ.cjs +11 -0
- package/dist/chunk-ZQMXWODK.js +11 -0
- package/dist/code-block-545L3TSB.js +3 -0
- package/dist/code-block-7UISP4WS.cjs +3 -0
- package/dist/code-block-IAODRGDW.cjs +3 -0
- package/dist/code-block-J5FCTA2M.cjs +3 -0
- package/dist/code-block-KIVMSKLW.cjs +3 -0
- package/dist/code-block-LZKEDTPW.js +3 -0
- package/dist/code-block-NXAWERAK.js +3 -0
- package/dist/code-block-TTK2QWKF.js +3 -0
- package/dist/code-block-VLCCYAP7.cjs +3 -0
- package/dist/code-block-WIRPTTWS.js +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/mermaid-2PSAQXNP.js +2 -0
- package/dist/mermaid-4NEPLM7L.js +2 -0
- package/dist/mermaid-6PNWU3RG.cjs +2 -0
- package/dist/mermaid-H523CKXV.cjs +2 -0
- package/dist/mermaid-JO5YD23W.js +2 -0
- package/dist/mermaid-KLEML6VY.cjs +2 -0
- package/dist/mermaid-LQXJBOYN.js +2 -0
- package/dist/mermaid-RDS2TFUL.js +2 -0
- package/dist/mermaid-ZLUP6YB5.cjs +2 -0
- package/dist/mermaid-ZP66M2KM.cjs +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
'use strict';var react=require('react'),rehypeHarden=require('rehype-harden'),Te=require('rehype-katex'),Rn=require('rehype-raw'),Sn=require('rehype-sanitize'),In=require('remark-cjk-friendly'),En=require('remark-cjk-friendly-gfm-strikethrough'),Dn=require('remark-gfm'),Le=require('remark-math'),Hn=require('remend'),jsxRuntime=require('react/jsx-runtime'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),hastUtilToJsxRuntime=require('hast-util-to-jsx-runtime'),Xo=require('remark-parse'),Jo=require('remark-rehype'),unified=require('unified'),marked=require('marked'),unistUtilVisit=require('unist-util-visit'),qt=require('shiki/langs/bash.mjs'),fn=require('shiki/langs/css.mjs'),$t=require('shiki/langs/go.mjs'),gn=require('shiki/langs/html.mjs'),hn=require('shiki/langs/javascript.mjs'),bn=require('shiki/langs/json.mjs'),yn=require('shiki/langs/jsx.mjs'),zt=require('shiki/langs/markdown.mjs'),Zt=require('shiki/langs/python.mjs'),Wt=require('shiki/langs/shellscript.mjs'),wn=require('shiki/langs/sql.mjs'),kn=require('shiki/langs/toml.mjs'),vn=require('shiki/langs/tsx.mjs'),xn=require('shiki/langs/typescript.mjs'),_t=require('shiki/langs/yaml.mjs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var Te__default=/*#__PURE__*/_interopDefault(Te);var Rn__default=/*#__PURE__*/_interopDefault(Rn);var Sn__default=/*#__PURE__*/_interopDefault(Sn);var In__default=/*#__PURE__*/_interopDefault(In);var En__default=/*#__PURE__*/_interopDefault(En);var Dn__default=/*#__PURE__*/_interopDefault(Dn);var Le__default=/*#__PURE__*/_interopDefault(Le);var Hn__default=/*#__PURE__*/_interopDefault(Hn);var Xo__default=/*#__PURE__*/_interopDefault(Xo);var Jo__default=/*#__PURE__*/_interopDefault(Jo);var qt__default=/*#__PURE__*/_interopDefault(qt);var fn__default=/*#__PURE__*/_interopDefault(fn);var $t__default=/*#__PURE__*/_interopDefault($t);var gn__default=/*#__PURE__*/_interopDefault(gn);var hn__default=/*#__PURE__*/_interopDefault(hn);var bn__default=/*#__PURE__*/_interopDefault(bn);var yn__default=/*#__PURE__*/_interopDefault(yn);var zt__default=/*#__PURE__*/_interopDefault(zt);var Zt__default=/*#__PURE__*/_interopDefault(Zt);var Wt__default=/*#__PURE__*/_interopDefault(Wt);var wn__default=/*#__PURE__*/_interopDefault(wn);var kn__default=/*#__PURE__*/_interopDefault(kn);var vn__default=/*#__PURE__*/_interopDefault(vn);var xn__default=/*#__PURE__*/_interopDefault(xn);var _t__default=/*#__PURE__*/_interopDefault(_t);var no=300,ro="300px",so=500;function Ne(e={}){let{immediate:t=false,debounceDelay:n=no,rootMargin:o=ro,idleTimeout:s=so}=e,[r,l]=react.useState(false),a=react.useRef(null),i=react.useRef(null),c=react.useRef(null),d=react.useMemo(()=>g=>{let u=Date.now();return window.setTimeout(()=>{g({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-u))});},1)},[]),m=react.useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(g,u)=>window.requestIdleCallback(g,u):d,[d]),p=react.useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?g=>window.cancelIdleCallback(g):g=>{clearTimeout(g);},[]);return react.useEffect(()=>{if(t){l(true);return}let g=a.current;if(!g)return;i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);let u=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);},h=C=>{c.current=m(M=>{M.timeRemaining()>0||M.didTimeout?(l(true),C.disconnect()):c.current=m(()=>{l(true),C.disconnect();},{timeout:s/2});},{timeout:s});},y=C=>{u(),i.current=window.setTimeout(()=>{var R,S;let M=C.takeRecords();(M.length===0||(S=(R=M.at(-1))==null?void 0:R.isIntersecting)!=null&&S)&&h(C);},n);},k=(C,M)=>{C.isIntersecting?y(M):u();},L=new IntersectionObserver(C=>{for(let M of C)k(M,L);},{rootMargin:o,threshold:0});return L.observe(g),()=>{i.current&&clearTimeout(i.current),c.current&&p(c.current),L.disconnect();}},[t,n,o,s,p,m]),{shouldRender:r,containerRef:a}}var G=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),Y=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),V=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),Re=e=>jsxRuntime.jsxs("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[jsxRuntime.jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsxRuntime.jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),Se=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),Ie=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),Ee=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),De=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),He=e=>jsxRuntime.jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsxRuntime.jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})});var f=(...e)=>tailwindMerge.twMerge(clsx.clsx(e)),H=(e,t,n)=>{let o=typeof t=="string"?new Blob([t],{type:n}):t,s=URL.createObjectURL(o),r=document.createElement("a");r.href=s,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s);};var po=react.createContext({code:""}),Q=()=>react.useContext(po);var ue=({onCopy:e,onError:t,timeout:n=2e3,children:o,className:s,code:r,...l})=>{let[a,i]=react.useState(false),c=react.useRef(0),{code:d}=Q(),{isAnimating:m}=react.useContext(T),p=r!=null?r:d,g=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{a||(await navigator.clipboard.writeText(p),i(!0),e==null||e(),c.current=window.setTimeout(()=>i(!1),n));}catch(y){t==null||t(y);}};react.useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let u=a?G:Y;return jsxRuntime.jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-copy-button",disabled:m,onClick:g,title:"Copy Code",type:"button",...l,children:o!=null?o:jsxRuntime.jsx(u,{size:14})})};var Be={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},Ve=({onDownload:e,onError:t,language:n,children:o,className:s,code:r,...l})=>{let{code:a}=Q(),{isAnimating:i}=react.useContext(T),c=r!=null?r:a,m=`file.${n&&n in Be?Be[n]:"txt"}`,p="text/plain",g=()=>{try{H(m,c,p),e==null||e();}catch(u){t==null||t(u);}};return jsxRuntime.jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-download-button",disabled:i,onClick:g,title:"Download file",type:"button",...l,children:o!=null?o:jsxRuntime.jsx(V,{size:14})})};var ge=()=>jsxRuntime.jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsxRuntime.jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsxRuntime.jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsxRuntime.jsx(Re,{className:"size-4 animate-spin"})})]});var wo=/\.[^/.]+$/,Oe=({node:e,className:t,src:n,alt:o,...s})=>{let r=async()=>{if(n)try{let a=await(await fetch(n)).blob(),c=new URL(n,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),m=c.includes(".")&&d!==void 0&&d.length<=4,p="";if(m)p=c;else {let g=a.type,u="png";g.includes("jpeg")||g.includes("jpg")?u="jpg":g.includes("png")?u="png":g.includes("svg")?u="svg":g.includes("gif")?u="gif":g.includes("webp")&&(u="webp"),p=`${(o||c||"image").replace(wo,"")}.${u}`;}H(p,a,a.type);}catch(l){console.error("Failed to download image:",l);}};return n?jsxRuntime.jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsxRuntime.jsx("img",{alt:o,className:f("max-w-full rounded-lg",t),"data-streamdown":"image",src:n,...s}),jsxRuntime.jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsxRuntime.jsx("button",{className:f("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:r,title:"Download image",type:"button",children:jsxRuntime.jsx(V,{size:14})})]}):null};var F={name:"streamdown",version:"2.0.0-canary.1",type:"module",main:"./dist/index.js",module:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"}},files:["dist","README.md"],homepage:"https://streamdown.ai",repository:{type:"git",url:"git+https://github.com/vercel/streamdown.git",directory:"packages/streamdown"},scripts:{build:"tsup",postbuild:"node scripts/postbuild.js",test:"vitest run","test:ui":"vitest --ui run","test:coverage":"vitest --coverage run",bench:"vitest bench --run > results.txt","bench:ui":"vitest bench --ui --run",size:"node scripts/bundle-size.js"},author:"Hayden Bleasel <hayden.bleasel@vercel.com>",license:"Apache-2.0",description:"A drop-in replacement for react-markdown, designed for AI-powered streaming.",devDependencies:{"@testing-library/jest-dom":"^6.9.1","@testing-library/react":"^16.3.0","@types/hast":"^3.0.4","@types/react":"^19.2.7","@types/react-dom":"^19.2.3","@vitejs/plugin-react":"^5.1.2","@vitest/coverage-v8":"^4.0.15",jsdom:"^27.3.0",mermaid:"^11.12.2",react:"^19.2.1","react-dom":"^19.2.1","react-markdown":"^10.1.0",tsup:"^8.5.1",vitest:"^4.0.15"},peerDependencies:{react:"^18.0.0 || ^19.0.0"},dependencies:{clsx:"^2.1.1",esbuild:"^0.27.2","hast-util-to-jsx-runtime":"^2.3.6","html-url-attributes":"^3.0.1",katex:"^0.16.27",marked:"^17.0.1","rehype-harden":"^1.1.7","rehype-katex":"^7.0.1","rehype-raw":"^7.0.0","rehype-sanitize":"^6.0.0","remark-cjk-friendly":"^1.2.3","remark-cjk-friendly-gfm-strikethrough":"^1.2.3","remark-gfm":"^4.0.1","remark-math":"^6.0.0","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",remend:"workspace:*",shiki:"^3.19.0","tailwind-merge":"^3.4.0",unified:"^11.0.5","unist-util-visit":"^5.0.0"}};var qe,$e,ze,Ze,xo=((Ze=(ze=(qe=F.dependencies)==null?void 0:qe.mermaid)!=null?ze:($e=F.devDependencies)==null?void 0:$e.mermaid)!=null?Ze:"11").replace(/^\^/,""),Co=e=>`${e}/mermaid/${xo}/mermaid.esm.min.mjs`,he=new Map,Mo=new Function("url","return import(url)"),te=async(e,t)=>{let o={...{startOnLoad:false,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:true},...e};if(t==null)throw new Error("[Streamdown] Mermaid requires a CDN URL to load. Please provide a cdnUrl prop.");let s=Co(t);if(!he.has(s)){let a=await Mo(s);he.set(s,a);}let l=he.get(s).default;return l.initialize(o),l},We=(e,t)=>{var o;let n=(o=void 0)!=null?o:5;return new Promise((s,r)=>{let l="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),a=new Image;a.crossOrigin="anonymous",a.onload=()=>{let i=document.createElement("canvas"),c=a.width*n,d=a.height*n;i.width=c,i.height=d;let m=i.getContext("2d");if(!m){r(new Error("Failed to create 2D canvas context for PNG export"));return}m.drawImage(a,0,0,c,d),i.toBlob(p=>{if(!p){r(new Error("Failed to create PNG blob"));return}s(p);},"image/png");},a.onerror=()=>r(new Error("Failed to load SVG image")),a.src=l;})};var Fe=({chart:e,children:t,className:n,onDownload:o,config:s,onError:r})=>{let[l,a]=react.useState(false),i=react.useRef(null),{isAnimating:c}=react.useContext(T),d=async m=>{try{if(m==="mmd"){H("diagram.mmd",e,"text/plain"),a(!1),o==null||o(m);return}let p=await te(s),g=e.split("").reduce((y,k)=>(y<<5)-y+k.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:h}=await p.render(u,e);if(!h){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){H("diagram.svg",h,"image/svg+xml"),a(!1),o==null||o(m);return}if(m==="png"){let y=await We(h);H("diagram.png",y,"image/png"),o==null||o(m),a(!1);return}}catch(p){r==null||r(p);}};return react.useEffect(()=>{let m=p=>{i.current&&!i.current.contains(p.target)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxRuntime.jsxs("div",{className:"relative",ref:i,children:[jsxRuntime.jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",n),disabled:c,onClick:()=>a(!l),title:"Download diagram",type:"button",children:t!=null?t:jsxRuntime.jsx(V,{size:14})}),l?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var X=0,Io=()=>{X+=1,X===1&&(document.body.style.overflow="hidden");},Eo=()=>{X=Math.max(0,X-1),X===0&&(document.body.style.overflow="");},Ke=({chart:e,config:t,onFullscreen:n,onExit:o,className:s,...r})=>{let[l,a]=react.useState(false),{isAnimating:i,controls:c}=react.useContext(T),d=(()=>{if(typeof c=="boolean")return c;let p=c.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),m=()=>{a(!l);};return react.useEffect(()=>{if(l){Io();let p=g=>{g.key==="Escape"&&a(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),Eo();}}},[l]),react.useEffect(()=>{l?n==null||n():o&&o();},[l,n,o]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:i,onClick:m,title:"View fullscreen",type:"button",...r,children:jsxRuntime.jsx(Se,{size:14})}),l?jsxRuntime.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:m,onKeyDown:p=>{p.key==="Escape"&&m();},role:"button",tabIndex:0,children:[jsxRuntime.jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:m,title:"Exit fullscreen",type:"button",children:jsxRuntime.jsx(Ee,{size:20})}),jsxRuntime.jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsxRuntime.jsx(Je,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var oe=e=>{var r,l;let t=[],n=[],o=e.querySelectorAll("thead th");for(let a of o)t.push(((r=a.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let a of s){let i=[],c=a.querySelectorAll("td");for(let d of c)i.push(((l=d.textContent)==null?void 0:l.trim())||"");n.push(i);}return {headers:t,rows:n}},ne=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false,c=false;for(let d of a){if(d==='"'){i=true,c=true;break}(d===","||d===`
|
|
3
|
+
`)&&(i=true);}return i?c?`"${a.replace(/"/g,'""')}"`:`"${a}"`:a},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(","),l+=1);for(let a of n)r[l]=a.map(o).join(","),l+=1;return r.join(`
|
|
4
|
+
`)},Ge=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false;for(let d of a)if(d===" "||d===`
|
|
5
|
+
`||d==="\r"){i=true;break}if(!i)return a;let c=[];for(let d of a)d===" "?c.push("\\t"):d===`
|
|
6
|
+
`?c.push("\\n"):d==="\r"?c.push("\\r"):c.push(d);return c.join("")},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(" "),l+=1);for(let a of n)r[l]=a.map(o).join(" "),l+=1;return r.join(`
|
|
7
|
+
`)},be=e=>{let t=false;for(let o of e)if(o==="\\"||o==="|"){t=true;break}if(!t)return e;let n=[];for(let o of e)o==="\\"?n.push("\\\\"):o==="|"?n.push("\\|"):n.push(o);return n.join("")},Ye=e=>{let{headers:t,rows:n}=e;if(t.length===0)return "";let o=new Array(n.length+2),s=0,r=t.map(a=>be(a));o[s]=`| ${r.join(" | ")} |`,s+=1;let l=new Array(t.length);for(let a=0;a<t.length;a+=1)l[a]="---";o[s]=`| ${l.join(" | ")} |`,s+=1;for(let a of n)if(a.length<t.length){let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]=c<a.length?be(a[c]):"";o[s]=`| ${i.join(" | ")} |`,s+=1;}else {let i=a.map(c=>be(c));o[s]=`| ${i.join(" | ")} |`,s+=1;}return o.join(`
|
|
8
|
+
`)};var ot=({children:e,className:t,onCopy:n,onError:o,timeout:s=2e3})=>{let[r,l]=react.useState(false),[a,i]=react.useState(false),c=react.useRef(null),d=react.useRef(0),{isAnimating:m}=react.useContext(T),p=async u=>{var h,y;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){o==null||o(new Error("Clipboard API not available"));return}try{let k=(y=c.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),L=k==null?void 0:k.querySelector("table");if(!L){o==null||o(new Error("Table not found"));return}let C=oe(L),M=u==="csv"?ne(C):Ge(C),E=new ClipboardItem({"text/plain":new Blob([M],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),i(!0),l(!1),n==null||n(u),d.current=window.setTimeout(()=>i(!1),s);}catch(k){o==null||o(k);}};react.useEffect(()=>{let u=h=>{c.current&&!c.current.contains(h.target)&&l(false);};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current);}},[]);let g=a?G:Y;return jsxRuntime.jsxs("div",{className:"relative",ref:c,children:[jsxRuntime.jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!r),title:"Copy table",type:"button",children:e!=null?e:jsxRuntime.jsx(g,{size:14})}),r?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var rt=({children:e,className:t,onDownload:n,onError:o})=>{let[s,r]=react.useState(false),l=react.useRef(null),{isAnimating:a}=react.useContext(T),i=c=>{var d;try{let m=(d=l.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),p=m==null?void 0:m.querySelector("table");if(!p){o==null||o(new Error("Table not found"));return}let g=oe(p),u=c==="csv"?ne(g):Ye(g);H(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),r(!1),n==null||n(c);}catch(m){o==null||o(m);}};return react.useEffect(()=>{let c=d=>{l.current&&!l.current.contains(d.target)&&r(false);};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c);}},[]),jsxRuntime.jsxs("div",{className:"relative",ref:l,children:[jsxRuntime.jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:a,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:jsxRuntime.jsx(V,{size:14})}),s?jsxRuntime.jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsxRuntime.jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var at=({children:e,className:t,showControls:n,...o})=>jsxRuntime.jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[n?jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsxRuntime.jsx(ot,{}),jsxRuntime.jsx(rt,{})]}):null,jsxRuntime.jsx("div",{className:"overflow-x-auto",children:jsxRuntime.jsx("table",{className:f("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]});var qo=react.lazy(()=>import('./code-block-J5FCTA2M.cjs').then(e=>({default:e.CodeBlock}))),$o=react.lazy(()=>import('./mermaid-ZP66M2KM.cjs').then(e=>({default:e.Mermaid}))),zo=/language-([^\s]+)/;function le(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let n=e.position.start,o=t.position.start,s=e.position.end,r=t.position.end;return (n==null?void 0:n.line)===(o==null?void 0:o.line)&&(n==null?void 0:n.column)===(o==null?void 0:o.column)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function P(e,t){return e.className===t.className&&le(e.node,t.node)}var we=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ie=(e,t)=>{if(typeof e=="boolean")return e;let n=e.mermaid;return n===false?false:n===true||n===void 0?true:n[t]!==false},ke=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("ol",{className:f("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>P(e,t));ke.displayName="MarkdownOl";var dt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("li",{className:f("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&le(e.node,t.node));dt.displayName="MarkdownLi";var mt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("ul",{className:f("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>P(e,t));mt.displayName="MarkdownUl";var pt=react.memo(({className:e,node:t,...n})=>jsxRuntime.jsx("hr",{className:f("my-6 border-border",e),"data-streamdown":"horizontal-rule",...n}),(e,t)=>P(e,t));pt.displayName="MarkdownHr";var ut=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("span",{className:f("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>P(e,t));ut.displayName="MarkdownStrong";var ft=react.memo(({children:e,className:t,href:n,node:o,...s})=>{let r=n==="streamdown:incomplete-link";return jsxRuntime.jsx("a",{className:f("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...s,children:e})},(e,t)=>P(e,t)&&e.href===t.href);ft.displayName="MarkdownA";var gt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h1",{className:f("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>P(e,t));gt.displayName="MarkdownH1";var ht=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h2",{className:f("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>P(e,t));ht.displayName="MarkdownH2";var bt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h3",{className:f("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>P(e,t));bt.displayName="MarkdownH3";var yt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h4",{className:f("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>P(e,t));yt.displayName="MarkdownH4";var wt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h5",{className:f("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>P(e,t));wt.displayName="MarkdownH5";var kt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("h6",{className:f("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>P(e,t));kt.displayName="MarkdownH6";var vt=react.memo(({children:e,className:t,node:n,...o})=>{let{controls:s}=react.useContext(T),r=we(s,"table");return jsxRuntime.jsx(at,{className:t,"data-streamdown":"table-wrapper",showControls:r,...o,children:e})},(e,t)=>P(e,t));vt.displayName="MarkdownTable";var xt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("thead",{className:f("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>P(e,t));xt.displayName="MarkdownThead";var Ct=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("tbody",{className:f("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>P(e,t));Ct.displayName="MarkdownTbody";var Mt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("tr",{className:f("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>P(e,t));Mt.displayName="MarkdownTr";var Pt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("th",{className:f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>P(e,t));Pt.displayName="MarkdownTh";var Tt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("td",{className:f("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>P(e,t));Tt.displayName="MarkdownTd";var Lt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("blockquote",{className:f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>P(e,t));Lt.displayName="MarkdownBlockquote";var Nt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("sup",{className:f("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>P(e,t));Nt.displayName="MarkdownSup";var Rt=react.memo(({children:e,className:t,node:n,...o})=>jsxRuntime.jsx("sub",{className:f("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>P(e,t));Rt.displayName="MarkdownSub";var St=react.memo(({children:e,className:t,node:n,...o})=>{if("data-footnotes"in o){let r=i=>{var p,g;if(!react.isValidElement(i))return false;let c=Array.isArray(i.props.children)?i.props.children:[i.props.children],d=false,m=false;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=true);else if(react.isValidElement(u))if(((p=u.props)==null?void 0:p["data-footnote-backref"])!==void 0)m=true;else {let h=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let y of h){if(typeof y=="string"&&y.trim()!==""){d=true;break}if(react.isValidElement(y)&&((g=y.props)==null?void 0:g["data-footnote-backref"])===void 0){d=true;break}}}}return m&&!d},l=Array.isArray(e)?e.map(i=>{if(!react.isValidElement(i))return i;if(i.type===ke){let d=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(m=>!r(m));return d.length===0?null:{...i,props:{...i.props,children:d}}}return i}):e;return (Array.isArray(l)?l.some(i=>i!==null):l!==null)?jsxRuntime.jsx("section",{className:t,...o,children:l}):null}return jsxRuntime.jsx("section",{className:t,...o,children:e})},(e,t)=>P(e,t));St.displayName="MarkdownSection";var Zo=({node:e,className:t,children:n,...o})=>{var m,p,g;let s=((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((p=e==null?void 0:e.position)==null?void 0:p.end.line),{mermaid:r,controls:l}=react.useContext(T);if(s)return jsxRuntime.jsx("code",{className:f("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...o,children:n});let a=t==null?void 0:t.match(zo),i=(g=a==null?void 0:a.at(1))!=null?g:"",c="";if(react.isValidElement(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?c=n.props.children:typeof n=="string"&&(c=n),i==="mermaid"){let u=we(l,"mermaid"),h=ie(l,"download"),y=ie(l,"copy"),k=ie(l,"fullscreen"),L=ie(l,"panZoom"),C=u&&(h||y||k);return jsxRuntime.jsx(react.Suspense,{fallback:jsxRuntime.jsx(ge,{}),children:jsxRuntime.jsxs("div",{className:f("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[C?jsxRuntime.jsxs("div",{className:"flex items-center justify-end gap-2",children:[h?jsxRuntime.jsx(Fe,{chart:c,config:r==null?void 0:r.config}):null,y?jsxRuntime.jsx(ue,{code:c}):null,k?jsxRuntime.jsx(Ke,{chart:c,config:r==null?void 0:r.config}):null]}):null,jsxRuntime.jsx($o,{chart:c,config:r==null?void 0:r.config,showControls:L})]})})}let d=we(l,"code");return jsxRuntime.jsx(react.Suspense,{fallback:jsxRuntime.jsx(ge,{}),children:jsxRuntime.jsx(qo,{className:f("overflow-x-auto border-border border-t",t),code:c,language:i,children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Ve,{code:c,language:i}),jsxRuntime.jsx(ue,{})]}):null})})},It=react.memo(Zo,(e,t)=>e.className===t.className&&le(e.node,t.node));It.displayName="MarkdownCode";var Et=react.memo(Oe,(e,t)=>e.className===t.className&&le(e.node,t.node));Et.displayName="MarkdownImg";var Dt=react.memo(({children:e,className:t,node:n,...o})=>{var l;let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");return r.length===1&&react.isValidElement(r[0])&&((l=r[0].props.node)==null?void 0:l.tagName)==="img"?jsxRuntime.jsx(jsxRuntime.Fragment,{children:e}):jsxRuntime.jsx("p",{className:t,...o,children:e})},(e,t)=>P(e,t));Dt.displayName="MarkdownParagraph";var Ht={ol:ke,li:dt,ul:mt,hr:pt,strong:ut,a:ft,h1:gt,h2:ht,h3:bt,h4:yt,h5:wt,h6:kt,table:vt,thead:xt,tbody:Ct,tr:Mt,th:Pt,td:Tt,blockquote:Lt,code:It,img:Et,pre:({children:e})=>e,sup:Nt,sub:Rt,p:Dt,section:St};var Bt=[],At={allowDangerousHtml:true},ce=new WeakMap,ve=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let n=this.keyCache.get(t);if(n)return n;let o=t.rehypePlugins,s=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(o||s||r)){let m="default";return this.keyCache.set(t,m),m}let l=m=>{if(!m||m.length===0)return "";let p="";for(let g=0;g<m.length;g+=1){let u=m[g];if(g>0&&(p+=","),Array.isArray(u)){let[h,y]=u;if(typeof h=="function"){let k=ce.get(h);k||(k=h.name,ce.set(h,k)),p+=k;}else p+=String(h);p+=":",p+=JSON.stringify(y);}else if(typeof u=="function"){let h=ce.get(u);h||(h=u.name,ce.set(u,h)),p+=h;}else p+=String(u);}return p},a=l(o),i=l(s),c=r?JSON.stringify(r):"",d=`${i}::${a}::${c}`;return this.keyCache.set(t,d),d}get(t){let n=this.generateCacheKey(t),o=this.cache.get(n);return o&&(this.cache.delete(n),this.cache.set(n,o)),o}set(t,n){let o=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let s=this.cache.keys().next().value;s&&this.cache.delete(s);}this.cache.set(o,n);}clear(){this.cache.clear();}},Vt=new ve,xe=e=>{let t=Go(e),n=e.children||"";return Qo(t.runSync(t.parse(n),n),e)},Go=e=>{let t=Vt.get(e);if(t)return t;let n=Yo(e);return Vt.set(e,n),n},Yo=e=>{let t=e.rehypePlugins||Bt,n=e.remarkPlugins||Bt,o=e.remarkRehypeOptions?{...At,...e.remarkRehypeOptions}:At;return unified.unified().use(Xo__default.default).use(n).use(Jo__default.default,o).use(t)},Qo=(e,t)=>hastUtilToJsxRuntime.toJsxRuntime(e,{Fragment:jsxRuntime.Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsxRuntime.jsx,jsxs:jsxRuntime.jsxs,passKeys:true,passNode:true});var tn=/\[\^[^\]\s]{1,200}\](?!:)/,on=/\[\^[^\]\s]{1,200}\]:/,nn=/<\/(\w+)>/,rn=/<(\w+)[\s>]/,Ce=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},sn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Me=e=>{let t=0;for(let n=0;n<e.length-1;n+=1)e[n]==="$"&&e[n+1]==="$"&&(t+=1,n+=1);return t},Pe=e=>{let t=tn.test(e),n=on.test(e);if(t||n)return [e];let o=marked.Lexer.lex(e,{gfm:true}),s=[],r=[];for(let l of o){let a=l.raw,i=s.length;if(r.length>0){if(s[i-1]+=a,l.type==="html"){let d=a.match(nn);if(d){let m=d[1];r.at(-1)===m&&r.pop();}}continue}if(l.type==="html"&&l.block){let d=a.match(rn);if(d){let m=d[1];a.includes(`</${m}>`)||r.push(m);}}if(a.trim()==="$$"&&i>0){let d=s[i-1],m=Ce(d),p=Me(d);if(m&&p%2===1){s[i-1]=d+a;continue}}if(i>0&&sn(a)){let d=s[i-1],m=Ce(d),p=Me(d),g=Me(a);if(m&&p%2===1&&!Ce(a)&&g===1){s[i-1]=d+a;continue}}s.push(a);}return s};var ln=new Set(["\u3002","\uFF0E","\uFF0C","\u3001","\uFF1F","\uFF01","\uFF1A","\uFF1B","\uFF08","\uFF09","\u3010","\u3011","\u300C","\u300D","\u300E","\u300F","\u3008","\u3009","\u300A","\u300B"]),cn=/^(https?:\/\/|mailto:|www\.)/i,dn=e=>{if(e.children.length!==1)return false;let t=e.children[0];return t.type==="text"&&t.value===e.url},mn=e=>{let t=0;for(let n of e){if(ln.has(n))return t;t+=n.length;}return null},pn=(e,t)=>({...t,url:e,children:[{type:"text",value:e}]}),un=e=>({type:"text",value:e}),Ot=()=>e=>{unistUtilVisit.visit(e,"link",(t,n,o)=>{if(!o||typeof n!="number"||!dn(t)||!cn.test(t.url))return;let s=mn(t.url);if(s===null||s===0)return;let r=t.url.slice(0,s),l=t.url.slice(s),a=pn(r,t),i=un(l);return o.children.splice(n,1,a,i),n+1});};var Ft={javascript:hn__default.default,typescript:xn__default.default,jsx:yn__default.default,tsx:vn__default.default,html:gn__default.default,css:fn__default.default,json:bn__default.default,bash:qt__default.default,shellscript:Wt__default.default,shell:Wt__default.default,sh:qt__default.default,yaml:_t__default.default,yml:_t__default.default,toml:kn__default.default,python:Zt__default.default,py:Zt__default.default,markdown:zt__default.default,md:zt__default.default,sql:wn__default.default,go:$t__default.default,golang:$t__default.default},Cn=e=>e in Ft;var jn=/[^$]\$[^$]/,Bn=/^\$[^$]/,An=/[^$]\$$/,Vn={raw:Rn__default.default,sanitize:[Sn__default.default,{}],katex:[Te__default.default,{errorColor:"var(--color-muted-foreground)"}],harden:[rehypeHarden.harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},On={gfm:[Dn__default.default,{}],cjkAutolinkBoundary:[Ot,{}],math:[Le__default.default,{singleDollarTextMath:false}],cjkFriendly:[In__default.default,{}],cjkFriendlyGfmStrikethrough:[En__default.default,{}]},qn=Object.values(Vn),$n=Object.values(On),zn={block:" \u258B",circle:" \u25CF"},Jt="https://www.streamdown.ai/cdn",Zn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,cdnUrl:Jt},T=react.createContext(Zn),Kt=react.memo(({content:e,...t})=>jsxRuntime.jsx(xe,{...t,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let n=Object.keys(e.components||{}),o=Object.keys(t.components||{});if(n.length!==o.length||n.some(s=>{var r,l;return ((r=e.components)==null?void 0:r[s])!==((l=t.components)==null?void 0:l[s])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Kt.displayName="Block";var Wn=["github-light","github-dark"],_n=e=>Array.isArray(e)&&e.some(t=>Array.isArray(t)?t[0]===Te__default.default:t===Te__default.default),Fn=e=>{if(!Array.isArray(e))return false;let t=e.find(n=>Array.isArray(n)?n[0]===Le__default.default:n===Le__default.default);return t&&Array.isArray(t)&&t[1]?t[1].singleDollarTextMath===true:false},Un=(e,t)=>{let n=e.includes("$$"),o=t&&(jn.test(e)||Bn.test(e)||An.test(e));return n||o},Xn=/^\^/,Jn=e=>{let t=F.dependencies["rehype-katex"].replace(Xn,"").split(".")[0],o={7:"0.16.22"}[t]||"0.16.22",s=document.createElement("link");s.rel="stylesheet",s.href=`${e}/katex/${o}/katex.min.css`,document.head.appendChild(s);},Kn=react.memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:n=true,components:o,rehypePlugins:s=qn,remarkPlugins:r=$n,className:l,shikiTheme:a=Wn,mermaid:i,controls:c=true,isAnimating:d=false,BlockComponent:m=Kt,parseMarkdownIntoBlocksFn:p=Pe,caret:g,cdnUrl:u=Jt,remend:h,...y})=>{let k=react.useId(),[L,C]=react.useTransition(),[M,E]=react.useState([]),R=react.useMemo(()=>typeof e!="string"?"":t==="streaming"&&n?Hn__default.default(e,h):e,[e,t,n,h]),S=react.useMemo(()=>p(R),[R,p]);react.useEffect(()=>{t==="streaming"?C(()=>{E(S);}):E(S);},[S,t]);let j=t==="streaming"?M:S,z=react.useMemo(()=>j.map((N,A)=>`${k}-${A}`),[j.length,k]),B=react.useMemo(()=>({shikiTheme:a,controls:c,isAnimating:d,mode:t,mermaid:i,cdnUrl:u}),[a,c,d,t,i,u]),D=react.useMemo(()=>({...Ht,...o}),[o]);react.useEffect(()=>{if(u===null||!_n(s))return;let A=Fn(r);Un(typeof e=="string"?e:"",A)&&Jn(u);},[s,r,e,u]);let w=react.useMemo(()=>g&&d?{"--streamdown-caret":`"${zn[g]}"`}:void 0,[g,d]);return t==="static"?jsxRuntime.jsx(T.Provider,{value:B,children:jsxRuntime.jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:jsxRuntime.jsx(xe,{components:D,rehypePlugins:s,remarkPlugins:r,...y,children:e})})}):jsxRuntime.jsx(T.Provider,{value:B,children:jsxRuntime.jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",g?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,l),style:w,children:j.map((N,A)=>jsxRuntime.jsx(m,{components:D,content:N,index:A,rehypePlugins:s,remarkPlugins:r,shouldParseIncompleteMarkdown:n,...y},z[A]))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode);Kn.displayName="Streamdown";var eo=({children:e,className:t,minZoom:n=.5,maxZoom:o=3,zoomStep:s=.1,showControls:r=true,initialZoom:l=1,fullscreen:a=false})=>{let i=react.useRef(null),c=react.useRef(null),[d,m]=react.useState(l),[p,g]=react.useState({x:0,y:0}),[u,h]=react.useState(false),[y,k]=react.useState({x:0,y:0}),[L,C]=react.useState({x:0,y:0}),M=react.useCallback(w=>{m(N=>Math.max(n,Math.min(o,N+w)));},[n,o]),E=react.useCallback(()=>{M(s);},[M,s]),R=react.useCallback(()=>{M(-s);},[M,s]),S=react.useCallback(()=>{m(l),g({x:0,y:0});},[l]),j=react.useCallback(w=>{w.preventDefault();let N=w.deltaY>0?-s:s;M(N);},[M,s]),z=react.useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;h(true),k({x:w.clientX,y:w.clientY}),C(p);let N=w.currentTarget;N instanceof HTMLElement&&N.setPointerCapture(w.pointerId);},[p]),B=react.useCallback(w=>{if(!u)return;w.preventDefault();let N=w.clientX-y.x,A=w.clientY-y.y;g({x:L.x+N,y:L.y+A});},[u,y,L]),D=react.useCallback(w=>{h(false);let N=w.currentTarget;N instanceof HTMLElement&&N.releasePointerCapture(w.pointerId);},[]);return react.useEffect(()=>{let w=i.current;if(w)return w.addEventListener("wheel",j,{passive:false}),()=>{w.removeEventListener("wheel",j);}},[j]),react.useEffect(()=>{let w=c.current;if(w&&u)return document.body.style.userSelect="none",w.addEventListener("pointermove",B,{passive:false}),w.addEventListener("pointerup",D),w.addEventListener("pointercancel",D),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",B),w.removeEventListener("pointerup",D),w.removeEventListener("pointercancel",D);}},[u,B,D]),jsxRuntime.jsxs("div",{className:f("relative flex flex-col",a?"h-full w-full":"min-h-28 w-full",t),ref:i,style:{cursor:u?"grabbing":"grab"},children:[r?jsxRuntime.jsxs("div",{className:f("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",a?"bottom-4 left-4":"bottom-2 left-2"),children:[jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d>=o,onClick:E,title:"Zoom in",type:"button",children:jsxRuntime.jsx(De,{size:16})}),jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d<=n,onClick:R,title:"Zoom out",type:"button",children:jsxRuntime.jsx(He,{size:16})}),jsxRuntime.jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:S,title:"Reset zoom and pan",type:"button",children:jsxRuntime.jsx(Ie,{size:16})})]}):null,jsxRuntime.jsx("div",{className:f("flex-1 origin-center transition-transform duration-150 ease-out",a?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:z,ref:c,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var Je=({chart:e,className:t,config:n,fullscreen:o=false,showControls:s=true})=>{let[r,l]=react.useState(null),[a,i]=react.useState(false),[c,d]=react.useState(""),[m,p]=react.useState(""),[g,u]=react.useState(0),{mermaid:h,cdnUrl:y}=react.useContext(T),k=h==null?void 0:h.errorComponent,{shouldRender:L,containerRef:C}=Ne({immediate:o});if(react.useEffect(()=>{if(!L)return;(async()=>{try{l(null),i(!0);let R=await te(n,y),S=e.split("").reduce((B,D)=>(B<<5)-B+D.charCodeAt(0)|0,0),j=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:z}=await R.render(j,e);d(z),p(z);}catch(R){if(!(m||c)){let S=R instanceof Error?R.message:"Failed to render Mermaid chart";l(S);}}finally{i(false);}})();},[e,n,g,L,y]),!(L||c||m))return jsxRuntime.jsx("div",{className:f("my-4 min-h-[200px]",t),ref:C});if(a&&!c&&!m)return jsxRuntime.jsx("div",{className:f("my-4 flex justify-center p-4",t),ref:C,children:jsxRuntime.jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsxRuntime.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsxRuntime.jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!c&&!m){let E=()=>u(R=>R+1);return k?jsxRuntime.jsx("div",{ref:C,children:jsxRuntime.jsx(k,{chart:e,error:r,retry:E})}):jsxRuntime.jsxs("div",{className:f("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:C,children:[jsxRuntime.jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),jsxRuntime.jsxs("details",{className:"mt-2",children:[jsxRuntime.jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsxRuntime.jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let M=c||m;return jsxRuntime.jsx("div",{className:"size-full",ref:C,children:jsxRuntime.jsx(eo,{className:f(o?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:o,maxZoom:3,minZoom:.5,showControls:s,zoomStep:.1,children:jsxRuntime.jsx("div",{"aria-label":"Mermaid chart",className:f("flex justify-center",o?"size-full items-center":null),dangerouslySetInnerHTML:{__html:M},role:"img"})})})};
|
|
11
|
+
exports.a=f;exports.b=po;exports.c=F;exports.d=Je;exports.e=Ft;exports.f=Cn;exports.g=Pe;exports.h=Vn;exports.i=On;exports.j=T;exports.k=Kt;exports.l=Kn;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {createContext,lazy,memo,useContext,isValidElement,useId,useTransition,useState,useMemo,useEffect,Suspense,useRef,useCallback}from'react';import {harden}from'rehype-harden';import Te from'rehype-katex';import Rn from'rehype-raw';import Sn from'rehype-sanitize';import In from'remark-cjk-friendly';import En from'remark-cjk-friendly-gfm-strikethrough';import Dn from'remark-gfm';import Le from'remark-math';import Hn from'remend';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import Xo from'remark-parse';import Jo from'remark-rehype';import {unified}from'unified';import {Lexer}from'marked';import {visit}from'unist-util-visit';import qt from'shiki/langs/bash.mjs';import fn from'shiki/langs/css.mjs';import $t from'shiki/langs/go.mjs';import gn from'shiki/langs/html.mjs';import hn from'shiki/langs/javascript.mjs';import bn from'shiki/langs/json.mjs';import yn from'shiki/langs/jsx.mjs';import zt from'shiki/langs/markdown.mjs';import Zt from'shiki/langs/python.mjs';import Wt from'shiki/langs/shellscript.mjs';import wn from'shiki/langs/sql.mjs';import kn from'shiki/langs/toml.mjs';import vn from'shiki/langs/tsx.mjs';import xn from'shiki/langs/typescript.mjs';import _t from'shiki/langs/yaml.mjs';var no=300,ro="300px",so=500;function Ne(e={}){let{immediate:t=false,debounceDelay:n=no,rootMargin:o=ro,idleTimeout:s=so}=e,[r,l]=useState(false),a=useRef(null),i=useRef(null),c=useRef(null),d=useMemo(()=>g=>{let u=Date.now();return window.setTimeout(()=>{g({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-u))});},1)},[]),m=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(g,u)=>window.requestIdleCallback(g,u):d,[d]),p=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?g=>window.cancelIdleCallback(g):g=>{clearTimeout(g);},[]);return useEffect(()=>{if(t){l(true);return}let g=a.current;if(!g)return;i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);let u=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);},h=C=>{c.current=m(M=>{M.timeRemaining()>0||M.didTimeout?(l(true),C.disconnect()):c.current=m(()=>{l(true),C.disconnect();},{timeout:s/2});},{timeout:s});},y=C=>{u(),i.current=window.setTimeout(()=>{var R,S;let M=C.takeRecords();(M.length===0||(S=(R=M.at(-1))==null?void 0:R.isIntersecting)!=null&&S)&&h(C);},n);},k=(C,M)=>{C.isIntersecting?y(M):u();},L=new IntersectionObserver(C=>{for(let M of C)k(M,L);},{rootMargin:o,threshold:0});return L.observe(g),()=>{i.current&&clearTimeout(i.current),c.current&&p(c.current),L.disconnect();}},[t,n,o,s,p,m]),{shouldRender:r,containerRef:a}}var G=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),Y=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),V=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),Re=e=>jsxs("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:[jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),Se=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),Ie=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),Ee=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),De=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),He=e=>jsx("svg",{color:"currentColor",height:16,strokeLinejoin:"round",viewBox:"0 0 16 16",width:16,...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})});var f=(...e)=>twMerge(clsx(e)),H=(e,t,n)=>{let o=typeof t=="string"?new Blob([t],{type:n}):t,s=URL.createObjectURL(o),r=document.createElement("a");r.href=s,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s);};var po=createContext({code:""}),Q=()=>useContext(po);var ue=({onCopy:e,onError:t,timeout:n=2e3,children:o,className:s,code:r,...l})=>{let[a,i]=useState(false),c=useRef(0),{code:d}=Q(),{isAnimating:m}=useContext(T),p=r!=null?r:d,g=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{a||(await navigator.clipboard.writeText(p),i(!0),e==null||e(),c.current=window.setTimeout(()=>i(!1),n));}catch(y){t==null||t(y);}};useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let u=a?G:Y;return jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-copy-button",disabled:m,onClick:g,title:"Copy Code",type:"button",...l,children:o!=null?o:jsx(u,{size:14})})};var Be={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},Ve=({onDownload:e,onError:t,language:n,children:o,className:s,code:r,...l})=>{let{code:a}=Q(),{isAnimating:i}=useContext(T),c=r!=null?r:a,m=`file.${n&&n in Be?Be[n]:"txt"}`,p="text/plain",g=()=>{try{H(m,c,p),e==null||e();}catch(u){t==null||t(u);}};return jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-download-button",disabled:i,onClick:g,title:"Download file",type:"button",...l,children:o!=null?o:jsx(V,{size:14})})};var ge=()=>jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsx(Re,{className:"size-4 animate-spin"})})]});var wo=/\.[^/.]+$/,Oe=({node:e,className:t,src:n,alt:o,...s})=>{let r=async()=>{if(n)try{let a=await(await fetch(n)).blob(),c=new URL(n,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),m=c.includes(".")&&d!==void 0&&d.length<=4,p="";if(m)p=c;else {let g=a.type,u="png";g.includes("jpeg")||g.includes("jpg")?u="jpg":g.includes("png")?u="png":g.includes("svg")?u="svg":g.includes("gif")?u="gif":g.includes("webp")&&(u="webp"),p=`${(o||c||"image").replace(wo,"")}.${u}`;}H(p,a,a.type);}catch(l){console.error("Failed to download image:",l);}};return n?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:o,className:f("max-w-full rounded-lg",t),"data-streamdown":"image",src:n,...s}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsx("button",{className:f("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:r,title:"Download image",type:"button",children:jsx(V,{size:14})})]}):null};var F={name:"streamdown",version:"2.0.0-canary.1",type:"module",main:"./dist/index.js",module:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"}},files:["dist","README.md"],homepage:"https://streamdown.ai",repository:{type:"git",url:"git+https://github.com/vercel/streamdown.git",directory:"packages/streamdown"},scripts:{build:"tsup",postbuild:"node scripts/postbuild.js",test:"vitest run","test:ui":"vitest --ui run","test:coverage":"vitest --coverage run",bench:"vitest bench --run > results.txt","bench:ui":"vitest bench --ui --run",size:"node scripts/bundle-size.js"},author:"Hayden Bleasel <hayden.bleasel@vercel.com>",license:"Apache-2.0",description:"A drop-in replacement for react-markdown, designed for AI-powered streaming.",devDependencies:{"@testing-library/jest-dom":"^6.9.1","@testing-library/react":"^16.3.0","@types/hast":"^3.0.4","@types/react":"^19.2.7","@types/react-dom":"^19.2.3","@vitejs/plugin-react":"^5.1.2","@vitest/coverage-v8":"^4.0.15",jsdom:"^27.3.0",mermaid:"^11.12.2",react:"^19.2.1","react-dom":"^19.2.1","react-markdown":"^10.1.0",tsup:"^8.5.1",vitest:"^4.0.15"},peerDependencies:{react:"^18.0.0 || ^19.0.0"},dependencies:{clsx:"^2.1.1",esbuild:"^0.27.2","hast-util-to-jsx-runtime":"^2.3.6","html-url-attributes":"^3.0.1",katex:"^0.16.27",marked:"^17.0.1","rehype-harden":"^1.1.7","rehype-katex":"^7.0.1","rehype-raw":"^7.0.0","rehype-sanitize":"^6.0.0","remark-cjk-friendly":"^1.2.3","remark-cjk-friendly-gfm-strikethrough":"^1.2.3","remark-gfm":"^4.0.1","remark-math":"^6.0.0","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",remend:"workspace:*",shiki:"^3.19.0","tailwind-merge":"^3.4.0",unified:"^11.0.5","unist-util-visit":"^5.0.0"}};var qe,$e,ze,Ze,xo=((Ze=(ze=(qe=F.dependencies)==null?void 0:qe.mermaid)!=null?ze:($e=F.devDependencies)==null?void 0:$e.mermaid)!=null?Ze:"11").replace(/^\^/,""),Co=e=>`${e}/mermaid/${xo}/mermaid.esm.min.mjs`,he=new Map,Mo=new Function("url","return import(url)"),te=async(e,t)=>{let o={...{startOnLoad:false,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:true},...e};if(t==null)throw new Error("[Streamdown] Mermaid requires a CDN URL to load. Please provide a cdnUrl prop.");let s=Co(t);if(!he.has(s)){let a=await Mo(s);he.set(s,a);}let l=he.get(s).default;return l.initialize(o),l},We=(e,t)=>{var o;let n=(o=void 0)!=null?o:5;return new Promise((s,r)=>{let l="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),a=new Image;a.crossOrigin="anonymous",a.onload=()=>{let i=document.createElement("canvas"),c=a.width*n,d=a.height*n;i.width=c,i.height=d;let m=i.getContext("2d");if(!m){r(new Error("Failed to create 2D canvas context for PNG export"));return}m.drawImage(a,0,0,c,d),i.toBlob(p=>{if(!p){r(new Error("Failed to create PNG blob"));return}s(p);},"image/png");},a.onerror=()=>r(new Error("Failed to load SVG image")),a.src=l;})};var Fe=({chart:e,children:t,className:n,onDownload:o,config:s,onError:r})=>{let[l,a]=useState(false),i=useRef(null),{isAnimating:c}=useContext(T),d=async m=>{try{if(m==="mmd"){H("diagram.mmd",e,"text/plain"),a(!1),o==null||o(m);return}let p=await te(s),g=e.split("").reduce((y,k)=>(y<<5)-y+k.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:h}=await p.render(u,e);if(!h){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){H("diagram.svg",h,"image/svg+xml"),a(!1),o==null||o(m);return}if(m==="png"){let y=await We(h);H("diagram.png",y,"image/png"),o==null||o(m),a(!1);return}}catch(p){r==null||r(p);}};return useEffect(()=>{let m=p=>{i.current&&!i.current.contains(p.target)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:"relative",ref:i,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",n),disabled:c,onClick:()=>a(!l),title:"Download diagram",type:"button",children:t!=null?t:jsx(V,{size:14})}),l?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var X=0,Io=()=>{X+=1,X===1&&(document.body.style.overflow="hidden");},Eo=()=>{X=Math.max(0,X-1),X===0&&(document.body.style.overflow="");},Ke=({chart:e,config:t,onFullscreen:n,onExit:o,className:s,...r})=>{let[l,a]=useState(false),{isAnimating:i,controls:c}=useContext(T),d=(()=>{if(typeof c=="boolean")return c;let p=c.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),m=()=>{a(!l);};return useEffect(()=>{if(l){Io();let p=g=>{g.key==="Escape"&&a(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),Eo();}}},[l]),useEffect(()=>{l?n==null||n():o&&o();},[l,n,o]),jsxs(Fragment,{children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:i,onClick:m,title:"View fullscreen",type:"button",...r,children:jsx(Se,{size:14})}),l?jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:m,onKeyDown:p=>{p.key==="Escape"&&m();},role:"button",tabIndex:0,children:[jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:m,title:"Exit fullscreen",type:"button",children:jsx(Ee,{size:20})}),jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsx(Je,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var oe=e=>{var r,l;let t=[],n=[],o=e.querySelectorAll("thead th");for(let a of o)t.push(((r=a.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let a of s){let i=[],c=a.querySelectorAll("td");for(let d of c)i.push(((l=d.textContent)==null?void 0:l.trim())||"");n.push(i);}return {headers:t,rows:n}},ne=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false,c=false;for(let d of a){if(d==='"'){i=true,c=true;break}(d===","||d===`
|
|
3
|
+
`)&&(i=true);}return i?c?`"${a.replace(/"/g,'""')}"`:`"${a}"`:a},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(","),l+=1);for(let a of n)r[l]=a.map(o).join(","),l+=1;return r.join(`
|
|
4
|
+
`)},Ge=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false;for(let d of a)if(d===" "||d===`
|
|
5
|
+
`||d==="\r"){i=true;break}if(!i)return a;let c=[];for(let d of a)d===" "?c.push("\\t"):d===`
|
|
6
|
+
`?c.push("\\n"):d==="\r"?c.push("\\r"):c.push(d);return c.join("")},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(" "),l+=1);for(let a of n)r[l]=a.map(o).join(" "),l+=1;return r.join(`
|
|
7
|
+
`)},be=e=>{let t=false;for(let o of e)if(o==="\\"||o==="|"){t=true;break}if(!t)return e;let n=[];for(let o of e)o==="\\"?n.push("\\\\"):o==="|"?n.push("\\|"):n.push(o);return n.join("")},Ye=e=>{let{headers:t,rows:n}=e;if(t.length===0)return "";let o=new Array(n.length+2),s=0,r=t.map(a=>be(a));o[s]=`| ${r.join(" | ")} |`,s+=1;let l=new Array(t.length);for(let a=0;a<t.length;a+=1)l[a]="---";o[s]=`| ${l.join(" | ")} |`,s+=1;for(let a of n)if(a.length<t.length){let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]=c<a.length?be(a[c]):"";o[s]=`| ${i.join(" | ")} |`,s+=1;}else {let i=a.map(c=>be(c));o[s]=`| ${i.join(" | ")} |`,s+=1;}return o.join(`
|
|
8
|
+
`)};var ot=({children:e,className:t,onCopy:n,onError:o,timeout:s=2e3})=>{let[r,l]=useState(false),[a,i]=useState(false),c=useRef(null),d=useRef(0),{isAnimating:m}=useContext(T),p=async u=>{var h,y;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){o==null||o(new Error("Clipboard API not available"));return}try{let k=(y=c.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),L=k==null?void 0:k.querySelector("table");if(!L){o==null||o(new Error("Table not found"));return}let C=oe(L),M=u==="csv"?ne(C):Ge(C),E=new ClipboardItem({"text/plain":new Blob([M],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),i(!0),l(!1),n==null||n(u),d.current=window.setTimeout(()=>i(!1),s);}catch(k){o==null||o(k);}};useEffect(()=>{let u=h=>{c.current&&!c.current.contains(h.target)&&l(false);};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current);}},[]);let g=a?G:Y;return jsxs("div",{className:"relative",ref:c,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!r),title:"Copy table",type:"button",children:e!=null?e:jsx(g,{size:14})}),r?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var rt=({children:e,className:t,onDownload:n,onError:o})=>{let[s,r]=useState(false),l=useRef(null),{isAnimating:a}=useContext(T),i=c=>{var d;try{let m=(d=l.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),p=m==null?void 0:m.querySelector("table");if(!p){o==null||o(new Error("Table not found"));return}let g=oe(p),u=c==="csv"?ne(g):Ye(g);H(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),r(!1),n==null||n(c);}catch(m){o==null||o(m);}};return useEffect(()=>{let c=d=>{l.current&&!l.current.contains(d.target)&&r(false);};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c);}},[]),jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:a,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:jsx(V,{size:14})}),s?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var at=({children:e,className:t,showControls:n,...o})=>jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[n?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(ot,{}),jsx(rt,{})]}):null,jsx("div",{className:"overflow-x-auto",children:jsx("table",{className:f("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]});var qo=lazy(()=>import('./code-block-WIRPTTWS.js').then(e=>({default:e.CodeBlock}))),$o=lazy(()=>import('./mermaid-RDS2TFUL.js').then(e=>({default:e.Mermaid}))),zo=/language-([^\s]+)/;function le(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let n=e.position.start,o=t.position.start,s=e.position.end,r=t.position.end;return (n==null?void 0:n.line)===(o==null?void 0:o.line)&&(n==null?void 0:n.column)===(o==null?void 0:o.column)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function P(e,t){return e.className===t.className&&le(e.node,t.node)}var we=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ie=(e,t)=>{if(typeof e=="boolean")return e;let n=e.mermaid;return n===false?false:n===true||n===void 0?true:n[t]!==false},ke=memo(({children:e,className:t,node:n,...o})=>jsx("ol",{className:f("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>P(e,t));ke.displayName="MarkdownOl";var dt=memo(({children:e,className:t,node:n,...o})=>jsx("li",{className:f("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&le(e.node,t.node));dt.displayName="MarkdownLi";var mt=memo(({children:e,className:t,node:n,...o})=>jsx("ul",{className:f("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>P(e,t));mt.displayName="MarkdownUl";var pt=memo(({className:e,node:t,...n})=>jsx("hr",{className:f("my-6 border-border",e),"data-streamdown":"horizontal-rule",...n}),(e,t)=>P(e,t));pt.displayName="MarkdownHr";var ut=memo(({children:e,className:t,node:n,...o})=>jsx("span",{className:f("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>P(e,t));ut.displayName="MarkdownStrong";var ft=memo(({children:e,className:t,href:n,node:o,...s})=>{let r=n==="streamdown:incomplete-link";return jsx("a",{className:f("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...s,children:e})},(e,t)=>P(e,t)&&e.href===t.href);ft.displayName="MarkdownA";var gt=memo(({children:e,className:t,node:n,...o})=>jsx("h1",{className:f("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>P(e,t));gt.displayName="MarkdownH1";var ht=memo(({children:e,className:t,node:n,...o})=>jsx("h2",{className:f("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>P(e,t));ht.displayName="MarkdownH2";var bt=memo(({children:e,className:t,node:n,...o})=>jsx("h3",{className:f("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>P(e,t));bt.displayName="MarkdownH3";var yt=memo(({children:e,className:t,node:n,...o})=>jsx("h4",{className:f("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>P(e,t));yt.displayName="MarkdownH4";var wt=memo(({children:e,className:t,node:n,...o})=>jsx("h5",{className:f("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>P(e,t));wt.displayName="MarkdownH5";var kt=memo(({children:e,className:t,node:n,...o})=>jsx("h6",{className:f("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>P(e,t));kt.displayName="MarkdownH6";var vt=memo(({children:e,className:t,node:n,...o})=>{let{controls:s}=useContext(T),r=we(s,"table");return jsx(at,{className:t,"data-streamdown":"table-wrapper",showControls:r,...o,children:e})},(e,t)=>P(e,t));vt.displayName="MarkdownTable";var xt=memo(({children:e,className:t,node:n,...o})=>jsx("thead",{className:f("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>P(e,t));xt.displayName="MarkdownThead";var Ct=memo(({children:e,className:t,node:n,...o})=>jsx("tbody",{className:f("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>P(e,t));Ct.displayName="MarkdownTbody";var Mt=memo(({children:e,className:t,node:n,...o})=>jsx("tr",{className:f("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>P(e,t));Mt.displayName="MarkdownTr";var Pt=memo(({children:e,className:t,node:n,...o})=>jsx("th",{className:f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>P(e,t));Pt.displayName="MarkdownTh";var Tt=memo(({children:e,className:t,node:n,...o})=>jsx("td",{className:f("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>P(e,t));Tt.displayName="MarkdownTd";var Lt=memo(({children:e,className:t,node:n,...o})=>jsx("blockquote",{className:f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>P(e,t));Lt.displayName="MarkdownBlockquote";var Nt=memo(({children:e,className:t,node:n,...o})=>jsx("sup",{className:f("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>P(e,t));Nt.displayName="MarkdownSup";var Rt=memo(({children:e,className:t,node:n,...o})=>jsx("sub",{className:f("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>P(e,t));Rt.displayName="MarkdownSub";var St=memo(({children:e,className:t,node:n,...o})=>{if("data-footnotes"in o){let r=i=>{var p,g;if(!isValidElement(i))return false;let c=Array.isArray(i.props.children)?i.props.children:[i.props.children],d=false,m=false;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=true);else if(isValidElement(u))if(((p=u.props)==null?void 0:p["data-footnote-backref"])!==void 0)m=true;else {let h=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let y of h){if(typeof y=="string"&&y.trim()!==""){d=true;break}if(isValidElement(y)&&((g=y.props)==null?void 0:g["data-footnote-backref"])===void 0){d=true;break}}}}return m&&!d},l=Array.isArray(e)?e.map(i=>{if(!isValidElement(i))return i;if(i.type===ke){let d=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(m=>!r(m));return d.length===0?null:{...i,props:{...i.props,children:d}}}return i}):e;return (Array.isArray(l)?l.some(i=>i!==null):l!==null)?jsx("section",{className:t,...o,children:l}):null}return jsx("section",{className:t,...o,children:e})},(e,t)=>P(e,t));St.displayName="MarkdownSection";var Zo=({node:e,className:t,children:n,...o})=>{var m,p,g;let s=((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((p=e==null?void 0:e.position)==null?void 0:p.end.line),{mermaid:r,controls:l}=useContext(T);if(s)return jsx("code",{className:f("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...o,children:n});let a=t==null?void 0:t.match(zo),i=(g=a==null?void 0:a.at(1))!=null?g:"",c="";if(isValidElement(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?c=n.props.children:typeof n=="string"&&(c=n),i==="mermaid"){let u=we(l,"mermaid"),h=ie(l,"download"),y=ie(l,"copy"),k=ie(l,"fullscreen"),L=ie(l,"panZoom"),C=u&&(h||y||k);return jsx(Suspense,{fallback:jsx(ge,{}),children:jsxs("div",{className:f("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[C?jsxs("div",{className:"flex items-center justify-end gap-2",children:[h?jsx(Fe,{chart:c,config:r==null?void 0:r.config}):null,y?jsx(ue,{code:c}):null,k?jsx(Ke,{chart:c,config:r==null?void 0:r.config}):null]}):null,jsx($o,{chart:c,config:r==null?void 0:r.config,showControls:L})]})})}let d=we(l,"code");return jsx(Suspense,{fallback:jsx(ge,{}),children:jsx(qo,{className:f("overflow-x-auto border-border border-t",t),code:c,language:i,children:d?jsxs(Fragment,{children:[jsx(Ve,{code:c,language:i}),jsx(ue,{})]}):null})})},It=memo(Zo,(e,t)=>e.className===t.className&&le(e.node,t.node));It.displayName="MarkdownCode";var Et=memo(Oe,(e,t)=>e.className===t.className&&le(e.node,t.node));Et.displayName="MarkdownImg";var Dt=memo(({children:e,className:t,node:n,...o})=>{var l;let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");return r.length===1&&isValidElement(r[0])&&((l=r[0].props.node)==null?void 0:l.tagName)==="img"?jsx(Fragment,{children:e}):jsx("p",{className:t,...o,children:e})},(e,t)=>P(e,t));Dt.displayName="MarkdownParagraph";var Ht={ol:ke,li:dt,ul:mt,hr:pt,strong:ut,a:ft,h1:gt,h2:ht,h3:bt,h4:yt,h5:wt,h6:kt,table:vt,thead:xt,tbody:Ct,tr:Mt,th:Pt,td:Tt,blockquote:Lt,code:It,img:Et,pre:({children:e})=>e,sup:Nt,sub:Rt,p:Dt,section:St};var Bt=[],At={allowDangerousHtml:true},ce=new WeakMap,ve=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let n=this.keyCache.get(t);if(n)return n;let o=t.rehypePlugins,s=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(o||s||r)){let m="default";return this.keyCache.set(t,m),m}let l=m=>{if(!m||m.length===0)return "";let p="";for(let g=0;g<m.length;g+=1){let u=m[g];if(g>0&&(p+=","),Array.isArray(u)){let[h,y]=u;if(typeof h=="function"){let k=ce.get(h);k||(k=h.name,ce.set(h,k)),p+=k;}else p+=String(h);p+=":",p+=JSON.stringify(y);}else if(typeof u=="function"){let h=ce.get(u);h||(h=u.name,ce.set(u,h)),p+=h;}else p+=String(u);}return p},a=l(o),i=l(s),c=r?JSON.stringify(r):"",d=`${i}::${a}::${c}`;return this.keyCache.set(t,d),d}get(t){let n=this.generateCacheKey(t),o=this.cache.get(n);return o&&(this.cache.delete(n),this.cache.set(n,o)),o}set(t,n){let o=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let s=this.cache.keys().next().value;s&&this.cache.delete(s);}this.cache.set(o,n);}clear(){this.cache.clear();}},Vt=new ve,xe=e=>{let t=Go(e),n=e.children||"";return Qo(t.runSync(t.parse(n),n),e)},Go=e=>{let t=Vt.get(e);if(t)return t;let n=Yo(e);return Vt.set(e,n),n},Yo=e=>{let t=e.rehypePlugins||Bt,n=e.remarkPlugins||Bt,o=e.remarkRehypeOptions?{...At,...e.remarkRehypeOptions}:At;return unified().use(Xo).use(n).use(Jo,o).use(t)},Qo=(e,t)=>toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true});var tn=/\[\^[^\]\s]{1,200}\](?!:)/,on=/\[\^[^\]\s]{1,200}\]:/,nn=/<\/(\w+)>/,rn=/<(\w+)[\s>]/,Ce=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},sn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Me=e=>{let t=0;for(let n=0;n<e.length-1;n+=1)e[n]==="$"&&e[n+1]==="$"&&(t+=1,n+=1);return t},Pe=e=>{let t=tn.test(e),n=on.test(e);if(t||n)return [e];let o=Lexer.lex(e,{gfm:true}),s=[],r=[];for(let l of o){let a=l.raw,i=s.length;if(r.length>0){if(s[i-1]+=a,l.type==="html"){let d=a.match(nn);if(d){let m=d[1];r.at(-1)===m&&r.pop();}}continue}if(l.type==="html"&&l.block){let d=a.match(rn);if(d){let m=d[1];a.includes(`</${m}>`)||r.push(m);}}if(a.trim()==="$$"&&i>0){let d=s[i-1],m=Ce(d),p=Me(d);if(m&&p%2===1){s[i-1]=d+a;continue}}if(i>0&&sn(a)){let d=s[i-1],m=Ce(d),p=Me(d),g=Me(a);if(m&&p%2===1&&!Ce(a)&&g===1){s[i-1]=d+a;continue}}s.push(a);}return s};var ln=new Set(["\u3002","\uFF0E","\uFF0C","\u3001","\uFF1F","\uFF01","\uFF1A","\uFF1B","\uFF08","\uFF09","\u3010","\u3011","\u300C","\u300D","\u300E","\u300F","\u3008","\u3009","\u300A","\u300B"]),cn=/^(https?:\/\/|mailto:|www\.)/i,dn=e=>{if(e.children.length!==1)return false;let t=e.children[0];return t.type==="text"&&t.value===e.url},mn=e=>{let t=0;for(let n of e){if(ln.has(n))return t;t+=n.length;}return null},pn=(e,t)=>({...t,url:e,children:[{type:"text",value:e}]}),un=e=>({type:"text",value:e}),Ot=()=>e=>{visit(e,"link",(t,n,o)=>{if(!o||typeof n!="number"||!dn(t)||!cn.test(t.url))return;let s=mn(t.url);if(s===null||s===0)return;let r=t.url.slice(0,s),l=t.url.slice(s),a=pn(r,t),i=un(l);return o.children.splice(n,1,a,i),n+1});};var Ft={javascript:hn,typescript:xn,jsx:yn,tsx:vn,html:gn,css:fn,json:bn,bash:qt,shellscript:Wt,shell:Wt,sh:qt,yaml:_t,yml:_t,toml:kn,python:Zt,py:Zt,markdown:zt,md:zt,sql:wn,go:$t,golang:$t},Cn=e=>e in Ft;var jn=/[^$]\$[^$]/,Bn=/^\$[^$]/,An=/[^$]\$$/,Vn={raw:Rn,sanitize:[Sn,{}],katex:[Te,{errorColor:"var(--color-muted-foreground)"}],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},On={gfm:[Dn,{}],cjkAutolinkBoundary:[Ot,{}],math:[Le,{singleDollarTextMath:false}],cjkFriendly:[In,{}],cjkFriendlyGfmStrikethrough:[En,{}]},qn=Object.values(Vn),$n=Object.values(On),zn={block:" \u258B",circle:" \u25CF"},Jt="https://www.streamdown.ai/cdn",Zn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,cdnUrl:Jt},T=createContext(Zn),Kt=memo(({content:e,...t})=>jsx(xe,{...t,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let n=Object.keys(e.components||{}),o=Object.keys(t.components||{});if(n.length!==o.length||n.some(s=>{var r,l;return ((r=e.components)==null?void 0:r[s])!==((l=t.components)==null?void 0:l[s])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Kt.displayName="Block";var Wn=["github-light","github-dark"],_n=e=>Array.isArray(e)&&e.some(t=>Array.isArray(t)?t[0]===Te:t===Te),Fn=e=>{if(!Array.isArray(e))return false;let t=e.find(n=>Array.isArray(n)?n[0]===Le:n===Le);return t&&Array.isArray(t)&&t[1]?t[1].singleDollarTextMath===true:false},Un=(e,t)=>{let n=e.includes("$$"),o=t&&(jn.test(e)||Bn.test(e)||An.test(e));return n||o},Xn=/^\^/,Jn=e=>{let t=F.dependencies["rehype-katex"].replace(Xn,"").split(".")[0],o={7:"0.16.22"}[t]||"0.16.22",s=document.createElement("link");s.rel="stylesheet",s.href=`${e}/katex/${o}/katex.min.css`,document.head.appendChild(s);},Kn=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:n=true,components:o,rehypePlugins:s=qn,remarkPlugins:r=$n,className:l,shikiTheme:a=Wn,mermaid:i,controls:c=true,isAnimating:d=false,BlockComponent:m=Kt,parseMarkdownIntoBlocksFn:p=Pe,caret:g,cdnUrl:u=Jt,remend:h,...y})=>{let k=useId(),[L,C]=useTransition(),[M,E]=useState([]),R=useMemo(()=>typeof e!="string"?"":t==="streaming"&&n?Hn(e,h):e,[e,t,n,h]),S=useMemo(()=>p(R),[R,p]);useEffect(()=>{t==="streaming"?C(()=>{E(S);}):E(S);},[S,t]);let j=t==="streaming"?M:S,z=useMemo(()=>j.map((N,A)=>`${k}-${A}`),[j.length,k]),B=useMemo(()=>({shikiTheme:a,controls:c,isAnimating:d,mode:t,mermaid:i,cdnUrl:u}),[a,c,d,t,i,u]),D=useMemo(()=>({...Ht,...o}),[o]);useEffect(()=>{if(u===null||!_n(s))return;let A=Fn(r);Un(typeof e=="string"?e:"",A)&&Jn(u);},[s,r,e,u]);let w=useMemo(()=>g&&d?{"--streamdown-caret":`"${zn[g]}"`}:void 0,[g,d]);return t==="static"?jsx(T.Provider,{value:B,children:jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:jsx(xe,{components:D,rehypePlugins:s,remarkPlugins:r,...y,children:e})})}):jsx(T.Provider,{value:B,children:jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",g?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,l),style:w,children:j.map((N,A)=>jsx(m,{components:D,content:N,index:A,rehypePlugins:s,remarkPlugins:r,shouldParseIncompleteMarkdown:n,...y},z[A]))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode);Kn.displayName="Streamdown";var eo=({children:e,className:t,minZoom:n=.5,maxZoom:o=3,zoomStep:s=.1,showControls:r=true,initialZoom:l=1,fullscreen:a=false})=>{let i=useRef(null),c=useRef(null),[d,m]=useState(l),[p,g]=useState({x:0,y:0}),[u,h]=useState(false),[y,k]=useState({x:0,y:0}),[L,C]=useState({x:0,y:0}),M=useCallback(w=>{m(N=>Math.max(n,Math.min(o,N+w)));},[n,o]),E=useCallback(()=>{M(s);},[M,s]),R=useCallback(()=>{M(-s);},[M,s]),S=useCallback(()=>{m(l),g({x:0,y:0});},[l]),j=useCallback(w=>{w.preventDefault();let N=w.deltaY>0?-s:s;M(N);},[M,s]),z=useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;h(true),k({x:w.clientX,y:w.clientY}),C(p);let N=w.currentTarget;N instanceof HTMLElement&&N.setPointerCapture(w.pointerId);},[p]),B=useCallback(w=>{if(!u)return;w.preventDefault();let N=w.clientX-y.x,A=w.clientY-y.y;g({x:L.x+N,y:L.y+A});},[u,y,L]),D=useCallback(w=>{h(false);let N=w.currentTarget;N instanceof HTMLElement&&N.releasePointerCapture(w.pointerId);},[]);return useEffect(()=>{let w=i.current;if(w)return w.addEventListener("wheel",j,{passive:false}),()=>{w.removeEventListener("wheel",j);}},[j]),useEffect(()=>{let w=c.current;if(w&&u)return document.body.style.userSelect="none",w.addEventListener("pointermove",B,{passive:false}),w.addEventListener("pointerup",D),w.addEventListener("pointercancel",D),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",B),w.removeEventListener("pointerup",D),w.removeEventListener("pointercancel",D);}},[u,B,D]),jsxs("div",{className:f("relative flex flex-col",a?"h-full w-full":"min-h-28 w-full",t),ref:i,style:{cursor:u?"grabbing":"grab"},children:[r?jsxs("div",{className:f("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",a?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d>=o,onClick:E,title:"Zoom in",type:"button",children:jsx(De,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d<=n,onClick:R,title:"Zoom out",type:"button",children:jsx(He,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:S,title:"Reset zoom and pan",type:"button",children:jsx(Ie,{size:16})})]}):null,jsx("div",{className:f("flex-1 origin-center transition-transform duration-150 ease-out",a?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:z,ref:c,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var Je=({chart:e,className:t,config:n,fullscreen:o=false,showControls:s=true})=>{let[r,l]=useState(null),[a,i]=useState(false),[c,d]=useState(""),[m,p]=useState(""),[g,u]=useState(0),{mermaid:h,cdnUrl:y}=useContext(T),k=h==null?void 0:h.errorComponent,{shouldRender:L,containerRef:C}=Ne({immediate:o});if(useEffect(()=>{if(!L)return;(async()=>{try{l(null),i(!0);let R=await te(n,y),S=e.split("").reduce((B,D)=>(B<<5)-B+D.charCodeAt(0)|0,0),j=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:z}=await R.render(j,e);d(z),p(z);}catch(R){if(!(m||c)){let S=R instanceof Error?R.message:"Failed to render Mermaid chart";l(S);}}finally{i(false);}})();},[e,n,g,L,y]),!(L||c||m))return jsx("div",{className:f("my-4 min-h-[200px]",t),ref:C});if(a&&!c&&!m)return jsx("div",{className:f("my-4 flex justify-center p-4",t),ref:C,children:jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!c&&!m){let E=()=>u(R=>R+1);return k?jsx("div",{ref:C,children:jsx(k,{chart:e,error:r,retry:E})}):jsxs("div",{className:f("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:C,children:[jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),jsxs("details",{className:"mt-2",children:[jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let M=c||m;return jsx("div",{className:"size-full",ref:C,children:jsx(eo,{className:f(o?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:o,maxZoom:3,minZoom:.5,showControls:s,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:f("flex justify-center",o?"size-full items-center":null),dangerouslySetInnerHTML:{__html:M},role:"img"})})})};
|
|
11
|
+
export{f as a,po as b,F as c,Je as d,Ft as e,Cn as f,Pe as g,Vn as h,On as i,T as j,Kt as k,Kn as l};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {createContext,lazy,memo,useContext,isValidElement,useId,useTransition,useState,useMemo,useEffect,Suspense,useRef,useCallback}from'react';import {harden}from'rehype-harden';import Te from'rehype-katex';import Rn from'rehype-raw';import Sn from'rehype-sanitize';import In from'remark-cjk-friendly';import En from'remark-cjk-friendly-gfm-strikethrough';import Dn from'remark-gfm';import Le from'remark-math';import Hn from'remend';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import Xo from'remark-parse';import Jo from'remark-rehype';import {unified}from'unified';import {Lexer}from'marked';import {visit}from'unist-util-visit';import qt from'shiki/langs/bash.mjs';import fn from'shiki/langs/css.mjs';import $t from'shiki/langs/go.mjs';import gn from'shiki/langs/html.mjs';import bn from'shiki/langs/javascript.mjs';import hn from'shiki/langs/json.mjs';import yn from'shiki/langs/jsx.mjs';import zt from'shiki/langs/markdown.mjs';import Zt from'shiki/langs/python.mjs';import Wt from'shiki/langs/shellscript.mjs';import wn from'shiki/langs/sql.mjs';import kn from'shiki/langs/toml.mjs';import vn from'shiki/langs/tsx.mjs';import xn from'shiki/langs/typescript.mjs';import _t from'shiki/langs/yaml.mjs';var no=300,ro="300px",so=500;function Ne(e={}){let{immediate:t=false,debounceDelay:n=no,rootMargin:o=ro,idleTimeout:s=so}=e,[r,l]=useState(false),a=useRef(null),i=useRef(null),c=useRef(null),d=useMemo(()=>g=>{let u=Date.now();return window.setTimeout(()=>{g({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-u))});},1)},[]),m=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(g,u)=>window.requestIdleCallback(g,u):d,[d]),p=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?g=>window.cancelIdleCallback(g):g=>{clearTimeout(g);},[]);return useEffect(()=>{if(t){l(true);return}let g=a.current;if(!g)return;i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);let u=()=>{i.current&&(clearTimeout(i.current),i.current=null),c.current&&(p(c.current),c.current=null);},b=C=>{c.current=m(M=>{M.timeRemaining()>0||M.didTimeout?(l(true),C.disconnect()):c.current=m(()=>{l(true),C.disconnect();},{timeout:s/2});},{timeout:s});},y=C=>{u(),i.current=window.setTimeout(()=>{var R,S;let M=C.takeRecords();(M.length===0||(S=(R=M.at(-1))==null?void 0:R.isIntersecting)!=null&&S)&&b(C);},n);},k=(C,M)=>{C.isIntersecting?y(M):u();},L=new IntersectionObserver(C=>{for(let M of C)k(M,L);},{rootMargin:o,threshold:0});return L.observe(g),()=>{i.current&&clearTimeout(i.current),c.current&&p(c.current),L.disconnect();}},[t,n,o,s,p,m]),{shouldRender:r,containerRef:a}}var G=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})}),Y=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M2.75 0.5C1.7835 0.5 1 1.2835 1 2.25V9.75C1 10.7165 1.7835 11.5 2.75 11.5H3.75H4.5V10H3.75H2.75C2.61193 10 2.5 9.88807 2.5 9.75V2.25C2.5 2.11193 2.61193 2 2.75 2H8.25C8.38807 2 8.5 2.11193 8.5 2.25V3H10V2.25C10 1.2835 9.2165 0.5 8.25 0.5H2.75ZM7.75 4.5C6.7835 4.5 6 5.2835 6 6.25V13.75C6 14.7165 6.7835 15.5 7.75 15.5H13.25C14.2165 15.5 15 14.7165 15 13.75V6.25C15 5.2835 14.2165 4.5 13.25 4.5H7.75ZM7.5 6.25C7.5 6.11193 7.61193 6 7.75 6H13.25C13.3881 6 13.5 6.11193 13.5 6.25V13.75C13.5 13.8881 13.3881 14 13.25 14H7.75C7.61193 14 7.5 13.8881 7.5 13.75V6.25Z",fill:"currentColor",fillRule:"evenodd"})}),V=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M8.75 1V1.75V8.68934L10.7197 6.71967L11.25 6.18934L12.3107 7.25L11.7803 7.78033L8.70711 10.8536C8.31658 11.2441 7.68342 11.2441 7.29289 10.8536L4.21967 7.78033L3.68934 7.25L4.75 6.18934L5.28033 6.71967L7.25 8.68934V1.75V1H8.75ZM13.5 9.25V13.5H2.5V9.25V8.5H1V9.25V14C1 14.5523 1.44771 15 2 15H14C14.5523 15 15 14.5523 15 14V9.25V8.5H13.5V9.25Z",fill:"currentColor",fillRule:"evenodd"})}),Re=e=>jsxs("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:[jsx("path",{d:"M8 0V4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M8 16V12",opacity:"0.5",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 1.52783L5.64887 4.7639",opacity:"0.9",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 1.52783L10.3511 4.7639",opacity:"0.1",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M12.7023 14.472L10.3511 11.236",opacity:"0.4",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M3.29773 14.472L5.64887 11.236",opacity:"0.6",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 5.52783L11.8043 6.7639",opacity:"0.2",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 10.472L4.19583 9.23598",opacity:"0.7",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M15.6085 10.4722L11.8043 9.2361",opacity:"0.3",stroke:"currentColor",strokeWidth:"1.5"}),jsx("path",{d:"M0.391602 5.52783L4.19583 6.7639",opacity:"0.8",stroke:"currentColor",strokeWidth:"1.5"})]}),Se=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M1 5.25V6H2.5V5.25V2.5H5.25H6V1H5.25H2C1.44772 1 1 1.44772 1 2V5.25ZM5.25 14.9994H6V13.4994H5.25H2.5V10.7494V9.99939H1V10.7494V13.9994C1 14.5517 1.44772 14.9994 2 14.9994H5.25ZM15 10V10.75V14C15 14.5523 14.5523 15 14 15H10.75H10V13.5H10.75H13.5V10.75V10H15ZM10.75 1H10V2.5H10.75H13.5V5.25V6H15V5.25V2C15 1.44772 14.5523 1 14 1H10.75Z",fill:"currentColor",fillRule:"evenodd"})}),Ie=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M13.5 8C13.5 4.96643 11.0257 2.5 7.96452 2.5C5.42843 2.5 3.29365 4.19393 2.63724 6.5H5.25H6V8H5.25H0.75C0.335787 8 0 7.66421 0 7.25V2.75V2H1.5V2.75V5.23347C2.57851 2.74164 5.06835 1 7.96452 1C11.8461 1 15 4.13001 15 8C15 11.87 11.8461 15 7.96452 15C5.62368 15 3.54872 13.8617 2.27046 12.1122L1.828 11.5066L3.03915 10.6217L3.48161 11.2273C4.48831 12.6051 6.12055 13.5 7.96452 13.5C11.0257 13.5 13.5 11.0336 13.5 8Z",fill:"currentColor",fillRule:"evenodd"})}),Ee=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M12.4697 13.5303L13 14.0607L14.0607 13L13.5303 12.4697L9.06065 7.99999L13.5303 3.53032L14.0607 2.99999L13 1.93933L12.4697 2.46966L7.99999 6.93933L3.53032 2.46966L2.99999 1.93933L1.93933 2.99999L2.46966 3.53032L6.93933 7.99999L2.46966 12.4697L1.93933 13L2.99999 14.0607L3.53032 13.5303L7.99999 9.06065L12.4697 13.5303Z",fill:"currentColor",fillRule:"evenodd"})}),De=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M1.5 6.5C1.5 3.73858 3.73858 1.5 6.5 1.5C9.26142 1.5 11.5 3.73858 11.5 6.5C11.5 9.26142 9.26142 11.5 6.5 11.5C3.73858 11.5 1.5 9.26142 1.5 6.5ZM6.5 0C2.91015 0 0 2.91015 0 6.5C0 10.0899 2.91015 13 6.5 13C8.02469 13 9.42677 12.475 10.5353 11.596L13.9697 15.0303L14.5 15.5607L15.5607 14.5L15.0303 13.9697L11.596 10.5353C12.475 9.42677 13 8.02469 13 6.5C13 2.91015 10.0899 0 6.5 0ZM4.125 5.875H4.75H5.875V4.75V4.125H7.125V4.75V5.875H8.25H8.875V7.125H8.25H7.125V8.25V8.875H5.875V8.25V7.125H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})}),He=e=>jsx("svg",{color:"currentColor",strokeLinejoin:"round",viewBox:"0 0 16 16",...e,children:jsx("path",{clipRule:"evenodd",d:"M15.5607 3.99999L15.0303 4.53032L6.23744 13.3232C5.55403 14.0066 4.44599 14.0066 3.76257 13.3232L4.2929 12.7929L3.76257 13.3232L0.969676 10.5303L0.439346 9.99999L1.50001 8.93933L2.03034 9.46966L4.82323 12.2626C4.92086 12.3602 5.07915 12.3602 5.17678 12.2626L13.9697 3.46966L14.5 2.93933L15.5607 3.99999Z",fill:"currentColor",fillRule:"evenodd"})});var f=(...e)=>twMerge(clsx(e)),H=(e,t,n)=>{let o=typeof t=="string"?new Blob([t],{type:n}):t,s=URL.createObjectURL(o),r=document.createElement("a");r.href=s,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s);};var po=createContext({code:""}),Q=()=>useContext(po);var ue=({onCopy:e,onError:t,timeout:n=2e3,children:o,className:s,code:r,...l})=>{let[a,i]=useState(false),c=useRef(0),{code:d}=Q(),{isAnimating:m}=useContext(T),p=r!=null?r:d,g=async()=>{var b;if(typeof window=="undefined"||!((b=navigator==null?void 0:navigator.clipboard)!=null&&b.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{a||(await navigator.clipboard.writeText(p),i(!0),e==null||e(),c.current=window.setTimeout(()=>i(!1),n));}catch(y){t==null||t(y);}};useEffect(()=>()=>{window.clearTimeout(c.current);},[]);let u=a?G:Y;return jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-copy-button",disabled:m,onClick:g,title:"Copy Code",type:"button",...l,children:o!=null?o:jsx(u,{size:14})})};var Be={"1c":"1c","1c-query":"1cq",abap:"abap","actionscript-3":"as",ada:"ada",adoc:"adoc","angular-html":"html","angular-ts":"ts",apache:"conf",apex:"cls",apl:"apl",applescript:"applescript",ara:"ara",asciidoc:"adoc",asm:"asm",astro:"astro",awk:"awk",ballerina:"bal",bash:"sh",bat:"bat",batch:"bat",be:"be",beancount:"beancount",berry:"berry",bibtex:"bib",bicep:"bicep",blade:"blade.php",bsl:"bsl",c:"c","c#":"cs","c++":"cpp",cadence:"cdc",cairo:"cairo",cdc:"cdc",clarity:"clar",clj:"clj",clojure:"clj","closure-templates":"soy",cmake:"cmake",cmd:"cmd",cobol:"cob",codeowners:"CODEOWNERS",codeql:"ql",coffee:"coffee",coffeescript:"coffee","common-lisp":"lisp",console:"sh",coq:"v",cpp:"cpp",cql:"cql",crystal:"cr",cs:"cs",csharp:"cs",css:"css",csv:"csv",cue:"cue",cypher:"cql",d:"d",dart:"dart",dax:"dax",desktop:"desktop",diff:"diff",docker:"dockerfile",dockerfile:"dockerfile",dotenv:"env","dream-maker":"dm",edge:"edge",elisp:"el",elixir:"ex",elm:"elm","emacs-lisp":"el",erb:"erb",erl:"erl",erlang:"erl",f:"f","f#":"fs",f03:"f03",f08:"f08",f18:"f18",f77:"f77",f90:"f90",f95:"f95",fennel:"fnl",fish:"fish",fluent:"ftl",for:"for","fortran-fixed-form":"f","fortran-free-form":"f90",fs:"fs",fsharp:"fs",fsl:"fsl",ftl:"ftl",gdresource:"tres",gdscript:"gd",gdshader:"gdshader",genie:"gs",gherkin:"feature","git-commit":"gitcommit","git-rebase":"gitrebase",gjs:"js",gleam:"gleam","glimmer-js":"js","glimmer-ts":"ts",glsl:"glsl",gnuplot:"plt",go:"go",gql:"gql",graphql:"graphql",groovy:"groovy",gts:"gts",hack:"hack",haml:"haml",handlebars:"hbs",haskell:"hs",haxe:"hx",hbs:"hbs",hcl:"hcl",hjson:"hjson",hlsl:"hlsl",hs:"hs",html:"html","html-derivative":"html",http:"http",hxml:"hxml",hy:"hy",imba:"imba",ini:"ini",jade:"jade",java:"java",javascript:"js",jinja:"jinja",jison:"jison",jl:"jl",js:"js",json:"json",json5:"json5",jsonc:"jsonc",jsonl:"jsonl",jsonnet:"jsonnet",jssm:"jssm",jsx:"jsx",julia:"jl",kotlin:"kt",kql:"kql",kt:"kt",kts:"kts",kusto:"kql",latex:"tex",lean:"lean",lean4:"lean",less:"less",liquid:"liquid",lisp:"lisp",lit:"lit",llvm:"ll",log:"log",logo:"logo",lua:"lua",luau:"luau",make:"mak",makefile:"mak",markdown:"md",marko:"marko",matlab:"m",md:"md",mdc:"mdc",mdx:"mdx",mediawiki:"wiki",mermaid:"mmd",mips:"s",mipsasm:"s",mmd:"mmd",mojo:"mojo",move:"move",nar:"nar",narrat:"narrat",nextflow:"nf",nf:"nf",nginx:"conf",nim:"nim",nix:"nix",nu:"nu",nushell:"nu",objc:"m","objective-c":"m","objective-cpp":"mm",ocaml:"ml",pascal:"pas",perl:"pl",perl6:"p6",php:"php",plsql:"pls",po:"po",polar:"polar",postcss:"pcss",pot:"pot",potx:"potx",powerquery:"pq",powershell:"ps1",prisma:"prisma",prolog:"pl",properties:"properties",proto:"proto",protobuf:"proto",ps:"ps",ps1:"ps1",pug:"pug",puppet:"pp",purescript:"purs",py:"py",python:"py",ql:"ql",qml:"qml",qmldir:"qmldir",qss:"qss",r:"r",racket:"rkt",raku:"raku",razor:"cshtml",rb:"rb",reg:"reg",regex:"regex",regexp:"regexp",rel:"rel",riscv:"s",rs:"rs",rst:"rst",ruby:"rb",rust:"rs",sas:"sas",sass:"sass",scala:"scala",scheme:"scm",scss:"scss",sdbl:"sdbl",sh:"sh",shader:"shader",shaderlab:"shader",shell:"sh",shellscript:"sh",shellsession:"sh",smalltalk:"st",solidity:"sol",soy:"soy",sparql:"rq",spl:"spl",splunk:"spl",sql:"sql","ssh-config":"config",stata:"do",styl:"styl",stylus:"styl",svelte:"svelte",swift:"swift","system-verilog":"sv",systemd:"service",talon:"talon",talonscript:"talon",tasl:"tasl",tcl:"tcl",templ:"templ",terraform:"tf",tex:"tex",tf:"tf",tfvars:"tfvars",toml:"toml",ts:"ts","ts-tags":"ts",tsp:"tsp",tsv:"tsv",tsx:"tsx",turtle:"ttl",twig:"twig",typ:"typ",typescript:"ts",typespec:"tsp",typst:"typ",v:"v",vala:"vala",vb:"vb",verilog:"v",vhdl:"vhdl",vim:"vim",viml:"vim",vimscript:"vim",vue:"vue","vue-html":"html","vue-vine":"vine",vy:"vy",vyper:"vy",wasm:"wasm",wenyan:"wy",wgsl:"wgsl",wiki:"wiki",wikitext:"wiki",wit:"wit",wl:"wl",wolfram:"wl",xml:"xml",xsl:"xsl",yaml:"yaml",yml:"yml",zenscript:"zs",zig:"zig",zsh:"zsh",\u6587\u8A00:"wy"},Ve=({onDownload:e,onError:t,language:n,children:o,className:s,code:r,...l})=>{let{code:a}=Q(),{isAnimating:i}=useContext(T),c=r!=null?r:a,m=`file.${n&&n in Be?Be[n]:"txt"}`,p="text/plain",g=()=>{try{H(m,c,p),e==null||e();}catch(u){t==null||t(u);}};return jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),"data-streamdown":"code-block-download-button",disabled:i,onClick:g,title:"Download file",type:"button",...l,children:o!=null?o:jsx(V,{size:14})})};var ge=()=>jsxs("div",{className:"w-full divide-y divide-border overflow-hidden rounded-xl border border-border",children:[jsx("div",{className:"h-[46px] w-full bg-muted/80"}),jsx("div",{className:"flex w-full items-center justify-center p-4",children:jsx(Re,{className:"size-4 animate-spin"})})]});var wo=/\.[^/.]+$/,Oe=({node:e,className:t,src:n,alt:o,...s})=>{let r=async()=>{if(n)try{let a=await(await fetch(n)).blob(),c=new URL(n,window.location.origin).pathname.split("/").pop()||"",d=c.split(".").pop(),m=c.includes(".")&&d!==void 0&&d.length<=4,p="";if(m)p=c;else {let g=a.type,u="png";g.includes("jpeg")||g.includes("jpg")?u="jpg":g.includes("png")?u="png":g.includes("svg")?u="svg":g.includes("gif")?u="gif":g.includes("webp")&&(u="webp"),p=`${(o||c||"image").replace(wo,"")}.${u}`;}H(p,a,a.type);}catch(l){console.error("Failed to download image:",l);}};return n?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:o,className:f("max-w-full rounded-lg",t),"data-streamdown":"image",src:n,...s}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsx("button",{className:f("absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background","opacity-0 group-hover:opacity-100"),onClick:r,title:"Download image",type:"button",children:jsx(V,{size:14})})]}):null};var F={name:"streamdown",version:"2.0.0-canary.1",type:"module",main:"./dist/index.js",module:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{types:"./dist/index.d.ts",import:"./dist/index.js",require:"./dist/index.cjs"}},files:["dist","README.md"],homepage:"https://streamdown.ai",repository:{type:"git",url:"git+https://github.com/vercel/streamdown.git",directory:"packages/streamdown"},scripts:{build:"tsup",postbuild:"node scripts/postbuild.js",test:"vitest run","test:ui":"vitest --ui run","test:coverage":"vitest --coverage run",bench:"vitest bench --run > results.txt","bench:ui":"vitest bench --ui --run",size:"node scripts/bundle-size.js"},author:"Hayden Bleasel <hayden.bleasel@vercel.com>",license:"Apache-2.0",description:"A drop-in replacement for react-markdown, designed for AI-powered streaming.",devDependencies:{"@testing-library/jest-dom":"^6.9.1","@testing-library/react":"^16.3.0","@types/hast":"^3.0.4","@types/react":"^19.2.7","@types/react-dom":"^19.2.3","@vitejs/plugin-react":"^5.1.2","@vitest/coverage-v8":"^4.0.15",jsdom:"^27.3.0",mermaid:"^11.12.2",react:"^19.2.1","react-dom":"^19.2.1","react-markdown":"^10.1.0",tsup:"^8.5.1",vitest:"^4.0.15"},peerDependencies:{react:"^18.0.0 || ^19.0.0"},dependencies:{clsx:"^2.1.1",esbuild:"^0.27.2","hast-util-to-jsx-runtime":"^2.3.6","html-url-attributes":"^3.0.1",katex:"^0.16.27",marked:"^17.0.1","rehype-harden":"^1.1.7","rehype-katex":"^7.0.1","rehype-raw":"^7.0.0","rehype-sanitize":"^6.0.0","remark-cjk-friendly":"^1.2.3","remark-cjk-friendly-gfm-strikethrough":"^1.2.3","remark-gfm":"^4.0.1","remark-math":"^6.0.0","remark-parse":"^11.0.0","remark-rehype":"^11.1.2",remend:"workspace:*",shiki:"^3.19.0","tailwind-merge":"^3.4.0",unified:"^11.0.5","unist-util-visit":"^5.0.0"}};var qe,$e,ze,Ze,xo=((Ze=(ze=(qe=F.dependencies)==null?void 0:qe.mermaid)!=null?ze:($e=F.devDependencies)==null?void 0:$e.mermaid)!=null?Ze:"11").replace(/^\^/,""),Co=e=>`${e}/mermaid/${xo}/mermaid.esm.min.mjs`,be=new Map,Mo=new Function("url","return import(url)"),te=async(e,t)=>{let o={...{startOnLoad:false,theme:"default",securityLevel:"strict",fontFamily:"monospace",suppressErrorRendering:true},...e};if(t==null)throw new Error("[Streamdown] Mermaid requires a CDN URL to load. Please provide a cdnUrl prop.");let s=Co(t);if(!be.has(s)){let a=await Mo(s);be.set(s,a);}let l=be.get(s).default;return l.initialize(o),l},We=(e,t)=>{var o;let n=(o=void 0)!=null?o:5;return new Promise((s,r)=>{let l="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),a=new Image;a.crossOrigin="anonymous",a.onload=()=>{let i=document.createElement("canvas"),c=a.width*n,d=a.height*n;i.width=c,i.height=d;let m=i.getContext("2d");if(!m){r(new Error("Failed to create 2D canvas context for PNG export"));return}m.drawImage(a,0,0,c,d),i.toBlob(p=>{if(!p){r(new Error("Failed to create PNG blob"));return}s(p);},"image/png");},a.onerror=()=>r(new Error("Failed to load SVG image")),a.src=l;})};var Fe=({chart:e,children:t,className:n,onDownload:o,config:s,onError:r})=>{let[l,a]=useState(false),i=useRef(null),{isAnimating:c}=useContext(T),d=async m=>{try{if(m==="mmd"){H("diagram.mmd",e,"text/plain"),a(!1),o==null||o(m);return}let p=await te(s),g=e.split("").reduce((y,k)=>(y<<5)-y+k.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(g)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:b}=await p.render(u,e);if(!b){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){H("diagram.svg",b,"image/svg+xml"),a(!1),o==null||o(m);return}if(m==="png"){let y=await We(b);H("diagram.png",y,"image/png"),o==null||o(m),a(!1);return}}catch(p){r==null||r(p);}};return useEffect(()=>{let m=p=>{i.current&&!i.current.contains(p.target)&&a(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:"relative",ref:i,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",n),disabled:c,onClick:()=>a(!l),title:"Download diagram",type:"button",children:t!=null?t:jsx(V,{size:14})}),l?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("svg"),title:"Download diagram as SVG",type:"button",children:"SVG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("png"),title:"Download diagram as PNG",type:"button",children:"PNG"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>d("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var X=0,Io=()=>{X+=1,X===1&&(document.body.style.overflow="hidden");},Eo=()=>{X=Math.max(0,X-1),X===0&&(document.body.style.overflow="");},Ke=({chart:e,config:t,onFullscreen:n,onExit:o,className:s,...r})=>{let[l,a]=useState(false),{isAnimating:i,controls:c}=useContext(T),d=(()=>{if(typeof c=="boolean")return c;let p=c.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),m=()=>{a(!l);};return useEffect(()=>{if(l){Io();let p=g=>{g.key==="Escape"&&a(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),Eo();}}},[l]),useEffect(()=>{l?n==null||n():o&&o();},[l,n,o]),jsxs(Fragment,{children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",s),disabled:i,onClick:m,title:"View fullscreen",type:"button",...r,children:jsx(Se,{size:14})}),l?jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:m,onKeyDown:p=>{p.key==="Escape"&&m();},role:"button",tabIndex:0,children:[jsx("button",{className:"absolute top-4 right-4 z-10 rounded-md p-2 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:m,title:"Exit fullscreen",type:"button",children:jsx(Ee,{size:20})}),jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.stopPropagation(),role:"presentation",children:jsx(Je,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var oe=e=>{var r,l;let t=[],n=[],o=e.querySelectorAll("thead th");for(let a of o)t.push(((r=a.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let a of s){let i=[],c=a.querySelectorAll("td");for(let d of c)i.push(((l=d.textContent)==null?void 0:l.trim())||"");n.push(i);}return {headers:t,rows:n}},ne=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false,c=false;for(let d of a){if(d==='"'){i=true,c=true;break}(d===","||d===`
|
|
3
|
+
`)&&(i=true);}return i?c?`"${a.replace(/"/g,'""')}"`:`"${a}"`:a},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(","),l+=1);for(let a of n)r[l]=a.map(o).join(","),l+=1;return r.join(`
|
|
4
|
+
`)},Ge=e=>{let{headers:t,rows:n}=e,o=a=>{let i=false;for(let d of a)if(d===" "||d===`
|
|
5
|
+
`||d==="\r"){i=true;break}if(!i)return a;let c=[];for(let d of a)d===" "?c.push("\\t"):d===`
|
|
6
|
+
`?c.push("\\n"):d==="\r"?c.push("\\r"):c.push(d);return c.join("")},s=t.length>0?n.length+1:n.length,r=new Array(s),l=0;t.length>0&&(r[l]=t.map(o).join(" "),l+=1);for(let a of n)r[l]=a.map(o).join(" "),l+=1;return r.join(`
|
|
7
|
+
`)},he=e=>{let t=false;for(let o of e)if(o==="\\"||o==="|"){t=true;break}if(!t)return e;let n=[];for(let o of e)o==="\\"?n.push("\\\\"):o==="|"?n.push("\\|"):n.push(o);return n.join("")},Ye=e=>{let{headers:t,rows:n}=e;if(t.length===0)return "";let o=new Array(n.length+2),s=0,r=t.map(a=>he(a));o[s]=`| ${r.join(" | ")} |`,s+=1;let l=new Array(t.length);for(let a=0;a<t.length;a+=1)l[a]="---";o[s]=`| ${l.join(" | ")} |`,s+=1;for(let a of n)if(a.length<t.length){let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]=c<a.length?he(a[c]):"";o[s]=`| ${i.join(" | ")} |`,s+=1;}else {let i=a.map(c=>he(c));o[s]=`| ${i.join(" | ")} |`,s+=1;}return o.join(`
|
|
8
|
+
`)};var ot=({children:e,className:t,onCopy:n,onError:o,timeout:s=2e3})=>{let[r,l]=useState(false),[a,i]=useState(false),c=useRef(null),d=useRef(0),{isAnimating:m}=useContext(T),p=async u=>{var b,y;if(typeof window=="undefined"||!((b=navigator==null?void 0:navigator.clipboard)!=null&&b.write)){o==null||o(new Error("Clipboard API not available"));return}try{let k=(y=c.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),L=k==null?void 0:k.querySelector("table");if(!L){o==null||o(new Error("Table not found"));return}let C=oe(L),M=u==="csv"?ne(C):Ge(C),E=new ClipboardItem({"text/plain":new Blob([M],{type:"text/plain"}),"text/html":new Blob([L.outerHTML],{type:"text/html"})});await navigator.clipboard.write([E]),i(!0),l(!1),n==null||n(u),d.current=window.setTimeout(()=>i(!1),s);}catch(k){o==null||o(k);}};useEffect(()=>{let u=b=>{c.current&&!c.current.contains(b.target)&&l(false);};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current);}},[]);let g=a?G:Y;return jsxs("div",{className:"relative",ref:c,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:m,onClick:()=>l(!r),title:"Copy table",type:"button",children:e!=null?e:jsx(g,{size:14})}),r?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("csv"),title:"Copy table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>p("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var rt=({children:e,className:t,onDownload:n,onError:o})=>{let[s,r]=useState(false),l=useRef(null),{isAnimating:a}=useContext(T),i=c=>{var d;try{let m=(d=l.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),p=m==null?void 0:m.querySelector("table");if(!p){o==null||o(new Error("Table not found"));return}let g=oe(p),u=c==="csv"?ne(g):Ye(g);H(`table.${c==="csv"?"csv":"md"}`,u,c==="csv"?"text/csv":"text/markdown"),r(!1),n==null||n(c);}catch(m){o==null||o(m);}};return useEffect(()=>{let c=d=>{l.current&&!l.current.contains(d.target)&&r(false);};return document.addEventListener("mousedown",c),()=>{document.removeEventListener("mousedown",c);}},[]),jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:a,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:jsx(V,{size:14})}),s?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("csv"),title:"Download table as CSV",type:"button",children:"CSV"}),jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>i("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var at=({children:e,className:t,showControls:n,...o})=>jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[n?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(ot,{}),jsx(rt,{})]}):null,jsx("div",{className:"overflow-x-auto",children:jsx("table",{className:f("w-full border-collapse border border-border",t),"data-streamdown":"table",...o,children:e})})]});var qo=lazy(()=>import('./code-block-TTK2QWKF.js').then(e=>({default:e.CodeBlock}))),$o=lazy(()=>import('./mermaid-4NEPLM7L.js').then(e=>({default:e.Mermaid}))),zo=/language-([^\s]+)/;function le(e,t){if(!(e!=null&&e.position||t!=null&&t.position))return true;if(!(e!=null&&e.position&&(t!=null&&t.position)))return false;let n=e.position.start,o=t.position.start,s=e.position.end,r=t.position.end;return (n==null?void 0:n.line)===(o==null?void 0:o.line)&&(n==null?void 0:n.column)===(o==null?void 0:o.column)&&(s==null?void 0:s.line)===(r==null?void 0:r.line)&&(s==null?void 0:s.column)===(r==null?void 0:r.column)}function P(e,t){return e.className===t.className&&le(e.node,t.node)}var we=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ie=(e,t)=>{if(typeof e=="boolean")return e;let n=e.mermaid;return n===false?false:n===true||n===void 0?true:n[t]!==false},ke=memo(({children:e,className:t,node:n,...o})=>jsx("ol",{className:f("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...o,children:e}),(e,t)=>P(e,t));ke.displayName="MarkdownOl";var dt=memo(({children:e,className:t,node:n,...o})=>jsx("li",{className:f("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...o,children:e}),(e,t)=>e.className===t.className&&le(e.node,t.node));dt.displayName="MarkdownLi";var mt=memo(({children:e,className:t,node:n,...o})=>jsx("ul",{className:f("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...o,children:e}),(e,t)=>P(e,t));mt.displayName="MarkdownUl";var pt=memo(({className:e,node:t,...n})=>jsx("hr",{className:f("my-6 border-border",e),"data-streamdown":"horizontal-rule",...n}),(e,t)=>P(e,t));pt.displayName="MarkdownHr";var ut=memo(({children:e,className:t,node:n,...o})=>jsx("span",{className:f("font-semibold",t),"data-streamdown":"strong",...o,children:e}),(e,t)=>P(e,t));ut.displayName="MarkdownStrong";var ft=memo(({children:e,className:t,href:n,node:o,...s})=>{let r=n==="streamdown:incomplete-link";return jsx("a",{className:f("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":r,"data-streamdown":"link",href:n,rel:"noreferrer",target:"_blank",...s,children:e})},(e,t)=>P(e,t)&&e.href===t.href);ft.displayName="MarkdownA";var gt=memo(({children:e,className:t,node:n,...o})=>jsx("h1",{className:f("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...o,children:e}),(e,t)=>P(e,t));gt.displayName="MarkdownH1";var bt=memo(({children:e,className:t,node:n,...o})=>jsx("h2",{className:f("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...o,children:e}),(e,t)=>P(e,t));bt.displayName="MarkdownH2";var ht=memo(({children:e,className:t,node:n,...o})=>jsx("h3",{className:f("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...o,children:e}),(e,t)=>P(e,t));ht.displayName="MarkdownH3";var yt=memo(({children:e,className:t,node:n,...o})=>jsx("h4",{className:f("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...o,children:e}),(e,t)=>P(e,t));yt.displayName="MarkdownH4";var wt=memo(({children:e,className:t,node:n,...o})=>jsx("h5",{className:f("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...o,children:e}),(e,t)=>P(e,t));wt.displayName="MarkdownH5";var kt=memo(({children:e,className:t,node:n,...o})=>jsx("h6",{className:f("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...o,children:e}),(e,t)=>P(e,t));kt.displayName="MarkdownH6";var vt=memo(({children:e,className:t,node:n,...o})=>{let{controls:s}=useContext(T),r=we(s,"table");return jsx(at,{className:t,"data-streamdown":"table-wrapper",showControls:r,...o,children:e})},(e,t)=>P(e,t));vt.displayName="MarkdownTable";var xt=memo(({children:e,className:t,node:n,...o})=>jsx("thead",{className:f("bg-muted/80",t),"data-streamdown":"table-header",...o,children:e}),(e,t)=>P(e,t));xt.displayName="MarkdownThead";var Ct=memo(({children:e,className:t,node:n,...o})=>jsx("tbody",{className:f("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...o,children:e}),(e,t)=>P(e,t));Ct.displayName="MarkdownTbody";var Mt=memo(({children:e,className:t,node:n,...o})=>jsx("tr",{className:f("border-border border-b",t),"data-streamdown":"table-row",...o,children:e}),(e,t)=>P(e,t));Mt.displayName="MarkdownTr";var Pt=memo(({children:e,className:t,node:n,...o})=>jsx("th",{className:f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...o,children:e}),(e,t)=>P(e,t));Pt.displayName="MarkdownTh";var Tt=memo(({children:e,className:t,node:n,...o})=>jsx("td",{className:f("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...o,children:e}),(e,t)=>P(e,t));Tt.displayName="MarkdownTd";var Lt=memo(({children:e,className:t,node:n,...o})=>jsx("blockquote",{className:f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...o,children:e}),(e,t)=>P(e,t));Lt.displayName="MarkdownBlockquote";var Nt=memo(({children:e,className:t,node:n,...o})=>jsx("sup",{className:f("text-sm",t),"data-streamdown":"superscript",...o,children:e}),(e,t)=>P(e,t));Nt.displayName="MarkdownSup";var Rt=memo(({children:e,className:t,node:n,...o})=>jsx("sub",{className:f("text-sm",t),"data-streamdown":"subscript",...o,children:e}),(e,t)=>P(e,t));Rt.displayName="MarkdownSub";var St=memo(({children:e,className:t,node:n,...o})=>{if("data-footnotes"in o){let r=i=>{var p,g;if(!isValidElement(i))return false;let c=Array.isArray(i.props.children)?i.props.children:[i.props.children],d=false,m=false;for(let u of c)if(u){if(typeof u=="string")u.trim()!==""&&(d=true);else if(isValidElement(u))if(((p=u.props)==null?void 0:p["data-footnote-backref"])!==void 0)m=true;else {let b=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let y of b){if(typeof y=="string"&&y.trim()!==""){d=true;break}if(isValidElement(y)&&((g=y.props)==null?void 0:g["data-footnote-backref"])===void 0){d=true;break}}}}return m&&!d},l=Array.isArray(e)?e.map(i=>{if(!isValidElement(i))return i;if(i.type===ke){let d=(Array.isArray(i.props.children)?i.props.children:[i.props.children]).filter(m=>!r(m));return d.length===0?null:{...i,props:{...i.props,children:d}}}return i}):e;return (Array.isArray(l)?l.some(i=>i!==null):l!==null)?jsx("section",{className:t,...o,children:l}):null}return jsx("section",{className:t,...o,children:e})},(e,t)=>P(e,t));St.displayName="MarkdownSection";var Zo=({node:e,className:t,children:n,...o})=>{var m,p,g;let s=((m=e==null?void 0:e.position)==null?void 0:m.start.line)===((p=e==null?void 0:e.position)==null?void 0:p.end.line),{mermaid:r,controls:l}=useContext(T);if(s)return jsx("code",{className:f("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...o,children:n});let a=t==null?void 0:t.match(zo),i=(g=a==null?void 0:a.at(1))!=null?g:"",c="";if(isValidElement(n)&&n.props&&typeof n.props=="object"&&"children"in n.props&&typeof n.props.children=="string"?c=n.props.children:typeof n=="string"&&(c=n),i==="mermaid"){let u=we(l,"mermaid"),b=ie(l,"download"),y=ie(l,"copy"),k=ie(l,"fullscreen"),L=ie(l,"panZoom"),C=u&&(b||y||k);return jsx(Suspense,{fallback:jsx(ge,{}),children:jsxs("div",{className:f("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[C?jsxs("div",{className:"flex items-center justify-end gap-2",children:[b?jsx(Fe,{chart:c,config:r==null?void 0:r.config}):null,y?jsx(ue,{code:c}):null,k?jsx(Ke,{chart:c,config:r==null?void 0:r.config}):null]}):null,jsx($o,{chart:c,config:r==null?void 0:r.config,showControls:L})]})})}let d=we(l,"code");return jsx(Suspense,{fallback:jsx(ge,{}),children:jsx(qo,{className:f("overflow-x-auto border-border border-t",t),code:c,language:i,children:d?jsxs(Fragment,{children:[jsx(Ve,{code:c,language:i}),jsx(ue,{})]}):null})})},It=memo(Zo,(e,t)=>e.className===t.className&&le(e.node,t.node));It.displayName="MarkdownCode";var Et=memo(Oe,(e,t)=>e.className===t.className&&le(e.node,t.node));Et.displayName="MarkdownImg";var Dt=memo(({children:e,className:t,node:n,...o})=>{var l;let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");return r.length===1&&isValidElement(r[0])&&((l=r[0].props.node)==null?void 0:l.tagName)==="img"?jsx(Fragment,{children:e}):jsx("p",{className:t,...o,children:e})},(e,t)=>P(e,t));Dt.displayName="MarkdownParagraph";var Ht={ol:ke,li:dt,ul:mt,hr:pt,strong:ut,a:ft,h1:gt,h2:bt,h3:ht,h4:yt,h5:wt,h6:kt,table:vt,thead:xt,tbody:Ct,tr:Mt,th:Pt,td:Tt,blockquote:Lt,code:It,img:Et,pre:({children:e})=>e,sup:Nt,sub:Rt,p:Dt,section:St};var Bt=[],At={allowDangerousHtml:true},ce=new WeakMap,ve=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let n=this.keyCache.get(t);if(n)return n;let o=t.rehypePlugins,s=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(o||s||r)){let m="default";return this.keyCache.set(t,m),m}let l=m=>{if(!m||m.length===0)return "";let p="";for(let g=0;g<m.length;g+=1){let u=m[g];if(g>0&&(p+=","),Array.isArray(u)){let[b,y]=u;if(typeof b=="function"){let k=ce.get(b);k||(k=b.name,ce.set(b,k)),p+=k;}else p+=String(b);p+=":",p+=JSON.stringify(y);}else if(typeof u=="function"){let b=ce.get(u);b||(b=u.name,ce.set(u,b)),p+=b;}else p+=String(u);}return p},a=l(o),i=l(s),c=r?JSON.stringify(r):"",d=`${i}::${a}::${c}`;return this.keyCache.set(t,d),d}get(t){let n=this.generateCacheKey(t),o=this.cache.get(n);return o&&(this.cache.delete(n),this.cache.set(n,o)),o}set(t,n){let o=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let s=this.cache.keys().next().value;s&&this.cache.delete(s);}this.cache.set(o,n);}clear(){this.cache.clear();}},Vt=new ve,xe=e=>{let t=Go(e),n=e.children||"";return Qo(t.runSync(t.parse(n),n),e)},Go=e=>{let t=Vt.get(e);if(t)return t;let n=Yo(e);return Vt.set(e,n),n},Yo=e=>{let t=e.rehypePlugins||Bt,n=e.remarkPlugins||Bt,o=e.remarkRehypeOptions?{...At,...e.remarkRehypeOptions}:At;return unified().use(Xo).use(n).use(Jo,o).use(t)},Qo=(e,t)=>toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true});var tn=/\[\^[^\]\s]{1,200}\](?!:)/,on=/\[\^[^\]\s]{1,200}\]:/,nn=/<\/(\w+)>/,rn=/<(\w+)[\s>]/,Ce=e=>{let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
9
|
+
`||e[t]==="\r");)t+=1;return t+1<e.length&&e[t]==="$"&&e[t+1]==="$"},sn=e=>{let t=e.length-1;for(;t>=0&&(e[t]===" "||e[t]===" "||e[t]===`
|
|
10
|
+
`||e[t]==="\r");)t-=1;return t>=1&&e[t]==="$"&&e[t-1]==="$"},Me=e=>{let t=0;for(let n=0;n<e.length-1;n+=1)e[n]==="$"&&e[n+1]==="$"&&(t+=1,n+=1);return t},Pe=e=>{let t=tn.test(e),n=on.test(e);if(t||n)return [e];let o=Lexer.lex(e,{gfm:true}),s=[],r=[];for(let l of o){let a=l.raw,i=s.length;if(r.length>0){if(s[i-1]+=a,l.type==="html"){let d=a.match(nn);if(d){let m=d[1];r.at(-1)===m&&r.pop();}}continue}if(l.type==="html"&&l.block){let d=a.match(rn);if(d){let m=d[1];a.includes(`</${m}>`)||r.push(m);}}if(a.trim()==="$$"&&i>0){let d=s[i-1],m=Ce(d),p=Me(d);if(m&&p%2===1){s[i-1]=d+a;continue}}if(i>0&&sn(a)){let d=s[i-1],m=Ce(d),p=Me(d),g=Me(a);if(m&&p%2===1&&!Ce(a)&&g===1){s[i-1]=d+a;continue}}s.push(a);}return s};var ln=new Set(["\u3002","\uFF0E","\uFF0C","\u3001","\uFF1F","\uFF01","\uFF1A","\uFF1B","\uFF08","\uFF09","\u3010","\u3011","\u300C","\u300D","\u300E","\u300F","\u3008","\u3009","\u300A","\u300B"]),cn=/^(https?:\/\/|mailto:|www\.)/i,dn=e=>{if(e.children.length!==1)return false;let t=e.children[0];return t.type==="text"&&t.value===e.url},mn=e=>{let t=0;for(let n of e){if(ln.has(n))return t;t+=n.length;}return null},pn=(e,t)=>({...t,url:e,children:[{type:"text",value:e}]}),un=e=>({type:"text",value:e}),Ot=()=>e=>{visit(e,"link",(t,n,o)=>{if(!o||typeof n!="number"||!dn(t)||!cn.test(t.url))return;let s=mn(t.url);if(s===null||s===0)return;let r=t.url.slice(0,s),l=t.url.slice(s),a=pn(r,t),i=un(l);return o.children.splice(n,1,a,i),n+1});};var Ft={javascript:bn,typescript:xn,jsx:yn,tsx:vn,html:gn,css:fn,json:hn,bash:qt,shellscript:Wt,shell:Wt,sh:qt,yaml:_t,yml:_t,toml:kn,python:Zt,py:Zt,markdown:zt,md:zt,sql:wn,go:$t,golang:$t},Cn=e=>e in Ft;var jn=/[^$]\$[^$]/,Bn=/^\$[^$]/,An=/[^$]\$$/,Vn={raw:Rn,sanitize:[Sn,{}],katex:[Te,{errorColor:"var(--color-muted-foreground)"}],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},On={gfm:[Dn,{}],cjkAutolinkBoundary:[Ot,{}],math:[Le,{singleDollarTextMath:false}],cjkFriendly:[In,{}],cjkFriendlyGfmStrikethrough:[En,{}]},qn=Object.values(Vn),$n=Object.values(On),zn={block:" \u258B",circle:" \u25CF"},Jt="https://www.streamdown.ai/cdn",Zn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,cdnUrl:Jt},T=createContext(Zn),Kt=memo(({content:e,...t})=>jsx(xe,{...t,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let n=Object.keys(e.components||{}),o=Object.keys(t.components||{});if(n.length!==o.length||n.some(s=>{var r,l;return ((r=e.components)==null?void 0:r[s])!==((l=t.components)==null?void 0:l[s])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});Kt.displayName="Block";var Wn=["github-light","github-dark"],_n=e=>Array.isArray(e)&&e.some(t=>Array.isArray(t)?t[0]===Te:t===Te),Fn=e=>{if(!Array.isArray(e))return false;let t=e.find(n=>Array.isArray(n)?n[0]===Le:n===Le);return t&&Array.isArray(t)&&t[1]?t[1].singleDollarTextMath===true:false},Un=(e,t)=>{let n=e.includes("$$"),o=t&&(jn.test(e)||Bn.test(e)||An.test(e));return n||o},Xn=/^\^/,Jn=e=>{let t=F.dependencies["rehype-katex"].replace(Xn,"").split(".")[0],o={7:"0.16.22"}[t]||"0.16.22",s=document.createElement("link");s.rel="stylesheet",s.href=`${e}/katex/${o}/katex.min.css`,document.head.appendChild(s);},Kn=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:n=true,components:o,rehypePlugins:s=qn,remarkPlugins:r=$n,className:l,shikiTheme:a=Wn,mermaid:i,controls:c=true,isAnimating:d=false,BlockComponent:m=Kt,parseMarkdownIntoBlocksFn:p=Pe,caret:g,cdnUrl:u=Jt,remend:b,...y})=>{let k=useId(),[L,C]=useTransition(),[M,E]=useState([]),R=useMemo(()=>typeof e!="string"?"":t==="streaming"&&n?Hn(e,b):e,[e,t,n,b]),S=useMemo(()=>p(R),[R,p]);useEffect(()=>{t==="streaming"?C(()=>{E(S);}):E(S);},[S,t]);let j=t==="streaming"?M:S,z=useMemo(()=>j.map((N,A)=>`${k}-${A}`),[j.length,k]),B=useMemo(()=>({shikiTheme:a,controls:c,isAnimating:d,mode:t,mermaid:i,cdnUrl:u}),[a,c,d,t,i,u]),D=useMemo(()=>({...Ht,...o}),[o]);useEffect(()=>{if(u===null||!_n(s))return;let A=Fn(r);Un(typeof e=="string"?e:"",A)&&Jn(u);},[s,r,e,u]);let w=useMemo(()=>g&&d?{"--streamdown-caret":`"${zn[g]}"`}:void 0,[g,d]);return t==="static"?jsx(T.Provider,{value:B,children:jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",l),children:jsx(xe,{components:D,rehypePlugins:s,remarkPlugins:r,...y,children:e})})}):jsx(T.Provider,{value:B,children:jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",g?"*:last:after:inline *:last:after:align-baseline *:last:after:content-(--streamdown-caret)":null,l),style:w,children:j.map((N,A)=>jsx(m,{components:D,content:N,index:A,rehypePlugins:s,remarkPlugins:r,shouldParseIncompleteMarkdown:n,...y},z[A]))})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.mode===t.mode);Kn.displayName="Streamdown";var eo=({children:e,className:t,minZoom:n=.5,maxZoom:o=3,zoomStep:s=.1,showControls:r=true,initialZoom:l=1,fullscreen:a=false})=>{let i=useRef(null),c=useRef(null),[d,m]=useState(l),[p,g]=useState({x:0,y:0}),[u,b]=useState(false),[y,k]=useState({x:0,y:0}),[L,C]=useState({x:0,y:0}),M=useCallback(w=>{m(N=>Math.max(n,Math.min(o,N+w)));},[n,o]),E=useCallback(()=>{M(s);},[M,s]),R=useCallback(()=>{M(-s);},[M,s]),S=useCallback(()=>{m(l),g({x:0,y:0});},[l]),j=useCallback(w=>{w.preventDefault();let N=w.deltaY>0?-s:s;M(N);},[M,s]),z=useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;b(true),k({x:w.clientX,y:w.clientY}),C(p);let N=w.currentTarget;N instanceof HTMLElement&&N.setPointerCapture(w.pointerId);},[p]),B=useCallback(w=>{if(!u)return;w.preventDefault();let N=w.clientX-y.x,A=w.clientY-y.y;g({x:L.x+N,y:L.y+A});},[u,y,L]),D=useCallback(w=>{b(false);let N=w.currentTarget;N instanceof HTMLElement&&N.releasePointerCapture(w.pointerId);},[]);return useEffect(()=>{let w=i.current;if(w)return w.addEventListener("wheel",j,{passive:false}),()=>{w.removeEventListener("wheel",j);}},[j]),useEffect(()=>{let w=c.current;if(w&&u)return document.body.style.userSelect="none",w.addEventListener("pointermove",B,{passive:false}),w.addEventListener("pointerup",D),w.addEventListener("pointercancel",D),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",B),w.removeEventListener("pointerup",D),w.removeEventListener("pointercancel",D);}},[u,B,D]),jsxs("div",{className:f("relative flex flex-col",a?"h-full w-full":"min-h-28 w-full",t),ref:i,style:{cursor:u?"grabbing":"grab"},children:[r?jsxs("div",{className:f("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",a?"bottom-4 left-4":"bottom-2 left-2"),children:[jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d>=o,onClick:E,title:"Zoom in",type:"button",children:jsx(De,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",disabled:d<=n,onClick:R,title:"Zoom out",type:"button",children:jsx(He,{size:16})}),jsx("button",{className:"flex items-center justify-center rounded p-1.5 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",onClick:S,title:"Reset zoom and pan",type:"button",children:jsx(Ie,{size:16})})]}):null,jsx("div",{className:f("flex-1 origin-center transition-transform duration-150 ease-out",a?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:z,ref:c,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var Je=({chart:e,className:t,config:n,fullscreen:o=false,showControls:s=true})=>{let[r,l]=useState(null),[a,i]=useState(false),[c,d]=useState(""),[m,p]=useState(""),[g,u]=useState(0),{mermaid:b,cdnUrl:y}=useContext(T),k=b==null?void 0:b.errorComponent,{shouldRender:L,containerRef:C}=Ne({immediate:o});if(useEffect(()=>{if(!L)return;(async()=>{try{l(null),i(!0);let R=await te(n,y),S=e.split("").reduce((B,D)=>(B<<5)-B+D.charCodeAt(0)|0,0),j=`mermaid-${Math.abs(S)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:z}=await R.render(j,e);d(z),p(z);}catch(R){if(!(m||c)){let S=R instanceof Error?R.message:"Failed to render Mermaid chart";l(S);}}finally{i(false);}})();},[e,n,g,L,y]),!(L||c||m))return jsx("div",{className:f("my-4 min-h-[200px]",t),ref:C});if(a&&!c&&!m)return jsx("div",{className:f("my-4 flex justify-center p-4",t),ref:C,children:jsxs("div",{className:"flex items-center space-x-2 text-muted-foreground",children:[jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-current border-b-2"}),jsx("span",{className:"text-sm",children:"Loading diagram..."})]})});if(r&&!c&&!m){let E=()=>u(R=>R+1);return k?jsx("div",{ref:C,children:jsx(k,{chart:e,error:r,retry:E})}):jsxs("div",{className:f("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:C,children:[jsxs("p",{className:"font-mono text-red-700 text-sm",children:["Mermaid Error: ",r]}),jsxs("details",{className:"mt-2",children:[jsx("summary",{className:"cursor-pointer text-red-600 text-xs",children:"Show Code"}),jsx("pre",{className:"mt-2 overflow-x-auto rounded bg-red-100 p-2 text-red-800 text-xs",children:e})]})]})}let M=c||m;return jsx("div",{className:"size-full",ref:C,children:jsx(eo,{className:f(o?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:o,maxZoom:3,minZoom:.5,showControls:s,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:f("flex justify-center",o?"size-full items-center":null),dangerouslySetInnerHTML:{__html:M},role:"img"})})})};
|
|
11
|
+
export{f as a,po as b,F as c,Je as d,Ft as e,Cn as f,Pe as g,Vn as h,On as i,T as j,Kt as k,Kn as l};
|