Skip to content

Commit beac1e5

Browse files
committed
[css-values-5][editorial] Reword ua-early random() stuff, and rewrite/expand example.
1 parent 2f24fc0 commit beac1e5

1 file changed

Lines changed: 75 additions & 15 deletions

File tree

css-values-5/Overview.bs

Lines changed: 75 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,7 @@ attr-security-animation.html
22572257
attr-security-if.html
22582258
attr-security-transition.html
22592259
attr-security.html
2260+
attr-security-transition-interpolated.html
22602261
</wpt>
22612262

22622263
An ''attr()'' function can reference attributes
@@ -3223,10 +3224,18 @@ Simplification of <<random-key>></h4>
32233224
which is then evaluated within 'width',
32243225
getting <<random-ua-ident>>s of ''ua-width-1'' and ''ua-width-2'' instead.
32253226
</div>
3227+
32263228
* when evaluated inside of an [=arbitrary substitution function=]
32273229
as part of the substitution process,
3228-
the prefix is ''ua-early-'' rather than just ''ua-''.
3229-
The INDEX portion, as well, is tracked across all substitutions in the property.
3230+
the prefix is ''ua-early-'' rather than just ''ua-'':
3231+
<css>ua-early-PROPERTY</css> or <css>ua-early-PROPERTY-INDEX</css>.
3232+
3233+
Additionally, if the INDEX portion is included in the ident,
3234+
it is incremented <em>separately</em> from non-"early" usage
3235+
(that is, the "early" usage counts up from 1, then non-"early" usage will also count up from 1)
3236+
and increments across substitutions in the property
3237+
(that is, multiple different [=arbitrary substitution functions=] will use successive indexes,
3238+
rather than resetting to 1 for each substitution).
32303239

32313240
<div class=example>
32323241
For example, in this relatively complex value:
@@ -3235,28 +3244,79 @@ Simplification of <<random-key>></h4>
32353244
.foo {
32363245
width: calc(
32373246
if(
3238-
style(random(/*eA*/) == random(/*eB*/)): random(/*lA*/);
3239-
else: random(/*lB*/))
3247+
style(/*eA*/random(auto, ...) < 0.5):
3248+
/*lA*/random(auto, ...);
3249+
else:
3250+
/*lB*/random(auto, ...))
3251+
)
3252+
+
3253+
if(
3254+
style(/*eB*/random(auto, ...) < 0.5):
3255+
/*lC*/random(auto, ...);
3256+
else:
3257+
/*lD*/random(auto, ...))
3258+
)
3259+
);
3260+
}
3261+
</xmp>
3262+
3263+
During [=/replace an arbitrary substitution function|replacement=],
3264+
the tests of both ''if()''s are parsed
3265+
(since using <css>==</css> or <css>></css> provides a numeric context,
3266+
giving the UA the necessary knowledge to evaluate them),
3267+
resulting in, effectively, the following code:
3268+
3269+
<xmp highlight=css>
3270+
.foo {
3271+
width: calc(
3272+
if(
3273+
style(/*eA*/random(element-scoped ua-early-width-1, ...) < 0.5):
3274+
/*lA*/random(auto, ...);
3275+
else:
3276+
/*lB*/random(auto, ...))
32403277
)
3241-
+ if(
3242-
style(random(/*eC*/) > random(/*eD*/): random(/*lC*/);
3243-
else: random(/*lD*/))
3278+
+
3279+
if(
3280+
style(/*eB*/random(element-scoped ua-early-width-2, ...) < 0.5):
3281+
/*lC*/random(auto, ...);
3282+
else:
3283+
/*lD*/random(auto, ...))
32443284
)
32453285
);
32463286
}
32473287
</xmp>
32483288

3249-
The four ''random()''s in the ''if/style()'' tests (''eA'' through ''eD'')
3250-
are all evaluated
3251-
(since using <css>==</css> or <css>></css> provides a numeric context)
3252-
as part of substitution,
3253-
so their <<random-ua-ident>>s are ''ua-early-width-1''/''-2''/''-3''/''-4''.
3289+
That is, the two values in the tests have distinct <<random-ua-ident>>s,
3290+
and will be element-scoped as well,
3291+
so every instance on every element will evaluate to distinct values.
32543292

3255-
Each ''if()'' will resolve to one of the "late" ''random()''s (''lA'' through ''lD''),
3256-
left unevaluated and substituted into the 'width',
3257-
giving "normal" <<random-ua-ident>>s of ''ua-width-1'' and ''ua-width-2''.
3293+
Based on these random values,
3294+
each ''if()'' will substitute itself with one of its two (unevaluated) branches.
3295+
When these are then parsed according to the 'width' grammar,
3296+
they will receive "normal" <<random-ua-ident>>s with their indexes restarting from 1,
3297+
effectively:
3298+
3299+
<xmp highlight=css>
3300+
.foo {
3301+
width: calc(
3302+
/*lA*/random(element-scoped ua-width-1, ...)
3303+
+
3304+
/*lD*/random(element-scoped ua-width-2, ...)
3305+
)
3306+
);
3307+
}
3308+
</xmp>
3309+
3310+
Since these are using different <<random-ua-ident>>s than the "early" ones,
3311+
their random values will be distinct as well.
32583312
</div>
32593313

3314+
These additional modifiers can be combined.
3315+
For example,
3316+
if a ''random(0, 1)'' is evaluated in the test of an ''if()''
3317+
used in the '@function/result' of a custom function named ''--foo()'',
3318+
the <<random-ua-ident>> will be ''ua-early---foo-result-1''.
3319+
32603320
If the <<random-key>> contains a <<random-ua-ident>>,
32613321
this must not be omitted in the serialization of the value,
32623322
even if this would normally be valid per the

0 commit comments

Comments
 (0)