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

Parse both dashed-ident and ident versions, and add missing dashed-idents to color spaces. #439

Merged
merged 7 commits into from
Feb 19, 2024

Conversation

jgerigmeyer
Copy link
Member

@jgerigmeyer jgerigmeyer commented Feb 14, 2024

Partial solution for #433, as an alternative to #435.

This PR makes a few changes, and I'm not tied strongly to any of them -- this is a starting point for discussion.

  • Parses both <dashed-ident> and <ident> versions of color() spaces, warning if e.g. color(rec2100-hlg) is used instead of color(--rec2100-hlg), and similarly if color(--display-p3) is used instead of color(display-p3).
  • Simplifies color space options, where now every color gets formats.color.id defined if it's missing -- defaults to cssId if provided, otherwise id.
  • Adds missing cssId option to color spaces, using dashed-ident where appropriate, and removes unnecessary formats.color definitions.
  • Adds parsing tests for all missing color spaces.

This PR does not attempt to auto-generate coordGrammer for color spaces.

This shouldn't be a breaking change in terms of parsing colors (and it does fix #433), but it is a breaking change in the sense that now e.g. color(acescc) will be serialized as color(--acescc).

Copy link

netlify bot commented Feb 14, 2024

Deploy Preview for colorjs ready!

Name Link
🔨 Latest commit da4dcb3
🔍 Latest deploy log https://app.netlify.com/sites/colorjs/deploys/65cfc009e20ade0008cac2c5
😎 Deploy Preview https://deploy-preview-439--colorjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@lloydk lloydk left a comment

Choose a reason for hiding this comment

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

Should the HDR color spaces in CSS Color HDR Module Level 1 have a <dashed-ident>?

Will we remove the <dashed-ident> cssId as a breaking change if/when the HDR spaces are implemented in browsers?

I think we should go with unprefixed ids for the HDR spaces as they'll most likely be made a standard part of CSS.

Overall I prefer this PR to #435.

src/spaces/prophoto-linear.js Show resolved Hide resolved
src/parse.js Show resolved Hide resolved
@jgerigmeyer
Copy link
Member Author

Should the HDR color spaces in CSS Color HDR Module Level 1 have a ?

I think we should go with unprefixed ids for the HDR spaces as they'll most likely be made a standard part of CSS.

I went with <dashed-ident> for color spaces that aren't currently part of the spec even if they will be added, but I'm fine with whatever @LeaVerou prefers here.

Will we remove the cssId as a breaking change if/when the HDR spaces are implemented in browsers?

Yes, my assumption is that as colors are added to the spec and implemented in browsers, we will remove the dashed-ident from their cssId. It's not entirely a breaking change in that we will still parse those colors with or without the prefix, but it would mean that they would be serialized without the dashed-ident going forward.

Overall I prefer this PR to #435.

🎉

src/parse.js Outdated
@@ -102,17 +103,24 @@ export default function parse (str, {meta} = {}) {
Object.assign(meta, {formatId: "color", types});
}

