tailwindcss 0.0.0-insiders.e2d5f21 → 0.0.0-insiders.e302ef1

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 (91) hide show
  1. package/CHANGELOG.md +244 -3
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.js +2 -1
  5. package/defaultConfig.js +2 -1
  6. package/defaultTheme.js +2 -1
  7. package/lib/cli.js +123 -88
  8. package/lib/corePlugins.js +288 -360
  9. package/lib/css/preflight.css +4 -4
  10. package/lib/featureFlags.js +4 -5
  11. package/lib/index.js +12 -3
  12. package/lib/lib/cacheInvalidation.js +69 -0
  13. package/lib/lib/collapseAdjacentRules.js +14 -1
  14. package/lib/lib/collapseDuplicateDeclarations.js +52 -1
  15. package/lib/lib/defaultExtractor.js +44 -0
  16. package/lib/lib/evaluateTailwindFunctions.js +1 -1
  17. package/lib/lib/expandApplyAtRules.js +265 -60
  18. package/lib/lib/expandTailwindAtRules.js +63 -48
  19. package/lib/lib/generateRules.js +136 -34
  20. package/lib/lib/normalizeTailwindDirectives.js +10 -2
  21. package/lib/lib/partitionApplyAtRules.js +53 -0
  22. package/lib/lib/resolveDefaultsAtRules.js +30 -12
  23. package/lib/lib/setupContextUtils.js +137 -81
  24. package/lib/lib/setupTrackingContext.js +8 -7
  25. package/lib/lib/sharedState.js +38 -5
  26. package/{nesting → lib/postcss-plugins/nesting}/README.md +0 -0
  27. package/lib/postcss-plugins/nesting/index.js +17 -0
  28. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  29. package/lib/processTailwindFeatures.js +10 -2
  30. package/lib/util/cloneNodes.js +12 -1
  31. package/lib/util/color.js +23 -8
  32. package/lib/util/createPlugin.js +1 -2
  33. package/lib/util/createUtilityPlugin.js +4 -8
  34. package/lib/util/dataTypes.js +4 -2
  35. package/lib/util/defaults.js +6 -0
  36. package/lib/util/flattenColorPalette.js +1 -3
  37. package/lib/util/log.js +10 -6
  38. package/lib/util/normalizeConfig.js +47 -15
  39. package/lib/util/normalizeScreens.js +6 -5
  40. package/lib/util/parseBoxShadowValue.js +44 -4
  41. package/lib/util/pluginUtils.js +6 -13
  42. package/lib/util/prefixSelector.js +4 -5
  43. package/lib/util/resolveConfig.js +48 -27
  44. package/lib/util/resolveConfigPath.js +1 -2
  45. package/lib/util/toColorValue.js +1 -2
  46. package/lib/util/toPath.js +6 -1
  47. package/lib/util/transformThemeValue.js +4 -8
  48. package/nesting/index.js +2 -12
  49. package/package.json +28 -33
  50. package/peers/index.js +3209 -4239
  51. package/plugin.js +2 -1
  52. package/resolveConfig.js +2 -1
  53. package/src/cli.js +62 -15
  54. package/src/corePlugins.js +212 -217
  55. package/src/css/preflight.css +4 -4
  56. package/src/featureFlags.js +3 -3
  57. package/src/index.js +14 -6
  58. package/src/lib/cacheInvalidation.js +52 -0
  59. package/src/lib/collapseAdjacentRules.js +16 -1
  60. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  61. package/src/lib/defaultExtractor.js +50 -0
  62. package/src/lib/evaluateTailwindFunctions.js +1 -1
  63. package/src/lib/expandApplyAtRules.js +285 -56
  64. package/src/lib/expandTailwindAtRules.js +75 -37
  65. package/src/lib/generateRules.js +121 -27
  66. package/src/lib/normalizeTailwindDirectives.js +7 -1
  67. package/src/lib/partitionApplyAtRules.js +52 -0
  68. package/src/lib/resolveDefaultsAtRules.js +35 -10
  69. package/src/lib/setupContextUtils.js +127 -45
  70. package/src/lib/setupTrackingContext.js +8 -7
  71. package/src/lib/sharedState.js +42 -4
  72. package/src/postcss-plugins/nesting/README.md +42 -0
  73. package/src/postcss-plugins/nesting/index.js +13 -0
  74. package/src/postcss-plugins/nesting/plugin.js +80 -0
  75. package/src/processTailwindFeatures.js +12 -2
  76. package/src/util/cloneNodes.js +14 -1
  77. package/src/util/color.js +20 -7
  78. package/src/util/dataTypes.js +7 -5
  79. package/src/util/defaults.js +6 -0
  80. package/src/util/log.js +10 -6
  81. package/src/util/normalizeConfig.js +24 -3
  82. package/src/util/normalizeScreens.js +6 -3
  83. package/src/util/parseBoxShadowValue.js +51 -3
  84. package/src/util/pluginUtils.js +1 -1
  85. package/src/util/prefixSelector.js +7 -5
  86. package/src/util/resolveConfig.js +41 -1
  87. package/src/util/toPath.js +23 -1
  88. package/stubs/defaultConfig.stub.js +2 -2
  89. package/lib/lib/setupWatchingContext.js +0 -288
  90. package/nesting/plugin.js +0 -41
  91. package/src/lib/setupWatchingContext.js +0 -311
