tailwindcss 3.1.4 → 3.1.7

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 (90) hide show
  1. package/CHANGELOG.md +37 -2
  2. package/defaultTheme.d.ts +2 -1
  3. package/lib/cli-peer-dependencies.js +12 -4
  4. package/lib/cli.js +78 -75
  5. package/lib/constants.js +19 -12
  6. package/lib/corePluginList.js +5 -3
  7. package/lib/corePlugins.js +197 -187
  8. package/lib/featureFlags.js +14 -7
  9. package/lib/index.js +9 -6
  10. package/lib/lib/cacheInvalidation.js +18 -15
  11. package/lib/lib/collapseAdjacentRules.js +14 -11
  12. package/lib/lib/collapseDuplicateDeclarations.js +11 -8
  13. package/lib/lib/defaultExtractor.js +41 -33
  14. package/lib/lib/detectNesting.js +4 -1
  15. package/lib/lib/evaluateTailwindFunctions.js +75 -44
  16. package/lib/lib/expandApplyAtRules.js +45 -42
  17. package/lib/lib/expandTailwindAtRules.js +153 -150
  18. package/lib/lib/generateRules.js +84 -70
  19. package/lib/lib/getModuleDependencies.js +21 -18
  20. package/lib/lib/normalizeTailwindDirectives.js +10 -7
  21. package/lib/lib/partitionApplyAtRules.js +14 -11
  22. package/lib/lib/regex.js +15 -7
  23. package/lib/lib/resolveDefaultsAtRules.js +92 -85
  24. package/lib/lib/setupContextUtils.js +115 -97
  25. package/lib/lib/setupTrackingContext.js +82 -75
  26. package/lib/lib/sharedState.js +15 -8
  27. package/lib/lib/substituteScreenAtRules.js +8 -5
  28. package/lib/postcss-plugins/nesting/index.js +7 -5
  29. package/lib/postcss-plugins/nesting/plugin.js +7 -4
  30. package/lib/processTailwindFeatures.js +34 -31
  31. package/lib/public/colors.js +6 -4
  32. package/lib/public/create-plugin.js +6 -4
  33. package/lib/public/default-config.js +7 -5
  34. package/lib/public/default-theme.js +7 -5
  35. package/lib/public/resolve-config.js +13 -10
  36. package/lib/util/bigSign.js +4 -1
  37. package/lib/util/buildMediaQuery.js +5 -2
  38. package/lib/util/cloneDeep.js +4 -1
  39. package/lib/util/cloneNodes.js +9 -2
  40. package/lib/util/color.js +11 -3
  41. package/lib/util/configurePlugins.js +4 -1
  42. package/lib/util/createPlugin.js +5 -3
  43. package/lib/util/createUtilityPlugin.js +13 -10
  44. package/lib/util/dataTypes.js +27 -19
  45. package/lib/util/defaults.js +4 -1
  46. package/lib/util/escapeClassName.js +12 -9
  47. package/lib/util/escapeCommas.js +4 -1
  48. package/lib/util/flattenColorPalette.js +5 -3
  49. package/lib/util/formatVariantSelector.js +23 -15
  50. package/lib/util/getAllConfigs.js +12 -9
  51. package/lib/util/hashConfig.js +10 -7
  52. package/lib/util/isKeyframeRule.js +4 -1
  53. package/lib/util/isPlainObject.js +4 -1
  54. package/lib/util/isValidArbitraryValue.js +33 -24
  55. package/lib/util/log.js +12 -5
  56. package/lib/util/nameClass.js +16 -8
  57. package/lib/util/negateValue.js +4 -1
  58. package/lib/util/normalizeConfig.js +26 -23
  59. package/lib/util/normalizeScreens.js +17 -2
  60. package/lib/util/parseAnimationValue.js +42 -39
  61. package/lib/util/parseBoxShadowValue.js +12 -4
  62. package/lib/util/parseDependency.js +35 -32
  63. package/lib/util/parseObjectStyles.js +14 -11
  64. package/lib/util/pluginUtils.js +28 -20
  65. package/lib/util/prefixSelector.js +6 -3
  66. package/lib/util/removeAlphaVariables.js +13 -2
  67. package/lib/util/resolveConfig.js +55 -52
  68. package/lib/util/resolveConfigPath.js +20 -17
  69. package/lib/util/responsive.js +12 -9
  70. package/lib/util/splitAtTopLevelOnly.js +16 -13
  71. package/lib/util/tap.js +4 -1
  72. package/lib/util/toColorValue.js +4 -1
  73. package/lib/util/toPath.js +18 -2
  74. package/lib/util/transformThemeValue.js +10 -7
  75. package/lib/util/validateConfig.js +5 -2
  76. package/lib/util/withAlphaVariable.js +30 -22
  77. package/package.json +12 -12
  78. package/peers/index.js +24 -10
  79. package/resolveConfig.d.ts +3 -0
  80. package/scripts/generate-types.js +53 -0
  81. package/scripts/type-utils.js +27 -0
  82. package/src/corePlugins.js +2 -1
  83. package/src/lib/defaultExtractor.js +7 -1
  84. package/src/lib/evaluateTailwindFunctions.js +41 -15
  85. package/src/lib/generateRules.js +10 -1
  86. package/src/lib/setupContextUtils.js +15 -2
  87. package/src/util/cloneNodes.js +5 -1
  88. package/src/util/formatVariantSelector.js +3 -1
  89. package/types/config.d.ts +7 -5
  90. package/types/generated/default-theme.d.ts +331 -0
