code: def docname_to_domain(docname: str, compaction: bool | str) -> str:
      """Convert docname to domain for catalogs."""
      if isinstance(compaction, str):
          return compaction
      if compaction:
          return docname.split(SEP, 1)[0]
      else:
          return docname
  
imports: from __future__ import annotations
  import os
  import re
  from datetime import datetime, timezone
  from os import path
  from typing import TYPE_CHECKING, Callable, NamedTuple
  import babel.dates
  from babel.messages.mofile import write_mo
  from babel.messages.pofile import read_po
  from sphinx.errors import SphinxError
  from sphinx.locale import __
  from sphinx.util import logging
  from sphinx.util.osutil import SEP, canon_path, relpath
label_desc: Use image node_id 1 for calling a global function with example usage: docname_to_domain(docname, compaction) and returns: compaction, docname, docname