import { recipe } from '../runtime'; import { designTokens as t } from '../tokens'; export const codeBlock = recipe({ name: 'code-block', slots: [ 'root', 'rootDefault', 'rootInline', 'rootDiff', 'rootTerminal', 'header', 'headerTerminal', 'title', 'filename', 'language', 'languageTerminal', 'actions', 'copyButton', 'copyButtonIdle', 'copyButtonCopied', 'copyButtonError', 'feedback', 'feedbackInline', 'feedbackToast', 'feedbackSuccess', 'feedbackError', 'body', 'bodyTerminal', 'bodyScrollable', 'pre', 'preTerminal', 'preWrap', 'preScrollX', 'code', 'lines', 'line', 'lineNumber', 'lineContent', 'lineHighlighted', 'lineAdded', 'lineDeleted', ] as const, styles: { base: { root: { border: `${t.borderWidth.default} solid ${t.color.border.default}`, borderRadius: t.radius.lg, backgroundColor: t.codeBlock.background, overflow: 'hidden', boxShadow: t.shadow.lg, }, rootDefault: {}, rootInline: { display: 'inline-flex', alignItems: 'center', gap: t.space[1], borderRadius: t.radius.md, border: `${t.borderWidth.default} solid ${t.color.border.default}`, padding: '2px 8px', backgroundColor: t.codeBlock.backgroundInline, }, rootDiff: { borderColor: t.color.border.strong, }, rootTerminal: { backgroundColor: t.color.text.primary, borderColor: t.color.text.primary, }, header: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: t.space[2], paddingBlock: t.space[1], paddingInline: t.space[3], borderBottom: `${t.borderWidth.default} solid ${t.color.border.default}`, backgroundColor: t.codeBlock.backgroundHeader, }, headerTerminal: { borderBottomColor: t.color.border.strong, backgroundColor: t.codeBlock.backgroundHeader, }, title: { display: 'flex', alignItems: 'center', gap: t.space[2], minWidth: 0, }, filename: { fontSize: t.fontSize.sm, fontWeight: t.fontWeight.medium, color: t.color.text.primary, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', }, language: { fontSize: t.fontSize.xs, fontWeight: t.fontWeight.bold, fontFamily: t.fontFamily.mono, textTransform: 'uppercase', letterSpacing: '0.06em', color: t.color.text.secondary, whiteSpace: 'nowrap', }, languageTerminal: { color: t.color.text.onAccent, borderColor: 'rgb(255 255 255 / 0.2)', }, actions: { display: 'inline-flex', alignItems: 'center', gap: t.space[1], flexShrink: 0, }, copyButton: { appearance: 'none', border: 'none', backgroundColor: 'transparent', color: t.color.text.secondary, borderRadius: t.radius.sm, paddingBlock: t.space[1], paddingInline: t.space[2], fontFamily: t.fontFamily.mono, fontSize: t.fontSize.xs, fontWeight: t.fontWeight.semibold, letterSpacing: '0.08em', textTransform: 'uppercase', cursor: 'pointer', transition: t.transition.colorShift, '&:hover': { color: t.color.text.primary, backgroundColor: t.color.background.subtle, }, '&:focus-visible': { outline: `${t.borderWidth.thin} solid ${t.color.border.focus}`, outlineOffset: '2px', }, '&[data-copied]': { color: t.color.success.default, }, '&[data-error]': { color: t.color.danger.default, }, }, copyButtonIdle: {}, copyButtonCopied: { color: t.color.success.default, }, copyButtonError: { color: t.color.danger.default, }, feedback: { fontSize: t.fontSize.sm, color: t.color.text.secondary, minHeight: '1lh', }, feedbackInline: { display: 'inline-flex', alignItems: 'center', marginInlineStart: t.space[1], }, feedbackToast: { position: 'absolute', right: t.space[3], top: t.space[3], zIndex: 1, border: `${t.borderWidth.default} solid ${t.color.border.default}`, backgroundColor: t.codeBlock.background, borderRadius: t.radius.md, padding: `2px ${t.space[2]}`, boxShadow: t.shadow.sm, }, feedbackSuccess: { color: t.color.success.default, }, feedbackError: { color: t.color.danger.default, }, body: { padding: 0, backgroundColor: t.codeBlock.background, }, bodyTerminal: { color: t.color.text.onAccent, }, bodyScrollable: { overflowX: 'auto', }, pre: { margin: 0, padding: t.space[4], fontFamily: t.fontFamily.mono, fontSize: t.fontSize.sm, lineHeight: 1.6, overflow: 'auto', backgroundColor: 'transparent', border: 'none', borderRadius: 0, }, preTerminal: { color: t.color.text.onAccent, }, preWrap: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', overflowX: 'visible', }, preScrollX: { whiteSpace: 'pre', overflowX: 'auto', }, code: { display: 'block', }, lines: { display: 'grid', gap: '2px', }, line: { display: 'grid', gridTemplateColumns: 'auto 1fr', alignItems: 'start', columnGap: t.space[3], borderRadius: t.radius.sm, paddingInline: t.space[2], }, lineNumber: { minWidth: '2ch', textAlign: 'right', fontSize: t.fontSize.sm, color: t.color.text.secondary, opacity: 0.8, userSelect: 'none', }, lineContent: { minWidth: 0, }, lineHighlighted: { backgroundColor: t.codeBlock.backgroundLineHighlight, }, lineAdded: { backgroundColor: 'rgb(16 185 129 / 0.12)', }, lineDeleted: { backgroundColor: 'rgb(248 113 113 / 0.12)', }, }, }, });