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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/CHANGELOG.md +526 -2
  2. package/LICENSE +1 -2
  3. package/README.md +13 -6
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +4 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli/build/deps.js +54 -0
  11. package/lib/cli/build/index.js +44 -0
  12. package/lib/cli/build/plugin.js +335 -0
  13. package/lib/cli/build/utils.js +78 -0
  14. package/lib/cli/build/watching.js +113 -0
  15. package/lib/cli/help/index.js +71 -0
  16. package/lib/cli/index.js +18 -0
  17. package/lib/cli/init/index.js +46 -0
  18. package/lib/cli/shared.js +12 -0
  19. package/lib/cli-peer-dependencies.js +20 -7
  20. package/lib/cli.js +91 -569
  21. package/lib/constants.js +27 -20
  22. package/lib/corePluginList.js +16 -4
  23. package/lib/corePlugins.js +2247 -1873
  24. package/lib/css/preflight.css +20 -9
  25. package/lib/featureFlags.js +37 -23
  26. package/lib/index.js +28 -12
  27. package/lib/lib/cacheInvalidation.js +90 -0
  28. package/lib/lib/collapseAdjacentRules.js +27 -9
  29. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  30. package/lib/lib/content.js +167 -0
  31. package/lib/lib/defaultExtractor.js +236 -0
  32. package/lib/lib/detectNesting.js +21 -3
  33. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  34. package/lib/lib/expandApplyAtRules.js +439 -160
  35. package/lib/lib/expandTailwindAtRules.js +141 -151
  36. package/lib/lib/findAtConfigPath.js +44 -0
  37. package/lib/lib/generateRules.js +572 -105
  38. package/lib/lib/getModuleDependencies.js +11 -8
  39. package/lib/lib/normalizeTailwindDirectives.js +45 -33
  40. package/lib/lib/offsets.js +217 -0
  41. package/lib/lib/partitionApplyAtRules.js +56 -0
  42. package/lib/lib/regex.js +60 -0
  43. package/lib/lib/resolveDefaultsAtRules.js +114 -81
  44. package/lib/lib/setupContextUtils.js +777 -385
  45. package/lib/lib/setupTrackingContext.js +43 -71
  46. package/lib/lib/sharedState.js +49 -18
  47. package/lib/lib/substituteScreenAtRules.js +13 -8
  48. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  49. package/lib/postcss-plugins/nesting/index.js +19 -0
  50. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  51. package/lib/processTailwindFeatures.js +36 -21
  52. package/lib/public/colors.js +250 -252
  53. package/lib/public/create-plugin.js +6 -4
  54. package/lib/public/default-config.js +7 -5
  55. package/lib/public/default-theme.js +7 -5
  56. package/lib/public/resolve-config.js +8 -5
  57. package/lib/util/bigSign.js +4 -1
  58. package/lib/util/buildMediaQuery.js +18 -24
  59. package/lib/util/cloneDeep.js +7 -6
  60. package/lib/util/cloneNodes.js +21 -3
  61. package/lib/util/color.js +54 -40
  62. package/lib/util/configurePlugins.js +5 -2
  63. package/lib/util/createPlugin.js +6 -6
  64. package/lib/util/createUtilityPlugin.js +11 -13
  65. package/lib/util/dataTypes.js +137 -100
  66. package/lib/util/defaults.js +10 -1
  67. package/lib/util/escapeClassName.js +7 -4
  68. package/lib/util/escapeCommas.js +5 -2
  69. package/lib/util/flattenColorPalette.js +9 -12
  70. package/lib/util/formatVariantSelector.js +285 -0
  71. package/lib/util/getAllConfigs.js +27 -8
  72. package/lib/util/hashConfig.js +6 -3
  73. package/lib/util/isKeyframeRule.js +5 -2
  74. package/lib/util/isPlainObject.js +5 -2
  75. package/lib/util/isValidArbitraryValue.js +72 -0
  76. package/lib/util/log.js +44 -22
  77. package/lib/util/nameClass.js +20 -8
  78. package/lib/util/negateValue.js +23 -6
  79. package/lib/util/normalizeConfig.js +267 -0
  80. package/lib/util/normalizeScreens.js +170 -0
  81. package/lib/util/parseAnimationValue.js +42 -40
  82. package/lib/util/parseBoxShadowValue.js +84 -0
  83. package/lib/util/parseDependency.js +38 -56
  84. package/lib/util/parseGlob.js +34 -0
  85. package/lib/util/parseObjectStyles.js +11 -8
  86. package/lib/util/pluginUtils.js +171 -189
  87. package/lib/util/prefixSelector.js +10 -10
  88. package/lib/util/removeAlphaVariables.js +29 -0
  89. package/lib/util/resolveConfig.js +92 -126
  90. package/lib/util/resolveConfigPath.js +11 -9
  91. package/lib/util/responsive.js +8 -5
  92. package/lib/util/splitAtTopLevelOnly.js +43 -0
  93. package/lib/util/tap.js +4 -1
  94. package/lib/util/toColorValue.js +5 -3
  95. package/lib/util/toPath.js +24 -3
  96. package/lib/util/transformThemeValue.js +49 -31
  97. package/lib/util/validateConfig.js +24 -0
  98. package/lib/util/validateFormalSyntax.js +24 -0
  99. package/lib/util/withAlphaVariable.js +23 -15
  100. package/nesting/index.js +2 -12
  101. package/package.json +48 -46
  102. package/peers/index.js +14817 -12471
  103. package/plugin.d.ts +11 -0
  104. package/plugin.js +2 -1
  105. package/resolveConfig.d.ts +3 -0
  106. package/resolveConfig.js +2 -1
  107. package/scripts/create-plugin-list.js +2 -2
  108. package/scripts/generate-types.js +105 -0
  109. package/scripts/release-channel.js +18 -0
  110. package/scripts/release-notes.js +21 -0
  111. package/scripts/type-utils.js +27 -0
  112. package/src/cli/build/deps.js +56 -0
  113. package/src/cli/build/index.js +45 -0
  114. package/src/cli/build/plugin.js +397 -0
  115. package/src/cli/build/utils.js +76 -0
  116. package/src/cli/build/watching.js +134 -0
  117. package/src/cli/help/index.js +70 -0
  118. package/src/cli/index.js +3 -0
  119. package/src/cli/init/index.js +50 -0
  120. package/src/cli/shared.js +5 -0
  121. package/src/cli-peer-dependencies.js +7 -1
  122. package/src/cli.js +26 -565
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +905 -615
  125. package/src/css/preflight.css +20 -9
  126. package/src/featureFlags.js +26 -10
  127. package/src/index.js +19 -6
  128. package/src/lib/cacheInvalidation.js +52 -0
  129. package/src/lib/collapseAdjacentRules.js +21 -2
  130. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  131. package/src/lib/content.js +205 -0
  132. package/src/lib/defaultExtractor.js +211 -0
  133. package/src/lib/detectNesting.js +22 -3
  134. package/src/lib/evaluateTailwindFunctions.js +84 -10
  135. package/src/lib/expandApplyAtRules.js +488 -153
  136. package/src/lib/expandTailwindAtRules.js +94 -106
  137. package/src/lib/findAtConfigPath.js +50 -0
  138. package/src/lib/generateRules.js +589 -67
  139. package/src/lib/normalizeTailwindDirectives.js +10 -3
  140. package/src/lib/offsets.js +270 -0
  141. package/src/lib/partitionApplyAtRules.js +52 -0
  142. package/src/lib/regex.js +74 -0
  143. package/src/lib/resolveDefaultsAtRules.js +98 -60
  144. package/src/lib/setupContextUtils.js +737 -246
  145. package/src/lib/setupTrackingContext.js +16 -54
  146. package/src/lib/sharedState.js +44 -7
  147. package/src/lib/substituteScreenAtRules.js +6 -3
  148. package/src/postcss-plugins/nesting/README.md +42 -0
  149. package/src/postcss-plugins/nesting/index.js +13 -0
  150. package/src/postcss-plugins/nesting/plugin.js +80 -0
  151. package/src/processTailwindFeatures.js +17 -2
  152. package/src/public/colors.js +4 -9
  153. package/src/util/buildMediaQuery.js +14 -16
  154. package/src/util/cloneNodes.js +19 -2
  155. package/src/util/color.js +31 -14
  156. package/src/util/createUtilityPlugin.js +2 -2
  157. package/src/util/dataTypes.js +57 -21
  158. package/src/util/defaults.js +6 -0
  159. package/src/util/formatVariantSelector.js +319 -0
  160. package/src/util/getAllConfigs.js +19 -0
  161. package/src/util/isValidArbitraryValue.js +61 -0
  162. package/src/util/log.js +23 -22
  163. package/src/util/nameClass.js +6 -2
  164. package/src/util/negateValue.js +14 -4
  165. package/src/util/normalizeConfig.js +282 -0
  166. package/src/util/normalizeScreens.js +140 -0
  167. package/src/util/parseBoxShadowValue.js +72 -0
  168. package/src/util/parseDependency.js +37 -42
  169. package/src/util/parseGlob.js +24 -0
  170. package/src/util/pluginUtils.js +144 -152
  171. package/src/util/prefixSelector.js +7 -8
  172. package/src/util/removeAlphaVariables.js +24 -0
  173. package/src/util/resolveConfig.js +82 -81
  174. package/src/util/splitAtTopLevelOnly.js +45 -0
  175. package/src/util/toPath.js +23 -1
  176. package/src/util/transformThemeValue.js +33 -8
  177. package/src/util/validateConfig.js +13 -0
  178. package/src/util/validateFormalSyntax.js +34 -0
  179. package/src/util/withAlphaVariable.js +1 -1
  180. package/stubs/defaultConfig.stub.js +173 -93
  181. package/stubs/simpleConfig.stub.js +1 -1
  182. package/types/config.d.ts +361 -0
  183. package/types/generated/.gitkeep +0 -0
  184. package/types/generated/colors.d.ts +276 -0
  185. package/types/generated/corePluginList.d.ts +1 -0
  186. package/types/generated/default-theme.d.ts +342 -0
  187. package/types/index.d.ts +7 -0
  188. package/lib/lib/setupWatchingContext.js +0 -284
  189. package/nesting/plugin.js +0 -41
  190. package/src/lib/setupWatchingContext.js +0 -306
