tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cb6e45a

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 (190) hide show
  1. package/CHANGELOG.md +526 -2
  2. package/LICENSE +1 -2
  3. package/README.md +13 -6
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +4 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli/build/deps.js +54 -0
  11. package/lib/cli/build/index.js +44 -0
  12. package/lib/cli/build/plugin.js +335 -0
  13. package/lib/cli/build/utils.js +78 -0
  14. package/lib/cli/build/watching.js +113 -0
  15. package/lib/cli/help/index.js +71 -0
  16. package/lib/cli/index.js +18 -0
  17. package/lib/cli/init/index.js +46 -0
  18. package/lib/cli/shared.js +12 -0
  19. package/lib/cli-peer-dependencies.js +20 -7
  20. package/lib/cli.js +91 -569
  21. package/lib/constants.js +27 -20
  22. package/lib/corePluginList.js +16 -4
  23. package/lib/corePlugins.js +2247 -1873
  24. package/lib/css/preflight.css +20 -9
  25. package/lib/featureFlags.js +37 -23
  26. package/lib/index.js +28 -12
  27. package/lib/lib/cacheInvalidation.js +90 -0
  28. package/lib/lib/collapseAdjacentRules.js +27 -9
  29. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  30. package/lib/lib/content.js +167 -0
  31. package/lib/lib/defaultExtractor.js +236 -0
  32. package/lib/lib/detectNesting.js +21 -3
  33. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  34. package/lib/lib/expandApplyAtRules.js +439 -160
  35. package/lib/lib/expandTailwindAtRules.js +141 -151
  36. package/lib/lib/findAtConfigPath.js +44 -0
  37. package/lib/lib/generateRules.js +572 -105
  38. package/lib/lib/getModuleDependencies.js +11 -8
  39. package/lib/lib/normalizeTailwindDirectives.js +45 -33
  40. package/lib/lib/offsets.js +217 -0
  41. package/lib/lib/partitionApplyAtRules.js +56 -0
  42. package/lib/lib/regex.js +60 -0
  43. package/lib/lib/resolveDefaultsAtRules.js +114 -81
  44. package/lib/lib/setupContextUtils.js +777 -385
  45. package/lib/lib/setupTrackingContext.js +43 -71
  46. package/lib/lib/sharedState.js +49 -18
  47. package/lib/lib/substituteScreenAtRules.js +13 -8
  48. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  49. package/lib/postcss-plugins/nesting/index.js +19 -0
  50. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  51. package/lib/processTailwindFeatures.js +36 -21
  52. package/lib/public/colors.js +250 -252
  53. package/lib/public/create-plugin.js +6 -4
  54. package/lib/public/default-config.js +7 -5
  55. package/lib/public/default-theme.js +7 -5
  56. package/lib/public/resolve-config.js +8 -5
  57. package/lib/util/bigSign.js +4 -1
  58. package/lib/util/buildMediaQuery.js +18 -24
  59. package/lib/util/cloneDeep.js +7 -6
  60. package/lib/util/cloneNodes.js +21 -3
  61. package/lib/util/color.js +54 -40
  62. package/lib/util/configurePlugins.js +5 -2
  63. package/lib/util/createPlugin.js +6 -6
  64. package/lib/util/createUtilityPlugin.js +11 -13
  65. package/lib/util/dataTypes.js +137 -100
  66. package/lib/util/defaults.js +10 -1
  67. package/lib/util/escapeClassName.js +7 -4
  68. package/lib/util/escapeCommas.js +5 -2
  69. package/lib/util/flattenColorPalette.js +9 -12
  70. package/lib/util/formatVariantSelector.js +285 -0
  71. package/lib/util/getAllConfigs.js +27 -8
  72. package/lib/util/hashConfig.js +6 -3
  73. package/lib/util/isKeyframeRule.js +5 -2
  74. package/lib/util/isPlainObject.js +5 -2
  75. package/lib/util/isValidArbitraryValue.js +72 -0
  76. package/lib/util/log.js +44 -22
  77. package/lib/util/nameClass.js +20 -8
  78. package/lib/util/negateValue.js +23 -6
  79. package/lib/util/normalizeConfig.js +267 -0
  80. package/lib/util/normalizeScreens.js +170 -0
  81. package/lib/util/parseAnimationValue.js +42 -40
  82. package/lib/util/parseBoxShadowValue.js +84 -0
  83. package/lib/util/parseDependency.js +38 -56
  84. package/lib/util/parseGlob.js +34 -0
  85. package/lib/util/parseObjectStyles.js +11 -8
  86. package/lib/util/pluginUtils.js +171 -189
  87. package/lib/util/prefixSelector.js +10 -10
  88. package/lib/util/removeAlphaVariables.js +29 -0
  89. package/lib/util/resolveConfig.js +92 -126
  90. package/lib/util/resolveConfigPath.js +11 -9
  91. package/lib/util/responsive.js +8 -5
  92. package/lib/util/splitAtTopLevelOnly.js +43 -0
  93. package/lib/util/tap.js +4 -1
  94. package/lib/util/toColorValue.js +5 -3
  95. package/lib/util/toPath.js +24 -3
  96. package/lib/util/transformThemeValue.js +49 -31
  97. package/lib/util/validateConfig.js +24 -0
  98. package/lib/util/validateFormalSyntax.js +24 -0
  99. package/lib/util/withAlphaVariable.js +23 -15
  100. package/nesting/index.js +2 -12
  101. package/package.json +48 -46
  102. package/peers/index.js +14817 -12471
  103. package/plugin.d.ts +11 -0
  104. package/plugin.js +2 -1
  105. package/resolveConfig.d.ts +3 -0
  106. package/resolveConfig.js +2 -1
  107. package/scripts/create-plugin-list.js +2 -2
  108. package/scripts/generate-types.js +105 -0
  109. package/scripts/release-channel.js +18 -0
  110. package/scripts/release-notes.js +21 -0
  111. package/scripts/type-utils.js +27 -0
  112. package/src/cli/build/deps.js +56 -0
  113. package/src/cli/build/index.js +45 -0
  114. package/src/cli/build/plugin.js +397 -0
  115. package/src/cli/build/utils.js +76 -0
  116. package/src/cli/build/watching.js +134 -0
  117. package/src/cli/help/index.js +70 -0
  118. package/src/cli/index.js +3 -0
  119. package/src/cli/init/index.js +50 -0
  120. package/src/cli/shared.js +5 -0
  121. package/src/cli-peer-dependencies.js +7 -1
  122. package/src/cli.js +26 -565
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +905 -615
  125. package/src/css/preflight.css +20 -9
  126. package/src/featureFlags.js +26 -10
  127. package/src/index.js +19 -6
  128. package/src/lib/cacheInvalidation.js +52 -0
  129. package/src/lib/collapseAdjacentRules.js +21 -2
  130. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  131. package/src/lib/content.js +205 -0
  132. package/src/lib/defaultExtractor.js +211 -0
  133. package/src/lib/detectNesting.js +22 -3
  134. package/src/lib/evaluateTailwindFunctions.js +84 -10
  135. package/src/lib/expandApplyAtRules.js +488 -153
  136. package/src/lib/expandTailwindAtRules.js +94 -106
  137. package/src/lib/findAtConfigPath.js +50 -0
  138. package/src/lib/generateRules.js +589 -67
  139. package/src/lib/normalizeTailwindDirectives.js +10 -3
  140. package/src/lib/offsets.js +270 -0
  141. package/src/lib/partitionApplyAtRules.js +52 -0
  142. package/src/lib/regex.js +74 -0
  143. package/src/lib/resolveDefaultsAtRules.js +98 -60
  144. package/src/lib/setupContextUtils.js +737 -246
  145. package/src/lib/setupTrackingContext.js +16 -54
  146. package/src/lib/sharedState.js +44 -7
  147. package/src/lib/substituteScreenAtRules.js +6 -3
  148. package/src/postcss-plugins/nesting/README.md +42 -0
  149. package/src/postcss-plugins/nesting/index.js +13 -0
  150. package/src/postcss-plugins/nesting/plugin.js +80 -0
  151. package/src/processTailwindFeatures.js +17 -2
  152. package/src/public/colors.js +4 -9
  153. package/src/util/buildMediaQuery.js +14 -16
  154. package/src/util/cloneNodes.js +19 -2
  155. package/src/util/color.js +31 -14
  156. package/src/util/createUtilityPlugin.js +2 -2
  157. package/src/util/dataTypes.js +57 -21
  158. package/src/util/defaults.js +6 -0
  159. package/src/util/formatVariantSelector.js +319 -0
  160. package/src/util/getAllConfigs.js +19 -0
  161. package/src/util/isValidArbitraryValue.js +61 -0
  162. package/src/util/log.js +23 -22
  163. package/src/util/nameClass.js +6 -2
  164. package/src/util/negateValue.js +14 -4
  165. package/src/util/normalizeConfig.js +282 -0
  166. package/src/util/normalizeScreens.js +140 -0
  167. package/src/util/parseBoxShadowValue.js +72 -0
  168. package/src/util/parseDependency.js +37 -42
  169. package/src/util/parseGlob.js +24 -0
  170. package/src/util/pluginUtils.js +144 -152
  171. package/src/util/prefixSelector.js +7 -8
  172. package/src/util/removeAlphaVariables.js +24 -0
  173. package/src/util/resolveConfig.js +82 -81
  174. package/src/util/splitAtTopLevelOnly.js +45 -0
  175. package/src/util/toPath.js +23 -1
  176. package/src/util/transformThemeValue.js +33 -8
  177. package/src/util/validateConfig.js +13 -0
  178. package/src/util/validateFormalSyntax.js +34 -0
  179. package/src/util/withAlphaVariable.js +1 -1
  180. package/stubs/defaultConfig.stub.js +173 -93
  181. package/stubs/simpleConfig.stub.js +1 -1
  182. package/types/config.d.ts +361 -0
  183. package/types/generated/.gitkeep +0 -0
  184. package/types/generated/colors.d.ts +276 -0
  185. package/types/generated/corePluginList.d.ts +1 -0
  186. package/types/generated/default-theme.d.ts +342 -0
  187. package/types/index.d.ts +7 -0
  188. package/lib/lib/setupWatchingContext.js +0 -284
  189. package/nesting/plugin.js +0 -41
  190. package/src/lib/setupWatchingContext.js +0 -306
