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

[css-images-4] Restriction on <percentage> values in stripes() #9551

Open
cdoublev opened this issue Nov 2, 2023 · 4 comments
Open

[css-images-4] Restriction on <percentage> values in stripes() #9551

cdoublev opened this issue Nov 2, 2023 · 4 comments

Comments

@cdoublev
Copy link
Collaborator

cdoublev commented Nov 2, 2023

<percentage> is currently restricted to [0,100] in stripes() otherwise the function is invalid:

<color-stripe> = <color> && [ <length-percentage> | <flex> ]?

  • <percentage [0,100]>: [...] Only values between 0% and 100% (inclusive) are valid.
  • <length [0,∞]> : [...] Negative length values are invalid.

I agree with #9516 (comment) that values outside this range are meaningless.

But then I am not sure why they make sense in <alpha-value> or <brightness()> (for example), which produce different animating behaviors (because <alpha-value> is clamped at parse time).

However my main concern is <length-percentage> expanding to <length [0,∞]> | <percentage [0,100]>, which is not great for grammar driven parser, therefore I suggest this change:

- <color-stripe> = <color> && [ <length-percentage> | <flex> ]?
+ <color-stripe> = <color> && [ <length [0,∞]> | <percentage [0,100]> | <flex> ]?

Note that <length-percentage [0,]> is not problematic because [0,] can be "inherited" during expansion.

@Loirooriol
Copy link
Contributor

Yeah, I don't think it makes much sense to forbid 101% but allow calc(1px / 0).

And as you say the grammar uses <length-percentage>, it's not clear how the restriction applies to e.g. calc(101% - 100px).

But rather than dropping <length-percentage>, I would just drop the restriction and define it correctly.

@cdoublev
Copy link
Collaborator Author

cdoublev commented Nov 3, 2023

I do not think calc(-1% + 1%) should be an invalid <percentage [0,100]> and:

Parse-time range-checking of values is not performed within math functions, and therefore out-of-range values do not cause the declaration to become invalid.

https://drafts.csswg.org/css-values-4/#calc-range

But I wonder why some values are invalid when out of range, instead of being consistently clamped at computed value time, so I am also fine with dropping the restriction. Cc @SebastianZ, who may disagree.

@SebastianZ
Copy link
Contributor

Clamping the values instead of disallowing them seems fine to me. Question is whether it should happen at computed value time as suggested by @cdoublev or already at parsed value time to be consistent with <alpha-value>.

Sebastian

@Loirooriol
Copy link
Contributor

I don't think this needs to be consistent with <alpha-value>, which is a pure percentage, here percentages resolve against a length and have type «[ "length" → 1 ]» so it's an entirely different situation.

So I would just rely on

The total width is defined by the context in which the stripes() function is used. If the sum of the stripes is smaller than the total width, the paint line is transparent black for its remaining length, as if a final transparent argument were given. If the sum is larger, any stripes or portions beyond the total width are truncated.

I don't see the need to truncate individual values at all.

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

No branches or pull requests

3 participants