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
@@ -18,6 +18,36 @@ import { env } from './sharedState'
18
18
  import { toPath } from '../util/toPath'
19
19
  import log from '../util/log'
20
20
  import negateValue from '../util/negateValue'
21
+ import isValidArbitraryValue from '../util/isValidArbitraryValue'
22
+
23
+ function parseVariantFormatString(input) {
24
+ if (input.includes('{')) {
25
+ if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`)
26
+
27
+ return input
28
+ .split(/{(.*)}/gim)
29
+ .flatMap((line) => parseVariantFormatString(line))
30
+ .filter(Boolean)
31
+ }
32
+
33
+ return [input.trim()]
34
+ }
35
+
36
+ function isBalanced(input) {
37
+ let count = 0
38
+
39
+ for (let char of input) {
40
+ if (char === '{') {
41
+ count++
42
+ } else if (char === '}') {
43
+ if (--count < 0) {
44
+ return false // unbalanced
45
+ }
46
+ }
47
+ }
48
+
49
+ return count === 0
50
+ }
21
51
 
22
52
  function insertInto(list, value, { before = [] } = {}) {
23
53
  before = [].concat(before)
@@ -59,39 +89,55 @@ function getClasses(selector) {
59
89
  return parser.transformSync(selector)
60
90
  }
61
91
 
62
- function extractCandidates(node) {
92
+ function extractCandidates(node, state = { containsNonOnDemandable: false }, depth = 0) {
63
93
  let classes = []
64
94
 
95
+ // Handle normal rules
65
96
  if (node.type === 'rule') {
66
97
  for (let selector of node.selectors) {
67
98
  let classCandidates = getClasses(selector)
68
99
  // At least one of the selectors contains non-"on-demandable" candidates.
69
- if (classCandidates.length === 0) return []
100
+ if (classCandidates.length === 0) {
101
+ state.containsNonOnDemandable = true
102
+ }
70
103
 
71
- classes = [...classes, ...classCandidates]
104
+ for (let classCandidate of classCandidates) {
105
+ classes.push(classCandidate)
106
+ }
72
107
  }
73
- return classes
74
108
  }
75
109
 
76
- if (node.type === 'atrule') {
110
+ // Handle at-rules (which contains nested rules)
111
+ else if (node.type === 'atrule') {
77
112
  node.walkRules((rule) => {
78
- classes = [...classes, ...rule.selectors.flatMap((selector) => getClasses(selector))]
113
+ for (let classCandidate of rule.selectors.flatMap((selector) =>
114
+ getClasses(selector, state, depth + 1)
115
+ )) {
116
+ classes.push(classCandidate)
117
+ }
79
118
  })
80
119
  }
81
120
 
121
+ if (depth === 0) {
122
+ return [state.containsNonOnDemandable || classes.length === 0, classes]
123
+ }
124
+
82
125
  return classes
83
126
  }
84
127
 
85
128
  function withIdentifiers(styles) {
86
129
  return parseStyles(styles).flatMap((node) => {
87
130
  let nodeMap = new Map()
88
- let candidates = extractCandidates(node)
131
+ let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node)
89
132
 
90
- // If this isn't "on-demandable", assign it a universal candidate.
91
- if (candidates.length === 0) {
92
- return [['*', node]]
133
+ // If this isn't "on-demandable", assign it a universal candidate to always include it.
134
+ if (containsNonOnDemandableSelectors) {
135
+ candidates.unshift('*')
93
136
  }
94
137
 
138
+ // However, it could be that it also contains "on-demandable" candidates.
139
+ // E.g.: `span, .foo {}`, in that case it should still be possible to use
140
+ // `@apply foo` for example.
95
141
  return candidates.map((c) => {
96
142
  if (!nodeMap.has(node)) {
97
143
  nodeMap.set(node, node)
@@ -101,64 +147,6 @@ function withIdentifiers(styles) {
101
147
  })
102
148
  }
103
149
 
104
- let matchingBrackets = new Map([
105
- ['{', '}'],
106
- ['[', ']'],
107
- ['(', ')'],
108
- ])
109
- let inverseMatchingBrackets = new Map(
110
- Array.from(matchingBrackets.entries()).map(([k, v]) => [v, k])
111
- )
112
-
113
- let quotes = new Set(['"', "'", '`'])
114
-
115
- // Arbitrary values must contain balanced brackets (), [] and {}. Escaped
116
- // values don't count, and brackets inside quotes also don't count.
117
- //
118
- // E.g.: w-[this-is]w-[weird-and-invalid]
119
- // E.g.: w-[this-is\\]w-\\[weird-but-valid]
120
- // E.g.: content-['this-is-also-valid]-weirdly-enough']
121
- function isValidArbitraryValue(value) {
122
- let stack = []
123
- let inQuotes = false
124
-
125
- for (let i = 0; i < value.length; i++) {
126
- let char = value[i]
127
-
128
- // Non-escaped quotes allow us to "allow" anything in between
129
- if (quotes.has(char) && value[i - 1] !== '\\') {
130
- inQuotes = !inQuotes
131
- }
132
-
133
- if (inQuotes) continue
134
- if (value[i - 1] === '\\') continue // Escaped
135
-
136
- if (matchingBrackets.has(char)) {
137
- stack.push(char)
138
- } else if (inverseMatchingBrackets.has(char)) {
139
- let inverse = inverseMatchingBrackets.get(char)
140
-
141
- // Nothing to pop from, therefore it is unbalanced
142
- if (stack.length <= 0) {
143
- return false
144
- }
145
-
146
- // Popped value must match the inverse value, otherwise it is unbalanced
147
- if (stack.pop() !== inverse) {
148
- return false
149
- }
150
- }
151
- }
152
-
153
- // If there is still something on the stack, it is also unbalanced
154
- if (stack.length > 0) {
155
- return false
156
- }
157
-
158
- // All good, totally balanced!
159
- return true
160
- }
161
-
162
150
  function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offsets, classList }) {
163
151
  function getConfigValue(path, defaultValue) {
164
152
  return path ? dlv(tailwindConfig, path, defaultValue) : tailwindConfig
@@ -177,16 +165,41 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
177
165
  return identifier
178
166
  }
179
167
 
180
- if (typeof context.tailwindConfig.prefix === 'function') {
181
- return prefixSelector(context.tailwindConfig.prefix, `.${identifier}`).substr(1)
182
- }
183
-
184
168
  return context.tailwindConfig.prefix + identifier
185
169
  }
