code: def parse_color(text: str) -> str:
      """
      Parse/validate color format.
  
      Like in Pygments, but also support the ANSI color names.
      (These will map to the colors of the 16 color palette.)
      """
      # ANSI color names.
      if text in ANSI_COLOR_NAMES:
          return text
      if text in ANSI_COLOR_NAMES_ALIASES:
          return ANSI_COLOR_NAMES_ALIASES[text]
  
      # 140 named colors.
      try:
          # Replace by 'hex' value.
          return _named_colors_lowercase[text.lower()]
      except KeyError:
          pass
  
      # Hex codes.
      if text[0:1] == "#":
          col = text[1:]
  
          # Keep this for backwards-compatibility (Pygments does it).
          # I don't like the '#' prefix for named colors.
          if col in ANSI_COLOR_NAMES:
              return col
          elif col in ANSI_COLOR_NAMES_ALIASES:
              return ANSI_COLOR_NAMES_ALIASES[col]
  
          # 6 digit hex color.
          elif len(col) == 6:
              return col
  
          # 3 digit hex color.
          elif len(col) == 3:
              return col[0] * 2 + col[1] * 2 + col[2] * 2
  
      # Default.
      elif text in ("", "default"):
          return text
  
      raise ValueError("Wrong color format %r" % text)
  
imports: from __future__ import annotations
  import itertools
  import re
  from enum import Enum
  from typing import Hashable, TypeVar
  from prompt_toolkit.cache import SimpleCache
  from .base import ANSI_COLOR_NAMES, ANSI_COLOR_NAMES_ALIASES, DEFAULT_ATTRS, Attrs, BaseStyle
  from .named_colors import NAMED_COLORS
label_desc: Use image node_id 1 for calling a global function with example usage: parse_color(text) and returns: text, ANSI_COLOR_NAMES_ALIASES, _named_colors_lowercase, col, text, ANSI_COLOR_NAMES_ALIASES, col, unknown