tailwindcss 0.0.0-insiders.fe08e91 → 0.0.0-oxide.dd87d75

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 (178) hide show
  1. package/CHANGELOG.md +379 -3
  2. package/LICENSE +1 -2
  3. package/README.md +12 -8
  4. package/colors.d.ts +3 -0
  5. package/defaultConfig.d.ts +3 -0
  6. package/defaultTheme.d.ts +4 -0
  7. package/lib/cli/build/deps.js +54 -0
  8. package/lib/cli/build/index.js +48 -0
  9. package/lib/cli/build/plugin.js +367 -0
  10. package/lib/cli/build/utils.js +78 -0
  11. package/lib/cli/build/watching.js +178 -0
  12. package/lib/cli/help/index.js +71 -0
  13. package/lib/cli/index.js +239 -0
  14. package/lib/cli/init/index.js +46 -0
  15. package/lib/cli/shared.js +13 -0
  16. package/lib/cli-peer-dependencies.js +20 -7
  17. package/lib/cli.js +4 -740
  18. package/lib/constants.js +27 -20
  19. package/lib/corePluginList.js +6 -3
  20. package/lib/corePlugins.js +2064 -1811
  21. package/lib/css/preflight.css +5 -5
  22. package/lib/featureFlags.js +31 -22
  23. package/lib/index.js +4 -28
  24. package/lib/lib/cacheInvalidation.js +90 -0
  25. package/lib/lib/collapseAdjacentRules.js +27 -9
  26. package/lib/lib/collapseDuplicateDeclarations.js +12 -9
  27. package/lib/lib/content.js +176 -0
  28. package/lib/lib/defaultExtractor.js +225 -31
  29. package/lib/lib/detectNesting.js +13 -10
  30. package/lib/lib/evaluateTailwindFunctions.js +118 -55
  31. package/lib/lib/expandApplyAtRules.js +439 -190
  32. package/lib/lib/expandTailwindAtRules.js +151 -134
  33. package/lib/lib/findAtConfigPath.js +44 -0
  34. package/lib/lib/generateRules.js +454 -187
  35. package/lib/lib/getModuleDependencies.js +11 -8
  36. package/lib/lib/normalizeTailwindDirectives.js +36 -32
  37. package/lib/lib/offsets.js +217 -0
  38. package/lib/lib/partitionApplyAtRules.js +56 -0
  39. package/lib/lib/regex.js +60 -0
  40. package/lib/lib/resolveDefaultsAtRules.js +89 -67
  41. package/lib/lib/setupContextUtils.js +667 -376
  42. package/lib/lib/setupTrackingContext.js +38 -67
  43. package/lib/lib/sharedState.js +27 -14
  44. package/lib/lib/substituteScreenAtRules.js +11 -9
  45. package/lib/plugin.js +48 -0
  46. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  47. package/lib/postcss-plugins/nesting/index.js +19 -0
  48. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  49. package/lib/processTailwindFeatures.js +35 -25
  50. package/lib/public/colors.js +247 -245
  51. package/lib/public/create-plugin.js +6 -4
  52. package/lib/public/default-config.js +7 -5
  53. package/lib/public/default-theme.js +7 -5
  54. package/lib/public/resolve-config.js +8 -5
  55. package/lib/util/bigSign.js +4 -1
  56. package/lib/util/buildMediaQuery.js +11 -6
  57. package/lib/util/cloneDeep.js +7 -6
  58. package/lib/util/cloneNodes.js +21 -3
  59. package/lib/util/color.js +53 -54
  60. package/lib/util/configurePlugins.js +5 -2
  61. package/lib/util/createPlugin.js +6 -6
  62. package/lib/util/createUtilityPlugin.js +12 -14
  63. package/lib/util/dataTypes.js +119 -110
  64. package/lib/util/defaults.js +4 -1
  65. package/lib/util/escapeClassName.js +7 -4
  66. package/lib/util/escapeCommas.js +5 -2
  67. package/lib/util/flattenColorPalette.js +9 -12
  68. package/lib/util/formatVariantSelector.js +184 -85
  69. package/lib/util/getAllConfigs.js +27 -8
  70. package/lib/util/hashConfig.js +6 -3
  71. package/lib/util/isKeyframeRule.js +5 -2
  72. package/lib/util/isPlainObject.js +5 -2
  73. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +23 -15
  74. package/lib/util/log.js +20 -14
  75. package/lib/util/nameClass.js +20 -9
  76. package/lib/util/negateValue.js +23 -8
  77. package/lib/util/normalizeConfig.js +116 -72
  78. package/lib/util/normalizeScreens.js +120 -11
  79. package/lib/util/parseAnimationValue.js +42 -40
  80. package/lib/util/parseBoxShadowValue.js +30 -23
  81. package/lib/util/parseDependency.js +38 -56
  82. package/lib/util/parseGlob.js +34 -0
  83. package/lib/util/parseObjectStyles.js +11 -8
  84. package/lib/util/pluginUtils.js +147 -50
  85. package/lib/util/prefixSelector.js +10 -8
  86. package/lib/util/removeAlphaVariables.js +29 -0
  87. package/lib/util/resolveConfig.js +97 -85
  88. package/lib/util/resolveConfigPath.js +11 -9
  89. package/lib/util/responsive.js +8 -5
  90. package/lib/util/splitAtTopLevelOnly.js +43 -0
  91. package/lib/util/tap.js +4 -1
  92. package/lib/util/toColorValue.js +5 -3
  93. package/lib/util/toPath.js +20 -4
  94. package/lib/util/transformThemeValue.js +37 -29
  95. package/lib/util/validateConfig.js +24 -0
  96. package/lib/util/validateFormalSyntax.js +24 -0
  97. package/lib/util/withAlphaVariable.js +23 -15
  98. package/nesting/index.js +2 -12
  99. package/package.json +47 -42
  100. package/peers/index.js +11381 -7950
  101. package/plugin.d.ts +11 -0
  102. package/resolveConfig.d.ts +12 -0
  103. package/scripts/generate-types.js +105 -0
  104. package/scripts/release-channel.js +18 -0
  105. package/scripts/release-notes.js +21 -0
  106. package/scripts/type-utils.js +27 -0
  107. package/src/cli/build/deps.js +56 -0
  108. package/src/cli/build/index.js +49 -0
  109. package/src/cli/build/plugin.js +439 -0
  110. package/src/cli/build/utils.js +76 -0
  111. package/src/cli/build/watching.js +227 -0
  112. package/src/cli/help/index.js +70 -0
  113. package/src/cli/index.js +234 -0
  114. package/src/cli/init/index.js +50 -0
  115. package/src/cli/shared.js +6 -0
  116. package/src/cli-peer-dependencies.js +7 -1
  117. package/src/cli.js +4 -810
  118. package/src/corePluginList.js +1 -1
  119. package/src/corePlugins.js +532 -217
  120. package/src/css/preflight.css +5 -5
  121. package/src/featureFlags.js +15 -9
  122. package/src/index.js +4 -27
  123. package/src/lib/cacheInvalidation.js +52 -0
  124. package/src/lib/collapseAdjacentRules.js +21 -2
  125. package/src/lib/content.js +212 -0
  126. package/src/lib/defaultExtractor.js +196 -33
  127. package/src/lib/evaluateTailwindFunctions.js +78 -7
  128. package/src/lib/expandApplyAtRules.js +482 -183
  129. package/src/lib/expandTailwindAtRules.js +106 -85
  130. package/src/lib/findAtConfigPath.js +48 -0
  131. package/src/lib/generateRules.js +418 -129
  132. package/src/lib/normalizeTailwindDirectives.js +1 -0
  133. package/src/lib/offsets.js +270 -0
  134. package/src/lib/partitionApplyAtRules.js +52 -0
  135. package/src/lib/regex.js +74 -0
  136. package/src/lib/resolveDefaultsAtRules.js +51 -30
  137. package/src/lib/setupContextUtils.js +556 -208
  138. package/src/lib/setupTrackingContext.js +11 -48
  139. package/src/lib/sharedState.js +5 -0
  140. package/src/plugin.js +47 -0
  141. package/src/postcss-plugins/nesting/README.md +42 -0
  142. package/src/postcss-plugins/nesting/index.js +13 -0
  143. package/src/postcss-plugins/nesting/plugin.js +80 -0
  144. package/src/processTailwindFeatures.js +8 -0
  145. package/src/util/buildMediaQuery.js +5 -3
  146. package/src/util/cloneNodes.js +19 -2
  147. package/src/util/color.js +25 -21
  148. package/src/util/dataTypes.js +29 -21
  149. package/src/util/formatVariantSelector.js +184 -61
  150. package/src/util/getAllConfigs.js +19 -0
  151. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  152. package/src/util/log.js +8 -8
  153. package/src/util/nameClass.js +4 -0
  154. package/src/util/negateValue.js +11 -3
  155. package/src/util/normalizeConfig.js +44 -6
  156. package/src/util/normalizeScreens.js +99 -4
  157. package/src/util/parseBoxShadowValue.js +4 -3
  158. package/src/util/parseDependency.js +37 -42
  159. package/src/util/parseGlob.js +24 -0
  160. package/src/util/pluginUtils.js +132 -10
  161. package/src/util/prefixSelector.js +7 -5
  162. package/src/util/removeAlphaVariables.js +24 -0
  163. package/src/util/resolveConfig.js +70 -32
  164. package/src/util/splitAtTopLevelOnly.js +45 -0
  165. package/src/util/toPath.js +1 -1
  166. package/src/util/transformThemeValue.js +13 -3
  167. package/src/util/validateConfig.js +13 -0
  168. package/src/util/validateFormalSyntax.js +34 -0
  169. package/src/util/withAlphaVariable.js +1 -1
  170. package/stubs/defaultConfig.stub.js +23 -20
  171. package/stubs/simpleConfig.stub.js +1 -0
  172. package/types/config.d.ts +362 -0
  173. package/types/generated/.gitkeep +0 -0
  174. package/types/generated/colors.d.ts +276 -0
  175. package/types/generated/corePluginList.d.ts +1 -0
  176. package/types/generated/default-theme.d.ts +342 -0
  177. package/types/index.d.ts +7 -0
  178. package/nesting/plugin.js +0 -41
