Skip to content
EliteChart

parseColor

Documentation


Documentation / @elitechart/core / parseColor

code
function parseColor(input): {
  alpha: number;
  hex: string;
};

Defined in: ui/floating-toolbar.ts:416

Parse a CSS color string into { hex, alpha }. Understands #rgb, #rrggbb, #rrggbbaa, and rgba(r, g, b, a). Unknown shapes fall back to #2962ff at alpha 1 (the brand accent) to keep the toolbar working.

Parameters

input

string

Returns

code
{
  alpha: number;
  hex: string;
}

alpha

code
readonly alpha: number;

hex

code
readonly hex: string;

Example

code
import { parseColor } from '@elitechart/core';
parseColor('#26a69a');           // { hex: '#26a69a', alpha: 1 }
parseColor('rgba(255,0,0,0.5)'); // { hex: '#ff0000', alpha: 0.5 }