tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce

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 (148) hide show
  1. package/CHANGELOG.md +380 -1
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  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 +3 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli-peer-dependencies.js +10 -5
  11. package/lib/cli.js +311 -213
  12. package/lib/constants.js +9 -9
  13. package/lib/corePluginList.js +11 -1
  14. package/lib/corePlugins.js +1895 -1773
  15. package/lib/css/preflight.css +19 -13
  16. package/lib/featureFlags.js +22 -16
  17. package/lib/index.js +17 -8
  18. package/lib/lib/cacheInvalidation.js +69 -0
  19. package/lib/lib/collapseAdjacentRules.js +30 -14
  20. package/lib/lib/collapseDuplicateDeclarations.js +80 -0
  21. package/lib/lib/defaultExtractor.js +187 -0
  22. package/lib/lib/detectNesting.js +17 -2
  23. package/lib/lib/evaluateTailwindFunctions.js +40 -24
  24. package/lib/lib/expandApplyAtRules.js +414 -157
  25. package/lib/lib/expandTailwindAtRules.js +156 -151
  26. package/lib/lib/generateRules.js +402 -68
  27. package/lib/lib/getModuleDependencies.js +14 -14
  28. package/lib/lib/normalizeTailwindDirectives.js +45 -36
  29. package/lib/lib/partitionApplyAtRules.js +53 -0
  30. package/lib/lib/regex.js +53 -0
  31. package/lib/lib/resolveDefaultsAtRules.js +105 -90
  32. package/lib/lib/setupContextUtils.js +416 -291
  33. package/lib/lib/setupTrackingContext.js +60 -56
  34. package/lib/lib/sharedState.js +38 -15
  35. package/lib/lib/substituteScreenAtRules.js +9 -6
  36. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  37. package/lib/postcss-plugins/nesting/index.js +17 -0
  38. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  39. package/lib/processTailwindFeatures.js +21 -9
  40. package/lib/public/colors.js +244 -248
  41. package/lib/public/resolve-config.js +5 -5
  42. package/lib/util/buildMediaQuery.js +13 -24
  43. package/lib/util/cloneDeep.js +1 -1
  44. package/lib/util/cloneNodes.js +12 -1
  45. package/lib/util/color.js +43 -32
  46. package/lib/util/createPlugin.js +1 -2
  47. package/lib/util/createUtilityPlugin.js +13 -17
  48. package/lib/util/dataTypes.js +114 -74
  49. package/lib/util/defaults.js +6 -0
  50. package/lib/util/escapeClassName.js +5 -5
  51. package/lib/util/escapeCommas.js +1 -1
  52. package/lib/util/flattenColorPalette.js +2 -4
  53. package/lib/util/formatVariantSelector.js +194 -0
  54. package/lib/util/getAllConfigs.js +13 -5
  55. package/lib/util/hashConfig.js +5 -5
  56. package/lib/util/isKeyframeRule.js +1 -1
  57. package/lib/util/isPlainObject.js +1 -1
  58. package/lib/util/isValidArbitraryValue.js +64 -0
  59. package/lib/util/log.js +35 -19
  60. package/lib/util/nameClass.js +7 -6
  61. package/lib/util/negateValue.js +5 -3
  62. package/lib/util/normalizeConfig.js +233 -0
  63. package/lib/util/normalizeScreens.js +59 -0
  64. package/lib/util/parseAnimationValue.js +56 -56
  65. package/lib/util/parseBoxShadowValue.js +76 -0
  66. package/lib/util/parseDependency.js +32 -32
  67. package/lib/util/parseObjectStyles.js +6 -6
  68. package/lib/util/pluginUtils.js +67 -170
  69. package/lib/util/prefixSelector.js +4 -7
  70. package/lib/util/resolveConfig.js +123 -133
  71. package/lib/util/resolveConfigPath.js +17 -18
  72. package/lib/util/responsive.js +6 -6
  73. package/lib/util/splitAtTopLevelOnly.js +72 -0
  74. package/lib/util/toColorValue.js +1 -2
  75. package/lib/util/toPath.js +6 -1
  76. package/lib/util/transformThemeValue.js +42 -34
  77. package/lib/util/validateConfig.js +21 -0
  78. package/lib/util/withAlphaVariable.js +19 -19
  79. package/nesting/index.js +2 -12
  80. package/package.json +41 -42
  81. package/peers/index.js +11539 -10859
  82. package/plugin.d.ts +11 -0
  83. package/plugin.js +2 -1
  84. package/resolveConfig.js +2 -1
  85. package/scripts/create-plugin-list.js +2 -2
  86. package/scripts/generate-types.js +52 -0
  87. package/src/cli-peer-dependencies.js +7 -1
  88. package/src/cli.js +174 -41
  89. package/src/corePluginList.js +1 -1
  90. package/src/corePlugins.js +641 -596
  91. package/src/css/preflight.css +19 -13
  92. package/src/featureFlags.js +16 -10
  93. package/src/index.js +14 -6
  94. package/src/lib/cacheInvalidation.js +52 -0
  95. package/src/lib/collapseAdjacentRules.js +21 -2
  96. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  97. package/src/lib/defaultExtractor.js +192 -0
  98. package/src/lib/detectNesting.js +22 -3
  99. package/src/lib/evaluateTailwindFunctions.js +24 -7
  100. package/src/lib/expandApplyAtRules.js +442 -154
  101. package/src/lib/expandTailwindAtRules.js +91 -65
  102. package/src/lib/generateRules.js +409 -43
  103. package/src/lib/normalizeTailwindDirectives.js +10 -3
  104. package/src/lib/partitionApplyAtRules.js +52 -0
  105. package/src/lib/regex.js +74 -0
  106. package/src/lib/resolveDefaultsAtRules.js +74 -53
  107. package/src/lib/setupContextUtils.js +388 -208
  108. package/src/lib/setupTrackingContext.js +15 -12
  109. package/src/lib/sharedState.js +42 -7
  110. package/src/lib/substituteScreenAtRules.js +6 -3
  111. package/src/postcss-plugins/nesting/README.md +42 -0
  112. package/src/postcss-plugins/nesting/index.js +13 -0
  113. package/src/postcss-plugins/nesting/plugin.js +80 -0
  114. package/src/processTailwindFeatures.js +17 -2
  115. package/src/public/colors.js +4 -9
  116. package/src/util/buildMediaQuery.js +14 -18
  117. package/src/util/cloneNodes.js +14 -1
  118. package/src/util/color.js +31 -14
  119. package/src/util/createUtilityPlugin.js +2 -2
  120. package/src/util/dataTypes.js +56 -16
  121. package/src/util/defaults.js +6 -0
  122. package/src/util/formatVariantSelector.js +213 -0
  123. package/src/util/getAllConfigs.js +7 -0
  124. package/src/util/isValidArbitraryValue.js +61 -0
  125. package/src/util/log.js +23 -22
  126. package/src/util/nameClass.js +2 -2
  127. package/src/util/negateValue.js +4 -2
  128. package/src/util/normalizeConfig.js +262 -0
  129. package/src/util/normalizeScreens.js +45 -0
  130. package/src/util/parseBoxShadowValue.js +72 -0
  131. package/src/util/pluginUtils.js +51 -147
  132. package/src/util/prefixSelector.js +7 -8
  133. package/src/util/resolveConfig.js +108 -79
  134. package/src/util/splitAtTopLevelOnly.js +71 -0
  135. package/src/util/toPath.js +23 -1
  136. package/src/util/transformThemeValue.js +24 -7
  137. package/src/util/validateConfig.js +13 -0
  138. package/stubs/defaultConfig.stub.js +157 -94
  139. package/stubs/simpleConfig.stub.js +0 -1
  140. package/types/config.d.ts +325 -0
  141. package/types/generated/.gitkeep +0 -0
  142. package/types/generated/colors.d.ts +276 -0
  143. package/types/generated/corePluginList.d.ts +1 -0
  144. package/types/index.d.ts +1 -0
  145. package/types.d.ts +1 -0
  146. package/lib/lib/setupWatchingContext.js +0 -284
  147. package/nesting/plugin.js +0 -41
  148. package/src/lib/setupWatchingContext.js +0 -306