@@ -1,21 +1,14 @@
1
1
  import fs from 'fs'
2
- import path from 'path'
3
-
4
- import fastGlob from 'fast-glob'
5
2
  import LRU from 'quick-lru'
6
- import normalizePath from 'normalize-path'
7
3
 
8
4
  import hash from '../util/hashConfig'
9
5
  import getModuleDependencies from '../lib/getModuleDependencies'
10
-
11
6
  import resolveConfig from '../public/resolve-config'
12
-
13
7
  import resolveConfigPath from '../util/resolveConfigPath'
14
-
15
- import { env } from './sharedState'
16
-
17
8
  import { getContext, getFileModifiedMap } from './setupContextUtils'
18
9
  import parseDependency from '../util/parseDependency'
10
+ import { validateConfig } from '../util/validateConfig.js'
11
+ import { parseCandidateFiles, resolvedChangedContent } from './content.js'
19
12
 
20
13
  let configPathCache = new LRU({ maxSize: 100 })
21
14
 
@@ -26,9 +19,7 @@ function getCandidateFiles(context, tailwindConfig) {
26
19
  return candidateFilesCache.get(context)
27
20
  }
28
21
 
29
- let candidateFiles = tailwindConfig.content.content
30
- .filter((item) => typeof item === 'string')
31
- .map((contentPath) => normalizePath(contentPath))
22
+ let candidateFiles = parseCandidateFiles(context, tailwindConfig)
32
23
 
