tailwindcss 0.0.0-oxide-insiders.dddaded → 0.0.0-oxide-insiders.b2e3cf2

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