tailwindcss 0.0.0-insiders.fda68f7 → 0.0.0-oxide.6bf5e56

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