@@ -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
  /*
@@ -155,6 +160,7 @@ select,
155
160
  textarea {
156
161
  font-family: inherit; /* 1 */
157
162
  font-size: 100%; /* 1 */
163
+ font-weight: inherit; /* 1 */
158
164
  line-height: inherit; /* 1 */
159
165
  color: inherit; /* 1 */
160
166
  margin: 0; /* 2 */
@@ -283,7 +289,8 @@ legend {
283
289
  }
284
290
 
285
291
  ol,
286
- ul {
292
+ ul,
293
+ menu {
287
294
  list-style: none;
288
295
  margin: 0;
289
296
  padding: 0;
@@ -304,7 +311,7 @@ textarea {
304
311
 
305
312
  input::placeholder,
306
313
  textarea::placeholder {
307
- opacity: 1; /* 1 */
314
+ opacity: 1; /* 1 */
308
315
  color: theme('colors.gray.400', #9ca3af); /* 2 */
309
316
  }
310
317
 
@@ -317,6 +324,13 @@ button,
317
324
  cursor: pointer;
318
325
  }
319
326
 
327
+ /*
328
+ Make sure disabled buttons don't get the pointer cursor.
329
+ */
330
+ :disabled {
331
+ cursor: default;
332
+ }
333
+
320
334
  /*
321
335
  1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
322
336
  2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
@@ -344,11 +358,3 @@ video {
344
358
  max-width: 100%;
345
359
  height: auto;
346
360
  }
347
-
348
- /*
349
- Ensure the default browser behavior of the `hidden` attribute.
350
- */
351
-
352
- [hidden] {
353
- display: none;
354
- }
@@ -1,18 +1,24 @@
1
- import chalk from 'chalk'
1
+ import colors from 'picocolors'
2
2
  import log from './util/log'
3
3
 
4
- const featureFlags = {
5
- future: [],
6
- experimental: ['optimizeUniversalDefaults'],
4
+ let defaults = {
5
+ optimizeUniversalDefaults: false,
6
+ }
7
+
8
+ let featureFlags = {
9
+ future: ['hoverOnlyWhenSupported', 'respectDefaultRingColorOpacity'],
10
+ experimental: ['optimizeUniversalDefaults', 'variantGrouping'],
7
11
  }
8
12
 
9
13
  export function flagEnabled(config, flag) {
10
14
  if (featureFlags.future.includes(flag)) {
11
- return config.future === 'all' || (config?.future?.[flag] ?? false)
15
+ return config.future === 'all' || (config?.future?.[flag] ?? defaults[flag] ?? false)
12
16
  }
13
17
 
14
18
  if (featureFlags.experimental.includes(flag)) {
15
- return config.experimental === 'all' || (config?.experimental?.[flag] ?? false)
19
+ return (
20
+ config.experimental === 'all' || (config?.experimental?.[flag] ?? defaults[flag] ?? false)
21
+ )
16
22
  }
17
23
 
18
24
  return false
@@ -34,13 +40,13 @@ export function issueFlagNotices(config) {
34
40
  }
35
41
 
36
42
  if (experimentalFlagsEnabled(config).length > 0) {
37
- const changes = experimentalFlagsEnabled(config)
38
- .map((s) => chalk.yellow(s))
43
+ let changes = experimentalFlagsEnabled(config)
44
+ .map((s) => colors.yellow(s))
39
45
  .join(', ')
40
46
 
41
- log.warn([
47
+ log.warn('experimental-flags-enabled', [
42
48
  `You have enabled experimental features: ${changes}`,
43
- 'Experimental features are not covered by semver, may introduce breaking changes, and can change at any time.',
49
+ 'Experimental features in Tailwind CSS are not covered by semver, may introduce breaking changes, and can change at any time.',
44
50
  ])
45
51
  }
46
52
  }
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,21 @@ 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)
16
+ let context = setupTrackingContext(configOrPath)
21
17
 
22
- processTailwindFeatures(setupContext)(root, result)
18
+ if (root.type === 'document') {
19
+ let roots = root.nodes.filter((node) => node.type === 'root')
20
+
21
+ for (const root of roots) {
22
+ if (root.type === 'root') {
23
+ processTailwindFeatures(context)(root, result)
24
+ }
25
+ }
26
+
27
+ return
28
+ }
29
+
30
+ processTailwindFeatures(context)(root, result)
23
31
  },
24
32
  env.DEBUG &&
25
33
  function (root) {
@@ -0,0 +1,52 @@
1
+ import crypto from 'crypto'
2
+ import * as sharedState from './sharedState'
3
+
4
+ /**
5
+ * Calculate the hash of a string.
6
+ *
7
+ * This doesn't need to be cryptographically secure or
8
+ * anything like that since it's used only to detect
9
+ * when the CSS changes to invalidate the context.
10
+ *
11
+ * This is wrapped in a try/catch because it's really dependent
12
+ * on how Node itself is build and the environment and OpenSSL
13
+ * version / build that is installed on the user's machine.
14
+ *
15
+ * Based on the environment this can just outright fail.
16
+ *
17
+ * See https://github.com/nodejs/node/issues/40455
18
+ *
19
+ * @param {string} str
20
+ */
21
+ function getHash(str) {
22
+ try {
23
+ return crypto.createHash('md5').update(str, 'utf-8').digest('binary')
24
+ } catch (err) {
25
+ return ''
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Determine if the CSS tree is different from the
31
+ * previous version for the given `sourcePath`.
32
+ *
33
+ * @param {string} sourcePath
34
+ * @param {import('postcss').Node} root
35
+ */
36
+ export function hasContentChanged(sourcePath, root) {
37
+ let css = root.toString()
38
+
39
+ // We only care about files with @tailwind directives
40
+ // Other files use an existing context
41
+ if (!css.includes('@tailwind')) {
42
+ return false
43
+ }
44
+
45
+ let existingHash = sharedState.sourceHashMap.get(sourcePath)
46
+ let rootHash = getHash(css)
47
+ let didChange = existingHash !== rootHash
48
+
49
+ sharedState.sourceHashMap.set(sourcePath, rootHash)
50
+
51
+ return didChange
52
+ }
@@ -5,7 +5,7 @@ let comparisonMap = {
5
5
  let types = new Set(Object.keys(comparisonMap))
6
6
 
7
7
  export default function collapseAdjacentRules() {
8
- return (root) => {
8
+ function collapseRulesIn(root) {
9
9
  let currentRule = null
10
10
  root.each((node) => {
11
11
  if (!types.has(node.type)) {
@@ -29,11 +29,30 @@ export default function collapseAdjacentRules() {
29
29
  (currentRule[property] ?? '').replace(/\s+/g, ' ')
30
30
  )
31
31
  ) {
32
- currentRule.append(node.nodes)
32
+ // An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
33
+ if (node.nodes) {
34
+ currentRule.append(node.nodes)
35
+ }
36
+
33
37
  node.remove()
34
38
  } else {
35
39
  currentRule = node
36
40
  }
37
41
  })
42
+
43
+ // After we've collapsed adjacent rules & at-rules, we need to collapse
44
+ // adjacent rules & at-rules that are children of at-rules.
45
+ // We do not care about nesting rules because Tailwind CSS
46
+ // explicitly does not handle rule nesting on its own as
47
+ // the user is expected to use a nesting plugin
48
+ root.each((node) => {
49
+ if (node.type === 'atrule') {
50
+ collapseRulesIn(node)
51
+ }
52
+ })
53
+ }
54
+
55
+ return (root) => {
56
+ collapseRulesIn(root)
38
57
  }
39
58
  }
@@ -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,192 @@
1
+ import { flagEnabled } from '../featureFlags.js'
2
+ import * as regex from './regex'
3
+
4
+ export function defaultExtractor(context) {
5
+ let patterns = Array.from(buildRegExps(context))
6
+
7
+ /**
8
+ * @param {string} content
9
+ */
10
+ return (content) => {
11
+ /** @type {(string|string)[]} */
12
+ let results = []
13
+
14
+ for (let pattern of patterns) {
15
+ results.push(...(content.match(pattern) ?? []))
16
+ }
17
+
18
+ return results.filter((v) => v !== undefined).map(clipAtBalancedParens)
19
+ }
20
+ }
21
+
22
+ function* buildRegExps(context) {
23
+ let separator = context.tailwindConfig.separator
24
+ let variantGroupingEnabled = flagEnabled(context.tailwindConfig, 'variantGrouping')
25
+
26
+ let utility = regex.any([
27
+ // Arbitrary properties
28
+ /\[[^\s:'"]+:[^\s\]]+\]/,
29
+
30
+ // Utilities
31
+ regex.pattern([
32
+ // Utility Name / Group Name
33
+ /-?(?:\w+)/,
34
+
35
+ // Normal/Arbitrary values
36
+ regex.optional(
37
+ regex.any([
38
+ regex.pattern([
39
+ // Arbitrary values
40
+ /-\[[^\s:]+\]/,
41
+
42
+ // Not immediately followed by an `{[(`
43
+ /(?![{([]])/,
44
+
45
+ // optionally followed by an opacity modifier
46
+ /(?:\/[^\s'"\\$]*)?/,
47
+ ]),
48
+
49
+ regex.pattern([
50
+ // Arbitrary values
51
+ /-\[[^\s]+\]/,
52
+
53
+ // Not immediately followed by an `{[(`
54
+ /(?![{([]])/,
55
+
56
+ // optionally followed by an opacity modifier
57
+ /(?:\/[^\s'"\\$]*)?/,
58
+ ]),
59
+
60
+ // Normal values w/o quotes — may include an opacity modifier
61
+ /[-\/][^\s'"\\$={]*/,
62
+ ])
63
+ ),
64
+ ]),
65
+ ])
66
+
67
+ yield regex.pattern([
68
+ // Variants
69
+ '((?=((',
70
+ regex.any(
71
+ [
72
+ regex.pattern([/([^\s"'\[\\]+-)?\[[^\s"'\\]+\]/, separator]),
73
+ regex.pattern([/[^\s"'\[\\]+/, separator]),
74
+ ],
75
+ true
76
+ ),
77
+ ')+))\\2)?',
78
+
79
+ // Important (optional)
80
+ /!?/,
81
+
82
+ variantGroupingEnabled
83
+ ? regex.any([
84
+ // Or any of those things but grouped separated by commas
85
+ regex.pattern([/\(/, utility, regex.zeroOrMore([/,/, utility]), /\)/]),
86
+
87
+ // Arbitrary properties, constrained utilities, arbitrary values, etc…
88
+ utility,
89
+ ])
90
+ : utility,
91
+ ])
92
+
93
+ // 5. Inner matches
94
+ // yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
95
+ }
96
+
97
+ // We want to capture any "special" characters
98
+ // AND the characters immediately following them (if there is one)
99
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g
100
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/
101
+
102
+ /**
103
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
104
+ * Used for arbitrary values only
105
+ *
106
+ * We will go past the end of the balanced parens until we find a non-class character
107
+ *
108
+ * Depth matching behavior:
109
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
110
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
111
+ * 1 2 3 4 34 3 210 END
112
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
113
+ *
114
+ * @param {string} input
115
+ */
116
+ function clipAtBalancedParens(input) {
117
+ // We are care about this for arbitrary values
118
+ if (!input.includes('-[')) {
119
+ return input
120
+ }
121
+
122
+ let depth = 0
123
+ let openStringTypes = []
124
+
125
+ // Find all parens, brackets, quotes, etc
126
+ // Stop when we end at a balanced pair
127
+ // This is naive and will treat mismatched parens as balanced
128
+ // This shouldn't be a problem in practice though
129
+ let matches = input.matchAll(SPECIALS)
130
+
131
+ // We can't use lookbehind assertions because we have to support Safari
132
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
133
+ matches = Array.from(matches).flatMap((match) => {
134
+ const [, ...groups] = match
135
+
136
+ return groups.map((group, idx) =>
137
+ Object.assign([], match, {
138
+ index: match.index + idx,
139
+ 0: group,
140
+ })
141
+ )
142
+ })
143
+
144
+ for (let match of matches) {
145
+ let char = match[0]
146
+ let inStringType = openStringTypes[openStringTypes.length - 1]
147
+
148
+ if (char === inStringType) {
149
+ openStringTypes.pop()
150
+ } else if (char === "'" || char === '"' || char === '`') {
151
+ openStringTypes.push(char)
152
+ }
153
+
154
+ if (inStringType) {
155
+ continue
156
+ } else if (char === '[') {
157
+ depth++
158
+ continue
159
+ } else if (char === ']') {
160
+ depth--
161
+ continue
162
+ }
163
+
164
+ // We've gone one character past the point where we should stop
165
+ // This means that there was an extra closing `]`
166
+ // We'll clip to just before it
167
+ if (depth < 0) {
168
+ return input.substring(0, match.index)
169
+ }
170
+
171
+ // We've finished balancing the brackets but there still may be characters that can be included
172
+ // For example in the class `text-[#336699]/[.35]`
173
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
174
+
175
+ // If we're at zero and encounter a non-class character then we clip the class there
176
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
177
+ return input.substring(0, match.index)
178
+ }
179
+ }
180
+
181
+ return input
182
+ }
183
+
184
+ // Regular utilities
185
+ // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
186
+
187
+ // Arbitrary values
188
+ // {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
189
+ // arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
190
+
191
+ // Arbitrary properties
192
+ // {{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,8 +2,10 @@ 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'
8
+ import { withAlphaValue } from '../util/withAlphaVariable'
7
9
 
8
10
  function isObject(input) {
9
11
  return typeof input === 'object' && input !== null
@@ -36,12 +38,12 @@ function listKeys(obj) {
36
38
  return list(Object.keys(obj))
37
39
  }
38
40
 
39
- function validatePath(config, path, defaultValue) {
41
+ function validatePath(config, path, defaultValue, themeOpts = {}) {
40
42
  const pathString = Array.isArray(path)
41
43
  ? pathToString(path)
42
44
  : path.replace(/^['"]+/g, '').replace(/['"]+$/g, '')
43
45
  const pathSegments = Array.isArray(path) ? path : toPath(pathString)
44
- const value = dlv(config.theme, pathString, defaultValue)
46
+ const value = dlv(config.theme, pathSegments, defaultValue)
45
47
 
46
48
  if (value === undefined) {
47
49
  let error = `'${pathString}' does not exist in your theme config.`
@@ -113,7 +115,7 @@ function validatePath(config, path, defaultValue) {
113
115
 
114
116
  return {
115
117
  isValid: true,
116
- value: transformThemeValue(themeSection)(value),
118
+ value: transformThemeValue(themeSection)(value, themeOpts),
117
119
  }
118
120
  }
119
121
 
@@ -159,26 +161,41 @@ let nodeTypePropertyMap = {
159
161
  export default function ({ tailwindConfig: config }) {
160
162
  let functions = {
161
163
  theme: (node, path, ...defaultValue) => {
162
- const { isValid, value, error } = validatePath(
164
+ let matches = path.match(/^([^\/\s]+)(?:\s*\/\s*([^\/\s]+))$/)
165
+ let alpha = undefined
166
+
167
+ if (matches) {
168
+ path = matches[1]
169
+ alpha = matches[2]
170
+ }
171
+
172
+ let { isValid, value, error } = validatePath(
163
173
  config,
164
174
  path,
165
- defaultValue.length ? defaultValue : undefined
175
+ defaultValue.length ? defaultValue : undefined,
176
+ { opacityValue: alpha }
166
177
  )
167
178
 
168
179
  if (!isValid) {
169
180
  throw node.error(error)
170
181
  }
171
182
 
183
+ if (alpha !== undefined) {
184
+ value = withAlphaValue(value, alpha, value)
185
+ }
186
+
172
187
  return value
173
188
  },
174
189
  screen: (node, screen) => {
175
190
  screen = screen.replace(/^['"]+/g, '').replace(/['"]+$/g, '')
191
+ let screens = normalizeScreens(config.theme.screens)
192
+ let screenDefinition = screens.find(({ name }) => name === screen)
176
193
 
177
- if (config.theme.screens[screen] === undefined) {
194
+ if (!screenDefinition) {
178
195
  throw node.error(`The '${screen}' screen does not exist in your theme.`)
179
196
  }
180
197
 
181
- return buildMediaQuery(config.theme.screens[screen])
198
+ return buildMediaQuery(screenDefinition)
182
199
  },
183
200
  }
184
201
  return (root) => {