tailwindcss 0.0.0-insiders.eebf529 → 0.0.0-insiders.ef2ebb2

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 (227) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +15 -7
  3. package/colors.d.ts +3 -0
  4. package/defaultConfig.d.ts +3 -0
  5. package/defaultTheme.d.ts +4 -0
  6. package/index.css +5 -0
  7. package/lib/cli/build/index.js +57 -0
  8. package/lib/cli/build/plugin.js +433 -0
  9. package/lib/cli/build/utils.js +88 -0
  10. package/lib/cli/build/watching.js +182 -0
  11. package/lib/cli/help/index.js +73 -0
  12. package/lib/cli/index.js +231 -0
  13. package/lib/cli/init/index.js +63 -0
  14. package/lib/cli.js +1 -704
  15. package/lib/corePluginList.js +13 -3
  16. package/lib/corePlugins.js +2399 -1867
  17. package/lib/css/preflight.css +17 -9
  18. package/lib/featureFlags.js +50 -26
  19. package/lib/index.js +1 -31
  20. package/lib/lib/cacheInvalidation.js +92 -0
  21. package/lib/lib/collapseAdjacentRules.js +30 -10
  22. package/lib/lib/collapseDuplicateDeclarations.js +60 -4
  23. package/lib/lib/content.js +207 -0
  24. package/lib/lib/defaultExtractor.js +243 -0
  25. package/lib/lib/detectNesting.js +21 -10
  26. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  27. package/lib/lib/expandApplyAtRules.js +467 -161
  28. package/lib/lib/expandTailwindAtRules.js +200 -133
  29. package/lib/lib/findAtConfigPath.js +46 -0
  30. package/lib/lib/generateRules.js +550 -200
  31. package/lib/lib/getModuleDependencies.js +88 -37
  32. package/lib/lib/handleImportAtRules.js +50 -0
  33. package/lib/lib/load-config.js +42 -0
  34. package/lib/lib/normalizeTailwindDirectives.js +36 -38
  35. package/lib/lib/offsets.js +306 -0
  36. package/lib/lib/partitionApplyAtRules.js +58 -0
  37. package/lib/lib/regex.js +74 -0
  38. package/lib/lib/remap-bitfield.js +89 -0
  39. package/lib/lib/resolveDefaultsAtRules.js +98 -58
  40. package/lib/lib/setupContextUtils.js +767 -325
  41. package/lib/lib/setupTrackingContext.js +71 -75
  42. package/lib/lib/sharedState.js +70 -10
  43. package/lib/lib/substituteScreenAtRules.js +14 -10
  44. package/lib/plugin.js +166 -0
  45. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  46. package/lib/postcss-plugins/nesting/index.js +21 -0
  47. package/lib/postcss-plugins/nesting/plugin.js +89 -0
  48. package/lib/processTailwindFeatures.js +39 -26
  49. package/lib/public/colors.js +272 -246
  50. package/lib/public/create-plugin.js +9 -5
  51. package/lib/public/default-config.js +10 -6
  52. package/lib/public/default-theme.js +10 -6
  53. package/lib/public/load-config.js +12 -0
  54. package/lib/public/resolve-config.js +11 -6
  55. package/lib/util/applyImportantSelector.js +36 -0
  56. package/lib/util/bigSign.js +6 -1
  57. package/lib/util/buildMediaQuery.js +13 -6
  58. package/lib/util/cloneDeep.js +9 -6
  59. package/lib/util/cloneNodes.js +23 -3
  60. package/lib/util/color.js +70 -38
  61. package/lib/util/colorNames.js +752 -0
  62. package/lib/util/configurePlugins.js +7 -2
  63. package/lib/util/createPlugin.js +8 -6
  64. package/lib/util/createUtilityPlugin.js +16 -16
  65. package/lib/util/dataTypes.js +182 -111
  66. package/lib/util/defaults.js +14 -3
  67. package/lib/util/escapeClassName.js +13 -8
  68. package/lib/util/escapeCommas.js +7 -2
  69. package/lib/util/flattenColorPalette.js +11 -12
  70. package/lib/util/formatVariantSelector.js +228 -151
  71. package/lib/util/getAllConfigs.js +33 -12
  72. package/lib/util/hashConfig.js +9 -4
  73. package/lib/util/isKeyframeRule.js +7 -2
  74. package/lib/util/isPlainObject.js +7 -2
  75. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
  76. package/lib/util/log.js +44 -13
  77. package/lib/util/nameClass.js +27 -10
  78. package/lib/util/negateValue.js +25 -8
  79. package/lib/util/normalizeConfig.js +167 -67
  80. package/lib/util/normalizeScreens.js +128 -11
  81. package/lib/util/parseAnimationValue.js +44 -40
  82. package/lib/util/parseBoxShadowValue.js +34 -23
  83. package/lib/util/parseDependency.js +39 -55
  84. package/lib/util/parseGlob.js +36 -0
  85. package/lib/util/parseObjectStyles.js +15 -10
  86. package/lib/util/pluginUtils.js +157 -69
  87. package/lib/util/prefixSelector.js +30 -12
  88. package/lib/util/pseudoElements.js +209 -0
  89. package/lib/util/removeAlphaVariables.js +31 -0
  90. package/lib/util/resolveConfig.js +101 -79
  91. package/lib/util/resolveConfigPath.js +30 -12
  92. package/lib/util/responsive.js +11 -6
  93. package/lib/util/splitAtTopLevelOnly.js +51 -0
  94. package/lib/util/tap.js +6 -1
  95. package/lib/util/toColorValue.js +7 -3
  96. package/lib/util/toPath.js +26 -3
  97. package/lib/util/transformThemeValue.js +40 -30
  98. package/lib/util/validateConfig.js +48 -0
  99. package/lib/util/validateFormalSyntax.js +26 -0
  100. package/lib/util/withAlphaVariable.js +27 -15
  101. package/lib/value-parser/LICENSE +22 -0
  102. package/lib/value-parser/README.md +3 -0
  103. package/lib/value-parser/index.d.js +2 -0
  104. package/lib/value-parser/index.js +22 -0
  105. package/lib/value-parser/parse.js +259 -0
  106. package/lib/value-parser/stringify.js +38 -0
  107. package/lib/value-parser/unit.js +86 -0
  108. package/lib/value-parser/walk.js +16 -0
  109. package/loadConfig.d.ts +4 -0
  110. package/loadConfig.js +2 -0
  111. package/nesting/index.js +2 -12
  112. package/package.json +63 -62
  113. package/plugin.d.ts +11 -0
  114. package/resolveConfig.d.ts +12 -0
  115. package/scripts/generate-types.js +105 -0
  116. package/scripts/release-channel.js +18 -0
  117. package/scripts/release-notes.js +21 -0
  118. package/scripts/type-utils.js +27 -0
  119. package/src/cli/build/index.js +53 -0
  120. package/src/cli/build/plugin.js +476 -0
  121. package/src/cli/build/utils.js +76 -0
  122. package/src/cli/build/watching.js +229 -0
  123. package/src/cli/help/index.js +70 -0
  124. package/src/cli/index.js +217 -0
  125. package/src/cli/init/index.js +79 -0
  126. package/src/cli.js +1 -766
  127. package/src/corePluginList.js +1 -1
  128. package/src/corePlugins.js +800 -296
  129. package/src/css/preflight.css +17 -9
  130. package/src/featureFlags.js +20 -6
  131. package/src/index.js +1 -34
  132. package/src/lib/cacheInvalidation.js +52 -0
  133. package/src/lib/collapseAdjacentRules.js +21 -2
  134. package/src/lib/collapseDuplicateDeclarations.js +66 -1
  135. package/src/lib/content.js +240 -0
  136. package/src/lib/defaultExtractor.js +217 -0
  137. package/src/lib/detectNesting.js +9 -1
  138. package/src/lib/evaluateTailwindFunctions.js +83 -9
  139. package/src/lib/expandApplyAtRules.js +515 -153
  140. package/src/lib/expandTailwindAtRules.js +147 -86
  141. package/src/lib/findAtConfigPath.js +48 -0
  142. package/src/lib/generateRules.js +541 -147
  143. package/src/lib/getModuleDependencies.js +70 -30
  144. package/src/lib/handleImportAtRules.js +34 -0
  145. package/src/lib/load-config.ts +31 -0
  146. package/src/lib/normalizeTailwindDirectives.js +5 -26
  147. package/src/lib/offsets.js +373 -0
  148. package/src/lib/partitionApplyAtRules.js +52 -0
  149. package/src/lib/regex.js +74 -0
  150. package/src/lib/remap-bitfield.js +82 -0
  151. package/src/lib/resolveDefaultsAtRules.js +59 -17
  152. package/src/lib/setupContextUtils.js +693 -176
  153. package/src/lib/setupTrackingContext.js +52 -65
  154. package/src/lib/sharedState.js +54 -7
  155. package/src/plugin.js +141 -0
  156. package/src/postcss-plugins/nesting/README.md +42 -0
  157. package/src/postcss-plugins/nesting/index.js +13 -0
  158. package/src/postcss-plugins/nesting/plugin.js +80 -0
  159. package/src/processTailwindFeatures.js +12 -2
  160. package/src/public/colors.js +22 -0
  161. package/src/public/default-config.js +1 -1
  162. package/src/public/default-theme.js +2 -2
  163. package/src/public/load-config.js +2 -0
  164. package/src/util/applyImportantSelector.js +27 -0
  165. package/src/util/buildMediaQuery.js +5 -3
  166. package/src/util/cloneNodes.js +19 -2
  167. package/src/util/color.js +44 -12
  168. package/src/util/colorNames.js +150 -0
  169. package/src/util/dataTypes.js +67 -23
  170. package/src/util/defaults.js +6 -0
  171. package/src/util/formatVariantSelector.js +264 -144
  172. package/src/util/getAllConfigs.js +21 -2
  173. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  174. package/src/util/log.js +35 -7
  175. package/src/util/nameClass.js +4 -0
  176. package/src/util/negateValue.js +11 -3
  177. package/src/util/normalizeConfig.js +86 -7
  178. package/src/util/normalizeScreens.js +99 -4
  179. package/src/util/parseBoxShadowValue.js +4 -3
  180. package/src/util/parseDependency.js +37 -42
  181. package/src/util/parseGlob.js +24 -0
  182. package/src/util/pluginUtils.js +118 -23
  183. package/src/util/prefixSelector.js +30 -10
  184. package/src/util/pseudoElements.js +167 -0
  185. package/src/util/removeAlphaVariables.js +24 -0
  186. package/src/util/resolveConfig.js +74 -26
  187. package/src/util/resolveConfigPath.js +12 -1
  188. package/src/util/splitAtTopLevelOnly.js +52 -0
  189. package/src/util/toPath.js +23 -1
  190. package/src/util/transformThemeValue.js +13 -3
  191. package/src/util/validateConfig.js +36 -0
  192. package/src/util/validateFormalSyntax.js +34 -0
  193. package/src/util/withAlphaVariable.js +1 -1
  194. package/src/value-parser/LICENSE +22 -0
  195. package/src/value-parser/README.md +3 -0
  196. package/src/value-parser/index.d.ts +177 -0
  197. package/src/value-parser/index.js +28 -0
  198. package/src/value-parser/parse.js +303 -0
  199. package/src/value-parser/stringify.js +41 -0
  200. package/src/value-parser/unit.js +118 -0
  201. package/src/value-parser/walk.js +18 -0
  202. package/stubs/.gitignore +1 -0
  203. package/stubs/.prettierrc.json +6 -0
  204. package/stubs/{defaultConfig.stub.js → config.full.js} +220 -167
  205. package/stubs/{simpleConfig.stub.js → config.simple.js} +1 -1
  206. package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -1
  207. package/stubs/postcss.config.js +5 -0
  208. package/stubs/tailwind.config.cjs +2 -0
  209. package/stubs/tailwind.config.js +2 -0
  210. package/stubs/tailwind.config.ts +3 -0
  211. package/types/config.d.ts +369 -0
  212. package/types/generated/.gitkeep +0 -0
  213. package/types/generated/colors.d.ts +298 -0
  214. package/types/generated/corePluginList.d.ts +1 -0
  215. package/types/generated/default-theme.d.ts +372 -0
  216. package/types/index.d.ts +7 -0
  217. package/CHANGELOG.md +0 -1853
  218. package/lib/cli-peer-dependencies.js +0 -15
  219. package/lib/constants.js +0 -37
  220. package/lib/lib/setupWatchingContext.js +0 -288
  221. package/nesting/plugin.js +0 -41
  222. package/peers/index.js +0 -76107
  223. package/scripts/install-integrations.js +0 -27
  224. package/scripts/rebuildFixtures.js +0 -68
  225. package/src/cli-peer-dependencies.js +0 -9
  226. package/src/constants.js +0 -17
  227. 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,
