Skip to content

feature:(#305) Add support for oklab and oklch color functions #436

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

Merged
merged 2 commits into from
May 7, 2025

Conversation

rgant
Copy link
Contributor

@rgant rgant commented Apr 24, 2025

RESOLVES:
feature - Add new CSS color functions [#305]

DESCRIPTION:
CSS Color Module Level 4 adds support for oklch and oklab to browsers. They are becoming more popular, and I wanted to use them with color previews in my editor.

This feature is built off of the original #306 which included steps for lab and lch but not the ok variants.

Generally this code was designed using real world color examples.

STEPS TO TEST:

Tests were added to relevant files following established patterns. Should be able to just run npm run test. However I don't use vscode, so I did not test in an actual editor.

rgant added 2 commits April 24, 2025 15:46
…ctions

__RESOLVES:__
_feature_ - *Add new CSS color functions* \[[microsoft#305](https://github.com/microsoft/vscode-css-languageservice/issues/305)\]

__DESCRIPTION:__
CSS Color Module Level 4 adds support for `oklch` and `oklab` to browsers. They are becoming more popular, and I wanted to use them with color previews in my editor.

This feature is built of of the original [microsoft#306](microsoft#306) which included steps for `lab` and `lch` but not the `ok` variants.

Generally this code was designed using real world color [examples](https://www.oddcontrast.com/#hex__*f00__*4d216f80__srgb).

__STEPS TO TEST:__
@rgant
Copy link
Contributor Author

rgant commented May 5, 2025

Any questions or concerns? Anything I can do to help move this along?

@aeschli
Copy link
Collaborator

aeschli commented May 7, 2025

@rgant Looks good, thanks a lot!

@vs-code-engineering vs-code-engineering bot added this to the May 2025 milestone May 7, 2025
export interface LAB { l: number; a: number; b: number; alpha?: number; }

export function labFromLCH(l: number, c: number, h: number, alpha: number = 1.0): LAB {
const DEGREES_TO_RADIANS_FACTOR = Math.PI / 180;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
const DEGREES_TO_RADIANS_FACTOR = Math.PI / 180;
const DEGREES_TO_RADIANS_FACTOR = Math.PI / (DEGREES_PER_CIRCLE / 2);

I think there should be a minor change here to re-use the constants better. Would you like that added to this PR, or a new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could also be const DEGREES_TO_RADIANS_FACTOR = Math.PI / DEGREES_PER_CIRCLE * 2;

If fewer parenthesis are preferred.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can make a follow-up PR, if you want. I think the brackets help, even if not strictly necessary.

@aeschli aeschli merged commit b947bea into microsoft:main May 7, 2025
3 checks passed
@rgant rgant deleted the add-css-color-4-oklab-oklch branch May 7, 2025 15:01
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.

3 participants