Skip to content

Commit 97cce81

Browse files
committed
[css-values-5] Define ident()
1 parent 2f1a48a commit 97cce81

File tree

1 file changed

+100
-12
lines changed

1 file changed

+100
-12
lines changed

css-values-5/Overview.bs

Lines changed: 100 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,94 @@ Security</h4>
17911791
''--foo: attr(foo type(&lt;number&gt;)); background-image: src(string(var(--foo)))''
17921792
needs to be invalid as well.
17931793

1794+
<!-- Big Text: ident()
1795+
1796+
████ ████▌ █████▌ █ █▌ █████▌ ██ ██
1797+
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
1798+
▐▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ ▐█
1799+
▐▌ █▌ █▌ ████ █▌▐█ █▌ █▌ █▌ ▐█
1800+
▐▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ ▐█
1801+
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
1802+
████ ████▌ █████▌ █▌ ▐▌ █▌ ██ ██
1803+
-->
1804+
1805+
<h3 id=ident>
1806+
Constructing <<custom-ident>> values: the ''ident()'' function</h3>
1807+
1808+
<!-- https://github.com/w3c/csswg-drafts/issues/9141 -->
1809+
1810+
The <dfn>ident()</dfn> function is an [=arbitrary substitution function=]
1811+
that can be used to manually construct <<custom-ident>> values from several parts.
1812+
1813+
<pre class=prod>
1814+
<dfn><<ident-fn>></dfn> = ident(<<ident-args>>);
1815+
<dfn><<ident-args>></dfn> = [<<string>> | <<integer>> | <<ident>>]+
1816+
</pre>
1817+
1818+
Issue: Should we allow a fallback value?
1819+
1820+
The ''ident()'' function can be used as a value for any property or function argument
1821+
that accepts a <<custom-ident>>.
1822+
1823+
<div class=example>
1824+
In the following example,
1825+
each matched element gets a unique <dfn><<'view-timeline-name'>></dfn>
1826+
in the format of <code>"vtl-<em>number</em>"</code>.
1827+
The <code><em>number</em></code> is generated using ''sibling-index()''.
1828+
1829+
```css
1830+
.item {
1831+
/* vtl-1, vtl-2, vtl-3, … */
1832+
view-timeline-name: ident("vtl-" sibling-index());
1833+
}
1834+
```
1835+
</div>
1836+
1837+
While in many cases ''attr()'' with the <<attr-type>> set to <code>type(<<custom-ident>>)</code> will do,
1838+
''ident()'' can be used to construct a <<custom-ident>> using values that come from other elements.
1839+
1840+
<div class=example>
1841+
In the following example, the ''ident()'' function uses a custom property
1842+
which is defined on a parent.
1843+
1844+
```css
1845+
.card[id] {
1846+
/* E.g. card1, card2, card3, … */
1847+
--id: attr(id);
1848+
1849+
view-transition-name: var(--id);
1850+
view-transition-class: card;
1851+
1852+
h1 {
1853+
/* E.g. card1-title, card2-title, card3-title, … */
1854+
view-transition-name: ident(var(--id) "-title");
1855+
view-transition-class: card-title;
1856+
}
1857+
}
1858+
```
1859+
</div>
1860+
1861+
To generate a <<dashed-ident>>, put <code>"--"</code> as the first argument.
1862+
1863+
<div class=example>
1864+
1865+
```css
1866+
.card[id] {
1867+
/* E.g. card1, card2, card3, … */
1868+
--id: attr(id);
1869+
1870+
view-transition-name: var(--id);
1871+
view-transition-class: card;
1872+
1873+
h1 {
1874+
/* E.g. card1-title, card2-title, card3-title, … */
1875+
view-transition-name: ident(var(--id) "-title");
1876+
view-transition-class: card-title;
1877+
}
1878+
}
1879+
```
1880+
</div>
1881+
17941882
<!-- Big Text: random
17951883

