@surplus/esbuild 2.0.1 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/css.mjs +63 -62
- package/package.json +1 -1
package/lib/css.mjs
CHANGED
|
@@ -9,7 +9,62 @@ const toArrayBuffer = (text) => new TextEncoder("utf-8").encode(text);
|
|
|
9
9
|
|
|
10
10
|
const camelize = (str) => camelCase(str, { transform: camelCase });
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
function processCSSRule(rule, uid, mappings) {
|
|
13
|
+
const { selectors, ...rest } = rule;
|
|
14
|
+
|
|
15
|
+
let globalize = false;
|
|
16
|
+
let ignore = false;
|
|
17
|
+
|
|
18
|
+
const result = {
|
|
19
|
+
selectors: selectors.map((selector) =>
|
|
20
|
+
cssWhat.stringify(
|
|
21
|
+
cssWhat.parse(selector).map((tokens) =>
|
|
22
|
+
tokens
|
|
23
|
+
.map((t) => {
|
|
24
|
+
if (t.type === "tag" && t.name === "@global") {
|
|
25
|
+
globalize = true;
|
|
26
|
+
return false;
|
|
27
|
+
} else if (
|
|
28
|
+
t.type === "attribute" &&
|
|
29
|
+
t.name === "class"
|
|
30
|
+
) {
|
|
31
|
+
const newValue = globalize
|
|
32
|
+
? t.value
|
|
33
|
+
: `${t.value}-${uid}`;
|
|
34
|
+
mappings[camelize(t.value)] = newValue;
|
|
35
|
+
return {
|
|
36
|
+
...t,
|
|
37
|
+
value: newValue,
|
|
38
|
+
};
|
|
39
|
+
} else if (t.type === "tag" && t.name === "@meta") {
|
|
40
|
+
// Don't emit it in the resulting CSS.
|
|
41
|
+
ignore = true;
|
|
42
|
+
|
|
43
|
+
for (const decl of rule.declarations) {
|
|
44
|
+
switch (decl.property) {
|
|
45
|
+
case "priority":
|
|
46
|
+
priority = parseFloat(
|
|
47
|
+
decl.value,
|
|
48
|
+
10,
|
|
49
|
+
);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return t;
|
|
56
|
+
})
|
|
57
|
+
.filter(Boolean),
|
|
58
|
+
),
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
...rest,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return ignore ? null : result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function processCSS(contents, uid, mappings) {
|
|
13
68
|
const ast = css.parse(contents);
|
|
14
69
|
|
|
15
70
|
let priority = 0;
|
|
@@ -18,66 +73,12 @@ async function processCSS(contents, uid, mappings) {
|
|
|
18
73
|
.map((rule) => {
|
|
19
74
|
switch (rule.type) {
|
|
20
75
|
case "rule":
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
selectors: selectors.map((selector) =>
|
|
28
|
-
cssWhat.stringify(
|
|
29
|
-
cssWhat.parse(selector).map((tokens) =>
|
|
30
|
-
tokens
|
|
31
|
-
.map((t) => {
|
|
32
|
-
if (
|
|
33
|
-
t.type === "tag" &&
|
|
34
|
-
t.name === "@global"
|
|
35
|
-
) {
|
|
36
|
-
globalize = true;
|
|
37
|
-
return false;
|
|
38
|
-
} else if (
|
|
39
|
-
t.type === "attribute" &&
|
|
40
|
-
t.name === "class"
|
|
41
|
-
) {
|
|
42
|
-
const newValue = globalize
|
|
43
|
-
? t.value
|
|
44
|
-
: `${t.value}-${uid}`;
|
|
45
|
-
mappings[camelize(t.value)] =
|
|
46
|
-
newValue;
|
|
47
|
-
return {
|
|
48
|
-
...t,
|
|
49
|
-
value: newValue,
|
|
50
|
-
};
|
|
51
|
-
} else if (
|
|
52
|
-
t.type === "tag" &&
|
|
53
|
-
t.name === "@meta"
|
|
54
|
-
) {
|
|
55
|
-
// Don't emit it in the resulting CSS.
|
|
56
|
-
ignore = true;
|
|
57
|
-
|
|
58
|
-
for (const decl of rule.declarations) {
|
|
59
|
-
switch (decl.property) {
|
|
60
|
-
case "priority":
|
|
61
|
-
priority =
|
|
62
|
-
parseFloat(
|
|
63
|
-
decl.value,
|
|
64
|
-
10,
|
|
65
|
-
);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return t;
|
|
72
|
-
})
|
|
73
|
-
.filter(Boolean),
|
|
74
|
-
),
|
|
75
|
-
),
|
|
76
|
-
),
|
|
77
|
-
...rest,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
return ignore ? null : result;
|
|
76
|
+
return processCSSRule(rule, uid, mappings);
|
|
77
|
+
case "media":
|
|
78
|
+
rule.rules = rule.rules.map((rule) =>
|
|
79
|
+
processCSSRule(rule, uid, mappings),
|
|
80
|
+
);
|
|
81
|
+
return rule;
|
|
81
82
|
default:
|
|
82
83
|
return rule;
|
|
83
84
|
}
|
|
@@ -105,7 +106,7 @@ export default ({ outfile } = {}) => {
|
|
|
105
106
|
if (cssFiles.has(args.path)) {
|
|
106
107
|
({ mappings } = cssFiles.get(args.path));
|
|
107
108
|
} else {
|
|
108
|
-
const { content, priority } =
|
|
109
|
+
const { content, priority } = processCSS(
|
|
109
110
|
contents,
|
|
110
111
|
cssFiles.size,
|
|
111
112
|
mappings,
|