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-4] Allow src() to take multiple arguments #6717

Closed
LeaVerou opened this issue Oct 8, 2021 · 3 comments
Closed

[css-values-4] Allow src() to take multiple arguments #6717

LeaVerou opened this issue Oct 8, 2021 · 3 comments
Labels
Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-values-4 Current Work css-values-5

Comments

@LeaVerou
Copy link
Member

LeaVerou commented Oct 8, 2021

In #541 we resolved to add src() as a url() alias without the weird parsing rules around unquoted strings that prevent url() from containing var() references, and @tabatkins made the edits.

However, for var() to truly be useful with URLs and cover the main use cases, there are two more pieces of the puzzle: concatenation and casting to string. There is #542 where we discuss proposals for syntax to do both, but so far they have not reached enough consensus (although there is mostly consensus on the necessity).

I was thinking, since the main use case for concatenating strings and casting to string is building dynamic URLs (especially SVG data URIs), what if we just allow src() to take multiple arguments, and concatenate (and cast, as needed) the result?

E.g. something like this would then work:

select {
	background-image: src('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 50">\
		<path d="m 20 10 L 50 40 L 80 10" fill="none" stroke="', currentColor, '" stroke-opacity=".4" stroke-width="13" stroke-linejoin="round" stroke-linecap="round" />\
	</svg>');
}

Which would address a lot of today's hacks wrt icons in one fell swoop.

@LeaVerou LeaVerou added the css-values-4 Current Work label Oct 8, 2021
@fantasai
Copy link
Collaborator

fantasai commented Oct 8, 2021

One of the main reasons to have src() was also to allow it to take multiple arguments, see e.g. #1603 so whatever syntax you want to introduce for string concatenation needs to be compatible with that as well.

Overall, I think I'd rather introduce syntax for general concatenation, even if we only allow it within src() for now, rather than do something specific to src() that complicates our ability to expand its syntax later.

@tabatkins
Copy link
Member

Yeah, given that one of the "casting" use-cases is keyword->string, building this directly into src() seems a little fraught with the other fetch-controlling keywords we've been planning to add to url()/src() forever.

Speccing out string() or whatever wouldn't be any more effort than speccing the exact same behavior in src(), so let's just do that.

@LeaVerou
Copy link
Member Author

LeaVerou commented Oct 9, 2021

Fair enough. And it would be strictly more powerful too. I'm gonna go ahead and close this then.

@LeaVerou LeaVerou closed this as completed Oct 9, 2021
@LeaVerou LeaVerou added the Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. label Oct 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Commenter Satisfied Commenter has indicated satisfaction with the resolution / edits. css-values-4 Current Work css-values-5
Projects
None yet
Development

No branches or pull requests

3 participants