Skip to content

fix: read 3-digit hex colours and fall back to light for invalid inputs (#72) - #73

Merged
blixvip merged 1 commit into
blixvip:mainfrom
Mohit-Gaur75:fix/hex-color-luminance
Nov 15, 2026
Merged

blixvip merged 1 commit into
blixvip:mainfrom
Mohit-Gaur75:fix/hex-color-luminance

Conversation

@Mohit-Gaur75

Copy link
Copy Markdown
Contributor

Summary

Fixes #72.

  • Expands three-digit hex values (#rgb to #rrggbb) in luminance() before parsing channels, so shorthand colors like #fff compute the exact same luminance as #ffffff.
  • Falls back to 1 (light default used by colors()) when given unparsable or named colors (e.g. 'white', invalid hex).
  • Exports luminance from public/drafts.mjs.
  • Adds unit tests in test/drafts.test.js covering #fff, #ffffff, #000, #070708, and 'white' as requested.

Verification

  • Ran npm test: all 39 tests pass.
  • Ran npm run check: passes cleanly.

…nce (blixvip#72)

- Expand 3-digit hex color strings to 6 digits before computing luminance
- Fall back to luminance 1 (light default) on invalid or unparsable inputs
- Export luminance function from public/drafts.mjs
- Add unit tests in test/drafts.test.js covering #fff, #ffffff, #000, #070708, and named colors

Fixes blixvip#72
@blixvip

blixvip commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Verified locally: npm test is green at 41/41, and the four new cases in test/drafts.test.js cover everything #72 asked for — #fff/#ffffff matching, #000, #070708, and the fallback to light for white and other unparsable values.

Nice touch converting luminance to an exported function declaration rather than moving the const — hoisting keeps colors() working unchanged.

Thanks @Mohit-Gaur75. Merging.

@blixvip
blixvip merged commit cba565d into blixvip:main Nov 15, 2026
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.

Read 3-digit hex colours correctly when choosing a draft's light or dark mode

2 participants