color-js / color.js

Color conversion & manipulation library by the editors of the CSS Color specifications
https://colorjs.io
MIT License
1.89k stars 82 forks source link

[getAll] Support precision, closes #542 #548

Closed DmitrySharabin closed 3 months ago

DmitrySharabin commented 3 months ago

Ensure that it’s something you had in mind, though. My approach is relatively straightforward. We should probably have an optional options parameter with precision as a property.

netlify[bot] commented 3 months ago

Deploy Preview for colorjs failed. Why did it fail? β†’

Name Link
Latest commit aa6db63fc85af94acddabd2cbb0c5b1ea5f142e0
Latest deploy log https://app.netlify.com/sites/colorjs/deploys/6669a09a10e10d000804bed9
DmitrySharabin commented 3 months ago

I don't think we want a separate parameter here, we'd want to make the second param an options object with space and precision as keys. Specifying a color space (either as a string or ColorSpace object should still work.

Agreed. Done. Could you please have another look?

MysteryBlokHed commented 3 months ago

Something like this in toGamut.js could be used maybe?

https://github.com/color-js/color.js/blob/3f97a65640ed283251fa125bbd6018ff74633c83/src/toGamut.js#L69-L71

Where a destructured object is used as a parameter, but then arguments is used to check if something else was passed. So if it's a string or instance of a color space, then space is just set to arguments[1].

DmitrySharabin commented 3 months ago

Something like this in toGamut.js could be used maybe?

https://github.com/color-js/color.js/blob/3f97a65640ed283251fa125bbd6018ff74633c83/src/toGamut.js#L69-L71

Where a destructured object is used as a parameter, but then arguments is used to check if something else was passed. So if it's a string or instance of a color space, then space is just set to arguments[1].

I was thinking of something like this, too. Thank you so much for the hint! πŸ™

DmitrySharabin commented 3 months ago

@MysteryBlokHed, could you please check if I get the idea with overloads right?

LeaVerou commented 3 months ago

@DmitrySharabin do you have access to edit the release notes for v0.6.0 to mention this? (make sure not to accidentally publish!)

DmitrySharabin commented 3 months ago

@DmitrySharabin do you have access to edit the release notes for v0.6.0 to mention this? (make sure not to accidentally publish!)

It looks like I don't β€” I don't see any drafts of release notes.