-
-
Notifications
You must be signed in to change notification settings - Fork 167
/
custom_property_properties.sql
125 lines (113 loc) · 2.74 KB
/
custom_property_properties.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#standardSQL
CREATE TEMPORARY FUNCTION getCustomPropertyProperties(css STRING)
RETURNS ARRAY<STRING>
LANGUAGE js
OPTIONS (library = "gs://httparchive/lib/css-utils.js")
AS '''
try {
function compute(ast) {
let ret = {
properties: {},
functions: {},
supports: {},
"pseudo-classes": {},
fallback: {
none: 0,
literal: 0,
var: 0
},
initial: 0
};
walkRules(ast, rule => {
for (let match of rule.supports.matchAll(/\\(--(?<name>[\\w-]+)\\s*:/g)) {
incrementByKey(ret.supports, match.groups.name);
}
}, {type: "supports"});
let parsedSelectors = {};
walkDeclarations(ast, ({property, value}, rule) => {
if (matches(value, /\\bvar\\(\\s*--/)) {
if (!property.startsWith("--")) {
incrementByKey(ret.properties, property);
}
for (let call of extractFunctionCalls(value)) {
if (call.name === "var") {
let fallback = call.args.split(",").slice(1).join(",");
if (matches(fallback, /\\bvar\\(\\s*--/)) {
ret.fallback.var++;
}
else if (fallback) {
ret.fallback.literal++;
}
else {
ret.fallback.none++;
}
}
else if (call.args.includes("var(--")) {
incrementByKey(ret.functions, call.name);
}
}
}
if (property.startsWith("--")) {
if (value === "initial") {
ret.initial++;
}
if (rule.selectors) {
for (let selector of rule.selectors) {
let sast = parsedSelectors[selector] = parsedSelectors[selector] || parsel.parse(selector);
parsel.walk(sast, node => {
if (node.type === "pseudo-class") {
incrementByKey(ret["pseudo-classes"], node.name);
}
})
}
}
}
});
for (let type in ret) {
ret[type] = sortObject(ret[type]);
}
return ret;
}
const ast = JSON.parse(css);
let custom_property = compute(ast);
return Object.keys(custom_property.properties);
} catch (e) {
return [];
}
''';
SELECT
client,
property,
COUNT(DISTINCT page) AS pages,
total,
COUNT(DISTINCT page) / total AS pct
FROM (
SELECT DISTINCT
client,
page,
LOWER(property) AS property
FROM
`httparchive.almanac.parsed_css`
LEFT JOIN
UNNEST(getCustomPropertyProperties(css)) AS property
WHERE
date = '2021-07-01' AND
property IS NOT NULL)
JOIN (
SELECT
_TABLE_SUFFIX AS client,
COUNT(0) AS total
FROM
`httparchive.summary_pages.2021_07_01_*`
GROUP BY
client)
USING
(client)
GROUP BY
client,
total,
property
HAVING
pct >= 0.01
ORDER BY
pct DESC