@bavard/agent-config
Advanced tools
Comparing version 0.1.48-alpha.0 to 0.1.48-alpha.1
@@ -80,7 +80,7 @@ interface IDecomposedColor { | ||
* Lightens a color. | ||
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color() | ||
* @param {string} colorStr - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color() | ||
* @param {number} coefficient - multiplier in the range 0 - 1 | ||
* @returns {string} A CSS color string. Hex input values are returned as rgb | ||
*/ | ||
export declare function lighten(color: string, coefficient: number): string; | ||
export declare function lighten(colorStr: string, coefficient: number): string; | ||
/** | ||
@@ -87,0 +87,0 @@ * Darken or lighten a color, depending on its luminance. |
@@ -268,24 +268,28 @@ "use strict"; | ||
* Lightens a color. | ||
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color() | ||
* @param {string} colorStr - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color() | ||
* @param {number} coefficient - multiplier in the range 0 - 1 | ||
* @returns {string} A CSS color string. Hex input values are returned as rgb | ||
*/ | ||
function lighten(color, coefficient) { | ||
const { type, values, colorSpace } = decomposeColor(color); | ||
function lighten(colorStr, coefficient) { | ||
const color = decomposeColor(colorStr); | ||
coefficient = clamp(coefficient); | ||
const valuesNumeric = values.map((v) => Number(v)); | ||
if (type.indexOf("hsl") !== -1) { | ||
valuesNumeric[2] += (100 - valuesNumeric[2]) * coefficient; | ||
const values = color.values.map((v) => Number(v)); | ||
if (color.type.indexOf("hsl") !== -1) { | ||
values[2] += (100 - values[2]) * coefficient; | ||
} | ||
else if (type.indexOf("rgb") !== -1) { | ||
else if (color.type.indexOf("rgb") !== -1) { | ||
for (let i = 0; i < 3; i += 1) { | ||
valuesNumeric[i] += (255 - valuesNumeric[i]) * coefficient; | ||
values[i] += (255 - values[i]) * coefficient; | ||
} | ||
} | ||
else if (type.indexOf("color") !== -1) { | ||
else if (color.type.indexOf("color") !== -1) { | ||
for (let i = 0; i < 3; i += 1) { | ||
valuesNumeric[i] += (1 - valuesNumeric[i]) * coefficient; | ||
values[i] += (1 - values[i]) * coefficient; | ||
} | ||
} | ||
return recomposeColor({ type, values, colorSpace }); | ||
return recomposeColor({ | ||
type: color.type, | ||
values, | ||
colorSpace: color.colorSpace, | ||
}); | ||
} | ||
@@ -292,0 +296,0 @@ exports.lighten = lighten; |
{ | ||
"name": "@bavard/agent-config", | ||
"version": "0.1.48-alpha.0", | ||
"version": "0.1.48-alpha.1", | ||
"description": "Shared code and single source of truth for Bavard data models.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
598419
9596