tailwindcss 0.0.0-insiders.8259dfd → 0.0.0-insiders.8293c2d

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 (93) hide show
  1. package/CHANGELOG.md +207 -2
  2. package/README.md +8 -4
  3. package/colors.js +2 -1
  4. package/defaultConfig.js +2 -1
  5. package/defaultTheme.js +2 -1
  6. package/lib/cli.js +94 -61
  7. package/lib/constants.js +1 -1
  8. package/lib/corePluginList.js +8 -1
  9. package/lib/corePlugins.js +477 -517
  10. package/lib/css/preflight.css +18 -5
  11. package/lib/featureFlags.js +5 -6
  12. package/lib/index.js +1 -3
  13. package/lib/lib/collapseDuplicateDeclarations.js +80 -0
  14. package/lib/lib/defaultExtractor.js +42 -0
  15. package/lib/lib/detectNesting.js +17 -2
  16. package/lib/lib/evaluateTailwindFunctions.js +10 -6
  17. package/lib/lib/expandApplyAtRules.js +94 -45
  18. package/lib/lib/expandTailwindAtRules.js +32 -33
  19. package/lib/lib/generateRules.js +167 -21
  20. package/lib/lib/normalizeTailwindDirectives.js +8 -1
  21. package/lib/lib/partitionApplyAtRules.js +53 -0
  22. package/lib/lib/resolveDefaultsAtRules.js +28 -14
  23. package/lib/lib/setupContextUtils.js +153 -129
  24. package/lib/lib/setupTrackingContext.js +11 -10
  25. package/lib/lib/sharedState.js +34 -5
  26. package/lib/lib/substituteScreenAtRules.js +7 -4
  27. package/lib/processTailwindFeatures.js +7 -2
  28. package/lib/util/buildMediaQuery.js +13 -24
  29. package/lib/util/color.js +23 -8
  30. package/lib/util/createPlugin.js +1 -2
  31. package/lib/util/createUtilityPlugin.js +6 -10
  32. package/lib/util/dataTypes.js +38 -7
  33. package/lib/util/defaults.js +6 -0
  34. package/lib/util/flattenColorPalette.js +1 -3
  35. package/lib/util/formatVariantSelector.js +186 -0
  36. package/lib/util/isValidArbitraryValue.js +64 -0
  37. package/lib/util/log.js +4 -0
  38. package/lib/util/nameClass.js +1 -0
  39. package/lib/util/normalizeConfig.js +63 -21
  40. package/lib/util/normalizeScreens.js +59 -0
  41. package/lib/util/parseBoxShadowValue.js +77 -0
  42. package/lib/util/pluginUtils.js +27 -158
  43. package/lib/util/prefixSelector.js +1 -3
  44. package/lib/util/resolveConfig.js +30 -31
  45. package/lib/util/resolveConfigPath.js +1 -2
  46. package/lib/util/toColorValue.js +1 -2
  47. package/lib/util/toPath.js +6 -1
  48. package/lib/util/transformThemeValue.js +19 -13
  49. package/nesting/plugin.js +4 -1
  50. package/package.json +19 -21
  51. package/peers/index.js +4621 -5626
  52. package/plugin.js +2 -1
  53. package/resolveConfig.js +2 -1
  54. package/src/cli.js +66 -14
  55. package/src/corePluginList.js +1 -1
  56. package/src/corePlugins.js +406 -518
  57. package/src/css/preflight.css +18 -5
  58. package/src/featureFlags.js +1 -1
  59. package/src/index.js +1 -7
  60. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  61. package/src/lib/defaultExtractor.js +48 -0
  62. package/src/lib/detectNesting.js +22 -3
  63. package/src/lib/evaluateTailwindFunctions.js +6 -3
  64. package/src/lib/expandApplyAtRules.js +101 -45
  65. package/src/lib/expandTailwindAtRules.js +33 -27
  66. package/src/lib/generateRules.js +178 -11
  67. package/src/lib/normalizeTailwindDirectives.js +6 -1
  68. package/src/lib/partitionApplyAtRules.js +52 -0
  69. package/src/lib/resolveDefaultsAtRules.js +31 -10
  70. package/src/lib/setupContextUtils.js +140 -84
  71. package/src/lib/setupTrackingContext.js +11 -10
  72. package/src/lib/sharedState.js +40 -4
  73. package/src/lib/substituteScreenAtRules.js +6 -3
  74. package/src/processTailwindFeatures.js +8 -2
  75. package/src/util/buildMediaQuery.js +14 -18
  76. package/src/util/color.js +20 -7
  77. package/src/util/dataTypes.js +43 -11
  78. package/src/util/defaults.js +6 -0
  79. package/src/util/formatVariantSelector.js +196 -0
  80. package/src/util/isValidArbitraryValue.js +61 -0
  81. package/src/util/log.js +4 -0
  82. package/src/util/nameClass.js +1 -1
  83. package/src/util/normalizeConfig.js +37 -2
  84. package/src/util/normalizeScreens.js +45 -0
  85. package/src/util/parseBoxShadowValue.js +71 -0
  86. package/src/util/pluginUtils.js +15 -138
  87. package/src/util/prefixSelector.js +1 -4
  88. package/src/util/resolveConfig.js +11 -1
  89. package/src/util/toPath.js +23 -1
  90. package/src/util/transformThemeValue.js +22 -7
  91. package/stubs/defaultConfig.stub.js +42 -16
  92. package/lib/lib/setupWatchingContext.js +0 -284
  93. package/src/lib/setupWatchingContext.js +0 -304
