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
|
@@ -15,6 +15,58 @@ var _resolveConfigPath = _interopRequireDefault(require("../util/resolveConfigPa
|
|
|
15
15
|
var _sharedState = require("./sharedState");
|
|
16
16
|
var _setupContextUtils = require("./setupContextUtils");
|
|
17
17
|
var _parseDependency = _interopRequireDefault(require("../util/parseDependency"));
|
|
18
|
+
var _validateConfigJs = require("../util/validateConfig.js");
|
|
19
|
+
function setupTrackingContext(configOrPath) {
|
|
20
|
+
return ({ tailwindDirectives , registerDependency })=>{
|
|
21
|
+
return (root, result)=>{
|
|
22
|
+
let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] = getTailwindConfig(configOrPath);
|
|
23
|
+
let contextDependencies = new Set(configDependencies);
|
|
24
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS
|
|
25
|
+
// file or its dependencies to be dependencies of the context. Can reuse
|
|
26
|
+
// the context even if they change. We may want to think about `@layer`
|
|
27
|
+
// being part of this trigger too, but it's tough because it's impossible
|
|
28
|
+
// for a layer in one file to end up in the actual @tailwind rule in
|
|
29
|
+
// another file since independent sources are effectively isolated.
|
|
30
|
+
if (tailwindDirectives.size > 0) {
|
|
31
|
+
// Add current css file as a context dependencies.
|
|
32
|
+
contextDependencies.add(result.opts.from);
|
|
33
|
+
// Add all css @import dependencies as context dependencies.
|
|
34
|
+
for (let message of result.messages){
|
|
35
|
+
if (message.type === "dependency") {
|
|
36
|
+
contextDependencies.add(message.file);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
let [context] = (0, _setupContextUtils).getContext(root, result, tailwindConfig, userConfigPath, tailwindConfigHash, contextDependencies);
|
|
41
|
+
let candidateFiles = getCandidateFiles(context, tailwindConfig);
|
|
42
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
|
|
43
|
+
// dependencies to be dependencies of the context. Can reuse the context even if they change.
|
|
44
|
+
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
45
|
+
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
46
|
+
// in another file since independent sources are effectively isolated.
|
|
47
|
+
if (tailwindDirectives.size > 0) {
|
|
48
|
+
let fileModifiedMap = (0, _setupContextUtils).getFileModifiedMap(context);
|
|
49
|
+
// Add template paths as postcss dependencies.
|
|
50
|
+
for (let fileOrGlob of candidateFiles){
|
|
51
|
+
let dependency = (0, _parseDependency).default(fileOrGlob);
|
|
52
|
+
if (dependency) {
|
|
53
|
+
registerDependency(dependency);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (let changedContent of resolvedChangedContent(context, candidateFiles, fileModifiedMap)){
|
|
57
|
+
context.changedContent.push(changedContent);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (let file of configDependencies){
|
|
61
|
+
registerDependency({
|
|
62
|
+
type: "dependency",
|
|
63
|
+
file
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return context;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
}
|
|
18
70
|
function _interopRequireDefault(obj) {
|
|
19
71
|
return obj && obj.__esModule ? obj : {
|
|
20
72
|
default: obj
|
|
@@ -28,7 +80,7 @@ function getCandidateFiles(context, tailwindConfig) {
|
|
|
28
80
|
if (candidateFilesCache.has(context)) {
|
|
29
81
|
return candidateFilesCache.get(context);
|
|
30
82
|
}
|
|
31
|
-
let candidateFiles = tailwindConfig.content.
|
|
83
|
+
let candidateFiles = tailwindConfig.content.files.filter((item)=>typeof item === "string"
|
|
32
84
|
).map((contentPath)=>(0, _normalizePath).default(contentPath)
|
|
33
85
|
);
|
|
34
86
|
return candidateFilesCache.set(context, candidateFiles).get(context);
|
|
@@ -63,6 +115,7 @@ function getTailwindConfig(configOrPath) {
|
|
|
63
115
|
delete require.cache[file1];
|
|
64
116
|
}
|
|
65
117
|
let newConfig = (0, _resolveConfig).default(require(userConfigPath));
|
|
118
|
+
newConfig = (0, _validateConfigJs).validateConfig(newConfig);
|
|
66
119
|
let newHash = (0, _hashConfig).default(newConfig);
|
|
67
120
|
configPathCache.set(userConfigPath, [
|
|
68
121
|
newConfig,
|
|
@@ -79,6 +132,7 @@ function getTailwindConfig(configOrPath) {
|
|
|
79
132
|
}
|
|
80
133
|
// It's a plain object, not a path
|
|
81
134
|
let newConfig = (0, _resolveConfig).default(configOrPath.config === undefined ? configOrPath : configOrPath.config);
|
|
135
|
+
newConfig = (0, _validateConfigJs).validateConfig(newConfig);
|
|
82
136
|
return [
|
|
83
137
|
newConfig,
|
|
84
138
|
null,
|
|
@@ -87,14 +141,14 @@ function getTailwindConfig(configOrPath) {
|
|
|
87
141
|
];
|
|
88
142
|
}
|
|
89
143
|
function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
|
|
90
|
-
let changedContent = context.tailwindConfig.content.
|
|
91
|
-
).
|
|
144
|
+
let changedContent = context.tailwindConfig.content.files.filter((item)=>typeof item.raw === "string"
|
|
145
|
+
).map(({ raw , extension ="html" })=>({
|
|
92
146
|
content: raw,
|
|
93
147
|
extension
|
|
94
148
|
})
|
|
95
149
|
);
|
|
96
150
|
for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)){
|
|
97
|
-
let content = _fs.default.readFileSync(changedFile,
|
|
151
|
+
let content = _fs.default.readFileSync(changedFile, "utf8");
|
|
98
152
|
let extension = _path.default.extname(changedFile).slice(1);
|
|
99
153
|
changedContent.push({
|
|
100
154
|
content,
|
|
@@ -105,7 +159,7 @@ function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
|
|
|
105
159
|
}
|
|
106
160
|
function resolveChangedFiles(candidateFiles, fileModifiedMap) {
|
|
107
161
|
let changedFiles = new Set();
|
|
108
|
-
_sharedState.env.DEBUG && console.time(
|
|
162
|
+
_sharedState.env.DEBUG && console.time("Finding changed files");
|
|
109
163
|
let files = _fastGlob.default.sync(candidateFiles);
|
|
110
164
|
for (let file of files){
|
|
111
165
|
let prevModified = fileModifiedMap.has(file) ? fileModifiedMap.get(file) : -Infinity;
|
|
@@ -115,56 +169,6 @@ function resolveChangedFiles(candidateFiles, fileModifiedMap) {
|
|
|
115
169
|
fileModifiedMap.set(file, modified);
|
|
116
170
|
}
|
|
117
171
|
}
|
|
118
|
-
_sharedState.env.DEBUG && console.timeEnd(
|
|
172
|
+
_sharedState.env.DEBUG && console.timeEnd("Finding changed files");
|
|
119
173
|
return changedFiles;
|
|
120
174
|
}
|
|
121
|
-
function setupTrackingContext(configOrPath) {
|
|
122
|
-
return ({ tailwindDirectives , registerDependency })=>{
|
|
123
|
-
return (root, result)=>{
|
|
124
|
-
let [tailwindConfig, userConfigPath, tailwindConfigHash, configDependencies] = getTailwindConfig(configOrPath);
|
|
125
|
-
let contextDependencies = new Set(configDependencies);
|
|
126
|
-
// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
|
|
127
|
-
// to be dependencies of the context. Can reuse the context even if they change.
|
|
128
|
-
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
129
|
-
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
130
|
-
// in another file since independent sources are effectively isolated.
|
|
131
|
-
if (tailwindDirectives.size > 0) {
|
|
132
|
-
// Add current css file as a context dependencies.
|
|
133
|
-
contextDependencies.add(result.opts.from);
|
|
134
|
-
// Add all css @import dependencies as context dependencies.
|
|
135
|
-
for (let message of result.messages){
|
|
136
|
-
if (message.type === 'dependency') {
|
|
137
|
-
contextDependencies.add(message.file);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
let [context] = (0, _setupContextUtils).getContext(root, result, tailwindConfig, userConfigPath, tailwindConfigHash, contextDependencies);
|
|
142
|
-
let candidateFiles = getCandidateFiles(context, tailwindConfig);
|
|
143
|
-
// If there are no @tailwind rules, we don't consider this CSS file or it's dependencies
|
|
144
|
-
// to be dependencies of the context. Can reuse the context even if they change.
|
|
145
|
-
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
146
|
-
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
147
|
-
// in another file since independent sources are effectively isolated.
|
|
148
|
-
if (tailwindDirectives.size > 0) {
|
|
149
|
-
let fileModifiedMap = (0, _setupContextUtils).getFileModifiedMap(context);
|
|
150
|
-
// Add template paths as postcss dependencies.
|
|
151
|
-
for (let fileOrGlob of candidateFiles){
|
|
152
|
-
let dependency = (0, _parseDependency).default(fileOrGlob);
|
|
153
|
-
if (dependency) {
|
|
154
|
-
registerDependency(dependency);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
for (let changedContent of resolvedChangedContent(context, candidateFiles, fileModifiedMap)){
|
|
158
|
-
context.changedContent.push(changedContent);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
for (let file of configDependencies){
|
|
162
|
-
registerDependency({
|
|
163
|
-
type: 'dependency',
|
|
164
|
-
file
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return context;
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
}
|
package/lib/lib/sharedState.js
CHANGED
|
@@ -2,19 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports.
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) {
|
|
8
|
-
return obj && obj.__esModule ? obj : {
|
|
9
|
-
default: obj
|
|
10
|
-
};
|
|
11
|
-
}
|
|
5
|
+
exports.resolveDebug = resolveDebug;
|
|
6
|
+
exports.NOT_ON_DEMAND = exports.sourceHashMap = exports.contextSourcesMap = exports.configContextMap = exports.contextMap = exports.env = void 0;
|
|
12
7
|
const env = {
|
|
13
|
-
TAILWIND_MODE: process.env.TAILWIND_MODE,
|
|
14
8
|
NODE_ENV: process.env.NODE_ENV,
|
|
15
|
-
DEBUG: process.env.DEBUG
|
|
16
|
-
TAILWIND_DISABLE_TOUCH: process.env.TAILWIND_DISABLE_TOUCH !== undefined,
|
|
17
|
-
TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR
|
|
9
|
+
DEBUG: resolveDebug(process.env.DEBUG)
|
|
18
10
|
};
|
|
19
11
|
exports.env = env;
|
|
20
12
|
const contextMap = new Map();
|
|
@@ -23,7 +15,38 @@ const configContextMap = new Map();
|
|
|
23
15
|
exports.configContextMap = configContextMap;
|
|
24
16
|
const contextSourcesMap = new Map();
|
|
25
17
|
exports.contextSourcesMap = contextSourcesMap;
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
exports.
|
|
18
|
+
const sourceHashMap = new Map();
|
|
19
|
+
exports.sourceHashMap = sourceHashMap;
|
|
20
|
+
const NOT_ON_DEMAND = new String("*");
|
|
21
|
+
exports.NOT_ON_DEMAND = NOT_ON_DEMAND;
|
|
22
|
+
function resolveDebug(debug) {
|
|
23
|
+
if (debug === undefined) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// Environment variables are strings, so convert to boolean
|
|
27
|
+
if (debug === "true" || debug === "1") {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (debug === "false" || debug === "0") {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Keep the debug convention into account:
|
|
34
|
+
// DEBUG=* -> This enables all debug modes
|
|
35
|
+
// DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
|
|
36
|
+
// DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
|
|
37
|
+
// DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB
|
|
38
|
+
if (debug === "*") {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
let debuggers = debug.split(",").map((d)=>d.split(":")[0]
|
|
42
|
+
);
|
|
43
|
+
// Ignoring tailwindcss
|
|
44
|
+
if (debuggers.includes("-tailwindcss")) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
// Including tailwindcss
|
|
48
|
+
if (debuggers.includes("tailwindcss")) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.default = _default;
|
|
6
|
+
var _normalizeScreens = require("../util/normalizeScreens");
|
|
6
7
|
var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
|
|
7
8
|
function _interopRequireDefault(obj) {
|
|
8
9
|
return obj && obj.__esModule ? obj : {
|
|
@@ -11,14 +12,16 @@ function _interopRequireDefault(obj) {
|
|
|
11
12
|
}
|
|
12
13
|
function _default({ tailwindConfig: { theme } }) {
|
|
13
14
|
return function(css) {
|
|
14
|
-
css.walkAtRules(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
css.walkAtRules("screen", (atRule)=>{
|
|
16
|
+
let screen = atRule.params;
|
|
17
|
+
let screens = (0, _normalizeScreens).normalizeScreens(theme.screens);
|
|
18
|
+
let screenDefinition = screens.find(({ name })=>name === screen
|
|
19
|
+
);
|
|
20
|
+
if (!screenDefinition) {
|
|
18
21
|
throw atRule.error(`No \`${screen}\` screen found.`);
|
|
19
22
|
}
|
|
20
|
-
atRule.name =
|
|
21
|
-
atRule.params = (0, _buildMediaQuery).default(
|
|
23
|
+
atRule.name = "media";
|
|
24
|
+
atRule.params = (0, _buildMediaQuery).default(screenDefinition);
|
|
22
25
|
});
|
|
23
26
|
};
|
|
24
27
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# tailwindcss/nesting
|
|
2
2
|
|
|
3
|
-
This is a PostCSS plugin that wraps [postcss-nested](https://github.com/postcss/postcss-nested) or [postcss-nesting](https://github.com/
|
|
3
|
+
This is a PostCSS plugin that wraps [postcss-nested](https://github.com/postcss/postcss-nested) or [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting) and acts as a compatibility layer to make sure your nesting plugin of choice properly understands Tailwind's custom syntax like `@apply` and `@screen`.
|
|
4
4
|
|
|
5
5
|
Add it to your PostCSS configuration, somewhere before Tailwind itself:
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ module.exports = {
|
|
|
18
18
|
|
|
19
19
|
By default, it uses the [postcss-nested](https://github.com/postcss/postcss-nested) plugin under the hood, which uses a Sass-like syntax and is the plugin that powers nesting support in the [Tailwind CSS plugin API](https://tailwindcss.com/docs/plugins#css-in-js-syntax).
|
|
20
20
|
|
|
21
|
-
If you'd rather use [postcss-nesting](https://github.com/
|
|
21
|
+
If you'd rather use [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting) (which is based on the work-in-progress [CSS Nesting](https://drafts.csswg.org/css-nesting-1/) specification), first install the plugin alongside:
|
|
22
22
|
|
|
23
23
|
```shell
|
|
24
24
|
npm install postcss-nesting
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _plugin = require("./plugin");
|
|
7
|
+
var _default = Object.assign(function(opts) {
|
|
8
|
+
return {
|
|
9
|
+
postcssPlugin: "tailwindcss/nesting",
|
|
10
|
+
Once (root, { result }) {
|
|
11
|
+
return (0, _plugin).nesting(opts)(root, result);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}, {
|
|
15
|
+
postcss: true
|
|
16
|
+
});
|
|
17
|
+
exports.default = _default;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.nesting = nesting;
|
|
6
|
+
var _postcss = _interopRequireDefault(require("postcss"));
|
|
7
|
+
var _postcssNested = _interopRequireDefault(require("postcss-nested"));
|
|
8
|
+
function _interopRequireDefault(obj) {
|
|
9
|
+
return obj && obj.__esModule ? obj : {
|
|
10
|
+
default: obj
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function nesting(opts = _postcssNested.default) {
|
|
14
|
+
return (root, result)=>{
|
|
15
|
+
root.walkAtRules("screen", (rule)=>{
|
|
16
|
+
rule.name = "media";
|
|
17
|
+
rule.params = `screen(${rule.params})`;
|
|
18
|
+
});
|
|
19
|
+
root.walkAtRules("apply", (rule)=>{
|
|
20
|
+
rule.before(_postcss.default.decl({
|
|
21
|
+
prop: "__apply",
|
|
22
|
+
value: rule.params,
|
|
23
|
+
source: rule.source
|
|
24
|
+
}));
|
|
25
|
+
rule.remove();
|
|
26
|
+
});
|
|
27
|
+
let plugin = (()=>{
|
|
28
|
+
var ref;
|
|
29
|
+
if (typeof opts === "function" || typeof opts === "object" && (opts === null || opts === void 0 ? void 0 : (ref = opts.hasOwnProperty) === null || ref === void 0 ? void 0 : ref.call(opts, "postcssPlugin"))) {
|
|
30
|
+
return opts;
|
|
31
|
+
}
|
|
32
|
+
if (typeof opts === "string") {
|
|
33
|
+
return require(opts);
|
|
34
|
+
}
|
|
35
|
+
if (Object.keys(opts).length <= 0) {
|
|
36
|
+
return _postcssNested.default;
|
|
37
|
+
}
|
|
38
|
+
throw new Error("tailwindcss/nesting should be loaded with a nesting plugin.");
|
|
39
|
+
})();
|
|
40
|
+
(0, _postcss).default([
|
|
41
|
+
plugin
|
|
42
|
+
]).process(root, result.opts).sync();
|
|
43
|
+
root.walkDecls("__apply", (decl)=>{
|
|
44
|
+
decl.before(_postcss.default.atRule({
|
|
45
|
+
name: "apply",
|
|
46
|
+
params: decl.value,
|
|
47
|
+
source: decl.source
|
|
48
|
+
}));
|
|
49
|
+
decl.remove();
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Use a private PostCSS API to remove the "clean" flag from the entire AST.
|
|
53
|
+
* This is done because running process() on the AST will set the "clean"
|
|
54
|
+
* flag on all nodes, which we don't want.
|
|
55
|
+
*
|
|
56
|
+
* This causes downstream plugins using the visitor API to be skipped.
|
|
57
|
+
*
|
|
58
|
+
* This is guarded because the PostCSS API is not public
|
|
59
|
+
* and may change in future versions of PostCSS.
|
|
60
|
+
*
|
|
61
|
+
* See https://github.com/postcss/postcss/issues/1712 for more details
|
|
62
|
+
*
|
|
63
|
+
* @param {import('postcss').Node} node
|
|
64
|
+
*/ function markDirty(node) {
|
|
65
|
+
if (!("markDirty" in node)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
// Traverse the tree down to the leaf nodes
|
|
69
|
+
if (node.nodes) {
|
|
70
|
+
node.nodes.forEach((n)=>markDirty(n)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
// If it's a leaf node mark it as dirty
|
|
74
|
+
// We do this here because marking a node as dirty
|
|
75
|
+
// will walk up the tree and mark all parents as dirty
|
|
76
|
+
// resulting in a lot of unnecessary work if we did this
|
|
77
|
+
// for every single node
|
|
78
|
+
if (!node.nodes) {
|
|
79
|
+
node.markDirty();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
markDirty(root);
|
|
83
|
+
return root;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
@@ -10,21 +10,24 @@ var _evaluateTailwindFunctions = _interopRequireDefault(require("./lib/evaluateT
|
|
|
10
10
|
var _substituteScreenAtRules = _interopRequireDefault(require("./lib/substituteScreenAtRules"));
|
|
11
11
|
var _resolveDefaultsAtRules = _interopRequireDefault(require("./lib/resolveDefaultsAtRules"));
|
|
12
12
|
var _collapseAdjacentRules = _interopRequireDefault(require("./lib/collapseAdjacentRules"));
|
|
13
|
+
var _collapseDuplicateDeclarations = _interopRequireDefault(require("./lib/collapseDuplicateDeclarations"));
|
|
14
|
+
var _partitionApplyAtRules = _interopRequireDefault(require("./lib/partitionApplyAtRules"));
|
|
13
15
|
var _detectNesting = _interopRequireDefault(require("./lib/detectNesting"));
|
|
14
16
|
var _setupContextUtils = require("./lib/setupContextUtils");
|
|
15
|
-
|
|
16
|
-
return obj && obj.__esModule ? obj : {
|
|
17
|
-
default: obj
|
|
18
|
-
};
|
|
19
|
-
}
|
|
17
|
+
var _featureFlags = require("./featureFlags");
|
|
20
18
|
function processTailwindFeatures(setupContext) {
|
|
21
19
|
return function(root, result) {
|
|
22
|
-
let tailwindDirectives = (0, _normalizeTailwindDirectives).default(root);
|
|
20
|
+
let { tailwindDirectives , applyDirectives } = (0, _normalizeTailwindDirectives).default(root);
|
|
21
|
+
(0, _detectNesting).default()(root, result);
|
|
22
|
+
// Partition apply rules that are found in the css
|
|
23
|
+
// itself.
|
|
24
|
+
(0, _partitionApplyAtRules).default()(root, result);
|
|
23
25
|
let context = setupContext({
|
|
24
26
|
tailwindDirectives,
|
|
27
|
+
applyDirectives,
|
|
25
28
|
registerDependency (dependency) {
|
|
26
29
|
result.messages.push({
|
|
27
|
-
plugin:
|
|
30
|
+
plugin: "tailwindcss",
|
|
28
31
|
parent: result.opts.from,
|
|
29
32
|
...dependency
|
|
30
33
|
});
|
|
@@ -33,15 +36,24 @@ function processTailwindFeatures(setupContext) {
|
|
|
33
36
|
return (0, _setupContextUtils).createContext(tailwindConfig, changedContent, root);
|
|
34
37
|
}
|
|
35
38
|
})(root, result);
|
|
36
|
-
if (context.tailwindConfig.separator ===
|
|
39
|
+
if (context.tailwindConfig.separator === "-") {
|
|
37
40
|
throw new Error("The '-' character cannot be used as a custom separator in JIT mode due to parsing ambiguity. Please use another character like '_' instead.");
|
|
38
41
|
}
|
|
39
|
-
(0,
|
|
42
|
+
(0, _featureFlags).issueFlagNotices(context.tailwindConfig);
|
|
40
43
|
(0, _expandTailwindAtRules).default(context)(root, result);
|
|
44
|
+
// Partition apply rules that are generated by
|
|
45
|
+
// addComponents, addUtilities and so on.
|
|
46
|
+
(0, _partitionApplyAtRules).default()(root, result);
|
|
41
47
|
(0, _expandApplyAtRules).default(context)(root, result);
|
|
42
48
|
(0, _evaluateTailwindFunctions).default(context)(root, result);
|
|
43
49
|
(0, _substituteScreenAtRules).default(context)(root, result);
|
|
44
50
|
(0, _resolveDefaultsAtRules).default(context)(root, result);
|
|
45
51
|
(0, _collapseAdjacentRules).default(context)(root, result);
|
|
52
|
+
(0, _collapseDuplicateDeclarations).default(context)(root, result);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function _interopRequireDefault(obj) {
|
|
56
|
+
return obj && obj.__esModule ? obj : {
|
|
57
|
+
default: obj
|
|
46
58
|
};
|
|
47
59
|
}
|