@gravity-ui/graph
Version:
Modern graph editor component
22 lines (21 loc) • 1.03 kB
TypeScript
/**
* Applies alpha (opacity) to a color string.
* This is useful as an alternative to using ctx.globalAlpha, which affects all drawing operations.
* Instead, you can apply opacity directly to specific colors.
*
* @param color - Color in any valid CSS format (hex, rgb, rgba, hsl, hsla, named colors)
* @param alpha - Alpha value between 0 (fully transparent) and 1 (fully opaque)
* @returns Color string in rgba format with applied alpha
*
* @example
* applyAlpha('#ff0000', 0.5) // returns 'rgba(255, 0, 0, 0.5)'
* applyAlpha('rgb(255, 0, 0)', 0.5) // returns 'rgba(255, 0, 0, 0.5)'
* applyAlpha('rgba(255, 0, 0, 0.8)', 0.5) // returns 'rgba(255, 0, 0, 0.4)' - multiplies existing alpha
* applyAlpha('red', 0.5) // returns 'rgba(255, 0, 0, 0.5)'
*/
export declare function applyAlpha(color: string, alpha: number): string;
/**
* Clears the color cache to free up memory.
* Use this if you've processed a large number of unique colors and want to reclaim memory.
*/
export declare function clearColorCache(): void;