tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21

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 (161) hide show
  1. package/CHANGELOG.md +246 -6
  2. package/README.md +13 -9
  3. package/defaultTheme.d.ts +2 -1
  4. package/lib/cli/build/deps.js +54 -0
  5. package/lib/cli/build/index.js +48 -0
  6. package/lib/cli/build/plugin.js +362 -0
  7. package/lib/cli/build/utils.js +78 -0
  8. package/lib/cli/build/watching.js +178 -0
  9. package/lib/cli/help/index.js +71 -0
  10. package/lib/cli/index.js +18 -0
  11. package/lib/cli/init/index.js +46 -0
  12. package/lib/cli/shared.js +12 -0
  13. package/lib/cli-peer-dependencies.js +18 -5
  14. package/lib/cli.js +62 -592
  15. package/lib/constants.js +19 -12
  16. package/lib/corePluginList.js +5 -3
  17. package/lib/corePlugins.js +619 -347
  18. package/lib/css/preflight.css +7 -0
  19. package/lib/featureFlags.js +34 -22
  20. package/lib/index.js +16 -9
  21. package/lib/lib/cacheInvalidation.js +42 -21
  22. package/lib/lib/collapseAdjacentRules.js +16 -14
  23. package/lib/lib/collapseDuplicateDeclarations.js +13 -10
  24. package/lib/lib/content.js +177 -0
  25. package/lib/lib/defaultExtractor.js +230 -33
  26. package/lib/lib/detectNesting.js +13 -4
  27. package/lib/lib/evaluateTailwindFunctions.js +105 -42
  28. package/lib/lib/expandApplyAtRules.js +151 -92
  29. package/lib/lib/expandTailwindAtRules.js +134 -149
  30. package/lib/lib/findAtConfigPath.js +44 -0
  31. package/lib/lib/generateRules.js +404 -185
  32. package/lib/lib/getModuleDependencies.js +21 -18
  33. package/lib/lib/normalizeTailwindDirectives.js +11 -8
  34. package/lib/lib/offsets.js +285 -0
  35. package/lib/lib/partitionApplyAtRules.js +14 -11
  36. package/lib/lib/regex.js +60 -0
  37. package/lib/lib/remap-bitfield.js +87 -0
  38. package/lib/lib/resolveDefaultsAtRules.js +97 -79
  39. package/lib/lib/setupContextUtils.js +567 -242
  40. package/lib/lib/setupTrackingContext.js +77 -106
  41. package/lib/lib/sharedState.js +18 -10
  42. package/lib/lib/substituteScreenAtRules.js +9 -7
  43. package/lib/postcss-plugins/nesting/index.js +7 -5
  44. package/lib/postcss-plugins/nesting/plugin.js +10 -8
  45. package/lib/processTailwindFeatures.js +34 -31
  46. package/lib/public/colors.js +7 -5
  47. package/lib/public/create-plugin.js +6 -4
  48. package/lib/public/default-config.js +7 -5
  49. package/lib/public/default-theme.js +7 -5
  50. package/lib/public/resolve-config.js +13 -10
  51. package/lib/util/bigSign.js +4 -1
  52. package/lib/util/buildMediaQuery.js +10 -5
  53. package/lib/util/cloneDeep.js +6 -5
  54. package/lib/util/cloneNodes.js +9 -2
  55. package/lib/util/color.js +20 -17
  56. package/lib/util/configurePlugins.js +5 -2
  57. package/lib/util/createPlugin.js +6 -5
  58. package/lib/util/createUtilityPlugin.js +15 -13
  59. package/lib/util/dataTypes.js +75 -51
  60. package/lib/util/defaults.js +8 -5
  61. package/lib/util/escapeClassName.js +13 -10
  62. package/lib/util/escapeCommas.js +4 -1
  63. package/lib/util/flattenColorPalette.js +7 -8
  64. package/lib/util/formatVariantSelector.js +270 -103
  65. package/lib/util/getAllConfigs.js +34 -15
  66. package/lib/util/hashConfig.js +10 -7
  67. package/lib/util/isKeyframeRule.js +4 -1
  68. package/lib/util/isPlainObject.js +4 -1
  69. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +34 -26
  70. package/lib/util/log.js +14 -8
  71. package/lib/util/nameClass.js +19 -8
  72. package/lib/util/negateValue.js +20 -5
  73. package/lib/util/normalizeConfig.js +94 -53
  74. package/lib/util/normalizeScreens.js +115 -4
  75. package/lib/util/parseAnimationValue.js +43 -41
  76. package/lib/util/parseBoxShadowValue.js +12 -45
  77. package/lib/util/parseDependency.js +37 -55
  78. package/lib/util/parseGlob.js +34 -0
  79. package/lib/util/parseObjectStyles.js +15 -12
  80. package/lib/util/pluginUtils.js +146 -42
  81. package/lib/util/prefixSelector.js +26 -9
  82. package/lib/util/removeAlphaVariables.js +29 -0
  83. package/lib/util/resolveConfig.js +104 -105
  84. package/lib/util/resolveConfigPath.js +20 -17
  85. package/lib/util/responsive.js +12 -9
  86. package/lib/util/splitAtTopLevelOnly.js +43 -0
  87. package/lib/util/tap.js +4 -1
  88. package/lib/util/toColorValue.js +4 -1
  89. package/lib/util/toPath.js +18 -2
  90. package/lib/util/transformThemeValue.js +23 -11
  91. package/lib/util/validateConfig.js +24 -0
  92. package/lib/util/validateFormalSyntax.js +24 -0
  93. package/lib/util/withAlphaVariable.js +32 -24
  94. package/package.json +32 -29
  95. package/peers/index.js +6693 -3036
  96. package/plugin.d.ts +10 -5
  97. package/resolveConfig.d.ts +12 -0
  98. package/scripts/generate-types.js +53 -0
  99. package/scripts/release-channel.js +18 -0
  100. package/scripts/release-notes.js +21 -0
  101. package/scripts/type-utils.js +27 -0
  102. package/src/cli/build/deps.js +56 -0
  103. package/src/cli/build/index.js +49 -0
  104. package/src/cli/build/plugin.js +434 -0
  105. package/src/cli/build/utils.js +76 -0
  106. package/src/cli/build/watching.js +227 -0
  107. package/src/cli/help/index.js +70 -0
  108. package/src/cli/index.js +3 -0
  109. package/src/cli/init/index.js +50 -0
  110. package/src/cli/shared.js +5 -0
  111. package/src/cli-peer-dependencies.js +7 -1
  112. package/src/cli.js +46 -659
  113. package/src/corePlugins.js +346 -79
  114. package/src/css/preflight.css +7 -0
  115. package/src/featureFlags.js +12 -2
  116. package/src/index.js +5 -0
  117. package/src/lib/content.js +213 -0
  118. package/src/lib/defaultExtractor.js +202 -35
  119. package/src/lib/detectNesting.js +9 -1
  120. package/src/lib/evaluateTailwindFunctions.js +78 -7
  121. package/src/lib/expandApplyAtRules.js +129 -34
  122. package/src/lib/expandTailwindAtRules.js +12 -50
  123. package/src/lib/findAtConfigPath.js +48 -0
  124. package/src/lib/generateRules.js +379 -126
  125. package/src/lib/offsets.js +351 -0
  126. package/src/lib/regex.js +74 -0
  127. package/src/lib/remap-bitfield.js +82 -0
  128. package/src/lib/resolveDefaultsAtRules.js +53 -36
  129. package/src/lib/setupContextUtils.js +510 -120
  130. package/src/lib/setupTrackingContext.js +8 -45
  131. package/src/lib/sharedState.js +2 -0
  132. package/src/util/buildMediaQuery.js +5 -3
  133. package/src/util/cloneNodes.js +5 -1
  134. package/src/util/dataTypes.js +51 -26
  135. package/src/util/formatVariantSelector.js +317 -101
  136. package/src/util/getAllConfigs.js +19 -0
  137. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  138. package/src/util/log.js +1 -1
  139. package/src/util/nameClass.js +4 -0
  140. package/src/util/negateValue.js +10 -2
  141. package/src/util/normalizeConfig.js +40 -10
  142. package/src/util/normalizeScreens.js +99 -4
  143. package/src/util/parseBoxShadowValue.js +3 -50
  144. package/src/util/parseDependency.js +37 -42
  145. package/src/util/parseGlob.js +24 -0
  146. package/src/util/pluginUtils.js +132 -10
  147. package/src/util/prefixSelector.js +28 -10
  148. package/src/util/removeAlphaVariables.js +24 -0
  149. package/src/util/resolveConfig.js +70 -62
  150. package/src/util/splitAtTopLevelOnly.js +45 -0
  151. package/src/util/toPath.js +1 -1
  152. package/src/util/transformThemeValue.js +13 -3
  153. package/src/util/validateConfig.js +13 -0
  154. package/src/util/validateFormalSyntax.js +34 -0
  155. package/src/util/withAlphaVariable.js +1 -1
  156. package/stubs/defaultConfig.stub.js +165 -164
  157. package/stubs/simpleConfig.stub.js +1 -0
  158. package/types/config.d.ts +77 -37
  159. package/types/generated/default-theme.d.ts +342 -0
  160. package/types/index.d.ts +7 -1
  161. package/types.d.ts +0 -1
@@ -1,22 +1,20 @@
1
1
  import negateValue from './negateValue'
2
2
  import corePluginList from '../corePluginList'
3
3
  import configurePlugins from './configurePlugins'
4
- import defaultConfig from '../../stubs/defaultConfig.stub'
5
4
  import colors from '../public/colors'
6
5
  import { defaults } from './defaults'
7
6
  import { toPath } from './toPath'
8
7
  import { normalizeConfig } from './normalizeConfig'
9
8
  import isPlainObject from './isPlainObject'
10
9
  import { cloneDeep } from './cloneDeep'
10
+ import { parseColorFormat } from './pluginUtils'
11
+ import { withAlphaValue } from './withAlphaVariable'
12
+ import toColorValue from './toColorValue'
11
13
 
12
14
  function isFunction(input) {
13
15
  return typeof input === 'function'
14
16
  }
15
17
 
16
- function isObject(input) {
17
- return typeof input === 'object' && input !== null
18
- }
19
-
20
18
  function mergeWith(target, ...sources) {
21
19
  let customizer = sources.pop()
22
20
 
@@ -25,8 +23,8 @@ function mergeWith(target, ...sources) {
25
23
  let merged = customizer(target[k], source[k])
26
24
 
27
25
  if (merged === undefined) {
28
- if (isObject(target[k]) && isObject(source[k])) {
29
- target[k] = mergeWith(target[k], source[k], customizer)
26
+ if (isPlainObject(target[k]) && isPlainObject(source[k])) {
27
+ target[k] = mergeWith({}, target[k], source[k], customizer)
30
28
  } else {
31
29
  target[k] = source[k]
32
30
  }
@@ -66,36 +64,6 @@ const configUtils = {
66
64
  {}
67
65
  )
68
66
  },
69
- rgb(property) {
70
- if (!property.startsWith('--')) {
71
- throw new Error(
72
- 'The rgb() helper requires a custom property name to be passed as the first argument.'
73
- )
74
- }
75
-
76
- return ({ opacityValue }) => {
77
- if (opacityValue === undefined || opacityValue === 1) {
78
- return `rgb(var(${property}) / 1.0)`
79
- }
80
-
81
- return `rgb(var(${property}) / ${opacityValue})`
82
- }
83
- },
84
- hsl(property) {
85
- if (!property.startsWith('--')) {
86
- throw new Error(
87
- 'The hsl() helper requires a custom property name to be passed as the first argument.'
88
- )
89
- }
90
-
91
- return ({ opacityValue }) => {
92
- if (opacityValue === undefined || opacityValue === 1) {
93
- return `hsl(var(${property}) / 1)`
94
- }
95
-
96
- return `hsl(var(${property}) / ${opacityValue})`
97
- }
98
- },
99
67
  }
100
68
 
101
69
  function value(valueToResolve, ...args) {
@@ -130,12 +98,12 @@ function mergeThemes(themes) {
130
98
 
131
99
  function mergeExtensionCustomizer(merged, value) {
132
100
  // When we have an array of objects, we do want to merge it
133
- if (Array.isArray(merged) && isObject(merged[0])) {
101
+ if (Array.isArray(merged) && isPlainObject(merged[0])) {
134
102
  return merged.concat(value)
135
103
  }
136
104
 
137
105
  // When the incoming value is an array, and the existing config is an object, prepend the existing object
138
- if (Array.isArray(value) && isObject(value[0]) && isObject(merged)) {
106
+ if (Array.isArray(value) && isPlainObject(value[0]) && isPlainObject(merged)) {
139
107
  return [merged, ...value]
140
108
  }
141
109
 
@@ -164,40 +132,81 @@ function mergeExtensions({ extend, ...theme }) {
164
132
  })
165
133
  }
166
134
 
135
+ /**
136
+ *
137
+ * @param {string} key
138
+ * @return {Iterable<string[] & {alpha: string | undefined}>}
139
+ */
140
+ function* toPaths(key) {
141
+ let path = toPath(key)
142
+
143
+ if (path.length === 0) {
144
+ return
145
+ }
146
+
147
+ yield path
148
+
149
+ if (Array.isArray(key)) {
150
+ return
151
+ }
152
+
153
+ let pattern = /^(.*?)\s*\/\s*([^/]+)$/
154
+ let matches = key.match(pattern)
155
+
156
+ if (matches !== null) {
157
+ let [, prefix, alpha] = matches
158
+
159
+ let newPath = toPath(prefix)
160
+ newPath.alpha = alpha
161
+
162
+ yield newPath
163
+ }
164
+ }
165
+
167
166
  function resolveFunctionKeys(object) {
167
+ // theme('colors.red.500 / 0.5') -> ['colors', 'red', '500 / 0', '5]
168
+
168
169
  const resolvePath = (key, defaultValue) => {
169
- const path = toPath(key)
170
+ for (const path of toPaths(key)) {
171
+ let index = 0
172
+ let val = object
170
173
 
171
- let index = 0
172
- let val = object
174
+ while (val !== undefined && val !== null && index < path.length) {
175
+ val = val[path[index++]]
173
176
 
174
- while (val !== undefined && val !== null && index < path.length) {
175
- val = val[path[index++]]
176
- val = isFunction(val) ? val(resolvePath, configUtils) : val
177
- }
177
+ let shouldResolveAsFn =
178
+ isFunction(val) && (path.alpha === undefined || index <= path.length - 1)
178
179
 
179
- if (val === undefined) {
180
- return defaultValue
181
- }
180
+ val = shouldResolveAsFn ? val(resolvePath, configUtils) : val
181
+ }
182
182
 
183
- if (isPlainObject(val)) {
184
- return cloneDeep(val)
185
- }
183
+ if (val !== undefined) {
184
+ if (path.alpha !== undefined) {
185
+ let normalized = parseColorFormat(val)
186
186
 
187
- return val
188
- }
187
+ return withAlphaValue(normalized, path.alpha, toColorValue(normalized))
188
+ }
189
189
 
190
- resolvePath.theme = resolvePath
190
+ if (isPlainObject(val)) {
191
+ return cloneDeep(val)
192
+ }
193
+
194
+ return val
195
+ }
196
+ }
191
197
 
192
- for (let key in configUtils) {
193
- resolvePath[key] = configUtils[key]
198
+ return defaultValue
194
199
  }
195
200
 
201
+ Object.assign(resolvePath, {
202
+ theme: resolvePath,
203
+ ...configUtils,
204
+ })
205
+
196
206
  return Object.keys(object).reduce((resolved, key) => {
197
- return {
198
- ...resolved,
199
- [key]: isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key],
200
- }
207
+ resolved[key] = isFunction(object[key]) ? object[key](resolvePath, configUtils) : object[key]
208
+
209
+ return resolved
201
210
  }, {})
202
211
  }
203
212
 
@@ -250,7 +259,6 @@ export default function resolveConfig(configs) {
250
259
  prefix: '',
251
260
  important: false,
252
261
  separator: ':',
253
- variantOrder: defaultConfig.variantOrder,
254
262
  },
255
263
  ]
256
264
 
@@ -0,0 +1,45 @@
1
+ /**
2
+ * This splits a string on a top-level character.
3
+ *
4
+ * Regex doesn't support recursion (at least not the JS-flavored version).
5
+ * So we have to use a tiny state machine to keep track of paren placement.
6
+ *
7
+ * Expected behavior using commas:
8
+ * var(--a, 0 0 1px rgb(0, 0, 0)), 0 0 1px rgb(0, 0, 0)
9
+ * ─┬─ ┬ ┬ ┬
10
+ * x x x ╰──────── Split because top-level
11
+ * ╰──────────────┴──┴───────────── Ignored b/c inside >= 1 levels of parens
12
+ *
13
+ * @param {string} input
14
+ * @param {string} separator
15
+ */
16
+ export function splitAtTopLevelOnly(input, separator) {
17
+ let stack = []
18
+ let parts = []
19
+ let lastPos = 0
20
+
21
+ for (let idx = 0; idx < input.length; idx++) {
22
+ let char = input[idx]
23
+
24
+ if (stack.length === 0 && char === separator[0]) {
25
+ if (separator.length === 1 || input.slice(idx, idx + separator.length) === separator) {
26
+ parts.push(input.slice(lastPos, idx))
27
+ lastPos = idx + separator.length
28
+ }
29
+ }
30
+
31
+ if (char === '(' || char === '[' || char === '{') {
32
+ stack.push(char)
33
+ } else if (
34
+ (char === ')' && stack[stack.length - 1] === '(') ||
35
+ (char === ']' && stack[stack.length - 1] === '[') ||
36
+ (char === '}' && stack[stack.length - 1] === '{')
37
+ ) {
38
+ stack.pop()
39
+ }
40
+ }
41
+
42
+ parts.push(input.slice(lastPos))
43
+
44
+ return parts
45
+ }
@@ -4,7 +4,7 @@
4
4
  * Square bracket notation `a[b]` may be used to "escape" dots that would otherwise be interpreted as path separators.
5
5
  *
6
6
  * Example:
7
- * a -> ['a]
7
+ * a -> ['a']
8
8
  * a.b.c -> ['a', 'b', 'c']
9
9
  * a[b].c -> ['a', 'b', 'c']
10
10
  * a[b.c].e.f -> ['a', 'b.c', 'e', 'f']
@@ -1,4 +1,5 @@
1
1
  import postcss from 'postcss'
2
+ import isPlainObject from './isPlainObject'
2
3
 
3
4
  export default function transformThemeValue(themeSection) {
4
5
  if (['fontSize', 'outline'].includes(themeSection)) {
@@ -10,9 +11,16 @@ export default function transformThemeValue(themeSection) {
10
11
  }
11
12
  }
12
13
 
14
+ if (themeSection === 'fontFamily') {
15
+ return (value) => {
16
+ if (typeof value === 'function') value = value({})
17
+ let families = Array.isArray(value) && isPlainObject(value[1]) ? value[0] : value
18
+ return Array.isArray(families) ? families.join(', ') : families
19
+ }
20
+ }
21
+
13
22
  if (
14
23
  [
15
- 'fontFamily',
16
24
  'boxShadow',
17
25
  'transitionProperty',
18
26
  'transitionDuration',
@@ -44,8 +52,10 @@ export default function transformThemeValue(themeSection) {
44
52
  }
45
53
  }
46
54
 
47
- return (value) => {
48
- if (typeof value === 'function') value = value({})
55
+ return (value, opts = {}) => {
56
+ if (typeof value === 'function') {
57
+ value = value(opts)
58
+ }
49
59
 
50
60
  return value
51
61
  }
@@ -0,0 +1,13 @@
1
+ import log from './log'
2
+
3
+ export function validateConfig(config) {
4
+ if (config.content.files.length === 0) {
5
+ log.warn('content-problems', [
6
+ 'The `content` option in your Tailwind CSS configuration is missing or empty.',
7
+ 'Configure your content sources or your generated CSS will be missing styles.',
8
+ 'https://tailwindcss.com/docs/content-configuration',
9
+ ])
10
+ }
11
+
12
+ return config
13
+ }
@@ -0,0 +1,34 @@
1
+ import { length, percentage } from './dataTypes'
2
+ import { splitAtTopLevelOnly } from './splitAtTopLevelOnly'
3
+
4
+ /**
5
+ *
6
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/background-size#formal_syntax
7
+ *
8
+ * background-size =
9
+ * <bg-size>#
10
+ *
11
+ * <bg-size> =
12
+ * [ <length-percentage [0,∞]> | auto ]{1,2} |
13
+ * cover |
14
+ * contain
15
+ *
16
+ * <length-percentage> =
17
+ * <length> |
18
+ * <percentage>
19
+ *
20
+ * @param {string} value
21
+ */
22
+ export function backgroundSize(value) {
23
+ let keywordValues = ['cover', 'contain']
24
+ // the <length-percentage> type will probably be a css function
25
+ // so we have to use `splitAtTopLevelOnly`
26
+ return splitAtTopLevelOnly(value, ',').every((part) => {
27
+ let sizes = splitAtTopLevelOnly(part, '_').filter(Boolean)
28
+ if (sizes.length === 1 && keywordValues.includes(sizes[0])) return true
29
+
30
+ if (sizes.length !== 1 && sizes.length !== 2) return false
31
+
32
+ return sizes.every((size) => length(size) || percentage(size) || size === 'auto')
33
+ })
34
+ }
@@ -5,7 +5,7 @@ export function withAlphaValue(color, alphaValue, defaultValue) {
5
5
  return color({ opacityValue: alphaValue })
6
6
  }
7
7
 
8
- let parsed = parseColor(color)
8
+ let parsed = parseColor(color, { loose: true })
9
9
 
10
10
  if (parsed === null) {
11
11
  return defaultValue