make-color-more-chill
Advanced tools
Comparing version 0.1.1 to 0.2.0
export declare const black = "#000000"; | ||
export declare const dark = "#25292E"; | ||
export declare const white = "#ffffff"; | ||
export declare const fallbackColors: { | ||
dark: string; | ||
light: string; | ||
}; | ||
export declare function isBlackOrWhite(color: string): boolean; | ||
export declare function isChill(color: string): boolean; | ||
export default function makeColorMoreChill(color: string): string; | ||
export declare function isChill(color: string, background?: string): boolean; | ||
export declare function fallbackColorForBackground(background?: string): string; | ||
export default function makeColorMoreChill(color: string, background?: string): string; |
@@ -13,20 +13,38 @@ 'use strict'; | ||
var black = '#000000'; | ||
var dark = '#25292E'; | ||
var white = '#ffffff'; | ||
var fallbackColors = { | ||
dark: '#25292E', | ||
light: '#525B66' | ||
}; | ||
function isBlackOrWhite(color) { | ||
return chroma(color).hex() === black || chroma(color).hex() === white; | ||
} | ||
function isChill(color) { | ||
var chillness = Number(chroma.contrast(color, white).toFixed(2)); | ||
function isChill(color, background) { | ||
if (background === void 0) { | ||
background = white; | ||
} | ||
var chillness = Number(chroma.contrast(color, background).toFixed(2)); | ||
return chillness > chillThreshold; | ||
} | ||
function makeColorMoreChill(color) { | ||
function fallbackColorForBackground(background) { | ||
if (background === void 0) { | ||
background = white; | ||
} | ||
return chroma.distance(white, background) < chroma.distance(black, background) ? fallbackColors.dark : fallbackColors.light; | ||
} | ||
function makeColorMoreChill(color, background) { | ||
if (background === void 0) { | ||
background = white; | ||
} | ||
// Pure white and pure black do not chill well with our interfaces, lets make it more chill. | ||
if (isBlackOrWhite(color)) return dark; // Return the color if it's already totally chill and doesn't need to be messed with. | ||
if (isBlackOrWhite(color)) return fallbackColorForBackground(background); // Return the color if it's already totally chill and doesn't need to be messed with. | ||
if (isChill(color)) return color; // Mess with the color just enough to make it pass the chillThreshold, but not too far past it. | ||
if (isChill(color, background)) return color; // Mess with the color just enough to make it pass the chillThreshold, but not too far past it. | ||
var chillColor = color; | ||
while (!isChill(chillColor)) { | ||
while (!isChill(chillColor, background)) { | ||
chillColor = chroma(chillColor).darken(0.02).saturate(0.02).hex(); | ||
@@ -39,4 +57,5 @@ } | ||
exports.black = black; | ||
exports.dark = dark; | ||
exports.default = makeColorMoreChill; | ||
exports.fallbackColorForBackground = fallbackColorForBackground; | ||
exports.fallbackColors = fallbackColors; | ||
exports.isBlackOrWhite = isBlackOrWhite; | ||
@@ -43,0 +62,0 @@ exports.isChill = isChill; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("chroma-js"))&&"object"==typeof e&&"default"in e?e.default:e;function t(e){return"#000000"===r(e).hex()||"#ffffff"===r(e).hex()}function f(e){return Number(r.contrast(e,"#ffffff").toFixed(2))>2.5}exports.black="#000000",exports.dark="#25292E",exports.default=function(e){if(t(e))return"#25292E";if(f(e))return e;for(var o=e;!f(o);)o=r(o).darken(.02).saturate(.02).hex();return o},exports.isBlackOrWhite=t,exports.isChill=f,exports.white="#ffffff"; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=(e=require("chroma-js"))&&"object"==typeof e&&"default"in e?e.default:e,t="#ffffff",o={dark:"#25292E",light:"#525B66"};function i(e){return"#000000"===r(e).hex()||r(e).hex()===t}function a(e,o){return void 0===o&&(o=t),Number(r.contrast(e,o).toFixed(2))>2.5}function n(e){return void 0===e&&(e=t),r.distance(t,e)<r.distance("#000000",e)?o.dark:o.light}exports.black="#000000",exports.default=function(e,o){if(void 0===o&&(o=t),i(e))return n(o);if(a(e,o))return e;for(var f=e;!a(f,o);)f=r(f).darken(.02).saturate(.02).hex();return f},exports.fallbackColorForBackground=n,exports.fallbackColors=o,exports.isBlackOrWhite=i,exports.isChill=a,exports.white=t; | ||
//# sourceMappingURL=make-color-more-chill.cjs.production.min.js.map |
@@ -7,20 +7,38 @@ import chroma from 'chroma-js'; | ||
var black = '#000000'; | ||
var dark = '#25292E'; | ||
var white = '#ffffff'; | ||
var fallbackColors = { | ||
dark: '#25292E', | ||
light: '#525B66' | ||
}; | ||
function isBlackOrWhite(color) { | ||
return chroma(color).hex() === black || chroma(color).hex() === white; | ||
} | ||
function isChill(color) { | ||
var chillness = Number(chroma.contrast(color, white).toFixed(2)); | ||
function isChill(color, background) { | ||
if (background === void 0) { | ||
background = white; | ||
} | ||
var chillness = Number(chroma.contrast(color, background).toFixed(2)); | ||
return chillness > chillThreshold; | ||
} | ||
function makeColorMoreChill(color) { | ||
function fallbackColorForBackground(background) { | ||
if (background === void 0) { | ||
background = white; | ||
} | ||
return chroma.distance(white, background) < chroma.distance(black, background) ? fallbackColors.dark : fallbackColors.light; | ||
} | ||
function makeColorMoreChill(color, background) { | ||
if (background === void 0) { | ||
background = white; | ||
} | ||
// Pure white and pure black do not chill well with our interfaces, lets make it more chill. | ||
if (isBlackOrWhite(color)) return dark; // Return the color if it's already totally chill and doesn't need to be messed with. | ||
if (isBlackOrWhite(color)) return fallbackColorForBackground(background); // Return the color if it's already totally chill and doesn't need to be messed with. | ||
if (isChill(color)) return color; // Mess with the color just enough to make it pass the chillThreshold, but not too far past it. | ||
if (isChill(color, background)) return color; // Mess with the color just enough to make it pass the chillThreshold, but not too far past it. | ||
var chillColor = color; | ||
while (!isChill(chillColor)) { | ||
while (!isChill(chillColor, background)) { | ||
chillColor = chroma(chillColor).darken(0.02).saturate(0.02).hex(); | ||
@@ -33,3 +51,3 @@ } | ||
export default makeColorMoreChill; | ||
export { black, dark, isBlackOrWhite, isChill, white }; | ||
export { black, fallbackColorForBackground, fallbackColors, isBlackOrWhite, isChill, white }; | ||
//# sourceMappingURL=make-color-more-chill.esm.js.map |
@@ -5,3 +5,3 @@ { | ||
"module": "dist/make-color-more-chill.esm.js", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
@@ -8,5 +8,9 @@ import chroma from 'chroma-js'; | ||
export const black = '#000000'; | ||
export const dark = '#25292E'; | ||
export const white = '#ffffff'; | ||
export const fallbackColors = { | ||
dark: '#25292E', | ||
light: '#525B66', | ||
}; | ||
export function isBlackOrWhite(color: string): boolean { | ||
@@ -16,17 +20,26 @@ return chroma(color).hex() === black || chroma(color).hex() === white; | ||
export function isChill(color: string): boolean { | ||
const chillness = Number(chroma.contrast(color, white).toFixed(2)); | ||
export function isChill(color: string, background: string = white): boolean { | ||
const chillness = Number(chroma.contrast(color, background).toFixed(2)); | ||
return chillness > chillThreshold; | ||
} | ||
export default function makeColorMoreChill(color: string) { | ||
export function fallbackColorForBackground(background: string = white) { | ||
return chroma.distance(white, background) < chroma.distance(black, background) | ||
? fallbackColors.dark | ||
: fallbackColors.light; | ||
} | ||
export default function makeColorMoreChill( | ||
color: string, | ||
background: string = white | ||
) { | ||
// Pure white and pure black do not chill well with our interfaces, lets make it more chill. | ||
if (isBlackOrWhite(color)) return dark; | ||
if (isBlackOrWhite(color)) return fallbackColorForBackground(background); | ||
// Return the color if it's already totally chill and doesn't need to be messed with. | ||
if (isChill(color)) return color; | ||
if (isChill(color, background)) return color; | ||
// Mess with the color just enough to make it pass the chillThreshold, but not too far past it. | ||
let chillColor = color; | ||
while (!isChill(chillColor)) { | ||
while (!isChill(chillColor, background)) { | ||
chillColor = chroma(chillColor) | ||
@@ -33,0 +46,0 @@ .darken(0.02) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
17991
150