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-typed-om] Should a type have a null percent hint to match <number>? #10763

Closed
cdoublev opened this issue Aug 21, 2024 · 5 comments
Closed

Comments

@cdoublev
Copy link
Collaborator

Before w3c/css-houdini-drafts@808c87a, a type always had to have a null percent hint to match <number>.

Now:

If the context in which the value is used does not allow <percentage> values, then the type must additionally have a null percent hint to be considered matching.

opacity: calc((1% + 1px) / 1px) is now valid if I am not mistaken, which seems unexpected because what is the resolved value of 1%?

  • the context allows <number> and <percentage> (resolved to <number>)
  • 1% has type [percent → 1]
  • 1% + 1px has type [length → 1] with a length percent hint
  • (1% + 1px) / 1px has type [length → 0] with a length percent hint
  • [length → 0] with a length percent hint matches <number>
@cdoublev
Copy link
Collaborator Author

cdoublev commented Aug 21, 2024

However, based from #10017 (comment):

things like height: calc(sqrt(50% / 1px) * 1px) should work

So to match <number>, maybe the percent hint should match the type that <percentage> resolves to, if the type has a percent hint.


Suggested text:

A type is said to match a CSS production in some circumstances:

  • A type matches <length> if its only non-zero entry is «[ "length" → 1 ]». Similarly for <angle>, <time>, <frequency>, <resolution>, <flex>, and <percentage>.
  • A type matches <number> if it has no non-zero entries.

If the type has a percent hint, its value must match the type that <percentage> resolves to in the context.

cdoublev added a commit to cdoublev/css that referenced this issue Aug 22, 2024
- a non-null percent hint must match the percentage resolution type (w3c/csswg-drafts#10763)
- trigonometric functions, pow(), sqrt(), log(), exp(), must accept <percentage> resolving to <number>/<angle> (w3c/csswg-drafts#10765)
- pow() and log() calculations must not need to have consistent types
cdoublev added a commit to cdoublev/css that referenced this issue Aug 22, 2024
- a non-null percent hint must match the percentage resolution type (w3c/csswg-drafts#10763)
- trigonometric functions, pow(), sqrt(), log(), exp(), must accept <percentage> resolving to <number>/<angle> (w3c/csswg-drafts#10765)
- pow() and log() calculations must not need to have consistent types
@tabatkins
Copy link
Member

Ah, indeed, matching number needs some more nuance there.

tabatkins added a commit to w3c/css-houdini-drafts that referenced this issue Aug 22, 2024
@tabatkins
Copy link
Member

Okay, tweaked the definitions a little in w3c/css-houdini-drafts@d384226 to pay more attention to the percent hint, when you have context for the value's use.

Your 'opacity' example is now properly invalid, as 'opacity' does not resolve percentages against any other type, so it requires the calculation to have a null percent hint.

@cdoublev
Copy link
Collaborator Author

cdoublev commented Aug 23, 2024

Thanks!

I am aware that the algorithm has to account for inputs that cannot be produced in a style sheet but with handmade CSSNumericValues. For example, a type [length → 1] with angle percent hint matching <length> in a context defined with <angle-percentage>.

That said, would you say that all context/percentage conditions can be simplified to "if the type has a percent hint, this percent hint must match the type that <percentage> resolves to in the context"?

@tabatkins
Copy link
Member

I think so, yes.

triple-underscore added a commit to triple-underscore/triple-underscore.github.io that referenced this issue Oct 9, 2024
Allow percent hints of 'percent' for cases where %s are kept as themselves.
w3c/css-houdini-drafts@3d51716

Tweak the validity of matching when you have a percent hint to be more correct. w3c/csswg-drafts#10763
w3c/css-houdini-drafts@d384226
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

2 participants