wessberg / color Goto Github PK
View Code? Open in Web Editor NEWA library of well-tested helper methods for working with colors.
License: MIT License
A library of well-tested helper methods for working with colors.
License: MIT License
Hi Frederik, thanks for creating this library - I'm currently using it in a TypeScript project and the API is really nice.
I'm trying to lighten a black color, but it remains black:
const {lighten} = require("@wessberg/color")
console.log(lighten('black', 10)) // => '#000000'
console.log(lighten('#000000', 10)) // => '#000000'
It works just fine for other colors.
I had a look at the source for lightenHsl
, and the lightness is calculated as follows:
Math.max(0, Math.min(100, ((100 + percentage) * parseFloat(L)) / 100))
(where percentage = 10
)
For black, L = 0
, so the resulting lightness value is 0
.
For L = 50
, the resulting lightness is 55
.
In general, it seems strange that the percentage is proportional to the existing lightness value, because colors that are already light will become much lighter than darker colors. I expected the lightness to simply be added to the existing lightness, ie. that
for L = 0
, the resulting lightness would be 10
,
and for L = 50
it would be 60
.
in JS:
Math.max(0, Math.min(100, parseFloat(L) + percentage))
This change would obviously affect all of the colors generated by your library so I don't know if this is something you'd want to do if you're relying on the way specific colors look already - just wanted to flag this as I'll unfortunately have to use a different library for the time being.
Anyway let me know if this makes sense & if you'd consider changing the behavior. Thanks a lot :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.