import { useState } from 'react'; export default function CopyCodeButton({ code }) { const [isCopied, setIsCopied] = useState(false); const handleCopyCode = async () => { try { // Replace local font with web-hosted OpenType font and adjust text positioning const modifiedCode = code .replace( /loadFont\(['"](?:\/)?fonts\/GoogleSans-Bold\.ttf['"]\)/, "loadFont('https://cdn.jsdelivr.net/npm/@fontsource/roboto@5.0.8/files/roboto-latin-700-normal.woff')" ) .replace( /points = font\.textToPoints\(word, width\/2 - textW\/2, height\/2 \+ fontSize\/3, fontSize,/, "points = font.textToPoints(word, (width + textW) / 3.5, (height - fontSize) / 1.75, fontSize," ); await navigator.clipboard.writeText(modifiedCode); setIsCopied(true); setTimeout(() => setIsCopied(false), 2000); } catch (err) { console.error('Failed to copy code:', err); } }; return ( ); }