{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "emoji",
  "title": "Emoji",
  "description": "One emoji from an image catalogue, drawn as an `<img>` the size of the text around it, named by its `alt` (the emoji's name).",
  "registryDependencies": [
    "@ouro/lib-class-name-check",
    "@ouro/lib-cn",
    "@ouro/lib-dev",
    "@ouro/lib-env",
    "@ouro/lib-refs",
    "@ouro/lib-use-dev-messages",
    "@ouro/lib-use-reduced-motion"
  ],
  "files": [
    {
      "path": "registry/ouro/components/ouro/emoji/emoji-styles.ts",
      "content": "import type { EmojiCatalogue, EmojiItem, EmojiItemTone } from \"@/registry/ouro/components/ouro/emoji/emoji\";\nimport { devWarn } from \"@/registry/ouro/lib/ouro/dev\";\n\nexport {\n  catalogueIndex,\n  emojiClass,\n  emojiPictureClass,\n  emojiPictureFadeClass,\n  emojiPlaceholderClass,\n  emojiPlaceholderFadeClass,\n  emojiSkinTones,\n  emojiToken,\n  emojiTextToTokens,\n  fold,\n  matchWords,\n  searchCatalogue,\n  splitEmojiText,\n  toneOf,\n};\nexport type { CatalogueIndex, EmojiSkinTone, EmojiTextPart, FoundEmoji };\n\n// Value lists and helpers for Emoji and the components that draw a catalogue's emoji, apart from\n// the component so its file exports only components (React Fast Refresh). Class strings are\n// literal so the app's Tailwind finds them.\n\n/**\n * A skin tone: the default (no tone) or one of Unicode's five, light to dark.\n *\n * @claim \"one of Unicode's five\" https://www.unicode.org/reports/tr51/#Diversity verify:urlOk(https://www.unicode.org/reports/tr51/#Diversity)\n * @claim \"one of Unicode's five\" registry/ouro/components/ouro/emoji/emoji-styles.ts verify:fileLine(registry/ouro/components/ouro/emoji/emoji-styles.ts, /\\[\"default\", \"light\", \"medium-light\", \"medium\", \"medium-dark\", \"dark\"\\]/)\n */\ntype EmojiSkinTone = \"default\" | \"light\" | \"medium-light\" | \"medium\" | \"medium-dark\" | \"dark\";\n\n/** The skin tones, in the order a picker offers them. @internal */\nconst emojiSkinTones: readonly EmojiSkinTone[] = [\"default\", \"light\", \"medium-light\", \"medium\", \"medium-dark\", \"dark\"];\n\n/**\n * An emoji's image: 1.25em square, so it takes the size of the text around it as a font's\n * emoji does, sitting on the line. It clips what it holds, so a picture that fails to load, which\n * the browser draws as its name in the box, sits on the line where the picture would and moves no\n * line. @internal\n *\n * @claim \"image: 1.25em square, so\" registry/ouro/components/ouro/emoji/emoji-styles.ts verify:fileLine(registry/ouro/components/ouro/emoji/emoji-styles.ts, /\"inline-block size-\\[1\\.25em\\]/)\n * @claim \"sits on the line where the picture would and moves no line\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > keeps every line and every emoji where a loaded picture would, when its picture fails to load)\n */\nconst emojiClass = \"inline-block size-[1.25em] shrink-0 overflow-hidden align-[-0.3em] object-contain select-none\";\n\n/**\n * An emoji's picture over its placeholder: the box of the emoji around it, hidden until the\n * root is marked `data-loaded`. @internal\n */\nconst emojiPictureClass = \"absolute inset-0 size-full object-contain opacity-0 group-data-loaded/emoji:opacity-100\";\n\n/** The picture's fade in over the short duration, once loaded only, left off when motion is reduced (`useReducedMotion`). @internal */\nconst emojiPictureFadeClass =\n  \"group-data-loaded/emoji:transition-opacity group-data-loaded/emoji:duration-(--ouro-duration-fast) group-data-loaded/emoji:ease-(--ouro-ease-out)\";\n\n/** What stands in for the picture: the emoji's box, with an element centred and clipped to it, hidden once the picture is loaded. @internal */\nconst emojiPlaceholderClass =\n  \"pointer-events-none absolute inset-0 grid size-full place-items-center overflow-hidden group-data-loaded/emoji:invisible group-data-loaded/emoji:opacity-0\";\n\n/** The placeholder's fade out with the picture's fade in, left off when motion is reduced. @internal */\nconst emojiPlaceholderFadeClass =\n  \"group-data-loaded/emoji:transition-[opacity,visibility] group-data-loaded/emoji:duration-(--ouro-duration-fast) group-data-loaded/emoji:ease-(--ouro-ease-out)\";\n\n/** The emoji's form in a skin tone: its toned image, or the emoji itself in the default tone or without tones. @internal */\nfunction toneOf(item: EmojiItem, tone: EmojiSkinTone | undefined): EmojiItem | EmojiItemTone {\n  // The default tone, or one that is no tone, is the emoji itself.\n  return item.skinTones?.[emojiSkinTones.indexOf(tone!) - 1] ?? item;\n}\n\n/**\n * The text that stands for an emoji in a message, `:shortcode:`: its first shortcode, or else\n * its id, and in a skin tone its tone's id. `EmojiText` draws it as the image. @internal\n *\n * @claim \"its first shortcode, or else its id\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > draws shortcode, id and tone id tokens as their images, and leaves unknown ones as text)\n */\nfunction emojiToken(item: EmojiItem, tone?: EmojiSkinTone): string {\n  const form = toneOf(item, tone);\n  return `:${form === item ? (item.shortcodes?.[0] ?? item.id) : form.id}:`;\n}\n\n/** An emoji found in a catalogue, and the skin tone its id or text named. */\ninterface FoundEmoji {\n  item: EmojiItem;\n  tone: EmojiSkinTone;\n}\n\n/** Finds an emoji by a key: an id, a token's name or an emoji's text. */\ninterface EmojiLookup {\n  get(key: string): FoundEmoji | undefined;\n  has(key: string): boolean;\n}\n\n/** A catalogue's emoji by id, by token and by text, built once per catalogue. */\ninterface CatalogueIndex {\n  /**\n   * The catalogue's emoji in order, each id once.\n   *\n  \n * @claim \"each id once\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > indexes a catalogue once, each emoji once, by id, tone id, token and text)\n   */\n  items: readonly EmojiItem[];\n  /** An emoji by its id or a tone's id. */\n  byId: EmojiLookup;\n  /** An emoji by what goes between the colons of a token: a shortcode (in lower case), an id or a tone's id. */\n  byToken: EmojiLookup;\n  /** An emoji by its text, without variation selectors. */\n  byText: EmojiLookup;\n  /** Finds a token's colon and name, up to its closing colon, and the emoji text the catalogue lists, longest text first. */\n  pattern: RegExp;\n  /**\n   * Finds only the emoji text the catalogue lists, longest first, and nothing when it lists none.\n   *\n  \n * @claim \"nothing when it lists none\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > splits text into its runs and emoji with no empty runs between or around them)\n   */\n  textPattern: RegExp;\n  /**\n   * The first character of each emoji text the catalogue lists: text with none of them (and no colon) holds no emoji.\n   *\n  \n * @claim \"The first character of each emoji text the catalogue lists: text with none of them (and no colon) holds no emoji.\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > passes text with no colon and no emoji text's first character straight through, and still finds a plain-text emoji)\n   */\n  textStarts: ReadonlySet<string>;\n}\n\nconst indexes = new WeakMap<EmojiCatalogue, CatalogueIndex>();\nconst VARIATION = /\\uFE0F/g;\nconst escape = (text: string) => text.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n\n/** A list of objects, kept with the index it leads to. */\ninterface IndexPath {\n  steps: readonly object[];\n  index?: CatalogueIndex;\n}\n\n/**\n * The lists indexed lately, by their first object, held weakly: at most `PATHS` for each first\n * object, the one indexed longest ago let go first.\n *\n * @claim \"the one indexed longest ago let go first\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > keeps the lists of the 8 catalogues indexed most recently that start with the same emoji)\n */\nconst paths = new WeakMap<object, IndexPath[]>();\nconst PATHS = 8;\n// Stryker disable next-line ObjectLiteral,ArrayDeclaration: the empty list's path is returned for having no first object; nothing reads its steps\nconst noSteps: IndexPath = { steps: [] };\n\n/**\n * Where a sequence of objects leads: the same objects in the same order lead to the same place.\n * One weak lookup, by the first object, then a comparison of the rest: a weak lookup per object\n * would chain one WeakMap per emoji, which a garbage collector that marks WeakMaps a level at a\n * time (WebKit's) walks once per level, in every collection, for as long as the emoji live (a\n * collection held the main thread for hundreds of milliseconds with a few thousand emoji).\n *\n * @claim \"the same objects in the same order lead to the same place\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > shares one index between fresh catalogue objects holding the same emoji)\n * @claim \"One weak lookup, by the first object\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > makes no WeakMap per emoji, however many the catalogue holds)\n */\nfunction pathOf(steps: readonly object[]): IndexPath {\n  const [first] = steps;\n  if (first === undefined) return noSteps;\n  let known = paths.get(first);\n  if (!known) paths.set(first, (known = []));\n  const found = known.find((path) => path.steps.length === steps.length && path.steps.every((step, at) => step === steps[at]));\n  if (found) return found;\n  const path: IndexPath = { steps: [...steps] };\n  known.push(path);\n  if (known.length > PATHS) known.shift();\n  return path;\n}\n\n/**\n * The indexes of catalogues an app named with an `id`, at most `NAMED` of them, the one used\n * longest ago let go first.\n *\n * @claim \"the one used longest ago let go first\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > keeps the ids used most recently, letting go of the one used longest ago)\n */\nconst named = new Map<string, CatalogueIndex>();\nconst NAMED = 16;\n\n/** The builds of the last `REBUILD_SPAN` milliseconds, oldest first: when, and a hash of their emoji's ids. In development only. */\nconst builds: { at: number; emoji: number }[] = [];\nconst REBUILD_SPAN = 1000;\nconst REBUILD_LIMIT = 3;\n\n/** A short hash of text, so a build's record holds a number rather than its emoji's ids. */\nfunction hashOf(text: string): number {\n  let hash = 0x811c9dc5;\n  for (const char of text) hash = Math.imul(hash ^ char.codePointAt(0)!, 0x01000193);\n  return hash;\n}\n\n/**\n * Warns once, in development, when the index of the same emoji is built more than\n * `REBUILD_LIMIT` times within a second, as when an app makes its catalogue's emoji afresh for\n * each message. Catalogues of different emoji, such as a page of examples, never count together.\n *\n * @claim \"the same emoji is built more than `REBUILD_LIMIT` times within a second\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > warns once in development when the same emoji are indexed more than three times within a second)\n * @claim \"Catalogues of different emoji, such as a page of examples, never count together\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > stays quiet for many different catalogues, and for equivalent fresh ones however often an app makes them)\n */\nfunction noteBuild(items: readonly EmojiItem[]): void {\n  const now = Date.now();\n  const emoji = hashOf(items.map((item) => item.id).join());\n  builds.push({ at: now, emoji });\n  // Only the last second's builds are kept, so the record stays as small as the builds in it.\n  while (builds[0]!.at <= now - REBUILD_SPAN) builds.shift();\n  /* istanbul ignore else @preserve -- the else path exists only in production bundles; scripts/dev-strip.test.mjs covers it */\n  if (process.env.NODE_ENV !== \"production\") {\n    if (builds.filter((build) => build.emoji === emoji).length > REBUILD_LIMIT) {\n      devWarn(\n        \"EmojiCatalogue\",\n        `the index of the same emoji was built more than ${REBUILD_LIMIT} times within a second, each time for a catalogue of new emoji objects. Each build maps every emoji, and compiles two patterns of their text when they changed, so drawing a conversation this way can take seconds`,\n        \"build the catalogue once and pass that object every time (useMemo(() => toCatalogue(emoji), [emoji])), or give every copy the same id that changes only when the emoji do: { id: \\\"contoso-2026-11\\\", categories }\",\n      );\n    }\n  }\n}\n\n/**\n * The catalogue's index, built on first use and kept while the catalogue's emoji live. A fresh\n * catalogue object with the same emoji shares it: one with the same `id`, or else one holding\n * the same emoji objects in the same order, found with a lookup per emoji, so an array the app\n * changed in place counts as new. An emoji object edited in place (its shortcodes or text)\n * keeps the index it had, so an app that edits emoji that way passes a new `id` or new emoji\n * objects. A catalogue whose emoji differ only in their pictures (new `src` addresses) shares the\n * patterns that find their text, compiling nothing again, and finds its own pictures. @internal\n *\n * @claim \"A catalogue whose emoji differ only\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > compiles nothing again for a catalogue whose emoji differ only in their pictures' addresses, and finds the new pictures)\n *\n * @claim \"A fresh catalogue object with the same emoji shares it\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > shares one index between fresh catalogue objects holding the same emoji)\n * @claim \"an array the app changed in place counts as new\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > finds an emoji the app pushed into the same array, in a fresh catalogue)\n */\nfunction catalogueIndex(catalogue: EmojiCatalogue): CatalogueIndex {\n  const known = indexes.get(catalogue);\n  if (known) return known;\n  const { id } = catalogue;\n  const index = named.get(id!) ?? (pathOf(catalogue.categories.flatMap((category) => category.items)).index ??= buildCatalogueIndex(catalogue));\n  if (id !== undefined) {\n    // Most recently used last, so the first is the one to let go.\n    named.delete(id);\n    named.set(id, index);\n    if (named.size > NAMED) named.delete(named.keys().next().value!);\n  }\n  indexes.set(catalogue, index);\n  return index;\n}\n\n/**\n * What a catalogue's index holds that depends only on its emoji's ids, texts and shortcodes, not on their pictures: where\n * each id, token and text leads (an emoji's place in the catalogue, times 8, plus its tone's), and the patterns that find\n * the text. Shared by every catalogue whose emoji say the same, so a catalogue that changes only its pictures' addresses\n * (a new `src` for each, as a CDN's signed addresses do) compiles nothing again.\n * @claim \"What a catalogue's index holds that\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > compiles nothing again for a catalogue whose emoji differ only in their pictures' addresses, and finds the new pictures)\n * @claim \"Shared by every catalogue whose emoji\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > compiles nothing again for a catalogue whose emoji differ only in their pictures' addresses, and finds the new pictures)\n */\ninterface IndexShape {\n  byId: ReadonlyMap<string, number>;\n  byToken: ReadonlyMap<string, number>;\n  byText: ReadonlyMap<string, number>;\n  pattern: RegExp;\n  textPattern: RegExp;\n  textStarts: ReadonlySet<string>;\n}\n\n/**\n * The shapes of the catalogues indexed most recently, by what their emoji say, at most `SHAPES` of them.\n * @claim \"The shapes of the catalogues indexed\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > keeps the shapes of the 8 catalogues indexed most recently, and compiles again for one indexed before them)\n */\nconst shapes = new Map<string, IndexShape>();\nconst SHAPES = 8;\n\n/**\n * What a catalogue's emoji say, each id, text and shortcode in order: the same for catalogues whose emoji differ only in their pictures.\n * @claim \"What a catalogue's emoji say, each\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > compiles nothing again for a catalogue whose emoji differ only in their pictures' addresses, and finds the new pictures)\n */\nfunction signatureOf(items: readonly EmojiItem[]): string {\n  // Stryker disable next-line StringLiteral: the signature only has to be the same for the same emoji, whatever it starts with.\n  let signature = \"\";\n  for (const item of items) {\n    signature += `\\u0001${item.id}\\u0002${item.text ?? \"\"}\\u0002${item.shortcodes?.join(\"\\u0003\") ?? \"\"}`;\n    for (const form of item.skinTones ?? []) signature += `\\u0002${form.id}\\u0003${form.text ?? \"\"}`;\n  }\n  return signature;\n}\n\n/**\n * Compiles the shape of a catalogue's emoji: where each id, token and text leads, and the patterns that find their text.\n * @claim \"Compiles the shape of a catalogue's\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > compiles nothing again for a catalogue whose emoji differ only in their pictures' addresses, and finds the new pictures)\n * @claim \"Compiles the shape of a catalogue's\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > indexes a catalogue once, each emoji once, by id, tone id, token and text)\n */\nfunction buildShape(items: readonly EmojiItem[]): IndexShape {\n  const byId = new Map<string, number>();\n  const byToken = new Map<string, number>();\n  const byText = new Map<string, number>();\n  items.forEach((item, at) => {\n    const forms: [{ id: string; text?: string | undefined }, number][] = [[item, 0], ...(item.skinTones ?? []).map((form, tone): [EmojiItemTone, number] => [form, tone + 1])];\n    for (const [form, tone] of forms) {\n      byId.set(form.id, at * 8 + tone);\n      byToken.set(form.id.toLowerCase(), at * 8 + tone);\n      if (form.text) byText.set(form.text.replace(VARIATION, \"\"), at * 8 + tone);\n    }\n  });\n  // Shortcodes win over ids that look the same, so they go in last.\n  items.forEach((item, at) => item.shortcodes?.forEach((shortcode) => byToken.set(shortcode.toLowerCase(), at * 8)));\n  // Longest first, so a sequence wins over the emoji it starts with; a variation selector may follow any character.\n  const texts = [...byText.keys()].sort((a, b) => b.length - a.length).map((text) => Array.from(text, (char) => `${escape(char)}\\\\uFE0F?`).join(\"\"));\n  const pattern = new RegExp([\":[^\\\\s:]+(?=:)\", ...texts].join(\"|\"), \"gu\");\n  // (?!) matches nothing, for a catalogue that lists no text.\n  const textPattern = new RegExp([\"(?!)\", ...texts].join(\"|\"), \"gu\");\n  const textStarts = new Set([...byText.keys()].map((text) => Array.from(text)[0]!));\n  return { byId, byToken, byText, pattern, textPattern, textStarts };\n}\n\n/** A shape's places, as the emoji of the catalogue in hand. */\nfunction lookup(places: ReadonlyMap<string, number>, items: readonly EmojiItem[]): EmojiLookup {\n  return {\n    get: (key) => {\n      const at = places.get(key);\n      return at === undefined ? undefined : { item: items[at >> 3]!, tone: emojiSkinTones[at & 7]! };\n    },\n    has: (key) => places.has(key),\n  };\n}\n\n/**\n * Builds a catalogue's index: its emoji, each id once, with the shape of what they say, compiled only when no catalogue indexed lately said the same.\n * @claim \"Builds a catalogue's index: its emoji\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > keeps the shapes of the 8 catalogues indexed most recently, and compiles again for one indexed before them)\n * @claim \"Builds a catalogue's index: its emoji\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > indexes a catalogue once, each emoji once, by id, tone id, token and text)\n */\nfunction buildCatalogueIndex(catalogue: EmojiCatalogue): CatalogueIndex {\n  const items: EmojiItem[] = [];\n  const seen = new Set<string>();\n  for (const item of catalogue.categories.flatMap((category) => category.items)) {\n    // Stryker disable next-line ConditionalExpression: an emoji listed twice adds nothing the first did not.\n    if (seen.has(item.id)) continue;\n    seen.add(item.id);\n    items.push(item);\n  }\n  /* istanbul ignore else @preserve -- the else path exists only in production bundles; scripts/dev-strip.test.mjs covers it */\n  if (process.env.NODE_ENV !== \"production\") noteBuild(items);\n  const signature = signatureOf(items);\n  const shape = shapes.get(signature) ?? buildShape(items);\n  // Most recently used last, so the first is the one to let go.\n  shapes.delete(signature);\n  shapes.set(signature, shape);\n  if (shapes.size > SHAPES) shapes.delete(shapes.keys().next().value!);\n  return {\n    items,\n    byId: lookup(shape.byId, items),\n    byToken: lookup(shape.byToken, items),\n    byText: lookup(shape.byText, items),\n    pattern: shape.pattern,\n    textPattern: shape.textPattern,\n    textStarts: shape.textStarts,\n  };\n}\n\n/** A run of text, or an emoji found in it with the text it was found as. */\ntype EmojiTextPart = string | (FoundEmoji & { source: string });\n\n/**\n * Splits text into runs of text and the emoji its tokens (`:shortcode:`, `:id:`) and emoji\n * text name in the catalogue, each with the text it was found as. A token the catalogue does not\n * know stays text, and its closing colon can still open the next one. With `tokens` false, only\n * the emoji text counts, for text such as code where `:name:` means something else. @internal\n *\n * @claim \"each with the text it was found as\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > splits text into its runs and emoji with no empty runs between or around them)\n * @claim \"A token the catalogue does not know stays text\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > draws shortcode, id and tone id tokens as their images, and leaves unknown ones as text)\n */\nfunction splitEmojiText(text: string, catalogue: EmojiCatalogue, tokens = true): EmojiTextPart[] {\n  const { byToken, byText, pattern, textPattern, textStarts } = catalogueIndex(catalogue);\n  // Most text holds no emoji: one pass over its characters says so without running the patterns, which list every\n  // emoji text the catalogue knows (thousands of alternatives).\n  if (!Array.from(text).some((char) => (tokens && char === \":\") || textStarts.has(char))) return text ? [text] : [];\n  const parts: EmojiTextPart[] = [];\n  let plainFrom = 0;\n  for (const match of text.matchAll(tokens ? pattern : textPattern)) {\n    // A token's closing colon, already taken, does not open another.\n    if (match.index < plainFrom) continue;\n    const token = match[0].startsWith(\":\");\n    const found = token ? byToken.get(match[0].slice(1).toLowerCase()) : byText.get(match[0].replace(VARIATION, \"\"));\n    if (!found) continue;\n    if (match.index > plainFrom) parts.push(text.slice(plainFrom, match.index));\n    const end = match.index + match[0].length + (token ? 1 : 0);\n    parts.push({ ...found, source: text.slice(match.index, end) });\n    plainFrom = end;\n  }\n  if (plainFrom < text.length) parts.push(text.slice(plainFrom));\n  return parts;\n}\n\n/** Lower case, without accents, so \"Café\" matches \"cafe\". @internal */\nfunction fold(text: string): string {\n  // Stryker disable next-line MethodExpression: both sides of every comparison fold the same way, so upper case matches as lower case does.\n  return text.normalize(\"NFD\").replace(/\\p{M}/gu, \"\").toLowerCase();\n}\n\n/**\n * Whether every word typed starts one of `words`, or a part of one split at spaces, hyphens,\n * underscores and colons, ignoring case and accents. Colons around a typed shortcode are\n * dropped, so `:party` finds `party_popper`. @internal\n *\n * @claim \"Whether every word typed starts\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > matches every typed word to the start of a word, a part of one, or a whole one, ignoring case, accents and colons)\n */\nfunction matchWords(words: readonly string[], query: string): boolean {\n  const whole = words.map(fold);\n  // Runs of separators leave empty words and terms, which match nothing and everything, so they change no result.\n  const parts = whole.flatMap((word) => word.split(/[\\s_:-]/));\n  return fold(query)\n    .split(/\\s/)\n    .map((term) => term.replace(/^:+|:+$/g, \"\"))\n    .every((term) => parts.some((word) => word.startsWith(term)) || whole.some((word) => word.startsWith(term)));\n}\n\n/**\n * The catalogue's emoji whose name, shortcodes or keywords the query starts, those with a\n * shortcode that starts with it first, at most `limit`. @internal\n */\nfunction searchCatalogue(catalogue: EmojiCatalogue, query: string, limit: number): EmojiItem[] {\n  const { items } = catalogueIndex(catalogue);\n  const typed = fold(query);\n  const byShortcode = items.filter((item) => item.shortcodes?.some((shortcode) => fold(shortcode).startsWith(typed)));\n  const rest = items.filter((item) => !byShortcode.includes(item) && matchWords([item.name, ...(item.shortcodes ?? []), ...(item.keywords ?? [])], query));\n  return [...byShortcode, ...rest].slice(0, limit);\n}\n\n/** Splits text into the characters a person sees, an emoji with its tone modifier or its joined parts whole. */\n// Stryker disable next-line ObjectLiteral: grapheme is Intl.Segmenter's default granularity, named here for the reader.\nconst graphemes = new Intl.Segmenter(undefined, { granularity: \"grapheme\" });\n\n/**\n * The text with the emoji the catalogue lists as text turned into their tokens: `:shortcode:`,\n * or a tone's `:id:`. It reads the text a whole character at a time, so an emoji joined from\n * others (a zero width joiner sequence) or one with a skin tone modifier changes only when the\n * catalogue lists it whole. Any other character, and an emoji the catalogue does not list,\n * stays as it is. @internal\n *\n * @claim \"changes only when the catalogue lists it whole\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji helpers > turns each emoji the catalogue lists as text into its token, a whole character at a time)\n */\nfunction emojiTextToTokens(text: string, catalogue: EmojiCatalogue): string {\n  const { byText } = catalogueIndex(catalogue);\n  let tokens = \"\";\n  for (const { segment } of graphemes.segment(text)) {\n    const found = byText.get(segment.replace(VARIATION, \"\"));\n    tokens += found ? emojiToken(found.item, found.tone) : segment;\n  }\n  return tokens;\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/emoji/emoji-styles.ts"
    },
    {
      "path": "registry/ouro/components/ouro/emoji/emoji.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useLayoutEffect, useRef, useState, type HTMLAttributes, type ImgHTMLAttributes, type JSX, type ReactElement, type ReactNode, type Ref } from \"react\";\nimport { useAppearanceClassNameCheck } from \"@/registry/ouro/lib/ouro/class-name-check\";\nimport { cn } from \"@/registry/ouro/lib/ouro/cn\";\nimport { useMergedRef } from \"@/registry/ouro/lib/ouro/refs\";\nimport { useDevWarnings } from \"@/registry/ouro/lib/ouro/use-dev-messages\";\nimport { useReducedMotion } from \"@/registry/ouro/lib/ouro/use-reduced-motion\";\nimport {\n  emojiClass,\n  emojiPictureClass,\n  emojiPictureFadeClass,\n  emojiPlaceholderClass,\n  emojiPlaceholderFadeClass,\n  emojiSkinTones,\n  splitEmojiText,\n  toneOf,\n  type EmojiSkinTone,\n} from \"@/registry/ouro/components/ouro/emoji/emoji-styles\";\n\nexport type { EmojiSkinTone } from \"@/registry/ouro/components/ouro/emoji/emoji-styles\";\n\n/**\n * An animation drawn as a filmstrip: square frames stacked top to bottom in one image, so the\n * frames are the image's height over its width.\n */\nexport interface EmojiFilmstrip {\n  /** The filmstrip image's address. */\n  src: string;\n  /** Frames a second. */\n  fps: number;\n}\n\n/** An emoji's image in one skin tone: `skinTones` on an `EmojiItem`. */\nexport interface EmojiItemTone {\n  /** Identifies the emoji in this tone, unique in the catalogue: `\"thumbs-up-tone3\"`. Reactions and tokens use it. */\n  id: string;\n  /** The still image's address. */\n  src: string;\n  /** Sizes of the still image for sharper screens, as `<img srcset>`: `\"wave-2x.png 2x\"`. */\n  srcSet?: string | undefined;\n  /** An animated image (GIF, animated WebP or PNG), shown while the emoji plays; the still one shows otherwise. */\n  animatedSrc?: string | undefined;\n  /** The animation as a filmstrip of square frames, played while the emoji plays, for a tone without `animatedSrc`. */\n  filmstrip?: EmojiFilmstrip | undefined;\n  /**\n   * The emoji in this tone as text (`\"👍🏽\"`), which `EmojiText` finds in messages; Ouro never draws it as text.\n   *\n   * @claim \"Ouro never draws it as text\" registry/ouro/components/ouro/emoji-picker/emoji-picker.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/emoji-picker/emoji-picker.catalogue.test.tsx::EmojiPicker with a catalogue > draws only the catalogue's images, each named by its emoji's name, with the custom category labelled by the app)\n   */\n  text?: string | undefined;\n}\n\n/**\n * One emoji in an image catalogue: its id, its name and the image that draws it. An app maps\n * its own emoji set to this, whether a standard set or an organization's custom emoji.\n *\n * @example\n * const party: EmojiItem = { id: \"party\", name: \"Party popper\", shortcodes: [\"party\", \"tada\"], keywords: [\"celebrate\"], src: \"/emoji/party.png\", animatedSrc: \"/emoji/party.gif\" };\n */\nexport interface EmojiItem {\n  /** Identifies the emoji, unique in the catalogue: `\"party\"`. Reactions, recents and `:id:` tokens use it. */\n  id: string;\n  /** Its name, which is the image's `alt`, what screen readers hear and what the search matches first: `\"Party popper\"`. */\n  name: string;\n  /**\n   * The still image's address. It shows whenever the emoji is not playing, and always with reduced motion.\n   *\n   * @claim \"always with reduced motion\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > shows the still image with reduced motion, whatever play says or the pointer does)\n   */\n  src: string;\n  /** Sizes of the still image for sharper screens, as `<img srcset>`: `\"party-2x.png 2x\"`. */\n  srcSet?: string | undefined;\n  /**\n   * An animated image (GIF, animated WebP or PNG), which plays while the pointer is on the emoji\n   * or on the button around it, or that button has focus. With reduced motion it never plays.\n   *\n   * @claim \"With reduced motion it never plays\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > shows the still image with reduced motion, whatever play says or the pointer does)\n   */\n  animatedSrc?: string | undefined;\n  /**\n   * The animation as a filmstrip, square frames stacked top to bottom in one image, for an\n   * emoji without `animatedSrc`: while the emoji plays, it steps through the frames at `fps`;\n   * otherwise, and always with reduced motion, `src` shows.\n   *\n   * @claim \"it steps through the frames at `fps`\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > plays a filmstrip by stepping through its frames at its fps while its button is under the mouse, and shows the still image after)\n   * @claim \"always with reduced motion, `src` shows\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > shows the still image with reduced motion, whatever play says or the pointer does)\n   */\n  filmstrip?: EmojiFilmstrip | undefined;\n  /** The still image's width in pixels, given to the `<img>` so the page keeps its shape while it loads. It shows at the text's size. */\n  width?: number | undefined;\n  /** The still image's height in pixels, as `width`. */\n  height?: number | undefined;\n  /** Short names typed between colons, without them: `[\"party\", \"tada\"]`. The first makes the emoji's token, `:party:`. */\n  shortcodes?: readonly string[] | undefined;\n  /** More words the search matches: `[\"celebrate\", \"hooray\"]`. */\n  keywords?: readonly string[] | undefined;\n  /**\n   * The emoji as plain text, such as its Unicode character (`\"🎉\"`), for places an image cannot\n   * go (a copied message, a notification). `EmojiText` finds it in messages and draws the image;\n   * Ouro never draws it as text.\n   *\n   * @claim \"Ouro never draws it as text\" registry/ouro/components/ouro/emoji-picker/emoji-picker.catalogue.test.tsx verify:testExists(registry/ouro/components/ouro/emoji-picker/emoji-picker.catalogue.test.tsx::EmojiPicker with a catalogue > draws only the catalogue's images, each named by its emoji's name, with the custom category labelled by the app)\n   */\n  text?: string | undefined;\n  /** It is the organization's or app's own emoji rather than one of the standard set. Ouro draws it the same; apps can label or treat it apart. */\n  custom?: boolean | undefined;\n  /**\n   * The emoji in Unicode's five skin tones, light to dark; leave it out for an emoji without tones.\n   *\n   * @claim \"Unicode's five skin tones\" https://www.unicode.org/reports/tr51/#Diversity verify:urlOk(https://www.unicode.org/reports/tr51/#Diversity)\n   */\n  skinTones?: readonly EmojiItemTone[] | undefined;\n}\n\n/** A category of a catalogue: its name, the icon its button shows, and its emoji in order. */\nexport interface EmojiCatalogueCategory {\n  /** Identifies the category, unique in the catalogue: `\"people\"`, `\"custom\"`. */\n  id: string;\n  /** Its name, shown as its heading and read for its button: `\"People\"`, or the organization's name for its custom emoji. */\n  label: string;\n  /** What its button in a picker's category bar shows: an icon element. Defaults to its first emoji's image. */\n  icon?: ReactNode;\n  /** Its emoji, in the order they show. */\n  items: readonly EmojiItem[];\n}\n\n/**\n * An image-based emoji set, by category: what `EmojiPicker`, `ReactionBar`, `Autocomplete`\n * and `EmojiText` draw instead of the platform's emoji font when an app passes it. Put an\n * organization's custom emoji in a category of their own, labelled by the app.\n *\n * The image addresses are used as they are, so an app that loads images its own way (a\n * content security policy, a custom scheme, signed or `blob:` URLs) puts the addresses it can\n * load in the catalogue when it builds it.\n *\n * Ouro indexes a catalogue's emoji once, to find them in text. Build the catalogue once and\n * pass that object, or give each copy the same `id`: a catalogue of new emoji objects on every\n * render is indexed again each time, and warns in development. Adding or removing emoji is seen\n * in a new catalogue object, even in the same array; to edit an emoji's shortcodes or text, pass\n * a new emoji object, or a new `id`.\n *\n * @example\n * const catalogue: EmojiCatalogue = { categories: [{ id: \"smileys\", label: \"Smileys\", items: smileys }, { id: \"custom\", label: \"Contoso\", items: custom }] };\n */\nexport interface EmojiCatalogue {\n  /**\n   * Names this set of emoji, for an app that makes a new catalogue object, emoji and all, each\n   * time it draws: catalogues with the same id share one index of their emoji, so change it when\n   * the emoji change (`\"contoso-2026-11\"`), an emoji edited in place included. Without one, a\n   * new catalogue object shares the index when it holds the same emoji objects in the same order,\n   * and a catalogue of new emoji objects builds its own.\n   *\n   * @claim \"catalogues with the same id share one index of their emoji\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > shares one index between catalogues with the same id, and keeps the most recent ids)\n   * @claim \"a new catalogue object shares the index when it holds the same emoji objects\" registry/ouro/components/ouro/emoji/emoji.index.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.index.test.tsx::catalogueIndex > shares one index between fresh catalogue objects holding the same emoji)\n   */\n  id?: string | undefined;\n  /** The categories, in the order they show. An emoji in more than one counts once, by its id. */\n  categories: readonly EmojiCatalogueCategory[];\n}\n\n/** The props Emoji adds to the `<img>` attributes it passes through. */\nexport interface EmojiOwnProps {\n  /** The emoji to draw, from the app's catalogue. */\n  item: EmojiItem;\n  /** The skin tone to draw it in, for an emoji with `skinTones`. @default \"default\" */\n  skinTone?: EmojiSkinTone | (string & { 'Use \"default\", \"light\", \"medium-light\", \"medium\", \"medium-dark\" or \"dark\"': never }) | undefined;\n  /**\n   * Plays an animated emoji now (`true`) or keeps it still (`false`). Without it, the emoji\n   * plays while the mouse is on it or on the button, link or option around it, or that has\n   * focus. Reduced motion keeps it still whatever this says.\n   */\n  play?: boolean | undefined;\n  /** The image's text alternative. @default the emoji's `name` */\n  alt?: string | undefined;\n  /**\n   * Shows in the emoji's place until its picture has loaded and decoded: an image's address,\n   * or an element (centred in the emoji's box, which it does not change). The picture then\n   * fades in over it, at once with reduced motion (the device's setting, or OuroProvider's\n   * `motion`). The placeholder is hidden from screen readers, so the emoji keeps its name, and\n   * a picture that fails to load or decode leaves it showing. It shows again for a new picture\n   * (another emoji, tone or `src`), not while an animated emoji plays. With it, the `<img>`\n   * sits in a `<span>` that takes `className`.\n   *\n   * @claim \"Shows in the emoji's place until\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > shows a placeholder image in the emoji's own box until the picture has decoded, then the picture, named as before, with no shift)\n   * @claim \"Shows in the emoji's place until\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > shows the picture once it has really loaded and decoded, and keeps the placeholder while a loaded picture is still decoding)\n   * @claim \"The picture then fades in over\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > fades the picture in and the placeholder out over the short duration, and swaps them at once with reduced motion)\n   * @claim \"the device's setting, or OuroProvider's\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > fades by OuroProvider's motion over the device's: over the short duration under full, and at once under reduced)\n   * @claim \"The placeholder is hidden from screen\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > draws an element placeholder hidden from screen readers, and passes the img attributes, ref and layout classes through)\n   * @claim \"a picture that fails to load or\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > keeps the placeholder for a picture that fails to load or to decode, and brings it back for a new picture that fails)\n   * @claim \"It shows again for a new\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > shows the placeholder again for a new picture or tone, and never for a stale picture's decode)\n   * @claim \"not while an animated emoji plays\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji placeholder > keeps the picture while the emoji plays and stops, and shows a picture only its animation could draw)\n   */\n  placeholder?: string | ReactElement | undefined;\n  /** Layout only: margins, and a size other than the text's (`size-8`). Appearance classes warn in development. */\n  className?: string | undefined;\n  /** The `<img>`. */\n  ref?: Ref<HTMLImageElement> | undefined;\n\n  /** Not a prop. The image comes from the catalogue's item: `<Emoji item={{ id, name, src }} />`. */\n  src?: { 'Use <Emoji item={{ id, name, src }} />': never };\n  /** Not a prop. Emoji draws a catalogue's item, not text: `<Emoji item={catalogueItem} />`. */\n  emoji?: { 'Use <Emoji item={catalogueItem} />': never };\n  /** Not a prop. Ouro UI uses `play`: `<Emoji item={item} play />`. */\n  animate?: { 'Use <Emoji item={item} play />': never };\n}\n\n/** Props for {@link Emoji}: its own props and the `<img>` attributes it passes through. */\nexport type EmojiProps = Omit<ImgHTMLAttributes<HTMLImageElement>, keyof EmojiOwnProps | \"srcSet\" | \"children\"> & EmojiOwnProps;\n\n/** What an emoji plays for: the button, link or option around it, else the image itself. */\nconst hostSelector = 'button, a[href], [role=\"button\"], [role=\"option\"], [role=\"menuitem\"]';\n\n/** Whether the mouse is on, or focus is in, the element the emoji plays for, while `watch` is on. */\nfunction useHostActive(image: { current: HTMLImageElement | null }, watch: boolean): boolean {\n  const [hovered, setHovered] = useState(false);\n  const [focused, setFocused] = useState(false);\n  useEffect(() => {\n    // Stryker disable next-line ConditionalExpression: listening without need changes nothing; play decides first.\n    if (!watch) return;\n    const own = image.current!;\n    const host = own.parentElement!.closest<HTMLElement>(hostSelector) ?? own;\n    const listening = new AbortController();\n    const listen = <K extends keyof HTMLElementEventMap>(type: K, handler: (event: HTMLElementEventMap[K]) => void) =>\n      // Stryker disable next-line ObjectLiteral: a listener left once play is set or the emoji is gone decides nothing.\n      host.addEventListener(type, handler, { signal: listening.signal });\n    listen(\"pointerenter\", (event) => setHovered(event.pointerType === \"mouse\"));\n    listen(\"pointerleave\", () => setHovered(false));\n    listen(\"focusin\", () => setFocused(true));\n    listen(\"focusout\", (event) => setFocused(host.contains(event.relatedTarget as Node | null)));\n    // Stryker disable next-line BlockStatement: once play is set or the emoji is gone, what the host did decides nothing.\n    return () => {\n      // Stryker disable next-line CallExpression: a listener left once play is set or the emoji is gone decides nothing.\n      listening.abort();\n      setHovered(false);\n      setFocused(false);\n    };\n  }, [image, watch]);\n  return hovered || focused;\n}\n\n/**\n * Cancels the image's filmstrip animation, at most one: the image runs no other.\n *\n * @claim \"at most one\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > plays an animated image over a filmstrip, a tone's filmstrip in that tone, leaves one frame or a broken strip still, and starts a strip once)\n */\nfunction stopAnimations(image: HTMLImageElement): void {\n  for (const animation of image.getAnimations()) animation.cancel();\n}\n\n/**\n * Steps a filmstrip through its frames while `strip` is set: one Web Animation on the image's\n * `object-position`, started once the filmstrip has loaded (its height over its width is the\n * number of frames) and cancelled when it stops. It is cancelled in the same commit that brings\n * back the still image, so the still is never drawn with the strip's motion.\n * @claim \"It is cancelled in the same commit that brings back the still image\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > stops a filmstrip in the same commit that brings back the still image, never after it)\n */\nfunction useFilmstrip(image: { current: HTMLImageElement | null }, strip: EmojiFilmstrip | undefined): void {\n  const src = strip?.src;\n  const fps = strip?.fps;\n  useLayoutEffect(() => {\n    if (src === undefined) return;\n    const own = image.current!;\n    let stopped = false;\n    // Starts once the filmstrip is ready, whether it loads now or was there already.\n    own.decode().then(\n      () => {\n        // A start for a filmstrip that has stopped, or changed pace, is stale: one animation an emoji.\n        // Stryker disable next-line ConditionalExpression: Chromium, where the mutation run tests, fails a stale decode itself; WebKit resolves it.\n        /* istanbul ignore if @preserve -- WebKit only, and only when its decode resolves late: Chromium fails a stale decode itself */ if (stopped) return;\n        const frames = Math.round(own.naturalHeight / own.naturalWidth);\n        if (!(frames > 1)) return;\n        own.animate([{ objectPosition: \"50% 0%\" }, { objectPosition: \"50% 100%\" }], {\n          duration: (frames / fps!) * 1000,\n          iterations: Infinity,\n          easing: `steps(${frames}, jump-none)`,\n        });\n      },\n      // A filmstrip that fails to load leaves the still image.\n      () => {},\n    );\n    return () => {\n      // Stryker disable next-line BooleanLiteral: Chromium, where the mutation run tests, fails a stale decode itself; WebKit resolves it.\n      stopped = true;\n      stopAnimations(own);\n    };\n  }, [image, src, fps]);\n}\n\n/**\n * Fetches the animation (`src`) once the still image has loaded, at low priority, so the first play\n * starts at once rather than waiting for it. Undefined when nothing can play, as under reduced\n * motion, or when the still itself is fetched at low priority (EmojiPicker's emoji further down its\n * grid). Nothing is fetched ahead while the browser asks to save data.\n */\nfunction useWarmAnimation(image: { current: HTMLImageElement | null }, src: string | undefined): void {\n  useEffect(() => {\n    if (src === undefined || (navigator as Navigator & { connection?: { saveData?: boolean } }).connection?.saveData) return;\n    // A still that fails to load leaves the animation unfetched; it would most likely fail too.\n    image.current!.decode().then(\n      () => {\n        const ahead = new Image();\n        ahead.fetchPriority = \"low\";\n        ahead.src = src;\n      },\n      () => {},\n    );\n  }, [image, src]);\n}\n\n/**\n * Marks the emoji's root `data-loaded` while `watch` is on, once the image the `<img>` shows\n * (`shown`) has loaded and decoded, and unmarks it when that fails. A new still image waits for\n * its own picture, while the still and animated forms of one emoji share it. The mark lives on\n * the element rather than in React state, so a decode that ends late, outside a test's `act`,\n * changes the page without a React update.\n */\nfunction usePictureReady(root: { current: HTMLElement | null }, image: { current: HTMLImageElement | null }, shown: string | undefined, still: string, watch: boolean): void {\n  // The still image whose picture has shown.\n  const ready = useRef<string>(undefined);\n  useLayoutEffect(() => {\n    if (!watch) return;\n    const own = root.current!;\n    own.toggleAttribute(\"data-loaded\", ready.current === still);\n    // A decode that ends after the image has moved on is stale; a browser fails it, or lets it finish.\n    let stale = false;\n    const decoded = (ok: boolean) => {\n      if (stale) return;\n      ready.current = ok ? still : undefined;\n      own.toggleAttribute(\"data-loaded\", ok);\n    };\n    image.current!.decode().then(\n      () => decoded(true),\n      () => decoded(false),\n    );\n    return () => {\n      stale = true;\n    };\n  }, [root, image, shown, still, watch]);\n}\n\n/**\n * One emoji from an image catalogue, drawn as an `<img>` the size of the text around it, named\n * by its `alt` (the emoji's name). An animated emoji shows its still image until it plays:\n * while the mouse is on it or on the button around it, or that button has focus, or while\n * `play` says so. Its animation is fetched once the still image has loaded, at low priority, so the\n * first play starts at once; not for a still given `fetchPriority=\"low\"`, nor while the browser asks\n * to save data. With reduced motion it always shows the still image, and the animation is not fetched. `skinTone` draws an\n * emoji with tones in one of them, and `placeholder` stands in until its picture has loaded.\n * Its picture is fetched as soon as it is drawn, not when it nears the screen, so an emoji in an\n * older message is there when the reader scrolls back to it. Its box is the text's size from the\n * first frame, and a picture that fails to load keeps it, so no line moves as emoji load or fail.\n *\n * Use `EmojiText` instead to draw the emoji in a message's text, and an emoji character for an\n * app that uses the platform's emoji font.\n *\n * @group Chat\n * @see https://ui.ouroboros.bot/docs/emoji\n *\n * @example\n * <Emoji item={party} />\n * <Emoji item={party} placeholder=\"/emoji/waiting.svg\" />\n * <Button variant=\"plain\" aria-label=\"Party popper\"><Emoji item={party} alt=\"\" /></Button>\n * @claim \"named by its `alt` (the emoji's name)\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > draws the still image named by the emoji's name, the size of the text, in the tone asked for)\n * @claim \"Its animation is fetched once the still\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji's animation > is fetched once the still image has loaded, so the first play starts at once, the still showing until then)\n * @claim \"at low priority, so the first play\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji's animation > is fetched at low priority, and not for a still fetched at low priority or while the browser asks to save data)\n * @claim \"and the animation is not fetched\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji's animation > is not fetched under reduced motion, which plays nothing, or for a still that fails to load)\n * @claim \"a picture that fails to load keeps it, so no line moves\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > keeps every line and every emoji where a loaded picture would, when its picture fails to load)\n * @claim \"Its picture is fetched as soon as\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:fileLine(registry/ouro/components/ouro/emoji/emoji.test.tsx, /expect\\(img\\.hasAttribute\\(\"loading\"\\)\\)\\.toBe\\(false\\)/)\n * @claim \"With reduced motion it always shows the\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > shows the still image with reduced motion, whatever play says or the pointer does)\n * @claim \"while the mouse is on it or on\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::Emoji > plays while the mouse is on its button or the button has focus, and stops after)\n */\nexport function Emoji(props: EmojiProps): JSX.Element {\n  const {\n    item,\n    skinTone = \"default\",\n    play,\n    alt,\n    placeholder,\n    className,\n    ref,\n    // Guard props (hint types), dropped here so they never reach the DOM.\n    src,\n    emoji,\n    animate,\n    ...rest\n  } = props;\n  const knownTone = emojiSkinTones.includes(skinTone as EmojiSkinTone);\n  useAppearanceClassNameCheck(\n    \"Emoji\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; an emoji is its image`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"Emoji\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !item.src && [\"item has no src, so there is no image to draw\", '<Emoji item={{ id: \"party\", name: \"Party popper\", src: \"/emoji/party.png\" }} />'],\n          !knownTone && [`skinTone=\"${skinTone}\" is not a skin tone; use ${emojiSkinTones.map((tone) => `\"${tone}\"`).join(\", \")}`, '<Emoji item={item} skinTone=\"medium\" />'],\n          src !== undefined && [\"src is not a prop; the image comes from item\", \"<Emoji item={{ id, name, src }} />\"],\n          emoji !== undefined && [\"emoji is not a prop; Emoji draws a catalogue's item\", \"<Emoji item={catalogueItem} />\"],\n          animate !== undefined && [\"animate is not a prop\", \"<Emoji item={item} play />\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n\n  const form = toneOf(item, skinTone as EmojiSkinTone);\n  const own = useRef<HTMLImageElement>(null);\n  const mergedRef = useMergedRef(ref, own);\n  const reduced = useReducedMotion(true);\n  const animated = Boolean(form.animatedSrc ?? form.filmstrip) && !reduced;\n  // Stryker disable next-line ConditionalExpression,LogicalOperator,EqualityOperator: listening saves work only; play decides first.\n  const hostActive = useHostActive(own, animated && play === undefined);\n  const playing = animated && (play ?? hostActive);\n  // An animated image wins over a filmstrip.\n  const strip = playing && !form.animatedSrc ? form.filmstrip : undefined;\n  useFilmstrip(own, strip);\n  useWarmAnimation(own, animated && rest.fetchPriority !== \"low\" ? (form.animatedSrc ?? form.filmstrip!.src) : undefined);\n  const shown = strip ? strip.src : playing ? form.animatedSrc : form.src;\n  const waits = placeholder !== undefined;\n  const box = useRef<HTMLSpanElement>(null);\n  usePictureReady(box, own, shown, form.src, waits);\n  const picture = (\n    <img\n      {...rest}\n      ref={mergedRef}\n      data-ouro={waits ? undefined : \"emoji\"}\n      src={shown}\n      srcSet={playing ? undefined : form.srcSet}\n      width={item.width}\n      height={item.height}\n      alt={alt ?? item.name}\n      draggable={false}\n      decoding=\"async\"\n      className={cn(waits ? [emojiPictureClass, !reduced && emojiPictureFadeClass] : emojiClass, strip && \"object-cover object-top\", !waits && className)}\n    />\n  );\n  if (!waits) return picture;\n  // The placeholder and the picture fill the root's box, the picture on top, so neither moves the text.\n  return (\n    <span ref={box} data-ouro=\"emoji\" className={cn(emojiClass, \"group/emoji relative\", className)}>\n      <span aria-hidden=\"true\" className={cn(emojiPlaceholderClass, !reduced && emojiPlaceholderFadeClass)}>\n        {typeof placeholder === \"string\" ? <img src={placeholder} alt=\"\" draggable={false} decoding=\"async\" className=\"size-full object-contain\" /> : placeholder}\n      </span>\n      {picture}\n    </span>\n  );\n}\n\n/** The props EmojiText adds to the `<span>` attributes it passes through. */\nexport interface EmojiTextOwnProps {\n  /** The text, with emoji as tokens (`:party:`, `:thumbs-up-tone3:`) or as the text the catalogue lists (`\"🎉\"`). */\n  text: string;\n  /** The emoji to draw, which the app supplies. */\n  catalogue: EmojiCatalogue;\n  /**\n   * Draws emoji that stand alone, up to three with nothing else but spaces, at more than twice\n   * the size, as chat apps show a message of only emoji.\n   *\n   * @claim \"up to three with nothing else but spaces\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > enlarges up to three emoji alone, and nothing with other text, more emoji or without enlarge)\n   */\n  enlarge?: boolean | undefined;\n  /** Layout only: margins, width (`mt-1`). Appearance classes warn in development. */\n  className?: string | undefined;\n  /** The `<span>`. */\n  ref?: Ref<HTMLSpanElement> | undefined;\n\n  /** Not a prop. The text goes in `text`, so EmojiText can find its emoji: `<EmojiText text={message.body} catalogue={catalogue} />`. */\n  children?: { 'Use <EmojiText text={message.body} catalogue={catalogue} />': never };\n}\n\n/** Props for {@link EmojiText}: its own props and the `<span>` attributes it passes through. */\nexport type EmojiTextProps = Omit<HTMLAttributes<HTMLSpanElement>, keyof EmojiTextOwnProps> & EmojiTextOwnProps;\n\n/**\n * A message's text with its emoji drawn from an image catalogue: each token (`:party:`, an\n * emoji's first shortcode or else its id, as `EmojiPicker` and `Autocomplete` put into a\n * `Composer`) and each emoji's `text` the catalogue lists becomes the emoji's image, which\n * screen readers hear by name. A token the catalogue does not know stays as typed. `enlarge`\n * shows a message of only emoji large.\n *\n * Use `Emoji` instead for a single emoji outside text, and plain text for an app that uses the\n * platform's emoji font.\n *\n * @group Chat\n * @see https://ui.ouroboros.bot/docs/emoji-text\n *\n * @example\n * <Message author={author} time={sentAt}>\n *   <EmojiText text={message.body} catalogue={catalogue} enlarge />\n * </Message>\n * @claim \"A token the catalogue does not know\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > draws shortcode, id and tone id tokens as their images, and leaves unknown ones as text)\n * @claim \"each emoji's `text` the catalogue lists becomes\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > draws the emoji text the catalogue lists as its images, longest first, with or without a variation selector)\n * @claim \"shows a message of only emoji large\" registry/ouro/components/ouro/emoji/emoji.test.tsx verify:testExists(registry/ouro/components/ouro/emoji/emoji.test.tsx::EmojiText > enlarges up to three emoji alone, and nothing with other text, more emoji or without enlarge)\n */\nexport function EmojiText(props: EmojiTextProps): JSX.Element {\n  const {\n    text,\n    catalogue,\n    enlarge = false,\n    className,\n    // Guard prop (a hint type), dropped here so it never reaches the DOM.\n    children,\n    ...rest\n  } = props;\n  useAppearanceClassNameCheck(\n    \"EmojiText\",\n    className,\n    process.env.NODE_ENV !== \"production\"\n      ? (token: string) => `remove \"${token}\"; EmojiText takes the look of the text around it`\n      : // Stryker disable next-line StringLiteral: production only; the check never runs there.\n        /* istanbul ignore next @preserve -- production only */ \"\",\n  );\n  useDevWarnings(\n    \"EmojiText\",\n    process.env.NODE_ENV !== \"production\"\n      ? () => [\n          !catalogue && [\"catalogue is missing, so no emoji can be drawn\", \"<EmojiText text={message.body} catalogue={catalogue} />\"],\n          children !== undefined && [\"children is not a prop; the text goes in text\", \"<EmojiText text={message.body} catalogue={catalogue} />\"],\n        ]\n      : /* istanbul ignore next @preserve -- production only */ undefined,\n  );\n  // Without text (an app that passed children), there is nothing to draw.\n  const parts = catalogue ? splitEmojiText(text ?? \"\", catalogue) : [text];\n  const found = parts.filter((part) => typeof part !== \"string\");\n  const large = enlarge && found.length > 0 && found.length <= 3 && parts.every((part) => typeof part !== \"string\" || part.trim() === \"\");\n  return (\n    <span {...rest} data-ouro=\"emoji-text\" data-enlarged={large ? \"\" : undefined} className={className}>\n      {parts.map((part, index) =>\n        typeof part === \"string\" ? (\n          part\n        ) : (\n          <Emoji key={index} item={part.item} skinTone={part.tone} className={large ? \"size-[2.75em] align-middle\" : undefined} />\n        ),\n      )}\n    </span>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@components/ouro/emoji/emoji.tsx"
    }
  ],
  "docs": "One emoji from an image catalogue, drawn as an `<img>` the size of the text around it, named by its `alt` (the emoji's name). Import: import { Emoji } from \"@/components/ouro/emoji/emoji\", with @/components replaced by your components alias (aliases.components in components.json, such as ~/components). Also installed: the helpers it imports in lib/ouro. Needs ouro-base in your stylesheet: add that item once per app, from the same place as this one, if you have not. Docs: https://ui.ouroboros.bot/docs/emoji.md Ouro UI v1.3.257.",
  "type": "registry:ui"
}