@@ -9,7 +9,12 @@
9
9
  box-sizing: border-box; /* 1 */
10
10
  border-width: 0; /* 2 */
11
11
  border-style: solid; /* 2 */
12
- border-color: currentColor; /* 2 */
12
+ border-color: theme('borderColor.DEFAULT', 'currentColor'); /* 2 */
13
+ }
14
+
15
+ ::before,
16
+ ::after {
17
+ --tw-content: '';
13
18
  }
14
19
 
15
20
  /*
@@ -53,7 +58,7 @@ hr {
53
58
  Add the correct text decoration in Chrome, Edge, and Safari.
54
59
  */
55
60
 
56
- abbr[title] {
61
+ abbr:where([title]) {
57
62
  text-decoration: underline dotted;
58
63
  }
59
64
 
@@ -139,7 +144,7 @@ sup {
139
144
  table {
140
145
  text-indent: 0; /* 1 */
141
146
  border-color: inherit; /* 2 */
142
- border-collapse: collapse; /* 3 */
147
+ border-collapse: collapse; /* 3 */
143
148
  }
144
149
 
145
150
  /*
@@ -283,7 +288,8 @@ legend {
283
288
  }
284
289
 
285
290
  ol,
286
- ul {
291
+ ul,
292
+ menu {
287
293
  list-style: none;
288
294
  margin: 0;
289
295
  padding: 0;
@@ -304,7 +310,7 @@ textarea {
304
310
 
305
311
  input::placeholder,
306
312
  textarea::placeholder {
307
- opacity: 1; /* 1 */
313
+ opacity: 1; /* 1 */
308
314
  color: theme('colors.gray.400', #9ca3af); /* 2 */
309
315
  }
310
316
 
@@ -317,6 +323,13 @@ button,
317
323
  cursor: pointer;
318
324
  }
319
325
 
326
+ /*
327
+ Make sure disabled buttons don't get the pointer cursor.
328
+ */
329
+ :disabled {
330
+ cursor: default;
331
+ }
332
+
320
333
  /*
321
334
  1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
322
335
  2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
@@ -2,7 +2,7 @@ import chalk from 'chalk'
2
2
  import log from './util/log'
3
3
 
4
4
  let defaults = {
5
- optimizeUniversalDefaults: true,
5
+ optimizeUniversalDefaults: false,
6
6
  }
7
7
 
8
8
  let featureFlags = {
package/src/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import setupTrackingContext from './lib/setupTrackingContext'
2
- import setupWatchingContext from './lib/setupWatchingContext'
3
2
  import processTailwindFeatures from './processTailwindFeatures'
4
3
  import { env } from './lib/sharedState'
5
4
 
@@ -14,12 +13,7 @@ module.exports = function tailwindcss(configOrPath) {
14
13
  return root
15
14
  },
16
15
  function (root, result) {
17
- let setupContext =
18
- env.TAILWIND_MODE === 'watch'
19
- ? setupWatchingContext(configOrPath)
20
- : setupTrackingContext(configOrPath)
21
-
22
- processTailwindFeatures(setupContext)(root, result)
16
+ processTailwindFeatures(setupTrackingContext(configOrPath))(root, result)
23
17
  },
24
18
  env.DEBUG &&
25
19
  function (root) {
@@ -0,0 +1,93 @@
1
+ export default function collapseDuplicateDeclarations() {
2
+ return (root) => {
3
+ root.walkRules((node) => {
4
+ let seen = new Map()
5
+ let droppable = new Set([])
6
+ let byProperty = new Map()
7
+
8
+ node.walkDecls((decl) => {
9
+ // This could happen if we have nested selectors. In that case the
10
+ // parent will loop over all its declarations but also the declarations
11
+ // of nested rules. With this we ensure that we are shallowly checking
12
+ // declarations.
13
+ if (decl.parent !== node) {
14
+ return
15
+ }
16
+
17
+ if (seen.has(decl.prop)) {
18
+ // Exact same value as what we have seen so far
19
+ if (seen.get(decl.prop).value === decl.value) {
20
+ // Keep the last one, drop the one we've seen so far
21
+ droppable.add(seen.get(decl.prop))
22
+ // Override the existing one with the new value. This is necessary
23
+ // so that if we happen to have more than one declaration with the
24
+ // same value, that we keep removing the previous one. Otherwise we
25
+ // will only remove the *first* one.
26
+ seen.set(decl.prop, decl)
27
+ return
28
+ }
29
+
30
+ // Not the same value, so we need to check if we can merge it so
31
+ // let's collect it first.
32
+ if (!byProperty.has(decl.prop)) {
33
+ byProperty.set(decl.prop, new Set())
34
+ }
35
+
36
+ byProperty.get(decl.prop).add(seen.get(decl.prop))
37
+ byProperty.get(decl.prop).add(decl)
38
+ }
39
+
40
+ seen.set(decl.prop, decl)
41
+ })
42
+
43
+ // Drop all the duplicate declarations with the exact same value we've
44
+ // already seen so far.
45
+ for (let decl of droppable) {
46
+ decl.remove()
47
+ }
48
+
49
+ // Analyze the declarations based on its unit, drop all the declarations
50
+ // with the same unit but the last one in the list.
51
+ for (let declarations of byProperty.values()) {
52
+ let byUnit = new Map()
53
+
54
+ for (let decl of declarations) {
55
+ let unit = resolveUnit(decl.value)
56
+ if (unit === null) {
57
+ // We don't have a unit, so should never try and collapse this
58
+ // value. This is because we can't know how to do it in a correct
59
+ // way (e.g.: overrides for older browsers)
60
+ continue
61
+ }
62
+
63
+ if (!byUnit.has(unit)) {
64
+ byUnit.set(unit, new Set())
65
+ }
66
+
67
+ byUnit.get(unit).add(decl)
68
+ }
69
+
70
+ for (let declarations of byUnit.values()) {
71
+ // Get all but the last one
72
+ let removableDeclarations = Array.from(declarations).slice(0, -1)
73
+
74
+ for (let decl of removableDeclarations) {
75
+ decl.remove()
76
+ }
77
+ }
78
+ }
79
+ })
80
+ }
81
+ }
82
+
83
+ let UNITLESS_NUMBER = Symbol('unitless-number')
84
+
85
+ function resolveUnit(input) {
86
+ let result = /^-?\d*.?\d+([\w%]+)?$/g.exec(input)
87
+
88
+ if (result) {
89
+ return result[1] ?? UNITLESS_NUMBER
90
+ }
91
+
92
+ return null
93
+ }
@@ -0,0 +1,48 @@
1
+ const PATTERNS = [
2
+ /(?:\['([^'\s]+[^<>"'`\s:\\])')/.source, // ['text-lg' -> text-lg
3
+ /(?:\["([^"\s]+[^<>"'`\s:\\])")/.source, // ["text-lg" -> text-lg
4
+ /(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source, // [`text-lg` -> text-lg
5
+ /([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source, // font-['some_font',sans-serif]
6
+ /([^<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source, // font-["some_font",sans-serif]
7
+ /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source, // bg-[url('...')]
8
+ /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source, // bg-[url("...")]
9
+ /([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source, // bg-[url('...'),url('...')]
10
+ /([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source, // bg-[url("..."),url("...")]
11
+ /([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
12
+ /([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
13
+ /([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source, // `[attr:value]`
14
+ /([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source, // `[content:'hello']` but not `[content:"hello"]`
15
+ /([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source, // `[content:"hello"]` but not `[content:'hello']`
16
+ /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source, // `fill-[#bada55]`, `fill-[#bada55]/50`
17
+ /([^"'`\s]*[^<>"'`\s:\\])/.source, // `<sm:underline`, `md>:font-bold`
18
+ /([^<>"'`\s]*[^"'`\s:\\])/.source, // `px-1.5`, `uppercase` but not `uppercase:`
19
+
20
+ // Arbitrary properties
21
+ // /([^"\s]*\[[^\s]+?\][^"\s]*)/.source,
22
+ // /([^'\s]*\[[^\s]+?\][^'\s]*)/.source,
23
+ // /([^`\s]*\[[^\s]+?\][^`\s]*)/.source,
24
+ ].join('|')
25
+
26
+ const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g')
27
+ const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
28
+
29
+ /**
30
+ * @param {string} content
31
+ */
32
+ export function defaultExtractor(content) {
33
+ let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP)
34
+ let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || []
35
+ let results = [...broadMatches, ...innerMatches].flat().filter((v) => v !== undefined)
36
+
37
+ return results
38
+ }
39
+
40
+ // Regular utilities
41
+ // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
42
+
43
+ // Arbitrary values
44
+ // {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
45
+ // arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
46
+
47
+ // Arbitrary properties
48
+ // {{modifier}:}*[{validCssPropertyName}:{arbitraryValue}]
@@ -2,6 +2,23 @@ export default function (_context) {
2
2
  return (root, result) => {
3
3
  let found = false
4
4
 
5
+ root.walkAtRules('tailwind', (node) => {
6
+ if (found) return false
7
+
8
+ if (node.parent && node.parent.type !== 'root') {
9
+ found = true
10
+ node.warn(
11
+ result,
12
+ [
13
+ 'Nested @tailwind rules were detected, but are not supported.',
14
+ "Consider using a prefix to scope Tailwind's classes: https://tailwindcss.com/docs/configuration#prefix",
15
+ 'Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy',
16
+ ].join('\n')
17
+ )
18
+ return false
19
+ }
20
+ })
21
+
5
22
  root.walkRules((rule) => {
6
23
  if (found) return false
7
24
 
@@ -9,10 +26,12 @@ export default function (_context) {
9
26
  found = true
10
27
  nestedRule.warn(
11
28
  result,
12
- // TODO: Improve this warning message
13
- 'Nested CSS detected, checkout the docs on how to support nesting: https://tailwindcss.com/docs/using-with-preprocessors#nesting'
29
+ [
30
+ 'Nested CSS was detected, but CSS nesting has not been configured correctly.',
31
+ 'Please enable a CSS nesting plugin *before* Tailwind in your configuration.',
32
+ 'See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting',
33
+ ].join('\n')
14
34
  )
15
-
16
35
  return false
17
36
  })
18
37
  })
@@ -2,6 +2,7 @@ import dlv from 'dlv'
2
2
  import didYouMean from 'didyoumean'
3
3
  import transformThemeValue from '../util/transformThemeValue'
4
4
  import parseValue from 'postcss-value-parser'
5
+ import { normalizeScreens } from '../util/normalizeScreens'
5
6
  import buildMediaQuery from '../util/buildMediaQuery'
6
7
  import { toPath } from '../util/toPath'
7
8
 
@@ -41,7 +42,7 @@ function validatePath(config, path, defaultValue) {
41
42
  ? pathToString(path)
42
43
  : path.replace(/^['"]+/g, '').replace(/['"]+$/g, '')
43
44
  const pathSegments = Array.isArray(path) ? path : toPath(pathString)
44
- const value = dlv(config.theme, pathString, defaultValue)
45
+ const value = dlv(config.theme, pathSegments, defaultValue)
45
46
 
46
47
  if (value === undefined) {
47
48
  let error = `'${pathString}' does not exist in your theme config.`
@@ -173,12 +174,14 @@ export default function ({ tailwindConfig: config }) {
173
174
  },
174
175
  screen: (node, screen) => {
175
176
  screen = screen.replace(/^['"]+/g, '').replace(/['"]+$/g, '')
177
+ let screens = normalizeScreens(config.theme.screens)
178
+ let screenDefinition = screens.find(({ name }) => name === screen)
176
179
 
177
- if (config.theme.screens[screen] === undefined) {
180
+ if (!screenDefinition) {
178
181
  throw node.error(`The '${screen}' screen does not exist in your theme.`)
179
182
  }
180
183
 
181
- return buildMediaQuery(config.theme.screens[screen])
184
+ return buildMediaQuery(screenDefinition)
182
185
  },
183
186
  }
184
187
  return (root) => {
@@ -1,8 +1,35 @@
1
1
  import postcss from 'postcss'
2
+ import parser from 'postcss-selector-parser'
3
+
2
4
  import { resolveMatches } from './generateRules'
3
5
  import bigSign from '../util/bigSign'
4
6
  import escapeClassName from '../util/escapeClassName'
5
7
 
8
+ function extractClasses(node) {
9
+ let classes = new Set()
10
+ let container = postcss.root({ nodes: [node.clone()] })
11
+
12
+ container.walkRules((rule) => {
13
+ parser((selectors) => {
14
+ selectors.walkClasses((classSelector) => {
15
+ classes.add(classSelector.value)
16
+ })
17
+ }).processSync(rule.selector)
18
+ })
19
+
20
+ return Array.from(classes)
21
+ }
22
+
23
+ function extractBaseCandidates(candidates, separator) {
24
+ let baseClasses = new Set()
25
+
26
+ for (let candidate of candidates) {
27
+ baseClasses.add(candidate.split(separator).pop())
28
+ }
29
+
30
+ return Array.from(baseClasses)
31
+ }
32
+
6
33
  function prefix(context, selector) {
7
34
  let prefix = context.tailwindConfig.prefix
8
35
  return typeof prefix === 'function' ? prefix(selector) : prefix + selector
@@ -45,47 +72,6 @@ function extractApplyCandidates(params) {
45
72
  return [candidates, false]
46
73
  }
47
74
 
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
75
  function processApply(root, context) {
90
76
  let applyCandidates = new Set()
91
77
 
@@ -129,10 +115,10 @@ function processApply(root, context) {
129
115
  // TODO: Should we use postcss-selector-parser for this instead?
130
116
  function replaceSelector(selector, utilitySelectors, candidate) {
131
117
  let needle = `.${escapeClassName(candidate)}`
132
- let utilitySelectorsList = utilitySelectors.split(/\s*,\s*/g)
118
+ let utilitySelectorsList = utilitySelectors.split(/\s*\,(?![^(]*\))\s*/g)
133
119
 
134
120
  return selector
135
- .split(/\s*,\s*/g)
121
+ .split(/\s*\,(?![^(]*\))\s*/g)
136
122
  .map((s) => {
137
123
  let replaced = []
138
124
 
@@ -197,12 +183,84 @@ function processApply(root, context) {
197
183
 
198
184
  for (let [applyCandidate, important, rules] of candidates) {
199
185
  for (let [meta, node] of rules) {
186
+ let parentClasses = extractClasses(parent)
187
+ let nodeClasses = extractClasses(node)
188
+
189
+ // Add base utility classes from the @apply node to the list of
190
+ // classes to check whether it intersects and therefore results in a
191
+ // circular dependency or not.
192
+ //
193
+ // E.g.:
194
+ // .foo {
195
+ // @apply hover:a; // This applies "a" but with a modifier
196
+ // }
197
+ //
198
+ // We only have to do that with base classes of the `node`, not of the `parent`
199
+ // E.g.:
200
+ // .hover\:foo {
201
+ // @apply bar;
202
+ // }
203
+ // .bar {
204
+ // @apply foo;
205
+ // }
206
+ //
207
+ // This should not result in a circular dependency because we are
208
+ // just applying `.foo` and the rule above is `.hover\:foo` which is
209
+ // unrelated. However, if we were to apply `hover:foo` then we _did_
210
+ // have to include this one.
211
+ nodeClasses = nodeClasses.concat(
212
+ extractBaseCandidates(nodeClasses, context.tailwindConfig.separator)
213
+ )
214
+
215
+ let intersects = parentClasses.some((selector) => nodeClasses.includes(selector))
216
+ if (intersects) {
217
+ throw node.error(
218
+ `You cannot \`@apply\` the \`${applyCandidate}\` utility here because it creates a circular dependency.`
219
+ )
220
+ }
221
+
200
222
  let root = postcss.root({ nodes: [node.clone()] })
201
223
  let canRewriteSelector =
202
224
  node.type !== 'atrule' || (node.type === 'atrule' && node.name !== 'keyframes')
203
225
 
204
226
  if (canRewriteSelector) {
205
227
  root.walkRules((rule) => {
228
+ // Let's imagine you have the following structure:
229
+ //
230
+ // .foo {
231
+ // @apply bar;
232
+ // }
233
+ //
234
+ // @supports (a: b) {
235
+ // .bar {
236
+ // color: blue
237
+ // }
238
+ //
239
+ // .something-unrelated {}
240
+ // }
241
+ //
242
+ // In this case we want to apply `.bar` but it happens to be in
243
+ // an atrule node. We clone that node instead of the nested one
244
+ // because we still want that @supports rule to be there once we
245
+ // applied everything.
246
+ //
247
+ // However it happens to be that the `.something-unrelated` is
248
+ // also in that same shared @supports atrule. This is not good,
249
+ // and this should not be there. The good part is that this is
250
+ // a clone already and it can be safely removed. The question is
251
+ // how do we know we can remove it. Basically what we can do is
252
+ // match it against the applyCandidate that you want to apply. If
253
+ // it doesn't match the we can safely delete it.
254
+ //
255
+ // If we didn't do this, then the `replaceSelector` function
256
+ // would have replaced this with something that didn't exist and
257
+ // therefore it removed the selector altogether. In this specific
258
+ // case it would result in `{}` instead of `.something-unrelated {}`
259
+ if (!extractClasses(rule).some((candidate) => candidate === applyCandidate)) {
260
+ rule.remove()
261
+ return
262
+ }
263
+
206
264
  rule.selector = replaceSelector(parent.selector, rule.selector, applyCandidate)
207
265
 
208
266
  rule.walkDecls((d) => {
@@ -223,7 +281,6 @@ function processApply(root, context) {
223
281
  // Inject the rules, sorted, correctly
224
282
  let nodes = siblings.sort(([a], [z]) => bigSign(a.sort - z.sort)).map((s) => s[1])
225
283
 
226
- // console.log(parent)
227
284
  // `parent` refers to the node at `.abc` in: .abc { @apply mt-2 }
228
285
  parent.after(nodes)
229
286
  }
@@ -245,7 +302,6 @@ function processApply(root, context) {
245
302
 
246
303
  export default function expandApplyAtRules(context) {
247
304
  return (root) => {
248
- partitionApplyParents(root)
249
305
  processApply(root, context)
250
306
  }
251
307
  }
@@ -2,30 +2,14 @@ import LRU from 'quick-lru'
2
2
  import * as sharedState from './sharedState'
3
3
  import { generateRules } from './generateRules'
4
4
  import bigSign from '../util/bigSign'
5
+ import log from '../util/log'
5
6
  import cloneNodes from '../util/cloneNodes'
7
+ import { defaultExtractor } from './defaultExtractor'
6
8
 
7
9
  let env = sharedState.env
8
10
 
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
11
  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
- },
12
+ DEFAULT: defaultExtractor,
29
13
  }
30
14
 
31
15
  const builtInTransformers = {
@@ -95,6 +79,7 @@ function buildStylesheet(rules, context) {
95
79
 
96
80
  let returnValue = {
97
81
  base: new Set(),
82
+ defaults: new Set(),
98
83
  components: new Set(),
99
84
  utilities: new Set(),
100
85
  variants: new Set(),
@@ -121,6 +106,11 @@ function buildStylesheet(rules, context) {
121
106
  continue
122
107
  }
123
108
 
109
+ if (sort & context.layerOrder.defaults) {
110
+ returnValue.defaults.add(rule)
111
+ continue
112
+ }
113
+
124
114
  if (sort & context.layerOrder.components) {
125
115
  returnValue.components.add(rule)
126
116
  continue
@@ -149,13 +139,15 @@ export default function expandTailwindAtRules(context) {
149
139
  variants: null,
150
140
  }
151
141
 
152
- // Make sure this file contains Tailwind directives. If not, we can save
153
- // a lot of work and bail early. Also we don't have to register our touch
154
- // file as a dependency since the output of this CSS does not depend on
155
- // the source of any templates. Think Vue <style> blocks for example.
156
- root.walkAtRules('tailwind', (rule) => {
157
- if (Object.keys(layerNodes).includes(rule.params)) {
158
- layerNodes[rule.params] = rule
142
+ root.walkAtRules((rule) => {
143
+ // Make sure this file contains Tailwind directives. If not, we can save
144
+ // a lot of work and bail early. Also we don't have to register our touch
145
+ // file as a dependency since the output of this CSS does not depend on
146
+ // the source of any templates. Think Vue <style> blocks for example.
147
+ if (rule.name === 'tailwind') {
148
+ if (Object.keys(layerNodes).includes(rule.params)) {
149
+ layerNodes[rule.params] = rule
150
+ }
159
151
  }
160
152
  })
161
153
 
@@ -177,6 +169,8 @@ export default function expandTailwindAtRules(context) {
177
169
  getClassCandidates(transformer(content), extractor, candidates, seen)
178
170
  }
179
171
 
172
+ env.DEBUG && console.timeEnd('Reading changed files')
173
+
180
174
  // ---
181
175
 
182
176
  // Generate the actual CSS
@@ -198,6 +192,7 @@ export default function expandTailwindAtRules(context) {
198
192
  env.DEBUG && console.timeEnd('Build stylesheet')
199
193
 
200
194
  let {
195
+ defaults: defaultNodes,
201
196
  base: baseNodes,
202
197
  components: componentNodes,
203
198
  utilities: utilityNodes,
@@ -209,7 +204,10 @@ export default function expandTailwindAtRules(context) {
209
204
  // Replace any Tailwind directives with generated CSS
210
205
 
211
206
  if (layerNodes.base) {
212
- layerNodes.base.before(cloneNodes([...baseNodes], layerNodes.base.source))
207
+ layerNodes.base.before(cloneNodes([...baseNodes, ...defaultNodes], layerNodes.base.source))
208
+ }
209
+
210
+ if (layerNodes.base) {
213
211
  layerNodes.base.remove()
214
212
  }
215
213
 
@@ -230,6 +228,14 @@ export default function expandTailwindAtRules(context) {
230
228
  root.append(cloneNodes([...screenNodes], root.source))
231
229
  }
232
230
 
231
+ // If we've got a utility layer and no utilities are generated there's likely something wrong
232
+ // TODO: Detect utility variants only
233
+ if (layerNodes.utilities && utilityNodes.size === 0 && screenNodes.size === 0) {
234
+ log.warn('content-problems', [
235
+ 'No utilities were generated there is likely a problem with the `content` key in the tailwind config. For more information see the documentation: https://tailwindcss.com/docs/content-configuration',
236
+ ])
237
+ }
238
+
233
239
  // ---
234
240
 
235
241
  if (env.DEBUG) {