tailwindcss 0.0.0-insiders.e2d5f21 → 0.0.0-insiders.e302ef1

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 (91) hide show
  1. package/CHANGELOG.md +244 -3
  2. package/LICENSE +1 -2
  3. package/README.md +8 -4
  4. package/colors.js +2 -1
  5. package/defaultConfig.js +2 -1
  6. package/defaultTheme.js +2 -1
  7. package/lib/cli.js +123 -88
  8. package/lib/corePlugins.js +288 -360
  9. package/lib/css/preflight.css +4 -4
  10. package/lib/featureFlags.js +4 -5
  11. package/lib/index.js +12 -3
  12. package/lib/lib/cacheInvalidation.js +69 -0
  13. package/lib/lib/collapseAdjacentRules.js +14 -1
  14. package/lib/lib/collapseDuplicateDeclarations.js +52 -1
  15. package/lib/lib/defaultExtractor.js +44 -0
  16. package/lib/lib/evaluateTailwindFunctions.js +1 -1
  17. package/lib/lib/expandApplyAtRules.js +265 -60
  18. package/lib/lib/expandTailwindAtRules.js +63 -48
  19. package/lib/lib/generateRules.js +136 -34
  20. package/lib/lib/normalizeTailwindDirectives.js +10 -2
  21. package/lib/lib/partitionApplyAtRules.js +53 -0
  22. package/lib/lib/resolveDefaultsAtRules.js +30 -12
  23. package/lib/lib/setupContextUtils.js +137 -81
  24. package/lib/lib/setupTrackingContext.js +8 -7
  25. package/lib/lib/sharedState.js +38 -5
  26. package/{nesting → lib/postcss-plugins/nesting}/README.md +0 -0
  27. package/lib/postcss-plugins/nesting/index.js +17 -0
  28. package/lib/postcss-plugins/nesting/plugin.js +85 -0
  29. package/lib/processTailwindFeatures.js +10 -2
  30. package/lib/util/cloneNodes.js +12 -1
  31. package/lib/util/color.js +23 -8
  32. package/lib/util/createPlugin.js +1 -2
  33. package/lib/util/createUtilityPlugin.js +4 -8
  34. package/lib/util/dataTypes.js +4 -2
  35. package/lib/util/defaults.js +6 -0
  36. package/lib/util/flattenColorPalette.js +1 -3
  37. package/lib/util/log.js +10 -6
  38. package/lib/util/normalizeConfig.js +47 -15
  39. package/lib/util/normalizeScreens.js +6 -5
  40. package/lib/util/parseBoxShadowValue.js +44 -4
  41. package/lib/util/pluginUtils.js +6 -13
  42. package/lib/util/prefixSelector.js +4 -5
  43. package/lib/util/resolveConfig.js +48 -27
  44. package/lib/util/resolveConfigPath.js +1 -2
  45. package/lib/util/toColorValue.js +1 -2
  46. package/lib/util/toPath.js +6 -1
  47. package/lib/util/transformThemeValue.js +4 -8
  48. package/nesting/index.js +2 -12
  49. package/package.json +28 -33
  50. package/peers/index.js +3209 -4239
  51. package/plugin.js +2 -1
  52. package/resolveConfig.js +2 -1
  53. package/src/cli.js +62 -15
  54. package/src/corePlugins.js +212 -217
  55. package/src/css/preflight.css +4 -4
  56. package/src/featureFlags.js +3 -3
  57. package/src/index.js +14 -6
  58. package/src/lib/cacheInvalidation.js +52 -0
  59. package/src/lib/collapseAdjacentRules.js +16 -1
  60. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  61. package/src/lib/defaultExtractor.js +50 -0
  62. package/src/lib/evaluateTailwindFunctions.js +1 -1
  63. package/src/lib/expandApplyAtRules.js +285 -56
  64. package/src/lib/expandTailwindAtRules.js +75 -37
  65. package/src/lib/generateRules.js +121 -27
  66. package/src/lib/normalizeTailwindDirectives.js +7 -1
  67. package/src/lib/partitionApplyAtRules.js +52 -0
  68. package/src/lib/resolveDefaultsAtRules.js +35 -10
  69. package/src/lib/setupContextUtils.js +127 -45
  70. package/src/lib/setupTrackingContext.js +8 -7
  71. package/src/lib/sharedState.js +42 -4
  72. package/src/postcss-plugins/nesting/README.md +42 -0
  73. package/src/postcss-plugins/nesting/index.js +13 -0
  74. package/src/postcss-plugins/nesting/plugin.js +80 -0
  75. package/src/processTailwindFeatures.js +12 -2
  76. package/src/util/cloneNodes.js +14 -1
  77. package/src/util/color.js +20 -7
  78. package/src/util/dataTypes.js +7 -5
  79. package/src/util/defaults.js +6 -0
  80. package/src/util/log.js +10 -6
  81. package/src/util/normalizeConfig.js +24 -3
  82. package/src/util/normalizeScreens.js +6 -3
  83. package/src/util/parseBoxShadowValue.js +51 -3
  84. package/src/util/pluginUtils.js +1 -1
  85. package/src/util/prefixSelector.js +7 -5
  86. package/src/util/resolveConfig.js +41 -1
  87. package/src/util/toPath.js +23 -1
  88. package/stubs/defaultConfig.stub.js +2 -2
  89. package/lib/lib/setupWatchingContext.js +0 -288
  90. package/nesting/plugin.js +0 -41
  91. package/src/lib/setupWatchingContext.js +0 -311