33
24
  return candidateFilesCache.set(context, candidateFiles).get(context)
34
25
  }
@@ -63,6 +54,7 @@ function getTailwindConfig(configOrPath) {
63
54
  delete require.cache[file]
64
55
  }
65
56
  let newConfig = resolveConfig(require(userConfigPath))
57
+ newConfig = validateConfig(newConfig)
66
58
  let newHash = hash(newConfig)
67
59
  configPathCache.set(userConfigPath, [newConfig, newHash, newDeps, newModified])
68
60
  return [newConfig, userConfigPath, newHash, newDeps]
@@ -73,39 +65,9 @@ function getTailwindConfig(configOrPath) {
73
65
  configOrPath.config === undefined ? configOrPath : configOrPath.config
74
66
  )
75
67
 
76
- return [newConfig, null, hash(newConfig), []]
77
- }
78
-
79
- function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
80
- let changedContent = context.tailwindConfig.content.content
81
- .filter((item) => typeof item.raw === 'string')
82
- .concat(context.tailwindConfig.content.safelist)
83
- .concat(context.safelist())
84
- .map(({ raw, extension }) => ({ content: raw, extension }))
85
-
86
- for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)) {
87
- let content = fs.readFileSync(changedFile, 'utf8')
88
- let extension = path.extname(changedFile).slice(1)
89
- changedContent.push({ content, extension })
90
- }
91
- return changedContent
92
- }
68
+ newConfig = validateConfig(newConfig)
93
69
 
