tailwindcss 0.0.0-insiders.bd4dddd → 0.0.0-insiders.bda8421

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 (224) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +13 -10
  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/build/deps.js +62 -0
  7. package/lib/cli/build/index.js +54 -0
  8. package/lib/cli/build/plugin.js +371 -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 +230 -0
  13. package/lib/cli/init/index.js +63 -0
  14. package/lib/cli-peer-dependencies.js +28 -7
  15. package/lib/cli.js +1 -741
  16. package/lib/corePluginList.js +17 -4
  17. package/lib/corePlugins.js +2503 -1839
  18. package/lib/css/preflight.css +32 -13
  19. package/lib/featureFlags.js +45 -28
  20. package/lib/index.js +1 -29
  21. package/lib/lib/cacheInvalidation.js +92 -0
  22. package/lib/lib/collapseAdjacentRules.js +30 -10
  23. package/lib/lib/collapseDuplicateDeclarations.js +13 -8
  24. package/lib/lib/content.js +214 -0
  25. package/lib/lib/defaultExtractor.js +240 -31
  26. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  27. package/lib/lib/expandApplyAtRules.js +466 -230
  28. package/lib/lib/expandTailwindAtRules.js +156 -135
  29. package/lib/lib/findAtConfigPath.js +46 -0
  30. package/lib/lib/generateRules.js +554 -200
  31. package/lib/lib/getModuleDependencies.js +88 -37
  32. package/lib/lib/load-config.js +57 -0
  33. package/lib/lib/normalizeTailwindDirectives.js +39 -33
  34. package/lib/lib/offsets.js +355 -0
  35. package/lib/lib/partitionApplyAtRules.js +58 -0
  36. package/lib/lib/regex.js +74 -0
  37. package/lib/lib/remap-bitfield.js +89 -0
  38. package/lib/lib/resolveDefaultsAtRules.js +97 -69
  39. package/lib/lib/setupContextUtils.js +796 -341
  40. package/lib/lib/setupTrackingContext.js +66 -71
  41. package/lib/lib/sharedState.js +45 -14
  42. package/lib/lib/substituteScreenAtRules.js +14 -10
  43. package/lib/plugin.js +48 -0
  44. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  45. package/lib/postcss-plugins/nesting/index.js +21 -0
  46. package/lib/postcss-plugins/nesting/plugin.js +89 -0
  47. package/lib/processTailwindFeatures.js +37 -27
  48. package/lib/public/colors.js +272 -246
  49. package/lib/public/create-plugin.js +9 -5
  50. package/lib/public/default-config.js +10 -6
  51. package/lib/public/default-theme.js +10 -6
  52. package/lib/public/load-config.js +12 -0
  53. package/lib/public/resolve-config.js +11 -6
  54. package/lib/util/applyImportantSelector.js +36 -0
  55. package/lib/util/bigSign.js +6 -1
  56. package/lib/util/buildMediaQuery.js +13 -6
  57. package/lib/util/cloneDeep.js +9 -6
  58. package/lib/util/cloneNodes.js +44 -4
  59. package/lib/util/color.js +70 -53
  60. package/lib/util/colorNames.js +752 -0
  61. package/lib/util/configurePlugins.js +7 -2
  62. package/lib/util/createPlugin.js +8 -6
  63. package/lib/util/createUtilityPlugin.js +16 -16
  64. package/lib/util/dataTypes.js +295 -113
  65. package/lib/util/defaults.js +12 -7
  66. package/lib/util/escapeClassName.js +13 -8
  67. package/lib/util/escapeCommas.js +7 -2
  68. package/lib/util/flattenColorPalette.js +11 -12
  69. package/lib/util/formatVariantSelector.js +235 -151
  70. package/lib/util/getAllConfigs.js +33 -12
  71. package/lib/util/hashConfig.js +9 -4
  72. package/lib/util/isKeyframeRule.js +7 -2
  73. package/lib/util/isPlainObject.js +8 -3
  74. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
  75. package/lib/util/log.js +25 -15
  76. package/lib/util/nameClass.js +27 -10
  77. package/lib/util/negateValue.js +25 -8
  78. package/lib/util/normalizeConfig.js +127 -82
  79. package/lib/util/normalizeScreens.js +128 -11
  80. package/lib/util/parseAnimationValue.js +44 -40
  81. package/lib/util/parseBoxShadowValue.js +34 -23
  82. package/lib/util/parseDependency.js +39 -55
  83. package/lib/util/parseGlob.js +36 -0
  84. package/lib/util/parseObjectStyles.js +15 -10
  85. package/lib/util/pluginUtils.js +172 -69
  86. package/lib/util/prefixSelector.js +30 -12
  87. package/lib/util/pseudoElements.js +212 -0
  88. package/lib/util/removeAlphaVariables.js +31 -0
  89. package/lib/util/resolveConfig.js +101 -87
  90. package/lib/util/resolveConfigPath.js +30 -12
  91. package/lib/util/responsive.js +11 -6
  92. package/lib/util/splitAtTopLevelOnly.js +51 -0
  93. package/lib/util/tap.js +6 -1
  94. package/lib/util/toColorValue.js +7 -3
  95. package/lib/util/toPath.js +22 -4
  96. package/lib/util/transformThemeValue.js +40 -30
  97. package/lib/util/validateConfig.js +37 -0
  98. package/lib/util/validateFormalSyntax.js +26 -0
  99. package/lib/util/withAlphaVariable.js +27 -15
  100. package/lib/value-parser/LICENSE +22 -0
  101. package/lib/value-parser/README.md +3 -0
  102. package/lib/value-parser/index.d.js +2 -0
  103. package/lib/value-parser/index.js +22 -0
  104. package/lib/value-parser/parse.js +259 -0
  105. package/lib/value-parser/stringify.js +38 -0
  106. package/lib/value-parser/unit.js +86 -0
  107. package/lib/value-parser/walk.js +16 -0
  108. package/loadConfig.d.ts +4 -0
  109. package/loadConfig.js +2 -0
  110. package/nesting/index.d.ts +4 -0
  111. package/nesting/index.js +2 -12
  112. package/package.json +60 -55
  113. package/peers/index.js +75503 -55095
  114. package/plugin.d.ts +11 -0
  115. package/resolveConfig.d.ts +31 -0
  116. package/scripts/generate-types.js +104 -0
  117. package/scripts/release-channel.js +18 -0
  118. package/scripts/release-notes.js +21 -0
  119. package/scripts/type-utils.js +27 -0
  120. package/src/cli/build/deps.js +56 -0
  121. package/src/cli/build/index.js +49 -0
  122. package/src/cli/build/plugin.js +437 -0
  123. package/src/cli/build/utils.js +76 -0
  124. package/src/cli/build/watching.js +229 -0
  125. package/src/cli/help/index.js +70 -0
  126. package/src/cli/index.js +216 -0
  127. package/src/cli/init/index.js +79 -0
  128. package/src/cli-peer-dependencies.js +7 -1
  129. package/src/cli.js +1 -811
  130. package/src/corePluginList.js +1 -1
  131. package/src/corePlugins.js +849 -243
  132. package/src/css/preflight.css +32 -13
  133. package/src/featureFlags.js +13 -9
  134. package/src/index.js +1 -28
  135. package/src/lib/cacheInvalidation.js +52 -0
  136. package/src/lib/collapseAdjacentRules.js +21 -2
  137. package/src/lib/content.js +249 -0
  138. package/src/lib/defaultExtractor.js +215 -33
  139. package/src/lib/evaluateTailwindFunctions.js +82 -8
  140. package/src/lib/expandApplyAtRules.js +512 -224
  141. package/src/lib/expandTailwindAtRules.js +102 -87
  142. package/src/lib/findAtConfigPath.js +48 -0
  143. package/src/lib/generateRules.js +541 -146
  144. package/src/lib/getModuleDependencies.js +70 -30
  145. package/src/lib/load-config.ts +44 -0
  146. package/src/lib/normalizeTailwindDirectives.js +1 -0
  147. package/src/lib/offsets.js +432 -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 +55 -30
  152. package/src/lib/setupContextUtils.js +720 -190
  153. package/src/lib/setupTrackingContext.js +47 -61
  154. package/src/lib/sharedState.js +15 -4
  155. package/src/plugin.js +47 -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 +11 -4
  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 +40 -2
  167. package/src/util/color.js +39 -20
  168. package/src/util/colorNames.js +150 -0
  169. package/src/util/dataTypes.js +184 -26
  170. package/src/util/formatVariantSelector.js +272 -144
  171. package/src/util/getAllConfigs.js +21 -2
  172. package/src/util/isPlainObject.js +1 -1
  173. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  174. package/src/util/log.js +8 -8
  175. package/src/util/nameClass.js +4 -0
  176. package/src/util/negateValue.js +11 -3
  177. package/src/util/normalizeConfig.js +45 -6
  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 +139 -24
  183. package/src/util/prefixSelector.js +31 -10
  184. package/src/util/pseudoElements.js +171 -0
  185. package/src/util/removeAlphaVariables.js +24 -0
  186. package/src/util/resolveConfig.js +70 -32
  187. package/src/util/resolveConfigPath.js +12 -1
  188. package/src/util/splitAtTopLevelOnly.js +52 -0
  189. package/src/util/toPath.js +1 -1
  190. package/src/util/transformThemeValue.js +13 -3
  191. package/src/util/validateConfig.js +26 -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} +290 -178
  205. package/stubs/postcss.config.js +6 -0
  206. package/stubs/tailwind.config.cjs +2 -0
  207. package/stubs/tailwind.config.js +2 -0
  208. package/stubs/tailwind.config.ts +3 -0
  209. package/types/config.d.ts +376 -0
  210. package/types/generated/.gitkeep +0 -0
  211. package/types/generated/colors.d.ts +298 -0
  212. package/types/generated/corePluginList.d.ts +1 -0
  213. package/types/generated/default-theme.d.ts +397 -0
  214. package/types/index.d.ts +11 -0
  215. package/CHANGELOG.md +0 -1959
  216. package/lib/constants.js +0 -37
  217. package/lib/lib/detectNesting.js +0 -34
  218. package/nesting/plugin.js +0 -41
  219. package/scripts/install-integrations.js +0 -27
  220. package/scripts/rebuildFixtures.js +0 -68
  221. package/src/constants.js +0 -17
  222. package/src/lib/detectNesting.js +0 -39
  223. /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
  224. /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
