code: def buildColrV1(
      colorGlyphs: _ColorGlyphsDict,
      glyphMap: Optional[Mapping[str, int]] = None,
      *,
      allowLayerReuse: bool = True,
  ) -> Tuple[Optional[ot.LayerList], ot.BaseGlyphList]:
      if glyphMap is not None:
          colorGlyphItems = sorted(
              colorGlyphs.items(), key=lambda item: glyphMap[item[0]]
          )
      else:
          colorGlyphItems = colorGlyphs.items()
  
      errors = {}
      baseGlyphs = []
      layerBuilder = LayerListBuilder(allowLayerReuse=allowLayerReuse)
      for baseGlyph, paint in colorGlyphItems:
          try:
              baseGlyphs.append(
                  buildBaseGlyphPaintRecord(
                      baseGlyph, layerBuilder, paint
                  )
              )
  
          except (
              ColorLibError,
              OverflowError,
              ValueError,
              TypeError,
          ) as e:
              errors[baseGlyph] = e
  
      if errors:
          failed_glyphs = _format_glyph_errors(errors)
          exc = ColorLibError(
              f"Failed to build BaseGlyphList:\n{failed_glyphs}"
          )
          exc.errors = errors
          raise exc from next(iter(errors.values()))
  
      layers = layerBuilder.build()
      glyphs = ot.BaseGlyphList()
      glyphs.BaseGlyphCount = len(baseGlyphs)
      glyphs.BaseGlyphPaintRecord = baseGlyphs
      return (layers, glyphs)
  
imports: import collections
  import copy
  import enum
  from functools import partial
  from math import ceil, log
  from typing import Any, Dict, Generator, Iterable, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union
  from fontTools.misc.arrayTools import intRect
  from fontTools.misc.fixedTools import fixedToFloat
  from fontTools.misc.treeTools import build_n_ary_tree
  from fontTools.ttLib.tables import C_O_L_R_
  from fontTools.ttLib.tables import C_P_A_L_
  from fontTools.ttLib.tables import _n_a_m_e
  from fontTools.ttLib.tables import otTables
  from fontTools.ttLib.tables.otTables import ExtendMode, CompositeMode
  from .errors import ColorLibError
  from .geometry import round_start_circle_stable_containment
  from .table_builder import BuildCallback, TableBuilder
label_desc: Use image node_id 19 for calling a global function with example usage: buildColrV1(colorGlyphs, glyphMap) and returns: layers,  glyphs