UNPKG

@kcuf/mere-color

Version:

Mere color utils for generating, manipulation, a11y purposes.

22 lines (21 loc) 617 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = mix; var _util = require("../util"); var _parse = require("../parse"); /** * Mixes two colors together by calculating the average of each RGB channel, returning the new color in the original notation normalized. */ function mix(color1, color2, ratio) { var rgb1 = (0, _parse.parseToRgb)(color1); var rgb2 = (0, _parse.parseToRgb)(color2); if (!rgb2) { return color1; } if (!rgb1) { return color2; } return (0, _util.toColorStringOriginalNotation)((0, _util.rgbMix)(rgb1, rgb2, ratio), color1); }