tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cab1fce
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.
- package/CHANGELOG.md +380 -1
- package/LICENSE +1 -2
- package/README.md +8 -4
- package/colors.d.ts +3 -0
- package/colors.js +2 -1
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -1
- package/defaultTheme.d.ts +3 -0
- package/defaultTheme.js +2 -1
- package/lib/cli-peer-dependencies.js +10 -5
- package/lib/cli.js +311 -213
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +11 -1
- package/lib/corePlugins.js +1895 -1773
- package/lib/css/preflight.css +19 -13
- package/lib/featureFlags.js +22 -16
- package/lib/index.js +17 -8
- package/lib/lib/cacheInvalidation.js +69 -0
- package/lib/lib/collapseAdjacentRules.js +30 -14
- package/lib/lib/collapseDuplicateDeclarations.js +80 -0
- package/lib/lib/defaultExtractor.js +187 -0
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +40 -24
- package/lib/lib/expandApplyAtRules.js +414 -157
- package/lib/lib/expandTailwindAtRules.js +156 -151
- package/lib/lib/generateRules.js +402 -68
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +45 -36
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/regex.js +53 -0
- package/lib/lib/resolveDefaultsAtRules.js +105 -90
- package/lib/lib/setupContextUtils.js +416 -291
- package/lib/lib/setupTrackingContext.js +60 -56
- package/lib/lib/sharedState.js +38 -15
- package/lib/lib/substituteScreenAtRules.js +9 -6
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +17 -0
- package/lib/postcss-plugins/nesting/plugin.js +85 -0
- package/lib/processTailwindFeatures.js +21 -9
- package/lib/public/colors.js +244 -248
- package/lib/public/resolve-config.js +5 -5
- package/lib/util/buildMediaQuery.js +13 -24
- package/lib/util/cloneDeep.js +1 -1
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +43 -32
- package/lib/util/createPlugin.js +1 -2
- package/lib/util/createUtilityPlugin.js +13 -17
- package/lib/util/dataTypes.js +114 -74
- package/lib/util/defaults.js +6 -0
- package/lib/util/escapeClassName.js +5 -5
- package/lib/util/escapeCommas.js +1 -1
- package/lib/util/flattenColorPalette.js +2 -4
- package/lib/util/formatVariantSelector.js +194 -0
- package/lib/util/getAllConfigs.js +13 -5
- package/lib/util/hashConfig.js +5 -5
- package/lib/util/isKeyframeRule.js +1 -1
- package/lib/util/isPlainObject.js +1 -1
- package/lib/util/isValidArbitraryValue.js +64 -0
- package/lib/util/log.js +35 -19
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +5 -3
- package/lib/util/normalizeConfig.js +233 -0
- package/lib/util/normalizeScreens.js +59 -0
- package/lib/util/parseAnimationValue.js +56 -56
- package/lib/util/parseBoxShadowValue.js +76 -0
- package/lib/util/parseDependency.js +32 -32
- package/lib/util/parseObjectStyles.js +6 -6
- package/lib/util/pluginUtils.js +67 -170
- package/lib/util/prefixSelector.js +4 -7
- package/lib/util/resolveConfig.js +123 -133
- package/lib/util/resolveConfigPath.js +17 -18
- package/lib/util/responsive.js +6 -6
- package/lib/util/splitAtTopLevelOnly.js +72 -0
- package/lib/util/toColorValue.js +1 -2
- package/lib/util/toPath.js +6 -1
- package/lib/util/transformThemeValue.js +42 -34
- package/lib/util/validateConfig.js +21 -0
- package/lib/util/withAlphaVariable.js +19 -19
- package/nesting/index.js +2 -12
- package/package.json +41 -42
- package/peers/index.js +11539 -10859
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/create-plugin-list.js +2 -2
- package/scripts/generate-types.js +52 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +174 -41
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +641 -596
- package/src/css/preflight.css +19 -13
- package/src/featureFlags.js +16 -10
- package/src/index.js +14 -6
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +93 -0
- package/src/lib/defaultExtractor.js +192 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +24 -7
- package/src/lib/expandApplyAtRules.js +442 -154
- package/src/lib/expandTailwindAtRules.js +91 -65
- package/src/lib/generateRules.js +409 -43
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +74 -53
- package/src/lib/setupContextUtils.js +388 -208
- package/src/lib/setupTrackingContext.js +15 -12
- package/src/lib/sharedState.js +42 -7
- package/src/lib/substituteScreenAtRules.js +6 -3
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +17 -2
- package/src/public/colors.js +4 -9
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -2
- package/src/util/dataTypes.js +56 -16
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +213 -0
- package/src/util/getAllConfigs.js +7 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +2 -2
- package/src/util/negateValue.js +4 -2
- package/src/util/normalizeConfig.js +262 -0
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/pluginUtils.js +51 -147
- package/src/util/prefixSelector.js +7 -8
- package/src/util/resolveConfig.js +108 -79
- package/src/util/splitAtTopLevelOnly.js +71 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +24 -7
- package/src/util/validateConfig.js +13 -0
- package/stubs/defaultConfig.stub.js +157 -94
- package/stubs/simpleConfig.stub.js +0 -1
- package/types/config.d.ts +325 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types.d.ts +1 -0
- package/lib/lib/setupWatchingContext.js +0 -284
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -306
|
@@ -1,31 +1,15 @@
|
|
|
1
|
+
import LRU from 'quick-lru'
|
|
1
2
|
import * as sharedState from './sharedState'
|
|
2
3
|
import { generateRules } from './generateRules'
|
|
3
4
|
import bigSign from '../util/bigSign'
|
|
5
|
+
import log from '../util/log'
|
|
4
6
|
import cloneNodes from '../util/cloneNodes'
|
|
7
|
+
import { defaultExtractor } from './defaultExtractor'
|
|
5
8
|
|
|
6
9
|
let env = sharedState.env
|
|
7
|
-
let contentMatchCache = sharedState.contentMatchCache
|
|
8
|
-
|
|
9
|
-
const PATTERNS = [
|
|
10
|
-
/([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source, // font-['some_font',sans-serif]
|
|
11
|
-
/([^<>"'`\s]*\[\w*"[^"`\s]*"?\])/.source, // font-["some_font",sans-serif]
|
|
12
|
-
/([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source, // bg-[url('...')]
|
|
13
|
-
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source, // bg-[url("...")]
|
|
14
|
-
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source, // `content-['hello']` but not `content-['hello']']`
|
|
15
|
-
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source, // `content-["hello"]` but not `content-["hello"]"]`
|
|
16
|
-
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source, // `fill-[#bada55]`, `fill-[#bada55]/50`
|
|
17
|
-
/([^<>"'`\s]*[^"'`\s:])/.source, // `px-1.5`, `uppercase` but not `uppercase:`].join('|')
|
|
18
|
-
].join('|')
|
|
19
|
-
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g')
|
|
20
|
-
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g
|
|
21
10
|
|
|
22
11
|
const builtInExtractors = {
|
|
23
|
-
DEFAULT:
|
|
24
|
-
let broadMatches = content.match(BROAD_MATCH_GLOBAL_REGEXP) || []
|
|
25
|
-
let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || []
|
|
26
|
-
|
|
27
|
-
return [...broadMatches, ...innerMatches]
|
|
28
|
-
},
|
|
12
|
+
DEFAULT: defaultExtractor,
|
|
29
13
|
}
|
|
30
14
|
|
|
31
15
|
const builtInTransformers = {
|
|
@@ -33,41 +17,20 @@ const builtInTransformers = {
|
|
|
33
17
|
svelte: (content) => content.replace(/(?:^|\s)class:/g, ' '),
|
|
34
18
|
}
|
|
35
19
|
|
|
36
|
-
function getExtractor(
|
|
37
|
-
let extractors = tailwindConfig.content.extract
|
|
38
|
-
let contentOptions = tailwindConfig.content.options
|
|
39
|
-
|
|
40
|
-
if (typeof extractors === 'function') {
|
|
41
|
-
extractors = {
|
|
42
|
-
DEFAULT: extractors,
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (contentOptions.defaultExtractor) {
|
|
46
|
-
extractors.DEFAULT = contentOptions.defaultExtractor
|
|
47
|
-
}
|
|
48
|
-
for (let { extensions, extractor } of contentOptions.extractors || []) {
|
|
49
|
-
for (let extension of extensions) {
|
|
50
|
-
extractors[extension] = extractor
|
|
51
|
-
}
|
|
52
|
-
}
|
|
20
|
+
function getExtractor(context, fileExtension) {
|
|
21
|
+
let extractors = context.tailwindConfig.content.extract
|
|
53
22
|
|
|
54
23
|
return (
|
|
55
24
|
extractors[fileExtension] ||
|
|
56
25
|
extractors.DEFAULT ||
|
|
57
26
|
builtInExtractors[fileExtension] ||
|
|
58
|
-
builtInExtractors.DEFAULT
|
|
27
|
+
builtInExtractors.DEFAULT(context)
|
|
59
28
|
)
|
|
60
29
|
}
|
|
61
30
|
|
|
62
31
|
function getTransformer(tailwindConfig, fileExtension) {
|
|
63
32
|
let transformers = tailwindConfig.content.transform
|
|
64
33
|
|
|
65
|
-
if (typeof transformers === 'function') {
|
|
66
|
-
transformers = {
|
|
67
|
-
DEFAULT: transformers,
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
34
|
return (
|
|
72
35
|
transformers[fileExtension] ||
|
|
73
36
|
transformers.DEFAULT ||
|
|
@@ -76,10 +39,16 @@ function getTransformer(tailwindConfig, fileExtension) {
|
|
|
76
39
|
)
|
|
77
40
|
}
|
|
78
41
|
|
|
42
|
+
let extractorCache = new WeakMap()
|
|
43
|
+
|
|
79
44
|
// Scans template contents for possible classes. This is a hot path on initial build but
|
|
80
45
|
// not too important for subsequent builds. The faster the better though — if we can speed
|
|
81
46
|
// up these regexes by 50% that could cut initial build time by like 20%.
|
|
82
|
-
function getClassCandidates(content, extractor,
|
|
47
|
+
function getClassCandidates(content, extractor, candidates, seen) {
|
|
48
|
+
if (!extractorCache.has(extractor)) {
|
|
49
|
+
extractorCache.set(extractor, new LRU({ maxSize: 25000 }))
|
|
50
|
+
}
|
|
51
|
+
|
|
83
52
|
for (let line of content.split('\n')) {
|
|
84
53
|
line = line.trim()
|
|
85
54
|
|
|
@@ -88,8 +57,8 @@ function getClassCandidates(content, extractor, contentMatchCache, candidates, s
|
|
|
88
57
|
}
|
|
89
58
|
seen.add(line)
|
|
90
59
|
|
|
91
|
-
if (
|
|
92
|
-
for (let match of
|
|
60
|
+
if (extractorCache.get(extractor).has(line)) {
|
|
61
|
+
for (let match of extractorCache.get(extractor).get(line)) {
|
|
93
62
|
candidates.add(match)
|
|
94
63
|
}
|
|
95
64
|
} else {
|
|
@@ -100,7 +69,7 @@ function getClassCandidates(content, extractor, contentMatchCache, candidates, s
|
|
|
100
69
|
candidates.add(match)
|
|
101
70
|
}
|
|
102
71
|
|
|
103
|
-
|
|
72
|
+
extractorCache.get(extractor).set(line, lineMatchesSet)
|
|
104
73
|
}
|
|
105
74
|
}
|
|
106
75
|
}
|
|
@@ -110,6 +79,7 @@ function buildStylesheet(rules, context) {
|
|
|
110
79
|
|
|
111
80
|
let returnValue = {
|
|
112
81
|
base: new Set(),
|
|
82
|
+
defaults: new Set(),
|
|
113
83
|
components: new Set(),
|
|
114
84
|
utilities: new Set(),
|
|
115
85
|
variants: new Set(),
|
|
@@ -136,6 +106,11 @@ function buildStylesheet(rules, context) {
|
|
|
136
106
|
continue
|
|
137
107
|
}
|
|
138
108
|
|
|
109
|
+
if (sort & context.layerOrder.defaults) {
|
|
110
|
+
returnValue.defaults.add(rule)
|
|
111
|
+
continue
|
|
112
|
+
}
|
|
113
|
+
|
|
139
114
|
if (sort & context.layerOrder.components) {
|
|
140
115
|
returnValue.components.add(rule)
|
|
141
116
|
continue
|
|
@@ -164,13 +139,15 @@ export default function expandTailwindAtRules(context) {
|
|
|
164
139
|
variants: null,
|
|
165
140
|
}
|
|
166
141
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
layerNodes
|
|
142
|
+
root.walkAtRules((rule) => {
|
|
143
|
+
// Make sure this file contains Tailwind directives. If not, we can save
|
|
144
|
+
// a lot of work and bail early. Also we don't have to register our touch
|
|
145
|
+
// file as a dependency since the output of this CSS does not depend on
|
|
146
|
+
// the source of any templates. Think Vue <style> blocks for example.
|
|
147
|
+
if (rule.name === 'tailwind') {
|
|
148
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
149
|
+
layerNodes[rule.params] = rule
|
|
150
|
+
}
|
|
174
151
|
}
|
|
175
152
|
})
|
|
176
153
|
|
|
@@ -181,17 +158,19 @@ export default function expandTailwindAtRules(context) {
|
|
|
181
158
|
// ---
|
|
182
159
|
|
|
183
160
|
// Find potential rules in changed files
|
|
184
|
-
let candidates = new Set([
|
|
161
|
+
let candidates = new Set([sharedState.NOT_ON_DEMAND])
|
|
185
162
|
let seen = new Set()
|
|
186
163
|
|
|
187
164
|
env.DEBUG && console.time('Reading changed files')
|
|
188
165
|
|
|
189
166
|
for (let { content, extension } of context.changedContent) {
|
|
190
167
|
let transformer = getTransformer(context.tailwindConfig, extension)
|
|
191
|
-
let extractor = getExtractor(context
|
|
192
|
-
getClassCandidates(transformer(content), extractor,
|
|
168
|
+
let extractor = getExtractor(context, extension)
|
|
169
|
+
getClassCandidates(transformer(content), extractor, candidates, seen)
|
|
193
170
|
}
|
|
194
171
|
|
|
172
|
+
env.DEBUG && console.timeEnd('Reading changed files')
|
|
173
|
+
|
|
195
174
|
// ---
|
|
196
175
|
|
|
197
176
|
// Generate the actual CSS
|
|
@@ -213,6 +192,7 @@ export default function expandTailwindAtRules(context) {
|
|
|
213
192
|
env.DEBUG && console.timeEnd('Build stylesheet')
|
|
214
193
|
|
|
215
194
|
let {
|
|
195
|
+
defaults: defaultNodes,
|
|
216
196
|
base: baseNodes,
|
|
217
197
|
components: componentNodes,
|
|
218
198
|
utilities: utilityNodes,
|
|
@@ -224,25 +204,72 @@ export default function expandTailwindAtRules(context) {
|
|
|
224
204
|
// Replace any Tailwind directives with generated CSS
|
|
225
205
|
|
|
226
206
|
if (layerNodes.base) {
|
|
227
|
-
layerNodes.base.before(
|
|
207
|
+
layerNodes.base.before(
|
|
208
|
+
cloneNodes([...baseNodes, ...defaultNodes], layerNodes.base.source, {
|
|
209
|
+
layer: 'base',
|
|
210
|
+
})
|
|
211
|
+
)
|
|
228
212
|
layerNodes.base.remove()
|
|
229
213
|
}
|
|
230
214
|
|
|
231
215
|
if (layerNodes.components) {
|
|
232
|
-
layerNodes.components.before(
|
|
216
|
+
layerNodes.components.before(
|
|
217
|
+
cloneNodes([...componentNodes], layerNodes.components.source, {
|
|
218
|
+
layer: 'components',
|
|
219
|
+
})
|
|
220
|
+
)
|
|
233
221
|
layerNodes.components.remove()
|
|
234
222
|
}
|
|
235
223
|
|
|
236
224
|
if (layerNodes.utilities) {
|
|
237
|
-
layerNodes.utilities.before(
|
|
225
|
+
layerNodes.utilities.before(
|
|
226
|
+
cloneNodes([...utilityNodes], layerNodes.utilities.source, {
|
|
227
|
+
layer: 'utilities',
|
|
228
|
+
})
|
|
229
|
+
)
|
|
238
230
|
layerNodes.utilities.remove()
|
|
239
231
|
}
|
|
240
232
|
|
|
233
|
+
// We do post-filtering to not alter the emitted order of the variants
|
|
234
|
+
const variantNodes = Array.from(screenNodes).filter((node) => {
|
|
235
|
+
const parentLayer = node.raws.tailwind?.parentLayer
|
|
236
|
+
|
|
237
|
+
if (parentLayer === 'components') {
|
|
238
|
+
return layerNodes.components !== null
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (parentLayer === 'utilities') {
|
|
242
|
+
return layerNodes.utilities !== null
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return true
|
|
246
|
+
})
|
|
247
|
+
|
|
241
248
|
if (layerNodes.variants) {
|
|
242
|
-
layerNodes.variants.before(
|
|
249
|
+
layerNodes.variants.before(
|
|
250
|
+
cloneNodes(variantNodes, layerNodes.variants.source, {
|
|
251
|
+
layer: 'variants',
|
|
252
|
+
})
|
|
253
|
+
)
|
|
243
254
|
layerNodes.variants.remove()
|
|
244
|
-
} else {
|
|
245
|
-
root.append(
|
|
255
|
+
} else if (variantNodes.length > 0) {
|
|
256
|
+
root.append(
|
|
257
|
+
cloneNodes(variantNodes, root.source, {
|
|
258
|
+
layer: 'variants',
|
|
259
|
+
})
|
|
260
|
+
)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// If we've got a utility layer and no utilities are generated there's likely something wrong
|
|
264
|
+
const hasUtilityVariants = variantNodes.some(
|
|
265
|
+
(node) => node.raws.tailwind?.parentLayer === 'utilities'
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
|
|
269
|
+
log.warn('content-problems', [
|
|
270
|
+
'No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.',
|
|
271
|
+
'https://tailwindcss.com/docs/content-configuration',
|
|
272
|
+
])
|
|
246
273
|
}
|
|
247
274
|
|
|
248
275
|
// ---
|
|
@@ -250,7 +277,6 @@ export default function expandTailwindAtRules(context) {
|
|
|
250
277
|
if (env.DEBUG) {
|
|
251
278
|
console.log('Potential classes: ', candidates.size)
|
|
252
279
|
console.log('Active contexts: ', sharedState.contextSourcesMap.size)
|
|
253
|
-
console.log('Content match entries', contentMatchCache.size)
|
|
254
280
|
}
|
|
255
281
|
|
|
256
282
|
// Clear the cache for the changed files
|