w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.44k stars 657 forks source link

[css-values] Add url() alias that does not accept unquoted URLs #541

Closed LeaVerou closed 3 years ago

LeaVerou commented 7 years ago

As discussed with @tabatkins during TPAC.

Due to the special way url() is parsed, var() references cannot be used in it. Building URLs with variables is extremely useful in a number of cases. For example, specifying images independent of the image folder path, building URLs of flags from country codes, creating inline SVG data URIs and many more.

Name of the new function TBB. Tab suggested fetch() but I think that is foreign to authors who don't know JS. Here are a few more ideas: href(), src(), location(), get(), uri(), iri().

css-meeting-bot commented 5 years ago

The CSS Working Group just discussed URL Stuff, and agreed to the following:

The full IRC log of that discussion <fantasai> Topic: URL Stuff
<astearns> github: https://github.com/w3c/csswg-drafts/issues/541
<fantasai> leaverou: Right now ppl cannot ? in url()
<fantasai> leaverou: reason being 1, we didn't have string concatenation
<fantasai> leaverou: but even if we did, you cannot put any function inside url() because of its weird parsing rules
<TabAtkins> s/?/use var()/
<fantasai> leaverou: It has a lot of weird parsing, because of unquoted URLs
<AmeliaBR> Examples for Twitter poll: `content: NAME(var(--percentage)); background: url(NAME("/assets/img", var(--icon-name), ".svg"))`
<fantasai> leaverou: We were thinking we should have another url function that only accepts <string>
<leaverou> Right url(var(--foo)) doesn't work
<fantasai> TabAtkins: Right now if you write url(var()) it'll be invalid
<fantasai> TabAtkins: Interpreted as a URL
<bkardell_> +1
<TabAtkins> fetch("http://example.com")
<fantasai> chris: We need a function that does stuff, I propose calling it fetch()
<fantasai> emilio: It doesn't fetch anything though, only if it's loaded
<florian> uri()
<heycam> q+
<fantasai> AmeliaBR: It's also a very JSy name and not very familiar to designers
<fantasai> AmeliaBR: I would go with href()
<chris> href() is nice actually
<fantasai> astearns: fetch() should have all of fetch()'s semantics which it won't so let's stay away from that
<xfq> ack heycam
<fantasai> chris: iri()!
<florian> +1 to href()
<fantasai> TabAtkins: leave
<fantasai> heycam: It might be nice to have a url function that uses relative URL rules rather than string concatenation
<Rossen> uniform-resource-locator( )
<chris> web-address()
<fantasai> leaverou: I think it would be useful to have a base argument, but not a name like resolve-url(), shoudl be named something...
<fantasai> leaverou: change the base URL
<AmeliaBR> Would it work as a modifier? `url("base.png", relative("assets/images/")`?
<fantasai> heycam: Similar but slightly different use csae
<leaverou> s/but not a name like resolve-url(), shoudl be named something.../but it shouldn't be named after that feature, since there are many use cases where the default resolution is fine/
<fantasai> heycam: But if that did overlap, might indicate a name
<fantasai> myles__: Would such an addition make us not want to do this stringify concat thing also?
<fantasai> chris: no, you need that generally. Just makes designing this easier
<fantasai> leaverou: also consider SVG data URLs with parameters in the SVG
<Rossen> pointer()
<AmeliaBR> q?
<fantasai> fremy: I like address()
<leaverou> s/also consider SVG data URLs with parameters in the SVG/URL resolution is not the only reason you want concat in URLs, e.g. think of SVG data URLs with parameters in the SVG/
<fantasai> heycam: I don't like that it's synonymous with url()
<chris> not-broken-url()
<chris> url++()
<fantasai> astearns: We actually want something that is basically better-URL, exact same semantics except working for all strings
<fantasai> heycam: Are you expecting ppl to use it for non-string-interpolation cases?
<fantasai> [yeah]
<dbaron> either address() or location() is kinda synonymous with url()
<leaverou> url(var(--foo)) is not string interpolation :)
<Rossen> chris, and then we can make it really good by url#()
<fantasai> AmeliaBR: We also talked a few days ago about url() modifiers, I'm assuming we'll create modifiers on the better function?
<chris> amela, yes I expect so
<chris> we are very constrained in how we can evolve url()
<fantasai> AmeliaBR: Any existing support for url modifiers?
<fantasai> No
<fantasai> AmeliaBR: So if we do modifiers, we can do it in the new function
<fantasai> AmeliaBR: No progressive enhancement reason to add new features to a legacy function
<astearns> q?
<fantasai> TabAtkins: No reason not to either
<Rossen> the-url()
<fantasai> chris: Incentive to move to the new one
<chris> u()
<tantek> you could give it inexplicable new capabilities and call it uri()
<jensimmons_> u2()
<fantasai> florian: If we want ppl to use it, then it needs to be a short name like url()
<fantasai> florian: For familiar names we could re-use HTML attribute names like href() or src()
<Rossen> get()
<chris> u2(href, echo-params, looping-params, reverb-level)
<fantasai> dbaron: hypertext-reference?
<tantek> another survey!
<chris> src is nice and short
<fantasai> astearns: From my reading of IRC, ppl like href() and src(), didn't see any other contenders that aren't silly
<bkardell_> fetch potentially wasn't silly imo
<fantasai> dbaron: address() and location() seem OK too
<leaverou> I'd vote for href() over src() because src: src(...) looks a bit weird (or maybe it doesn't?)
<Rossen> clear-winner()
<bkardell_> agree with lea actually
<fantasai> TabAtkins: I suggest polling later
<bkardell_> href() > src()
<leaverou> fantasai: descriptor
<fantasai> RESOLVED: Add a new url function that accepts only <string>, name tbd
<chris> right, we have a src descriptor, which takes a url() currently
<tantek> urls
ExE-Boss commented 4 years ago

