-
Notifications
You must be signed in to change notification settings - Fork 3
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
Going deeper on custom-property usage #1
Comments
A few thoughts on how we could calculate these metrics:
for (let rule of ast.stylesheet.rules) {
if (rule.type === "supports" && rule.supports.indexOf("(--") > -1) {
let [,property, value] = rule.supports.match(/\(--(\w+)(?::\s*(.+?))?\)/);
console.log({property, value});
}
}
|
I'm going to start writing queries for this one if nobody picked this up yet @LeaVerou ? |
@dooman87 I was actually hoping to do this one myself, but perhaps we could collaborate? E.g. I can write the JS part and you write the SQL part? |
All good, I can pickup the other one or we can collaborate, but I could be a bit slow :) Let me know what you think would be the most productive. |
I tried to write a script today to create a dependency graph based on the computed styles of the various elements in the DOM. Unfortunately, it proved out harder than expected, since: a) There seems to be no way to tell if a variable value is inherited or not (we can compare with the parent value, but it can have false positives) We could traverse One workaround/horrible hack I can think of is to traverse |
Alright, this was painful but I've made progress on this and have pushed a proof of concept. import('https://leaverou.github.io/css-almanac/runtime/var-tree.js') I have currently set up the code to print a nicely formatted JSON object in the console, for easier debugging. For example, this is what it generates for smashingmagazine.com. This data structure can help us answer questions like:
And many others. One issue I haven't managed to resolve is that when the Properties & Values API is used, that property appears everywhere due to having an initial value (see @rviscomi A few questions:
|
Depends on the value of the raw data. If there are many ways to slice and dice it to get different insights, keeping the raw JSON and analyzing it in SQL SGTM. Otherwise precomputing metrics is a good idea.
You should inline the
That's a great question, I'm not sure. Could you make a clone and modify that as needed, rather than the global/shared object? |
Oh the JSON definitely is high value and should be kept, I was just asking if I should precompute some metrics in addition to it.
Will do! How urgently do I need to do that? I would like to iterate a bit more if possible, in case I can fix that annoying Properties & Values bug.
I'm afraid not, the way this works is it adds custom properties that mirror properties with |
ASAP. Custom metrics were due yesterday and PRs are being reviewed now to make it into the August crawl.
I'm not very familiar with the possible effects of adding new custom properties on other metrics. If the CSS chapter metrics are the only ones looking at custom properties, I think it should be safe? |
Ok, I'm staying up tonight to get both this and the Sass one in, as I've made lots of good progress on that too. Hopefully submitting the PRs around noon EST should still be ok?
Cool. If there were another metric looking at runtime custom props I'd be aware of it, so let's leave the cleanup out for now. |
SGTM thanks for accelerating this. We need to get it merged by EOD today. |
Just saw this, on it. |
Rel #1 - Common values - Types - Properties with var() Bookmarklet for testing
Can we mark this one as |
Done! Finally all metrics have JS! 🎉 |
Some topics like this one have many queries, which I've only partially implemented so far. I'll be sure to |
I think I've implemented everything that has JS, but TBH I'm not sure if that covers all the questions you had about custom properties. @LeaVerou can you check the results sheet and let me know if there's anything missing and where I could find its corresponding JS? |
@rviscomi Did you notice |
Ahh I missed some of the other props in there. Could you help me understand how you intended they be aggregated (supports, pseudo-classes, fallback, initial)? For example, I can sum up the value of |
I'm also unsure what you're looking to measure for these two metrics under the "Custom Properties" section:
Could you point me to any other detailed descriptions and/or JS? |
Constants is covered by popular values I suppose. Custom properties in JS, is whether people set CSS variables from JS. Another component to see if people take advantage of the reactivity, or just use them like preprocessor variables, along with things like pseudo-classes etc. I don't see it being measured anywhere right now and I'm not sure how to measure it without access to the JS. If we can query the JS, I suppose we could look for things like |
Ok great, so we can check off "constants" with the Top Custom Property Values results. Custom properties in JS doesn't have a custom metric to parse the JS so unfortunately this one isn't feasible at this stage. I'll update the analysis PR accordingly. |
@rviscomi Another way to figure this out is if there are custom properties in the computed style that are not found in the stylesheets.
Thoughts? |
Given the drawbacks, I'd punt on this metric. |
I see last year we only calculated how many websites use custom properties (5%).
This year, I would like to go a lot deeper. E.g.:
var()
only, or both? (via custom metric):root
like static variables? (via custom metric)@supports
? If so, what property name do they test for? (via AST)initial
? (via custom metric or AST)The text was updated successfully, but these errors were encountered: