tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.ca7b10e

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 (179) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +18 -11
  3. package/dist/chunk-7MHEDNEU.mjs +1 -0
  4. package/dist/chunk-AZANAYY2.mjs +1 -0
  5. package/dist/chunk-YTVGJJD3.mjs +12 -0
  6. package/dist/colors-b_6i0Oi7.d.ts +295 -0
  7. package/dist/colors.d.mts +295 -0
  8. package/dist/colors.d.ts +5 -0
  9. package/dist/colors.js +1 -0
  10. package/dist/colors.mjs +1 -0
  11. package/dist/default-theme.d.mts +1147 -0
  12. package/dist/default-theme.d.ts +1147 -0
  13. package/dist/default-theme.js +1 -0
  14. package/dist/default-theme.mjs +1 -0
  15. package/dist/flatten-color-palette.d.mts +6 -0
  16. package/dist/flatten-color-palette.d.ts +6 -0
  17. package/dist/flatten-color-palette.js +1 -0
  18. package/dist/flatten-color-palette.mjs +1 -0
  19. package/dist/lib.d.mts +264 -0
  20. package/dist/lib.d.ts +3 -0
  21. package/dist/lib.js +33 -0
  22. package/dist/lib.mjs +22 -0
  23. package/dist/plugin.d.mts +11 -0
  24. package/dist/plugin.d.ts +104 -0
  25. package/dist/plugin.js +1 -0
  26. package/dist/plugin.mjs +1 -0
  27. package/dist/resolve-config-BIFUA2FY.d.ts +29 -0
  28. package/dist/resolve-config-QUZ9b-Gn.d.mts +190 -0
  29. package/dist/types-B254mqw1.d.mts +98 -0
  30. package/index.css +866 -0
  31. package/package.json +73 -100
  32. package/preflight.css +375 -0
  33. package/theme.css +453 -0
  34. package/CHANGELOG.md +0 -1758
  35. package/base.css +0 -1
  36. package/colors.js +0 -1
  37. package/components.css +0 -1
  38. package/defaultConfig.js +0 -1
  39. package/defaultTheme.js +0 -1
  40. package/lib/cli-peer-dependencies.js +0 -15
  41. package/lib/cli.js +0 -707
  42. package/lib/constants.js +0 -37
  43. package/lib/corePluginList.js +0 -169
  44. package/lib/corePlugins.js +0 -3525
  45. package/lib/css/LICENSE +0 -25
  46. package/lib/css/preflight.css +0 -354
  47. package/lib/featureFlags.js +0 -57
  48. package/lib/index.js +0 -32
  49. package/lib/lib/collapseAdjacentRules.js +0 -41
  50. package/lib/lib/detectNesting.js +0 -19
  51. package/lib/lib/evaluateTailwindFunctions.js +0 -167
  52. package/lib/lib/expandApplyAtRules.js +0 -228
  53. package/lib/lib/expandTailwindAtRules.js +0 -257
  54. package/lib/lib/generateRules.js +0 -350
  55. package/lib/lib/getModuleDependencies.js +0 -48
  56. package/lib/lib/normalizeTailwindDirectives.js +0 -75
  57. package/lib/lib/resolveDefaultsAtRules.js +0 -128
  58. package/lib/lib/setupContextUtils.js +0 -791
  59. package/lib/lib/setupTrackingContext.js +0 -170
  60. package/lib/lib/setupWatchingContext.js +0 -284
  61. package/lib/lib/sharedState.js +0 -29
  62. package/lib/lib/substituteScreenAtRules.js +0 -24
  63. package/lib/processTailwindFeatures.js +0 -47
  64. package/lib/public/colors.js +0 -333
  65. package/lib/public/create-plugin.js +0 -13
  66. package/lib/public/default-config.js +0 -14
  67. package/lib/public/default-theme.js +0 -14
  68. package/lib/public/resolve-config.js +0 -19
  69. package/lib/util/bigSign.js +0 -8
  70. package/lib/util/buildMediaQuery.js +0 -31
  71. package/lib/util/cloneDeep.js +0 -19
  72. package/lib/util/cloneNodes.js +0 -14
  73. package/lib/util/color.js +0 -84
  74. package/lib/util/configurePlugins.js +0 -18
  75. package/lib/util/createPlugin.js +0 -30
  76. package/lib/util/createUtilityPlugin.js +0 -53
  77. package/lib/util/dataTypes.js +0 -202
  78. package/lib/util/defaults.js +0 -16
  79. package/lib/util/escapeClassName.js +0 -19
  80. package/lib/util/escapeCommas.js +0 -8
  81. package/lib/util/flattenColorPalette.js +0 -19
  82. package/lib/util/getAllConfigs.js +0 -29
  83. package/lib/util/hashConfig.js +0 -16
  84. package/lib/util/isKeyframeRule.js +0 -8
  85. package/lib/util/isPlainObject.js +0 -12
  86. package/lib/util/log.js +0 -35
  87. package/lib/util/nameClass.js +0 -31
  88. package/lib/util/negateValue.js +0 -17
  89. package/lib/util/parseAnimationValue.js +0 -89
  90. package/lib/util/parseDependency.js +0 -63
  91. package/lib/util/parseObjectStyles.js +0 -31
  92. package/lib/util/pluginUtils.js +0 -282
  93. package/lib/util/prefixSelector.js +0 -23
  94. package/lib/util/resolveConfig.js +0 -293
  95. package/lib/util/resolveConfigPath.js +0 -52
  96. package/lib/util/responsive.js +0 -19
  97. package/lib/util/tap.js +0 -9
  98. package/lib/util/toColorValue.js +0 -9
  99. package/lib/util/toPath.js +0 -9
  100. package/lib/util/transformThemeValue.js +0 -53
  101. package/lib/util/withAlphaVariable.js +0 -67
  102. package/nesting/README.md +0 -42
  103. package/nesting/index.js +0 -12
  104. package/nesting/plugin.js +0 -41
  105. package/peers/index.js +0 -77111
  106. package/plugin.js +0 -1
  107. package/prettier.config.js +0 -19
  108. package/resolveConfig.js +0 -1
  109. package/screens.css +0 -1
  110. package/scripts/create-plugin-list.js +0 -10
  111. package/scripts/install-integrations.js +0 -27
  112. package/scripts/rebuildFixtures.js +0 -68
  113. package/src/cli-peer-dependencies.js +0 -9
  114. package/src/cli.js +0 -762
  115. package/src/constants.js +0 -17
  116. package/src/corePluginList.js +0 -1
  117. package/src/corePlugins.js +0 -2382
  118. package/src/css/LICENSE +0 -25
  119. package/src/css/preflight.css +0 -354
  120. package/src/featureFlags.js +0 -48
  121. package/src/index.js +0 -34
  122. package/src/lib/collapseAdjacentRules.js +0 -39
  123. package/src/lib/detectNesting.js +0 -20
  124. package/src/lib/evaluateTailwindFunctions.js +0 -195
  125. package/src/lib/expandApplyAtRules.js +0 -251
  126. package/src/lib/expandTailwindAtRules.js +0 -266
  127. package/src/lib/generateRules.js +0 -320
  128. package/src/lib/getModuleDependencies.js +0 -39
  129. package/src/lib/normalizeTailwindDirectives.js +0 -77
  130. package/src/lib/resolveDefaultsAtRules.js +0 -125
  131. package/src/lib/setupContextUtils.js +0 -775
  132. package/src/lib/setupTrackingContext.js +0 -184
  133. package/src/lib/setupWatchingContext.js +0 -306
  134. package/src/lib/sharedState.js +0 -13
  135. package/src/lib/substituteScreenAtRules.js +0 -16
  136. package/src/processTailwindFeatures.js +0 -43
  137. package/src/public/colors.js +0 -305
  138. package/src/public/create-plugin.js +0 -2
  139. package/src/public/default-config.js +0 -4
  140. package/src/public/default-theme.js +0 -4
  141. package/src/public/resolve-config.js +0 -7
  142. package/src/util/bigSign.js +0 -3
  143. package/src/util/buildMediaQuery.js +0 -24
  144. package/src/util/cloneDeep.js +0 -11
  145. package/src/util/cloneNodes.js +0 -11
  146. package/src/util/color.js +0 -56
  147. package/src/util/configurePlugins.js +0 -23
  148. package/src/util/createPlugin.js +0 -27
  149. package/src/util/createUtilityPlugin.js +0 -37
  150. package/src/util/dataTypes.js +0 -216
  151. package/src/util/defaults.js +0 -11
  152. package/src/util/escapeClassName.js +0 -8
  153. package/src/util/escapeCommas.js +0 -3
  154. package/src/util/flattenColorPalette.js +0 -13
  155. package/src/util/getAllConfigs.js +0 -19
  156. package/src/util/hashConfig.js +0 -5
  157. package/src/util/isKeyframeRule.js +0 -3
  158. package/src/util/isPlainObject.js +0 -8
  159. package/src/util/log.js +0 -28
  160. package/src/util/nameClass.js +0 -26
  161. package/src/util/negateValue.js +0 -14
  162. package/src/util/parseAnimationValue.js +0 -68
  163. package/src/util/parseDependency.js +0 -49
  164. package/src/util/parseObjectStyles.js +0 -19
  165. package/src/util/pluginUtils.js +0 -288
  166. package/src/util/prefixSelector.js +0 -15
  167. package/src/util/resolveConfig.js +0 -282
  168. package/src/util/resolveConfigPath.js +0 -55
  169. package/src/util/responsive.js +0 -10
  170. package/src/util/tap.js +0 -4
  171. package/src/util/toColorValue.js +0 -3
  172. package/src/util/toPath.js +0 -4
  173. package/src/util/transformThemeValue.js +0 -37
  174. package/src/util/withAlphaVariable.js +0 -49
  175. package/stubs/defaultConfig.stub.js +0 -890
  176. package/stubs/defaultPostCssConfig.stub.js +0 -6
  177. package/stubs/simpleConfig.stub.js +0 -8
  178. package/tailwind.css +0 -5
  179. package/variants.css +0 -1
