TakumiTakumi

Helpers / Emoji

Replace emoji glyphs in a node tree with provider-hosted SVG images.

takumi-js/helpers/emoji solves the "emoji renders as a black square" problem without bundling a color emoji font. It walks a node tree, splits each emoji grapheme out of text runs, and swaps in an <img> pointing at one of six providers' CDN-hosted SVG.

render() already calls this for you via the emoji option. Import extractEmojis directly only when you want to control the output tree — say, to swap providers per locale or to inspect what got extracted.

Functions

extractEmojis

import {  } from "takumi-js/helpers/emoji";

const  = { : "text" as , : "Hello 👋 from Takumi 🎨" };
const  = (, "twemoji");

Returns a new node tree. Text nodes containing emoji are replaced with containers holding alternating text and image children; non-emoji text is preserved verbatim. Image nodes get style: { display: "inline-block", width: "1em", height: "1em", margin: "0 0.05em 0 0.1em", verticalAlign: "-0.1em" } so they line up with surrounding text.

Detection uses \p{Extended_Pictographic}, regional-indicator pairs, and keycap sequences. Multi-codepoint emoji (ZWJ sequences like 👨‍👩‍👧) are resolved through Intl.Segmenter when available.

Types

EmojiType

type EmojiType = "twemoji" | "blobmoji" | "noto" | "openmoji" | "fluent" | "fluentFlat";
ProviderSourceLook
twemojijdecked/twemoji 17.0.2 (X / Discord style)Default. Flat, vector-clean.
notogooglefonts/noto-emoji (Android)Soft, rounded.
openmojihfg-gmuend/openmojiGeometric, branding-friendly.
blobmojiC1710/blobmojiOld Android blob style.
fluentmicrosoft/fluentui-emoji colorPolished, gradient-heavy.
fluentFlatmicrosoft/fluentui-emoji flatSame shapes, flat fills.

All providers serve .svg from jsDelivr. See the Emoji guide for side-by-side renders.

Edit on GitHub

Last updated on

On this page