if (colorSpec.id.startsWith("--") && !id.startsWith("--")) {
console.warn(`Use prefixed color(${colorSpec.id}) instead of color(${id}).`);
Copy link
Member

Choose a reason for hiding this comment

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

We need to clarify why this distinction exists, otherwise the warning makes it sound like Color.js is annoying for no reason. E.g. something like:

Suggested change
console.warn(`Use prefixed color(${colorSpec.id}) instead of color(${id}).`);
console.warn(`${space.name} is a non-standard space, so you should use color(${colorSpec.id}) instead of color(${id}).`);

Copy link
Member Author

Choose a reason for hiding this comment

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

@LeaVerou Adjusted in b1cf95a -- what do you think?

src/parse.js Show resolved Hide resolved
@@ -14,6 +14,7 @@ const fromXYZ_M = [

export default new RGBColorSpace({
id: "p3-linear",
cssId: "--display-p3-linear",
Copy link
Member

Choose a reason for hiding this comment

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

Oof. I understand why it's as awkward as it is, but it makes me sad.

I wonder if it may make sense to allow providing multiple dashed ids, so we could also provide --p3-linear but that's a out of scope for this PR…

Copy link
Member

@svgeesus svgeesus Feb 16, 2024

Choose a reason for hiding this comment

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

we should not have called it just "p3" because that is ambiguous. Cinema uses DCI-P3, video uses P3-D65 and CSS (among other things) uses Display-P3.

src/spaces/p3.js Outdated Show resolved Hide resolved
Copy link
Member

@LeaVerou LeaVerou left a comment

Choose a reason for hiding this comment

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

This is fantastic work @jgerigmeyer, thank you so much for working on this!!

My only substantive comment at this point is that I'd prefer to keep the trailing commas to keep the diff small, but even that I wouldn't elevate it to a blocker.

Copy link
Collaborator

@lloydk lloydk left a comment

Choose a reason for hiding this comment

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

LGTM

* main:
  Enforce trailing commas unless `]` or `}` is on the same line. (#440)
  Update index.html
  Update color-swatch.css
  lint
  [apps/gamut-mapping] Support multiple colors
  [apps/gamut-mapping] Show favicon and title immediately, not just when color changes
  [apps/gamut-mapping] Prepare HTML & CSS for supporting multiple colors
@svgeesus
Copy link
Member

I like the idea of parsing both the dashed and undashed forms.

I went with <dashed-ident> for color spaces that aren't currently part of the spec even if they will be added, but I'm fine with whatever @LeaVerou prefers here.

Note that CSS Color HDR is now an official CSSWG spec, building on CSS Color 4 which remains SDR-only. So we should not have dashed idents for things already part of that spec.

See also:

src/spaces/ictcp.js Outdated Show resolved Hide resolved
src/spaces/jzazbz.js Outdated Show resolved Hide resolved
src/spaces/jzczhz.js Outdated Show resolved Hide resolved
@@ -14,6 +14,7 @@ const fromXYZ_M = [

export default new RGBColorSpace({
id: "p3-linear",
cssId: "--display-p3-linear",
Copy link
Member

@svgeesus svgeesus Feb 16, 2024

Choose a reason for hiding this comment

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

we should not have called it just "p3" because that is ambiguous. Cinema uses DCI-P3, video uses P3-D65 and CSS (among other things) uses Display-P3.

src/spaces/rec2100-hlg.js Outdated Show resolved Hide resolved
src/spaces/rec2100-pq.js Outdated Show resolved Hide resolved
@jgerigmeyer
Copy link
Member Author

Note that CSS Color HDR is now an official CSSWG spec, building on CSS Color 4 which remains SDR-only. So we should not have dashed idents for things already part of that spec.

@svgeesus Adjusted in da4dcb3

Copy link
Member

@svgeesus svgeesus left a comment

Choose a reason for hiding this comment

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

LGTM

@jgerigmeyer jgerigmeyer merged commit d6f6836 into main Feb 19, 2024
5 checks passed
@jgerigmeyer jgerigmeyer deleted the missing-space-formats branch February 19, 2024 16:12
jgerigmeyer added a commit that referenced this pull request Feb 19, 2024
* main:
  [ci] Update lint rules for PR's (#444)
  Parse both dashed-ident and ident versions, and add missing dashed-idents to color spaces. (#439)
  [types] Fix formatting in `toGamut.d.ts` (#445)
  [types] Add JSDoc based on website docs (#436)
ardov pushed a commit to ardov/color.js that referenced this pull request Feb 27, 2024
…ents to color spaces. (color-js#439)

* Parse both dashed-ident and ident versions, and add missing dashed-idents to color spaces.

* Warn when using incorrect dashed-ident/ident

* refactor

* Update warnings

* Add trailing commas and make warning more descriptive.

* Remove dashed-ident prefix for HDR colors.
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.

(Some) nonstandard color spaces error when round-tripping
4 participants