@@ -24,6 +24,8 @@ var _toPath = require("../util/toPath");
24
24
  var _log = _interopRequireDefault(require("../util/log"));
25
25
  var _negateValue = _interopRequireDefault(require("../util/negateValue"));
26
26
  var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
27
+ var _generateRules = require("./generateRules");
28
+ var _cacheInvalidationJs = require("./cacheInvalidation.js");
27
29
  function _interopRequireDefault(obj) {
28
30
  return obj && obj.__esModule ? obj : {
29
31
  default: obj
@@ -33,13 +35,11 @@ function _interopRequireWildcard(obj) {
33
35
  if (obj && obj.__esModule) {
34
36
  return obj;
35
37
  } else {
36
- var newObj = {
37
- };
38
+ var newObj = {};
38
39
  if (obj != null) {
39
40
  for(var key in obj){
40
41
  if (Object.prototype.hasOwnProperty.call(obj, key)) {
41
- var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
42
- };
42
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
43
43
  if (desc.get || desc.set) {
44
44
  Object.defineProperty(newObj, key, desc);
45
45
  } else {
@@ -52,6 +52,10 @@ function _interopRequireWildcard(obj) {
52
52
  return newObj;
53
53
  }
54
54
  }
55
+ function prefix(context, selector) {
56
+ let prefix1 = context.tailwindConfig.prefix;
57
+ return typeof prefix1 === 'function' ? prefix1(selector) : prefix1 + selector;
58
+ }
55
59
  function parseVariantFormatString(input) {
56
60
  if (input.includes('{')) {
57
61
  if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`);
@@ -76,8 +80,7 @@ function isBalanced(input) {
76
80
  }
77
81
  return count === 0;
78
82
  }
79
- function insertInto(list, value, { before =[] } = {
80
- }) {
83
+ function insertInto(list, value, { before =[] } = {}) {
81
84
  before = [].concat(before);
82
85
  if (before.length <= 0) {
83
86
  list.push(value);
@@ -112,44 +115,49 @@ function getClasses(selector) {
112
115
  });
113
116
  return parser.transformSync(selector);
114
117
  }
115
- function extractCandidates(node) {
118
+ function extractCandidates(node, state = {
119
+ containsNonOnDemandable: false
120
+ }, depth = 0) {
116
121
  let classes = [];
122
+ // Handle normal rules
117
123
  if (node.type === 'rule') {
118
124
  for (let selector of node.selectors){
119
125
  let classCandidates = getClasses(selector);
120
126
  // At least one of the selectors contains non-"on-demandable" candidates.
121
- if (classCandidates.length === 0) return [];
122
- classes = [
123
- ...classes,
124
- ...classCandidates
125
- ];
127
+ if (classCandidates.length === 0) {
128
+ state.containsNonOnDemandable = true;
129
+ }
130
+ for (let classCandidate of classCandidates){
131
+ classes.push(classCandidate);
132
+ }
126
133
  }
127
- return classes;
128
- }
129
- if (node.type === 'atrule') {
134
+ } else if (node.type === 'atrule') {
130
135
  node.walkRules((rule)=>{
131
- classes = [
132
- ...classes,
133
- ...rule.selectors.flatMap((selector)=>getClasses(selector)
134
- )
135
- ];
136
+ for (let classCandidate of rule.selectors.flatMap((selector)=>getClasses(selector, state, depth + 1)
137
+ )){
138
+ classes.push(classCandidate);
139
+ }
136
140
  });
137
141
  }
142
+ if (depth === 0) {
143
+ return [
144
+ state.containsNonOnDemandable || classes.length === 0,
145
+ classes
146
+ ];
147
+ }
138
148
  return classes;
139
149
  }
140
150
  function withIdentifiers(styles) {
141
151
  return parseStyles(styles).flatMap((node)=>{
142
152
  let nodeMap = new Map();
143
- let candidates = extractCandidates(node);
144
- // If this isn't "on-demandable", assign it a universal candidate.
145
- if (candidates.length === 0) {
146
- return [
147
- [
148
- '*',
149
- node
150
- ]
151
- ];
153
+ let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node);
154
+ // If this isn't "on-demandable", assign it a universal candidate to always include it.
155
+ if (containsNonOnDemandableSelectors) {
156
+ candidates.unshift(sharedState.NOT_ON_DEMAND);
152
157
  }
158
+ // However, it could be that it also contains "on-demandable" candidates.
159
+ // E.g.: `span, .foo {}`, in that case it should still be possible to use
160
+ // `@apply foo` for example.
153
161
  return candidates.map((c)=>{
154
162
  if (!nodeMap.has(node)) {
155
163
  nodeMap.set(node, node);
@@ -169,8 +177,8 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
169
177
  return (0, _prefixSelector).default(tailwindConfig.prefix, selector);
170
178
  }
171
179
  function prefixIdentifier(identifier, options) {
172
- if (identifier === '*') {
173
- return '*';
180
+ if (identifier === sharedState.NOT_ON_DEMAND) {
181
+ return sharedState.NOT_ON_DEMAND;
174
182
  }
175
183
  if (!options.respectPrefix) {
176
184
  return identifier;
@@ -178,8 +186,7 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
178
186
  return context.tailwindConfig.prefix + identifier;
179
187
  }
180
188
  return {
181
- addVariant (variantName, variantFunctions, options = {
182
- }) {
189
+ addVariant (variantName, variantFunctions, options = {}) {
183
190
  variantFunctions = [].concat(variantFunctions).map((variantFunction)=>{
184
191
  if (typeof variantFunction !== 'string') {
185
192
  // Safelist public API functions
@@ -239,33 +246,38 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
239
246
  // Preserved for backwards compatibility but not used in v3.0+
240
247
  return [];
241
248
  },
242
- addUserCss (userCss) {
243
- for (let [identifier, rule] of withIdentifiers(userCss)){
244
- let offset = offsets.user++;
245
- if (!context.candidateRuleMap.has(identifier)) {
246
- context.candidateRuleMap.set(identifier, []);
249
+ addBase (base) {
250
+ for (let [identifier, rule] of withIdentifiers(base)){
251
+ let prefixedIdentifier = prefixIdentifier(identifier, {});
252
+ let offset = offsets.base++;
253
+ if (!context.candidateRuleMap.has(prefixedIdentifier)) {
254
+ context.candidateRuleMap.set(prefixedIdentifier, []);
247
255
  }
248
- context.candidateRuleMap.get(identifier).push([
256
+ context.candidateRuleMap.get(prefixedIdentifier).push([
249
257
  {
250
258
  sort: offset,
251
- layer: 'user'
259
+ layer: 'base'
252
260
  },
253
261
  rule
254
262
  ]);
255
263
  }
256
264
  },
257
- addBase (base) {
258
- for (let [identifier, rule] of withIdentifiers(base)){
259
- let prefixedIdentifier = prefixIdentifier(identifier, {
260
- });
261
- let offset = offsets.base++;
265
+ /**
266
+ * @param {string} group
267
+ * @param {Record<string, string | string[]>} declarations
268
+ */ addDefaults (group, declarations) {
269
+ const groups = {
270
+ [`@defaults ${group}`]: declarations
271
+ };
272
+ for (let [identifier, rule] of withIdentifiers(groups)){
273
+ let prefixedIdentifier = prefixIdentifier(identifier, {});
262
274
  if (!context.candidateRuleMap.has(prefixedIdentifier)) {
263
275
  context.candidateRuleMap.set(prefixedIdentifier, []);
264
276
  }
265
277
  context.candidateRuleMap.get(prefixedIdentifier).push([
266
278
  {
267
- sort: offset,
268
- layer: 'base'
279
+ sort: offsets.base++,
280
+ layer: 'defaults'
269
281
  },
270
282
  rule
271
283
  ]);
@@ -276,19 +288,16 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
276
288
  respectPrefix: true,
277
289
  respectImportant: false
278
290
  };
279
- options = Object.assign({
280
- }, defaultOptions, Array.isArray(options) ? {
281
- } : options);
291
+ options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options);
282
292
  for (let [identifier, rule] of withIdentifiers(components)){
283
293
  let prefixedIdentifier = prefixIdentifier(identifier, options);
284
- let offset = offsets.components++;
285
294
  classList.add(prefixedIdentifier);
286
295
  if (!context.candidateRuleMap.has(prefixedIdentifier)) {
287
296
  context.candidateRuleMap.set(prefixedIdentifier, []);
288
297
  }
289
298
  context.candidateRuleMap.get(prefixedIdentifier).push([
290
299
  {
291
- sort: offset,
300
+ sort: offsets.components++,
292
301
  layer: 'components',
293
302
  options
294
303
  },
@@ -301,19 +310,16 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
301
310
  respectPrefix: true,
302
311
  respectImportant: true
303
312
  };
304
- options = Object.assign({
305
- }, defaultOptions, Array.isArray(options) ? {
306
- } : options);
313
+ options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options);
307
314
  for (let [identifier, rule] of withIdentifiers(utilities)){
308
315
  let prefixedIdentifier = prefixIdentifier(identifier, options);
309
- let offset = offsets.utilities++;
310
316
  classList.add(prefixedIdentifier);
311
317
  if (!context.candidateRuleMap.has(prefixedIdentifier)) {
312
318
  context.candidateRuleMap.set(prefixedIdentifier, []);
313
319
  }
314
320
  context.candidateRuleMap.get(prefixedIdentifier).push([
315
321
  {
316
- sort: offset,
322
+ sort: offsets.utilities++,
317
323
  layer: 'utilities',
318
324
  options
319
325
  },
@@ -440,11 +446,17 @@ function getFileModifiedMap(context) {
440
446
  function trackModified(files, fileModifiedMap) {
441
447
  let changed = false;
442
448
  for (let file of files){
449
+ var ref;
443
450
  if (!file) continue;
444
451
  let parsed = _url.default.parse(file);
445
452
  let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href;
446
453
  pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname;
447
- let newModified = _fs.default.statSync(decodeURIComponent(pathname)).mtimeMs;
454
+ let newModified = (ref = _fs.default.statSync(decodeURIComponent(pathname), {
455
+ throwIfNoEntry: false
456
+ })) === null || ref === void 0 ? void 0 : ref.mtimeMs;
457
+ if (!newModified) {
458
+ continue;
459
+ }
448
460
  if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
449
461
  changed = true;
450
462
  }
@@ -507,16 +519,6 @@ function collectLayerPlugins(root) {
507
519
  layerRule.remove();
508
520
  }
509
521
  });
510
- root.walkRules((rule)=>{
511
- // At this point it is safe to include all the left-over css from the
512
- // user's css file. This is because the `@tailwind` and `@layer` directives
513
- // will already be handled and will be removed from the css tree.
514
- layerPlugins.push(function({ addUserCss }) {
515
- addUserCss(rule, {
516
- respectPrefix: false
517
- });
518
- });
519
- });
520
522
  return layerPlugins;
521
523
  }
522
524
  function resolvePlugins(context, root) {
@@ -562,6 +564,7 @@ function registerPlugins(plugins, context) {
562
564
  let variantList = [];
563
565
  let variantMap = new Map();
564
566
  let offsets = {
567
+ defaults: 0n,
565
568
  base: 0n,
566
569
  components: 0n,
567
570
  utilities: 0n,
@@ -587,6 +590,7 @@ function registerPlugins(plugins, context) {
587
590
  )
588
591
  )([
589
592
  offsets.base,
593
+ offsets.defaults,
590
594
  offsets.components,
591
595
  offsets.utilities,
592
596
  offsets.user,
@@ -596,12 +600,13 @@ function registerPlugins(plugins, context) {
596
600
  // so arbitrary properties are always sorted at the end.
597
601
  context.arbitraryPropertiesSort = (1n << reservedBits << 0n) - 1n;
598
602
  context.layerOrder = {
599
- base: 1n << reservedBits << 0n,
600
- components: 1n << reservedBits << 1n,
601
- utilities: 1n << reservedBits << 2n,
602
- user: 1n << reservedBits << 3n
603
+ defaults: 1n << reservedBits << 0n,
604
+ base: 1n << reservedBits << 1n,
605
+ components: 1n << reservedBits << 2n,
606
+ utilities: 1n << reservedBits << 3n,
607
+ user: 1n << reservedBits << 4n
603
608
  };
604
- reservedBits += 4n;
609
+ reservedBits += 5n;
605
610
  let offset = 0;
606
611
  context.variantOrder = new Map(variantList.map((variant, i)=>{
607
612
  let variantFunctions = variantMap.get(variant).length;
@@ -640,7 +645,8 @@ function registerPlugins(plugins, context) {
640
645
  if (value1 instanceof RegExp) {
641
646
  _log.default.warn('root-regex', [
642
647
  'Regular expressions in `safelist` work differently in Tailwind CSS v3.0.',
643
- 'Update your `safelist` configuration to eliminate this warning.'
648
+ 'Update your `safelist` configuration to eliminate this warning.',
649
+ 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
644
650
  ]);
645
651
  continue;
646
652
  }
@@ -648,13 +654,33 @@ function registerPlugins(plugins, context) {
648
654
  }
649
655
  if (checks.length > 0) {
650
656
  let patternMatchingCount = new Map();
657
+ let prefixLength = context.tailwindConfig.prefix.length;
651
658
  for (let util of classList){
652
659
  let utils = Array.isArray(util) ? (()=>{
653
660
  let [utilName, options] = util;
654
661
  var ref;
655
- return Object.keys((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {
656
- }).map((value)=>(0, _nameClass).formatClass(utilName, value)
662
+ let values = Object.keys((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {});
663
+ let classes = values.map((value)=>(0, _nameClass).formatClass(utilName, value)
657
664
  );
665
+ if (options === null || options === void 0 ? void 0 : options.supportsNegativeValues) {
666
+ // This is the normal negated version
667
+ // e.g. `-inset-1` or `-tw-inset-1`
668
+ classes = [
669
+ ...classes,
670
+ ...classes.map((cls)=>'-' + cls
671
+ )
672
+ ];
673
+ // This is the negated version *after* the prefix
674
+ // e.g. `tw--inset-1`
675
+ // The prefix is already attached to util name
676
+ // So we add the negative after the prefix
677
+ classes = [
678
+ ...classes,
679
+ ...classes.map((cls)=>cls.slice(0, prefixLength) + '-' + cls.slice(prefixLength)
680
+ ),
681
+ ];
682
+ }
683
+ return classes;
658
684
  })() : [
659
685
  util
660
686
  ];
@@ -685,22 +711,51 @@ function registerPlugins(plugins, context) {
685
711
  if (count !== 0) continue;
686
712
  _log.default.warn([
687
713
  `The safelist pattern \`${regex}\` doesn't match any Tailwind CSS classes.`,
688
- 'Fix this pattern or remove it from your `safelist` configuration.',
714
+ 'Fix this pattern or remove it from your `safelist` configuration.',
715
+ 'https://tailwindcss.com/docs/content-configuration#safelisting-classes',
689
716
  ]);
690
717
  }
691
718
  }
692
719
  }
720
+ // A list of utilities that are used by certain Tailwind CSS utilities but
721
+ // that don't exist on their own. This will result in them "not existing" and
722
+ // sorting could be weird since you still require them in order to make the
723
+ // host utitlies work properly. (Thanks Biology)
724
+ let parasiteUtilities = new Set([
725
+ prefix(context, 'group'),
726
+ prefix(context, 'peer')
727
+ ]);
728
+ context.getClassOrder = function getClassOrder(classes) {
729
+ let sortedClassNames = new Map();
730
+ for (let [sort, rule] of (0, _generateRules).generateRules(new Set(classes), context)){
731
+ if (sortedClassNames.has(rule.raws.tailwind.candidate)) continue;
732
+ sortedClassNames.set(rule.raws.tailwind.candidate, sort);
733
+ }
734
+ return classes.map((className)=>{
735
+ var ref;
736
+ let order = (ref = sortedClassNames.get(className)) !== null && ref !== void 0 ? ref : null;
737
+ if (order === null && parasiteUtilities.has(className)) {
738
+ // This will make sure that it is at the very beginning of the
739
+ // `components` layer which technically means 'before any
740
+ // components'.
741
+ order = context.layerOrder.components;
742
+ }
743
+ return [
744
+ className,
745
+ order
746
+ ];
747
+ });
748
+ };
693
749
  // Generate a list of strings for autocompletion purposes, e.g.
694
750
  // ['uppercase', 'lowercase', ...]
695
- context.getClassList = function() {
751
+ context.getClassList = function getClassList() {
696
752
  let output = [];
697
753
  for (let util of classList){
698
754
  if (Array.isArray(util)) {
699
755
  let [utilName, options] = util;
700
756
  let negativeClasses = [];
701
757
  var ref;
702
- for (let [key, value] of Object.entries((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {
703
- })){
758
+ for (let [key, value] of Object.entries((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {})){
704
759
  output.push((0, _nameClass).formatClass(utilName, key));
705
760
  if ((options === null || options === void 0 ? void 0 : options.supportsNegativeValues) && (0, _negateValue).default(value)) {
706
761
  negativeClasses.push((0, _nameClass).formatClass(utilName, `-${key}`));
@@ -748,13 +803,14 @@ function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfig
748
803
  contextMap.set(sourcePath, context);
749
804
  existingContext = context;
750
805
  }
806
+ let cssDidChange = (0, _cacheInvalidationJs).hasContentChanged(sourcePath, root);
751
807
  // If there's already a context in the cache and we don't need to
752
808
  // reset the context, return the cached context.
753
809
  if (existingContext) {
754
810
  let contextDependenciesChanged = trackModified([
755
811
  ...contextDependencies
756
812
  ], getFileModifiedMap(existingContext));
757
- if (!contextDependenciesChanged) {
813
+ if (!contextDependenciesChanged && !cssDidChange) {
758
814
  return [
759
815
  existingContext,
760
816
  false
@@ -123,11 +123,12 @@ function setupTrackingContext(configOrPath) {
123
123
  return (root, result)=>{
124
124
  let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] = getTailwindConfig(configOrPath);
125
125
  let contextDependencies = new Set(configDependencies);
126
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
127
- // to be dependencies of the context. Can reuse the context even if they change.
128
- // We may want to think about `@layer` being part of this trigger too, but it's tough
129
- // because it's impossible for a layer in one file to end up in the actual @tailwind rule
130
- // in another file since independent sources are effectively isolated.
126
+ // If there are no @tailwind or @apply rules, we don't consider this CSS
127
+ // file or its dependencies to be dependencies of the context. Can reuse
128
+ // the context even if they change. We may want to think about `@layer`
129
+ // being part of this trigger too, but it's tough because it's impossible
130
+ // for a layer in one file to end up in the actual @tailwind rule in
131
+ // another file since independent sources are effectively isolated.
131
132
  if (tailwindDirectives.size > 0) {
132
133
  // Add current css file as a context dependencies.
133
134
  contextDependencies.add(result.opts.from);
@@ -140,8 +141,8 @@ function setupTrackingContext(configOrPath) {
140
141
  }
141
142
  let [context] = (0, _setupContextUtils).getContext(root, result, tailwindConfig, userConfigPath, tailwindConfigHash, contextDependencies);
142
143
  let candidateFiles = getCandidateFiles(context, tailwindConfig);
143
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
144
- // to be dependencies of the context. Can reuse the context even if they change.
144
+ // If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
145
+ // dependencies to be dependencies of the context. Can reuse the context even if they change.
145
146
  // We may want to think about `@layer` being part of this trigger too, but it's tough
146
147
  // because it's impossible for a layer in one file to end up in the actual @tailwind rule
147
148
  // in another file since independent sources are effectively isolated.
@@ -2,13 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.contextSourcesMap = exports.configContextMap = exports.contextMap = exports.env = void 0;
5
+ exports.resolveDebug = resolveDebug;
6
+ exports.NOT_ON_DEMAND = exports.sourceHashMap = exports.contextSourcesMap = exports.configContextMap = exports.contextMap = exports.env = void 0;
6
7
  const env = {
7
- TAILWIND_MODE: process.env.TAILWIND_MODE,
8
8
  NODE_ENV: process.env.NODE_ENV,
9
- DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== '0',
10
- TAILWIND_DISABLE_TOUCH: process.env.TAILWIND_DISABLE_TOUCH !== undefined,
11
- TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR
9
+ DEBUG: resolveDebug(process.env.DEBUG)
12
10
  };
13
11
  exports.env = env;
14
12
  const contextMap = new Map();
@@ -17,3 +15,38 @@ const configContextMap = new Map();
17
15
  exports.configContextMap = configContextMap;
18
16
  const contextSourcesMap = new Map();
19
17
  exports.contextSourcesMap = contextSourcesMap;
18
+ const sourceHashMap = new Map();
19
+ exports.sourceHashMap = sourceHashMap;
20
+ const NOT_ON_DEMAND = new String('*');
21
+ exports.NOT_ON_DEMAND = NOT_ON_DEMAND;
22
+ function resolveDebug(debug) {
23
+ if (debug === undefined) {
24
+ return false;
25
+ }
26
+ // Environment variables are strings, so convert to boolean
27
+ if (debug === 'true' || debug === '1') {
28
+ return true;
29
+ }
30
+ if (debug === 'false' || debug === '0') {
31
+ return false;
32
+ }
33
+ // Keep the debug convention into account:
34
+ // DEBUG=* -> This enables all debug modes
35
+ // DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
36
+ // DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
37
+ // DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB
38
+ if (debug === '*') {
39
+ return true;
40
+ }
41
+ let debuggers = debug.split(',').map((d)=>d.split(':')[0]
42
+ );
43
+ // Ignoring tailwindcss
44
+ if (debuggers.includes('-tailwindcss')) {
45
+ return false;
46
+ }
47
+ // Including tailwindcss
48
+ if (debuggers.includes('tailwindcss')) {
49
+ return true;
50
+ }
51
+ return false;
52
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = void 0;
6
+ var _plugin = require("./plugin");
7
+ var _default = Object.assign(function(opts) {
8
+ return {
9
+ postcssPlugin: 'tailwindcss/nesting',
10
+ Once (root, { result }) {
11
+ return (0, _plugin).nesting(opts)(root, result);
12
+ }
13
+ };
14
+ }, {
15
+ postcss: true
16
+ });
17
+ exports.default = _default;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.nesting = nesting;
6
+ var _postcss = _interopRequireDefault(require("postcss"));
7
+ var _postcssNested = _interopRequireDefault(require("postcss-nested"));
8
+ function _interopRequireDefault(obj) {
9
+ return obj && obj.__esModule ? obj : {
10
+ default: obj
11
+ };
12
+ }
13
+ function nesting(opts = _postcssNested.default) {
14
+ return (root, result)=>{
15
+ root.walkAtRules('screen', (rule)=>{
16
+ rule.name = 'media';
17
+ rule.params = `screen(${rule.params})`;
18
+ });
19
+ root.walkAtRules('apply', (rule)=>{
20
+ rule.before(_postcss.default.decl({
21
+ prop: '__apply',
22
+ value: rule.params,
23
+ source: rule.source
24
+ }));
25
+ rule.remove();
26
+ });
27
+ let plugin = (()=>{
28
+ var ref;
29
+ if (typeof opts === 'function' || typeof opts === 'object' && (opts === null || opts === void 0 ? void 0 : (ref = opts.hasOwnProperty) === null || ref === void 0 ? void 0 : ref.call(opts, 'postcssPlugin'))) {
30
+ return opts;
31
+ }
32
+ if (typeof opts === 'string') {
33
+ return require(opts);
34
+ }
35
+ if (Object.keys(opts).length <= 0) {
36
+ return _postcssNested.default;
37
+ }
38
+ throw new Error('tailwindcss/nesting should be loaded with a nesting plugin.');
39
+ })();
40
+ (0, _postcss).default([
41
+ plugin
42
+ ]).process(root, result.opts).sync();
43
+ root.walkDecls('__apply', (decl)=>{
44
+ decl.before(_postcss.default.atRule({
45
+ name: 'apply',
46
+ params: decl.value,
47
+ source: decl.source
48
+ }));
49
+ decl.remove();
50
+ });
51
+ /**
52
+ * Use a private PostCSS API to remove the "clean" flag from the entire AST.
53
+ * This is done because running process() on the AST will set the "clean"
54
+ * flag on all nodes, which we don't want.
55
+ *
56
+ * This causes downstream plugins using the visitor API to be skipped.
57
+ *
58
+ * This is guarded because the PostCSS API is not public
59
+ * and may change in future versions of PostCSS.
60
+ *
61
+ * See https://github.com/postcss/postcss/issues/1712 for more details
62
+ *
63
+ * @param {import('postcss').Node} node
64
+ */ function markDirty(node) {
65
+ if (!('markDirty' in node)) {
66
+ return;
67
+ }
68
+ // Traverse the tree down to the leaf nodes
69
+ if (node.nodes) {
70
+ node.nodes.forEach((n)=>markDirty(n)
71
+ );
72
+ }
73
+ // If it's a leaf node mark it as dirty
74
+ // We do this here because marking a node as dirty
75
+ // will walk up the tree and mark all parents as dirty
76
+ // resulting in a lot of unnecessary work if we did this
77
+ // for every single node
78
+ if (!node.nodes) {
79
+ node.markDirty();
80
+ }
81
+ }
82
+ markDirty(root);
83
+ return root;
84
+ };
85
+ }
@@ -11,6 +11,7 @@ var _substituteScreenAtRules = _interopRequireDefault(require("./lib/substituteS
11
11
  var _resolveDefaultsAtRules = _interopRequireDefault(require("./lib/resolveDefaultsAtRules"));
12
12
  var _collapseAdjacentRules = _interopRequireDefault(require("./lib/collapseAdjacentRules"));
13
13
  var _collapseDuplicateDeclarations = _interopRequireDefault(require("./lib/collapseDuplicateDeclarations"));
14
+ var _partitionApplyAtRules = _interopRequireDefault(require("./lib/partitionApplyAtRules"));
14
15
  var _detectNesting = _interopRequireDefault(require("./lib/detectNesting"));
15
16
  var _setupContextUtils = require("./lib/setupContextUtils");
16
17
  var _featureFlags = require("./featureFlags");
@@ -21,9 +22,14 @@ function _interopRequireDefault(obj) {
21
22
  }
22
23
  function processTailwindFeatures(setupContext) {
23
24
  return function(root, result) {
24
- let tailwindDirectives = (0, _normalizeTailwindDirectives).default(root);
25
+ let { tailwindDirectives , applyDirectives } = (0, _normalizeTailwindDirectives).default(root);
26
+ (0, _detectNesting).default()(root, result);
27
+ // Partition apply rules that are found in the css
28
+ // itself.
29
+ (0, _partitionApplyAtRules).default()(root, result);
25
30
  let context = setupContext({
26
31
  tailwindDirectives,
32
+ applyDirectives,
27
33
  registerDependency (dependency) {
28
34
  result.messages.push({
29
35
  plugin: 'tailwindcss',
@@ -39,8 +45,10 @@ function processTailwindFeatures(setupContext) {
39
45
  throw new Error("The '-' character cannot be used as a custom separator in JIT mode due to parsing ambiguity. Please use another character like '_' instead.");
40
46
  }
41
47
  (0, _featureFlags).issueFlagNotices(context.tailwindConfig);
42
- (0, _detectNesting).default(context)(root, result);
43
48
  (0, _expandTailwindAtRules).default(context)(root, result);
49
+ // Partition apply rules that are generated by
50
+ // addComponents, addUtilities and so on.
51
+ (0, _partitionApplyAtRules).default()(root, result);
44
52
  (0, _expandApplyAtRules).default(context)(root, result);
45
53
  (0, _evaluateTailwindFunctions).default(context)(root, result);
46
54
  (0, _substituteScreenAtRules).default(context)(root, result);