186
170
 
187
171
  return {
188
172
  addVariant(variantName, variantFunctions, options = {}) {
189
- variantFunctions = [].concat(variantFunctions)
173
+ variantFunctions = [].concat(variantFunctions).map((variantFunction) => {
174
+ if (typeof variantFunction !== 'string') {
175
+ // Safelist public API functions
176
+ return ({ modifySelectors, container, separator }) => {
177
+ return variantFunction({ modifySelectors, container, separator })
178
+ }
179
+ }
180
+
181
+ variantFunction = variantFunction
182
+ .replace(/\n+/g, '')
183
+ .replace(/\s{1,}/g, ' ')
184
+ .trim()
185
+
186
+ let fns = parseVariantFormatString(variantFunction)
187
+ .map((str) => {
188
+ if (!str.startsWith('@')) {
189
+ return ({ format }) => format(str)
190
+ }
191
+
192
+ let [, name, params] = /@(.*?) (.*)/g.exec(str)
193
+ return ({ wrap }) => wrap(postcss.atRule({ name, params }))
194
+ })
195
+ .reverse()
196
+
197
+ return (api) => {
198
+ for (let fn of fns) {
199
+ fn(api)
200
+ }
201
+ }
202
+ })
190
203
 
191
204
  insertInto(variantList, variantName, options)
192
205
  variantMap.set(variantName, variantFunctions)
@@ -236,6 +249,27 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
236
249
  .push([{ sort: offset, layer: 'base' }, rule])
237
250
  }
238
251
  },
