rollup-plugin-react-scoped-css 1.0.0-alpha.12 → 1.0.0-alpha.13
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/dist/css/scope-css.js +18 -32
- package/package.json +1 -1
package/dist/css/scope-css.js
CHANGED
|
@@ -26,31 +26,10 @@ const isScopePiercingPseudoSelector = (item) => {
|
|
|
26
26
|
return (item?.data?.type === "PseudoElementSelector" &&
|
|
27
27
|
(item?.data?.name === "v-deep" || item?.data?.name === "deep"));
|
|
28
28
|
};
|
|
29
|
-
const isThisScopedAttributeSelector = (item, hash) => {
|
|
30
|
-
return (item?.data?.type === "AttributeSelector" && item?.data?.name?.name === hash);
|
|
31
|
-
};
|
|
32
|
-
const isChainedSelector = (item) => {
|
|
33
|
-
return ((item?.data?.type === "TypeSelector" ||
|
|
34
|
-
item?.data?.type === "ClassSelector" ||
|
|
35
|
-
item?.data?.type === "AttributeSelector" ||
|
|
36
|
-
item?.data?.type === "IdSelector" ||
|
|
37
|
-
item?.data?.type === "PseudoClassSelector" ||
|
|
38
|
-
item?.data?.type === "PseudoElementSelector") &&
|
|
39
|
-
(item?.next?.data?.type === "ClassSelector" ||
|
|
40
|
-
item?.next?.data?.type === "AttributeSelector" ||
|
|
41
|
-
item?.next?.data?.type === "IdSelector" ||
|
|
42
|
-
item?.next?.data?.type === "PseudoClassSelector" ||
|
|
43
|
-
item?.next?.data?.type === "PseudoElementSelector"));
|
|
44
|
-
};
|
|
45
29
|
const isPseudoSelector = (item) => {
|
|
46
30
|
return (item?.data?.type === "PseudoClassSelector" ||
|
|
47
31
|
item?.data?.type === "PseudoElementSelector");
|
|
48
32
|
};
|
|
49
|
-
const isNextItemScopable = (item) => {
|
|
50
|
-
return (item?.next?.data?.type === "ClassSelector" ||
|
|
51
|
-
item?.next?.data?.type === "AttributeSelector" ||
|
|
52
|
-
item?.next?.data?.type === "IdSelector");
|
|
53
|
-
};
|
|
54
33
|
const isCombinator = (item) => {
|
|
55
34
|
return item?.data?.type === "Combinator";
|
|
56
35
|
};
|
|
@@ -71,25 +50,32 @@ function scopeCss(css, filename, hash) {
|
|
|
71
50
|
return;
|
|
72
51
|
}
|
|
73
52
|
let item = selector.children.head;
|
|
53
|
+
const itemsToInsertScopeBefore = [];
|
|
54
|
+
let currentChunkIndex = 0;
|
|
74
55
|
while (item !== null) {
|
|
75
|
-
if ((
|
|
76
|
-
|
|
77
|
-
isPseudoSelector(item) ||
|
|
78
|
-
isThisScopedAttributeSelector(item, hash)) {
|
|
79
|
-
item = item?.next ?? null;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (item.next && isScopePiercingPseudoSelector(item.next)) {
|
|
83
|
-
Object.assign(item.next.data, attributeSelector);
|
|
56
|
+
if (isScopePiercingPseudoSelector(item)) {
|
|
57
|
+
Object.assign(item.data, attributeSelector);
|
|
84
58
|
break;
|
|
85
59
|
}
|
|
86
|
-
if (item
|
|
60
|
+
else if (isCombinator(item) || isPseudoSelector(item)) {
|
|
61
|
+
currentChunkIndex += 1;
|
|
62
|
+
}
|
|
63
|
+
else if (item.next) {
|
|
64
|
+
itemsToInsertScopeBefore[currentChunkIndex] = item.next;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
87
67
|
selector.children.appendData(attributeSelector);
|
|
88
68
|
break;
|
|
89
69
|
}
|
|
90
|
-
selector.children.insertData(attributeSelector, item.next);
|
|
91
70
|
item = item?.next ?? null;
|
|
92
71
|
}
|
|
72
|
+
// This is true if one of the two break statements above was run. Which means we don't want to add to the last one.
|
|
73
|
+
if (itemsToInsertScopeBefore[currentChunkIndex]) {
|
|
74
|
+
itemsToInsertScopeBefore.pop();
|
|
75
|
+
}
|
|
76
|
+
itemsToInsertScopeBefore.forEach((scopePositionItem) => {
|
|
77
|
+
selector.children.insertData(attributeSelector, scopePositionItem);
|
|
78
|
+
});
|
|
93
79
|
});
|
|
94
80
|
});
|
|
95
81
|
return (0, css_tree_1.generate)(ast);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rollup-plugin-react-scoped-css",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.13",
|
|
4
4
|
"description": "A rollup plugin designed to allow scoped css to be run in react (Compatible with vite and rollup)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|