@@ -22,6 +22,8 @@
22
22
  2. Prevent adjustments of font size after orientation changes in iOS.
23
23
  3. Use a more readable tab size.
24
24
  4. Use the user's configured `sans` font-family by default.
25
+ 5. Use the user's configured `sans` font-feature-settings by default.
26
+ 6. Use the user's configured `sans` font-variation-settings by default.
25
27
  */
26
28
 
27
29
  html {
@@ -30,6 +32,8 @@ html {
30
32
  -moz-tab-size: 4; /* 3 */
31
33
  tab-size: 4; /* 3 */
32
34
  font-family: theme('fontFamily.sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"); /* 4 */
35
+ font-feature-settings: theme('fontFamily.sans[1].fontFeatureSettings', normal); /* 5 */
36
+ font-variation-settings: theme('fontFamily.sans[1].fontVariationSettings', normal); /* 6 */
33
37
  }
34
38
 
35
39
  /*
@@ -58,7 +62,7 @@ hr {
58
62
  Add the correct text decoration in Chrome, Edge, and Safari.
59
63
  */
60
64
 
61
- abbr[title] {
65
+ abbr:where([title]) {
62
66
  text-decoration: underline dotted;
63
67
  }
64
68
 
@@ -144,7 +148,7 @@ sup {
144
148
  table {
145
149
  text-indent: 0; /* 1 */
146
150
  border-color: inherit; /* 2 */
147
- border-collapse: collapse; /* 3 */
151
+ border-collapse: collapse; /* 3 */
148
152
  }
149
153
 
150
154
  /*
@@ -159,7 +163,10 @@ optgroup,
159
163
  select,
160
164
  textarea {
161
165
  font-family: inherit; /* 1 */
166
+ font-feature-settings: inherit; /* 1 */
167
+ font-variation-settings: inherit; /* 1 */
162
168
  font-size: 100%; /* 1 */
169
+ font-weight: inherit; /* 1 */
163
170
  line-height: inherit; /* 1 */
164
171
  color: inherit; /* 1 */
165
172
  margin: 0; /* 2 */
@@ -259,7 +266,7 @@ summary {
259
266
  }
260
267
 
261
268
  /*
262
- Removes the default spacing and border for appropriate elements.
269
+ Removes the default spacing for appropriate elements.
263
270
  */
264
271
 
265
272
  blockquote,
@@ -295,6 +302,10 @@ menu {
295
302
  padding: 0;
296
303
  }
297
304
 
305
+ dialog {
306
+ padding: 0;
307
+ }
308
+
298
309
  /*
299
310
  Prevent resizing textareas horizontally by default.
300
311
  */
@@ -310,7 +321,7 @@ textarea {
310
321
 
311
322
  input::placeholder,
312
323
  textarea::placeholder {
313
- opacity: 1; /* 1 */
324
+ opacity: 1; /* 1 */
314
325
  color: theme('colors.gray.400', #9ca3af); /* 2 */
315
326
  }
316
327
 
@@ -358,10 +369,7 @@ video {
358
369
  height: auto;
359
370
  }
360
371
 
361
- /*
362
- Ensure the default browser behavior of the `hidden` attribute.
363
- */
364
-
372
+ /* Make elements with the HTML hidden attribute stay hidden by default */
365
373
  [hidden] {
366
374
  display: none;
367
375
  }
@@ -1,13 +1,27 @@
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
+ disableColorOpacityUtilitiesByDefault: false,
7
+ relativeContentPathsByDefault: false,
8
+ oxideParser: true,
9
+ logicalSiblingUtilities: false,
6
10
  }
7
11
 
8
- let featureFlags = {
9
- future: [],
10
- experimental: ['optimizeUniversalDefaults'],
12
+ export let featureFlags = {
13
+ future: [
14
+ 'hoverOnlyWhenSupported',
15
+ 'respectDefaultRingColorOpacity',
16
+ 'disableColorOpacityUtilitiesByDefault',
17
+ 'relativeContentPathsByDefault',
18
+ 'logicalSiblingUtilities',
19
+ ],
20
+ experimental: [
21
+ 'optimizeUniversalDefaults',
22
+ 'oxideParser',
23
+ // 'variantGrouping',
24
+ ],
11
25
  }
12
26
 
13
27
  export function flagEnabled(config, flag) {
@@ -41,7 +55,7 @@ export function issueFlagNotices(config) {
41
55
 
42
56
  if (experimentalFlagsEnabled(config).length > 0) {
43
57
  let changes = experimentalFlagsEnabled(config)
44
- .map((s) => chalk.yellow(s))
58
+ .map((s) => colors.yellow(s))
45
59
  .join(', ')
46
60
 
47
61
  log.warn('experimental-flags-enabled', [
package/src/index.js CHANGED
@@ -1,34 +1 @@
1
- import setupTrackingContext from './lib/setupTrackingContext'
2
- import setupWatchingContext from './lib/setupWatchingContext'
3
- import processTailwindFeatures from './processTailwindFeatures'
4
- import { env } from './lib/sharedState'
5
-
6
- module.exports = function tailwindcss(configOrPath) {
7
- return {
8
- postcssPlugin: 'tailwindcss',
9
- plugins: [
10
- env.DEBUG &&
11
- function (root) {
12
- console.log('\n')
13
- console.time('JIT TOTAL')
14
- return root
15
- },
16
- function (root, result) {
17
- let setupContext =
18
- env.TAILWIND_MODE === 'watch'
19
- ? setupWatchingContext(configOrPath)
20
- : setupTrackingContext(configOrPath)
21
-
22
- processTailwindFeatures(setupContext)(root, result)
23
- },
24
- env.DEBUG &&
25
- function (root) {
26
- console.timeEnd('JIT TOTAL')
27
- console.log('\n')
28
- return root
29
- },
30
- ].filter(Boolean),
31
- }
32
- }
33
-
34
- module.exports.postcss = true
1
+ module.exports = require('./plugin')
@@ -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)) {
@@ -29,11 +29,30 @@ 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
36
40
  }
37
41
  })
42
+
43
+ // After we've collapsed adjacent rules & at-rules, we need to collapse
44
+ // adjacent rules & at-rules that are children of at-rules.
45
+ // We do not care about nesting rules because Tailwind CSS
46
+ // explicitly does not handle rule nesting on its own as
47
+ // the user is expected to use a nesting plugin
48
+ root.each((node) => {
49
+ if (node.type === 'atrule') {
50
+ collapseRulesIn(node)
51
+ }
52
+ })
53
+ }
54
+
55
+ return (root) => {
56
+ collapseRulesIn(root)
38
57
  }
39
58
  }
@@ -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,240 @@
1
+ // @ts-check
2
+
3
+ import fs from 'fs'
4
+ import path from 'path'
5
+ import isGlob from 'is-glob'
6
+ import fastGlob from 'fast-glob'
7
+ import normalizePath from 'normalize-path'
8
+ import { parseGlob } from '../util/parseGlob'
9
+ import { env } from './sharedState'
10
+ import { resolveContentPaths } from '@tailwindcss/oxide'
11
+
12
+ /** @typedef {import('../../types/config.js').RawFile} RawFile */
13
+ /** @typedef {import('../../types/config.js').FilePath} FilePath */
14
+
15
+ /*
16
+ * @param {import('tailwindcss').Config} tailwindConfig
17
+ * @param {{skip:string[]}} options
18
+ * @returns {ContentPath[]}
19
+ */
20
+ function resolveContentFiles(tailwindConfig, { skip = [] } = {}) {
21
+ if (
22
+ Array.isArray(tailwindConfig.content.files) &&
23
+ tailwindConfig.content.files.includes('auto')
24
+ ) {
25
+ let idx = tailwindConfig.content.files.indexOf('auto')
26
+ if (idx !== -1) {
27
+ env.DEBUG && console.time('Calculating resolve content paths')
28
+ let resolved = resolveContentPaths({ base: process.cwd() })
29
+ env.DEBUG && console.timeEnd('Calculating resolve content paths')
30
+
31
+ tailwindConfig.content.files.splice(idx, 1, ...resolved)
32
+ }
33
+ }
34
+
35
+ if (skip.length > 0) {
36
+ tailwindConfig.content.files = tailwindConfig.content.files.filter(
37
+ (filePath) => !skip.includes(filePath)
38
+ )
39
+ }
40
+
41
+ return tailwindConfig.content.files
42
+ }
43
+
44
+ /**
45
+ * @typedef {object} ContentPath
46
+ * @property {string} original
47
+ * @property {string} base
48
+ * @property {string | null} glob
49
+ * @property {boolean} ignore
50
+ * @property {string} pattern
51
+ */
52
+
53
+ /**
54
+ * Turn a list of content paths (absolute or not; glob or not) into a list of
55
+ * absolute file paths that exist on the filesystem
56
+ *
57
+ * If there are symlinks in the path then multiple paths will be returned
58
+ * one for the symlink and one for the actual file
59
+ *
60
+ * @param {*} context
61
+ * @param {import('tailwindcss').Config} tailwindConfig
62
+ * @returns {ContentPath[]}
63
+ */
64
+ export function parseCandidateFiles(context, tailwindConfig) {
65
+ let files = resolveContentFiles(tailwindConfig, {
66
+ skip: [context.userConfigPath],
67
+ })
68
+
69
+ // Normalize the file globs
70
+ files = files.filter((filePath) => typeof filePath === 'string')
71
+ files = files.map(normalizePath)
72
+
73
+ // Split into included and excluded globs
74
+ let tasks = fastGlob.generateTasks(files)
75
+
76
+ /** @type {ContentPath[]} */
77
+ let included = []
78
+
79
+ /** @type {ContentPath[]} */
80
+ let excluded = []
81
+
82
+ for (const task of tasks) {
83
+ included.push(...task.positive.map((filePath) => parseFilePath(filePath, false)))
84
+ excluded.push(...task.negative.map((filePath) => parseFilePath(filePath, true)))
85
+ }
86
+
87
+ let paths = [...included, ...excluded]
88
+
89
+ // Resolve paths relative to the config file or cwd
90
+ paths = resolveRelativePaths(context, paths)
91
+
92
+ // Resolve symlinks if possible
93
+ paths = paths.flatMap(resolvePathSymlinks)
94
+
95
+ // Update cached patterns
96
+ paths = paths.map(resolveGlobPattern)
97
+
98
+ return paths
99
+ }
100
+
101
+ /**
102
+ *
103
+ * @param {string} filePath
104
+ * @param {boolean} ignore
105
+ * @returns {ContentPath}
106
+ */
107
+ function parseFilePath(filePath, ignore) {
108
+ let contentPath = {
109
+ original: filePath,
110
+ base: filePath,
111
+ ignore,
112
+ pattern: filePath,
113
+ glob: null,
114
+ }
115
+
116
+ if (isGlob(filePath)) {
117
+ Object.assign(contentPath, parseGlob(filePath))
118
+ }
119
+
120
+ return contentPath
121
+ }
122
+
123
+ /**
124
+ *
125
+ * @param {ContentPath} contentPath
126
+ * @returns {ContentPath}
127
+ */
128
+ function resolveGlobPattern(contentPath) {
129
+ // This is required for Windows support to properly pick up Glob paths.
130
+ // Afaik, this technically shouldn't be needed but there's probably
131
+ // some internal, direct path matching with a normalized path in
132
+ // a package which can't handle mixed directory separators
133
+ let base = normalizePath(contentPath.base)
134
+
135
+ // If the user's file path contains any special characters (like parens) for instance fast-glob
136
+ // is like "OOOH SHINY" and treats them as such. So we have to escape the base path to fix this
137
+ base = fastGlob.escapePath(base)
138
+
139
+ contentPath.pattern = contentPath.glob ? `${base}/${contentPath.glob}` : base
140
+ contentPath.pattern = contentPath.ignore ? `!${contentPath.pattern}` : contentPath.pattern
141
+
142
+ return contentPath
143
+ }
144
+
145
+ /**
146
+ * Resolve each path relative to the config file (when possible) if the experimental flag is enabled
147
+ * Otherwise, resolve relative to the current working directory
148
+ *
149
+ * @param {any} context
150
+ * @param {ContentPath[]} contentPaths
151
+ * @returns {ContentPath[]}
152
+ */
153
+ function resolveRelativePaths(context, contentPaths) {
154
+ let resolveFrom = []
155
+
156
+ // Resolve base paths relative to the config file (when possible) if the experimental flag is enabled
157
+ if (context.userConfigPath && context.tailwindConfig.content.relative) {
158
+ resolveFrom = [path.dirname(context.userConfigPath)]
159
+ }
160
+
161
+ return contentPaths.map((contentPath) => {
162
+ contentPath.base = path.resolve(...resolveFrom, contentPath.base)
163
+
164
+ return contentPath
165
+ })
166
+ }
167
+
168
+ /**
169
+ * Resolve the symlink for the base directory / file in each path
170
+ * These are added as additional dependencies to watch for changes because
171
+ * some tools (like webpack) will only watch the actual file or directory
172
+ * but not the symlink itself even in projects that use monorepos.
173
+ *
174
+ * @param {ContentPath} contentPath
175
+ * @returns {ContentPath[]}
176
+ */
177
+ function resolvePathSymlinks(contentPath) {
178
+ let paths = [contentPath]
179
+
180
+ try {
181
+ let resolvedPath = fs.realpathSync(contentPath.base)
182
+ if (resolvedPath !== contentPath.base) {
183
+ paths.push({
184
+ ...contentPath,
185
+ base: resolvedPath,
186
+ })
187
+ }
188
+ } catch {
189
+ // TODO: log this?
190
+ }
191
+
192
+ return paths
193
+ }
194
+
195
+ /**
196
+ * @param {any} context
197
+ * @param {ContentPath[]} candidateFiles
198
+ * @param {Map<string, number>} fileModifiedMap
199
+ * @returns {[{ content: string, extension: string }[], Map<string, number>]}
200
+ */
201
+ export function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
202
+ let changedContent = context.tailwindConfig.content.files
203
+ .filter((item) => typeof item.raw === 'string')
204
+ .map(({ raw, extension = 'html' }) => ({ content: raw, extension }))
205
+
206
+ let [changedFiles, mTimesToCommit] = resolveChangedFiles(candidateFiles, fileModifiedMap)
207
+
208
+ for (let changedFile of changedFiles) {
209
+ let extension = path.extname(changedFile).slice(1)
210
+ changedContent.push({ file: changedFile, extension })
211
+ }
212
+
213
+ return [changedContent, mTimesToCommit]
214
+ }
215
+
216
+ /**
217
+ *
218
+ * @param {ContentPath[]} candidateFiles
219
+ * @param {Map<string, number>} fileModifiedMap
220
+ * @returns {[Set<string>, Map<string, number>]}
221
+ */
222
+ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
223
+ let paths = candidateFiles.map((contentPath) => contentPath.pattern)
224
+ let mTimesToCommit = new Map()
225
+
226
+ let changedFiles = new Set()
227
+ env.DEBUG && console.time('Finding changed files')
228
+ let files = fastGlob.sync(paths, { absolute: true })
229
+ for (let file of files) {
230
+ let prevModified = fileModifiedMap.get(file) || -Infinity
231
+ let modified = fs.statSync(file).mtimeMs
232
+
233
+ if (modified > prevModified) {
234
+ changedFiles.add(file)
235
+ mTimesToCommit.set(file, modified)
236
+ }
237
+ }
238
+ env.DEBUG && console.timeEnd('Finding changed files')
239
+ return [changedFiles, mTimesToCommit]
240
+ }