@@ -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,14 +22,21 @@
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.
27
+ 7. Disable tap highlights on iOS
25
28
  */
26
29
 
27
- html {
30
+ html,
31
+ :host {
28
32
  line-height: 1.5; /* 1 */
29
33
  -webkit-text-size-adjust: 100%; /* 2 */
30
34
  -moz-tab-size: 4; /* 3 */
31
35
  tab-size: 4; /* 3 */
32
- 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 */
36
+ font-family: theme('fontFamily.sans', ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"); /* 4 */
37
+ font-feature-settings: theme('fontFamily.sans[1].fontFeatureSettings', normal); /* 5 */
38
+ font-variation-settings: theme('fontFamily.sans[1].fontVariationSettings', normal); /* 6 */
39
+ -webkit-tap-highlight-color: transparent; /* 7 */
33
40
  }
34
41
 
35
42
  /*
@@ -95,8 +102,10 @@ strong {
95
102
  }
96
103
 
97
104
  /*
98
- 1. Use the user's configured `mono` font family by default.
99
- 2. Correct the odd `em` font sizing in all browsers.
105
+ 1. Use the user's configured `mono` font-family by default.
106
+ 2. Use the user's configured `mono` font-feature-settings by default.
107
+ 3. Use the user's configured `mono` font-variation-settings by default.
108
+ 4. Correct the odd `em` font sizing in all browsers.
100
109
  */
101
110
 
102
111
  code,
@@ -104,7 +113,9 @@ kbd,
104
113
  samp,
105
114
  pre {
106
115
  font-family: theme('fontFamily.mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace); /* 1 */
107
- font-size: 1em; /* 2 */
116
+ font-feature-settings: theme('fontFamily.mono[1].fontFeatureSettings', normal); /* 2 */
117
+ font-variation-settings: theme('fontFamily.mono[1].fontVariationSettings', normal); /* 3 */
118
+ font-size: 1em; /* 4 */
108
119
  }
109
120
 
110
121
  /*
@@ -159,8 +170,12 @@ optgroup,
159
170
  select,
160
171
  textarea {
161
172
  font-family: inherit; /* 1 */
173
+ font-feature-settings: inherit; /* 1 */
174
+ font-variation-settings: inherit; /* 1 */
162
175
  font-size: 100%; /* 1 */
176
+ font-weight: inherit; /* 1 */
163
177
  line-height: inherit; /* 1 */
178
+ letter-spacing: inherit; /* 1 */
164
179
  color: inherit; /* 1 */
165
180
  margin: 0; /* 2 */
166
181
  padding: 0; /* 3 */
@@ -181,9 +196,9 @@ select {
181
196
  */
182
197
 
183
198
  button,
184
- [type='button'],
185
- [type='reset'],
186
- [type='submit'] {
199
+ input:where([type='button']),
200
+ input:where([type='reset']),
201
+ input:where([type='submit']) {
187
202
  -webkit-appearance: button; /* 1 */
188
203
  background-color: transparent; /* 2 */
189
204
  background-image: none; /* 2 */
@@ -295,6 +310,13 @@ menu {
295
310
  padding: 0;
296
311
  }
297
312
 
313
+ /*
314
+ Reset default styling for dialogs.
315
+ */
316
+ dialog {
317
+ padding: 0;
318
+ }
319
+
298
320
  /*
299
321
  Prevent resizing textareas horizontally by default.
300
322
  */
@@ -358,10 +380,7 @@ video {
358
380
  height: auto;
359
381
  }
360
382
 
361
- /*
362
- Ensure the default browser behavior of the `hidden` attribute.
363
- */
364
-
383
+ /* Make elements with the HTML hidden attribute stay hidden by default */
365
384
  [hidden] {
366
385
  display: none;
367
386
  }
@@ -1,17 +1,21 @@
1
- import chalk from 'chalk'
1
+ import colors from 'picocolors'
2
2
  import log from './util/log'
3
3
 
4
4
  let defaults = {
5
- // TODO: Drop this once we can safely rely on optimizeUniversalDefaults being
6
- // the default.
7
- optimizeUniversalDefaults: process.env.NODE_ENV === 'test' ? true : false,
8
-
9
- // optimizeUniversalDefaults: true
5
+ optimizeUniversalDefaults: false,
6
+ generalizedModifiers: true,
7
+ disableColorOpacityUtilitiesByDefault: false,
8
+ relativeContentPathsByDefault: false,
10
9
  }
11
10
 
12
11
  let featureFlags = {
13
- future: [],
14
- experimental: ['optimizeUniversalDefaults'],
12
+ future: [
13
+ 'hoverOnlyWhenSupported',
14
+ 'respectDefaultRingColorOpacity',
15
+ 'disableColorOpacityUtilitiesByDefault',
16
+ 'relativeContentPathsByDefault',
17
+ ],
18
+ experimental: ['optimizeUniversalDefaults', 'generalizedModifiers'],
15
19
  }
16
20
 
17
21
  export function flagEnabled(config, flag) {
@@ -45,7 +49,7 @@ export function issueFlagNotices(config) {
45
49
 
46
50
  if (experimentalFlagsEnabled(config).length > 0) {
47
51
  let changes = experimentalFlagsEnabled(config)
48
- .map((s) => chalk.yellow(s))
52
+ .map((s) => colors.yellow(s))
49
53
  .join(', ')
50
54
 
51
55
  log.warn('experimental-flags-enabled', [
package/src/index.js CHANGED
@@ -1,28 +1 @@
1
- import setupTrackingContext from './lib/setupTrackingContext'
2
- import processTailwindFeatures from './processTailwindFeatures'
3
- import { env } from './lib/sharedState'
4
-
5
- module.exports = function tailwindcss(configOrPath) {
6
- return {
7
- postcssPlugin: 'tailwindcss',
8
- plugins: [
9
- env.DEBUG &&
10
- function (root) {
11
- console.log('\n')
12
- console.time('JIT TOTAL')
13
- return root
14
- },
15
- function (root, result) {
16
- processTailwindFeatures(setupTrackingContext(configOrPath))(root, result)
17
- },
18
- env.DEBUG &&
19
- function (root) {
20
- console.timeEnd('JIT TOTAL')
21
- console.log('\n')
22
- return root
23
- },
24
- ].filter(Boolean),
25
- }
26
- }
27
-
28
- 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
  }
@@ -0,0 +1,249 @@
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 { parseGlob } from '../util/parseGlob'
8
+ import { env } from './sharedState'
9
+
10
+ /*!
11
+ * Modified version of normalize-path, original license below
12
+ *
13
+ * normalize-path <https://github.com/jonschlinkert/normalize-path>
14
+ *
15
+ * Copyright (c) 2014-2018, Jon Schlinkert.
16
+ * Released under the MIT License.
17
+ */
18
+
19
+ function normalizePath(path) {
20
+ if (typeof path !== 'string') {
21
+ throw new TypeError('expected path to be a string')
22
+ }
23
+
24
+ if (path === '\\' || path === '/') return '/'
25
+
26
+ var len = path.length
27
+ if (len <= 1) return path
28
+
29
+ // ensure that win32 namespaces has two leading slashes, so that the path is
30
+ // handled properly by the win32 version of path.parse() after being normalized
31
+ // https://msdn.microsoft.com/library/windows/desktop/aa365247(v=vs.85).aspx#namespaces
32
+ var prefix = ''
33
+ if (len > 4 && path[3] === '\\') {
34
+ var ch = path[2]
35
+ if ((ch === '?' || ch === '.') && path.slice(0, 2) === '\\\\') {
36
+ path = path.slice(2)
37
+ prefix = '//'
38
+ }
39
+ }
40
+
41
+ // Modified part: instead of purely splitting on `\\` and `/`, we split on
42
+ // `/` and `\\` that is _not_ followed by any of the following characters: ()[]
43
+ // This is to ensure that we keep the escaping of brackets and parentheses
44
+ let segs = path.split(/[/\\]+(?![\(\)\[\]])/)
45
+ return prefix + segs.join('/')
46
+ }
47
+
48
+ /** @typedef {import('../../types/config.js').RawFile} RawFile */
49
+ /** @typedef {import('../../types/config.js').FilePath} FilePath */
50
+
51
+ /**
52
+ * @typedef {object} ContentPath
53
+ * @property {string} original
54
+ * @property {string} base
55
+ * @property {string | null} glob
56
+ * @property {boolean} ignore
57
+ * @property {string} pattern
58
+ */
59
+
60
+ /**
61
+ * Turn a list of content paths (absolute or not; glob or not) into a list of
62
+ * absolute file paths that exist on the filesystem
63
+ *
64
+ * If there are symlinks in the path then multiple paths will be returned
65
+ * one for the symlink and one for the actual file
66
+ *
67
+ * @param {*} context
68
+ * @param {import('tailwindcss').Config} tailwindConfig
69
+ * @returns {ContentPath[]}
70
+ */
71
+ export function parseCandidateFiles(context, tailwindConfig) {
72
+ let files = tailwindConfig.content.files
73
+
74
+ // Normalize the file globs
75
+ files = files.filter((filePath) => typeof filePath === 'string')
76
+ files = files.map(normalizePath)
77
+
78
+ // Split into included and excluded globs
79
+ let tasks = fastGlob.generateTasks(files)
80
+
81
+ /** @type {ContentPath[]} */
82
+ let included = []
83
+
84
+ /** @type {ContentPath[]} */
85
+ let excluded = []
86
+
87
+ for (const task of tasks) {
88
+ included.push(...task.positive.map((filePath) => parseFilePath(filePath, false)))
89
+ excluded.push(...task.negative.map((filePath) => parseFilePath(filePath, true)))
90
+ }
91
+
92
+ let paths = [...included, ...excluded]
93
+
94
+ // Resolve paths relative to the config file or cwd
95
+ paths = resolveRelativePaths(context, paths)
96
+
97
+ // Resolve symlinks if possible
98
+ paths = paths.flatMap(resolvePathSymlinks)
99
+
100
+ // Update cached patterns
101
+ paths = paths.map(resolveGlobPattern)
102
+
103
+ return paths
104
+ }
105
+
106
+ /**
107
+ *
108
+ * @param {string} filePath
109
+ * @param {boolean} ignore
110
+ * @returns {ContentPath}
111
+ */
112
+ function parseFilePath(filePath, ignore) {
113
+ // Escape special characters in the file path such as: ()[]
114
+ // But only if the special character isn't already escaped
115
+ filePath = filePath.replace(/(?<!\\)([\[\]\(\)])/g, '\\$1')
116
+
117
+ let contentPath = {
118
+ original: filePath,
119
+ base: filePath,
120
+ ignore,
121
+ pattern: filePath,
122
+ glob: null,
123
+ }
124
+
125
+ if (isGlob(filePath)) {
126
+ Object.assign(contentPath, parseGlob(filePath))
127
+ }
128
+
129
+ return contentPath
130
+ }
131
+
132
+ /**
133
+ *
134
+ * @param {ContentPath} contentPath
135
+ * @returns {ContentPath}
136
+ */
137
+ function resolveGlobPattern(contentPath) {
138
+ // This is required for Windows support to properly pick up Glob paths.
139
+ // Afaik, this technically shouldn't be needed but there's probably
140
+ // some internal, direct path matching with a normalized path in
141
+ // a package which can't handle mixed directory separators
142
+ let base = normalizePath(contentPath.base)
143
+
144
+ // If the user's file path contains any special characters (like parens) for instance fast-glob
145
+ // is like "OOOH SHINY" and treats them as such. So we have to escape the base path to fix this
146
+ base = fastGlob.escapePath(base)
147
+
148
+ contentPath.pattern = contentPath.glob ? `${base}/${contentPath.glob}` : base
149
+ contentPath.pattern = contentPath.ignore ? `!${contentPath.pattern}` : contentPath.pattern
150
+
151
+ return contentPath
152
+ }
153
+
154
+ /**
155
+ * Resolve each path relative to the config file (when possible) if the experimental flag is enabled
156
+ * Otherwise, resolve relative to the current working directory
157
+ *
158
+ * @param {any} context
159
+ * @param {ContentPath[]} contentPaths
160
+ * @returns {ContentPath[]}
161
+ */
162
+ function resolveRelativePaths(context, contentPaths) {
163
+ let resolveFrom = []
164
+
165
+ // Resolve base paths relative to the config file (when possible) if the experimental flag is enabled
166
+ if (context.userConfigPath && context.tailwindConfig.content.relative) {
167
+ resolveFrom = [path.dirname(context.userConfigPath)]
168
+ }
169
+
170
+ return contentPaths.map((contentPath) => {
171
+ contentPath.base = path.resolve(...resolveFrom, contentPath.base)
172
+
173
+ return contentPath
174
+ })
175
+ }
176
+
177
+ /**
178
+ * Resolve the symlink for the base directory / file in each path
179
+ * These are added as additional dependencies to watch for changes because
180
+ * some tools (like webpack) will only watch the actual file or directory
181
+ * but not the symlink itself even in projects that use monorepos.
182
+ *
183
+ * @param {ContentPath} contentPath
184
+ * @returns {ContentPath[]}
185
+ */
186
+ function resolvePathSymlinks(contentPath) {
187
+ let paths = [contentPath]
188
+
189
+ try {
190
+ let resolvedPath = fs.realpathSync(contentPath.base)
191
+ if (resolvedPath !== contentPath.base) {
192
+ paths.push({
193
+ ...contentPath,
194
+ base: resolvedPath,
195
+ })
196
+ }
197
+ } catch {
198
+ // TODO: log this?
199
+ }
200
+
201
+ return paths
202
+ }
203
+
204
+ /**
205
+ * @param {any} context
206
+ * @param {ContentPath[]} candidateFiles
207
+ * @param {Map<string, number>} fileModifiedMap
208
+ * @returns {[{ content: string, extension: string }[], Map<string, number>]}
209
+ */
210
+ export function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
211
+ let changedContent = context.tailwindConfig.content.files
212
+ .filter((item) => typeof item.raw === 'string')
213
+ .map(({ raw, extension = 'html' }) => ({ content: raw, extension }))
214
+
215
+ let [changedFiles, mTimesToCommit] = resolveChangedFiles(candidateFiles, fileModifiedMap)
216
+
217
+ for (let changedFile of changedFiles) {
218
+ let extension = path.extname(changedFile).slice(1)
219
+ changedContent.push({ file: changedFile, extension })
220
+ }
221
+
222
+ return [changedContent, mTimesToCommit]
223
+ }
224
+
225
+ /**
226
+ *
227
+ * @param {ContentPath[]} candidateFiles
228
+ * @param {Map<string, number>} fileModifiedMap
229
+ * @returns {[Set<string>, Map<string, number>]}
230
+ */
231
+ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
232
+ let paths = candidateFiles.map((contentPath) => contentPath.pattern)
233
+ let mTimesToCommit = new Map()
234
+
235
+ let changedFiles = new Set()
236
+ env.DEBUG && console.time('Finding changed files')
237
+ let files = fastGlob.sync(paths, { absolute: true })
238
+ for (let file of files) {
239
+ let prevModified = fileModifiedMap.get(file) || -Infinity
240
+ let modified = fs.statSync(file).mtimeMs
241
+
242
+ if (modified > prevModified) {
243
+ changedFiles.add(file)
244
+ mTimesToCommit.set(file, modified)
245
+ }
246
+ }
247
+ env.DEBUG && console.timeEnd('Finding changed files')
248
+ return [changedFiles, mTimesToCommit]
249
+ }