17961884
████▌ ███▌ █ █▌ ████▌ ███▌ █ █
@@ -3024,13 +3112,13 @@ Appendix A: Arbitrary Substitution Functions</h2>
30243112

30253113
<!-- Big Text: invalid
30263114

3027-
████ █ █▌ █▌ █▌ ███▌ █▌ ████ ████▌
3115+
████ █ █▌ █▌ █▌ ███▌ █▌ ████ ████▌
30283116
▐▌ █▌ █▌ █▌ █▌ ▐█ ▐█ █▌ ▐▌ █▌ █▌
30293117
▐▌ ██▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐▌ █▌ █▌
30303118
▐▌ █▌▐█ █▌ ▐▌ █ █▌ █▌ █▌ ▐▌ █▌ █▌
30313119
▐▌ █▌ ██▌ █ ▐▌ █████▌ █▌ ▐▌ █▌ █▌
30323120
▐▌ █▌ █▌ ▐▌ █ █▌ █▌ █▌ ▐▌ █▌ █▌
3033-
████ █▌ ▐▌ ▐█ █▌ █▌ █████ ████ ████▌
3121+
████ █▌ ▐▌ ▐█ █▌ █▌ █████ ████ ████▌
30343122
-->
30353123

30363124
<h3 id=invalid-substitution oldids='invalid-variables'>
@@ -3090,13 +3178,13 @@ Invalid Substitution</h3>
30903178

30913179
<!-- Big Text: shorthand
30923180

3093-
███▌ █▌ █▌ ███▌ ████▌ █████▌ █▌ █▌ ███▌ █ █▌ ████▌
3181+
███▌ █▌ █▌ ███▌ ████▌ █████▌ █▌ █▌ ███▌ █ █▌ ████▌
30943182
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█ ▐█ █▌ █▌ █▌ █▌
30953183
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌
30963184
███▌ █████▌ █▌ █▌ ████▌ █▌ █████▌ █▌ █▌ █▌▐█ █▌ █▌ █▌
30973185
█▌ █▌ █▌ █▌ █▌ █▌▐█ █▌ █▌ █▌ █████▌ █▌ ██▌ █▌ █▌
30983186
█▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
3099-
███▌ █▌ █▌ ███▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐▌ ████▌
3187+
███▌ █▌ █▌ ███▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐▌ ████▌
31003188
-->
31013189

31023190
<h3 id=substitution-in-shorthands oldids=variables-in-shorthands>
@@ -3165,13 +3253,13 @@ Substitution in Shorthand Properties</h3>
31653253

31663254
<!-- Big Text: too long
31673255

3168-
█████▌ ███▌ ███▌ █▌ ███▌ █ █▌ ███▌
3256+
█████▌ ███▌ ███▌ █▌ ███▌ █ █▌ ███▌
31693257
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
3170-
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌
3258+
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌
31713259
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌▐█ █▌ █▌ ██▌
31723260
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌
31733261
█▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌
3174-
█▌ ███▌ ███▌ █████ ███▌ █▌ ▐▌ ███▌
3262+
█▌ ███▌ ███▌ █████ ███▌ █▌ ▐▌ ███▌
31753263
-->
31763264

31773265
<h3 id=long-substitution oldids=long-variables>
@@ -3269,13 +3357,13 @@ Appendix B: Boolean Logic</h2>
32693357

32703358
<!-- Big Text: etc
32713359

3272-
█████▌ █████▌ ███▌
3360+
█████▌ █████▌ ███▌
32733361
█▌ █▌ █▌ █▌
3274-
█▌ █▌ █▌
3275-
████ █▌ █▌
3276-
█▌ █▌ █▌
3362+
█▌ █▌ █▌
3363+
████ █▌ █▌
3364+
█▌ █▌ █▌
32773365
█▌ █▌ █▌ █▌
3278-
█████▌ █▌ ███▌
3366+
█████▌ █▌ ███▌
32793367
-->
32803368

32813369

0 commit comments

Comments
 (0)