0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Replace :shortcode: text with Unicode emoji in containers, accessible-name attributes and live in inputs. Without JavaScript, shortcodes stay as readable text.
Overview
data-emoji turns :shortcode: tokens into Unicode emoji. On a container it rewrites text nodes (no wrapping elements, no innerHTML) and the alt, title and aria-label attributes inside it. On an <input> or <textarea> it replaces each token as the user finishes typing it.
Without JavaScript, :wave: stays as readable text.
Usage
Container, observe mode and inputs
1234567891011
<articledata-emoji><h2>Release notes :tada:</h2><p>We shipped :rocket: the new feature. Thanks :heart: to all contributors.</p></article><sectiondata-emojidata-emoji-scan="observe"><!-- content added later is replaced too --></section><labelfor="msg">Message</label><textareaid="msg"data-emojirows="3"></textarea>
What the script does:
Finds [data-emoji] elements on load, when they are inserted, and when the attribute is added to an existing element. Removing the attribute stops observe mode and live input replacement; text already replaced stays.
On a container, walks its text nodes and replaces every token whose opening colon is not glued to a letter, digit or underscore, so 10:30:45, 16:9 and a:b:c are never touched. Adjacent codes such as :fire::rocket: both convert.
Skips text inside <code>, <pre>, <kbd>, <samp>, <var>, <script>, <style>, <textarea>, <code-block>, contenteditable regions and [data-emoji-skip], at any depth (syntax-highlighted <pre><code><span> is safe). Only elements between the text and the container count: a container that is itself inside <code> has opted in on purpose.
Converts alt, title and aria-label on the container and its descendants, with the same skip rules.
Tracks enhanced elements in memory, not in an attribute, so a cloned input ("add another row") is enhanced on its own.
Turns replacement on for a container, <input> or <textarea>.
data-emoji-scan
once, observe
once
observe rescans the container 100ms after its text, children or name attributes change.
data-emoji-unknown
keep, strip
keep
What happens to tokens with no emoji. keep leaves them. strip removes the whole token, colons and name, but only when the name contains a letter: :30: is kept. The spaces around a removed token stay, so and :nope: world becomes and world. Containers only; inputs always keep unknown tokens.
data-emoji-skip
boolean
—
On a descendant: leave its text and attributes alone.
Shortcodes
The core set has 209 emoji in 9 groups (Smileys, People, Animals & Nature, Food & Drink, Travel & Places, Activities, Objects, Symbols, Flags), reachable through 252 shortcodes: one canonical code each plus 43 aliases (for example :heart: for :red_heart:, :+1: for :thumbsup:). Browse them in <emoji-picker>, which shares the dataset.
Extended set
Load the extended file to add about 1,700 more shortcodes (the full gemoji GitHub/Slack set, roughly 1,640 more emoji). Load order does not matter; containers already scanned are rescanned when it arrives, and it reaches <emoji-picker> too.
Inside vanilla-breeze.js, vanilla-breeze-extras.js and the autoload bundle (loaded when a [data-emoji] element first appears). Not in vanilla-breeze-core.js.
Extended (opt-in)
about 1,700 more
about 23 KB
Separate script or import
Events
No events of its own. In a focused field the replacement is an editing command, so it fires a normal input event and other listeners (data-count, autosave) see the emoji; the setRangeText() fallback fires none. Setting value from script is not processed until an input event; dispatch one to replace every token in the new value.
Nothing to style: the result is plain text in the page's font. Emoji glyphs come from the system emoji font, so they look different on each platform.
Accessibility
Emoji are read by name. Screen readers announce the Unicode (CLDR) name, which may not match the shortcode: :heart: is read "red heart", :+1: "thumbs up". A row of emoji is read as a row of names, so keep them few and never use one as the only carrier of meaning ("Status: ✅" should also say "done").
Names match the text. Shortcodes in alt, title and aria-label are converted, so the accessible name says the same as the visible text.
Undo works. While the field has focus, a typed replacement uses document.execCommand('insertText'), which keeps it on the undo stack: Ctrl+Z (⌘+Z) brings the shortcode back. Typing replaces only the token whose closing colon was just typed, so the restored shortcode is not replaced again by the next keystroke (pasted text is replaced throughout). Where that command is unavailable it falls back to setRangeText(), which browsers do not record for undo. Fields without a text selection (type="email", number) are rewritten directly.
Caret and IME. The caret stays where it was relative to the text. Replacement waits while an IME composition is active.
Code is left alone. Literal shortcodes in <code>, <kbd> and friends stay readable as written.
Examples
What is and is not replaced
Times, skip tags, strip mode and title
12345678
<articledata-emojidata-emoji-unknown="strip"><h1>Stand-up notes :memo:</h1><p>Call at 10:30:45, ratio 16:9 :rocket: (times and ratios are never touched).</p><p>Unknown :not_a_real_code: tokens are removed in strip mode; :30: is not shortcode-shaped, so it stays.</p><p>Run <kbd>:wq</kbd> then <code>git commit -m ":tada: release"</code>; code and keys are skipped.</p><pdata-emoji-skip>This paragraph opted out with data-emoji-skip: :wave:</p><p><abbrtitle="Thumbs up :+1:">TU</abbr> has its title converted too.</p></article>