import{r as u,C as k,j as s,D as j,u as b,c as v,a as N,b as w}from"./index-BCTWtQQB.js";var y=b("block","before:content-[counter(line)]","before:inline-block","before:[counter-increment:line]","before:w-4","before:mr-4","before:text-[13px]","before:text-right","before:text-muted-foreground/50","before:font-mono","before:select-none"),$=u.memo(({children:e,result:t,language:a,className:n,...l})=>{let r=u.useMemo(()=>({backgroundColor:t.bg,color:t.fg}),[t.bg,t.fg]);return s.jsx("pre",{className:b(n,"p-4 text-sm dark:bg-(--shiki-dark-bg)!"),"data-language":a,"data-streamdown":"code-block-body",style:r,...l,children:s.jsx("code",{className:"[counter-increment:line_0] [counter-reset:line]",children:t.tokens.map((i,d)=>s.jsx("span",{className:y,children:i.map((o,c)=>s.jsx("span",{className:"dark:bg-(--shiki-dark-bg)! dark:text-(--shiki-dark)!",style:{color:o.color,backgroundColor:o.bgColor,...o.htmlStyle},...o.htmlAttrs,children:o.content},c))},d))})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className),C=({className:e,language:t,style:a,...n})=>s.jsx("div",{className:b("my-4 w-full overflow-hidden rounded-xl border border-border",e),"data-language":t,"data-streamdown":"code-block",style:{contentVisibility:"auto",containIntrinsicSize:"auto 200px",...a},...n}),S=({language:e,children:t})=>s.jsxs("div",{className:"flex items-center justify-between bg-muted/80 p-3 text-muted-foreground text-xs","data-language":e,"data-streamdown":"code-block-header",children:[s.jsx("span",{className:"ml-1 font-mono lowercase",children:e}),s.jsx("div",{className:"flex items-center gap-2",children:t})]}),E=N({forgiving:!0}),m=new Map,h=new Map,g=new Map,M=(e,t)=>`${e}-${t[0]}-${t[1]}`,T=(e,t,a)=>{let n=e.slice(0,100),l=e.length>100?e.slice(-100):"";return`${t}:${a[0]}:${a[1]}:${e.length}:${n}:${l}`},x=e=>Object.hasOwn(w,e),A=(e,t)=>{let a=x(e)?e:"text",n=M(a,t);if(m.has(n))return m.get(n);let l=v({themes:t,langs:[a],engine:E});return m.set(n,l),l},f=(e,t,a,n)=>{let l=x(t)?t:"text",r=T(e,l,a);return h.has(r)?h.get(r):(n&&(g.has(r)||g.set(r,new Set),g.get(r).add(n)),A(l,a).then(i=>{let d=i.codeToTokens(e,{lang:l,themes:{light:a[0],dark:a[1]}});h.set(r,d);let o=g.get(r);if(o){for(let c of o)c(d);g.delete(r)}}).catch(i=>{console.error("Failed to highlight code:",i),g.delete(r)}),null)},L=({code:e,language:t,className:a,children:n,...l})=>{let{shikiTheme:r}=u.useContext(k),i=u.useMemo(()=>({bg:"transparent",fg:"inherit",tokens:e.split(`
`).map(c=>[{content:c,color:"inherit",bgColor:"transparent",htmlStyle:{},offset:0}])}),[e]),[d,o]=u.useState(i);return u.useEffect(()=>{let c=f(e,t,r);if(c){o(c);return}f(e,t,r,p=>{o(p)})},[e,t,r]),s.jsx(j.Provider,{value:{code:e},children:s.jsxs(C,{language:t,children:[s.jsx(S,{language:t,children:n}),s.jsx($,{className:a,language:t,result:d,...l})]})})};export{L as CodeBlock};
