random-item() is a new css-values-5 arbitrary-substitution
function: give it a random-key and a comma-separated list of
items, and it substitutes one of the items.
The key can be auto, a <dashed-ident>
with optional element-scoped,
property-scoped or property-index-scoped, or a
fixed <number> for deterministic picks. Sibling
elements with an element-scoped key pick independently; the same
dashed-ident across declarations shares a base value.
Implementation reuses random()'s base-value cache and
RandomCacheKey. random-item() auto and
property-*-scoped buckets stay disjoint from random()'s by
prefixing the synthesized ua-ident with "ri-"; named-ident
and bare element-scoped keys share the bucket per
spec.
Inside @container style() there is no property context so
random-item() becomes IACVT, matching
random()'s behavior.
<random-item()> = random-item( <random-key>,
[ <declaration-value>? ]# )
<random-key> = <random-caching-key> | fixed <number>
<random-caching-key> =
[ [ auto | <dashed-ident> ] || element-scoped ]
| <dashed-ident> [ property-scoped | property-index-scoped ]
random-item()
is unknown and falls back to initial values -- run with
--enable-blink-features=CSSRandomItemFunction or on a
build that includes this CL to see the picks.
random-item()
declaration is IACVT and the sections collapse to initial.
fixed 0.5 always picks
index 2 ("lime"); the two shared-key boxes always land on
the same colour.
random-item().All eight external/wpt/css/css-values/random-item-*.html
tests pass 100% of their subtests locally:
| test | subtests | pass |
|---|---|---|
| random-item-valid | 21 | 21 |
| random-item-invalid | 14 | 14 |
| random-item-serialize | 15 | 15 |
| random-item-computed | 37 | 37 |
| random-item-nested | 4 | 4 |
| random-item-in-keyframe | 1 | 1 |
| random-item-in-container-query.tentative | 4 | 4 |
| random-item-unresolvable-argument | 3 | 3 |
| total | 99 | 99 |
wpt.fyi currently reports 0/0 for Chrome, Firefox and
Safari on these tests (the suite is not yet enabled on their public runs),
so landing this makes Blink the first stable run to report full coverage.
# Enable the flag
content_shell --enable-blink-features=CSSRandomItemFunction sampler.html
# or via the generic umbrella flag
content_shell --enable-experimental-web-platform-features sampler.html