tailwindcss 0.0.0-oxide-insiders.a7fe2fe → 0.0.0-oxide-insiders.759a8c2

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.
Files changed (108) hide show
  1. package/lib/cli/build/deps.js +34 -18
  2. package/lib/cli/build/index.js +45 -12
  3. package/lib/cli/build/plugin.js +273 -90
  4. package/lib/cli/build/utils.js +56 -24
  5. package/lib/cli/build/watching.js +156 -38
  6. package/lib/cli/help/index.js +61 -16
  7. package/lib/cli/index.js +121 -62
  8. package/lib/cli/init/index.js +47 -23
  9. package/lib/cli-peer-dependencies.js +23 -13
  10. package/lib/cli.js +5 -1
  11. package/lib/corePluginList.js +7 -4
  12. package/lib/corePlugins.js +855 -386
  13. package/lib/featureFlags.js +43 -18
  14. package/lib/lib/cacheInvalidation.js +78 -30
  15. package/lib/lib/collapseAdjacentRules.js +46 -23
  16. package/lib/lib/collapseDuplicateDeclarations.js +70 -27
  17. package/lib/lib/content.js +134 -41
  18. package/lib/lib/defaultExtractor.js +201 -96
  19. package/lib/lib/detectNesting.js +38 -12
  20. package/lib/lib/evaluateTailwindFunctions.js +192 -103
  21. package/lib/lib/expandApplyAtRules.js +488 -181
  22. package/lib/lib/expandTailwindAtRules.js +240 -70
  23. package/lib/lib/findAtConfigPath.js +34 -15
  24. package/lib/lib/generateRules.js +775 -353
  25. package/lib/lib/getModuleDependencies.js +67 -29
  26. package/lib/lib/load-config.js +27 -17
  27. package/lib/lib/normalizeTailwindDirectives.js +73 -27
  28. package/lib/lib/offsets.js +227 -62
  29. package/lib/lib/partitionApplyAtRules.js +53 -29
  30. package/lib/lib/regex.js +50 -28
  31. package/lib/lib/remap-bitfield.js +86 -9
  32. package/lib/lib/resolveDefaultsAtRules.js +123 -53
  33. package/lib/lib/setupContextUtils.js +1117 -584
  34. package/lib/lib/setupTrackingContext.js +149 -58
  35. package/lib/lib/sharedState.js +71 -23
  36. package/lib/lib/substituteScreenAtRules.js +19 -9
  37. package/lib/oxide/cli/build/deps.js +46 -23
  38. package/lib/oxide/cli/build/index.js +44 -12
  39. package/lib/oxide/cli/build/plugin.js +271 -89
  40. package/lib/oxide/cli/build/utils.js +55 -24
  41. package/lib/oxide/cli/build/watching.js +153 -36
  42. package/lib/oxide/cli/help/index.js +60 -16
  43. package/lib/oxide/cli/index.js +128 -67
  44. package/lib/oxide/cli/init/index.js +40 -19
  45. package/lib/oxide/cli.js +3 -2
  46. package/lib/plugin.js +58 -31
  47. package/lib/postcss-plugins/nesting/index.js +13 -7
  48. package/lib/postcss-plugins/nesting/plugin.js +65 -20
  49. package/lib/processTailwindFeatures.js +41 -10
  50. package/lib/public/colors.js +25 -16
  51. package/lib/public/create-plugin.js +11 -6
  52. package/lib/public/default-config.js +12 -6
  53. package/lib/public/default-theme.js +12 -6
  54. package/lib/public/load-config.js +9 -5
  55. package/lib/public/resolve-config.js +10 -6
  56. package/lib/util/applyImportantSelector.js +28 -17
  57. package/lib/util/bigSign.js +9 -6
  58. package/lib/util/buildMediaQuery.js +19 -10
  59. package/lib/util/cloneDeep.js +19 -9
  60. package/lib/util/cloneNodes.js +29 -14
  61. package/lib/util/color.js +87 -47
  62. package/lib/util/colorNames.js +752 -0
  63. package/lib/util/configurePlugins.js +18 -9
  64. package/lib/util/createPlugin.js +17 -8
  65. package/lib/util/createUtilityPlugin.js +30 -16
  66. package/lib/util/dataTypes.js +189 -38
  67. package/lib/util/defaults.js +21 -9
  68. package/lib/util/escapeClassName.js +15 -9
  69. package/lib/util/escapeCommas.js +9 -6
  70. package/lib/util/flattenColorPalette.js +11 -7
  71. package/lib/util/formatVariantSelector.js +209 -60
  72. package/lib/util/getAllConfigs.js +44 -35
  73. package/lib/util/hashConfig.js +12 -8
  74. package/lib/util/isKeyframeRule.js +10 -7
  75. package/lib/util/isPlainObject.js +14 -9
  76. package/lib/util/isSyntacticallyValidPropertyValue.js +45 -14
  77. package/lib/util/log.js +20 -9
  78. package/lib/util/nameClass.js +31 -10
  79. package/lib/util/negateValue.js +28 -10
  80. package/lib/util/normalizeConfig.js +242 -63
  81. package/lib/util/normalizeScreens.js +145 -70
  82. package/lib/util/parseAnimationValue.js +64 -14
  83. package/lib/util/parseBoxShadowValue.js +63 -14
  84. package/lib/util/parseDependency.js +39 -13
  85. package/lib/util/parseGlob.js +25 -8
  86. package/lib/util/parseObjectStyles.js +29 -18
  87. package/lib/util/pluginUtils.js +196 -77
  88. package/lib/util/prefixSelector.js +31 -12
  89. package/lib/util/pseudoElements.js +116 -34
  90. package/lib/util/removeAlphaVariables.js +23 -8
  91. package/lib/util/resolveConfig.js +224 -105
  92. package/lib/util/resolveConfigPath.js +45 -15
  93. package/lib/util/responsive.js +10 -6
  94. package/lib/util/splitAtTopLevelOnly.js +46 -10
  95. package/lib/util/tap.js +11 -7
  96. package/lib/util/toColorValue.js +10 -7
  97. package/lib/util/toPath.js +28 -8
  98. package/lib/util/transformThemeValue.js +49 -14
  99. package/lib/util/validateConfig.js +25 -15
  100. package/lib/util/validateFormalSyntax.js +14 -6
  101. package/lib/util/withAlphaVariable.js +54 -30
  102. package/package.json +18 -22
  103. package/peers/index.js +57849 -43101
  104. package/src/lib/expandTailwindAtRules.js +1 -1
  105. package/src/lib/setupTrackingContext.js +1 -1
  106. package/src/util/color.js +1 -1
  107. package/src/util/colorNames.js +150 -0
  108. package/src/util/pseudoElements.js +4 -4
