Re: [csswg-drafts] [css-mixins] Improve ergonomics of `using` by allowing wildcards (#10954)

I'm slightly against this. The use-case is reasonable, but I think we should solve it more directly.

Basically, a function knows exactly what variables *it* is going to use. There's no need to import every single color; just write the ones you're *actually using* in your `using` list. 

The problem is that a function doesn't know what theming variables its *own* called functions will want to use, and so pulling in the entire theme, as in your example, makes sense. This means it would probably end up being common practice to just write `using (--*)` on all your functions, *just in case*, and that sucks.

We do want to make sure that an outer function can *override* a theming variable for the functions it calls (and the functions they call, etc, if they're not further overriden). This sort of theming control is important. 

Maybe `using` variables can crawl up the scope tree to find a valid declaration for the given variabale, bottoming out at the element it's used on? So if an outer function just *doesn't mention* a given a variable, then an inner function with `using (--foo)` will look higher up the call tree for that variable. But if an outer function *does* redefine --foo in its body, then the inner function will see that definition.

Here's an example:

```css
@function --outer() {
  --v1: 10;
  result: --inner();
}
@function --inner() using (--v1: 100, --v2: 200) {
  result: calc(var(--v1) + var(--v2));
}
.foo {
  --v1: 1;
  --v2: 2;
  z-index: --outer();
}
```

Under the *current* specced behavior, the z-index is 210 - `--inner()` sees the `--v1` defined by `--outer()` (10), but doesn't see any `--v2` at all, so uses its default value (200).

Under the alternative I describe above, the z-index is 12 - `--inner()` still sees the `--v1` defined by `--outer()` (10), but since it doesn't see a `--v2` from `--outer()`, it moves up the call tree and takes the `--v2` from the element (2).

@andruud, any thoughts?

-- 
GitHub Notification of comment by tabatkins
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/10954#issuecomment-2377723197 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 26 September 2024 19:05:37 UTC