252
+ /**
253
+ * @param {string} group
254
+ * @param {Record<string, string | string[]>} declarations
255
+ */
256
+ addDefaults(group, declarations) {
257
+ const groups = {
258
+ [`@defaults ${group}`]: declarations,
259
+ }
260
+
261
+ for (let [identifier, rule] of withIdentifiers(groups)) {
262
+ let prefixedIdentifier = prefixIdentifier(identifier, {})
263
+
264
+ if (!context.candidateRuleMap.has(prefixedIdentifier)) {
265
+ context.candidateRuleMap.set(prefixedIdentifier, [])
266
+ }
267
+
268
+ context.candidateRuleMap
269
+ .get(prefixedIdentifier)
270
+ .push([{ sort: offsets.base++, layer: 'defaults' }, rule])
271
+ }
272
+ },
239
273
  addComponents(components, options) {
240
274
  let defaultOptions = {
241
275
  respectPrefix: true,
@@ -246,7 +280,6 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
246
280
 
247
281
  for (let [identifier, rule] of withIdentifiers(components)) {
248
282
  let prefixedIdentifier = prefixIdentifier(identifier, options)
249
- let offset = offsets.components++
250
283
 
251
284
  classList.add(prefixedIdentifier)
252
285
 
@@ -256,7 +289,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
256
289
 
257
290
  context.candidateRuleMap
258
291
  .get(prefixedIdentifier)
259
- .push([{ sort: offset, layer: 'components', options }, rule])
292
+ .push([{ sort: offsets.components++, layer: 'components', options }, rule])
260
293
  }
261
294
  },
262
295
  addUtilities(utilities, options) {
@@ -269,7 +302,6 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
269
302
 
270
303
  for (let [identifier, rule] of withIdentifiers(utilities)) {
271
304
  let prefixedIdentifier = prefixIdentifier(identifier, options)
272
- let offset = offsets.utilities++
273
305
 
274
306
  classList.add(prefixedIdentifier)
275
307
 
@@ -279,7 +311,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
279
311
 
280
312
  context.candidateRuleMap
281
313
  .get(prefixedIdentifier)
282
- .push([{ sort: offset, layer: 'utilities', options }, rule])
314
+ .push([{ sort: offsets.utilities++, layer: 'utilities', options }, rule])
283
315
  }
284
316
  },
285
317
  matchUtilities: function (utilities, options) {
@@ -416,7 +448,14 @@ function trackModified(files, fileModifiedMap) {
416
448
  let parsed = url.parse(file)
417
449
  let pathname = parsed.hash ? parsed.href.replace(parsed.hash, '') : parsed.href
418
450
  pathname = parsed.search ? pathname.replace(parsed.search, '') : pathname
419
- let newModified = fs.statSync(decodeURIComponent(pathname)).mtimeMs
451
+ let newModified = fs.statSync(decodeURIComponent(pathname), { throwIfNoEntry: false })?.mtimeMs
452
+ if (!newModified) {
453
+ // It could happen that a file is passed in that doesn't exist. E.g.:
454
+ // postcss-cli will provide you a fake path when reading from stdin. This
455
+ // path then looks like /path-to-your-project/stdin In that case we just
456
+ // want to ignore it and don't track changes at all.
457
+ continue
458
+ }
420
459
 
421
460
  if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
422
461
  changed = true
@@ -519,7 +558,9 @@ function resolvePlugins(context, root) {
519
558
  variantPlugins['directionVariants'],
520
559
  variantPlugins['reducedMotionVariants'],
521
560
  variantPlugins['darkVariants'],
561
+ variantPlugins['printVariant'],
522
562
  variantPlugins['screenVariants'],
563
+ variantPlugins['orientationVariants'],
523
564
  ]
524
565
 
525
566
  return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]
@@ -529,6 +570,7 @@ function registerPlugins(plugins, context) {
529
570
  let variantList = []
530
571
  let variantMap = new Map()
531
572
  let offsets = {
573
+ defaults: 0n,
532
574
  base: 0n,
533
575
  components: 0n,
534
576
  utilities: 0n,
@@ -556,20 +598,26 @@ function registerPlugins(plugins, context) {
556
598
 
557
599
  let highestOffset = ((args) => args.reduce((m, e) => (e > m ? e : m)))([
558
600
  offsets.base,
601
+ offsets.defaults,
559
602
  offsets.components,
560
603
  offsets.utilities,
561
604
  offsets.user,
562
605
  ])
563
606
  let reservedBits = BigInt(highestOffset.toString(2).length)
564
607
 
608
+ // A number one less than the top range of the highest offset area
609
+ // so arbitrary properties are always sorted at the end.
610
+ context.arbitraryPropertiesSort = ((1n << reservedBits) << 0n) - 1n
611
+
565
612
  context.layerOrder = {
566
- base: (1n << reservedBits) << 0n,
567
- components: (1n << reservedBits) << 1n,
568
- utilities: (1n << reservedBits) << 2n,
569
- user: (1n << reservedBits) << 3n,
613
+ defaults: (1n << reservedBits) << 0n,
614
+ base: (1n << reservedBits) << 1n,
615
+ components: (1n << reservedBits) << 2n,
616
+ utilities: (1n << reservedBits) << 3n,
617
+ user: (1n << reservedBits) << 4n,
570
618
  }
571
619
 
572
- reservedBits += 4n
620
+ reservedBits += 5n
573
621
 
574
622
  let offset = 0
575
623
  context.variantOrder = new Map(
@@ -623,7 +671,15 @@ function registerPlugins(plugins, context) {
623
671
  let utils = Array.isArray(util)
624
672
  ? (() => {
625
673
  let [utilName, options] = util
626
- return Object.keys(options?.values ?? {}).map((value) => formatClass(utilName, value))
674
+ let classes = Object.keys(options?.values ?? {}).map((value) =>
675
+ formatClass(utilName, value)
676
+ )
677
+
678
+ if (options?.supportsNegativeValues) {
679
+ classes = [...classes, ...classes.map((cls) => '-' + cls)]
680
+ }
681
+
682
+ return classes
627
683
  })()
628
684
  : [util]
629
685
 
@@ -112,19 +112,20 @@ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
112
112
  // source path), or set up a new one (including setting up watchers and registering
113
113
  // plugins) then return it
114
114
  export default function setupTrackingContext(configOrPath) {
115
- return ({ tailwindDirectives, registerDependency }) => {
115
+ return ({ tailwindDirectives, registerDependency, applyDirectives }) => {
116
116
  return (root, result) => {
117
117
  let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] =
118
118
  getTailwindConfig(configOrPath)
119
119
 
120
120
  let contextDependencies = new Set(configDependencies)
121
121
 
122
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
123
- // to be dependencies of the context. Can reuse the context even if they change.
124
- // We may want to think about `@layer` being part of this trigger too, but it's tough
125
- // because it's impossible for a layer in one file to end up in the actual @tailwind rule
126
- // in another file since independent sources are effectively isolated.
127
- if (tailwindDirectives.size > 0) {
122
+ // If there are no @tailwind or @apply rules, we don't consider this CSS
123
+ // file or its dependencies to be dependencies of the context. Can reuse
124
+ // the context even if they change. We may want to think about `@layer`
125
+ // being part of this trigger too, but it's tough because it's impossible
126
+ // for a layer in one file to end up in the actual @tailwind rule in
127
+ // another file since independent sources are effectively isolated.
128
+ if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
128
129
  // Add current css file as a context dependencies.
129
130
  contextDependencies.add(result.opts.from)
130
131
 
@@ -147,12 +148,12 @@ export default function setupTrackingContext(configOrPath) {
147
148
 
148
149
  let candidateFiles = getCandidateFiles(context, tailwindConfig)
149
150
 
150
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
151
- // to be dependencies of the context. Can reuse the context even if they change.
151
+ // If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
152
+ // dependencies to be dependencies of the context. Can reuse the context even if they change.
152
153
  // We may want to think about `@layer` being part of this trigger too, but it's tough
153
154
  // because it's impossible for a layer in one file to end up in the actual @tailwind rule
154
155
  // in another file since independent sources are effectively isolated.
155
- if (tailwindDirectives.size > 0) {
156
+ if (tailwindDirectives.size > 0 || applyDirectives.size > 0) {
156
157
  let fileModifiedMap = getFileModifiedMap(context)
157
158
 
158
159
  // Add template paths as postcss dependencies.
@@ -1,10 +1,46 @@
1
1
  export const env = {
2
- TAILWIND_MODE: process.env.TAILWIND_MODE,
3
2
  NODE_ENV: process.env.NODE_ENV,
4
- DEBUG: process.env.DEBUG !== undefined,
5
- TAILWIND_DISABLE_TOUCH: process.env.TAILWIND_DISABLE_TOUCH !== undefined,
6
- TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR,
3
+ DEBUG: resolveDebug(process.env.DEBUG),
7
4
  }
8
5
  export const contextMap = new Map()
9
6
  export const configContextMap = new Map()
10
7
  export const contextSourcesMap = new Map()
8
+
9
+ export function resolveDebug(debug) {
10
+ if (debug === undefined) {
11
+ return false
12
+ }
13
+
14
+ // Environment variables are strings, so convert to boolean
15
+ if (debug === 'true' || debug === '1') {
16
+ return true
17
+ }
18
+
19
+ if (debug === 'false' || debug === '0') {
20
+ return false
21
+ }
22
+
23
+ // Keep the debug convention into account:
24
+ // DEBUG=* -> This enables all debug modes
25
+ // DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
26
+ // DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
27
+ // DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB
28
+
29
+ if (debug === '*') {
30
+ return true
31
+ }
32
+
33
+ let debuggers = debug.split(',').map((d) => d.split(':')[0])
34
+
35
+ // Ignoring tailwindcss
36
+ if (debuggers.includes('-tailwindcss')) {
37
+ return false
38
+ }
39
+
40
+ // Including tailwindcss
41
+ if (debuggers.includes('tailwindcss')) {
42
+ return true
43
+ }
44
+
45
+ return false
46
+ }
@@ -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
  }
@@ -5,16 +5,22 @@ 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'
10
12
  import { issueFlagNotices } from './featureFlags'
11
13
 
12
14
  export default function processTailwindFeatures(setupContext) {
13
15
  return function (root, result) {
14
- let tailwindDirectives = normalizeTailwindDirectives(root)
16
+ let { tailwindDirectives, applyDirectives } = normalizeTailwindDirectives(root)
17
+
18
+ detectNesting()(root, result)
19
+ partitionApplyAtRules()(root, result)
15
20
 
16
21
  let context = setupContext({
17
22
  tailwindDirectives,
23
+ applyDirectives,
18
24
  registerDependency(dependency) {
19
25
  result.messages.push({
20
26
  plugin: 'tailwindcss',
@@ -35,12 +41,12 @@ export default function processTailwindFeatures(setupContext) {
35
41
 
36
42
  issueFlagNotices(context.tailwindConfig)
37
43
 
38
- detectNesting(context)(root, result)
39
44
  expandTailwindAtRules(context)(root, result)
40
45
  expandApplyAtRules(context)(root, result)
41
46
  evaluateTailwindFunctions(context)(root, result)
42
47
  substituteScreenAtRules(context)(root, result)
43
48
  resolveDefaultsAtRules(context)(root, result)
44
49
  collapseAdjacentRules(context)(root, result)
50
+ collapseDuplicateDeclarations(context)(root, result)
45
51
  }
46
52
  }
@@ -1,24 +1,20 @@
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
- .map((screen) => {
12
- if (screen?.hasOwnProperty?.('raw')) {
13
- return screen.raw
14
- }
5
+ .map((screen) =>
6
+ screen.values.map((screen) => {
7
+ if (screen.raw !== undefined) {
8
+ return screen.raw
9
+ }
15
10
 
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 ')
22
- })
11
+ return [
12
+ screen.min && `(min-width: ${screen.min})`,
13
+ screen.max && `(max-width: ${screen.max})`,
14
+ ]
15
+ .filter(Boolean)
16
+ .join(' and ')
17
+ })
18
+ )
23
19
  .join(', ')
24
20
  }
package/src/util/color.js CHANGED
@@ -5,8 +5,11 @@ let SHORT_HEX = /^#([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i
5
5
  let VALUE = `(?:\\d+|\\d*\\.\\d+)%?`
6
6
  let SEP = `(?:\\s*,\\s*|\\s+)`
7
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*\\)$`
8
+ let RGB = new RegExp(
9
+ `^rgba?\\(\\s*(${VALUE})${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
10
+ )
11
+ let HSL = new RegExp(
12
+ `^hsla?\\(\\s*((?:${VALUE})(?:deg|rad|grad|turn)?)${SEP}(${VALUE})${SEP}(${VALUE})(?:${ALPHA_SEP}(${VALUE}))?\\s*\\)$`
10
13
  )
11
14
 
12
15
  export function parseColor(value) {
@@ -37,13 +40,23 @@ export function parseColor(value) {
37
40
  }
38
41
  }
39
42
 
40
- let match = value.match(RGB_HSL)
43
+ let rgbMatch = value.match(RGB)
44
+
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
+ }
51
+ }
52
+
53
+ let hslMatch = value.match(HSL)
41
54
 
42
- if (match !== null) {
55
+ if (hslMatch !== null) {
43
56
  return {
44
- mode: match[1],
45
- color: [match[2], match[3], match[4]].map((v) => v.toString()),
46
- alpha: match[5]?.toString?.(),
57
+ mode: 'hsl',
58
+ color: [hslMatch[1], hslMatch[2], hslMatch[3]].map((v) => v.toString()),
59
+ alpha: hslMatch[4]?.toString?.(),
47
60
  }
48
61
  }
49
62