DEV Community

ludy.dev
ludy.dev

Posted on • Originally published at cursivetool.com

Building a zero-dependency Unicode text engine in the browser (and why clipboard APIs are still a pain)

This works perfectly for sequential blocks. However, Unicode has some historical quirks (like the cursive "g" or "h" sometimes pointing to different ranges in the Letterlike Symbols block), which required custom fallback exceptions.

The Glitch (Zalgo) Generator and Diacritics

For the glitch and strikethrough generators, I had to work with Combining Diacritical Marks. These are characters designed to be rendered on top of, below, or through the preceding character.

For the strikethrough tool, it's as simple as appending \u0336 after every character. For the glitch tool, I wrote a randomizer that stacks up to 15 different random combining marks (like \u030d or \u0311) on top of a single base letter. This forces the browser to render symbols that physically overflow the CSS line-height boundaries.

The iOS Clipboard Struggle

Since the main user interaction is "one-click copy," I needed clipboard copying to be bulletproof. Modern browsers support navigator.clipboard.writeText(), but iOS Safari is notoriously strict. If the copy action isn't directly inside a synchronous user-initiated call stack, iOS blocks it.

To solve this, I built a reliable fallback:

async function copyToClipboard(text) {
  try {
    await navigator.clipboard.writeText(text);
  } catch (err) {
    const textArea = document.createElement("textarea");
    textArea.value = text;
    textArea.style.position = "fixed"; 
    document.body.appendChild(textArea);
    textArea.focus();
    textArea.select();
    document.execCommand('copy');
    document.body.removeChild(textArea);
  }
}
Enter fullscreen mode Exit fullscreen mode

Keeping it Ultra-Light

By sticking to vanilla JS, avoiding modern UI frameworks (no React, no Vue), and optimizing our SVG icons, the entire site footprint is under 30KB.

You can test the live tool out at cursivetool.com.

I would love to hear your thoughts on how you handle text manipulation and clipboard compatibility in your own utility projects!

Top comments (0)