gen-streamdown 1.0.0 → 1.2.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-CPZCRXUI.js +8 -0
- package/dist/chunk-K6I6ZIQQ.js +8 -0
- package/dist/chunk-KKE7R55B.js +8 -0
- package/dist/chunk-KQJW3NAF.js +8 -0
- package/dist/chunk-LYGAQKT2.js +8 -0
- package/dist/chunk-RU5ZTBRD.js +8 -0
- package/dist/chunk-TXDBDMIZ.js +8 -0
- package/dist/chunk-X4ZHWAH2.js +8 -0
- package/dist/code-block-33PFYS4I.js +3 -0
- package/dist/code-block-CT72EYWF.js +3 -0
- package/dist/code-block-DLIUSOIP.js +3 -0
- package/dist/code-block-EL3QZ455.js +3 -0
- package/dist/code-block-RTXWJSUQ.js +3 -0
- package/dist/code-block-U2M37G6K.js +3 -0
- package/dist/code-block-V4LMA2LA.js +3 -0
- package/dist/code-block-XHOE4N52.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mermaid-4CT6ZWDE.js +2 -0
- package/dist/mermaid-4CXL2ISL.js +2 -0
- package/dist/mermaid-DKBQ5YLW.js +2 -0
- package/dist/mermaid-DR2KBNNL.js +2 -0
- package/dist/mermaid-KWRIC3LD.js +2 -0
- package/dist/mermaid-QBQQOBQR.js +2 -0
- package/dist/mermaid-SNSEEODE.js +2 -0
- package/dist/mermaid-UFZBFCXL.js +2 -0
- package/dist/vega-XDO2S4CX.js +2 -0
- package/package.json +5 -5
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {a,b}from'./chunk-O2KN3ML5.js';import {createContext,lazy,memo,useContext,isValidElement,useId,useTransition,useMemo,useState,useEffect,useCallback,Suspense,cloneElement,useRef}from'react';import {code}from'@streamdown/code';import {math}from'@streamdown/math';import {mermaid}from'@streamdown/mermaid';import {harden}from'rehype-harden';import Ut from'rehype-raw';import no,{defaultSchema}from'rehype-sanitize';import Un from'remark-gfm';import Fn from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';import {jsx,Fragment,jsxs}from'react/jsx-runtime';import {toJsxRuntime}from'hast-util-to-jsx-runtime';import {urlAttributes}from'html-url-attributes';import kn from'remark-parse';import vn 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 We(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(()=>g=>{let f=Date.now();return window.setTimeout(()=>{g({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-f))});},1)},[]),p=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(g,f)=>window.requestIdleCallback(g,f):d,[d]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?g=>window.cancelIdleCallback(g):g=>{clearTimeout(g);},[]);return useEffect(()=>{if(t){a(true);return}let g=c.current;if(!g)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(g),()=>{s.current&&clearTimeout(s.current),l.current&&m(l.current),C.disconnect();}},[t,o,n,i,m,p]),{shouldRender:r,containerRef:c}}var $e=/\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=$e.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)$e.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 U=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"})}),_e=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"})]}),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.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"})}),Je=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"})}),Pe=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"})}),Ue=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"})}),Fe=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 So=createContext({code:""}),ae=()=>useContext(So);var Me=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:i,code:r,...a$1})=>{let[c,s]=useState(false),l=useRef(0),{code:d}=ae(),{isAnimating:p}=useContext(L),m=r!=null?r:d,g=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?U:F;return jsx("button",{className:a("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:g,title:"Copy Code",type:"button",...a$1,children:n!=null?n:jsx(f,{size:14})})};var Ge={"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"},Qe=({onDownload:e,onError:t,language:o,children:n,className:i,code:r,...a$1})=>{let{code:c}=ae(),{isAnimating:s}=useContext(L),l=r!=null?r:c,p=`file.${o&&o in Ge?Ge[o]:"txt"}`,m="text/plain",g=()=>{try{b(p,l,m),e==null||e();}catch(f){t==null||t(f);}};return jsx("button",{className:a("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:g,title:"Download file",type:"button",...a$1,children:n!=null?n:jsx(Z,{size:14})})};var ie=()=>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(_e,{className:"size-4 animate-spin"})})]});var Bo=/\.[^/.]+$/,et=({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 g=c.type,f="png";g.includes("jpeg")||g.includes("jpg")?f="jpg":g.includes("png")?f="png":g.includes("svg")?f="svg":g.includes("gif")?f="gif":g.includes("webp")&&(f="webp"),m=`${(n||l||"image").replace(Bo,"")}.${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:a("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:a("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,zo=()=>{ee+=1,ee===1&&(document.body.style.overflow="hidden");},Zo=()=>{ee=Math.max(0,ee-1),ee===0&&(document.body.style.overflow="");},nt=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[i,r]=useState(false),a$1=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){zo();let s=l=>{l.key==="Escape"&&o();};return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s),Zo();}}},[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(Pe,{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:a("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$1,type:"button",children:i?jsxs(Fragment,{children:[jsx(U,{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(Pe,{size:14}),jsx("span",{children:"Open link"})]})]})]})}):null};var ce=createContext(null),rt=()=>useContext(ce),Zr=()=>{var t;let e=rt();return (t=e==null?void 0:e.code)!=null?t:null},K=()=>{var t;let e=rt();return (t=e==null?void 0:e.mermaid)!=null?t:null};var st=(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 it=({chart:e,children:t,className:o,onDownload:n,config:i,onError:r})=>{let[a$1,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 g=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 g.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 st(y);b("diagram.png",k,"image/png"),n==null||n(m),c(!1);return}}catch(g){r==null||r(g);}};return useEffect(()=>{let m=g=>{let f=g.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:a("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$1),title:"Download diagram",type:"button",children:t!=null?t:jsx(Z,{size:14})}),a$1?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,Go=()=>{oe+=1,oe===1&&(document.body.style.overflow="hidden");},Yo=()=>{oe=Math.max(0,oe-1),oe===0&&(document.body.style.overflow="");},mt=({chart:e,config:t,onFullscreen:o,onExit:n,className:i,...r})=>{let[a$1,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$1);};return useEffect(()=>{if(a$1){Go();let m=g=>{g.key==="Escape"&&c(false);};return document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m),Yo();}}},[a$1]),useEffect(()=>{a$1?o==null||o():n&&n();},[a$1,o,n]),jsxs(Fragment,{children:[jsx("button",{className:a("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(Xe,{size:14})}),a$1?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(dt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var de=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}},me=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
|
+
`)},pt=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("")},ut=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 ht=({children:e,className:t,onCopy:o,onError:n,timeout:i=2e3})=>{let[r,a$1]=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=de(C),M=f==="csv"?me(P):pt(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(!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$1(false);};return document.addEventListener("mousedown",f),()=>{document.removeEventListener("mousedown",f),window.clearTimeout(d.current);}},[]);let g=c?U:F;return jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:p,onClick:()=>a$1(!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:()=>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 wt=({children:e,className:t,onDownload:o,onError:n})=>{let[i,r]=useState(false),a$1=useRef(null),{isAnimating:c}=useContext(L),s=l=>{var d;try{let p=(d=a$1.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 g=de(m),f=l==="csv"?me(g):ut(g);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$1.current&&!p.includes(a$1.current)&&r(false);};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l);}},[]),jsxs("div",{className:"relative",ref:a$1,children:[jsx("button",{className:a("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 vt=({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(ht,{}),jsx(wt,{})]}):null,jsx("div",{className:"overflow-x-auto overscroll-y-auto",children:jsx("table",{className:a("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});var cn=lazy(()=>import('./code-block-RTXWJSUQ.js').then(e=>({default:e.CodeBlock}))),dn=lazy(()=>import('./mermaid-4CT6ZWDE.js').then(e=>({default:e.Mermaid}))),mn=lazy(()=>import('./vega-W36RN4XC.js').then(e=>({default:e.default}))),pn=/language-([^\s]+)/;function ye(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&&ye(e.node,t.node)}var Se=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ge=(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},He=memo(({children:e,className:t,node:o,...n})=>jsx("ol",{className:a("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>N(e,t));He.displayName="MarkdownOl";var Ct=memo(({children:e,className:t,node:o,...n})=>jsx("li",{className:a("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&ye(e.node,t.node));Ct.displayName="MarkdownLi";var xt=memo(({children:e,className:t,node:o,...n})=>jsx("ul",{className:a("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:a("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:a("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>N(e,t));Mt.displayName="MarkdownStrong";var un=({children:e,className:t,href:o,node:n,...i})=>{let{linkSafety:r}=useContext(L),[a$1,c]=useState(false),s=o==="streamdown:incomplete-link",l=useCallback(async g=>{if(!(!(r!=null&&r.enabled&&o)||s)){if(g.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$1,onClose:p,onConfirm:d};return r!=null&&r.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:a("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(nt,{...m})]}):jsx("a",{className:a("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(un,(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:a("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:a("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:a("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:a("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:a("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:a("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=Se(i,"table");return jsx(vt,{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:a("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:a("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:a("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:a("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:a("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:a("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:a("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:a("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,g;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)&&((g=y.props)==null?void 0:g["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===He){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 fn=({node:e,className:t,children:o,...n})=>{var m;let i=!("data-block"in n),{mermaid:r,controls:a$1}=useContext(L),c=K();if(i)return jsx("code",{className:a("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(pn),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==="vega-lite")try{let g=JSON.parse(d);return jsx(Suspense,{fallback:jsx(ie,{}),children:jsx("div",{className:a("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"vega-lite-block",children:jsx(mn,{spec:g})})})}catch(g){console.warn("Failed to parse vega-lite spec:",g);}if(l==="mermaid"&&c){let g=Se(a$1,"mermaid"),f=ge(a$1,"download"),u=ge(a$1,"copy"),y=ge(a$1,"fullscreen"),k=ge(a$1,"panZoom"),C=g&&(f||u||y);return jsx(Suspense,{fallback:jsx(ie,{}),children:jsxs("div",{className:a("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(it,{chart:d,config:r==null?void 0:r.config}):null,u?jsx(Me,{code:d}):null,y?jsx(mt,{chart:d,config:r==null?void 0:r.config}):null]}):null,jsx(dn,{chart:d,config:r==null?void 0:r.config,showControls:k})]})})}let p=Se(a$1,"code");return jsx(Suspense,{fallback:jsx(ie,{}),children:jsx(cn,{className:a("overflow-x-auto border-border border-t",t),code:d,language:l,children:p?jsxs(Fragment,{children:[jsx(Qe,{code:d,language:l}),jsx(Me,{})]}):null})})},Wt=memo(fn,(e,t)=>e.className===t.className&&ye(e.node,t.node));Wt.displayName="MarkdownCode";var $t=memo(et,(e,t)=>e.className===t.className&&ye(e.node,t.node));$t.displayName="MarkdownImg";var _t=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));_t.displayName="MarkdownParagraph";var Xt={ol:He,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:_t,section:Zt};var Jt=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var Ft=[],Kt={allowDangerousHtml:true},we=new WeakMap,Ve=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 g=0;g<p.length;g+=1){let f=p[g];if(g>0&&(m+=","),Array.isArray(f)){let[u,y]=f;if(typeof u=="function"){let k=we.get(u);k||(k=u.name,we.set(u,k)),m+=k;}else m+=String(u);m+=":",m+=JSON.stringify(y);}else if(typeof f=="function"){let u=we.get(f);u||(u=f.name,we.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 Ve,je=e=>{let t=Pn(e),o=e.children||"";return Sn(t.runSync(t.parse(o),o),e)},Pn=e=>{let t=Gt.get(e);if(t)return t;let o=Tn(e);return Gt.set(e,o),o},Mn=e=>e.some(t=>Array.isArray(t)?t[0]===Ut:t===Ut),Tn=e=>{let t=e.rehypePlugins||Ft,o=e.remarkPlugins||Ft,n=Mn(t)?o:[...o,Jt],i=e.remarkRehypeOptions?{...Kt,...e.remarkRehypeOptions}:Kt;return unified().use(kn).use(n).use(vn,i).use(t)},Yt=e=>e,Nn=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},Ln=(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);}},Rn=(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},Sn=(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 Nn(m,p,r,d.value),p;if(d.type==="element"&&(Ln(d,l),Rn(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 In=/\[\^[\w-]{1,200}\](?!:)/,Hn=/\[\^[\w-]{1,200}\]:/,Dn=/<\/(\w+)>/,Vn=/<(\w+)[\s>]/,jn=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Bn=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},Be=e=>{let t=In.test(e),o=Hn.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(Dn);if(d){let p=d[1];r.at(-1)===p&&r.pop();}}continue}if(c.type==="html"&&c.block){let d=s.match(Vn);if(d){let p=d[1];s.includes(`</${p}>`)||jn.has(p.toLowerCase())||r.push(p);}}if(l>0&&!a){let d=i[l-1];if(Bn(d)%2===1){i[l-1]=d+s;continue}}i.push(s),c.type!=="space"&&(a=c.type==="code");}return i};var eo,to,ke={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(to=(eo=defaultSchema.protocols)==null?void 0:eo.href)!=null?to:[],"tel"]}},Ae={raw:Ut,sanitize:[no,ke],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Kn={gfm:[Un,{}]},Qt=Object.values(Ae),Gn=Object.values(Kn),Yn={block:" \u258B",circle:" \u25CF"},Qn={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},L=createContext(Qn),ro=memo(({content:e,shouldParseIncompleteMarkdown:t,index:o,...n})=>jsx(je,{...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 er=["github-light","github-dark"],tr={code:code,math:math,mermaid:mermaid},or=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,components:n,rehypePlugins:i=Qt,remarkPlugins:r=Gn,className:a$1,shikiTheme:c=er,mermaid:s,controls:l=true,isAnimating:d=false,animated:p,BlockComponent:m=ro,parseMarkdownIntoBlocksFn:g=Be,caret:f,plugins:u=tr,remend:y,linkSafety:k={enabled:true},allowedTags:C,...P})=>{let M=useId(),[z,E]=useTransition(),H=useMemo(()=>typeof e!="string"?"":t==="streaming"&&o?Fn(e,y):e,[e,t,o,y]),D=useMemo(()=>g(H),[H,g]),[J,O]=useState(D);useEffect(()=>{t==="streaming"?E(()=>{O(D);}):O(D);},[D,t]);let I=t==="streaming"?J: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]),qe=useMemo(()=>({...Xt,...n}),[n]),ze=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]),Ze=useMemo(()=>{var j;let T=i;if(C&&Object.keys(C).length>0&&i===Qt){let mo={...ke,tagNames:[...(j=ke.tagNames)!=null?j:[],...Object.keys(C)],attributes:{...ke.attributes,...C}};T=[Ae.raw,[no,mo],Ae.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":`"${Yn[f]}"`}:void 0,[f,d]);return t==="static"?jsx(ce.Provider,{value:u!=null?u:null,children:jsx(L.Provider,{value:Y,children:jsx("div",{className:a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",a$1),children:jsx(je,{components:qe,rehypePlugins:Ze,remarkPlugins:ze,...P,children:e})})})}):jsx(ce.Provider,{value:u!=null?u:null,children:jsx(L.Provider,{value:Y,children:jsxs("div",{className:a("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$1),style:co,children:[I.length===0&&f&&d&&jsx("span",{}),I.map((T,j)=>jsx(m,{components:qe,content:T,index:j,rehypePlugins:Ze,remarkPlugins:ze,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);or.displayName="Streamdown";var lo=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:i=.1,showControls:r=true,initialZoom:a$1=1,fullscreen:c=false})=>{let s=useRef(null),l=useRef(null),[d,p]=useState(a$1),[m,g]=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$1),g({x:0,y:0});},[a$1]),D=useCallback(w=>{w.preventDefault();let R=w.deltaY>0?-i:i;M(R);},[M,i]),J=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;g({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:a("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:a("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(Ue,{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(Fe,{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(Je,{size:16})})]}):null,jsx("div",{className:a("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:J,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 dt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:i=true})=>{let[r,a$1]=useState(null),[c,s]=useState(false),[l,d]=useState(""),[p,m]=useState(""),[g,f]=useState(0),{mermaid:u}=useContext(L),y=K(),k=u==null?void 0:u.errorComponent,{shouldRender:C,containerRef:P}=We({immediate:n});if(useEffect(()=>{if(!C)return;if(!y){a$1("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{a$1(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:J}=await E.render(D,e);d(J),m(J);}catch(E){if(!(p||l)){let H=E instanceof Error?E.message:"Failed to render Mermaid chart";a$1(H);}}finally{s(false);}})();},[e,o,g,C,y]),!(C||l||p))return jsx("div",{className:a("my-4 min-h-[200px]",t),ref:P});if(c&&!l&&!p)return jsx("div",{className:a("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:a("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:a("size-full",t),"data-streamdown":"mermaid",ref:P,children:jsx(lo,{className:a(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:a("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:M},role:"img"})})})};export{Q as a,So as b,Zr as c,dt as d,Yt as e,Be as f,Ae as g,Kn as h,L as i,ro as j,or as k};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {a,b}from'./chunk-O2KN3ML5.js';import {createContext,lazy,memo,useContext,isValidElement,useMemo,useId,useTransition,useState,useEffect,useCallback,Suspense,cloneElement,useRef}from'react';import {code}from'@streamdown/code';import {math}from'@streamdown/math';import {mermaid}from'@streamdown/mermaid';import {harden}from'rehype-harden';import Ft from'rehype-raw';import ro,{defaultSchema}from'rehype-sanitize';import Fn from'remark-gfm';import Kn from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';import {jsx,Fragment,jsxs}from'react/jsx-runtime';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 go=300,bo="300px",ho=500;function $e(e={}){let{immediate:t=false,debounceDelay:o=go,rootMargin:n=bo,idleTimeout:l=ho}=e,[r,a]=useState(false),d=useRef(null),s=useRef(null),i=useRef(null),c=useMemo(()=>b=>{let u=Date.now();return window.setTimeout(()=>{b({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-u))});},1)},[]),p=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(b,u)=>window.requestIdleCallback(b,u):c,[c]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?b=>window.cancelIdleCallback(b):b=>{clearTimeout(b);},[]);return useEffect(()=>{if(t){a(true);return}let b=d.current;if(!b)return;s.current&&(clearTimeout(s.current),s.current=null),i.current&&(m(i.current),i.current=null);let u=()=>{s.current&&(clearTimeout(s.current),s.current=null),i.current&&(m(i.current),i.current=null);},h=P=>{i.current=p(f=>{f.timeRemaining()>0||f.didTimeout?(a(true),P.disconnect()):i.current=p(()=>{a(true),P.disconnect();},{timeout:l/2});},{timeout:l});},w=P=>{u(),s.current=window.setTimeout(()=>{var E,D;let f=P.takeRecords();(f.length===0||(D=(E=f.at(-1))==null?void 0:E.isIntersecting)!=null&&D)&&h(P);},o);},v=(P,f)=>{P.isIntersecting?w(f):u();},C=new IntersectionObserver(P=>{for(let f of P)v(f,C);},{rootMargin:n,threshold:0});return C.observe(b),()=>{s.current&&clearTimeout(s.current),i.current&&m(i.current),C.disconnect();}},[t,o,n,l,m,p]),{shouldRender:r,containerRef:d}}var _e=/\s/,ko=/^\s+$/,vo=new Set(["code","pre","svg","math","annotation"]),Co=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",xo=e=>e.some(t=>Co(t)&&vo.has(t.tagName)),Po=e=>{let t=[],o="",n=false;for(let l of e){let r=_e.test(l);r!==n&&o&&(t.push(o),o=""),o+=l,n=r;}return o&&t.push(o),t},Mo=e=>{let t=[],o="";for(let n of e)_e.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},To=(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}]}),No=(e,t,o)=>{let n=t.at(-1);if(!(n&&"children"in n))return;if(xo(t))return SKIP;let l=n,r=l.children.indexOf(e);if(r===-1)return;let a=e.value;if(!a.trim())return;let s=(o.sep==="char"?Mo(a):Po(a)).map(i=>ko.test(i)?{type:"text",value:i}:To(i,o.animation,o.duration,o.easing));return l.children.splice(r,1,...s),r+s.length};function Q(e){var n,l,r,a;let t={animation:(n=e==null?void 0:e.animation)!=null?n:"fadeIn",duration:(l=e==null?void 0:e.duration)!=null?l: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:()=>d=>{visitParents(d,"text",(s,i)=>No(s,i,t));}}}Q();var F=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"})}),W=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"})}),Xe=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"})]}),Je=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"})}),Pe=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"})}),Fe=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"})}),Ke=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 Eo=createContext({code:""}),ae=()=>useContext(Eo);var Me=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:l,code:r,...a$1})=>{let[d,s]=useState(false),i=useRef(0),{code:c}=ae(),{isAnimating:p}=useContext(L),m=r!=null?r:c,b=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{d||(await navigator.clipboard.writeText(m),s(!0),e==null||e(),i.current=window.setTimeout(()=>s(!1),o));}catch(w){t==null||t(w);}};useEffect(()=>()=>{window.clearTimeout(i.current);},[]);let u=d?F:K;return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",l),"data-streamdown":"code-block-copy-button",disabled:p,onClick:b,title:"Copy Code",type:"button",...a$1,children:n!=null?n:jsx(u,{size:14})})};var Ye={"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"},et=({onDownload:e,onError:t,language:o,children:n,className:l,code:r,...a$1})=>{let{code:d}=ae(),{isAnimating:s}=useContext(L),i=r!=null?r:d,p=`file.${o&&o in Ye?Ye[o]:"txt"}`,m="text/plain",b$1=()=>{try{b(p,i,m),e==null||e();}catch(u){t==null||t(u);}};return jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",l),"data-streamdown":"code-block-download-button",disabled:s,onClick:b$1,title:"Download file",type:"button",...a$1,children:n!=null?n:jsx(W,{size:14})})};var ie=()=>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(Xe,{className:"size-4 animate-spin"})})]});var Oo=/\.[^/.]+$/,tt=({node:e,className:t,src:o,alt:n,...l})=>{let r=async()=>{if(o)try{let d=await(await fetch(o)).blob(),i=new URL(o,window.location.origin).pathname.split("/").pop()||"",c=i.split(".").pop(),p=i.includes(".")&&c!==void 0&&c.length<=4,m="";if(p)m=i;else {let b=d.type,u="png";b.includes("jpeg")||b.includes("jpg")?u="jpg":b.includes("png")?u="png":b.includes("svg")?u="svg":b.includes("gif")?u="gif":b.includes("webp")&&(u="webp"),m=`${(n||i||"image").replace(Oo,"")}.${u}`;}b(m,d,d.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:a("max-w-full rounded-lg",t),"data-streamdown":"image",src:o,...l}),jsx("div",{className:"pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"}),jsx("button",{className:a("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(W,{size:14})})]}):null};var ee=0,Zo=()=>{ee+=1,ee===1&&(document.body.style.overflow="hidden");},Wo=()=>{ee=Math.max(0,ee-1),ee===0&&(document.body.style.overflow="");},rt=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[l,r]=useState(false),a$1=useCallback(async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3);}catch(s){}},[e]),d=useCallback(()=>{n(),o();},[n,o]);return useEffect(()=>{if(t){Zo();let s=i=>{i.key==="Escape"&&o();};return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s),Wo();}}},[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(Pe,{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:a("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$1,type:"button",children:l?jsxs(Fragment,{children:[jsx(F,{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:d,type:"button",children:[jsx(Pe,{size:14}),jsx("span",{children:"Open link"})]})]})]})}):null};var ce=createContext(null),st=()=>useContext(ce),Wr=()=>{var t;let e=st();return (t=e==null?void 0:e.code)!=null?t:null},G=()=>{var t;let e=st();return (t=e==null?void 0:e.mermaid)!=null?t:null};var at=(e,t)=>{var n;let o=(n=void 0)!=null?n:5;return new Promise((l,r)=>{let a="data:image/svg+xml;base64,"+btoa(unescape(encodeURIComponent(e))),d=new Image;d.crossOrigin="anonymous",d.onload=()=>{let s=document.createElement("canvas"),i=d.width*o,c=d.height*o;s.width=i,s.height=c;let p=s.getContext("2d");if(!p){r(new Error("Failed to create 2D canvas context for PNG export"));return}p.drawImage(d,0,0,i,c),s.toBlob(m=>{if(!m){r(new Error("Failed to create PNG blob"));return}l(m);},"image/png");},d.onerror=()=>r(new Error("Failed to load SVG image")),d.src=a;})};var lt=({chart:e,children:t,className:o,onDownload:n,config:l,onError:r})=>{let[a$1,d]=useState(false),s=useRef(null),{isAnimating:i}=useContext(L),c=G(),p=async m=>{try{if(m==="mmd"){b("diagram.mmd",e,"text/plain"),d(!1),n==null||n(m);return}if(!c){r==null||r(new Error("Mermaid plugin not available"));return}let b$1=c.getMermaid(l),u=e.split("").reduce((v,C)=>(v<<5)-v+C.charCodeAt(0)|0,0),h=`mermaid-${Math.abs(u)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:w}=await b$1.render(h,e);if(!w){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){b("diagram.svg",w,"image/svg+xml"),d(!1),n==null||n(m);return}if(m==="png"){let v=await at(w);b("diagram.png",v,"image/png"),n==null||n(m),d(!1);return}}catch(b){r==null||r(b);}};return useEffect(()=>{let m=b=>{let u=b.composedPath();s.current&&!u.includes(s.current)&&d(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:"relative",ref:s,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",o),disabled:i,onClick:()=>d(!a$1),title:"Download diagram",type:"button",children:t!=null?t:jsx(W,{size:14})}),a$1?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,Yo=()=>{oe+=1,oe===1&&(document.body.style.overflow="hidden");},Qo=()=>{oe=Math.max(0,oe-1),oe===0&&(document.body.style.overflow="");},pt=({chart:e,config:t,onFullscreen:o,onExit:n,className:l,...r})=>{let[a$1,d]=useState(false),{isAnimating:s,controls:i}=useContext(L),c=(()=>{if(typeof i=="boolean")return i;let m=i.mermaid;return m===false?false:m===true||m===void 0?true:m.panZoom!==false})(),p=()=>{d(!a$1);};return useEffect(()=>{if(a$1){Yo();let m=b=>{b.key==="Escape"&&d(false);};return document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m),Qo();}}},[a$1]),useEffect(()=>{a$1?o==null||o():n&&n();},[a$1,o,n]),jsxs(Fragment,{children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",l),disabled:s,onClick:p,title:"View fullscreen",type:"button",...r,children:jsx(Je,{size:14})}),a$1?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(mt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:c})})]}):null]})};var de=e=>{var r,a;let t=[],o=[],n=e.querySelectorAll("thead th");for(let d of n)t.push(((r=d.textContent)==null?void 0:r.trim())||"");let l=e.querySelectorAll("tbody tr");for(let d of l){let s=[],i=d.querySelectorAll("td");for(let c of i)s.push(((a=c.textContent)==null?void 0:a.trim())||"");o.push(s);}return {headers:t,rows:o}},me=e=>{let{headers:t,rows:o}=e,n=d=>{let s=false,i=false;for(let c of d){if(c==='"'){s=true,i=true;break}(c===","||c===`
|
|
3
|
+
`)&&(s=true);}return s?i?`"${d.replace(/"/g,'""')}"`:`"${d}"`:d},l=t.length>0?o.length+1:o.length,r=new Array(l),a=0;t.length>0&&(r[a]=t.map(n).join(","),a+=1);for(let d of o)r[a]=d.map(n).join(","),a+=1;return r.join(`
|
|
4
|
+
`)},ut=e=>{let{headers:t,rows:o}=e,n=d=>{let s=false;for(let c of d)if(c===" "||c===`
|
|
5
|
+
`||c==="\r"){s=true;break}if(!s)return d;let i=[];for(let c of d)c===" "?i.push("\\t"):c===`
|
|
6
|
+
`?i.push("\\n"):c==="\r"?i.push("\\r"):i.push(c);return i.join("")},l=t.length>0?o.length+1:o.length,r=new Array(l),a=0;t.length>0&&(r[a]=t.map(n).join(" "),a+=1);for(let d of o)r[a]=d.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("")},ft=e=>{let{headers:t,rows:o}=e;if(t.length===0)return "";let n=new Array(o.length+2),l=0,r=t.map(d=>Ne(d));n[l]=`| ${r.join(" | ")} |`,l+=1;let a=new Array(t.length);for(let d=0;d<t.length;d+=1)a[d]="---";n[l]=`| ${a.join(" | ")} |`,l+=1;for(let d of o)if(d.length<t.length){let s=new Array(t.length);for(let i=0;i<t.length;i+=1)s[i]=i<d.length?Ne(d[i]):"";n[l]=`| ${s.join(" | ")} |`,l+=1;}else {let s=d.map(i=>Ne(i));n[l]=`| ${s.join(" | ")} |`,l+=1;}return n.join(`
|
|
8
|
+
`)};var yt=({children:e,className:t,onCopy:o,onError:n,timeout:l=2e3})=>{let[r,a$1]=useState(false),[d,s]=useState(false),i=useRef(null),c=useRef(0),{isAnimating:p}=useContext(L),m=async u=>{var h,w;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 v=(w=i.current)==null?void 0:w.closest('[data-streamdown="table-wrapper"]'),C=v==null?void 0:v.querySelector("table");if(!C){n==null||n(new Error("Table not found"));return}let P=de(C),f=u==="csv"?me(P):ut(P),H=new ClipboardItem({"text/plain":new Blob([f],{type:"text/plain"}),"text/html":new Blob([C.outerHTML],{type:"text/html"})});await navigator.clipboard.write([H]),s(!0),a$1(!1),o==null||o(u),c.current=window.setTimeout(()=>s(!1),l);}catch(v){n==null||n(v);}};useEffect(()=>{let u=h=>{let w=h.composedPath();i.current&&!w.includes(i.current)&&a$1(false);};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(c.current);}},[]);let b=d?F:K;return jsxs("div",{className:"relative",ref:i,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:p,onClick:()=>a$1(!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 kt=({children:e,className:t,onDownload:o,onError:n})=>{let[l,r]=useState(false),a$1=useRef(null),{isAnimating:d}=useContext(L),s=i=>{var c;try{let p=(c=a$1.current)==null?void 0:c.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$1=de(m),u=i==="csv"?me(b$1):ft(b$1);b(`table.${i==="csv"?"csv":"md"}`,u,i==="csv"?"text/csv":"text/markdown"),r(!1),o==null||o(i);}catch(p){n==null||n(p);}};return useEffect(()=>{let i=c=>{let p=c.composedPath();a$1.current&&!p.includes(a$1.current)&&r(false);};return document.addEventListener("mousedown",i),()=>{document.removeEventListener("mousedown",i);}},[]),jsxs("div",{className:"relative",ref:a$1,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:d,onClick:()=>r(!l),title:"Download table",type:"button",children:e!=null?e:jsx(W,{size:14})}),l?jsxs("div",{className:"absolute top-full right-0 z-10 mt-1 min-w-[120px] overflow-hidden rounded-md border border-border bg-background shadow-lg",children:[jsx("button",{className:"w-full px-3 py-2 text-left text-sm transition-colors hover:bg-muted/40",onClick:()=>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 Ct=({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(yt,{}),jsx(kt,{})]}):null,jsx("div",{className:"overflow-x-auto overscroll-y-auto",children:jsx("table",{className:a("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});var dn=lazy(()=>import('./code-block-U2M37G6K.js').then(e=>({default:e.CodeBlock}))),mn=lazy(()=>import('./mermaid-QBQQOBQR.js').then(e=>({default:e.Mermaid}))),pn=lazy(()=>import('./vega-XDO2S4CX.js').then(e=>({default:e.default}))),un=/language-([^\s]+)/;function ye(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,l=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)&&(l==null?void 0:l.line)===(r==null?void 0:r.line)&&(l==null?void 0:l.column)===(r==null?void 0:r.column)}function N(e,t){return e.className===t.className&&ye(e.node,t.node)}var Re=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ge=(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},He=memo(({children:e,className:t,node:o,...n})=>jsx("ol",{className:a("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>N(e,t));He.displayName="MarkdownOl";var xt=memo(({children:e,className:t,node:o,...n})=>jsx("li",{className:a("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&ye(e.node,t.node));xt.displayName="MarkdownLi";var Pt=memo(({children:e,className:t,node:o,...n})=>jsx("ul",{className:a("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>N(e,t));Pt.displayName="MarkdownUl";var Mt=memo(({className:e,node:t,...o})=>jsx("hr",{className:a("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>N(e,t));Mt.displayName="MarkdownHr";var Tt=memo(({children:e,className:t,node:o,...n})=>jsx("span",{className:a("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>N(e,t));Tt.displayName="MarkdownStrong";var fn=({children:e,className:t,href:o,node:n,...l})=>{let{linkSafety:r}=useContext(L),[a$1,d]=useState(false),s=o==="streamdown:incomplete-link",i=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}d(true);}},[r,o,s]),c=useCallback(()=>{o&&window.open(o,"_blank","noreferrer");},[o]),p=useCallback(()=>{d(false);},[]),m={url:o!=null?o:"",isOpen:a$1,onClose:p,onConfirm:c};return r!=null&&r.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:a("wrap-anywhere appearance-none text-left font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",onClick:i,type:"button",children:e}),r.renderModal?r.renderModal(m):jsx(rt,{...m})]}):jsx("a",{className:a("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...l,children:e})},Nt=memo(fn,(e,t)=>N(e,t)&&e.href===t.href);Nt.displayName="MarkdownA";var Lt=memo(({children:e,className:t,node:o,...n})=>jsx("h1",{className:a("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>N(e,t));Lt.displayName="MarkdownH1";var St=memo(({children:e,className:t,node:o,...n})=>jsx("h2",{className:a("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>N(e,t));St.displayName="MarkdownH2";var Rt=memo(({children:e,className:t,node:o,...n})=>jsx("h3",{className:a("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 Et=memo(({children:e,className:t,node:o,...n})=>jsx("h4",{className:a("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>N(e,t));Et.displayName="MarkdownH4";var It=memo(({children:e,className:t,node:o,...n})=>jsx("h5",{className:a("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>N(e,t));It.displayName="MarkdownH5";var Ht=memo(({children:e,className:t,node:o,...n})=>jsx("h6",{className:a("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>N(e,t));Ht.displayName="MarkdownH6";var Dt=memo(({children:e,className:t,node:o,...n})=>{let{controls:l}=useContext(L),r=Re(l,"table");return jsx(Ct,{className:t,showControls:r,...n,children:e})},(e,t)=>N(e,t));Dt.displayName="MarkdownTable";var Vt=memo(({children:e,className:t,node:o,...n})=>jsx("thead",{className:a("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>N(e,t));Vt.displayName="MarkdownThead";var jt=memo(({children:e,className:t,node:o,...n})=>jsx("tbody",{className:a("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>N(e,t));jt.displayName="MarkdownTbody";var Bt=memo(({children:e,className:t,node:o,...n})=>jsx("tr",{className:a("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>N(e,t));Bt.displayName="MarkdownTr";var Ot=memo(({children:e,className:t,node:o,...n})=>jsx("th",{className:a("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));Ot.displayName="MarkdownTh";var At=memo(({children:e,className:t,node:o,...n})=>jsx("td",{className:a("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>N(e,t));At.displayName="MarkdownTd";var qt=memo(({children:e,className:t,node:o,...n})=>jsx("blockquote",{className:a("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));qt.displayName="MarkdownBlockquote";var zt=memo(({children:e,className:t,node:o,...n})=>jsx("sup",{className:a("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>N(e,t));zt.displayName="MarkdownSup";var Zt=memo(({children:e,className:t,node:o,...n})=>jsx("sub",{className:a("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>N(e,t));Zt.displayName="MarkdownSub";var Wt=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 i=Array.isArray(s.props.children)?s.props.children:[s.props.children],c=false,p=false;for(let u of i)if(u){if(typeof u=="string")u.trim()!==""&&(c=true);else if(isValidElement(u))if(((m=u.props)==null?void 0:m["data-footnote-backref"])!==void 0)p=true;else {let h=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let w of h){if(typeof w=="string"&&w.trim()!==""){c=true;break}if(isValidElement(w)&&((b=w.props)==null?void 0:b["data-footnote-backref"])===void 0){c=true;break}}}}return p&&!c},a=Array.isArray(e)?e.map(s=>{if(!isValidElement(s))return s;if(s.type===He){let c=(Array.isArray(s.props.children)?s.props.children:[s.props.children]).filter(p=>!r(p));return c.length===0?null:{...s,props:{...s.props,children:c}}}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));Wt.displayName="MarkdownSection";var gn=({node:e,className:t,children:o,...n})=>{var b,u;let l=!("data-block"in n),{mermaid:r,controls:a$1}=useContext(L),d=G();if(l)return jsx("code",{className:a("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),i=(b=s==null?void 0:s.at(1))!=null?b:"",c="";if(isValidElement(o)&&o.props&&typeof o.props=="object"&&"children"in o.props&&typeof o.props.children=="string"?c=o.props.children:typeof o=="string"&&(c=o),i==="vega-lite"||i==="vega"||c.includes("vega.github.io/schema/vega-lite/")||c.includes("vega.github.io/schema/vega/"))try{let h=JSON.parse(c),w=i==="vega-lite"||typeof h=="object"&&h!==null&&(((u=h.$schema)==null?void 0:u.includes("vega-lite"))||c.includes("vega.github.io/schema/vega-lite/"));return jsx(Suspense,{fallback:jsx(ie,{}),children:jsx("div",{className:a("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"vega-block",children:jsx(pn,{spec:h,isVegaLite:w})})})}catch(h){console.warn("Failed to parse vega spec:",h);}if(i==="mermaid"&&d){let h=Re(a$1,"mermaid"),w=ge(a$1,"download"),v=ge(a$1,"copy"),C=ge(a$1,"fullscreen"),P=ge(a$1,"panZoom"),f=h&&(w||v||C);return jsx(Suspense,{fallback:jsx(ie,{}),children:jsxs("div",{className:a("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[f?jsxs("div",{className:"flex items-center justify-end gap-2",children:[w?jsx(lt,{chart:c,config:r==null?void 0:r.config}):null,v?jsx(Me,{code:c}):null,C?jsx(pt,{chart:c,config:r==null?void 0:r.config}):null]}):null,jsx(mn,{chart:c,config:r==null?void 0:r.config,showControls:P})]})})}let m=Re(a$1,"code");return jsx(Suspense,{fallback:jsx(ie,{}),children:jsx(dn,{className:a("overflow-x-auto border-border border-t",t),code:c,language:i,children:m?jsxs(Fragment,{children:[jsx(et,{code:c,language:i}),jsx(Me,{})]}):null})})},$t=memo(gn,(e,t)=>e.className===t.className&&ye(e.node,t.node));$t.displayName="MarkdownCode";var _t=memo(tt,(e,t)=>e.className===t.className&&ye(e.node,t.node));_t.displayName="MarkdownImg";var Xt=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,d=a==null?void 0:a.tagName;if(d==="img")return jsx(Fragment,{children:e});if(d==="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));Xt.displayName="MarkdownParagraph";var Jt={ol:He,li:xt,ul:Pt,hr:Mt,strong:Tt,a:Nt,h1:Lt,h2:St,h3:Rt,h4:Et,h5:It,h6:Ht,table:Dt,thead:Vt,tbody:jt,tr:Bt,th:Ot,td:At,blockquote:qt,code:$t,img:_t,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:zt,sub:Zt,p:Xt,section:Wt};var Ut=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var Kt=[],Gt={allowDangerousHtml:true},we=new WeakMap,Ve=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,l=t.remarkPlugins,r=t.remarkRehypeOptions;if(!(n||l||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 u=p[b];if(b>0&&(m+=","),Array.isArray(u)){let[h,w]=u;if(typeof h=="function"){let v=we.get(h);v||(v=h.name,we.set(h,v)),m+=v;}else m+=String(h);m+=":",m+=JSON.stringify(w);}else if(typeof u=="function"){let h=we.get(u);h||(h=u.name,we.set(u,h)),m+=h;}else m+=String(u);}return m},d=a(n),s=a(l),i=r?JSON.stringify(r):"",c=`${s}::${d}::${i}`;return this.keyCache.set(t,c),c}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 l=this.cache.keys().next().value;l&&this.cache.delete(l);}this.cache.set(n,o);}clear(){this.cache.clear();}},Yt=new Ve,je=e=>{let t=Mn(e),o=e.children||"";return En(t.runSync(t.parse(o),o),e)},Mn=e=>{let t=Yt.get(e);if(t)return t;let o=Nn(e);return Yt.set(e,o),o},Tn=e=>e.some(t=>Array.isArray(t)?t[0]===Ft:t===Ft),Nn=e=>{let t=e.rehypePlugins||Kt,o=e.remarkPlugins||Kt,n=Tn(t)?o:[...o,Ut],l=e.remarkRehypeOptions?{...Gt,...e.remarkRehypeOptions}:Gt;return unified().use(vn).use(n).use(Cn,l).use(t)},Qt=e=>e,Ln=(e,t,o,n)=>{o?e.children.splice(t,1):e.children[t]={type:"text",value:n};},Sn=(e,t)=>{var o;for(let n in urlAttributes)if(Object.hasOwn(urlAttributes,n)&&Object.hasOwn(e.properties,n)){let l=e.properties[n],r=urlAttributes[n];(r===null||r.includes(e.tagName))&&(e.properties[n]=(o=t(String(l||""),n,e))!=null?o:void 0);}},Rn=(e,t,o,n,l,r)=>{let a=false;return n?a=!n.includes(e.tagName):l&&(a=l.includes(e.tagName)),!a&&r&&typeof t=="number"&&(a=!r(e,t,o)),a},En=(e,t)=>{let{allowElement:o,allowedElements:n,disallowedElements:l,skipHtml:r,unwrapDisallowed:a,urlTransform:d}=t;if(o||n||l||r||d){let i=d||Qt;visit(e,(c,p,m)=>{if(c.type==="raw"&&m&&typeof p=="number")return Ln(m,p,r,c.value),p;if(c.type==="element"&&(Sn(c,i),Rn(c,p,m,n,l,o)&&m&&typeof p=="number"))return a&&c.children?m.children.splice(p,1,...c.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},Be=e=>{let t=Hn.test(e),o=Dn.test(e);if(t||o)return [e];let n=Lexer.lex(e,{gfm:true}),l=[],r=[],a=false;for(let d of n){let s=d.raw,i=l.length;if(r.length>0){if(l[i-1]+=s,d.type==="html"){let c=s.match(Vn);if(c){let p=c[1];r.at(-1)===p&&r.pop();}}continue}if(d.type==="html"&&d.block){let c=s.match(jn);if(c){let p=c[1];s.includes(`</${p}>`)||Bn.has(p.toLowerCase())||r.push(p);}}if(i>0&&!a){let c=l[i-1];if(On(c)%2===1){l[i-1]=c+s;continue}}l.push(s),d.type!=="space"&&(a=d.type==="code");}return l};var to,oo,ke={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(oo=(to=defaultSchema.protocols)==null?void 0:to.href)!=null?oo:[],"tel"]}},Ae={raw:Ft,sanitize:[ro,ke],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Gn={gfm:[Fn,{}]},eo=Object.values(Ae),Yn=Object.values(Gn),Qn={block:" \u258B",circle:" \u25CF"},er={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},L=createContext(er),so=memo(({content:e,shouldParseIncompleteMarkdown:t,index:o,...n})=>jsx(je,{...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(l=>{var r,a;return ((r=e.components)==null?void 0:r[l])!==((a=t.components)==null?void 0:a[l])}))return false}return !(e.rehypePlugins!==t.rehypePlugins||e.remarkPlugins!==t.remarkPlugins)});so.displayName="Block";var tr=["github-light","github-dark"],or={code:code,math:math,mermaid:mermaid},nr=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,components:n,rehypePlugins:l=eo,remarkPlugins:r=Yn,className:a$1,shikiTheme:d=tr,mermaid:s,controls:i=true,isAnimating:c=false,animated:p,BlockComponent:m=so,parseMarkdownIntoBlocksFn:b=Be,caret:u,plugins:h,remend:w,linkSafety:v={enabled:true},allowedTags:C,...P})=>{let f=useMemo(()=>({...or,...h}),[h]),H=useId(),[E,D]=useTransition(),z=useMemo(()=>typeof e!="string"?"":t==="streaming"&&o?Kn(e,w):e,[e,t,o,w]),V=useMemo(()=>b(z),[z,b]),[Z,j]=useState(V);useEffect(()=>{t==="streaming"?D(()=>{j(V);}):j(V);},[V,t]);let k=t==="streaming"?Z:V,R=useMemo(()=>k.map((T,B)=>`${H}-${B}`),[k.length,H]),U=useMemo(()=>p?p===true?Q():Q(p):null,[p]),qe=useMemo(()=>{var T,B;return {shikiTheme:(B=(T=f==null?void 0:f.code)==null?void 0:T.getThemes())!=null?B:d,controls:i,isAnimating:c,mode:t,mermaid:s,linkSafety:v}},[d,i,c,t,s,v,f==null?void 0:f.code]),ze=useMemo(()=>({...Jt,...n}),[n]),Ze=useMemo(()=>{let T=[];return f!=null&&f.cjk&&(T=[...T,...f.cjk.remarkPluginsBefore]),T=[...T,...r],f!=null&&f.cjk&&(T=[...T,...f.cjk.remarkPluginsAfter]),f!=null&&f.math&&(T=[...T,f.math.remarkPlugin]),T},[r,f==null?void 0:f.math,f==null?void 0:f.cjk]),We=useMemo(()=>{var B;let T=l;if(C&&Object.keys(C).length>0&&l===eo){let po={...ke,tagNames:[...(B=ke.tagNames)!=null?B:[],...Object.keys(C)],attributes:{...ke.attributes,...C}};T=[Ae.raw,[ro,po],Ae.harden];}return f!=null&&f.math&&(T=[...T,f.math.rehypePlugin]),U&&c&&(T=[...T,U.rehypePlugin]),T},[l,f==null?void 0:f.math,U,c,C]),mo=useMemo(()=>u&&c?{"--streamdown-caret":`"${Qn[u]}"`}:void 0,[u,c]);return t==="static"?jsx(ce.Provider,{value:f!=null?f:null,children:jsx(L.Provider,{value:qe,children:jsx("div",{className:a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",a$1),children:jsx(je,{components:ze,rehypePlugins:We,remarkPlugins:Ze,...P,children:e})})})}):jsx(ce.Provider,{value:f!=null?f:null,children:jsx(L.Provider,{value:qe,children:jsxs("div",{className:a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",u?"*:last:after:inline *:last:after:align-baseline *:last:after:content-[var(--streamdown-caret)]":null,a$1),style:mo,children:[k.length===0&&u&&c&&jsx("span",{}),k.map((T,B)=>jsx(m,{components:ze,content:T,index:B,rehypePlugins:We,remarkPlugins:Ze,shouldParseIncompleteMarkdown:o,...P},R[B]))]})})})},(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);nr.displayName="Streamdown";var co=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:l=.1,showControls:r=true,initialZoom:a$1=1,fullscreen:d=false})=>{let s=useRef(null),i=useRef(null),[c,p]=useState(a$1),[m,b]=useState({x:0,y:0}),[u,h]=useState(false),[w,v]=useState({x:0,y:0}),[C,P]=useState({x:0,y:0}),f=useCallback(k=>{p(R=>Math.max(o,Math.min(n,R+k)));},[o,n]),H=useCallback(()=>{f(l);},[f,l]),E=useCallback(()=>{f(-l);},[f,l]),D=useCallback(()=>{p(a$1),b({x:0,y:0});},[a$1]),z=useCallback(k=>{k.preventDefault();let R=k.deltaY>0?-l:l;f(R);},[f,l]),V=useCallback(k=>{if(k.button!==0||k.isPrimary===false)return;h(true),v({x:k.clientX,y:k.clientY}),P(m);let R=k.currentTarget;R instanceof HTMLElement&&R.setPointerCapture(k.pointerId);},[m]),Z=useCallback(k=>{if(!u)return;k.preventDefault();let R=k.clientX-w.x,U=k.clientY-w.y;b({x:C.x+R,y:C.y+U});},[u,w,C]),j=useCallback(k=>{h(false);let R=k.currentTarget;R instanceof HTMLElement&&R.releasePointerCapture(k.pointerId);},[]);return useEffect(()=>{let k=s.current;if(k)return k.addEventListener("wheel",z,{passive:false}),()=>{k.removeEventListener("wheel",z);}},[z]),useEffect(()=>{let k=i.current;if(k&&u)return document.body.style.userSelect="none",k.addEventListener("pointermove",Z,{passive:false}),k.addEventListener("pointerup",j),k.addEventListener("pointercancel",j),()=>{document.body.style.userSelect="",k.removeEventListener("pointermove",Z),k.removeEventListener("pointerup",j),k.removeEventListener("pointercancel",j);}},[u,Z,j]),jsxs("div",{className:a("relative flex flex-col",d?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:u?"grabbing":"grab"},children:[r?jsxs("div",{className:a("absolute z-10 flex flex-col gap-1 rounded-md border border-border bg-background/90 p-1 shadow-sm backdrop-blur-sm",d?"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:c>=n,onClick:H,title:"Zoom in",type:"button",children:jsx(Fe,{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:c<=o,onClick:E,title:"Zoom out",type:"button",children:jsx(Ke,{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:D,title:"Reset zoom and pan",type:"button",children:jsx(Ue,{size:16})})]}):null,jsx("div",{className:a("flex-1 origin-center transition-transform duration-150 ease-out",d?"flex h-full w-full items-center justify-center":"flex w-full items-center justify-center"),onPointerDown:V,ref:i,role:"application",style:{transform:`translate(${m.x}px, ${m.y}px) scale(${c})`,transformOrigin:"center center",touchAction:"none",willChange:"transform"},children:e})]})};var mt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:l=true})=>{let[r,a$1]=useState(null),[d,s]=useState(false),[i,c]=useState(""),[p,m]=useState(""),[b,u]=useState(0),{mermaid:h}=useContext(L),w=G(),v=h==null?void 0:h.errorComponent,{shouldRender:C,containerRef:P}=$e({immediate:n});if(useEffect(()=>{if(!C)return;if(!w){a$1("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{a$1(null),s(!0);let E=w.getMermaid(o),D=e.split("").reduce((Z,j)=>(Z<<5)-Z+j.charCodeAt(0)|0,0),z=`mermaid-${Math.abs(D)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:V}=await E.render(z,e);c(V),m(V);}catch(E){if(!(p||i)){let D=E instanceof Error?E.message:"Failed to render Mermaid chart";a$1(D);}}finally{s(false);}})();},[e,o,b,C,w]),!(C||i||p))return jsx("div",{className:a("my-4 min-h-[200px]",t),ref:P});if(d&&!i&&!p)return jsx("div",{className:a("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&&!i&&!p){let H=()=>u(E=>E+1);return v?jsx("div",{ref:P,children:jsx(v,{chart:e,error:r,retry:H})}):jsxs("div",{className:a("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 f=i||p;return jsx("div",{className:a("size-full",t),"data-streamdown":"mermaid",ref:P,children:jsx(co,{className:a(n?"size-full overflow-hidden":"my-4 overflow-hidden",t),fullscreen:n,maxZoom:3,minZoom:.5,showControls:l,zoomStep:.1,children:jsx("div",{"aria-label":"Mermaid chart",className:a("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:f},role:"img"})})})};export{Q as a,Eo as b,Wr as c,mt as d,Qt as e,Be as f,Ae as g,Gn as h,L as i,so as j,nr as k};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {a,b}from'./chunk-O2KN3ML5.js';import {createContext,lazy,memo,useContext,isValidElement,useMemo,useId,useTransition,useState,useEffect,useCallback,Suspense,cloneElement,useRef}from'react';import {code}from'@streamdown/code';import {math}from'@streamdown/math';import {mermaid}from'@streamdown/mermaid';import {harden}from'rehype-harden';import Ft from'rehype-raw';import ro,{defaultSchema}from'rehype-sanitize';import Fn from'remark-gfm';import Kn from'remend';import {visitParents,SKIP}from'unist-util-visit-parents';import {jsx,Fragment,jsxs}from'react/jsx-runtime';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 go=300,bo="300px",ho=500;function $e(e={}){let{immediate:t=false,debounceDelay:o=go,rootMargin:n=bo,idleTimeout:i=ho}=e,[r,a]=useState(false),c=useRef(null),s=useRef(null),l=useRef(null),d=useMemo(()=>f=>{let u=Date.now();return window.setTimeout(()=>{f({didTimeout:false,timeRemaining:()=>Math.max(0,50-(Date.now()-u))});},1)},[]),p=useMemo(()=>typeof window!="undefined"&&window.requestIdleCallback?(f,u)=>window.requestIdleCallback(f,u):d,[d]),m=useMemo(()=>typeof window!="undefined"&&window.cancelIdleCallback?f=>window.cancelIdleCallback(f):f=>{clearTimeout(f);},[]);return useEffect(()=>{if(t){a(true);return}let f=c.current;if(!f)return;s.current&&(clearTimeout(s.current),s.current=null),l.current&&(m(l.current),l.current=null);let u=()=>{s.current&&(clearTimeout(s.current),s.current=null),l.current&&(m(l.current),l.current=null);},y=M=>{l.current=p(b=>{b.timeRemaining()>0||b.didTimeout?(a(true),M.disconnect()):l.current=p(()=>{a(true),M.disconnect();},{timeout:i/2});},{timeout:i});},k=M=>{u(),s.current=window.setTimeout(()=>{var E,D;let b=M.takeRecords();(b.length===0||(D=(E=b.at(-1))==null?void 0:E.isIntersecting)!=null&&D)&&y(M);},o);},v=(M,b)=>{M.isIntersecting?k(b):u();},x=new IntersectionObserver(M=>{for(let b of M)v(b,x);},{rootMargin:n,threshold:0});return x.observe(f),()=>{s.current&&clearTimeout(s.current),l.current&&m(l.current),x.disconnect();}},[t,o,n,i,m,p]),{shouldRender:r,containerRef:c}}var _e=/\s/,ko=/^\s+$/,vo=new Set(["code","pre","svg","math","annotation"]),Co=e=>typeof e=="object"&&e!==null&&"type"in e&&e.type==="element",xo=e=>e.some(t=>Co(t)&&vo.has(t.tagName)),Po=e=>{let t=[],o="",n=false;for(let i of e){let r=_e.test(i);r!==n&&o&&(t.push(o),o=""),o+=i,n=r;}return o&&t.push(o),t},Mo=e=>{let t=[],o="";for(let n of e)_e.test(n)?o+=n:(o&&(t.push(o),o=""),t.push(n));return o&&t.push(o),t},To=(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}]}),No=(e,t,o)=>{let n=t.at(-1);if(!(n&&"children"in n))return;if(xo(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"?Mo(a):Po(a)).map(l=>ko.test(l)?{type:"text",value:l}:To(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)=>No(s,l,t));}}}Q();var F=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"})}),W=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"})}),Xe=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"})]}),Je=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"})}),Pe=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"})}),Fe=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"})}),Ke=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 Eo=createContext({code:""}),ae=()=>useContext(Eo);var Me=({onCopy:e,onError:t,timeout:o=2e3,children:n,className:i,code:r,...a$1})=>{let[c,s]=useState(false),l=useRef(0),{code:d}=ae(),{isAnimating:p}=useContext(L),m=r!=null?r:d,f=async()=>{var y;if(typeof window=="undefined"||!((y=navigator==null?void 0:navigator.clipboard)!=null&&y.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(k){t==null||t(k);}};useEffect(()=>()=>{window.clearTimeout(l.current);},[]);let u=c?F:K;return jsx("button",{className:a("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:f,title:"Copy Code",type:"button",...a$1,children:n!=null?n:jsx(u,{size:14})})};var Ye={"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"},et=({onDownload:e,onError:t,language:o,children:n,className:i,code:r,...a$1})=>{let{code:c}=ae(),{isAnimating:s}=useContext(L),l=r!=null?r:c,p=`file.${o&&o in Ye?Ye[o]:"txt"}`,m="text/plain",f=()=>{try{b(p,l,m),e==null||e();}catch(u){t==null||t(u);}};return jsx("button",{className:a("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:f,title:"Download file",type:"button",...a$1,children:n!=null?n:jsx(W,{size:14})})};var ie=()=>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(Xe,{className:"size-4 animate-spin"})})]});var Oo=/\.[^/.]+$/,tt=({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 f=c.type,u="png";f.includes("jpeg")||f.includes("jpg")?u="jpg":f.includes("png")?u="png":f.includes("svg")?u="svg":f.includes("gif")?u="gif":f.includes("webp")&&(u="webp"),m=`${(n||l||"image").replace(Oo,"")}.${u}`;}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:a("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:a("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(W,{size:14})})]}):null};var ee=0,Zo=()=>{ee+=1,ee===1&&(document.body.style.overflow="hidden");},Wo=()=>{ee=Math.max(0,ee-1),ee===0&&(document.body.style.overflow="");},rt=({url:e,isOpen:t,onClose:o,onConfirm:n})=>{let[i,r]=useState(false),a$1=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){Zo();let s=l=>{l.key==="Escape"&&o();};return document.addEventListener("keydown",s),()=>{document.removeEventListener("keydown",s),Wo();}}},[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(Pe,{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:a("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$1,type:"button",children:i?jsxs(Fragment,{children:[jsx(F,{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(Pe,{size:14}),jsx("span",{children:"Open link"})]})]})]})}):null};var ce=createContext(null),st=()=>useContext(ce),Wr=()=>{var t;let e=st();return (t=e==null?void 0:e.code)!=null?t:null},G=()=>{var t;let e=st();return (t=e==null?void 0:e.mermaid)!=null?t:null};var at=(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 lt=({chart:e,children:t,className:o,onDownload:n,config:i,onError:r})=>{let[a$1,c]=useState(false),s=useRef(null),{isAnimating:l}=useContext(L),d=G(),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 f=d.getMermaid(i),u=e.split("").reduce((v,x)=>(v<<5)-v+x.charCodeAt(0)|0,0),y=`mermaid-${Math.abs(u)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:k}=await f.render(y,e);if(!k){r==null||r(new Error("SVG not found. Please wait for the diagram to render."));return}if(m==="svg"){b("diagram.svg",k,"image/svg+xml"),c(!1),n==null||n(m);return}if(m==="png"){let v=await at(k);b("diagram.png",v,"image/png"),n==null||n(m),c(!1);return}}catch(f){r==null||r(f);}};return useEffect(()=>{let m=f=>{let u=f.composedPath();s.current&&!u.includes(s.current)&&c(false);};return document.addEventListener("mousedown",m),()=>{document.removeEventListener("mousedown",m);}},[]),jsxs("div",{className:"relative",ref:s,children:[jsx("button",{className:a("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$1),title:"Download diagram",type:"button",children:t!=null?t:jsx(W,{size:14})}),a$1?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,Yo=()=>{oe+=1,oe===1&&(document.body.style.overflow="hidden");},Qo=()=>{oe=Math.max(0,oe-1),oe===0&&(document.body.style.overflow="");},pt=({chart:e,config:t,onFullscreen:o,onExit:n,className:i,...r})=>{let[a$1,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$1);};return useEffect(()=>{if(a$1){Yo();let m=f=>{f.key==="Escape"&&c(false);};return document.addEventListener("keydown",m),()=>{document.removeEventListener("keydown",m),Qo();}}},[a$1]),useEffect(()=>{a$1?o==null||o():n&&n();},[a$1,o,n]),jsxs(Fragment,{children:[jsx("button",{className:a("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(Je,{size:14})}),a$1?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(mt,{chart:e,className:"size-full [&_svg]:h-auto [&_svg]:w-auto",config:t,fullscreen:true,showControls:d})})]}):null]})};var de=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}},me=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
|
+
`)},ut=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("")},ft=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 yt=({children:e,className:t,onCopy:o,onError:n,timeout:i=2e3})=>{let[r,a$1]=useState(false),[c,s]=useState(false),l=useRef(null),d=useRef(0),{isAnimating:p}=useContext(L),m=async u=>{var y,k;if(typeof window=="undefined"||!((y=navigator==null?void 0:navigator.clipboard)!=null&&y.write)){n==null||n(new Error("Clipboard API not available"));return}try{let v=(k=l.current)==null?void 0:k.closest('[data-streamdown="table-wrapper"]'),x=v==null?void 0:v.querySelector("table");if(!x){n==null||n(new Error("Table not found"));return}let M=de(x),b=u==="csv"?me(M):ut(M),H=new ClipboardItem({"text/plain":new Blob([b],{type:"text/plain"}),"text/html":new Blob([x.outerHTML],{type:"text/html"})});await navigator.clipboard.write([H]),s(!0),a$1(!1),o==null||o(u),d.current=window.setTimeout(()=>s(!1),i);}catch(v){n==null||n(v);}};useEffect(()=>{let u=y=>{let k=y.composedPath();l.current&&!k.includes(l.current)&&a$1(false);};return document.addEventListener("mousedown",u),()=>{document.removeEventListener("mousedown",u),window.clearTimeout(d.current);}},[]);let f=c?F:K;return jsxs("div",{className:"relative",ref:l,children:[jsx("button",{className:a("cursor-pointer p-1 text-muted-foreground transition-all hover:text-foreground disabled:cursor-not-allowed disabled:opacity-50",t),disabled:p,onClick:()=>a$1(!r),title:"Copy table",type:"button",children:e!=null?e:jsx(f,{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 kt=({children:e,className:t,onDownload:o,onError:n})=>{let[i,r]=useState(false),a$1=useRef(null),{isAnimating:c}=useContext(L),s=l=>{var d;try{let p=(d=a$1.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 f=de(m),u=l==="csv"?me(f):ft(f);b(`table.${l==="csv"?"csv":"md"}`,u,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$1.current&&!p.includes(a$1.current)&&r(false);};return document.addEventListener("mousedown",l),()=>{document.removeEventListener("mousedown",l);}},[]),jsxs("div",{className:"relative",ref:a$1,children:[jsx("button",{className:a("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(W,{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 Ct=({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(yt,{}),jsx(kt,{})]}):null,jsx("div",{className:"overflow-x-auto overscroll-y-auto",children:jsx("table",{className:a("w-full border-collapse border border-border",t),"data-streamdown":"table",...n,children:e})})]});var dn=lazy(()=>import('./code-block-XHOE4N52.js').then(e=>({default:e.CodeBlock}))),mn=lazy(()=>import('./mermaid-KWRIC3LD.js').then(e=>({default:e.Mermaid}))),pn=lazy(()=>import('./vega-W36RN4XC.js').then(e=>({default:e.default}))),un=/language-([^\s]+)/;function ye(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&&ye(e.node,t.node)}var Se=(e,t)=>typeof e=="boolean"?e:e[t]!==false,ge=(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},He=memo(({children:e,className:t,node:o,...n})=>jsx("ol",{className:a("list-inside list-decimal whitespace-normal [li_&]:pl-6",t),"data-streamdown":"ordered-list",...n,children:e}),(e,t)=>N(e,t));He.displayName="MarkdownOl";var xt=memo(({children:e,className:t,node:o,...n})=>jsx("li",{className:a("py-1 [&>p]:inline",t),"data-streamdown":"list-item",...n,children:e}),(e,t)=>e.className===t.className&&ye(e.node,t.node));xt.displayName="MarkdownLi";var Pt=memo(({children:e,className:t,node:o,...n})=>jsx("ul",{className:a("list-inside list-disc whitespace-normal [li_&]:pl-6",t),"data-streamdown":"unordered-list",...n,children:e}),(e,t)=>N(e,t));Pt.displayName="MarkdownUl";var Mt=memo(({className:e,node:t,...o})=>jsx("hr",{className:a("my-6 border-border",e),"data-streamdown":"horizontal-rule",...o}),(e,t)=>N(e,t));Mt.displayName="MarkdownHr";var Tt=memo(({children:e,className:t,node:o,...n})=>jsx("span",{className:a("font-semibold",t),"data-streamdown":"strong",...n,children:e}),(e,t)=>N(e,t));Tt.displayName="MarkdownStrong";var fn=({children:e,className:t,href:o,node:n,...i})=>{let{linkSafety:r}=useContext(L),[a$1,c]=useState(false),s=o==="streamdown:incomplete-link",l=useCallback(async f=>{if(!(!(r!=null&&r.enabled&&o)||s)){if(f.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$1,onClose:p,onConfirm:d};return r!=null&&r.enabled&&o?jsxs(Fragment,{children:[jsx("button",{className:a("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(rt,{...m})]}):jsx("a",{className:a("wrap-anywhere font-medium text-primary underline",t),"data-incomplete":s,"data-streamdown":"link",href:o,rel:"noreferrer",target:"_blank",...i,children:e})},Nt=memo(fn,(e,t)=>N(e,t)&&e.href===t.href);Nt.displayName="MarkdownA";var Lt=memo(({children:e,className:t,node:o,...n})=>jsx("h1",{className:a("mt-6 mb-2 font-semibold text-3xl",t),"data-streamdown":"heading-1",...n,children:e}),(e,t)=>N(e,t));Lt.displayName="MarkdownH1";var Rt=memo(({children:e,className:t,node:o,...n})=>jsx("h2",{className:a("mt-6 mb-2 font-semibold text-2xl",t),"data-streamdown":"heading-2",...n,children:e}),(e,t)=>N(e,t));Rt.displayName="MarkdownH2";var St=memo(({children:e,className:t,node:o,...n})=>jsx("h3",{className:a("mt-6 mb-2 font-semibold text-xl",t),"data-streamdown":"heading-3",...n,children:e}),(e,t)=>N(e,t));St.displayName="MarkdownH3";var Et=memo(({children:e,className:t,node:o,...n})=>jsx("h4",{className:a("mt-6 mb-2 font-semibold text-lg",t),"data-streamdown":"heading-4",...n,children:e}),(e,t)=>N(e,t));Et.displayName="MarkdownH4";var It=memo(({children:e,className:t,node:o,...n})=>jsx("h5",{className:a("mt-6 mb-2 font-semibold text-base",t),"data-streamdown":"heading-5",...n,children:e}),(e,t)=>N(e,t));It.displayName="MarkdownH5";var Ht=memo(({children:e,className:t,node:o,...n})=>jsx("h6",{className:a("mt-6 mb-2 font-semibold text-sm",t),"data-streamdown":"heading-6",...n,children:e}),(e,t)=>N(e,t));Ht.displayName="MarkdownH6";var Dt=memo(({children:e,className:t,node:o,...n})=>{let{controls:i}=useContext(L),r=Se(i,"table");return jsx(Ct,{className:t,showControls:r,...n,children:e})},(e,t)=>N(e,t));Dt.displayName="MarkdownTable";var Vt=memo(({children:e,className:t,node:o,...n})=>jsx("thead",{className:a("bg-muted/80",t),"data-streamdown":"table-header",...n,children:e}),(e,t)=>N(e,t));Vt.displayName="MarkdownThead";var jt=memo(({children:e,className:t,node:o,...n})=>jsx("tbody",{className:a("divide-y divide-border bg-muted/40",t),"data-streamdown":"table-body",...n,children:e}),(e,t)=>N(e,t));jt.displayName="MarkdownTbody";var Bt=memo(({children:e,className:t,node:o,...n})=>jsx("tr",{className:a("border-border border-b",t),"data-streamdown":"table-row",...n,children:e}),(e,t)=>N(e,t));Bt.displayName="MarkdownTr";var Ot=memo(({children:e,className:t,node:o,...n})=>jsx("th",{className:a("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));Ot.displayName="MarkdownTh";var At=memo(({children:e,className:t,node:o,...n})=>jsx("td",{className:a("px-4 py-2 text-sm",t),"data-streamdown":"table-cell",...n,children:e}),(e,t)=>N(e,t));At.displayName="MarkdownTd";var qt=memo(({children:e,className:t,node:o,...n})=>jsx("blockquote",{className:a("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));qt.displayName="MarkdownBlockquote";var zt=memo(({children:e,className:t,node:o,...n})=>jsx("sup",{className:a("text-sm",t),"data-streamdown":"superscript",...n,children:e}),(e,t)=>N(e,t));zt.displayName="MarkdownSup";var Zt=memo(({children:e,className:t,node:o,...n})=>jsx("sub",{className:a("text-sm",t),"data-streamdown":"subscript",...n,children:e}),(e,t)=>N(e,t));Zt.displayName="MarkdownSub";var Wt=memo(({children:e,className:t,node:o,...n})=>{if("data-footnotes"in n){let r=s=>{var m,f;if(!isValidElement(s))return false;let l=Array.isArray(s.props.children)?s.props.children:[s.props.children],d=false,p=false;for(let u of l)if(u){if(typeof u=="string")u.trim()!==""&&(d=true);else if(isValidElement(u))if(((m=u.props)==null?void 0:m["data-footnote-backref"])!==void 0)p=true;else {let y=Array.isArray(u.props.children)?u.props.children:[u.props.children];for(let k of y){if(typeof k=="string"&&k.trim()!==""){d=true;break}if(isValidElement(k)&&((f=k.props)==null?void 0:f["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===He){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));Wt.displayName="MarkdownSection";var gn=({node:e,className:t,children:o,...n})=>{var m;let i=!("data-block"in n),{mermaid:r,controls:a$1}=useContext(L),c=G();if(i)return jsx("code",{className:a("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==="vega-lite")try{let f=JSON.parse(d);return jsx(Suspense,{fallback:jsx(ie,{}),children:jsx("div",{className:a("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"vega-lite-block",children:jsx(pn,{spec:f})})})}catch(f){console.warn("Failed to parse vega-lite spec:",f);}if(l==="mermaid"&&c){let f=Se(a$1,"mermaid"),u=ge(a$1,"download"),y=ge(a$1,"copy"),k=ge(a$1,"fullscreen"),v=ge(a$1,"panZoom"),x=f&&(u||y||k);return jsx(Suspense,{fallback:jsx(ie,{}),children:jsxs("div",{className:a("group relative my-4 h-auto rounded-xl border p-4",t),"data-streamdown":"mermaid-block",children:[x?jsxs("div",{className:"flex items-center justify-end gap-2",children:[u?jsx(lt,{chart:d,config:r==null?void 0:r.config}):null,y?jsx(Me,{code:d}):null,k?jsx(pt,{chart:d,config:r==null?void 0:r.config}):null]}):null,jsx(mn,{chart:d,config:r==null?void 0:r.config,showControls:v})]})})}let p=Se(a$1,"code");return jsx(Suspense,{fallback:jsx(ie,{}),children:jsx(dn,{className:a("overflow-x-auto border-border border-t",t),code:d,language:l,children:p?jsxs(Fragment,{children:[jsx(et,{code:d,language:l}),jsx(Me,{})]}):null})})},$t=memo(gn,(e,t)=>e.className===t.className&&ye(e.node,t.node));$t.displayName="MarkdownCode";var _t=memo(tt,(e,t)=>e.className===t.className&&ye(e.node,t.node));_t.displayName="MarkdownImg";var Xt=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));Xt.displayName="MarkdownParagraph";var Jt={ol:He,li:xt,ul:Pt,hr:Mt,strong:Tt,a:Nt,h1:Lt,h2:Rt,h3:St,h4:Et,h5:It,h6:Ht,table:Dt,thead:Vt,tbody:jt,tr:Bt,th:Ot,td:At,blockquote:qt,code:$t,img:_t,pre:({children:e})=>isValidElement(e)?cloneElement(e,{"data-block":"true"}):e,sup:zt,sub:Zt,p:Xt,section:Wt};var Ut=()=>e=>{visit(e,"html",(t,o,n)=>{!n||typeof o!="number"||(n.children[o]={type:"text",value:t.value});});};var Kt=[],Gt={allowDangerousHtml:true},we=new WeakMap,Ve=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 f=0;f<p.length;f+=1){let u=p[f];if(f>0&&(m+=","),Array.isArray(u)){let[y,k]=u;if(typeof y=="function"){let v=we.get(y);v||(v=y.name,we.set(y,v)),m+=v;}else m+=String(y);m+=":",m+=JSON.stringify(k);}else if(typeof u=="function"){let y=we.get(u);y||(y=u.name,we.set(u,y)),m+=y;}else m+=String(u);}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();}},Yt=new Ve,je=e=>{let t=Mn(e),o=e.children||"";return En(t.runSync(t.parse(o),o),e)},Mn=e=>{let t=Yt.get(e);if(t)return t;let o=Nn(e);return Yt.set(e,o),o},Tn=e=>e.some(t=>Array.isArray(t)?t[0]===Ft:t===Ft),Nn=e=>{let t=e.rehypePlugins||Kt,o=e.remarkPlugins||Kt,n=Tn(t)?o:[...o,Ut],i=e.remarkRehypeOptions?{...Gt,...e.remarkRehypeOptions}:Gt;return unified().use(vn).use(n).use(Cn,i).use(t)},Qt=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||Qt;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},Be=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 to,oo,ke={...defaultSchema,protocols:{...defaultSchema.protocols,href:[...(oo=(to=defaultSchema.protocols)==null?void 0:to.href)!=null?oo:[],"tel"]}},Ae={raw:Ft,sanitize:[ro,ke],harden:[harden,{allowedImagePrefixes:["*"],allowedLinkPrefixes:["*"],allowedProtocols:["*"],defaultOrigin:void 0,allowDataImages:true}]},Gn={gfm:[Fn,{}]},eo=Object.values(Ae),Yn=Object.values(Gn),Qn={block:" \u258B",circle:" \u25CF"},er={shikiTheme:["github-light","github-dark"],controls:true,isAnimating:false,mode:"streaming",mermaid:void 0,linkSafety:{enabled:true}},L=createContext(er),so=memo(({content:e,shouldParseIncompleteMarkdown:t,index:o,...n})=>jsx(je,{...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)});so.displayName="Block";var tr=["github-light","github-dark"],or={code:code,math:math,mermaid:mermaid},nr=memo(({children:e,mode:t="streaming",parseIncompleteMarkdown:o=true,components:n,rehypePlugins:i=eo,remarkPlugins:r=Yn,className:a$1,shikiTheme:c=tr,mermaid:s,controls:l=true,isAnimating:d=false,animated:p,BlockComponent:m=so,parseMarkdownIntoBlocksFn:f=Be,caret:u,plugins:y,remend:k,linkSafety:v={enabled:true},allowedTags:x,...M})=>{let b=useMemo(()=>({...or,...y}),[y]),H=useId(),[E,D]=useTransition(),z=useMemo(()=>typeof e!="string"?"":t==="streaming"&&o?Kn(e,k):e,[e,t,o,k]),V=useMemo(()=>f(z),[z,f]),[Z,j]=useState(V);useEffect(()=>{t==="streaming"?D(()=>{j(V);}):j(V);},[V,t]);let w=t==="streaming"?Z:V,S=useMemo(()=>w.map((T,B)=>`${H}-${B}`),[w.length,H]),U=useMemo(()=>p?p===true?Q():Q(p):null,[p]),qe=useMemo(()=>{var T,B;return {shikiTheme:(B=(T=b==null?void 0:b.code)==null?void 0:T.getThemes())!=null?B:c,controls:l,isAnimating:d,mode:t,mermaid:s,linkSafety:v}},[c,l,d,t,s,v,b==null?void 0:b.code]),ze=useMemo(()=>({...Jt,...n}),[n]),Ze=useMemo(()=>{let T=[];return b!=null&&b.cjk&&(T=[...T,...b.cjk.remarkPluginsBefore]),T=[...T,...r],b!=null&&b.cjk&&(T=[...T,...b.cjk.remarkPluginsAfter]),b!=null&&b.math&&(T=[...T,b.math.remarkPlugin]),T},[r,b==null?void 0:b.math,b==null?void 0:b.cjk]),We=useMemo(()=>{var B;let T=i;if(x&&Object.keys(x).length>0&&i===eo){let po={...ke,tagNames:[...(B=ke.tagNames)!=null?B:[],...Object.keys(x)],attributes:{...ke.attributes,...x}};T=[Ae.raw,[ro,po],Ae.harden];}return b!=null&&b.math&&(T=[...T,b.math.rehypePlugin]),U&&d&&(T=[...T,U.rehypePlugin]),T},[i,b==null?void 0:b.math,U,d,x]),mo=useMemo(()=>u&&d?{"--streamdown-caret":`"${Qn[u]}"`}:void 0,[u,d]);return t==="static"?jsx(ce.Provider,{value:b!=null?b:null,children:jsx(L.Provider,{value:qe,children:jsx("div",{className:a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",a$1),children:jsx(je,{components:ze,rehypePlugins:We,remarkPlugins:Ze,...M,children:e})})})}):jsx(ce.Provider,{value:b!=null?b:null,children:jsx(L.Provider,{value:qe,children:jsxs("div",{className:a("space-y-4 whitespace-normal *:first:mt-0 *:last:mb-0",u?"*:last:after:inline *:last:after:align-baseline *:last:after:content-[var(--streamdown-caret)]":null,a$1),style:mo,children:[w.length===0&&u&&d&&jsx("span",{}),w.map((T,B)=>jsx(m,{components:ze,content:T,index:B,rehypePlugins:We,remarkPlugins:Ze,shouldParseIncompleteMarkdown:o,...M},S[B]))]})})})},(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);nr.displayName="Streamdown";var co=({children:e,className:t,minZoom:o=.5,maxZoom:n=3,zoomStep:i=.1,showControls:r=true,initialZoom:a$1=1,fullscreen:c=false})=>{let s=useRef(null),l=useRef(null),[d,p]=useState(a$1),[m,f]=useState({x:0,y:0}),[u,y]=useState(false),[k,v]=useState({x:0,y:0}),[x,M]=useState({x:0,y:0}),b=useCallback(w=>{p(S=>Math.max(o,Math.min(n,S+w)));},[o,n]),H=useCallback(()=>{b(i);},[b,i]),E=useCallback(()=>{b(-i);},[b,i]),D=useCallback(()=>{p(a$1),f({x:0,y:0});},[a$1]),z=useCallback(w=>{w.preventDefault();let S=w.deltaY>0?-i:i;b(S);},[b,i]),V=useCallback(w=>{if(w.button!==0||w.isPrimary===false)return;y(true),v({x:w.clientX,y:w.clientY}),M(m);let S=w.currentTarget;S instanceof HTMLElement&&S.setPointerCapture(w.pointerId);},[m]),Z=useCallback(w=>{if(!u)return;w.preventDefault();let S=w.clientX-k.x,U=w.clientY-k.y;f({x:x.x+S,y:x.y+U});},[u,k,x]),j=useCallback(w=>{y(false);let S=w.currentTarget;S instanceof HTMLElement&&S.releasePointerCapture(w.pointerId);},[]);return useEffect(()=>{let w=s.current;if(w)return w.addEventListener("wheel",z,{passive:false}),()=>{w.removeEventListener("wheel",z);}},[z]),useEffect(()=>{let w=l.current;if(w&&u)return document.body.style.userSelect="none",w.addEventListener("pointermove",Z,{passive:false}),w.addEventListener("pointerup",j),w.addEventListener("pointercancel",j),()=>{document.body.style.userSelect="",w.removeEventListener("pointermove",Z),w.removeEventListener("pointerup",j),w.removeEventListener("pointercancel",j);}},[u,Z,j]),jsxs("div",{className:a("relative flex flex-col",c?"h-full w-full":"min-h-28 w-full",t),ref:s,style:{cursor:u?"grabbing":"grab"},children:[r?jsxs("div",{className:a("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:H,title:"Zoom in",type:"button",children:jsx(Fe,{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(Ke,{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:D,title:"Reset zoom and pan",type:"button",children:jsx(Ue,{size:16})})]}):null,jsx("div",{className:a("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:V,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 mt=({chart:e,className:t,config:o,fullscreen:n=false,showControls:i=true})=>{let[r,a$1]=useState(null),[c,s]=useState(false),[l,d]=useState(""),[p,m]=useState(""),[f,u]=useState(0),{mermaid:y}=useContext(L),k=G(),v=y==null?void 0:y.errorComponent,{shouldRender:x,containerRef:M}=$e({immediate:n});if(useEffect(()=>{if(!x)return;if(!k){a$1("Mermaid plugin not available. Please add the mermaid plugin to enable diagram rendering.");return}(async()=>{try{a$1(null),s(!0);let E=k.getMermaid(o),D=e.split("").reduce((Z,j)=>(Z<<5)-Z+j.charCodeAt(0)|0,0),z=`mermaid-${Math.abs(D)}-${Date.now()}-${Math.random().toString(36).substring(2,9)}`,{svg:V}=await E.render(z,e);d(V),m(V);}catch(E){if(!(p||l)){let D=E instanceof Error?E.message:"Failed to render Mermaid chart";a$1(D);}}finally{s(false);}})();},[e,o,f,x,k]),!(x||l||p))return jsx("div",{className:a("my-4 min-h-[200px]",t),ref:M});if(c&&!l&&!p)return jsx("div",{className:a("my-4 flex justify-center p-4",t),ref:M,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 H=()=>u(E=>E+1);return v?jsx("div",{ref:M,children:jsx(v,{chart:e,error:r,retry:H})}):jsxs("div",{className:a("rounded-lg border border-red-200 bg-red-50 p-4",t),ref:M,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 b=l||p;return jsx("div",{className:a("size-full",t),"data-streamdown":"mermaid",ref:M,children:jsx(co,{className:a(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:a("flex justify-center",n?"size-full items-center":null),dangerouslySetInnerHTML:{__html:b},role:"img"})})})};export{Q as a,Eo as b,Wr as c,mt as d,Qt as e,Be as f,Ae as g,Gn as h,L as i,so as j,nr as k};
|