Skip to content

Commit 5c4e0fc

Browse files
committed
[css-values-5] ident() is now an arbitrary-substitution function. #14213
1 parent de6672a commit 5c4e0fc

1 file changed

Lines changed: 52 additions & 15 deletions

File tree

css-values-5/Overview.bs

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,26 +2344,34 @@ Constructing <<custom-ident>> values: the ''ident()'' function</h3>
23442344
<wpt>
23452345
ident-function-computed.html
23462346
ident-function-parsing.html
2347+
ident-function-substitution.html
23472348
</wpt>
23482349

23492350
<!-- https://github.com/w3c/csswg-drafts/issues/9141 -->
23502351

2351-
The <dfn>ident()</dfn> function represents an <<ident>>,
2352-
and can be used to manually construct <<custom-ident>> values from several parts.
2352+
The <dfn>ident()</dfn> function represents an arbitrary <<ident>>,
2353+
built from one or more separate idents, strings, and integers.
2354+
It is an [=arbitrary substitution function=].
23532355

23542356
<pre class=prod>
23552357
<<ident()>> = ident( <<ident-arg>>+ )
23562358
<dfn><<ident-arg>></dfn> = <<string>> | <<integer>> | <<ident>>
23572359
</pre>
23582360

2359-
The ''ident()'' function can be used as a value for any property or function argument
2360-
that accepts a <<custom-ident>>.
2361+
The ''ident()'' function's [=argument grammar=] is:
2362+
2363+
<pre class=prod>
2364+
<dfn><<ident-args>></dfn> = ident( <<declaration-value>> )
2365+
</pre>
2366+
2367+
''ident()'' can be used anywhere that an [=identifier=] is expected,
2368+
but it's most useful to construct <<custom-ident>> or <<dashed-ident>> values.
23612369

23622370
<div class=example>
23632371
In the following example,
2364-
each matched element gets a unique <<'view-timeline-name'>>
2365-
in the format of <code>"vtl-<em>number</em>"</code>.
2366-
The <code><em>number</em></code> is generated using ''sibling-index()''.
2372+
each matched element gets a unique 'view-timeline-name'
2373+
by combining a shared prefix
2374+
with ''sibling-index()'' to differentiate each element:
23672375

23682376
```css
23692377
.item {
@@ -2373,12 +2381,13 @@ ident-function-parsing.html
23732381
```
23742382
</div>
23752383

2376-
While in many cases ''attr()'' with the <<attr-type>> set to <css>type(<<custom-ident>>)</css> will do,
2377-
''ident()'' can be used to construct a <<custom-ident>> using values that come from other elements.
2378-
23792384
<div class=example>
2380-
In the following example, the ''ident()'' function uses a custom property
2381-
which is defined on a parent.
2385+
While in many cases ''attr()'' with the <<attr-type>> set to <<custom-ident>> will do,
2386+
''ident()'' can be used to construct a <<custom-ident>> using values that come from other elements.
2387+
In the following example,
2388+
the ''ident()'' function combines
2389+
a [=custom property=] defined on a parent
2390+
with an ''attr()'' value coming from the element itself:
23822391

23832392
```css
23842393
.card[id] {
@@ -2397,17 +2406,44 @@ ident-function-parsing.html
23972406
```
23982407
</div>
23992408

2400-
To generate a <<dashed-ident>>, put <code>"--"</code> as the first argument.
2401-
24022409
<div class=example>
2410+
To generate a <<dashed-ident>>,
2411+
simply use a ''--'' ident as the first segment:
24032412

24042413
```css
24052414
.element {
2406-
anchor-name: ident("--" attr(id));
2415+
anchor-name: ident(-- attr(id));
24072416
}
24082417
```
24092418
</div>
24102419

2420+
<div algorithm>
2421+
To <dfn export>[=replace an arbitrary substitution function|replace an ident() function=]</dfn>,
2422+
given a list of |arguments|:
2423+
2424+
1. Let |arg| be the first item of |arguments|.
2425+
2426+
Note: ''ident()'' only takes a single argument.
2427+
2428+
2. [=Substitute arbitrary substitution functions=] in |arg|,
2429+
then [=CSS/parse=] it as <css><<ident-arg>>+</css>.
2430+
If that returns failure,
2431+
return the [=guaranteed-invalid value=].
2432+
Otherwise, let |pieces| be the result.
2433+
2434+
3. Replace each item in |pieces| with its [=computed value=].
2435+
If any item does not,
2436+
at this point,
2437+
become a [=string=], [=integer=], or [=ident=],
2438+
return the [=guaranteed-invalid value=].
2439+
2440+
Note: For example, if the value is a function that can't resolve at [=computed value=] time.
2441+
2442+
4. Serialize each item in |pieces|,
2443+
then [=string/concatenate=] the list.
2444+
Return an [=ident=] whose value is the result.
2445+
</div>
2446+
24112447
<!-- Big Text: random
24122448

24132449
████▌ ███▌ █ █▌ ████▌ ███▌ █ █
@@ -5292,6 +5328,7 @@ typed-arithmetic-mixed-units-crash.html
52925328
typed_arithmetic.html
52935329
typed_arithmetic_cycle.html
52945330
update-subpixel-rem-unit.html
5331+
using-font-relative-units-in-font-properties.html
52955332
various-values-important.html
52965333
vh-calc-support-pct.html
52975334
vh-calc-support.html

0 commit comments

Comments
 (0)