@@ -1,251 +0,0 @@
1
- import postcss from 'postcss'
2
- import { resolveMatches } from './generateRules'
3
- import bigSign from '../util/bigSign'
4
- import escapeClassName from '../util/escapeClassName'
5
-
6
- function prefix(context, selector) {
7
- let prefix = context.tailwindConfig.prefix
8
- return typeof prefix === 'function' ? prefix(selector) : prefix + selector
9
- }
10
-
11
- function buildApplyCache(applyCandidates, context) {
12
- for (let candidate of applyCandidates) {
13
- if (context.notClassCache.has(candidate) || context.applyClassCache.has(candidate)) {
14
- continue
15
- }
16
-
17
- if (context.classCache.has(candidate)) {
18
- context.applyClassCache.set(
19
- candidate,
20
- context.classCache.get(candidate).map(([meta, rule]) => [meta, rule.clone()])
21
- )
22
- continue
23
- }
24
-
25
- let matches = Array.from(resolveMatches(candidate, context))
26
-
27
- if (matches.length === 0) {
28
- context.notClassCache.add(candidate)
29
- continue
30
- }
31
-
32
- context.applyClassCache.set(candidate, matches)
33
- }
34
-
35
- return context.applyClassCache
36
- }
37
-
38
- function extractApplyCandidates(params) {
39
- let candidates = params.split(/[\s\t\n]+/g)
40
-
41
- if (candidates[candidates.length - 1] === '!important') {
42
- return [candidates.slice(0, -1), true]
43
- }
44
-
45
- return [candidates, false]
46
- }
47
-
48
- function partitionApplyParents(root) {
49
- let applyParents = new Set()
50
-
51
- root.walkAtRules('apply', (rule) => {
52
- applyParents.add(rule.parent)
53
- })
54
-
55
- for (let rule of applyParents) {
56
- let nodeGroups = []
57
- let lastGroup = []
58
-
59
- for (let node of rule.nodes) {
60
- if (node.type === 'atrule' && node.name === 'apply') {
61
- if (lastGroup.length > 0) {
62
- nodeGroups.push(lastGroup)
63
- lastGroup = []
64
- }
65
- nodeGroups.push([node])
66
- } else {
67
- lastGroup.push(node)
68
- }
69
- }
70
-
71
- if (lastGroup.length > 0) {
72
- nodeGroups.push(lastGroup)
73
- }
74
-
75
- if (nodeGroups.length === 1) {
76
- continue
77
- }
78
-
79
- for (let group of [...nodeGroups].reverse()) {
80
- let newParent = rule.clone({ nodes: [] })
81
- newParent.append(group)
82
- rule.after(newParent)
83
- }
84
-
85
- rule.remove()
86
- }
87
- }
88
-
89
- function processApply(root, context) {
90
- let applyCandidates = new Set()
91
-
92
- // Collect all @apply rules and candidates
93
- let applies = []
94
- root.walkAtRules('apply', (rule) => {
95
- let [candidates] = extractApplyCandidates(rule.params)
96
-
97
- for (let util of candidates) {
98
- applyCandidates.add(util)
99
- }
100
-
101
- applies.push(rule)
102
- })
103
-
104
- // Start the @apply process if we have rules with @apply in them
105
- if (applies.length > 0) {
106
- // Fill up some caches!
107
- let applyClassCache = buildApplyCache(applyCandidates, context)
108
-
109
- /**
110
- * When we have an apply like this:
111
- *
112
- * .abc {
113
- * @apply hover:font-bold;
114
- * }
115
- *
116
- * What we essentially will do is resolve to this:
117
- *
118
- * .abc {
119
- * @apply .hover\:font-bold:hover {
120
- * font-weight: 500;
121
- * }
122
- * }
123
- *
124
- * Notice that the to-be-applied class is `.hover\:font-bold:hover` and that the utility candidate was `hover:font-bold`.
125
- * What happens in this function is that we prepend a `.` and escape the candidate.
126
- * This will result in `.hover\:font-bold`
127
- * Which means that we can replace `.hover\:font-bold` with `.abc` in `.hover\:font-bold:hover` resulting in `.abc:hover`
128
- */
129
- // TODO: Should we use postcss-selector-parser for this instead?
130
- function replaceSelector(selector, utilitySelectors, candidate) {
131
- let needle = `.${escapeClassName(candidate)}`
132
- let utilitySelectorsList = utilitySelectors.split(/\s*,\s*/g)
133
-
134
- return selector
135
- .split(/\s*,\s*/g)
136
- .map((s) => {
137
- let replaced = []
138
-
139
- for (let utilitySelector of utilitySelectorsList) {
140
- let replacedSelector = utilitySelector.replace(needle, s)
141
- if (replacedSelector === utilitySelector) {
142
- continue
143
- }
144
- replaced.push(replacedSelector)
145
- }
146
- return replaced.join(', ')
147
- })
148
- .join(', ')
149
- }
150
-
151
- let perParentApplies = new Map()
152
-
153
- // Collect all apply candidates and their rules
154
- for (let apply of applies) {
155
- let candidates = perParentApplies.get(apply.parent) || []
156
-
157
- perParentApplies.set(apply.parent, candidates)
158
-
159
- let [applyCandidates, important] = extractApplyCandidates(apply.params)
160
-
161
- if (apply.parent.type === 'atrule') {
162
- if (apply.parent.name === 'screen') {
163
- const screenType = apply.parent.params
164
-
165
- throw apply.error(
166
- `@apply is not supported within nested at-rules like @screen. We suggest you write this as @apply ${applyCandidates
167
- .map((c) => `${screenType}:${c}`)
168
- .join(' ')} instead.`
169
- )
170
- }
171
-
172
- throw apply.error(
173
- `@apply is not supported within nested at-rules like @${apply.parent.name}. You can fix this by un-nesting @${apply.parent.name}.`
174
- )
175
- }
176
-
177
- for (let applyCandidate of applyCandidates) {
178
- if (!applyClassCache.has(applyCandidate)) {
179
- if (applyCandidate === prefix(context, 'group')) {
180
- // TODO: Link to specific documentation page with error code.
181
- throw apply.error(`@apply should not be used with the '${applyCandidate}' utility`)
182
- }
183
-
184
- throw apply.error(
185
- `The \`${applyCandidate}\` class does not exist. If \`${applyCandidate}\` is a custom class, make sure it is defined within a \`@layer\` directive.`
186
- )
187
- }
188
-
189
- let rules = applyClassCache.get(applyCandidate)
190
-
191
- candidates.push([applyCandidate, important, rules])
192
- }
193
- }
194
-
195
- for (const [parent, candidates] of perParentApplies) {
196
- let siblings = []
197
-
198
- for (let [applyCandidate, important, rules] of candidates) {
199
- for (let [meta, node] of rules) {
200
- let root = postcss.root({ nodes: [node.clone()] })
201
- let canRewriteSelector =
202
- node.type !== 'atrule' || (node.type === 'atrule' && node.name !== 'keyframes')
203
-
204
- if (canRewriteSelector) {
205
- root.walkRules((rule) => {
206
- rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate)
207
-
208
- rule.walkDecls((d) => {
209
- d.important = meta.important || important
210
- })
211
- })
212
- }
213
-
214
- // Insert it
215
- siblings.push([
216
- // Ensure that when we are sorting, that we take the layer order into account
217
- { ...meta, sort: meta.sort | context.layerOrder[meta.layer] },
218
- root.nodes[0],
219
- ])
220
- }
221
- }
222
-
223
- // Inject the rules, sorted, correctly
224
- let nodes = siblings.sort(([a], [z]) => bigSign(a.sort - z.sort)).map((s) => s[1])
225
-
226
- // console.log(parent)
227
- // `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
228
- parent.after(nodes)
229
- }
230
-
231
- for (let apply of applies) {
232
- // If there are left-over declarations, just remove the @apply
233
- if (apply.parent.nodes.length > 1) {
234
- apply.remove()
235
- } else {
236
- // The node is empty, drop the full node
237
- apply.parent.remove()
238
- }
239
- }
240
-
241
- // Do it again, in case we have other `@apply` rules
242
- processApply(root, context)
243
- }
244
- }
245
-
246
- export default function expandApplyAtRules(context) {
247
- return (root) => {
248
- partitionApplyParents(root)
249
- processApply(root, context)
250
- }
251
- }
@@ -1,266 +0,0 @@
1
- import * as sharedState from './sharedState'
2
- import { generateRules } from './generateRules'
3
- import bigSign from '../util/bigSign'
4
- import cloneNodes from '../util/cloneNodes'
5
-
6
- let env = sharedState.env
7
- let contentMatchCache = sharedState.contentMatchCache
8
-
9
- const PATTERNS = [
10
- /([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source, // font-['some_font',sans-serif]
11
- /([^<>"'`\s]*\[\w*"[^"`\s]*"?\])/.source, // font-["some_font",sans-serif]
12
- /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source, // bg-[url('...')]
13
- /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source, // bg-[url("...")]
14
- /([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
15
- /([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
16
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source, // `fill-[#bada55]`, `fill-[#bada55]/50`
17
- /([^<>"'`\s]*[^"'`\s:])/.source, // `px-1.5`, `uppercase` but not `uppercase:`].join('|')
18
- ].join('|')
19
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g')
20
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g
21
-
22
- const builtInExtractors = {
23
- DEFAULT: (content) => {
24
- let broadMatches = content.match(BROAD_MATCH_GLOBAL_REGEXP) || []
25
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || []
26
-
27
- return [...broadMatches, ...innerMatches]
28
- },
29
- }
30
-
31
- const builtInTransformers = {
32
- DEFAULT: (content) => content,
33
- svelte: (content) => content.replace(/(?:^|\s)class:/g, ' '),
34
- }
35
-
36
- function getExtractor(tailwindConfig, fileExtension) {
37
- let extractors = tailwindConfig.content.extract
38
- let contentOptions = tailwindConfig.content.options
39
-
40
- if (typeof extractors === 'function') {
41
- extractors = {
42
- DEFAULT: extractors,
43
- }
44
- }
45
- if (contentOptions.defaultExtractor) {
46
- extractors.DEFAULT = contentOptions.defaultExtractor
47
- }
48
- for (let { extensions, extractor } of contentOptions.extractors || []) {
49
- for (let extension of extensions) {
50
- extractors[extension] = extractor
51
- }
52
- }
53
-
54
- return (
55
- extractors[fileExtension] ||
56
- extractors.DEFAULT ||
57
- builtInExtractors[fileExtension] ||
58
- builtInExtractors.DEFAULT
59
- )
60
- }
61
-
62
- function getTransformer(tailwindConfig, fileExtension) {
63
- let transformers = tailwindConfig.content.transform
64
-
65
- if (typeof transformers === 'function') {
66
- transformers = {
67
- DEFAULT: transformers,
68
- }
69
- }
70
-
71
- return (
72
- transformers[fileExtension] ||
73
- transformers.DEFAULT ||
74
- builtInTransformers[fileExtension] ||
75
- builtInTransformers.DEFAULT
76
- )
77
- }
78
-
79
- // Scans template contents for possible classes. This is a hot path on initial build but
80
- // not too important for subsequent builds. The faster the better though — if we can speed
81
- // up these regexes by 50% that could cut initial build time by like 20%.
82
- function getClassCandidates(content, extractor, contentMatchCache, candidates, seen) {
83
- for (let line of content.split('\n')) {
84
- line = line.trim()
85
-
86
- if (seen.has(line)) {
87
- continue
88
- }
89
- seen.add(line)
90
-
91
- if (contentMatchCache.has(line)) {
92
- for (let match of contentMatchCache.get(line)) {
93
- candidates.add(match)
94
- }
95
- } else {
96
- let extractorMatches = extractor(line).filter((s) => s !== '!*')
97
- let lineMatchesSet = new Set(extractorMatches)
98
-
99
- for (let match of lineMatchesSet) {
100
- candidates.add(match)
101
- }
102
-
103
- contentMatchCache.set(line, lineMatchesSet)
104
- }
105
- }
106
- }
107
-
108
- function buildStylesheet(rules, context) {
109
- let sortedRules = rules.sort(([a], [z]) => bigSign(a - z))
110
-
111
- let returnValue = {
112
- base: new Set(),
113
- components: new Set(),
114
- utilities: new Set(),
115
- variants: new Set(),
116
-
117
- // All the CSS that is not Tailwind related can be put in this bucket. This
118
- // will make it easier to later use this information when we want to
119
- // `@apply` for example. The main reason we do this here is because we
120
- // still need to make sure the order is correct. Last but not least, we
121
- // will make sure to always re-inject this section into the css, even if
122
- // certain rules were not used. This means that it will look like a no-op
123
- // from the user's perspective, but we gathered all the useful information
124
- // we need.
125
- user: new Set(),
126
- }
127
-
128
- for (let [sort, rule] of sortedRules) {
129
- if (sort >= context.minimumScreen) {
130
- returnValue.variants.add(rule)
131
- continue
132
- }
133
-
134
- if (sort & context.layerOrder.base) {
135
- returnValue.base.add(rule)
136
- continue
137
- }
138
-
139
- if (sort & context.layerOrder.components) {
140
- returnValue.components.add(rule)
141
- continue
142
- }
143
-
144
- if (sort & context.layerOrder.utilities) {
145
- returnValue.utilities.add(rule)
146
- continue
147
- }
148
-
149
- if (sort & context.layerOrder.user) {
150
- returnValue.user.add(rule)
151
- continue
152
- }
153
- }
154
-
155
- return returnValue
156
- }
157
-
158
- export default function expandTailwindAtRules(context) {
159
- return (root) => {
160
- let layerNodes = {
161
- base: null,
162
- components: null,
163
- utilities: null,
164
- variants: null,
165
- }
166
-
167
- // Make sure this file contains Tailwind directives. If not, we can save
168
- // a lot of work and bail early. Also we don't have to register our touch
169
- // file as a dependency since the output of this CSS does not depend on
170
- // the source of any templates. Think Vue <style> blocks for example.
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
-
181
- // ---
182
-
183
- // Find potential rules in changed files
184
- let candidates = new Set(['*'])
185
- let seen = new Set()
186
-
187
- env.DEBUG && console.time('Reading changed files')
188
-
189
- for (let { content, extension } of context.changedContent) {
190
- let transformer = getTransformer(context.tailwindConfig, extension)
191
- let extractor = getExtractor(context.tailwindConfig, extension)
192
- getClassCandidates(transformer(content), extractor, contentMatchCache, candidates, seen)
193
- }
194
-
195
- // ---
196
-
197
- // Generate the actual CSS
198
- let classCacheCount = context.classCache.size
199
-
200
- env.DEBUG && console.time('Generate rules')
201
- let rules = generateRules(candidates, context)
202
- env.DEBUG && console.timeEnd('Generate rules')
203
-
204
- // We only ever add to the classCache, so if it didn't grow, there is nothing new.
205
- env.DEBUG && console.time('Build stylesheet')
206
- if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
207
- for (let rule of rules) {
208
- context.ruleCache.add(rule)
209
- }
210
-
211
- context.stylesheetCache = buildStylesheet([...context.ruleCache], context)
212
- }
213
- env.DEBUG && console.timeEnd('Build stylesheet')
214
-
215
- let {
216
- base: baseNodes,
217
- components: componentNodes,
218
- utilities: utilityNodes,
219
- variants: screenNodes,
220
- } = context.stylesheetCache
221
-
222
- // ---
223
-
224
- // Replace any Tailwind directives with generated CSS
225
-
226
- if (layerNodes.base) {
227
- layerNodes.base.before(cloneNodes([...baseNodes], layerNodes.base.source))
228
- layerNodes.base.remove()
229
- }
230
-
231
- if (layerNodes.components) {
232
- layerNodes.components.before(cloneNodes([...componentNodes], layerNodes.components.source))
233
- layerNodes.components.remove()
234
- }
235
-
236
- if (layerNodes.utilities) {
237
- layerNodes.utilities.before(cloneNodes([...utilityNodes], layerNodes.utilities.source))
238
- layerNodes.utilities.remove()
239
- }
240
-
241
- if (layerNodes.variants) {
242
- layerNodes.variants.before(cloneNodes([...screenNodes], layerNodes.variants.source))
243
- layerNodes.variants.remove()
244
- } else {
245
- root.append(cloneNodes([...screenNodes], root.source))
246
- }
247
-
248
- // ---
249
-
250
- if (env.DEBUG) {
251
- console.log('Potential classes: ', candidates.size)
252
- console.log('Active contexts: ', sharedState.contextSourcesMap.size)
253
- console.log('Content match entries', contentMatchCache.size)
254
- }
255
-
256
- // Clear the cache for the changed files
257
- context.changedContent = []
258
-
259
- // Cleanup any leftover @layer atrules
260
- root.walkAtRules('layer', (rule) => {
261
- if (Object.keys(layerNodes).includes(rule.params)) {
262
- rule.remove()
263
- }
264
- })
265
- }
266
- }