@@ -9,7 +9,7 @@
9
9
  box-sizing: border-box; /* 1 */
10
10
  border-width: 0; /* 2 */
11
11
  border-style: solid; /* 2 */
12
- border-color: currentColor; /* 2 */
12
+ border-color: theme('borderColor.DEFAULT', currentColor); /* 2 */
13
13
  }
14
14
 
15
15
  ::before,
@@ -58,7 +58,7 @@ hr {
58
58
  Add the correct text decoration in Chrome, Edge, and Safari.
59
59
  */
60
60
 
61
- abbr[title] {
61
+ abbr:where([title]) {
62
62
  text-decoration: underline dotted;
63
63
  }
64
64
 
@@ -144,7 +144,7 @@ sup {
144
144
  table {
145
145
  text-indent: 0; /* 1 */
146
146
  border-color: inherit; /* 2 */
147
- border-collapse: collapse; /* 3 */
147
+ border-collapse: collapse; /* 3 */
148
148
  }
149
149
 
150
150
  /*
@@ -310,7 +310,7 @@ textarea {
310
310
 
311
311
  input::placeholder,
312
312
  textarea::placeholder {
313
- opacity: 1; /* 1 */
313
+ opacity: 1; /* 1 */
314
314
  color: theme('colors.gray.400', #9ca3af); /* 2 */
315
315
  }
316
316
 
@@ -1,8 +1,8 @@
1
- import chalk from 'chalk'
1
+ import colors from 'picocolors'
2
2
  import log from './util/log'
3
3
 
4
4
  let defaults = {
5
- optimizeUniversalDefaults: true,
5
+ optimizeUniversalDefaults: false,
6
6
  }
7
7
 
8
8
  let featureFlags = {
@@ -41,7 +41,7 @@ export function issueFlagNotices(config) {
41
41
 
42
42
  if (experimentalFlagsEnabled(config).length > 0) {
43
43
  let changes = experimentalFlagsEnabled(config)
44
- .map((s) => chalk.yellow(s))
44
+ .map((s) => colors.yellow(s))
45
45
  .join(', ')
46
46
 
47
47
  log.warn('experimental-flags-enabled', [
package/src/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import setupTrackingContext from './lib/setupTrackingContext'
2
- import setupWatchingContext from './lib/setupWatchingContext'
3
2
  import processTailwindFeatures from './processTailwindFeatures'
4
3
  import { env } from './lib/sharedState'
5
4
 
@@ -14,12 +13,21 @@ module.exports = function tailwindcss(configOrPath) {
14
13
  return root
15
14
  },
16
15
  function (root, result) {
17
- let setupContext =
18
- env.TAILWIND_MODE === 'watch'
19
- ? setupWatchingContext(configOrPath)
20
- : setupTrackingContext(configOrPath)
16
+ let context = setupTrackingContext(configOrPath)
21
17
 
22
- processTailwindFeatures(setupContext)(root, result)
18
+ if (root.type === 'document') {
19
+ let roots = root.nodes.filter((node) => node.type === 'root')
20
+
21
+ for (const root of roots) {
22
+ if (root.type === 'root') {
23
+ processTailwindFeatures(context)(root, result)
24
+ }
25
+ }
26
+
27
+ return
28
+ }
29
+
30
+ processTailwindFeatures(context)(root, result)
23
31
  },
24
32
  env.DEBUG &&
25
33
  function (root) {
@@ -0,0 +1,52 @@
1
+ import crypto from 'crypto'
2
+ import * as sharedState from './sharedState'
3
+
4
+ /**
5
+ * Calculate the hash of a string.
6
+ *
7
+ * This doesn't need to be cryptographically secure or
8
+ * anything like that since it's used only to detect
9
+ * when the CSS changes to invalidate the context.
10
+ *
11
+ * This is wrapped in a try/catch because it's really dependent
12
+ * on how Node itself is build and the environment and OpenSSL
13
+ * version / build that is installed on the user's machine.
14
+ *
15
+ * Based on the environment this can just outright fail.
16
+ *
17
+ * See https://github.com/nodejs/node/issues/40455
18
+ *
19
+ * @param {string} str
20
+ */
21
+ function getHash(str) {
22
+ try {
23
+ return crypto.createHash('md5').update(str, 'utf-8').digest('binary')
24
+ } catch (err) {
25
+ return ''
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Determine if the CSS tree is different from the
31
+ * previous version for the given `sourcePath`.
32
+ *
33
+ * @param {string} sourcePath
34
+ * @param {import('postcss').Node} root
35
+ */
36
+ export function hasContentChanged(sourcePath, root) {
37
+ let css = root.toString()
38
+
39
+ // We only care about files with @tailwind directives
40
+ // Other files use an existing context
41
+ if (!css.includes('@tailwind')) {
42
+ return false
43
+ }
44
+
45
+ let existingHash = sharedState.sourceHashMap.get(sourcePath)
46
+ let rootHash = getHash(css)
47
+ let didChange = existingHash !== rootHash
48
+
49
+ sharedState.sourceHashMap.set(sourcePath, rootHash)
50
+
51
+ return didChange
52
+ }
@@ -5,7 +5,7 @@ let comparisonMap = {
5
5
  let types = new Set(Object.keys(comparisonMap))
6
6
 
7
7
  export default function collapseAdjacentRules() {
8
- return (root) => {
8
+ function collapseRulesIn(root) {
9
9
  let currentRule = null
10
10
  root.each((node) => {
11
11
  if (!types.has(node.type)) {
@@ -35,5 +35,20 @@ export default function collapseAdjacentRules() {
35
35
  currentRule = node
36
36
  }
37
37
  })
38
+
39
+ // After we've collapsed adjacent rules & at-rules, we need to collapse
40
+ // adjacent rules & at-rules that are children of at-rules.
41
+ // We do not care about nesting rules because Tailwind CSS
42
+ // explicitly does not handle rule nesting on its own as
43
+ // the user is expected to use a nesting plugin
44
+ root.each((node) => {
45
+ if (node.type === 'atrule') {
46
+ collapseRulesIn(node)
47
+ }
48
+ })
49
+ }
50
+
51
+ return (root) => {
52
+ collapseRulesIn(root)
38
53
  }
39
54
  }
@@ -3,6 +3,7 @@ export default function collapseDuplicateDeclarations() {
3
3
  root.walkRules((node) => {
4
4
  let seen = new Map()
5
5
  let droppable = new Set([])
6
+ let byProperty = new Map()
6
7
 
7
8
  node.walkDecls((decl) => {
8
9
  // This could happen if we have nested selectors. In that case the
@@ -14,15 +15,79 @@ export default function collapseDuplicateDeclarations() {
14
15
  }
15
16
 
16
17
  if (seen.has(decl.prop)) {
17
- droppable.add(seen.get(decl.prop))
18
+ // Exact same value as what we have seen so far
19
+ if (seen.get(decl.prop).value === decl.value) {
20
+ // Keep the last one, drop the one we've seen so far
21
+ droppable.add(seen.get(decl.prop))
22
+ // Override the existing one with the new value. This is necessary
23
+ // so that if we happen to have more than one declaration with the
24
+ // same value, that we keep removing the previous one. Otherwise we
25
+ // will only remove the *first* one.
26
+ seen.set(decl.prop, decl)
27
+ return
28
+ }
29
+
30
+ // Not the same value, so we need to check if we can merge it so
31
+ // let's collect it first.
32
+ if (!byProperty.has(decl.prop)) {
33
+ byProperty.set(decl.prop, new Set())
34
+ }
35
+
36
+ byProperty.get(decl.prop).add(seen.get(decl.prop))
37
+ byProperty.get(decl.prop).add(decl)
18
38
  }
19
39
 
20
40
  seen.set(decl.prop, decl)
21
41
  })
22
42
 
43
+ // Drop all the duplicate declarations with the exact same value we've
44
+ // already seen so far.
23
45
  for (let decl of droppable) {
24
46
  decl.remove()
25
47
  }
48
+
49
+ // Analyze the declarations based on its unit, drop all the declarations
50
+ // with the same unit but the last one in the list.
51
+ for (let declarations of byProperty.values()) {
52
+ let byUnit = new Map()
53
+
54
+ for (let decl of declarations) {
55
+ let unit = resolveUnit(decl.value)
56
+ if (unit === null) {
57
+ // We don't have a unit, so should never try and collapse this
58
+ // value. This is because we can't know how to do it in a correct
59
+ // way (e.g.: overrides for older browsers)
60
+ continue
61
+ }
62
+
63
+ if (!byUnit.has(unit)) {
64
+ byUnit.set(unit, new Set())
65
+ }
66
+
67
+ byUnit.get(unit).add(decl)
68
+ }
69
+
70
+ for (let declarations of byUnit.values()) {
71
+ // Get all but the last one
72
+ let removableDeclarations = Array.from(declarations).slice(0, -1)
73
+
74
+ for (let decl of removableDeclarations) {
75
+ decl.remove()
76
+ }
77
+ }
78
+ }
26
79
  })
27
80
  }
28
81
  }
82
+
83
+ let UNITLESS_NUMBER = Symbol('unitless-number')
84
+
85
+ function resolveUnit(input) {
86
+ let result = /^-?\d*.?\d+([\w%]+)?$/g.exec(input)
87
+
88
+ if (result) {
89
+ return result[1] ?? UNITLESS_NUMBER
90
+ }
91
+
92
+ return null
93
+ }
@@ -0,0 +1,50 @@
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
30
+
31
+ /**
32
+ * @param {string} content
33
+ */
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)
38
+
39
+ return results
40
+ }
41
+
42
+ // Regular utilities
43
+ // {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
44
+
45
+ // Arbitrary values
46
+ // {{modifier}:}*{namespace}-[{arbitraryValue}]{/{opacityModifier}}?
47
+ // arbitraryValue: no whitespace, balanced quotes unless within quotes, balanced brackets unless within quotes
48
+
49
+ // Arbitrary properties
50
+ // {{modifier}:}*[{validCssPropertyName}:{arbitraryValue}]
@@ -42,7 +42,7 @@ function validatePath(config, path, defaultValue) {
42
42
  ? pathToString(path)
43
43
  : path.replace(/^['"]+/g, '').replace(/['"]+$/g, '')
44
44
  const pathSegments = Array.isArray(path) ? path : toPath(pathString)
45
- const value = dlv(config.theme, pathString, defaultValue)
45
+ const value = dlv(config.theme, pathSegments, defaultValue)
46
46
 
47
47
  if (value === undefined) {
48
48
  let error = `'${pathString}' does not exist in your theme config.`