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

Color format adjustments #257

Open
wants to merge 7 commits into
base: color-first-draft
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions technical-reports/color/color-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ For example, initially color tokens may be defined as such:

```json
{
"Majestic magenta": {
"Hot pink": {
"$type": "color",
"$value": {
"$hex": "#ff00ff"
Copy link
Contributor

Choose a reason for hiding this comment

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

For this file, we should just define it in the srgb space, and we don’t need the hex fallback:

Suggested change
"$hex": "#ff00ff"
"colorSpace": "srgb",
"channels": [1, 0, 1]

Here and below they should follow the same format

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback! No changes have been added to this file yet. Once we get alignment on the rest, we can make adjustments throughout here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion: it is easier to review if this PR made everything consistent in all files, since that has to be done one way or another. Otherwise it ends up in a state of confusion not being able to tell where the proposal starts and where it ends. Would it be OK to just make everything a consistent format so it’s clear to reviewers?

Expand All @@ -52,7 +52,7 @@ Then, the output file may look something like:

```scss
// colors-hex.scss
$majestic-magenta: #ff00ff;
$hot-pink: #ff00ff;
$translucent-shadow: #00000080;
```

Expand All @@ -75,20 +75,20 @@ For example, initially color tokens may be defined as such:

```json
{
"Majestic magenta": {
"Hot pink": {
"$type": "color",
"$value": {
"$hex": "#c44587",
"$hex": "#ff00ff",
"$colorSpace": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Here, and below, these should align with the current spec:

Suggested change
"$colorSpace": {
"colorSpace": "srgb",
"channels": [1, 0, 1],

Copy link
Author

Choose a reason for hiding this comment

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

See above comment

"name": "srgb",
"$components": [196, 69, 135]
}
}
},
"Simple sage": {
"Acid green": {
"$type": "color",
"$value": {
"$hex": "#b4d8a7",
"$hex": "#00ff66",
"$colorSpace": {
"name": "srgb",
"$components": [180, 216, 167],
Expand All @@ -107,8 +107,8 @@ Then, the output from a tool’s conversion to RGBA may look something like:

```scss
// colors-rgba.scss
$majestic-magenta: rgba(196, 69, 135, 1);
$simple-sage: rgba(180, 216, 167, 0.75);
$hot-pink: rgba(255, 0, 255, 1);
$acid-green: rgba(0, 255, 102, 1);
```

</aside>
Expand All @@ -125,20 +125,20 @@ Formatted in H (hue), S (saturation), L (lightness) and an optional (A) alpha. H

```json
{
"Majestic magenta": {
"Hot pink": {
"$type": "color",
"$value": {
"$hex": "#c44587",
"$hex": "#ff00ff",
"$colorSpace": {
"name": "hsl",
"$components": [329, 0.52, 0.52]
}
}
},
"Simple sage": {
"Acid green": {
"$type": "color",
"$value": {
"$hex": "#b4d8a7",
"$hex": "#00ff66",
"$colorSpace": {
"name": "hsl",
"$components": [104, 0.39, 0.75],
Expand All @@ -157,8 +157,8 @@ Then, the output variables may look like:

```scss
// colors-hsl.scss
$majestic-magenta: hsl(329, 52%, 52%);
$simple-sage: hsl(104, 39%, 74%, 0.75);
$hot-pink: hsl(300, 100%, 50%);
$acid-green: hsl(144, 100%, 50%, 0.75);
```

</aside>
Expand All @@ -177,16 +177,16 @@ Hex8 uses two extra digits, known as the alpha value, to change the transparency

```json
{
"Majestic magenta": {
"Hot pink": {
"$type": "color",
"$value": {
"$hex": "#c4458780"
"$hex": "#ff00ff"
}
},
"Simple sage": {
"Acid green": {
"$type": "color",
"$value": {
"$hex": "#b4d8a780"
"$hex": "#00ff66"
}
}
}
Expand All @@ -200,12 +200,12 @@ Then, the output variables may look like:

```scss
// colors-hex.scss
$majestic-magenta: #c4458780;
$simple-sage: #b4d8a780;
$hot-pink: #ff00ff;
$acid-green: #00ff66;

// colors-rgba.scss
$majestic-magenta: rgba(196, 69, 135, 0.5);
$simple-sage: rgba(180, 216, 167, 0.5);
$hot-pink: rgba(255, 0, 255, 1);
$acid-green: rgba(0, 255, 102, 1);
```

</aside>
Expand Down
2 changes: 1 addition & 1 deletion technical-reports/color/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
latestVersion: null,
edDraftURI: null,
editors: [
{ name: 'Adekunle Oduye', url: 'https://www.adekunleoduye.com/' },
{ name: 'Adekunle Oduye', url: 'http://twitter.com/adekunleoduye' },
{
name: 'Ayesha Mazrana (Mazumdar)',
url: 'https://twitter.com/AyeshaKMaz',
Expand Down
2 changes: 1 addition & 1 deletion technical-reports/color/token-naming.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export const SubbrandContext = React.createContext();

const Theme = React.forwardRef(function Theme(
{ theme = 'light', subbrand, children },
forwardedRef
forwardedRef,
) {
return (
<SubbrandContext.Provider value={subbrand}>
Expand Down
4 changes: 2 additions & 2 deletions technical-reports/format/composite-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ Describes a gradient that is solid yellow for the first 2/3 and then fades to re
{
"brand-primary": {
"$type": "color",
"$value": "#99ff66"
"$value": "#00ff66"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"$value": "#00ff66"
"$value": {
"colorSpace": "srgb",
"channels": [0, 1, 0.4]

Copy link
Author

Choose a reason for hiding this comment

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

I can make this update in the interim. The color format editors have a different proposal for color gradient, and we should sync with format to align/make recommendations for community feedback.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK! Yes breaking out changes to gradient as a separate PR would be easier to review! This PR shouldn’t introduce any changes to gradient. Because, yes, gradients do use colors, that doesn’t mean gradients change necessarily. Then we can review those unique changes easier

},

"position-end": {
Expand Down Expand Up @@ -453,7 +453,7 @@ Describes a gradient that is solid yellow for the first 2/3 and then fades to re

Describes a color token called "brand-primary", which is referenced as the mid-point of a gradient is black at either end.

<div style="height: 2rem; background: linear-gradient(90deg, #000000, #99ff66, #000000);"></div>
<div style="height: 2rem; background: linear-gradient(90deg, #000000, #00ff66, #000000);"></div>

</aside>

Expand Down
20 changes: 10 additions & 10 deletions technical-reports/format/groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Group keys without a dollar sign (`$`) prefix denote:
"$description": "This is an example of a group containing a single token",
"Token name": {
"$value": "#000000",
resource11 marked this conversation as resolved.
Show resolved Hide resolved
"$type": "color",
"$type": "color"
}
}
}
Expand All @@ -95,11 +95,11 @@ Group keys without a dollar sign (`$`) prefix denote:
"Subgroup of tokens": {
"Token 1 name": {
"$value": "#aabbcc",
"$type": "color",
"$type": "color"
},
"Token 2 name": {
"$value": "#ddeeff",
"$type": "color",
"$type": "color"
}
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ For example:
"$type": "color"
},
"hot pink": {
"$value": "#dd22cc",
"$value": "#ff00ff",
"$type": "color"
}
}
Expand Down Expand Up @@ -162,7 +162,7 @@ For example:
"$value": "#00ff66"
},
"hot pink": {
"$value": "#dd22cc"
"$value": "#ff00ff"
}
}
}
Expand Down Expand Up @@ -199,7 +199,7 @@ Note that, since a group's `$extensions` only relate to that group, they do not
"$type": "color"
},
"hot pink": {
"$value": "#dd22cc",
"$value": "#ff00ff",
"$type": "color"
}
}
Expand Down Expand Up @@ -230,7 +230,7 @@ For example:
"$value": "#00ff66"
},
"hot pink": {
"$value": "#dd22cc"
"$value": "#ff00ff"
}
},
"typeface": {
Expand Down Expand Up @@ -259,7 +259,7 @@ For example:
"$type": "color"
},
"brand-color-hot-pink": {
"$value": "#dd22cc",
"$value": "#ff00ff",
"$type": "color"
},
"brand-typeface-primary": {
Expand Down Expand Up @@ -301,7 +301,7 @@ For example, a [=translation tool=] like [Style Dictionary](https://amzn.github.
"$value": "#00ff66"
},
"hot pink": {
"$value": "#dd22cc"
"$value": "#ff00ff"
}
},
"typeface": {
Expand All @@ -325,7 +325,7 @@ For example, a [=translation tool=] like [Style Dictionary](https://amzn.github.

```scss
$brand-color-acid-green: #00ff66;
$brand-color-hot-pink: #dd22cc;
$brand-color-hot-pink: #ff00ff;
$brand-typeface-primary: 'Comic Sans MS';
$brand-typeface-secondary: 'Times New Roman';
```
Expand Down
11 changes: 1 addition & 10 deletions technical-reports/format/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@
latestVersion: 'https://tr.designtokens.org/format/',
edDraftURI: null,
editors: [
{ name: 'Adekunle Oduye', url: 'https://www.adekunleoduye.com/' },
{
name: 'Ayesha Mazrana (Mazumdar)',
url: 'https://twitter.com/AyeshaKMaz',
},
{ name: 'Daniel Banks', url: 'https://twitter.com/dbanksDesign' },
{ name: 'Donna Vitan', url: 'https://www.donnavitan.com/' },
{ name: 'Drew Powers', url: 'https://pow.rs/' },
{ name: 'Donna Vitan', url: 'http://twitter.com/donnavitan' },
{ name: 'James Nash', url: 'https://cirrus.twiddles.com/' },
{ name: 'Kathleen McMahon', url: 'https://kathleenmcmahon.dev' },
{ name: 'Kevin Powell', url: 'https://twitter.com/kevinmpowell' },
{ name: 'Louis Chenais', url: 'https://twitter.com/chuckn0risk' },
{ name: 'Mike Kamminga', url: 'https://twitter.com/mikekamminga' },
{ name: 'Matthew Ström', url: 'https://matthewstrom.com/' },
],

github: {
Expand Down
39 changes: 30 additions & 9 deletions technical-reports/format/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,42 @@ If an explicit type is set, but the value does not match the expected syntax the

## Color

Represents a 24bit RGB or 24+8bit RGBA color in the sRGB color space. The `$type` property MUST be set to the string `color`. The `$value` property MUST be a string containing a [hex triplet/quartet](https://www.w3.org/TR/css-color-4/#typedef-hex-color) including the preceding `#` character. To support other color spaces, such as HSL, translation tools SHOULD convert color tokens to the equivalent value as needed.
Represents a color in the UI. The `$type` property MUST be set to the string `color`. The `$value` property MUST be an object string containing a string `colorSpace`, a numeric `coordinates` array, optional numeric `alpha`, string `colorProfile`, and string `fallback` to support legacy color spaces as needed.

| Key | Type | Required | Description |
| :------------- | :------------: | :------: | :--------------------------------------------------------------------------------------------------------------------------------------- |
| `colorSpace` | `string` | Y | An string representing the color space. |
Copy link
Contributor

@drwpow drwpow Nov 10, 2024

Choose a reason for hiding this comment

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

Note: we could probably link to all the valid values from CSS Color Module 4 (or possibly 5, if we want to extend to that) edit: let’s limit to 4, and only propose 5 in a followup

Suggested change
| `colorSpace` | `string` | Y | An string representing the color space. |
| `colorSpace` | `string` | Y | A string representing the color space. |

| `colorProfile` | `string` | | String representing url of color profile. |
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we are not using colorProfile, and just aligning with CSS Color Module 4? colorSpace is a shorthand for space + profile + gamut, also borrowing from the same spec

Suggested change
| `colorProfile` | `string` | | String representing url of color profile. |

Copy link
Author

Choose a reason for hiding this comment

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

In CSS Color Module 4 color terminology section, here's the definition of color space:

A color space is an organization of colors with respect to an underlying colorimetric model, such that there is a clear, objectively-measurable meaning for any color in that color space. This also means that the same color can be expressed in multiple color spaces, or transformed from one color space to another, while still looking the same.

Color profile is different, it's about using a particular ICC color profile for device specific implementations (print, for example). For example, you can use the CMYK color space and choose more than one color profile to implement those colors.

Copy link
Contributor

Choose a reason for hiding this comment

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

You’re 100% right, and yes I do see us needing this. As we talked about earlier today, perhaps we limit this initial PR to CSS Color Module 4 where:

  • only colorSpace is used
  • colorSpace is limited to the allowed values in CSS Color Module 4 (srgb, srgb-linear, display-p3, etc.)

Then, we open a separate PR to expand the format to include CSS Color Module 5’s concept of @color-profile. That way we can get feedback on that separately. Not being prescriptive, but if we copy CSS Color Module 5’s mental model, I could see it introducing a new $type: 'colorProfile' token type that maps 1:1 to @color-profile (perhaps; maybe we think of another pattern!)

| `coordinates` | `number array` | Y | An array of numeric values representing individual color coordinates. |
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we were leaning toward “channels” being the term. Also just in the interest of being really specific, “an array” doesn’t specify the length of the list. Calling it a “tuple of 3 values” means that the values must always be 3—no more, no less. Just like any color in CSS, I think we should enforce that the length is always 3, no matter what.

Suggested change
| `coordinates` | `number array` | Y | An array of numeric values representing individual color coordinates. |
| `channels` | `[number, number, number]` | Y | Tuple of 3 numbers representing the 3 components of the color space. The allowed ranges depend on the `colorSpace` specified. |

Copy link
Author

@resource11 resource11 Nov 14, 2024

Choose a reason for hiding this comment

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

Yes, we were leaning towards that!

The terms component and channel were used in different capacities in the W3C CSS Color Level docs, sometimes interchangeably. I agree that we should standardize terminology and clarify what this means.

For example in the CSS Color Level 4 color type definition it reads:

Colors in CSS are represented as a list of color components, also sometimes called “channels”, representing axises in the color space. Each channel has a minimum and maximum value, and can take any value between those two. Additionally, every color is accompanied by an alpha component, indicating how transparent it is, and thus how much of the backdrop one can see through the color.

The CSS Color Level 5 spec builds upon Level 4, yet the terminology is still interchangeable.

In ColorJS, the term "coordinates" could be shorthand for component coordinate or channel coordinate if I assume correctly (need to confirm).

Happy to move back to channels for now.

Also, I suggest we adjust wording to include none along with numbers in the allowable channel value types, to account for 4.4“Missing” Color Components and the none Keyword support.

Choose a reason for hiding this comment

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

Also, I suggest we adjust wording to include none along with numbers in the allowable channel value types, to account for 4.4“Missing” Color Components and the none Keyword support.

Oh smart! I like the idea of aligning with all that great thinking as much as possible

Copy link
Author

Choose a reason for hiding this comment

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

Yes, there have been interest in this support in the legacy color thread!

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh also I think as I said in another comment, maybe we like components better and that’s fine with me! I don’t have any strong opinions. We could decide on the exact words at the last minute without it changing the proposal too much.

Copy link
Contributor

Choose a reason for hiding this comment

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

Calling it a “tuple of 3 values” means that the values must always be 3—no more, no less.

This should be an array of arbitrary length.
CMYK for example has 4 channels.
Other print profiles might have many more for spot colors and varnishes.

Defining these as arrays now means that implementers are less likely to make assumptions that these will always have a length of 3.

| `alpha` | `number` | | An integer or floating-point value representing the numeric value. |
Copy link
Contributor

Choose a reason for hiding this comment

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

We should specify this MUST be in the range of (0, 1) (inclusive). 0 = 0%, 1 = 100%.

Copy link
Author

Choose a reason for hiding this comment

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

Can do. Where should this sentence occur?

Copy link
Contributor

Choose a reason for hiding this comment

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

Anywhere in the alpha description

| `fallback` | `string` | | Unit of distance. Supported values: [HEX 6](https://www.w3.org/TR/css-color-4/#typedef-hex-color) including the preceding `#` character. |
resource11 marked this conversation as resolved.
Show resolved Hide resolved

For example, initially the color tokens MAY be defined as such:

<aside class="example">

```json
resource11 marked this conversation as resolved.
Show resolved Hide resolved
{
"Majestic magenta": {
"$value": "#ff00ff",
"$type": "color"
"Hot pink": {
"$type": "color",
"$value": {
"colorSpace": "display-p3",
"colorProfile": "http://example.org/display-p3.icc",
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below, the format should match the updated syntax of colorSpace + channels + alpha (optional) + hex (optional)

Suggested change
"colorProfile": "http://example.org/display-p3.icc",
"channels": [0.92, 0.2, 0.97],
"hex": "#ff00ff" // HEX 6 supported only

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for this suggestion! I should clarify why the optional colorProfile is listed here. I was thinking of the cases for print where a specific color profile should be associated with the color space for conversion. Perhaps we do a separate callout for this and use CMYK as the color space example.

"coordinates": [0.92, 0.2, 0.97],
"alpha": 1,
"fallback": "#ff00ff" // HEX 6 supported only
}
},
"Translucent shadow": {
"$value": "#00000080",
"$type": "color"
"$value": "#000000",
Copy link
Contributor

Choose a reason for hiding this comment

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

Intentional to have two value fields?

"$type": "color",
"$value": {
"colorSpace": "display-p3",
"colorProfile": "http://example.org/display-p3.icc",
"coordinates": [0, 0, 0],
"alpha": 0.5,
"fallback": "#000000" // HEX 6 supported only
}
}
}
```
Expand All @@ -39,12 +60,12 @@ Then, the output from a tool's conversion to HSL(A) MAY look something like:

```scss
// colors-hex.scss
$majestic-magenta: #ff00ff;
$hot-pink: #ff00ff;
$translucent-shadow: #00000080;

// colors-hsl.scss
$majestic-magenta: hsl(300, 100%, 50%);
$translucent-shadow: hsla(300, 100%, 50%, 0.5);
$hot-pink: hsl(300, 100%, 50%);
$translucent-shadow: hsla(0, 0%, 0%, 0.5);
```

</aside>
Expand Down
Loading