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

[system] Add blend color manipulator #40258

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

romgrk
Copy link
Contributor

@romgrk romgrk commented Dec 20, 2023

Add a blend function to colorManipulator.js, which is used in mui/mui-x#10059.

@romgrk romgrk added the core Infrastructure work going on behind the scenes label Dec 20, 2023
@mui-bot
Copy link

mui-bot commented Dec 20, 2023

Netlify deploy preview

https://deploy-preview-40258--material-ui.netlify.app/

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 6dfb84d

@romgrk romgrk changed the base branch from next to master January 17, 2024 10:33
@romgrk romgrk force-pushed the feat-color-manipulator-blend branch from c7fb7db to 005338d Compare January 17, 2024 10:36
Comment on lines +358 to +360
* @param {number} [gamma=1.0] - Gamma correction factor. For gamma-correct blending, 2.2 is usual.
*/
export function blend(background, overlay, opacity, gamma = 1.0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally set the gamma correction factor to 2.2, but I had to set it back to 1.0 because that's how browsers do it and blending wouldn't match browser behavior otherwise.

It's just another case in a long serie of Everyone Does sRGB Wrong Because Everyone Else Does sRGB Wrong
.

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Let's add few tests to make sure we won't break it in the future.

packages/mui-system/src/colorManipulator.js Outdated Show resolved Hide resolved
packages/mui-system/src/colorManipulator.js Outdated Show resolved Hide resolved
@romgrk
Copy link
Contributor Author

romgrk commented Jan 17, 2024

I have addressed the comments & added tests.

@romgrk
Copy link
Contributor Author

romgrk commented Feb 5, 2024

@mnajdova Is this one good for merging?

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. I am merging it.

@mnajdova mnajdova merged commit 0b38955 into mui:master Feb 5, 2024
19 checks passed
@mnajdova mnajdova changed the title [core] add colorManipulator.blend [system] Add blend color manipulator Feb 5, 2024
@oliviertassinari oliviertassinari added the package: system Specific to @mui/system label Feb 5, 2024

describe('blend', () => {
it('works', () => {
expect(blend('rgb(90, 90, 90)', 'rgb(10, 100, 255)', 0.5)).to.equal('rgb(50, 95, 173)');
Copy link
Member

@oliviertassinari oliviertassinari Feb 5, 2024

Choose a reason for hiding this comment

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

Nice, it's pretty much what I get with:

background: color-mix(in srgb, rgb(90, 90, 90), rgb(10, 100, 255) 50%);

It's not supported by https://mui.com/material-ui/getting-started/supported-platforms/#browser but browser support it pretty good today: https://caniuse.com/?search=color-mix.

@oliviertassinari oliviertassinari added new feature New feature or request and removed core Infrastructure work going on behind the scenes labels Feb 5, 2024
* @param {number} opacity - Opacity multiplier in the range 0 - 1
* @param {number} [gamma=1.0] - Gamma correction factor. For gamma-correct blending, 2.2 is usual.
*/
export function blend(background, overlay, opacity, gamma = 1.0) {
Copy link
Member

@oliviertassinari oliviertassinari Feb 5, 2024

Choose a reason for hiding this comment

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

Should we export this as

Suggested change
export function blend(background, overlay, opacity, gamma = 1.0) {
export function unstable_blend(background, overlay, opacity, gamma = 1.0) {

?

With #40958, assuming we can use color-mix, I'm not clear why we need to make this util part of the public API. cc @DiegoAndai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants