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

Ensure alpha is a number in Color constructor #400

Merged
merged 5 commits into from Feb 6, 2024

Conversation

lloydk
Copy link
Collaborator

@lloydk lloydk commented Feb 4, 2024

Fixes two failing constructor tests.

Copy link

netlify bot commented Feb 4, 2024

Deploy Preview for colorjs ready!

Name Link
🔨 Latest commit 03562cd
🔍 Latest deploy log https://app.netlify.com/sites/colorjs/deploys/65c2a1f5ed0bc2000814b2d8
😎 Deploy Preview https://deploy-preview-400--colorjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

src/color.js Outdated Show resolved Hide resolved
lloydk and others added 2 commits February 5, 2024 19:09
Co-authored-by: Lea Verou <lea@verou.me>
Copy link
Collaborator

@jgerigmeyer jgerigmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, alpha could be passed in as NaN and it would be retained as such -- this now coerces it to 1. Is that intentional?

@lloydk
Copy link
Collaborator Author

lloydk commented Feb 6, 2024

Before, alpha could be passed in as NaN and it would be retained as such -- this now coerces it to 1. Is that intentional?

You're right, I think we need to allow NaN to be specified.

The getColor function checks alpha === undefined so maybe that's what we should do in the Color constructor.

color.js/src/getColor.js

Lines 27 to 29 in 44f3741

if (color.alpha === undefined) {
color.alpha = 1;
}

Should getColor clamp alpha like the Color constructor?

@LeaVerou
Copy link
Member

LeaVerou commented Feb 6, 2024

Oh good point. We do plan to eventually use null for none, rather than NaN, since that's a separate keyword, but for now we should coerce to NaN.

@lloydk
Copy link
Collaborator Author

lloydk commented Feb 6, 2024

I've added some additional constructor tests for NaN/none/clamping and alpha is set to 1 only if it's > 1 or undefined.

@LeaVerou LeaVerou merged commit a2ba4b7 into color-js:main Feb 6, 2024
4 checks passed
@lloydk lloydk deleted the fix-constructor branch February 6, 2024 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants