-
Notifications
You must be signed in to change notification settings - Fork 30.5k
culori: Add XYB colorspace, missing fns, and culori/css + culori/all entry points #69771
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| export { | ||
| a98, | ||
| cubehelix, | ||
| dlab, | ||
| dlch, | ||
| hsi, | ||
| hsl, | ||
| hsv, | ||
| hwb, | ||
| jab, | ||
| jch, | ||
| lab, | ||
| lab65, | ||
| lch, | ||
| lch65, | ||
| lchuv, | ||
| lrgb, | ||
| luv, | ||
| okhsl, | ||
| okhsv, | ||
| oklab, | ||
| oklch, | ||
| p3, | ||
| prophoto, | ||
| rec2020, | ||
| rgb, | ||
| xyb, | ||
| xyz50, | ||
| xyz65, | ||
| yiq, | ||
| } from "../index"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| export { | ||
| a98, | ||
| hsl, | ||
| hsv, | ||
| hwb, | ||
| lab, | ||
| lab65, | ||
| lch, | ||
| lch65, | ||
| lrgb, | ||
| oklab, | ||
| oklch, | ||
| p3, | ||
| prophoto, | ||
| rec2020, | ||
| rgb, | ||
| xyz50, | ||
| xyz65, | ||
| } from "../index"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,84 @@ | ||
| import { Color, GamutMode, Mode } from "./common"; | ||
| import { Color, FindColorByMode, GamutMode, Mode } from "./common"; | ||
|
|
||
| /** | ||
| * Returns whether the color is in the sRGB gamut. | ||
| */ | ||
| export function displayable(color: Color | string): boolean; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| /** | ||
| * Given a color space `mode`, returns a function | ||
| * with which to check whether a color is | ||
| * in that color space's gamut. | ||
| */ | ||
| export function inGamut(mode?: Mode): (color: Color | string) => boolean; | ||
|
|
||
| /* | ||
| * Obtain a color that's in the sRGB gamut | ||
| * by converting it to sRGB and clipping the channel values | ||
| * so that they're within the [0, 1] range. | ||
| * | ||
| * The result is returned in the color's original color space. | ||
| */ | ||
| export function clampRgb(color: string): Color | undefined; | ||
| export function clampRgb<C extends Color>(color: C): C; | ||
|
|
||
| export function clampChroma(color: string, mode?: Mode, rgbGamut?: GamutMode): Color | undefined; | ||
| /** | ||
| * Given the `mode` color space, returns a function | ||
| * with which to obtain a color that's in gamut for | ||
| * the `mode` color space by clipping the channel values | ||
| * so that they fit in their respective ranges. | ||
| * | ||
| * It's similar to `clampRgb`, but works for any | ||
| * bounded color space (RGB or not) for which | ||
| * any combination of in-range channel values | ||
| * produces an in-gamut color. | ||
| */ | ||
| export function clampGamut<M extends Mode = "rgb">(mode?: M): (color: Color | string) => FindColorByMode<M> | undefined; | ||
|
|
||
| /** | ||
| * Obtain a color that’s in a RGB gamut (by default sRGB) | ||
| * by first converting it to `mode` and then finding | ||
| * the greatest chroma value that fits the gamut. | ||
| * | ||
| * By default, the CIELCh color space is used, | ||
| * but any color that has a chroma component will do. | ||
| * | ||
| * The result is returned in the color's original color space. | ||
| */ | ||
| export function clampChroma( | ||
| color: string, | ||
| mode?: Mode, | ||
| rgbGamut?: GamutMode, | ||
| ): Color | undefined; | ||
| export function clampChroma<C extends Color>(color: C, mode?: Mode, rgbGamut?: GamutMode): C; | ||
|
|
||
| /* | ||
| * Obtain a color that's in the `dest` gamut, | ||
| * by first converting it to the `mode` color space | ||
| * and then finding the largest chroma that's in gamut, | ||
| * similar to `clampChroma`. | ||
| * | ||
| * The color returned is in the `dest` color space. | ||
| * | ||
| * To address the shortcomings of `clampChroma`, which can | ||
| * sometimes produce colors more desaturated than necessary, | ||
| * the test used in the binary search is replaced with | ||
| * "is color is roughly in gamut", by comparing the candidate | ||
| * to the clipped version (obtained with `clampGamut`). | ||
| * The test passes if the colors are not too dissimilar, | ||
| * judged by the `delta` color difference function | ||
| * and an associated `jnd` just-noticeable difference value. | ||
| * | ||
| * The default arguments for this function correspond to the | ||
| * gamut mapping algorithm defined in CSS Color Level 4: | ||
| * https://drafts.csswg.org/css-color/#css-gamut-mapping | ||
| * | ||
| * To disable the “roughly in gamut” part, pass either | ||
| * `null` for the `delta` parameter, or zero for `jnd`. | ||
| */ | ||
| export function toGamut<M extends Mode>( | ||
| dest: M, | ||
| mode: Mode, | ||
| delta?: number | null, | ||
| jnd?: number, | ||
| ): (color: string | Color) => FindColorByMode<M>; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export const bias: number; | ||
| export const bias_cbrt: number; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { Rgb } from "../rgb/types"; | ||
| import { Xyb } from "./types"; | ||
|
|
||
| declare function convertRgbToXyb(rgb: Omit<Rgb, "mode">): Xyb; | ||
|
|
||
| export default convertRgbToXyb; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { Rgb } from "../rgb/types"; | ||
| import { Xyb } from "./types"; | ||
|
|
||
| declare function convertXybToRgb(color: Omit<Xyb, "mode">): Rgb; | ||
|
|
||
| export default convertXybToRgb; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { fixupAlpha } from "../fixup/alpha"; | ||
| import { interpolatorLinear } from "../interpolate/linear"; | ||
| import convertRgbToXyb from "./convertRgbToXyb"; | ||
| import convertXybToRgb from "./convertXybToRgb"; | ||
|
|
||
| declare const definition: { | ||
| mode: "xyb"; | ||
| parse: ["xyz-d50", "--xyz-d50"]; | ||
| serialize: "xyz-d50"; | ||
|
|
||
| toMode: { | ||
| rgb: typeof convertXybToRgb; | ||
| }; | ||
|
|
||
| fromMode: { | ||
| rgb: typeof convertRgbToXyb; | ||
| }; | ||
|
|
||
| channels: ["x", "y", "z", "alpha"]; | ||
|
|
||
| ranges: { | ||
| x: [0, 0.964]; | ||
| y: [0, 0.999]; | ||
| z: [0, 0.825]; | ||
| }; | ||
|
|
||
| interpolate: { | ||
| x: typeof interpolatorLinear; | ||
| y: typeof interpolatorLinear; | ||
| b: typeof interpolatorLinear; | ||
| alpha: { use: typeof interpolatorLinear; fixup: typeof fixupAlpha }; | ||
| }; | ||
| }; | ||
|
|
||
| export default definition; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export interface Xyb { | ||
| mode: "xyb"; | ||
| x: number; | ||
| y: number; | ||
| b: number; | ||
| alpha?: number; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,9 @@ | |
| "forceConsistentCasingInFileNames": true | ||
| }, | ||
| "files": [ | ||
| "all/index.d.ts", | ||
| "css/index.d.ts", | ||
| "fn/index.d.ts", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m actually not sure if this change is needed; can revert if so (it seems like |
||
| "index.d.ts", | ||
| "test/average.test.ts", | ||
| "test/blend.test.ts", | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried adding
"contributors"like your original suggestion, but was getting linting errors. It seemed to prefer"owners"only inpackage.json, if this is OK.