unifiedEmojiService Service
File: src/services/unifiedEmojiService.ts
Overview
Exports
- for - type export
- EmojiLookups - interface export
- EmojiEntry - interface export
- EmojiCategory - interface export
- EmojiData - interface export
- ResolvedEmoji - interface export
- useUnifiedEmoji - function export
Functions
loadEmojiData()
No description available.
Parameters: None
Returns: Promise<void>
/**
* Unified Emoji Service
*
* A professional, DRY emoji system that:
* - Stores reactions as standard unicode (portable across packs)
* - Renders emojis based on user's selected pack (twemoji, mutant, or native)
* - Provides lookup between shortcode ↔ unicode ↔ codepoint
* - Works seamlessly when switching emoji packs
*
* Data source: unicode-emoji-data.json (single source of truth)
*/
import { ref, computed } from 'vue'
import { debug } from '@/utils/debug'
import {
TWEMOJI_BASE_URL,
MUTANT_BASE_URL,
DEFAULT_EMOJI_PACK,
EMOJI_CATEGORIES,
type EmojiPack
} from '@/utils/emojiConstants'
import {
getCachedStaticEmojiData,
setCachedStaticEmojiData,
} from '@/services/emojiIndexedDBCache'
// Re-export type for convenience
export type { EmojiPack } from '@/utils/emojiConstants'
// Types
export interface EmojiLookups {
shortcodeToUnicode: Record<string, string>
unicodeToShortcode: Record<string, string>
unicodeToCodepoint: Record<string, string>
// Legacy support for mutant pack
shortcodeToSvg?: Record<string, string>
svgBasePath?: string
}
export interface EmojiEntry {
unicode: string
shortcode: string
name: string
category: string
codepoint: string
keywords: string[]
skinToneSupport?: boolean
// Legacy mutant fields
svgPath?: string
description?: string
subcategory?: string
codepoints?: number[]
}
export interface EmojiCategory {
id: string
name: string
icon: string
order: number
count: number
}
export interface EmojiData {
version: string
source?: string
pack?: string
totalCount: number
categories: EmojiCategory[]
emojis: EmojiEntry[]
lookups: EmojiLookups
}
// State
const PACK_STORAGE_KEY = 'harmony-emoji-pack'
const currentPack = ref<EmojiPack>(DEFAULT_EMOJI_PACK)
const emojiData = ref<EmojiData | null>(null)
const lookups = ref<EmojiLookups | null>(null)
const isLoaded = ref(false)
const isLoading = ref(false)
// Cache for mutant lookups (loaded separately when needed)
const mutantLookups = ref<EmojiLookups | null>(null)
// Twemoji file map for accurate SVG path resolution
const twemojiFileMap = ref<Record<string, boolean> | null>(null)
// Cache version — bump this when the static JSON files change to bust the IndexedDB cache
const EMOJI_DATA_CACHE_VERSION = '1'
/**
* Load the unified emoji data.
* Tries IndexedDB first for instant hydration, then falls back to network fetch.
*/
async function loadEmojiData(): Promise<void>loadMutantLookups()
No description available.
Parameters: None
Returns: Promise<void>
/**
* Load mutant-specific lookups (for shortcode to SVG path mapping)
*/
async function loadMutantLookups(): Promise<void>loadPackPreference()
No description available.
Parameters: None
Returns: void
/**
* Load user's emoji pack preference
*/
function loadPackPreference(): voidsavePackPreference()
No description available.
Parameters: None
Returns: void
/**
* Save user's emoji pack preference
*/
function savePackPreference(): voidsetEmojiPack(pack: EmojiPack)
No description available.
Parameters:
pack: EmojiPack
Returns: void
/**
* Set the current emoji pack
*/
function setEmojiPack(pack: EmojiPack): voidshortcodeToUnicode(shortcode: string)
No description available.
Parameters:
shortcode: string
Returns: string | null
/**
* Convert shortcode to unicode emoji
* e.g., "grinning_face" → "😀"
* Case insensitive lookup
*/
function shortcodeToUnicode(shortcode: string): string | nullunicodeToShortcode(unicode: string)
No description available.
Parameters:
unicode: string
Returns: string | null
/**
* Convert unicode emoji to shortcode
* e.g., "😀" → "grinning_face"
*/
function unicodeToShortcode(unicode: string): string | nullunicodeToCodepoint(unicode: string)
No description available.
Parameters:
unicode: string
Returns: string | null
/**
* Convert unicode emoji to hex codepoint
* e.g., "😀" → "1f600"
*/
function unicodeToCodepoint(unicode: string): string | nullshortcodeToCodepoint(shortcode: string)
No description available.
Parameters:
shortcode: string
Returns: string | null
/**
* Get emoji codepoint from shortcode
*/
function shortcodeToCodepoint(shortcode: string): string | nullfindTwemojiFile(codepoint: string)
No description available.
Parameters:
codepoint: string
Returns: string | null
/**
* Find a Twemoji file by trying different fe0f variations
* Returns the actual filename if found, or null
*/
function findTwemojiFile(codepoint: string): string | nullgetTwemojiUrl(unicode: string)
No description available.
Parameters:
unicode: string
Returns: string | null
/**
* Get Twemoji SVG URL from unicode emoji
* Uses file map for accurate resolution, with fallback to heuristic normalization
*/
function getTwemojiUrl(unicode: string): string | nullunicodeToCodepointDirect(unicode: string)
No description available.
Parameters:
unicode: string
Returns: string | null
/**
* Convert unicode directly to codepoint (without lookup)
* Used as fallback when lookups aren't loaded
*/
function unicodeToCodepointDirect(unicode: string): string | nullgetMutantSvgUrl(shortcode: string)
No description available.
Parameters:
shortcode: string
Returns: string | null
/**
* Get Mutant SVG URL from shortcode
* Legacy support for mutant pack
*/
function getMutantSvgUrl(shortcode: string): string | nullshortcodeToSvgPath(shortcode: string)
No description available.
Parameters:
shortcode: string
Returns: string | null
/**
* Get SVG path for a shortcode (legacy compatibility)
*/
function shortcodeToSvgPath(shortcode: string): string | nullgetSvgUrl(shortcode: string)
No description available.
Parameters:
shortcode: string
Returns: string | null
/**
* Get full SVG URL for a shortcode (legacy compatibility)
*/
function getSvgUrl(shortcode: string): string | nullunicodeToSvgUrl(unicode: string)
No description available.
Parameters:
unicode: string
Returns: string | null
/**
* Get SVG URL from unicode emoji
*/
function unicodeToSvgUrl(unicode: string): string | nullresolveEmoji(input: string)
No description available.
Parameters:
input: string
Returns: ResolvedEmoji
/**
* Resolve an emoji for display based on current pack
* Input can be: unicode emoji, shortcode, or legacy "mutant:path" format
*/
/**
* Resolve emoji from input (unicode, shortcode, or name)
* LAZY: Triggers background load if not already loaded (non-blocking)
*/
function resolveEmoji(input: string): ResolvedEmojinormalizeToUnicode(input: string)
No description available.
Parameters:
input: string
Returns: string
/**
* Normalize emoji input to unicode for storage
* This ensures reactions are stored as standard unicode
*/
function normalizeToUnicode(input: string): stringsearchEmojis(query: string, limit: number = 50)
No description available.
Parameters:
query: stringlimit: number = 50
Returns: EmojiEntry[]
/**
* Search emojis by query
* LAZY: Triggers background load if not already loaded
*/
function searchEmojis(query: string, limit: number = 50): EmojiEntry[]getEmojisByCategory(categoryId: string)
No description available.
Parameters:
categoryId: string
Returns: EmojiEntry[]
/**
* Get emojis by category
*/
function getEmojisByCategory(categoryId: string): EmojiEntry[]getCategories()
No description available.
Parameters: None
Returns: EmojiCategory[]
/**
* Get all categories (sorted by order)
*/
function getCategories(): EmojiCategory[]getAllEmojis()
No description available.
Parameters: None
Returns: EmojiEntry[]
/**
* Get all emojis
*/
function getAllEmojis(): EmojiEntry[]useUnifiedEmoji()
No description available.
Parameters: None
Returns: void
/**
* Unified emoji composable
* LAZY: Only loads emoji data when actually needed (emoji picker, search, etc.)
*/
export function useUnifiedEmoji()Interfaces
EmojiLookups
No description available.
interface EmojiLookups {
shortcodeToUnicode: Record<string, string>
unicodeToShortcode: Record<string, string>
unicodeToCodepoint: Record<string, string>
// Legacy support for mutant pack
shortcodeToSvg?: Record<string, string>
svgBasePath?: string
}EmojiEntry
No description available.
interface EmojiEntry {
unicode: string
shortcode: string
name: string
category: string
codepoint: string
keywords: string[]
skinToneSupport?: boolean
// Legacy mutant fields
svgPath?: string
description?: string
subcategory?: string
codepoints?: number[]
}EmojiCategory
No description available.
interface EmojiCategory {
id: string
name: string
icon: string
order: number
count: number
}EmojiData
No description available.
interface EmojiData {
version: string
source?: string
pack?: string
totalCount: number
categories: EmojiCategory[]
emojis: EmojiEntry[]
lookups: EmojiLookups
}ResolvedEmoji
No description available.
interface ResolvedEmoji {
unicode: string // The actual unicode character (always stored)
shortcode: string | null // Shortcode if known
display: {
type: 'native' | 'svg'
content: string // Unicode char for native, URL for svg
}
}Constants
PACK_STORAGE_KEY
No description available.
const PACK_STORAGE_KEY = 'harmony-emoji-pack'EMOJI_DATA_CACHE_VERSION
No description available.
const EMOJI_DATA_CACHE_VERSION = '1'Source Code Insights
File Size: 22241 characters Lines of Code: 795 Imports: 4
Usage Example
import { for, EmojiLookups, EmojiEntry, EmojiCategory, EmojiData, ResolvedEmoji, useUnifiedEmoji } from '@/services/unifiedEmojiService'
// Example usage
loadEmojiData()This documentation was automatically generated from the source code.
