@onesy/utils
Version:
18 lines (17 loc) • 899 B
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const is_1 = __importDefault(require("./is"));
const clamp_1 = __importDefault(require("./clamp"));
const colorToRgb_1 = __importDefault(require("./colorToRgb"));
const lighten = (value, coefficient) => {
const values = (0, colorToRgb_1.default)(value, undefined, true);
if ((0, is_1.default)('array', values) && values.length >= 3) {
values.slice(0, 3).forEach((item, index) => values[index] += (255 - item) * (0, clamp_1.default)(coefficient, 0, 1));
const [r, g, b, a] = [...values.slice(0, 3).map(item => Math.round(Number(item))), values[3]];
return `rgb${a ? 'a' : ''}(${r}, ${g}, ${b}${a ? `, ${a}` : ''})`;
}
};
exports.default = lighten;
;