tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce

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 (148) hide show
  1. package/CHANGELOG.md +380 -1
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +3 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli-peer-dependencies.js +10 -5
  11. package/lib/cli.js +311 -213
  12. package/lib/constants.js +9 -9
  13. package/lib/corePluginList.js +11 -1
  14. package/lib/corePlugins.js +1895 -1773
  15. package/lib/css/preflight.css +19 -13
  16. package/lib/featureFlags.js +22 -16
  17. package/lib/index.js +17 -8
  18. package/lib/lib/cacheInvalidation.js +69 -0
  19. package/lib/lib/collapseAdjacentRules.js +30 -14
  20. package/lib/lib/collapseDuplicateDeclarations.js +80 -0
  21. package/lib/lib/defaultExtractor.js +187 -0
  22. package/lib/lib/detectNesting.js +17 -2
  23. package/lib/lib/evaluateTailwindFunctions.js +40 -24
  24. package/lib/lib/expandApplyAtRules.js +414 -157
  25. package/lib/lib/expandTailwindAtRules.js +156 -151
  26. package/lib/lib/generateRules.js +402 -68
  27. package/lib/lib/getModuleDependencies.js +14 -14
  28. package/lib/lib/normalizeTailwindDirectives.js +45 -36
  29. package/lib/lib/partitionApplyAtRules.js +53 -0
  30. package/lib/lib/regex.js +53 -0
  31. package/lib/lib/resolveDefaultsAtRules.js +105 -90
  32. package/lib/lib/setupContextUtils.js +416 -291
  33. package/lib/lib/setupTrackingContext.js +60 -56
  34. package/lib/lib/sharedState.js +38 -15
  35. package/lib/lib/substituteScreenAtRules.js +9 -6
  36. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  37. package/lib/postcss-plugins/nesting/index.js +17 -0
  38. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  39. package/lib/processTailwindFeatures.js +21 -9
  40. package/lib/public/colors.js +244 -248
  41. package/lib/public/resolve-config.js +5 -5
  42. package/lib/util/buildMediaQuery.js +13 -24
  43. package/lib/util/cloneDeep.js +1 -1
  44. package/lib/util/cloneNodes.js +12 -1
  45. package/lib/util/color.js +43 -32
  46. package/lib/util/createPlugin.js +1 -2
  47. package/lib/util/createUtilityPlugin.js +13 -17
  48. package/lib/util/dataTypes.js +114 -74
  49. package/lib/util/defaults.js +6 -0
  50. package/lib/util/escapeClassName.js +5 -5
  51. package/lib/util/escapeCommas.js +1 -1
  52. package/lib/util/flattenColorPalette.js +2 -4
  53. package/lib/util/formatVariantSelector.js +194 -0
  54. package/lib/util/getAllConfigs.js +13 -5
  55. package/lib/util/hashConfig.js +5 -5
  56. package/lib/util/isKeyframeRule.js +1 -1
  57. package/lib/util/isPlainObject.js +1 -1
  58. package/lib/util/isValidArbitraryValue.js +64 -0
  59. package/lib/util/log.js +35 -19
  60. package/lib/util/nameClass.js +7 -6
  61. package/lib/util/negateValue.js +5 -3
  62. package/lib/util/normalizeConfig.js +233 -0
  63. package/lib/util/normalizeScreens.js +59 -0
  64. package/lib/util/parseAnimationValue.js +56 -56
  65. package/lib/util/parseBoxShadowValue.js +76 -0
  66. package/lib/util/parseDependency.js +32 -32
  67. package/lib/util/parseObjectStyles.js +6 -6
  68. package/lib/util/pluginUtils.js +67 -170
  69. package/lib/util/prefixSelector.js +4 -7
  70. package/lib/util/resolveConfig.js +123 -133
  71. package/lib/util/resolveConfigPath.js +17 -18
  72. package/lib/util/responsive.js +6 -6
  73. package/lib/util/splitAtTopLevelOnly.js +72 -0
  74. package/lib/util/toColorValue.js +1 -2
  75. package/lib/util/toPath.js +6 -1
  76. package/lib/util/transformThemeValue.js +42 -34
  77. package/lib/util/validateConfig.js +21 -0
  78. package/lib/util/withAlphaVariable.js +19 -19
  79. package/nesting/index.js +2 -12
  80. package/package.json +41 -42
  81. package/peers/index.js +11539 -10859
  82. package/plugin.d.ts +11 -0
  83. package/plugin.js +2 -1
  84. package/resolveConfig.js +2 -1
  85. package/scripts/create-plugin-list.js +2 -2
  86. package/scripts/generate-types.js +52 -0
  87. package/src/cli-peer-dependencies.js +7 -1
  88. package/src/cli.js +174 -41
  89. package/src/corePluginList.js +1 -1
  90. package/src/corePlugins.js +641 -596
  91. package/src/css/preflight.css +19 -13
  92. package/src/featureFlags.js +16 -10
  93. package/src/index.js +14 -6
  94. package/src/lib/cacheInvalidation.js +52 -0
  95. package/src/lib/collapseAdjacentRules.js +21 -2
  96. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  97. package/src/lib/defaultExtractor.js +192 -0
  98. package/src/lib/detectNesting.js +22 -3
  99. package/src/lib/evaluateTailwindFunctions.js +24 -7
  100. package/src/lib/expandApplyAtRules.js +442 -154
  101. package/src/lib/expandTailwindAtRules.js +91 -65
  102. package/src/lib/generateRules.js +409 -43
  103. package/src/lib/normalizeTailwindDirectives.js +10 -3
  104. package/src/lib/partitionApplyAtRules.js +52 -0
  105. package/src/lib/regex.js +74 -0
  106. package/src/lib/resolveDefaultsAtRules.js +74 -53
  107. package/src/lib/setupContextUtils.js +388 -208
  108. package/src/lib/setupTrackingContext.js +15 -12
  109. package/src/lib/sharedState.js +42 -7
  110. package/src/lib/substituteScreenAtRules.js +6 -3
  111. package/src/postcss-plugins/nesting/README.md +42 -0
  112. package/src/postcss-plugins/nesting/index.js +13 -0
  113. package/src/postcss-plugins/nesting/plugin.js +80 -0
  114. package/src/processTailwindFeatures.js +17 -2
  115. package/src/public/colors.js +4 -9
  116. package/src/util/buildMediaQuery.js +14 -18
  117. package/src/util/cloneNodes.js +14 -1
  118. package/src/util/color.js +31 -14
  119. package/src/util/createUtilityPlugin.js +2 -2
  120. package/src/util/dataTypes.js +56 -16
  121. package/src/util/defaults.js +6 -0
  122. package/src/util/formatVariantSelector.js +213 -0
  123. package/src/util/getAllConfigs.js +7 -0
  124. package/src/util/isValidArbitraryValue.js +61 -0
  125. package/src/util/log.js +23 -22
  126. package/src/util/nameClass.js +2 -2
  127. package/src/util/negateValue.js +4 -2
  128. package/src/util/normalizeConfig.js +262 -0
  129. package/src/util/normalizeScreens.js +45 -0
  130. package/src/util/parseBoxShadowValue.js +72 -0
  131. package/src/util/pluginUtils.js +51 -147
  132. package/src/util/prefixSelector.js +7 -8
  133. package/src/util/resolveConfig.js +108 -79
  134. package/src/util/splitAtTopLevelOnly.js +71 -0
  135. package/src/util/toPath.js +23 -1
  136. package/src/util/transformThemeValue.js +24 -7
  137. package/src/util/validateConfig.js +13 -0
  138. package/stubs/defaultConfig.stub.js +157 -94
  139. package/stubs/simpleConfig.stub.js +0 -1
  140. package/types/config.d.ts +325 -0
  141. package/types/generated/.gitkeep +0 -0
  142. package/types/generated/colors.d.ts +276 -0
  143. package/types/generated/corePluginList.d.ts +1 -0
  144. package/types/index.d.ts +1 -0
  145. package/types.d.ts +1 -0
  146. package/lib/lib/setupWatchingContext.js +0 -284
  147. package/nesting/plugin.js +0 -41
  148. package/src/lib/setupWatchingContext.js +0 -306
@@ -1,31 +1,15 @@
1
+ import LRU from 'quick-lru'
1
2
  import * as sharedState from './sharedState'
2
3
  import { generateRules } from './generateRules'
3
4
  import bigSign from '../util/bigSign'
5
+ import log from '../util/log'
4
6
  import cloneNodes from '../util/cloneNodes'
7
+ import { defaultExtractor } from './defaultExtractor'
5
8
 
6
9
  let env = sharedState.env
7
- let contentMatchCache = sharedState.contentMatchCache
8
-
9
- const PATTERNS = [
10
- /([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source, // font-['some_font',sans-serif]
11
- /([^<>"'`\s]*\[\w*"[^"`\s]*"?\])/.source, // font-["some_font",sans-serif]
12
- /([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source, // bg-[url('...')]
13
- /([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source, // bg-[url("...")]
14
- /([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
15
- /([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
16
- /([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source, // `fill-[#bada55]`, `fill-[#bada55]/50`
17
- /([^<>"'`\s]*[^"'`\s:])/.source, // `px-1.5`, `uppercase` but not `uppercase:`].join('|')
18
- ].join('|')
19
- const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g')
20
- const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g
21
10
 
22
11
  const builtInExtractors = {
23
- DEFAULT: (content) => {
24
- let broadMatches = content.match(BROAD_MATCH_GLOBAL_REGEXP) || []
25
- let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || []
26
-
27
- return [...broadMatches, ...innerMatches]
28
- },
12
+ DEFAULT: defaultExtractor,
29
13
  }
30
14
 
31
15
  const builtInTransformers = {
@@ -33,41 +17,20 @@ const builtInTransformers = {
33
17
  svelte: (content) => content.replace(/(?:^|\s)class:/g, ' '),
34
18
  }
35
19
 
36
- function getExtractor(tailwindConfig, fileExtension) {
37
- let extractors = tailwindConfig.content.extract
38
- let contentOptions = tailwindConfig.content.options
39
-
40
- if (typeof extractors === 'function') {
41
- extractors = {
42
- DEFAULT: extractors,
43
- }
44
- }
45
- if (contentOptions.defaultExtractor) {
46
- extractors.DEFAULT = contentOptions.defaultExtractor
47
- }
48
- for (let { extensions, extractor } of contentOptions.extractors || []) {
49
- for (let extension of extensions) {
50
- extractors[extension] = extractor
51
- }
52
- }
20
+ function getExtractor(context, fileExtension) {
21
+ let extractors = context.tailwindConfig.content.extract
53
22
 
54
23
  return (
55
24
  extractors[fileExtension] ||
56
25
  extractors.DEFAULT ||
57
26
  builtInExtractors[fileExtension] ||
58
- builtInExtractors.DEFAULT
27
+ builtInExtractors.DEFAULT(context)
59
28
  )
60
29
  }
61
30
 
62
31
  function getTransformer(tailwindConfig, fileExtension) {
63
32
  let transformers = tailwindConfig.content.transform
64
33
 
65
- if (typeof transformers === 'function') {
66
- transformers = {
67
- DEFAULT: transformers,
68
- }
69
- }
70
-
71
34
  return (
72
35
  transformers[fileExtension] ||
73
36
  transformers.DEFAULT ||
@@ -76,10 +39,16 @@ function getTransformer(tailwindConfig, fileExtension) {
76
39
  )
77
40
  }
78
41
 
42
+ let extractorCache = new WeakMap()
43
+
79
44
  // Scans template contents for possible classes. This is a hot path on initial build but
80
45
  // not too important for subsequent builds. The faster the better though — if we can speed
81
46
  // up these regexes by 50% that could cut initial build time by like 20%.
82
- function getClassCandidates(content, extractor, contentMatchCache, candidates, seen) {
47
+ function getClassCandidates(content, extractor, candidates, seen) {
48
+ if (!extractorCache.has(extractor)) {
49
+ extractorCache.set(extractor, new LRU({ maxSize: 25000 }))
50
+ }
51
+
83
52
  for (let line of content.split('\n')) {
84
53
  line = line.trim()
85
54
 
@@ -88,8 +57,8 @@ function getClassCandidates(content, extractor, contentMatchCache, candidates, s
88
57
  }
89
58
  seen.add(line)
90
59
 
91
- if (contentMatchCache.has(line)) {
92
- for (let match of contentMatchCache.get(line)) {
60
+ if (extractorCache.get(extractor).has(line)) {
61
+ for (let match of extractorCache.get(extractor).get(line)) {
93
62
  candidates.add(match)
94
63
  }
95
64
  } else {
@@ -100,7 +69,7 @@ function getClassCandidates(content, extractor, contentMatchCache, candidates, s
100
69
  candidates.add(match)
101
70
  }
102
71
 
103
- contentMatchCache.set(line, lineMatchesSet)
72
+ extractorCache.get(extractor).set(line, lineMatchesSet)
104
73
  }
105
74
  }
106
75
  }
@@ -110,6 +79,7 @@ function buildStylesheet(rules, context) {
110
79
 
111
80
  let returnValue = {
112
81
  base: new Set(),
82
+ defaults: new Set(),
113
83
  components: new Set(),
114
84
  utilities: new Set(),
115
85
  variants: new Set(),
@@ -136,6 +106,11 @@ function buildStylesheet(rules, context) {
136
106
  continue
137
107
  }
138
108
 
109
+ if (sort & context.layerOrder.defaults) {
110
+ returnValue.defaults.add(rule)
111
+ continue
112
+ }
113
+
139
114
  if (sort & context.layerOrder.components) {
140
115
  returnValue.components.add(rule)
141
116
  continue
@@ -164,13 +139,15 @@ export default function expandTailwindAtRules(context) {
164
139
  variants: null,
165
140
  }
166
141
 
167
- // Make sure this file contains Tailwind directives. If not, we can save
168
- // a lot of work and bail early. Also we don't have to register our touch
169
- // file as a dependency since the output of this CSS does not depend on
170
- // the source of any templates. Think Vue <style> blocks for example.
171
- root.walkAtRules('tailwind', (rule) => {
172
- if (Object.keys(layerNodes).includes(rule.params)) {
173
- layerNodes[rule.params] = rule
142
+ root.walkAtRules((rule) => {
143
+ // Make sure this file contains Tailwind directives. If not, we can save
144
+ // a lot of work and bail early. Also we don't have to register our touch
145
+ // file as a dependency since the output of this CSS does not depend on
146
+ // the source of any templates. Think Vue <style> blocks for example.
147
+ if (rule.name === 'tailwind') {
148
+ if (Object.keys(layerNodes).includes(rule.params)) {
149
+ layerNodes[rule.params] = rule
150
+ }
174
151
  }
175
152
  })
176
153
 
@@ -181,17 +158,19 @@ export default function expandTailwindAtRules(context) {
181
158
  // ---
182
159
 
183
160
  // Find potential rules in changed files
184
- let candidates = new Set(['*'])
161
+ let candidates = new Set([sharedState.NOT_ON_DEMAND])
185
162
  let seen = new Set()
186
163
 
187
164
  env.DEBUG && console.time('Reading changed files')
188
165
 
189
166
  for (let { content, extension } of context.changedContent) {
190
167
  let transformer = getTransformer(context.tailwindConfig, extension)
191
- let extractor = getExtractor(context.tailwindConfig, extension)
192
- getClassCandidates(transformer(content), extractor, contentMatchCache, candidates, seen)
168
+ let extractor = getExtractor(context, extension)
169
+ getClassCandidates(transformer(content), extractor, candidates, seen)
193
170
  }
194
171
 
172
+ env.DEBUG && console.timeEnd('Reading changed files')
173
+
195
174
  // ---
196
175
 
197
176
  // Generate the actual CSS
@@ -213,6 +192,7 @@ export default function expandTailwindAtRules(context) {
213
192
  env.DEBUG && console.timeEnd('Build stylesheet')
214
193
 
215
194
  let {
195
+ defaults: defaultNodes,
216
196
  base: baseNodes,
217
197
  components: componentNodes,
218
198
  utilities: utilityNodes,
@@ -224,25 +204,72 @@ export default function expandTailwindAtRules(context) {
224
204
  // Replace any Tailwind directives with generated CSS
225
205
 
226
206
  if (layerNodes.base) {
227
- layerNodes.base.before(cloneNodes([...baseNodes], layerNodes.base.source))
207
+ layerNodes.base.before(
208
+ cloneNodes([...baseNodes, ...defaultNodes], layerNodes.base.source, {
209
+ layer: 'base',
210
+ })
211
+ )
228
212
  layerNodes.base.remove()
229
213
  }
230
214
 
231
215
  if (layerNodes.components) {
232
- layerNodes.components.before(cloneNodes([...componentNodes], layerNodes.components.source))
216
+ layerNodes.components.before(
217
+ cloneNodes([...componentNodes], layerNodes.components.source, {
218
+ layer: 'components',
219
+ })
220
+ )
233
221
  layerNodes.components.remove()
234
222
  }
235
223
 
236
224
  if (layerNodes.utilities) {
237
- layerNodes.utilities.before(cloneNodes([...utilityNodes], layerNodes.utilities.source))
225
+ layerNodes.utilities.before(
226
+ cloneNodes([...utilityNodes], layerNodes.utilities.source, {
227
+ layer: 'utilities',
228
+ })
229
+ )
238
230
  layerNodes.utilities.remove()
239
231
  }
240
232
 
233
+ // We do post-filtering to not alter the emitted order of the variants
234
+ const variantNodes = Array.from(screenNodes).filter((node) => {
235
+ const parentLayer = node.raws.tailwind?.parentLayer
236
+
237
+ if (parentLayer === 'components') {
238
+ return layerNodes.components !== null
239
+ }
240
+
241
+ if (parentLayer === 'utilities') {
242
+ return layerNodes.utilities !== null
243
+ }
244
+
245
+ return true
246
+ })
247
+
241
248
  if (layerNodes.variants) {
242
- layerNodes.variants.before(cloneNodes([...screenNodes], layerNodes.variants.source))
249
+ layerNodes.variants.before(
250
+ cloneNodes(variantNodes, layerNodes.variants.source, {
251
+ layer: 'variants',
252
+ })
253
+ )
243
254
  layerNodes.variants.remove()
244
- } else {
245
- root.append(cloneNodes([...screenNodes], root.source))
255
+ } else if (variantNodes.length > 0) {
256
+ root.append(
257
+ cloneNodes(variantNodes, root.source, {
258
+ layer: 'variants',
259
+ })
260
+ )
261
+ }
262
+
263
+ // If we've got a utility layer and no utilities are generated there's likely something wrong
264
+ const hasUtilityVariants = variantNodes.some(
265
+ (node) => node.raws.tailwind?.parentLayer === 'utilities'
266
+ )
267
+
268
+ if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
269
+ log.warn('content-problems', [
270
+ 'No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.',
271
+ 'https://tailwindcss.com/docs/content-configuration',
272
+ ])
246
273
  }
247
274
 
248
275
  // ---
@@ -250,7 +277,6 @@ export default function expandTailwindAtRules(context) {
250
277
  if (env.DEBUG) {
251
278
  console.log('Potential classes: ', candidates.size)
252
279
  console.log('Active contexts: ', sharedState.contextSourcesMap.size)
253
- console.log('Content match entries', contentMatchCache.size)
254
280
  }
255
281
 
256
282
  // Clear the cache for the changed files