Skip to content

Conversation

@JakeQZ
Copy link
Collaborator

@JakeQZ JakeQZ commented Jan 27, 2025

The "legacy" syntax does not allow a mixture of percentages and numbers for the red, green and blue components.
So if rgb/rgba functions that have such a mixture are rendered in the "legacy" syntax, an invalid property value will result.

An OutputFormat option to use the "modern" syntax throughout will be added later (see #801).

@JakeQZ JakeQZ added bug enhancement css4 Relating to features introduced in CSS4 labels Jan 27, 2025
@JakeQZ JakeQZ self-assigned this Jan 27, 2025
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jan 27, 2025

This is part-bug, part-feature. It could be viewed as a bug in the new feature, or just a continuation of the implementation of that feature.

@coveralls
Copy link

coveralls commented Jan 27, 2025

Coverage Status

coverage: 45.006% (+1.0%) from 44.039%
when pulling ecaccc5 on feature/color/render-modern
into e24aa71 on main.

The "legacy" syntax does not allow a mixture of `percentage`s and `number`s
for the red, green and blue components.
So if `rgb`/`rgba` functions that have such a mixture are rendered in the
"legacy" syntax, an invalid property value will result.

An `OutputFormat` option to use the "modern" syntax throughout will be added
later (see #801).
@JakeQZ JakeQZ force-pushed the feature/color/render-modern branch from 72df316 to e70a55f Compare January 27, 2025 23:28
Copy link
Collaborator

@oliverklee oliverklee left a comment

Choose a reason for hiding this comment

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

Looks functionally okay to me. I think we can make the code more readable and easier to grok, though. I've left some comments.

private function renderInModernSyntax(OutputFormat $outputFormat): string
{
\end($this->aComponents);
if (\key($this->aComponents) === 'a') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer if we don't rely on $this->aComponents having the associative array keys being in a any particular order. (This also is nothing which we currently can annotate and hence check with PHPStan.)

Instead, we can use array_key_exists or isset.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The order is specific and comes from the CSS function name (e.g. rgba). There's a newer one lab in which a is not alpha. a is only alpha if it is the final element (in all cases I'm aware of).

$alpha = $this->aComponents['a'];
$componentsWithoutAlpha = \array_diff_key($this->aComponents, ['a' => 0]);
} else {
$componentsWithoutAlpha = $this->aComponents;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we use unset, we also don't need the if/else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Except if we want

a local variable $hasAlpha

we might still need an else clause.

Co-authored-by: Oliver Klee <[email protected]>
@JakeQZ JakeQZ force-pushed the feature/color/render-modern branch from ae35316 to 148f265 Compare January 28, 2025 23:38
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jan 29, 2025

I've made most suggested changes, and commented on some as to why they can't be made. There's a remaining dichotomy (I can only make or other of two suggested changes). Hopfully this will be clearer now, with the other changes made...

@JakeQZ JakeQZ requested a review from oliverklee January 29, 2025 01:47
@JakeQZ JakeQZ force-pushed the feature/color/render-modern branch from 84421d4 to e966c06 Compare January 29, 2025 02:28
@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jan 29, 2025

I added some spec links to the latest commit message (re "legacy" and "modern") which will need to be integrated into the final commit message somehow, if desired.

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jan 30, 2025

I've addressed most issues, but there are still two unresolved that require your feedback (see the comments).

@JakeQZ JakeQZ requested a review from oliverklee January 30, 2025 02:56
@oliverklee oliverklee merged commit dbf016e into main Jan 30, 2025
21 checks passed
@oliverklee oliverklee deleted the feature/color/render-modern branch January 30, 2025 09:53
@oliverklee
Copy link
Collaborator

By the way, I see this in the commit messages of your PRs:

Co-authored-by: Jake Hotson <[email protected]>

Are you using two different email addresses? And are both registered in your GitHub account?

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jan 30, 2025

By the way, I see this in the commit messages of your PRs:

Co-authored-by: Jake Hotson <[email protected]>

Are you using two different email addresses? And are both registered in your GitHub account?

I've edited some PR commit messages to have this email address, because I don't want my main one listed on GitHub. I'm getting increasing amounts of spam arising from email addresses being scraped from GitHub. Ideally I would change my GitHib account to use this address, but I suspect that would be some hassle.

@oliverklee
Copy link
Collaborator

Have you tried adding it as an additional email address?

@JakeQZ
Copy link
Collaborator Author

JakeQZ commented Jan 30, 2025

Have you tried adding it as an additional email address?

Didn't know that was possible. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug css4 Relating to features introduced in CSS4 enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants