tailwindcss 0.0.0-insiders.bbafc8e → 0.0.0-insiders.bbf2b1b

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 (128) hide show
  1. package/CHANGELOG.md +163 -8
  2. package/README.md +6 -3
  3. package/colors.d.ts +3 -0
  4. package/defaultConfig.d.ts +3 -0
  5. package/defaultTheme.d.ts +4 -0
  6. package/lib/cli-peer-dependencies.js +20 -7
  7. package/lib/cli.js +314 -247
  8. package/lib/constants.js +27 -20
  9. package/lib/corePluginList.js +6 -3
  10. package/lib/corePlugins.js +1719 -1628
  11. package/lib/css/preflight.css +1 -8
  12. package/lib/featureFlags.js +27 -18
  13. package/lib/index.js +17 -15
  14. package/lib/lib/cacheInvalidation.js +45 -24
  15. package/lib/lib/collapseAdjacentRules.js +14 -9
  16. package/lib/lib/collapseDuplicateDeclarations.js +12 -9
  17. package/lib/lib/defaultExtractor.js +220 -33
  18. package/lib/lib/detectNesting.js +13 -10
  19. package/lib/lib/evaluateTailwindFunctions.js +101 -54
  20. package/lib/lib/expandApplyAtRules.js +254 -209
  21. package/lib/lib/expandTailwindAtRules.js +86 -69
  22. package/lib/lib/generateRules.js +244 -145
  23. package/lib/lib/getModuleDependencies.js +11 -8
  24. package/lib/lib/normalizeTailwindDirectives.js +35 -32
  25. package/lib/lib/partitionApplyAtRules.js +11 -8
  26. package/lib/lib/regex.js +60 -0
  27. package/lib/lib/resolveDefaultsAtRules.js +89 -71
  28. package/lib/lib/setupContextUtils.js +290 -205
  29. package/lib/lib/setupTrackingContext.js +44 -37
  30. package/lib/lib/sharedState.js +22 -16
  31. package/lib/lib/substituteScreenAtRules.js +11 -9
  32. package/lib/postcss-plugins/nesting/README.md +2 -2
  33. package/lib/postcss-plugins/nesting/index.js +8 -6
  34. package/lib/postcss-plugins/nesting/plugin.js +18 -16
  35. package/lib/processTailwindFeatures.js +31 -28
  36. package/lib/public/colors.js +247 -245
  37. package/lib/public/create-plugin.js +6 -4
  38. package/lib/public/default-config.js +7 -5
  39. package/lib/public/default-theme.js +7 -5
  40. package/lib/public/resolve-config.js +8 -5
  41. package/lib/util/bigSign.js +4 -1
  42. package/lib/util/buildMediaQuery.js +7 -5
  43. package/lib/util/cloneDeep.js +7 -6
  44. package/lib/util/cloneNodes.js +10 -3
  45. package/lib/util/color.js +53 -54
  46. package/lib/util/configurePlugins.js +4 -1
  47. package/lib/util/createPlugin.js +6 -5
  48. package/lib/util/createUtilityPlugin.js +9 -7
  49. package/lib/util/dataTypes.js +110 -100
  50. package/lib/util/defaults.js +4 -1
  51. package/lib/util/escapeClassName.js +7 -4
  52. package/lib/util/escapeCommas.js +5 -2
  53. package/lib/util/flattenColorPalette.js +9 -10
  54. package/lib/util/formatVariantSelector.js +100 -85
  55. package/lib/util/getAllConfigs.js +17 -8
  56. package/lib/util/hashConfig.js +6 -3
  57. package/lib/util/isKeyframeRule.js +5 -2
  58. package/lib/util/isPlainObject.js +5 -2
  59. package/lib/util/isValidArbitraryValue.js +21 -13
  60. package/lib/util/log.js +18 -12
  61. package/lib/util/nameClass.js +17 -9
  62. package/lib/util/negateValue.js +8 -6
  63. package/lib/util/normalizeConfig.js +84 -71
  64. package/lib/util/normalizeScreens.js +22 -8
  65. package/lib/util/parseAnimationValue.js +42 -40
  66. package/lib/util/parseBoxShadowValue.js +29 -62
  67. package/lib/util/parseDependency.js +18 -15
  68. package/lib/util/parseObjectStyles.js +10 -7
  69. package/lib/util/pluginUtils.js +47 -31
  70. package/lib/util/prefixSelector.js +7 -4
  71. package/lib/util/removeAlphaVariables.js +29 -0
  72. package/lib/util/resolveConfig.js +88 -84
  73. package/lib/util/resolveConfigPath.js +10 -7
  74. package/lib/util/responsive.js +8 -5
  75. package/lib/util/splitAtTopLevelOnly.js +93 -0
  76. package/lib/util/tap.js +4 -1
  77. package/lib/util/toColorValue.js +5 -2
  78. package/lib/util/toPath.js +20 -4
  79. package/lib/util/transformThemeValue.js +30 -25
  80. package/lib/util/validateConfig.js +24 -0
  81. package/lib/util/withAlphaVariable.js +23 -15
  82. package/package.json +32 -27
  83. package/peers/index.js +8612 -4245
  84. package/plugin.d.ts +11 -0
  85. package/resolveConfig.d.ts +3 -0
  86. package/scripts/generate-types.js +105 -0
  87. package/scripts/type-utils.js +27 -0
  88. package/src/cli-peer-dependencies.js +7 -1
  89. package/src/cli.js +125 -25
  90. package/src/corePluginList.js +1 -1
  91. package/src/corePlugins.js +145 -49
  92. package/src/css/preflight.css +1 -8
  93. package/src/featureFlags.js +2 -2
  94. package/src/lib/collapseAdjacentRules.js +5 -1
  95. package/src/lib/defaultExtractor.js +193 -35
  96. package/src/lib/evaluateTailwindFunctions.js +56 -6
  97. package/src/lib/expandApplyAtRules.js +252 -187
  98. package/src/lib/expandTailwindAtRules.js +4 -4
  99. package/src/lib/generateRules.js +156 -59
  100. package/src/lib/regex.js +74 -0
  101. package/src/lib/resolveDefaultsAtRules.js +53 -36
  102. package/src/lib/setupContextUtils.js +142 -46
  103. package/src/lib/setupTrackingContext.js +5 -1
  104. package/src/postcss-plugins/nesting/README.md +2 -2
  105. package/src/util/cloneNodes.js +5 -1
  106. package/src/util/color.js +25 -21
  107. package/src/util/dataTypes.js +13 -7
  108. package/src/util/formatVariantSelector.js +82 -63
  109. package/src/util/getAllConfigs.js +8 -0
  110. package/src/util/log.js +1 -1
  111. package/src/util/normalizeConfig.js +0 -8
  112. package/src/util/parseBoxShadowValue.js +3 -50
  113. package/src/util/pluginUtils.js +13 -1
  114. package/src/util/removeAlphaVariables.js +24 -0
  115. package/src/util/resolveConfig.js +66 -52
  116. package/src/util/splitAtTopLevelOnly.js +71 -0
  117. package/src/util/toPath.js +1 -1
  118. package/src/util/transformThemeValue.js +4 -2
  119. package/src/util/validateConfig.js +13 -0
  120. package/src/util/withAlphaVariable.js +1 -1
  121. package/stubs/defaultConfig.stub.js +5 -1
  122. package/stubs/simpleConfig.stub.js +1 -0
  123. package/types/config.d.ts +327 -0
  124. package/types/generated/.gitkeep +0 -0
  125. package/types/generated/colors.d.ts +276 -0
  126. package/types/generated/corePluginList.d.ts +1 -0
  127. package/types/generated/default-theme.d.ts +331 -0
  128. package/types/index.d.ts +7 -0