@@ -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.files
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,37 +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.files
81
- .filter((item) => typeof item.raw === 'string')
82
- .map(({ raw, extension = 'html' }) => ({ content: raw, extension }))
83
-
84
- for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)) {
85
- let content = fs.readFileSync(changedFile, 'utf8')
86
- let extension = path.extname(changedFile).slice(1)
87
- changedContent.push({ content, extension })
88
- }
89
- return changedContent
90
- }
68
+ newConfig = validateConfig(newConfig)
91
69
 
92
- function resolveChangedFiles(candidateFiles, fileModifiedMap) {
93
- let changedFiles = new Set()
94
- env.DEBUG && console.time('Finding changed files')
95
- let files = fastGlob.sync(candidateFiles)
96
- for (let file of files) {
97
- let prevModified = fileModifiedMap.has(file) ? fileModifiedMap.get(file) : -Infinity
98
- let modified = fs.statSync(file).mtimeMs
99
-
100
- if (modified > prevModified) {
101
- changedFiles.add(file)
102
- fileModifiedMap.set(file, modified)
103
- }
104
- }
105
- env.DEBUG && console.timeEnd('Finding changed files')
106
- return changedFiles
70
+ return [newConfig, null, hash(newConfig), []]
107
71
  }
108
72
 
109
73
  // DISABLE_TOUCH = TRUE
