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
|
@@ -3,10 +3,142 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = expandTailwindAtRules;
|
|
6
|
+
var _quickLru = _interopRequireDefault(require("quick-lru"));
|
|
6
7
|
var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
7
8
|
var _generateRules = require("./generateRules");
|
|
8
9
|
var _bigSign = _interopRequireDefault(require("../util/bigSign"));
|
|
10
|
+
var _log = _interopRequireDefault(require("../util/log"));
|
|
9
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
|
+
)) {
|
|
34
|
+
return root;
|
|
35
|
+
}
|
|
36
|
+
// ---
|
|
37
|
+
// Find potential rules in changed files
|
|
38
|
+
let candidates = new Set([
|
|
39
|
+
sharedState.NOT_ON_DEMAND
|
|
40
|
+
]);
|
|
41
|
+
let seen = new Set();
|
|
42
|
+
env.DEBUG && console.time("Reading changed files");
|
|
43
|
+
for (let { content , extension } of context.changedContent){
|
|
44
|
+
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
45
|
+
let extractor = getExtractor(context, extension);
|
|
46
|
+
getClassCandidates(transformer(content), extractor, candidates, seen);
|
|
47
|
+
}
|
|
48
|
+
env.DEBUG && console.timeEnd("Reading changed files");
|
|
49
|
+
// ---
|
|
50
|
+
// Generate the actual CSS
|
|
51
|
+
let classCacheCount = context.classCache.size;
|
|
52
|
+
env.DEBUG && console.time("Generate rules");
|
|
53
|
+
let rules = (0, _generateRules).generateRules(candidates, context);
|
|
54
|
+
env.DEBUG && console.timeEnd("Generate rules");
|
|
55
|
+
// We only ever add to the classCache, so if it didn't grow, there is nothing new.
|
|
56
|
+
env.DEBUG && console.time("Build stylesheet");
|
|
57
|
+
if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
|
|
58
|
+
for (let rule of rules){
|
|
59
|
+
context.ruleCache.add(rule);
|
|
60
|
+
}
|
|
61
|
+
context.stylesheetCache = buildStylesheet([
|
|
62
|
+
...context.ruleCache
|
|
63
|
+
], context);
|
|
64
|
+
}
|
|
65
|
+
env.DEBUG && console.timeEnd("Build stylesheet");
|
|
66
|
+
let { defaults: defaultNodes , base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
67
|
+
// ---
|
|
68
|
+
// Replace any Tailwind directives with generated CSS
|
|
69
|
+
if (layerNodes.base) {
|
|
70
|
+
layerNodes.base.before((0, _cloneNodes).default([
|
|
71
|
+
...baseNodes,
|
|
72
|
+
...defaultNodes
|
|
73
|
+
], layerNodes.base.source, {
|
|
74
|
+
layer: "base"
|
|
75
|
+
}));
|
|
76
|
+
layerNodes.base.remove();
|
|
77
|
+
}
|
|
78
|
+
if (layerNodes.components) {
|
|
79
|
+
layerNodes.components.before((0, _cloneNodes).default([
|
|
80
|
+
...componentNodes
|
|
81
|
+
], layerNodes.components.source, {
|
|
82
|
+
layer: "components"
|
|
83
|
+
}));
|
|
84
|
+
layerNodes.components.remove();
|
|
85
|
+
}
|
|
86
|
+
if (layerNodes.utilities) {
|
|
87
|
+
layerNodes.utilities.before((0, _cloneNodes).default([
|
|
88
|
+
...utilityNodes
|
|
89
|
+
], layerNodes.utilities.source, {
|
|
90
|
+
layer: "utilities"
|
|
91
|
+
}));
|
|
92
|
+
layerNodes.utilities.remove();
|
|
93
|
+
}
|
|
94
|
+
// We do post-filtering to not alter the emitted order of the variants
|
|
95
|
+
const variantNodes = Array.from(screenNodes).filter((node)=>{
|
|
96
|
+
var ref;
|
|
97
|
+
const parentLayer = (ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer;
|
|
98
|
+
if (parentLayer === "components") {
|
|
99
|
+
return layerNodes.components !== null;
|
|
100
|
+
}
|
|
101
|
+
if (parentLayer === "utilities") {
|
|
102
|
+
return layerNodes.utilities !== null;
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
});
|
|
106
|
+
if (layerNodes.variants) {
|
|
107
|
+
layerNodes.variants.before((0, _cloneNodes).default(variantNodes, layerNodes.variants.source, {
|
|
108
|
+
layer: "variants"
|
|
109
|
+
}));
|
|
110
|
+
layerNodes.variants.remove();
|
|
111
|
+
} else if (variantNodes.length > 0) {
|
|
112
|
+
root.append((0, _cloneNodes).default(variantNodes, root.source, {
|
|
113
|
+
layer: "variants"
|
|
114
|
+
}));
|
|
115
|
+
}
|
|
116
|
+
// If we've got a utility layer and no utilities are generated there's likely something wrong
|
|
117
|
+
const hasUtilityVariants = variantNodes.some((node)=>{
|
|
118
|
+
var ref;
|
|
119
|
+
return ((ref = node.raws.tailwind) === null || ref === void 0 ? void 0 : ref.parentLayer) === "utilities";
|
|
120
|
+
});
|
|
121
|
+
if (layerNodes.utilities && utilityNodes.size === 0 && !hasUtilityVariants) {
|
|
122
|
+
_log.default.warn("content-problems", [
|
|
123
|
+
"No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.",
|
|
124
|
+
"https://tailwindcss.com/docs/content-configuration",
|
|
125
|
+
]);
|
|
126
|
+
}
|
|
127
|
+
// ---
|
|
128
|
+
if (env.DEBUG) {
|
|
129
|
+
console.log("Potential classes: ", candidates.size);
|
|
130
|
+
console.log("Active contexts: ", sharedState.contextSourcesMap.size);
|
|
131
|
+
}
|
|
132
|
+
// Clear the cache for the changed files
|
|
133
|
+
context.changedContent = [];
|
|
134
|
+
// Cleanup any leftover @layer atrules
|
|
135
|
+
root.walkAtRules("layer", (rule)=>{
|
|
136
|
+
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
137
|
+
rule.remove();
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
}
|
|
10
142
|
function _interopRequireDefault(obj) {
|
|
11
143
|
return obj && obj.__esModule ? obj : {
|
|
12
144
|
default: obj
|
|
@@ -16,13 +148,11 @@ function _interopRequireWildcard(obj) {
|
|
|
16
148
|
if (obj && obj.__esModule) {
|
|
17
149
|
return obj;
|
|
18
150
|
} else {
|
|
19
|
-
var newObj = {
|
|
20
|
-
};
|
|
151
|
+
var newObj = {};
|
|
21
152
|
if (obj != null) {
|
|
22
153
|
for(var key in obj){
|
|
23
154
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
24
|
-
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
|
|
25
|
-
};
|
|
155
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
26
156
|
if (desc.get || desc.set) {
|
|
27
157
|
Object.defineProperty(newObj, key, desc);
|
|
28
158
|
} else {
|
|
@@ -36,83 +166,50 @@ function _interopRequireWildcard(obj) {
|
|
|
36
166
|
}
|
|
37
167
|
}
|
|
38
168
|
let env = sharedState.env;
|
|
39
|
-
let contentMatchCache = sharedState.contentMatchCache;
|
|
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]*\['[^"'`\s]*'\])/.source,
|
|
46
|
-
/([^<>"'`\s]*\["[^"'`\s]*"\])/.source,
|
|
47
|
-
/([^<>"'`\s]*\[[^"'`\s]+\][^<>"'`\s]*)/.source,
|
|
48
|
-
/([^<>"'`\s]*[^"'`\s:])/.source
|
|
49
|
-
].join('|');
|
|
50
|
-
const BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, 'g');
|
|
51
|
-
const INNER_MATCH_GLOBAL_REGEXP = /[^<>"'`\s.(){}[\]#=%]*[^<>"'`\s.(){}[\]#=%:]/g;
|
|
52
169
|
const builtInExtractors = {
|
|
53
|
-
DEFAULT:
|
|
54
|
-
let broadMatches = content.match(BROAD_MATCH_GLOBAL_REGEXP) || [];
|
|
55
|
-
let innerMatches = content.match(INNER_MATCH_GLOBAL_REGEXP) || [];
|
|
56
|
-
return [
|
|
57
|
-
...broadMatches,
|
|
58
|
-
...innerMatches
|
|
59
|
-
];
|
|
60
|
-
}
|
|
170
|
+
DEFAULT: _defaultExtractor.defaultExtractor
|
|
61
171
|
};
|
|
62
172
|
const builtInTransformers = {
|
|
63
173
|
DEFAULT: (content)=>content
|
|
64
174
|
,
|
|
65
|
-
svelte: (content)=>content.replace(/(?:^|\s)class:/g,
|
|
175
|
+
svelte: (content)=>content.replace(/(?:^|\s)class:/g, " ")
|
|
66
176
|
};
|
|
67
|
-
function getExtractor(
|
|
68
|
-
let extractors = tailwindConfig.content.extract;
|
|
69
|
-
|
|
70
|
-
if (typeof extractors === 'function') {
|
|
71
|
-
extractors = {
|
|
72
|
-
DEFAULT: extractors
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
if (contentOptions.defaultExtractor) {
|
|
76
|
-
extractors.DEFAULT = contentOptions.defaultExtractor;
|
|
77
|
-
}
|
|
78
|
-
for (let { extensions , extractor } of contentOptions.extractors || []){
|
|
79
|
-
for (let extension of extensions){
|
|
80
|
-
extractors[extension] = extractor;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT;
|
|
177
|
+
function getExtractor(context, fileExtension) {
|
|
178
|
+
let extractors = context.tailwindConfig.content.extract;
|
|
179
|
+
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT(context);
|
|
84
180
|
}
|
|
85
181
|
function getTransformer(tailwindConfig, fileExtension) {
|
|
86
182
|
let transformers = tailwindConfig.content.transform;
|
|
87
|
-
if (typeof transformers === 'function') {
|
|
88
|
-
transformers = {
|
|
89
|
-
DEFAULT: transformers
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
183
|
return transformers[fileExtension] || transformers.DEFAULT || builtInTransformers[fileExtension] || builtInTransformers.DEFAULT;
|
|
93
184
|
}
|
|
185
|
+
let extractorCache = new WeakMap();
|
|
94
186
|
// Scans template contents for possible classes. This is a hot path on initial build but
|
|
95
187
|
// not too important for subsequent builds. The faster the better though — if we can speed
|
|
96
188
|
// up these regexes by 50% that could cut initial build time by like 20%.
|
|
97
|
-
function getClassCandidates(content, extractor,
|
|
98
|
-
|
|
189
|
+
function getClassCandidates(content, extractor, candidates, seen) {
|
|
190
|
+
if (!extractorCache.has(extractor)) {
|
|
191
|
+
extractorCache.set(extractor, new _quickLru.default({
|
|
192
|
+
maxSize: 25000
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
for (let line of content.split("\n")){
|
|
99
196
|
line = line.trim();
|
|
100
197
|
if (seen.has(line)) {
|
|
101
198
|
continue;
|
|
102
199
|
}
|
|
103
200
|
seen.add(line);
|
|
104
|
-
if (
|
|
105
|
-
for (let match of
|
|
201
|
+
if (extractorCache.get(extractor).has(line)) {
|
|
202
|
+
for (let match of extractorCache.get(extractor).get(line)){
|
|
106
203
|
candidates.add(match);
|
|
107
204
|
}
|
|
108
205
|
} else {
|
|
109
|
-
let extractorMatches = extractor(line).filter((s)=>s !==
|
|
206
|
+
let extractorMatches = extractor(line).filter((s)=>s !== "!*"
|
|
110
207
|
);
|
|
111
208
|
let lineMatchesSet = new Set(extractorMatches);
|
|
112
209
|
for (let match of lineMatchesSet){
|
|
113
210
|
candidates.add(match);
|
|
114
211
|
}
|
|
115
|
-
|
|
212
|
+
extractorCache.get(extractor).set(line, lineMatchesSet);
|
|
116
213
|
}
|
|
117
214
|
}
|
|
118
215
|
}
|
|
@@ -121,6 +218,7 @@ function buildStylesheet(rules, context) {
|
|
|
121
218
|
);
|
|
122
219
|
let returnValue = {
|
|
123
220
|
base: new Set(),
|
|
221
|
+
defaults: new Set(),
|
|
124
222
|
components: new Set(),
|
|
125
223
|
utilities: new Set(),
|
|
126
224
|
variants: new Set(),
|
|
@@ -143,6 +241,10 @@ function buildStylesheet(rules, context) {
|
|
|
143
241
|
returnValue.base.add(rule);
|
|
144
242
|
continue;
|
|
145
243
|
}
|
|
244
|
+
if (sort & context.layerOrder.defaults) {
|
|
245
|
+
returnValue.defaults.add(rule);
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
146
248
|
if (sort & context.layerOrder.components) {
|
|
147
249
|
returnValue.components.add(rule);
|
|
148
250
|
continue;
|
|
@@ -158,100 +260,3 @@ function buildStylesheet(rules, context) {
|
|
|
158
260
|
}
|
|
159
261
|
return returnValue;
|
|
160
262
|
}
|
|
161
|
-
function expandTailwindAtRules(context) {
|
|
162
|
-
return (root)=>{
|
|
163
|
-
let layerNodes = {
|
|
164
|
-
base: null,
|
|
165
|
-
components: null,
|
|
166
|
-
utilities: null,
|
|
167
|
-
variants: null
|
|
168
|
-
};
|
|
169
|
-
// Make sure this file contains Tailwind directives. If not, we can save
|
|
170
|
-
// a lot of work and bail early. Also we don't have to register our touch
|
|
171
|
-
// file as a dependency since the output of this CSS does not depend on
|
|
172
|
-
// the source of any templates. Think Vue <style> blocks for example.
|
|
173
|
-
root.walkAtRules('tailwind', (rule)=>{
|
|
174
|
-
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
175
|
-
layerNodes[rule.params] = rule;
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
if (Object.values(layerNodes).every((n)=>n === null
|
|
179
|
-
)) {
|
|
180
|
-
return root;
|
|
181
|
-
}
|
|
182
|
-
// ---
|
|
183
|
-
// Find potential rules in changed files
|
|
184
|
-
let candidates = new Set([
|
|
185
|
-
'*'
|
|
186
|
-
]);
|
|
187
|
-
let seen = new Set();
|
|
188
|
-
env.DEBUG && console.time('Reading changed files');
|
|
189
|
-
for (let { content , extension } of context.changedContent){
|
|
190
|
-
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
191
|
-
let extractor = getExtractor(context.tailwindConfig, extension);
|
|
192
|
-
getClassCandidates(transformer(content), extractor, contentMatchCache, candidates, seen);
|
|
193
|
-
}
|
|
194
|
-
// ---
|
|
195
|
-
// Generate the actual CSS
|
|
196
|
-
let classCacheCount = context.classCache.size;
|
|
197
|
-
env.DEBUG && console.time('Generate rules');
|
|
198
|
-
let rules = (0, _generateRules).generateRules(candidates, context);
|
|
199
|
-
env.DEBUG && console.timeEnd('Generate rules');
|
|
200
|
-
// We only ever add to the classCache, so if it didn't grow, there is nothing new.
|
|
201
|
-
env.DEBUG && console.time('Build stylesheet');
|
|
202
|
-
if (context.stylesheetCache === null || context.classCache.size !== classCacheCount) {
|
|
203
|
-
for (let rule of rules){
|
|
204
|
-
context.ruleCache.add(rule);
|
|
205
|
-
}
|
|
206
|
-
context.stylesheetCache = buildStylesheet([
|
|
207
|
-
...context.ruleCache
|
|
208
|
-
], context);
|
|
209
|
-
}
|
|
210
|
-
env.DEBUG && console.timeEnd('Build stylesheet');
|
|
211
|
-
let { base: baseNodes , components: componentNodes , utilities: utilityNodes , variants: screenNodes , } = context.stylesheetCache;
|
|
212
|
-
// ---
|
|
213
|
-
// Replace any Tailwind directives with generated CSS
|
|
214
|
-
if (layerNodes.base) {
|
|
215
|
-
layerNodes.base.before((0, _cloneNodes).default([
|
|
216
|
-
...baseNodes
|
|
217
|
-
], layerNodes.base.source));
|
|
218
|
-
layerNodes.base.remove();
|
|
219
|
-
}
|
|
220
|
-
if (layerNodes.components) {
|
|
221
|
-
layerNodes.components.before((0, _cloneNodes).default([
|
|
222
|
-
...componentNodes
|
|
223
|
-
], layerNodes.components.source));
|
|
224
|
-
layerNodes.components.remove();
|
|
225
|
-
}
|
|
226
|
-
if (layerNodes.utilities) {
|
|
227
|
-
layerNodes.utilities.before((0, _cloneNodes).default([
|
|
228
|
-
...utilityNodes
|
|
229
|
-
], layerNodes.utilities.source));
|
|
230
|
-
layerNodes.utilities.remove();
|
|
231
|
-
}
|
|
232
|
-
if (layerNodes.variants) {
|
|
233
|
-
layerNodes.variants.before((0, _cloneNodes).default([
|
|
234
|
-
...screenNodes
|
|
235
|
-
], layerNodes.variants.source));
|
|
236
|
-
layerNodes.variants.remove();
|
|
237
|
-
} else {
|
|
238
|
-
root.append((0, _cloneNodes).default([
|
|
239
|
-
...screenNodes
|
|
240
|
-
], root.source));
|
|
241
|
-
}
|
|
242
|
-
// ---
|
|
243
|
-
if (env.DEBUG) {
|
|
244
|
-
console.log('Potential classes: ', candidates.size);
|
|
245
|
-
console.log('Active contexts: ', sharedState.contextSourcesMap.size);
|
|
246
|
-
console.log('Content match entries', contentMatchCache.size);
|
|
247
|
-
}
|
|
248
|
-
// Clear the cache for the changed files
|
|
249
|
-
context.changedContent = [];
|
|
250
|
-
// Cleanup any leftover @layer atrules
|
|
251
|
-
root.walkAtRules('layer', (rule)=>{
|
|
252
|
-
if (Object.keys(layerNodes).includes(rule.params)) {
|
|
253
|
-
rule.remove();
|
|
254
|
-
}
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
}
|