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-values-5] Should ident() accept <number> and <dimension>? #11551

Closed
tabatkins opened this issue Jan 21, 2025 · 6 comments
Closed

[css-values-5] Should ident() accept <number> and <dimension>? #11551

tabatkins opened this issue Jan 21, 2025 · 6 comments

Comments

@tabatkins
Copy link
Member

Currently, the ident() function is defined to accept <string> | <integer> | <ident>, and serializes these before concatenating them.

This means that ident("foo" 1) is valid (producing the ident foo1), but ident("foo" 1.2) isn't, and ident("foo" calc(1.2)) produces foo1. That seems odd.

Is there a good reason to exclude <number>, and with that, <dimension>? The serialization for numbers is inherently a bit less predictable, of course, due to floating-point, but in common cases it should do what the author expected. (Especially with CSS's "no more than 6 digits after the decimal point", so we avoid things like JS's .1 + .2 yielding 0.30000000000000004.)

@keithamus
Copy link
Member

Floating point is a concern especially with different architectures/languages/platforms. <dimension> serialises lowercase right? Is it surprising that ident("foo" 1FR) would come back as foo1fr?

@bramus
Copy link
Contributor

bramus commented Jan 22, 2025

Is there a good reason to exclude <number>, and with that, <dimension>?

AFAIK dots are not allowed in <custom-ident>, so accepting <number> would result in an invalid value?

@tabatkins
Copy link
Member Author

Dots aren't allowed literally in a custom ident, but you can escape any character into one.

That said, that is an excellent argument against this. (It just means that when we do the string() function it'll have slightly different behavior.)

@LeaVerou
Copy link
Member

LeaVerou commented Jan 22, 2025

Can we get a WG resolution before closing this?

I think it makes sense to exclude <dimension>, but IMO if <integer> is allowed, <number> should also be.

  • calc(1.2) and 1.2 behaving differently is definitely weird.
  • There are many operations that get you into <number> even when all you have is an integer, e.g. calc(12 / 4) IIRC. We should try to avoid the "ugh, I know this is an integer, but how do I explain it to CSS?"

So it seems reasonable to just round <number> if used directly. People can always customize the rounding via round(), but they should not have to use it just to get things working. And if they actually literally want a decimal with a dot, well they can use string() then.

@tabatkins
Copy link
Member Author

tabatkins commented Jan 23, 2025

Can we get a WG resolution before closing this?

As the author of the issue, I'm allowed to withdraw my own comments without a WG resolution. ^_^

There are many operations that get you into even when all you have is an integer, e.g. calc(12 / 4) IIRC. We should try to avoid the "ugh, I know this is an integer, but how do I explain it to CSS?"

This just works already. You'll get a 3, because CSS auto-rounds math functions when used an an <integer>.

So it seems reasonable to just round <number> if used directly.

We purposely don't do that rounding on numeric literals, because it's virtually guaranteed to be a mistake to write a non-integer where an integer is expected. We shouldn't break with our general tradition here.

@astearns astearns moved this from FTF agenda items to Friday morning in CSSWG January 2025 meeting Jan 28, 2025
@bramus
Copy link
Contributor

bramus commented Jan 30, 2025

Discussed this with @tabatkins and @LeaVerou in person over lunch. We agreed to close no change because of the following, as Tab explained:

(#) CSS auto-rounds math functions when used as an <integer>.

Worst-case, authors can choose to wrap things in round().

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

5 participants