tailwindcss 0.0.0-insiders.f4635e0 → 0.0.0-insiders.f6eeed3
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/CHANGELOG.md +360 -1
- package/LICENSE +1 -2
- package/README.md +8 -4
- package/colors.d.ts +3 -0
- package/colors.js +2 -304
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -4
- package/defaultTheme.d.ts +3 -0
- package/defaultTheme.js +2 -4
- package/lib/cli-peer-dependencies.js +5 -10
- package/lib/cli.js +702 -706
- package/lib/constants.js +23 -23
- package/lib/corePluginList.js +175 -4
- package/lib/corePlugins.js +3601 -2950
- package/lib/css/preflight.css +18 -5
- package/lib/featureFlags.js +44 -45
- package/lib/index.js +35 -25
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +47 -36
- package/lib/lib/collapseDuplicateDeclarations.js +80 -0
- package/lib/lib/defaultExtractor.js +44 -0
- package/lib/lib/detectNesting.js +29 -16
- package/lib/lib/evaluateTailwindFunctions.js +134 -155
- package/lib/lib/expandApplyAtRules.js +391 -203
- package/lib/lib/expandTailwindAtRules.js +238 -236
- package/lib/lib/generateRules.js +594 -310
- package/lib/lib/getModuleDependencies.js +38 -43
- package/lib/lib/normalizeTailwindDirectives.js +74 -58
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +129 -91
- package/lib/lib/setupContextUtils.js +806 -666
- package/lib/lib/setupTrackingContext.js +145 -164
- package/lib/lib/sharedState.js +40 -17
- package/lib/lib/substituteScreenAtRules.js +22 -26
- package/{nesting → lib/postcss-plugins/nesting}/README.md +0 -0
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +45 -46
- package/lib/public/colors.js +329 -0
- package/lib/public/create-plugin.js +13 -0
- package/lib/public/default-config.js +14 -0
- package/lib/public/default-theme.js +14 -0
- package/lib/public/resolve-config.js +19 -0
- package/lib/util/bigSign.js +3 -5
- package/lib/util/buildMediaQuery.js +15 -31
- package/lib/util/cloneDeep.js +14 -13
- package/lib/util/cloneNodes.js +21 -14
- package/lib/util/color.js +89 -63
- package/lib/util/configurePlugins.js +13 -14
- package/lib/util/createPlugin.js +20 -24
- package/lib/util/createUtilityPlugin.js +43 -45
- package/lib/util/dataTypes.js +235 -0
- package/lib/util/defaults.js +16 -14
- package/lib/util/escapeClassName.js +12 -14
- package/lib/util/escapeCommas.js +3 -5
- package/lib/util/flattenColorPalette.js +12 -10
- package/lib/util/formatVariantSelector.js +186 -0
- package/lib/util/getAllConfigs.js +23 -16
- package/lib/util/hashConfig.js +10 -10
- package/lib/util/isKeyframeRule.js +3 -5
- package/lib/util/isPlainObject.js +7 -10
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +45 -32
- package/lib/util/nameClass.js +22 -27
- package/lib/util/negateValue.js +14 -15
- package/lib/util/normalizeConfig.js +240 -0
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseAnimationValue.js +83 -54
- package/lib/util/parseBoxShadowValue.js +117 -0
- package/lib/util/parseDependency.js +51 -62
- package/lib/util/parseObjectStyles.js +23 -20
- package/lib/util/pluginUtils.js +146 -285
- package/lib/util/prefixSelector.js +15 -18
- package/lib/util/resolveConfig.js +218 -252
- package/lib/util/resolveConfigPath.js +39 -47
- package/lib/util/responsive.js +12 -11
- package/lib/util/tap.js +4 -6
- package/lib/util/toColorValue.js +3 -5
- package/lib/util/toPath.js +9 -6
- package/lib/util/transformThemeValue.js +53 -26
- package/lib/util/withAlphaVariable.js +59 -57
- package/nesting/index.js +2 -12
- package/package.json +48 -60
- package/peers/index.js +72849 -84292
- package/plugin.d.ts +6 -0
- package/plugin.js +1 -2
- package/resolveConfig.js +2 -7
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +52 -0
- package/src/cli.js +115 -36
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +2147 -1968
- package/src/css/preflight.css +18 -5
- package/src/featureFlags.js +14 -8
- package/src/index.js +14 -6
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +16 -1
- package/src/lib/collapseDuplicateDeclarations.js +93 -0
- package/src/lib/defaultExtractor.js +50 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +6 -3
- package/src/lib/expandApplyAtRules.js +285 -56
- package/src/lib/expandTailwindAtRules.js +87 -57
- package/src/lib/generateRules.js +364 -41
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/resolveDefaultsAtRules.js +81 -40
- package/src/lib/setupContextUtils.js +374 -201
- package/src/lib/setupTrackingContext.js +17 -16
- package/src/lib/sharedState.js +42 -7
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +18 -3
- package/src/public/colors.js +300 -0
- package/src/public/create-plugin.js +2 -0
- package/src/public/default-config.js +4 -0
- package/src/public/default-theme.js +4 -0
- package/src/public/resolve-config.js +7 -0
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +25 -10
- package/src/util/createUtilityPlugin.js +2 -11
- package/src/util/dataTypes.js +250 -0
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +196 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +2 -2
- package/src/util/negateValue.js +4 -2
- package/src/util/normalizeConfig.js +270 -0
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseAnimationValue.js +7 -1
- package/src/util/parseBoxShadowValue.js +119 -0
- package/src/util/parseDependency.js +4 -0
- package/src/util/pluginUtils.js +101 -204
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +53 -66
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +22 -7
- package/src/util/withAlphaVariable.js +13 -8
- package/stubs/defaultConfig.stub.js +168 -99
- package/stubs/simpleConfig.stub.js +0 -1
- package/types/config.d.ts +323 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types.d.ts +1 -0
- package/lib/lib/setupWatchingContext.js +0 -331
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -307
|
@@ -1,120 +1,247 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
2
|
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
|
|
3
|
+
value: true
|
|
5
4
|
});
|
|
6
5
|
exports.default = expandApplyAtRules;
|
|
7
|
-
|
|
8
6
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
9
|
-
|
|
7
|
+
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
10
8
|
var _generateRules = require("./generateRules");
|
|
11
|
-
|
|
12
9
|
var _bigSign = _interopRequireDefault(require("../util/bigSign"));
|
|
13
|
-
|
|
14
10
|
var _escapeClassName = _interopRequireDefault(require("../util/escapeClassName"));
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
function expandApplyAtRules(context) {
|
|
12
|
+
return (root)=>{
|
|
13
|
+
// Build a cache of the user's CSS so we can use it to resolve classes used by @apply
|
|
14
|
+
let localCache = lazyCache(()=>buildLocalApplyCache(root, context)
|
|
15
|
+
);
|
|
16
|
+
processApply(root, context, localCache);
|
|
17
|
+
};
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
function _interopRequireDefault(obj) {
|
|
20
|
+
return obj && obj.__esModule ? obj : {
|
|
21
|
+
default: obj
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/** @typedef {Map<string, [any, import('postcss').Rule[]]>} ApplyCache */ function extractClasses(node) {
|
|
25
|
+
let classes = new Set();
|
|
26
|
+
let container = _postcss.default.root({
|
|
27
|
+
nodes: [
|
|
28
|
+
node.clone()
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
container.walkRules((rule)=>{
|
|
32
|
+
(0, _postcssSelectorParser).default((selectors)=>{
|
|
33
|
+
selectors.walkClasses((classSelector)=>{
|
|
34
|
+
classes.add(classSelector.value);
|
|
35
|
+
});
|
|
36
|
+
}).processSync(rule.selector);
|
|
37
|
+
});
|
|
38
|
+
return Array.from(classes);
|
|
39
|
+
}
|
|
40
|
+
function extractBaseCandidates(candidates, separator) {
|
|
41
|
+
let baseClasses = new Set();
|
|
42
|
+
for (let candidate of candidates){
|
|
43
|
+
baseClasses.add(candidate.split(separator).pop());
|
|
32
44
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
return Array.from(baseClasses);
|
|
46
|
+
}
|
|
47
|
+
function prefix(context, selector) {
|
|
48
|
+
let prefix1 = context.tailwindConfig.prefix;
|
|
49
|
+
return typeof prefix1 === "function" ? prefix1(selector) : prefix1 + selector;
|
|
50
|
+
}
|
|
51
|
+
function* pathToRoot(node) {
|
|
52
|
+
yield node;
|
|
53
|
+
while(node.parent){
|
|
54
|
+
yield node.parent;
|
|
55
|
+
node = node.parent;
|
|
39
56
|
}
|
|
40
|
-
|
|
41
|
-
context.applyClassCache.set(candidate, matches);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return context.applyClassCache;
|
|
45
57
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Only clone the node itself and not its children
|
|
60
|
+
*
|
|
61
|
+
* @param {*} node
|
|
62
|
+
* @param {*} overrides
|
|
63
|
+
* @returns
|
|
64
|
+
*/ function shallowClone(node, overrides = {}) {
|
|
65
|
+
let children = node.nodes;
|
|
66
|
+
node.nodes = [];
|
|
67
|
+
let tmp = node.clone(overrides);
|
|
68
|
+
node.nodes = children;
|
|
69
|
+
return tmp;
|
|
55
70
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Clone just the nodes all the way to the top that are required to represent
|
|
73
|
+
* this singular rule in the tree.
|
|
74
|
+
*
|
|
75
|
+
* For example, if we have CSS like this:
|
|
76
|
+
* ```css
|
|
77
|
+
* @media (min-width: 768px) {
|
|
78
|
+
* @supports (display: grid) {
|
|
79
|
+
* .foo {
|
|
80
|
+
* display: grid;
|
|
81
|
+
* grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
82
|
+
* }
|
|
83
|
+
* }
|
|
84
|
+
*
|
|
85
|
+
* @supports (backdrop-filter: blur(1px)) {
|
|
86
|
+
* .bar {
|
|
87
|
+
* backdrop-filter: blur(1px);
|
|
88
|
+
* }
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* .baz {
|
|
92
|
+
* color: orange;
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* And we're cloning `.bar` it'll return a cloned version of what's required for just that single node:
|
|
98
|
+
*
|
|
99
|
+
* ```css
|
|
100
|
+
* @media (min-width: 768px) {
|
|
101
|
+
* @supports (backdrop-filter: blur(1px)) {
|
|
102
|
+
* .bar {
|
|
103
|
+
* backdrop-filter: blur(1px);
|
|
104
|
+
* }
|
|
105
|
+
* }
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @param {import('postcss').Node} node
|
|
110
|
+
*/ function nestedClone(node) {
|
|
111
|
+
for (let parent of pathToRoot(node)){
|
|
112
|
+
if (node === parent) {
|
|
113
|
+
continue;
|
|
72
114
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
nodeGroups.push(lastGroup);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (nodeGroups.length === 1) {
|
|
85
|
-
continue;
|
|
115
|
+
if (parent.type === "root") {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
node = shallowClone(parent, {
|
|
119
|
+
nodes: [
|
|
120
|
+
node
|
|
121
|
+
]
|
|
122
|
+
});
|
|
86
123
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
124
|
+
return node;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @param {import('postcss').Root} root
|
|
128
|
+
*/ function buildLocalApplyCache(root, context) {
|
|
129
|
+
/** @type {ApplyCache} */ let cache = new Map();
|
|
130
|
+
let highestOffset = context.layerOrder.user >> 4n;
|
|
131
|
+
root.walkRules((rule, idx)=>{
|
|
132
|
+
// Ignore rules generated by Tailwind
|
|
133
|
+
for (let node of pathToRoot(rule)){
|
|
134
|
+
var ref;
|
|
135
|
+
if (((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.layer) !== undefined) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Clone what's required to represent this singular rule in the tree
|
|
140
|
+
let container = nestedClone(rule);
|
|
141
|
+
for (let className of extractClasses(rule)){
|
|
142
|
+
let list = cache.get(className) || [];
|
|
143
|
+
cache.set(className, list);
|
|
144
|
+
list.push([
|
|
145
|
+
{
|
|
146
|
+
layer: "user",
|
|
147
|
+
sort: BigInt(idx) + highestOffset,
|
|
148
|
+
important: false
|
|
149
|
+
},
|
|
150
|
+
container,
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return cache;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @returns {ApplyCache}
|
|
158
|
+
*/ function buildApplyCache(applyCandidates, context) {
|
|
159
|
+
for (let candidate of applyCandidates){
|
|
160
|
+
if (context.notClassCache.has(candidate) || context.applyClassCache.has(candidate)) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (context.classCache.has(candidate)) {
|
|
164
|
+
context.applyClassCache.set(candidate, context.classCache.get(candidate).map(([meta, rule])=>[
|
|
165
|
+
meta,
|
|
166
|
+
rule.clone()
|
|
167
|
+
]
|
|
168
|
+
));
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
let matches = Array.from((0, _generateRules).resolveMatches(candidate, context));
|
|
172
|
+
if (matches.length === 0) {
|
|
173
|
+
context.notClassCache.add(candidate);
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
context.applyClassCache.set(candidate, matches);
|
|
94
177
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
178
|
+
return context.applyClassCache;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Build a cache only when it's first used
|
|
182
|
+
*
|
|
183
|
+
* @param {() => ApplyCache} buildCacheFn
|
|
184
|
+
* @returns {ApplyCache}
|
|
185
|
+
*/ function lazyCache(buildCacheFn) {
|
|
186
|
+
let cache = null;
|
|
187
|
+
return {
|
|
188
|
+
get: (name)=>{
|
|
189
|
+
cache = cache || buildCacheFn();
|
|
190
|
+
return cache.get(name);
|
|
191
|
+
},
|
|
192
|
+
has: (name)=>{
|
|
193
|
+
cache = cache || buildCacheFn();
|
|
194
|
+
return cache.has(name);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Take a series of multiple caches and merge
|
|
200
|
+
* them so they act like one large cache
|
|
201
|
+
*
|
|
202
|
+
* @param {ApplyCache[]} caches
|
|
203
|
+
* @returns {ApplyCache}
|
|
204
|
+
*/ function combineCaches(caches) {
|
|
205
|
+
return {
|
|
206
|
+
get: (name)=>caches.flatMap((cache)=>cache.get(name) || []
|
|
207
|
+
)
|
|
208
|
+
,
|
|
209
|
+
has: (name)=>caches.some((cache)=>cache.has(name)
|
|
210
|
+
)
|
|
211
|
+
};
|
|
98
212
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
for (let util of candidates) {
|
|
108
|
-
applyCandidates.add(util);
|
|
213
|
+
function extractApplyCandidates(params) {
|
|
214
|
+
let candidates = params.split(/[\s\t\n]+/g);
|
|
215
|
+
if (candidates[candidates.length - 1] === "!important") {
|
|
216
|
+
return [
|
|
217
|
+
candidates.slice(0, -1),
|
|
218
|
+
true
|
|
219
|
+
];
|
|
109
220
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
let
|
|
117
|
-
|
|
221
|
+
return [
|
|
222
|
+
candidates,
|
|
223
|
+
false
|
|
224
|
+
];
|
|
225
|
+
}
|
|
226
|
+
function processApply(root, context, localCache) {
|
|
227
|
+
let applyCandidates = new Set();
|
|
228
|
+
// Collect all @apply rules and candidates
|
|
229
|
+
let applies = [];
|
|
230
|
+
root.walkAtRules("apply", (rule)=>{
|
|
231
|
+
let [candidates] = extractApplyCandidates(rule.params);
|
|
232
|
+
for (let util of candidates){
|
|
233
|
+
applyCandidates.add(util);
|
|
234
|
+
}
|
|
235
|
+
applies.push(rule);
|
|
236
|
+
});
|
|
237
|
+
// Start the @apply process if we have rules with @apply in them
|
|
238
|
+
if (applies.length > 0) {
|
|
239
|
+
// Fill up some caches!
|
|
240
|
+
let applyClassCache = combineCaches([
|
|
241
|
+
localCache,
|
|
242
|
+
buildApplyCache(applyCandidates, context)
|
|
243
|
+
]);
|
|
244
|
+
/**
|
|
118
245
|
* When we have an apply like this:
|
|
119
246
|
*
|
|
120
247
|
* .abc {
|
|
@@ -133,113 +260,174 @@ function processApply(root, context) {
|
|
|
133
260
|
* What happens in this function is that we prepend a `.` and escape the candidate.
|
|
134
261
|
* This will result in `.hover\:font-bold`
|
|
135
262
|
* Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
replaced.push(replacedSelector);
|
|
263
|
+
*/ // TODO: Should we use postcss-selector-parser for this instead?
|
|
264
|
+
function replaceSelector(selector, utilitySelectors, candidate) {
|
|
265
|
+
let needle = `.${(0, _escapeClassName).default(candidate)}`;
|
|
266
|
+
let utilitySelectorsList = utilitySelectors.split(/\s*\,(?![^(]*\))\s*/g);
|
|
267
|
+
return selector.split(/\s*\,(?![^(]*\))\s*/g).map((s)=>{
|
|
268
|
+
let replaced = [];
|
|
269
|
+
for (let utilitySelector of utilitySelectorsList){
|
|
270
|
+
let replacedSelector = utilitySelector.replace(needle, s);
|
|
271
|
+
if (replacedSelector === utilitySelector) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
replaced.push(replacedSelector);
|
|
275
|
+
}
|
|
276
|
+
return replaced.join(", ");
|
|
277
|
+
}).join(", ");
|
|
153
278
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
279
|
+
let perParentApplies = new Map();
|
|
280
|
+
// Collect all apply candidates and their rules
|
|
281
|
+
for (let apply of applies){
|
|
282
|
+
let candidates = perParentApplies.get(apply.parent) || [];
|
|
283
|
+
perParentApplies.set(apply.parent, [
|
|
284
|
+
candidates,
|
|
285
|
+
apply.source
|
|
286
|
+
]);
|
|
287
|
+
let [applyCandidates, important] = extractApplyCandidates(apply.params);
|
|
288
|
+
if (apply.parent.type === "atrule") {
|
|
289
|
+
if (apply.parent.name === "screen") {
|
|
290
|
+
const screenType = apply.parent.params;
|
|
291
|
+
throw apply.error(`@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates.map((c)=>`${screenType}:${c}`
|
|
292
|
+
).join(" ")} instead.`);
|
|
293
|
+
}
|
|
294
|
+
throw apply.error(`@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`);
|
|
295
|
+
}
|
|
296
|
+
for (let applyCandidate of applyCandidates){
|
|
297
|
+
if ([
|
|
298
|
+
prefix(context, "group"),
|
|
299
|
+
prefix(context, "peer")
|
|
300
|
+
].includes(applyCandidate)) {
|
|
301
|
+
// TODO: Link to specific documentation page with error code.
|
|
302
|
+
throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`);
|
|
303
|
+
}
|
|
304
|
+
if (!applyClassCache.has(applyCandidate)) {
|
|
305
|
+
throw apply.error(`The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`);
|
|
306
|
+
}
|
|
307
|
+
let rules = applyClassCache.get(applyCandidate);
|
|
308
|
+
candidates.push([
|
|
309
|
+
applyCandidate,
|
|
310
|
+
important,
|
|
311
|
+
rules
|
|
312
|
+
]);
|
|
313
|
+
}
|
|
170
314
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
315
|
+
for (const [parent, [candidates, atApplySource]] of perParentApplies){
|
|
316
|
+
let siblings = [];
|
|
317
|
+
for (let [applyCandidate, important, rules] of candidates){
|
|
318
|
+
for (let [meta, node1] of rules){
|
|
319
|
+
let parentClasses = extractClasses(parent);
|
|
320
|
+
let nodeClasses = extractClasses(node1);
|
|
321
|
+
// Add base utility classes from the @apply node to the list of
|
|
322
|
+
// classes to check whether it intersects and therefore results in a
|
|
323
|
+
// circular dependency or not.
|
|
324
|
+
//
|
|
325
|
+
// E.g.:
|
|
326
|
+
// .foo {
|
|
327
|
+
// @apply hover:a; // This applies "a" but with a modifier
|
|
328
|
+
// }
|
|
329
|
+
//
|
|
330
|
+
// We only have to do that with base classes of the `node`, not of the `parent`
|
|
331
|
+
// E.g.:
|
|
332
|
+
// .hover\:foo {
|
|
333
|
+
// @apply bar;
|
|
334
|
+
// }
|
|
335
|
+
// .bar {
|
|
336
|
+
// @apply foo;
|
|
337
|
+
// }
|
|
338
|
+
//
|
|
339
|
+
// This should not result in a circular dependency because we are
|
|
340
|
+
// just applying `.foo` and the rule above is `.hover\:foo` which is
|
|
341
|
+
// unrelated. However, if we were to apply `hover:foo` then we _did_
|
|
342
|
+
// have to include this one.
|
|
343
|
+
nodeClasses = nodeClasses.concat(extractBaseCandidates(nodeClasses, context.tailwindConfig.separator));
|
|
344
|
+
let intersects = parentClasses.some((selector)=>nodeClasses.includes(selector)
|
|
345
|
+
);
|
|
346
|
+
if (intersects) {
|
|
347
|
+
throw node1.error(`You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`);
|
|
348
|
+
}
|
|
349
|
+
let root = _postcss.default.root({
|
|
350
|
+
nodes: [
|
|
351
|
+
node1.clone()
|
|
352
|
+
]
|
|
353
|
+
});
|
|
354
|
+
// Make sure every node in the entire tree points back at the @apply rule that generated it
|
|
355
|
+
root.walk((node)=>{
|
|
356
|
+
node.source = atApplySource;
|
|
357
|
+
});
|
|
358
|
+
let canRewriteSelector = node1.type !== "atrule" || node1.type === "atrule" && node1.name !== "keyframes";
|
|
359
|
+
if (canRewriteSelector) {
|
|
360
|
+
root.walkRules((rule)=>{
|
|
361
|
+
// Let's imagine you have the following structure:
|
|
362
|
+
//
|
|
363
|
+
// .foo {
|
|
364
|
+
// @apply bar;
|
|
365
|
+
// }
|
|
366
|
+
//
|
|
367
|
+
// @supports (a: b) {
|
|
368
|
+
// .bar {
|
|
369
|
+
// color: blue
|
|
370
|
+
// }
|
|
371
|
+
//
|
|
372
|
+
// .something-unrelated {}
|
|
373
|
+
// }
|
|
374
|
+
//
|
|
375
|
+
// In this case we want to apply `.bar` but it happens to be in
|
|
376
|
+
// an atrule node. We clone that node instead of the nested one
|
|
377
|
+
// because we still want that @supports rule to be there once we
|
|
378
|
+
// applied everything.
|
|
379
|
+
//
|
|
380
|
+
// However it happens to be that the `.something-unrelated` is
|
|
381
|
+
// also in that same shared @supports atrule. This is not good,
|
|
382
|
+
// and this should not be there. The good part is that this is
|
|
383
|
+
// a clone already and it can be safely removed. The question is
|
|
384
|
+
// how do we know we can remove it. Basically what we can do is
|
|
385
|
+
// match it against the applyCandidate that you want to apply. If
|
|
386
|
+
// it doesn't match the we can safely delete it.
|
|
387
|
+
//
|
|
388
|
+
// If we didn't do this, then the `replaceSelector` function
|
|
389
|
+
// would have replaced this with something that didn't exist and
|
|
390
|
+
// therefore it removed the selector altogether. In this specific
|
|
391
|
+
// case it would result in `{}` instead of `.something-unrelated {}`
|
|
392
|
+
if (!extractClasses(rule).some((candidate)=>candidate === applyCandidate
|
|
393
|
+
)) {
|
|
394
|
+
rule.remove();
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate);
|
|
398
|
+
rule.walkDecls((d)=>{
|
|
399
|
+
d.important = meta.important || important;
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
// Insert it
|
|
404
|
+
siblings.push([
|
|
405
|
+
// Ensure that when we are sorting, that we take the layer order into account
|
|
406
|
+
{
|
|
407
|
+
...meta,
|
|
408
|
+
sort: meta.sort | context.layerOrder[meta.layer]
|
|
409
|
+
},
|
|
410
|
+
root.nodes[0],
|
|
411
|
+
]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// Inject the rules, sorted, correctly
|
|
415
|
+
let nodes = siblings.sort(([a], [z])=>(0, _bigSign).default(a.sort - z.sort)
|
|
416
|
+
).map((s)=>s[1]
|
|
417
|
+
);
|
|
418
|
+
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
419
|
+
parent.after(nodes);
|
|
183
420
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
for (let [applyCandidate, important, rules] of candidates) {
|
|
194
|
-
for (let [meta, node] of rules) {
|
|
195
|
-
let root = _postcss.default.root({
|
|
196
|
-
nodes: [node.clone()]
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
let canRewriteSelector = node.type !== 'atrule' || node.type === 'atrule' && node.name !== 'keyframes';
|
|
200
|
-
|
|
201
|
-
if (canRewriteSelector) {
|
|
202
|
-
root.walkRules(rule => {
|
|
203
|
-
rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate);
|
|
204
|
-
rule.walkDecls(d => {
|
|
205
|
-
d.important = meta.important || important;
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
} // Insert it
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
siblings.push([// Ensure that when we are sorting, that we take the layer order into account
|
|
212
|
-
{ ...meta,
|
|
213
|
-
sort: meta.sort | context.layerOrder[meta.layer]
|
|
214
|
-
}, root.nodes[0]]);
|
|
421
|
+
for (let apply1 of applies){
|
|
422
|
+
// If there are left-over declarations, just remove the @apply
|
|
423
|
+
if (apply1.parent.nodes.length > 1) {
|
|
424
|
+
apply1.remove();
|
|
425
|
+
} else {
|
|
426
|
+
// The node is empty, drop the full node
|
|
427
|
+
apply1.parent.remove();
|
|
428
|
+
}
|
|
215
429
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
let nodes = siblings.sort(([a], [z]) => (0, _bigSign.default)(a.sort - z.sort)).map(s => s[1]); // console.log(parent)
|
|
220
|
-
// `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
|
|
221
|
-
|
|
222
|
-
parent.after(nodes);
|
|
430
|
+
// Do it again, in case we have other `@apply` rules
|
|
431
|
+
processApply(root, context, localCache);
|
|
223
432
|
}
|
|
224
|
-
|
|
225
|
-
for (let apply of applies) {
|
|
226
|
-
// If there are left-over declarations, just remove the @apply
|
|
227
|
-
if (apply.parent.nodes.length > 1) {
|
|
228
|
-
apply.remove();
|
|
229
|
-
} else {
|
|
230
|
-
// The node is empty, drop the full node
|
|
231
|
-
apply.parent.remove();
|
|
232
|
-
}
|
|
233
|
-
} // Do it again, in case we have other `@apply` rules
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
processApply(root, context);
|
|
237
|
-
}
|
|
238
433
|
}
|
|
239
|
-
|
|
240
|
-
function expandApplyAtRules(context) {
|
|
241
|
-
return root => {
|
|
242
|
-
partitionApplyParents(root);
|
|
243
|
-
processApply(root, context);
|
|
244
|
-
};
|
|
245
|
-
}
|