meo-canvas - v8.0.0
    Preparing search index...

    Function parseColor

    • Resolves any colour the rendering engine accepts into sRGB.

      The engine does the work: the colour is painted onto a one-pixel canvas and read back. That is deliberately not a CSS parser — it means every syntax the engine supports is supported here for free, today and after any upgrade, including lab(), oklch() and color(display-p3 …), which a hand-written parser would either miss or approximate.

      Wide-gamut inputs survive: the scratch surface holds floats, so a colour beyond sRGB comes back as extended sRGB rather than clipped to the edge of it.

      Parameters

      • css: string

      Returns Rgba

      if the engine does not recognise the colour, rather than returning a misleading black.

      parseColor('rebeccapurple')            // { r: 102, g: 51, b: 153, a: 1 }
      parseColor('oklch(0.7 0.2 30)') // resolved by the engine
      parseColor('color(display-p3 1 0 0)') // { r: 278.73, … } — beyond sRGB, kept