@@ -112,7 +76,7 @@ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
112
76
  // source path), or set up a new one (including setting up watchers and registering
113
77
  // plugins) then return it
114
78
  export default function setupTrackingContext(configOrPath) {
115
- return ({ tailwindDirectives, registerDependency, applyDirectives }) => {
79
+ return ({ tailwindDirectives, registerDependency }) => {
116
80
  return (root, result) => {
117
81
  let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] =
118
82
  getTailwindConfig(configOrPath)
@@ -125,7 +89,7 @@ export default function setupTrackingContext(configOrPath) {
125
89
  // being part of this trigger too, but it's tough because it's impossible
126
90
  // for a layer in one file to end up in the actual @tailwind rule in
127
91
  // another file since independent sources are effectively isolated.
128
- if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
92
+ if (tailwindDirectives.size > 0) {
129
93
  // Add current css file as a context dependencies.
130
94
  contextDependencies.add(result.opts.from)
131
95
 
@@ -153,13 +117,12 @@ export default function setupTrackingContext(configOrPath) {
153
117
  // We may want to think about `@layer` being part of this trigger too, but it's tough
154
118
  // because it's impossible for a layer in one file to end up in the actual @tailwind rule
155
119
  // in another file since independent sources are effectively isolated.
156
- if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
120
+ if (tailwindDirectives.size > 0) {
157
121
  let fileModifiedMap = getFileModifiedMap(context)
158
122
 
159
123
  // Add template paths as postcss dependencies.
160
- for (let fileOrGlob of candidateFiles) {
161
- let dependency = parseDependency(fileOrGlob)
162
- if (dependency) {
124
+ for (let contentPath of candidateFiles) {
125
+ for (let dependency of parseDependency(contentPath)) {
163
126
  registerDependency(dependency)
164
127
  }
165
128
  }
@@ -1,10 +1,15 @@
1
1
  export const env = {
2
2
  NODE_ENV: process.env.NODE_ENV,
3
3
  DEBUG: resolveDebug(process.env.DEBUG),
4
+ OXIDE: process.env.OXIDE,
4
5
  }
5
6
  export const contextMap = new Map()
6
7
  export const configContextMap = new Map()
7
8
  export const contextSourcesMap = new Map()
9
+ export const sourceHashMap = new Map()
10
+ export const NOT_ON_DEMAND = new String('*')
11
+
12
+ export const NONE = Symbol('__NONE__')
8
13
 
9
14
  export function resolveDebug(debug) {
10
15
  if (debug === undefined) {
package/src/plugin.js ADDED
@@ -0,0 +1,47 @@
1
+ import setupTrackingContext from './lib/setupTrackingContext'
2
+ import processTailwindFeatures from './processTailwindFeatures'
3
+ import { env } from './lib/sharedState'
4
+ import { findAtConfigPath } from './lib/findAtConfigPath'
5
+
6
+ module.exports = function tailwindcss(configOrPath) {
7
+ return {
8
+ postcssPlugin: 'tailwindcss',
9
+ plugins: [
10
+ env.DEBUG &&
11
+ function (root) {
12
+ console.log('\n')
13
+ console.time('JIT TOTAL')
14
+ return root
15
+ },
16
+ function (root, result) {
17
+ // Use the path for the `@config` directive if it exists, otherwise use the
18
+ // path for the file being processed
19
+ configOrPath = findAtConfigPath(root, result) ?? configOrPath
20
+
21
+ let context = setupTrackingContext(configOrPath)
22
+
23
+ if (root.type === 'document') {
24
+ let roots = root.nodes.filter((node) => node.type === 'root')
25
+
26
+ for (const root of roots) {
27
+ if (root.type === 'root') {
28
+ processTailwindFeatures(context)(root, result)
29
+ }
30
+ }
31
+
32
+ return
33
+ }
34
+
35
+ processTailwindFeatures(context)(root, result)
36
+ },
37
+ env.DEBUG &&
38
+ function (root) {
39
+ console.timeEnd('JIT TOTAL')
40
+ console.log('\n')
41
+ return root
42
+ },
43
+ ].filter(Boolean),
44
+ }
45
+ }
46
+
47
+ module.exports.postcss = true
@@ -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
+ }
@@ -6,6 +6,7 @@ import substituteScreenAtRules from './lib/substituteScreenAtRules'
6
6
  import resolveDefaultsAtRules from './lib/resolveDefaultsAtRules'
7
7
  import collapseAdjacentRules from './lib/collapseAdjacentRules'
8
8
  import collapseDuplicateDeclarations from './lib/collapseDuplicateDeclarations'
9
+ import partitionApplyAtRules from './lib/partitionApplyAtRules'
9
10
  import detectNesting from './lib/detectNesting'
10
11
  import { createContext } from './lib/setupContextUtils'
11
12
  import { issueFlagNotices } from './featureFlags'
@@ -16,6 +17,10 @@ export default function processTailwindFeatures(setupContext) {
16
17
 
17
18
  detectNesting()(root, result)
18
19
 
20
+ // Partition apply rules that are found in the css
21
+ // itself.
22
+ partitionApplyAtRules()(root, result)
23
+
19
24
  let context = setupContext({
20
25
  tailwindDirectives,
21
26
  applyDirectives,
@@ -40,6 +45,9 @@ export default function processTailwindFeatures(setupContext) {
40
45
  issueFlagNotices(context.tailwindConfig)
41
46
 
42
47
  expandTailwindAtRules(context)(root, result)
48
+ // Partition apply rules that are generated by
49
+ // addComponents, addUtilities and so on.
50
+ partitionApplyAtRules()(root, result)
43
51
  expandApplyAtRules(context)(root, result)
44
52
  evaluateTailwindFunctions(context)(root, result)
45
53
  substituteScreenAtRules(context)(root, result)
@@ -2,8 +2,8 @@ export default function buildMediaQuery(screens) {
2
2
  screens = Array.isArray(screens) ? screens : [screens]
3
3
 
4
4
  return screens
5
- .map((screen) =>
6
- screen.values.map((screen) => {
5
+ .map((screen) => {
6
+ let values = screen.values.map((screen) => {
7
7
  if (screen.raw !== undefined) {
8
8
  return screen.raw
9
9
  }
@@ -15,6 +15,8 @@ export default function buildMediaQuery(screens) {
15
15
  .filter(Boolean)
16
16
  .join(' and ')
17
17
  })
18
- )
18
+
19
+ return screen.not ? `not all and ${values}` : values
20
+ })
19
21
  .join(', ')
20
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,17 +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*`
5
+ let VALUE = /(?:\d+|\d*\.\d+)%?/
6
+ let SEP = /(?:\s*,\s*|\s+)/
7
+ let ALPHA_SEP = /\s*[,/]\s*/
8
+ let CUSTOM_PROPERTY = /var\(--(?:[^ )]*?)\)/
9
+
8
10
  let RGB = new RegExp(
9
- `^rgba?\\(\\s*(${VALUE})${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
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*\\)$`
10
12
  )
11
13
  let HSL = new RegExp(
12
- `^hsla?\\(\\s*((?:${VALUE})(?:deg|rad|grad|turn)?)${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
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*\\)$`
13
15
  )
14
16
 
15
- 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 } = {}) {
16
20
  if (typeof value !== 'string') {
17
21
  return null
18
22
  }
@@ -40,27 +44,27 @@ export function parseColor(value) {
40
44
  }
41
45
  }
42
46
 
43
- let rgbMatch = value.match(RGB)
47
+ let match = value.match(RGB) ?? value.match(HSL)
44
48
 
45
- if (rgbMatch !== null) {
46
- return {
47
- mode: 'rgb',
48
- color: [rgbMatch[1], rgbMatch[2], rgbMatch[3]].map((v) => v.toString()),
49
- alpha: rgbMatch[4]?.toString?.(),
50
- }
49
+ if (match === null) {
50
+ return null
51
51
  }
52
52
 
53
- let hslMatch = value.match(HSL)
53
+ let color = [match[2], match[3], match[4]].filter(Boolean).map((v) => v.toString())
54
54
 
55
- if (hslMatch !== null) {
56
- return {
57
- mode: 'hsl',
58
- color: [hslMatch[1], hslMatch[2], hslMatch[3]].map((v) => v.toString()),
59
- alpha: hslMatch[4]?.toString?.(),
60
- }
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
61
  }
62
62
 
63
- return null
63
+ return {
64
+ mode: match[1],
65
+ color,
66
+ alpha: match[5]?.toString?.(),
67
+ }
64
68
  }
65
69
 
66
70
  export function formatColor({ mode, color, alpha }) {
@@ -1,16 +1,22 @@
1
1
  import { parseColor } from './color'
2
2
  import { parseBoxShadowValue } from './parseBoxShadowValue'
3
+ import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
3
4
 
4
5
  let cssFunctions = ['min', 'max', 'clamp', 'calc']
5
6
 
6
7
  // Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Types
7
8
 
8
- let COMMA = /,(?![^(]*\))/g // Comma separator that is not located between brackets. E.g.: `cubiz-bezier(a, b, c)` these don't count.
9
- let UNDERSCORE = /_(?![^(]*\))/g // Underscore separator that is not located between brackets. E.g.: `rgba(255,_255,_255)_black` these don't count.
9
+ function isCSSFunction(value) {
10
+ return cssFunctions.some((fn) => new RegExp(`^${fn}\\(.*\\)`).test(value))
11
+ }
10
12
 
11
13
  // This is not a data type, but rather a function that can normalize the
12
14
  // correct values.
13
15
  export function normalize(value, isRoot = true) {
16
+ if (value.startsWith('--')) {
17
+ return `var(${value})`
18
+ }
19
+
14
20
  // Keep raw strings if it starts with `url(`
15
21
  if (value.includes('url(')) {
16
22
  return value
@@ -40,12 +46,16 @@ export function normalize(value, isRoot = true) {
40
46
  value = value.trim()
41
47
  }
42
48
 
43
- // Add spaces around operators inside calc() that do not follow an operator
49
+ // Add spaces around operators inside math functions like calc() that do not follow an operator
44
50
  // or '('.
45
- return value.replace(
46
- /(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
47
- '$1 $2 '
48
- )
51
+ value = value.replace(/(calc|min|max|clamp)\(.+\)/g, (match) => {
52
+ return match.replace(
53
+ /(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g,
54
+ '$1 $2 '
55
+ )
56
+ })
57
+
58
+ return value
49
59
  }
50
60
 
51
61
  export function url(value) {
@@ -53,11 +63,11 @@ export function url(value) {
53
63
  }
54
64
 
55
65
  export function number(value) {
56
- return !isNaN(Number(value)) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?`).test(value))
66
+ return !isNaN(Number(value)) || isCSSFunction(value)
57
67
  }
58
68
 
59
69
  export function percentage(value) {
60
- return /%$/g.test(value) || cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?%`).test(value))
70
+ return (value.endsWith('%') && number(value.slice(0, -1))) || isCSSFunction(value)
61
71
  }
62
72
 
63
73
  let lengthUnits = [
@@ -80,13 +90,11 @@ let lengthUnits = [
80
90
  ]
81
91
  let lengthUnitsPattern = `(?:${lengthUnits.join('|')})`
82
92
  export function length(value) {
83
- return value.split(UNDERSCORE).every((part) => {
84
- return (
85
- part === '0' ||
86
- new RegExp(`${lengthUnitsPattern}$`).test(part) ||
87
- cssFunctions.some((fn) => new RegExp(`^${fn}\\(.+?${lengthUnitsPattern}`).test(part))
88
- )
89
- })
93
+ return (
94
+ value === '0' ||
95
+ new RegExp(`^[+-]?[0-9]*\.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`).test(value) ||
96
+ isCSSFunction(value)
97
+ )
90
98
  }
91
99
 
92
100
  let lineWidths = new Set(['thin', 'medium', 'thick'])
@@ -109,11 +117,11 @@ export function shadow(value) {
109
117
  export function color(value) {
110
118
  let colors = 0
111
119
 
112
- let result = value.split(UNDERSCORE).every((part) => {
120
+ let result = splitAtTopLevelOnly(value, '_').every((part) => {
113
121
  part = normalize(part)
114
122
 
115
123
  if (part.startsWith('var(')) return true
116
- if (parseColor(part) !== null) return colors++, true
124
+ if (parseColor(part, { loose: true }) !== null) return colors++, true
117
125
 
118
126
  return false
119
127
  })
@@ -124,7 +132,7 @@ export function color(value) {
124
132
 
125
133
  export function image(value) {
126
134
  let images = 0
127
- let result = value.split(COMMA).every((part) => {
135
+ let result = splitAtTopLevelOnly(value, ',').every((part) => {
128
136
  part = normalize(part)
129
137
 
130
138
  if (part.startsWith('var(')) return true
@@ -165,7 +173,7 @@ export function gradient(value) {
165
173
  let validPositions = new Set(['center', 'top', 'right', 'bottom', 'left'])
166
174
  export function position(value) {
167
175
  let positions = 0
168
- let result = value.split(UNDERSCORE).every((part) => {
176
+ let result = splitAtTopLevelOnly(value, '_').every((part) => {
169
177
  part = normalize(part)
170
178
 
171
179
  if (part.startsWith('var(')) return true
@@ -183,7 +191,7 @@ export function position(value) {
183
191
 
184
192
  export function familyName(value) {
185
193
  let fonts = 0
186
- let result = value.split(COMMA).every((part) => {
194
+ let result = splitAtTopLevelOnly(value, ',').every((part) => {
187
195
  part = normalize(part)
188
196
 
189
197
  if (part.startsWith('var(')) return true