@@ -2,159 +2,121 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.default = expandTailwindAtRules;
6
- var sharedState = _interopRequireWildcard(require("./sharedState"));
7
- var _generateRules = require("./generateRules");
8
- var _bigSign = _interopRequireDefault(require("../util/bigSign"));
9
- var _cloneNodes = _interopRequireDefault(require("../util/cloneNodes"));
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>expandTailwindAtRules
8
+ });
9
+ const _quickLru = /*#__PURE__*/ _interopRequireDefault(require("quick-lru"));
10
+ const _sharedState = /*#__PURE__*/ _interopRequireWildcard(require("./sharedState"));
11
+ const _generateRules = require("./generateRules");
12
+ const _log = /*#__PURE__*/ _interopRequireDefault(require("../util/log"));
13
+ const _cloneNodes = /*#__PURE__*/ _interopRequireDefault(require("../util/cloneNodes"));
14
+ const _defaultExtractor = require("./defaultExtractor");
10
15
  function _interopRequireDefault(obj) {
11
16
  return obj && obj.__esModule ? obj : {
12
17
  default: obj
13
18
  };
14
19
  }
15
- function _interopRequireWildcard(obj) {
16
- if (obj && obj.__esModule) {
20
+ function _getRequireWildcardCache(nodeInterop) {
21
+ if (typeof WeakMap !== "function") return null;
22
+ var cacheBabelInterop = new WeakMap();
23
+ var cacheNodeInterop = new WeakMap();
24
+ return (_getRequireWildcardCache = function(nodeInterop) {
25
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
26
+ })(nodeInterop);
27
+ }
28
+ function _interopRequireWildcard(obj, nodeInterop) {
29
+ if (!nodeInterop && obj && obj.__esModule) {
17
30
  return obj;
18
- } else {
19
- var newObj = {
31
+ }
32
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
33
+ return {
34
+ default: obj
20
35
  };
21
- if (obj != null) {
22
- for(var key in obj){
23
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
24
- var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
25
- };
26
- if (desc.get || desc.set) {
27
- Object.defineProperty(newObj, key, desc);
28
- } else {
29
- newObj[key] = obj[key];
30
- }
31
- }
36
+ }
37
+ var cache = _getRequireWildcardCache(nodeInterop);
38
+ if (cache && cache.has(obj)) {
39
+ return cache.get(obj);
40
+ }
41
+ var newObj = {};
42
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
43
+ for(var key in obj){
44
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
45
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
46
+ if (desc && (desc.get || desc.set)) {
47
+ Object.defineProperty(newObj, key, desc);
48
+ } else {
49
+ newObj[key] = obj[key];
32
50
  }
33
51
  }
34
- newObj.default = obj;
35
- return newObj;
36
52
  }
53
+ newObj.default = obj;
54
+ if (cache) {
55
+ cache.set(obj, newObj);
56
+ }
57
+ return newObj;
37
58
  }
38
- let env = sharedState.env;
39
- let contentMatchCache = sharedState.contentMatchCache;
40
- const PATTERNS = [
41
- /([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
42
- /([^<>"'`\s]*\[\w*"[^"`\s]*"?\])/.source,
43
- /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
44
- /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
45
- /([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
46
- /([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
47
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
48
- /([^<>"'`\s]*[^"'`\s:])/.source
49
- ].join('|');
50
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
51
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g;
59
+ let env = _sharedState.env;
52
60
  const builtInExtractors = {
53
- DEFAULT: (content)=>{
54
- let broadMatches = content.match(BROAD_MATCH_GLOBAL_REGEXP) || [];
55
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
56
- return [
57
- ...broadMatches,
58
- ...innerMatches
59
- ];
60
- }
61
+ DEFAULT: _defaultExtractor.defaultExtractor
61
62
  };
62
63
  const builtInTransformers = {
63
- DEFAULT: (content)=>content
64
- ,
65
- svelte: (content)=>content.replace(/(?:^|\s)class:/g, ' ')
64
+ DEFAULT: (content)=>content,
65
+ svelte: (content)=>content.replace(/(?:^|\s)class:/g, " ")
66
66
  };
67
- function getExtractor(tailwindConfig, fileExtension) {
68
- let extractors = tailwindConfig.content.extract;
69
- let contentOptions = tailwindConfig.content.options;
70
- if (typeof extractors === 'function') {
71
- extractors = {
72
- DEFAULT: extractors
73
- };
74
- }
75
- if (contentOptions.defaultExtractor) {
76
- extractors.DEFAULT = contentOptions.defaultExtractor;
77
- }
78
- for (let { extensions , extractor } of contentOptions.extractors || []){
79
- for (let extension of extensions){
80
- extractors[extension] = extractor;
81
- }
82
- }
83
- return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT;
67
+ function getExtractor(context, fileExtension) {
68
+ let extractors = context.tailwindConfig.content.extract;
69
+ return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT(context);
84
70
  }
85
71
  function getTransformer(tailwindConfig, fileExtension) {
86
72
  let transformers = tailwindConfig.content.transform;
87
- if (typeof transformers === 'function') {
88
- transformers = {
89
- DEFAULT: transformers
90
- };
91
- }
92
73
  return transformers[fileExtension] || transformers.DEFAULT || builtInTransformers[fileExtension] || builtInTransformers.DEFAULT;
93
74
  }
75
+ let extractorCache = new WeakMap();
94
76
  // Scans template contents for possible classes. This is a hot path on initial build but
95
77
  // not too important for subsequent builds. The faster the better though — if we can speed
96
78
  // up these regexes by 50% that could cut initial build time by like 20%.
97
- function getClassCandidates(content, extractor, contentMatchCache, candidates, seen) {
98
- for (let line of content.split('\n')){
79
+ function getClassCandidates(content, extractor, candidates, seen) {
80
+ if (!extractorCache.has(extractor)) {
81
+ extractorCache.set(extractor, new _quickLru.default({
82
+ maxSize: 25000
83
+ }));
84
+ }
85
+ for (let line of content.split("\n")){
99
86
  line = line.trim();
100
87
  if (seen.has(line)) {
101
88
  continue;
102
89
  }
103
90
  seen.add(line);
104
- if (contentMatchCache.has(line)) {
105
- for (let match of contentMatchCache.get(line)){
91
+ if (extractorCache.get(extractor).has(line)) {
92
+ for (let match of extractorCache.get(extractor).get(line)){
106
93
  candidates.add(match);
107
94
  }
108
95
  } else {
109
- let extractorMatches = extractor(line).filter((s)=>s !== '!*'
110
- );
96
+ let extractorMatches = extractor(line).filter((s)=>s !== "!*");
111
97
  let lineMatchesSet = new Set(extractorMatches);
112
- for (let match of lineMatchesSet){
113
- candidates.add(match);
98
+ for (let match1 of lineMatchesSet){
99
+ candidates.add(match1);
114
100
  }
115
- contentMatchCache.set(line, lineMatchesSet);
101
+ extractorCache.get(extractor).set(line, lineMatchesSet);
116
102
  }
117
103
  }
118
104
  }
119
- function buildStylesheet(rules, context) {
120
- let sortedRules = rules.sort(([a], [z])=>(0, _bigSign).default(a - z)
121
- );
105
+ /**
106
+ *
107
+ * @param {[import('./offsets.js').RuleOffset, import('postcss').Node][]} rules
108
+ * @param {*} context
109
+ */ function buildStylesheet(rules, context) {
110
+ let sortedRules = context.offsets.sort(rules);
122
111
  let returnValue = {
123
112
  base: new Set(),
113
+ defaults: new Set(),
124
114
  components: new Set(),
125
115
  utilities: new Set(),
126
- variants: new Set(),
127
- // All the CSS that is not Tailwind related can be put in this bucket. This
128
- // will make it easier to later use this information when we want to
129
- // `@apply` for example. The main reason we do this here is because we
130
- // still need to make sure the order is correct. Last but not least, we
131
- // will make sure to always re-inject this section into the css, even if
132
- // certain rules were not used. This means that it will look like a no-op
133
- // from the user's perspective, but we gathered all the useful information
134
- // we need.
135
- user: new Set()
116
+ variants: new Set()
136
117
  };
137
118
  for (let [sort, rule] of sortedRules){
138
- if (sort >= context.minimumScreen) {
139
- returnValue.variants.add(rule);
140
- continue;
141
- }
142
- if (sort & context.layerOrder.base) {
143
- returnValue.base.add(rule);
144
- continue;
145
- }
146
- if (sort & context.layerOrder.components) {
147
- returnValue.components.add(rule);
148
- continue;
149
- }
150
- if (sort & context.layerOrder.utilities) {
151
- returnValue.utilities.add(rule);
152
- continue;
153
- }
154
- if (sort & context.layerOrder.user) {
155
- returnValue.user.add(rule);
156
- continue;
157
- }
119
+ returnValue[sort.layer].add(rule);
158
120
  }
159
121
  return returnValue;
160
122
  }
@@ -166,89 +128,117 @@ function expandTailwindAtRules(context) {
166
128
  utilities: null,
167
129
  variants: null
168
130
  };
169
- // Make sure this file contains Tailwind directives. If not, we can save
170
- // a lot of work and bail early. Also we don't have to register our touch
171
- // file as a dependency since the output of this CSS does not depend on
172
- // the source of any templates. Think Vue <style> blocks for example.
173
- root.walkAtRules('tailwind', (rule)=>{
174
- if (Object.keys(layerNodes).includes(rule.params)) {
175
- layerNodes[rule.params] = rule;
131
+ root.walkAtRules((rule)=>{
132
+ // Make sure this file contains Tailwind directives. If not, we can save
133
+ // a lot of work and bail early. Also we don't have to register our touch
134
+ // file as a dependency since the output of this CSS does not depend on
135
+ // the source of any templates. Think Vue <style> blocks for example.
136
+ if (rule.name === "tailwind") {
137
+ if (Object.keys(layerNodes).includes(rule.params)) {
138
+ layerNodes[rule.params] = rule;
139
+ }
176
140
  }
177
141
  });
178
- if (Object.values(layerNodes).every((n)=>n === null
179
- )) {
142
+ if (Object.values(layerNodes).every((n)=>n === null)) {
180
143
  return root;
181
144
  }
182
145
  // ---
183
146
  // Find potential rules in changed files
184
147
  let candidates = new Set([
185
- '*'
148
+ _sharedState.NOT_ON_DEMAND
186
149
  ]);
187
150
  let seen = new Set();
188
- env.DEBUG && console.time('Reading changed files');
151
+ env.DEBUG && console.time("Reading changed files");
189
152
  for (let { content , extension } of context.changedContent){
190
153
  let transformer = getTransformer(context.tailwindConfig, extension);
191
- let extractor = getExtractor(context.tailwindConfig, extension);
192
- getClassCandidates(transformer(content), extractor, contentMatchCache, candidates, seen);
154
+ let extractor = getExtractor(context, extension);
155
+ getClassCandidates(transformer(content), extractor, candidates, seen);
193
156
  }
157
+ env.DEBUG && console.timeEnd("Reading changed files");
194
158
  // ---
195
159
  // Generate the actual CSS
196
160
  let classCacheCount = context.classCache.size;
197
- env.DEBUG && console.time('Generate rules');
198
- let rules = (0, _generateRules).generateRules(candidates, context);
199
- env.DEBUG && console.timeEnd('Generate rules');
161
+ env.DEBUG && console.time("Generate rules");
162
+ (0, _generateRules.generateRules)(candidates, context);
163
+ env.DEBUG && console.timeEnd("Generate rules");
200
164
  // We only ever add to the classCache, so if it didn't grow, there is nothing new.
201
- env.DEBUG && console.time('Build stylesheet');
165
+ env.DEBUG && console.time("Build stylesheet");
202
166
  if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
203
- for (let rule of rules){
204
- context.ruleCache.add(rule);
205
- }
206
167
  context.stylesheetCache = buildStylesheet([
207
168
  ...context.ruleCache
208
169
  ], context);
209
170
  }
210
- env.DEBUG && console.timeEnd('Build stylesheet');
211
- let { base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
171
+ env.DEBUG && console.timeEnd("Build stylesheet");
172
+ let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
212
173
  // ---
213
174
  // Replace any Tailwind directives with generated CSS
214
175
  if (layerNodes.base) {
215
- layerNodes.base.before((0, _cloneNodes).default([
216
- ...baseNodes
217
- ], layerNodes.base.source));
176
+ layerNodes.base.before((0, _cloneNodes.default)([
177
+ ...baseNodes,
178
+ ...defaultNodes
179
+ ], layerNodes.base.source, {
180
+ layer: "base"
181
+ }));
218
182
  layerNodes.base.remove();
219
183
  }
220
184
  if (layerNodes.components) {
221
- layerNodes.components.before((0, _cloneNodes).default([
185
+ layerNodes.components.before((0, _cloneNodes.default)([
222
186
  ...componentNodes
223
- ], layerNodes.components.source));
187
+ ], layerNodes.components.source, {
188
+ layer: "components"
189
+ }));
224
190
  layerNodes.components.remove();
225
191
  }
226
192
  if (layerNodes.utilities) {
227
- layerNodes.utilities.before((0, _cloneNodes).default([
193
+ layerNodes.utilities.before((0, _cloneNodes.default)([
228
194
  ...utilityNodes
229
- ], layerNodes.utilities.source));
195
+ ], layerNodes.utilities.source, {
196
+ layer: "utilities"
197
+ }));
230
198
  layerNodes.utilities.remove();
231
199
  }
200
+ // We do post-filtering to not alter the emitted order of the variants
201
+ const variantNodes = Array.from(screenNodes).filter((node)=>{
202
+ var ref;
203
+ const parentLayer = (ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer;
204
+ if (parentLayer === "components") {
205
+ return layerNodes.components !== null;
206
+ }
207
+ if (parentLayer === "utilities") {
208
+ return layerNodes.utilities !== null;
209
+ }
210
+ return true;
211
+ });
232
212
  if (layerNodes.variants) {
233
- layerNodes.variants.before((0, _cloneNodes).default([
234
- ...screenNodes
235
- ], layerNodes.variants.source));
213
+ layerNodes.variants.before((0, _cloneNodes.default)(variantNodes, layerNodes.variants.source, {
214
+ layer: "variants"
215
+ }));
236
216
  layerNodes.variants.remove();
237
- } else {
238
- root.append((0, _cloneNodes).default([
239
- ...screenNodes
240
- ], root.source));
217
+ } else if (variantNodes.length > 0) {
218
+ root.append((0, _cloneNodes.default)(variantNodes, root.source, {
219
+ layer: "variants"
220
+ }));
221
+ }
222
+ // If we've got a utility layer and no utilities are generated there's likely something wrong
223
+ const hasUtilityVariants = variantNodes.some((node)=>{
224
+ var ref;
225
+ return ((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer) === "utilities";
226
+ });
227
+ if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
228
+ _log.default.warn("content-problems", [
229
+ "No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.",
230
+ "https://tailwindcss.com/docs/content-configuration"
231
+ ]);
241
232
  }
242
233
  // ---
243
234
  if (env.DEBUG) {
244
- console.log('Potential classes: ', candidates.size);
245
- console.log('Active contexts: ', sharedState.contextSourcesMap.size);
246
- console.log('Content match entries', contentMatchCache.size);
235
+ console.log("Potential classes: ", candidates.size);
236
+ console.log("Active contexts: ", _sharedState.contextSourcesMap.size);
247
237
  }
248
238
  // Clear the cache for the changed files
249
239
  context.changedContent = [];
250
240
  // Cleanup any leftover @layer atrules
251
- root.walkAtRules('layer', (rule)=>{
241
+ root.walkAtRules("layer", (rule)=>{
252
242
  if (Object.keys(layerNodes).includes(rule.params)) {
253
243
  rule.remove();
254
244
  }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "findAtConfigPath", {
6
+ enumerable: true,
7
+ get: ()=>findAtConfigPath
8
+ });
9
+ const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
10
+ const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
11
+ function _interopRequireDefault(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
16
+ function findAtConfigPath(root, result) {
17
+ let configPath = null;
18
+ let relativeTo = null;
19
+ root.walkAtRules("config", (rule)=>{
20
+ var ref;
21
+ var _file, ref1;
22
+ relativeTo = (ref1 = (_file = (ref = rule.source) === null || ref === void 0 ? void 0 : ref.input.file) !== null && _file !== void 0 ? _file : result.opts.from) !== null && ref1 !== void 0 ? ref1 : null;
23
+ if (relativeTo === null) {
24
+ throw rule.error("The `@config` at-rule cannot be used without a `from` option being set on the PostCSS config.");
25
+ }
26
+ if (configPath) {
27
+ throw rule.error("Only `@config` at-rule is allowed per file.");
28
+ }
29
+ let matches = rule.params.match(/(['"])(.*?)\1/);
30
+ if (!matches) {
31
+ throw rule.error("The `@config` at-rule must be followed by a string containing the path to the config file.");
32
+ }
33
+ let inputPath = matches[2];
34
+ if (_path.default.isAbsolute(inputPath)) {
35
+ throw rule.error("The `@config` at-rule cannot be used with an absolute path.");
36
+ }
37
+ configPath = _path.default.resolve(_path.default.dirname(relativeTo), inputPath);
38
+ if (!_fs.default.existsSync(configPath)) {
39
+ throw rule.error(`The config file at "${inputPath}" does not exist. Make sure the path is correct and the file exists.`);
40
+ }
41
+ rule.remove();
42
+ });
43
+ return configPath ? configPath : null;
44
+ }