tailwindcss 0.0.0-insiders.de1bdb4 → 0.0.0-insiders.deefbf5
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 +415 -3
- 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 +4 -0
- package/defaultTheme.js +2 -1
- package/lib/cli-peer-dependencies.js +10 -5
- package/lib/cli.js +329 -230
- package/lib/constants.js +9 -9
- package/lib/corePluginList.js +9 -1
- package/lib/corePlugins.js +1836 -1684
- package/lib/css/preflight.css +7 -13
- package/lib/featureFlags.js +17 -16
- package/lib/index.js +16 -8
- package/lib/lib/cacheInvalidation.js +87 -0
- package/lib/lib/collapseAdjacentRules.js +30 -15
- package/lib/lib/collapseDuplicateDeclarations.js +54 -3
- package/lib/lib/defaultExtractor.js +228 -0
- package/lib/lib/detectNesting.js +17 -2
- package/lib/lib/evaluateTailwindFunctions.js +79 -31
- package/lib/lib/expandApplyAtRules.js +401 -159
- package/lib/lib/expandTailwindAtRules.js +175 -144
- package/lib/lib/generateRules.js +342 -113
- package/lib/lib/getModuleDependencies.js +14 -14
- package/lib/lib/normalizeTailwindDirectives.js +43 -35
- package/lib/lib/partitionApplyAtRules.js +53 -0
- package/lib/lib/regex.js +52 -0
- package/lib/lib/resolveDefaultsAtRules.js +98 -69
- package/lib/lib/setupContextUtils.js +331 -258
- package/lib/lib/setupTrackingContext.js +61 -62
- package/lib/lib/sharedState.js +37 -5
- package/lib/lib/substituteScreenAtRules.js +8 -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 +84 -0
- package/lib/processTailwindFeatures.js +17 -9
- package/lib/public/colors.js +241 -241
- package/lib/public/resolve-config.js +5 -5
- package/lib/util/buildMediaQuery.js +12 -24
- package/lib/util/cloneDeep.js +3 -5
- package/lib/util/cloneNodes.js +12 -1
- package/lib/util/color.js +43 -37
- package/lib/util/createPlugin.js +1 -3
- package/lib/util/createUtilityPlugin.js +11 -16
- package/lib/util/dataTypes.js +99 -75
- 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 +4 -9
- package/lib/util/formatVariantSelector.js +122 -30
- package/lib/util/getAllConfigs.js +15 -10
- 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 +63 -0
- package/lib/util/log.js +12 -9
- package/lib/util/nameClass.js +7 -6
- package/lib/util/negateValue.js +4 -5
- package/lib/util/normalizeConfig.js +93 -51
- package/lib/util/normalizeScreens.js +58 -0
- package/lib/util/parseAnimationValue.js +56 -57
- 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 +34 -32
- package/lib/util/prefixSelector.js +4 -5
- package/lib/util/removeAlphaVariables.js +18 -0
- package/lib/util/resolveConfig.js +95 -73
- package/lib/util/resolveConfigPath.js +17 -18
- package/lib/util/responsive.js +6 -6
- package/lib/util/splitAtTopLevelOnly.js +90 -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 +23 -23
- package/nesting/index.js +2 -12
- package/package.json +43 -43
- package/peers/index.js +11870 -9389
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.js +2 -1
- package/scripts/generate-types.js +105 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +185 -38
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +460 -286
- package/src/css/preflight.css +7 -13
- package/src/featureFlags.js +5 -5
- 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 +66 -1
- package/src/lib/defaultExtractor.js +208 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +62 -9
- package/src/lib/expandApplyAtRules.js +442 -154
- package/src/lib/expandTailwindAtRules.js +79 -39
- package/src/lib/generateRules.js +308 -84
- package/src/lib/normalizeTailwindDirectives.js +7 -1
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +59 -17
- package/src/lib/setupContextUtils.js +261 -136
- package/src/lib/setupTrackingContext.js +12 -7
- package/src/lib/sharedState.js +42 -4
- 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 +12 -2
- package/src/util/buildMediaQuery.js +14 -18
- package/src/util/cloneNodes.js +14 -1
- package/src/util/color.js +31 -14
- package/src/util/dataTypes.js +36 -12
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +134 -24
- package/src/util/getAllConfigs.js +7 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +11 -7
- package/src/util/nameClass.js +1 -1
- package/src/util/normalizeConfig.js +16 -3
- package/src/util/normalizeScreens.js +45 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/pluginUtils.js +16 -2
- package/src/util/prefixSelector.js +7 -5
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -16
- 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/src/util/withAlphaVariable.js +1 -1
- package/stubs/defaultConfig.stub.js +47 -17
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +327 -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/generated/default-theme.d.ts +331 -0
- package/types/index.d.ts +7 -0
- package/lib/lib/setupWatchingContext.js +0 -288
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -311
|
@@ -7,68 +7,192 @@ var _quickLru = _interopRequireDefault(require("quick-lru"));
|
|
|
7
7
|
var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
8
8
|
var _generateRules = require("./generateRules");
|
|
9
9
|
var _bigSign = _interopRequireDefault(require("../util/bigSign"));
|
|
10
|
+
var _log = _interopRequireDefault(require("../util/log"));
|
|
10
11
|
var _cloneNodes = _interopRequireDefault(require("../util/cloneNodes"));
|
|
12
|
+
var _defaultExtractor = require("./defaultExtractor");
|
|
13
|
+
function expandTailwindAtRules(context) {
|
|
14
|
+
return (root)=>{
|
|
15
|
+
let layerNodes = {
|
|
16
|
+
base: null,
|
|
17
|
+
components: null,
|
|
18
|
+
utilities: null,
|
|
19
|
+
variants: null
|
|
20
|
+
};
|
|
21
|
+
root.walkAtRules((rule)=>{
|
|
22
|
+
// Make sure this file contains Tailwind directives. If not, we can save
|
|
23
|
+
// a lot of work and bail early. Also we don't have to register our touch
|
|
24
|
+
// file as a dependency since the output of this CSS does not depend on
|
|
25
|
+
// the source of any templates. Think Vue <style> blocks for example.
|
|
26
|
+
if (rule.name === "tailwind") {
|
|
27
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
28
|
+
layerNodes[rule.params] = rule;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
if (Object.values(layerNodes).every((n)=>n === null)) {
|
|
33
|
+
return root;
|
|
34
|
+
}
|
|
35
|
+
// ---
|
|
36
|
+
// Find potential rules in changed files
|
|
37
|
+
let candidates = new Set([
|
|
38
|
+
sharedState.NOT_ON_DEMAND
|
|
39
|
+
]);
|
|
40
|
+
let seen = new Set();
|
|
41
|
+
env.DEBUG && console.time("Reading changed files");
|
|
42
|
+
for (let { content , extension } of context.changedContent){
|
|
43
|
+
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
44
|
+
let extractor = getExtractor(context, extension);
|
|
45
|
+
getClassCandidates(transformer(content), extractor, candidates, seen);
|
|
46
|
+
}
|
|
47
|
+
env.DEBUG && console.timeEnd("Reading changed files");
|
|
48
|
+
// ---
|
|
49
|
+
// Generate the actual CSS
|
|
50
|
+
let classCacheCount = context.classCache.size;
|
|
51
|
+
env.DEBUG && console.time("Generate rules");
|
|
52
|
+
let rules = (0, _generateRules).generateRules(candidates, context);
|
|
53
|
+
env.DEBUG && console.timeEnd("Generate rules");
|
|
54
|
+
// We only ever add to the classCache, so if it didn't grow, there is nothing new.
|
|
55
|
+
env.DEBUG && console.time("Build stylesheet");
|
|
56
|
+
if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
|
|
57
|
+
for (let rule of rules){
|
|
58
|
+
context.ruleCache.add(rule);
|
|
59
|
+
}
|
|
60
|
+
context.stylesheetCache = buildStylesheet([
|
|
61
|
+
...context.ruleCache
|
|
62
|
+
], context);
|
|
63
|
+
}
|
|
64
|
+
env.DEBUG && console.timeEnd("Build stylesheet");
|
|
65
|
+
let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
66
|
+
// ---
|
|
67
|
+
// Replace any Tailwind directives with generated CSS
|
|
68
|
+
if (layerNodes.base) {
|
|
69
|
+
layerNodes.base.before((0, _cloneNodes).default([
|
|
70
|
+
...baseNodes,
|
|
71
|
+
...defaultNodes
|
|
72
|
+
], layerNodes.base.source, {
|
|
73
|
+
layer: "base"
|
|
74
|
+
}));
|
|
75
|
+
layerNodes.base.remove();
|
|
76
|
+
}
|
|
77
|
+
if (layerNodes.components) {
|
|
78
|
+
layerNodes.components.before((0, _cloneNodes).default([
|
|
79
|
+
...componentNodes
|
|
80
|
+
], layerNodes.components.source, {
|
|
81
|
+
layer: "components"
|
|
82
|
+
}));
|
|
83
|
+
layerNodes.components.remove();
|
|
84
|
+
}
|
|
85
|
+
if (layerNodes.utilities) {
|
|
86
|
+
layerNodes.utilities.before((0, _cloneNodes).default([
|
|
87
|
+
...utilityNodes
|
|
88
|
+
], layerNodes.utilities.source, {
|
|
89
|
+
layer: "utilities"
|
|
90
|
+
}));
|
|
91
|
+
layerNodes.utilities.remove();
|
|
92
|
+
}
|
|
93
|
+
// We do post-filtering to not alter the emitted order of the variants
|
|
94
|
+
const variantNodes = Array.from(screenNodes).filter((node)=>{
|
|
95
|
+
var ref;
|
|
96
|
+
const parentLayer = (ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer;
|
|
97
|
+
if (parentLayer === "components") {
|
|
98
|
+
return layerNodes.components !== null;
|
|
99
|
+
}
|
|
100
|
+
if (parentLayer === "utilities") {
|
|
101
|
+
return layerNodes.utilities !== null;
|
|
102
|
+
}
|
|
103
|
+
return true;
|
|
104
|
+
});
|
|
105
|
+
if (layerNodes.variants) {
|
|
106
|
+
layerNodes.variants.before((0, _cloneNodes).default(variantNodes, layerNodes.variants.source, {
|
|
107
|
+
layer: "variants"
|
|
108
|
+
}));
|
|
109
|
+
layerNodes.variants.remove();
|
|
110
|
+
} else if (variantNodes.length > 0) {
|
|
111
|
+
root.append((0, _cloneNodes).default(variantNodes, root.source, {
|
|
112
|
+
layer: "variants"
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
// If we've got a utility layer and no utilities are generated there's likely something wrong
|
|
116
|
+
const hasUtilityVariants = variantNodes.some((node)=>{
|
|
117
|
+
var ref;
|
|
118
|
+
return ((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer) === "utilities";
|
|
119
|
+
});
|
|
120
|
+
if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
|
|
121
|
+
_log.default.warn("content-problems", [
|
|
122
|
+
"No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.",
|
|
123
|
+
"https://tailwindcss.com/docs/content-configuration",
|
|
124
|
+
]);
|
|
125
|
+
}
|
|
126
|
+
// ---
|
|
127
|
+
if (env.DEBUG) {
|
|
128
|
+
console.log("Potential classes: ", candidates.size);
|
|
129
|
+
console.log("Active contexts: ", sharedState.contextSourcesMap.size);
|
|
130
|
+
}
|
|
131
|
+
// Clear the cache for the changed files
|
|
132
|
+
context.changedContent = [];
|
|
133
|
+
// Cleanup any leftover @layer atrules
|
|
134
|
+
root.walkAtRules("layer", (rule)=>{
|
|
135
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
136
|
+
rule.remove();
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
}
|
|
11
141
|
function _interopRequireDefault(obj) {
|
|
12
142
|
return obj && obj.__esModule ? obj : {
|
|
13
143
|
default: obj
|
|
14
144
|
};
|
|
15
145
|
}
|
|
146
|
+
function _getRequireWildcardCache() {
|
|
147
|
+
if (typeof WeakMap !== "function") return null;
|
|
148
|
+
var cache = new WeakMap();
|
|
149
|
+
_getRequireWildcardCache = function() {
|
|
150
|
+
return cache;
|
|
151
|
+
};
|
|
152
|
+
return cache;
|
|
153
|
+
}
|
|
16
154
|
function _interopRequireWildcard(obj) {
|
|
17
155
|
if (obj && obj.__esModule) {
|
|
18
156
|
return obj;
|
|
19
|
-
}
|
|
20
|
-
|
|
157
|
+
}
|
|
158
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
159
|
+
return {
|
|
160
|
+
default: obj
|
|
21
161
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
162
|
+
}
|
|
163
|
+
var cache = _getRequireWildcardCache();
|
|
164
|
+
if (cache && cache.has(obj)) {
|
|
165
|
+
return cache.get(obj);
|
|
166
|
+
}
|
|
167
|
+
var newObj = {};
|
|
168
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
169
|
+
for(var key in obj){
|
|
170
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
171
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
172
|
+
if (desc && (desc.get || desc.set)) {
|
|
173
|
+
Object.defineProperty(newObj, key, desc);
|
|
174
|
+
} else {
|
|
175
|
+
newObj[key] = obj[key];
|
|
33
176
|
}
|
|
34
177
|
}
|
|
35
|
-
newObj.default = obj;
|
|
36
|
-
return newObj;
|
|
37
178
|
}
|
|
179
|
+
newObj.default = obj;
|
|
180
|
+
if (cache) {
|
|
181
|
+
cache.set(obj, newObj);
|
|
182
|
+
}
|
|
183
|
+
return newObj;
|
|
38
184
|
}
|
|
39
185
|
let env = sharedState.env;
|
|
40
|
-
const PATTERNS = [
|
|
41
|
-
/([^<>"'`\s]*\[\w*'[^"`\s]*'?\])/.source,
|
|
42
|
-
/([^<>"'`\s]*\[\w*"[^"`\s]*"?\])/.source,
|
|
43
|
-
/([^<>"'`\s]*\[\w*\('[^"'`\s]*'\)\])/.source,
|
|
44
|
-
/([^<>"'`\s]*\[\w*\("[^"'`\s]*"\)\])/.source,
|
|
45
|
-
/([^<>"'`\s]*\[\w*\('[^"`\s]*'\)\])/.source,
|
|
46
|
-
/([^<>"'`\s]*\[\w*\("[^'`\s]*"\)\])/.source,
|
|
47
|
-
/([^<>"'`\s]*\['[^"'`\s]*'\])/.source,
|
|
48
|
-
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
49
|
-
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
|
|
50
|
-
/([^<>"'`\s]*[^"'`\s:])/.source
|
|
51
|
-
].join('|');
|
|
52
|
-
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
|
|
53
|
-
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g;
|
|
54
186
|
const builtInExtractors = {
|
|
55
|
-
DEFAULT:
|
|
56
|
-
let broadMatches = content.match(BROAD_MATCH_GLOBAL_REGEXP) || [];
|
|
57
|
-
let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
|
|
58
|
-
return [
|
|
59
|
-
...broadMatches,
|
|
60
|
-
...innerMatches
|
|
61
|
-
];
|
|
62
|
-
}
|
|
187
|
+
DEFAULT: _defaultExtractor.defaultExtractor
|
|
63
188
|
};
|
|
64
189
|
const builtInTransformers = {
|
|
65
|
-
DEFAULT: (content)=>content
|
|
66
|
-
,
|
|
67
|
-
svelte: (content)=>content.replace(/(?:^|\s)class:/g, ' ')
|
|
190
|
+
DEFAULT: (content)=>content,
|
|
191
|
+
svelte: (content)=>content.replace(/(?:^|\s)class:/g, " ")
|
|
68
192
|
};
|
|
69
|
-
function getExtractor(
|
|
70
|
-
let extractors = tailwindConfig.content.extract;
|
|
71
|
-
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT;
|
|
193
|
+
function getExtractor(context, fileExtension) {
|
|
194
|
+
let extractors = context.tailwindConfig.content.extract;
|
|
195
|
+
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT(context);
|
|
72
196
|
}
|
|
73
197
|
function getTransformer(tailwindConfig, fileExtension) {
|
|
74
198
|
let transformers = tailwindConfig.content.transform;
|
|
@@ -84,7 +208,7 @@ function getClassCandidates(content, extractor, candidates, seen) {
|
|
|
84
208
|
maxSize: 25000
|
|
85
209
|
}));
|
|
86
210
|
}
|
|
87
|
-
for (let line of content.split(
|
|
211
|
+
for (let line of content.split("\n")){
|
|
88
212
|
line = line.trim();
|
|
89
213
|
if (seen.has(line)) {
|
|
90
214
|
continue;
|
|
@@ -95,8 +219,7 @@ function getClassCandidates(content, extractor, candidates, seen) {
|
|
|
95
219
|
candidates.add(match);
|
|
96
220
|
}
|
|
97
221
|
} else {
|
|
98
|
-
let extractorMatches = extractor(line).filter((s)=>s !==
|
|
99
|
-
);
|
|
222
|
+
let extractorMatches = extractor(line).filter((s)=>s !== "!*");
|
|
100
223
|
let lineMatchesSet = new Set(extractorMatches);
|
|
101
224
|
for (let match of lineMatchesSet){
|
|
102
225
|
candidates.add(match);
|
|
@@ -106,10 +229,10 @@ function getClassCandidates(content, extractor, candidates, seen) {
|
|
|
106
229
|
}
|
|
107
230
|
}
|
|
108
231
|
function buildStylesheet(rules, context) {
|
|
109
|
-
let sortedRules = rules.sort(([a], [z])=>(0, _bigSign).default(a - z)
|
|
110
|
-
);
|
|
232
|
+
let sortedRules = rules.sort(([a], [z])=>(0, _bigSign).default(a - z));
|
|
111
233
|
let returnValue = {
|
|
112
234
|
base: new Set(),
|
|
235
|
+
defaults: new Set(),
|
|
113
236
|
components: new Set(),
|
|
114
237
|
utilities: new Set(),
|
|
115
238
|
variants: new Set(),
|
|
@@ -132,6 +255,10 @@ function buildStylesheet(rules, context) {
|
|
|
132
255
|
returnValue.base.add(rule);
|
|
133
256
|
continue;
|
|
134
257
|
}
|
|
258
|
+
if (sort & context.layerOrder.defaults) {
|
|
259
|
+
returnValue.defaults.add(rule);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
135
262
|
if (sort & context.layerOrder.components) {
|
|
136
263
|
returnValue.components.add(rule);
|
|
137
264
|
continue;
|
|
@@ -147,99 +274,3 @@ function buildStylesheet(rules, context) {
|
|
|
147
274
|
}
|
|
148
275
|
return returnValue;
|
|
149
276
|
}
|
|
150
|
-
function expandTailwindAtRules(context) {
|
|
151
|
-
return (root)=>{
|
|
152
|
-
let layerNodes = {
|
|
153
|
-
base: null,
|
|
154
|
-
components: null,
|
|
155
|
-
utilities: null,
|
|
156
|
-
variants: null
|
|
157
|
-
};
|
|
158
|
-
// Make sure this file contains Tailwind directives. If not, we can save
|
|
159
|
-
// a lot of work and bail early. Also we don't have to register our touch
|
|
160
|
-
// file as a dependency since the output of this CSS does not depend on
|
|
161
|
-
// the source of any templates. Think Vue <style> blocks for example.
|
|
162
|
-
root.walkAtRules('tailwind', (rule)=>{
|
|
163
|
-
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
164
|
-
layerNodes[rule.params] = rule;
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
if (Object.values(layerNodes).every((n)=>n === null
|
|
168
|
-
)) {
|
|
169
|
-
return root;
|
|
170
|
-
}
|
|
171
|
-
// ---
|
|
172
|
-
// Find potential rules in changed files
|
|
173
|
-
let candidates = new Set([
|
|
174
|
-
'*'
|
|
175
|
-
]);
|
|
176
|
-
let seen = new Set();
|
|
177
|
-
env.DEBUG && console.time('Reading changed files');
|
|
178
|
-
for (let { content , extension } of context.changedContent){
|
|
179
|
-
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
180
|
-
let extractor = getExtractor(context.tailwindConfig, extension);
|
|
181
|
-
getClassCandidates(transformer(content), extractor, candidates, seen);
|
|
182
|
-
}
|
|
183
|
-
// ---
|
|
184
|
-
// Generate the actual CSS
|
|
185
|
-
let classCacheCount = context.classCache.size;
|
|
186
|
-
env.DEBUG && console.time('Generate rules');
|
|
187
|
-
let rules = (0, _generateRules).generateRules(candidates, context);
|
|
188
|
-
env.DEBUG && console.timeEnd('Generate rules');
|
|
189
|
-
// We only ever add to the classCache, so if it didn't grow, there is nothing new.
|
|
190
|
-
env.DEBUG && console.time('Build stylesheet');
|
|
191
|
-
if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
|
|
192
|
-
for (let rule of rules){
|
|
193
|
-
context.ruleCache.add(rule);
|
|
194
|
-
}
|
|
195
|
-
context.stylesheetCache = buildStylesheet([
|
|
196
|
-
...context.ruleCache
|
|
197
|
-
], context);
|
|
198
|
-
}
|
|
199
|
-
env.DEBUG && console.timeEnd('Build stylesheet');
|
|
200
|
-
let { base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
201
|
-
// ---
|
|
202
|
-
// Replace any Tailwind directives with generated CSS
|
|
203
|
-
if (layerNodes.base) {
|
|
204
|
-
layerNodes.base.before((0, _cloneNodes).default([
|
|
205
|
-
...baseNodes
|
|
206
|
-
], layerNodes.base.source));
|
|
207
|
-
layerNodes.base.remove();
|
|
208
|
-
}
|
|
209
|
-
if (layerNodes.components) {
|
|
210
|
-
layerNodes.components.before((0, _cloneNodes).default([
|
|
211
|
-
...componentNodes
|
|
212
|
-
], layerNodes.components.source));
|
|
213
|
-
layerNodes.components.remove();
|
|
214
|
-
}
|
|
215
|
-
if (layerNodes.utilities) {
|
|
216
|
-
layerNodes.utilities.before((0, _cloneNodes).default([
|
|
217
|
-
...utilityNodes
|
|
218
|
-
], layerNodes.utilities.source));
|
|
219
|
-
layerNodes.utilities.remove();
|
|
220
|
-
}
|
|
221
|
-
if (layerNodes.variants) {
|
|
222
|
-
layerNodes.variants.before((0, _cloneNodes).default([
|
|
223
|
-
...screenNodes
|
|
224
|
-
], layerNodes.variants.source));
|
|
225
|
-
layerNodes.variants.remove();
|
|
226
|
-
} else {
|
|
227
|
-
root.append((0, _cloneNodes).default([
|
|
228
|
-
...screenNodes
|
|
229
|
-
], root.source));
|
|
230
|
-
}
|
|
231
|
-
// ---
|
|
232
|
-
if (env.DEBUG) {
|
|
233
|
-
console.log('Potential classes: ', candidates.size);
|
|
234
|
-
console.log('Active contexts: ', sharedState.contextSourcesMap.size);
|
|
235
|
-
}
|
|
236
|
-
// Clear the cache for the changed files
|
|
237
|
-
context.changedContent = [];
|
|
238
|
-
// Cleanup any leftover @layer atrules
|
|
239
|
-
root.walkAtRules('layer', (rule)=>{
|
|
240
|
-
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
241
|
-
rule.remove();
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
};
|
|
245
|
-
}
|