Skip to content

Commit 7191886

Browse files
committed
[css-values-5][editorial] Clean up some random() prose.
1 parent 432b442 commit 7191886

File tree

1 file changed

+46
-44
lines changed

1 file changed

+46
-44
lines changed

css-values-5/Overview.bs

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,11 +2287,6 @@ Generating a Random Numeric Value: the ''random()'' function</h3>
22872287

22882288
<pre class=prod>
22892289
&lt;random()> = random( <<random-cache-key>>? , <<calc-sum>>, <<calc-sum>>, <<calc-sum>>? )
2290-
2291-
<dfn><<random-cache-key>></dfn> = auto | <<random-name>> | fixed <<number [0,1]>>
2292-
<dfn><<random-name>></dfn> = <<dashed-ident>> || element-scoped
2293-
|| [ property-scoped | property-index-scoped | <<random-ua-ident>> ]
2294-
<dfn><<random-ua-ident>></dfn> = <<custom-ident>>
22952290
</pre>
22962291

22972292
See [[#random-evaluation]] and [[#random-caching]]
@@ -2580,70 +2575,76 @@ Evaluating Random Values</h3>
25802575
Sharing (Or Not) Random Values: the <<random-cache-key>> value</h3>
25812576

25822577
CSS is a declarative language,
2583-
so functions don't have a specific "time" when they're "evaluated";
2584-
the user agent is free to "execute" functions in any order,
2578+
so functions don't have a specific time when they're evaluated;
2579+
the user agent is free to execute functions in any order,
25852580
as many times as they want,
25862581
as every execution will return the same value.
2587-
This is difficult to square with "random" functions,
2582+
This is difficult to square with random-value functions,
25882583
which are inherently <em>stateful</em> and care about
25892584
when, how often, and in what order they're executed.
25902585

2591-
To fix this, the [=random functions=] are associated with a [=random cache name=],
2586+
To solve this, the [=random functions=] are associated with a [=random cache name=],
25922587
ensuring that any time the random function is evaluated with the same cache key,
25932588
it will return the same [=random base value=];
25942589
and also that [=random functions=] with <em>different</em> caching keys
25952590
will return <em>different</em> [=random base value=] from each other
25962591
(unless they are, randomly, the same).
25972592

2598-
The <<random-cache-key>> value controls this behavior:
2593+
The <<random-cache-key>> value controls this behavior,
2594+
and defaults to ''random()/auto'' when omitted.
2595+
It's syntax is as follows, and interpreted as described below:
2596+
2597+
<pre class=prod>
2598+
<dfn><<random-cache-key>></dfn> = auto | <<random-name>> | fixed <<number [0,1]>>
2599+
<dfn><<random-name>></dfn> = <<dashed-ident>> || element-scoped
2600+
|| [ property-scoped | property-index-scoped | <<random-ua-ident>> ]
2601+
<dfn><<random-ua-ident>></dfn> = <<custom-ident>>
2602+
</pre>
25992603

26002604
<dl dfn-type=value dfn-for="random(),random-item(),<random-cache-key>">
26012605
: <dfn>auto</dfn>
2602-
:: The [=random function=] is roughly "as random as possible":
2603-
every usage in a property,
2604-
between different properties,
2605-
and between different elements
2606-
will get a different [=random cache name=].
2606+
:: The [=random function=] is roughly “as random as possible”:
2607+
the [=random cache name=], and thus the result,
2608+
varies across every ''random()'' instance in a multi-component value,
2609+
across different properties,
2610+
and across different elements.
2611+
26072612
This is equivalent to specifying ''element-scoped property-index-scoped'',
26082613
and simplifies in exactly the same way.
26092614

2610-
If the <<random-cache-key>> is omitted,
2611-
it behaves as ''random()/auto''.
2612-
26132615
: <dfn><<random-name>></dfn>
2614-
:: The <<random-name>> specifies the [=random cache name=] directly,
2615-
<em>naming</em> the random value and allowing it to be explicitly shared (or not)
2616+
:: The <<random-name>> specifies the [=random cache name=],
2617+
allowing it to be explicitly shared (or not)
26162618
with other uses of [=random functions=].
26172619
Every [=random function=] using the same [=random cache name=]
26182620
will get the same random value;
26192621
every one using a <em>different</em> [=random cache name=]
26202622
will get unrelated random values.
26212623

2622-
The [=random cache name=] is made of several possible parts,
2623-
which are all optional
2624-
and can be specified in any order:
2625-
2626-
* The <<dashed-ident>>, giving the value an explicit name.
2624+
* The <<dashed-ident>> gives the value an explicit name.
26272625
If omitted, this part of the name is null.
26282626
* <dfn>element-scoped</dfn> adds an element-specific identifier
26292627
to the [=random cache name=],
26302628
so different elements will get different random values.
26312629
* <dfn>property-scoped</dfn> adds the property name the [=random function=] is being used on
26322630
to the [=random cache name=],
26332631
so different properties will get different random values.
2632+
Note that shorthand declarations will apply the [=shorthand property=]'s name.
26342633
* <dfn>property-index-scoped</dfn>
26352634
adds the property name <em>and</em> the index of the random function
26362635
among all the random functions used in the same property value
26372636
to the [=random cache name=],
2638-
so multiple uses of a [=random function=] in the same property
2639-
will get different random values.
2637+
so multiple instances of a [=random function=] in the same declaration
2638+
will each get different [=random cache names=].
2639+
Note this index is assigned <em>before</em> [=shorthand=] expansion.
26402640

2641-
''property-scoped'' and ''property-index-scoped''
2642-
are mutually exclusive with each other,
2643-
and also with the <dfn><<random-ua-ident>></dfn> value.
2644-
This value, like ''fixed'' below, isn't intended to be specified by authors,
2641+
See [[#random-simplify]] for how these values resolve.
2642+
2643+
The <dfn><<random-ua-ident>></dfn> value,
2644+
like ''fixed'' below, isn't intended to be specified by authors,
26452645
but can show up in [=computed values=].
2646-
It is a <<custom-ident>> that must start with the prefix <css>ua-</css>.
2646+
It is a <<custom-ident>> that must start with the prefix <css>ua-</css>,
2647+
or else it is invalid.
26472648
When generated automatically by the user agent,
26482649
it will always be <css>ua-PROPERTY</css> or <css>ua-PROPERTY-INDEX</css>,
26492650
with the <css>PROPERTY</css> and <css>INDEX</css> parts
@@ -2797,7 +2798,8 @@ Sharing (Or Not) Random Values: the <<random-cache-key>> value</h3>
27972798
(both are the first [=random function=] used in 'animation'),
27982799
so they'll share [=random base values=] on a single element
27992800
and generate related random values,
2800-
even tho the author likely considers them to be "different uses".
2801+
even though the author likely considers them to be
2802+
different instances of ''random()''.
28012803

28022804
This unexpected sharing is, unfortunately, unavoidable.
28032805
CSS generally doesn't care <em>how</em> you organize styles for your elements;
@@ -2858,28 +2860,28 @@ Sharing (Or Not) Random Values: the <<random-cache-key>> value</h3>
28582860
2. A nullable [=string=] property/index value:
28592861
the value of the <<random-ua-ident>>, if specified/calculated;
28602862
otherwise null.
2861-
4. A nullable "element identifier"
2863+
4. A nullable /element identifier/
28622864
uniquely identifying the {{Element}} or [=pseudo-element=]
28632865
the style is being applied to,
28642866
if ''random()/element-scoped'' is specified;
28652867
otherwise null.
2866-
5. A document ID identifying the {{Document}} the styles are from.
2868+
5. A /document identifier/ identifying the {{Document}} the styles are from.
28672869

2868-
The "element ID" and "document ID" must have the same lifetimes and equivalence semantics
2870+
The /element identifier/ and /document identifier/
2871+
must have the same lifetimes and equivalence semantics
28692872
as a JavaScript reference to the {{Element}} or {{Document}}.
28702873

28712874
Issue: The behavior for pseudo-elements needs to be clarified.
28722875

28732876
* The [=random cache name=] and [=random base value=]
28742877
must be determined by [=computed value=] time,
28752878
before [=inheritance=],
2876-
so that a random function which is unresolved by inheritance time
2879+
so that a random function that is unresolved by inheritance time
28772880
(due to containing, for example, a layout-sensitive percentage)
28782881
does not have a different behavior on children
2879-
from one that resolves immediately.
2882+
than one that resolves immediately.
28802883

28812884
<div class=example>
2882-
28832885
Shorthands are recorded as part of the [=random cache name=],
28842886
rather than the longhand the value gets expanded to.
28852887
For example:
@@ -2941,8 +2943,8 @@ Sharing (Or Not) Random Values: the <<random-cache-key>> value</h3>
29412943

29422944
Similarly, ''random()/element-scoped'' in the <<random-cache-key>>
29432945
won't cause the function to determine its "element identifier"
2944-
until substitution actually happens,
2945-
which might be <em>after</em> '--size' has inherited through multiple elements,
2946+
until substitution actually happens--
2947+
which might be <em>after</em> '--size' has inherited through multiple elements--
29462948
so again multiple elements using ''var(--size)''
29472949
would end up with distinct random values
29482950
rather than sharing one value defined on their ancestor.
@@ -2955,14 +2957,14 @@ Sharing (Or Not) Random Values: the <<random-cache-key>> value</h3>
29552957
Both issues can be resolved
29562958
by instead using a [=registered custom property=]
29572959
with a non-universal grammar,
2958-
so the ''random()'' function will be parsed and evaluated in the [=custom property=]
2960+
so the ''random()'' function will be parsed and evaluated by the [=custom property=]
29592961
(gaining a <<random-ua-ident>> of "ua---size-1"),
29602962
and then the resolved random value will be substituted into each property.
29612963
</div>
29622964

29632965

29642966
<h4 id=random-simplify>
2965-
Simplification</h4>
2967+
Random Simplification</h4>
29662968

29672969
At parse time,
29682970
certain transformations are performed on the <<random-cache-key>> of a [=random function=]:
@@ -2975,7 +2977,7 @@ Simplification</h4>
29752977
either <css>ua-PROPERTY</css> with PROPERTY being the property the value was parsed as,
29762978
or <css>ua-PROPERTY-INDEX</css> with PROPERTY as the previous
29772979
and INDEX being the 1-indexed integer index of this [=random function=]
2978-
among all [=random functions=] being used in the property.
2980+
among all [=random functions=] being used in the declaration.
29792981

29802982
The INDEX value is based on the ordering in the parsed value,
29812983
before any canonicalization/reordering might occur

0 commit comments

Comments
 (0)