@@ -3,6 +3,7 @@ import * as path from 'path'
3
3
  import postcss from 'postcss'
4
4
  import createUtilityPlugin from './util/createUtilityPlugin'
5
5
  import buildMediaQuery from './util/buildMediaQuery'
6
+ import escapeClassName from './util/escapeClassName'
6
7
  import parseAnimationValue from './util/parseAnimationValue'
7
8
  import flattenColorPalette from './util/flattenColorPalette'
8
9
  import withAlphaVariable, { withAlphaValue } from './util/withAlphaVariable'
@@ -13,19 +14,35 @@ import { version as tailwindVersion } from '../package.json'
13
14
  import log from './util/log'
14
15
  import { normalizeScreens } from './util/normalizeScreens'
15
16
  import { formatBoxShadowValue, parseBoxShadowValue } from './util/parseBoxShadowValue'
17
+ import { removeAlphaVariables } from './util/removeAlphaVariables'
18
+ import { flagEnabled } from './featureFlags'
16
19
 
17
20
  export let variantPlugins = {
18
21
  pseudoElementVariants: ({ addVariant }) => {
19
22
  addVariant('first-letter', '&::first-letter')
20
23
  addVariant('first-line', '&::first-line')
21
24
 
22
- addVariant('marker', ['& *::marker', '&::marker'])
25
+ addVariant('marker', [
26
+ ({ container }) => {
27
+ removeAlphaVariables(container, ['--tw-text-opacity'])
28
+
29
+ return '& *::marker'
30
+ },
31
+ ({ container }) => {
32
+ removeAlphaVariables(container, ['--tw-text-opacity'])
33
+
34
+ return '&::marker'
35
+ },
36
+ ])
37
+
23
38
  addVariant('selection', ['& *::selection', '&::selection'])
24
39
 
25
40
  addVariant('file', '&::file-selector-button')
26
41
 
27
42
  addVariant('placeholder', '&::placeholder')
28
43
 
44
+ addVariant('backdrop', '&::backdrop')
45
+
29
46
  addVariant('before', ({ container }) => {
30
47
  container.walkRules((rule) => {
31
48
  let foundContent = false
@@ -57,14 +74,14 @@ export let variantPlugins = {
57
74
  })
58
75
  },
59
76
 
60
- pseudoClassVariants: ({ addVariant }) => {
77
+ pseudoClassVariants: ({ addVariant, config }) => {
61
78
  let pseudoVariants = [
62
79
  // Positional
63
- ['first', ':first-child'],
64
- ['last', ':last-child'],
65
- ['only', ':only-child'],
66
- ['odd', ':nth-child(odd)'],
67
- ['even', ':nth-child(even)'],
80
+ ['first', '&:first-child'],
81
+ ['last', '&:last-child'],
82
+ ['only', '&:only-child'],
83
+ ['odd', '&:nth-child(odd)'],
84
+ ['even', '&:nth-child(even)'],
68
85
  'first-of-type',
69
86
  'last-of-type',
70
87
  'only-of-type',
@@ -73,27 +90,17 @@ export let variantPlugins = {
73
90
  [
74
91
  'visited',
75
92
  ({ container }) => {
76
- let toRemove = ['--tw-text-opacity', '--tw-border-opacity', '--tw-bg-opacity']
77
-
78
- container.walkDecls((decl) => {
79
- if (toRemove.includes(decl.prop)) {
80
- decl.remove()
93
+ removeAlphaVariables(container, [
94
+ '--tw-text-opacity',
95
+ '--tw-border-opacity',
96
+ '--tw-bg-opacity',
97
+ ])
81
98
 
82
- return
83
- }
84
-
85
- for (const varName of toRemove) {
86
- if (decl.value.includes(`/ var(${varName})`)) {
87
- decl.value = decl.value.replace(`/ var(${varName})`, '')
88
- }
89
- }
90
- })
91
-
92
- return ':visited'
99
+ return '&:visited'
93
100
  },
94
101
  ],
95
102
  'target',
96
- ['open', '[open]'],
103
+ ['open', '&[open]'],
97
104
 
98
105
  // Forms
99
106
  'default',
@@ -101,6 +108,7 @@ export let variantPlugins = {
101
108
  'indeterminate',
102
109
  'placeholder-shown',
103
110
  'autofill',
111
+ 'optional',
104
112
  'required',
105
113
  'valid',
106
114
  'invalid',
@@ -113,18 +121,24 @@ export let variantPlugins = {
113
121
 
114
122
  // Interactive
115
123
  'focus-within',
116
- 'hover',
124
+ [
125
+ 'hover',
126
+ !flagEnabled(config(), 'hoverOnlyWhenSupported')
127
+ ? '&:hover'
128
+ : '@media (hover: hover) and (pointer: fine) { &:hover }',
129
+ ],
117
130
  'focus',
118
131
  'focus-visible',
119
132
  'active',
133
+ 'enabled',
120
134
  'disabled',
121
- ].map((variant) => (Array.isArray(variant) ? variant : [variant, `:${variant}`]))
135
+ ].map((variant) => (Array.isArray(variant) ? variant : [variant, `&:${variant}`]))
122
136
 
123
137
  for (let [variantName, state] of pseudoVariants) {
124
138
  addVariant(variantName, (ctx) => {
125
139
  let result = typeof state === 'function' ? state(ctx) : state
126
140
 
127
- return `&${result}`
141
+ return result
128
142
  })
129
143
  }
130
144
 
@@ -132,7 +146,7 @@ export let variantPlugins = {
132
146
  addVariant(`group-${variantName}`, (ctx) => {
133
147
  let result = typeof state === 'function' ? state(ctx) : state
134
148
 
135
- return `:merge(.group)${result} &`
149
+ return result.replace(/&(\S+)/, ':merge(.group)$1 &')
136
150
  })
137
151
  }
138
152
 
@@ -140,7 +154,7 @@ export let variantPlugins = {
140
154
  addVariant(`peer-${variantName}`, (ctx) => {
141
155
  let result = typeof state === 'function' ? state(ctx) : state
142
156
 
143
- return `:merge(.peer)${result} ~ &`
157
+ return result.replace(/&(\S+)/, ':merge(.peer)$1 ~ &')
144
158
  })
145
159
  }
146
160
  },
@@ -171,7 +185,8 @@ export let variantPlugins = {
171
185
  },
172
186
 
173
187
  darkVariants: ({ config, addVariant }) => {
174
- let mode = config('darkMode', 'media')
188
+ let [mode, className = '.dark'] = [].concat(config('darkMode', 'media'))
189
+
175
190
  if (mode === false) {
176
191
  mode = 'media'
177
192
  log.warn('darkmode-false', [
@@ -182,7 +197,7 @@ export let variantPlugins = {
182
197
  }
183
198
 
184
199
  if (mode === 'class') {
185
- addVariant('dark', '.dark &')
200
+ addVariant('dark', `${className} &`)
186
201
  } else if (mode === 'media') {
187
202
  addVariant('dark', '@media (prefers-color-scheme: dark)')
188
203
  }
@@ -204,6 +219,11 @@ export let variantPlugins = {
204
219
  addVariant('portrait', '@media (orientation: portrait)')
205
220
  addVariant('landscape', '@media (orientation: landscape)')
206
221
  },
222
+
223
+ prefersContrastVariants: ({ addVariant }) => {
224
+ addVariant('contrast-more', '@media (prefers-contrast: more)')
225
+ addVariant('contrast-less', '@media (prefers-contrast: less)')
226
+ },
207
227
  }
208
228
 
209
229
  let cssTransformValue = [
@@ -527,6 +547,41 @@ export let corePlugins = {
527
547
  })
528
548
  },
529
549
 
550
+ borderSpacing: ({ addDefaults, matchUtilities, theme }) => {
551
+ addDefaults('border-spacing', {
552
+ '--tw-border-spacing-x': 0,
553
+ '--tw-border-spacing-y': 0,
554
+ })
555
+
556
+ matchUtilities(
557
+ {
558
+ 'border-spacing': (value) => {
559
+ return {
560
+ '--tw-border-spacing-x': value,
561
+ '--tw-border-spacing-y': value,
562
+ '@defaults border-spacing': {},
563
+ 'border-spacing': 'var(--tw-border-spacing-x) var(--tw-border-spacing-y)',
564
+ }
565
+ },
566
+ 'border-spacing-x': (value) => {
567
+ return {
568
+ '--tw-border-spacing-x': value,
569
+ '@defaults border-spacing': {},
570
+ 'border-spacing': 'var(--tw-border-spacing-x) var(--tw-border-spacing-y)',
571
+ }
572
+ },
573
+ 'border-spacing-y': (value) => {
574
+ return {
575
+ '--tw-border-spacing-y': value,
576
+ '@defaults border-spacing': {},
577
+ 'border-spacing': 'var(--tw-border-spacing-x) var(--tw-border-spacing-y)',
578
+ }
579
+ },
580
+ },
581
+ { values: theme('borderSpacing') }
582
+ )
583
+ },
584
+
530
585
  transformOrigin: createUtilityPlugin('transformOrigin', [['origin', ['transformOrigin']]]),
531
586
  translate: createUtilityPlugin(
532
587
  'translate',
@@ -611,8 +666,8 @@ export let corePlugins = {
611
666
  })
612
667
  },
613
668
 
614
- animation: ({ matchUtilities, theme, prefix }) => {
615
- let prefixName = (name) => prefix(`.${name}`).slice(1)
669
+ animation: ({ matchUtilities, theme, config }) => {
670
+ let prefixName = (name) => `${config('prefix')}${escapeClassName(name)}`
616
671
  let keyframes = Object.fromEntries(
617
672
  Object.entries(theme('keyframes') ?? {}).map(([key, value]) => {
618
673
  return [key, { [`@keyframes ${prefixName(key)}`]: value }]
@@ -844,6 +899,7 @@ export let corePlugins = {
844
899
  addUtilities({
845
900
  '.grid-flow-row': { gridAutoFlow: 'row' },
846
901
  '.grid-flow-col': { gridAutoFlow: 'column' },
902
+ '.grid-flow-dense': { gridAutoFlow: 'dense' },
847
903
  '.grid-flow-row-dense': { gridAutoFlow: 'row dense' },
848
904
  '.grid-flow-col-dense': { gridAutoFlow: 'column dense' },
849
905
  })
@@ -1384,7 +1440,8 @@ export let corePlugins = {
1384
1440
 
1385
1441
  return {
1386
1442
  '--tw-gradient-from': toColorValue(value, 'from'),
1387
- '--tw-gradient-stops': `var(--tw-gradient-from), var(--tw-gradient-to, ${transparentToValue})`,
1443
+ '--tw-gradient-to': transparentToValue,
1444
+ '--tw-gradient-stops': `var(--tw-gradient-from), var(--tw-gradient-to)`,
1388
1445
  }
1389
1446
  },
1390
1447
  },
@@ -1396,10 +1453,11 @@ export let corePlugins = {
1396
1453
  let transparentToValue = transparentTo(value)
1397
1454
 
1398
1455
  return {
1456
+ '--tw-gradient-to': transparentToValue,
1399
1457
  '--tw-gradient-stops': `var(--tw-gradient-from), ${toColorValue(
1400
1458
  value,
1401
1459
  'via'
1402
- )}, var(--tw-gradient-to, ${transparentToValue})`,
1460
+ )}, var(--tw-gradient-to)`,
1403
1461
  }
1404
1462
  },
1405
1463
  },
@@ -1522,6 +1580,8 @@ export let corePlugins = {
1522
1580
  '.text-center': { 'text-align': 'center' },
1523
1581
  '.text-right': { 'text-align': 'right' },
1524
1582
  '.text-justify': { 'text-align': 'justify' },
1583
+ '.text-start': { 'text-align': 'start' },
1584
+ '.text-end': { 'text-align': 'end' },
1525
1585
  })
1526
1586
  },
1527
1587
 
@@ -1544,16 +1604,35 @@ export let corePlugins = {
1544
1604
  matchUtilities({ align: (value) => ({ 'vertical-align': value }) })
1545
1605
  },
1546
1606
 
1547
- fontFamily: createUtilityPlugin('fontFamily', [['font', ['fontFamily']]], {
1548
- type: ['lookup', 'generic-name', 'family-name'],
1549
- }),
1607
+ fontFamily: ({ matchUtilities, theme }) => {
1608
+ matchUtilities(
1609
+ {
1610
+ font: (value) => {
1611
+ let [families, options = {}] =
1612
+ Array.isArray(value) && isPlainObject(value[1]) ? value : [value]
1613
+ let { fontFeatureSettings } = options
1614
+
1615
+ return {
1616
+ 'font-family': Array.isArray(families) ? families.join(', ') : families,
1617
+ ...(fontFeatureSettings === undefined
1618
+ ? {}
1619
+ : { 'font-feature-settings': fontFeatureSettings }),
1620
+ }
1621
+ },
1622
+ },
1623
+ {
1624
+ values: theme('fontFamily'),
1625
+ type: ['lookup', 'generic-name', 'family-name'],
1626
+ }
1627
+ )
1628
+ },
1550
1629
 
1551
1630
  fontSize: ({ matchUtilities, theme }) => {
1552
1631
  matchUtilities(
1553
1632
  {
1554
1633
  text: (value) => {
1555
1634
  let [fontSize, options] = Array.isArray(value) ? value : [value]
1556
- let { lineHeight, letterSpacing } = isPlainObject(options)
1635
+ let { lineHeight, letterSpacing, fontWeight } = isPlainObject(options)
1557
1636
  ? options
1558
1637
  : { lineHeight: options }
1559
1638
 
@@ -1561,6 +1640,7 @@ export let corePlugins = {
1561
1640
  'font-size': fontSize,
1562
1641
  ...(lineHeight === undefined ? {} : { 'line-height': lineHeight }),
1563
1642
  ...(letterSpacing === undefined ? {} : { 'letter-spacing': letterSpacing }),
1643
+ ...(fontWeight === undefined ? {} : { 'font-weight': fontWeight }),
1564
1644
  }
1565
1645
  },
1566
1646
  },
@@ -1828,6 +1908,7 @@ export let corePlugins = {
1828
1908
  '.mix-blend-saturation': { 'mix-blend-mode': 'saturation' },
1829
1909
  '.mix-blend-color': { 'mix-blend-mode': 'color' },
1830
1910
  '.mix-blend-luminosity': { 'mix-blend-mode': 'luminosity' },
1911
+ '.mix-blend-plus-lighter': { 'mix-blend-mode': 'plus-lighter' },
1831
1912
  })
1832
1913
  },
1833
1914
 
@@ -1922,13 +2003,24 @@ export let corePlugins = {
1922
2003
  )
1923
2004
  },
1924
2005
 
1925
- ringWidth: ({ matchUtilities, addDefaults, addUtilities, theme }) => {
1926
- let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5')
1927
- let ringColorDefault = withAlphaValue(
1928
- theme('ringColor')?.DEFAULT,
1929
- ringOpacityDefault,
1930
- `rgb(147 197 253 / ${ringOpacityDefault})`
1931
- )
2006
+ ringWidth: ({ matchUtilities, addDefaults, addUtilities, theme, config }) => {
2007
+ let ringColorDefault = (() => {
2008
+ if (flagEnabled(config(), 'respectDefaultRingColorOpacity')) {
2009
+ return theme('ringColor.DEFAULT')
2010
+ }
2011
+
2012
+ let ringOpacityDefault = theme('ringOpacity.DEFAULT', '0.5')
2013
+
2014
+ if (!theme('ringColor')?.DEFAULT) {
2015
+ return `rgb(147 197 253 / ${ringOpacityDefault})`
2016
+ }
2017
+
2018
+ return withAlphaValue(
2019
+ theme('ringColor')?.DEFAULT,
2020
+ ringOpacityDefault,
2021
+ `rgb(147 197 253 / ${ringOpacityDefault})`
2022
+ )
2023
+ })()
1932
2024
 
1933
2025
  addDefaults('ring-width', {
1934
2026
  '--tw-ring-inset': ' ',
@@ -1992,9 +2084,13 @@ export let corePlugins = {
1992
2084
  )
1993
2085
  },
1994
2086
 
1995
- ringOpacity: createUtilityPlugin('ringOpacity', [['ring-opacity', ['--tw-ring-opacity']]], {
1996
- filterDefault: true,
1997
- }),
2087
+ ringOpacity: (helpers) => {
2088
+ let { config } = helpers
2089
+
2090
+ return createUtilityPlugin('ringOpacity', [['ring-opacity', ['--tw-ring-opacity']]], {
2091
+ filterDefault: !flagEnabled(config(), 'respectDefaultRingColorOpacity'),
2092
+ })(helpers)
2093
+ },
1998
2094
  ringOffsetWidth: createUtilityPlugin(
1999
2095
  'ringOffsetWidth',
2000
2096
  [['ring-offset', ['--tw-ring-offset-width']]],
@@ -160,6 +160,7 @@ select,
160
160
  textarea {
161
161
  font-family: inherit; /* 1 */
162
162
  font-size: 100%; /* 1 */
163
+ font-weight: inherit; /* 1 */
163
164
  line-height: inherit; /* 1 */
164
165
  color: inherit; /* 1 */
165
166
  margin: 0; /* 2 */
@@ -357,11 +358,3 @@ video {
357
358
  max-width: 100%;
358
359
  height: auto;
359
360
  }
360
-
361
- /*
362
- Ensure the default browser behavior of the `hidden` attribute.
363
- */
364
-
365
- [hidden] {
366
- display: none;
367
- }
@@ -6,8 +6,8 @@ let defaults = {
6
6
  }
7
7
 
8
8
  let featureFlags = {
9
- future: [],
10
- experimental: ['optimizeUniversalDefaults'],
9
+ future: ['hoverOnlyWhenSupported', 'respectDefaultRingColorOpacity'],
10
+ experimental: ['optimizeUniversalDefaults', 'matchVariant' /* , 'variantGrouping' */],
11
11
  }
12
12
 
13
13
  export function flagEnabled(config, flag) {
@@ -29,7 +29,11 @@ export default function collapseAdjacentRules() {
29
29
  (currentRule[property] ?? '').replace(/\s+/g, ' ')
30
30
  )
31
31
  ) {
32
- currentRule.append(node.nodes)
32
+ // An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
33
+ if (node.nodes) {
34
+ currentRule.append(node.nodes)
35
+ }
36
+
33
37
  node.remove()
34
38
  } else {
35
39
  currentRule = node
@@ -1,42 +1,200 @@
1
- const PATTERNS = [
2
- /(?:\['([^'\s]+[^<>"'`\s:\\])')/.source, // ['text-lg' -> text-lg
3
- /(?:\["([^"\s]+[^<>"'`\s:\\])")/.source, // ["text-lg" -> text-lg
4
- /(?:\[`([^`\s]+[^<>"'`\s:\\])`)/.source, // [`text-lg` -> text-lg
5
- /([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source, // font-['some_font',sans-serif]
6
- /([^<>"'`\s]*\[\w*"[^'`\s]*"?\])/.source, // font-["some_font",sans-serif]
7
- /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source, // bg-[url('...')]
8
- /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source, // bg-[url("...")]
9
- /([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source, // bg-[url('...'),url('...')]
10
- /([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source, // bg-[url("..."),url("...")]
11
- /([^<>"'`\s]*\[[^<>"'`\s]*\('[^"`\s]*'\)+\])/.source, // h-[calc(100%-theme('spacing.1'))]
12
- /([^<>"'`\s]*\[[^<>"'`\s]*\("[^'`\s]*"\)+\])/.source, // h-[calc(100%-theme("spacing.1"))]
13
- /([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
14
- /([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
15
- /([^<>"'`\s]*\[[^<>"'`\s]*:[^\]\s]*\])/.source, // `[attr:value]`
16
- /([^<>"'`\s]*\[[^<>"'`\s]*:'[^"'`\s]*'\])/.source, // `[content:'hello']` but not `[content:"hello"]`
17
- /([^<>"'`\s]*\[[^<>"'`\s]*:"[^"'`\s]*"\])/.source, // `[content:"hello"]` but not `[content:'hello']`
18
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source, // `fill-[#bada55]`, `fill-[#bada55]/50`
19
- /([^"'`\s]*[^<>"'`\s:\\])/.source, // `<sm:underline`, `md>:font-bold`
20
- /([^<>"'`\s]*[^"'`\s:\\])/.source, // `px-1.5`, `uppercase` but not `uppercase:`
21
-
22
- // Arbitrary properties
23
- // /([^"\s]*\[[^\s]+?\][^"\s]*)/.source,
24
- // /([^'\s]*\[[^\s]+?\][^'\s]*)/.source,
25
- // /([^`\s]*\[[^\s]+?\][^`\s]*)/.source,
26
- ].join('|')
27
-
28
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g')
29
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
1
+ import { flagEnabled } from '../featureFlags'
2
+ import * as regex from './regex'
3
+
4
+ export function defaultExtractor(context) {
5
+ let patterns = Array.from(buildRegExps(context))
6
+
7
+ /**
8
+ * @param {string} content
9
+ */
10
+ return (content) => {
11
+ /** @type {(string|string)[]} */
12
+ let results = []
13
+
14
+ for (let pattern of patterns) {
15
+ results = [...results, ...(content.match(pattern) ?? [])]
16
+ }
17
+
18
+ return results.filter((v) => v !== undefined).map(clipAtBalancedParens)
19
+ }
20
+ }
21
+
22
+ function* buildRegExps(context) {
23
+ let separator = context.tailwindConfig.separator
24
+ let variantGroupingEnabled = flagEnabled(context.tailwindConfig, 'variantGrouping')
25
+ let prefix =
26
+ context.tailwindConfig.prefix !== ''
27
+ ? regex.optional(regex.pattern([/-?/, regex.escape(context.tailwindConfig.prefix)]))
28
+ : ''
29
+
30
+ let utility = regex.any([
31
+ // Arbitrary properties
32
+ /\[[^\s:'"`]+:[^\s\]]+\]/,
33
+
34
+ // Utilities
35
+ regex.pattern([
36
+ // Utility Name / Group Name
37
+ /-?(?:\w+)/,
38
+
39
+ // Normal/Arbitrary values
40
+ regex.optional(
41
+ regex.any([
42
+ regex.pattern([
43
+ // Arbitrary values
44
+ /-(?:\w+-)*\[[^\s:]+\]/,
45
+
46
+ // Not immediately followed by an `{[(`
47
+ /(?![{([]])/,
48
+
49
+ // optionally followed by an opacity modifier
50
+ /(?:\/[^\s'"`\\><$]*)?/,
51
+ ]),
52
+
53
+ regex.pattern([
54
+ // Arbitrary values
55
+ /-(?:\w+-)*\[[^\s]+\]/,
56
+
57
+ // Not immediately followed by an `{[(`
58
+ /(?![{([]])/,
59
+
60
+ // optionally followed by an opacity modifier
61
+ /(?:\/[^\s'"`\\$]*)?/,
62
+ ]),
63
+
64
+ // Normal values w/o quotes — may include an opacity modifier
65
+ /[-\/][^\s'"`\\$={><]*/,
66
+ ])
67
+ ),
68
+ ]),
69
+ ])
70
+
71
+ let variantPatterns = [
72
+ // Without quotes
73
+ regex.any([
74
+ regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/, separator]),
75
+ regex.pattern([/[^\s"'`\[\\]+/, separator]),
76
+ ]),
77
+
78
+ // With quotes allowed
79
+ regex.any([
80
+ regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s`]+\]/, separator]),
81
+ regex.pattern([/[^\s`\[\\]+/, separator]),
82
+ ]),
83
+ ]
84
+
85
+ for (const variantPattern of variantPatterns) {
86
+ yield regex.pattern([
87
+ // Variants
88
+ '((?=((',
89
+ variantPattern,
90
+ ')+))\\2)?',
91
+
92
+ // Important (optional)
93
+ /!?/,
94
+
95
+ prefix,
96
+
97
+ variantGroupingEnabled
98
+ ? regex.any([
99
+ // Or any of those things but grouped separated by commas
100
+ regex.pattern([/\(/, utility, regex.zeroOrMore([/,/, utility]), /\)/]),
101
+
102
+ // Arbitrary properties, constrained utilities, arbitrary values, etc…
103
+ utility,
104
+ ])
105
+ : utility,
106
+ ])
107
+ }
108
+
109
+ // 5. Inner matches
110
+ yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
111
+ }
112
+
113
+ // We want to capture any "special" characters
114
+ // AND the characters immediately following them (if there is one)
115
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g
116
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/
30
117
 
31
118
  /**
32
- * @param {string} content
119
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
120
+ * Used for arbitrary values only
121
+ *
122
+ * We will go past the end of the balanced parens until we find a non-class character
123
+ *
124
+ * Depth matching behavior:
125
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
126
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
127
+ * 1 2 3 4 34 3 210 END
128
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
129
+ *
130
+ * @param {string} input
33
131
  */
34
- export function defaultExtractor(content) {
35
- let broadMatches = content.matchAll(BROAD_MATCH_GLOBAL_REGEXP)
36
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || []
37
- let results = [...broadMatches, ...innerMatches].flat().filter((v) => v !== undefined)
132
+ function clipAtBalancedParens(input) {
133
+ // We are care about this for arbitrary values
134
+ if (!input.includes('-[')) {
135
+ return input
136
+ }
137
+
138
+ let depth = 0
139
+ let openStringTypes = []
140
+
141
+ // Find all parens, brackets, quotes, etc
142
+ // Stop when we end at a balanced pair
143
+ // This is naive and will treat mismatched parens as balanced
144
+ // This shouldn't be a problem in practice though
145
+ let matches = input.matchAll(SPECIALS)
146
+
147
+ // We can't use lookbehind assertions because we have to support Safari
148
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
149
+ matches = Array.from(matches).flatMap((match) => {
150
+ const [, ...groups] = match
151
+
152
+ return groups.map((group, idx) =>
153
+ Object.assign([], match, {
154
+ index: match.index + idx,
155
+ 0: group,
156
+ })
157
+ )
158
+ })
159
+
160
+ for (let match of matches) {
161
+ let char = match[0]
162
+ let inStringType = openStringTypes[openStringTypes.length - 1]
163
+
164
+ if (char === inStringType) {
165
+ openStringTypes.pop()
166
+ } else if (char === "'" || char === '"' || char === '`') {
167
+ openStringTypes.push(char)
168
+ }
169
+
170
+ if (inStringType) {
171
+ continue
172
+ } else if (char === '[') {
173
+ depth++
174
+ continue
175
+ } else if (char === ']') {
176
+ depth--
177
+ continue
178
+ }
179
+
180
+ // We've gone one character past the point where we should stop
181
+ // This means that there was an extra closing `]`
182
+ // We'll clip to just before it
183
+ if (depth < 0) {
184
+ return input.substring(0, match.index)
185
+ }
186
+
187
+ // We've finished balancing the brackets but there still may be characters that can be included
188
+ // For example in the class `text-[#336699]/[.35]`
189
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
190
+
191
+ // If we're at zero and encounter a non-class character then we clip the class there
192
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
193
+ return input.substring(0, match.index)
194
+ }
195
+ }
38
196
 
39
- return results
197
+ return input
40
198
  }
41
199
 
42
200
  // Regular utilities