import{o as e}from"./chunk-CFjPhJqf.js";import{g as t,h as n,i as r,n as i,r as a,t as o}from"./index-DwCcYXch.js";var s=e(t(),1),c=n(),l=r(`block`,`before:content-[counter(line)]`,`before:inline-block`,`before:[counter-increment:line]`,`before:w-6`,`before:mr-4`,`before:text-[13px]`,`before:text-right`,`before:text-muted-foreground/50`,`before:font-mono`,`before:select-none`),u=e=>{let t={};for(let n of e.split(`;`)){let e=n.indexOf(`:`);if(e>0){let r=n.slice(0,e).trim(),i=n.slice(e+1).trim();r&&i&&(t[r]=i)}}return t},d=(0,s.memo)(({children:e,result:t,language:n,className:i,...a})=>{let o=(0,s.useMemo)(()=>{let e={};return t.bg&&(e[`--sdm-bg`]=t.bg),t.fg&&(e[`--sdm-fg`]=t.fg),t.rootStyle&&Object.assign(e,u(t.rootStyle)),e},[t.bg,t.fg,t.rootStyle]);return(0,c.jsx)(`pre`,{className:r(i,`p-4 text-sm`,`bg-[var(--sdm-bg,transparent)]`,`dark:bg-[var(--shiki-dark-bg,var(--sdm-bg,transparent))]`),"data-language":n,"data-streamdown":`code-block-body`,style:o,...a,children:(0,c.jsx)(`code`,{className:`[counter-increment:line_0] [counter-reset:line]`,children:t.tokens.map((e,t)=>(0,c.jsx)(`span`,{className:l,children:e.map((e,t)=>(0,c.jsx)(`span`,{className:r(`text-[var(--sdm-c,inherit)]`,`dark:text-[var(--shiki-dark,var(--sdm-c,inherit))]`,e.bgColor&&`bg-[var(--sdm-tbg)]`,e.bgColor&&`dark:bg-[var(--shiki-dark-bg,var(--sdm-tbg))]`),style:{...e.color?{"--sdm-c":e.color}:{},...e.bgColor?{"--sdm-tbg":e.bgColor}:{},...e.htmlStyle},...e.htmlAttrs,children:e.content},t))},t))})})},(e,t)=>e.result===t.result&&e.language===t.language&&e.className===t.className),f=({className:e,language:t,style:n,...i})=>(0,c.jsx)(`div`,{className:r(`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`,...n},...i}),p=({language:e,children:t})=>(0,c.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:[(0,c.jsx)(`span`,{className:`ml-1 font-mono lowercase`,children:e}),(0,c.jsx)(`div`,{className:`flex items-center gap-2`,children:t})]}),m=/\n+$/,h=({code:e,language:t,className:n,children:r,...l})=>{let{shikiTheme:u}=(0,s.useContext)(i),h=a(),g=(0,s.useMemo)(()=>e.replace(m,``),[e]),_=(0,s.useMemo)(()=>({bg:`transparent`,fg:`inherit`,tokens:g.split(`
`).map(e=>[{content:e,color:`inherit`,bgColor:`transparent`,htmlStyle:{},offset:0}])}),[g]),[v,y]=(0,s.useState)(_);return(0,s.useEffect)(()=>{if(!h){y(_);return}let e=h.highlight({code:g,language:t,themes:u},e=>{y(e)});if(e){y(e);return}y(_)},[g,t,u,h,_]),(0,c.jsx)(o.Provider,{value:{code:e},children:(0,c.jsxs)(f,{language:t,children:[(0,c.jsx)(p,{language:t,children:r}),(0,c.jsx)(d,{className:n,language:t,result:v,...l})]})})};export{h as CodeBlock};