94
- function resolveChangedFiles(candidateFiles, fileModifiedMap) {
95
- let changedFiles = new Set()
96
- env.DEBUG && console.time('Finding changed files')
97
- let files = fastGlob.sync(candidateFiles)
98
- for (let file of files) {
99
- let prevModified = fileModifiedMap.has(file) ? fileModifiedMap.get(file) : -Infinity
100
- let modified = fs.statSync(file).mtimeMs
101
-
102
- if (modified > prevModified) {
103
- changedFiles.add(file)
104
- fileModifiedMap.set(file, modified)
105
- }
106
- }
107
- env.DEBUG && console.timeEnd('Finding changed files')
108
- return changedFiles
70
+ return [newConfig, null, hash(newConfig), []]
109
71
  }
110
72
 
111
73
  // DISABLE_TOUCH = TRUE
@@ -121,11 +83,12 @@ export default function setupTrackingContext(configOrPath) {
121
83
 
122
84
  let contextDependencies = new Set(configDependencies)
123
85
 
124
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
125
- // to be dependencies of the context. Can reuse the context even if they change.
126
- // We may want to think about `@layer` being part of this trigger too, but it's tough
127
- // because it's impossible for a layer in one file to end up in the actual @tailwind rule
128
- // in another file since independent sources are effectively isolated.
86
+ // If there are no @tailwind or @apply rules, we don't consider this CSS
87
+ // file or its dependencies to be dependencies of the context. Can reuse
88
+ // the context even if they change. We may want to think about `@layer`
89
+ // being part of this trigger too, but it's tough because it's impossible
90
+ // for a layer in one file to end up in the actual @tailwind rule in
91
+ // another file since independent sources are effectively isolated.
129
92
  if (tailwindDirectives.size > 0) {
130
93
  // Add current css file as a context dependencies.
131
94
  contextDependencies.add(result.opts.from)
@@ -149,8 +112,8 @@ export default function setupTrackingContext(configOrPath) {
149
112
 
150
113
  let candidateFiles = getCandidateFiles(context, tailwindConfig)
151
114
 
152
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
153
- // to be dependencies of the context. Can reuse the context even if they change.
115
+ // If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
116
+ // dependencies to be dependencies of the context. Can reuse the context even if they change.
154
117
  // We may want to think about `@layer` being part of this trigger too, but it's tough
155
118
  // because it's impossible for a layer in one file to end up in the actual @tailwind rule
156
119
  // in another file since independent sources are effectively isolated.
@@ -158,9 +121,8 @@ export default function setupTrackingContext(configOrPath) {
158
121
  let fileModifiedMap = getFileModifiedMap(context)
159
122
 
160
123
  // Add template paths as postcss dependencies.
161
- for (let fileOrGlob of candidateFiles) {
162
- let dependency = parseDependency(fileOrGlob)
163
- if (dependency) {
124
+ for (let contentPath of candidateFiles) {
125
+ for (let dependency of parseDependency(contentPath)) {
164
126
  registerDependency(dependency)
165
127
  }
166
128
  }
@@ -1,13 +1,50 @@
1
- import LRU from 'quick-lru'
2
-
3
1
  export const env = {
4
- TAILWIND_MODE: process.env.TAILWIND_MODE,
5
2
  NODE_ENV: process.env.NODE_ENV,
6
- DEBUG: process.env.DEBUG !== undefined,
7
- TAILWIND_DISABLE_TOUCH: process.env.TAILWIND_DISABLE_TOUCH !== undefined,
8
- TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR,
3
+ DEBUG: resolveDebug(process.env.DEBUG),
9
4
  }
10
5
  export const contextMap = new Map()
11
6
  export const configContextMap = new Map()
12
7
  export const contextSourcesMap = new Map()
13
- export const contentMatchCache = new LRU({ maxSize: 25000 })
8
+ export const sourceHashMap = new Map()
9
+ export const NOT_ON_DEMAND = new String('*')
10
+
11
+ export const NONE = Symbol('__NONE__')
12
+
13
+ export function resolveDebug(debug) {
14
+ if (debug === undefined) {
15
+ return false
16
+ }
17
+
18
+ // Environment variables are strings, so convert to boolean
19
+ if (debug === 'true' || debug === '1') {
20
+ return true
21
+ }
22
+
23
+ if (debug === 'false' || debug === '0') {
24
+ return false
25
+ }
26
+
27
+ // Keep the debug convention into account:
28
+ // DEBUG=* -> This enables all debug modes
29
+ // DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
30
+ // DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
31
+ // DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB
32
+
33
+ if (debug === '*') {
34
+ return true
35
+ }
36
+
37
+ let debuggers = debug.split(',').map((d) => d.split(':')[0])
38
+
39
+ // Ignoring tailwindcss
40
+ if (debuggers.includes('-tailwindcss')) {
41
+ return false
42
+ }
43
+
44
+ // Including tailwindcss
45
+ if (debuggers.includes('tailwindcss')) {
46
+ return true
47
+ }
48
+
49
+ return false
50
+ }
@@ -1,16 +1,19 @@
1
+ import { normalizeScreens } from '../util/normalizeScreens'
1
2
  import buildMediaQuery from '../util/buildMediaQuery'
2
3
 
3
4
  export default function ({ tailwindConfig: { theme } }) {
4
5
  return function (css) {
5
6
  css.walkAtRules('screen', (atRule) => {
6
- const screen = atRule.params
7
+ let screen = atRule.params
8
+ let screens = normalizeScreens(theme.screens)
9
+ let screenDefinition = screens.find(({ name }) => name === screen)
7
10
 
8
- if (!theme.screens?.hasOwnProperty?.(screen)) {
11
+ if (!screenDefinition) {
9
12
  throw atRule.error(`No \`${screen}\` screen found.`)
10
13
  }
11
14
 
12
15
  atRule.name = 'media'
13
- atRule.params = buildMediaQuery(theme.screens[screen])
16
+ atRule.params = buildMediaQuery(screenDefinition)
14
17
  })
15
18
  }
16
19
  }
@@ -0,0 +1,42 @@
1
+ # tailwindcss/nesting
2
+
3
+ This is a PostCSS plugin that wraps [postcss-nested](https://github.com/postcss/postcss-nested) or [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting) and acts as a compatibility layer to make sure your nesting plugin of choice properly understands Tailwind's custom syntax like `@apply` and `@screen`.
4
+
5
+ Add it to your PostCSS configuration, somewhere before Tailwind itself:
6
+
7
+ ```js
8
+ // postcss.config.js
9
+ module.exports = {
10
+ plugins: [
11
+ require('postcss-import'),
12
+ require('tailwindcss/nesting'),
13
+ require('tailwindcss'),
14
+ require('autoprefixer'),
15
+ ]
16
+ }
17
+ ```
18
+
19
+ By default, it uses the [postcss-nested](https://github.com/postcss/postcss-nested) plugin under the hood, which uses a Sass-like syntax and is the plugin that powers nesting support in the [Tailwind CSS plugin API](https://tailwindcss.com/docs/plugins#css-in-js-syntax).
20
+
21
+ If you'd rather use [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting) (which is based on the work-in-progress [CSS Nesting](https://drafts.csswg.org/css-nesting-1/) specification), first install the plugin alongside:
22
+
23
+ ```shell
24
+ npm install postcss-nesting
25
+ ```
26
+
27
+ Then pass the plugin itself as an argument to `tailwindcss/nesting` in your PostCSS configuration:
28
+
29
+ ```js
30
+ // postcss.config.js
31
+ module.exports = {
32
+ plugins: [
33
+ require('postcss-import'),
34
+ require('tailwindcss/nesting')(require('postcss-nesting')),
35
+ require('tailwindcss'),
36
+ require('autoprefixer'),
37
+ ]
38
+ }
39
+ ```
40
+
41
+ This can also be helpful if for whatever reason you need to use a very specific version of `postcss-nested` and want to override the version we bundle with `tailwindcss/nesting` itself.
42
+
@@ -0,0 +1,13 @@
1
+ import { nesting } from './plugin'
2
+
3
+ export default Object.assign(
4
+ function (opts) {
5
+ return {
6
+ postcssPlugin: 'tailwindcss/nesting',
7
+ Once(root, { result }) {
8
+ return nesting(opts)(root, result)
9
+ },
10
+ }
11
+ },
12
+ { postcss: true }
13
+ )
@@ -0,0 +1,80 @@
1
+ import postcss from 'postcss'
2
+ import postcssNested from 'postcss-nested'
3
+
4
+ export function nesting(opts = postcssNested) {
5
+ return (root, result) => {
6
+ root.walkAtRules('screen', (rule) => {
7
+ rule.name = 'media'
8
+ rule.params = `screen(${rule.params})`
9
+ })
10
+
11
+ root.walkAtRules('apply', (rule) => {
12
+ rule.before(postcss.decl({ prop: '__apply', value: rule.params, source: rule.source }))
13
+ rule.remove()
14
+ })
15
+
16
+ let plugin = (() => {
17
+ if (
18
+ typeof opts === 'function' ||
19
+ (typeof opts === 'object' && opts?.hasOwnProperty?.('postcssPlugin'))
20
+ ) {
21
+ return opts
22
+ }
23
+
24
+ if (typeof opts === 'string') {
25
+ return require(opts)
26
+ }
27
+
28
+ if (Object.keys(opts).length <= 0) {
29
+ return postcssNested
30
+ }
31
+
32
+ throw new Error('tailwindcss/nesting should be loaded with a nesting plugin.')
33
+ })()
34
+
35
+ postcss([plugin]).process(root, result.opts).sync()
36
+
37
+ root.walkDecls('__apply', (decl) => {
38
+ decl.before(postcss.atRule({ name: 'apply', params: decl.value, source: decl.source }))
39
+ decl.remove()
40
+ })
41
+
42
+ /**
43
+ * Use a private PostCSS API to remove the "clean" flag from the entire AST.
44
+ * This is done because running process() on the AST will set the "clean"
45
+ * flag on all nodes, which we don't want.
46
+ *
47
+ * This causes downstream plugins using the visitor API to be skipped.
48
+ *
49
+ * This is guarded because the PostCSS API is not public
50
+ * and may change in future versions of PostCSS.
51
+ *
52
+ * See https://github.com/postcss/postcss/issues/1712 for more details
53
+ *
54
+ * @param {import('postcss').Node} node
55
+ */
56
+ function markDirty(node) {
57
+ if (!('markDirty' in node)) {
58
+ return
59
+ }
60
+
61
+ // Traverse the tree down to the leaf nodes
62
+ if (node.nodes) {
63
+ node.nodes.forEach((n) => markDirty(n))
64
+ }
65
+
66
+ // If it's a leaf node mark it as dirty
67
+ // We do this here because marking a node as dirty
68
+ // will walk up the tree and mark all parents as dirty
69
+ // resulting in a lot of unnecessary work if we did this
70
+ // for every single node
71
+ if (!node.nodes) {
72
+ node.markDirty()
73
+ }
74
+ }
75
+
76
+ markDirty(root)
77
+
78
+ return root
79
+ }
80
+ }
@@ -5,15 +5,25 @@ import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
5
5
  import substituteScreenAtRules from './lib/substituteScreenAtRules'
6
6
  import resolveDefaultsAtRules from './lib/resolveDefaultsAtRules'
7
7
  import collapseAdjacentRules from './lib/collapseAdjacentRules'
8
+ import collapseDuplicateDeclarations from './lib/collapseDuplicateDeclarations'
9
+ import partitionApplyAtRules from './lib/partitionApplyAtRules'
8
10
  import detectNesting from './lib/detectNesting'
9
11
  import { createContext } from './lib/setupContextUtils'
12
+ import { issueFlagNotices } from './featureFlags'
10
13
 
11
14
  export default function processTailwindFeatures(setupContext) {
12
15
  return function (root, result) {
13
- let tailwindDirectives = normalizeTailwindDirectives(root)
16
+ let { tailwindDirectives, applyDirectives } = normalizeTailwindDirectives(root)
17
+
18
+ detectNesting()(root, result)
19
+
20
+ // Partition apply rules that are found in the css
21
+ // itself.
22
+ partitionApplyAtRules()(root, result)
14
23
 
15
24
  let context = setupContext({
16
25
  tailwindDirectives,
26
+ applyDirectives,
17
27
  registerDependency(dependency) {
18
28
  result.messages.push({
19
29
  plugin: 'tailwindcss',
@@ -32,12 +42,17 @@ export default function processTailwindFeatures(setupContext) {
32
42
  )
33
43
  }
34
44
 
35
- detectNesting(context)(root, result)
45
+ issueFlagNotices(context.tailwindConfig)
46
+
36
47
  expandTailwindAtRules(context)(root, result)
48
+ // Partition apply rules that are generated by
49
+ // addComponents, addUtilities and so on.
50
+ partitionApplyAtRules()(root, result)
37
51
  expandApplyAtRules(context)(root, result)
38
52
  evaluateTailwindFunctions(context)(root, result)
39
53
  substituteScreenAtRules(context)(root, result)
40
54
  resolveDefaultsAtRules(context)(root, result)
41
55
  collapseAdjacentRules(context)(root, result)
56
+ collapseDuplicateDeclarations(context)(root, result)
42
57
  }
43
58
  }
@@ -1,15 +1,10 @@
1
1
  import log from '../util/log'
2
2
 
3
- let warned = []
4
-
5
3
  function warn({ version, from, to }) {
6
- if (!warned.includes(from)) {
7
- log.warn([
8
- `As of Tailwind CSS ${version}, \`${from}\` has been renamed to \`${to}\`.`,
9
- 'Please update your color palette to eliminate this warning.',
10
- ])
11
- warned.push(from)
12
- }
4
+ log.warn(`${from}-color-renamed`, [
5
+ `As of Tailwind CSS ${version}, \`${from}\` has been renamed to \`${to}\`.`,
6
+ 'Update your configuration file to silence this warning.',
7
+ ])
13
8
  }
14
9
 
15
10
  export default {
@@ -1,24 +1,22 @@
1
1
  export default function buildMediaQuery(screens) {
2
- if (typeof screens === 'string') {
3
- screens = { min: screens }
4
- }
5
-
6
- if (!Array.isArray(screens)) {
7
- screens = [screens]
8
- }
2
+ screens = Array.isArray(screens) ? screens : [screens]
9
3
 
10
4
  return screens
11
5
  .map((screen) => {
12
- if (screen?.hasOwnProperty?.('raw')) {
13
- return screen.raw
14
- }
6
+ let values = screen.values.map((screen) => {
7
+ if (screen.raw !== undefined) {
8
+ return screen.raw
9
+ }
10
+
11
+ return [
12
+ screen.min && `(min-width: ${screen.min})`,
13
+ screen.max && `(max-width: ${screen.max})`,
14
+ ]
15
+ .filter(Boolean)
16
+ .join(' and ')
17
+ })
15
18
 
16
- return Object.entries(screen)
17
- .map(([feature, value]) => {
18
- feature = { min: 'min-width', max: 'max-width' }[feature] ?? feature
19
- return `(${feature}: ${value})`
20
- })
21
- .join(' and ')
19
+ return screen.not ? `not all and ${values}` : values
22
20
  })
23
21
  .join(', ')
24
22
  }
@@ -1,9 +1,26 @@
1
- export default function cloneNodes(nodes, source) {
1
+ export default function cloneNodes(nodes, source = undefined, raws = undefined) {
2
2
  return nodes.map((node) => {
3
3
  let cloned = node.clone()
4
4
 
5
- if (source !== undefined) {
5
+ // We always want override the source map
6
+ // except when explicitly told not to
7
+ let shouldOverwriteSource = node.raws.tailwind?.preserveSource !== true || !cloned.source
8
+
9
+ if (source !== undefined && shouldOverwriteSource) {
6
10
  cloned.source = source
11
+
12
+ if ('walk' in cloned) {
13
+ cloned.walk((child) => {
14
+ child.source = source
15
+ })
16
+ }
17
+ }
18
+
19
+ if (raws !== undefined) {
20
+ cloned.raws.tailwind = {
21
+ ...cloned.raws.tailwind,
22
+ ...raws,
23
+ }
7
24
  }
8
25
 
9
26
  return cloned
package/src/util/color.js CHANGED
@@ -2,14 +2,21 @@ import namedColors from 'color-name'
2
2
 
3
3
  let HEX = /^#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i
4
4
  let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i
5
- let VALUE = `(?:\\d+|\\d*\\.\\d+)%?`
6
- let SEP = `(?:\\s*,\\s*|\\s+)`
7
- let ALPHA_SEP = `\\s*[,/]\\s*`
8
- let RGB_HSL = new RegExp(
9
- `^(rgb|hsl)a?\\(\\s*(${VALUE})${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
5
+ let VALUE = /(?:\d+|\d*\.\d+)%?/
6
+ let SEP = /(?:\s*,\s*|\s+)/
7
+ let ALPHA_SEP = /\s*[,/]\s*/
8
+ let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)\)/
9
+
10
+ let RGB = new RegExp(
11
+ `^(rgb)a?\\(\\s*(${VALUE.source}|${CUSTOM_PROPERTY.source})(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`
12
+ )
13
+ let HSL = new RegExp(
14
+ `^(hsl)a?\\(\\s*((?:${VALUE.source})(?:deg|rad|grad|turn)?|${CUSTOM_PROPERTY.source})(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?(?:${ALPHA_SEP.source}(${VALUE.source}|${CUSTOM_PROPERTY.source}))?\\s*\\)$`
10
15
  )
11
16
 
12
- export function parseColor(value) {
17
+ // In "loose" mode the color may contain fewer than 3 parts, as long as at least
18
+ // one of the parts is variable.
19
+ export function parseColor(value, { loose = false } = {}) {
13
20
  if (typeof value !== 'string') {
14
21
  return null
15
22
  }
@@ -37,17 +44,27 @@ export function parseColor(value) {
37
44
  }
38
45
  }
39
46
 
40
- let match = value.match(RGB_HSL)
47
+ let match = value.match(RGB) ?? value.match(HSL)
41
48
 
42
- if (match !== null) {
43
- return {
44
- mode: match[1],
45
- color: [match[2], match[3], match[4]].map((v) => v.toString()),
46
- alpha: match[5]?.toString?.(),
47
- }
49
+ if (match === null) {
50
+ return null
48
51
  }
49
52
 
50
- return null
53
+ let color = [match[2], match[3], match[4]].filter(Boolean).map((v) => v.toString())
54
+
55
+ if (!loose && color.length !== 3) {
56
+ return null
57
+ }
58
+
59
+ if (color.length < 3 && !color.some((part) => /^var\(.*?\)$/.test(part))) {
60
+ return null
61
+ }
62
+
63
+ return {
64
+ mode: match[1],
65
+ color,
66
+ alpha: match[5]?.toString?.(),
67
+ }
51
68
  }
52
69
 
53
70
  export function formatColor({ mode, color, alpha }) {
@@ -3,7 +3,7 @@ import transformThemeValue from './transformThemeValue'
3
3
  export default function createUtilityPlugin(
4
4
  themeKey,
5
5
  utilityVariations = [[themeKey, [themeKey]]],
6
- { filterDefault = false, type = 'any' } = {}
6
+ { filterDefault = false, ...options } = {}
7
7
  ) {
8
8
  let transformValue = transformThemeValue(themeKey)
9
9
  return function ({ matchUtilities, theme }) {
@@ -24,12 +24,12 @@ export default function createUtilityPlugin(
24
24
  })
25
25
  }, {}),
26
26
  {
27
+ ...options,
27
28
  values: filterDefault
28
29
  ? Object.fromEntries(
29
30
  Object.entries(theme(themeKey) ?? {}).filter(([modifier]) => modifier !== 'DEFAULT')
30
31
  )
31
32
  : theme(themeKey),
32
- type,
33
33
  }
34
34
  )
35
35
  }