tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cb6e45a

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 (190) hide show
  1. package/CHANGELOG.md +526 -2
  2. package/LICENSE +1 -2
  3. package/README.md +13 -6
  4. package/colors.d.ts +3 -0
  5. package/colors.js +2 -1
  6. package/defaultConfig.d.ts +3 -0
  7. package/defaultConfig.js +2 -1
  8. package/defaultTheme.d.ts +4 -0
  9. package/defaultTheme.js +2 -1
  10. package/lib/cli/build/deps.js +54 -0
  11. package/lib/cli/build/index.js +44 -0
  12. package/lib/cli/build/plugin.js +335 -0
  13. package/lib/cli/build/utils.js +78 -0
  14. package/lib/cli/build/watching.js +113 -0
  15. package/lib/cli/help/index.js +71 -0
  16. package/lib/cli/index.js +18 -0
  17. package/lib/cli/init/index.js +46 -0
  18. package/lib/cli/shared.js +12 -0
  19. package/lib/cli-peer-dependencies.js +20 -7
  20. package/lib/cli.js +91 -569
  21. package/lib/constants.js +27 -20
  22. package/lib/corePluginList.js +16 -4
  23. package/lib/corePlugins.js +2247 -1873
  24. package/lib/css/preflight.css +20 -9
  25. package/lib/featureFlags.js +37 -23
  26. package/lib/index.js +28 -12
  27. package/lib/lib/cacheInvalidation.js +90 -0
  28. package/lib/lib/collapseAdjacentRules.js +27 -9
  29. package/lib/lib/collapseDuplicateDeclarations.js +83 -0
  30. package/lib/lib/content.js +167 -0
  31. package/lib/lib/defaultExtractor.js +236 -0
  32. package/lib/lib/detectNesting.js +21 -3
  33. package/lib/lib/evaluateTailwindFunctions.js +117 -50
  34. package/lib/lib/expandApplyAtRules.js +439 -160
  35. package/lib/lib/expandTailwindAtRules.js +141 -151
  36. package/lib/lib/findAtConfigPath.js +44 -0
  37. package/lib/lib/generateRules.js +572 -105
  38. package/lib/lib/getModuleDependencies.js +11 -8
  39. package/lib/lib/normalizeTailwindDirectives.js +45 -33
  40. package/lib/lib/offsets.js +217 -0
  41. package/lib/lib/partitionApplyAtRules.js +56 -0
  42. package/lib/lib/regex.js +60 -0
  43. package/lib/lib/resolveDefaultsAtRules.js +114 -81
  44. package/lib/lib/setupContextUtils.js +777 -385
  45. package/lib/lib/setupTrackingContext.js +43 -71
  46. package/lib/lib/sharedState.js +49 -18
  47. package/lib/lib/substituteScreenAtRules.js +13 -8
  48. package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
  49. package/lib/postcss-plugins/nesting/index.js +19 -0
  50. package/lib/postcss-plugins/nesting/plugin.js +87 -0
  51. package/lib/processTailwindFeatures.js +36 -21
  52. package/lib/public/colors.js +250 -252
  53. package/lib/public/create-plugin.js +6 -4
  54. package/lib/public/default-config.js +7 -5
  55. package/lib/public/default-theme.js +7 -5
  56. package/lib/public/resolve-config.js +8 -5
  57. package/lib/util/bigSign.js +4 -1
  58. package/lib/util/buildMediaQuery.js +18 -24
  59. package/lib/util/cloneDeep.js +7 -6
  60. package/lib/util/cloneNodes.js +21 -3
  61. package/lib/util/color.js +54 -40
  62. package/lib/util/configurePlugins.js +5 -2
  63. package/lib/util/createPlugin.js +6 -6
  64. package/lib/util/createUtilityPlugin.js +11 -13
  65. package/lib/util/dataTypes.js +137 -100
  66. package/lib/util/defaults.js +10 -1
  67. package/lib/util/escapeClassName.js +7 -4
  68. package/lib/util/escapeCommas.js +5 -2
  69. package/lib/util/flattenColorPalette.js +9 -12
  70. package/lib/util/formatVariantSelector.js +285 -0
  71. package/lib/util/getAllConfigs.js +27 -8
  72. package/lib/util/hashConfig.js +6 -3
  73. package/lib/util/isKeyframeRule.js +5 -2
  74. package/lib/util/isPlainObject.js +5 -2
  75. package/lib/util/isValidArbitraryValue.js +72 -0
  76. package/lib/util/log.js +44 -22
  77. package/lib/util/nameClass.js +20 -8
  78. package/lib/util/negateValue.js +23 -6
  79. package/lib/util/normalizeConfig.js +267 -0
  80. package/lib/util/normalizeScreens.js +170 -0
  81. package/lib/util/parseAnimationValue.js +42 -40
  82. package/lib/util/parseBoxShadowValue.js +84 -0
  83. package/lib/util/parseDependency.js +38 -56
  84. package/lib/util/parseGlob.js +34 -0
  85. package/lib/util/parseObjectStyles.js +11 -8
  86. package/lib/util/pluginUtils.js +171 -189
  87. package/lib/util/prefixSelector.js +10 -10
  88. package/lib/util/removeAlphaVariables.js +29 -0
  89. package/lib/util/resolveConfig.js +92 -126
  90. package/lib/util/resolveConfigPath.js +11 -9
  91. package/lib/util/responsive.js +8 -5
  92. package/lib/util/splitAtTopLevelOnly.js +43 -0
  93. package/lib/util/tap.js +4 -1
  94. package/lib/util/toColorValue.js +5 -3
  95. package/lib/util/toPath.js +24 -3
  96. package/lib/util/transformThemeValue.js +49 -31
  97. package/lib/util/validateConfig.js +24 -0
  98. package/lib/util/validateFormalSyntax.js +24 -0
  99. package/lib/util/withAlphaVariable.js +23 -15
  100. package/nesting/index.js +2 -12
  101. package/package.json +48 -46
  102. package/peers/index.js +14817 -12471
  103. package/plugin.d.ts +11 -0
  104. package/plugin.js +2 -1
  105. package/resolveConfig.d.ts +3 -0
  106. package/resolveConfig.js +2 -1
  107. package/scripts/create-plugin-list.js +2 -2
  108. package/scripts/generate-types.js +105 -0
  109. package/scripts/release-channel.js +18 -0
  110. package/scripts/release-notes.js +21 -0
  111. package/scripts/type-utils.js +27 -0
  112. package/src/cli/build/deps.js +56 -0
  113. package/src/cli/build/index.js +45 -0
  114. package/src/cli/build/plugin.js +397 -0
  115. package/src/cli/build/utils.js +76 -0
  116. package/src/cli/build/watching.js +134 -0
  117. package/src/cli/help/index.js +70 -0
  118. package/src/cli/index.js +3 -0
  119. package/src/cli/init/index.js +50 -0
  120. package/src/cli/shared.js +5 -0
  121. package/src/cli-peer-dependencies.js +7 -1
  122. package/src/cli.js +26 -565
  123. package/src/corePluginList.js +1 -1
  124. package/src/corePlugins.js +905 -615
  125. package/src/css/preflight.css +20 -9
  126. package/src/featureFlags.js +26 -10
  127. package/src/index.js +19 -6
  128. package/src/lib/cacheInvalidation.js +52 -0
  129. package/src/lib/collapseAdjacentRules.js +21 -2
  130. package/src/lib/collapseDuplicateDeclarations.js +93 -0
  131. package/src/lib/content.js +205 -0
  132. package/src/lib/defaultExtractor.js +211 -0
  133. package/src/lib/detectNesting.js +22 -3
  134. package/src/lib/evaluateTailwindFunctions.js +84 -10
  135. package/src/lib/expandApplyAtRules.js +488 -153
  136. package/src/lib/expandTailwindAtRules.js +94 -106
  137. package/src/lib/findAtConfigPath.js +50 -0
  138. package/src/lib/generateRules.js +589 -67
  139. package/src/lib/normalizeTailwindDirectives.js +10 -3
  140. package/src/lib/offsets.js +270 -0
  141. package/src/lib/partitionApplyAtRules.js +52 -0
  142. package/src/lib/regex.js +74 -0
  143. package/src/lib/resolveDefaultsAtRules.js +98 -60
  144. package/src/lib/setupContextUtils.js +737 -246
  145. package/src/lib/setupTrackingContext.js +16 -54
  146. package/src/lib/sharedState.js +44 -7
  147. package/src/lib/substituteScreenAtRules.js +6 -3
  148. package/src/postcss-plugins/nesting/README.md +42 -0
  149. package/src/postcss-plugins/nesting/index.js +13 -0
  150. package/src/postcss-plugins/nesting/plugin.js +80 -0
  151. package/src/processTailwindFeatures.js +17 -2
  152. package/src/public/colors.js +4 -9
  153. package/src/util/buildMediaQuery.js +14 -16
  154. package/src/util/cloneNodes.js +19 -2
  155. package/src/util/color.js +31 -14
  156. package/src/util/createUtilityPlugin.js +2 -2
  157. package/src/util/dataTypes.js +57 -21
  158. package/src/util/defaults.js +6 -0
  159. package/src/util/formatVariantSelector.js +319 -0
  160. package/src/util/getAllConfigs.js +19 -0
  161. package/src/util/isValidArbitraryValue.js +61 -0
  162. package/src/util/log.js +23 -22
  163. package/src/util/nameClass.js +6 -2
  164. package/src/util/negateValue.js +14 -4
  165. package/src/util/normalizeConfig.js +282 -0
  166. package/src/util/normalizeScreens.js +140 -0
  167. package/src/util/parseBoxShadowValue.js +72 -0
  168. package/src/util/parseDependency.js +37 -42
  169. package/src/util/parseGlob.js +24 -0
  170. package/src/util/pluginUtils.js +144 -152
  171. package/src/util/prefixSelector.js +7 -8
  172. package/src/util/removeAlphaVariables.js +24 -0
  173. package/src/util/resolveConfig.js +82 -81
  174. package/src/util/splitAtTopLevelOnly.js +45 -0
  175. package/src/util/toPath.js +23 -1
  176. package/src/util/transformThemeValue.js +33 -8
  177. package/src/util/validateConfig.js +13 -0
  178. package/src/util/validateFormalSyntax.js +34 -0
  179. package/src/util/withAlphaVariable.js +1 -1
  180. package/stubs/defaultConfig.stub.js +173 -93
  181. package/stubs/simpleConfig.stub.js +1 -1
  182. package/types/config.d.ts +361 -0
  183. package/types/generated/.gitkeep +0 -0
  184. package/types/generated/colors.d.ts +276 -0
  185. package/types/generated/corePluginList.d.ts +1 -0
  186. package/types/generated/default-theme.d.ts +342 -0
  187. package/types/index.d.ts +7 -0
  188. package/lib/lib/setupWatchingContext.js +0 -284
  189. package/nesting/plugin.js +0 -41
  190. package/src/lib/setupWatchingContext.js +0 -306
@@ -1,306 +0,0 @@
1
- import fs from 'fs'
2
- import path from 'path'
3
-
4
- import tmp from 'tmp'
5
- import chokidar from 'chokidar'
6
- import fastGlob from 'fast-glob'
7
- import LRU from 'quick-lru'
8
- import normalizePath from 'normalize-path'
9
-
10
- import hash from '../util/hashConfig'
11
- import log from '../util/log'
12
- import getModuleDependencies from '../lib/getModuleDependencies'
13
- import resolveConfig from '../public/resolve-config'
14
- import resolveConfigPath from '../util/resolveConfigPath'
15
- import { getContext } from './setupContextUtils'
16
-
17
- // This is used to trigger rebuilds. Just updating the timestamp
18
- // is significantly faster than actually writing to the file (10x).
19
-
20
- function touch(filename) {
21
- let time = new Date()
22
-
23
- try {
24
- fs.utimesSync(filename, time, time)
25
- } catch (err) {
26
- fs.closeSync(fs.openSync(filename, 'w'))
27
- }
28
- }
29
-
30
- let watchers = new WeakMap()
31
-
32
- function getWatcher(context) {
33
- if (watchers.has(context)) {
34
- return watchers.get(context)
35
- }
36
-
37
- return null
38
- }
39
-
40
- function setWatcher(context, watcher) {
41
- return watchers.set(context, watcher)
42
- }
43
-
44
- let touchFiles = new WeakMap()
45
-
46
- function getTouchFile(context) {
47
- if (touchFiles.has(context)) {
48
- return touchFiles.get(context)
49
- }
50
-
51
- return null
52
- }
53
-
54
- function setTouchFile(context, touchFile) {
55
- return touchFiles.set(context, touchFile)
56
- }
57
-
58
- let configPaths = new WeakMap()
59
-
60
- function getConfigPath(context, configOrPath) {
61
- if (!configPaths.has(context)) {
62
- configPaths.set(context, resolveConfigPath(configOrPath))
63
- }
64
-
65
- return configPaths.get(context)
66
- }
67
-
68
- function rebootWatcher(context, configPath, configDependencies, candidateFiles) {
69
- let touchFile = getTouchFile(context)
70
-
71
- if (touchFile === null) {
72
- touchFile = tmp.fileSync().name
73
- setTouchFile(context, touchFile)
74
- touch(touchFile)
75
- }
76
-
77
- let watcher = getWatcher(context)
78
-
79
- Promise.resolve(watcher ? watcher.close() : null).then(() => {
80
- log.info([
81
- 'Tailwind CSS is watching for changes...',
82
- 'https://tailwindcss.com/docs/just-in-time-mode#watch-mode-and-one-off-builds',
83
- ])
84
-
85
- watcher = chokidar.watch([...candidateFiles, ...configDependencies], {
86
- ignoreInitial: true,
87
- })
88
-
89
- setWatcher(context, watcher)
90
-
91
- watcher.on('add', (file) => {
92
- let changedFile = path.resolve('.', file)
93
- let content = fs.readFileSync(changedFile, 'utf8')
94
- let extension = path.extname(changedFile).slice(1)
95
- context.changedContent.push({ content, extension })
96
- touch(touchFile)
97
- })
98
-
99
- watcher.on('change', (file) => {
100
- // If it was a config dependency, touch the config file to trigger a new context.
101
- // This is not really that clean of a solution but it's the fastest, because we
102
- // can do a very quick check on each build to see if the config has changed instead
103
- // of having to get all of the module dependencies and check every timestamp each
104
- // time.
105
- if (configDependencies.has(file)) {
106
- for (let dependency of configDependencies) {
107
- delete require.cache[require.resolve(dependency)]
108
- }
109
- touch(configPath)
110
- } else {
111
- let changedFile = path.resolve('.', file)
112
- let content = fs.readFileSync(changedFile, 'utf8')
113
- let extension = path.extname(changedFile).slice(1)
114
- context.changedContent.push({ content, extension })
115
- touch(touchFile)
116
- }
117
- })
118
-
119
- watcher.on('unlink', (file) => {
120
- // Touch the config file if any of the dependencies are deleted.
121
- if (configDependencies.has(file)) {
122
- for (let dependency of configDependencies) {
123
- delete require.cache[require.resolve(dependency)]
124
- }
125
- touch(configPath)
126
- }
127
- })
128
- })
129
- }
130
-
131
- let configPathCache = new LRU({ maxSize: 100 })
132
-
133
- let configDependenciesCache = new WeakMap()
134
-
135
- function getConfigDependencies(context) {
136
- if (!configDependenciesCache.has(context)) {
137
- configDependenciesCache.set(context, new Set())
138
- }
139
-
140
- return configDependenciesCache.get(context)
141
- }
142
-
143
- let candidateFilesCache = new WeakMap()
144
-
145
- function getCandidateFiles(context, tailwindConfig) {
146
- if (candidateFilesCache.has(context)) {
147
- return candidateFilesCache.get(context)
148
- }
149
-
150
- let candidateFiles = tailwindConfig.content.content
151
- .filter((item) => typeof item === 'string')
152
- .map((contentPath) => normalizePath(contentPath))
153
-
154
- return candidateFilesCache.set(context, candidateFiles).get(context)
155
- }
156
-
157
- // Get the config object based on a path
158
- function getTailwindConfig(configOrPath) {
159
- let userConfigPath = resolveConfigPath(configOrPath)
160
-
161
- if (userConfigPath !== null) {
162
- let [prevConfig, prevModified = -Infinity, prevConfigHash] =
163
- configPathCache.get(userConfigPath) || []
164
- let modified = fs.statSync(userConfigPath).mtimeMs
165
-
166
- // It hasn't changed (based on timestamp)
167
- if (modified <= prevModified) {
168
- return [prevConfig, userConfigPath, prevConfigHash, [userConfigPath]]
169
- }
170
-
171
- // It has changed (based on timestamp), or first run
172
- delete require.cache[userConfigPath]
173
- let newConfig = resolveConfig(require(userConfigPath))
174
- let newHash = hash(newConfig)
175
- configPathCache.set(userConfigPath, [newConfig, modified, newHash])
176
- return [newConfig, userConfigPath, newHash, [userConfigPath]]
177
- }
178
-
179
- // It's a plain object, not a path
180
- let newConfig = resolveConfig(
181
- configOrPath.config === undefined ? configOrPath : configOrPath.config
182
- )
183
-
184
- return [newConfig, null, hash(newConfig), []]
185
- }
186
-
187
- function resolvedChangedContent(context, candidateFiles) {
188
- let changedContent = context.tailwindConfig.content.content
189
- .filter((item) => typeof item.raw === 'string')
190
- .concat(context.tailwindConfig.content.safelist)
191
- .concat(context.safelist())
192
- .map(({ raw, extension }) => ({ content: raw, extension }))
193
-
194
- for (let changedFile of resolveChangedFiles(context, candidateFiles)) {
195
- let content = fs.readFileSync(changedFile, 'utf8')
196
- let extension = path.extname(changedFile).slice(1)
197
- changedContent.push({ content, extension })
198
- }
199
- return changedContent
200
- }
201
-
202
- let scannedContentCache = new WeakMap()
203
-
204
- function resolveChangedFiles(context, candidateFiles) {
205
- let changedFiles = new Set()
206
-
207
- // If we're not set up and watching files ourselves, we need to do
208
- // the work of grabbing all of the template files for candidate
209
- // detection.
210
- if (!scannedContentCache.has(context)) {
211
- let files = fastGlob.sync(candidateFiles)
212
- for (let file of files) {
213
- changedFiles.add(file)
214
- }
215
- scannedContentCache.set(context, true)
216
- }
217
-
218
- return changedFiles
219
- }
220
-
221
- // DISABLE_TOUCH = FALSE
222
-
223
- // Retrieve an existing context from cache if possible (since contexts are unique per
224
- // source path), or set up a new one (including setting up watchers and registering
225
- // plugins) then return it
226
- export default function setupWatchingContext(configOrPath) {
227
- return ({ tailwindDirectives, registerDependency }) => {
228
- return (root, result) => {
229
- let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] =
230
- getTailwindConfig(configOrPath)
231
-
232
- let contextDependencies = new Set(configDependencies)
233
-
234
- // If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
235
- // to be dependencies of the context. Can reuse the context even if they change.
236
- // We may want to think about `@layer` being part of this trigger too, but it's tough
237
- // because it's impossible for a layer in one file to end up in the actual @tailwind rule
238
- // in another file since independent sources are effectively isolated.
239
- if (tailwindDirectives.size > 0) {
240
- // Add current css file as a context dependencies.
241
- contextDependencies.add(result.opts.from)
242
-
243
- // Add all css @import dependencies as context dependencies.
244
- for (let message of result.messages) {
245
- if (message.type === 'dependency') {
246
- contextDependencies.add(message.file)
247
- }
248
- }
249
- }
250
-
251
- let [context, isNewContext] = getContext(
252
- root,
253
- result,
254
- tailwindConfig,
255
- userConfigPath,
256
- tailwindConfigHash,
257
- contextDependencies
258
- )
259
-
260
- let candidateFiles = getCandidateFiles(context, tailwindConfig)
261
- let contextConfigDependencies = getConfigDependencies(context)
262
-
263
- for (let file of configDependencies) {
264
- registerDependency({ type: 'dependency', file })
265
- }
266
-
267
- context.disposables.push((oldContext) => {
268
- let watcher = getWatcher(oldContext)
269
- if (watcher !== null) {
270
- watcher.close()
271
- }
272
- })
273
-
274
- let configPath = getConfigPath(context, configOrPath)
275
-
276
- if (configPath !== null) {
277
- for (let dependency of getModuleDependencies(configPath)) {
278
- if (dependency.file === configPath) {
279
- continue
280
- }
281
-
282
- contextConfigDependencies.add(dependency.file)
283
- }
284
- }
285
-
286
- if (isNewContext) {
287
- rebootWatcher(context, configPath, contextConfigDependencies, candidateFiles)
288
- }
289
-
290
- // Register our temp file as a dependency — we write to this file
291
- // to trigger rebuilds.
292
- let touchFile = getTouchFile(context)
293
- if (touchFile) {
294
- registerDependency({ type: 'dependency', file: touchFile })
295
- }
296
-
297
- if (tailwindDirectives.size > 0) {
298
- for (let changedContent of resolvedChangedContent(context, candidateFiles)) {
299
- context.changedContent.push(changedContent)
300
- }
301
- }
302
-
303
- return context
304
- }
305
- }
306
- }