streamdown 2.2.0 → 2.3.0
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-RLXIAIE6.js +13 -0
- package/dist/highlighted-body-B3W2YXNL.js +2 -0
- package/dist/index.d.ts +70 -45
- package/dist/index.js +1 -1
- package/dist/mermaid-3ZIDBTTL.js +2 -0
- package/package.json +8 -6
- package/dist/chunk-LPQFK2AO.js +0 -8
- package/dist/code-block-OCS4YCEC.js +0 -3
- package/dist/mermaid-NOHMQCX5.js +0 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {createContext,memo,useMemo,lazy,useContext,isValidElement,useId,useTransition,useState,useEffect,cloneElement,useCallback,useRef,Suspense}from'react';import {harden}from'rehype-harden';import po from'rehype-raw';import To,{defaultSchema}from'rehype-sanitize';import Er from'remark-gfm';import Hr from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import {urlAttributes}from'html-url-attributes';import ar from'remark-parse';import ir from'remark-rehype';import {unified}from'unified';import {visit}from'unist-util-visit';import {Lexer}from'marked';var Oo=300,Vo="300px",Ao=500;function Ge(e={}){let{immediate:t=false,debounceDelay:o=Oo,rootMargin:n=Vo,idleTimeout:s=Ao}=e,[r,i]=useState(false),c=useRef(null),a=useRef(null),l=useRef(null),m=useMemo(()=>g=>{let b=Date.now();return window.setTimeout(()=>{g({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-b))});},1)},[]),d=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(g,b)=>window.requestIdleCallback(g,b):m,[m]),p=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?g=>window.cancelIdleCallback(g):g=>{clearTimeout(g);},[]);return useEffect(()=>{if(t){i(true);return}let g=c.current;if(!g)return;a.current&&(clearTimeout(a.current),a.current=null),l.current&&(p(l.current),l.current=null);let b=()=>{a.current&&(clearTimeout(a.current),a.current=null),l.current&&(p(l.current),l.current=null);},h=w=>{l.current=d(T=>{T.timeRemaining()>0||T.didTimeout?(i(true),w.disconnect()):l.current=d(()=>{i(true),w.disconnect();},{timeout:s/2});},{timeout:s});},u=w=>{b(),a.current=window.setTimeout(()=>{var S,B;let T=w.takeRecords();(T.length===0||(B=(S=T.at(-1))==null?void 0:S.isIntersecting)!=null&&B)&&h(w);},o);},C=(w,T)=>{w.isIntersecting?u(T):b();},k=new IntersectionObserver(w=>{for(let T of w)C(T,k);},{rootMargin:n,threshold:0});return k.observe(g),()=>{a.current&&clearTimeout(a.current),l.current&&p(l.current),k.disconnect();}},[t,o,n,s,p,d]),{shouldRender:r,containerRef:c}}var Ye=/\s/,qo=/^\s+$/,_o=new Set(["code","pre","svg","math","annotation"]),Zo=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",Wo=e=>e.some(t=>Zo(t)&&_o.has(t.tagName)),$o=e=>{let t=[],o="",n=false;for(let s of e){let r=Ye.test(s);r!==n&&o&&(t.push(o),o=""),o+=s,n=r;}return o&&t.push(o),t},Fo=e=>{let t=[],o="";for(let n of e)Ye.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},Uo=(e,t,o,n)=>({type:"element",tagName:"span",properties:{"data-sd-animate":true,style:`--sd-animation:sd-${t};--sd-duration:${o}ms;--sd-easing:${n}`},children:[{type:"text",value:e}]}),Xo=(e,t,o)=>{let n=t.at(-1);if(!(n&&"children"in n))return;if(Wo(t))return SKIP;let s=n,r=s.children.indexOf(e);if(r===-1)return;let i=e.value;if(!i.trim())return;let a=(o.sep==="char"?Fo(i):$o(i)).map(l=>qo.test(l)?{type:"text",value:l}:Uo(l,o.animation,o.duration,o.easing));return s.children.splice(r,1,...a),r+a.length};function Q(e){var n,s,r,i;let t={animation:(n=e==null?void 0:e.animation)!=null?n:"fadeIn",duration:(s=e==null?void 0:e.duration)!=null?s:150,easing:(r=e==null?void 0:e.easing)!=null?r:"ease",sep:(i=e==null?void 0:e.sep)!=null?i:"word"};return {name:"animate",type:"animate",rehypePlugin:()=>c=>{visitParents(c,"text",(a,l)=>Xo(a,l,t));}}}Q();var Re=createContext(false),Ie=()=>useContext(Re);var f=(...e)=>twMerge(clsx(e)),q=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,s=URL.createObjectURL(n),r=document.createElement("a");r.href=s,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(s);};var tn=f("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),on=e=>{let t={};for(let o of e.split(";")){let n=o.indexOf(":");if(n>0){let s=o.slice(0,n).trim(),r=o.slice(n+1).trim();s&&r&&(t[s]=r);}}return t},Qe=memo(({children:e,result:t,language:o,className:n,...s})=>{let r=useMemo(()=>{let i={};return t.bg&&(i["--sdm-bg"]=t.bg),t.fg&&(i["--sdm-fg"]=t.fg),t.rootStyle&&Object.assign(i,on(t.rootStyle)),i},[t.bg,t.fg,t.rootStyle]);return jsx("div",{className:f(n,"overflow-hidden rounded-md border border-border bg-background p-4 text-sm"),"data-language":o,"data-streamdown":"code-block-body",...s,children:jsx("pre",{className:f(n,"bg-[var(--sdm-bg,inherit]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,inherit)]"),style:r,children:jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:t.tokens.map((i,c)=>jsx("span",{className:tn,children:i.map((a,l)=>{let m={},d=!!a.bgColor;if(a.color&&(m["--sdm-c"]=a.color),a.bgColor&&(m["--sdm-tbg"]=a.bgColor),a.htmlStyle)for(let[p,g]of Object.entries(a.htmlStyle))p==="color"?m["--sdm-c"]=g:p==="background-color"?(m["--sdm-tbg"]=g,d=true):m[p]=g;return jsx("span",{className:f("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",d&&"bg-[var(--sdm-tbg)]",d&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:m,...a.htmlAttrs,children:a.content},l)})},c))})})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className);var et=({className:e,language:t,style:o,isIncomplete:n,...s})=>jsx("div",{className:f("my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",e),"data-incomplete":n||void 0,"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...o},...s});var Se=createContext({code:""}),de=()=>useContext(Se);var ot=({language:e})=>jsx("div",{className:"flex h-8 items-center text-muted-foreground text-xs","data-language":e,"data-streamdown":"code-block-header",children:jsx("span",{className:"ml-1 font-mono lowercase",children:e})});var cn=/\n+$/,dn=lazy(()=>import('./highlighted-body-B3W2YXNL.js').then(e=>({default:e.HighlightedCodeBlockBody}))),rt=({code:e,language:t,className:o,children:n,isIncomplete:s=false,...r})=>{let i=useMemo(()=>e.replace(cn,""),[e]),c=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:i.split(`
|
|
3
|
+
`).map(a=>[{content:a,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[i]);return jsx(Se.Provider,{value:{code:e},children:jsxs(et,{isIncomplete:s,language:t,children:[jsx(ot,{language:t}),n?jsx("div",{className:"pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end",children:jsx("div",{className:"pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur","data-streamdown":"code-block-actions",children:n})}):null,jsx(Suspense,{fallback:jsx(Qe,{className:o,language:t,result:c,...r}),children:jsx(dn,{className:o,code:i,language:t,raw:c,...r})})]})})};var J=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"})}),K=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"})}),Z=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"})}),st=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"})]}),at=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"})}),it=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"})}),me=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"})}),Ee=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 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",fill:"currentColor",fillRule:"evenodd"})}),lt=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"})}),ct=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.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})});var He=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:s,code:r,...i})=>{let[c,a]=useState(false),l=useRef(0),{code:m}=de(),{isAnimating:d}=useContext(R),p=r!=null?r:m,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{c||(await navigator.clipboard.writeText(p),a(!0),e==null||e(),l.current=window.setTimeout(()=>a(!1),o));}catch(u){t==null||t(u);}};useEffect(()=>()=>{window.clearTimeout(l.current);},[]);let b=c?J:K;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:d,onClick:g,title:"Copy Code",type:"button",...i,children:n!=null?n:jsx(b,{size:14})})};var mt={"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"},ut=({onDownload:e,onError:t,language:o,children:n,className:s,code:r,...i})=>{let{code:c}=de(),{isAnimating:a}=useContext(R),l=r!=null?r:c,d=`file.${o&&o in mt?mt[o]:"txt"}`,p="text/plain",g=()=>{try{q(d,l,p),e==null||e();}catch(b){t==null||t(b);}};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:a,onClick:g,title:"Download file",type:"button",...i,children:n!=null?n:jsx(Z,{size:14})})};var ft=()=>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(st,{className:"size-4 animate-spin"})})]});var Cn=/\.[^/.]+$/,ht=({node:e,className:t,src:o,alt:n,onLoad:s,onError:r,...i})=>{let c=useRef(null),[a,l]=useState(false),[m,d]=useState(false),p=i.width!=null||i.height!=null,g=(a||p)&&!m,b=m&&!p;useEffect(()=>{let k=c.current;if(k!=null&&k.complete){let w=k.naturalWidth>0;l(w),d(!w);}},[]);let h=useCallback(k=>{l(true),d(false),s==null||s(k);},[s]),u=useCallback(k=>{l(false),d(true),r==null||r(k);},[r]),C=async()=>{if(o)try{let w=await(await fetch(o)).blob(),H=new URL(o,window.location.origin).pathname.split("/").pop()||"",S=H.split(".").pop(),B=H.includes(".")&&S!==void 0&&S.length<=4,O="";if(B)O=H;else {let E=w.type,I="png";E.includes("jpeg")||E.includes("jpg")?I="jpg":E.includes("png")?I="png":E.includes("svg")?I="svg":E.includes("gif")?I="gif":E.includes("webp")&&(I="webp"),O=`${(n||H||"image").replace(Cn,"")}.${I}`;}q(O,w,w.type);}catch(k){window.open(o,"_blank");}};return o?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:f("max-w-full rounded-lg",b&&"hidden",t),"data-streamdown":"image",onError:u,onLoad:h,ref:c,src:o,...i}),b&&jsx("span",{className:"text-muted-foreground text-xs italic","data-streamdown":"image-fallback",children:"Image not available"}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),g&&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:C,title:"Download image",type:"button",children:jsx(Z,{size:14})})]}):null};var oe=0,Mn=()=>{oe+=1,oe===1&&(document.body.style.overflow="hidden");},Tn=()=>{oe=Math.max(0,oe-1),oe===0&&(document.body.style.overflow="");},kt=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[s,r]=useState(false),i=useCallback(async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3);}catch(a){}},[e]),c=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){Mn();let a=l=>{l.key==="Escape"&&o();};return document.addEventListener("keydown",a),()=>{document.removeEventListener("keydown",a),Tn();}}},[t,o]),t?jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm","data-streamdown":"link-safety-modal",onClick:o,onKeyDown:a=>{a.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:"relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg",onClick:a=>a.stopPropagation(),onKeyDown:a=>a.stopPropagation(),role:"presentation",children:[jsx("button",{className:"absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:o,title:"Close",type:"button",children:jsx(me,{size:16})}),jsxs("div",{className:"flex flex-col gap-2",children:[jsxs("div",{className:"flex items-center gap-2 font-semibold text-lg",children:[jsx(Ee,{size:20}),jsx("span",{children:"Open external link?"})]}),jsx("p",{className:"text-muted-foreground text-sm",children:"You're about to visit an external website."})]}),jsx("div",{className:f("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxs("div",{className:"flex gap-2",children:[jsx("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted",onClick:i,type:"button",children:s?jsxs(Fragment,{children:[jsx(J,{size:14}),jsx("span",{children:"Copied"})]}):jsxs(Fragment,{children:[jsx(K,{size:14}),jsx("span",{children:"Copy link"})]})}),jsxs("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90",onClick:c,type:"button",children:[jsx(Ee,{size:14}),jsx("span",{children:"Open link"})]})]})]})}):null};var pe=createContext(null),Ct=()=>useContext(pe),Ks=()=>{var t;let e=Ct();return (t=e==null?void 0:e.code)!=null?t:null},G=()=>{var t;let e=Ct();return (t=e==null?void 0:e.mermaid)!=null?t:null};var vt=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((s,r)=>{let i="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),c=new Image;c.crossOrigin="anonymous",c.onload=()=>{let a=document.createElement("canvas"),l=c.width*o,m=c.height*o;a.width=l,a.height=m;let d=a.getContext("2d");if(!d){r(new Error("Failed to create 2D canvas context for PNG export"));return}d.drawImage(c,0,0,l,m),a.toBlob(p=>{if(!p){r(new Error("Failed to create PNG blob"));return}s(p);},"image/png");},c.onerror=()=>r(new Error("Failed to load SVG image")),c.src=i;})};var Pt=({chart:e,children:t,className:o,onDownload:n,config:s,onError:r})=>{let[i,c]=useState(false),a=useRef(null),{isAnimating:l}=useContext(R),m=G(),d=async p=>{try{if(p==="mmd"){q("diagram.mmd",e,"text/plain"),c(!1),n==null||n(p);return}if(!m){r==null||r(new Error("Mermaid plugin not available"));return}let g=m.getMermaid(s),b=e.split("").reduce((C,k)=>(C<<5)-C+k.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(b)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:u}=await g.render(h,e);if(!u){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(p==="svg"){q("diagram.svg",u,"image/svg+xml"),c(!1),n==null||n(p);return}if(p==="png"){let C=await vt(u);q("diagram.png",C,"image/png"),n==null||n(p),c(!1);return}}catch(g){r==null||r(g);}};return useEffect(()=>{let p=g=>{let b=g.composedPath();a.current&&!b.includes(a.current)&&c(false);};return document.addEventListener("mousedown",p),()=>{document.removeEventListener("mousedown",p);}},[]),jsxs("div",{className:"relative",ref:a,children:[jsx("button",{className:f("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:l,onClick:()=>c(!i),title:"Download diagram",type:"button",children:t!=null?t:jsx(Z,{size:14})}),i?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 re=0,On=()=>{re+=1,re===1&&(document.body.style.overflow="hidden");},Vn=()=>{re=Math.max(0,re-1),re===0&&(document.body.style.overflow="");},Lt=({chart:e,config:t,onFullscreen:o,onExit:n,className:s,...r})=>{let[i,c]=useState(false),{isAnimating:a,controls:l}=useContext(R),m=(()=>{if(typeof l=="boolean")return l;let p=l.mermaid;return p===false?false:p===true||p===void 0?true:p.panZoom!==false})(),d=()=>{c(!i);};return useEffect(()=>{if(i){On();let p=g=>{g.key==="Escape"&&c(false);};return document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p),Vn();}}},[i]),useEffect(()=>{i?o==null||o():n&&n();},[i,o,n]),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:a,onClick:d,title:"View fullscreen",type:"button",...r,children:jsx(at,{size:14})}),i?createPortal(jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:d,onKeyDown:p=>{p.key==="Escape"&&d();},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:d,title:"Exit fullscreen",type:"button",children:jsx(me,{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(Nt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:m})})]}),document.body):null]})};var ue=e=>{var r,i;let t=[],o=[],n=e.querySelectorAll("thead th");for(let c of n)t.push(((r=c.textContent)==null?void 0:r.trim())||"");let s=e.querySelectorAll("tbody tr");for(let c of s){let a=[],l=c.querySelectorAll("td");for(let m of l)a.push(((i=m.textContent)==null?void 0:i.trim())||"");o.push(a);}return {headers:t,rows:o}},fe=e=>{let{headers:t,rows:o}=e,n=c=>{let a=false,l=false;for(let m of c){if(m==='"'){a=true,l=true;break}(m===","||m===`
|
|
4
|
+
`)&&(a=true);}return a?l?`"${c.replace(/"/g,'""')}"`:`"${c}"`:c},s=t.length>0?o.length+1:o.length,r=new Array(s),i=0;t.length>0&&(r[i]=t.map(n).join(","),i+=1);for(let c of o)r[i]=c.map(n).join(","),i+=1;return r.join(`
|
|
5
|
+
`)},Rt=e=>{let{headers:t,rows:o}=e,n=c=>{let a=false;for(let m of c)if(m===" "||m===`
|
|
6
|
+
`||m==="\r"){a=true;break}if(!a)return c;let l=[];for(let m of c)m===" "?l.push("\\t"):m===`
|
|
7
|
+
`?l.push("\\n"):m==="\r"?l.push("\\r"):l.push(m);return l.join("")},s=t.length>0?o.length+1:o.length,r=new Array(s),i=0;t.length>0&&(r[i]=t.map(n).join(" "),i+=1);for(let c of o)r[i]=c.map(n).join(" "),i+=1;return r.join(`
|
|
8
|
+
`)},De=e=>{let t=false;for(let n of e)if(n==="\\"||n==="|"){t=true;break}if(!t)return e;let o=[];for(let n of e)n==="\\"?o.push("\\\\"):n==="|"?o.push("\\|"):o.push(n);return o.join("")},se=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),s=0,r=t.map(c=>De(c));n[s]=`| ${r.join(" | ")} |`,s+=1;let i=new Array(t.length);for(let c=0;c<t.length;c+=1)i[c]="---";n[s]=`| ${i.join(" | ")} |`,s+=1;for(let c of o)if(c.length<t.length){let a=new Array(t.length);for(let l=0;l<t.length;l+=1)a[l]=l<c.length?De(c[l]):"";n[s]=`| ${a.join(" | ")} |`,s+=1;}else {let a=c.map(l=>De(l));n[s]=`| ${a.join(" | ")} |`,s+=1;}return n.join(`
|
|
9
|
+
`)};var Ht=({children:e,className:t,onCopy:o,onError:n,timeout:s=2e3})=>{let[r,i]=useState(false),[c,a]=useState(false),l=useRef(null),m=useRef(0),{isAnimating:d}=useContext(R),p=async b=>{var h,u;if(typeof window=="undefined"||!((h=navigator==null?void 0:navigator.clipboard)!=null&&h.write)){n==null||n(new Error("Clipboard API not available"));return}try{let C=(u=l.current)==null?void 0:u.closest('[data-streamdown="table-wrapper"]'),k=C==null?void 0:C.querySelector("table");if(!k){n==null||n(new Error("Table not found"));return}let w=ue(k),S=({csv:fe,tsv:Rt,md:se}[b]||se)(w),B=new ClipboardItem({"text/plain":new Blob([S],{type:"text/plain"}),"text/html":new Blob([k.outerHTML],{type:"text/html"})});await navigator.clipboard.write([B]),a(!0),i(!1),o==null||o(b),m.current=window.setTimeout(()=>a(!1),s);}catch(C){n==null||n(C);}};useEffect(()=>{let b=h=>{let u=h.composedPath();l.current&&!u.includes(l.current)&&i(false);};return document.addEventListener("mousedown",b),()=>{document.removeEventListener("mousedown",b),window.clearTimeout(m.current);}},[]);let g=c?J:K;return 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:d,onClick:()=>i(!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("md"),title:"Copy table as Markdown",type:"button",children:"Markdown"}),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 Dt=({children:e,className:t,onDownload:o,onError:n})=>{let[s,r]=useState(false),i=useRef(null),{isAnimating:c}=useContext(R),a=l=>{var m;try{let d=(m=i.current)==null?void 0:m.closest('[data-streamdown="table-wrapper"]'),p=d==null?void 0:d.querySelector("table");if(!p){n==null||n(new Error("Table not found"));return}let g=ue(p),b=l==="csv"?fe(g):se(g);q(`table.${l==="csv"?"csv":"md"}`,b,l==="csv"?"text/csv":"text/markdown"),r(!1),o==null||o(l);}catch(d){n==null||n(d);}};return useEffect(()=>{let l=m=>{let d=m.composedPath();i.current&&!d.includes(i.current)&&r(false);};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l);}},[]),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",t),disabled:c,onClick:()=>r(!s),title:"Download table",type:"button",children:e!=null?e:jsx(Z,{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:()=>a("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:()=>a("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var Vt=({children:e,className:t,showControls:o,...n})=>jsxs("div",{className:"my-4 flex flex-col gap-2 rounded-lg border border-border bg-sidebar p-2","data-streamdown":"table-wrapper",children:[o?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(Ht,{}),jsx(Dt,{})]}):null,jsx("div",{className:"border-collapse overflow-x-auto overscroll-y-auto rounded-md border border-border bg-background",children:jsx("table",{className:f("w-full divide-y divide-border",t),"data-streamdown":"table",...n,children:e})})]});var Jn=lazy(()=>import('./mermaid-3ZIDBTTL.js').then(e=>({default:e.Mermaid}))),Kn=/language-([^\s]+)/;function ke(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 o=e.position.start,n=t.position.start,s=e.position.end,r=t.position.end;return (o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.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 N(e,t){return e.className===t.className&&ke(e.node,t.node)}var Ve=(e,t)=>typeof e=="boolean"?e:e[t]!==false,he=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===false?false:o===true||o===void 0?true:o[t]!==false},je=memo(({children:e,className:t,node:o,...n})=>jsx("ol",{className:f("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>N(e,t));je.displayName="MarkdownOl";var At=memo(({children:e,className:t,node:o,...n})=>jsx("li",{className:f("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&ke(e.node,t.node));At.displayName="MarkdownLi";var jt=memo(({children:e,className:t,node:o,...n})=>jsx("ul",{className:f("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>N(e,t));jt.displayName="MarkdownUl";var zt=memo(({className:e,node:t,...o})=>jsx("hr",{className:f("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>N(e,t));zt.displayName="MarkdownHr";var qt=memo(({children:e,className:t,node:o,...n})=>jsx("span",{className:f("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>N(e,t));qt.displayName="MarkdownStrong";var Gn=({children:e,className:t,href:o,node:n,...s})=>{let{linkSafety:r}=useContext(R),[i,c]=useState(false),a=o==="streamdown:incomplete-link",l=useCallback(async g=>{if(!(!(r!=null&&r.enabled&&o)||a)){if(g.preventDefault(),r.onLinkCheck&&await r.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}c(true);}},[r,o,a]),m=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),d=useCallback(()=>{c(false);},[]),p={url:o!=null?o:"",isOpen:i,onClose:d,onConfirm:m};return r!=null&&r.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:f("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":a,"data-streamdown":"link",onClick:l,type:"button",children:e}),r.renderModal?r.renderModal(p):jsx(kt,{...p})]}):jsx("a",{className:f("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":a,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...s,children:e})},_t=memo(Gn,(e,t)=>N(e,t)&&e.href===t.href);_t.displayName="MarkdownA";var Zt=memo(({children:e,className:t,node:o,...n})=>jsx("h1",{className:f("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>N(e,t));Zt.displayName="MarkdownH1";var Wt=memo(({children:e,className:t,node:o,...n})=>jsx("h2",{className:f("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>N(e,t));Wt.displayName="MarkdownH2";var $t=memo(({children:e,className:t,node:o,...n})=>jsx("h3",{className:f("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>N(e,t));$t.displayName="MarkdownH3";var Ft=memo(({children:e,className:t,node:o,...n})=>jsx("h4",{className:f("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>N(e,t));Ft.displayName="MarkdownH4";var Ut=memo(({children:e,className:t,node:o,...n})=>jsx("h5",{className:f("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>N(e,t));Ut.displayName="MarkdownH5";var Xt=memo(({children:e,className:t,node:o,...n})=>jsx("h6",{className:f("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>N(e,t));Xt.displayName="MarkdownH6";var Jt=memo(({children:e,className:t,node:o,...n})=>{let{controls:s}=useContext(R),r=Ve(s,"table");return jsx(Vt,{className:t,showControls:r,...n,children:e})},(e,t)=>N(e,t));Jt.displayName="MarkdownTable";var Kt=memo(({children:e,className:t,node:o,...n})=>jsx("thead",{className:f("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>N(e,t));Kt.displayName="MarkdownThead";var Gt=memo(({children:e,className:t,node:o,...n})=>jsx("tbody",{className:f("divide-y divide-border",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>N(e,t));Gt.displayName="MarkdownTbody";var Yt=memo(({children:e,className:t,node:o,...n})=>jsx("tr",{className:f("border-border",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>N(e,t));Yt.displayName="MarkdownTr";var Qt=memo(({children:e,className:t,node:o,...n})=>jsx("th",{className:f("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>N(e,t));Qt.displayName="MarkdownTh";var eo=memo(({children:e,className:t,node:o,...n})=>jsx("td",{className:f("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>N(e,t));eo.displayName="MarkdownTd";var to=memo(({children:e,className:t,node:o,...n})=>jsx("blockquote",{className:f("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>N(e,t));to.displayName="MarkdownBlockquote";var oo=memo(({children:e,className:t,node:o,...n})=>jsx("sup",{className:f("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>N(e,t));oo.displayName="MarkdownSup";var no=memo(({children:e,className:t,node:o,...n})=>jsx("sub",{className:f("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>N(e,t));no.displayName="MarkdownSub";var ro=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let r=a=>{var p,g;if(!isValidElement(a))return false;let l=Array.isArray(a.props.children)?a.props.children:[a.props.children],m=false,d=false;for(let b of l)if(b){if(typeof b=="string")b.trim()!==""&&(m=true);else if(isValidElement(b))if(((p=b.props)==null?void 0:p["data-footnote-backref"])!==void 0)d=true;else {let h=Array.isArray(b.props.children)?b.props.children:[b.props.children];for(let u of h){if(typeof u=="string"&&u.trim()!==""){m=true;break}if(isValidElement(u)&&((g=u.props)==null?void 0:g["data-footnote-backref"])===void 0){m=true;break}}}}return d&&!m},i=Array.isArray(e)?e.map(a=>{if(!isValidElement(a))return a;if(a.type===je){let m=(Array.isArray(a.props.children)?a.props.children:[a.props.children]).filter(d=>!r(d));return m.length===0?null:{...a,props:{...a.props,children:m}}}return a}):e;return (Array.isArray(i)?i.some(a=>a!==null):i!==null)?jsx("section",{className:t,...n,children:i}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>N(e,t));ro.displayName="MarkdownSection";var Yn=({node:e,className:t,children:o,...n})=>{var g;let s=!("data-block"in n),{mermaid:r,controls:i}=useContext(R),c=G(),a=Ie();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",...n,children:o});let l=t==null?void 0:t.match(Kn),m=(g=l==null?void 0:l.at(1))!=null?g:"",d="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?d=o.props.children:typeof o=="string"&&(d=o),m==="mermaid"&&c){let b=Ve(i,"mermaid"),h=he(i,"download"),u=he(i,"copy"),C=he(i,"fullscreen"),k=he(i,"panZoom"),w=b&&(h||u||C);return jsx(Suspense,{fallback:jsx(ft,{}),children:jsxs("div",{className:f("group relative my-4 flex w-full flex-col gap-2 rounded-xl border border-border bg-sidebar p-2",t),"data-streamdown":"mermaid-block",children:[jsx("div",{className:"flex h-8 items-center text-muted-foreground text-xs",children:jsx("span",{className:"ml-1 font-mono lowercase",children:"mermaid"})}),w?jsx("div",{className:"pointer-events-none sticky top-2 z-10 -mt-10 flex h-8 items-center justify-end",children:jsxs("div",{className:"pointer-events-auto flex shrink-0 items-center gap-2 rounded-md border border-sidebar bg-sidebar/80 px-1.5 py-1 supports-[backdrop-filter]:bg-sidebar/70 supports-[backdrop-filter]:backdrop-blur","data-streamdown":"mermaid-block-actions",children:[h?jsx(Pt,{chart:d,config:r==null?void 0:r.config}):null,u?jsx(He,{code:d}):null,C?jsx(Lt,{chart:d,config:r==null?void 0:r.config}):null]})}):null,jsx("div",{className:"rounded-md border border-border bg-background",children:jsx(Jn,{chart:d,config:r==null?void 0:r.config,showControls:k})})]})})}let p=Ve(i,"code");return jsx(rt,{className:t,code:d,isIncomplete:a,language:m,children:p?jsxs(Fragment,{children:[jsx(ut,{code:d,language:m}),jsx(He,{})]}):null})},so=memo(Yn,(e,t)=>e.className===t.className&&ke(e.node,t.node));so.displayName="MarkdownCode";var ao=memo(ht,(e,t)=>e.className===t.className&&ke(e.node,t.node));ao.displayName="MarkdownImg";var io=memo(({children:e,node:t,...o})=>{let s=(Array.isArray(e)?e:[e]).filter(r=>r!=null&&r!=="");if(s.length===1&&isValidElement(s[0])){let r=s[0].props.node,i=r==null?void 0:r.tagName;if(i==="img")return jsx(Fragment,{children:e});if(i==="code"&&"data-block"in s[0].props)return jsx(Fragment,{children:e})}return jsx("p",{...o,children:e})},(e,t)=>N(e,t));io.displayName="MarkdownParagraph";var lo={ol:je,li:At,ul:jt,hr:zt,strong:qt,a:_t,h1:Zt,h2:Wt,h3:$t,h4:Ft,h5:Ut,h6:Xt,table:Jt,thead:Kt,tbody:Gt,tr:Yt,th:Qt,td:eo,blockquote:to,code:so,img:ao,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:oo,sub:no,p:io,section:ro};var Qn=/^[ \t]{0,3}(`{3,}|~{3,})/,er=/^\|?[ \t]*:?-{1,}:?[ \t]*(\|[ \t]*:?-{1,}:?[ \t]*)*\|?$/,ze=e=>{let t=e.split(`
|
|
10
|
+
`),o=null,n=0;for(let s of t){let r=Qn.exec(s);if(o===null){if(r){let i=r[1];o=i[0],n=i.length;}}else if(r){let i=r[1],c=i[0],a=i.length;c===o&&a>=n&&(o=null,n=0);}}return o!==null},co=e=>{let t=e.split(`
|
|
11
|
+
`);for(let o of t){let n=o.trim();if(n.length>0&&n.includes("|")&&er.test(n))return true}return false};var mo=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var uo=[],fo={allowDangerousHtml:true},Ce=new WeakMap,_e=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,s=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(n||s||r)){let d="default";return this.keyCache.set(t,d),d}let i=d=>{if(!d||d.length===0)return "";let p="";for(let g=0;g<d.length;g+=1){let b=d[g];if(g>0&&(p+=","),Array.isArray(b)){let[h,u]=b;if(typeof h=="function"){let C=Ce.get(h);C||(C=h.name,Ce.set(h,C)),p+=C;}else p+=String(h);p+=":",p+=JSON.stringify(u);}else if(typeof b=="function"){let h=Ce.get(b);h||(h=b.name,Ce.set(b,h)),p+=h;}else p+=String(b);}return p},c=i(n),a=i(s),l=r?JSON.stringify(r):"",m=`${a}::${c}::${l}`;return this.keyCache.set(t,m),m}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let s=this.cache.keys().next().value;s&&this.cache.delete(s);}this.cache.set(n,o);}clear(){this.cache.clear();}},go=new _e,Ze=e=>{let t=dr(e),o=e.children||"";return br(t.runSync(t.parse(o),o),e)},dr=e=>{let t=go.get(e);if(t)return t;let o=pr(e);return go.set(e,o),o},mr=e=>e.some(t=>Array.isArray(t)?t[0]===po:t===po),pr=e=>{let t=e.rehypePlugins||uo,o=e.remarkPlugins||uo,n=mr(t)?o:[...o,mo],s=e.remarkRehypeOptions?{...fo,...e.remarkRehypeOptions}:fo;return unified().use(ar).use(n).use(ir,s).use(t)},bo=e=>e,ur=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},fr=(e,t)=>{var o;for(let n in urlAttributes)if(Object.hasOwn(urlAttributes,n)&&Object.hasOwn(e.properties,n)){let s=e.properties[n],r=urlAttributes[n];(r===null||r.includes(e.tagName))&&(e.properties[n]=(o=t(String(s||""),n,e))!=null?o:void 0);}},gr=(e,t,o,n,s,r)=>{let i=false;return n?i=!n.includes(e.tagName):s&&(i=s.includes(e.tagName)),!i&&r&&typeof t=="number"&&(i=!r(e,t,o)),i},br=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:s,skipHtml:r,unwrapDisallowed:i,urlTransform:c}=t;if(o||n||s||r||c){let l=c||bo;visit(e,(m,d,p)=>{if(m.type==="raw"&&p&&typeof d=="number")return ur(p,d,r,m.value),d;if(m.type==="element"&&(fr(m,l),gr(m,d,p,n,s,o)&&p&&typeof d=="number"))return i&&m.children?p.children.splice(d,1,...m.children):p.children.splice(d,1),d});}return toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true})};var yr=/\[\^[\w-]{1,200}\](?!:)/,wr=/\[\^[\w-]{1,200}\]:/;var kr=/<(\w+)[\s>]/,Cr=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),ho=new Map,yo=new Map,vr=e=>{let t=e.toLowerCase(),o=ho.get(t);if(o)return o;let n=new RegExp(`<${t}(?=[\\s>/])[^>]*>`,"gi");return ho.set(t,n),n},xr=e=>{let t=e.toLowerCase(),o=yo.get(t);if(o)return o;let n=new RegExp(`</${t}(?=[\\s>])[^>]*>`,"gi");return yo.set(t,n),n},wo=(e,t)=>{if(Cr.has(t.toLowerCase()))return 0;let o=e.match(vr(t));if(!o)return 0;let n=0;for(let s of o)s.trimEnd().endsWith("/>")||(n+=1);return n},ko=(e,t)=>{let o=e.match(xr(t));return o?o.length:0},Pr=e=>{let t=0;for(let o=0;o<e.length-1;o+=1)e[o]==="$"&&e[o+1]==="$"&&(t+=1,o+=1);return t},We=e=>{let t=yr.test(e),o=wr.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),s=[],r=[],i=false;for(let c of n){let a=c.raw,l=s.length;if(r.length>0){s[l-1]+=a;let m=r.at(-1),d=wo(a,m),p=ko(a,m);for(let g=0;g<d;g+=1)r.push(m);for(let g=0;g<p;g+=1)r.length>0&&r.at(-1)===m&&r.pop();continue}if(c.type==="html"&&c.block){let m=a.match(kr);if(m){let d=m[1],p=wo(a,d),g=ko(a,d);p>g&&r.push(d);}}if(l>0&&!i){let m=s[l-1];if(Pr(m)%2===1){s[l-1]=m+a;continue}}s.push(a),c.type!=="space"&&(i=c.type==="code");}return s};var Co=(e,t)=>{if(!t.length)return e;let o=e;for(let n of t){let s=new RegExp(`(<${n}(?=[\\s>/])[^>]*>)([\\s\\S]*?)(</${n}\\s*>)`,"gi");o=o.replace(s,(r,i,c,a)=>{let l=c.replace(/\n\n/g,`
|
|
12
|
+
<!---->
|
|
13
|
+
`);return i+l+a});}return o};var Br=/^[ \t]*<[\w!/?-]/,Dr=/(^|\n)[ \t]{4,}(?=<[\w!/?-])/g,Or=e=>typeof e!="string"||e.length===0||!Br.test(e)?e:e.replace(Dr,"$1"),xo,Po,ve={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(Po=(xo=defaultSchema.protocols)==null?void 0:xo.href)!=null?Po:[],"tel"]}},Fe={raw:po,sanitize:[To,ve],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Vr={gfm:[Er,{}]},vo=Object.values(Fe),Ar=Object.values(Vr),jr={block:" \u258B",circle:" \u25CF"},zr={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},R=createContext(zr),No=memo(({content:e,shouldParseIncompleteMarkdown:t,shouldNormalizeHtmlIndentation:o,index:n,isIncomplete:s,...r})=>{let i=typeof e=="string"&&o?Or(e):e;return jsx(Re.Provider,{value:s,children:jsx(Ze,{...r,children:i})})},(e,t)=>{if(e.content!==t.content||e.shouldNormalizeHtmlIndentation!==t.shouldNormalizeHtmlIndentation||e.index!==t.index||e.isIncomplete!==t.isIncomplete)return false;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(s=>{var r,i;return ((r=e.components)==null?void 0:r[s])!==((i=t.components)==null?void 0:i[s])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});No.displayName="Block";var qr=["github-light","github-dark"],_r=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,normalizeHtmlIndentation:n=false,components:s,rehypePlugins:r=vo,remarkPlugins:i=Ar,className:c,shikiTheme:a=qr,mermaid:l,controls:m=true,isAnimating:d=false,animated:p,BlockComponent:g=No,parseMarkdownIntoBlocksFn:b=We,caret:h,plugins:u,remend:C,linkSafety:k={enabled:true},allowedTags:w,...T})=>{let H=useId(),[S,B]=useTransition(),O=useMemo(()=>w?Object.keys(w):[],[w]),E=useMemo(()=>{if(typeof e!="string")return "";let x=t==="streaming"&&o?Hr(e,C):e;return O.length>0&&(x=Co(x,O)),x},[e,t,o,C,O]),I=useMemo(()=>b(E),[E,b]),[z,v]=useState(I);useEffect(()=>{t==="streaming"?B(()=>{v(I);}):v(I);},[I,t]);let L=t==="streaming"?z:I,ce=useMemo(()=>L.map((x,V)=>`${H}-${V}`),[L.length,H]),Pe=useMemo(()=>p?p===true?Q():Q(p):null,[p]),Ue=useMemo(()=>{var x,V;return {shikiTheme:(V=(x=u==null?void 0:u.code)==null?void 0:x.getThemes())!=null?V:a,controls:m,isAnimating:d,mode:t,mermaid:l,linkSafety:k}},[a,m,d,t,l,k,u==null?void 0:u.code]),Xe=useMemo(()=>({...lo,...s}),[s]),Je=useMemo(()=>{let x=[];return u!=null&&u.cjk&&(x=[...x,...u.cjk.remarkPluginsBefore]),x=[...x,...i],u!=null&&u.cjk&&(x=[...x,...u.cjk.remarkPluginsAfter]),u!=null&&u.math&&(x=[...x,u.math.remarkPlugin]),x},[i,u==null?void 0:u.math,u==null?void 0:u.cjk]),Ke=useMemo(()=>{var V;let x=r;if(w&&Object.keys(w).length>0&&r===vo){let Te={...ve,tagNames:[...(V=ve.tagNames)!=null?V:[],...Object.keys(w)],attributes:{...ve.attributes,...w}};x=[Fe.raw,[To,Te],Fe.harden];}return u!=null&&u.math&&(x=[...x,u.math.rehypePlugin]),Pe&&d&&(x=[...x,Pe.rehypePlugin]),x},[r,u==null?void 0:u.math,Pe,d,w]),Me=useMemo(()=>{if(!d||L.length===0)return false;let x=L.at(-1);return ze(x)||co(x)},[d,L]),Eo=useMemo(()=>h&&d&&!Me?{"--streamdown-caret":`"${jr[h]}"`}:void 0,[h,d,Me]);return t==="static"?jsx(pe.Provider,{value:u!=null?u:null,children:jsx(R.Provider,{value:Ue,children:jsx("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",c),children:jsx(Ze,{components:Xe,rehypePlugins:Ke,remarkPlugins:Je,...T,children:E})})})}):jsx(pe.Provider,{value:u!=null?u:null,children:jsx(R.Provider,{value:Ue,children:jsxs("div",{className:f("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",h&&!Me?"*:last:after:inline *:last:after:align-baseline *:last:after:content-[var(--streamdown-caret)]":null,c),style:Eo,children:[L.length===0&&h&&d&&jsx("span",{}),L.map((x,V)=>{let Te=V===L.length-1,Ho=d&&Te&&ze(x);return jsx(g,{components:Xe,content:x,index:V,isIncomplete:Ho,rehypePlugins:Ke,remarkPlugins:Je,shouldNormalizeHtmlIndentation:n,shouldParseIncompleteMarkdown:o,...T},ce[V])})]})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.animated===t.animated&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety&&e.normalizeHtmlIndentation===t.normalizeHtmlIndentation);_r.displayName="Streamdown";var So=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:s=.1,showControls:r=true,initialZoom:i=1,fullscreen:c=false})=>{let a=useRef(null),l=useRef(null),[m,d]=useState(i),[p,g]=useState({x:0,y:0}),[b,h]=useState(false),[u,C]=useState({x:0,y:0}),[k,w]=useState({x:0,y:0}),T=useCallback(v=>{d(L=>Math.max(o,Math.min(n,L+v)));},[o,n]),H=useCallback(()=>{T(s);},[T,s]),S=useCallback(()=>{T(-s);},[T,s]),B=useCallback(()=>{d(i),g({x:0,y:0});},[i]),O=useCallback(v=>{v.preventDefault();let L=v.deltaY>0?-s:s;T(L);},[T,s]),E=useCallback(v=>{if(v.button!==0||v.isPrimary===false)return;h(true),C({x:v.clientX,y:v.clientY}),w(p);let L=v.currentTarget;L instanceof HTMLElement&&L.setPointerCapture(v.pointerId);},[p]),I=useCallback(v=>{if(!b)return;v.preventDefault();let L=v.clientX-u.x,ce=v.clientY-u.y;g({x:k.x+L,y:k.y+ce});},[b,u,k]),z=useCallback(v=>{h(false);let L=v.currentTarget;L instanceof HTMLElement&&L.releasePointerCapture(v.pointerId);},[]);return useEffect(()=>{let v=a.current;if(v)return v.addEventListener("wheel",O,{passive:false}),()=>{v.removeEventListener("wheel",O);}},[O]),useEffect(()=>{let v=l.current;if(v&&b)return document.body.style.userSelect="none",v.addEventListener("pointermove",I,{passive:false}),v.addEventListener("pointerup",z),v.addEventListener("pointercancel",z),()=>{document.body.style.userSelect="",v.removeEventListener("pointermove",I),v.removeEventListener("pointerup",z),v.removeEventListener("pointercancel",z);}},[b,I,z]),jsxs("div",{className:f("relative flex flex-col",c?"h-full w-full":"min-h-28 w-full",t),ref:a,style:{cursor:b?"grabbing":"grab"},children:[r?jsxs("div",{className:f("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/80 p-1 supports-[backdrop-filter]:bg-background/70 supports-[backdrop-filter]:backdrop-blur-sm",c?"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:m>=n,onClick:H,title:"Zoom in",type:"button",children:jsx(lt,{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:m<=o,onClick:S,title:"Zoom out",type:"button",children:jsx(ct,{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:B,title:"Reset zoom and pan",type:"button",children:jsx(it,{size:16})})]}):null,jsx("div",{className:f("flex-1 origin-center transition-transform duration-150 ease-out",c?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:E,ref:l,role:"application",style:{transform:`translate(${p.x}px, ${p.y}px) scale(${m})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var Nt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:s=true})=>{let[r,i]=useState(null),[c,a]=useState(false),[l,m]=useState(""),[d,p]=useState(""),[g,b]=useState(0),{mermaid:h}=useContext(R),u=G(),C=h==null?void 0:h.errorComponent,{shouldRender:k,containerRef:w}=Ge({immediate:n});if(useEffect(()=>{if(!k)return;if(!u){i("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{i(null),a(!0);let S=u.getMermaid(o),B=e.split("").reduce((I,z)=>(I<<5)-I+z.charCodeAt(0)|0,0),O=`mermaid-${Math.abs(B)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:E}=await S.render(O,e);m(E),p(E);}catch(S){if(!(d||l)){let B=S instanceof Error?S.message:"Failed to render Mermaid chart";i(B);}}finally{a(false);}})();},[e,o,g,k,u]),!(k||l||d))return jsx("div",{className:f("my-4 min-h-[200px]",t),ref:w});if(c&&!l&&!d)return jsx("div",{className:f("my-4 flex justify-center p-4",t),ref:w,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&&!l&&!d){let H=()=>b(S=>S+1);return C?jsx("div",{ref:w,children:jsx(C,{chart:e,error:r,retry:H})}):jsxs("div",{className:f("rounded-md bg-red-50 p-4",t),ref:w,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 T=l||d;return jsx("div",{className:f("size-full",t),"data-streamdown":"mermaid",ref:w,children:jsx(So,{className:f(n?"size-full overflow-hidden":"overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:s,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:f("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:T},role:"img"})})})};export{Q as a,Ie as b,Qe as c,Ks as d,Nt as e,bo as f,We as g,Or as h,Fe as i,Vr as j,R as k,No as l,_r as m};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {k,d,c}from'./chunk-RLXIAIE6.js';import {useContext,useState,useEffect}from'react';import {jsx}from'react/jsx-runtime';var L=({code:s,language:t,raw:e,className:n,...d$1})=>{let{shikiTheme:l}=useContext(k),o=d(),[m,i]=useState(e);return useEffect(()=>{if(!o){i(e);return}let g=o.highlight({code:s,language:t,themes:l},p=>{i(p);});g&&i(g);},[s,t,l,o,e]),jsx(c,{className:n,language:t,result:m,...d$1})};export{L as HighlightedCodeBlockBody};
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ import { Options as Options$1 } from 'remark-rehype';
|
|
|
11
11
|
|
|
12
12
|
interface AnimatePlugin {
|
|
13
13
|
name: "animate";
|
|
14
|
-
type: "animate";
|
|
15
14
|
rehypePlugin: Pluggable;
|
|
15
|
+
type: "animate";
|
|
16
16
|
}
|
|
17
17
|
interface AnimateOptions {
|
|
18
18
|
animation?: "fadeIn" | "blurIn" | "slideUp" | (string & {});
|
|
@@ -51,21 +51,21 @@ declare const defaultUrlTransform: UrlTransform;
|
|
|
51
51
|
* A single token in a highlighted line
|
|
52
52
|
*/
|
|
53
53
|
interface HighlightToken {
|
|
54
|
-
content: string;
|
|
55
|
-
color?: string;
|
|
56
54
|
bgColor?: string;
|
|
57
|
-
|
|
55
|
+
color?: string;
|
|
56
|
+
content: string;
|
|
58
57
|
htmlAttrs?: Record<string, string>;
|
|
58
|
+
htmlStyle?: Record<string, string>;
|
|
59
59
|
offset?: number;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Result from code highlighting (compatible with shiki's TokensResult)
|
|
63
63
|
*/
|
|
64
64
|
interface HighlightResult {
|
|
65
|
-
tokens: HighlightToken[][];
|
|
66
|
-
fg?: string;
|
|
67
65
|
bg?: string;
|
|
66
|
+
fg?: string;
|
|
68
67
|
rootStyle?: string | false;
|
|
68
|
+
tokens: HighlightToken[][];
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
71
|
* Options for highlighting code
|
|
@@ -79,26 +79,26 @@ interface HighlightOptions {
|
|
|
79
79
|
* Plugin for code syntax highlighting (Shiki)
|
|
80
80
|
*/
|
|
81
81
|
interface CodeHighlighterPlugin {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Get list of supported languages
|
|
84
|
+
*/
|
|
85
|
+
getSupportedLanguages: () => BundledLanguage[];
|
|
86
|
+
/**
|
|
87
|
+
* Get the configured themes
|
|
88
|
+
*/
|
|
89
|
+
getThemes: () => [BundledTheme, BundledTheme];
|
|
84
90
|
/**
|
|
85
91
|
* Highlight code and return tokens
|
|
86
92
|
* Returns null if highlighting not ready yet (async loading)
|
|
87
93
|
* Use callback for async result
|
|
88
94
|
*/
|
|
89
95
|
highlight: (options: HighlightOptions, callback?: (result: HighlightResult) => void) => HighlightResult | null;
|
|
96
|
+
name: "shiki";
|
|
90
97
|
/**
|
|
91
98
|
* Check if language is supported
|
|
92
99
|
*/
|
|
93
100
|
supportsLanguage: (language: BundledLanguage) => boolean;
|
|
94
|
-
|
|
95
|
-
* Get list of supported languages
|
|
96
|
-
*/
|
|
97
|
-
getSupportedLanguages: () => BundledLanguage[];
|
|
98
|
-
/**
|
|
99
|
-
* Get the configured themes
|
|
100
|
-
*/
|
|
101
|
-
getThemes: () => [BundledTheme, BundledTheme];
|
|
101
|
+
type: "code-highlighter";
|
|
102
102
|
}
|
|
103
103
|
/**
|
|
104
104
|
* Mermaid instance interface
|
|
@@ -113,70 +113,90 @@ interface MermaidInstance {
|
|
|
113
113
|
* Plugin for diagram rendering (Mermaid)
|
|
114
114
|
*/
|
|
115
115
|
interface DiagramPlugin {
|
|
116
|
-
name: "mermaid";
|
|
117
|
-
type: "diagram";
|
|
118
|
-
/**
|
|
119
|
-
* Language identifier for code blocks
|
|
120
|
-
*/
|
|
121
|
-
language: string;
|
|
122
116
|
/**
|
|
123
117
|
* Get the mermaid instance (initialized with optional config)
|
|
124
118
|
*/
|
|
125
119
|
getMermaid: (config?: MermaidConfig) => MermaidInstance;
|
|
120
|
+
/**
|
|
121
|
+
* Language identifier for code blocks
|
|
122
|
+
*/
|
|
123
|
+
language: string;
|
|
124
|
+
name: "mermaid";
|
|
125
|
+
type: "diagram";
|
|
126
126
|
}
|
|
127
127
|
/**
|
|
128
128
|
* Plugin for math rendering (KaTeX)
|
|
129
129
|
*/
|
|
130
130
|
interface MathPlugin {
|
|
131
|
-
name: "katex";
|
|
132
|
-
type: "math";
|
|
133
131
|
/**
|
|
134
|
-
* Get
|
|
132
|
+
* Get CSS styles for math rendering (injected into head)
|
|
135
133
|
*/
|
|
136
|
-
|
|
134
|
+
getStyles?: () => string;
|
|
135
|
+
name: "katex";
|
|
137
136
|
/**
|
|
138
137
|
* Get rehype plugin for rendering math
|
|
139
138
|
*/
|
|
140
139
|
rehypePlugin: Pluggable;
|
|
141
140
|
/**
|
|
142
|
-
* Get
|
|
141
|
+
* Get remark plugin for parsing math syntax
|
|
143
142
|
*/
|
|
144
|
-
|
|
143
|
+
remarkPlugin: Pluggable;
|
|
144
|
+
type: "math";
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* Plugin for CJK text handling
|
|
148
148
|
*/
|
|
149
149
|
interface CjkPlugin {
|
|
150
150
|
name: "cjk";
|
|
151
|
-
type: "cjk";
|
|
152
151
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
152
|
+
* @deprecated Use remarkPluginsBefore and remarkPluginsAfter instead
|
|
153
|
+
* All remark plugins (for backwards compatibility)
|
|
155
154
|
*/
|
|
156
|
-
|
|
155
|
+
remarkPlugins: Pluggable[];
|
|
157
156
|
/**
|
|
158
157
|
* Remark plugins that must run AFTER remarkGfm
|
|
159
158
|
* (e.g., autolink boundary splitting, strikethrough enhancements)
|
|
160
159
|
*/
|
|
161
160
|
remarkPluginsAfter: Pluggable[];
|
|
162
161
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
162
|
+
* Remark plugins that must run BEFORE remarkGfm
|
|
163
|
+
* (e.g., remark-cjk-friendly which modifies emphasis handling)
|
|
165
164
|
*/
|
|
166
|
-
|
|
165
|
+
remarkPluginsBefore: Pluggable[];
|
|
166
|
+
type: "cjk";
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
169
|
* Plugin configuration passed to Streamdown
|
|
170
170
|
*/
|
|
171
171
|
interface PluginConfig {
|
|
172
|
+
cjk?: CjkPlugin;
|
|
172
173
|
code?: CodeHighlighterPlugin;
|
|
173
|
-
mermaid?: DiagramPlugin;
|
|
174
174
|
math?: MathPlugin;
|
|
175
|
-
|
|
175
|
+
mermaid?: DiagramPlugin;
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Hook to check if the current block has an incomplete (unclosed) code fence.
|
|
180
|
+
*
|
|
181
|
+
* Returns `true` when the code fence in this block is still being streamed.
|
|
182
|
+
* Useful for deferring expensive renders (syntax highlighting, Mermaid diagrams)
|
|
183
|
+
* until the code block is complete.
|
|
184
|
+
*/
|
|
185
|
+
declare const useIsCodeFenceIncomplete: () => boolean;
|
|
186
|
+
|
|
178
187
|
declare const parseMarkdownIntoBlocks: (markdown: string) => string[];
|
|
179
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Normalizes indentation in HTML blocks to prevent Markdown parsers from
|
|
191
|
+
* treating indented HTML tags as code blocks (4+ spaces = code in Markdown).
|
|
192
|
+
*
|
|
193
|
+
* Useful when rendering AI-generated HTML content with nested tags that
|
|
194
|
+
* are indented for readability.
|
|
195
|
+
*
|
|
196
|
+
* @param content - The raw HTML/Markdown string to normalize
|
|
197
|
+
* @returns The normalized string with reduced indentation before HTML tags
|
|
198
|
+
*/
|
|
199
|
+
declare const normalizeHtmlIndentation: (content: string) => string;
|
|
180
200
|
type ControlsConfig = boolean | {
|
|
181
201
|
table?: boolean;
|
|
182
202
|
code?: boolean;
|
|
@@ -188,10 +208,10 @@ type ControlsConfig = boolean | {
|
|
|
188
208
|
};
|
|
189
209
|
};
|
|
190
210
|
interface LinkSafetyModalProps {
|
|
191
|
-
url: string;
|
|
192
211
|
isOpen: boolean;
|
|
193
212
|
onClose: () => void;
|
|
194
213
|
onConfirm: () => void;
|
|
214
|
+
url: string;
|
|
195
215
|
}
|
|
196
216
|
interface LinkSafetyConfig {
|
|
197
217
|
enabled: boolean;
|
|
@@ -199,8 +219,8 @@ interface LinkSafetyConfig {
|
|
|
199
219
|
renderModal?: (props: LinkSafetyModalProps) => React.ReactNode;
|
|
200
220
|
}
|
|
201
221
|
interface MermaidErrorComponentProps {
|
|
202
|
-
error: string;
|
|
203
222
|
chart: string;
|
|
223
|
+
error: string;
|
|
204
224
|
retry: () => void;
|
|
205
225
|
}
|
|
206
226
|
interface MermaidOptions {
|
|
@@ -213,6 +233,8 @@ type StreamdownProps = Options & {
|
|
|
213
233
|
BlockComponent?: React.ComponentType<BlockProps>;
|
|
214
234
|
parseMarkdownIntoBlocksFn?: (markdown: string) => string[];
|
|
215
235
|
parseIncompleteMarkdown?: boolean;
|
|
236
|
+
/** Normalize HTML block indentation to prevent 4+ spaces being treated as code blocks. @default false */
|
|
237
|
+
normalizeHtmlIndentation?: boolean;
|
|
216
238
|
className?: string;
|
|
217
239
|
shikiTheme?: [BundledTheme, BundledTheme];
|
|
218
240
|
mermaid?: MermaidOptions;
|
|
@@ -233,20 +255,23 @@ declare const carets: {
|
|
|
233
255
|
circle: string;
|
|
234
256
|
};
|
|
235
257
|
interface StreamdownContextType {
|
|
236
|
-
shikiTheme: [BundledTheme, BundledTheme];
|
|
237
258
|
controls: ControlsConfig;
|
|
238
259
|
isAnimating: boolean;
|
|
239
|
-
mode: "static" | "streaming";
|
|
240
|
-
mermaid?: MermaidOptions;
|
|
241
260
|
linkSafety?: LinkSafetyConfig;
|
|
261
|
+
mermaid?: MermaidOptions;
|
|
262
|
+
mode: "static" | "streaming";
|
|
263
|
+
shikiTheme: [BundledTheme, BundledTheme];
|
|
242
264
|
}
|
|
243
265
|
declare const StreamdownContext: react.Context<StreamdownContextType>;
|
|
244
266
|
type BlockProps = Options & {
|
|
245
267
|
content: string;
|
|
246
268
|
shouldParseIncompleteMarkdown: boolean;
|
|
269
|
+
shouldNormalizeHtmlIndentation: boolean;
|
|
247
270
|
index: number;
|
|
271
|
+
/** Whether this block is incomplete (still being streamed) */
|
|
272
|
+
isIncomplete: boolean;
|
|
248
273
|
};
|
|
249
|
-
declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown: _, index: __, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
250
|
-
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, animated, BlockComponent, parseMarkdownIntoBlocksFn, caret, plugins, remend: remendOptions, linkSafety, allowedTags, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
274
|
+
declare const Block: react.MemoExoticComponent<({ content, shouldParseIncompleteMarkdown: _, shouldNormalizeHtmlIndentation, index: __, isIncomplete, ...props }: BlockProps) => react_jsx_runtime.JSX.Element>;
|
|
275
|
+
declare const Streamdown: react.MemoExoticComponent<({ children, mode, parseIncompleteMarkdown: shouldParseIncompleteMarkdown, normalizeHtmlIndentation: shouldNormalizeHtmlIndentation, components, rehypePlugins, remarkPlugins, className, shikiTheme, mermaid, controls, isAnimating, animated, BlockComponent, parseMarkdownIntoBlocksFn, caret, plugins, remend: remendOptions, linkSafety, allowedTags, ...props }: StreamdownProps) => react_jsx_runtime.JSX.Element>;
|
|
251
276
|
|
|
252
|
-
export { type AllowElement, type AllowedTags, type AnimateOptions, Block, type CjkPlugin, type CodeHighlighterPlugin, type Components, type ControlsConfig, type DiagramPlugin, type ExtraProps, type HighlightOptions, type LinkSafetyConfig, type LinkSafetyModalProps, type MathPlugin, type MermaidErrorComponentProps, type MermaidOptions, type PluginConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, type UrlTransform, createAnimatePlugin, defaultRehypePlugins, defaultRemarkPlugins, defaultUrlTransform, parseMarkdownIntoBlocks };
|
|
277
|
+
export { type AllowElement, type AllowedTags, type AnimateOptions, Block, type BlockProps, type CjkPlugin, type CodeHighlighterPlugin, type Components, type ControlsConfig, type DiagramPlugin, type ExtraProps, type HighlightOptions, type LinkSafetyConfig, type LinkSafetyModalProps, type MathPlugin, type MermaidErrorComponentProps, type MermaidOptions, type PluginConfig, Streamdown, StreamdownContext, type StreamdownContextType, type StreamdownProps, type UrlTransform, createAnimatePlugin, defaultRehypePlugins, defaultRemarkPlugins, defaultUrlTransform, normalizeHtmlIndentation, parseMarkdownIntoBlocks, useIsCodeFenceIncomplete };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
export{
|
|
2
|
+
export{l as Block,m as Streamdown,k as StreamdownContext,a as createAnimatePlugin,i as defaultRehypePlugins,j as defaultRemarkPlugins,f as defaultUrlTransform,h as normalizeHtmlIndentation,g as parseMarkdownIntoBlocks,b as useIsCodeFenceIncomplete}from'./chunk-RLXIAIE6.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamdown",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"@types/hast": "^3.0.4",
|
|
33
33
|
"@types/react": "^19.2.7",
|
|
34
34
|
"@types/react-dom": "^19.2.3",
|
|
35
|
+
"react-dom": "^19.2.3",
|
|
35
36
|
"@vitejs/plugin-react": "^5.1.2",
|
|
36
37
|
"@vitest/coverage-v8": "^4.0.15",
|
|
37
38
|
"jsdom": "^27.3.0",
|
|
@@ -43,18 +44,19 @@
|
|
|
43
44
|
"tsup": "^8.5.1",
|
|
44
45
|
"vitest": "^4.0.15",
|
|
45
46
|
"@streamdown/cjk": "1.0.2",
|
|
46
|
-
"@streamdown/
|
|
47
|
-
"@streamdown/
|
|
47
|
+
"@streamdown/mermaid": "1.0.2",
|
|
48
|
+
"@streamdown/math": "1.0.2"
|
|
48
49
|
},
|
|
49
50
|
"peerDependencies": {
|
|
50
|
-
"react": "^18.0.0 || ^19.0.0"
|
|
51
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
52
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
55
|
"clsx": "^2.1.1",
|
|
54
56
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
55
57
|
"html-url-attributes": "^3.0.1",
|
|
56
58
|
"marked": "^17.0.1",
|
|
57
|
-
"rehype-harden": "^1.1.
|
|
59
|
+
"rehype-harden": "^1.1.8",
|
|
58
60
|
"rehype-raw": "^7.0.0",
|
|
59
61
|
"rehype-sanitize": "^6.0.0",
|
|
60
62
|
"remark-gfm": "^4.0.1",
|
|
@@ -64,7 +66,7 @@
|
|
|
64
66
|
"unified": "^11.0.5",
|
|
65
67
|
"unist-util-visit": "^5.0.0",
|
|
66
68
|
"unist-util-visit-parents": "^6.0.0",
|
|
67
|
-
"remend": "1.2.
|
|
69
|
+
"remend": "1.2.1"
|
|
68
70
|
},
|
|
69
71
|
"scripts": {
|
|
70
72
|
"build": "tsup",
|
package/dist/chunk-LPQFK2AO.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {createContext,lazy,memo,useContext,isValidElement,useId,useTransition,useMemo,useState,useEffect,cloneElement,useCallback,Suspense,useRef}from'react';import {harden}from'rehype-harden';import Jt from'rehype-raw';import no,{defaultSchema}from'rehype-sanitize';import _n from'remark-gfm';import Xn from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';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 {urlAttributes}from'html-url-attributes';import vn from'remark-parse';import Cn from'remark-rehype';import {unified}from'unified';import {visit}from'unist-util-visit';import {Lexer}from'marked';var fo=300,go="300px",bo=500;function ze(e={}){let{immediate:t=false,debounceDelay:o=fo,rootMargin:n=go,idleTimeout:i=bo}=e,[r,a]=useState(false),c=useRef(null),s=useRef(null),l=useRef(null),d=useMemo(()=>b=>{let f=Date.now();return window.setTimeout(()=>{b({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-f))});},1)},[]),p=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(b,f)=>window.requestIdleCallback(b,f):d,[d]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?b=>window.cancelIdleCallback(b):b=>{clearTimeout(b);},[]);return useEffect(()=>{if(t){a(true);return}let b=c.current;if(!b)return;s.current&&(clearTimeout(s.current),s.current=null),l.current&&(m(l.current),l.current=null);let f=()=>{s.current&&(clearTimeout(s.current),s.current=null),l.current&&(m(l.current),l.current=null);},u=P=>{l.current=p(M=>{M.timeRemaining()>0||M.didTimeout?(a(true),P.disconnect()):l.current=p(()=>{a(true),P.disconnect();},{timeout:i/2});},{timeout:i});},y=P=>{f(),s.current=window.setTimeout(()=>{var E,H;let M=P.takeRecords();(M.length===0||(H=(E=M.at(-1))==null?void 0:E.isIntersecting)!=null&&H)&&u(P);},o);},k=(P,M)=>{P.isIntersecting?y(M):f();},C=new IntersectionObserver(P=>{for(let M of P)k(M,C);},{rootMargin:n,threshold:0});return C.observe(b),()=>{s.current&&clearTimeout(s.current),l.current&&m(l.current),C.disconnect();}},[t,o,n,i,m,p]),{shouldRender:r,containerRef:c}}var Ze=/\s/,wo=/^\s+$/,ko=new Set(["code","pre","svg","math","annotation"]),vo=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",Co=e=>e.some(t=>vo(t)&&ko.has(t.tagName)),xo=e=>{let t=[],o="",n=false;for(let i of e){let r=Ze.test(i);r!==n&&o&&(t.push(o),o=""),o+=i,n=r;}return o&&t.push(o),t},Po=e=>{let t=[],o="";for(let n of e)Ze.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},Mo=(e,t,o,n)=>({type:"element",tagName:"span",properties:{"data-sd-animate":true,style:`--sd-animation:sd-${t};--sd-duration:${o}ms;--sd-easing:${n}`},children:[{type:"text",value:e}]}),To=(e,t,o)=>{let n=t.at(-1);if(!(n&&"children"in n))return;if(Co(t))return SKIP;let i=n,r=i.children.indexOf(e);if(r===-1)return;let a=e.value;if(!a.trim())return;let s=(o.sep==="char"?Po(a):xo(a)).map(l=>wo.test(l)?{type:"text",value:l}:Mo(l,o.animation,o.duration,o.easing));return i.children.splice(r,1,...s),r+s.length};function Q(e){var n,i,r,a;let t={animation:(n=e==null?void 0:e.animation)!=null?n:"fadeIn",duration:(i=e==null?void 0:e.duration)!=null?i:150,easing:(r=e==null?void 0:e.easing)!=null?r:"ease",sep:(a=e==null?void 0:e.sep)!=null?a:"word"};return {name:"animate",type:"animate",rehypePlugin:()=>c=>{visitParents(c,"text",(s,l)=>To(s,l,t));}}}Q();var J=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"})}),F=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"})}),Z=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"})}),We=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"})]}),$e=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"})}),Ue=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"})}),se=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"})}),xe=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 10.25V13.25C13.5 13.3881 13.3881 13.5 13.25 13.5H2.75C2.61193 13.5 2.5 13.3881 2.5 13.25L2.5 2.75C2.5 2.61193 2.61193 2.5 2.75 2.5H5.75H6.5V1H5.75H2.75C1.7835 1 1 1.7835 1 2.75V13.25C1 14.2165 1.7835 15 2.75 15H13.25C14.2165 15 15 14.2165 15 13.25V10.25V9.5H13.5V10.25ZM9 1H9.75H14.2495C14.6637 1 14.9995 1.33579 14.9995 1.75V6.25V7H13.4995V6.25V3.56066L8.53033 8.52978L8 9.06011L6.93934 7.99945L7.46967 7.46912L12.4388 2.5H9.75H9V1Z",fill:"currentColor",fillRule:"evenodd"})}),_e=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"})}),Xe=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.75H8.25H8.875V7.125H8.25H4.75H4.125V5.875Z",fill:"currentColor",fillRule:"evenodd"})});var g=(...e)=>twMerge(clsx(e)),B=(e,t,o)=>{let n=typeof t=="string"?new Blob([t],{type:o}):t,i=URL.createObjectURL(n),r=document.createElement("a");r.href=i,r.download=e,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(i);};var Io=createContext({code:""}),ae=()=>useContext(Io);var Pe=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:i,code:r,...a})=>{let[c,s]=useState(false),l=useRef(0),{code:d}=ae(),{isAnimating:p}=useContext(L),m=r!=null?r:d,b=async()=>{var u;if(typeof window=="undefined"||!((u=navigator==null?void 0:navigator.clipboard)!=null&&u.writeText)){t==null||t(new Error("Clipboard API not available"));return}try{c||(await navigator.clipboard.writeText(m),s(!0),e==null||e(),l.current=window.setTimeout(()=>s(!1),o));}catch(y){t==null||t(y);}};useEffect(()=>()=>{window.clearTimeout(l.current);},[]);let f=c?J:F;return jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),"data-streamdown":"code-block-copy-button",disabled:p,onClick:b,title:"Copy Code",type:"button",...a,children:n!=null?n:jsx(f,{size:14})})};var Fe={"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"},Ge=({onDownload:e,onError:t,language:o,children:n,className:i,code:r,...a})=>{let{code:c}=ae(),{isAnimating:s}=useContext(L),l=r!=null?r:c,p=`file.${o&&o in Fe?Fe[o]:"txt"}`,m="text/plain",b=()=>{try{B(p,l,m),e==null||e();}catch(f){t==null||t(f);}};return jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),"data-streamdown":"code-block-download-button",disabled:s,onClick:b,title:"Download file",type:"button",...a,children:n!=null?n:jsx(Z,{size:14})})};var Te=()=>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(We,{className:"size-4 animate-spin"})})]});var Ao=/\.[^/.]+$/,Ye=({node:e,className:t,src:o,alt:n,...i})=>{let r=async()=>{if(o)try{let c=await(await fetch(o)).blob(),l=new URL(o,window.location.origin).pathname.split("/").pop()||"",d=l.split(".").pop(),p=l.includes(".")&&d!==void 0&&d.length<=4,m="";if(p)m=l;else {let b=c.type,f="png";b.includes("jpeg")||b.includes("jpg")?f="jpg":b.includes("png")?f="png":b.includes("svg")?f="svg":b.includes("gif")?f="gif":b.includes("webp")&&(f="webp"),m=`${(n||l||"image").replace(Ao,"")}.${f}`;}B(m,c,c.type);}catch(a){window.open(o,"_blank");}};return o?jsxs("div",{className:"group relative my-4 inline-block","data-streamdown":"image-wrapper",children:[jsx("img",{alt:n,className:g("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...i}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsx("button",{className:g("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(Z,{size:14})})]}):null};var ee=0,Wo=()=>{ee+=1,ee===1&&(document.body.style.overflow="hidden");},$o=()=>{ee=Math.max(0,ee-1),ee===0&&(document.body.style.overflow="");},tt=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[i,r]=useState(false),a=useCallback(async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3);}catch(s){}},[e]),c=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){Wo();let s=l=>{l.key==="Escape"&&o();};return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s),$o();}}},[t,o]),t?jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/50 backdrop-blur-sm","data-streamdown":"link-safety-modal",onClick:o,onKeyDown:s=>{s.key==="Escape"&&o();},role:"button",tabIndex:0,children:jsxs("div",{className:"relative mx-4 flex w-full max-w-md flex-col gap-4 rounded-xl border bg-background p-6 shadow-lg",onClick:s=>s.stopPropagation(),onKeyDown:s=>s.stopPropagation(),role:"presentation",children:[jsx("button",{className:"absolute top-4 right-4 rounded-md p-1 text-muted-foreground transition-all hover:bg-muted hover:text-foreground",onClick:o,title:"Close",type:"button",children:jsx(se,{size:16})}),jsxs("div",{className:"flex flex-col gap-2",children:[jsxs("div",{className:"flex items-center gap-2 font-semibold text-lg",children:[jsx(xe,{size:20}),jsx("span",{children:"Open external link?"})]}),jsx("p",{className:"text-muted-foreground text-sm",children:"You're about to visit an external website."})]}),jsx("div",{className:g("break-all rounded-md bg-muted p-3 font-mono text-sm",e.length>100&&"max-h-32 overflow-y-auto"),children:e}),jsxs("div",{className:"flex gap-2",children:[jsx("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md border bg-background px-4 py-2 font-medium text-sm transition-all hover:bg-muted",onClick:a,type:"button",children:i?jsxs(Fragment,{children:[jsx(J,{size:14}),jsx("span",{children:"Copied"})]}):jsxs(Fragment,{children:[jsx(F,{size:14}),jsx("span",{children:"Copy link"})]})}),jsxs("button",{className:"flex flex-1 items-center justify-center gap-2 rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground text-sm transition-all hover:bg-primary/90",onClick:c,type:"button",children:[jsx(xe,{size:14}),jsx("span",{children:"Open link"})]})]})]})}):null};var le=createContext(null),ot=()=>useContext(le),Zr=()=>{var t;let e=ot();return (t=e==null?void 0:e.code)!=null?t:null},K=()=>{var t;let e=ot();return (t=e==null?void 0:e.mermaid)!=null?t:null};var nt=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((i,r)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),c=new Image;c.crossOrigin="anonymous",c.onload=()=>{let s=document.createElement("canvas"),l=c.width*o,d=c.height*o;s.width=l,s.height=d;let p=s.getContext("2d");if(!p){r(new Error("Failed to create 2D canvas context for PNG export"));return}p.drawImage(c,0,0,l,d),s.toBlob(m=>{if(!m){r(new Error("Failed to create PNG blob"));return}i(m);},"image/png");},c.onerror=()=>r(new Error("Failed to load SVG image")),c.src=a;})};var st=({chart:e,children:t,className:o,onDownload:n,config:i,onError:r})=>{let[a,c]=useState(false),s=useRef(null),{isAnimating:l}=useContext(L),d=K(),p=async m=>{try{if(m==="mmd"){B("diagram.mmd",e,"text/plain"),c(!1),n==null||n(m);return}if(!d){r==null||r(new Error("Mermaid plugin not available"));return}let b=d.getMermaid(i),f=e.split("").reduce((k,C)=>(k<<5)-k+C.charCodeAt(0)|0,0),u=`mermaid-${Math.abs(f)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:y}=await b.render(u,e);if(!y){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){B("diagram.svg",y,"image/svg+xml"),c(!1),n==null||n(m);return}if(m==="png"){let k=await nt(y);B("diagram.png",k,"image/png"),n==null||n(m),c(!1);return}}catch(b){r==null||r(b);}};return useEffect(()=>{let m=b=>{let f=b.composedPath();s.current&&!f.includes(s.current)&&c(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:"relative",ref:s,children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:l,onClick:()=>c(!a),title:"Download diagram",type:"button",children:t!=null?t:jsx(Z,{size:14})}),a?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("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:()=>p("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:()=>p("mmd"),title:"Download diagram as MMD",type:"button",children:"MMD"})]}):null]})};var oe=0,Qo=()=>{oe+=1,oe===1&&(document.body.style.overflow="hidden");},en=()=>{oe=Math.max(0,oe-1),oe===0&&(document.body.style.overflow="");},ct=({chart:e,config:t,onFullscreen:o,onExit:n,className:i,...r})=>{let[a,c]=useState(false),{isAnimating:s,controls:l}=useContext(L),d=(()=>{if(typeof l=="boolean")return l;let m=l.mermaid;return m===false?false:m===true||m===void 0?true:m.panZoom!==false})(),p=()=>{c(!a);};return useEffect(()=>{if(a){Qo();let m=b=>{b.key==="Escape"&&c(false);};return document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m),en();}}},[a]),useEffect(()=>{a?o==null||o():n&&n();},[a,o,n]),jsxs(Fragment,{children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",i),disabled:s,onClick:p,title:"View fullscreen",type:"button",...r,children:jsx($e,{size:14})}),a?jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-background/95 backdrop-blur-sm",onClick:p,onKeyDown:m=>{m.key==="Escape"&&p();},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:p,title:"Exit fullscreen",type:"button",children:jsx(se,{size:20})}),jsx("div",{className:"flex size-full items-center justify-center p-4",onClick:m=>m.stopPropagation(),onKeyDown:m=>m.stopPropagation(),role:"presentation",children:jsx(lt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var ce=e=>{var r,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let c of n)t.push(((r=c.textContent)==null?void 0:r.trim())||"");let i=e.querySelectorAll("tbody tr");for(let c of i){let s=[],l=c.querySelectorAll("td");for(let d of l)s.push(((a=d.textContent)==null?void 0:a.trim())||"");o.push(s);}return {headers:t,rows:o}},de=e=>{let{headers:t,rows:o}=e,n=c=>{let s=false,l=false;for(let d of c){if(d==='"'){s=true,l=true;break}(d===","||d===`
|
|
3
|
-
`)&&(s=true);}return s?l?`"${c.replace(/"/g,'""')}"`:`"${c}"`:c},i=t.length>0?o.length+1:o.length,r=new Array(i),a=0;t.length>0&&(r[a]=t.map(n).join(","),a+=1);for(let c of o)r[a]=c.map(n).join(","),a+=1;return r.join(`
|
|
4
|
-
`)},dt=e=>{let{headers:t,rows:o}=e,n=c=>{let s=false;for(let d of c)if(d===" "||d===`
|
|
5
|
-
`||d==="\r"){s=true;break}if(!s)return c;let l=[];for(let d of c)d===" "?l.push("\\t"):d===`
|
|
6
|
-
`?l.push("\\n"):d==="\r"?l.push("\\r"):l.push(d);return l.join("")},i=t.length>0?o.length+1:o.length,r=new Array(i),a=0;t.length>0&&(r[a]=t.map(n).join(" "),a+=1);for(let c of o)r[a]=c.map(n).join(" "),a+=1;return r.join(`
|
|
7
|
-
`)},Ne=e=>{let t=false;for(let n of e)if(n==="\\"||n==="|"){t=true;break}if(!t)return e;let o=[];for(let n of e)n==="\\"?o.push("\\\\"):n==="|"?o.push("\\|"):o.push(n);return o.join("")},mt=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),i=0,r=t.map(c=>Ne(c));n[i]=`| ${r.join(" | ")} |`,i+=1;let a=new Array(t.length);for(let c=0;c<t.length;c+=1)a[c]="---";n[i]=`| ${a.join(" | ")} |`,i+=1;for(let c of o)if(c.length<t.length){let s=new Array(t.length);for(let l=0;l<t.length;l+=1)s[l]=l<c.length?Ne(c[l]):"";n[i]=`| ${s.join(" | ")} |`,i+=1;}else {let s=c.map(l=>Ne(l));n[i]=`| ${s.join(" | ")} |`,i+=1;}return n.join(`
|
|
8
|
-
`)};var gt=({children:e,className:t,onCopy:o,onError:n,timeout:i=2e3})=>{let[r,a]=useState(false),[c,s]=useState(false),l=useRef(null),d=useRef(0),{isAnimating:p}=useContext(L),m=async f=>{var u,y;if(typeof window=="undefined"||!((u=navigator==null?void 0:navigator.clipboard)!=null&&u.write)){n==null||n(new Error("Clipboard API not available"));return}try{let k=(y=l.current)==null?void 0:y.closest('[data-streamdown="table-wrapper"]'),C=k==null?void 0:k.querySelector("table");if(!C){n==null||n(new Error("Table not found"));return}let P=ce(C),M=f==="csv"?de(P):dt(P),z=new ClipboardItem({"text/plain":new Blob([M],{type:"text/plain"}),"text/html":new Blob([C.outerHTML],{type:"text/html"})});await navigator.clipboard.write([z]),s(!0),a(!1),o==null||o(f),d.current=window.setTimeout(()=>s(!1),i);}catch(k){n==null||n(k);}};useEffect(()=>{let f=u=>{let y=u.composedPath();l.current&&!y.includes(l.current)&&a(false);};return document.addEventListener("mousedown",f),()=>{document.removeEventListener("mousedown",f),window.clearTimeout(d.current);}},[]);let b=c?J:F;return jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:p,onClick:()=>a(!r),title:"Copy table",type:"button",children:e!=null?e:jsx(b,{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:()=>m("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:()=>m("tsv"),title:"Copy table as TSV",type:"button",children:"TSV"})]}):null]})};var ht=({children:e,className:t,onDownload:o,onError:n})=>{let[i,r]=useState(false),a=useRef(null),{isAnimating:c}=useContext(L),s=l=>{var d;try{let p=(d=a.current)==null?void 0:d.closest('[data-streamdown="table-wrapper"]'),m=p==null?void 0:p.querySelector("table");if(!m){n==null||n(new Error("Table not found"));return}let b=ce(m),f=l==="csv"?de(b):mt(b);B(`table.${l==="csv"?"csv":"md"}`,f,l==="csv"?"text/csv":"text/markdown"),r(!1),o==null||o(l);}catch(p){n==null||n(p);}};return useEffect(()=>{let l=d=>{let p=d.composedPath();a.current&&!p.includes(a.current)&&r(false);};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l);}},[]),jsxs("div",{className:"relative",ref:a,children:[jsx("button",{className:g("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:c,onClick:()=>r(!i),title:"Download table",type:"button",children:e!=null?e:jsx(Z,{size:14})}),i?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:()=>s("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:()=>s("markdown"),title:"Download table as Markdown",type:"button",children:"Markdown"})]}):null]})};var wt=({children:e,className:t,showControls:o,...n})=>jsxs("div",{className:"my-4 flex flex-col space-y-2","data-streamdown":"table-wrapper",children:[o?jsxs("div",{className:"flex items-center justify-end gap-1",children:[jsx(gt,{}),jsx(ht,{})]}):null,jsx("div",{className:"overflow-x-auto overscroll-y-auto",children:jsx("table",{className:g("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});var mn=lazy(()=>import('./code-block-OCS4YCEC.js').then(e=>({default:e.CodeBlock}))),pn=lazy(()=>import('./mermaid-NOHMQCX5.js').then(e=>({default:e.Mermaid}))),un=/language-([^\s]+)/;function he(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 o=e.position.start,n=t.position.start,i=e.position.end,r=t.position.end;return (o==null?void 0:o.line)===(n==null?void 0:n.line)&&(o==null?void 0:o.column)===(n==null?void 0:n.column)&&(i==null?void 0:i.line)===(r==null?void 0:r.line)&&(i==null?void 0:i.column)===(r==null?void 0:r.column)}function N(e,t){return e.className===t.className&&he(e.node,t.node)}var Re=(e,t)=>typeof e=="boolean"?e:e[t]!==false,fe=(e,t)=>{if(typeof e=="boolean")return e;let o=e.mermaid;return o===false?false:o===true||o===void 0?true:o[t]!==false},Ee=memo(({children:e,className:t,node:o,...n})=>jsx("ol",{className:g("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>N(e,t));Ee.displayName="MarkdownOl";var Ct=memo(({children:e,className:t,node:o,...n})=>jsx("li",{className:g("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&he(e.node,t.node));Ct.displayName="MarkdownLi";var xt=memo(({children:e,className:t,node:o,...n})=>jsx("ul",{className:g("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>N(e,t));xt.displayName="MarkdownUl";var Pt=memo(({className:e,node:t,...o})=>jsx("hr",{className:g("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>N(e,t));Pt.displayName="MarkdownHr";var Mt=memo(({children:e,className:t,node:o,...n})=>jsx("span",{className:g("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>N(e,t));Mt.displayName="MarkdownStrong";var fn=({children:e,className:t,href:o,node:n,...i})=>{let{linkSafety:r}=useContext(L),[a,c]=useState(false),s=o==="streamdown:incomplete-link",l=useCallback(async b=>{if(!(!(r!=null&&r.enabled&&o)||s)){if(b.preventDefault(),r.onLinkCheck&&await r.onLinkCheck(o)){window.open(o,"_blank","noreferrer");return}c(true);}},[r,o,s]),d=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),p=useCallback(()=>{c(false);},[]),m={url:o!=null?o:"",isOpen:a,onClose:p,onConfirm:d};return r!=null&&r.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:g("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",onClick:l,type:"button",children:e}),r.renderModal?r.renderModal(m):jsx(tt,{...m})]}):jsx("a",{className:g("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...i,children:e})},Tt=memo(fn,(e,t)=>N(e,t)&&e.href===t.href);Tt.displayName="MarkdownA";var Nt=memo(({children:e,className:t,node:o,...n})=>jsx("h1",{className:g("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>N(e,t));Nt.displayName="MarkdownH1";var Lt=memo(({children:e,className:t,node:o,...n})=>jsx("h2",{className:g("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>N(e,t));Lt.displayName="MarkdownH2";var Rt=memo(({children:e,className:t,node:o,...n})=>jsx("h3",{className:g("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>N(e,t));Rt.displayName="MarkdownH3";var St=memo(({children:e,className:t,node:o,...n})=>jsx("h4",{className:g("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>N(e,t));St.displayName="MarkdownH4";var Et=memo(({children:e,className:t,node:o,...n})=>jsx("h5",{className:g("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>N(e,t));Et.displayName="MarkdownH5";var It=memo(({children:e,className:t,node:o,...n})=>jsx("h6",{className:g("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>N(e,t));It.displayName="MarkdownH6";var Ht=memo(({children:e,className:t,node:o,...n})=>{let{controls:i}=useContext(L),r=Re(i,"table");return jsx(wt,{className:t,showControls:r,...n,children:e})},(e,t)=>N(e,t));Ht.displayName="MarkdownTable";var Dt=memo(({children:e,className:t,node:o,...n})=>jsx("thead",{className:g("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>N(e,t));Dt.displayName="MarkdownThead";var Vt=memo(({children:e,className:t,node:o,...n})=>jsx("tbody",{className:g("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>N(e,t));Vt.displayName="MarkdownTbody";var jt=memo(({children:e,className:t,node:o,...n})=>jsx("tr",{className:g("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>N(e,t));jt.displayName="MarkdownTr";var Bt=memo(({children:e,className:t,node:o,...n})=>jsx("th",{className:g("whitespace-nowrap px-4 py-2 text-left font-semibold text-sm",t),"data-streamdown":"table-header-cell",...n,children:e}),(e,t)=>N(e,t));Bt.displayName="MarkdownTh";var Ot=memo(({children:e,className:t,node:o,...n})=>jsx("td",{className:g("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>N(e,t));Ot.displayName="MarkdownTd";var At=memo(({children:e,className:t,node:o,...n})=>jsx("blockquote",{className:g("my-4 border-muted-foreground/30 border-l-4 pl-4 text-muted-foreground italic",t),"data-streamdown":"blockquote",...n,children:e}),(e,t)=>N(e,t));At.displayName="MarkdownBlockquote";var qt=memo(({children:e,className:t,node:o,...n})=>jsx("sup",{className:g("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>N(e,t));qt.displayName="MarkdownSup";var zt=memo(({children:e,className:t,node:o,...n})=>jsx("sub",{className:g("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>N(e,t));zt.displayName="MarkdownSub";var Zt=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let r=s=>{var m,b;if(!isValidElement(s))return false;let l=Array.isArray(s.props.children)?s.props.children:[s.props.children],d=false,p=false;for(let f of l)if(f){if(typeof f=="string")f.trim()!==""&&(d=true);else if(isValidElement(f))if(((m=f.props)==null?void 0:m["data-footnote-backref"])!==void 0)p=true;else {let u=Array.isArray(f.props.children)?f.props.children:[f.props.children];for(let y of u){if(typeof y=="string"&&y.trim()!==""){d=true;break}if(isValidElement(y)&&((b=y.props)==null?void 0:b["data-footnote-backref"])===void 0){d=true;break}}}}return p&&!d},a=Array.isArray(e)?e.map(s=>{if(!isValidElement(s))return s;if(s.type===Ee){let d=(Array.isArray(s.props.children)?s.props.children:[s.props.children]).filter(p=>!r(p));return d.length===0?null:{...s,props:{...s.props,children:d}}}return s}):e;return (Array.isArray(a)?a.some(s=>s!==null):a!==null)?jsx("section",{className:t,...n,children:a}):null}return jsx("section",{className:t,...n,children:e})},(e,t)=>N(e,t));Zt.displayName="MarkdownSection";var gn=({node:e,className:t,children:o,...n})=>{var m;let i=!("data-block"in n),{mermaid:r,controls:a}=useContext(L),c=K();if(i)return jsx("code",{className:g("rounded bg-muted px-1.5 py-0.5 font-mono text-sm",t),"data-streamdown":"inline-code",...n,children:o});let s=t==null?void 0:t.match(un),l=(m=s==null?void 0:s.at(1))!=null?m:"",d="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?d=o.props.children:typeof o=="string"&&(d=o),l==="mermaid"&&c){let b=Re(a,"mermaid"),f=fe(a,"download"),u=fe(a,"copy"),y=fe(a,"fullscreen"),k=fe(a,"panZoom"),C=b&&(f||u||y);return jsx(Suspense,{fallback:jsx(Te,{}),children:jsxs("div",{className:g("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:[f?jsx(st,{chart:d,config:r==null?void 0:r.config}):null,u?jsx(Pe,{code:d}):null,y?jsx(ct,{chart:d,config:r==null?void 0:r.config}):null]}):null,jsx(pn,{chart:d,config:r==null?void 0:r.config,showControls:k})]})})}let p=Re(a,"code");return jsx(Suspense,{fallback:jsx(Te,{}),children:jsx(mn,{className:g("overflow-x-auto border-border border-t",t),code:d,language:l,children:p?jsxs(Fragment,{children:[jsx(Ge,{code:d,language:l}),jsx(Pe,{})]}):null})})},Wt=memo(gn,(e,t)=>e.className===t.className&&he(e.node,t.node));Wt.displayName="MarkdownCode";var $t=memo(Ye,(e,t)=>e.className===t.className&&he(e.node,t.node));$t.displayName="MarkdownImg";var Ut=memo(({children:e,className:t,node:o,...n})=>{let r=(Array.isArray(e)?e:[e]).filter(a=>a!=null&&a!=="");if(r.length===1&&isValidElement(r[0])){let a=r[0].props.node,c=a==null?void 0:a.tagName;if(c==="img")return jsx(Fragment,{children:e});if(c==="code"&&"data-block"in r[0].props)return jsx(Fragment,{children:e})}return jsx("p",{className:t,...n,children:e})},(e,t)=>N(e,t));Ut.displayName="MarkdownParagraph";var _t={ol:Ee,li:Ct,ul:xt,hr:Pt,strong:Mt,a:Tt,h1:Nt,h2:Lt,h3:Rt,h4:St,h5:Et,h6:It,table:Ht,thead:Dt,tbody:Vt,tr:jt,th:Bt,td:Ot,blockquote:At,code:Wt,img:$t,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:qt,sub:zt,p:Ut,section:Zt};var Xt=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var Ft=[],Kt={allowDangerousHtml:true},ye=new WeakMap,He=class{constructor(){this.cache=new Map;this.keyCache=new WeakMap;this.maxSize=100;}generateCacheKey(t){let o=this.keyCache.get(t);if(o)return o;let n=t.rehypePlugins,i=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(n||i||r)){let p="default";return this.keyCache.set(t,p),p}let a=p=>{if(!p||p.length===0)return "";let m="";for(let b=0;b<p.length;b+=1){let f=p[b];if(b>0&&(m+=","),Array.isArray(f)){let[u,y]=f;if(typeof u=="function"){let k=ye.get(u);k||(k=u.name,ye.set(u,k)),m+=k;}else m+=String(u);m+=":",m+=JSON.stringify(y);}else if(typeof f=="function"){let u=ye.get(f);u||(u=f.name,ye.set(f,u)),m+=u;}else m+=String(f);}return m},c=a(n),s=a(i),l=r?JSON.stringify(r):"",d=`${s}::${c}::${l}`;return this.keyCache.set(t,d),d}get(t){let o=this.generateCacheKey(t),n=this.cache.get(o);return n&&(this.cache.delete(o),this.cache.set(o,n)),n}set(t,o){let n=this.generateCacheKey(t);if(this.cache.size>=this.maxSize){let i=this.cache.keys().next().value;i&&this.cache.delete(i);}this.cache.set(n,o);}clear(){this.cache.clear();}},Gt=new He,De=e=>{let t=Mn(e),o=e.children||"";return En(t.runSync(t.parse(o),o),e)},Mn=e=>{let t=Gt.get(e);if(t)return t;let o=Nn(e);return Gt.set(e,o),o},Tn=e=>e.some(t=>Array.isArray(t)?t[0]===Jt:t===Jt),Nn=e=>{let t=e.rehypePlugins||Ft,o=e.remarkPlugins||Ft,n=Tn(t)?o:[...o,Xt],i=e.remarkRehypeOptions?{...Kt,...e.remarkRehypeOptions}:Kt;return unified().use(vn).use(n).use(Cn,i).use(t)},Yt=e=>e,Ln=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},Rn=(e,t)=>{var o;for(let n in urlAttributes)if(Object.hasOwn(urlAttributes,n)&&Object.hasOwn(e.properties,n)){let i=e.properties[n],r=urlAttributes[n];(r===null||r.includes(e.tagName))&&(e.properties[n]=(o=t(String(i||""),n,e))!=null?o:void 0);}},Sn=(e,t,o,n,i,r)=>{let a=false;return n?a=!n.includes(e.tagName):i&&(a=i.includes(e.tagName)),!a&&r&&typeof t=="number"&&(a=!r(e,t,o)),a},En=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:i,skipHtml:r,unwrapDisallowed:a,urlTransform:c}=t;if(o||n||i||r||c){let l=c||Yt;visit(e,(d,p,m)=>{if(d.type==="raw"&&m&&typeof p=="number")return Ln(m,p,r,d.value),p;if(d.type==="element"&&(Rn(d,l),Sn(d,p,m,n,i,o)&&m&&typeof p=="number"))return a&&d.children?m.children.splice(p,1,...d.children):m.children.splice(p,1),p});}return toJsxRuntime(e,{Fragment:Fragment,components:t.components,ignoreInvalidStyle:true,jsx:jsx,jsxs:jsxs,passKeys:true,passNode:true})};var Hn=/\[\^[\w-]{1,200}\](?!:)/,Dn=/\[\^[\w-]{1,200}\]:/,Vn=/<\/(\w+)>/,jn=/<(\w+)[\s>]/,Bn=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),On=e=>{let t=0;for(let o=0;o<e.length-1;o+=1)e[o]==="$"&&e[o+1]==="$"&&(t+=1,o+=1);return t},Ve=e=>{let t=Hn.test(e),o=Dn.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),i=[],r=[],a=false;for(let c of n){let s=c.raw,l=i.length;if(r.length>0){if(i[l-1]+=s,c.type==="html"){let d=s.match(Vn);if(d){let p=d[1];r.at(-1)===p&&r.pop();}}continue}if(c.type==="html"&&c.block){let d=s.match(jn);if(d){let p=d[1];s.includes(`</${p}>`)||Bn.has(p.toLowerCase())||r.push(p);}}if(l>0&&!a){let d=i[l-1];if(On(d)%2===1){i[l-1]=d+s;continue}}i.push(s),c.type!=="space"&&(a=c.type==="code");}return i};var eo,to,we={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(to=(eo=defaultSchema.protocols)==null?void 0:eo.href)!=null?to:[],"tel"]}},Be={raw:Jt,sanitize:[no,we],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Jn={gfm:[_n,{}]},Qt=Object.values(Be),Fn=Object.values(Jn),Kn={block:" \u258B",circle:" \u25CF"},Gn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},L=createContext(Gn),ro=memo(({content:e,shouldParseIncompleteMarkdown:t,index:o,...n})=>jsx(De,{...n,children:e}),(e,t)=>{if(e.content!==t.content||e.index!==t.index)return false;if(e.components!==t.components){let o=Object.keys(e.components||{}),n=Object.keys(t.components||{});if(o.length!==n.length||o.some(i=>{var r,a;return ((r=e.components)==null?void 0:r[i])!==((a=t.components)==null?void 0:a[i])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});ro.displayName="Block";var Yn=["github-light","github-dark"],Qn=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,components:n,rehypePlugins:i=Qt,remarkPlugins:r=Fn,className:a,shikiTheme:c=Yn,mermaid:s,controls:l=true,isAnimating:d=false,animated:p,BlockComponent:m=ro,parseMarkdownIntoBlocksFn:b=Ve,caret:f,plugins:u,remend:y,linkSafety:k={enabled:true},allowedTags:C,...P})=>{let M=useId(),[z,E]=useTransition(),H=useMemo(()=>typeof e!="string"?"":t==="streaming"&&o?Xn(e,y):e,[e,t,o,y]),D=useMemo(()=>b(H),[H,b]),[X,O]=useState(D);useEffect(()=>{t==="streaming"?E(()=>{O(D);}):O(D);},[D,t]);let I=t==="streaming"?X:D,w=useMemo(()=>I.map((T,j)=>`${M}-${j}`),[I.length,M]),R=useMemo(()=>p?p===true?Q():Q(p):null,[p]),Y=useMemo(()=>{var T,j;return {shikiTheme:(j=(T=u==null?void 0:u.code)==null?void 0:T.getThemes())!=null?j:c,controls:l,isAnimating:d,mode:t,mermaid:s,linkSafety:k}},[c,l,d,t,s,k,u==null?void 0:u.code]),Oe=useMemo(()=>({..._t,...n}),[n]),Ae=useMemo(()=>{let T=[];return u!=null&&u.cjk&&(T=[...T,...u.cjk.remarkPluginsBefore]),T=[...T,...r],u!=null&&u.cjk&&(T=[...T,...u.cjk.remarkPluginsAfter]),u!=null&&u.math&&(T=[...T,u.math.remarkPlugin]),T},[r,u==null?void 0:u.math,u==null?void 0:u.cjk]),qe=useMemo(()=>{var j;let T=i;if(C&&Object.keys(C).length>0&&i===Qt){let mo={...we,tagNames:[...(j=we.tagNames)!=null?j:[],...Object.keys(C)],attributes:{...we.attributes,...C}};T=[Be.raw,[no,mo],Be.harden];}return u!=null&&u.math&&(T=[...T,u.math.rehypePlugin]),R&&d&&(T=[...T,R.rehypePlugin]),T},[i,u==null?void 0:u.math,R,d,C]),co=useMemo(()=>f&&d?{"--streamdown-caret":`"${Kn[f]}"`}:void 0,[f,d]);return t==="static"?jsx(le.Provider,{value:u!=null?u:null,children:jsx(L.Provider,{value:Y,children:jsx("div",{className:g("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",a),children:jsx(De,{components:Oe,rehypePlugins:qe,remarkPlugins:Ae,...P,children:e})})})}):jsx(le.Provider,{value:u!=null?u:null,children:jsx(L.Provider,{value:Y,children:jsxs("div",{className:g("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",f?"*:last:after:inline *:last:after:align-baseline *:last:after:content-[var(--streamdown-caret)]":null,a),style:co,children:[I.length===0&&f&&d&&jsx("span",{}),I.map((T,j)=>jsx(m,{components:Oe,content:T,index:j,rehypePlugins:qe,remarkPlugins:Ae,shouldParseIncompleteMarkdown:o,...P},w[j]))]})})})},(e,t)=>e.children===t.children&&e.shikiTheme===t.shikiTheme&&e.isAnimating===t.isAnimating&&e.animated===t.animated&&e.mode===t.mode&&e.plugins===t.plugins&&e.className===t.className&&e.linkSafety===t.linkSafety);Qn.displayName="Streamdown";var lo=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:i=.1,showControls:r=true,initialZoom:a=1,fullscreen:c=false})=>{let s=useRef(null),l=useRef(null),[d,p]=useState(a),[m,b]=useState({x:0,y:0}),[f,u]=useState(false),[y,k]=useState({x:0,y:0}),[C,P]=useState({x:0,y:0}),M=useCallback(w=>{p(R=>Math.max(o,Math.min(n,R+w)));},[o,n]),z=useCallback(()=>{M(i);},[M,i]),E=useCallback(()=>{M(-i);},[M,i]),H=useCallback(()=>{p(a),b({x:0,y:0});},[a]),D=useCallback(w=>{w.preventDefault();let R=w.deltaY>0?-i:i;M(R);},[M,i]),X=useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;u(true),k({x:w.clientX,y:w.clientY}),P(m);let R=w.currentTarget;R instanceof HTMLElement&&R.setPointerCapture(w.pointerId);},[m]),O=useCallback(w=>{if(!f)return;w.preventDefault();let R=w.clientX-y.x,Y=w.clientY-y.y;b({x:C.x+R,y:C.y+Y});},[f,y,C]),I=useCallback(w=>{u(false);let R=w.currentTarget;R instanceof HTMLElement&&R.releasePointerCapture(w.pointerId);},[]);return useEffect(()=>{let w=s.current;if(w)return w.addEventListener("wheel",D,{passive:false}),()=>{w.removeEventListener("wheel",D);}},[D]),useEffect(()=>{let w=l.current;if(w&&f)return document.body.style.userSelect="none",w.addEventListener("pointermove",O,{passive:false}),w.addEventListener("pointerup",I),w.addEventListener("pointercancel",I),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",O),w.removeEventListener("pointerup",I),w.removeEventListener("pointercancel",I);}},[f,O,I]),jsxs("div",{className:g("relative flex flex-col",c?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:f?"grabbing":"grab"},children:[r?jsxs("div",{className:g("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",c?"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>=n,onClick:z,title:"Zoom in",type:"button",children:jsx(_e,{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<=o,onClick:E,title:"Zoom out",type:"button",children:jsx(Xe,{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:H,title:"Reset zoom and pan",type:"button",children:jsx(Ue,{size:16})})]}):null,jsx("div",{className:g("flex-1 origin-center transition-transform duration-150 ease-out",c?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:X,ref:l,role:"application",style:{transform:`translate(${m.x}px, ${m.y}px) scale(${d})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var lt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:i=true})=>{let[r,a]=useState(null),[c,s]=useState(false),[l,d]=useState(""),[p,m]=useState(""),[b,f]=useState(0),{mermaid:u}=useContext(L),y=K(),k=u==null?void 0:u.errorComponent,{shouldRender:C,containerRef:P}=ze({immediate:n});if(useEffect(()=>{if(!C)return;if(!y){a("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{a(null),s(!0);let E=y.getMermaid(o),H=e.split("").reduce((O,I)=>(O<<5)-O+I.charCodeAt(0)|0,0),D=`mermaid-${Math.abs(H)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:X}=await E.render(D,e);d(X),m(X);}catch(E){if(!(p||l)){let H=E instanceof Error?E.message:"Failed to render Mermaid chart";a(H);}}finally{s(false);}})();},[e,o,b,C,y]),!(C||l||p))return jsx("div",{className:g("my-4 min-h-[200px]",t),ref:P});if(c&&!l&&!p)return jsx("div",{className:g("my-4 flex justify-center p-4",t),ref:P,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&&!l&&!p){let z=()=>f(E=>E+1);return k?jsx("div",{ref:P,children:jsx(k,{chart:e,error:r,retry:z})}):jsxs("div",{className:g("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:P,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=l||p;return jsx("div",{className:g("size-full",t),"data-streamdown":"mermaid",ref:P,children:jsx(lo,{className:g(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:i,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:g("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:M},role:"img"})})})};export{Q as a,g as b,Io as c,Zr as d,lt as e,Yt as f,Ve as g,Be as h,Jn as i,L as j,ro as k,Qn as l};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {b,j,d,c}from'./chunk-LPQFK2AO.js';import {memo,useMemo,useContext,useState,useEffect}from'react';import {jsx,jsxs}from'react/jsx-runtime';var P=b("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-6","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),R=o=>{let e={};for(let s of o.split(";")){let n=s.indexOf(":");if(n>0){let a=s.slice(0,n).trim(),i=s.slice(n+1).trim();a&&i&&(e[a]=i);}}return e},y=memo(({children:o,result:e,language:s,className:n,...a})=>{let i=useMemo(()=>{let r={};return e.bg&&(r["--sdm-bg"]=e.bg),e.fg&&(r["--sdm-fg"]=e.fg),e.rootStyle&&Object.assign(r,R(e.rootStyle)),r},[e.bg,e.fg,e.rootStyle]);return jsx("pre",{className:b(n,"p-4 text-sm","bg-[var(--sdm-bg,transparent)]","dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,transparent))]"),"data-language":s,"data-streamdown":"code-block-body",style:i,...a,children:jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:e.tokens.map((r,l)=>jsx("span",{className:P,children:r.map((t,p)=>jsx("span",{className:b("text-[var(--sdm-c,inherit)]","dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]",t.bgColor&&"bg-[var(--sdm-tbg)]",t.bgColor&&"dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]"),style:{...t.color?{"--sdm-c":t.color}:{},...t.bgColor?{"--sdm-tbg":t.bgColor}:{},...t.htmlStyle},...t.htmlAttrs,children:t.content},p))},l))})})},(o,e)=>o.result===e.result&&o.language===e.language&&o.className===e.className);var h=({className:o,language:e,style:s,...n})=>jsx("div",{className:b("my-4 w-full overflow-hidden rounded-xl border border-border",o),"data-language":e,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...s},...n});var B=({language:o,children:e})=>jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":o,"data-streamdown":"code-block-header",children:[jsx("span",{className:"ml-1 font-mono lowercase",children:o}),jsx("div",{className:"flex items-center gap-2",children:e})]});var I=/\n+$/,Y=({code:o,language:e,className:s,children:n,...a})=>{let{shikiTheme:i}=useContext(j),r=d(),l=useMemo(()=>o.replace(I,""),[o]),t=useMemo(()=>({bg:"transparent",fg:"inherit",tokens:l.split(`
|
|
3
|
-
`).map(m=>[{content:m,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[l]),[p,c$1]=useState(t);return useEffect(()=>{if(!r){c$1(t);return}let m=r.highlight({code:l,language:e,themes:i},S=>{c$1(S);});if(m){c$1(m);return}c$1(t);},[l,e,i,r,t]),jsx(c.Provider,{value:{code:o},children:jsxs(h,{language:e,children:[jsx(B,{language:e,children:n}),jsx(y,{className:s,language:e,result:p,...a})]})})};export{Y as CodeBlock};
|
package/dist/mermaid-NOHMQCX5.js
DELETED