/**
* Chat emotes and reaction glyphs, hand-drawn as inline SVG so they look
* the same on every platform (no emoji fonts). Emote codes are typed as
* words, Twitch-style: "SealIt", "o7", "HeliSpin".
*/
import { esc } from './dom.js';
const S = (body, vb = '0 0 32 32') =>
``;
/** Reaction glyphs (the heart stream). Filled, with a soft highlight. */
export const REACT = {
heart: {
label: 'Heart',
color: '#ff5a7a',
svg: S(
``,
),
},
fire: {
label: 'Fire',
color: '#ff8a3d',
svg: S(
``,
),
},
eyes: {
label: 'Eyes',
color: '#a3d8ff',
svg: S(
``,
),
},
wow: {
label: 'Wow',
color: '#ffd166',
svg: S(
``,
),
},
};
export const REACT_KINDS = ['heart', 'fire', 'eyes', 'wow'];
/** Chat emotes. */
export const EMOTES = {
SealIt: {
hint: 'Seal it or it didn’t happen',
svg: S(
``,
),
},
o7: {
hint: 'Salute',
svg: S(
``,
),
},
EyesUp: {
hint: 'Look up',
svg: S(
``,
),
},
HeliSpin: {
hint: 'Helicopter circling',
svg: S(
``,
),
},
Receipts: {
hint: 'Show the receipts',
svg: S(
``,
),
},
Doubt: {
hint: 'Doubt',
svg: S(
``,
),
},
StormMode: {
hint: 'Storm mode',
svg: S(
``,
),
},
LiftOff: {
hint: 'Launch',
svg: S(
``,
),
},
};
export const EMOTE_CODES = Object.keys(EMOTES);
export const reactSvg = (kind) => (REACT[kind] || REACT.heart).svg;
/**
* Chat line → HTML: escapes text, turns emote codes into glyphs and
* @mentions into highlighted handles.
* @param {string} text
* @param {{ me?: string }} o
*/
export function richText(text, { me = '' } = {}) {
const parts = String(text || '').split(/(\s+)/);
let mentionsMe = false;
const html = parts
.map((w) => {
if (/^\s+$/.test(w)) return w;
const bare = w.replace(/[.,!?]+$/, '');
const tail = w.slice(bare.length);
if (EMOTES[bare])
return `${EMOTES[bare].svg}${esc(tail)}`;
if (/^@[\w.-]{2,}$/.test(bare)) {
const mine =
me && bare.toLowerCase() === String(me).toLowerCase().trim();
if (mine) mentionsMe = true;
return `${esc(bare)}${esc(tail)}`;
}
return esc(w);
})
.join('');
return { html, mentionsMe };
}