-
Notifications
You must be signed in to change notification settings - Fork 759
Description
I took random() for a spin and must say I struggled quite a bit with the <random-value-sharing> options.
What we have now
As it currently stands, the options are:
auto: Each random function in an element’s styles will use a distinct random base value.<dashed-ident>: Each random function in an element’s styles with the same<dashed-ident>will share the same random base value; ones with different<dashed-ident>s will use distinct random base values.element-shared: If element-shared is omitted, random functions on different elements will use distinct random base values.
If specified, random functions on different elements will share the same random base value if they have the same<dashed-ident>(if specified) or if they’re used in the same style in the same way (if not)fixed <number>: If fixed<number>is specified, the<number>is used as the random function’s random base value, rather than allowing the UA to generate a random base value and controlling how it’s shared.
What trips me up
I have a feeling the things are named incorrectly, because:
- The
<custom-ident>you use acts like a little cache to hold the value. When reused on an element, it will reused the same value from the cache linked with that element. This makes it a value that is “element shared”, as also mentioned in the title that goes with the example: “Shared by name within an element“. element-sharedcaches the value on a per property base, as made clear in the title that goes with the example: “Shared between elements within a property“. So this isn’t exactlyelement-sharedbut moreper-property.
Additionally, my first reaction to seeing <custom-ident> would be that this is an identifier that is a global one. But that is not the case. To get that behavior, one must use <custom-ident> element-shared.
How can we fix this?
As mentioned my gut feeling is that <custom-ident> acted as if it was global. I think we should to that and use that as the base. Using keywords, one can then narrow down the scope to per-element or per-property.
So for this example, with 100 of those .random elements:
.random {
width: random(<caching-strategy>, 100px, 200px);
height: random(<caching-strategy>, 100px, 200px);
}You’d get these behaviors for different <caching-strategy> values:
--foo: The value is cached globally, you end up with 100 identical squares--foo per-element: The value is cached per-element, so you end up with 100 different squares--foo per-property: The value is cached per-property, so you end up with 100 identical rectangles
The auto case (or no value) would still get you 100 random rectangles.
I’d like to believe that the thing I am suggesting here leads to an easier to understand mental model.
/cc @fantasai @nt1m @jensimmons because I saw this one mentioned in the Safari 26.2 beta release notes.