"use client"; import { forwardRef, useMemo, type HTMLAttributes, type ReactNode } from "react"; import { cn } from "@/lib/utils"; import { highlightMarkdownLines } from "@/lib/wiki/editorHighlight"; interface WikiEditorHighlightLayerProps extends HTMLAttributes { readonly body: string; } /** * Colored text layer rendered underneath the editor textarea (which uses * transparent text). Sizing must mirror the textarea exactly: same padding, * font, and a transparent border so text starts at the same 1px + padding * offset inside the shared wrapper's border. */ export const WikiEditorHighlightLayer = forwardRef< HTMLDivElement, WikiEditorHighlightLayerProps >(function WikiEditorHighlightLayer({ body, className, ...rest }, ref) { const lines = useMemo(() => highlightMarkdownLines(body), [body]); const nodes: ReactNode[] = []; lines.forEach((segments, lineIndex) => { if (lineIndex > 0) nodes.push("\n"); segments.forEach((segment, segmentIndex) => { if (segment.className) { nodes.push( {segment.text} , ); } else { nodes.push(segment.text); } }); }); return ( ); });