Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sass library equivalent #5

Open
pygy opened this issue Sep 5, 2015 · 3 comments
Open

Sass library equivalent #5

pygy opened this issue Sep 5, 2015 · 3 comments

Comments

@pygy
Copy link
Member

pygy commented Sep 5, 2015

It would be useful to provide as a companion library functions that tweak colors (lighten('#f00', 0.2)) and do arithmetic on sizes (add('2em', '0.5em') or mul('3px', 2)).

This issue is there to discuss the specifics. I'd like to keep the gzipped size as small as possible, of course.

  • add and sub take two measures with the same unit.
  • mul and div take a measure and a number.

both return a measure of the same unit as the input.

  • the color functions take a color and a number, and output either a #ff0000 formated color of possible and rgba() otherwise.

Taking inspiration on the Sass standard library, I'd borrow adjust-color, scale-color and change-color but split them into *-rgba and *-hsla versions. You can't change both rgb and hsl using the original, anyway, and the long parameter list makes them unusable in practice.

Maybe also provide rgba and hsla constructors (the a being optional)? Do they return color strings or {r, g, b, a} / {h, s, l, a} objects? The former means that their output can be fed to j2c, but the latter means that we can skip the parse step in the color modifying functions. We could use valueOf to make '' + rgba(...) return a string. Make them accept color strings, and they also do the job of the rgba and hsl getters of Sass.

Feedback most welcome :-)

@der-On
Copy link

der-On commented Sep 6, 2015

Take a look at color. I do use that one currently.

@pygy
Copy link
Member Author

pygy commented Sep 7, 2015

@ArthruClemens also mentioned https://github.com/bgrins/TinyColor which clocks at 6K mingzipped, while https://github.com/harthur/color is at 3K.

I'll try to get lower still, not sure if it's possible.

@StephanHoyer
Copy link

https://github.com/One-com/one-color 2.8kb mingzipped

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants