tailwindcss 0.0.0-insiders.ea80db2 → 0.0.0-insiders.eae2b7a

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 (213) hide show
  1. package/README.md +13 -9
  2. package/defaultTheme.d.ts +2 -1
  3. package/index.css +5 -0
  4. package/lib/cli/build/index.js +57 -0
  5. package/lib/cli/build/plugin.js +427 -0
  6. package/lib/cli/build/utils.js +88 -0
  7. package/lib/cli/build/watching.js +182 -0
  8. package/lib/cli/help/index.js +73 -0
  9. package/lib/cli/index.js +231 -0
  10. package/lib/cli/init/index.js +63 -0
  11. package/lib/cli.js +1 -759
  12. package/lib/corePluginList.js +12 -3
  13. package/lib/corePlugins.js +2308 -1739
  14. package/lib/css/preflight.css +13 -5
  15. package/lib/featureFlags.js +50 -25
  16. package/lib/index.js +1 -40
  17. package/lib/lib/cacheInvalidation.js +48 -25
  18. package/lib/lib/collapseAdjacentRules.js +17 -10
  19. package/lib/lib/collapseDuplicateDeclarations.js +13 -8
  20. package/lib/lib/content.js +207 -0
  21. package/lib/lib/defaultExtractor.js +232 -33
  22. package/lib/lib/detectNesting.js +21 -10
  23. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  24. package/lib/lib/expandApplyAtRules.js +316 -215
  25. package/lib/lib/expandTailwindAtRules.js +167 -115
  26. package/lib/lib/findAtConfigPath.js +46 -0
  27. package/lib/lib/generateRules.js +444 -211
  28. package/lib/lib/getModuleDependencies.js +88 -37
  29. package/lib/lib/handleImportAtRules.js +50 -0
  30. package/lib/lib/load-config.js +42 -0
  31. package/lib/lib/normalizeTailwindDirectives.js +29 -39
  32. package/lib/lib/offsets.js +306 -0
  33. package/lib/lib/partitionApplyAtRules.js +13 -8
  34. package/lib/lib/regex.js +74 -0
  35. package/lib/lib/remap-bitfield.js +89 -0
  36. package/lib/lib/resolveDefaultsAtRules.js +96 -74
  37. package/lib/lib/setupContextUtils.js +672 -300
  38. package/lib/lib/setupTrackingContext.js +63 -68
  39. package/lib/lib/sharedState.js +44 -17
  40. package/lib/lib/substituteScreenAtRules.js +14 -10
  41. package/lib/plugin.js +160 -0
  42. package/lib/postcss-plugins/nesting/README.md +2 -2
  43. package/lib/postcss-plugins/nesting/index.js +10 -6
  44. package/lib/postcss-plugins/nesting/plugin.js +24 -20
  45. package/lib/processTailwindFeatures.js +34 -29
  46. package/lib/public/colors.js +272 -246
  47. package/lib/public/create-plugin.js +9 -5
  48. package/lib/public/default-config.js +10 -6
  49. package/lib/public/default-theme.js +10 -6
  50. package/lib/public/load-config.js +12 -0
  51. package/lib/public/resolve-config.js +11 -6
  52. package/lib/util/applyImportantSelector.js +36 -0
  53. package/lib/util/bigSign.js +6 -1
  54. package/lib/util/buildMediaQuery.js +13 -6
  55. package/lib/util/cloneDeep.js +9 -6
  56. package/lib/util/cloneNodes.js +12 -3
  57. package/lib/util/color.js +66 -50
  58. package/lib/util/colorNames.js +752 -0
  59. package/lib/util/configurePlugins.js +7 -2
  60. package/lib/util/createPlugin.js +8 -5
  61. package/lib/util/createUtilityPlugin.js +13 -9
  62. package/lib/util/dataTypes.js +182 -111
  63. package/lib/util/defaults.js +12 -7
  64. package/lib/util/escapeClassName.js +13 -8
  65. package/lib/util/escapeCommas.js +7 -2
  66. package/lib/util/flattenColorPalette.js +11 -10
  67. package/lib/util/formatVariantSelector.js +228 -151
  68. package/lib/util/getAllConfigs.js +33 -12
  69. package/lib/util/hashConfig.js +9 -4
  70. package/lib/util/isKeyframeRule.js +7 -2
  71. package/lib/util/isPlainObject.js +7 -2
  72. package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
  73. package/lib/util/log.js +40 -13
  74. package/lib/util/nameClass.js +27 -10
  75. package/lib/util/negateValue.js +25 -8
  76. package/lib/util/normalizeConfig.js +155 -87
  77. package/lib/util/normalizeScreens.js +127 -8
  78. package/lib/util/parseAnimationValue.js +44 -40
  79. package/lib/util/parseBoxShadowValue.js +33 -62
  80. package/lib/util/parseDependency.js +39 -55
  81. package/lib/util/parseGlob.js +36 -0
  82. package/lib/util/parseObjectStyles.js +15 -10
  83. package/lib/util/pluginUtils.js +154 -59
  84. package/lib/util/prefixSelector.js +29 -10
  85. package/lib/util/pseudoElements.js +209 -0
  86. package/lib/util/removeAlphaVariables.js +31 -0
  87. package/lib/util/resolveConfig.js +96 -95
  88. package/lib/util/resolveConfigPath.js +29 -10
  89. package/lib/util/responsive.js +11 -6
  90. package/lib/util/splitAtTopLevelOnly.js +51 -0
  91. package/lib/util/tap.js +6 -1
  92. package/lib/util/toColorValue.js +7 -2
  93. package/lib/util/toPath.js +22 -4
  94. package/lib/util/transformThemeValue.js +40 -26
  95. package/lib/util/validateConfig.js +48 -0
  96. package/lib/util/validateFormalSyntax.js +26 -0
  97. package/lib/util/withAlphaVariable.js +27 -15
  98. package/lib/value-parser/LICENSE +22 -0
  99. package/lib/value-parser/README.md +3 -0
  100. package/lib/value-parser/index.d.js +2 -0
  101. package/lib/value-parser/index.js +22 -0
  102. package/lib/value-parser/parse.js +259 -0
  103. package/lib/value-parser/stringify.js +38 -0
  104. package/lib/value-parser/unit.js +86 -0
  105. package/lib/value-parser/walk.js +16 -0
  106. package/loadConfig.d.ts +4 -0
  107. package/loadConfig.js +2 -0
  108. package/package.json +54 -52
  109. package/plugin.d.ts +10 -5
  110. package/resolveConfig.d.ts +12 -0
  111. package/scripts/generate-types.js +53 -0
  112. package/scripts/release-channel.js +18 -0
  113. package/scripts/release-notes.js +21 -0
  114. package/scripts/type-utils.js +27 -0
  115. package/src/cli/build/index.js +53 -0
  116. package/src/cli/build/plugin.js +465 -0
  117. package/src/cli/build/utils.js +76 -0
  118. package/src/cli/build/watching.js +229 -0
  119. package/src/cli/help/index.js +70 -0
  120. package/src/cli/index.js +217 -0
  121. package/src/cli/init/index.js +79 -0
  122. package/src/cli.js +1 -836
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +576 -106
  125. package/src/css/preflight.css +13 -5
  126. package/src/featureFlags.js +17 -3
  127. package/src/index.js +1 -42
  128. package/src/lib/collapseAdjacentRules.js +5 -1
  129. package/src/lib/content.js +240 -0
  130. package/src/lib/defaultExtractor.js +202 -35
  131. package/src/lib/detectNesting.js +9 -1
  132. package/src/lib/evaluateTailwindFunctions.js +82 -8
  133. package/src/lib/expandApplyAtRules.js +322 -189
  134. package/src/lib/expandTailwindAtRules.js +82 -59
  135. package/src/lib/findAtConfigPath.js +48 -0
  136. package/src/lib/generateRules.js +413 -132
  137. package/src/lib/getModuleDependencies.js +70 -30
  138. package/src/lib/handleImportAtRules.js +34 -0
  139. package/src/lib/load-config.ts +31 -0
  140. package/src/lib/normalizeTailwindDirectives.js +0 -27
  141. package/src/lib/offsets.js +373 -0
  142. package/src/lib/regex.js +74 -0
  143. package/src/lib/remap-bitfield.js +82 -0
  144. package/src/lib/resolveDefaultsAtRules.js +53 -36
  145. package/src/lib/setupContextUtils.js +570 -151
  146. package/src/lib/setupTrackingContext.js +44 -58
  147. package/src/lib/sharedState.js +13 -4
  148. package/src/plugin.js +128 -0
  149. package/src/postcss-plugins/nesting/README.md +2 -2
  150. package/src/public/colors.js +22 -0
  151. package/src/public/default-config.js +1 -1
  152. package/src/public/default-theme.js +2 -2
  153. package/src/public/load-config.js +2 -0
  154. package/src/util/applyImportantSelector.js +27 -0
  155. package/src/util/buildMediaQuery.js +5 -3
  156. package/src/util/cloneNodes.js +5 -1
  157. package/src/util/color.js +34 -17
  158. package/src/util/colorNames.js +150 -0
  159. package/src/util/dataTypes.js +67 -23
  160. package/src/util/formatVariantSelector.js +264 -144
  161. package/src/util/getAllConfigs.js +21 -2
  162. package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
  163. package/src/util/log.js +25 -1
  164. package/src/util/nameClass.js +4 -0
  165. package/src/util/negateValue.js +11 -3
  166. package/src/util/normalizeConfig.js +78 -20
  167. package/src/util/normalizeScreens.js +99 -4
  168. package/src/util/parseBoxShadowValue.js +3 -50
  169. package/src/util/parseDependency.js +37 -42
  170. package/src/util/parseGlob.js +24 -0
  171. package/src/util/pluginUtils.js +118 -23
  172. package/src/util/prefixSelector.js +28 -10
  173. package/src/util/pseudoElements.js +167 -0
  174. package/src/util/removeAlphaVariables.js +24 -0
  175. package/src/util/resolveConfig.js +70 -62
  176. package/src/util/resolveConfigPath.js +12 -1
  177. package/src/util/splitAtTopLevelOnly.js +52 -0
  178. package/src/util/toPath.js +1 -1
  179. package/src/util/transformThemeValue.js +13 -3
  180. package/src/util/validateConfig.js +36 -0
  181. package/src/util/validateFormalSyntax.js +34 -0
  182. package/src/util/withAlphaVariable.js +1 -1
  183. package/src/value-parser/LICENSE +22 -0
  184. package/src/value-parser/README.md +3 -0
  185. package/src/value-parser/index.d.ts +177 -0
  186. package/src/value-parser/index.js +28 -0
  187. package/src/value-parser/parse.js +303 -0
  188. package/src/value-parser/stringify.js +41 -0
  189. package/src/value-parser/unit.js +118 -0
  190. package/src/value-parser/walk.js +18 -0
  191. package/stubs/.gitignore +1 -0
  192. package/stubs/.prettierrc.json +6 -0
  193. package/stubs/{defaultConfig.stub.js → config.full.js} +215 -165
  194. package/stubs/{simpleConfig.stub.js → config.simple.js} +1 -1
  195. package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -1
  196. package/stubs/postcss.config.js +5 -0
  197. package/stubs/tailwind.config.cjs +2 -0
  198. package/stubs/tailwind.config.js +2 -0
  199. package/stubs/tailwind.config.ts +3 -0
  200. package/types/config.d.ts +102 -56
  201. package/types/generated/colors.d.ts +22 -0
  202. package/types/generated/corePluginList.d.ts +1 -1
  203. package/types/generated/default-theme.d.ts +372 -0
  204. package/types/index.d.ts +7 -1
  205. package/CHANGELOG.md +0 -2099
  206. package/lib/cli-peer-dependencies.js +0 -15
  207. package/lib/constants.js +0 -37
  208. package/peers/index.js +0 -75156
  209. package/scripts/install-integrations.js +0 -27
  210. package/scripts/rebuildFixtures.js +0 -68
  211. package/src/cli-peer-dependencies.js +0 -9
  212. package/src/constants.js +0 -17
  213. package/types.d.ts +0 -1
@@ -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
  /*
@@ -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
  */
@@ -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
  }
@@ -3,11 +3,25 @@ import log from './util/log'
3
3
 
4
4
  let defaults = {
5
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) {
package/src/index.js CHANGED
@@ -1,42 +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
- let context = setupTrackingContext(configOrPath)
17
-
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)
31
- },
32
- env.DEBUG &&
33
- function (root) {
34
- console.timeEnd('JIT TOTAL')
35
- console.log('\n')
36
- return root
37
- },
38
- ].filter(Boolean),
39
- }
40
- }
41
-
42
- module.exports.postcss = true
1
+ module.exports = require('./plugin')
@@ -29,7 +29,11 @@ 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
@@ -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
+ }
@@ -1,42 +1,209 @@
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
1
+ import { flagEnabled } from '../featureFlags'
2
+ import * as regex from './regex'
3
+
4
+ export function defaultExtractor(context) {
5
+ let patterns = Array.from(buildRegExps(context))
6
+
7
+ /**
8
+ * @param {string} content
9
+ */
10
+ return (content) => {
11
+ /** @type {(string|string)[]} */
12
+ let results = []
13
+
14
+ for (let pattern of patterns) {
15
+ results = [...results, ...(content.match(pattern) ?? [])]
16
+ }
17
+
18
+ return results.filter((v) => v !== undefined).map(clipAtBalancedParens)
19
+ }
20
+ }
21
+
22
+ function* buildRegExps(context) {
23
+ let separator = context.tailwindConfig.separator
24
+ let variantGroupingEnabled = flagEnabled(context.tailwindConfig, 'variantGrouping')
25
+ let prefix =
26
+ context.tailwindConfig.prefix !== ''
27
+ ? regex.optional(regex.pattern([/-?/, regex.escape(context.tailwindConfig.prefix)]))
28
+ : ''
29
+
30
+ let utility = regex.any([
31
+ // Arbitrary properties (without square brackets)
32
+ /\[[^\s:'"`]+:[^\s\[\]]+\]/,
33
+
34
+ // Arbitrary properties with balanced square brackets
35
+ // This is a targeted fix to continue to allow theme()
36
+ // with square brackets to work in arbitrary properties
37
+ // while fixing a problem with the regex matching too much
38
+ /\[[^\s:'"`]+:[^\s]+?\[[^\s]+\][^\s]+?\]/,
39
+
40
+ // Utilities
41
+ regex.pattern([
42
+ // Utility Name / Group Name
43
+ /-?(?:\w+)/,
44
+
45
+ // Normal/Arbitrary values
46
+ regex.optional(
47
+ regex.any([
48
+ regex.pattern([
49
+ // Arbitrary values
50
+ /-(?:\w+-)*\[[^\s:]+\]/,
51
+
52
+ // Not immediately followed by an `{[(`
53
+ /(?![{([]])/,
54
+
55
+ // optionally followed by an opacity modifier
56
+ /(?:\/[^\s'"`\\><$]*)?/,
57
+ ]),
58
+
59
+ regex.pattern([
60
+ // Arbitrary values
61
+ /-(?:\w+-)*\[[^\s]+\]/,
62
+
63
+ // Not immediately followed by an `{[(`
64
+ /(?![{([]])/,
65
+
66
+ // optionally followed by an opacity modifier
67
+ /(?:\/[^\s'"`\\$]*)?/,
68
+ ]),
69
+
70
+ // Normal values w/o quotes — may include an opacity modifier
71
+ /[-\/][^\s'"`\\$={><]*/,
72
+ ])
73
+ ),
74
+ ]),
75
+ ])
76
+
77
+ let variantPatterns = [
78
+ // Without quotes
79
+ regex.any([
80
+ // This is here to provide special support for the `@` variant
81
+ regex.pattern([/@\[[^\s"'`]+\](\/[^\s"'`]+)?/, separator]),
82
+
83
+ regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s"'`]+\]/, separator]),
84
+ regex.pattern([/[^\s"'`\[\\]+/, separator]),
85
+ ]),
86
+
87
+ // With quotes allowed
88
+ regex.any([
89
+ regex.pattern([/([^\s"'`\[\\]+-)?\[[^\s`]+\]/, separator]),
90
+ regex.pattern([/[^\s`\[\\]+/, separator]),
91
+ ]),
92
+ ]
93
+
94
+ for (const variantPattern of variantPatterns) {
95
+ yield regex.pattern([
96
+ // Variants
97
+ '((?=((',
98
+ variantPattern,
99
+ ')+))\\2)?',
100
+
101
+ // Important (optional)
102
+ /!?/,
103
+
104
+ prefix,
105
+
106
+ variantGroupingEnabled
107
+ ? regex.any([
108
+ // Or any of those things but grouped separated by commas
109
+ regex.pattern([/\(/, utility, regex.zeroOrMore([/,/, utility]), /\)/]),
110
+
111
+ // Arbitrary properties, constrained utilities, arbitrary values, etc…
112
+ utility,
113
+ ])
114
+ : utility,
115
+ ])
116
+ }
117
+
118
+ // 5. Inner matches
119
+ yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
120
+ }
121
+
122
+ // We want to capture any "special" characters
123
+ // AND the characters immediately following them (if there is one)
124
+ let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g
125
+ let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/
30
126
 
31
127
  /**
32
- * @param {string} content
128
+ * Clips a string ensuring that parentheses, quotes, etc… are balanced
129
+ * Used for arbitrary values only
130
+ *
131
+ * We will go past the end of the balanced parens until we find a non-class character
132
+ *
133
+ * Depth matching behavior:
134
+ * w-[calc(100%-theme('spacing[some_key][1.5]'))]']
135
+ * ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
136
+ * 1 2 3 4 34 3 210 END
137
+ * ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
138
+ *
139
+ * @param {string} input
33
140
  */
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)
141
+ function clipAtBalancedParens(input) {
142
+ // We are care about this for arbitrary values
143
+ if (!input.includes('-[')) {
144
+ return input
145
+ }
146
+
147
+ let depth = 0
148
+ let openStringTypes = []
149
+
150
+ // Find all parens, brackets, quotes, etc
151
+ // Stop when we end at a balanced pair
152
+ // This is naive and will treat mismatched parens as balanced
153
+ // This shouldn't be a problem in practice though
154
+ let matches = input.matchAll(SPECIALS)
155
+
156
+ // We can't use lookbehind assertions because we have to support Safari
157
+ // So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
158
+ matches = Array.from(matches).flatMap((match) => {
159
+ const [, ...groups] = match
160
+
161
+ return groups.map((group, idx) =>
162
+ Object.assign([], match, {
163
+ index: match.index + idx,
164
+ 0: group,
165
+ })
166
+ )
167
+ })
168
+
169
+ for (let match of matches) {
170
+ let char = match[0]
171
+ let inStringType = openStringTypes[openStringTypes.length - 1]
172
+
173
+ if (char === inStringType) {
174
+ openStringTypes.pop()
175
+ } else if (char === "'" || char === '"' || char === '`') {
176
+ openStringTypes.push(char)
177
+ }
178
+
179
+ if (inStringType) {
180
+ continue
181
+ } else if (char === '[') {
182
+ depth++
183
+ continue
184
+ } else if (char === ']') {
185
+ depth--
186
+ continue
187
+ }
188
+
189
+ // We've gone one character past the point where we should stop
190
+ // This means that there was an extra closing `]`
191
+ // We'll clip to just before it
192
+ if (depth < 0) {
193
+ return input.substring(0, match.index - 1)
194
+ }
195
+
196
+ // We've finished balancing the brackets but there still may be characters that can be included
197
+ // For example in the class `text-[#336699]/[.35]`
198
+ // The depth goes to `0` at the closing `]` but goes up again at the `[`
199
+
200
+ // If we're at zero and encounter a non-class character then we clip the class there
201
+ if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
202
+ return input.substring(0, match.index)
203
+ }
204
+ }
38
205
 
39
- return results
206
+ return input
40
207
  }
41
208
 
42
209
  // Regular utilities
@@ -1,3 +1,11 @@
1
+ function isRoot(node) {
2
+ return node.type === 'root'
3
+ }
4
+
5
+ function isAtLayer(node) {
6
+ return node.type === 'atrule' && node.name === 'layer'
7
+ }
8
+
1
9
  export default function (_context) {
2
10
  return (root, result) => {
3
11
  let found = false
@@ -5,7 +13,7 @@ export default function (_context) {
5
13
  root.walkAtRules('tailwind', (node) => {
6
14
  if (found) return false
7
15
 
8
- if (node.parent && node.parent.type !== 'root') {
16
+ if (node.parent && !(isRoot(node.parent) || isAtLayer(node.parent))) {
9
17
  found = true
10
18
  node.warn(
11
19
  result,