File
Blob: src/client/lib/emoji/index.ts
| 1 | import type * as AssetLookup from "./asset-lookup"; |
| 2 | |
| 3 | export { buildEmojiAssetUrl, normalizeEmoji } from "@/shared/emoji/shared"; |
| 4 | |
| 5 | let assetLookup: typeof AssetLookup | null = null; |
| 6 | let assetLookupPromise: Promise<typeof AssetLookup> | null = null; |
| 7 | |
| 8 | // Synchronous fast-path: returns null until the asset map has been loaded at least once. |
| 9 | // Callers should treat null as "not resolved yet" and fall back to a unicode glyph. |
| 10 | export function getEmojiAssetUrlSync(emoji: string): string | null { |
| 11 | return assetLookup ? assetLookup.getEmojiAssetUrl(emoji) : null; |
| 12 | } |
| 13 | |
| 14 | // Lazy loader: dynamically imports the ~54KB emoji → asset-path map on first call, |
| 15 | // then resolves synchronously from the cached module on subsequent calls. |
| 16 | export async function loadEmojiAssetUrl(emoji: string): Promise<string | null> { |
| 17 | if (assetLookup) return assetLookup.getEmojiAssetUrl(emoji); |
| 18 | if (!assetLookupPromise) { |
| 19 | assetLookupPromise = import("./asset-lookup").then((mod) => { |
| 20 | assetLookup = mod; |
| 21 | return mod; |
| 22 | }); |
| 23 | } |
| 24 | const mod = await assetLookupPromise; |
| 25 | return mod.getEmojiAssetUrl(emoji); |
| 26 | } |