"use client"; import { BundledLanguage, codeToTokens, createHighlighter } from "shiki"; import { motion, AnimatePresence } from "framer-motion"; import { useEffect, useState } from "react"; import mist from "../../public/mist.tmLanguage.json"; interface Props { code: string; } const highlighterPromise = createHighlighter({ themes: ["github-dark"], langs: [mist], }); export default function MorphCode({ code }: Props) { const [lines, setLines] = useState([]); useEffect(() => { async function run() { const highlighter = await highlighterPromise; const result = highlighter.codeToTokens(code, { lang: "mist" as any, theme: "github-dark", }); const rawLines = code.split("\n"); const fixed = rawLines.map((_, i) => { return ( result.tokens[i] ?? [ { content: "\n", color: undefined, }, ] ); }); setLines(fixed); } run(); }, [code]); return (
      
        
          {lines.map((line, lineIndex) => (
            
{line.map((token, tokenIndex) => ( {token.content} ))}
))}
); }