@@ -289,6 +289,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
289
289
  },
290
290
  addComponents(components, options) {
291
291
  let defaultOptions = {
292
+ preserveSource: false,
292
293
  respectPrefix: true,
293
294
  respectImportant: false,
294
295
  }
@@ -311,6 +312,7 @@ function buildPluginApi(tailwindConfig, context, { variantList, variantMap, offs
311
312
  },
312
313
  addUtilities(utilities, options) {
313
314
  let defaultOptions = {
315
+ preserveSource: false,
314
316
  respectPrefix: true,
315
317
  respectImportant: true,
316
318
  }
@@ -579,14 +581,14 @@ function collectLayerPlugins(root) {
579
581
  } else if (layerRule.params === 'components') {
580
582
  for (let node of layerRule.nodes) {
581
583
  layerPlugins.push(function ({ addComponents }) {
582
- addComponents(node, { respectPrefix: false })
584
+ addComponents(node, { respectPrefix: false, preserveSource: true })
583
585
  })
584
586
  }
585
587
  layerRule.remove()
586
588
  } else if (layerRule.params === 'utilities') {
587
589
  for (let node of layerRule.nodes) {
588
590
  layerPlugins.push(function ({ addUtilities }) {
589
- addUtilities(node, { respectPrefix: false })
591
+ addUtilities(node, { respectPrefix: false, preserveSource: true })
590
592
  })
591
593
  }
592
594
  layerRule.remove()
@@ -762,6 +764,17 @@ function registerPlugins(plugins, context) {
762
764
  ]
763
765
  }
764
766
 
767
+ if ([].concat(options?.type).includes('color')) {
768
+ classes = [
769
+ ...classes,
770
+ ...classes.flatMap((cls) =>
771
+ Object.keys(context.tailwindConfig.theme.opacity).map(
772
+ (opacity) => `${cls}/${opacity}`
773
+ )
774
+ ),
775
+ ]
776
+ }
777
+
765
778
  return classes
766
779
  })()
767
780
  : [util]
@@ -2,7 +2,11 @@ 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
7
11
 
8
12
  if ('walk' in cloned) {
@@ -35,6 +35,7 @@ export function finalizeSelector(
35
35
  selector,
36
36
  candidate,
37
37
  context,
38
+ isArbitraryVariant,
38
39
 
39
40
  // Split by the separator, but ignore the separator inside square brackets:
40
41
  //
@@ -50,7 +51,8 @@ export function finalizeSelector(
50
51
  ) {
51
52
  let ast = selectorParser().astSync(selector)
52
53
 
53
- if (context?.tailwindConfig?.prefix) {
54
+ // We explicitly DO NOT prefix classes in arbitrary variants
55
+ if (context?.tailwindConfig?.prefix && !isArbitraryVariant) {
54
56
  format = prefixSelector(context.tailwindConfig.prefix, format)
55
57
  }
56
58
 
package/types/config.d.ts CHANGED
@@ -12,6 +12,7 @@ interface RecursiveKeyValuePair<K extends keyof any = string, V = string> {
12
12
  [key: string]: V | RecursiveKeyValuePair<K, V>
13
13
  }
14
14
  type ResolvableTo<T> = T | ((utils: PluginUtils) => T)
15
+ type CSSRuleObject = RecursiveKeyValuePair<string, string | string[]>
15
16
 
16
17
  interface PluginUtils {
17
18
  colors: DefaultColors
@@ -163,6 +164,7 @@ interface ThemeConfig {
163
164
  configuration: Partial<{
164
165
  lineHeight: string
165
166
  letterSpacing: string
167
+ fontWeight: string | number
166
168
  }>
167
169
  ]
168
170
  >
@@ -242,7 +244,7 @@ type ValueType =
242
244
  export interface PluginAPI {
243
245
  // for registering new static utility styles
244
246
  addUtilities(
245
- utilities: RecursiveKeyValuePair | RecursiveKeyValuePair[],
247
+ utilities: CSSRuleObject | CSSRuleObject[],
246
248
  options?: Partial<{
247
249
  respectPrefix: boolean
248
250
  respectImportant: boolean
@@ -250,7 +252,7 @@ export interface PluginAPI {
250
252
  ): void
251
253
  // for registering new dynamic utility styles
252
254
  matchUtilities<T>(
253
- utilities: KeyValuePair<string, (value: T) => RecursiveKeyValuePair>,
255
+ utilities: KeyValuePair<string, (value: T) => CSSRuleObject>,
254
256
  options?: Partial<{
255
257
  respectPrefix: boolean
256
258
  respectImportant: boolean
@@ -261,7 +263,7 @@ export interface PluginAPI {
261
263
  ): void
262
264
  // for registering new static component styles
263
265
  addComponents(
264
- components: RecursiveKeyValuePair | RecursiveKeyValuePair[],
266
+ components: CSSRuleObject | CSSRuleObject[],
265
267
  options?: Partial<{
266
268
  respectPrefix: boolean
267
269
  respectImportant: boolean
@@ -269,7 +271,7 @@ export interface PluginAPI {
269
271
  ): void
270
272
  // for registering new dynamic component styles
271
273
  matchComponents<T>(
272
- components: KeyValuePair<string, (value: T) => RecursiveKeyValuePair>,
274
+ components: KeyValuePair<string, (value: T) => CSSRuleObject>,
273
275
  options?: Partial<{
274
276
  respectPrefix: boolean
275
277
  respectImportant: boolean
@@ -279,7 +281,7 @@ export interface PluginAPI {
279
281
  }>
280
282
  ): void
281
283
  // for registering new base styles
282
- addBase(base: RecursiveKeyValuePair | RecursiveKeyValuePair[]): void
284
+ addBase(base: CSSRuleObject | CSSRuleObject[]): void
283
285
  // for registering custom variants
284
286
  addVariant(name: string, definition: string | string[] | (() => string) | (() => string)[]): void
285
287
  // for looking up values in the user’s theme configuration
@@ -0,0 +1,331 @@
1
+ import { Config } from '../../types'
2
+ type CSSDeclarationList = Record<string, string>
3
+ export type DefaultTheme = Config['theme'] & {
4
+ screens: Record<'sm' | 'md' | 'lg' | 'xl' | '2xl', string>
5
+ columns: Record<
6
+ | '1'
7
+ | '2'
8
+ | '3'
9
+ | '4'
10
+ | '5'
11
+ | '6'
12
+ | '7'
13
+ | '8'
14
+ | '9'
15
+ | '10'
16
+ | '11'
17
+ | '12'
18
+ | 'auto'
19
+ | '3xs'
20
+ | '2xs'
21
+ | 'xs'
22
+ | 'sm'
23
+ | 'md'
24
+ | 'lg'
25
+ | 'xl'
26
+ | '2xl'
27
+ | '3xl'
28
+ | '4xl'
29
+ | '5xl'
30
+ | '6xl'
31
+ | '7xl',
32
+ string
33
+ >
34
+ spacing: Record<
35
+ | '0'
36
+ | '1'
37
+ | '2'
38
+ | '3'
39
+ | '4'
40
+ | '5'
41
+ | '6'
42
+ | '7'
43
+ | '8'
44
+ | '9'
45
+ | '10'
46
+ | '11'
47
+ | '12'
48
+ | '14'
49
+ | '16'
50
+ | '20'
51
+ | '24'
52
+ | '28'
53
+ | '32'
54
+ | '36'
55
+ | '40'
56
+ | '44'
57
+ | '48'
58
+ | '52'
59
+ | '56'
60
+ | '60'
61
+ | '64'
62
+ | '72'
63
+ | '80'
64
+ | '96'
65
+ | 'px'
66
+ | '0.5'
67
+ | '1.5'
68
+ | '2.5'
69
+ | '3.5',
70
+ string
71
+ >
72
+ animation: Record<'none' | 'spin' | 'ping' | 'pulse' | 'bounce', string>
73
+ aspectRatio: Record<'auto' | 'square' | 'video', string>
74
+ backgroundImage: Record<
75
+ | 'none'
76
+ | 'gradient-to-t'
77
+ | 'gradient-to-tr'
78
+ | 'gradient-to-r'
79
+ | 'gradient-to-br'
80
+ | 'gradient-to-b'
81
+ | 'gradient-to-bl'
82
+ | 'gradient-to-l'
83
+ | 'gradient-to-tl',
84
+ string
85
+ >
86
+ backgroundPosition: Record<
87
+ | 'bottom'
88
+ | 'center'
89
+ | 'left'
90
+ | 'left-bottom'
91
+ | 'left-top'
92
+ | 'right'
93
+ | 'right-bottom'
94
+ | 'right-top'
95
+ | 'top',
96
+ string
97
+ >
98
+ backgroundSize: Record<'auto' | 'cover' | 'contain', string>
99
+ blur: Record<'0' | 'none' | 'sm' | 'DEFAULT' | 'md' | 'lg' | 'xl' | '2xl' | '3xl', string>
100
+ brightness: Record<
101
+ '0' | '50' | '75' | '90' | '95' | '100' | '105' | '110' | '125' | '150' | '200',
102
+ string
103
+ >
104
+ borderRadius: Record<
105
+ 'none' | 'sm' | 'DEFAULT' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | 'full',
106
+ string
107
+ >
108
+ borderWidth: Record<'0' | '2' | '4' | '8' | 'DEFAULT', string>
109
+ boxShadow: Record<'sm' | 'DEFAULT' | 'md' | 'lg' | 'xl' | '2xl' | 'inner' | 'none', string>
110
+ contrast: Record<'0' | '50' | '75' | '100' | '125' | '150' | '200', string>
111
+ content: Record<'none', string>
112
+ cursor: Record<
113
+ | 'auto'
114
+ | 'default'
115
+ | 'pointer'
116
+ | 'wait'
117
+ | 'text'
118
+ | 'move'
119
+ | 'help'
120
+ | 'not-allowed'
121
+ | 'none'
122
+ | 'context-menu'
123
+ | 'progress'
124
+ | 'cell'
125
+ | 'crosshair'
126
+ | 'vertical-text'
127
+ | 'alias'
128
+ | 'copy'
129
+ | 'no-drop'
130
+ | 'grab'
131
+ | 'grabbing'
132
+ | 'all-scroll'
133
+ | 'col-resize'
134
+ | 'row-resize'
135
+ | 'n-resize'
136
+ | 'e-resize'
137
+ | 's-resize'
138
+ | 'w-resize'
139
+ | 'ne-resize'
140
+ | 'nw-resize'
141
+ | 'se-resize'
142
+ | 'sw-resize'
143
+ | 'ew-resize'
144
+ | 'ns-resize'
145
+ | 'nesw-resize'
146
+ | 'nwse-resize'
147
+ | 'zoom-in'
148
+ | 'zoom-out',
149
+ string
150
+ >
151
+ dropShadow: Record<'sm' | 'DEFAULT' | 'md' | 'lg' | 'xl' | '2xl' | 'none', string | string[]>
152
+ grayscale: Record<'0' | 'DEFAULT', string>
153
+ hueRotate: Record<'0' | '15' | '30' | '60' | '90' | '180', string>
154
+ invert: Record<'0' | 'DEFAULT', string>
155
+ flex: Record<'1' | 'auto' | 'initial' | 'none', string>
156
+ flexGrow: Record<'0' | 'DEFAULT', string>
157
+ flexShrink: Record<'0' | 'DEFAULT', string>
158
+ fontFamily: Record<'sans' | 'serif' | 'mono', string[]>
159
+ fontSize: Record<
160
+ | 'xs'
161
+ | 'sm'
162
+ | 'base'
163
+ | 'lg'
164
+ | 'xl'
165
+ | '2xl'
166
+ | '3xl'
167
+ | '4xl'
168
+ | '5xl'
169
+ | '6xl'
170
+ | '7xl'
171
+ | '8xl'
172
+ | '9xl',
173
+ [string, { lineHeight: string }]
174
+ >
175
+ fontWeight: Record<
176
+ | 'thin'
177
+ | 'extralight'
178
+ | 'light'
179
+ | 'normal'
180
+ | 'medium'
181
+ | 'semibold'
182
+ | 'bold'
183
+ | 'extrabold'
184
+ | 'black',
185
+ string
186
+ >
187
+ gridAutoColumns: Record<'auto' | 'min' | 'max' | 'fr', string>
188
+ gridAutoRows: Record<'auto' | 'min' | 'max' | 'fr', string>
189
+ gridColumn: Record<
190
+ | 'auto'
191
+ | 'span-1'
192
+ | 'span-2'
193
+ | 'span-3'
194
+ | 'span-4'
195
+ | 'span-5'
196
+ | 'span-6'
197
+ | 'span-7'
198
+ | 'span-8'
199
+ | 'span-9'
200
+ | 'span-10'
201
+ | 'span-11'
202
+ | 'span-12'
203
+ | 'span-full',
204
+ string
205
+ >
206
+ gridColumnEnd: Record<
207
+ '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | 'auto',
208
+ string
209
+ >
210
+ gridColumnStart: Record<
211
+ '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | '13' | 'auto',
212
+ string
213
+ >
214
+ gridRow: Record<
215
+ 'auto' | 'span-1' | 'span-2' | 'span-3' | 'span-4' | 'span-5' | 'span-6' | 'span-full',
216
+ string
217
+ >
218
+ gridRowStart: Record<'1' | '2' | '3' | '4' | '5' | '6' | '7' | 'auto', string>
219
+ gridRowEnd: Record<'1' | '2' | '3' | '4' | '5' | '6' | '7' | 'auto', string>
220
+ gridTemplateColumns: Record<
221
+ '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | '10' | '11' | '12' | 'none',
222
+ string
223
+ >
224
+ gridTemplateRows: Record<'1' | '2' | '3' | '4' | '5' | '6' | 'none', string>
225
+ keyframes: Record<'spin' | 'ping' | 'pulse' | 'bounce', Record<string, CSSDeclarationList>>
226
+ letterSpacing: Record<'tighter' | 'tight' | 'normal' | 'wide' | 'wider' | 'widest', string>
227
+ lineHeight: Record<
228
+ | '3'
229
+ | '4'
230
+ | '5'
231
+ | '6'
232
+ | '7'
233
+ | '8'
234
+ | '9'
235
+ | '10'
236
+ | 'none'
237
+ | 'tight'
238
+ | 'snug'
239
+ | 'normal'
240
+ | 'relaxed'
241
+ | 'loose',
242
+ string
243
+ >
244
+ listStyleType: Record<'none' | 'disc' | 'decimal', string>
245
+ minHeight: Record<'0' | 'full' | 'screen' | 'min' | 'max' | 'fit', string>
246
+ minWidth: Record<'0' | 'full' | 'min' | 'max' | 'fit', string>
247
+ objectPosition: Record<
248
+ | 'bottom'
249
+ | 'center'
250
+ | 'left'
251
+ | 'left-bottom'
252
+ | 'left-top'
253
+ | 'right'
254
+ | 'right-bottom'
255
+ | 'right-top'
256
+ | 'top',
257
+ string
258
+ >
259
+ opacity: Record<
260
+ | '0'
261
+ | '5'
262
+ | '10'
263
+ | '20'
264
+ | '25'
265
+ | '30'
266
+ | '40'
267
+ | '50'
268
+ | '60'
269
+ | '70'
270
+ | '75'
271
+ | '80'
272
+ | '90'
273
+ | '95'
274
+ | '100',
275
+ string
276
+ >
277
+ order: Record<
278
+ | '1'
279
+ | '2'
280
+ | '3'
281
+ | '4'
282
+ | '5'
283
+ | '6'
284
+ | '7'
285
+ | '8'
286
+ | '9'
287
+ | '10'
288
+ | '11'
289
+ | '12'
290
+ | 'first'
291
+ | 'last'
292
+ | 'none',
293
+ string
294
+ >
295
+ outlineOffset: Record<'0' | '1' | '2' | '4' | '8', string>
296
+ outlineWidth: Record<'0' | '1' | '2' | '4' | '8', string>
297
+ ringOffsetWidth: Record<'0' | '1' | '2' | '4' | '8', string>
298
+ ringWidth: Record<'0' | '1' | '2' | '4' | '8' | 'DEFAULT', string>
299
+ rotate: Record<'0' | '1' | '2' | '3' | '6' | '12' | '45' | '90' | '180', string>
300
+ saturate: Record<'0' | '50' | '100' | '150' | '200', string>
301
+ scale: Record<'0' | '50' | '75' | '90' | '95' | '100' | '105' | '110' | '125' | '150', string>
302
+ sepia: Record<'0' | 'DEFAULT', string>
303
+ skew: Record<'0' | '1' | '2' | '3' | '6' | '12', string>
304
+ strokeWidth: Record<'0' | '1' | '2', string>
305
+ textDecorationThickness: Record<'0' | '1' | '2' | '4' | '8' | 'auto' | 'from-font', string>
306
+ textUnderlineOffset: Record<'0' | '1' | '2' | '4' | '8' | 'auto', string>
307
+ transformOrigin: Record<
308
+ | 'center'
309
+ | 'top'
310
+ | 'top-right'
311
+ | 'right'
312
+ | 'bottom-right'
313
+ | 'bottom'
314
+ | 'bottom-left'
315
+ | 'left'
316
+ | 'top-left',
317
+ string
318
+ >
319
+ transitionDelay: Record<'75' | '100' | '150' | '200' | '300' | '500' | '700' | '1000', string>
320
+ transitionDuration: Record<
321
+ '75' | '100' | '150' | '200' | '300' | '500' | '700' | '1000' | 'DEFAULT',
322
+ string
323
+ >
324
+ transitionProperty: Record<
325
+ 'none' | 'all' | 'DEFAULT' | 'colors' | 'opacity' | 'shadow' | 'transform',
326
+ string
327
+ >
328
+ transitionTimingFunction: Record<'DEFAULT' | 'linear' | 'in' | 'out' | 'in-out', string>
329
+ willChange: Record<'auto' | 'scroll' | 'contents' | 'transform', string>
330
+ zIndex: Record<'0' | '10' | '20' | '30' | '40' | '50' | 'auto', string>
331
+ }