@@ -1,208 +1,722 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
- value: !0
4
- }), function(target, all) {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
5
6
  for(var name in all)Object.defineProperty(target, name, {
6
- enumerable: !0,
7
+ enumerable: true,
7
8
  get: all[name]
8
9
  });
9
- }(exports, {
10
- getClassNameFromSelector: ()=>getClassNameFromSelector,
11
- resolveMatches: ()=>resolveMatches,
12
- generateRules: ()=>generateRules
10
+ }
11
+ _export(exports, {
12
+ getClassNameFromSelector: function() {
13
+ return getClassNameFromSelector;
14
+ },
15
+ resolveMatches: function() {
16
+ return resolveMatches;
17
+ },
18
+ generateRules: function() {
19
+ return generateRules;
20
+ }
13
21
  });
14
- const _postcss = _interopRequireDefault(require("postcss")), _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser")), _parseObjectStyles = _interopRequireDefault(require("../util/parseObjectStyles")), _isPlainObject = _interopRequireDefault(require("../util/isPlainObject")), _prefixSelector = _interopRequireDefault(require("../util/prefixSelector")), _pluginUtils = require("../util/pluginUtils"), _log = _interopRequireDefault(require("../util/log")), _sharedState = function(obj, nodeInterop) {
15
- if (!nodeInterop && obj && obj.__esModule) return obj;
16
- if (null === obj || "object" != typeof obj && "function" != typeof obj) return {
17
- default: obj
18
- };
19
- var cache = _getRequireWildcardCache(nodeInterop);
20
- if (cache && cache.has(obj)) return cache.get(obj);
21
- var newObj = {}, hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
22
- for(var key in obj)if ("default" !== key && Object.prototype.hasOwnProperty.call(obj, key)) {
23
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
24
- desc && (desc.get || desc.set) ? Object.defineProperty(newObj, key, desc) : newObj[key] = obj[key];
25
- }
26
- return newObj.default = obj, cache && cache.set(obj, newObj), newObj;
27
- }(require("./sharedState")), _formatVariantSelector = require("../util/formatVariantSelector"), _nameClass = require("../util/nameClass"), _dataTypes = require("../util/dataTypes"), _setupContextUtils = require("./setupContextUtils"), _isSyntacticallyValidPropertyValue = _interopRequireDefault(require("../util/isSyntacticallyValidPropertyValue")), _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js"), _featureFlags = require("../featureFlags"), _applyImportantSelector = require("../util/applyImportantSelector");
28
- function _interopRequireDefault(obj) {
22
+ const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
23
+ const _postcssselectorparser = /*#__PURE__*/ _interop_require_default(require("postcss-selector-parser"));
24
+ const _parseObjectStyles = /*#__PURE__*/ _interop_require_default(require("../util/parseObjectStyles"));
25
+ const _isPlainObject = /*#__PURE__*/ _interop_require_default(require("../util/isPlainObject"));
26
+ const _prefixSelector = /*#__PURE__*/ _interop_require_default(require("../util/prefixSelector"));
27
+ const _pluginUtils = require("../util/pluginUtils");
28
+ const _log = /*#__PURE__*/ _interop_require_default(require("../util/log"));
29
+ const _sharedState = /*#__PURE__*/ _interop_require_wildcard(require("./sharedState"));
30
+ const _formatVariantSelector = require("../util/formatVariantSelector");
31
+ const _nameClass = require("../util/nameClass");
32
+ const _dataTypes = require("../util/dataTypes");
33
+ const _setupContextUtils = require("./setupContextUtils");
34
+ const _isSyntacticallyValidPropertyValue = /*#__PURE__*/ _interop_require_default(require("../util/isSyntacticallyValidPropertyValue"));
35
+ const _splitAtTopLevelOnly = require("../util/splitAtTopLevelOnly.js");
36
+ const _featureFlags = require("../featureFlags");
37
+ const _applyImportantSelector = require("../util/applyImportantSelector");
38
+ function _interop_require_default(obj) {
29
39
  return obj && obj.__esModule ? obj : {
30
40
  default: obj
31
41
  };
32
42
  }
33
43
  function _getRequireWildcardCache(nodeInterop) {
34
- if ("function" != typeof WeakMap) return null;
35
- var cacheBabelInterop = new WeakMap(), cacheNodeInterop = new WeakMap();
44
+ if (typeof WeakMap !== "function") return null;
45
+ var cacheBabelInterop = new WeakMap();
46
+ var cacheNodeInterop = new WeakMap();
36
47
  return (_getRequireWildcardCache = function(nodeInterop) {
37
48
  return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
38
49
  })(nodeInterop);
39
50
  }
40
- let classNameParser = (0, _postcssSelectorParser.default)((selectors)=>selectors.first.filter(({ type })=>"class" === type).pop().value);
51
+ function _interop_require_wildcard(obj, nodeInterop) {
52
+ if (!nodeInterop && obj && obj.__esModule) {
53
+ return obj;
54
+ }
55
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
56
+ return {
57
+ default: obj
58
+ };
59
+ }
60
+ var cache = _getRequireWildcardCache(nodeInterop);
61
+ if (cache && cache.has(obj)) {
62
+ return cache.get(obj);
63
+ }
64
+ var newObj = {};
65
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
66
+ for(var key in obj){
67
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
68
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
69
+ if (desc && (desc.get || desc.set)) {
70
+ Object.defineProperty(newObj, key, desc);
71
+ } else {
72
+ newObj[key] = obj[key];
73
+ }
74
+ }
75
+ }
76
+ newObj.default = obj;
77
+ if (cache) {
78
+ cache.set(obj, newObj);
79
+ }
80
+ return newObj;
81
+ }
82
+ let classNameParser = (0, _postcssselectorparser.default)((selectors)=>{
83
+ return selectors.first.filter(({ type })=>type === "class").pop().value;
84
+ });
41
85
  function getClassNameFromSelector(selector) {
42
86
  return classNameParser.transformSync(selector);
43
87
  }
88
+ // Generate match permutations for a class candidate, like:
89
+ // ['ring-offset-blue', '100']
90
+ // ['ring-offset', 'blue-100']
91
+ // ['ring', 'offset-blue-100']
92
+ // Example with dynamic classes:
93
+ // ['grid-cols', '[[linename],1fr,auto]']
94
+ // ['grid', 'cols-[[linename],1fr,auto]']
95
+ function* candidatePermutations(candidate) {
96
+ let lastIndex = Infinity;
97
+ while(lastIndex >= 0){
98
+ let dashIdx;
99
+ let wasSlash = false;
100
+ if (lastIndex === Infinity && candidate.endsWith("]")) {
101
+ let bracketIdx = candidate.indexOf("[");
102
+ // If character before `[` isn't a dash or a slash, this isn't a dynamic class
103
+ // eg. string[]
104
+ if (candidate[bracketIdx - 1] === "-") {
105
+ dashIdx = bracketIdx - 1;
106
+ } else if (candidate[bracketIdx - 1] === "/") {
107
+ dashIdx = bracketIdx - 1;
108
+ wasSlash = true;
109
+ } else {
110
+ dashIdx = -1;
111
+ }
112
+ } else if (lastIndex === Infinity && candidate.includes("/")) {
113
+ dashIdx = candidate.lastIndexOf("/");
114
+ wasSlash = true;
115
+ } else {
116
+ dashIdx = candidate.lastIndexOf("-", lastIndex);
117
+ }
118
+ if (dashIdx < 0) {
119
+ break;
120
+ }
121
+ let prefix = candidate.slice(0, dashIdx);
122
+ let modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1);
123
+ lastIndex = dashIdx - 1;
124
+ // TODO: This feels a bit hacky
125
+ if (prefix === "" || modifier === "/") {
126
+ continue;
127
+ }
128
+ yield [
129
+ prefix,
130
+ modifier
131
+ ];
132
+ }
133
+ }
134
+ function applyPrefix(matches, context) {
135
+ if (matches.length === 0 || context.tailwindConfig.prefix === "") {
136
+ return matches;
137
+ }
138
+ for (let match of matches){
139
+ let [meta] = match;
140
+ if (meta.options.respectPrefix) {
141
+ let container = _postcss.default.root({
142
+ nodes: [
143
+ match[1].clone()
144
+ ]
145
+ });
146
+ let classCandidate = match[1].raws.tailwind.classCandidate;
147
+ container.walkRules((r)=>{
148
+ // If this is a negative utility with a dash *before* the prefix we
149
+ // have to ensure that the generated selector matches the candidate
150
+ // Not doing this will cause `-tw-top-1` to generate the class `.tw--top-1`
151
+ // The disconnect between candidate <-> class can cause @apply to hard crash.
152
+ let shouldPrependNegative = classCandidate.startsWith("-");
153
+ r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
154
+ });
155
+ match[1] = container.nodes[0];
156
+ }
157
+ }
158
+ return matches;
159
+ }
160
+ function applyImportant(matches, classCandidate) {
161
+ if (matches.length === 0) {
162
+ return matches;
163
+ }
164
+ let result = [];
165
+ for (let [meta, rule] of matches){
166
+ let container = _postcss.default.root({
167
+ nodes: [
168
+ rule.clone()
169
+ ]
170
+ });
171
+ container.walkRules((r)=>{
172
+ let ast = (0, _postcssselectorparser.default)().astSync(r.selector);
173
+ // Remove extraneous selectors that do not include the base candidate
174
+ ast.each((sel)=>(0, _formatVariantSelector.eliminateIrrelevantSelectors)(sel, classCandidate));
175
+ // Update all instances of the base candidate to include the important marker
176
+ (0, _pluginUtils.updateAllClasses)(ast, (className)=>className === classCandidate ? `!${className}` : className);
177
+ r.selector = ast.toString();
178
+ r.walkDecls((d)=>d.important = true);
179
+ });
180
+ result.push([
181
+ {
182
+ ...meta,
183
+ important: true
184
+ },
185
+ container.nodes[0]
186
+ ]);
187
+ }
188
+ return result;
189
+ }
190
+ // Takes a list of rule tuples and applies a variant like `hover`, sm`,
191
+ // whatever to it. We used to do some extra caching here to avoid generating
192
+ // a variant of the same rule more than once, but this was never hit because
193
+ // we cache at the entire selector level further up the tree.
194
+ //
195
+ // Technically you can get a cache hit if you have `hover:focus:text-center`
196
+ // and `focus:hover:text-center` in the same project, but it doesn't feel
197
+ // worth the complexity for that case.
198
+ function applyVariant(variant, matches, context) {
199
+ if (matches.length === 0) {
200
+ return matches;
201
+ }
202
+ /** @type {{modifier: string | null, value: string | null}} */ let args = {
203
+ modifier: null,
204
+ value: _sharedState.NONE
205
+ };
206
+ // Retrieve "modifier"
207
+ {
208
+ let [baseVariant, ...modifiers] = (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(variant, "/");
209
+ // This is a hack to support variants with `/` in them, like `ar-1/10/20:text-red-500`
210
+ // In this case 1/10 is a value but /20 is a modifier
211
+ if (modifiers.length > 1) {
212
+ baseVariant = baseVariant + "/" + modifiers.slice(0, -1).join("/");
213
+ modifiers = modifiers.slice(-1);
214
+ }
215
+ if (modifiers.length && !context.variantMap.has(variant)) {
216
+ variant = baseVariant;
217
+ args.modifier = modifiers[0];
218
+ if (!(0, _featureFlags.flagEnabled)(context.tailwindConfig, "generalizedModifiers")) {
219
+ return [];
220
+ }
221
+ }
222
+ }
223
+ // Retrieve "arbitrary value"
224
+ if (variant.endsWith("]") && !variant.startsWith("[")) {
225
+ // We either have:
226
+ // @[200px]
227
+ // group-[:hover]
228
+ //
229
+ // But we don't want:
230
+ // @-[200px] (`-` is incorrect)
231
+ // group[:hover] (`-` is missing)
232
+ let match = /(.)(-?)\[(.*)\]/g.exec(variant);
233
+ if (match) {
234
+ let [, char, seperator, value] = match;
235
+ // @-[200px] case
236
+ if (char === "@" && seperator === "-") return [];
237
+ // group[:hover] case
238
+ if (char !== "@" && seperator === "") return [];
239
+ variant = variant.replace(`${seperator}[${value}]`, "");
240
+ args.value = value;
241
+ }
242
+ }
243
+ // Register arbitrary variants
244
+ if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
245
+ let sort = context.offsets.recordVariant(variant);
246
+ let selector = (0, _dataTypes.normalize)(variant.slice(1, -1));
247
+ let selectors = (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(selector, ",");
248
+ // We do not support multiple selectors for arbitrary variants
249
+ if (selectors.length > 1) {
250
+ return [];
251
+ }
252
+ if (!selectors.every(_setupContextUtils.isValidVariantFormatString)) {
253
+ return [];
254
+ }
255
+ let records = selectors.map((sel, idx)=>[
256
+ context.offsets.applyParallelOffset(sort, idx),
257
+ (0, _setupContextUtils.parseVariant)(sel.trim())
258
+ ]);
259
+ context.variantMap.set(variant, records);
260
+ }
261
+ if (context.variantMap.has(variant)) {
262
+ let isArbitraryVariant = isArbitraryValue(variant);
263
+ let variantFunctionTuples = context.variantMap.get(variant).slice();
264
+ let result = [];
265
+ for (let [meta, rule] of matches){
266
+ // Don't generate variants for user css
267
+ if (meta.layer === "user") {
268
+ continue;
269
+ }
270
+ let container = _postcss.default.root({
271
+ nodes: [
272
+ rule.clone()
273
+ ]
274
+ });
275
+ for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples){
276
+ let clone = (containerFromArray !== null && containerFromArray !== void 0 ? containerFromArray : container).clone();
277
+ let collectedFormats = [];
278
+ function prepareBackup() {
279
+ // Already prepared, chicken out
280
+ if (clone.raws.neededBackup) {
281
+ return;
282
+ }
283
+ clone.raws.neededBackup = true;
284
+ clone.walkRules((rule)=>rule.raws.originalSelector = rule.selector);
285
+ }
286
+ function modifySelectors(modifierFunction) {
287
+ prepareBackup();
288
+ clone.each((rule)=>{
289
+ if (rule.type !== "rule") {
290
+ return;
291
+ }
292
+ rule.selectors = rule.selectors.map((selector)=>{
293
+ return modifierFunction({
294
+ get className () {
295
+ return getClassNameFromSelector(selector);
296
+ },
297
+ selector
298
+ });
299
+ });
300
+ });
301
+ return clone;
302
+ }
303
+ let ruleWithVariant = variantFunction({
304
+ // Public API
305
+ get container () {
306
+ prepareBackup();
307
+ return clone;
308
+ },
309
+ separator: context.tailwindConfig.separator,
310
+ modifySelectors,
311
+ // Private API for now
312
+ wrap (wrapper) {
313
+ let nodes = clone.nodes;
314
+ clone.removeAll();
315
+ wrapper.append(nodes);
316
+ clone.append(wrapper);
317
+ },
318
+ format (selectorFormat) {
319
+ collectedFormats.push({
320
+ format: selectorFormat,
321
+ isArbitraryVariant
322
+ });
323
+ },
324
+ args
325
+ });
326
+ // It can happen that a list of format strings is returned from within the function. In that
327
+ // case, we have to process them as well. We can use the existing `variantSort`.
328
+ if (Array.isArray(ruleWithVariant)) {
329
+ for (let [idx, variantFunction] of ruleWithVariant.entries()){
330
+ // This is a little bit scary since we are pushing to an array of items that we are
331
+ // currently looping over. However, you can also think of it like a processing queue
332
+ // where you keep handling jobs until everything is done and each job can queue more
333
+ // jobs if needed.
334
+ variantFunctionTuples.push([
335
+ context.offsets.applyParallelOffset(variantSort, idx),
336
+ variantFunction,
337
+ // If the clone has been modified we have to pass that back
338
+ // though so each rule can use the modified container
339
+ clone.clone()
340
+ ]);
341
+ }
342
+ continue;
343
+ }
344
+ if (typeof ruleWithVariant === "string") {
345
+ collectedFormats.push({
346
+ format: ruleWithVariant,
347
+ isArbitraryVariant
348
+ });
349
+ }
350
+ if (ruleWithVariant === null) {
351
+ continue;
352
+ }
353
+ // We had to backup selectors, therefore we assume that somebody touched
354
+ // `container` or `modifySelectors`. Let's see if they did, so that we
355
+ // can restore the selectors, and collect the format strings.
356
+ if (clone.raws.neededBackup) {
357
+ delete clone.raws.neededBackup;
358
+ clone.walkRules((rule)=>{
359
+ let before = rule.raws.originalSelector;
360
+ if (!before) return;
361
+ delete rule.raws.originalSelector;
362
+ if (before === rule.selector) return; // No mutation happened
363
+ let modified = rule.selector;
364
+ // Rebuild the base selector, this is what plugin authors would do
365
+ // as well. E.g.: `${variant}${separator}${className}`.
366
+ // However, plugin authors probably also prepend or append certain
367
+ // classes, pseudos, ids, ...
368
+ let rebuiltBase = (0, _postcssselectorparser.default)((selectors)=>{
369
+ selectors.walkClasses((classNode)=>{
370
+ classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
371
+ });
372
+ }).processSync(before);
373
+ // Now that we know the original selector, the new selector, and
374
+ // the rebuild part in between, we can replace the part that plugin
375
+ // authors need to rebuild with `&`, and eventually store it in the
376
+ // collectedFormats. Similar to what `format('...')` would do.
377
+ //
378
+ // E.g.:
379
+ // variant: foo
380
+ // selector: .markdown > p
381
+ // modified (by plugin): .foo .foo\\:markdown > p
382
+ // rebuiltBase (internal): .foo\\:markdown > p
383
+ // format: .foo &
384
+ collectedFormats.push({
385
+ format: modified.replace(rebuiltBase, "&"),
386
+ isArbitraryVariant
387
+ });
388
+ rule.selector = before;
389
+ });
390
+ }
391
+ // This tracks the originating layer for the variant
392
+ // For example:
393
+ // .sm:underline {} is a variant of something in the utilities layer
394
+ // .sm:container {} is a variant of the container component
395
+ clone.nodes[0].raws.tailwind = {
396
+ ...clone.nodes[0].raws.tailwind,
397
+ parentLayer: meta.layer
398
+ };
399
+ var _meta_collectedFormats;
400
+ let withOffset = [
401
+ {
402
+ ...meta,
403
+ sort: context.offsets.applyVariantOffset(meta.sort, variantSort, Object.assign(args, context.variantOptions.get(variant))),
404
+ collectedFormats: ((_meta_collectedFormats = meta.collectedFormats) !== null && _meta_collectedFormats !== void 0 ? _meta_collectedFormats : []).concat(collectedFormats)
405
+ },
406
+ clone.nodes[0]
407
+ ];
408
+ result.push(withOffset);
409
+ }
410
+ }
411
+ return result;
412
+ }
413
+ return [];
414
+ }
44
415
  function parseRules(rule, cache, options = {}) {
45
- return (0, _isPlainObject.default)(rule) || Array.isArray(rule) ? Array.isArray(rule) ? parseRules(rule[0], cache, rule[1]) : (cache.has(rule) || cache.set(rule, (0, _parseObjectStyles.default)(rule)), [
416
+ // PostCSS node
417
+ if (!(0, _isPlainObject.default)(rule) && !Array.isArray(rule)) {
418
+ return [
419
+ [
420
+ rule
421
+ ],
422
+ options
423
+ ];
424
+ }
425
+ // Tuple
426
+ if (Array.isArray(rule)) {
427
+ return parseRules(rule[0], cache, rule[1]);
428
+ }
429
+ // Simple object
430
+ if (!cache.has(rule)) {
431
+ cache.set(rule, (0, _parseObjectStyles.default)(rule));
432
+ }
433
+ return [
46
434
  cache.get(rule),
47
435
  options
48
- ]) : [
49
- [
50
- rule
51
- ],
52
- options
53
436
  ];
54
437
  }
55
438
  const IS_VALID_PROPERTY_NAME = /^[a-z_-]/;
439
+ function isValidPropName(name) {
440
+ return IS_VALID_PROPERTY_NAME.test(name);
441
+ }
442
+ /**
443
+ * @param {string} declaration
444
+ * @returns {boolean}
445
+ */ function looksLikeUri(declaration) {
446
+ // Quick bailout for obvious non-urls
447
+ // This doesn't support schemes that don't use a leading // but that's unlikely to be a problem
448
+ if (!declaration.includes("://")) {
449
+ return false;
450
+ }
451
+ try {
452
+ const url = new URL(declaration);
453
+ return url.scheme !== "" && url.host !== "";
454
+ } catch (err) {
455
+ // Definitely not a valid url
456
+ return false;
457
+ }
458
+ }
56
459
  function isParsableNode(node) {
57
- let isParsable = !0;
58
- return node.walkDecls((decl)=>{
59
- if (!isParsableCssValue(decl.prop, decl.value)) return isParsable = !1, !1;
60
- }), isParsable;
460
+ let isParsable = true;
461
+ node.walkDecls((decl)=>{
462
+ if (!isParsableCssValue(decl.prop, decl.value)) {
463
+ isParsable = false;
464
+ return false;
465
+ }
466
+ });
467
+ return isParsable;
61
468
  }
62
469
  function isParsableCssValue(property, value) {
63
- if (function(declaration) {
64
- if (!declaration.includes("://")) return !1;
65
- try {
66
- let url = new URL(declaration);
67
- return "" !== url.scheme && "" !== url.host;
68
- } catch (err) {
69
- return !1;
70
- }
71
- }(`${property}:${value}`)) return !1;
470
+ // We don't want to to treat [https://example.com] as a custom property
471
+ // Even though, according to the CSS grammar, it's a totally valid CSS declaration
472
+ // So we short-circuit here by checking if the custom property looks like a url
473
+ if (looksLikeUri(`${property}:${value}`)) {
474
+ return false;
475
+ }
72
476
  try {
73
- return _postcss.default.parse(`a{${property}:${value}}`).toResult(), !0;
477
+ _postcss.default.parse(`a{${property}:${value}}`).toResult();
478
+ return true;
74
479
  } catch (err) {
75
- return !1;
480
+ return false;
76
481
  }
77
482
  }
78
- function* resolveMatches(candidate, context, original = candidate) {
79
- var _sort_options, _sort_options_types, _sort_options1, _findFallback, _typesByMatches_get;
80
- let separator = context.tailwindConfig.separator, [classCandidate, ...variants] = (candidate === _sharedState.NOT_ON_DEMAND ? [
81
- _sharedState.NOT_ON_DEMAND
82
- ] : (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(candidate, separator)).reverse(), important = !1;
83
- if (classCandidate.startsWith("!") && (important = !0, classCandidate = classCandidate.slice(1)), (0, _featureFlags.flagEnabled)(context.tailwindConfig, "variantGrouping") && classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
84
- let base = variants.slice().reverse().join(separator);
85
- for (let part of (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(classCandidate.slice(1, -1), ","))yield* resolveMatches(base + separator + part, context, original);
86
- }
87
- for (let matchedPlugins of function*(classCandidate, context) {
88
- context.candidateRuleMap.has(classCandidate) && (yield [
483
+ function extractArbitraryProperty(classCandidate, context) {
484
+ var _classCandidate_match;
485
+ let [, property, value] = (_classCandidate_match = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) !== null && _classCandidate_match !== void 0 ? _classCandidate_match : [];
486
+ if (value === undefined) {
487
+ return null;
488
+ }
489
+ if (!isValidPropName(property)) {
490
+ return null;
491
+ }
492
+ if (!(0, _isSyntacticallyValidPropertyValue.default)(value)) {
493
+ return null;
494
+ }
495
+ let normalized = (0, _dataTypes.normalize)(value);
496
+ if (!isParsableCssValue(property, normalized)) {
497
+ return null;
498
+ }
499
+ let sort = context.offsets.arbitraryProperty();
500
+ return [
501
+ [
502
+ {
503
+ sort,
504
+ layer: "utilities"
505
+ },
506
+ ()=>({
507
+ [(0, _nameClass.asClass)(classCandidate)]: {
508
+ [property]: normalized
509
+ }
510
+ })
511
+ ]
512
+ ];
513
+ }
514
+ function* resolveMatchedPlugins(classCandidate, context) {
515
+ if (context.candidateRuleMap.has(classCandidate)) {
516
+ yield [
89
517
  context.candidateRuleMap.get(classCandidate),
90
518
  "DEFAULT"
91
- ]), yield* function*(arbitraryPropertyRule) {
92
- null !== arbitraryPropertyRule && (yield [
519
+ ];
520
+ }
521
+ yield* function*(arbitraryPropertyRule) {
522
+ if (arbitraryPropertyRule !== null) {
523
+ yield [
93
524
  arbitraryPropertyRule,
94
525
  "DEFAULT"
95
- ]);
96
- }(function(classCandidate, context) {
97
- var _classCandidate_match;
98
- let [, property, value] = null !== (_classCandidate_match = classCandidate.match(/^\[([a-zA-Z0-9-_]+):(\S+)\]$/)) && void 0 !== _classCandidate_match ? _classCandidate_match : [];
99
- if (void 0 === value || !IS_VALID_PROPERTY_NAME.test(property) || !(0, _isSyntacticallyValidPropertyValue.default)(value)) return null;
100
- let normalized = (0, _dataTypes.normalize)(value);
101
- return isParsableCssValue(property, normalized) ? [
102
- [
103
- {
104
- sort: context.offsets.arbitraryProperty(),
105
- layer: "utilities"
106
- },
107
- ()=>({
108
- [(0, _nameClass.asClass)(classCandidate)]: {
109
- [property]: normalized
110
- }
111
- })
112
- ]
113
- ] : null;
114
- }(classCandidate, context));
115
- let candidatePrefix = classCandidate, negative = !1, twConfigPrefix = context.tailwindConfig.prefix, twConfigPrefixLen = twConfigPrefix.length, hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
116
- for (let [prefix, modifier] of ("-" === candidatePrefix[twConfigPrefixLen] && hasMatchingPrefix && (negative = !0, candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1)), negative && context.candidateRuleMap.has(candidatePrefix) && (yield [
526
+ ];
527
+ }
528
+ }(extractArbitraryProperty(classCandidate, context));
529
+ let candidatePrefix = classCandidate;
530
+ let negative = false;
531
+ const twConfigPrefix = context.tailwindConfig.prefix;
532
+ const twConfigPrefixLen = twConfigPrefix.length;
533
+ const hasMatchingPrefix = candidatePrefix.startsWith(twConfigPrefix) || candidatePrefix.startsWith(`-${twConfigPrefix}`);
534
+ if (candidatePrefix[twConfigPrefixLen] === "-" && hasMatchingPrefix) {
535
+ negative = true;
536
+ candidatePrefix = twConfigPrefix + candidatePrefix.slice(twConfigPrefixLen + 1);
537
+ }
538
+ if (negative && context.candidateRuleMap.has(candidatePrefix)) {
539
+ yield [
117
540
  context.candidateRuleMap.get(candidatePrefix),
118
541
  "-DEFAULT"
119
- ]), function*(candidate) {
120
- let lastIndex = 1 / 0;
121
- for(; lastIndex >= 0;){
122
- let dashIdx;
123
- let wasSlash = !1;
124
- if (lastIndex === 1 / 0 && candidate.endsWith("]")) {
125
- let bracketIdx = candidate.indexOf("[");
126
- "-" === candidate[bracketIdx - 1] ? dashIdx = bracketIdx - 1 : "/" === candidate[bracketIdx - 1] ? (dashIdx = bracketIdx - 1, wasSlash = !0) : dashIdx = -1;
127
- } else lastIndex === 1 / 0 && candidate.includes("/") ? (dashIdx = candidate.lastIndexOf("/"), wasSlash = !0) : dashIdx = candidate.lastIndexOf("-", lastIndex);
128
- if (dashIdx < 0) break;
129
- let prefix = candidate.slice(0, dashIdx), modifier = candidate.slice(wasSlash ? dashIdx : dashIdx + 1);
130
- lastIndex = dashIdx - 1, "" !== prefix && "/" !== modifier && (yield [
131
- prefix,
132
- modifier
133
- ]);
542
+ ];
543
+ }
544
+ for (let [prefix, modifier] of candidatePermutations(candidatePrefix)){
545
+ if (context.candidateRuleMap.has(prefix)) {
546
+ yield [
547
+ context.candidateRuleMap.get(prefix),
548
+ negative ? `-${modifier}` : modifier
549
+ ];
550
+ }
551
+ }
552
+ }
553
+ function splitWithSeparator(input, separator) {
554
+ if (input === _sharedState.NOT_ON_DEMAND) {
555
+ return [
556
+ _sharedState.NOT_ON_DEMAND
557
+ ];
558
+ }
559
+ return (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(input, separator);
560
+ }
561
+ function* recordCandidates(matches, classCandidate) {
562
+ for (const match of matches){
563
+ var _match__options;
564
+ var _match__options_preserveSource;
565
+ match[1].raws.tailwind = {
566
+ ...match[1].raws.tailwind,
567
+ classCandidate,
568
+ preserveSource: (_match__options_preserveSource = (_match__options = match[0].options) === null || _match__options === void 0 ? void 0 : _match__options.preserveSource) !== null && _match__options_preserveSource !== void 0 ? _match__options_preserveSource : false
569
+ };
570
+ yield match;
571
+ }
572
+ }
573
+ function* resolveMatches(candidate, context, original = candidate) {
574
+ let separator = context.tailwindConfig.separator;
575
+ let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
576
+ let important = false;
577
+ if (classCandidate.startsWith("!")) {
578
+ important = true;
579
+ classCandidate = classCandidate.slice(1);
580
+ }
581
+ if ((0, _featureFlags.flagEnabled)(context.tailwindConfig, "variantGrouping")) {
582
+ if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
583
+ let base = variants.slice().reverse().join(separator);
584
+ for (let part of (0, _splitAtTopLevelOnly.splitAtTopLevelOnly)(classCandidate.slice(1, -1), ",")){
585
+ yield* resolveMatches(base + separator + part, context, original);
134
586
  }
135
- }(candidatePrefix)))context.candidateRuleMap.has(prefix) && (yield [
136
- context.candidateRuleMap.get(prefix),
137
- negative ? `-${modifier}` : modifier
138
- ]);
139
- }(classCandidate, context)){
140
- let matches = [], typesByMatches = new Map(), [plugins, modifier] = matchedPlugins, isOnlyPlugin = 1 === plugins.length;
587
+ }
588
+ }
589
+ // TODO: Reintroduce this in ways that doesn't break on false positives
590
+ // function sortAgainst(toSort, against) {
591
+ // return toSort.slice().sort((a, z) => {
592
+ // return bigSign(against.get(a)[0] - against.get(z)[0])
593
+ // })
594
+ // }
595
+ // let sorted = sortAgainst(variants, context.variantMap)
596
+ // if (sorted.toString() !== variants.toString()) {
597
+ // let corrected = sorted.reverse().concat(classCandidate).join(':')
598
+ // throw new Error(`Class ${candidate} should be written as ${corrected}`)
599
+ // }
600
+ for (let matchedPlugins of resolveMatchedPlugins(classCandidate, context)){
601
+ let matches = [];
602
+ let typesByMatches = new Map();
603
+ let [plugins, modifier] = matchedPlugins;
604
+ let isOnlyPlugin = plugins.length === 1;
141
605
  for (let [sort, plugin] of plugins){
142
606
  let matchesPerPlugin = [];
143
- if ("function" == typeof plugin) for (let ruleSet of [].concat(plugin(modifier, {
144
- isOnlyPlugin
145
- }))){
607
+ if (typeof plugin === "function") {
608
+ for (let ruleSet of [].concat(plugin(modifier, {
609
+ isOnlyPlugin
610
+ }))){
611
+ let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
612
+ for (let rule of rules){
613
+ matchesPerPlugin.push([
614
+ {
615
+ ...sort,
616
+ options: {
617
+ ...sort.options,
618
+ ...options
619
+ }
620
+ },
621
+ rule
622
+ ]);
623
+ }
624
+ }
625
+ } else if (modifier === "DEFAULT" || modifier === "-DEFAULT") {
626
+ let ruleSet = plugin;
146
627
  let [rules, options] = parseRules(ruleSet, context.postCssNodeCache);
147
- for (let rule of rules)matchesPerPlugin.push([
148
- {
149
- ...sort,
150
- options: {
151
- ...sort.options,
152
- ...options
153
- }
154
- },
155
- rule
156
- ]);
157
- }
158
- else if ("DEFAULT" === modifier || "-DEFAULT" === modifier) {
159
- let [rules, options] = parseRules(plugin, context.postCssNodeCache);
160
- for (let rule of rules)matchesPerPlugin.push([
161
- {
162
- ...sort,
163
- options: {
164
- ...sort.options,
165
- ...options
166
- }
167
- },
168
- rule
169
- ]);
628
+ for (let rule of rules){
629
+ matchesPerPlugin.push([
630
+ {
631
+ ...sort,
632
+ options: {
633
+ ...sort.options,
634
+ ...options
635
+ }
636
+ },
637
+ rule
638
+ ]);
639
+ }
170
640
  }
171
641
  if (matchesPerPlugin.length > 0) {
172
- let matchingTypes = Array.from((0, _pluginUtils.getMatchingTypes)(null !== (_sort_options_types = null === (_sort_options = sort.options) || void 0 === _sort_options ? void 0 : _sort_options.types) && void 0 !== _sort_options_types ? _sort_options_types : [], modifier, null !== (_sort_options1 = sort.options) && void 0 !== _sort_options1 ? _sort_options1 : {}, context.tailwindConfig)).map(([_, type])=>type);
173
- matchingTypes.length > 0 && typesByMatches.set(matchesPerPlugin, matchingTypes), matches.push(matchesPerPlugin);
642
+ var _sort_options;
643
+ var _sort_options_types, _sort_options1;
644
+ let matchingTypes = Array.from((0, _pluginUtils.getMatchingTypes)((_sort_options_types = (_sort_options = sort.options) === null || _sort_options === void 0 ? void 0 : _sort_options.types) !== null && _sort_options_types !== void 0 ? _sort_options_types : [], modifier, (_sort_options1 = sort.options) !== null && _sort_options1 !== void 0 ? _sort_options1 : {}, context.tailwindConfig)).map(([_, type])=>type);
645
+ if (matchingTypes.length > 0) {
646
+ typesByMatches.set(matchesPerPlugin, matchingTypes);
647
+ }
648
+ matches.push(matchesPerPlugin);
174
649
  }
175
650
  }
176
651
  if (isArbitraryValue(modifier)) {
177
652
  if (matches.length > 1) {
178
- let [withAny, withoutAny] = matches.reduce((group, plugin)=>(plugin.some(([{ options }])=>options.types.some(({ type })=>"any" === type)) ? group[0].push(plugin) : group[1].push(plugin), group), [
653
+ // Partition plugins in 2 categories so that we can start searching in the plugins that
654
+ // don't have `any` as a type first.
655
+ let [withAny, withoutAny] = matches.reduce((group, plugin)=>{
656
+ let hasAnyType = plugin.some(([{ options }])=>options.types.some(({ type })=>type === "any"));
657
+ if (hasAnyType) {
658
+ group[0].push(plugin);
659
+ } else {
660
+ group[1].push(plugin);
661
+ }
662
+ return group;
663
+ }, [
179
664
  [],
180
665
  []
181
666
  ]);
182
667
  function findFallback(matches) {
183
- return 1 === matches.length ? matches[0] : matches.find((rules)=>{
668
+ // If only a single plugin matches, let's take that one
669
+ if (matches.length === 1) {
670
+ return matches[0];
671
+ }
672
+ // Otherwise, find the plugin that creates a valid rule given the arbitrary value, and
673
+ // also has the correct type which preferOnConflicts the plugin in case of clashes.
674
+ return matches.find((rules)=>{
184
675
  let matchingTypes = typesByMatches.get(rules);
185
- return rules.some(([{ options }, rule])=>!!isParsableNode(rule) && options.types.some(({ type , preferOnConflict })=>matchingTypes.includes(type) && preferOnConflict));
676
+ return rules.some(([{ options }, rule])=>{
677
+ if (!isParsableNode(rule)) {
678
+ return false;
679
+ }
680
+ return options.types.some(({ type , preferOnConflict })=>matchingTypes.includes(type) && preferOnConflict);
681
+ });
186
682
  });
187
683
  }
188
- let fallback = null !== (_findFallback = findFallback(withoutAny)) && void 0 !== _findFallback ? _findFallback : findFallback(withAny);
189
- if (fallback) matches = [
190
- fallback
191
- ];
192
- else {
684
+ var _findFallback;
685
+ // Try to find a fallback plugin, because we already know that multiple plugins matched for
686
+ // the given arbitrary value.
687
+ let fallback = (_findFallback = findFallback(withoutAny)) !== null && _findFallback !== void 0 ? _findFallback : findFallback(withAny);
688
+ if (fallback) {
689
+ matches = [
690
+ fallback
691
+ ];
692
+ } else {
693
+ var _typesByMatches_get;
193
694
  let typesPerPlugin = matches.map((match)=>new Set([
194
- ...null !== (_typesByMatches_get = typesByMatches.get(match)) && void 0 !== _typesByMatches_get ? _typesByMatches_get : []
695
+ ...(_typesByMatches_get = typesByMatches.get(match)) !== null && _typesByMatches_get !== void 0 ? _typesByMatches_get : []
195
696
  ]));
196
- for (let pluginTypes of typesPerPlugin)for (let type of pluginTypes){
197
- let removeFromOwnGroup = !1;
198
- for (let otherGroup of typesPerPlugin)pluginTypes !== otherGroup && otherGroup.has(type) && (otherGroup.delete(type), removeFromOwnGroup = !0);
199
- removeFromOwnGroup && pluginTypes.delete(type);
697
+ // Remove duplicates, so that we can detect proper unique types for each plugin.
698
+ for (let pluginTypes of typesPerPlugin){
699
+ for (let type of pluginTypes){
700
+ let removeFromOwnGroup = false;
701
+ for (let otherGroup of typesPerPlugin){
702
+ if (pluginTypes === otherGroup) continue;
703
+ if (otherGroup.has(type)) {
704
+ otherGroup.delete(type);
705
+ removeFromOwnGroup = true;
706
+ }
707
+ }
708
+ if (removeFromOwnGroup) pluginTypes.delete(type);
709
+ }
200
710
  }
201
711
  let messages = [];
202
- for (let [idx, group] of typesPerPlugin.entries())for (let type of group){
203
- let rules = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1).map((line)=>line.trim()).map((x)=>` ${x}`).join("\n")).join("\n\n");
204
- messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
205
- break;
712
+ for (let [idx, group] of typesPerPlugin.entries()){
713
+ for (let type of group){
714
+ let rules = matches[idx].map(([, rule])=>rule).flat().map((rule)=>rule.toString().split("\n").slice(1, -1) // Remove selector and closing '}'
715
+ .map((line)=>line.trim()).map((x)=>` ${x}`) // Re-indent
716
+ .join("\n")).join("\n\n");
717
+ messages.push(` Use \`${candidate.replace("[", `[${type}:`)}\` for \`${rules.trim()}\``);
718
+ break;
719
+ }
206
720
  }
207
721
  _log.default.warn([
208
722
  `The class \`${candidate}\` is ambiguous and matches multiple utilities.`,
@@ -214,229 +728,134 @@ function* resolveMatches(candidate, context, original = candidate) {
214
728
  }
215
729
  matches = matches.map((list)=>list.filter((match)=>isParsableNode(match[1])));
216
730
  }
217
- for (let variant of (matches = function(matches, context) {
218
- if (0 === matches.length || "" === context.tailwindConfig.prefix) return matches;
219
- for (let match of matches){
220
- let [meta] = match;
221
- if (meta.options.respectPrefix) {
222
- let container = _postcss.default.root({
223
- nodes: [
224
- match[1].clone()
225
- ]
226
- }), classCandidate = match[1].raws.tailwind.classCandidate;
227
- container.walkRules((r)=>{
228
- let shouldPrependNegative = classCandidate.startsWith("-");
229
- r.selector = (0, _prefixSelector.default)(context.tailwindConfig.prefix, r.selector, shouldPrependNegative);
230
- }), match[1] = container.nodes[0];
231
- }
232
- }
233
- return matches;
234
- }(matches = Array.from(function*(matches, classCandidate) {
235
- for (let match of matches){
236
- var _match__options, _match__options_preserveSource;
237
- match[1].raws.tailwind = {
238
- ...match[1].raws.tailwind,
239
- classCandidate,
240
- preserveSource: null !== (_match__options_preserveSource = null === (_match__options = match[0].options) || void 0 === _match__options ? void 0 : _match__options.preserveSource) && void 0 !== _match__options_preserveSource && _match__options_preserveSource
241
- }, yield match;
242
- }
243
- }(matches = matches.flat(), classCandidate)), context), important && (matches = function(matches, classCandidate) {
244
- if (0 === matches.length) return matches;
245
- let result = [];
246
- for (let [meta, rule] of matches){
247
- let container = _postcss.default.root({
248
- nodes: [
249
- rule.clone()
250
- ]
251
- });
252
- container.walkRules((r)=>{
253
- let ast = (0, _postcssSelectorParser.default)().astSync(r.selector);
254
- ast.each((sel)=>(0, _formatVariantSelector.eliminateIrrelevantSelectors)(sel, classCandidate)), (0, _pluginUtils.updateAllClasses)(ast, (className)=>className === classCandidate ? `!${className}` : className), r.selector = ast.toString(), r.walkDecls((d)=>d.important = !0);
255
- }), result.push([
256
- {
257
- ...meta,
258
- important: !0
259
- },
260
- container.nodes[0]
261
- ]);
262
- }
263
- return result;
264
- }(matches, classCandidate)), variants))matches = function(variant, matches, context) {
265
- if (0 === matches.length) return matches;
266
- let args = {
267
- modifier: null,
268
- value: _sharedState.NONE
731
+ matches = matches.flat();
732
+ matches = Array.from(recordCandidates(matches, classCandidate));
733
+ matches = applyPrefix(matches, context);
734
+ if (important) {
735
+ matches = applyImportant(matches, classCandidate);
736
+ }
737
+ for (let variant of variants){
738
+ matches = applyVariant(variant, matches, context);
739
+ }
740
+ for (let match of matches){
741
+ match[1].raws.tailwind = {
742
+ ...match[1].raws.tailwind,
743
+ candidate
269
744
  };
270
- {
271
- let [baseVariant, ...modifiers] = (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(variant, "/");
272
- if (modifiers.length > 1 && (baseVariant = baseVariant + "/" + modifiers.slice(0, -1).join("/"), modifiers = modifiers.slice(-1)), modifiers.length && !context.variantMap.has(variant) && (variant = baseVariant, args.modifier = modifiers[0], !(0, _featureFlags.flagEnabled)(context.tailwindConfig, "generalizedModifiers"))) return [];
273
- }
274
- if (variant.endsWith("]") && !variant.startsWith("[")) {
275
- let match = /(.)(-?)\[(.*)\]/g.exec(variant);
276
- if (match) {
277
- let [, char, seperator, value] = match;
278
- if ("@" === char && "-" === seperator || "@" !== char && "" === seperator) return [];
279
- variant = variant.replace(`${seperator}[${value}]`, ""), args.value = value;
280
- }
281
- }
282
- if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
283
- let sort = context.offsets.recordVariant(variant), selector = (0, _dataTypes.normalize)(variant.slice(1, -1)), selectors = (0, _splitAtTopLevelOnlyJs.splitAtTopLevelOnly)(selector, ",");
284
- if (selectors.length > 1 || !selectors.every(_setupContextUtils.isValidVariantFormatString)) return [];
285
- let records = selectors.map((sel, idx)=>[
286
- context.offsets.applyParallelOffset(sort, idx),
287
- (0, _setupContextUtils.parseVariant)(sel.trim())
288
- ]);
289
- context.variantMap.set(variant, records);
290
- }
291
- if (context.variantMap.has(variant)) {
292
- let isArbitraryVariant = isArbitraryValue(variant), variantFunctionTuples = context.variantMap.get(variant).slice(), result = [];
293
- for (let [meta, rule] of matches){
294
- if ("user" === meta.layer) continue;
295
- let container = _postcss.default.root({
296
- nodes: [
297
- rule.clone()
298
- ]
299
- });
300
- for (let [variantSort, variantFunction, containerFromArray] of variantFunctionTuples){
301
- var _meta_collectedFormats;
302
- let clone = (null != containerFromArray ? containerFromArray : container).clone(), collectedFormats = [];
303
- function prepareBackup() {
304
- clone.raws.neededBackup || (clone.raws.neededBackup = !0, clone.walkRules((rule)=>rule.raws.originalSelector = rule.selector));
305
- }
306
- function modifySelectors(modifierFunction) {
307
- return prepareBackup(), clone.each((rule)=>{
308
- "rule" === rule.type && (rule.selectors = rule.selectors.map((selector)=>modifierFunction({
309
- get className () {
310
- return getClassNameFromSelector(selector);
311
- },
312
- selector
313
- })));
314
- }), clone;
315
- }
316
- let ruleWithVariant = variantFunction({
317
- get container () {
318
- return prepareBackup(), clone;
319
- },
320
- separator: context.tailwindConfig.separator,
321
- modifySelectors,
322
- wrap (wrapper) {
323
- let nodes = clone.nodes;
324
- clone.removeAll(), wrapper.append(nodes), clone.append(wrapper);
325
- },
326
- format (selectorFormat) {
327
- collectedFormats.push({
328
- format: selectorFormat,
329
- isArbitraryVariant
330
- });
331
- },
332
- args
333
- });
334
- if (Array.isArray(ruleWithVariant)) {
335
- for (let [idx, variantFunction] of ruleWithVariant.entries())variantFunctionTuples.push([
336
- context.offsets.applyParallelOffset(variantSort, idx),
337
- variantFunction,
338
- clone.clone()
339
- ]);
340
- continue;
341
- }
342
- if ("string" == typeof ruleWithVariant && collectedFormats.push({
343
- format: ruleWithVariant,
344
- isArbitraryVariant
345
- }), null === ruleWithVariant) continue;
346
- clone.raws.neededBackup && (delete clone.raws.neededBackup, clone.walkRules((rule)=>{
347
- let before = rule.raws.originalSelector;
348
- if (!before || (delete rule.raws.originalSelector, before === rule.selector)) return;
349
- let modified = rule.selector, rebuiltBase = (0, _postcssSelectorParser.default)((selectors)=>{
350
- selectors.walkClasses((classNode)=>{
351
- classNode.value = `${variant}${context.tailwindConfig.separator}${classNode.value}`;
352
- });
353
- }).processSync(before);
354
- collectedFormats.push({
355
- format: modified.replace(rebuiltBase, "&"),
356
- isArbitraryVariant
357
- }), rule.selector = before;
358
- })), clone.nodes[0].raws.tailwind = {
359
- ...clone.nodes[0].raws.tailwind,
360
- parentLayer: meta.layer
361
- };
362
- let withOffset = [
363
- {
364
- ...meta,
365
- sort: context.offsets.applyVariantOffset(meta.sort, variantSort, Object.assign(args, context.variantOptions.get(variant))),
366
- collectedFormats: (null !== (_meta_collectedFormats = meta.collectedFormats) && void 0 !== _meta_collectedFormats ? _meta_collectedFormats : []).concat(collectedFormats)
367
- },
368
- clone.nodes[0]
369
- ];
370
- result.push(withOffset);
371
- }
372
- }
373
- return result;
745
+ // Apply final format selector
746
+ match = applyFinalFormat(match, {
747
+ context,
748
+ candidate,
749
+ original
750
+ });
751
+ // Skip rules with invalid selectors
752
+ // This will cause the candidate to be added to the "not class"
753
+ // cache skipping it entirely for future builds
754
+ if (match === null) {
755
+ continue;
374
756
  }
375
- return [];
376
- }(variant, matches, context);
377
- for (let match of matches)match[1].raws.tailwind = {
378
- ...match[1].raws.tailwind,
757
+ yield match;
758
+ }
759
+ }
760
+ }
761
+ function applyFinalFormat(match, { context , candidate , original }) {
762
+ if (!match[0].collectedFormats) {
763
+ return match;
764
+ }
765
+ let isValid = true;
766
+ let finalFormat;
767
+ try {
768
+ finalFormat = (0, _formatVariantSelector.formatVariantSelector)(match[0].collectedFormats, {
769
+ context,
379
770
  candidate
380
- }, null !== (match = function(match, { context , candidate , original }) {
381
- let finalFormat;
382
- if (!match[0].collectedFormats) return match;
383
- let isValid = !0;
384
- try {
385
- finalFormat = (0, _formatVariantSelector.formatVariantSelector)(match[0].collectedFormats, {
386
- context,
387
- candidate
388
- });
389
- } catch {
390
- return null;
391
- }
392
- let container = _postcss.default.root({
393
- nodes: [
394
- match[1].clone()
395
- ]
771
+ });
772
+ } catch {
773
+ // The format selector we produced is invalid
774
+ // This could be because:
775
+ // - A bug exists
776
+ // - A plugin introduced an invalid variant selector (ex: `addVariant('foo', '&;foo')`)
777
+ // - The user used an invalid arbitrary variant (ex: `[&;foo]:underline`)
778
+ // Either way the build will fail because of this
779
+ // We would rather that the build pass "silently" given that this could
780
+ // happen because of picking up invalid things when scanning content
781
+ // So we'll throw out the candidate instead
782
+ return null;
783
+ }
784
+ let container = _postcss.default.root({
785
+ nodes: [
786
+ match[1].clone()
787
+ ]
788
+ });
789
+ container.walkRules((rule)=>{
790
+ if (inKeyframes(rule)) {
791
+ return;
792
+ }
793
+ try {
794
+ rule.selector = (0, _formatVariantSelector.finalizeSelector)(rule.selector, finalFormat, {
795
+ candidate: original,
796
+ context
396
797
  });
397
- return (container.walkRules((rule)=>{
398
- if (!inKeyframes(rule)) try {
399
- rule.selector = (0, _formatVariantSelector.finalizeSelector)(rule.selector, finalFormat, {
400
- candidate: original,
401
- context
402
- });
403
- } catch {
404
- return isValid = !1, !1;
405
- }
406
- }), isValid) ? (match[1] = container.nodes[0], match) : null;
407
- }(match, {
408
- context,
409
- candidate,
410
- original
411
- })) && (yield match);
798
+ } catch {
799
+ // If this selector is invalid we also want to skip it
800
+ // But it's likely that being invalid here means there's a bug in a plugin rather than too loosely matching content
801
+ isValid = false;
802
+ return false;
803
+ }
804
+ });
805
+ if (!isValid) {
806
+ return null;
412
807
  }
808
+ match[1] = container.nodes[0];
809
+ return match;
413
810
  }
414
811
  function inKeyframes(rule) {
415
- return rule.parent && "atrule" === rule.parent.type && "keyframes" === rule.parent.name;
812
+ return rule.parent && rule.parent.type === "atrule" && rule.parent.name === "keyframes";
813
+ }
814
+ function getImportantStrategy(important) {
815
+ if (important === true) {
816
+ return (rule)=>{
817
+ if (inKeyframes(rule)) {
818
+ return;
819
+ }
820
+ rule.walkDecls((d)=>{
821
+ if (d.parent.type === "rule" && !inKeyframes(d.parent)) {
822
+ d.important = true;
823
+ }
824
+ });
825
+ };
826
+ }
827
+ if (typeof important === "string") {
828
+ return (rule)=>{
829
+ if (inKeyframes(rule)) {
830
+ return;
831
+ }
832
+ rule.selectors = rule.selectors.map((selector)=>{
833
+ return (0, _applyImportantSelector.applyImportantSelector)(selector, important);
834
+ });
835
+ };
836
+ }
416
837
  }
417
838
  function generateRules(candidates, context) {
418
- var important, _context_candidateRuleCache_get;
419
- let allRules = [], strategy = !0 === (important = context.tailwindConfig.important) ? (rule)=>{
420
- inKeyframes(rule) || rule.walkDecls((d)=>{
421
- "rule" !== d.parent.type || inKeyframes(d.parent) || (d.important = !0);
422
- });
423
- } : "string" == typeof important ? (rule)=>{
424
- inKeyframes(rule) || (rule.selectors = rule.selectors.map((selector)=>(0, _applyImportantSelector.applyImportantSelector)(selector, important)));
425
- } : void 0;
839
+ let allRules = [];
840
+ let strategy = getImportantStrategy(context.tailwindConfig.important);
426
841
  for (let candidate of candidates){
427
- if (context.notClassCache.has(candidate)) continue;
842
+ if (context.notClassCache.has(candidate)) {
843
+ continue;
844
+ }
428
845
  if (context.candidateRuleCache.has(candidate)) {
429
846
  allRules = allRules.concat(Array.from(context.candidateRuleCache.get(candidate)));
430
847
  continue;
431
848
  }
432
849
  let matches = Array.from(resolveMatches(candidate, context));
433
- if (0 === matches.length) {
850
+ if (matches.length === 0) {
434
851
  context.notClassCache.add(candidate);
435
852
  continue;
436
853
  }
437
854
  context.classCache.set(candidate, matches);
438
- let rules = null !== (_context_candidateRuleCache_get = context.candidateRuleCache.get(candidate)) && void 0 !== _context_candidateRuleCache_get ? _context_candidateRuleCache_get : new Set();
439
- for (let match of (context.candidateRuleCache.set(candidate, rules), matches)){
855
+ var _context_candidateRuleCache_get;
856
+ let rules = (_context_candidateRuleCache_get = context.candidateRuleCache.get(candidate)) !== null && _context_candidateRuleCache_get !== void 0 ? _context_candidateRuleCache_get : new Set();
857
+ context.candidateRuleCache.set(candidate, rules);
858
+ for (const match of matches){
440
859
  let [{ sort , options }, rule] = match;
441
860
  if (options.respectImportant && strategy) {
442
861
  let container = _postcss.default.root({
@@ -444,13 +863,16 @@ function generateRules(candidates, context) {
444
863
  rule.clone()
445
864
  ]
446
865
  });
447
- container.walkRules(strategy), rule = container.nodes[0];
866
+ container.walkRules(strategy);
867
+ rule = container.nodes[0];
448
868
  }
449
869
  let newEntry = [
450
870
  sort,
451
871
  rule
452
872
  ];
453
- rules.add(newEntry), context.ruleCache.add(newEntry), allRules.push(newEntry);
873
+ rules.add(newEntry);
874
+ context.ruleCache.add(newEntry);
875
+ allRules.push(newEntry);
454
876
  }
455
877
  }
456
878
  return allRules;