Skip to content

Use .blue() instead of .b() in textColorForBackgroundColor#905

Open
fueko wants to merge 3 commits into
TryGhost:mainfrom
fueko:patch-1
Open

Use .blue() instead of .b() in textColorForBackgroundColor#905
fueko wants to merge 3 commits into
TryGhost:mainfrom
fueko:patch-1

Conversation

@fueko
Copy link
Copy Markdown

@fueko fueko commented May 9, 2026

.b() returns the HSB brightness component, not the blue RGB channel. This caused incorrect YIQ calculation for most colors.


Note

Low Risk
Small, localized bugfix in textColorForBackgroundColor that changes text color selection results for some backgrounds; low risk but may affect UI contrast outcomes.

Overview
Fixes textColorForBackgroundColor’s YIQ computation to use the RGB blue channel via blue() instead of b() (which refers to a different color component), correcting text color selection for many backgrounds.

Rebuilds the generated cjs/es outputs to reflect this change.

Reviewed by Cursor Bugbot for commit 301ad96. Bugbot is set up for automated code reviews on this repo. Configure here.

.b() returns the HSB brightness component, not the blue RGB channel. This caused incorrect YIQ calculation for most colors.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

Review Change Stack

Walkthrough

This PR adjusts formatting and line breaks in the yiq calculation within the textColorForBackgroundColor function in the color utilities module. The change repositions the backgroundColor.blue() * 0.114 term across lines without altering the computed value or downstream logic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: replacing .b() with .blue() in textColorForBackgroundColor, which is the core fix in this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description clearly describes the bug being fixed and its impact, directly relating to the changeset which corrects the YIQ calculation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit eca1791. Configure here.

Comment thread packages/color-utils/cjs/color-utils.js
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/color-utils/cjs/color-utils.js`:
- Around line 38-41: The YIQ luminance calculation uses the Lab b-channel method
call `.b()` in the TypeScript source (packages/color-utils/src/color-utils.ts)
causing wrong RGB values; update the calculation where `yiq` is computed (the
expression that multiplies backgroundColor channels) to call
`backgroundColor.blue()` instead of `backgroundColor.b()`, ensure the code still
references `backgroundColor.red()` and `backgroundColor.green()` as before, then
rebuild the package so CJS/ES/UMD outputs are regenerated with the corrected
YIQ/contrast logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ed186db0-2471-4a27-877f-6dd9ab54ba21

📥 Commits

Reviewing files that changed from the base of the PR and between c0a7fd1 and eca1791.

📒 Files selected for processing (1)
  • packages/color-utils/cjs/color-utils.js

Comment thread packages/color-utils/cjs/color-utils.js
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.

1 participant