tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21

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