-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin for random()
#601
Comments
Closing for now, waiting on the final specification |
The issue I have with this is that this would be a random value at generation time vs at consumed time unless we go the JS way |
It can not even be random at generation time, that would make CSS builds indeterministic. It can work as a fallback, but never as a polyfill. |
This is not something we can do 🤔 .random {
width: random(per-element, 100px, 500px);
} Would become : .random {
width: 372px;
} But that is the same for each element.
Edit : I always forget that counter values can not be used in |
🤔 true that! |
@romainmenke re this:
My understanding of Is that not the case? Where in the spec is that, if you know? This
|
That is correct :) I was working under the assumption to include this in PostCSS Preset Env. If we include a non-deterministic plugin there, we would break a lot of things. A standalone plugin, not included in PostCSS Preset Env would not have this constraint. My initial idea was to have a plugin that helps authors with a semi-random fallback value. A second idea I had was to use the DOM itself as a source of entropy. Not every page would have 5th child in a 6th child in a 13th child in ... By creating a bunch of these conditions and assigning different values to attributes you can create semi-random numbers. Something that would appear random to an end user. :root:has(:nth-child(...) :nth-child(...) ...) {
--random-1: 1;
--random-2: 2;
--random-3: 3;
}
:root:has(:nth-child(...) :nth-child(...) ...) {
--random-1: 2;
--random-2: 3;
--random-3: 1;
}
:root:has(:nth-child(...) :nth-child(...) ...) {
--random-1: 3;
--random-2: 1;
--random-3: 2;
}
.foo {
/* really quick maths, likely very broken/incorrect */
width: clamp(100px, calc(100px + (var(--random-1) * (300px - 100px))), 300px);
width: random(100px, 300px);
} |
The technique above could also be done without |
/* just writing numbers, haven't tested any of this */
:nth-child(2) {
--random-1: 1;
}
:nth-child(2n+1) {
--random-1: 2;
}
:nth-child(2n+2) {
--random-1: 3;
}
:nth-child(2n+3) {
--random-1: 4;
}
:nth-child(3) {
--random-2: 1;
}
:nth-child(3n+1) {
--random-2: 2;
}
:nth-child(3n+2) {
--random-2: 3;
}
:nth-child(3n+3) {
--random-2: 4;
}
/* ... */
.foo {
/* really quick maths, likely very broken/incorrect */
width: clamp(100px, calc(100px + (((var(--random-1) + var(--random-2) + var(--random-3)) / 3) * (300px - 100px))), 300px);
width: random(100px, 300px);
} |
@brandonmcconnell I am doing a bit of pruning in the issues here and this one hasn't seen activity in the past few weeks. But feel free to reach out with any questions. |
@romainmenke I just assumed you were still working on it. No worries, thanks for the heads up 🙂 |
Ha, no, didn't want to steal your thunder, only wanted to provide some options. |
Ah got it. No worries! |
What would you want to propose?
TODO
Suggested solution
TODO
Additional context
css-values-5
: https://drafts.csswg.org/css-values-5/Validations
Would you like to open a PR for this feature?
The text was updated successfully, but these errors were encountered: