tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce
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 +380 -1
- package/LICENSE +1 -2
- package/README.md +8 -4
- package/colors.d.ts +3 -0
- package/colors.js +2 -1
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -1
- package/defaultTheme.d.ts +3 -0
- package/defaultTheme.js +2 -1
- package/lib/cli-peer-dependencies.js +10 -5
- package/lib/cli.js +311 -213
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +11 -1
- package/lib/corePlugins.js +1895 -1773
- package/lib/css/preflight.css +19 -13
- package/lib/featureFlags.js +22 -16
- package/lib/index.js +17 -8
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +30 -14
- package/lib/lib/collapseDuplicateDeclarations.js +80 -0
- package/lib/lib/defaultExtractor.js +187 -0
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +40 -24
- package/lib/lib/expandApplyAtRules.js +414 -157
- package/lib/lib/expandTailwindAtRules.js +156 -151
- package/lib/lib/generateRules.js +402 -68
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +45 -36
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/regex.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +105 -90
- package/lib/lib/setupContextUtils.js +416 -291
- package/lib/lib/setupTrackingContext.js +60 -56
- package/lib/lib/sharedState.js +38 -15
- package/lib/lib/substituteScreenAtRules.js +9 -6
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +21 -9
- package/lib/public/colors.js +244 -248
- package/lib/public/resolve-config.js +5 -5
- package/lib/util/buildMediaQuery.js +13 -24
- package/lib/util/cloneDeep.js +1 -1
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +43 -32
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +13 -17
- package/lib/util/dataTypes.js +114 -74
- package/lib/util/defaults.js +6 -0
- package/lib/util/escapeClassName.js +5 -5
- package/lib/util/escapeCommas.js +1 -1
- package/lib/util/flattenColorPalette.js +2 -4
- package/lib/util/formatVariantSelector.js +194 -0
- package/lib/util/getAllConfigs.js +13 -5
- package/lib/util/hashConfig.js +5 -5
- package/lib/util/isKeyframeRule.js +1 -1
- package/lib/util/isPlainObject.js +1 -1
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +35 -19
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +5 -3
- package/lib/util/normalizeConfig.js +233 -0
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseAnimationValue.js +56 -56
- package/lib/util/parseBoxShadowValue.js +76 -0
- package/lib/util/parseDependency.js +32 -32
- package/lib/util/parseObjectStyles.js +6 -6
- package/lib/util/pluginUtils.js +67 -170
- package/lib/util/prefixSelector.js +4 -7
- package/lib/util/resolveConfig.js +123 -133
- package/lib/util/resolveConfigPath.js +17 -18
- package/lib/util/responsive.js +6 -6
- package/lib/util/splitAtTopLevelOnly.js +72 -0
- package/lib/util/toColorValue.js +1 -2
- package/lib/util/toPath.js +6 -1
- package/lib/util/transformThemeValue.js +42 -34
- package/lib/util/validateConfig.js +21 -0
- package/lib/util/withAlphaVariable.js +19 -19
- package/nesting/index.js +2 -12
- package/package.json +41 -42
- package/peers/index.js +11539 -10859
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +52 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +174 -41
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +641 -596
- package/src/css/preflight.css +19 -13
- package/src/featureFlags.js +16 -10
- package/src/index.js +14 -6
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +93 -0
- package/src/lib/defaultExtractor.js +192 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +24 -7
- package/src/lib/expandApplyAtRules.js +442 -154
- package/src/lib/expandTailwindAtRules.js +91 -65
- package/src/lib/generateRules.js +409 -43
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +74 -53
- package/src/lib/setupContextUtils.js +388 -208
- package/src/lib/setupTrackingContext.js +15 -12
- 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 +17 -2
- package/src/public/colors.js +4 -9
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -2
- package/src/util/dataTypes.js +56 -16
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +213 -0
- package/src/util/getAllConfigs.js +7 -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 +262 -0
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/pluginUtils.js +51 -147
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +108 -79
- package/src/util/splitAtTopLevelOnly.js +71 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +24 -7
- package/src/util/validateConfig.js +13 -0
- package/stubs/defaultConfig.stub.js +157 -94
- package/stubs/simpleConfig.stub.js +0 -1
- package/types/config.d.ts +325 -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 -284
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -306
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
exports.isValidVariantFormatString = isValidVariantFormatString;
|
|
6
|
+
exports.parseVariant = parseVariant;
|
|
5
7
|
exports.getFileModifiedMap = getFileModifiedMap;
|
|
6
8
|
exports.createContext = createContext;
|
|
7
9
|
exports.getContext = getContext;
|
|
@@ -18,10 +20,14 @@ var _escapeClassName = _interopRequireDefault(require("../util/escapeClassName")
|
|
|
18
20
|
var _nameClass = _interopRequireWildcard(require("../util/nameClass"));
|
|
19
21
|
var _pluginUtils = require("../util/pluginUtils");
|
|
20
22
|
var _bigSign = _interopRequireDefault(require("../util/bigSign"));
|
|
21
|
-
var _corePlugins =
|
|
23
|
+
var _corePlugins = require("../corePlugins");
|
|
22
24
|
var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
23
25
|
var _toPath = require("../util/toPath");
|
|
24
26
|
var _log = _interopRequireDefault(require("../util/log"));
|
|
27
|
+
var _negateValue = _interopRequireDefault(require("../util/negateValue"));
|
|
28
|
+
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
29
|
+
var _generateRules = require("./generateRules");
|
|
30
|
+
var _cacheInvalidationJs = require("./cacheInvalidation.js");
|
|
25
31
|
function _interopRequireDefault(obj) {
|
|
26
32
|
return obj && obj.__esModule ? obj : {
|
|
27
33
|
default: obj
|
|
@@ -31,13 +37,11 @@ function _interopRequireWildcard(obj) {
|
|
|
31
37
|
if (obj && obj.__esModule) {
|
|
32
38
|
return obj;
|
|
33
39
|
} else {
|
|
34
|
-
var newObj = {
|
|
35
|
-
};
|
|
40
|
+
var newObj = {};
|
|
36
41
|
if (obj != null) {
|
|
37
42
|
for(var key in obj){
|
|
38
43
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
39
|
-
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
|
|
40
|
-
};
|
|
44
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
41
45
|
if (desc.get || desc.set) {
|
|
42
46
|
Object.defineProperty(newObj, key, desc);
|
|
43
47
|
} else {
|
|
@@ -50,8 +54,36 @@ function _interopRequireWildcard(obj) {
|
|
|
50
54
|
return newObj;
|
|
51
55
|
}
|
|
52
56
|
}
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
let MATCH_VARIANT = Symbol();
|
|
58
|
+
function prefix(context, selector) {
|
|
59
|
+
let prefix1 = context.tailwindConfig.prefix;
|
|
60
|
+
return typeof prefix1 === "function" ? prefix1(selector) : prefix1 + selector;
|
|
61
|
+
}
|
|
62
|
+
function parseVariantFormatString(input) {
|
|
63
|
+
if (input.includes("{")) {
|
|
64
|
+
if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`);
|
|
65
|
+
return input.split(/{(.*)}/gim).flatMap((line)=>parseVariantFormatString(line)
|
|
66
|
+
).filter(Boolean);
|
|
67
|
+
}
|
|
68
|
+
return [
|
|
69
|
+
input.trim()
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
function isBalanced(input) {
|
|
73
|
+
let count = 0;
|
|
74
|
+
for (let char of input){
|
|
75
|
+
if (char === "{") {
|
|
76
|
+
count++;
|
|
77
|
+
} else if (char === "}") {
|
|
78
|
+
if (--count < 0) {
|
|
79
|
+
return false // unbalanced
|
|
80
|
+
;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return count === 0;
|
|
85
|
+
}
|
|
86
|
+
function insertInto(list, value, { before =[] } = {}) {
|
|
55
87
|
before = [].concat(before);
|
|
56
88
|
if (before.length <= 0) {
|
|
57
89
|
list.push(value);
|
|
@@ -76,9 +108,12 @@ function parseStyles(styles) {
|
|
|
76
108
|
return isNode ? style : (0, _parseObjectStyles).default(style);
|
|
77
109
|
});
|
|
78
110
|
}
|
|
79
|
-
function getClasses(selector) {
|
|
111
|
+
function getClasses(selector, mutate) {
|
|
80
112
|
let parser = (0, _postcssSelectorParser).default((selectors)=>{
|
|
81
113
|
let allClasses = [];
|
|
114
|
+
if (mutate) {
|
|
115
|
+
mutate(selectors);
|
|
116
|
+
}
|
|
82
117
|
selectors.walkClasses((classNode)=>{
|
|
83
118
|
allClasses.push(classNode.value);
|
|
84
119
|
});
|
|
@@ -86,44 +121,60 @@ function getClasses(selector) {
|
|
|
86
121
|
});
|
|
87
122
|
return parser.transformSync(selector);
|
|
88
123
|
}
|
|
89
|
-
function extractCandidates(node
|
|
124
|
+
function extractCandidates(node, state = {
|
|
125
|
+
containsNonOnDemandable: false
|
|
126
|
+
}, depth = 0) {
|
|
90
127
|
let classes = [];
|
|
91
|
-
|
|
128
|
+
// Handle normal rules
|
|
129
|
+
if (node.type === "rule") {
|
|
130
|
+
// Ignore everything inside a :not(...). This allows you to write code like
|
|
131
|
+
// `div:not(.foo)`. If `.foo` is never found in your code, then we used to
|
|
132
|
+
// not generated it. But now we will ignore everything inside a `:not`, so
|
|
133
|
+
// that it still gets generated.
|
|
134
|
+
function ignoreNot(selectors) {
|
|
135
|
+
selectors.walkPseudos((pseudo)=>{
|
|
136
|
+
if (pseudo.value === ":not") {
|
|
137
|
+
pseudo.remove();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
92
141
|
for (let selector of node.selectors){
|
|
93
|
-
let classCandidates = getClasses(selector);
|
|
142
|
+
let classCandidates = getClasses(selector, ignoreNot);
|
|
94
143
|
// At least one of the selectors contains non-"on-demandable" candidates.
|
|
95
|
-
if (classCandidates.length === 0)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
144
|
+
if (classCandidates.length === 0) {
|
|
145
|
+
state.containsNonOnDemandable = true;
|
|
146
|
+
}
|
|
147
|
+
for (let classCandidate of classCandidates){
|
|
148
|
+
classes.push(classCandidate);
|
|
149
|
+
}
|
|
100
150
|
}
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
if (node.type === 'atrule') {
|
|
151
|
+
} else if (node.type === "atrule") {
|
|
104
152
|
node.walkRules((rule)=>{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
];
|
|
153
|
+
for (let classCandidate of rule.selectors.flatMap((selector)=>getClasses(selector)
|
|
154
|
+
)){
|
|
155
|
+
classes.push(classCandidate);
|
|
156
|
+
}
|
|
110
157
|
});
|
|
111
158
|
}
|
|
159
|
+
if (depth === 0) {
|
|
160
|
+
return [
|
|
161
|
+
state.containsNonOnDemandable || classes.length === 0,
|
|
162
|
+
classes
|
|
163
|
+
];
|
|
164
|
+
}
|
|
112
165
|
return classes;
|
|
113
166
|
}
|
|
114
167
|
function withIdentifiers(styles) {
|
|
115
168
|
return parseStyles(styles).flatMap((node)=>{
|
|
116
169
|
let nodeMap = new Map();
|
|
117
|
-
let candidates = extractCandidates(node);
|
|
118
|
-
// If this isn't "on-demandable", assign it a universal candidate.
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
[
|
|
122
|
-
'*',
|
|
123
|
-
node
|
|
124
|
-
]
|
|
125
|
-
];
|
|
170
|
+
let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node);
|
|
171
|
+
// If this isn't "on-demandable", assign it a universal candidate to always include it.
|
|
172
|
+
if (containsNonOnDemandableSelectors) {
|
|
173
|
+
candidates.unshift(sharedState.NOT_ON_DEMAND);
|
|
126
174
|
}
|
|
175
|
+
// However, it could be that it also contains "on-demandable" candidates.
|
|
176
|
+
// E.g.: `span, .foo {}`, in that case it should still be possible to use
|
|
177
|
+
// `@apply foo` for example.
|
|
127
178
|
return candidates.map((c)=>{
|
|
128
179
|
if (!nodeMap.has(node)) {
|
|
129
180
|
nodeMap.set(node, node);
|
|
@@ -135,67 +186,28 @@ function withIdentifiers(styles) {
|
|
|
135
186
|
});
|
|
136
187
|
});
|
|
137
188
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
[
|
|
148
|
-
'(',
|
|
149
|
-
')'
|
|
150
|
-
],
|
|
151
|
-
]);
|
|
152
|
-
let inverseMatchingBrackets = new Map(Array.from(matchingBrackets.entries()).map(([k, v])=>[
|
|
153
|
-
v,
|
|
154
|
-
k
|
|
155
|
-
]
|
|
156
|
-
));
|
|
157
|
-
let quotes = new Set([
|
|
158
|
-
'"',
|
|
159
|
-
"'",
|
|
160
|
-
'`'
|
|
161
|
-
]);
|
|
162
|
-
// Arbitrary values must contain balanced brackets (), [] and {}. Escaped
|
|
163
|
-
// values don't count, and brackets inside quotes also don't count.
|
|
164
|
-
//
|
|
165
|
-
// E.g.: w-[this-is]w-[weird-and-invalid]
|
|
166
|
-
// E.g.: w-[this-is\\]w-\\[weird-but-valid]
|
|
167
|
-
// E.g.: content-['this-is-also-valid]-weirdly-enough']
|
|
168
|
-
function isValidArbitraryValue(value) {
|
|
169
|
-
let stack = [];
|
|
170
|
-
let inQuotes = false;
|
|
171
|
-
for(let i = 0; i < value.length; i++){
|
|
172
|
-
let char = value[i];
|
|
173
|
-
// Non-escaped quotes allow us to "allow" anything in between
|
|
174
|
-
if (quotes.has(char) && value[i - 1] !== '\\') {
|
|
175
|
-
inQuotes = !inQuotes;
|
|
189
|
+
function isValidVariantFormatString(format) {
|
|
190
|
+
return format.startsWith("@") || format.includes("&");
|
|
191
|
+
}
|
|
192
|
+
function parseVariant(variant) {
|
|
193
|
+
variant = variant.replace(/\n+/g, "").replace(/\s{1,}/g, " ").trim();
|
|
194
|
+
let fns = parseVariantFormatString(variant).map((str)=>{
|
|
195
|
+
if (!str.startsWith("@")) {
|
|
196
|
+
return ({ format })=>format(str)
|
|
197
|
+
;
|
|
176
198
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
// Popped value must match the inverse value, otherwise it is unbalanced
|
|
188
|
-
if (stack.pop() !== inverse) {
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
199
|
+
let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str);
|
|
200
|
+
return ({ wrap })=>wrap(_postcss.default.atRule({
|
|
201
|
+
name,
|
|
202
|
+
params: params.trim()
|
|
203
|
+
}))
|
|
204
|
+
;
|
|
205
|
+
}).reverse();
|
|
206
|
+
return (api)=>{
|
|
207
|
+
for (let fn of fns){
|
|
208
|
+
fn(api);
|
|
191
209
|
}
|
|
192
|
-
}
|
|
193
|
-
// If there is still something on the stack, it is also unbalanced
|
|
194
|
-
if (stack.length > 0) {
|
|
195
|
-
return false;
|
|
196
|
-
}
|
|
197
|
-
// All good, totally balanced!
|
|
198
|
-
return true;
|
|
210
|
+
};
|
|
199
211
|
}
|
|
200
212
|
function buildPluginApi(tailwindConfig, context, { variantList , variantMap , offsets , classList }) {
|
|
201
213
|
function getConfigValue(path, defaultValue) {
|
|
@@ -205,43 +217,41 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
205
217
|
return (0, _prefixSelector).default(tailwindConfig.prefix, selector);
|
|
206
218
|
}
|
|
207
219
|
function prefixIdentifier(identifier, options) {
|
|
208
|
-
if (identifier ===
|
|
209
|
-
return
|
|
220
|
+
if (identifier === sharedState.NOT_ON_DEMAND) {
|
|
221
|
+
return sharedState.NOT_ON_DEMAND;
|
|
210
222
|
}
|
|
211
223
|
if (!options.respectPrefix) {
|
|
212
224
|
return identifier;
|
|
213
225
|
}
|
|
214
|
-
if (typeof context.tailwindConfig.prefix === 'function') {
|
|
215
|
-
return (0, _prefixSelector).default(context.tailwindConfig.prefix, `.${identifier}`).substr(1);
|
|
216
|
-
}
|
|
217
226
|
return context.tailwindConfig.prefix + identifier;
|
|
218
227
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
228
|
+
function resolveThemeValue(path, defaultValue, opts = {}) {
|
|
229
|
+
const [pathRoot, ...subPaths] = (0, _toPath).toPath(path);
|
|
230
|
+
const value = getConfigValue([
|
|
231
|
+
"theme",
|
|
232
|
+
pathRoot,
|
|
233
|
+
...subPaths
|
|
234
|
+
], defaultValue);
|
|
235
|
+
return (0, _transformThemeValue).default(pathRoot)(value, opts);
|
|
236
|
+
}
|
|
237
|
+
const theme = Object.assign((path, defaultValue = undefined)=>resolveThemeValue(path, defaultValue)
|
|
238
|
+
, {
|
|
239
|
+
withAlpha: (path, opacityValue)=>resolveThemeValue(path, undefined, {
|
|
240
|
+
opacityValue
|
|
241
|
+
})
|
|
242
|
+
});
|
|
243
|
+
let api1 = {
|
|
226
244
|
postcss: _postcss.default,
|
|
227
245
|
prefix: applyConfiguredPrefix,
|
|
228
246
|
e: _escapeClassName.default,
|
|
229
247
|
config: getConfigValue,
|
|
230
|
-
theme
|
|
231
|
-
const [pathRoot, ...subPaths] = (0, _toPath).toPath(path);
|
|
232
|
-
const value = getConfigValue([
|
|
233
|
-
'theme',
|
|
234
|
-
pathRoot,
|
|
235
|
-
...subPaths
|
|
236
|
-
], defaultValue);
|
|
237
|
-
return (0, _transformThemeValue).default(pathRoot)(value);
|
|
238
|
-
},
|
|
248
|
+
theme,
|
|
239
249
|
corePlugins: (path)=>{
|
|
240
250
|
if (Array.isArray(tailwindConfig.corePlugins)) {
|
|
241
251
|
return tailwindConfig.corePlugins.includes(path);
|
|
242
252
|
}
|
|
243
253
|
return getConfigValue([
|
|
244
|
-
|
|
254
|
+
"corePlugins",
|
|
245
255
|
path
|
|
246
256
|
], true);
|
|
247
257
|
},
|
|
@@ -249,33 +259,38 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
249
259
|
// Preserved for backwards compatibility but not used in v3.0+
|
|
250
260
|
return [];
|
|
251
261
|
},
|
|
252
|
-
|
|
253
|
-
for (let [identifier, rule] of withIdentifiers(
|
|
254
|
-
let
|
|
255
|
-
|
|
256
|
-
|
|
262
|
+
addBase (base) {
|
|
263
|
+
for (let [identifier, rule] of withIdentifiers(base)){
|
|
264
|
+
let prefixedIdentifier = prefixIdentifier(identifier, {});
|
|
265
|
+
let offset = offsets.base++;
|
|
266
|
+
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
267
|
+
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
257
268
|
}
|
|
258
|
-
context.candidateRuleMap.get(
|
|
269
|
+
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
259
270
|
{
|
|
260
271
|
sort: offset,
|
|
261
|
-
layer:
|
|
272
|
+
layer: "base"
|
|
262
273
|
},
|
|
263
274
|
rule
|
|
264
275
|
]);
|
|
265
276
|
}
|
|
266
277
|
},
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
278
|
+
/**
|
|
279
|
+
* @param {string} group
|
|
280
|
+
* @param {Record<string, string | string[]>} declarations
|
|
281
|
+
*/ addDefaults (group, declarations) {
|
|
282
|
+
const groups = {
|
|
283
|
+
[`@defaults ${group}`]: declarations
|
|
284
|
+
};
|
|
285
|
+
for (let [identifier, rule] of withIdentifiers(groups)){
|
|
286
|
+
let prefixedIdentifier = prefixIdentifier(identifier, {});
|
|
272
287
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
273
288
|
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
274
289
|
}
|
|
275
290
|
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
276
291
|
{
|
|
277
|
-
sort:
|
|
278
|
-
layer:
|
|
292
|
+
sort: offsets.base++,
|
|
293
|
+
layer: "defaults"
|
|
279
294
|
},
|
|
280
295
|
rule
|
|
281
296
|
]);
|
|
@@ -283,26 +298,20 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
283
298
|
},
|
|
284
299
|
addComponents (components, options) {
|
|
285
300
|
let defaultOptions = {
|
|
286
|
-
variants: [],
|
|
287
301
|
respectPrefix: true,
|
|
288
|
-
respectImportant: false
|
|
289
|
-
respectVariants: true
|
|
302
|
+
respectImportant: false
|
|
290
303
|
};
|
|
291
|
-
options = Object.assign({
|
|
292
|
-
}, defaultOptions, Array.isArray(options) ? {
|
|
293
|
-
variants: options
|
|
294
|
-
} : options);
|
|
304
|
+
options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options);
|
|
295
305
|
for (let [identifier, rule] of withIdentifiers(components)){
|
|
296
306
|
let prefixedIdentifier = prefixIdentifier(identifier, options);
|
|
297
|
-
let offset = offsets.components++;
|
|
298
307
|
classList.add(prefixedIdentifier);
|
|
299
308
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
300
309
|
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
301
310
|
}
|
|
302
311
|
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
303
312
|
{
|
|
304
|
-
sort:
|
|
305
|
-
layer:
|
|
313
|
+
sort: offsets.components++,
|
|
314
|
+
layer: "components",
|
|
306
315
|
options
|
|
307
316
|
},
|
|
308
317
|
rule
|
|
@@ -311,26 +320,20 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
311
320
|
},
|
|
312
321
|
addUtilities (utilities, options) {
|
|
313
322
|
let defaultOptions = {
|
|
314
|
-
variants: [],
|
|
315
323
|
respectPrefix: true,
|
|
316
|
-
respectImportant: true
|
|
317
|
-
respectVariants: true
|
|
324
|
+
respectImportant: true
|
|
318
325
|
};
|
|
319
|
-
options = Object.assign({
|
|
320
|
-
}, defaultOptions, Array.isArray(options) ? {
|
|
321
|
-
variants: options
|
|
322
|
-
} : options);
|
|
326
|
+
options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options);
|
|
323
327
|
for (let [identifier, rule] of withIdentifiers(utilities)){
|
|
324
328
|
let prefixedIdentifier = prefixIdentifier(identifier, options);
|
|
325
|
-
let offset = offsets.utilities++;
|
|
326
329
|
classList.add(prefixedIdentifier);
|
|
327
330
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
328
331
|
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
329
332
|
}
|
|
330
333
|
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
331
334
|
{
|
|
332
|
-
sort:
|
|
333
|
-
layer:
|
|
335
|
+
sort: offsets.utilities++,
|
|
336
|
+
layer: "utilities",
|
|
334
337
|
options
|
|
335
338
|
},
|
|
336
339
|
rule
|
|
@@ -339,10 +342,8 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
339
342
|
},
|
|
340
343
|
matchUtilities: function(utilities, options) {
|
|
341
344
|
let defaultOptions = {
|
|
342
|
-
variants: [],
|
|
343
345
|
respectPrefix: true,
|
|
344
|
-
respectImportant: true
|
|
345
|
-
respectVariants: true
|
|
346
|
+
respectImportant: true
|
|
346
347
|
};
|
|
347
348
|
options = {
|
|
348
349
|
...defaultOptions,
|
|
@@ -357,9 +358,59 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
357
358
|
options
|
|
358
359
|
]);
|
|
359
360
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
360
|
-
let { type =
|
|
361
|
+
let { type ="any" } = options;
|
|
361
362
|
type = [].concat(type);
|
|
362
|
-
let [value, coercedType] = (0, _pluginUtils).coerceValue(type, modifier, options
|
|
363
|
+
let [value, coercedType] = (0, _pluginUtils).coerceValue(type, modifier, options, tailwindConfig);
|
|
364
|
+
if (value === undefined) {
|
|
365
|
+
return [];
|
|
366
|
+
}
|
|
367
|
+
if (!type.includes(coercedType) && !isOnlyPlugin) {
|
|
368
|
+
return [];
|
|
369
|
+
}
|
|
370
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
371
|
+
return [];
|
|
372
|
+
}
|
|
373
|
+
let ruleSets = [].concat(rule(value)).filter(Boolean).map((declaration)=>({
|
|
374
|
+
[(0, _nameClass).default(identifier, modifier)]: declaration
|
|
375
|
+
})
|
|
376
|
+
);
|
|
377
|
+
return ruleSets;
|
|
378
|
+
}
|
|
379
|
+
let withOffsets = [
|
|
380
|
+
{
|
|
381
|
+
sort: offset,
|
|
382
|
+
layer: "utilities",
|
|
383
|
+
options
|
|
384
|
+
},
|
|
385
|
+
wrapped
|
|
386
|
+
];
|
|
387
|
+
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
388
|
+
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
389
|
+
}
|
|
390
|
+
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets);
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
matchComponents: function(components, options) {
|
|
394
|
+
let defaultOptions = {
|
|
395
|
+
respectPrefix: true,
|
|
396
|
+
respectImportant: false
|
|
397
|
+
};
|
|
398
|
+
options = {
|
|
399
|
+
...defaultOptions,
|
|
400
|
+
...options
|
|
401
|
+
};
|
|
402
|
+
let offset = offsets.components++;
|
|
403
|
+
for(let identifier in components){
|
|
404
|
+
let prefixedIdentifier = prefixIdentifier(identifier, options);
|
|
405
|
+
let rule = components[identifier];
|
|
406
|
+
classList.add([
|
|
407
|
+
prefixedIdentifier,
|
|
408
|
+
options
|
|
409
|
+
]);
|
|
410
|
+
function wrapped(modifier, { isOnlyPlugin }) {
|
|
411
|
+
let { type ="any" } = options;
|
|
412
|
+
type = [].concat(type);
|
|
413
|
+
let [value, coercedType] = (0, _pluginUtils).coerceValue(type, modifier, options, tailwindConfig);
|
|
363
414
|
if (value === undefined) {
|
|
364
415
|
return [];
|
|
365
416
|
}
|
|
@@ -367,33 +418,25 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
367
418
|
if (isOnlyPlugin) {
|
|
368
419
|
_log.default.warn([
|
|
369
420
|
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
370
|
-
`You can safely update it to \`${identifier}-${modifier.replace(coercedType +
|
|
421
|
+
`You can safely update it to \`${identifier}-${modifier.replace(coercedType + ":", "")}\`.`,
|
|
371
422
|
]);
|
|
372
423
|
} else {
|
|
373
424
|
return [];
|
|
374
425
|
}
|
|
375
426
|
}
|
|
376
|
-
if (!
|
|
427
|
+
if (!(0, _isValidArbitraryValue).default(value)) {
|
|
377
428
|
return [];
|
|
378
429
|
}
|
|
379
|
-
let
|
|
380
|
-
let ruleSets = [].concat(rule(value, {
|
|
381
|
-
includeRules (rules) {
|
|
382
|
-
includedRules.push(...rules);
|
|
383
|
-
}
|
|
384
|
-
})).filter(Boolean).map((declaration)=>({
|
|
430
|
+
let ruleSets = [].concat(rule(value)).filter(Boolean).map((declaration)=>({
|
|
385
431
|
[(0, _nameClass).default(identifier, modifier)]: declaration
|
|
386
432
|
})
|
|
387
433
|
);
|
|
388
|
-
return
|
|
389
|
-
...includedRules,
|
|
390
|
-
...ruleSets
|
|
391
|
-
];
|
|
434
|
+
return ruleSets;
|
|
392
435
|
}
|
|
393
436
|
let withOffsets = [
|
|
394
437
|
{
|
|
395
438
|
sort: offset,
|
|
396
|
-
layer:
|
|
439
|
+
layer: "components",
|
|
397
440
|
options
|
|
398
441
|
},
|
|
399
442
|
wrapped
|
|
@@ -403,8 +446,51 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
403
446
|
}
|
|
404
447
|
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets);
|
|
405
448
|
}
|
|
449
|
+
},
|
|
450
|
+
addVariant (variantName, variantFunctions, options = {}) {
|
|
451
|
+
variantFunctions = [].concat(variantFunctions).map((variantFunction)=>{
|
|
452
|
+
if (typeof variantFunction !== "string") {
|
|
453
|
+
// Safelist public API functions
|
|
454
|
+
return (api)=>{
|
|
455
|
+
let { args , modifySelectors , container , separator , wrap , format } = api;
|
|
456
|
+
let result = variantFunction(Object.assign({
|
|
457
|
+
modifySelectors,
|
|
458
|
+
container,
|
|
459
|
+
separator
|
|
460
|
+
}, variantFunction[MATCH_VARIANT] && {
|
|
461
|
+
args,
|
|
462
|
+
wrap,
|
|
463
|
+
format
|
|
464
|
+
}));
|
|
465
|
+
if (typeof result === "string" && !isValidVariantFormatString(result)) {
|
|
466
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
467
|
+
}
|
|
468
|
+
// result may be undefined with legacy variants that use APIs like `modifySelectors`
|
|
469
|
+
return result && parseVariant(result)(api);
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
if (!isValidVariantFormatString(variantFunction)) {
|
|
473
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
474
|
+
}
|
|
475
|
+
return parseVariant(variantFunction);
|
|
476
|
+
});
|
|
477
|
+
insertInto(variantList, variantName, options);
|
|
478
|
+
variantMap.set(variantName, variantFunctions);
|
|
479
|
+
},
|
|
480
|
+
matchVariant: function(variants, options) {
|
|
481
|
+
for(let variant in variants){
|
|
482
|
+
var ref;
|
|
483
|
+
for (let [k, v] of Object.entries((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {})){
|
|
484
|
+
api1.addVariant(`${variant}-${k}`, variants[variant](v));
|
|
485
|
+
}
|
|
486
|
+
api1.addVariant(variant, Object.assign(({ args })=>variants[variant](args)
|
|
487
|
+
, {
|
|
488
|
+
[MATCH_VARIANT]: true
|
|
489
|
+
}), options);
|
|
490
|
+
}
|
|
406
491
|
}
|
|
407
492
|
};
|
|
493
|
+
return api1;
|
|
408
494
|
}
|
|
409
495
|
let fileModifiedMapCache = new WeakMap();
|
|
410
496
|
function getFileModifiedMap(context) {
|
|
@@ -416,11 +502,17 @@ function getFileModifiedMap(context) {
|
|
|
416
502
|
function trackModified(files, fileModifiedMap) {
|
|
417
503
|
let changed = false;
|
|
418
504
|
for (let file of files){
|
|
505
|
+
var ref;
|
|
419
506
|
if (!file) continue;
|
|
420
507
|
let parsed = _url.default.parse(file);
|
|
421
|
-
let pathname = parsed.hash ? parsed.href.replace(parsed.hash,
|
|
422
|
-
pathname = parsed.search ? pathname.replace(parsed.search,
|
|
423
|
-
let newModified = _fs.default.statSync(decodeURIComponent(pathname)
|
|
508
|
+
let pathname = parsed.hash ? parsed.href.replace(parsed.hash, "") : parsed.href;
|
|
509
|
+
pathname = parsed.search ? pathname.replace(parsed.search, "") : pathname;
|
|
510
|
+
let newModified = (ref = _fs.default.statSync(decodeURIComponent(pathname), {
|
|
511
|
+
throwIfNoEntry: false
|
|
512
|
+
})) === null || ref === void 0 ? void 0 : ref.mtimeMs;
|
|
513
|
+
if (!newModified) {
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
424
516
|
if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
|
|
425
517
|
changed = true;
|
|
426
518
|
}
|
|
@@ -431,8 +523,8 @@ function trackModified(files, fileModifiedMap) {
|
|
|
431
523
|
function extractVariantAtRules(node) {
|
|
432
524
|
node.walkAtRules((atRule)=>{
|
|
433
525
|
if ([
|
|
434
|
-
|
|
435
|
-
|
|
526
|
+
"responsive",
|
|
527
|
+
"variants"
|
|
436
528
|
].includes(atRule.name)) {
|
|
437
529
|
extractVariantAtRules(atRule);
|
|
438
530
|
atRule.before(atRule.nodes);
|
|
@@ -443,18 +535,18 @@ function extractVariantAtRules(node) {
|
|
|
443
535
|
function collectLayerPlugins(root) {
|
|
444
536
|
let layerPlugins = [];
|
|
445
537
|
root.each((node)=>{
|
|
446
|
-
if (node.type ===
|
|
447
|
-
|
|
448
|
-
|
|
538
|
+
if (node.type === "atrule" && [
|
|
539
|
+
"responsive",
|
|
540
|
+
"variants"
|
|
449
541
|
].includes(node.name)) {
|
|
450
|
-
node.name =
|
|
451
|
-
node.params =
|
|
542
|
+
node.name = "layer";
|
|
543
|
+
node.params = "utilities";
|
|
452
544
|
}
|
|
453
545
|
});
|
|
454
546
|
// Walk @layer rules and treat them like plugins
|
|
455
|
-
root.walkAtRules(
|
|
547
|
+
root.walkAtRules("layer", (layerRule)=>{
|
|
456
548
|
extractVariantAtRules(layerRule);
|
|
457
|
-
if (layerRule.params ===
|
|
549
|
+
if (layerRule.params === "base") {
|
|
458
550
|
for (let node of layerRule.nodes){
|
|
459
551
|
layerPlugins.push(function({ addBase }) {
|
|
460
552
|
addBase(node, {
|
|
@@ -463,7 +555,7 @@ function collectLayerPlugins(root) {
|
|
|
463
555
|
});
|
|
464
556
|
}
|
|
465
557
|
layerRule.remove();
|
|
466
|
-
} else if (layerRule.params ===
|
|
558
|
+
} else if (layerRule.params === "components") {
|
|
467
559
|
for (let node of layerRule.nodes){
|
|
468
560
|
layerPlugins.push(function({ addComponents }) {
|
|
469
561
|
addComponents(node, {
|
|
@@ -472,7 +564,7 @@ function collectLayerPlugins(root) {
|
|
|
472
564
|
});
|
|
473
565
|
}
|
|
474
566
|
layerRule.remove();
|
|
475
|
-
} else if (layerRule.params ===
|
|
567
|
+
} else if (layerRule.params === "utilities") {
|
|
476
568
|
for (let node of layerRule.nodes){
|
|
477
569
|
layerPlugins.push(function({ addUtilities }) {
|
|
478
570
|
addUtilities(node, {
|
|
@@ -483,20 +575,13 @@ function collectLayerPlugins(root) {
|
|
|
483
575
|
layerRule.remove();
|
|
484
576
|
}
|
|
485
577
|
});
|
|
486
|
-
root.walkRules((rule)=>{
|
|
487
|
-
// At this point it is safe to include all the left-over css from the
|
|
488
|
-
// user's css file. This is because the `@tailwind` and `@layer` directives
|
|
489
|
-
// will already be handled and will be removed from the css tree.
|
|
490
|
-
layerPlugins.push(function({ addUserCss }) {
|
|
491
|
-
addUserCss(rule, {
|
|
492
|
-
respectPrefix: false
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
});
|
|
496
578
|
return layerPlugins;
|
|
497
579
|
}
|
|
498
580
|
function resolvePlugins(context, root) {
|
|
499
|
-
let corePluginList = Object.entries(
|
|
581
|
+
let corePluginList = Object.entries({
|
|
582
|
+
..._corePlugins.variantPlugins,
|
|
583
|
+
..._corePlugins.corePlugins
|
|
584
|
+
}).map(([name, plugin])=>{
|
|
500
585
|
if (!context.tailwindConfig.corePlugins.includes(name)) {
|
|
501
586
|
return null;
|
|
502
587
|
}
|
|
@@ -506,20 +591,23 @@ function resolvePlugins(context, root) {
|
|
|
506
591
|
if (plugin.__isOptionsFunction) {
|
|
507
592
|
plugin = plugin();
|
|
508
593
|
}
|
|
509
|
-
return typeof plugin ===
|
|
594
|
+
return typeof plugin === "function" ? plugin : plugin.handler;
|
|
510
595
|
});
|
|
511
596
|
let layerPlugins = collectLayerPlugins(root);
|
|
512
597
|
// TODO: This is a workaround for backwards compatibility, since custom variants
|
|
513
598
|
// were historically sorted before screen/stackable variants.
|
|
514
599
|
let beforeVariants = [
|
|
515
|
-
_corePlugins.
|
|
516
|
-
_corePlugins.
|
|
600
|
+
_corePlugins.variantPlugins["pseudoElementVariants"],
|
|
601
|
+
_corePlugins.variantPlugins["pseudoClassVariants"],
|
|
517
602
|
];
|
|
518
603
|
let afterVariants = [
|
|
519
|
-
_corePlugins.
|
|
520
|
-
_corePlugins.
|
|
521
|
-
_corePlugins.
|
|
522
|
-
_corePlugins.
|
|
604
|
+
_corePlugins.variantPlugins["directionVariants"],
|
|
605
|
+
_corePlugins.variantPlugins["reducedMotionVariants"],
|
|
606
|
+
_corePlugins.variantPlugins["prefersContrastVariants"],
|
|
607
|
+
_corePlugins.variantPlugins["darkVariants"],
|
|
608
|
+
_corePlugins.variantPlugins["printVariant"],
|
|
609
|
+
_corePlugins.variantPlugins["screenVariants"],
|
|
610
|
+
_corePlugins.variantPlugins["orientationVariants"],
|
|
523
611
|
];
|
|
524
612
|
return [
|
|
525
613
|
...corePluginList,
|
|
@@ -533,6 +621,7 @@ function registerPlugins(plugins, context) {
|
|
|
533
621
|
let variantList = [];
|
|
534
622
|
let variantMap = new Map();
|
|
535
623
|
let offsets = {
|
|
624
|
+
defaults: 0n,
|
|
536
625
|
base: 0n,
|
|
537
626
|
components: 0n,
|
|
538
627
|
utilities: 0n,
|
|
@@ -558,18 +647,23 @@ function registerPlugins(plugins, context) {
|
|
|
558
647
|
)
|
|
559
648
|
)([
|
|
560
649
|
offsets.base,
|
|
650
|
+
offsets.defaults,
|
|
561
651
|
offsets.components,
|
|
562
652
|
offsets.utilities,
|
|
563
653
|
offsets.user,
|
|
564
654
|
]);
|
|
565
655
|
let reservedBits = BigInt(highestOffset.toString(2).length);
|
|
656
|
+
// A number one less than the top range of the highest offset area
|
|
657
|
+
// so arbitrary properties are always sorted at the end.
|
|
658
|
+
context.arbitraryPropertiesSort = (1n << reservedBits << 0n) - 1n;
|
|
566
659
|
context.layerOrder = {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
660
|
+
defaults: 1n << reservedBits << 0n,
|
|
661
|
+
base: 1n << reservedBits << 1n,
|
|
662
|
+
components: 1n << reservedBits << 2n,
|
|
663
|
+
utilities: 1n << reservedBits << 3n,
|
|
664
|
+
user: 1n << reservedBits << 4n
|
|
571
665
|
};
|
|
572
|
-
reservedBits +=
|
|
666
|
+
reservedBits += 5n;
|
|
573
667
|
let offset = 0;
|
|
574
668
|
context.variantOrder = new Map(variantList.map((variant, i)=>{
|
|
575
669
|
let variantFunctions = variantMap.get(variant).length;
|
|
@@ -585,116 +679,146 @@ function registerPlugins(plugins, context) {
|
|
|
585
679
|
...context.variantOrder.values()
|
|
586
680
|
].shift();
|
|
587
681
|
// Build variantMap
|
|
588
|
-
for (let [variantName,
|
|
682
|
+
for (let [variantName, variantFunctions1] of variantMap.entries()){
|
|
589
683
|
let sort = context.variantOrder.get(variantName);
|
|
590
|
-
context.variantMap.set(variantName,
|
|
684
|
+
context.variantMap.set(variantName, variantFunctions1.map((variantFunction, idx)=>[
|
|
591
685
|
sort << BigInt(idx),
|
|
592
686
|
variantFunction
|
|
593
687
|
]
|
|
594
688
|
));
|
|
595
689
|
}
|
|
596
|
-
|
|
597
|
-
let
|
|
598
|
-
|
|
599
|
-
var _safelist;
|
|
600
|
-
let safelist = ((_safelist = context.tailwindConfig.safelist) !== null && _safelist !== void 0 ? _safelist : []).filter(Boolean);
|
|
601
|
-
if (safelist.length <= 0) return [];
|
|
602
|
-
let output = [];
|
|
690
|
+
var _safelist;
|
|
691
|
+
let safelist = ((_safelist = context.tailwindConfig.safelist) !== null && _safelist !== void 0 ? _safelist : []).filter(Boolean);
|
|
692
|
+
if (safelist.length > 0) {
|
|
603
693
|
let checks = [];
|
|
604
|
-
for (let
|
|
605
|
-
if (typeof
|
|
606
|
-
|
|
694
|
+
for (let value1 of safelist){
|
|
695
|
+
if (typeof value1 === "string") {
|
|
696
|
+
context.changedContent.push({
|
|
697
|
+
content: value1,
|
|
698
|
+
extension: "html"
|
|
699
|
+
});
|
|
607
700
|
continue;
|
|
608
701
|
}
|
|
609
|
-
if (
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
]);
|
|
616
|
-
warnedAbout.add('root-regex');
|
|
617
|
-
}
|
|
702
|
+
if (value1 instanceof RegExp) {
|
|
703
|
+
_log.default.warn("root-regex", [
|
|
704
|
+
"Regular expressions in `safelist` work differently in Tailwind CSS v3.0.",
|
|
705
|
+
"Update your `safelist` configuration to eliminate this warning.",
|
|
706
|
+
"https://tailwindcss.com/docs/content-configuration#safelisting-classes",
|
|
707
|
+
]);
|
|
618
708
|
continue;
|
|
619
709
|
}
|
|
620
|
-
checks.push(
|
|
710
|
+
checks.push(value1);
|
|
621
711
|
}
|
|
622
|
-
if (checks.length
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
712
|
+
if (checks.length > 0) {
|
|
713
|
+
let patternMatchingCount = new Map();
|
|
714
|
+
let prefixLength = context.tailwindConfig.prefix.length;
|
|
715
|
+
for (let util of classList){
|
|
716
|
+
let utils = Array.isArray(util) ? (()=>{
|
|
717
|
+
let [utilName, options] = util;
|
|
718
|
+
var ref;
|
|
719
|
+
let values = Object.keys((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {});
|
|
720
|
+
let classes = values.map((value)=>(0, _nameClass).formatClass(utilName, value)
|
|
721
|
+
);
|
|
722
|
+
if (options === null || options === void 0 ? void 0 : options.supportsNegativeValues) {
|
|
723
|
+
// This is the normal negated version
|
|
724
|
+
// e.g. `-inset-1` or `-tw-inset-1`
|
|
725
|
+
classes = [
|
|
726
|
+
...classes,
|
|
727
|
+
...classes.map((cls)=>"-" + cls
|
|
728
|
+
)
|
|
729
|
+
];
|
|
730
|
+
// This is the negated version *after* the prefix
|
|
731
|
+
// e.g. `tw--inset-1`
|
|
732
|
+
// The prefix is already attached to util name
|
|
733
|
+
// So we add the negative after the prefix
|
|
734
|
+
classes = [
|
|
735
|
+
...classes,
|
|
736
|
+
...classes.map((cls)=>cls.slice(0, prefixLength) + "-" + cls.slice(prefixLength)
|
|
737
|
+
),
|
|
738
|
+
];
|
|
645
739
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
740
|
+
return classes;
|
|
741
|
+
})() : [
|
|
742
|
+
util
|
|
743
|
+
];
|
|
744
|
+
for (let util1 of utils){
|
|
745
|
+
for (let { pattern , variants =[] } of checks){
|
|
746
|
+
// RegExp with the /g flag are stateful, so let's reset the last
|
|
747
|
+
// index pointer to reset the state.
|
|
748
|
+
pattern.lastIndex = 0;
|
|
749
|
+
if (!patternMatchingCount.has(pattern)) {
|
|
750
|
+
patternMatchingCount.set(pattern, 0);
|
|
751
|
+
}
|
|
752
|
+
if (!pattern.test(util1)) continue;
|
|
753
|
+
patternMatchingCount.set(pattern, patternMatchingCount.get(pattern) + 1);
|
|
754
|
+
context.changedContent.push({
|
|
755
|
+
content: util1,
|
|
756
|
+
extension: "html"
|
|
757
|
+
});
|
|
758
|
+
for (let variant of variants){
|
|
759
|
+
context.changedContent.push({
|
|
760
|
+
content: variant + context.tailwindConfig.separator + util1,
|
|
761
|
+
extension: "html"
|
|
762
|
+
});
|
|
763
|
+
}
|
|
651
764
|
}
|
|
652
765
|
}
|
|
653
766
|
}
|
|
767
|
+
for (let [regex, count] of patternMatchingCount.entries()){
|
|
768
|
+
if (count !== 0) continue;
|
|
769
|
+
_log.default.warn([
|
|
770
|
+
`The safelist pattern \`${regex}\` doesn't match any Tailwind CSS classes.`,
|
|
771
|
+
"Fix this pattern or remove it from your `safelist` configuration.",
|
|
772
|
+
"https://tailwindcss.com/docs/content-configuration#safelisting-classes",
|
|
773
|
+
]);
|
|
774
|
+
}
|
|
654
775
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
776
|
+
}
|
|
777
|
+
// A list of utilities that are used by certain Tailwind CSS utilities but
|
|
778
|
+
// that don't exist on their own. This will result in them "not existing" and
|
|
779
|
+
// sorting could be weird since you still require them in order to make the
|
|
780
|
+
// host utitlies work properly. (Thanks Biology)
|
|
781
|
+
let parasiteUtilities = new Set([
|
|
782
|
+
prefix(context, "group"),
|
|
783
|
+
prefix(context, "peer")
|
|
784
|
+
]);
|
|
785
|
+
context.getClassOrder = function getClassOrder(classes) {
|
|
786
|
+
let sortedClassNames = new Map();
|
|
787
|
+
for (let [sort, rule] of (0, _generateRules).generateRules(new Set(classes), context)){
|
|
788
|
+
if (sortedClassNames.has(rule.raws.tailwind.candidate)) continue;
|
|
789
|
+
sortedClassNames.set(rule.raws.tailwind.candidate, sort);
|
|
662
790
|
}
|
|
663
|
-
return
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
791
|
+
return classes.map((className)=>{
|
|
792
|
+
var ref;
|
|
793
|
+
let order = (ref = sortedClassNames.get(className)) !== null && ref !== void 0 ? ref : null;
|
|
794
|
+
if (order === null && parasiteUtilities.has(className)) {
|
|
795
|
+
// This will make sure that it is at the very beginning of the
|
|
796
|
+
// `components` layer which technically means 'before any
|
|
797
|
+
// components'.
|
|
798
|
+
order = context.layerOrder.components;
|
|
799
|
+
}
|
|
800
|
+
return [
|
|
801
|
+
className,
|
|
802
|
+
order
|
|
803
|
+
];
|
|
804
|
+
});
|
|
668
805
|
};
|
|
669
|
-
// Generate a list of strings for autocompletion purposes.
|
|
670
|
-
//
|
|
671
|
-
|
|
672
|
-
context.completions = function() {
|
|
673
|
-
// TODO: Try and detect color from components?
|
|
674
|
-
// TODO: Should we provide a simple "public api" file with functions?
|
|
806
|
+
// Generate a list of strings for autocompletion purposes, e.g.
|
|
807
|
+
// ['uppercase', 'lowercase', ...]
|
|
808
|
+
context.getClassList = function getClassList() {
|
|
675
809
|
let output = [];
|
|
676
810
|
for (let util of classList){
|
|
677
811
|
if (Array.isArray(util)) {
|
|
678
812
|
let [utilName, options] = util;
|
|
679
|
-
let
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
(0, _nameClass).formatClass(utilName, value),
|
|
686
|
-
{
|
|
687
|
-
color
|
|
688
|
-
}
|
|
689
|
-
]);
|
|
690
|
-
}
|
|
691
|
-
} else {
|
|
692
|
-
var ref;
|
|
693
|
-
for (let value of Object.keys((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {
|
|
694
|
-
})){
|
|
695
|
-
output.push((0, _nameClass).formatClass(utilName, value));
|
|
813
|
+
let negativeClasses = [];
|
|
814
|
+
var ref;
|
|
815
|
+
for (let [key, value] of Object.entries((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {})){
|
|
816
|
+
output.push((0, _nameClass).formatClass(utilName, key));
|
|
817
|
+
if ((options === null || options === void 0 ? void 0 : options.supportsNegativeValues) && (0, _negateValue).default(value)) {
|
|
818
|
+
negativeClasses.push((0, _nameClass).formatClass(utilName, `-${key}`));
|
|
696
819
|
}
|
|
697
820
|
}
|
|
821
|
+
output.push(...negativeClasses);
|
|
698
822
|
} else {
|
|
699
823
|
output.push(util);
|
|
700
824
|
}
|
|
@@ -726,7 +850,7 @@ let contextSourcesMap = sharedState.contextSourcesMap;
|
|
|
726
850
|
function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfigHash, contextDependencies) {
|
|
727
851
|
let sourcePath = result.opts.from;
|
|
728
852
|
let isConfigFile = userConfigPath !== null;
|
|
729
|
-
sharedState.env.DEBUG && console.log(
|
|
853
|
+
sharedState.env.DEBUG && console.log("Source path:", sourcePath);
|
|
730
854
|
let existingContext;
|
|
731
855
|
if (isConfigFile && contextMap.has(sourcePath)) {
|
|
732
856
|
existingContext = contextMap.get(sourcePath);
|
|
@@ -736,13 +860,14 @@ function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfig
|
|
|
736
860
|
contextMap.set(sourcePath, context);
|
|
737
861
|
existingContext = context;
|
|
738
862
|
}
|
|
863
|
+
let cssDidChange = (0, _cacheInvalidationJs).hasContentChanged(sourcePath, root);
|
|
739
864
|
// If there's already a context in the cache and we don't need to
|
|
740
865
|
// reset the context, return the cached context.
|
|
741
866
|
if (existingContext) {
|
|
742
867
|
let contextDependenciesChanged = trackModified([
|
|
743
868
|
...contextDependencies
|
|
744
869
|
], getFileModifiedMap(existingContext));
|
|
745
|
-
if (!contextDependenciesChanged) {
|
|
870
|
+
if (!contextDependenciesChanged && !cssDidChange) {
|
|
746
871
|
return [
|
|
747
872
|
existingContext,
|
|
748
873
|
false
|
|
@@ -771,7 +896,7 @@ function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfig
|
|
|
771
896
|
}
|
|
772
897
|
}
|
|
773
898
|
}
|
|
774
|
-
sharedState.env.DEBUG && console.log(
|
|
899
|
+
sharedState.env.DEBUG && console.log("Setting up new context...");
|
|
775
900
|
let context = createContext(tailwindConfig, [], root);
|
|
776
901
|
trackModified([
|
|
777
902
|
...contextDependencies
|