I suggest naming the function uri(…), since URIs are a superset of URLs.


It would also match what the Java programming language did to avoid their legacy baggage involving URL processing.

cvrebert commented 4 years ago

https://url.spec.whatwg.org/#goals suggests avoiding URI and IRI (in favor of URL, in general)

tabatkins commented 4 years ago

Yeah, uri() is dead in the water; the concept of URI/IRI is weird and not relevant here, plus it would (incorrectly) imply that this function somehow has more general functionality than url().

Dang tho, it's been 18 months here, I should just bite the bullet and add fetch()

tabatkins commented 4 years ago

And done. This work for you, @LeaVerou?

ExE-Boss commented 4 years ago

Shouldn’t https://github.com/w3c/csswg-drafts/commit/5b28aaab25fc1171c143d52186dfe32ca45f6d2d be done in a PR?

LeaVerou commented 4 years ago

Wording seems fine, I'm still unsure if fetch() is a good name. It's a verb, which implies that an action happens, whereas CSS is a declarative, reactive language, and its functions declare values, they do not perform actions. The semantics of this new function are identical to url(), but the naming implies that it is completely different.

It's good to have it in the spec with any name, but I'm hoping we won't just resolve to that without discussion.

tabatkins commented 4 years ago

Let's put in on next week's agenda, yeah.

css-meeting-bot commented 4 years ago

The CSS Working Group just discussed [css-values] Add url() alias that does not accept unquoted URLs, and agreed to the following:

The full IRC log of that discussion <dael> Topic: [css-values] Add url() alias that does not accept unquoted URLs
<TabAtkins> https://drafts.csswg.org/css-values/#urls
<dael> github: https://github.com/w3c/csswg-drafts/issues/541
<dael> TabAtkins: About 4 years ago took a resolution to add alias of url that only accepts strings. Right now url parsing you can't provide url via a function. Can't pull from attr etc.
<dael> TabAtkins: Finally added it in. It's trvial spec text. Idential to url but without special parsing. Added explaination as why it exists.
<dael> TabAtkins: Name is only question. I speced as fetch(). I don't care what we name it as long as it's not uri(). Good to hear other ideas or if people like fetch. Need to resolve on a name so we can call this done
<ericwilligers> We can use href as it is used in SVG
<florian> +1 to src
<dael> fantasai: I like src. href and location aren't good. location is too long and href it's not about hypertext
<florian> -1 to [u|i]ri
<dael> Rossen_: Between fetch and src
<dael> Rossen_: Which do we lean toward? fantasai votes src and florian +1
<plinss> +1 src
<dael> Rossen_: Objections to name it src?
<dael> RESOLVED: Rename fetch() to src()
<dael> Rossen_: Do we need to republish?
<dael> TabAtkins: Soon, but needs review first